Add IfNewHostNotify to DeviceManager 84/484/2
authorKalvin Hom <kahom@cisco.com>
Fri, 14 Jun 2013 01:25:52 +0000 (18:25 -0700)
committerKalvin Hom <kahom@cisco.com>
Fri, 14 Jun 2013 17:32:53 +0000 (10:32 -0700)
Small changes so that DeviceManager uses
IfNewHostNotify as listener to pass new
host info.  SimpleForwardingManager app should
now function, creating flows and allowing hosts
to ping each other.

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

index 2cf1c1d..cb02476 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Hashtable;
 import org.apache.felix.dm.Component;
 import org.opendaylight.controller.hosttracker.IDeviceService;
 import org.opendaylight.controller.hosttracker.IfIptoHost;
+import org.opendaylight.controller.hosttracker.IfNewHostNotify;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.sal.packet.IDataPacketService;
 import org.opendaylight.controller.sal.packet.IListenDataPacket;
@@ -91,6 +92,11 @@ public class Activator extends ComponentActivatorAbstractBase {
                     .setCallbacks("setDataPacketService",
                             "unsetDataPacketService").setRequired(true));
 
+            c.add(createContainerServiceDependency(containerName)
+                    .setService(IfNewHostNotify.class)
+                    .setCallbacks("setNewHostNotify",
+                            "unsetNewHostNotify").setRequired(false));
+
             // c.add(createContainerServiceDependency(containerName).setService(
             // IClusterContainerServices.class).setCallbacks(
             // "setClusterContainerService",
@@ -99,11 +105,6 @@ public class Activator extends ComponentActivatorAbstractBase {
                     .setService(ITopologyManager.class)
                     .setCallbacks("setTopologyManager", "unsetTopologyManager")
                     .setRequired(false));
-
-            c.add(createContainerServiceDependency(containerName)
-                    .setService(IDataPacketService.class)
-                    .setCallbacks("setDataPacketService",
-                            "unsetDataPacketService").setRequired(true));
         }
     }
 
index 50e77ec..a97cb27 100755 (executable)
@@ -784,10 +784,14 @@ public class Device implements IDevice {
     public HostNodeConnector toHostNodeConnector() {
         Integer[] ipv4s = this.getIPv4Addresses();
         try {
+            Entity e = this.entities[this.entities.length-1];
+            NodeConnector n = null;
+            if(e!=null)
+                 n = e.getPort();
             InetAddress ip = InetAddress.getByName(ipv4s[ipv4s.length - 1]
                     .toString());
             byte[] macAddr = macLongToByte(this.getMACAddress());
-            HostNodeConnector nc = new HostNodeConnector(macAddr, ip, null,
+            HostNodeConnector nc = new HostNodeConnector(macAddr, ip, n,
                     (short) 0);
             return nc;
         } catch (Exception e) {
index bda1372..0a70b72 100755 (executable)
@@ -67,6 +67,7 @@ import org.opendaylight.controller.hosttracker.IEntityClass;
 import org.opendaylight.controller.hosttracker.IEntityClassListener;
 import org.opendaylight.controller.hosttracker.IEntityClassifierService;
 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.Edge;
@@ -290,6 +291,10 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
      */
     protected ListenerDispatcher<String, IDeviceListener> deviceListeners;
 
+    /**
+     * Using the IfNewHostNotify to notify listeners of host changes.
+     */
+    private Set<IfNewHostNotify> newHostNotify = Collections.synchronizedSet(new HashSet<IfNewHostNotify>());
     /**
      * A device update event to be dispatched
      */
@@ -429,6 +434,14 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
     // Dependency injection
     // ********************
 
+    void setNewHostNotify(IfNewHostNotify obj){
+        this.newHostNotify.add(obj);
+    }
+
+    void unsetNewHostNotify(IfNewHostNotify obj){
+        this.newHostNotify.remove(obj);
+    }
+
     void setDataPacketService(IDataPacketService s) {
         this.dataPacketService = s;
     }
@@ -780,11 +793,11 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
         if (inPkt == null) {
             return PacketResult.IGNORED;
         }
-        try {
-            throw new Exception("Sample");
-        } catch (Exception e) {
-            logger.error("Sample stack trace", e);
-        }
+//        try {
+//            throw new Exception("Sample");
+//        } catch (Exception e) {
+//            logger.error("Sample stack trace", e);
+//        }
 
         Packet formattedPak = this.dataPacketService.decodeDataPacket(inPkt);
         Ethernet eth;
@@ -1444,9 +1457,28 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener,
 
     protected void notifyListeners(List<IDeviceListener> listeners,
             DeviceUpdate update) {
-        if (listeners == null) {
+        if (listeners == null && newHostNotify.isEmpty()) {
             return;
         }
+        /**
+         * TODO: IfNewHostNotify is needed for current controller API.
+         * Adding logic so that existing apps (like SimpleForwardingManager)
+         * work.  IDeviceListener adds additional methods and uses IListener's
+         * callback ordering.  The two interfaces need to be merged.
+         */
+
+        for (IfNewHostNotify notify : newHostNotify){
+            switch (update.change) {
+            case ADD:
+                notify.notifyHTClient(update.device.toHostNodeConnector());
+                break;
+            }
+        }
+
+        /**
+         * TODO: Remove this section as IDeviceListener functionality gets
+         * merged with IfNewHostNotify
+         */
         for (IDeviceListener listener : listeners) {
             switch (update.change) {
             case ADD: