X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FInventoryServiceShim.java;h=a920adf71d35163094514674fbb5b8a158bf66d7;hb=18e1184615fd939644d3660e5edcfbb676c187fa;hp=241fa92deb267414704bb8f2dca5095cf8078d05;hpb=850d5b748e96c2667bb95ce423bdb00083838619;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java index 241fa92deb..a920adf71d 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java @@ -26,12 +26,14 @@ 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.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; import org.opendaylight.controller.sal.core.Description; +import org.opendaylight.controller.sal.core.IContainerAware; import org.opendaylight.controller.sal.core.IContainerListener; import org.opendaylight.controller.sal.core.MacAddress; import org.opendaylight.controller.sal.core.Node; @@ -59,7 +61,7 @@ import org.slf4j.LoggerFactory; * */ public class InventoryServiceShim implements IContainerListener, - IMessageListener, ISwitchStateListener, IOFStatisticsListener { + IMessageListener, ISwitchStateListener, IOFStatisticsListener, IContainerAware { protected static final Logger logger = LoggerFactory .getLogger(InventoryServiceShim.class); private IController controller = null; @@ -139,7 +141,7 @@ public class InventoryServiceShim implements IContainerListener, } void setInventoryShimExternalListener(IInventoryShimExternalListener s) { - logger.trace("Set inventoryShimExternalListener"); + logger.trace("Set inventoryShimExternalListener {}", s); if ((this.inventoryShimExternalListeners != null) && !this.inventoryShimExternalListeners.contains(s)) { this.inventoryShimExternalListeners.add(s); @@ -147,6 +149,7 @@ public class InventoryServiceShim implements IContainerListener, } void unsetInventoryShimExternalListener(IInventoryShimExternalListener s) { + logger.trace("Unset inventoryShimExternalListener {}", s); if ((this.inventoryShimExternalListeners != null) && this.inventoryShimExternalListeners.contains(s)) { this.inventoryShimExternalListeners.remove(s); @@ -237,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> ncProps = InventoryServiceHelper @@ -248,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 @@ -350,15 +361,13 @@ public class InventoryServiceShim implements IContainerListener, } } - private void notifyInventoryShimExternalListener(Node node, - UpdateType type, Set props) { + private void notifyInventoryShimExternalListener(Node node, UpdateType type, Set props) { for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) { s.updateNode(node, type, props); } } - private void notifyInventoryShimExternalListener( - NodeConnector nodeConnector, UpdateType type, Set props) { + private void notifyInventoryShimExternalListener(NodeConnector nodeConnector, UpdateType type, Set props) { for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) { s.updateNodeConnector(nodeConnector, type, props); } @@ -366,14 +375,11 @@ public class InventoryServiceShim implements IContainerListener, private void notifyInventoryShimInternalListener(String container, NodeConnector nodeConnector, UpdateType type, Set 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 }); } } @@ -381,65 +387,74 @@ public class InventoryServiceShim implements IContainerListener, * Notify all internal and external listeners */ private void notifyInventoryShimListener(NodeConnector nodeConnector, UpdateType type, Set props) { - notifyGlobalInventoryShimInternalListener(nodeConnector, type, props); - /* - * isLocal is intentionally moved after the GlobalInventory listener call. - * The above notification to GlobalInventory will make sure that the connectionOutService be ready - * to reply to isLocal query. - */ - if (!connectionOutService.isLocal(nodeConnector.getNode())) { - logger.debug("Connection service dropped the inventory notification for {} {}", nodeConnector.toString(), type); - return; + + //establish locality before notifying + boolean isNodeLocal; + if (type == UpdateType.REMOVED){ + //if removing get the locality first + isNodeLocal = connectionOutService.isLocal(nodeConnector.getNode()); + notifyGlobalInventoryShimInternalListener(nodeConnector, type, props); } else { - logger.debug("Connection service accepted the inventory notification for {} {}", nodeConnector.toString(), type); + notifyGlobalInventoryShimInternalListener(nodeConnector, type, props); + isNodeLocal = connectionOutService.isLocal(nodeConnector.getNode()); } - // notify other containers - Set containers = (nodeConnectorContainerMap.get(nodeConnector) == null) ? new HashSet() - : new HashSet(nodeConnectorContainerMap.get(nodeConnector)); - containers.add(GlobalConstants.DEFAULT.toString()); - for (String container : containers) { - notifyInventoryShimInternalListener(container, nodeConnector, type, props); - } + if (isNodeLocal) { + // notify other containers + Set containers = (nodeConnectorContainerMap.get(nodeConnector) == null) ? new HashSet() + : new HashSet(nodeConnectorContainerMap.get(nodeConnector)); + containers.add(GlobalConstants.DEFAULT.toString()); + for (String container : containers) { + notifyInventoryShimInternalListener(container, nodeConnector, type, props); + } - // Notify DiscoveryService - notifyInventoryShimExternalListener(nodeConnector, type, props); + // Notify plugin listeners (Discovery, DataPacket, OFstats etc.) + notifyInventoryShimExternalListener(nodeConnector, type, props); + + logger.debug("Connection service accepted the inventory notification for {} {}", nodeConnector, type); + } else { + logger.debug("Connection service dropped the inventory notification for {} {}", nodeConnector, type); + } } /* * Notify all internal and external listeners */ private void notifyInventoryShimListener(Node node, UpdateType type, Set props) { - notifyGlobalInventoryShimInternalListener(node, type, props); - /* - * isLocal is intentionally moved after the GlobalInventory listener call. - * The above notification to GlobalInventory will make sure that the connectionOutService be ready - * to reply to isLocal query. - */ - if (!connectionOutService.isLocal(node)) { - logger.debug("Connection service dropped the inventory notification for {} {}", node.toString(), type); - return; + + //establish locality before notifying + boolean isNodeLocal; + if (type == UpdateType.REMOVED){ + //if removing get the locality first + isNodeLocal = connectionOutService.isLocal(node); + notifyGlobalInventoryShimInternalListener(node, type, props); } else { - logger.debug("Connection service accepted the inventory notification for {} {}", node.toString(), type); - } - // Now notify other containers - Set containers = (nodeContainerMap.get(node) == null) ? new HashSet() : new HashSet( - nodeContainerMap.get(node)); - containers.add(GlobalConstants.DEFAULT.toString()); - for (String container : containers) { - notifyInventoryShimInternalListener(container, node, type, props); + notifyGlobalInventoryShimInternalListener(node, type, props); + isNodeLocal = connectionOutService.isLocal(node); } - // Notify external listener - notifyInventoryShimExternalListener(node, type, props); + if (isNodeLocal) { + // Now notify other containers + Set containers = (nodeContainerMap.get(node) == null) ? new HashSet() + : new HashSet(nodeContainerMap.get(node)); + containers.add(GlobalConstants.DEFAULT.toString()); + for (String container : containers) { + notifyInventoryShimInternalListener(container, node, type, props); + } + + // Notify plugin listeners (Discovery, DataPacket, OFstats etc.) + notifyInventoryShimExternalListener(node, type, props); + + logger.debug("Connection service accepted the inventory notification for {} {}", node, type); + } else { + logger.debug("Connection service dropped the inventory notification for {} {}", node, type); + } } private void notifyGlobalInventoryShimInternalListener(Node node, UpdateType type, Set 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 }); } } @@ -471,8 +486,7 @@ public class InventoryServiceShim implements IContainerListener, Set props = new HashSet(); Long sid = (Long) node.getID(); - Date connectedSince = controller.getSwitches().get(sid) - .getConnectedDate(); + Date connectedSince = sw.getConnectedDate(); Long connectedSinceTime = (connectedSince == null) ? 0 : connectedSince .getTime(); props.add(new TimeStamp(connectedSinceTime, "connectedSince")); @@ -499,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); @@ -573,4 +592,43 @@ public class InventoryServiceShim implements IContainerListener, public void tableStatisticsRefreshed(Long switchId, List tables) { // Nothing to do } + + @Override + public void containerCreate(String containerName) { + // Nothing to do + } + + @Override + public void containerDestroy(String containerName) { + Set removeNodeConnectorSet = new HashSet(); + Set removeNodeSet = new HashSet(); + for (Map.Entry> entry : nodeConnectorContainerMap.entrySet()) { + Set ncContainers = entry.getValue(); + if (ncContainers.contains(containerName)) { + NodeConnector nodeConnector = entry.getKey(); + removeNodeConnectorSet.add(nodeConnector); + } + } + for (Map.Entry> entry : nodeContainerMap.entrySet()) { + Set nodeContainers = entry.getValue(); + if (nodeContainers.contains(containerName)) { + Node node = entry.getKey(); + removeNodeSet.add(node); + } + } + for (NodeConnector nodeConnector : removeNodeConnectorSet) { + Set ncContainers = nodeConnectorContainerMap.get(nodeConnector); + ncContainers.remove(containerName); + if (ncContainers.isEmpty()) { + nodeConnectorContainerMap.remove(nodeConnector); + } + } + for (Node node : removeNodeSet) { + Set nodeContainers = nodeContainerMap.get(node); + nodeContainers.remove(containerName); + if (nodeContainers.isEmpty()) { + nodeContainerMap.remove(node); + } + } + } }