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/test/java/org/onlab/packet/ipv6/EncapSecurityPayloadTest.java b/utils/misc/src/test/java/org/onlab/packet/ipv6/EncapSecurityPayloadTest.java
index 294dffb..e0e9919 100644
--- a/utils/misc/src/test/java/org/onlab/packet/ipv6/EncapSecurityPayloadTest.java
+++ b/utils/misc/src/test/java/org/onlab/packet/ipv6/EncapSecurityPayloadTest.java
@@ -16,9 +16,13 @@
 
 package org.onlab.packet.ipv6;
 
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.onlab.packet.Data;
+import org.onlab.packet.DeserializationException;
+import org.onlab.packet.Deserializer;
+
 import java.util.Arrays;
 
 import static org.hamcrest.Matchers.is;
@@ -35,6 +39,8 @@
     private static byte[] dataByte = new byte[32];
     private static byte[] bytePacket;
 
+    private Deserializer<EncapSecurityPayload> deserializer;
+
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
         Arrays.fill(dataByte, (byte) 0xff);
@@ -50,6 +56,11 @@
         System.arraycopy(bytePayload, 0, bytePacket, byteHeader.length, bytePayload.length);
     }
 
+    @Before
+    public void setUp() {
+        deserializer = EncapSecurityPayload.deserializer();
+    }
+
     /**
      * Tests serialize and setters.
      */
@@ -67,9 +78,8 @@
      * Tests deserialize and getters.
      */
     @Test
-    public void testDeserialize() {
-        EncapSecurityPayload esp = new EncapSecurityPayload();
-        esp.deserialize(bytePacket, 0, bytePacket.length);
+    public void testDeserialize() throws DeserializationException {
+        EncapSecurityPayload esp = deserializer.deserialize(bytePacket, 0, bytePacket.length);
 
         assertThat(esp.getSecurityParamIndex(), is(0x13572468));
         assertThat(esp.getSequence(), is(0xffff00));