Fixed a bug in PortStatus decoding 31/3931/2
authorEd Warnicke <eaw@cisco.com>
Thu, 26 Dec 2013 03:53:24 +0000 (19:53 -0800)
committerEd Warnicke <eaw@cisco.com>
Fri, 27 Dec 2013 17:21:19 +0000 (09:21 -0800)
PortStatusMessageFactory was neglecting to decode
the port name, and as a result was (among other things)
failing to correctly decode the port state (and actually
everything after port name in the message).

Change-Id: I6940e3255471996a38d8b5deefae520dac24eecc
Signed-off-by: Ed Warnicke <eaw@cisco.com>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java

index 1252e4ebda19e2fcc4fa23e4d72f7f7a1ccc15a4..1d193645c6848de4dc6466853bc8f3b5897e9b15 100644 (file)
@@ -32,6 +32,7 @@ public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessag
     private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
     private static final byte PADDING_IN_OFP_PORT_HEADER_1 = 4;
     private static final byte PADDING_IN_OFP_PORT_HEADER_2 = 2;
+    private static final byte MAX_PORT_NAME_LEN = 16;
     
     private PortStatusMessageFactory() {
         // Singleton
@@ -60,6 +61,7 @@ public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessag
         rawMessage.readBytes(hwAddress);
         builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(hwAddress)));
         rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_2);
+        builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
         builder.setConfig(createPortConfig(rawMessage.readUnsignedInt()));
         builder.setState(createPortState(rawMessage.readUnsignedInt()));
         builder.setCurrentFeatures(createPortFeatures(rawMessage.readUnsignedInt()));
index 9d427381250ec19a6f6095159b619a8e65842abe..43923853c9c3806dc1592e0988b652f0ae5677a6 100644 (file)
@@ -37,6 +37,7 @@ public class PortStatusMessageFactoryTest {
                                               "00 00 00 00 " + //padding in ofp_port1
                                               "08 00 27 00 B0 EB " + //mac address
                                               "00 00 " + //padding in ofp_port2
+                                              "73 31 2d 65 74 68 31 00 00 00 00 00 00 00 00 00 " + // port name, String "s1-eth1"
                                               "00 00 00 41 " + //port config
                                               "00 00 00 05 " + //port state
                                               "00 00 00 81 " + //current features
@@ -53,6 +54,7 @@ public class PortStatusMessageFactoryTest {
         Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());
         Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue());
         Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), builtByFactory.getHwAddr());
+        Assert.assertEquals("Wrong name", "s1-eth1", builtByFactory.getName());
         Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig());
         Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState());
         Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false,