RPC opendaylight-direct-statistics:get-flow-statistics not taking nicira
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / SinglePurposeMultipartReplyTranslator.java
index 732bc4f465ba2cce2f0a1213424fbacc0bd56810..6116659180e32948227d650850eca761c5419f1b 100644 (file)
@@ -9,16 +9,21 @@ package org.opendaylight.openflowplugin.impl.statistics;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupStatsResponseConvertor;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterStatsResponseConvertor;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.impl.util.GroupUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
+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.FlowTableStatisticsUpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
@@ -37,6 +42,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectLiveness;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectWeight;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdatedBuilder;
@@ -49,6 +56,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterKbps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterPktps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.BytesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.PacketsBuilder;
@@ -104,30 +112,31 @@ public class SinglePurposeMultipartReplyTranslator {
 
     protected static final Logger logger = LoggerFactory
             .getLogger(SinglePurposeMultipartReplyTranslator.class);
+    private final ConvertorExecutor convertorExecutor;
 
-    private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
-    private static GroupStatsResponseConvertor groupStatsConvertor = new GroupStatsResponseConvertor();
-    private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
-
+    public SinglePurposeMultipartReplyTranslator(ConvertorExecutor convertorExecutor) {
+        this.convertorExecutor = convertorExecutor;
+    }
 
     public List<DataObject> translate(final BigInteger datapathId, final short version, final OfHeader msg) {
 
         List<DataObject> listDataObject = new ArrayList<>();
 
-        OpenflowVersion ofVersion = OpenflowVersion.get(version);
-
         if (msg instanceof MultipartReplyMessage) {
             MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
-            NodeId node = SinglePurposeMultipartReplyTranslator.nodeIdFromDatapathId(datapathId);
+            OpenflowVersion ofVersion = OpenflowVersion.get(version);
+            NodeId node = nodeIdFromDatapathId(datapathId);
+            VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version);
+            data.setDatapathId(datapathId);
 
-            translateFlow(listDataObject, mpReply, node, ofVersion, datapathId);
+            translateFlow(listDataObject, mpReply, node, data);
             translateAggregate(listDataObject, mpReply, node);
             translatePortStats(listDataObject, mpReply, node, ofVersion, datapathId);
-            translateGroup(listDataObject, mpReply, node);
-            translateGroupDesc(listDataObject, mpReply, node, ofVersion);
+            translateGroup(listDataObject, mpReply, node, data);
+            translateGroupDesc(listDataObject, mpReply, node, data);
             translateGroupFeatures(listDataObject, mpReply, node);
-            translateMeter(listDataObject, mpReply, node);
-            translateMeterConfig(listDataObject, mpReply, node);
+            translateMeter(listDataObject, mpReply, node, data);
+            translateMeterConfig(listDataObject, mpReply, node, data);
             translateMeterFeatures(listDataObject, mpReply, node);
             translateTable(listDataObject, mpReply, node);
             translateQueue(listDataObject, mpReply, node, ofVersion, datapathId);
@@ -136,29 +145,33 @@ public class SinglePurposeMultipartReplyTranslator {
         return listDataObject;
     }
 
-    private static void translateFlow(final List<DataObject> listDataObject,
-                                      final MultipartReplyMessage mpReply,
-                                      final NodeId node,
-                                      final OpenflowVersion ofVersion,
-                                      final BigInteger datapathId) {
+    private void translateFlow(final List<DataObject> listDataObject,
+                               final MultipartReplyMessage mpReply,
+                               final NodeId node, VersionDatapathIdConvertorData data) {
         if (!MultipartType.OFPMPFLOW.equals(mpReply.getType())) {
             return;
         }
 
+        FlowStatsResponseConvertorData flowData = new FlowStatsResponseConvertorData(data.getVersion());
+        flowData.setDatapathId(data.getDatapathId());
+        flowData.setMatchPath(MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
         FlowsStatisticsUpdateBuilder message = new FlowsStatisticsUpdateBuilder();
         message.setId(node);
         message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
         message.setTransactionId(generateTransactionId(mpReply.getXid()));
         MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody();
         MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
-        message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), datapathId, ofVersion));
+        final Optional<List<FlowAndStatisticsMapList>> flowAndStatisticsMapLists =
+                convertorExecutor.convert(replyBody.getFlowStats(), flowData);
+
+        message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList()));
 
         listDataObject.add(message.build());
     }
 
-    private static void translateAggregate(final List<DataObject> listDataObject,
-                                           final MultipartReplyMessage mpReply,
-                                           final NodeId node) {
+    private void translateAggregate(final List<DataObject> listDataObject,
+                                    final MultipartReplyMessage mpReply,
+                                    final NodeId node) {
         if (!MultipartType.OFPMPAGGREGATE.equals(mpReply.getType())) {
             return;
         }
@@ -177,11 +190,11 @@ public class SinglePurposeMultipartReplyTranslator {
         listDataObject.add(message.build());
     }
 
-    private static void translatePortStats(final List<DataObject> listDataObject,
-                                           final MultipartReplyMessage mpReply,
-                                           final NodeId node,
-                                           final OpenflowVersion ofVersion,
-                                           final BigInteger datapathId) {
+    private void translatePortStats(final List<DataObject> listDataObject,
+                                    final MultipartReplyMessage mpReply,
+                                    final NodeId node,
+                                    final OpenflowVersion ofVersion,
+                                    final BigInteger datapathId) {
         if (!MultipartType.OFPMPPORTSTATS.equals(mpReply.getType())) {
             return;
         }
@@ -240,9 +253,10 @@ public class SinglePurposeMultipartReplyTranslator {
         listDataObject.add(message.build());
     }
 
-    private static void translateGroup(final List<DataObject> listDataObject,
-                                       final MultipartReplyMessage mpReply,
-                                       final NodeId node) {
+    private void translateGroup(final List<DataObject> listDataObject,
+                                final MultipartReplyMessage mpReply,
+                                final NodeId node,
+                                final VersionDatapathIdConvertorData data) {
         if (!MultipartType.OFPMPGROUP.equals(mpReply.getType())) {
             return;
         }
@@ -253,15 +267,18 @@ public class SinglePurposeMultipartReplyTranslator {
         message.setTransactionId(generateTransactionId(mpReply.getXid()));
         MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody();
         MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
-        message.setGroupStats(groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats()));
+        final Optional<List<GroupStats>> groupStatsList = convertorExecutor.convert(
+                replyBody.getGroupStats(), data);
+
+        message.setGroupStats(groupStatsList.orElse(Collections.emptyList()));
 
         listDataObject.add(message.build());
     }
 
-    private static void translateGroupDesc(final List<DataObject> listDataObject,
-                                           final MultipartReplyMessage mpReply,
-                                           final NodeId node,
-                                           final OpenflowVersion ofVersion) {
+    private void translateGroupDesc(final List<DataObject> listDataObject,
+                                    final MultipartReplyMessage mpReply,
+                                    final NodeId node,
+                                    final VersionDatapathIdConvertorData data) {
         if (!MultipartType.OFPMPGROUPDESC.equals(mpReply.getType())) {
             return;
         }
@@ -273,14 +290,17 @@ public class SinglePurposeMultipartReplyTranslator {
         MultipartReplyGroupDescCase caseBody = (MultipartReplyGroupDescCase) mpReply.getMultipartReplyBody();
         MultipartReplyGroupDesc replyBody = caseBody.getMultipartReplyGroupDesc();
 
-        message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc(), ofVersion));
+        final Optional<List<GroupDescStats>> groupDescStatsList = convertorExecutor.convert(
+                replyBody.getGroupDesc(), data);
+
+        message.setGroupDescStats(groupDescStatsList.orElse(Collections.emptyList()));
 
         listDataObject.add(message.build());
     }
 
-    private static void translateGroupFeatures(final List<DataObject> listDataObject,
-                                               final MultipartReplyMessage mpReply,
-                                               final NodeId node) {
+    private void translateGroupFeatures(final List<DataObject> listDataObject,
+                                        final MultipartReplyMessage mpReply,
+                                        final NodeId node) {
         if (!MultipartType.OFPMPGROUPFEATURES.equals(mpReply.getType())) {
             return;
         }
@@ -327,13 +347,14 @@ public class SinglePurposeMultipartReplyTranslator {
 
         message.setGroupCapabilitiesSupported(supportedCapabilities);
 
-        message.setActions(getGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
+        message.setActions(GroupUtil.extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
         listDataObject.add(message.build());
     }
 
-    private static void translateMeter(final List<DataObject> listDataObject,
-                                       final MultipartReplyMessage mpReply,
-                                       final NodeId node) {
+    private void translateMeter(final List<DataObject> listDataObject,
+                                final MultipartReplyMessage mpReply,
+                                final NodeId node,
+                                final VersionDatapathIdConvertorData data) {
         if (!MultipartType.OFPMPMETER.equals(mpReply.getType())) {
             return;
         }
@@ -345,14 +366,18 @@ public class SinglePurposeMultipartReplyTranslator {
 
         MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody();
         MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter();
-        message.setMeterStats(meterStatsConvertor.toSALMeterStatsList(replyBody.getMeterStats()));
+        final Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats>> meterStatsList =
+                convertorExecutor.convert(replyBody.getMeterStats(), data);
+
+        message.setMeterStats(meterStatsList.orElse(Collections.emptyList()));
 
         listDataObject.add(message.build());
     }
 
-    private static void translateMeterConfig(final List<DataObject> listDataObject,
-                                             final MultipartReplyMessage mpReply,
-                                             final NodeId node) {
+    private void translateMeterConfig(final List<DataObject> listDataObject,
+                                      final MultipartReplyMessage mpReply,
+                                      final NodeId node,
+                                      final VersionDatapathIdConvertorData data) {
         if (!MultipartType.OFPMPMETERCONFIG.equals(mpReply.getType())) {
             return;
         }
@@ -364,12 +389,14 @@ public class SinglePurposeMultipartReplyTranslator {
 
         MultipartReplyMeterConfigCase caseBody = (MultipartReplyMeterConfigCase) mpReply.getMultipartReplyBody();
         MultipartReplyMeterConfig replyBody = caseBody.getMultipartReplyMeterConfig();
-        message.setMeterConfigStats(meterStatsConvertor.toSALMeterConfigList(replyBody.getMeterConfig()));
+        final Optional<List<MeterConfigStats>> meterConfigStatsList = convertorExecutor.convert(replyBody.getMeterConfig(), data);
+
+        message.setMeterConfigStats(meterConfigStatsList.orElse(Collections.emptyList()));
 
         listDataObject.add(message.build());
     }
 
-    private static void translateMeterFeatures(final List<DataObject> listDataObject,
+    private void translateMeterFeatures(final List<DataObject> listDataObject,
                                                final MultipartReplyMessage mpReply,
                                                final NodeId node) {
         if (!MultipartType.OFPMPMETERFEATURES.equals(mpReply.getType())) {
@@ -419,7 +446,7 @@ public class SinglePurposeMultipartReplyTranslator {
         listDataObject.add(message.build());
     }
 
-    private static void translateTable(final List<DataObject> listDataObject,
+    private void translateTable(final List<DataObject> listDataObject,
                                        final MultipartReplyMessage mpReply,
                                        final NodeId node) {
         if (!MultipartType.OFPMPTABLE.equals(mpReply.getType())) {
@@ -450,7 +477,7 @@ public class SinglePurposeMultipartReplyTranslator {
         listDataObject.add(message.build());
     }
 
-    private static void translateQueue(final List<DataObject> listDataObject,
+    private void translateQueue(final List<DataObject> listDataObject,
                                        final MultipartReplyMessage mpReply,
                                        final NodeId node,
                                        final OpenflowVersion ofVersion,
@@ -506,36 +533,4 @@ public class SinglePurposeMultipartReplyTranslator {
         BigInteger bigIntXid = BigInteger.valueOf(xid);
         return new TransactionId(bigIntXid);
     }
-
-    /*
-     * Method returns the bitmap of actions supported by each group.
-     *
-     * @param actionsSupported
-     * @return
-     */
-    static List<Long> getGroupActionsSupportBitmap(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType> actionsSupported) {
-        List<Long> supportActionByGroups = new ArrayList<Long>();
-        for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported) {
-            long supportActionBitmap = 0;
-            supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1 << 0) : 0;
-            supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
-            supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
-            supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
-            supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
-            supportActionBitmap |= supportedActions.isOFPATPUSHVLAN() ? (1 << 17) : 0;
-            supportActionBitmap |= supportedActions.isOFPATPOPVLAN() ? (1 << 18) : 0;
-            supportActionBitmap |= supportedActions.isOFPATPUSHMPLS() ? (1 << 19) : 0;
-            supportActionBitmap |= supportedActions.isOFPATPOPMPLS() ? (1 << 20) : 0;
-            supportActionBitmap |= supportedActions.isOFPATSETQUEUE() ? (1 << 21) : 0;
-            supportActionBitmap |= supportedActions.isOFPATGROUP() ? (1 << 22) : 0;
-            supportActionBitmap |= supportedActions.isOFPATSETNWTTL() ? (1 << 23) : 0;
-            supportActionBitmap |= supportedActions.isOFPATDECNWTTL() ? (1 << 24) : 0;
-            supportActionBitmap |= supportedActions.isOFPATSETFIELD() ? (1 << 25) : 0;
-            supportActionBitmap |= supportedActions.isOFPATPUSHPBB() ? (1 << 26) : 0;
-            supportActionBitmap |= supportedActions.isOFPATPOPPBB() ? (1 << 27) : 0;
-            supportActionByGroups.add(Long.valueOf(supportActionBitmap));
-        }
-        return supportActionByGroups;
-    }
-
 }