X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fserialization%2Ffactories%2FPacketOutInputMessageFactoryTest.java;h=5da3a53d8ed62f84ff5be28b911851cbe27462d2;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=292bca15d4dc56e47ee9e5db47fc6f988cc0e3ec;hpb=a4af04c204a636b6c0782cc2248068e0860a69ad;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java index 292bca15..5da3a53d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java @@ -15,11 +15,15 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; @@ -39,10 +43,23 @@ public class PacketOutInputMessageFactoryTest { private static final byte MESSAGE_TYPE = 13; private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; private static final int PADDING_IN_ACTION_HEADER = 4; - + private SerializerRegistry registry; + private OFSerializer packetOutFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + packetOutFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, PacketOutInput.class)); + } + /** * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO - * @throws Exception + * @throws Exception */ @Test public void testPacketOutInputMessage() throws Exception { @@ -63,11 +80,10 @@ public class PacketOutInputMessageFactoryTest { 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(); - PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - + 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()); @@ -82,4 +98,27 @@ public class PacketOutInputMessageFactoryTest { out.skipBytes(PADDING_IN_ACTION_HEADER); Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array()); } -} + + /** + * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testPacketOutInputWithNoData() throws Exception { + PacketOutInputBuilder builder = new PacketOutInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setBufferId(256L); + builder.setInPort(new PortNumber(256L)); + List actions = new ArrayList<>(); + builder.setAction(actions); + builder.setData(null); + PacketOutInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + packetOutFactory.serialize(message, out); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 24); + out.skipBytes(16); // skip packet out message to data index + Assert.assertTrue("Unexpected data", out.readableBytes() == 0); + } +} \ No newline at end of file