Bug 2820 - LLDP TLV support and testing
[controller.git] / opendaylight / commons / liblldp / src / main / java / org / opendaylight / controller / liblldp / LLDP.java
index 94f25c03a302523cec0e275f18074020b90e4820..c7dc6915ad32b432054c9a3d2c08e4b046003aec 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.controller.liblldp;
 
-import java.util.Collections;
 import com.google.common.collect.Iterables;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -31,14 +30,15 @@ public class LLDP extends Packet {
             (byte) 0xc2, 0, 0, (byte) 0xe };
     private Map<Byte, LLDPTLV> tlvList;
 
-    private List<LLDPTLV> customTlvList = Collections.emptyList();
+    private List<LLDPTLV> customTlvList;
 
     /**
      * Default constructor that creates the tlvList LinkedHashMap
      */
     public LLDP() {
         super();
-        tlvList = new LinkedHashMap<Byte, LLDPTLV>(LLDPDefaultTlvs);
+        tlvList = new LinkedHashMap<>(LLDPDefaultTlvs);
+        customTlvList = new ArrayList<>();
     }
 
     /**
@@ -63,6 +63,8 @@ public class LLDP extends Packet {
             return LLDPTLV.TLVType.PortID.getValue();
         } else if (typeDesc.equals(TTL)) {
             return LLDPTLV.TLVType.TTL.getValue();
+        } else if (typeDesc.equals(SYSTEMNAMEID)) {
+            return LLDPTLV.TLVType.SystemName.getValue();
         } else {
             return LLDPTLV.TLVType.Unknown.getValue();
         }
@@ -163,7 +165,8 @@ public class LLDP extends Packet {
             byte type = entry.getKey();
             if ((type == LLDPTLV.TLVType.ChassisID.getValue())
                     || (type == LLDPTLV.TLVType.PortID.getValue())
-                    || (type == LLDPTLV.TLVType.TTL.getValue())) {
+                    || (type == LLDPTLV.TLVType.TTL.getValue())
+                    || (type == LLDPTLV.TLVType.SystemName.getValue())) {
                 continue;
             } else {
                 list.add(entry.getValue());
@@ -172,6 +175,13 @@ public class LLDP extends Packet {
         return list;
     }
 
+    /**
+     * @return the customTlvList
+     */
+    public List<LLDPTLV> getCustomTlvList() {
+        return customTlvList;
+    }
+
     /**
      * @param optionalTLVList
      *            the optionalTLVList to set
@@ -216,7 +226,11 @@ public class LLDP extends Packet {
             int tlvSize = tlv.getTLVSize(); // Size of current TLV in bits
             lldpOffset += tlvSize;
             lldpSize -= tlvSize;
-            this.tlvList.put(tlv.getType(), tlv);
+            if (tlv.getType() == LLDPTLV.TLVType.Custom.getValue()) {
+                customTlvList.add(tlv);
+            } else {
+                this.tlvList.put(tlv.getType(), tlv);
+            }
         }
         return this;
     }