X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fcommons%2Fliblldp%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fliblldp%2FLLDPTLV.java;h=7b93d5f19cc3f9dcdbdb85454bb128b64b84a7c6;hb=dea515c8870769408b9bea29f555d6b71ff43211;hp=22bd4626d196c11a9c4b2a4bc00929e27e79ff33;hpb=b725fdb758008195a98f7fad0fd3804c363170aa;p=controller.git diff --git a/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java b/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java index 22bd4626d1..7b93d5f19c 100644 --- a/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java +++ b/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java @@ -8,13 +8,16 @@ package org.opendaylight.controller.liblldp; +import org.apache.commons.lang3.ArrayUtils; +import org.slf4j.LoggerFactory; + +import org.slf4j.Logger; import java.io.UnsupportedEncodingException; 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.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -27,14 +30,26 @@ public class LLDPTLV extends Packet { private static final String LENGTH = "Length"; private static final String VALUE = "Value"; private static final int LLDPTLVFields = 3; + + /** OpenFlow OUI */ public static final byte[] OFOUI = new byte[] { (byte) 0x00, (byte) 0x26, - (byte) 0xe1 }; // OpenFlow OUI - public static final byte[] customTlvSubType = new byte[] { 0 }; - public static final int customTlvOffset = OFOUI.length - + customTlvSubType.length; + (byte) 0xe1 }; + + /** Length of Organizationally defined subtype field of TLV in bytes */ + private static final byte customTlvSubTypeLength = (byte)1; + + /** OpenFlow subtype: nodeConnectorId of source */ + public static final byte[] CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID = new byte[] { 0 }; + + /** OpenFlow subtype: custom sec = hash code of verification of origin of LLDP */ + public static final byte[] CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC = new byte[] { 1 }; + + public static final int customTlvOffset = OFOUI.length + customTlvSubTypeLength; public static final byte chassisIDSubType[] = new byte[] { 4 }; // MAC address for the system public static final byte portIDSubType[] = new byte[] { 7 }; // locally assigned + private static final Logger LOG = LoggerFactory.getLogger(LLDPTLV.class); + 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( @@ -254,16 +269,27 @@ public class LLDPTLV extends Packet { * @param portId * port identifier string * @return the custom TLV value in byte array + * @see {@link #createCustomTLVValue(byte,String)} */ static public byte[] createCustomTLVValue(String customString) { - byte[] customArray = customString.getBytes(Charset.defaultCharset()); - byte[] customValue = new byte[customTlvOffset + customArray.length]; + byte[] customByteArray = customString.getBytes(Charset.defaultCharset()); + return createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID, customByteArray); + } + + /** + * Creates the custom TLV value including OUI, subtype and custom string + * @param subtype openflow subtype + * @param portId + * port identifier string + * @return the custom TLV value in byte array + */ + static public byte[] createCustomTLVValue(byte[] subtype, byte[] customByteArray) { + byte[] customValue = new byte[customTlvOffset + customByteArray.length]; System.arraycopy(OFOUI, 0, customValue, 0, OFOUI.length); - System.arraycopy(customTlvSubType, 0, customValue, OFOUI.length, - customTlvSubType.length); - System.arraycopy(customArray, 0, customValue, customTlvOffset, - customArray.length); + System.arraycopy(subtype, 0, customValue, OFOUI.length, 1); + System.arraycopy(customByteArray, 0, customValue, customTlvOffset, + customByteArray.length); return customValue; } @@ -334,4 +360,14 @@ public class LLDPTLV extends Packet { return customString; } + + public static int extractCustomOUI(final LLDPTLV lldptlv) { + byte[] value = lldptlv.getValue(); + return BitBufferHelper.getInt(ArrayUtils.subarray(value, 0, 3)); + } + + public static byte extractCustomSubtype(final LLDPTLV lldptlv) { + byte[] value = lldptlv.getValue(); + return BitBufferHelper.getByte(ArrayUtils.subarray(value, 3, 4)); + } }