-/*\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.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;\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.MplsTtlAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;\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.PortNumberMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;\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.common.action.rev130731.CopyTtlIn;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;\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.PopMpls;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;\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.EtherType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;\r
-\r
-/**\r
- * @author michal.polkorab\r
- * \r
- */\r
-public class OF13ActionsSerializerTest {\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\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 port = new PortActionBuilder();\r
- port.setPort(new PortNumber(42L));\r
- actionBuilder.addAugmentation(PortAction.class, port.build());\r
- MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();\r
- maxLen.setMaxLength(52);\r
- actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(CopyTtlOut.class);\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(CopyTtlIn.class);\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetMplsTtl.class);\r
- MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder();\r
- mplsTtl.setMplsTtl((short) 4);\r
- actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(DecMplsTtl.class);\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(PushVlan.class);\r
- EthertypeActionBuilder etherType = new EthertypeActionBuilder();\r
- etherType.setEthertype(new EtherType(16));\r
- actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(PopVlan.class);\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(PushMpls.class);\r
- etherType = new EthertypeActionBuilder();\r
- etherType.setEthertype(new EtherType(17));\r
- actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(PopMpls.class);\r
- etherType = new EthertypeActionBuilder();\r
- etherType.setEthertype(new EtherType(18));\r
- actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetQueue.class);\r
- QueueIdActionBuilder queueId = new QueueIdActionBuilder();\r
- queueId.setQueueId(1234L);\r
- actionBuilder.addAugmentation(QueueIdAction.class, queueId.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Group.class);\r
- GroupIdActionBuilder group = new GroupIdActionBuilder();\r
- group.setGroupId(555L);\r
- actionBuilder.addAugmentation(GroupIdAction.class, group.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetNwTtl.class);\r
- NwTtlActionBuilder nwTtl = new NwTtlActionBuilder();\r
- nwTtl.setNwTtl((short) 8);\r
- actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(DecNwTtl.class);\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetField.class);\r
- OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();\r
- List<MatchEntries> entries = new ArrayList<>();\r
- MatchEntriesBuilder matchBuilder = new MatchEntriesBuilder();\r
- matchBuilder.setOxmClass(OpenflowBasicClass.class);\r
- matchBuilder.setOxmMatchField(InPort.class);\r
- matchBuilder.setHasMask(false);\r
- PortNumberMatchEntryBuilder portBuilder = new PortNumberMatchEntryBuilder();\r
- portBuilder.setPortNumber(new PortNumber(1L));\r
- matchBuilder.addAugmentation(PortNumberMatchEntry.class, portBuilder.build());\r
- entries.add(matchBuilder.build());\r
- matchEntries.setMatchEntries(entries);\r
- actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(PushPbb.class);\r
- etherType = new EthertypeActionBuilder();\r
- etherType.setEthertype(new EtherType(19));\r
- actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());\r
- actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(PopPbb.class);\r
- actions.add(actionBuilder.build());\r
- \r
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- ListSerializer.serializeList(actions, TypeKeyMakerFactory\r
- .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);\r
- \r
- Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action port", 42, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong action max-length", 52, out.readUnsignedShort());\r
- out.skipBytes(6);\r
- Assert.assertEquals("Wrong action type", 11, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 12, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 15, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action mpls-ttl", 4, out.readUnsignedByte());\r
- out.skipBytes(3);\r
- Assert.assertEquals("Wrong action type", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action ethertype", 16, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 19, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action ethertype", 17, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 20, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action ethertype", 18, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 21, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action queue-id", 1234, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong action type", 22, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action group", 555, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action nw-ttl", 8, out.readUnsignedByte());\r
- out.skipBytes(3);\r
- Assert.assertEquals("Wrong action type", 24, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 25, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong match entry field & mask", 0, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedInt());\r
- out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 26, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action ethertype", 19, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- out.skipBytes(4);\r
- Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
- }\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.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCaseBuilder;
+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.PopMplsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.group._case.GroupActionBuilder;
+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.pop.mpls._case.PopMplsActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.pbb._case.PushPbbActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.mpls.ttl._case.SetMplsTtlActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.ttl._case.SetNwTtlActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.queue._case.SetQueueActionBuilder;
+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.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.port._case.InPortBuilder;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF13ActionsSerializerTest {
+
+ 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
+ */
+ @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(52);
+ caseBuilder.setOutputAction(outputBuilder.build());
+ actionBuilder.setActionChoice(caseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetMplsTtlCaseBuilder setMplsTtlCaseBuilder = new SetMplsTtlCaseBuilder();
+ SetMplsTtlActionBuilder setMplsTtlBuilder = new SetMplsTtlActionBuilder();
+ setMplsTtlBuilder.setMplsTtl((short) 4);
+ setMplsTtlCaseBuilder.setSetMplsTtlAction(setMplsTtlBuilder.build());
+ actionBuilder.setActionChoice(setMplsTtlCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new DecMplsTtlCaseBuilder().build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ PushVlanCaseBuilder pushVlanCaseBuilder = new PushVlanCaseBuilder();
+ PushVlanActionBuilder pushVlanBuilder = new PushVlanActionBuilder();
+ pushVlanBuilder.setEthertype(new EtherType(new EtherType(16)));
+ pushVlanCaseBuilder.setPushVlanAction(pushVlanBuilder.build());
+ actionBuilder.setActionChoice(pushVlanCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new PopVlanCaseBuilder().build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ PushMplsCaseBuilder pushMplsCaseBuilder = new PushMplsCaseBuilder();
+ PushMplsActionBuilder pushMplsBuilder = new PushMplsActionBuilder();
+ pushMplsBuilder.setEthertype(new EtherType(new EtherType(17)));
+ pushMplsCaseBuilder.setPushMplsAction(pushMplsBuilder.build());
+ actionBuilder.setActionChoice(pushMplsCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ PopMplsCaseBuilder popMplsCaseBuilder = new PopMplsCaseBuilder();
+ PopMplsActionBuilder popMplsBuilder = new PopMplsActionBuilder();
+ popMplsBuilder.setEthertype(new EtherType(new EtherType(18)));
+ popMplsCaseBuilder.setPopMplsAction(popMplsBuilder.build());
+ actionBuilder.setActionChoice(popMplsCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetQueueCaseBuilder setQueueCaseBuilder = new SetQueueCaseBuilder();
+ SetQueueActionBuilder setQueueBuilder = new SetQueueActionBuilder();
+ setQueueBuilder.setQueueId(1234L);
+ setQueueCaseBuilder.setSetQueueAction(setQueueBuilder.build());
+ actionBuilder.setActionChoice(setQueueCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ GroupCaseBuilder groupCaseBuilder = new GroupCaseBuilder();
+ GroupActionBuilder groupActionBuilder = new GroupActionBuilder();
+ groupActionBuilder.setGroupId(555L);
+ groupCaseBuilder.setGroupAction(groupActionBuilder.build());
+ actionBuilder.setActionChoice(groupCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetNwTtlCaseBuilder nwTtlCaseBuilder = new SetNwTtlCaseBuilder();
+ SetNwTtlActionBuilder nwTtlBuilder = new SetNwTtlActionBuilder();
+ nwTtlBuilder.setNwTtl((short) 8);
+ nwTtlCaseBuilder.setSetNwTtlAction(nwTtlBuilder.build());
+ actionBuilder.setActionChoice(nwTtlCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
+ SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
+ List<MatchEntry> entries = new ArrayList<>();
+ MatchEntryBuilder matchBuilder = new MatchEntryBuilder();
+ matchBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchBuilder.setOxmMatchField(InPort.class);
+ matchBuilder.setHasMask(false);
+ InPortCaseBuilder inPortCaseBuilder = new InPortCaseBuilder();
+ InPortBuilder inPortBuilder = new InPortBuilder();
+ inPortBuilder.setPortNumber(new PortNumber(1L));
+ inPortCaseBuilder.setInPort(inPortBuilder.build());
+ matchBuilder.setMatchEntryValue(inPortCaseBuilder.build());
+ entries.add(matchBuilder.build());
+ setFieldBuilder.setMatchEntry(entries);
+ setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
+ actionBuilder.setActionChoice(setFieldCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ PushPbbCaseBuilder pushPbbCaseBuilder = new PushPbbCaseBuilder();
+ PushPbbActionBuilder pushPbbBuilder = new PushPbbActionBuilder();
+ pushPbbBuilder.setEthertype(new EtherType(new EtherType(19)));
+ pushPbbCaseBuilder.setPushPbbAction(pushPbbBuilder.build());
+ actionBuilder.setActionChoice(pushPbbCaseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
+ actions.add(actionBuilder.build());
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+ ListSerializer.serializeList(actions, TypeKeyMakerFactory
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);
+
+ Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action port", 42, out.readUnsignedInt());
+ Assert.assertEquals("Wrong action max-length", 52, out.readUnsignedShort());
+ out.skipBytes(6);
+ Assert.assertEquals("Wrong action type", 11, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 12, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 15, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action mpls-ttl", 4, out.readUnsignedByte());
+ out.skipBytes(3);
+ Assert.assertEquals("Wrong action type", 16, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action ethertype", 16, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 19, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action ethertype", 17, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 20, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action ethertype", 18, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 21, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action queue-id", 1234, out.readUnsignedInt());
+ Assert.assertEquals("Wrong action type", 22, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action group", 555, out.readUnsignedInt());
+ Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action nw-ttl", 8, out.readUnsignedByte());
+ out.skipBytes(3);
+ Assert.assertEquals("Wrong action type", 24, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 25, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
+ Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());
+ Assert.assertEquals("Wrong match entry field & mask", 0, out.readUnsignedByte());
+ Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());
+ Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedInt());
+ out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 26, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action ethertype", 19, out.readUnsignedShort());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertTrue("Unread data", out.readableBytes() == 0);
+ }
+
+ /**
+ * Testing correct serialization of actions
+ */
+ @Test
+ public void testHeaders() {
+ List<Action> actions = new ArrayList<>();
+ ActionBuilder actionBuilder = new ActionBuilder();
+ OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
+ OutputActionBuilder outputBuilder = new OutputActionBuilder();
+ outputBuilder.setPort(new PortNumber(42L));
+ outputBuilder.setMaxLength(52);
+ caseBuilder.setOutputAction(outputBuilder.build());
+ actionBuilder.setActionChoice(caseBuilder.build());
+ actions.add(actionBuilder.build());
+ actionBuilder = new ActionBuilder();
+ SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
+ SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
+ List<MatchEntry> entries = new ArrayList<>();
+ MatchEntryBuilder matchBuilder = new MatchEntryBuilder();
+ matchBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchBuilder.setOxmMatchField(InPort.class);
+ matchBuilder.setHasMask(false);
+ InPortCaseBuilder inPortCaseBuilder = new InPortCaseBuilder();
+ InPortBuilder inPortBuilder = new InPortBuilder();
+ inPortBuilder.setPortNumber(new PortNumber(1L));
+ inPortCaseBuilder.setInPort(inPortBuilder.build());
+ matchBuilder.setMatchEntryValue(inPortCaseBuilder.build());
+ entries.add(matchBuilder.build());
+ setFieldBuilder.setMatchEntry(entries);
+ setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
+ actionBuilder.setActionChoice(setFieldCaseBuilder.build());
+ actions.add(actionBuilder.build());
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+ ListSerializer.serializeHeaderList(actions, TypeKeyMakerFactory
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);
+
+ Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 4, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action type", 25, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 4, out.readUnsignedShort());
+ Assert.assertTrue("Unread data", out.readableBytes() == 0);
+ }
+}
\ No newline at end of file