grouptype : fast failover:OFPGT_FF,null check for wieght, watch port and watch group... 40/3440/2
authorusha <usha.m.s@ericsson.com>
Wed, 4 Dec 2013 12:33:44 +0000 (18:03 +0530)
committerMichal Rehak <mirehak@cisco.com>
Thu, 12 Dec 2013 23:29:18 +0000 (00:29 +0100)
rebased

Change-Id: I76467d3f85a2bdae315ffa52975e77355bccca14
Signed-off-by: usha <usha.m.s@ericsson.com>
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertorTest.java

index 1e6b4f8f2e37e8a0c65ec6d3146c52f056dfebd8..db0cd278e78fdaae2d569e6d18b3539a576d0009 100644 (file)
@@ -45,7 +45,7 @@ public final class GroupConvertor {
     public static GroupModInput toGroupModInput(
 
     org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group source, short version) {
-        List<BucketsList> bucketLists = new ArrayList<BucketsList>();
+        List<BucketsList> bucketLists = null;
         GroupModInputBuilder groupModInputBuilder = new GroupModInputBuilder();
         if (source instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput) {
             groupModInputBuilder.setCommand(GroupModCommand.OFPGCADD);
@@ -71,10 +71,11 @@ public final class GroupConvertor {
             groupModInputBuilder.setType(GroupType.OFPGTFF);
         }
 
-        
         groupModInputBuilder.setGroupId(new GroupId(source.getGroupId().getValue()));
         // Only if the bucket is configured for the group then add it
-        if (source.getBuckets().getBucket().size() != 0) {
+        if ((source.getBuckets() != null) && (source.getBuckets().getBucket().size() != 0)) {
+
+            bucketLists = new ArrayList<BucketsList>();
             getbucketList(source.getBuckets(), bucketLists, version, source.getGroupType().getIntValue());
             groupModInputBuilder.setBucketsList(bucketLists);
         }
index c8e34ed1433c5248ca8020e389d203432a7af567..4a581c3776b4b6c49f625166cdb78fea243e1c8a 100644 (file)
@@ -30,6 +30,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 
 public class GroupConvertorTest {
 
+    /**
+     * test of {@link GroupConvertor#toGroupModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, short)}
+     */
     @Test
     public void testGroupModConvertorwithallParameters() {
 
@@ -37,8 +40,7 @@ public class GroupConvertorTest {
 
         addGroupBuilder.setGroupId(new GroupId(10L));
 
-        addGroupBuilder
-                .setGroupType(GroupTypes.GroupAll);
+        addGroupBuilder.setGroupType(GroupTypes.GroupAll);
         List<Bucket> bucketList = new ArrayList<Bucket>();
         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>();
         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList1 = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>();
@@ -146,4 +148,215 @@ public class GroupConvertorTest {
 
     }
 
+    /**
+     * test of {@link GroupConvertor#toGroupModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, short)}
+     */
+    @Test
+    public void testGroupModConvertorNoBucket() {
+        AddGroupInputBuilder addGroupBuilder = new AddGroupInputBuilder();
+
+        addGroupBuilder.setGroupId(new GroupId(10L));
+
+        addGroupBuilder.setGroupType(GroupTypes.GroupAll);
+
+        GroupModInput outAddGroupInput = GroupConvertor.toGroupModInput(addGroupBuilder.build(), (short) 0X4);
+
+        Assert.assertEquals(GroupModCommand.OFPGCADD, outAddGroupInput.getCommand());
+        Assert.assertEquals(GroupType.OFPGTALL, outAddGroupInput.getType());
+    }
+
+    /**
+     * test of {@link GroupConvertor#toGroupModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, short)}
+     */
+    @Test
+    public void testGroupModConvertorBucketwithNOWieghtValuesForGroupTypeFastFailure() {
+
+        AddGroupInputBuilder addGroupBuilder = new AddGroupInputBuilder();
+
+        addGroupBuilder.setGroupId(new GroupId(10L));
+
+        addGroupBuilder.setGroupType(GroupTypes.GroupFf);
+        List<Bucket> bucketList = new ArrayList<Bucket>();
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>();
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList1 = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>();
+
+        // Action1: 005
+        actionsList.add(assembleActionBuilder("005").build());
+        // Action2: 006
+        actionsList.add(assembleActionBuilder("006").build());
+        // .. and mr.Bond is not coming today
+
+        BucketsBuilder bucketsB = new BucketsBuilder();
+
+        BucketBuilder bucketB = new BucketBuilder();
+
+        bucketB.setAction(actionsList);
+        Bucket bucket = bucketB.build();
+
+        bucketList.add(bucket); // List of bucket
+        
+
+        
+        BucketBuilder bucketB1 = new BucketBuilder();
+
+        // Action1
+        actionsList1.add(assembleCopyTtlInBuilder().build());
+        // Action2:
+        actionsList1.add(assembleSetMplsTtlActionBuilder().build());
+
+        bucketB1.setAction(actionsList1);
+
+        Bucket bucket1 = bucketB1.build(); // second bucket
+
+        bucketList.add(bucket1);
+
+        bucketsB.setBucket(bucketList);// List of bucket added to the Buckets
+        Buckets buckets = bucketsB.build();
+
+        addGroupBuilder.setBuckets(buckets);
+
+        GroupModInput outAddGroupInput = GroupConvertor.toGroupModInput(addGroupBuilder.build(), (short) 0X4);
+
+        Assert.assertEquals(GroupModCommand.OFPGCADD, outAddGroupInput.getCommand());
+        Assert.assertEquals(GroupType.OFPGTFF, outAddGroupInput.getType());
+
+        Assert.assertEquals(10L, outAddGroupInput.getGroupId().getValue().longValue());
+
+        List<ActionsList> outActionList = outAddGroupInput.getBucketsList().get(0).getActionsList();
+        for (int outItem = 0; outItem < outActionList.size(); outItem++) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action = outActionList
+                    .get(outItem).getAction();
+            if (action instanceof GroupIdAction) {
+                Assert.assertEquals((Long) 5L, ((GroupIdAction) action).getGroupId());
+            }
+        }
+
+        List<ActionsList> outActionList1 = outAddGroupInput.getBucketsList().get(1).getActionsList();
+        for (int outItem = 0; outItem < outActionList1.size(); outItem++) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action = outActionList1
+                    .get(outItem).getAction();
+            if (action instanceof GroupIdAction) {
+                Assert.assertEquals((Long) 6L, ((GroupIdAction) action).getGroupId());
+            }
+        }
+    }
+
+    /**
+     * @return
+     */
+    private static ActionBuilder assembleSetMplsTtlActionBuilder() {
+        SetMplsTtlActionBuilder setMplsTtlActionBuilder = new SetMplsTtlActionBuilder();
+        setMplsTtlActionBuilder.setMplsTtl((short) 0X1);
+        SetMplsTtlActionCaseBuilder setMplsTtlActionCaseBuilder = new SetMplsTtlActionCaseBuilder();
+        setMplsTtlActionCaseBuilder.setSetMplsTtlAction(setMplsTtlActionBuilder.build());
+        ActionBuilder actionsB3 = new ActionBuilder();
+        actionsB3.setAction(setMplsTtlActionCaseBuilder.build());
+        return actionsB3;
+    }
+
+    /**
+     * @return
+     */
+    private static ActionBuilder assembleCopyTtlInBuilder() {
+        CopyTtlInBuilder copyTtlB = new CopyTtlInBuilder();
+        CopyTtlInCaseBuilder copyTtlInCaseBuilder = new CopyTtlInCaseBuilder();
+        copyTtlInCaseBuilder.setCopyTtlIn(copyTtlB.build());
+        ActionBuilder actionsB2 = new ActionBuilder();
+        actionsB2.setAction(copyTtlInCaseBuilder.build());
+        return actionsB2;
+    }
+
+    /**
+     * @param groupName name of group
+     * @return 
+     * 
+     */
+    private static ActionBuilder assembleActionBuilder(String groupName) {
+        GroupActionBuilder groupActionBuilder = new GroupActionBuilder();
+        groupActionBuilder.setGroup(groupName);
+        GroupActionCaseBuilder groupActionCaseBuilder = new GroupActionCaseBuilder();
+        groupActionCaseBuilder.setGroupAction(groupActionBuilder.build());
+        ActionBuilder actionsBld = new ActionBuilder();
+        actionsBld.setAction(groupActionCaseBuilder.build());
+        return actionsBld;
+    }
+
+    /**
+     * test of {@link GroupConvertor#toGroupModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, short)}
+     */
+    @Test
+    public void testGroupModConvertorBucketwithNOWieghtValuesForGroupTypeAll() {
+
+        AddGroupInputBuilder addGroupBuilder = new AddGroupInputBuilder();
+
+        addGroupBuilder.setGroupId(new GroupId(10L));
+
+        addGroupBuilder.setGroupType(GroupTypes.GroupAll);
+        List<Bucket> bucketList = new ArrayList<Bucket>();
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>();
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList1 = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>();
+
+        // Action1
+        actionsList.add(assembleActionBuilder("005").build());
+        // Action2:
+        actionsList.add(assembleActionBuilder("006").build());
+
+        BucketsBuilder bucketsB = new BucketsBuilder();
+
+        BucketBuilder bucketB = new BucketBuilder();
+
+        bucketB.setAction(actionsList);
+        Bucket bucket = bucketB.build();
+
+        bucketList.add(bucket); // List of bucket
+
+        BucketBuilder bucketB1 = new BucketBuilder();
+
+        // Action1
+        actionsList1.add(assembleCopyTtlInBuilder().build());
+        // Action2:
+        actionsList1.add(assembleSetMplsTtlActionBuilder().build());
+
+        bucketB1.setAction(actionsList);
+
+        Bucket bucket1 = bucketB1.build(); // second bucket
+
+        bucketList.add(bucket1);
+
+        bucketsB.setBucket(bucketList);// List of bucket added to the Buckets
+        Buckets buckets = bucketsB.build();
+
+        addGroupBuilder.setBuckets(buckets);
+
+        GroupModInput outAddGroupInput = GroupConvertor.toGroupModInput(addGroupBuilder.build(), (short) 0X4);
+
+        Assert.assertEquals(GroupModCommand.OFPGCADD, outAddGroupInput.getCommand());
+        Assert.assertEquals(GroupType.OFPGTALL, outAddGroupInput.getType());
+
+        Assert.assertEquals(10L, outAddGroupInput.getGroupId().getValue().longValue());
+
+        List<ActionsList> outActionList = outAddGroupInput.getBucketsList().get(0).getActionsList();
+        for (int outItem = 0; outItem < outActionList.size(); outItem++) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action = outActionList
+                    .get(outItem).getAction();
+            if (action instanceof GroupIdAction) {
+                Assert.assertEquals((Long) 5L, ((GroupIdAction) action).getGroupId());
+
+            }
+
+        }
+
+        List<ActionsList> outActionList1 = outAddGroupInput.getBucketsList().get(1).getActionsList();
+        for (int outItem = 0; outItem < outActionList1.size(); outItem++) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action = outActionList1
+                    .get(outItem).getAction();
+            if (action instanceof GroupIdAction) {
+
+                Assert.assertEquals((Long) 6L, ((GroupIdAction) action).getGroupId());
+
+            }
+
+        }
+
+    }
 }