Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10StatsReplyMessageFactoryTest.java
index d5a1c779468703a293481e6fb273398eaccbbbe2..77ac5d912aa1a0df17ba2889d628954f96fbb70a 100644 (file)
-/*\r
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-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.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.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
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregate;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\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
-    @Test\r
-    public void testDesc() {\r
-        final int DESC_STR_LEN = 256;\r
-        final int SERIAL_NUM_LEN = 32;\r
-        ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00");\r
-        \r
-        String mfrDesc = "Manufacturer description";\r
-        byte[] mfrDescBytes = new byte[256];\r
-        mfrDescBytes = mfrDesc.getBytes();\r
-        bb.writeBytes(mfrDescBytes);\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
-        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
-        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
-        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
-        bb.writeZero(DESC_STR_LEN - dpDescBytes.length);\r
-        \r
-        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
-        \r
-        BufferHelper.checkHeaderV10(builtByFactory);\r
-        Assert.assertEquals("Wrong type", 0, builtByFactory.getType().getIntValue());\r
-        Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());\r
-        MultipartReplyDescCase messageCase = (MultipartReplyDescCase) builtByFactory.getMultipartReplyBody();\r
-        MultipartReplyDesc message = messageCase.getMultipartReplyDesc();\r
-        Assert.assertEquals("Wrong mfrDesc", "Manufacturer description", message.getMfrDesc());\r
-        Assert.assertEquals("Wrong hwDesc", "Hardware description", message.getHwDesc());\r
-        Assert.assertEquals("Wrong swDesc", "Software description", message.getSwDesc());\r
-        Assert.assertEquals("Wrong serialNum", "SN0123456789", message.getSerialNum());\r
-        Assert.assertEquals("Wrong dpDesc", "switch3 in room 3120", message.getDpDesc());\r
-        Assert.assertTrue("Unread data", bb.readableBytes() == 0);\r
-    }\r
-    \r
-    /**\r
-     * Testing OF10StatsReplyMessageFactory (Flow) for correct deserialization\r
-     */\r
-    @Test\r
-    public void testFlow() {\r
-        ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 68 01 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 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
-                + "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 = BufferHelper.deserialize(statsFactory, bb);\r
-\r
-        BufferHelper.checkHeaderV10(builtByFactory);\r
-        Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());\r
-        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());\r
-        MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();\r
-        MultipartReplyFlow message = messageCase.getMultipartReplyFlow();\r
-        Assert.assertEquals("Wrong tableId", 1, message.getFlowStats().get(0).getTableId().intValue());\r
-        Assert.assertEquals("Wrong durationSec", 2, message.getFlowStats().get(0).getDurationSec().intValue());\r
-        Assert.assertEquals("Wrong durationNsec", 3, message.getFlowStats().get(0).getDurationNsec().intValue());\r
-        Assert.assertEquals("Wrong priority", 4, message.getFlowStats().get(0).getPriority().intValue());\r
-        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(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(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(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).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).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
-        Assert.assertTrue("Unread data", bb.readableBytes() == 0);\r
-    }\r
-    \r
-    /**\r
-     * Testing OF10StatsReplyMessageFactory (Aggregate) for correct deserialization\r
-     */\r
-    @Test\r
-    public void testAggregate() {\r
-        ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 "\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 = BufferHelper.deserialize(statsFactory, bb);\r
-\r
-        BufferHelper.checkHeaderV10(builtByFactory);\r
-        Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue());\r
-        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());\r
-        MultipartReplyAggregateCase messageCase = (MultipartReplyAggregateCase) builtByFactory.getMultipartReplyBody();\r
-        MultipartReplyAggregate message = messageCase.getMultipartReplyAggregate();\r
-        Assert.assertEquals("Wrong packet-count",\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(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
-    }\r
-    \r
-    /**\r
-     * Testing OF10StatsReplyMessageFactory (Table) for correct deserialization\r
-     */\r
-    @Test\r
-    public void testTable() {\r
-        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 FF 01 01 01 01 01 01 01 FF 01 01 01 01 01 01 00");\r
-\r
-        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
-\r
-        BufferHelper.checkHeaderV10(builtByFactory);\r
-        Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());\r
-        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());\r
-\r
-        MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();\r
-        MultipartReplyTable message = messageCase.getMultipartReplyTable();\r
-        Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());\r
-        Assert.assertEquals("Wrong name", "JAMES BOND", message.getTableStats().get(0).getName());\r
-        Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, false, false, false, false,\r
-                false, false, false), message.getTableStats().get(0).getWildcards());\r
-        Assert.assertEquals("Wrong src-mask", 32, message.getTableStats().get(0).getNwSrcMask().intValue());\r
-        Assert.assertEquals("Wrong dst-mask", 32, message.getTableStats().get(0).getNwDstMask().intValue());\r
-        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(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(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
-    \r
-    /**\r
-     * Testing OF10StatsReplyMessageFactory (Port) for correct deserialization\r
-     */\r
-    @Test\r
-    public void testPort() {\r
-        ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 "\r
-                + "00 FF 00 00 00 00 00 00 "\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.deserialize(statsFactory, bb);\r
-\r
-        BufferHelper.checkHeaderV10(builtByFactory);\r
-        Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue());\r
-        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());\r
-        MultipartReplyPortStatsCase messageCase = (MultipartReplyPortStatsCase) builtByFactory.getMultipartReplyBody();\r
-        MultipartReplyPortStats message = messageCase.getMultipartReplyPortStats();\r
-        Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue());\r
-        Assert.assertEquals("Wrong rxPackets", \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(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(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(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(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(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(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(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(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(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(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(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
-    \r
-    /**\r
-     * Testing OF10StatsReplyMessageFactory (Queue) for correct deserialization\r
-     */\r
-    @Test\r
-    public void testQueue() {\r
-        ByteBuf bb = BufferHelper.buildBuffer("00 05 00 00 "\r
-                + "00 FF 00 00 00 00 00 10 "\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.deserialize(statsFactory, bb);\r
-\r
-        BufferHelper.checkHeaderV10(builtByFactory);\r
-        Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue());\r
-        Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());\r
-        MultipartReplyQueueCase messageCase = (MultipartReplyQueueCase) builtByFactory.getMultipartReplyBody();\r
-        MultipartReplyQueue message = messageCase.getMultipartReplyQueue();\r
-        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(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(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(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
-\r
-}\r
+/*
+ * 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 java.math.BigInteger;
+
+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.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.MaxLengthAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.PortAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.VlanVidAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF10StatsReplyMessageFactoryTest {
+
+    private OFDeserializer<MultipartReplyMessage> statsFactory;
+
+    /**
+     * Initializes deserializer registry and lookups correct deserializer
+     */
+    @Before
+    public void startUp() {
+        DeserializerRegistry registry = new DeserializerRegistryImpl();
+        registry.init();
+        statsFactory = registry.getDeserializer(
+                new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 17, MultipartReplyMessage.class));
+    }
+
+    /**
+     * Testing OF10StatsReplyMessageFactory (Desc) for correct deserialization
+     */
+    @Test
+    public void testDesc() {
+        final int DESC_STR_LEN = 256;
+        final int SERIAL_NUM_LEN = 32;
+        ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00");
+
+        String mfrDesc = "Manufacturer description";
+        byte[] mfrDescBytes = new byte[256];
+        mfrDescBytes = mfrDesc.getBytes();
+        bb.writeBytes(mfrDescBytes);
+        bb.writeZero(DESC_STR_LEN - mfrDescBytes.length);
+
+        String hwDesc = "Hardware description";
+        byte[] hwDescBytes = new byte[256];
+        hwDescBytes = hwDesc.getBytes();
+        bb.writeBytes(hwDescBytes);
+        bb.writeZero(DESC_STR_LEN - hwDescBytes.length);
+
+        String swDesc = "Software description";
+        byte[] swDescBytes = new byte[256];
+        swDescBytes = swDesc.getBytes();
+        bb.writeBytes(swDescBytes);
+        bb.writeZero(DESC_STR_LEN - swDescBytes.length);
+
+        String serialNum = "SN0123456789";
+        byte[] serialNumBytes = new byte[32];
+        serialNumBytes = serialNum.getBytes();
+        bb.writeBytes(serialNumBytes);
+        bb.writeZero(SERIAL_NUM_LEN - serialNumBytes.length);
+
+        String dpDesc = "switch3 in room 3120";
+        byte[] dpDescBytes = new byte[256];
+        dpDescBytes = dpDesc.getBytes();
+        bb.writeBytes(dpDescBytes);
+        bb.writeZero(DESC_STR_LEN - dpDescBytes.length);
+
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
+
+        BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong type", 0, builtByFactory.getType().getIntValue());
+        Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());
+        MultipartReplyDescCase messageCase = (MultipartReplyDescCase) builtByFactory.getMultipartReplyBody();
+        MultipartReplyDesc message = messageCase.getMultipartReplyDesc();
+        Assert.assertEquals("Wrong mfrDesc", "Manufacturer description", message.getMfrDesc());
+        Assert.assertEquals("Wrong hwDesc", "Hardware description", message.getHwDesc());
+        Assert.assertEquals("Wrong swDesc", "Software description", message.getSwDesc());
+        Assert.assertEquals("Wrong serialNum", "SN0123456789", message.getSerialNum());
+        Assert.assertEquals("Wrong dpDesc", "switch3 in room 3120", message.getDpDesc());
+        Assert.assertTrue("Unread data", bb.readableBytes() == 0);
+    }
+
+    /**
+     * Testing OF10StatsReplyMessageFactory (Flow) for correct deserialization
+     */
+    @Test
+    public void testFlow() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 68 01 00 "
+                + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
+                + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
+                + "00 00 00 02 00 00 00 03 00 04 00 05 00 06 00 00 00 00 00 00 "
+                + "FF 01 02 03 04 05 06 07 FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 "
+                + "00 00 00 08 00 01 00 02 00 01 00 08 00 03 00 00");
+
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
+
+        BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
+        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());
+        MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
+        MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
+        Assert.assertEquals("Wrong tableId", 1, message.getFlowStats().get(0).getTableId().intValue());
+        Assert.assertEquals("Wrong durationSec", 2, message.getFlowStats().get(0).getDurationSec().intValue());
+        Assert.assertEquals("Wrong durationNsec", 3, message.getFlowStats().get(0).getDurationNsec().intValue());
+        Assert.assertEquals("Wrong priority", 4, message.getFlowStats().get(0).getPriority().intValue());
+        Assert.assertEquals("Wrong idleTimeOut", 5, message.getFlowStats().get(0).getIdleTimeout().intValue());
+        Assert.assertEquals("Wrong hardTimeOut", 6, message.getFlowStats().get(0).getHardTimeout().intValue());
+        Assert.assertEquals("Wrong cookie",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}),
+                message.getFlowStats().get(0).getCookie());
+        Assert.assertEquals("Wrong packetCount",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}),
+                message.getFlowStats().get(0).getPacketCount());
+        Assert.assertEquals("Wrong byteCount",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}),
+                message.getFlowStats().get(0).getByteCount());
+        Action action1 = message.getFlowStats().get(0).getAction().get(0);
+        Assert.assertEquals("Wrong action type", Output.class, action1.getType());
+        Assert.assertEquals("Wrong action port", 1, action1.getAugmentation(PortAction.class)
+                .getPort().getValue().intValue());
+        Assert.assertEquals("Wrong action port", 2, action1.getAugmentation(MaxLengthAction.class)
+                .getMaxLength().intValue());
+        Action action2 = message.getFlowStats().get(0).getAction().get(1);
+        Assert.assertEquals("Wrong action type", SetVlanVid.class, action2.getType());
+        Assert.assertEquals("Wrong action port", 3, action2.getAugmentation(VlanVidAction.class)
+                .getVlanVid().intValue());
+        Assert.assertTrue("Unread data", bb.readableBytes() == 0);
+    }
+
+    /**
+     * Testing OF10StatsReplyMessageFactory (Aggregate) for correct deserialization
+     */
+    @Test
+    public void testAggregate() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 "
+                + "FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 00 00 00 30 00 00 00 00");
+
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
+
+        BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue());
+        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());
+        MultipartReplyAggregateCase messageCase = (MultipartReplyAggregateCase) builtByFactory.getMultipartReplyBody();
+        MultipartReplyAggregate message = messageCase.getMultipartReplyAggregate();
+        Assert.assertEquals("Wrong packet-count",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}),
+                message.getPacketCount());
+        Assert.assertEquals("Wrong byte-count",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}),
+                message.getByteCount());
+        Assert.assertEquals("Wrong flow-count", 48, message.getFlowCount().intValue());
+        Assert.assertTrue("Unread data", bb.readableBytes() == 0);
+    }
+
+    /**
+     * Testing OF10StatsReplyMessageFactory (Table) for correct deserialization
+     */
+    @Test
+    public void testTable() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 "
+                + "08 00 00 00 4A 41 4D 45 53 20 42 4F 4E 44 00 00 00 00 00 00 00 00 00 "
+                + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
+                + "00 00 00 30 00 00 00 10 FF 01 01 01 01 01 01 01 FF 01 01 01 01 01 01 00");
+
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
+
+        BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());
+        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
+
+        MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();
+        MultipartReplyTable message = messageCase.getMultipartReplyTable();
+        Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());
+        Assert.assertEquals("Wrong name", "JAMES BOND", message.getTableStats().get(0).getName());
+        Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, false, false, false, false,
+                false, false, false), message.getTableStats().get(0).getWildcards());
+        Assert.assertEquals("Wrong src-mask", 32, message.getTableStats().get(0).getNwSrcMask().intValue());
+        Assert.assertEquals("Wrong dst-mask", 32, message.getTableStats().get(0).getNwDstMask().intValue());
+        Assert.assertEquals("Wrong max-entries", 48, message.getTableStats().get(0).getMaxEntries().longValue());
+        Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());
+        Assert.assertEquals("Wrong lookupCount",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
+                message.getTableStats().get(0).getLookupCount());
+        Assert.assertEquals("Wrong matchedCount",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}),
+                message.getTableStats().get(0).getMatchedCount());
+        Assert.assertTrue("Unread data", bb.readableBytes() == 0);
+    }
+
+    /**
+     * Testing OF10StatsReplyMessageFactory (Port) for correct deserialization
+     */
+    @Test
+    public void testPort() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 "
+                + "00 FF 00 00 00 00 00 00 "
+                + "FF 01 01 01 01 01 01 01 FF 02 02 02 02 02 02 02 "
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "
+                + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "
+                + "FF 02 03 02 03 02 03 02");
+
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
+
+        BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue());
+        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
+        MultipartReplyPortStatsCase messageCase = (MultipartReplyPortStatsCase) builtByFactory.getMultipartReplyBody();
+        MultipartReplyPortStats message = messageCase.getMultipartReplyPortStats();
+        Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue());
+        Assert.assertEquals("Wrong rxPackets",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
+                message.getPortStats().get(0).getRxPackets());
+        Assert.assertEquals("Wrong txPackets",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
+                message.getPortStats().get(0).getTxPackets());
+        Assert.assertEquals("Wrong rxBytes",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getRxBytes());
+        Assert.assertEquals("Wrong txBytes",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getTxBytes());
+        Assert.assertEquals("Wrong rxDropped",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getRxDropped());
+        Assert.assertEquals("Wrong txDropped",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getTxDropped());
+        Assert.assertEquals("Wrong rxErrors",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getRxErrors());
+        Assert.assertEquals("Wrong txErrors",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getTxErrors());
+        Assert.assertEquals("Wrong rxFrameErr",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getRxFrameErr());
+        Assert.assertEquals("Wrong rxOverErr",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getRxOverErr());
+        Assert.assertEquals("Wrong rxCrcErr",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getRxCrcErr());
+        Assert.assertEquals("Wrong collisions",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getPortStats().get(0).getCollisions());
+        Assert.assertTrue("Unread data", bb.readableBytes() == 0);
+    }
+
+    /**
+     * Testing OF10StatsReplyMessageFactory (Queue) for correct deserialization
+     */
+    @Test
+    public void testQueue() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 05 00 00 "
+                + "00 FF 00 00 00 00 00 10 "
+                + "FF 02 03 02 03 02 03 02 "
+                + "FF 02 02 02 02 02 02 02 "
+                + "FF 02 03 02 03 02 03 02");
+
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
+
+        BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue());
+        Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());
+        MultipartReplyQueueCase messageCase = (MultipartReplyQueueCase) builtByFactory.getMultipartReplyBody();
+        MultipartReplyQueue message = messageCase.getMultipartReplyQueue();
+        Assert.assertEquals("Wrong portNo", 255, message.getQueueStats().get(0).getPortNo().intValue());
+        Assert.assertEquals("Wrong queueId", 16, message.getQueueStats().get(0).getQueueId().intValue());
+        Assert.assertEquals("Wrong txBytes",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getQueueStats().get(0).getTxBytes());
+        Assert.assertEquals("Wrong txPackets",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
+                message.getQueueStats().get(0).getTxPackets());
+        Assert.assertEquals("Wrong txErrors",
+                new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
+                message.getQueueStats().get(0).getTxErrors());
+        Assert.assertTrue("Unread data", bb.readableBytes() == 0);
+    }
+
+}