Increased unit test coverage for some deserialization factories 81/12081/1
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 20 Oct 2014 12:25:09 +0000 (14:25 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 20 Oct 2014 16:22:40 +0000 (18:22 +0200)
Change-Id: If770094c17a7c2988602d17a7463243cbce63fee
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OpenflowUtils.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OpenflowUtilsTest.java [new file with mode: 0644]

index 2d3cc782394230a9da1807f78e8979e7a455a71f..13da41f0ca8a42fc6ab9ae0efabe6393adb24a15 100644 (file)
@@ -15,14 +15,12 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.OpenflowUtils;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
@@ -88,7 +86,7 @@ public class OF10FeaturesReplyMessageFactory implements OFDeserializer<GetFeatur
                 SET_NW_DST, SET_NW_SRC, SET_NW_TOS, SET_TP_DST, SET_TP_SRC,
                 SET_VLAN_PCP, SET_VLAN_VID, STRIP_VLAN, VENDOR);
     }
-    
+
     private static PhyPort deserializePort(ByteBuf rawMessage) {
         PhyPortBuilder builder = new PhyPortBuilder();
         builder.setPortNo((long) rawMessage.readUnsignedShort());
@@ -96,55 +94,12 @@ public class OF10FeaturesReplyMessageFactory implements OFDeserializer<GetFeatur
         rawMessage.readBytes(address);
         builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address)));
         builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
-        builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));
-        builder.setStateV10(createPortState(rawMessage.readUnsignedInt()));
-        builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
-        builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
-        builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
-        builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt()));
+        builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt()));
+        builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
         return builder.build();
     }
-
-    
-    
-    private static PortStateV10 createPortState(long input){
-        final Boolean _linkDown = ((input) & (1<<0)) != 0;
-        final Boolean _blocked = ((input) & (1<<1)) != 0;
-        final Boolean _live = ((input) & (1<<2)) != 0;
-        final Boolean _stpListen = ((input) & (0<<8)) != 0;
-        final Boolean _stpLearn = ((input) & (1<<8)) != 0;
-        final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8
-        final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8
-        final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8
-        return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask);
-    }
-    
-    private static PortConfigV10 createPortConfig(long input){
-        final Boolean _portDown = ((input) & (1<<0)) != 0;
-        final Boolean _noStp = ((input) & (1<<1)) != 0;
-        final Boolean _noRecv = ((input) & (1<<2)) != 0;
-        final Boolean _noRecvStp = ((input) & (1<<3)) != 0;
-        final Boolean _noFlood = ((input) & (1<<4)) != 0;
-        final Boolean _noFwd  = ((input) & (1<<5)) != 0;
-        final Boolean _noPacketIn = ((input) & (1<<6)) != 0;
-        return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown);
-    }
-    
-    private static PortFeaturesV10 createPortFeatures(long input){
-        final Boolean _10mbHd = ((input) & (1<<0)) != 0;
-        final Boolean _10mbFd = ((input) & (1<<1)) != 0;
-        final Boolean _100mbHd = ((input) & (1<<2)) != 0;
-        final Boolean _100mbFd = ((input) & (1<<3)) != 0;
-        final Boolean _1gbHd = ((input) & (1<<4)) != 0;
-        final Boolean _1gbFd = ((input) & (1<<5)) != 0;
-        final Boolean _10gbFd = ((input) & (1<<6)) != 0;
-        final Boolean _copper = ((input) & (1<<7)) != 0;
-        final Boolean _fiber = ((input) & (1<<8)) != 0;
-        final Boolean _autoneg = ((input) & (1<<9)) != 0;
-        final Boolean _pause = ((input) & (1<<10)) != 0;
-        final Boolean _pauseAsym = ((input) & (1<<11)) != 0;
-        return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd,
-                _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym);
-    }
-    
-}
+}
\ No newline at end of file
index e7036ed82df975aea57a82ffa8535da3feba5eb0..eed4b104289de8cbe436feb5f56535faba018625 100644 (file)
@@ -11,13 +11,11 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 import io.netty.buffer.ByteBuf;
 
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.OpenflowUtils;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
 
@@ -40,57 +38,17 @@ public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMe
         return builder.build();
     }
 
-    private static PortStateV10 createPortState(long input){
-        final Boolean _linkDown = ((input) & (1<<0)) != 0;
-        final Boolean _blocked = ((input) & (1<<1)) != 0;
-        final Boolean _live = ((input) & (1<<2)) != 0;
-        final Boolean _stpListen = ((input) & (0<<8)) != 0;
-        final Boolean _stpLearn = ((input) & (1<<8)) != 0;
-        final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8
-        final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8
-        final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8
-        return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask);
-    }
-    
-    private static PortConfigV10 createPortConfig(long input){
-        final Boolean _portDown = ((input) & (1<<0)) != 0;
-        final Boolean _noStp = ((input) & (1<<1)) != 0;
-        final Boolean _noRecv = ((input) & (1<<2)) != 0;
-        final Boolean _noRecvStp = ((input) & (1<<3)) != 0;
-        final Boolean _noFlood = ((input) & (1<<4)) != 0;
-        final Boolean _noFwd  = ((input) & (1<<5)) != 0;
-        final Boolean _noPacketIn = ((input) & (1<<6)) != 0;
-        return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown);
-    }
-    
-    private static PortFeaturesV10 createPortFeatures(long input){
-        final Boolean _10mbHd = ((input) & (1<<0)) != 0;
-        final Boolean _10mbFd = ((input) & (1<<1)) != 0;
-        final Boolean _100mbHd = ((input) & (1<<2)) != 0;
-        final Boolean _100mbFd = ((input) & (1<<3)) != 0;
-        final Boolean _1gbHd = ((input) & (1<<4)) != 0;
-        final Boolean _1gbFd = ((input) & (1<<5)) != 0;
-        final Boolean _10gbFd = ((input) & (1<<6)) != 0;
-        final Boolean _copper = ((input) & (1<<7)) != 0;
-        final Boolean _fiber = ((input) & (1<<8)) != 0;
-        final Boolean _autoneg = ((input) & (1<<9)) != 0;
-        final Boolean _pause = ((input) & (1<<10)) != 0;
-        final Boolean _pauseAsym = ((input) & (1<<11)) != 0;
-        return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd,
-                _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym);
-    }
-    
     private static void deserializePort(ByteBuf rawMessage, PortStatusMessageBuilder builder) {
         builder.setPortNo((long) rawMessage.readUnsignedShort());
         byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
         rawMessage.readBytes(address);
         builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address)));
         builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
-        builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));
-        builder.setStateV10(createPortState(rawMessage.readUnsignedInt()));
-        builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
-        builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
-        builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
-        builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt()));
+        builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt()));
+        builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
+        builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
     }
-}
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OpenflowUtils.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OpenflowUtils.java
new file mode 100644 (file)
index 0000000..8ba8e74
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Copyright (c) 2014 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
+\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;\r
+\r
+/**\r
+ * Used for common structures translation / conversion\r
+ * \r
+ * @author michal.polkorab\r
+ */\r
+public abstract class OpenflowUtils {\r
+\r
+    /**\r
+     * Creates PortState (OF v1.0) from input\r
+     * @param input value read from buffer\r
+     * @return port state\r
+     */\r
+    public static PortStateV10 createPortState(long input){\r
+        final Boolean _linkDown = ((input) & (1<<0)) != 0;\r
+        final Boolean _blocked = ((input) & (1<<1)) != 0;\r
+        final Boolean _live = ((input) & (1<<2)) != 0;\r
+        final Boolean _stpListen = ((input) & (1<<8)) == 0;\r
+        final Boolean _stpLearn = ((input) & (1<<8)) != 0;\r
+        final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8\r
+        final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8\r
+        final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8\r
+        return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask);\r
+    }\r
+\r
+    /**\r
+     * Creates PortConfig (OF v1.0) from input\r
+     * @param input value read from buffer\r
+     * @return port state\r
+     */\r
+    public static PortConfigV10 createPortConfig(long input){\r
+        final Boolean _portDown = ((input) & (1<<0)) != 0;\r
+        final Boolean _noStp = ((input) & (1<<1)) != 0;\r
+        final Boolean _noRecv = ((input) & (1<<2)) != 0;\r
+        final Boolean _noRecvStp = ((input) & (1<<3)) != 0;\r
+        final Boolean _noFlood = ((input) & (1<<4)) != 0;\r
+        final Boolean _noFwd  = ((input) & (1<<5)) != 0;\r
+        final Boolean _noPacketIn = ((input) & (1<<6)) != 0;\r
+        return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown);\r
+    }\r
+\r
+    /**\r
+     * Creates PortFeatures (OF v1.0) from input\r
+     * @param input value read from buffer\r
+     * @return port state\r
+     */\r
+    public static PortFeaturesV10 createPortFeatures(long input){\r
+        final Boolean _10mbHd = ((input) & (1<<0)) != 0;\r
+        final Boolean _10mbFd = ((input) & (1<<1)) != 0;\r
+        final Boolean _100mbHd = ((input) & (1<<2)) != 0;\r
+        final Boolean _100mbFd = ((input) & (1<<3)) != 0;\r
+        final Boolean _1gbHd = ((input) & (1<<4)) != 0;\r
+        final Boolean _1gbFd = ((input) & (1<<5)) != 0;\r
+        final Boolean _10gbFd = ((input) & (1<<6)) != 0;\r
+        final Boolean _copper = ((input) & (1<<7)) != 0;\r
+        final Boolean _fiber = ((input) & (1<<8)) != 0;\r
+        final Boolean _autoneg = ((input) & (1<<9)) != 0;\r
+        final Boolean _pause = ((input) & (1<<10)) != 0;\r
+        final Boolean _pauseAsym = ((input) & (1<<11)) != 0;\r
+        return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd,\r
+                _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym);\r
+    }\r
+}
\ No newline at end of file
index 233c7e3820fbe1c8f307ae09f0ad7194df58b08d..ad4ccc596979047ae0df7d46e4fcf039735ae7bd 100644 (file)
@@ -47,7 +47,7 @@ public class FeaturesReplyMessageFactoryTest {
     @Test
     public void test() {
         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
-                + " 00 01 41 00 01 02 03");
+                + " 00 00 00 00 01 02 03");
         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV13(builtByFactory);
@@ -55,7 +55,21 @@ public class FeaturesReplyMessageFactoryTest {
         Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
         Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());
         Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());
-        Assert.assertEquals("Wrong capabilities", new Capabilities(true, false, false, true, false, true, false), builtByFactory.getCapabilities());
+        Assert.assertEquals("Wrong capabilities", new Capabilities(false, false, false, false, false, false, false), builtByFactory.getCapabilities());
         Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());
     }
-}
+
+    /**
+     * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO
+     * (capabilities set)
+     */
+    @Test
+    public void testCapabilities() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
+                + " 00 01 6F 00 01 02 03");
+        GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
+
+        BufferHelper.checkHeaderV13(builtByFactory);
+        Assert.assertEquals("Wrong capabilities", new Capabilities(true, true, true, true, true, true, true), builtByFactory.getCapabilities());
+    }
+}
\ No newline at end of file
index 4330e32dd2921dd79097e1101c62d65c95bc6ab3..9530eabafe3df6407c37dad454260d20d207f3da 100644 (file)
@@ -53,31 +53,31 @@ public class OF10FeaturesReplyMessageFactoryTest {
     @Test
     public void test() {
         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
-                + "00 00 00 8B 00 00 03 B5 "
-                + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
-                + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
+                + "00 00 00 FF 00 00 0F FF "
+                + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7F 00 00 02 00 "
+                + "00 00 0F FF 00 00 00 00 00 00 03 0C 00 00 08 88");
         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV10(builtByFactory);
         Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
         Assert.assertEquals("Wrong n-buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
         Assert.assertEquals("Wrong n-tables", 0x01, builtByFactory.getTables().shortValue());
-        Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, false, false, false, false, true, true),
+        Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, true, true, true, true, true, true),
                 builtByFactory.getCapabilitiesV10());
-        Assert.assertEquals("Wrong actions", new ActionTypeV10(false, true, true, true, true, false, true,
-                false, true, true, false, false, false), builtByFactory.getActionsV10());
+        Assert.assertEquals("Wrong actions", new ActionTypeV10(true, true, true, true, true, true, true,
+                true, true, true, true, true, false), builtByFactory.getActionsV10());
         PhyPort port = builtByFactory.getPhyPort().get(0);
         Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());
         Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());
         Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());
-        Assert.assertEquals("Wrong port - config", new PortConfigV10(true, false, false, true, false, false, true),
+        Assert.assertEquals("Wrong port - config", new PortConfigV10(true, true, true, true, true, true, true),
                 port.getConfigV10());
-        Assert.assertEquals("Wrong port - state", new PortStateV10(false, true, false, false, false, true, false, false),
+        Assert.assertEquals("Wrong port - state",  new PortStateV10(false, false, false, false, true, false, true, false),
                 port.getStateV10());
-        Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(false, false, false, false, true, true, true,
-                false, false, false, false, false), port.getCurrentFeaturesV10());
-        Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, true, true, false, false,
-                false, false, false, false, true, false), port.getAdvertisedFeaturesV10());
+        Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(true, true, true, true, true, true, true,
+                true, true, true, true, true), port.getCurrentFeaturesV10());
+        Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, false, false, false, false,
+                false, false, false, false, false, false), port.getAdvertisedFeaturesV10());
         Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false,
                 false, true, false, true, false, false), port.getSupportedFeaturesV10());
         Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false,
@@ -88,30 +88,44 @@ public class OF10FeaturesReplyMessageFactoryTest {
      * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
      */
     @Test
-    public void testWithNoPortsSet() {
+    public void testWithTwoPortsSet() {
         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
                 + "00 00 00 8B 00 00 03 B5 "
-                + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
+                + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 01 "
                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "
-                + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
+                + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 00 "
                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV10(builtByFactory);
         Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size());
+        PhyPort port = builtByFactory.getPhyPort().get(0);
+        Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());
+        Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());
+        Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());
+        Assert.assertEquals("Wrong port - config", new PortConfigV10(false, false, false, false, false, false, false),
+                port.getConfigV10());
+        Assert.assertEquals("Wrong port - state",  new PortStateV10(false, true, false, true, true, true, false, true),
+                port.getStateV10());
+        port = builtByFactory.getPhyPort().get(1);
+        Assert.assertEquals("Wrong port - state",  new PortStateV10(false, false, false, false, false, false, true, false),
+                port.getStateV10());
     }
-    
+
     /**
      * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
      */
     @Test
-    public void testWithTwoPortsSet() {
+    public void testWithNoPortsSet() {
         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
-                + "00 00 00 8B 00 00 03 B5");
+                + "00 00 00 00 00 00 00 00");
         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV10(builtByFactory);
+        Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(false, false, false, false, false, false, false, false),
+                builtByFactory.getCapabilitiesV10());
+        Assert.assertEquals("Wrong actions", new ActionTypeV10(false, false, false, false, false, false, false,
+                false, false, false, false, false, false), builtByFactory.getActionsV10());
         Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size());
     }
-
-}
+}
\ No newline at end of file
index 759b0b6643cd7f794910db3831f0772f8cfb6986..6b45187208c4c8605125576929f1435399324c97 100644 (file)
@@ -52,7 +52,7 @@ public class OF10PortStatusMessageFactoryTest {
     public void test(){
         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00 00 00 00 00 "
                 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 "
-                + "00 00 00 00 15 00 00 01 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
+                + "00 00 00 00 15 00 00 00 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
         PortStatusMessage builtByFactory = BufferHelper.deserialize(statusFactory, bb);
         
         BufferHelper.checkHeaderV10(builtByFactory);
@@ -62,7 +62,7 @@ public class OF10PortStatusMessageFactoryTest {
         Assert.assertEquals("Wrong builtByFactory - name", new String("ALOHA"), builtByFactory.getName());
         Assert.assertEquals("Wrong builtByFactory - config", new PortConfigV10(true, false, false, true, false, false, true),
                 builtByFactory.getConfigV10());
-        Assert.assertEquals("Wrong builtByFactory - state", new PortStateV10(false, true, false, false, false, true, false, false),
+        Assert.assertEquals("Wrong builtByFactory - state", new PortStateV10(false, true, false, false, false, false, true, false),
                 builtByFactory.getStateV10());
         Assert.assertEquals("Wrong builtByFactory - curr", new PortFeaturesV10(false, false, false, false, true, true, true,
                 false, false, false, false, false), builtByFactory.getCurrentFeaturesV10());
@@ -73,5 +73,4 @@ public class OF10PortStatusMessageFactoryTest {
         Assert.assertEquals("Wrong builtByFactory - peer", new PortFeaturesV10(true, false, false, false, false, false, false,
                 false, true, false, false, true), builtByFactory.getPeerFeaturesV10());
     }
-
-}
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OpenflowUtilsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OpenflowUtilsTest.java
new file mode 100644 (file)
index 0000000..47e9262
--- /dev/null
@@ -0,0 +1,68 @@
+/*\r
+ * Copyright (c) 2014 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
+\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OpenflowUtilsTest {\r
+\r
+    /**\r
+     * Tests {@link OpenflowUtils#createPortState(long)}\r
+     */\r
+    @Test\r
+    public void testPortState() {\r
+        PortStateV10 state = OpenflowUtils.createPortState(512L);\r
+        Assert.assertEquals("Wrong port state",\r
+                new PortStateV10(false, false, false, false, true, false, true, false), state);\r
+\r
+        state = OpenflowUtils.createPortState(1793L);\r
+        Assert.assertEquals("Wrong port state",\r
+                new PortStateV10(false, true, false, true, true, true, false, true), state);\r
+\r
+        state = OpenflowUtils.createPortState(1L);\r
+        Assert.assertEquals("Wrong port state",\r
+                new PortStateV10(false, true, false, false, false, false, true, false), state);\r
+    }\r
+\r
+    /**\r
+     * Tests {@link OpenflowUtils#createPortConfig(long)}\r
+     */\r
+    @Test\r
+    public void testPortConfig() {\r
+        PortConfigV10 config = OpenflowUtils.createPortConfig(127L);\r
+        Assert.assertEquals("Wrong port config",\r
+                new PortConfigV10(true, true, true, true, true, true, true), config);\r
+\r
+        config = OpenflowUtils.createPortConfig(0L);\r
+        Assert.assertEquals("Wrong port config",\r
+                new PortConfigV10(false, false, false, false, false, false, false), config);\r
+    }\r
+\r
+    /**\r
+     * Tests {@link OpenflowUtils#createPortFeatures(long)}\r
+     */\r
+    @Test\r
+    public void testPortFeatures() {\r
+        PortFeaturesV10 features = OpenflowUtils.createPortFeatures(4095L);\r
+        Assert.assertEquals("Wrong port features", new PortFeaturesV10(true, true, true, true, true, true, true,\r
+                true, true, true, true, true), features);\r
+\r
+        features = OpenflowUtils.createPortFeatures(0L);\r
+        Assert.assertEquals("Wrong port features", new PortFeaturesV10(false, false, false, false, false, false,\r
+                false, false, false, false, false, false), features);\r
+    }\r
+}
\ No newline at end of file