Improves ping responder

Patch contains several bugfixes and improvements:
- Fixes sid retrieval when the destination leaf is down
- Fixes sid retrieval when ping goes through the spine
- Fixes MPLS deserializer
- Improves Ethernet toString
- Fixes ping to looback for dh host when bond sends to wrong leaf

Change-Id: I05963e74b2976e526826ffd377cadeb462ba0a8d
diff --git a/utils/misc/src/main/java/org/onlab/packet/MPLS.java b/utils/misc/src/main/java/org/onlab/packet/MPLS.java
index 948075b..07ead0c 100644
--- a/utils/misc/src/main/java/org/onlab/packet/MPLS.java
+++ b/utils/misc/src/main/java/org/onlab/packet/MPLS.java
@@ -30,13 +30,15 @@
     public static final int HEADER_LENGTH = 4;
 
     public static final byte PROTOCOL_IPV4 = 0x1;
+    public static final byte PROTOCOL_IPV6 = 0x2;
     public static final byte PROTOCOL_MPLS = 0x6;
     // mutable for Testing
     static Map<Byte, Deserializer<? extends IPacket>> protocolDeserializerMap =
             ImmutableMap.<Byte, Deserializer<? extends IPacket>>builder()
-                .put(PROTOCOL_IPV4, IPv4.deserializer())
-                .put(PROTOCOL_MPLS, MPLS.deserializer())
-                .build();
+                    .put(PROTOCOL_IPV6, IPv6.deserializer())
+                    .put(PROTOCOL_IPV4, IPv4.deserializer())
+                    .put(PROTOCOL_MPLS, MPLS.deserializer())
+                    .build();
 
     protected int label; //20bits
     protected byte bos; //1bit
@@ -108,6 +110,22 @@
         this.ttl = ttl;
     }
 
+    @Override
+    public IPacket setPayload(final IPacket payload) {
+        // We implicitly assume that traffic can be only of these three types
+        if (payload instanceof MPLS) {
+            this.bos = 0;
+            this.protocol = PROTOCOL_MPLS;
+        } else if (payload instanceof IPv6) {
+            this.bos = 1;
+            this.protocol = PROTOCOL_IPV6;
+        } else {
+            this.bos = 1;
+            this.protocol = PROTOCOL_IPV4;
+        }
+        return super.setPayload(payload);
+    }
+
     /**
      * Deserializer function for MPLS packets.
      *
@@ -124,7 +142,11 @@
             mpls.label = ((mplsheader & 0xfffff000) >>> 12);
             mpls.bos = (byte) ((mplsheader & 0x00000100) >> 8);
             mpls.ttl = (byte) (mplsheader & 0x000000ff);
-            mpls.protocol = (mpls.bos == 1) ? PROTOCOL_IPV4 : PROTOCOL_MPLS;
+
+            ByteBuffer duplicate = bb.duplicate();
+            short protocol = (short) ((duplicate.get() & 0xf0) >> 4);
+            mpls.protocol = (mpls.bos == 1) ? protocol == 4 ?
+                    PROTOCOL_IPV4 : PROTOCOL_IPV6 : PROTOCOL_MPLS;
 
             Deserializer<? extends IPacket> deserializer;
             if (protocolDeserializerMap.containsKey(mpls.protocol)) {