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;
*
*/
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;
}
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);
}
void unsetInventoryShimExternalListener(IInventoryShimExternalListener s) {
+ logger.trace("Unset inventoryShimExternalListener {}", s);
if ((this.inventoryShimExternalListeners != null)
&& this.inventoryShimExternalListeners.contains(s)) {
this.inventoryShimExternalListeners.remove(s);
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
* Notify all internal and external listeners
*/
private void notifyInventoryShimListener(NodeConnector nodeConnector, UpdateType type, Set<Property> 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<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);
- }
+ 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);
- // 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) {
- 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<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);
+ notifyGlobalInventoryShimInternalListener(node, type, props);
+ isNodeLocal = connectionOutService.isLocal(node);
}
- // Notify external listener
- notifyInventoryShimExternalListener(node, type, props);
+ 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);
+ }
}
private void notifyGlobalInventoryShimInternalListener(Node node, UpdateType type, Set<Property> props) {
Set<Property> props = new HashSet<Property>();
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"));
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);
public void tableStatisticsRefreshed(Long switchId, List<OFStatistics> tables) {
// Nothing to do
}
+
+ @Override
+ public void containerCreate(String containerName) {
+ // Nothing to do
+ }
+
+ @Override
+ public void containerDestroy(String containerName) {
+ Set<NodeConnector> removeNodeConnectorSet = new HashSet<NodeConnector>();
+ Set<Node> removeNodeSet = new HashSet<Node>();
+ for (Map.Entry<NodeConnector, Set<String>> entry : nodeConnectorContainerMap.entrySet()) {
+ Set<String> ncContainers = entry.getValue();
+ if (ncContainers.contains(containerName)) {
+ NodeConnector nodeConnector = entry.getKey();
+ removeNodeConnectorSet.add(nodeConnector);
+ }
+ }
+ for (Map.Entry<Node, Set<String>> entry : nodeContainerMap.entrySet()) {
+ Set<String> nodeContainers = entry.getValue();
+ if (nodeContainers.contains(containerName)) {
+ Node node = entry.getKey();
+ removeNodeSet.add(node);
+ }
+ }
+ for (NodeConnector nodeConnector : removeNodeConnectorSet) {
+ Set<String> ncContainers = nodeConnectorContainerMap.get(nodeConnector);
+ ncContainers.remove(containerName);
+ if (ncContainers.isEmpty()) {
+ nodeConnectorContainerMap.remove(nodeConnector);
+ }
+ }
+ for (Node node : removeNodeSet) {
+ Set<String> nodeContainers = nodeContainerMap.get(node);
+ nodeContainers.remove(containerName);
+ if (nodeContainers.isEmpty()) {
+ nodeContainerMap.remove(node);
+ }
+ }
+ }
}