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=8db83f0fc7e2449b99079aadf5dfc709204f2f35;hb=ab70c9c38302ae1034bbde5d9c2964d7ec8bcebe;hp=f0b8735f83f960b0626fff87c20304ce40a03cb9;hpb=4731ee462f09ad75d31a175b0dd5abfa11eb2b6a;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 f0b8735f83..8db83f0fc7 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,11 +26,13 @@ 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.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; @@ -58,16 +60,18 @@ 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; private final ConcurrentMap inventoryShimInternalListeners = new ConcurrentHashMap(); + private final Set globalInventoryShimInternalListeners = new HashSet(); private final List inventoryShimExternalListeners = new CopyOnWriteArrayList(); private final ConcurrentMap> nodeConnectorContainerMap = new ConcurrentHashMap>(); private final ConcurrentMap> nodeContainerMap = new ConcurrentHashMap>(); private final ConcurrentMap> nodeConnectorProps = new ConcurrentHashMap>(); private final ConcurrentMap> nodeProps = new ConcurrentHashMap>(); + private IPluginOutConnectionService connectionOutService; void setController(IController s) { this.controller = s; @@ -79,6 +83,20 @@ public class InventoryServiceShim implements IContainerListener, } } + void setInventoryShimGlobalInternalListener(Map props, + IInventoryShimInternalListener s) { + if ((this.globalInventoryShimInternalListeners != null)) { + this.globalInventoryShimInternalListeners.add(s); + } + } + + void unsetInventoryShimGlobalInternalListener(Map props, + IInventoryShimInternalListener s) { + if ((this.globalInventoryShimInternalListeners != null)) { + this.globalInventoryShimInternalListeners.remove(s); + } + } + void setInventoryShimInternalListener(Map props, IInventoryShimInternalListener s) { if (props == null) { @@ -107,7 +125,7 @@ public class InventoryServiceShim implements IContainerListener, } String containerName = (String) props.get("containerName"); if (containerName == null) { - logger.error("unsetInventoryShimInternalListener containerName not supplied"); + logger.error("setInventoryShimInternalListener containerName not supplied"); return; } if ((this.inventoryShimInternalListeners != null) @@ -122,7 +140,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); @@ -130,12 +148,23 @@ 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); } } + void setIPluginOutConnectionService(IPluginOutConnectionService s) { + connectionOutService = s; + } + + void unsetIPluginOutConnectionService(IPluginOutConnectionService s) { + if (connectionOutService == s) { + connectionOutService = null; + } + } + /** * Function called by the dependency manager when all the required * dependencies are satisfied @@ -167,6 +196,7 @@ public class InventoryServiceShim implements IContainerListener, this.inventoryShimInternalListeners.clear(); this.nodeConnectorContainerMap.clear(); this.nodeContainerMap.clear(); + this.globalInventoryShimInternalListeners.clear(); this.controller = null; } @@ -353,32 +383,86 @@ public class InventoryServiceShim implements IContainerListener, * Notify all internal and external listeners */ private void notifyInventoryShimListener(NodeConnector nodeConnector, UpdateType type, Set props) { - // 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); + //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 { + notifyGlobalInventoryShimInternalListener(nodeConnector, type, props); + isNodeLocal = connectionOutService.isLocal(nodeConnector.getNode()); + } + + 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); + + 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) { - // 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); + + //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 { + notifyGlobalInventoryShimInternalListener(node, type, props); + isNodeLocal = connectionOutService.isLocal(node); + } + + 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 external listener + 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); } + } - // Notify external listener - notifyInventoryShimExternalListener(node, type, props); + 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 }); + } + } + + private void notifyGlobalInventoryShimInternalListener(NodeConnector nodeConnector, UpdateType type, Set props) { + for (IInventoryShimInternalListener globalListener : globalInventoryShimInternalListeners) { + globalListener.updateNodeConnector(nodeConnector, type, props); + logger.trace( + "notifyGlobalInventoryShimInternalListener {} type {}", + new Object[] { nodeConnector, type }); + } } private void notifyInventoryShimInternalListener(String container, @@ -400,8 +484,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")); @@ -502,4 +585,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); + } + } + } }