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%2FActionsDeserializerTest.java;h=e0dfb8f70d1261ede3a73b9da076a12da6b5c01c;hb=632f1b4f5c0fca12f8f48eef64c78e0f48fa55e4;hp=a63edea95735bf90c54ff2624fd5b25cf1e71df5;hpb=6cd66ac6ecd35ddd17b9a489633a2443464e8581;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java index a63edea9..e0dfb8f7 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java @@ -12,9 +12,13 @@ import io.netty.buffer.ByteBuf; import java.util.List; 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.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.AbstractActionDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; @@ -36,6 +40,17 @@ public class ActionsDeserializerTest { private static final Logger LOGGER = LoggerFactory .getLogger(ActionsDeserializerTest.class); + private DeserializerRegistry registry; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + registry = new DeserializerRegistryImpl(); + registry.init(); + } + /** * Testing actions deserialization */ @@ -56,12 +71,14 @@ public class ActionsDeserializerTest { + "00 18 00 08 00 00 00 00 " + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 " + "00 1A 00 08 00 0A 00 00 " - + "00 1B 00 08 00 00 00 00 " - + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07"); + + "00 1B 00 08 00 00 00 00"); message.skipBytes(4); // skip XID LOGGER.info("bytes: " + message.readableBytes()); - List actions = ActionsDeserializer.createActions(message, message.readableBytes()); + + CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); + List actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, + message.readableBytes(), message, keyMaker, registry); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName()); Assert.assertEquals("Wrong action port", 1, @@ -123,13 +140,27 @@ public class ActionsDeserializerTest { actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName()); - Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." - + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName()); - Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class) - .getExperimenter().intValue()); - Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, actions.get(16) - .getAugmentation(ExperimenterAction.class).getData()); Assert.assertTrue("Unread data in message", message.readableBytes() == 0); } + /** + * Tests {@link AbstractActionDeserializer#deserializeHeader(ByteBuf)} + */ + @Test + public void testDeserializeHeader() { + ByteBuf message = BufferHelper.buildBuffer("00 00 00 04 00 19 00 04"); + + message.skipBytes(4); // skip XID + CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); + List actions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, + message.readableBytes(), message, keyMaker, registry); + + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName()); + Assert.assertEquals("Wrong action port", null, actions.get(0).getAugmentation(PortAction.class)); + Assert.assertEquals("Wrong action max-length", null, actions.get(0).getAugmentation(MaxLengthAction.class)); + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + + "openflow.common.action.rev130731.SetField", actions.get(1).getType().getName()); + Assert.assertEquals("Wrong action oxm field", null, actions.get(1).getAugmentation(OxmFieldsAction.class)); + } }