Search in sources :

Example 6 with PacketOutInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder in project openflowplugin by opendaylight.

the class OF10PacketOutInputMessageFactoryTest method testPacketOutInputMessage.

/**
 * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testPacketOutInputMessage() throws Exception {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setBufferId(256L);
    builder.setInPort(new PortNumber(257L));
    final List<Action> actions = new ArrayList<>();
    OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
    OutputActionBuilder outputBuilder = new OutputActionBuilder();
    outputBuilder.setPort(new PortNumber(42L));
    outputBuilder.setMaxLength(50);
    caseBuilder.setOutputAction(outputBuilder.build());
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(caseBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new StripVlanCaseBuilder().build());
    builder.setAction(actions);
    actions.add(actionBuilder.build());
    builder.setAction(actions);
    builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"));
    PacketOutInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    packetOutFactory.serialize(message, out);
    BufferHelper.checkHeaderV10(out, (byte) 13, 48);
    Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt());
    Assert.assertEquals("Wrong PortNumber", 257, out.readUnsignedShort());
    Assert.assertEquals("Wrong actions length", 16, out.readUnsignedShort());
    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 maxlength", 50, out.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    byte[] readData = new byte[out.readableBytes()];
    out.readBytes(readData);
    Assert.assertArrayEquals("Wrong data", message.getData(), readData);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder) StripVlanCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder) PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) ArrayList(java.util.ArrayList) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) ByteBuf(io.netty.buffer.ByteBuf) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Example 7 with PacketOutInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder in project openflowplugin by opendaylight.

the class PacketOutInputMessageFactoryTest method testPacketOutInputMessage.

/**
 * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testPacketOutInputMessage() throws Exception {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setBufferId(256L);
    builder.setInPort(new PortNumber(256L));
    final List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    PushVlanCaseBuilder pushVlanCaseBuilder = new PushVlanCaseBuilder();
    PushVlanActionBuilder pushVlanBuilder = new PushVlanActionBuilder();
    pushVlanBuilder.setEthertype(new EtherType(new EtherType(25)));
    pushVlanCaseBuilder.setPushVlanAction(pushVlanBuilder.build());
    actionBuilder.setActionChoice(pushVlanCaseBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new PopVlanCaseBuilder().build());
    actions.add(actionBuilder.build());
    builder.setAction(actions);
    builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"));
    PacketOutInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    packetOutFactory.serialize(message, out);
    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56);
    Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong ActionsLength", 16, out.readUnsignedShort());
    out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE);
    Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong ethertype", 25, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(PADDING_IN_ACTION_HEADER);
    byte[] readData = new byte[out.readableBytes()];
    out.readBytes(readData);
    Assert.assertArrayEquals("Wrong data", message.getData(), readData);
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) PushVlanActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder) PopVlanCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCaseBuilder) ArrayList(java.util.ArrayList) EtherType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType) ByteBuf(io.netty.buffer.ByteBuf) PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) PushVlanCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder) PushVlanActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Aggregations

Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)7 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)7 PacketOutInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder)7 ArrayList (java.util.ArrayList)5 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)4 PacketOutInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput)4 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)3 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)2 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder)2 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder)2 List (java.util.List)1 ActionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData)1 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)1 PopVlanCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCaseBuilder)1 PushVlanCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder)1 StripVlanCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder)1 PushVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder)1 EtherType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType)1 PathArgument (org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument)1