Bug 3577 - Message decoder fails to decode "all IP addresses match this update"
[bgpcep.git] / util / src / main / java / org / opendaylight / protocol / util / Ipv6Util.java
index b1c1964738caf501976e15dfbd4809b29a4fc4fb..c43883bb8d78762c2abc004a49272183afebaff0 100644 (file)
@@ -104,11 +104,14 @@ public final class Ipv6Util {
      */
     public static byte[] bytesForPrefixBegin(final Ipv6Prefix prefix) {
         final String p = prefix.getValue();
+        final int length = Ipv4Util.getPrefixLength(p);
+        if (length == 0) {
+            return new byte[] { 0 };
+        }
         final int sep = p.indexOf('/');
         final InetAddress a = InetAddresses.forString(p.substring(0, sep));
         Preconditions.checkArgument(a instanceof Inet6Address);
         final byte[] bytes = a.getAddress();
-        final int length = Ipv4Util.getPrefixLength(p);
         return Bytes.concat(new byte[] { UnsignedBytes.checkedCast(length) }, ByteArray.subByte(bytes, 0 , Ipv4Util.getPrefixLengthBytes(p)));
     }
 
@@ -156,9 +159,15 @@ public final class Ipv6Util {
         while (byteOffset < bytes.length) {
             final int bitLength = UnsignedBytes.toInt(ByteArray.subByte(bytes, byteOffset, 1)[0]);
             byteOffset += 1;
+            // if length == 0, default route will be added
+            if (bitLength == 0) {
+                list.add(new Ipv6Prefix("::/0"));
+                continue;
+            }
             final int byteCount = (bitLength % Byte.SIZE != 0) ? (bitLength / Byte.SIZE) + 1 : bitLength / Byte.SIZE;
             list.add(prefixForBytes(ByteArray.subByte(bytes, byteOffset, byteCount), bitLength));
             byteOffset += byteCount;
+
         }
         return list;
     }