SONAR TD - Group actions redundancy 62/43962/1
authorTomas Slusny <tomas.slusny@pantheon.sk>
Mon, 15 Aug 2016 11:38:13 +0000 (13:38 +0200)
committerTomas Slusny <tomas.slusny@pantheon.sk>
Mon, 15 Aug 2016 11:38:13 +0000 (13:38 +0200)
- Moved logic that converts list of action types to group actions bitmap
  to single method in GroupUtil

Change-Id: Ie8fc71945c4a5412c5adf88cb66d26f2d9a9a229
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.sk>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/common/NodeStaticReplyTranslatorUtil.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GroupFeaturesService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/GroupUtil.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslatorTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/GroupUtilTest.java

index 9828888c835f2feb83d22047e21cb96122e3490b..61c737efa9998a4f5237cce17cb1f69467f8bc5c 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 import java.util.Optional;
 import javax.annotation.CheckForNull;
 import org.opendaylight.openflowplugin.api.OFConstants;
+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.VersionConvertorData;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
@@ -50,7 +51,6 @@ 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.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeatures;
@@ -158,28 +158,7 @@ public class NodeStaticReplyTranslatorUtil {
         addGroupCapabilities(reply, gCapability);
         groupFeature.setGroupCapabilitiesSupported(gCapability);
 
-        final List<Long> supportActionByGroups = new ArrayList<>();
-        for (final ActionType actionType : reply.getActionsBitmap()) {
-            long supportActionBitmap = 0;
-            supportActionBitmap |= actionType.isOFPATOUTPUT() ? (1 << 0) : 0;
-            supportActionBitmap |= actionType.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
-            supportActionBitmap |= actionType.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
-            supportActionBitmap |= actionType.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
-            supportActionBitmap |= actionType.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
-            supportActionBitmap |= actionType.isOFPATPUSHVLAN() ? (1 << 17) : 0;
-            supportActionBitmap |= actionType.isOFPATPOPVLAN() ? (1 << 18) : 0;
-            supportActionBitmap |= actionType.isOFPATPUSHMPLS() ? (1 << 19) : 0;
-            supportActionBitmap |= actionType.isOFPATPOPMPLS() ? (1 << 20) : 0;
-            supportActionBitmap |= actionType.isOFPATSETQUEUE() ? (1 << 21) : 0;
-            supportActionBitmap |= actionType.isOFPATGROUP() ? (1 << 22) : 0;
-            supportActionBitmap |= actionType.isOFPATSETNWTTL() ? (1 << 23) : 0;
-            supportActionBitmap |= actionType.isOFPATDECNWTTL() ? (1 << 24) : 0;
-            supportActionBitmap |= actionType.isOFPATSETFIELD() ? (1 << 25) : 0;
-            supportActionBitmap |= actionType.isOFPATPUSHPBB() ? (1 << 26) : 0;
-            supportActionBitmap |= actionType.isOFPATPOPPBB() ? (1 << 27) : 0;
-            supportActionByGroups.add(Long.valueOf(supportActionBitmap));
-        }
-        groupFeature.setActions(supportActionByGroups);
+        groupFeature.setActions(GroupUtil.extractGroupActionsSupportBitmap(reply.getActionsBitmap()));
         return new NodeGroupFeaturesBuilder().setGroupFeatures(groupFeature.build()).build();
     }
 
index 80c9d42cfa5854435303737d7338918756d2d937..a09e0bf840db2f74418df465ea5ae9aa3a0a16bc 100644 (file)
@@ -13,6 +13,7 @@ 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.impl.util.GroupUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
@@ -341,7 +342,7 @@ public class SinglePurposeMultipartReplyTranslator {
 
         message.setGroupCapabilitiesSupported(supportedCapabilities);
 
-        message.setActions(getGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
+        message.setActions(GroupUtil.extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
         listDataObject.add(message.build());
     }
 
@@ -527,36 +528,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;
-    }
-
 }
index 008429797eff41b0cb774dee8f2cc4c7cc71face..5dc48381823c1ec3bed83ab5ebb097dedee3002e 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
+import org.opendaylight.openflowplugin.impl.util.GroupUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
@@ -33,7 +34,6 @@ 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.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
@@ -84,7 +84,7 @@ final class GroupFeaturesService
         notification.setGroupTypesSupported(extractSupportedGroupTypes(replyBody.getTypes()));
         notification.setMaxGroups(replyBody.getMaxGroups());
         notification.setGroupCapabilitiesSupported(extractSupportedCapabilities(replyBody.getCapabilities()));
-        notification.setActions(extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
+        notification.setActions(GroupUtil.extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
 
         return notification.build();
     }
@@ -126,30 +126,4 @@ final class GroupFeaturesService
         }
         return supportedGroups;
     }
-
-    @VisibleForTesting
-    static List<Long> extractGroupActionsSupportBitmap(final List<ActionType> actionsSupported) {
-        List<Long> supportActionByGroups = new ArrayList<>();
-        for (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;
-    }
 }
index d6b250e25596829de9b5c1d33eae08f46a72aa90..14f1ecc44302a1d2b0fd482ae53b1f4e76448b86 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 
 /**
  * provides group util methods
@@ -161,6 +162,37 @@ public final class GroupUtil {
         };
     }
 
+    /*
+     * Method returns the bitmap of actions supported by each group.
+     *
+     * @param actionsSupported
+     * @return
+     */
+    public static List<Long> extractGroupActionsSupportBitmap(final List<ActionType> actionsSupported) {
+        List<Long> supportActionByGroups = new ArrayList<>();
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported) {
+            long supportActionBitmap = 0;
+            supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1) : 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(supportActionBitmap);
+        }
+        return supportActionByGroups;
+    }
+
     /**
      * Factory method: create {@link Function} which attaches barrier response to given {@link RpcResult}&lt;T&gt;
      * and changes success flag if needed.
index 3c1cabd8972489b47ac673a37ef8139b883a60f4..5ab810539ebbfdc55b2129595d0743495a88cc85 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 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.GroupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
@@ -87,7 +86,6 @@ public class SinglePurposeMultipartReplyTranslatorTest {
     private static final Long DUMMY_REF_COUNT = 1234L;
     private static final GroupTypes DUMMY_GROUPS_TYPE = GroupTypes.GroupAll;
     private static final GroupType DUMMY_GROUP_TYPE = GroupType.OFPGTALL;
-    private static final Long GROUP_ACTION_BITMAP = 0b00000000000000000000000000000000000001111111111111001100000000001L;
 
     @Before
     public void setUp() {
@@ -209,15 +207,6 @@ public class SinglePurposeMultipartReplyTranslatorTest {
         assertEquals(DUMMY_GROUPS_TYPE,groupDescStat.getGroupType() );
     }
 
-    @Test
-    public void getGroupActionsSupportBitmap() {
-        ActionType actionSupported = new ActionType(true,true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
-        final List<Long> groupActionsSupportBitmap = SinglePurposeMultipartReplyTranslator.getGroupActionsSupportBitmap(Lists.newArrayList(actionSupported));
-        assertEquals(1, groupActionsSupportBitmap.size());
-        final Long bitmap = groupActionsSupportBitmap.get(0);
-        assertEquals(GROUP_ACTION_BITMAP, bitmap);
-    }
-
     private MultipartReplyBody prepareMultipartReplyGroupDesc() {
         MultipartReplyGroupDescCaseBuilder multipartReplyGroupDescCaseBuilder = new MultipartReplyGroupDescCaseBuilder();
         MultipartReplyGroupDescBuilder multipartReplyGroupDescBuilder = new MultipartReplyGroupDescBuilder();
index 37500c4661c6b0846d8cac4be08deb9917b6677b..e433a499208c931d594b794c87eb538f1422e5a7 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.openflowplugin.impl.util;
 
+import static org.junit.Assert.assertEquals;
+
 import com.google.common.base.Function;
 import com.google.common.collect.Lists;
 import java.util.Collections;
@@ -28,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 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.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -41,6 +44,7 @@ public class GroupUtilTest {
     public static final NodeId DUMMY_NODE_ID = new NodeId("dummyNodeId");
     private static final GroupId DUMMY_GROUP_ID = new GroupId(42L);
     private static final GroupId DUMMY_GROUP_ID_2 = new GroupId(43L);
+    private static final Long GROUP_ACTION_BITMAP = 0b00000000000000000000000000000000000001111111111111001100000000001L;
 
     @Test
     public void testBuildGroupPath() throws Exception {
@@ -202,6 +206,15 @@ public class GroupUtilTest {
         Assert.assertEquals(1, composite.getResult().getBatchFailedGroupsOutput().size());
     }
 
+    @Test
+    public void testExtractGroupActionsSupportBitmap() {
+        ActionType actionSupported = new ActionType(true,true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
+        final List<Long> groupActionsSupportBitmap = GroupUtil.extractGroupActionsSupportBitmap(Lists.newArrayList(actionSupported));
+        assertEquals(1, groupActionsSupportBitmap.size());
+        final Long bitmap = groupActionsSupportBitmap.get(0);
+        assertEquals(GROUP_ACTION_BITMAP, bitmap);
+    }
+
     private RpcResult<Void> createBarrierFailureOutcome() {
         return RpcResultBuilder.<Void>failed()
                 .withError(RpcError.ErrorType.APPLICATION, "ut-barrier-error")