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%2FInventoryService.java;h=7a2ace5bae6008e0262b06755d1e70bec668219f;hb=refs%2Fchanges%2F17%2F417%2F1;hp=3a3eaad93ec5c8844e148dcdbfcdeeaa75bb6a7e;hpb=e326757873804be369d20efd0b54467871094c06;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java index 3a3eaad93e..7a2ace5bae 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java @@ -19,15 +19,14 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.apache.felix.dm.Component; +import org.opendaylight.controller.protocol_plugin.openflow.IInventoryProvider; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; 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.ConstructionException; -import org.opendaylight.controller.sal.core.Description; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Node.NodeIDType; import org.opendaylight.controller.sal.core.NodeConnector; @@ -38,7 +37,6 @@ import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.openflow.protocol.statistics.OFDescriptionStatistics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,11 +45,11 @@ import org.slf4j.LoggerFactory; * container of the network. Each instance gets container specific inventory * events from InventoryServiceShim. It interacts with SAL to pass inventory * data to the upper application. - * - * + * + * */ public class InventoryService implements IInventoryShimInternalListener, - IPluginInInventoryService, IStatisticsListener { + IPluginInInventoryService, IInventoryProvider { protected static final Logger logger = LoggerFactory .getLogger(InventoryService.class); private Set pluginOutInventoryServices = Collections @@ -74,7 +72,7 @@ public class InventoryService implements IInventoryShimInternalListener, /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ @SuppressWarnings("rawtypes") void init(Component c) { @@ -95,7 +93,7 @@ public class InventoryService implements IInventoryShimInternalListener, * Function called by the dependency manager when at least one dependency * become unsatisfied or when the component is shutting down because for * example bundle is being stopped. - * + * */ void destroy() { logger.trace("DESTROY called!"); @@ -104,7 +102,7 @@ public class InventoryService implements IInventoryShimInternalListener, /** * Function called by dependency manager after "init ()" is called and after * the services provided by the class are registered in the service registry - * + * */ void start() { logger.trace("START called!"); @@ -114,7 +112,7 @@ public class InventoryService implements IInventoryShimInternalListener, * Function called by the dependency manager before the services exported by * the component are unregistered, this will be followed by a "destroy ()" * calls - * + * */ void stop() { logger.trace("STOP called!"); @@ -142,7 +140,7 @@ public class InventoryService implements IInventoryShimInternalListener, try { node = new Node(NodeIDType.OPENFLOW, id); } catch (ConstructionException e) { - logger.error("",e); + logger.error("", e); } return node; @@ -197,8 +195,9 @@ public class InventoryService implements IInventoryShimInternalListener, @Override public ConcurrentMap> getNodeConnectorProps( Boolean refresh) { - if (nodeConnectorProps == null) + if (nodeConnectorProps == null) { return null; + } if (isDefaultContainer && refresh) { Map switches = controller.getSwitches(); @@ -230,9 +229,9 @@ public class InventoryService implements IInventoryShimInternalListener, switch (type) { case ADDED: case CHANGED: - if (propMap == null) + if (propMap == null) { propMap = new HashMap(); - + } if (props != null) { for (Property prop : props) { propMap.put(prop.getName(), prop); @@ -256,9 +255,10 @@ public class InventoryService implements IInventoryShimInternalListener, } private void addNode(Node node, Set props) { - logger.trace("{} added", node); - if (nodeProps == null) + logger.trace("{} added, props: {}", node, props); + if (nodeProps == null) { return; + } // update local cache Map propMap = new HashMap(); @@ -301,30 +301,30 @@ public class InventoryService implements IInventoryShimInternalListener, } } - private void updateSwitchProperty(Long switchId, Set propSet) { - // update local cache - Node node = OFSwitchToNode(controller.getSwitch(switchId)); - Map propMap = nodeProps.get(node); - if (propMap == null) { - propMap = new HashMap(); + private void updateNode(Node node, Set properties) { + logger.trace("{} updated, props: {}", node, properties); + if (nodeProps == null || !nodeProps.containsKey(node) || + properties == null || properties.isEmpty()) { + return; } - boolean change = false; - for (Property prop : propSet) { - String propertyName = prop.getName(); - Property currentProp = propMap.get(propertyName); - if (!prop.equals(currentProp)) { - change = true; - propMap.put(propertyName, prop); + // Update local cache with new properties + Set newProperties = new HashSet(properties.size()); + Map propertyMap = nodeProps.get(node); + for (Property property : properties) { + String name = property.getName(); + Property currentProperty = propertyMap.get(name); + if (!property.equals(currentProperty)) { + propertyMap.put(name, property); + newProperties.add(property); } } - nodeProps.put(node, propMap); - // Update sal if any of the properties has changed - if (change) { + // Update SAL if we got new properties + if (!newProperties.isEmpty()) { synchronized (pluginOutInventoryServices) { for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.CHANGED, propSet); + service.updateNode(node, UpdateType.CHANGED, newProperties); } } } @@ -339,19 +339,12 @@ public class InventoryService implements IInventoryShimInternalListener, case REMOVED: removeNode(node); break; + case CHANGED: + updateNode(node, props); + break; default: break; } } - @Override - public void descriptionRefreshed(Long switchId, - OFDescriptionStatistics descriptionStats) { - - Set propSet = new HashSet(1); - Description desc = new Description( - descriptionStats.getDatapathDescription()); - propSet.add(desc); - this.updateSwitchProperty(switchId, propSet); - } }