Keep track of the tables we discover 97/5297/6
authorRobert Varga <rovarga@cisco.com>
Thu, 13 Feb 2014 03:23:54 +0000 (04:23 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 15 Feb 2014 01:44:56 +0000 (01:44 +0000)
NodeStatisticsHandler has always the most uptodate information about
which tables were discovered. Let's cache the table IDs -- we will
need them for sending out follow-up requests.

And now that we do that, we do not have to read the tables from
DataProviderService just to get the keys -- use whatever we cached.

Change-Id: I9550ae3330215277d373ec0b2ea67945ef0e7c5c
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java

index e9cecc521e2c8f24f828019dca70d4652ffdbf45..6a7033d795a63bc60d792d11583c1d8204ac2352 100644 (file)
@@ -7,11 +7,15 @@
  */
 package org.opendaylight.controller.md.statistics.manager;
 
  */
 package org.opendaylight.controller.md.statistics.manager;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import java.util.concurrent.TimeUnit;
 
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
@@ -114,6 +118,7 @@ public class NodeStatisticsHandler implements AutoCloseable {
     private final InstanceIdentifier<Node> targetNodeIdentifier;
     private final StatisticsProvider statisticsProvider;
     private final NodeKey targetNodeKey;
     private final InstanceIdentifier<Node> targetNodeIdentifier;
     private final StatisticsProvider statisticsProvider;
     private final NodeKey targetNodeKey;
+    private Collection<TableKey> knownTables = Collections.emptySet();
     private int unaccountedFlowsCounter = 1;
 
     public NodeStatisticsHandler(StatisticsProvider statisticsProvider, NodeKey nodeKey){
     private int unaccountedFlowsCounter = 1;
 
     public NodeStatisticsHandler(StatisticsProvider statisticsProvider, NodeKey nodeKey){
@@ -171,7 +176,7 @@ public class NodeStatisticsHandler implements AutoCloseable {
         }
     }
 
         }
     }
 
-    private static final class QueueEntry{
+    private static final class QueueEntry {
         private final NodeConnectorId nodeConnectorId;
         private final QueueId queueId;
         public QueueEntry(NodeConnectorId ncId, QueueId queueId){
         private final NodeConnectorId nodeConnectorId;
         private final QueueId queueId;
         public QueueEntry(NodeConnectorId ncId, QueueId queueId){
@@ -226,6 +231,10 @@ public class NodeStatisticsHandler implements AutoCloseable {
         return targetNodeKey;
     }
 
         return targetNodeKey;
     }
 
+    public Collection<TableKey> getKnownTables() {
+        return knownTables;
+    }
+
     public synchronized void updateGroupDescStats(List<GroupDescStats> list){
         final Long expiryTime = getExpiryTime();
         final DataModificationTransaction trans = statisticsProvider.startChange();
     public synchronized void updateGroupDescStats(List<GroupDescStats> list){
         final Long expiryTime = getExpiryTime();
         final DataModificationTransaction trans = statisticsProvider.startChange();
@@ -254,7 +263,6 @@ public class NodeStatisticsHandler implements AutoCloseable {
         trans.commit();
     }
 
         trans.commit();
     }
 
-
     public synchronized void updateGroupStats(List<GroupStats> list) {
         final DataModificationTransaction trans = statisticsProvider.startChange();
 
     public synchronized void updateGroupStats(List<GroupStats> list) {
         final DataModificationTransaction trans = statisticsProvider.startChange();
 
@@ -381,19 +389,14 @@ public class NodeStatisticsHandler implements AutoCloseable {
     public synchronized void updateFlowTableStats(List<FlowTableAndStatisticsMap> list) {
         final DataModificationTransaction trans = statisticsProvider.startChange();
 
     public synchronized void updateFlowTableStats(List<FlowTableAndStatisticsMap> list) {
         final DataModificationTransaction trans = statisticsProvider.startChange();
 
+        final Set<TableKey> knownTables = new HashSet<>(list.size());
         for (FlowTableAndStatisticsMap ftStats : list) {
 
             InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNodeKey)
                     .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
 
             FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
         for (FlowTableAndStatisticsMap ftStats : list) {
 
             InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNodeKey)
                     .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
 
             FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
-
-            FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
-            statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
-            statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
-            statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
-
-            final FlowTableStatistics stats = statisticsBuilder.build();
+            final FlowTableStatistics stats = new FlowTableStatisticsBuilder(ftStats).build();
             statisticsDataBuilder.setFlowTableStatistics(stats);
 
             logger.debug("Augment flow table statistics: {} for table {} on Node {}",
             statisticsDataBuilder.setFlowTableStatistics(stats);
 
             logger.debug("Augment flow table statistics: {} for table {} on Node {}",
@@ -404,9 +407,10 @@ public class NodeStatisticsHandler implements AutoCloseable {
             tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
             trans.putOperationalData(tableRef, tableBuilder.build());
 
             tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
             trans.putOperationalData(tableRef, tableBuilder.build());
 
-            // FIXME: should we be tracking this data?
+            knownTables.add(tableBuilder.getKey());
         }
 
         }
 
+        this.knownTables = Collections.unmodifiableCollection(knownTables);
         trans.commit();
     }
 
         trans.commit();
     }
 
index b7fb4e9473f740a842d190dec7f916bd4eaa7c33..ce2a0b3eeb40bdc4f0be621730e98b472a3988e0 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.md.statistics.manager;
 
 import java.util.Collection;
 package org.opendaylight.controller.md.statistics.manager;
 
 import java.util.Collection;
-import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
@@ -25,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
@@ -236,26 +236,29 @@ public class StatisticsProvider implements AutoCloseable {
 
     private void statsRequestSender() {
         for (NodeStatisticsHandler h : handlers.values()) {
 
     private void statsRequestSender() {
         for (NodeStatisticsHandler h : handlers.values()) {
-            sendStatisticsRequestsToNode(h.getTargetNodeKey());
+            sendStatisticsRequestsToNode(h);
         }
     }
 
         }
     }
 
-    private void sendStatisticsRequestsToNode(NodeKey targetNode){
+    private void sendStatisticsRequestsToNode(NodeStatisticsHandler h) {
+        NodeKey targetNode = h.getTargetNodeKey();
+        spLogger.debug("Send requests for statistics collection to node : {}", targetNode.getId());
 
 
-        spLogger.debug("Send requests for statistics collection to node : {})",targetNode.getId());
-
-        InstanceIdentifier<Node> targetInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class,targetNode).toInstance();
+        InstanceIdentifier<Node> targetInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNode).build();
 
         NodeRef targetNodeRef = new NodeRef(targetInstanceId);
 
         try{
 
         NodeRef targetNodeRef = new NodeRef(targetInstanceId);
 
         try{
-            if(flowStatsService != null){
-                sendAggregateFlowsStatsFromAllTablesRequest(targetNode);
-                sendAllFlowsStatsFromAllTablesRequest(targetNodeRef);
-            }
             if(flowTableStatsService != null){
                 sendAllFlowTablesStatisticsRequest(targetNodeRef);
             }
             if(flowTableStatsService != null){
                 sendAllFlowTablesStatisticsRequest(targetNodeRef);
             }
+            if(flowStatsService != null){
+                // FIXME: it does not make sense to trigger this before sendAllFlowTablesStatisticsRequest()
+                //        comes back -- we do not have any tables anyway.
+                sendAggregateFlowsStatsFromAllTablesRequest(h);
+
+                sendAllFlowsStatsFromAllTablesRequest(targetNodeRef);
+            }
             if(portStatsService != null){
                 sendAllNodeConnectorsStatisticsRequest(targetNodeRef);
             }
             if(portStatsService != null){
                 sendAllNodeConnectorsStatisticsRequest(targetNodeRef);
             }
@@ -268,7 +271,7 @@ public class StatisticsProvider implements AutoCloseable {
                 sendMeterConfigStatisticsRequest(targetNodeRef);
             }
             if(queueStatsService != null){
                 sendMeterConfigStatisticsRequest(targetNodeRef);
             }
             if(queueStatsService != null){
-                sendAllQueueStatsFromAllNodeConnector (targetNodeRef);
+                sendAllQueueStatsFromAllNodeConnector(targetNodeRef);
             }
         }catch(Exception e){
             spLogger.error("Exception occured while sending statistics requests : {}", e);
             }
         }catch(Exception e){
             spLogger.error("Exception occured while sending statistics requests : {}", e);
@@ -319,21 +322,12 @@ public class StatisticsProvider implements AutoCloseable {
 
     }
 
 
     }
 
-    private void sendAggregateFlowsStatsFromAllTablesRequest(final NodeKey nodeKey) throws InterruptedException, ExecutionException{
-        FlowCapableNode node = (FlowCapableNode)dps.readOperationalData(
-                InstanceIdentifier.builder(Nodes.class).child(Node.class,nodeKey).augmentation(FlowCapableNode.class).build());
-        if (node != null) {
-            final List<Table> tables = node.getTable();
-            if (tables != null) {
-                spLogger.debug("Node {} supports {} table(s)", nodeKey, tables.size());
-                for(Table table : tables) {
-                    sendAggregateFlowsStatsFromTableRequest(nodeKey, table.getId());
-                }
-            } else {
-                spLogger.debug("Node {} has no associated tables", nodeKey);
-            }
-        } else {
-            spLogger.debug("Node {} not found", nodeKey);
+    private void sendAggregateFlowsStatsFromAllTablesRequest(final NodeStatisticsHandler h) throws InterruptedException, ExecutionException{
+        final Collection<TableKey> tables = h.getKnownTables();
+        spLogger.debug("Node {} supports {} table(s)", h, tables.size());
+
+        for (TableKey key : h.getKnownTables()) {
+            sendAggregateFlowsStatsFromTableRequest(h.getTargetNodeKey(), key.getId().shortValue());
         }
     }
 
         }
     }
 
@@ -502,7 +496,7 @@ public class StatisticsProvider implements AutoCloseable {
             spLogger.debug("Started node handler for {}", key.getId());
 
             // FIXME: this should be in the NodeStatisticsHandler itself
             spLogger.debug("Started node handler for {}", key.getId());
 
             // FIXME: this should be in the NodeStatisticsHandler itself
-            sendStatisticsRequestsToNode(key);
+            sendStatisticsRequestsToNode(h);
         }
     }
 
         }
     }