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);
}
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);
}
Aggregations