From: Kalvin Hom Date: Tue, 16 Jul 2013 21:53:33 +0000 (-0700) Subject: Get/remove inactive hosts X-Git-Tag: releasepom-0.1.0~259^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=09fa865f5f711b68d32d56eaae0989824ed7df31 Get/remove inactive hosts 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 --- diff --git a/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/Entity.java b/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/Entity.java index 7c98e9505b..924d0717e9 100644 --- a/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/Entity.java +++ b/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/Entity.java @@ -33,9 +33,12 @@ 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 { 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=" diff --git a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java index 7e97942437..95d33ceef9 100755 --- a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java +++ b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java @@ -2227,8 +2227,16 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, @Override public Set getInactiveStaticHosts() { - // TODO Auto-generated method stub - return null; + Collection devices = Collections + .unmodifiableCollection(inactiveStaticDevices.values()); + Iterator i = devices.iterator(); + Set nc = new HashSet(); + 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 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.