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/EthType.java b/utils/misc/src/main/java/org/onlab/packet/EthType.java
index 4f52b7d..7573ae8 100644
--- a/utils/misc/src/main/java/org/onlab/packet/EthType.java
+++ b/utils/misc/src/main/java/org/onlab/packet/EthType.java
@@ -93,25 +93,27 @@
 
     public static enum EtherType {
 
-        ARP(0x806, "arp", ARP.class),
-        RARP(0x8035, "rarp", null),
-        IPV4(0x800, "ipv4", IPv4.class),
-        IPV6(0x86dd, "ipv6", IPv6.class),
-        LLDP(0x88cc, "lldp", LLDP.class),
-        VLAN(0x8100, "vlan", null),
-        BDDP(0x8942, "bddp", LLDP.class),
-        MPLS_UNICAST(0x8847, "mpls_unicast", null),
-        MPLS_MULTICAST(0x8848, "mpls_unicast", null);
+        ARP(0x806, "arp", ARP.class, org.onlab.packet.ARP.deserializer()),
+        RARP(0x8035, "rarp", null, org.onlab.packet.ARP.deserializer()),
+        IPV4(0x800, "ipv4", IPv4.class, org.onlab.packet.IPv4.deserializer()),
+        IPV6(0x86dd, "ipv6", IPv6.class, org.onlab.packet.IPv6.deserializer()),
+        LLDP(0x88cc, "lldp", LLDP.class, org.onlab.packet.LLDP.deserializer()),
+        VLAN(0x8100, "vlan", null, null),
+        BDDP(0x8942, "bddp", LLDP.class, org.onlab.packet.LLDP.deserializer()),
+        MPLS_UNICAST(0x8847, "mpls_unicast", null, org.onlab.packet.MPLS.deserializer()),
+        MPLS_MULTICAST(0x8848, "mpls_unicast", null, org.onlab.packet.MPLS.deserializer());
 
 
         private final Class clazz;
         private EthType ethType;
         private String type;
+        private Deserializer<?> deserializer;
 
-        EtherType(int ethType, String type, Class clazz) {
+        EtherType(int ethType, String type, Class clazz, Deserializer deserializer) {
             this.ethType = new EthType(ethType);
             this.type = type;
             this.clazz = clazz;
+            this.deserializer = deserializer;
         }
 
         public EthType ethType() {
@@ -127,6 +129,8 @@
             return clazz;
         }
 
-
+        public Deserializer<?> deserializer() {
+            return deserializer;
+        }
     }
 }