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;
.getLogger(InventoryServiceShim.class);
private IController controller = null;
private final ConcurrentMap<String, IInventoryShimInternalListener> inventoryShimInternalListeners = new ConcurrentHashMap<String, IInventoryShimInternalListener>();
+ private final Set<IInventoryShimInternalListener> globalInventoryShimInternalListeners = new HashSet<IInventoryShimInternalListener>();
private final List<IInventoryShimExternalListener> inventoryShimExternalListeners = new CopyOnWriteArrayList<IInventoryShimExternalListener>();
private final ConcurrentMap<NodeConnector, Set<String>> nodeConnectorContainerMap = new ConcurrentHashMap<NodeConnector, Set<String>>();
private final ConcurrentMap<Node, Set<String>> nodeContainerMap = new ConcurrentHashMap<Node, Set<String>>();
private final ConcurrentMap<NodeConnector, Set<Property>> nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Set<Property>>();
private final ConcurrentMap<Node, Set<Property>> nodeProps = new ConcurrentHashMap<Node, Set<Property>>();
+ private IPluginOutConnectionService connectionOutService;
void setController(IController s) {
this.controller = s;
}
}
+ 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) {
}
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)
}
}
+ 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
this.inventoryShimInternalListeners.clear();
this.nodeConnectorContainerMap.clear();
this.nodeContainerMap.clear();
+ this.globalInventoryShimInternalListeners.clear();
this.controller = null;
}
* Notify all internal and external listeners
*/
private void notifyInventoryShimListener(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
- // notify other containers
- Set<String> containers = (nodeConnectorContainerMap.get(nodeConnector) == null) ? new HashSet<String>()
- : new HashSet<String>(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<String> containers = (nodeConnectorContainerMap.get(nodeConnector) == null) ? new HashSet<String>()
+ : new HashSet<String>(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<Property> props) {
- // Now notify other containers
- 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);
+
+ //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<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
+ 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<Property> 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<Property> props) {
+ for (IInventoryShimInternalListener globalListener : globalInventoryShimInternalListeners) {
+ globalListener.updateNodeConnector(nodeConnector, type, props);
+ logger.trace(
+ "notifyGlobalInventoryShimInternalListener {} type {}",
+ new Object[] { nodeConnector, type });
+ }
}
private void notifyInventoryShimInternalListener(String container,