Action redesign: use the new ActionInfo Genius classes
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / internal / ElanNodeListener.java
index 4cea2b858818042f144a49ad6cfa7b6c5615c5e7..98cd9f0ddcfc7fa6a2134d06b9053f9c06add8ff 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.elan.internal;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
@@ -16,7 +17,6 @@ import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
-import org.opendaylight.genius.mdsalutil.ActionType;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
 import org.opendaylight.genius.mdsalutil.InstructionType;
@@ -26,6 +26,9 @@ import org.opendaylight.genius.mdsalutil.MatchInfoBase;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
 import org.opendaylight.genius.mdsalutil.NxMatchInfo;
+import org.opendaylight.genius.mdsalutil.actions.ActionLearn;
+import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
+import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
@@ -40,7 +43,7 @@ import org.slf4j.LoggerFactory;
 public class ElanNodeListener extends AbstractDataChangeListener<Node> implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(ElanNodeListener.class);
-    private static final String LEARN_MATCH_REG4_VALUE = "1";
+    private static final int LEARN_MATCH_REG4_VALUE = 1;
 
     private final DataBroker broker;
     private final IMdsalApiManager mdsalManager;
@@ -95,28 +98,14 @@ public class ElanNodeListener extends AbstractDataChangeListener<Node> implement
 
     private void setupTableMissSmacFlow(BigInteger dpId) {
         List<ActionInfo> actionsInfos = new ArrayList<>();
-        actionsInfos.add(new ActionInfo(ActionType.punt_to_controller, new String[] {}));
-
-        String[][] learnActionMatches = new String[2][];
-        learnActionMatches[0] = new String[] { NwConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getHexType(),
-                NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getHexType(),
-                NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getFlowModHeaderLen() };
-        learnActionMatches[1] = new String[] {
-                NwConstants.LearnFlowModsType.COPY_FROM_VALUE.name(), LEARN_MATCH_REG4_VALUE,
-                NwConstants.NxmOfFieldType.NXM_NX_REG4.getHexType(), "8" };
-
-        String[] header = new String[] {
-            String.valueOf(0),
-            String.valueOf(tempSmacLearnTimeout),
-            BigInteger.ZERO.toString(),
-            ElanConstants.COOKIE_ELAN_LEARNED_SMAC.toString(),
-            "0",
-            Short.toString(NwConstants.ELAN_SMAC_LEARNED_TABLE),
-            String.valueOf(0),
-            String.valueOf(0)
-        };
-        actionsInfos.add(new ActionInfo(ActionType.learn, header, learnActionMatches));
+        actionsInfos.add(new ActionPuntToController());
+        actionsInfos.add(new ActionLearn(0, tempSmacLearnTimeout, 0, ElanConstants.COOKIE_ELAN_LEARNED_SMAC, 0,
+                NwConstants.ELAN_SMAC_LEARNED_TABLE, 0, 0, Arrays.asList(
+                new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
+                        NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
+                        NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getFlowModHeaderLenInt()),
+                new ActionLearn.CopyFromValue(LEARN_MATCH_REG4_VALUE,
+                        NwConstants.NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
 
         List<InstructionInfo> mkInstructions = new ArrayList<>();
         mkInstructions.add(new InstructionInfo(InstructionType.apply_actions, actionsInfos));
@@ -135,10 +124,8 @@ public class ElanNodeListener extends AbstractDataChangeListener<Node> implement
     private void addSmacBaseTableFlow(BigInteger dpId) {
         //T48 - resubmit to T49 & T50
         List<ActionInfo> actionsInfo = new ArrayList<>();
-        actionsInfo.add(new ActionInfo(ActionType.nx_resubmit,
-                new String[] {Short.toString(NwConstants.ELAN_SMAC_LEARNED_TABLE) }));
-        actionsInfo.add(new ActionInfo(ActionType.nx_resubmit,
-                new String[] {Short.toString(NwConstants.ELAN_SMAC_TABLE) }));
+        actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
+        actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
         List<InstructionInfo> mkInstruct = new ArrayList<>();
         mkInstruct.add(new InstructionInfo(InstructionType.apply_actions, actionsInfo));
         List<MatchInfo> mkMatch = new ArrayList<>();
@@ -161,7 +148,7 @@ public class ElanNodeListener extends AbstractDataChangeListener<Node> implement
                 .append(LEARN_MATCH_REG4_VALUE).toString();
         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef,
                 10, "ELAN sMac Table Reg4 Flow", 0, 0,
-                ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(new BigInteger(LEARN_MATCH_REG4_VALUE)),
+                ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE)),
                 mkMatches, mkInstructions);
         mdsalManager.installFlow(flowEntity);
     }