Merge "Bug #25: Installing/removing flows with ".""
authorAlessandro Boch <aboch@cisco.com>
Tue, 25 Jun 2013 13:55:09 +0000 (13:55 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 25 Jun 2013 13:55:09 +0000 (13:55 +0000)
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
opendaylight/web/devices/src/main/resources/js/page.js

index faf9416..0a6c271 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 74da404..90a7803 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
      *
index e0d052d..ce59238 100644 (file)
@@ -110,7 +110,7 @@ one.f.switchmanager.nodesLearnt = {
                     var h3;
                     var footer = [];
                     var $body = one.f.switchmanager.nodesLearnt.modal.body.updateNode(nodeId, evt.target.switchDetails, tiers);
-                    if (one.main.registry.container == 'default' && evt.target.privilege == 'WRITE'){
+                    if ( (one.main.registry == undefined || one.main.registry.container == 'default') && evt.target.privilege == 'WRITE'){
                         h3 = "Update Node Information";
                         footer = one.f.switchmanager.nodesLearnt.modal.footer.updateNode();
                     } else { //disable node edit