Improve the resiliency of the packet deserialization code.

Packet deserializers now check for malformed input while reading the byte
stream. Deserializers are re-implemented as functions that take a byte array
and return a packet object. The old IPacket.deserialize(...) methods have been
deprecated with the goal of eventually moving to immutable packet objects.
Unit tests have been implemented for all Deserializer functions.

ONOS-1589

Change-Id: I9073d5e6e7991e15d43830cfd810989256b71c56
diff --git a/utils/misc/src/main/java/org/onlab/packet/LLDPTLV.java b/utils/misc/src/main/java/org/onlab/packet/LLDPTLV.java
index b5fe833..77efe1b 100644
--- a/utils/misc/src/main/java/org/onlab/packet/LLDPTLV.java
+++ b/utils/misc/src/main/java/org/onlab/packet/LLDPTLV.java
@@ -95,18 +95,23 @@
         return data;
     }
 
-    public LLDPTLV deserialize(final ByteBuffer bb) {
-        short sscratch;
-        sscratch = bb.getShort();
-        this.type = (byte) (sscratch >> 9 & 0x7f);
-        this.length = (short) (sscratch & 0x1ff);
+    public LLDPTLV deserialize(final ByteBuffer bb) throws DeserializationException {
+        if (bb.remaining() < 2) {
+            throw new DeserializationException(
+                    "Not enough bytes to deserialize TLV type and length");
+        }
+        short typeLength;
+        typeLength = bb.getShort();
+        this.type = (byte) (typeLength >> 9 & 0x7f);
+        this.length = (short) (typeLength & 0x1ff);
 
         if (this.length > 0) {
             this.value = new byte[this.length];
 
             // if there is an underrun just toss the TLV
             if (bb.remaining() < this.length) {
-                return null;
+                throw new DeserializationException(
+                        "Remaining bytes are less then the length of the TLV");
             }
             bb.get(this.value);
         }