Fixing a recent breakage in Flow programmer introduced by https://git.opendaylight...
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / InventoryServiceShim.java
index 8db83f0fc7e2449b99079aadf5dfc709204f2f35..f4843cf8283f36f2dc4ae957c2e46c42d363e4d6 100644 (file)
@@ -26,8 +26,9 @@ import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
 import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
 import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitchStateListener;
+import org.opendaylight.controller.sal.action.SupportedFlowActions;
+import org.opendaylight.controller.sal.connection.ConnectionLocality;
 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
-import org.opendaylight.controller.sal.core.Actions;
 import org.opendaylight.controller.sal.core.Buffers;
 import org.opendaylight.controller.sal.core.Capabilities;
 import org.opendaylight.controller.sal.core.ContainerFlow;
@@ -239,6 +240,11 @@ public class InventoryServiceShim implements IContainerListener,
         if (sw == null) {
             return;
         }
+        Node node = NodeCreator.createOFNode(sw.getId());
+        if ((nodeProps.get(node) != null)  && (connectionOutService.isLocal(node))) {
+            logger.debug("Ignore switchAdded {}", sw);
+            return;
+        }
 
         // Add all the nodeConnectors of this switch
         Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper
@@ -250,12 +256,15 @@ public class InventoryServiceShim implements IContainerListener,
                 props.addAll(prop);
             }
             nodeConnectorProps.put(entry.getKey(), props);
-            notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED,
-                    entry.getValue());
+            notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry.getValue());
         }
 
         // Add this node
-        addNode(sw);
+        if (connectionOutService.getLocalityStatus(node) != ConnectionLocality.NOT_CONNECTED) {
+            addNode(sw);
+        } else {
+            logger.debug("Skipping node addition due to Connectivity Status : {}", connectionOutService.getLocalityStatus(node).name());
+        }
     }
 
     @Override
@@ -352,15 +361,13 @@ public class InventoryServiceShim implements IContainerListener,
         }
     }
 
-    private void notifyInventoryShimExternalListener(Node node,
-            UpdateType type, Set<Property> props) {
+    private void notifyInventoryShimExternalListener(Node node, UpdateType type, Set<Property> props) {
         for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) {
             s.updateNode(node, type, props);
         }
     }
 
-    private void notifyInventoryShimExternalListener(
-            NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
+    private void notifyInventoryShimExternalListener(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
         for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) {
             s.updateNodeConnector(nodeConnector, type, props);
         }
@@ -368,14 +375,11 @@ public class InventoryServiceShim implements IContainerListener,
 
     private void notifyInventoryShimInternalListener(String container,
             NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
-        IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners
-                .get(container);
+        IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners.get(container);
         if (inventoryShimInternalListener != null) {
-            inventoryShimInternalListener.updateNodeConnector(nodeConnector,
-                    type, props);
-            logger.trace(
-                    "notifyInventoryShimInternalListener {} type {} for container {}",
-                    new Object[] { nodeConnector, type, container });
+            inventoryShimInternalListener.updateNodeConnector(nodeConnector, type, props);
+            logger.trace("notifyInventoryShimInternalListener {} type {} for container {}", new Object[] {
+                    nodeConnector, type, container });
         }
     }
 
@@ -404,7 +408,7 @@ public class InventoryServiceShim implements IContainerListener,
                 notifyInventoryShimInternalListener(container, nodeConnector, type, props);
             }
 
-            // Notify DiscoveryService
+            // Notify plugin listeners (Discovery, DataPacket, OFstats etc.)
             notifyInventoryShimExternalListener(nodeConnector, type, props);
 
             logger.debug("Connection service accepted the inventory notification for {} {}", nodeConnector, type);
@@ -431,14 +435,14 @@ public class InventoryServiceShim implements IContainerListener,
 
         if (isNodeLocal) {
             // Now notify other containers
-            Set<String> containers = (nodeContainerMap.get(node) == null) ? new HashSet<String>() : new HashSet<String>(
-                    nodeContainerMap.get(node));
+            Set<String> containers = (nodeContainerMap.get(node) == null) ? new HashSet<String>()
+                    : new HashSet<String>(nodeContainerMap.get(node));
             containers.add(GlobalConstants.DEFAULT.toString());
             for (String container : containers) {
                 notifyInventoryShimInternalListener(container, node, type, props);
             }
 
-            // Notify external listener
+            // Notify plugin listeners (Discovery, DataPacket, OFstats etc.)
             notifyInventoryShimExternalListener(node, type, props);
 
             logger.debug("Connection service accepted the inventory notification for {} {}", node, type);
@@ -450,9 +454,7 @@ public class InventoryServiceShim implements IContainerListener,
     private void notifyGlobalInventoryShimInternalListener(Node node, UpdateType type, Set<Property> props) {
         for (IInventoryShimInternalListener globalListener : globalInventoryShimInternalListeners) {
             globalListener.updateNode(node, type, props);
-            logger.trace(
-                    "notifyGlobalInventoryShimInternalListener {} type {}",
-                    new Object[] { node, type });
+            logger.trace("notifyGlobalInventoryShimInternalListener {} type {}", new Object[] { node, type });
         }
     }
 
@@ -501,7 +503,7 @@ public class InventoryServiceShim implements IContainerListener,
             props.add(c);
         }
         int act = sw.getActions();
-        Actions a = new Actions(act);
+        SupportedFlowActions a = new SupportedFlowActions(FlowConverter.getFlowActions(act));
         if (a != null) {
             props.add(a);
         }
@@ -511,6 +513,11 @@ public class InventoryServiceShim implements IContainerListener,
             props.add(b);
         }
 
+        if ((nodeProps.get(node) == null) &&  (connectionOutService.isLocal(node)))  {
+            // The switch is connected for the first time, flush all flows
+            // that may exist on this switch
+            sw.deleteAllFlows();
+       }
         nodeProps.put(node, props);
         // Notify all internal and external listeners
         notifyInventoryShimListener(node, type, props);