Added unit tests for Error and Vendor/Experimenter message factories
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10StatsReplyMessageFactoryTest.java
index 438f9b2ea78ac1dfe7b0250a66fc1c1cf183b81e..d5a1c779468703a293481e6fb273398eaccbbbe2 100644 (file)
@@ -12,15 +12,20 @@ import io.netty.buffer.ByteBuf;
 import java.math.BigInteger;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;\r
@@ -42,6 +47,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public class OF10StatsReplyMessageFactoryTest {\r
 \r
+    private OFDeserializer<MultipartReplyMessage> statsFactory;\r
+\r
+    /**\r
+     * Initializes deserializer registry and lookups correct deserializer\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        DeserializerRegistry registry = new DeserializerRegistryImpl();\r
+        registry.init();\r
+        statsFactory = registry.getDeserializer(\r
+                new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 17, MultipartReplyMessage.class));\r
+    }\r
+\r
     /**\r
      * Testing OF10StatsReplyMessageFactory (Desc) for correct deserialization\r
      */\r
@@ -55,33 +73,33 @@ public class OF10StatsReplyMessageFactoryTest {
         byte[] mfrDescBytes = new byte[256];\r
         mfrDescBytes = mfrDesc.getBytes();\r
         bb.writeBytes(mfrDescBytes);\r
-        ByteBufUtils.padBuffer((DESC_STR_LEN - mfrDescBytes.length), bb);\r
+        bb.writeZero(DESC_STR_LEN - mfrDescBytes.length);\r
         \r
         String hwDesc = "Hardware description";\r
         byte[] hwDescBytes = new byte[256];\r
         hwDescBytes = hwDesc.getBytes();\r
         bb.writeBytes(hwDescBytes);\r
-        ByteBufUtils.padBuffer((DESC_STR_LEN - hwDescBytes.length), bb);\r
+        bb.writeZero(DESC_STR_LEN - hwDescBytes.length);\r
         \r
         String swDesc = "Software description";\r
         byte[] swDescBytes = new byte[256];\r
         swDescBytes = swDesc.getBytes();\r
         bb.writeBytes(swDescBytes);\r
-        ByteBufUtils.padBuffer((DESC_STR_LEN - swDescBytes.length), bb);\r
+        bb.writeZero(DESC_STR_LEN - swDescBytes.length);\r
         \r
         String serialNum = "SN0123456789";\r
         byte[] serialNumBytes = new byte[32];\r
         serialNumBytes = serialNum.getBytes();\r
         bb.writeBytes(serialNumBytes);\r
-        ByteBufUtils.padBuffer((SERIAL_NUM_LEN - serialNumBytes.length), bb);\r
+        bb.writeZero(SERIAL_NUM_LEN - serialNumBytes.length);\r
         \r
         String dpDesc = "switch3 in room 3120";\r
         byte[] dpDescBytes = new byte[256];\r
         dpDescBytes = dpDesc.getBytes();\r
         bb.writeBytes(dpDescBytes);\r
-        ByteBufUtils.padBuffer((DESC_STR_LEN - dpDescBytes.length), bb);\r
+        bb.writeZero(DESC_STR_LEN - dpDescBytes.length);\r
         \r
-        MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb);\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
         \r
         BufferHelper.checkHeaderV10(builtByFactory);\r
         Assert.assertEquals("Wrong type", 0, builtByFactory.getType().getIntValue());\r
@@ -105,11 +123,10 @@ public class OF10StatsReplyMessageFactoryTest {
                 + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "\r
                 + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "\r
                 + "00 00 00 02 00 00 00 03 00 04 00 05 00 06 00 00 00 00 00 00 "\r
-                + "00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 00 00 00 00 00 00 20 "\r
+                + "FF 01 02 03 04 05 06 07 FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 "\r
                 + "00 00 00 08 00 01 00 02 00 01 00 08 00 03 00 00");\r
         \r
-        MultipartReplyMessage builtByFactory = \r
-                BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb);\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
 \r
         BufferHelper.checkHeaderV10(builtByFactory);\r
         Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());\r
@@ -123,21 +140,21 @@ public class OF10StatsReplyMessageFactoryTest {
         Assert.assertEquals("Wrong idleTimeOut", 5, message.getFlowStats().get(0).getIdleTimeout().intValue());\r
         Assert.assertEquals("Wrong hardTimeOut", 6, message.getFlowStats().get(0).getHardTimeout().intValue());\r
         Assert.assertEquals("Wrong cookie",\r
-                new BigInteger(new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}), \r
                 message.getFlowStats().get(0).getCookie());\r
         Assert.assertEquals("Wrong packetCount",\r
-                new BigInteger(new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}), \r
                 message.getFlowStats().get(0).getPacketCount());\r
         Assert.assertEquals("Wrong byteCount",\r
-                new BigInteger(new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}), \r
                 message.getFlowStats().get(0).getByteCount());\r
-        Action action1 = message.getFlowStats().get(0).getActionsList().get(0).getAction();\r
+        Action action1 = message.getFlowStats().get(0).getAction().get(0);\r
         Assert.assertEquals("Wrong action type", Output.class, action1.getType());\r
         Assert.assertEquals("Wrong action port", 1, action1.getAugmentation(PortAction.class)\r
                 .getPort().getValue().intValue());\r
         Assert.assertEquals("Wrong action port", 2, action1.getAugmentation(MaxLengthAction.class)\r
                 .getMaxLength().intValue());\r
-        Action action2 = message.getFlowStats().get(0).getActionsList().get(1).getAction();\r
+        Action action2 = message.getFlowStats().get(0).getAction().get(1);\r
         Assert.assertEquals("Wrong action type", SetVlanVid.class, action2.getType());\r
         Assert.assertEquals("Wrong action port", 3, action2.getAugmentation(VlanVidAction.class)\r
                 .getVlanVid().intValue());\r
@@ -150,10 +167,9 @@ public class OF10StatsReplyMessageFactoryTest {
     @Test\r
     public void testAggregate() {\r
         ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 "\r
-                + "00 01 02 03 04 05 06 07 00 00 00 00 00 00 00 20 00 00 00 30 00 00 00 00");\r
+                + "FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 00 00 00 30 00 00 00 00");\r
         \r
-        MultipartReplyMessage builtByFactory = \r
-                BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb);\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
 \r
         BufferHelper.checkHeaderV10(builtByFactory);\r
         Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue());\r
@@ -161,10 +177,10 @@ public class OF10StatsReplyMessageFactoryTest {
         MultipartReplyAggregateCase messageCase = (MultipartReplyAggregateCase) builtByFactory.getMultipartReplyBody();\r
         MultipartReplyAggregate message = messageCase.getMultipartReplyAggregate();\r
         Assert.assertEquals("Wrong packet-count",\r
-                new BigInteger(new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}), \r
                 message.getPacketCount());\r
         Assert.assertEquals("Wrong byte-count",\r
-                new BigInteger(new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}), \r
                 message.getByteCount());\r
         Assert.assertEquals("Wrong flow-count", 48, message.getFlowCount().intValue());\r
         Assert.assertTrue("Unread data", bb.readableBytes() == 0);\r
@@ -178,9 +194,9 @@ public class OF10StatsReplyMessageFactoryTest {
         ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 "\r
                 + "08 00 00 00 4A 41 4D 45 53 20 42 4F 4E 44 00 00 00 00 00 00 00 00 00 "\r
                 + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "\r
-                + "00 00 00 30 00 00 00 10 00 01 01 01 01 01 01 01 02 01 01 01 01 01 01 00");\r
+                + "00 00 00 30 00 00 00 10 FF 01 01 01 01 01 01 01 FF 01 01 01 01 01 01 00");\r
 \r
-        MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb);\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
 \r
         BufferHelper.checkHeaderV10(builtByFactory);\r
         Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());\r
@@ -197,10 +213,10 @@ public class OF10StatsReplyMessageFactoryTest {
         Assert.assertEquals("Wrong max-entries", 48, message.getTableStats().get(0).getMaxEntries().longValue());\r
         Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());\r
         Assert.assertEquals("Wrong lookupCount", \r
-                new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), \r
                 message.getTableStats().get(0).getLookupCount());\r
         Assert.assertEquals("Wrong matchedCount", \r
-                new BigInteger(new byte[]{0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}), \r
                 message.getTableStats().get(0).getMatchedCount());\r
         Assert.assertTrue("Unread data", bb.readableBytes() == 0);\r
     }\r
@@ -212,14 +228,14 @@ public class OF10StatsReplyMessageFactoryTest {
     public void testPort() {\r
         ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 "\r
                 + "00 FF 00 00 00 00 00 00 "\r
-                + "00 01 01 01 01 01 01 01 00 02 02 02 02 02 02 02 "\r
-                + "00 02 03 02 03 02 03 02 00 02 03 02 03 02 03 02 "\r
-                + "00 02 03 02 03 02 03 02 00 02 03 02 03 02 03 02 "\r
-                + "00 02 03 02 03 02 03 02 00 02 03 02 03 02 03 02 "\r
-                + "00 02 03 02 03 02 03 02 00 02 03 02 03 02 03 02 00 02 03 02 03 02 03 02 "\r
-                + "00 02 03 02 03 02 03 02 ");\r
+                + "FF 01 01 01 01 01 01 01 FF 02 02 02 02 02 02 02 "\r
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
+                + "FF 02 03 02 03 02 03 02");\r
 \r
-        MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb);\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
 \r
         BufferHelper.checkHeaderV10(builtByFactory);\r
         Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue());\r
@@ -228,40 +244,40 @@ public class OF10StatsReplyMessageFactoryTest {
         MultipartReplyPortStats message = messageCase.getMultipartReplyPortStats();\r
         Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue());\r
         Assert.assertEquals("Wrong rxPackets", \r
-                new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), \r
                 message.getPortStats().get(0).getRxPackets());\r
         Assert.assertEquals("Wrong txPackets", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), \r
                 message.getPortStats().get(0).getTxPackets());\r
         Assert.assertEquals("Wrong rxBytes", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getRxBytes());\r
         Assert.assertEquals("Wrong txBytes", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getTxBytes());\r
         Assert.assertEquals("Wrong rxDropped", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getRxDropped());\r
         Assert.assertEquals("Wrong txDropped", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getTxDropped());\r
         Assert.assertEquals("Wrong rxErrors", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getRxErrors());\r
         Assert.assertEquals("Wrong txErrors", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getTxErrors());\r
         Assert.assertEquals("Wrong rxFrameErr", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getRxFrameErr());\r
         Assert.assertEquals("Wrong rxOverErr", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getRxOverErr());\r
         Assert.assertEquals("Wrong rxCrcErr", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getRxCrcErr());\r
         Assert.assertEquals("Wrong collisions", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getPortStats().get(0).getCollisions());\r
         Assert.assertTrue("Unread data", bb.readableBytes() == 0);\r
     }\r
@@ -273,11 +289,11 @@ public class OF10StatsReplyMessageFactoryTest {
     public void testQueue() {\r
         ByteBuf bb = BufferHelper.buildBuffer("00 05 00 00 "\r
                 + "00 FF 00 00 00 00 00 10 "\r
-                + "00 02 03 02 03 02 03 02 "\r
-                + "00 02 02 02 02 02 02 02 "\r
-                + "00 02 03 02 03 02 03 02 ");\r
+                + "FF 02 03 02 03 02 03 02 "\r
+                + "FF 02 02 02 02 02 02 02 "\r
+                + "FF 02 03 02 03 02 03 02");\r
 \r
-        MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb);\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
 \r
         BufferHelper.checkHeaderV10(builtByFactory);\r
         Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue());\r
@@ -287,13 +303,13 @@ public class OF10StatsReplyMessageFactoryTest {
         Assert.assertEquals("Wrong portNo", 255, message.getQueueStats().get(0).getPortNo().intValue());\r
         Assert.assertEquals("Wrong queueId", 16, message.getQueueStats().get(0).getQueueId().intValue());\r
         Assert.assertEquals("Wrong txBytes", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getQueueStats().get(0).getTxBytes());\r
         Assert.assertEquals("Wrong txPackets", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), \r
                 message.getQueueStats().get(0).getTxPackets());\r
         Assert.assertEquals("Wrong txErrors", \r
-                new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), \r
                 message.getQueueStats().get(0).getTxErrors());\r
         Assert.assertTrue("Unread data", bb.readableBytes() == 0);\r
     }\r