X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2FLLDPTLV.java;h=bf674022596d8eb09df2b99bdb72314bdbdaf2cc;hp=45706fc77ce675e68d90df71bcce127e1f740606;hb=50d50e106bcbe761b05417e747c217c1f5b36534;hpb=e326757873804be369d20efd0b54467871094c06 diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java index 45706fc77c..bf67402259 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java @@ -9,13 +9,12 @@ package org.opendaylight.controller.sal.packet; import java.io.UnsupportedEncodingException; -import java.util.HashMap; - +import java.nio.charset.Charset; 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; @@ -31,7 +30,7 @@ public class LLDPTLV extends Packet { private static final String VALUE = "Value"; private static final int LLDPTLVFields = 3; public static final byte[] OFOUI = new byte[] { (byte) 0x00, (byte) 0x26, - (byte) 0xe1 }; // OpenFlow OUI + (byte) 0xe1 }; // OpenFlow OUI public static final byte[] customTlvSubType = new byte[] { 0 }; public static final int customTlvOffset = OFOUI.length + customTlvSubType.length; @@ -41,7 +40,7 @@ public class LLDPTLV extends Packet { public enum TLVType { Unknown((byte) 0), ChassisID((byte) 1), PortID((byte) 2), TTL((byte) 3), PortDesc( (byte) 4), SystemName((byte) 5), SystemDesc((byte) 6), Custom( - (byte) 127); + (byte) 127); private byte value; @@ -143,40 +142,55 @@ 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 - public int getfieldnumBits(String fieldName) throws Exception { + public int getfieldnumBits(String fieldName) { if (fieldName.equals(VALUE)) { - return (NetUtils.NumBitsInAByte * (int) BitBufferHelper.getShort( + return (NetUtils.NumBitsInAByte * BitBufferHelper.getShort( fieldValues.get(LENGTH), fieldCoordinates.get(LENGTH) - .getRight().intValue())); + .getRight().intValue())); } return fieldCoordinates.get(fieldName).getRight(); } /** * Returns the size in bits of the whole TLV - * + * * @return int - size in bits of full TLV - * @throws Exception */ - public int getTLVSize() throws Exception { + public int getTLVSize() { return (LLDPTLV.fieldCoordinates.get(TYPE).getRight() + // static LLDPTLV.fieldCoordinates.get(LENGTH).getRight() + // static - getfieldnumBits(VALUE)); // variable + getfieldnumBits(VALUE)); // variable } /** * 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,13 +218,13 @@ 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 */ static public byte[] createPortIDTLVValue(String portId) { - byte[] pid = portId.getBytes(); + byte[] pid = portId.getBytes(Charset.defaultCharset()); byte[] pidValue = new byte[pid.length + portIDSubType.length]; System.arraycopy(portIDSubType, 0, pidValue, 0, portIDSubType.length); @@ -221,13 +235,13 @@ 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 */ static public byte[] createCustomTLVValue(String customString) { - byte[] customArray = customString.getBytes(); + byte[] customArray = customString.getBytes(Charset.defaultCharset()); byte[] customValue = new byte[customTlvOffset + customArray.length]; System.arraycopy(OFOUI, 0, customValue, 0, OFOUI.length); @@ -241,7 +255,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 +271,7 @@ public class LLDPTLV extends Packet { /** * Retrieves the string from TLV value - * + * * @param tlvValue * the TLV value * @param tlvLen @@ -268,13 +282,13 @@ public class LLDPTLV extends Packet { byte[] pidBytes = new byte[tlvLen - portIDSubType.length]; System.arraycopy(tlvValue, portIDSubType.length, pidBytes, 0, pidBytes.length); - return (new String(pidBytes)); + 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