Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / ActionConvertorV10Test.java
index 4e52e384f50d6f1ae92722bcd14bf105b994ec76..aae4978bba3a7c2a2a7117df35f4047d48019d75 100644 (file)
@@ -5,10 +5,8 @@
  * 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.openflowplugin.openflow.md.core.sal.convertor.action;
 
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -54,6 +52,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 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.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
@@ -73,10 +72,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanPcpCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanVidCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
- * @author michal.polkorab
+ * Unit tests for v1.0 action converters.
  *
+ * @author michal.polkorab
  */
 public class ActionConvertorV10Test {
     private ConvertorManager convertorManager;
@@ -87,18 +91,19 @@ public class ActionConvertorV10Test {
     }
 
     /**
-     * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData)}}
+     * Test {@link ActionConvertor#convert(java.util.Collection, ActionConvertorData)}}.
      */
     @Test
     public void testGetActions() {
-        List<Action> salActions = new ArrayList<>();
         ActionBuilder actionBuilder = new ActionBuilder();
         SetVlanPcpActionCaseBuilder vlanPcpCaseBuilder = new SetVlanPcpActionCaseBuilder();
         SetVlanPcpActionBuilder pcpBuilder = new SetVlanPcpActionBuilder();
-        pcpBuilder.setVlanPcp(new VlanPcp((short) 7));
+        pcpBuilder.setVlanPcp(new VlanPcp(Uint8.valueOf(7)));
         vlanPcpCaseBuilder.setSetVlanPcpAction(pcpBuilder.build());
         actionBuilder.setAction(vlanPcpCaseBuilder.build());
         actionBuilder.setOrder(0);
+
+        List<Action> salActions = new ArrayList<>();
         salActions.add(actionBuilder.build());
 
         actionBuilder = new ActionBuilder();
@@ -140,11 +145,12 @@ public class ActionConvertorV10Test {
         salActions.add(actionBuilder.build());
 
         actionBuilder = new ActionBuilder();
-        SetNwDstActionCaseBuilder nwDstCaseBuilder = new SetNwDstActionCaseBuilder();
         SetNwDstActionBuilder nwDstBuilder = new SetNwDstActionBuilder();
         ipv4Builder = new Ipv4Builder();
         ipv4Builder.setIpv4Address(new Ipv4Prefix("10.0.0.2/32"));
         nwDstBuilder.setAddress(ipv4Builder.build());
+
+        SetNwDstActionCaseBuilder nwDstCaseBuilder = new SetNwDstActionCaseBuilder();
         nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
         actionBuilder.setAction(nwDstCaseBuilder.build());
         actionBuilder.setOrder(5);
@@ -153,7 +159,7 @@ public class ActionConvertorV10Test {
         actionBuilder = new ActionBuilder();
         SetTpSrcActionCaseBuilder tpSrcCaseBuilder = new SetTpSrcActionCaseBuilder();
         SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder();
-        tpSrcBuilder.setPort(new PortNumber(54));
+        tpSrcBuilder.setPort(new PortNumber(Uint16.valueOf(54)));
         tpSrcCaseBuilder.setSetTpSrcAction(tpSrcBuilder.build());
         actionBuilder.setAction(tpSrcCaseBuilder.build());
         actionBuilder.setOrder(6);
@@ -162,7 +168,7 @@ public class ActionConvertorV10Test {
         actionBuilder = new ActionBuilder();
         SetTpDstActionCaseBuilder tpDstCaseBuilder = new SetTpDstActionCaseBuilder();
         SetTpDstActionBuilder tpDstBuilder = new SetTpDstActionBuilder();
-        tpDstBuilder.setPort(new PortNumber(45));
+        tpDstBuilder.setPort(new PortNumber(Uint16.valueOf(45)));
         tpDstCaseBuilder.setSetTpDstAction(tpDstBuilder.build());
         actionBuilder.setAction(tpDstCaseBuilder.build());
         actionBuilder.setOrder(7);
@@ -180,7 +186,7 @@ public class ActionConvertorV10Test {
         actionBuilder = new ActionBuilder();
         SetVlanIdActionCaseBuilder vlanIdCaseBuilder = new SetVlanIdActionCaseBuilder();
         SetVlanIdActionBuilder vlanIdBuilder = new SetVlanIdActionBuilder();
-        vlanIdBuilder.setVlanId(new VlanId(22));
+        vlanIdBuilder.setVlanId(new VlanId(Uint16.valueOf(22)));
         vlanIdCaseBuilder.setSetVlanIdAction(vlanIdBuilder.build());
         actionBuilder.setAction(vlanIdCaseBuilder.build());
         actionBuilder.setOrder(9);
@@ -196,7 +202,7 @@ public class ActionConvertorV10Test {
         SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
-        vlanMatchBuilder.setVlanId(new VlanIdBuilder().setVlanId(new VlanId(22)).build());
+        vlanMatchBuilder.setVlanId(new VlanIdBuilder().setVlanId(new VlanId(Uint16.valueOf(22))).build());
         setFieldBuilder.setVlanMatch(vlanMatchBuilder.build());
         setFieldCaseBuilder.setSetField(setFieldBuilder.build());
         actionBuilder.setAction(setFieldCaseBuilder.build());
@@ -206,112 +212,130 @@ public class ActionConvertorV10Test {
         IpMatchBuilder ipMatchBld = new IpMatchBuilder().setIpProto(IpVersion.Ipv4);
         MatchBuilder matchBld = new MatchBuilder().setIpMatch(ipMatchBld.build());
         FlowBuilder flowBld = new FlowBuilder().setMatch(matchBld.build());
-        Flow flow = flowBld.build();
+        Flow flow = flowBld.setId(new FlowId("foo")).build();
 
         ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_0);
-        data.setDatapathId(new BigInteger("42"));
+        data.setDatapathId(Uint64.valueOf(42));
         data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow));
 
-        Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action>> actionsOptional =
-                convertorManager.convert(salActions, data);
+        Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping
+            .Action>> actionsOptional = convertorManager.convert(salActions, data);
 
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> actions = actionsOptional.orElse(Collections.emptyList());
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action>
+            actions = actionsOptional.orElse(Collections.emptyList());
 
         Assert.assertEquals("Wrong number of actions", 12, actions.size());
 
-        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actions.get(0);
+        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action
+            action = actions.get(0);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetVlanPcpCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetVlanPcpCase",
+                action.getActionChoice().implementedInterface().getName());
         SetVlanPcpCase setVlanPcpCase = (SetVlanPcpCase) action.getActionChoice();
         Assert.assertEquals("Wrong vlan pcp", 7, setVlanPcpCase.getSetVlanPcpAction().getVlanPcp().intValue());
 
         action = actions.get(1);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.StripVlanCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.StripVlanCase",
+                action.getActionChoice().implementedInterface().getName());
 
         action = actions.get(2);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetDlDstCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetDlDstCase",
+                action.getActionChoice().implementedInterface().getName());
         SetDlDstCase setDlDstCase = (SetDlDstCase) action.getActionChoice();
-        Assert.assertEquals("Wrong dl dst", "00:00:00:00:00:06", setDlDstCase.getSetDlDstAction().getDlDstAddress().getValue());
+        Assert.assertEquals("Wrong dl dst", "00:00:00:00:00:06",
+                setDlDstCase.getSetDlDstAction().getDlDstAddress().getValue());
 
         action = actions.get(3);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetDlSrcCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetDlSrcCase",
+                action.getActionChoice().implementedInterface().getName());
         SetDlSrcCase setDlSrcCase = (SetDlSrcCase) action.getActionChoice();
-        Assert.assertEquals("Wrong dl src", "00:00:00:00:00:05", setDlSrcCase.getSetDlSrcAction().getDlSrcAddress().getValue());
+        Assert.assertEquals("Wrong dl src", "00:00:00:00:00:05",
+                setDlSrcCase.getSetDlSrcAction().getDlSrcAddress().getValue());
 
         action = actions.get(4);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetNwSrcCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetNwSrcCase",
+                action.getActionChoice().implementedInterface().getName());
         SetNwSrcCase setNwSrcCase = (SetNwSrcCase) action.getActionChoice();
         Assert.assertEquals("Wrong nw src", "10.0.0.0", setNwSrcCase.getSetNwSrcAction().getIpAddress().getValue());
 
         action = actions.get(5);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetNwDstCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetNwDstCase",
+                action.getActionChoice().implementedInterface().getName());
         SetNwDstCase setNwDstCase = (SetNwDstCase) action.getActionChoice();
         Assert.assertEquals("Wrong nw dst", "10.0.0.2", setNwDstCase.getSetNwDstAction().getIpAddress().getValue());
 
         action = actions.get(6);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetTpSrcCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetTpSrcCase",
+                action.getActionChoice().implementedInterface().getName());
         SetTpSrcCase setTpSrcCase = (SetTpSrcCase) action.getActionChoice();
         Assert.assertEquals("Wrong tp src", 54, setTpSrcCase.getSetTpSrcAction().getPort().getValue().intValue());
 
         action = actions.get(7);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetTpDstCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetTpDstCase",
+                action.getActionChoice().implementedInterface().getName());
         SetTpDstCase setTpDstCase = (SetTpDstCase) action.getActionChoice();
         Assert.assertEquals("Wrong tp dst", 45, setTpDstCase.getSetTpDstAction().getPort().getValue().intValue());
 
         action = actions.get(8);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetNwTosCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetNwTosCase",
+                action.getActionChoice().implementedInterface().getName());
         SetNwTosCase setNwTosCase = (SetNwTosCase) action.getActionChoice();
         Assert.assertEquals("Wrong nw tos", 18, setNwTosCase.getSetNwTosAction().getNwTos().intValue());
 
         action = actions.get(9);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetVlanVidCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetVlanVidCase",
+                action.getActionChoice().implementedInterface().getName());
         SetVlanVidCase setVlanVidCase = (SetVlanVidCase) action.getActionChoice();
         Assert.assertEquals("Wrong vlan id", 22, setVlanVidCase.getSetVlanVidAction().getVlanVid().intValue());
 
         action = actions.get(10);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.StripVlanCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.StripVlanCase",
+                action.getActionChoice().implementedInterface().getName());
 
         action = actions.get(11);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
-                + ".action.rev150203.action.grouping.action.choice.SetVlanVidCase", action.getActionChoice().getImplementedInterface().getName());
+                + ".action.rev150203.action.grouping.action.choice.SetVlanVidCase",
+                action.getActionChoice().implementedInterface().getName());
         setVlanVidCase = (SetVlanVidCase) action.getActionChoice();
         Assert.assertEquals("Wrong vlan id", 22, setVlanVidCase.getSetVlanVidAction().getVlanVid().intValue());
     }
 
     /**
-     * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionResponseConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData)}}
+     * Test {@link ActionResponseConvertor#convert(List, ActionResponseConvertorData)}}.
      */
     @Test
     public void testToMDSalActions() {
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> actions = new ArrayList<>();
-        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionbuilder =
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
-
         OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
         OutputActionBuilder outputBuilder = new OutputActionBuilder();
-        outputBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(14L));
-        outputBuilder.setMaxLength(555);
+        outputBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731
+            .PortNumber(Uint32.valueOf(14)));
+        outputBuilder.setMaxLength(Uint16.valueOf(555));
         caseBuilder.setOutputAction(outputBuilder.build());
-        actionbuilder.setActionChoice(caseBuilder.build());
-        actions.add(actionbuilder.build());
+
+        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder
+            actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions
+                .grouping.ActionBuilder();
+        actionBuilder.setActionChoice(caseBuilder.build());
+
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action>
+            actions = new ArrayList<>();
+        actions.add(actionBuilder.build());
 
         ActionResponseConvertorData data = new ActionResponseConvertorData(OFConstants.OFP_VERSION_1_0);
         data.setActionPath(ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
 
-        Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action
-        .Action>> mdSalActionsOptional =
-                convertorManager.convert(
-                        actions, data);
+        Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>>
+            mdSalActionsOptional = convertorManager.convert(actions, data);
 
         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action
                 .Action> mdSalActions = mdSalActionsOptional.orElse(Collections.emptyList());
@@ -319,9 +343,10 @@ public class ActionConvertorV10Test {
         Assert.assertEquals("Wrong number of output actions", 1, mdSalActions.size());
         org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = mdSalActions.get(0);
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types"
-                + ".rev131112.action.action.OutputActionCase", action.getImplementedInterface().getName());
+                + ".rev131112.action.action.OutputActionCase", action.implementedInterface().getName());
         OutputActionCase outputAction = (OutputActionCase) action;
-        Assert.assertEquals("Wrong output port", "14", outputAction.getOutputAction().getOutputNodeConnector().getValue());
+        Assert.assertEquals("Wrong output port", "14",
+                outputAction.getOutputAction().getOutputNodeConnector().getValue());
         Assert.assertEquals("Wrong max length", 555, outputAction.getOutputAction().getMaxLength().intValue());
     }
 }