Merge "Adding support for the git-review command line tool"
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / PortStatusMessageFactory.java
index 57676126f4301c38603918f4c2edbb0598053e6f..1d193645c6848de4dc6466853bc8f3b5897e9b15 100644 (file)
@@ -1,9 +1,18 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
+/*
+ * 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 org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
 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.PortConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
@@ -13,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
 
 /**
+ * Translates PortStatus messages
  * @author michal.polkorab
  * @author timotej.kubas
  */
@@ -22,7 +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 int macAddressLength = 6;
+    private static final byte MAX_PORT_NAME_LEN = 16;
     
     private PortStatusMessageFactory() {
         // Singleton
@@ -47,14 +57,11 @@ public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessag
         rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
         builder.setPortNo(rawMessage.readUnsignedInt());
         rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_1);
-        StringBuffer macToString = new StringBuffer();
-        for(int i=0; i<macAddressLength; i++){
-            short mac = 0;
-            mac = rawMessage.readUnsignedByte();
-            macToString.append(String.format("%02X", mac));
-        }
-        builder.setHwAddr(new MacAddress(macToString.toString()));
+        byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
+        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()));
@@ -91,7 +98,7 @@ public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessag
         final Boolean _linkDown = ((input) & (1<<0)) != 0;
         final Boolean _blocked  = ((input) & (1<<1)) != 0;
         final Boolean _live     = ((input) & (1<<2)) != 0;
-        return new PortState(_linkDown, _blocked,_live);
+        return new PortState(_blocked, _linkDown, _live);
     }
     
     private static PortConfig createPortConfig(long input){