Move stats caching to FM StatisticsManager
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / InventoryServiceShim.java
index f7210a333bd870d87216128b73cffb8a8402842f..a6d5a15313719829f92d8be37f2ec3766d7dea1e 100644 (file)
@@ -19,7 +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.IOFStatisticsListener;
 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;
@@ -40,11 +40,13 @@ import org.opendaylight.controller.sal.core.Tables;
 import org.opendaylight.controller.sal.core.TimeStamp;
 import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
+import org.opendaylight.controller.sal.utils.NodeCreator;
 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.openflow.protocol.statistics.OFStatistics;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,7 +58,7 @@ import org.slf4j.LoggerFactory;
  *
  */
 public class InventoryServiceShim implements IContainerListener,
-        IMessageListener, ISwitchStateListener, IStatisticsListener {
+        IMessageListener, ISwitchStateListener, IOFStatisticsListener {
     protected static final Logger logger = LoggerFactory
             .getLogger(InventoryServiceShim.class);
     private IController controller = null;
@@ -178,7 +180,7 @@ public class InventoryServiceShim implements IContainerListener,
 
     protected void handlePortStatusMessage(ISwitch sw, OFPortStatus m)
             throws ConstructionException {
-        Node node = new Node(NodeIDType.OPENFLOW, sw.getId());
+        Node node = NodeCreator.createOFNode(sw.getId());
         NodeConnector nodeConnector = PortConverter.toNodeConnector(m.getDesc()
                 .getPortNumber(), node);
         UpdateType type = null;
@@ -236,6 +238,8 @@ public class InventoryServiceShim implements IContainerListener,
     @Override
     public void tagUpdated(String containerName, Node n, short oldTag,
             short newTag, UpdateType t) {
+        logger.debug("tagUpdated: {} type {} for container {}", new Object[] {
+                n, t, containerName });
     }
 
     @Override
@@ -246,6 +250,8 @@ public class InventoryServiceShim implements IContainerListener,
     @Override
     public void nodeConnectorUpdated(String containerName, NodeConnector p,
             UpdateType t) {
+        logger.debug("nodeConnectorUpdated: {} type {} for container {}",
+                new Object[] { p, t, containerName });
         if (this.containerMap == null) {
             logger.error("containerMap is NULL");
             return;
@@ -283,6 +289,7 @@ public class InventoryServiceShim implements IContainerListener,
 
         // notify InventoryService
         notifyInventoryShimInternalListener(containerName, p, t, null);
+        notifyInventoryShimInternalListener(containerName, p.getNode(), t, null);
     }
 
     private void notifyInventoryShimExternalListener(Node node,
@@ -308,7 +315,7 @@ public class InventoryServiceShim implements IContainerListener,
                     type, props);
             logger.trace(
                     "notifyInventoryShimInternalListener {} type {} for container {}",
-                    nodeConnector, type, container);
+                    new Object[] { nodeConnector, type, container });
         }
     }
 
@@ -373,15 +380,20 @@ public class InventoryServiceShim implements IContainerListener,
         notifyInventoryShimExternalListener(node, type, props);
     }
 
-    private void addNode(ISwitch sw) {
-        Node node;
-        try {
-            node = new Node(NodeIDType.OPENFLOW, sw.getId());
-        } catch (ConstructionException e) {
-            logger.error("{}", e.getMessage());
-            return;
+    private void notifyInventoryShimInternalListener(String container,
+            Node node, UpdateType type, Set<Property> props) {
+        IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners
+                .get(container);
+        if (inventoryShimInternalListener != null) {
+            inventoryShimInternalListener.updateNode(node, type, props);
+            logger.trace(
+                    "notifyInventoryShimInternalListener {} type {} for container {}",
+                    new Object[] { node, type, container });
         }
+    }
 
+    private void addNode(ISwitch sw) {
+        Node node = NodeCreator.createOFNode(sw.getId());
         UpdateType type = UpdateType.ADDED;
 
         Set<Property> props = new HashSet<Property>();
@@ -443,19 +455,11 @@ public class InventoryServiceShim implements IContainerListener,
     }
 
     @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;
-        }
-
+    public void descriptionStatisticsRefreshed(Long switchId, List<OFStatistics> descriptionStats) {
+        Node node = NodeCreator.createOFNode(switchId);
         Set<Property> properties = new HashSet<Property>(1);
-        Description desc = new Description(
-                descriptionStats.getDatapathDescription());
+        OFDescriptionStatistics ofDesc = (OFDescriptionStatistics) descriptionStats.get(0);
+        Description desc = new Description(ofDesc.getDatapathDescription());
         properties.add(desc);
 
         // Notify all internal and external listeners
@@ -472,4 +476,19 @@ public class InventoryServiceShim implements IContainerListener,
 
         return mac;
     }
+
+    @Override
+    public void flowStatisticsRefreshed(Long switchId, List<OFStatistics> flows) {
+        // Nothing to do
+    }
+
+    @Override
+    public void portStatisticsRefreshed(Long switchId, List<OFStatistics> ports) {
+        // Nothing to do
+    }
+
+    @Override
+    public void tableStatisticsRefreshed(Long switchId, List<OFStatistics> tables) {
+        // Nothing to do
+    }
 }