statistics context implements dedicated services 61/17661/3
authorMartin Bobak <mbobak@cisco.com>
Thu, 2 Apr 2015 16:17:14 +0000 (18:17 +0200)
committerMartin Bobak <mbobak@cisco.com>
Thu, 2 Apr 2015 18:53:52 +0000 (20:53 +0200)
Change-Id: I4e018b13d1240fc78179ae606782bdc90994ed5b
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/RequestContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/FlowStatisticsService.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/FlowTableStatisticsService.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/GroupStatisticsService.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/MeterStatisticsService.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/PortStatisticsService.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/QueueStatisticsService.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java

index 50775136ca61b4ff864c511f779266c08d2aa66a..e9468807208bec86cf6a739301c392b535841c84 100644 (file)
@@ -8,30 +8,31 @@
 package org.opendaylight.openflowplugin.api.openflow.device;
 
 
-import org.opendaylight.yangtools.yang.binding.DataObject;
-
 /**
  * Request context handles all requests on device. Number of requests is limited by request quota. When this quota is
  * exceeded all rpc's will end up with exception.
- * <p>
+ * <p/>
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
  */
 public interface RequestContext<T> extends RequestFutureContext<T>, AutoCloseable {
 
     /**
      * Returns xid generated for this request.
+     *
      * @return
      */
     Xid getXid();
 
     /**
      * Sets xid generated for this request.
+     *
      * @return
      */
     void setXid(Xid xid);
 
     /**
      * Returns request timeout value.
+     *
      * @return
      */
     long getWaitTimeout();
@@ -39,6 +40,7 @@ public interface RequestContext<T> extends RequestFutureContext<T>, AutoCloseabl
 
     /**
      * Sets request timeout value.
+     *
      * @return
      */
     void setWaitTimeout(long waitTimeout);
index 496ea9ac307a9eb491c6093385aa12012d89e811..be3e1e7b3e2a9361b658412549396dd063f5aee0 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.openflowplugin.impl.statistics;
 
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
@@ -37,7 +39,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.O
 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.FlowStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.FlowTableStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.GroupStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.MeterStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.PortStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.QueueStatisticsService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.Arrays;
 
 /**
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 1.4.2015.
@@ -46,32 +55,25 @@ public class StatisticsContextImpl implements StatisticsContext {
 
     private final List<RequestContext> requestContexts = new ArrayList();
     private final DeviceContext deviceContext;
-    private final RequestContext requestContext;
 
 
-    private final OpendaylightFlowStatisticsService flowStatisticsService;
-    private final OpendaylightFlowTableStatisticsService flowTableStatisticsService;
-    private final OpendaylightGroupStatisticsService groupStatisticsService;
-    private final OpendaylightMeterStatisticsService meterStatisticsService;
-    private final OpendaylightPortStatisticsService portStatisticsService;
-    private final OpendaylightQueueStatisticsService queueStatisticsService;
+    private final FlowStatisticsService flowStatisticsService;
+    private final FlowTableStatisticsService flowTableStatisticsService;
+    private final GroupStatisticsService groupStatisticsService;
+    private final MeterStatisticsService meterStatisticsService;
+    private final PortStatisticsService portStatisticsService;
+    private final QueueStatisticsService queueStatisticsService;
 
 
-    /**
-     * FIXME : Why we need RequestContext
-     * @param deviceContext
-     * @param requestContext
-     */
-    public StatisticsContextImpl(final DeviceContext deviceContext, final RequestContext requestContext) {
+    public StatisticsContextImpl(DeviceContext deviceContext) {
         this.deviceContext = deviceContext;
-        this.requestContext = requestContext;
 
-        flowStatisticsService = new OpendaylightFlowStatisticsServiceImpl(this, deviceContext);
-        flowTableStatisticsService = new OpendaylightFlowTableStatisticsServiceImpl(this, deviceContext);
-        groupStatisticsService = new OpendaylightGroupStatisticsServiceImpl(this, deviceContext);
-        meterStatisticsService = new OpendaylightMeterStatisticsServiceImpl(this, deviceContext);
-        portStatisticsService = new OpendaylightPortStatisticsServiceImpl(this, deviceContext);
-        queueStatisticsService = new OpendaylightQueueStatisticsServiceImpl(this, deviceContext);
+        flowStatisticsService = new FlowStatisticsService(this, deviceContext);
+        flowTableStatisticsService = new FlowTableStatisticsService(this, deviceContext);
+        groupStatisticsService = new GroupStatisticsService(this, deviceContext);
+        meterStatisticsService = new MeterStatisticsService(this, deviceContext);
+        portStatisticsService = new PortStatisticsService(this, deviceContext);
+        queueStatisticsService = new QueueStatisticsService(this, deviceContext);
 
     }
 
@@ -81,19 +83,32 @@ public class StatisticsContextImpl implements StatisticsContext {
         final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder builder =
                 new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
         builder.setNode(nodeRef);
-        final Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> flowStatisticsResult = flowStatisticsService.getAllFlowsStatisticsFromAllFlowTables(builder.build());
         //TODO : process data from result
     }
 
     @Override
     public ListenableFuture<Void> gatherDynamicData() {
-        final ListenableFuture<Boolean> flowStatistics = StatisticsGatheringUtils.gatherFlowStatistics(flowStatisticsService, deviceContext);
-        final ListenableFuture<Boolean> tableStatistics = StatisticsGatheringUtils.gatherTableStatistics(flowTableStatisticsService, deviceContext);
-        final ListenableFuture<Boolean> groupStatistics = StatisticsGatheringUtils.gatherGroupStatistics(groupStatisticsService, deviceContext);
-        final ListenableFuture<Boolean> meterStatistics = StatisticsGatheringUtils.gatherMeterStatistics(meterStatisticsService, deviceContext);
-        final ListenableFuture<Boolean> portStatistics = StatisticsGatheringUtils.gatherPortStatistics(portStatisticsService, deviceContext);
-        final ListenableFuture<Boolean> queueStatistics = StatisticsGatheringUtils.gatherQueueStatistics(queueStatisticsService, deviceContext);
-        return null;
+        ListenableFuture<Boolean> flowStatistics = StatisticsGatheringUtils.gatherFlowStatistics(flowStatisticsService, deviceContext);
+        ListenableFuture<Boolean> tableStatistics = StatisticsGatheringUtils.gatherTableStatistics(flowTableStatisticsService, deviceContext);
+        ListenableFuture<Boolean> groupStatistics = StatisticsGatheringUtils.gatherGroupStatistics(groupStatisticsService, deviceContext);
+        ListenableFuture<Boolean> meterStatistics = StatisticsGatheringUtils.gatherMeterStatistics(meterStatisticsService, deviceContext);
+        ListenableFuture<Boolean> portStatistics = StatisticsGatheringUtils.gatherPortStatistics(portStatisticsService, deviceContext);
+        ListenableFuture<Boolean> queueStatistics = StatisticsGatheringUtils.gatherQueueStatistics(queueStatisticsService, deviceContext);
+
+        ListenableFuture<List<Boolean>> allFutures = Futures.allAsList(Arrays.asList(flowStatistics, tableStatistics, groupStatistics, meterStatistics, portStatistics, queueStatistics));
+        final SettableFuture<Void> resultingFuture = SettableFuture.create();
+        Futures.addCallback(allFutures, new FutureCallback<List<Boolean>>() {
+            @Override
+            public void onSuccess(final List<Boolean> booleans) {
+                resultingFuture.set(null);
+            }
+
+            @Override
+            public void onFailure(final Throwable throwable) {
+                resultingFuture.setException(throwable);
+            }
+        });
+        return resultingFuture;
     }
 
     @Override
index 8b242010634355638c7b9311dfa54fc84a0503be..22f9563cb730459a4acb234395f94ada24f19fde 100644 (file)
@@ -13,29 +13,19 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.FlowStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.FlowTableStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.GroupStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.MeterStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.PortStatisticsService;
+import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.QueueStatisticsService;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.translator.MultipartReplyTranslator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -47,148 +37,85 @@ import java.util.List;
  */
 public final class StatisticsGatheringUtils {
 
+    private static final FlowStatsResponseConvertor FLOW_STATS_RESPONSE_CONVERTOR = new FlowStatsResponseConvertor();
+    private static final MultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new MultipartReplyTranslator();
+
+
     private StatisticsGatheringUtils() {
         throw new IllegalStateException("This class should not be instantiated.");
     }
 
     private static NodeRef createNodeRef(DeviceContext deviceContext) {
-        final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
+        final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = getInstanceIdentifier(deviceContext);
         return new NodeRef(nodeInstanceIdentifier);
     }
 
-    public static ListenableFuture<Boolean> gatherQueueStatistics(OpendaylightQueueStatisticsService queueStatisticsService, DeviceContext deviceContext) {
-
-        final GetAllQueuesStatisticsFromAllPortsInputBuilder builder =
-                new GetAllQueuesStatisticsFromAllPortsInputBuilder();
+    private static KeyedInstanceIdentifier<Node, NodeKey> getInstanceIdentifier(final DeviceContext deviceContext) {
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
+    }
 
-        builder.setNode(createNodeRef(deviceContext));
+    public static ListenableFuture<Boolean> gatherQueueStatistics(QueueStatisticsService queueStatisticsService, final DeviceContext deviceContext) {
 
-        ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> statisticsDataInFuture =
-                JdkFutureAdapters.
-                        listenInPoolThread(queueStatisticsService.
-                                getAllQueuesStatisticsFromAllPorts(builder.build()));
+        ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
+                JdkFutureAdapters.listenInPoolThread(queueStatisticsService.getAllQueuesStatisticsFromAllPorts());
 
-        return Futures.transform(statisticsDataInFuture, new Function<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>, Boolean>() {
-            @Nullable
-            @Override
-            public Boolean apply(final RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult) {
-                if (rpcResult.isSuccessful()) {
-                    //TODO : implement data read and put them into transaction chain
-                    return Boolean.TRUE;
-                }
-                return Boolean.FALSE;
-            }
-        });
+        return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
     }
 
 
-    public static ListenableFuture<Boolean> gatherPortStatistics(OpendaylightPortStatisticsService portStatisticsService, DeviceContext deviceContext) {
-
-        final GetAllNodeConnectorsStatisticsInputBuilder builder =
-                new GetAllNodeConnectorsStatisticsInputBuilder();
+    public static ListenableFuture<Boolean> gatherPortStatistics(PortStatisticsService portStatisticsService, final DeviceContext deviceContext) {
 
-        builder.setNode(createNodeRef(deviceContext));
+        ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
+                JdkFutureAdapters.listenInPoolThread(portStatisticsService.getAllNodeConnectorsStatistics());
 
-        ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> statisticsDataInFuture =
-                JdkFutureAdapters.
-                        listenInPoolThread(portStatisticsService.
-                                getAllNodeConnectorsStatistics(builder.build()));
-
-        return Futures.transform(statisticsDataInFuture, new Function<RpcResult<GetAllNodeConnectorsStatisticsOutput>, Boolean>() {
-            @Nullable
-            @Override
-            public Boolean apply(final RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult) {
-                if (rpcResult.isSuccessful()) {
-                    //TODO : implement data read and put them into transaction chain
-                    return Boolean.TRUE;
-                }
-                return Boolean.FALSE;
-            }
-        });
+        return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
     }
 
-    public static ListenableFuture<Boolean> gatherMeterStatistics(OpendaylightMeterStatisticsService meterStatisticsService, DeviceContext deviceContext) {
-
-        final GetAllMeterStatisticsInputBuilder builder =
-                new GetAllMeterStatisticsInputBuilder();
+    public static ListenableFuture<Boolean> gatherMeterStatistics(MeterStatisticsService meterStatisticsService, final DeviceContext deviceContext) {
 
-        builder.setNode(createNodeRef(deviceContext));
 
-        ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> statisticsDataInFuture =
+        ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
                 JdkFutureAdapters.
                         listenInPoolThread(meterStatisticsService.
-                                getAllMeterStatistics(builder.build()));
+                                getAllMeterStatistics());
 
-        return Futures.transform(statisticsDataInFuture, new Function<RpcResult<GetAllMeterStatisticsOutput>, Boolean>() {
-            @Nullable
-            @Override
-            public Boolean apply(final RpcResult<GetAllMeterStatisticsOutput> rpcResult) {
-                if (rpcResult.isSuccessful()) {
-                    //TODO : implement data read and put them into transaction chain
-                    return Boolean.TRUE;
-                }
-                return Boolean.FALSE;
-            }
-        });
+        return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
     }
 
 
-    public static ListenableFuture<Boolean> gatherGroupStatistics(OpendaylightGroupStatisticsService groupStatisticsService, DeviceContext deviceContext) {
-        final GetAllGroupStatisticsInputBuilder builder =
-                new GetAllGroupStatisticsInputBuilder();
-        builder.setNode(createNodeRef(deviceContext));
-        ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> allFlowTablesDataInFuture =
+    public static ListenableFuture<Boolean> gatherGroupStatistics(GroupStatisticsService groupStatisticsService, final DeviceContext deviceContext) {
+        ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
                 JdkFutureAdapters.
                         listenInPoolThread(groupStatisticsService.
-                                getAllGroupStatistics(builder.build()));
+                                getAllGroupStatistics());
 
-        return Futures.transform(allFlowTablesDataInFuture, new Function<RpcResult<GetAllGroupStatisticsOutput>, Boolean>() {
-            @Nullable
-            @Override
-            public Boolean apply(final RpcResult<GetAllGroupStatisticsOutput> rpcResult) {
-                if (rpcResult.isSuccessful()) {
-                    //TODO : implement data read and put them into transaction chain
-                    return Boolean.TRUE;
-                }
-                return Boolean.FALSE;
-            }
-        });
+        return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
     }
 
-    public static ListenableFuture<Boolean> gatherFlowStatistics(OpendaylightFlowStatisticsService flowStatisticsService, DeviceContext deviceContext) {
-        final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder builder =
-                new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
-        builder.setNode(createNodeRef(deviceContext));
-        ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> allFlowTablesDataInFuture =
+    public static ListenableFuture<Boolean> gatherFlowStatistics(FlowStatisticsService flowStatisticsService, final DeviceContext deviceContext) {
+        ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
                 JdkFutureAdapters.
                         listenInPoolThread(flowStatisticsService.
-                                getAllFlowsStatisticsFromAllFlowTables(builder.build()));
 
-        return Futures.transform(allFlowTablesDataInFuture, new Function<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>, Boolean>() {
-            @Nullable
-            @Override
-            public Boolean apply(final RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult) {
-                if (rpcResult.isSuccessful()) {
-                    List<FlowAndStatisticsMapList> flowAndStatsList = rpcResult.getResult().getFlowAndStatisticsMapList();
-                    //TODO : implement data read and put them into transaction chain
-                    for (FlowAndStatisticsMapList flowAndStatisticsMap : flowAndStatsList) {
-                    }
-                    return Boolean.TRUE;
-                }
-                return Boolean.FALSE;
-            }
-        });
+                                getAllFlowsStatisticsFromAllFlowTables());
+        return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
+
+    }
+
+    public static ListenableFuture<Boolean> gatherTableStatistics(FlowTableStatisticsService flowTableStatisticsService, final DeviceContext deviceContext) {
+
+        ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
+                JdkFutureAdapters.listenInPoolThread(
+                        flowTableStatisticsService.getFlowTablesStatistics());
+
+        return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
     }
 
-    public static ListenableFuture<Boolean> gatherTableStatistics(OpendaylightFlowTableStatisticsService flowTableStatisticsService, DeviceContext deviceContext) {
-        GetFlowTablesStatisticsInputBuilder getFlowTablesStatisticsInputBuilder = new GetFlowTablesStatisticsInputBuilder();
-        getFlowTablesStatisticsInputBuilder.setNode(createNodeRef(deviceContext));
-        ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> flowTableStaticsDataInFuture = JdkFutureAdapters.listenInPoolThread(flowTableStatisticsService.getFlowTablesStatistics(getFlowTablesStatisticsInputBuilder.build()));
-        return Futures.transform(flowTableStaticsDataInFuture, new Function<RpcResult<GetFlowTablesStatisticsOutput>, Boolean>() {
+    private static ListenableFuture<Boolean> transformAndStoreStatisticsData(final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture, final DeviceContext deviceContext) {
+        return Futures.transform(statisticsDataInFuture, new Function<RpcResult<List<MultipartReply>>, Boolean>() {
             @Nullable
             @Override
-            public Boolean apply(
-                    final RpcResult<GetFlowTablesStatisticsOutput> rpcResult) {
+            public Boolean apply(final RpcResult<List<MultipartReply>> rpcResult) {
                 if (rpcResult.isSuccessful()) {
                     //TODO : implement data read and put them into transaction chain
                     return Boolean.TRUE;
index 427f1cf5f243e2f225c0526d1efa832661cf1beb..5cea9cc3205d97c1727ab33d857420a719401037 100644 (file)
@@ -32,7 +32,7 @@ public class StatisticsManagerImpl implements StatisticsManager {
 
     @Override
     public void deviceConnected(final DeviceContext deviceContext) {
-        final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceContext, null);
+        final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceContext);
         final ListenableFuture<Void> weHaveDynamicData = statisticsContext.gatherDynamicData();
         Futures.addCallback(weHaveDynamicData, new FutureCallback<Void>() {
             @Override
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/FlowStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/FlowStatisticsService.java
new file mode 100644 (file)
index 0000000..5080b44
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.4.2015.
+ */
+public class FlowStatisticsService extends CommonService {
+    public FlowStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
+    }
+
+    public Future<RpcResult<List<MultipartReply>>> getAllFlowsStatisticsFromAllFlowTables() {
+        return handleServiceCall(
+                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, Future<RpcResult<Void>>>() {
+                    @Override
+                    public Future<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
+
+                        final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
+                        final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+                        mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
+                        mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
+                        mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+                        mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+                        mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+                        FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
+
+                        final Xid xid = deviceContext.getNextXid();
+                        data.getRequestContext().setXid(xid);
+                        final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+                                MultipartType.OFPMPFLOW, xid.getValue(), version);
+
+                        multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+                        mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+                        final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
+                                .getConnectionAdapter().multipartRequest(mprInput.build());
+                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+                    }
+                }
+
+        );
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/FlowTableStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/FlowTableStatisticsService.java
new file mode 100644 (file)
index 0000000..d37619b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.4.2015.
+ */
+public class FlowTableStatisticsService extends CommonService {
+    public FlowTableStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
+    }
+
+    public Future<RpcResult<List<MultipartReply>>> getFlowTablesStatistics() {
+        return handleServiceCall(
+                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, Future<RpcResult<Void>>>() {
+                    @Override
+                    public Future<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
+
+                        // Create multipart request body for fetch all the group stats
+                        final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
+                        final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
+                        multipartRequestTableBuilder.setEmpty(true);
+                        multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
+
+                        // Set request body to main multipart request
+                        final Xid xid = deviceContext.getNextXid();
+                        data.getRequestContext().setXid(xid);
+                        final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+                                MultipartType.OFPMPFLOW, xid.getValue(), version);
+
+                        mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
+                        final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
+                                .getConnectionAdapter().multipartRequest(mprInput.build());
+
+                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+                    }
+                });
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/GroupStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/GroupStatisticsService.java
new file mode 100644 (file)
index 0000000..37e3933
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import org.opendaylight.openflowjava.protocol.api.util.BinContent;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.4.2015.
+ */
+public class GroupStatisticsService extends CommonService {
+    public GroupStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
+    }
+
+    public Future<RpcResult<List<MultipartReply>>> getAllGroupStatistics() {
+        return handleServiceCall(
+                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, Future<RpcResult<Void>>>() {
+                    @Override
+                    public Future<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
+                        final MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
+                        final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
+                        mprGroupBuild.setGroupId(new GroupId(
+                                BinContent
+                                        .intToUnsignedLong(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group.OFPGALL
+                                                .getIntValue())));
+                        caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
+
+                        // Create multipart request header
+                        final Xid xid = deviceContext.getNextXid();
+                        data.getRequestContext().setXid(xid);
+                        final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+                                MultipartType.OFPMPGROUP, xid.getValue(), version);
+
+                        // Set request body to main multipart request
+                        mprInput.setMultipartRequestBody(caseBuilder.build());
+
+                        // Send the request, no cookies associated, use any connection
+
+                        final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
+                                .getConnectionAdapter().multipartRequest(mprInput.build());
+                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                    }
+                });
+    }
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/MeterStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/MeterStatisticsService.java
new file mode 100644 (file)
index 0000000..d7f2250
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import org.opendaylight.openflowjava.protocol.api.util.BinContent;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.4.2015.
+ */
+public class MeterStatisticsService extends CommonService {
+
+    public MeterStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
+    }
+
+    public Future<RpcResult<List<MultipartReply>>> getAllMeterStatistics() {
+        return handleServiceCall(
+                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, Future<RpcResult<Void>>>() {
+                    @Override
+                    public Future<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
+
+                        MultipartRequestMeterCaseBuilder caseBuilder =
+                                new MultipartRequestMeterCaseBuilder();
+                        MultipartRequestMeterBuilder mprMeterBuild =
+                                new MultipartRequestMeterBuilder();
+                        mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
+                                org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
+                                        .types.rev130731.Meter.OFPMALL.getIntValue())));
+                        caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
+
+                        final Xid xid = deviceContext.getNextXid();
+
+                        MultipartRequestInputBuilder mprInput = RequestInputUtils
+                                .createMultipartHeader(MultipartType.OFPMPMETER, xid.getValue(), version);
+                        mprInput.setMultipartRequestBody(caseBuilder.build());
+                        Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
+                                .getConnectionAdapter().multipartRequest(mprInput.build());
+
+                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+                    }
+                }
+        );
+
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/PortStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/PortStatisticsService.java
new file mode 100644 (file)
index 0000000..a0fedeb
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.4.2015.
+ */
+public class PortStatisticsService extends CommonService {
+    public PortStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
+    }
+
+    public Future<RpcResult<List<MultipartReply>>> getAllNodeConnectorsStatistics() {
+        return handleServiceCall(
+                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, Future<RpcResult<Void>>>() {
+                    @Override
+                    public Future<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
+
+                        MultipartRequestPortStatsCaseBuilder caseBuilder =
+                                new MultipartRequestPortStatsCaseBuilder();
+                        MultipartRequestPortStatsBuilder mprPortStatsBuilder =
+                                new MultipartRequestPortStatsBuilder();
+                        // Select all ports
+                        mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
+                        caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
+
+                        final Xid xid = deviceContext.getNextXid();
+                        data.getRequestContext().setXid(xid);
+                        MultipartRequestInputBuilder mprInput = RequestInputUtils
+                                .createMultipartHeader(MultipartType.OFPMPPORTSTATS, xid.getValue(), version);
+                        mprInput.setMultipartRequestBody(caseBuilder.build());
+                        Future<RpcResult<Void>> resultFromOFLib = deviceContext
+                                .getPrimaryConnectionContext().getConnectionAdapter().multipartRequest(mprInput.build());
+                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+                    }
+                }
+
+        );
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/QueueStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/QueueStatisticsService.java
new file mode 100644 (file)
index 0000000..963ad17
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.4.2015.
+ */
+public class QueueStatisticsService extends CommonService {
+
+    public QueueStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
+    }
+
+    public Future<RpcResult<List<MultipartReply>>> getAllQueuesStatisticsFromAllPorts() {
+        return handleServiceCall(
+                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, Future<RpcResult<Void>>>() {
+
+                    @Override
+                    public Future<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
+
+                        MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
+                        MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
+                        // Select all ports
+                        mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
+                        // Select all the ports
+                        mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
+                        caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
+
+                        // Set request body to main multipart request
+                        final Xid xid = deviceContext.getNextXid();
+                        data.getRequestContext().setXid(xid);
+                        MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+                                MultipartType.OFPMPQUEUE, xid.getValue(), version);
+                        mprInput.setMultipartRequestBody(caseBuilder.build());
+                        Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
+                                .getConnectionAdapter().multipartRequest(mprInput.build());
+                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+                    }
+                });
+    }
+
+}
index 56f2ebec56c37c3aa8f893869959975d8fa12202..69a4e2ddb12f0477a22c86d71c736e40173dacf9 100644 (file)
@@ -112,6 +112,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
     private static GroupStatsResponseConvertor groupStatsConvertor = new GroupStatsResponseConvertor();
     private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
 
+
     @Override
     public  List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {