Action redesign: migrate nx_load_in_port 81/49481/6
authorStephen Kitt <skitt@redhat.com>
Fri, 16 Dec 2016 14:27:53 +0000 (15:27 +0100)
committerStephen Kitt <skitt@redhat.com>
Thu, 12 Jan 2017 12:33:59 +0000 (13:33 +0100)
Change-Id: Ia3975bf642439cc33166613a5c2bfa8e2c58cf52
Signed-off-by: Stephen Kitt <skitt@redhat.com>
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/ActionType.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/actions/ActionNxLoadInPort.java [new file with mode: 0644]
mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/mdsalutil/actions/ActionNxLoadInPortTest.java [new file with mode: 0644]

index d8cbaca00ea66d4ecb1432065692adee744a5b2d..158211749dfcddc421dbab03f8acb05586ccb90c 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.genius.mdsalutil.actions.ActionLearn;
 import org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth;
 import org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIp;
 import org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack;
+import org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort;
 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
 import org.opendaylight.genius.mdsalutil.actions.ActionOutput;
 import org.opendaylight.genius.mdsalutil.actions.ActionPopMpls;
@@ -515,20 +516,15 @@ public enum ActionType {
         }
     },
 
+    @Deprecated
     nx_load_in_port {
         @Override
         public Action buildAction(int newActionKey, ActionInfo actionInfo) {
-            BigInteger[] actionValues = actionInfo.getBigActionValues();
-            NxRegLoad rb = new NxRegLoadBuilder()
-                    .setDst(new DstBuilder()
-                            .setDstChoice(new DstNxOfInPortCaseBuilder().setOfInPort(Boolean.TRUE).build())
-                            .setStart(0).setEnd(15).build())
-                    .setValue(actionValues[0]).build();
-            ActionBuilder ab = new ActionBuilder();
-            ab.setKey(new ActionKey(newActionKey));
-            ab.setOrder(newActionKey);
-            ab.setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder().setNxRegLoad(rb).build());
-            return ab.build();
+            if (actionInfo instanceof ActionNxLoadInPort) {
+                return ((ActionNxLoadInPort) actionInfo).buildAction(newActionKey);
+            } else {
+                return new ActionNxLoadInPort(actionInfo).buildAction(newActionKey);
+            }
         }
     },
 
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/actions/ActionNxLoadInPort.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/actions/ActionNxLoadInPort.java
new file mode 100644 (file)
index 0000000..28d2610
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc. 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
+ */
+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.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxOfInPortCaseBuilder;
+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.NxRegLoadBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
+
+/**
+ * NX load in port action.
+ */
+public class ActionNxLoadInPort extends ActionInfo {
+    private final BigInteger value;
+
+    public ActionNxLoadInPort(BigInteger value) {
+        this(0, value);
+    }
+
+    public ActionNxLoadInPort(int actionKey, BigInteger value) {
+        super(ActionType.nx_load_in_port, new BigInteger[] {value}, actionKey);
+        this.value = value;
+    }
+
+    @Deprecated
+    public ActionNxLoadInPort(ActionInfo actionInfo) {
+        this(actionInfo.getActionKey(), actionInfo.getBigActionValues()[0]);
+    }
+
+    @Override
+    public Action buildAction() {
+        return buildAction(getActionKey());
+    }
+
+    public Action buildAction(int newActionKey) {
+        return new ActionBuilder()
+            .setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder()
+                .setNxRegLoad(new NxRegLoadBuilder()
+                    .setDst(new DstBuilder()
+                        .setDstChoice(new DstNxOfInPortCaseBuilder().setOfInPort(true).build())
+                        .setStart(0)
+                        .setEnd(15)
+                        .build())
+                    .setValue(value)
+                    .build())
+                .build())
+            .setKey(new ActionKey(newActionKey))
+            .build();
+    }
+
+    public BigInteger getValue() {
+        return value;
+    }
+}
diff --git a/mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/mdsalutil/actions/ActionNxLoadInPortTest.java b/mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/mdsalutil/actions/ActionNxLoadInPortTest.java
new file mode 100644 (file)
index 0000000..b3c02d7
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2016, 2017 Red Hat, Inc. and others.
+ *
+ * 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
+ */
+package org.opendaylight.genius.mdsalutil.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import ch.vorburger.xtendbeans.XtendBeanGenerator;
+import java.math.BigInteger;
+import org.junit.Test;
+import org.opendaylight.genius.mdsalutil.ActionInfo;
+import org.opendaylight.genius.mdsalutil.ActionType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxOfInPortCase;
+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.NxActionRegLoadNodesNodeTableFlowApplyActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
+
+/**
+ * Test for {@link ActionNxLoadInPort}.
+ */
+public class ActionNxLoadInPortTest {
+    private static final BigInteger VALUE = BigInteger.TEN;
+
+    private XtendBeanGenerator generator = new XtendBeanGenerator();
+
+    @Test
+    public void actionInfoTest() {
+        verifyAction(new ActionNxLoadInPort(VALUE).buildAction());
+    }
+
+    @Test
+    public void backwardsCompatibleAction() {
+        verifyAction(new ActionInfo(ActionType.nx_load_in_port, new BigInteger[] {VALUE}).buildAction());
+    }
+
+    private void verifyAction(Action action) {
+        assertTrue(action.getAction() instanceof NxActionRegLoadNodesNodeTableFlowApplyActionsCase);
+        NxActionRegLoadNodesNodeTableFlowApplyActionsCase actionCase =
+            (NxActionRegLoadNodesNodeTableFlowApplyActionsCase) action.getAction();
+        assertNotNull(actionCase.getNxRegLoad());
+        NxRegLoad nxRegLoad = actionCase.getNxRegLoad();
+        assertTrue(nxRegLoad.getDst().getDstChoice() instanceof DstNxOfInPortCase);
+        DstNxOfInPortCase dstNxOfInPortCase = (DstNxOfInPortCase) nxRegLoad.getDst().getDstChoice();
+        assertTrue(dstNxOfInPortCase.isOfInPort());
+        assertEquals(0, nxRegLoad.getDst().getStart().intValue());
+        assertEquals(15, nxRegLoad.getDst().getEnd().intValue());
+        assertEquals(VALUE, nxRegLoad.getValue());
+    }
+
+    @Test
+    public void generateAction() {
+        ActionInfo actionInfo = new ActionNxLoadInPort(VALUE);
+        assertEquals(
+            "new ActionNxLoadInPort(0, " + VALUE + "bi)", generator.getExpression(actionInfo));
+    }
+}