Bump version odlparent->6.0.0,mdsal->5.0.3
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetTunnelDestinationIp.java
index acf92eea82f1e6b5f105f3b3d0bdf915da4cb8f4..e48f1bb489e1879c5bd3bf316ce1e90d67acb5e6 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.genius.mdsalutil.actions;
 
-import java.math.BigInteger;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
-import org.opendaylight.genius.mdsalutil.ActionType;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
@@ -18,18 +16,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4DstCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.Dst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 /**
  * Set tunnel destination IP action.
  */
 public class ActionSetTunnelDestinationIp extends ActionInfo {
-    private final BigInteger destIp;
+    private static final Dst NX_REGEX_LOAD_DST = new DstBuilder()
+            .setDstChoice(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Empty.getInstance()).build())
+            .setStart(Uint16.ZERO)
+            .setEnd(Uint16.valueOf(31).intern())
+            .build();
+
+
+    private final Uint64 destIp;
     private final boolean groupBucket;
 
-    public ActionSetTunnelDestinationIp(BigInteger destIp) {
+    public ActionSetTunnelDestinationIp(Uint64 destIp) {
         this(0, destIp);
     }
 
@@ -37,8 +46,8 @@ public class ActionSetTunnelDestinationIp extends ActionInfo {
         this(0, destIp);
     }
 
-    public ActionSetTunnelDestinationIp(int actionKey, BigInteger destIp) {
-        super(ActionType.set_tunnel_dest_ip, new BigInteger[] {destIp}, actionKey);
+    public ActionSetTunnelDestinationIp(int actionKey, Uint64 destIp) {
+        super(actionKey);
         this.destIp = destIp;
         this.groupBucket = false;
     }
@@ -47,12 +56,12 @@ public class ActionSetTunnelDestinationIp extends ActionInfo {
         this(actionKey, MDSALUtil.getBigIntIpFromIpAddress(destIp));
     }
 
-    @Deprecated
-    public ActionSetTunnelDestinationIp(ActionInfo actionInfo) {
-        super(ActionType.set_tunnel_dest_ip, actionInfo.getBigActionValues(), actionInfo.getActionKey());
-        BigInteger[] bigActionValues = actionInfo.getBigActionValues();
-        this.destIp = bigActionValues[0];
-        this.groupBucket = bigActionValues.length > 1;
+    public Uint64 getDestIp() {
+        return destIp;
+    }
+
+    public boolean isGroupBucket() {
+        return groupBucket;
     }
 
     @Override
@@ -60,37 +69,41 @@ public class ActionSetTunnelDestinationIp extends ActionInfo {
         return buildAction(getActionKey());
     }
 
+    @Override
     public Action buildAction(int newActionKey) {
-        NxRegLoadBuilder nxRegLoadBuilder = new NxRegLoadBuilder();
-        Dst dst = new DstBuilder()
-            .setDstChoice(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Boolean.TRUE).build())
-            .setStart(0)
-            .setEnd(31)
-            .build();
-        nxRegLoadBuilder.setDst(dst);
-        nxRegLoadBuilder.setValue(destIp);
-        ActionBuilder ab = new ActionBuilder();
+        NxRegLoad nxRegLoad = new NxRegLoadBuilder()
+                .setDst(NX_REGEX_LOAD_DST)
+                .setValue(destIp)
+                .build();
 
+        ActionBuilder ab = new ActionBuilder().withKey(new ActionKey(newActionKey));
         if (groupBucket) {
             ab.setAction(new NxActionRegLoadNodesNodeGroupBucketsBucketActionsCaseBuilder()
-                .setNxRegLoad(nxRegLoadBuilder.build()).build());
+                .setNxRegLoad(nxRegLoad).build());
         } else {
             ab.setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder()
-                .setNxRegLoad(nxRegLoadBuilder.build()).build());
+                .setNxRegLoad(nxRegLoad).build());
         }
-        ab.setKey(new ActionKey(newActionKey));
         return ab.build();
     }
 
     @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        if (!super.equals(o)) return false;
+    public boolean equals(Object other) {
+        if (this == other) {
+            return true;
+        }
+        if (other == null || getClass() != other.getClass()) {
+            return false;
+        }
+        if (!super.equals(other)) {
+            return false;
+        }
 
-        ActionSetTunnelDestinationIp that = (ActionSetTunnelDestinationIp) o;
+        ActionSetTunnelDestinationIp that = (ActionSetTunnelDestinationIp) other;
 
-        if (groupBucket != that.groupBucket) return false;
+        if (groupBucket != that.groupBucket) {
+            return false;
+        }
         return destIp != null ? destIp.equals(that.destIp) : that.destIp == null;
     }
 
@@ -101,4 +114,10 @@ public class ActionSetTunnelDestinationIp extends ActionInfo {
         result = 31 * result + (groupBucket ? 1 : 0);
         return result;
     }
+
+    @Override
+    public String toString() {
+        return "ActionSetTunnelDestinationIp [destIp=" + destIp + ", groupBucket=" + groupBucket + ", getActionKey()="
+                + getActionKey() + "]";
+    }
 }