Controller ignores switch, if no ports are present 94/3594/2
authorAlessandro Boch <aboch@cisco.com>
Mon, 9 Dec 2013 21:19:50 +0000 (13:19 -0800)
committerAlessandro Boch <aboch@cisco.com>
Mon, 9 Dec 2013 22:45:41 +0000 (14:45 -0800)
 - At switch connection, InventoryServiceShim mistakenly skips to
   inform the global listeners if no ports are configured on the switch.
   This is not visible with software switches because they always
   advertise they have the OFLocal port active.
   Being Connection Service a listener of global inventory service,
   it will not get to know about the switch presence, and in subsequent
   queries from InventoryServiceShim it will reply the switch is not
   locally connected to this controller, causing Inventory Shim to
   not inform its upper layer listeners about the switch. Therefore
   no other controller service will get to know the switch is conencted.

Change-Id: I29f658cc2a84ab7aab2c19ae9fe4d5a33c0afe0c
Signed-off-by: Alessandro Boch <aboch@cisco.com>
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java

index f4843cf8283f36f2dc4ae957c2e46c42d363e4d6..2b26ecb749447aa3e31648c3d425f641a11a82e2 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.protocol_plugin.openflow.internal;
 
 import java.util.ArrayList;
 package org.opendaylight.controller.protocol_plugin.openflow.internal;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
@@ -238,6 +239,7 @@ public class InventoryServiceShim implements IContainerListener,
     @Override
     public void switchAdded(ISwitch sw) {
         if (sw == null) {
     @Override
     public void switchAdded(ISwitch sw) {
         if (sw == null) {
+            logger.debug("Ignore null switch addition");
             return;
         }
         Node node = NodeCreator.createOFNode(sw.getId());
             return;
         }
         Node node = NodeCreator.createOFNode(sw.getId());
@@ -246,17 +248,24 @@ public class InventoryServiceShim implements IContainerListener,
             return;
         }
 
             return;
         }
 
-        // Add all the nodeConnectors of this switch
-        Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper
-                .OFSwitchToProps(sw);
-        for (Map.Entry<NodeConnector, Set<Property>> entry : ncProps.entrySet()) {
-            Set<Property> props = new HashSet<Property>();
-            Set<Property> prop = entry.getValue();
-            if (prop != null) {
-                props.addAll(prop);
+        // Add all the nodeConnectors of this switch if any
+        Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper.OFSwitchToProps(sw);
+        if (!ncProps.isEmpty()) {
+            for (Map.Entry<NodeConnector, Set<Property>> entry : ncProps.entrySet()) {
+                Set<Property> props = new HashSet<Property>();
+                Set<Property> prop = entry.getValue();
+                if (prop != null) {
+                    props.addAll(prop);
+                }
+                nodeConnectorProps.put(entry.getKey(), props);
+                notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry.getValue());
             }
             }
-            nodeConnectorProps.put(entry.getKey(), props);
-            notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry.getValue());
+        } else {
+            /*
+             * If no node connector is present, publish the node addition itself
+             * in order to let Connection Manager properly set the node locality
+             */
+            this.notifyInventoryShimListener(node, UpdateType.ADDED, Collections.<Property>emptySet());
         }
 
         // Add this node
         }
 
         // Add this node