Host updates for Topology 05/505/2
authorKalvin Hom <kahom@cisco.com>
Wed, 19 Jun 2013 23:02:26 +0000 (16:02 -0700)
committerKalvin Hom <kahom@cisco.com>
Fri, 21 Jun 2013 19:22:26 +0000 (12:22 -0700)
new HostTracker will now properly update
topologyManager when hosts get added/removed.
UI's diagram will now show the hosts.

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

index faf9416934f897dd77bafda31ea565d4c75742e7..0a6c2713dde0a2e6a0087f7d7c889e5d77668765 100755 (executable)
@@ -71,9 +71,14 @@ import org.opendaylight.controller.hosttracker.IfIptoHost;
 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
 import org.opendaylight.controller.hosttracker.SwitchPort;
 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
+import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.Host;
+import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
+import org.opendaylight.controller.sal.core.Tier;
+import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.sal.packet.ARP;
 import org.opendaylight.controller.sal.packet.Ethernet;
 import org.opendaylight.controller.sal.packet.IDataPacketService;
@@ -81,10 +86,13 @@ import org.opendaylight.controller.sal.packet.IListenDataPacket;
 import org.opendaylight.controller.sal.packet.Packet;
 import org.opendaylight.controller.sal.packet.PacketResult;
 import org.opendaylight.controller.sal.packet.RawPacket;
+import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
+import org.opendaylight.controller.sal.packet.address.EthernetAddress;
 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.ListenerDispatcher;
 import org.opendaylight.controller.sal.utils.MultiIterator;
+import org.opendaylight.controller.sal.utils.NetUtils;
 import org.opendaylight.controller.sal.utils.SingletonTask;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
@@ -1461,6 +1469,45 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
 
     protected void notifyListeners(List<IDeviceListener> listeners,
             DeviceUpdate update) {
+       // Topology update is for some reason outside of listeners registry
+       // logic
+        Entity[] ents = update.device.getEntities();
+        Entity e = ents[ents.length-1];
+        NodeConnector p = e.getPort();
+        Node node = p.getNode();
+        Host h = null;
+        try {
+            byte[] mac = NetUtils.longToByteArray6(e.getMacAddress());
+            DataLinkAddress dla = new EthernetAddress(
+                    mac);
+            e.getIpv4Address();
+            InetAddress.getAllByName(e.getIpv4Address().toString());
+            h = new org.opendaylight.controller.sal.core.Host(dla,
+                    InetAddress.getByName(e.getIpv4Address().toString()));
+        } catch (ConstructionException ce) {
+            p = null;
+            h = null;
+        } catch (UnknownHostException ue){
+            p = null;
+            h = null;
+        }
+
+        if (topology != null && p != null && h != null) {
+            if (update.change.equals(DeviceUpdate.Change.ADD)) {
+                Tier tier = new Tier(1);
+                switchManager.setNodeProp(node, tier);
+                topology.updateHostLink(p, h, UpdateType.ADDED, null);
+            } else {
+                // No need to reset the tiering if no other hosts are currently
+                // connected
+                // If this switch was discovered to be an access switch, it
+                // still is even if the host is down
+                Tier tier = new Tier(0);
+                switchManager.setNodeProp(node, tier);
+                topology.updateHostLink(p, h, UpdateType.REMOVED, null);
+            }
+        }
+
         if (listeners == null && newHostNotify.isEmpty()) {
             return;
         }
index 74da40449646059b640e96465b9b01bbf93ac2d5..90a7803ba07b02568a06f16edc2ed892dcd5460e 100644 (file)
@@ -47,6 +47,21 @@ public abstract class NetUtils {
                 | (0xff & ba[2]) << 8 | (0xff & ba[3]);
     }
 
+    /**
+     * Converts a long to 6 bytes array for mac addresses
+     * @param addr
+     * @return
+     */
+
+    public static byte[] longToByteArray6(long addr){
+        byte[] mac = new byte[6];
+        for(int i = 0; i < 6; i++){
+            mac[i] = (byte) (addr >> (i*8));
+        }
+        return mac;
+    }
+
+
     /**
      * Converts an integer number into a 4 bytes array
      *