Merge "Introducing the Modification classses"
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / packet / LLDPTLV.java
index 9254e824c57494a528a8e40bcf2052e0e7ab5fdd..35244ea697d871617b09db6e232da95af0d51ebf 100644 (file)
@@ -10,13 +10,11 @@ package org.opendaylight.controller.sal.packet;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
-import java.util.HashMap;
-
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
+
 import org.apache.commons.lang3.tuple.MutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.controller.sal.utils.HexEncode;
@@ -144,12 +142,33 @@ public class LLDPTLV extends Packet {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((fieldValues == null) ? 0 : fieldValues.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        LLDPTLV other = (LLDPTLV) obj;
+        if (fieldValues == null) {
+            if (other.fieldValues != null) {
+                return false;
+            }
+        } else if (!fieldValues.equals(other.fieldValues)) {
+            return false;
+        }
+        return true;
     }
 
     @Override
@@ -164,7 +183,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Returns the size in bits of the whole TLV
-     * 
+     *
      * @return int - size in bits of full TLV
      */
     public int getTLVSize() {
@@ -173,10 +192,22 @@ public class LLDPTLV extends Packet {
                 getfieldnumBits(VALUE)); // variable
     }
 
+    /**
+     * Creates the SystemName TLV value
+     *
+     * @param nodeId
+     *            node identifier string
+     * @return the SystemName TLV value in byte array
+     */
+    static public byte[] createSystemNameTLVValue(String nodeId) {
+        byte[] nid = nodeId.getBytes();
+        return nid;
+    }
+
     /**
      * Creates the ChassisID TLV value including the subtype and ChassisID
      * string
-     * 
+     *
      * @param nodeId
      *            node identifier string
      * @return the ChassisID TLV value in byte array
@@ -204,7 +235,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Creates the PortID TLV value including the subtype and PortID string
-     * 
+     *
      * @param portId
      *            port identifier string
      * @return the PortID TLV value in byte array
@@ -221,7 +252,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Creates the custom TLV value including OUI, subtype and custom string
-     * 
+     *
      * @param portId
      *            port identifier string
      * @return the custom TLV value in byte array
@@ -241,7 +272,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Retrieves the string from TLV value and returns it in HexString format
-     * 
+     *
      * @param tlvValue
      *            the TLV value
      * @param tlvLen
@@ -257,7 +288,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Retrieves the string from TLV value
-     * 
+     *
      * @param tlvValue
      *            the TLV value
      * @param tlvLen
@@ -265,16 +296,23 @@ public class LLDPTLV extends Packet {
      * @return the string
      */
     static public String getStringValue(byte[] tlvValue, int tlvLen) {
+        byte[] pidSubType = new byte[portIDSubType.length];
         byte[] pidBytes = new byte[tlvLen - portIDSubType.length];
+        System.arraycopy(tlvValue, 0, pidSubType, 0,
+                pidSubType.length);
         System.arraycopy(tlvValue, portIDSubType.length, pidBytes, 0,
                 pidBytes.length);
-        return (new String(pidBytes, Charset.defaultCharset()));
+        if (pidSubType[0] == (byte) 0x3) {
+            return HexEncode.bytesToHexStringFormat(pidBytes);
+        } else {
+            return (new String(pidBytes, Charset.defaultCharset()));
+        }
     }
 
     /**
      * Retrieves the custom string from the Custom TLV value which includes OUI,
      * subtype and custom string
-     * 
+     *
      * @param customTlvValue
      *            the custom TLV value
      * @param customTlvLen