-/*\r
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-import io.netty.buffer.UnpooledByteBufAllocator;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class OF10ActionsSerializerTest {\r
-\r
- private SerializerRegistry registry;\r
-\r
- /**\r
- * Initializes serializer table and stores correct factory in field\r
- */\r
- @Before\r
- public void startUp() {\r
- registry = new SerializerRegistryImpl();\r
- registry.init();\r
- }\r
-\r
- /**\r
- * Testing correct serialization of actions (OF v1.0) \r
- */\r
- @Test\r
- public void test() {\r
- List<Action> actions = new ArrayList<>();\r
- ActionBuilder actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Output.class);\r
- PortActionBuilder portBuilder = new PortActionBuilder();\r
- portBuilder.setPort(new PortNumber(42L));\r
- actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
- MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();\r
- maxLen.setMaxLength(32);\r
- actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetVlanVid.class);\r
- VlanVidActionBuilder vlanBuilder = new VlanVidActionBuilder();\r
- vlanBuilder.setVlanVid(15);\r
- actionBuilder.addAugmentation(VlanVidAction.class, vlanBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetVlanPcp.class);\r
- VlanPcpActionBuilder pcpBuilder = new VlanPcpActionBuilder();\r
- pcpBuilder.setVlanPcp((short) 16);\r
- actionBuilder.addAugmentation(VlanPcpAction.class, pcpBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(StripVlan.class);\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetDlSrc.class);\r
- DlAddressActionBuilder dlBuilder = new DlAddressActionBuilder();\r
- dlBuilder.setDlAddress(new MacAddress("00:00:00:02:03:04"));\r
- actionBuilder.addAugmentation(DlAddressAction.class, dlBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetDlDst.class);\r
- dlBuilder = new DlAddressActionBuilder();\r
- dlBuilder.setDlAddress(new MacAddress("00:00:00:01:02:03"));\r
- actionBuilder.addAugmentation(DlAddressAction.class, dlBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetNwSrc.class);\r
- IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder();\r
- ipBuilder.setIpAddress(new Ipv4Address("10.0.0.1"));\r
- actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetNwDst.class);\r
- ipBuilder = new IpAddressActionBuilder();\r
- ipBuilder.setIpAddress(new Ipv4Address("10.0.0.3"));\r
- actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetNwTos.class);\r
- NwTosActionBuilder tosBuilder = new NwTosActionBuilder();\r
- tosBuilder.setNwTos((short) 204);\r
- actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetTpSrc.class);\r
- portBuilder = new PortActionBuilder();\r
- portBuilder.setPort(new PortNumber(6653L));\r
- actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetTpDst.class);\r
- portBuilder = new PortActionBuilder();\r
- portBuilder.setPort(new PortNumber(6633L));\r
- actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Enqueue.class);\r
- portBuilder = new PortActionBuilder();\r
- portBuilder.setPort(new PortNumber(6613L));\r
- actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
- QueueIdActionBuilder queueBuilder = new QueueIdActionBuilder();\r
- queueBuilder.setQueueId(400L);\r
- actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Experimenter.class);\r
- ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder();\r
- expBuilder.setExperimenter(82L);\r
- byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1};\r
- expBuilder.setData(expData);\r
- actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Experimenter.class);\r
- expBuilder = new ExperimenterActionBuilder();\r
- expBuilder.setExperimenter(102L);\r
- actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build());\r
- actions.add(actionBuilder.build());\r
- \r
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory\r
- .createActionKeyMaker(EncodeConstants.OF10_VERSION_ID), registry, out);\r
- \r
- Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong port", 42, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong max-length", 32, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action type", 1, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong vlan-vid", 15, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 2, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong vlan-pcp", 16, out.readUnsignedByte());\r
- out.skipBytes(3);\r
- Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 4, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- byte[] data = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];\r
- out.readBytes(data);\r
- Assert.assertArrayEquals("Wrong dl-address", ByteBufUtils.macAddressToBytes("00:00:00:02:03:04"), data);\r
- out.skipBytes(6);\r
- Assert.assertEquals("Wrong action type", 5, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- data = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];\r
- out.readBytes(data);\r
- Assert.assertArrayEquals("Wrong dl-address", ByteBufUtils.macAddressToBytes("00:00:00:01:02:03"), data);\r
- out.skipBytes(6);\r
- Assert.assertEquals("Wrong action type", 6, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong ip-address(1)", 10, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong ip-address(2)", 0, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong ip-address(3)", 0, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong ip-address(4)", 1, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong action type", 7, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong ip-address(1)", 10, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong ip-address(2)", 0, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong ip-address(3)", 0, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong ip-address(4)", 3, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong action type", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong nw-tos", 204, out.readUnsignedByte());\r
- out.skipBytes(3);\r
- Assert.assertEquals("Wrong action type", 9, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong port", 6653, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 10, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong port", 6633, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 11, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong port", 6613, out.readUnsignedShort());\r
- out.skipBytes(6);\r
- Assert.assertEquals("Wrong queue-id", 400, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong experimenter", 82, out.readUnsignedInt());\r
- byte[] tmp = new byte[8];\r
- out.readBytes(tmp);\r
- Assert.assertArrayEquals("Wrong data", expData, tmp);\r
- Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong experimenter", 102, out.readUnsignedInt());\r
- Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0);\r
- }\r
- \r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.util;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.UnpooledByteBufAllocator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.EnqueueCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlDstCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlSrcCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTosCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpDstCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanPcpCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanVidCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.enqueue._case.EnqueueActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.dl.dst._case.SetDlDstActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.dl.src._case.SetDlSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.tos._case.SetNwTosActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.dst._case.SetTpDstActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.pcp._case.SetVlanPcpActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.vid._case.SetVlanVidActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF10ActionsSerializerTest {
+
+ private SerializerRegistry registry;
+
+ /**
+ * Initializes serializer table and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ }
+
+ /**
+ * Testing correct serialization of actions (OF v1.0)
+ */
+ @Test
+ public void test() {
+ List<Action> actions = new ArrayList<>();
+ ActionBuilder actionBuilder = new ActionBuilder();
+ OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
+ OutputActionBuilder outputBuilder = new OutputActionBuilder();
+ outputBuilder.setPort(new PortNumber(42L));
+ outputBuilder.setMaxLength(32);
+ caseBuilder.setOutputAction(outputBuilder.build());
+ actionBuilder.setActionChoice(caseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetVlanVidCaseBuilder vlanVidCaseBuilder = new SetVlanVidCaseBuilder();
+ SetVlanVidActionBuilder vlanVidBuilder = new SetVlanVidActionBuilder();
+ vlanVidBuilder.setVlanVid(15);
+ vlanVidCaseBuilder.setSetVlanVidAction(vlanVidBuilder.build());
+ actionBuilder.setActionChoice(vlanVidCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetVlanPcpCaseBuilder vlanPcpCaseBuilder = new SetVlanPcpCaseBuilder();
+ SetVlanPcpActionBuilder vlanPcpBuilder = new SetVlanPcpActionBuilder();
+ vlanPcpBuilder.setVlanPcp((short) 16);
+ vlanPcpCaseBuilder.setSetVlanPcpAction(vlanPcpBuilder.build());
+ actionBuilder.setActionChoice(vlanPcpCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new StripVlanCaseBuilder().build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetDlSrcCaseBuilder dlSrcCaseBuilder = new SetDlSrcCaseBuilder();
+ SetDlSrcActionBuilder dlSrcBuilder = new SetDlSrcActionBuilder();
+ dlSrcBuilder.setDlSrcAddress(new MacAddress("00:00:00:02:03:04"));
+ dlSrcCaseBuilder.setSetDlSrcAction(dlSrcBuilder.build());
+ actionBuilder.setActionChoice(dlSrcCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetDlDstCaseBuilder dlDstCaseBuilder = new SetDlDstCaseBuilder();
+ SetDlDstActionBuilder dlDstBuilder = new SetDlDstActionBuilder();
+ dlDstBuilder.setDlDstAddress(new MacAddress("00:00:00:01:02:03"));
+ dlDstCaseBuilder.setSetDlDstAction(dlDstBuilder.build());
+ actionBuilder.setActionChoice(dlDstCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetNwSrcCaseBuilder nwSrcCaseBuilder = new SetNwSrcCaseBuilder();
+ SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder();
+ nwSrcBuilder.setIpAddress(new Ipv4Address("10.0.0.1"));
+ nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build());
+ actionBuilder.setActionChoice(nwSrcCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetNwDstCaseBuilder nwDstCaseBuilder = new SetNwDstCaseBuilder();
+ SetNwDstActionBuilder nwDstBuilder = new SetNwDstActionBuilder();
+ nwDstBuilder.setIpAddress(new Ipv4Address("10.0.0.3"));
+ nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
+ actionBuilder.setActionChoice(nwDstCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetNwTosCaseBuilder tosCaseBuilder = new SetNwTosCaseBuilder();
+ SetNwTosActionBuilder tosBuilder = new SetNwTosActionBuilder();
+ tosBuilder.setNwTos((short) 204);
+ tosCaseBuilder.setSetNwTosAction(tosBuilder.build());
+ actionBuilder.setActionChoice(tosCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetTpSrcCaseBuilder tpSrcCaseBuilder = new SetTpSrcCaseBuilder();
+ SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder();
+ tpSrcBuilder.setPort(new PortNumber(6653L));
+ tpSrcCaseBuilder.setSetTpSrcAction(tpSrcBuilder.build());
+ actionBuilder.setActionChoice(tpSrcCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetTpDstCaseBuilder tpDstCaseBuilder = new SetTpDstCaseBuilder();
+ SetTpDstActionBuilder tpDstBuilder = new SetTpDstActionBuilder();
+ tpDstBuilder.setPort(new PortNumber(6633L));
+ tpDstCaseBuilder.setSetTpDstAction(tpDstBuilder.build());
+ actionBuilder.setActionChoice(tpDstCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ EnqueueCaseBuilder enqueueCaseBuilder = new EnqueueCaseBuilder();
+ EnqueueActionBuilder enqueueBuilder = new EnqueueActionBuilder();
+ enqueueBuilder.setPort(new PortNumber(6613L));
+ enqueueBuilder.setQueueId(new QueueId(400L));
+ enqueueCaseBuilder.setEnqueueAction(enqueueBuilder.build());
+ actionBuilder.setActionChoice(enqueueCaseBuilder.build());
+ actions.add(actionBuilder.build());
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+ ListSerializer.serializeList(actions, TypeKeyMakerFactory
+ .createActionKeyMaker(EncodeConstants.OF10_VERSION_ID), registry, out);
+
+ Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong port", 42, out.readUnsignedShort());
+ Assert.assertEquals("Wrong max-length", 32, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action type", 1, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong vlan-vid", 15, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 2, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong vlan-pcp", 16, out.readUnsignedByte());
+ out.skipBytes(3);
+ Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 4, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
+ byte[] data = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
+ out.readBytes(data);
+ Assert.assertArrayEquals("Wrong dl-address", ByteBufUtils.macAddressToBytes("00:00:00:02:03:04"), data);
+ out.skipBytes(6);
+ Assert.assertEquals("Wrong action type", 5, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
+ data = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
+ out.readBytes(data);
+ Assert.assertArrayEquals("Wrong dl-address", ByteBufUtils.macAddressToBytes("00:00:00:01:02:03"), data);
+ out.skipBytes(6);
+ Assert.assertEquals("Wrong action type", 6, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong ip-address(1)", 10, out.readUnsignedByte());
+ Assert.assertEquals("Wrong ip-address(2)", 0, out.readUnsignedByte());
+ Assert.assertEquals("Wrong ip-address(3)", 0, out.readUnsignedByte());
+ Assert.assertEquals("Wrong ip-address(4)", 1, out.readUnsignedByte());
+ Assert.assertEquals("Wrong action type", 7, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong ip-address(1)", 10, out.readUnsignedByte());
+ Assert.assertEquals("Wrong ip-address(2)", 0, out.readUnsignedByte());
+ Assert.assertEquals("Wrong ip-address(3)", 0, out.readUnsignedByte());
+ Assert.assertEquals("Wrong ip-address(4)", 3, out.readUnsignedByte());
+ Assert.assertEquals("Wrong action type", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong nw-tos", 204, out.readUnsignedByte());
+ out.skipBytes(3);
+ Assert.assertEquals("Wrong action type", 9, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong port", 6653, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 10, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong port", 6633, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 11, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
+ Assert.assertEquals("Wrong port", 6613, out.readUnsignedShort());
+ out.skipBytes(6);
+ Assert.assertEquals("Wrong queue-id", 400, out.readUnsignedInt());
+ Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0);
+ }
+