X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FOF10PacketInMessageFactoryTest.java;h=53ed80fcd0a3fc1bda0339f02eba3d6d2caeb41f;hb=e149a02d7ccbdc4ea67863bbfc92fc141e89d2dd;hp=11ec46b3f452184a4636bed1b3c5443debc9d874;hpb=3d6680258cc25e4e8ec0476c947b2a6f3b1ce96d;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java index 11ec46b3..53ed80fc 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java @@ -1,30 +1,69 @@ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; - -public class OF10PacketInMessageFactoryTest { - - /** - * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04"); - PacketInMessage builtByFactory = BufferHelper.decodeV10(OF10PacketInMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); - Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); - Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue()); - Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason()); - Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); - } - -} +/* + * 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.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; + +/** + * @author michal.polkorab + */ +public class OF10PacketInMessageFactoryTest { + + private OFDeserializer packetInFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + packetInFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 10, PacketInMessage.class)); + } + + /** + * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04"); + PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); + Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); + Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue()); + Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason()); + Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); + } + + /** + * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO + */ + @Test + public void testWithNoAdditionalData(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00"); + PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); + + Assert.assertNull("Wrong data", builtByFactory.getData()); + } +} \ No newline at end of file