X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Futil%2FOF10ActionsSerializerTest.java;h=f66aa0616ecbb4a4a883708dae43a4b67983d1ee;hb=5f5622e79402f70a944fa93fd7ee2d84d1776b08;hp=bb7930918fdcaf338a8920a6a34eb2874b433b4e;hpb=26aeaa7e2754b2cf4f6ad63055ab3ce34f68c961;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java index bb793091..f66aa061 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java @@ -1,244 +1,222 @@ -/* - * 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.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.augments.rev131002.DlAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; - -/** - * @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 actions = new ArrayList<>(); - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Output.class); - PortActionBuilder portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber(42L)); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); - maxLen.setMaxLength(32); - actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetVlanVid.class); - VlanVidActionBuilder vlanBuilder = new VlanVidActionBuilder(); - vlanBuilder.setVlanVid(15); - actionBuilder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetVlanPcp.class); - VlanPcpActionBuilder pcpBuilder = new VlanPcpActionBuilder(); - pcpBuilder.setVlanPcp((short) 16); - actionBuilder.addAugmentation(VlanPcpAction.class, pcpBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(StripVlan.class); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetDlSrc.class); - DlAddressActionBuilder dlBuilder = new DlAddressActionBuilder(); - dlBuilder.setDlAddress(new MacAddress("00:00:00:02:03:04")); - actionBuilder.addAugmentation(DlAddressAction.class, dlBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetDlDst.class); - dlBuilder = new DlAddressActionBuilder(); - dlBuilder.setDlAddress(new MacAddress("00:00:00:01:02:03")); - actionBuilder.addAugmentation(DlAddressAction.class, dlBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwSrc.class); - IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); - ipBuilder.setIpAddress(new Ipv4Address("10.0.0.1")); - actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwDst.class); - ipBuilder = new IpAddressActionBuilder(); - ipBuilder.setIpAddress(new Ipv4Address("10.0.0.3")); - actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwTos.class); - NwTosActionBuilder tosBuilder = new NwTosActionBuilder(); - tosBuilder.setNwTos((short) 204); - actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetTpSrc.class); - portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber(6653L)); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetTpDst.class); - portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber(6633L)); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Enqueue.class); - portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber(6613L)); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - QueueIdActionBuilder queueBuilder = new QueueIdActionBuilder(); - queueBuilder.setQueueId(400L); - actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(82L); - byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1}; - expBuilder.setData(expData); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(102L); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory - .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.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 82, out.readUnsignedInt()); - byte[] tmp = new byte[8]; - out.readBytes(tmp); - Assert.assertArrayEquals("Wrong data", expData, tmp); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 102, out.readUnsignedInt()); - Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0); - } - +/* + * 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 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); + } + } \ No newline at end of file