package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
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;
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);
@Override
public void switchAdded(ISwitch sw) {
if (sw == null) {
+ logger.debug("Ignore null switch addition");
+ 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
- .OFSwitchToProps(sw);
- for (Map.Entry<NodeConnector, Set<Property>> entry : ncProps.entrySet()) {
- Set<Property> props = new HashSet<Property>();
- Set<Property> prop = entry.getValue();
- if (prop != null) {
- props.addAll(prop);
+ // Add all the nodeConnectors of this switch if any
+ Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper.OFSwitchToProps(sw);
+ if (!ncProps.isEmpty()) {
+ for (Map.Entry<NodeConnector, Set<Property>> entry : ncProps.entrySet()) {
+ Set<Property> props = new HashSet<Property>();
+ Set<Property> prop = entry.getValue();
+ if (prop != null) {
+ props.addAll(prop);
+ }
+ nodeConnectorProps.put(entry.getKey(), props);
+ notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry.getValue());
}
- nodeConnectorProps.put(entry.getKey(), props);
- notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED,
- entry.getValue());
+ } else {
+ /*
+ * If no node connector is present, publish the node addition itself
+ * in order to let Connection Manager properly set the node locality
+ */
+ this.notifyInventoryShimListener(node, UpdateType.ADDED, Collections.<Property>emptySet());
}
// 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
}
}
- 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);
}
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 });
}
}
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);
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);
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 });
}
}
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(c);
}
int act = sw.getActions();
- Actions a = new Actions(act);
+ SupportedFlowActions a = new SupportedFlowActions(FlowConverter.getFlowActions(act));
if (a != null) {
props.add(a);
}
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);
+ }
+ }
+ }
}