Get/remove inactive hosts 06/606/1
authorKalvin Hom <kahom@cisco.com>
Tue, 16 Jul 2013 21:53:33 +0000 (14:53 -0700)
committerKalvin Hom <kahom@cisco.com>
Tue, 16 Jul 2013 21:53:33 +0000 (14:53 -0700)
Added logic for removing inactive hosts
when removing static hosts, and for
retrieving list of inactive hosts.

Change-Id: I2f08f35eec36a99dee21979c5a64d62d01647602
Signed-off-by: Kalvin Hom <kahom@cisco.com>
opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/Entity.java
opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java

index 7c98e95..924d071 100644 (file)
 
 package org.opendaylight.controller.hosttracker;
 
+import java.net.InetAddress;
 import java.util.Date;
 
+import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.utils.NetUtils;
 
 /**
  * An entity on the network is a visible trace of a device that corresponds to a
@@ -218,6 +221,19 @@ public class Entity implements Comparable<Entity> {
         return true;
     }
 
+    public HostNodeConnector toHostNodeConnector() {
+        try {
+            NodeConnector n = this.getPort();
+            InetAddress ip = InetAddress.getByAddress(NetUtils.intToByteArray4(this.getIpv4Address()));
+            byte[] macAddr = NetUtils.longToByteArray6(this.getMacAddress());
+            HostNodeConnector nc = new HostNodeConnector(macAddr, ip, n,
+                    (short) 0);
+            return nc;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
     @Override
     public String toString() {
         return "Entity [macAddress=" + macAddress + ", ipv4Address="
index 7e97942..95d33ce 100755 (executable)
@@ -2227,8 +2227,16 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
 
     @Override
     public Set<HostNodeConnector> getInactiveStaticHosts() {
-        // TODO Auto-generated method stub
-        return null;
+        Collection<Entity> devices = Collections
+                .unmodifiableCollection(inactiveStaticDevices.values());
+        Iterator<Entity> i = devices.iterator();
+        Set<HostNodeConnector> nc = new HashSet<HostNodeConnector>();
+        while (i.hasNext()) {
+            Entity ent = i.next();
+                nc.add(ent.toHostNodeConnector());
+
+        }
+        return nc;
     }
 
     @Override
@@ -2277,6 +2285,16 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
                     listener.deviceRemoved(d);
             }
         }
+        //go through inactive entites.
+        Set<HostNodeConnector> inactive = this.getInactiveStaticHosts();
+        for(HostNodeConnector nc : inactive){
+            Integer ip =toIPv4Address(nc.getNetworkAddress().getAddress());
+            if(ip.equals(addr)){
+                this.inactiveStaticDevices.remove(nc.getnodeConnector());
+            }
+        }
+
+
         return new Status(StatusCode.SUCCESS);
     }
 
@@ -2335,15 +2353,17 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
 
             Entity ent = inactiveStaticDevices.get(nodeConnector);
             Device device = this.learnDeviceByEntity(ent);
-            HostNodeConnector host = device.toHostNodeConnector();
-            if (host != null) {
-                inactiveStaticDevices.remove(nodeConnector);
-                for (IfNewHostNotify notify : newHostNotify)
-                    notify.notifyHTClient(host);
-                for (IDeviceListener listener : listeners)
-                    listener.deviceAdded(device);
-            } else {
-                logger.debug("handleNodeConnectorStatusDown {}", nodeConnector);
+            if(device!=null){
+                HostNodeConnector host = device.toHostNodeConnector();
+                if (host != null) {
+                    inactiveStaticDevices.remove(nodeConnector);
+                    for (IfNewHostNotify notify : newHostNotify)
+                        notify.notifyHTClient(host);
+                    for (IDeviceListener listener : listeners)
+                        listener.deviceAdded(device);
+                } else {
+                    logger.debug("handleNodeConnectorStatusDown {}", nodeConnector);
+                }
             }
         }else{
                 // remove all devices on the node that went down.