BUG-1491: handle SET_TP_SRC/SET_TP_DST actions
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / GroupConvertor.java
index 77e1261455b491f11f3b12bb39437924182407f9..26842fbcab864ac31e92eea4bce9bdc1bfa41816 100644 (file)
@@ -1,5 +1,15 @@
+/**
+ * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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
+ *
+ * Contributor: hema.gopalkrishnan@ericsson.com
+ */
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
 
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -7,14 +17,14 @@ import java.util.List;
 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
+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.GroupModCommand;
 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.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,7 +41,7 @@ public final class GroupConvertor {
     private static final Logger logger = LoggerFactory.getLogger(GroupConvertor.class);
     private static final String PREFIX_SEPARATOR = "/";
 
-    private static final  Integer DEFAULT_WEIGHT = new Integer(0);
+    private static final Integer DEFAULT_WEIGHT = 0;
     private static final Long OFPP_ANY = Long.parseLong("ffffffff", 16);
     private static final Long DEFAULT_WATCH_PORT = OFPP_ANY;
     private static final Long OFPG_ANY = Long.parseLong("ffffffff", 16);
@@ -41,10 +51,10 @@ public final class GroupConvertor {
 
     }
 
-    public static GroupModInput toGroupModInput(
+    public static GroupModInputBuilder toGroupModInput(
 
-    org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group source, short version) {
-        List<BucketsList> bucketLists = new ArrayList<BucketsList>();
+    org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group source, short version,BigInteger datapathid) {
+        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);
@@ -70,16 +80,20 @@ public final class GroupConvertor {
             groupModInputBuilder.setType(GroupType.OFPGTFF);
         }
 
-        
-        groupModInputBuilder.setGroupId(new Long(source.getGroupId().getValue()));
-        getbucketList(source.getBuckets(), bucketLists, version, source.getGroupType().getIntValue());
-        groupModInputBuilder.setBucketsList(bucketLists);
+        groupModInputBuilder.setGroupId(new GroupId(source.getGroupId().getValue()));
+        // Only if the bucket is configured for the group then add it
+        if ((source.getBuckets() != null) && (source.getBuckets().getBucket().size() != 0)) {
+
+            bucketLists = new ArrayList<BucketsList>();
+            getbucketList(source.getBuckets(), bucketLists, version, source.getGroupType().getIntValue(),datapathid);
+            groupModInputBuilder.setBucketsList(bucketLists);
+        }
         groupModInputBuilder.setVersion(version);
-        return groupModInputBuilder.build();
+        return groupModInputBuilder;
 
     }
 
-    private static void getbucketList(Buckets buckets, List<BucketsList> bucketLists, short version, int groupType) {
+    private static void getbucketList(Buckets buckets, List<BucketsList> bucketLists, short version, int groupType,BigInteger datapathid) {
 
         Iterator<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket> groupBucketIterator = buckets
                 .getBucket().iterator();
@@ -125,8 +139,8 @@ public final class GroupConvertor {
                 bucketBuilder.setWatchPort(new PortNumber(BinContent.intToUnsignedLong(DEFAULT_WATCH_PORT.intValue())));
             }
 
-            List<ActionsList> bucketActionList = ActionConvertor.getActionList(groupBucket.getAction(), version);
-            bucketBuilder.setActionsList(bucketActionList);
+            List<Action> bucketActionList = ActionConvertor.getActions(groupBucket.getAction(), version,datapathid, null);
+            bucketBuilder.setAction(bucketActionList);
             BucketsList bucket = bucketBuilder.build();
             bucketLists.add(bucket);
         }