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%2FInventoryServiceShim.java;h=c472747a8e16eac2b421e17931f51a9d09f1b84f;hb=378663c85ee1cc4cec906edd8f83ed00d0812bf9;hp=fb295a24c068fc54dc4ca450f5b70253e87d0dab;hpb=11837100975c9ad113e12668c09ecd78f9433f73;p=controller.git 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 fb295a24c0..c472747a8e 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 @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -20,6 +19,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; 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.IMessageListener; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; @@ -29,6 +29,7 @@ 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.ContainerFlow; +import org.opendaylight.controller.sal.core.Description; import org.opendaylight.controller.sal.core.IContainerListener; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Node.NodeIDType; @@ -42,6 +43,7 @@ import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFPortStatus; import org.openflow.protocol.OFPortStatus.OFPortReason; import org.openflow.protocol.OFType; +import org.openflow.protocol.statistics.OFDescriptionStatistics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,11 +51,11 @@ import org.slf4j.LoggerFactory; * The class describes a shim layer that bridges inventory events from Openflow * core to various listeners. The notifications are filtered based on container * configurations. - * - * + * + * */ public class InventoryServiceShim implements IContainerListener, - IMessageListener, ISwitchStateListener { + IMessageListener, ISwitchStateListener, IStatisticsListener { protected static final Logger logger = LoggerFactory .getLogger(InventoryServiceShim.class); private IController controller = null; @@ -74,42 +76,42 @@ public class InventoryServiceShim implements IContainerListener, void setInventoryShimInternalListener(Map props, IInventoryShimInternalListener s) { if (props == null) { - logger.error("Didn't receive the service properties"); + logger.error("setInventoryShimInternalListener property is null"); return; } String containerName = (String) props.get("containerName"); if (containerName == null) { - logger.error("containerName not supplied"); + logger.error("setInventoryShimInternalListener containerName not supplied"); return; } if ((this.inventoryShimInternalListeners != null) && !this.inventoryShimInternalListeners.containsValue(s)) { this.inventoryShimInternalListeners.put(containerName, s); - logger.trace("Added inventoryShimInternalListener for container:" - + containerName); + logger.trace( + "Added inventoryShimInternalListener for container {}", + containerName); } } void unsetInventoryShimInternalListener(Map props, IInventoryShimInternalListener s) { if (props == null) { - logger.error("Didn't receive the service properties"); + logger.error("unsetInventoryShimInternalListener property is null"); return; } String containerName = (String) props.get("containerName"); if (containerName == null) { - logger.error("containerName not supplied"); + logger.error("unsetInventoryShimInternalListener containerName not supplied"); return; } if ((this.inventoryShimInternalListeners != null) - && this.inventoryShimInternalListeners - .get(containerName) != null - && this.inventoryShimInternalListeners - .get(containerName).equals(s)) { + && this.inventoryShimInternalListeners.get(containerName) != null + && this.inventoryShimInternalListeners.get(containerName) + .equals(s)) { this.inventoryShimInternalListeners.remove(containerName); - logger - .trace("Removed inventoryShimInternalListener for container: " - + containerName); + logger.trace( + "Removed inventoryShimInternalListener for container {}", + containerName); } } @@ -131,7 +133,7 @@ public class InventoryServiceShim implements IContainerListener, /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ void init() { this.controller.addMessageListener(OFType.PORT_STATUS, this); @@ -139,8 +141,7 @@ public class InventoryServiceShim implements IContainerListener, } /** - * Function called after registering the - * service in OSGi service registry. + * Function called after registering the service in OSGi service registry. */ void started() { /* Start with existing switches */ @@ -148,10 +149,10 @@ public class InventoryServiceShim implements IContainerListener, } /** - * 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. - * + * 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() { this.controller.removeMessageListener(OFType.PACKET_IN, this); @@ -189,6 +190,8 @@ public class InventoryServiceShim implements IContainerListener, type = UpdateType.CHANGED; } + logger.trace("handlePortStatusMessage {} type {}", nodeConnector, type); + if (type != null) { // get node connector properties Set props = InventoryServiceHelper.OFPortToProps(m @@ -206,8 +209,8 @@ public class InventoryServiceShim implements IContainerListener, Map> ncProps = InventoryServiceHelper .OFSwitchToProps(sw); for (Map.Entry> entry : ncProps.entrySet()) { - notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry - .getValue()); + notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, + entry.getValue()); } // Add this node @@ -300,17 +303,19 @@ public class InventoryServiceShim implements IContainerListener, if (inventoryShimInternalListener != null) { inventoryShimInternalListener.updateNodeConnector(nodeConnector, type, props); - logger.trace(type + " " + nodeConnector + " on container " - + container); + logger.trace( + "notifyInventoryShimInternalListener {} type {} for container {}", + nodeConnector, type, container); } } /* - * Notify all internal and external listeners + * Notify all internal and external listeners */ private void notifyInventoryShimListener(NodeConnector nodeConnector, UpdateType type, Set props) { - // Always notify default InventoryService. Store properties in default one. + // Always notify default InventoryService. Store properties in default + // one. notifyInventoryShimInternalListener(GlobalConstants.DEFAULT.toString(), nodeConnector, type, props); @@ -329,7 +334,7 @@ public class InventoryServiceShim implements IContainerListener, } /* - * Notify all internal and external listeners + * Notify all internal and external listeners */ private void notifyInventoryShimListener(Node node, UpdateType type, Set props) { @@ -349,6 +354,14 @@ public class InventoryServiceShim implements IContainerListener, inventoryShimInternalListener.updateNode(node, type, null); } break; + case CHANGED: + // Notify only the default Inventory Service + inventoryShimDefaultListener = inventoryShimInternalListeners + .get(GlobalConstants.DEFAULT.toString()); + if (inventoryShimDefaultListener != null) { + inventoryShimDefaultListener.updateNode(node, type, props); + } + break; default: break; } @@ -380,22 +393,22 @@ public class InventoryServiceShim implements IContainerListener, byte tables = sw.getTables(); Tables t = new Tables(tables); if (t != null) { - props.add(t); + props.add(t); } int cap = sw.getCapabilities(); Capabilities c = new Capabilities(cap); if (c != null) { - props.add(c); + props.add(c); } int act = sw.getActions(); Actions a = new Actions(act); if (a != null) { - props.add(a); + props.add(a); } int buffers = sw.getBuffers(); Buffers b = new Buffers(buffers); if (b != null) { - props.add(b); + props.add(b); } // Notify all internal and external listeners notifyInventoryShimListener(node, type, props); @@ -423,4 +436,26 @@ public class InventoryServiceShim implements IContainerListener, switchAdded(sw); } } + + @Override + public void descriptionRefreshed(Long switchId, + OFDescriptionStatistics descriptionStats) { + Node node; + try { + node = new Node(NodeIDType.OPENFLOW, switchId); + } catch (ConstructionException e) { + logger.error("{}", e.getMessage()); + return; + } + + Set properties = new HashSet(1); + Description desc = new Description( + descriptionStats.getDatapathDescription()); + properties.add(desc); + + // Notify all internal and external listeners + notifyInventoryShimListener(node, UpdateType.CHANGED, properties); + } + + }