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>
package org.opendaylight.controller.hosttracker;
package org.opendaylight.controller.hosttracker;
+import java.net.InetAddress;
+import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
import org.opendaylight.controller.sal.core.NodeConnector;
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
/**
* An entity on the network is a visible trace of a device that corresponds to a
+ 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="
@Override
public String toString() {
return "Entity [macAddress=" + macAddress + ", ipv4Address="
@Override
public Set<HostNodeConnector> getInactiveStaticHosts() {
@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;
listener.deviceRemoved(d);
}
}
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);
}
return new Status(StatusCode.SUCCESS);
}
Entity ent = inactiveStaticDevices.get(nodeConnector);
Device device = this.learnDeviceByEntity(ent);
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.
}
}else{
// remove all devices on the node that went down.