MacAddress (de)serialization fixed
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / PortModInputMessageFactoryTest.java
index 9617e61251597652b6a23d7c10636e0ba29b975f..b5469e22229e4684646108385b1f3dd804d562c9 100644 (file)
@@ -8,6 +8,7 @@ import junit.framework.Assert;
 import org.junit.Test;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;\r
@@ -36,7 +37,7 @@ public class PortModInputMessageFactoryTest {
         PortModInputBuilder builder = new PortModInputBuilder();\r
         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);\r
         builder.setPortNo(new PortNumber(9L));\r
-        builder.setHwAddress(new MacAddress("08002700B0EB"));\r
+        builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));\r
         builder.setConfig(new PortConfig(true, false, true, false));\r
         builder.setMask(new PortConfig(false, true, false, true));\r
         builder.setAdvertise(new PortFeatures(true, false, false, false,\r
@@ -52,7 +53,10 @@ public class PortModInputMessageFactoryTest {
         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);\r
         Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedInt());\r
         out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_01);\r
-        Assert.assertEquals("Wrong MacAddress", message.getHwAddress().getValue(), new MacAddress(makeMacAddress(out)).getValue());\r
+        byte[] address = new byte[6];\r
+        out.readBytes(address);\r
+        Assert.assertEquals("Wrong MacAddress", message.getHwAddress().getValue(),\r
+                new MacAddress(ByteBufUtils.macAddressToString(address)).getValue());\r
         out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_02);\r
         Assert.assertEquals("Wrong config", message.getConfig(), createPortConfig(out.readInt()));\r
         Assert.assertEquals("Wrong mask", message.getMask(), createPortConfig(out.readInt()));\r
@@ -89,15 +93,4 @@ public class PortModInputMessageFactoryTest {
                 _1gbFd, _1gbHd, _1tbFd, _40gbFd, _autoneg, _copper, _fiber, _other, _pause, _pauseAsym);\r
     }\r
     \r
-    private static String makeMacAddress(ByteBuf input) {\r
-        final int macAddressLength = 6;\r
-        StringBuffer macToString = new StringBuffer();\r
-        \r
-        for(int i=0; i<macAddressLength; i++){\r
-            short mac = 0;\r
-            mac = input.readUnsignedByte();\r
-            macToString.append(String.format("%02X", mac));\r
-        }\r
-        return macToString.toString();\r
-    }\r
 }\r