From e297d01f3b85ca6753e607bba5b3e9b441bd6307 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Mon, 9 Dec 2013 13:19:50 -0800 Subject: [PATCH] Controller ignores switch, if no ports are present - At switch connection, InventoryServiceShim mistakenly skips to inform the global listeners if no ports are configured on the switch. This is not visible with software switches because they always advertise they have the OFLocal port active. Being Connection Service a listener of global inventory service, it will not get to know about the switch presence, and in subsequent queries from InventoryServiceShim it will reply the switch is not locally connected to this controller, causing Inventory Shim to not inform its upper layer listeners about the switch. Therefore no other controller service will get to know the switch is conencted. Change-Id: I29f658cc2a84ab7aab2c19ae9fe4d5a33c0afe0c Signed-off-by: Alessandro Boch --- .../internal/InventoryServiceShim.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) 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 f4843cf828..2b26ecb749 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 @@ -9,6 +9,7 @@ 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; @@ -238,6 +239,7 @@ public class InventoryServiceShim implements IContainerListener, @Override public void switchAdded(ISwitch sw) { if (sw == null) { + logger.debug("Ignore null switch addition"); return; } Node node = NodeCreator.createOFNode(sw.getId()); @@ -246,17 +248,24 @@ public class InventoryServiceShim implements IContainerListener, return; } - // Add all the nodeConnectors of this switch - Map> ncProps = InventoryServiceHelper - .OFSwitchToProps(sw); - for (Map.Entry> entry : ncProps.entrySet()) { - Set props = new HashSet(); - Set prop = entry.getValue(); - if (prop != null) { - props.addAll(prop); + // Add all the nodeConnectors of this switch if any + Map> ncProps = InventoryServiceHelper.OFSwitchToProps(sw); + if (!ncProps.isEmpty()) { + for (Map.Entry> entry : ncProps.entrySet()) { + Set props = new HashSet(); + Set 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.emptySet()); } // Add this node -- 2.36.6