BUG-5983: Fix wrong representation of Ip length 93/39693/3
authorClaudio D. Gasparini <cgaspari@cisco.com>
Wed, 1 Jun 2016 08:35:48 +0000 (10:35 +0200)
committerMilos Fabian <milfabia@cisco.com>
Wed, 1 Jun 2016 10:31:28 +0000 (10:31 +0000)
Ip Length representation  is in bits for
Ethernet Segment Route, Inclusive Multicast Ethernet Tag Route.

Change-Id: I5c3057acb83ab4881d0889d8684d6ea4c405a385
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ArbitraryParser.java
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParser.java
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParserTest.java
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParserTest.java
util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java

index b2c784c941b5844952bed8ea0f24e82a2949e19a..2583f8370c89b8ea84dbe7440a49f37f49d7145c 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.EsiType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.Esi;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.EsiType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.Esi;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCase;
@@ -40,7 +41,7 @@ final class ArbitraryParser extends AbstractEsiType {
 
 
     @Override
 
 
     @Override
-    public Esi parseEsi(final ByteBuf buffer) {
-        return new ArbitraryCaseBuilder().setArbitrary(new ArbitraryBuilder().setArbitrary(buffer.readSlice(ARBITRARY_LENGTH).array()).build()).build();
+    public Esi parseEsi(final ByteBuf body) {
+        return new ArbitraryCaseBuilder().setArbitrary(new ArbitraryBuilder().setArbitrary(ByteArray.readBytes(body, ARBITRARY_LENGTH)).build()).build();
     }
 }
     }
 }
index 0ffe8683e58b149b8b0f093c8ce4d74130facdbe..936e3a42515ebdbc8dc373247acc46b9108b11e2 100644 (file)
@@ -79,10 +79,10 @@ final class EthSegRParser extends AbstractEvpnNlri {
     }
 
     public static IpAddress parseOrigRouteIp(final ByteBuf buffer) {
     }
 
     public static IpAddress parseOrigRouteIp(final ByteBuf buffer) {
-        final int ipLength = buffer.readByte();
-        if (ipLength == Ipv6Util.IPV6_LENGTH) {
+        final int ipLength = buffer.readUnsignedByte();
+        if (ipLength == Ipv6Util.IPV6_BITS_LENGTH) {
             return new IpAddress(Ipv6Util.addressForByteBuf(buffer));
             return new IpAddress(Ipv6Util.addressForByteBuf(buffer));
-        } else if (ipLength == Ipv4Util.IP4_LENGTH) {
+        } else if (ipLength == Ipv4Util.IP4_BITS_LENGTH) {
             return new IpAddress(Ipv4Util.addressForByteBuf(buffer));
         }
         return null;
             return new IpAddress(Ipv4Util.addressForByteBuf(buffer));
         }
         return null;
@@ -91,10 +91,10 @@ final class EthSegRParser extends AbstractEvpnNlri {
     static ByteBuf serializeOrigRouteIp(final IpAddress origRouteIp) {
         final ByteBuf body = Unpooled.buffer();
         if (origRouteIp.getIpv4Address() != null) {
     static ByteBuf serializeOrigRouteIp(final IpAddress origRouteIp) {
         final ByteBuf body = Unpooled.buffer();
         if (origRouteIp.getIpv4Address() != null) {
-            body.writeByte(Ipv4Util.IP4_LENGTH);
+            body.writeByte(Ipv4Util.IP4_BITS_LENGTH);
             body.writeBytes(Ipv4Util.bytesForAddress(origRouteIp.getIpv4Address()));
         } else if (origRouteIp.getIpv6Address() != null) {
             body.writeBytes(Ipv4Util.bytesForAddress(origRouteIp.getIpv4Address()));
         } else if (origRouteIp.getIpv6Address() != null) {
-            body.writeByte(Ipv6Util.IPV6_LENGTH);
+            body.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
             body.writeBytes(Ipv6Util.bytesForAddress(origRouteIp.getIpv6Address()));
         } else {
             body.writeZero(ZERO_BYTE);
             body.writeBytes(Ipv6Util.bytesForAddress(origRouteIp.getIpv6Address()));
         } else {
             body.writeZero(ZERO_BYTE);
index 062405f8b45ae0d72450c3846930d6b79f935f8a..4295769a2e3b2d9d73bdef99f8db7b037ed1ddc9 100644 (file)
@@ -126,10 +126,10 @@ final class MACIpAdvRParser extends AbstractEvpnNlri {
     private static ByteBuf serializeIp(final IpAddress ipAddress) {
         final ByteBuf body = Unpooled.buffer();
         if (ipAddress.getIpv4Address() != null) {
     private static ByteBuf serializeIp(final IpAddress ipAddress) {
         final ByteBuf body = Unpooled.buffer();
         if (ipAddress.getIpv4Address() != null) {
-            body.writeByte(Ipv4Util.IP4_LENGTH * BITS_SIZE);
+            body.writeByte(Ipv4Util.IP4_BITS_LENGTH);
             body.writeBytes(Ipv4Util.bytesForAddress(ipAddress.getIpv4Address()));
         } else if (ipAddress.getIpv6Address() != null) {
             body.writeBytes(Ipv4Util.bytesForAddress(ipAddress.getIpv4Address()));
         } else if (ipAddress.getIpv6Address() != null) {
-            body.writeByte(Ipv6Util.IPV6_LENGTH * BITS_SIZE);
+            body.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
             body.writeBytes(Ipv6Util.bytesForAddress(ipAddress.getIpv6Address()));
         } else {
             body.writeZero(ZERO_BYTE);
             body.writeBytes(Ipv6Util.bytesForAddress(ipAddress.getIpv6Address()));
         } else {
             body.writeZero(ZERO_BYTE);
@@ -139,9 +139,9 @@ final class MACIpAdvRParser extends AbstractEvpnNlri {
 
     private static IpAddress parseIp(final ByteBuf buffer) {
         final int ipLength = buffer.readUnsignedByte();
 
     private static IpAddress parseIp(final ByteBuf buffer) {
         final int ipLength = buffer.readUnsignedByte();
-        if (ipLength == Ipv6Util.IPV6_LENGTH * BITS_SIZE) {
+        if (ipLength == Ipv6Util.IPV6_BITS_LENGTH) {
             return new IpAddress(Ipv6Util.addressForByteBuf(buffer));
             return new IpAddress(Ipv6Util.addressForByteBuf(buffer));
-        } else if (ipLength == Ipv4Util.IP4_LENGTH * BITS_SIZE) {
+        } else if (ipLength == Ipv4Util.IP4_BITS_LENGTH) {
             return new IpAddress(Ipv4Util.addressForByteBuf(buffer));
         }
         return null;
             return new IpAddress(Ipv4Util.addressForByteBuf(buffer));
         }
         return null;
index 65a7b9d6542a7e66ff08b0734b1975536928036e..3020cb818e484974d462abb33f3934cc29498794 100644 (file)
@@ -41,17 +41,17 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContaine
 public class EthSegRParserTest {
     private static final byte[] VALUE = {
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
 public class EthSegRParserTest {
     private static final byte[] VALUE = {
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
-        (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+        (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
     };
     private static final byte[] RESULT = {
         (byte) 0x04, (byte) 0x17,
         (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
     };
     private static final byte[] RESULT = {
         (byte) 0x04, (byte) 0x17,
         (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
-        (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+        (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
     };
     private static final byte[] VALUE2 = {
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
     };
     private static final byte[] VALUE2 = {
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
-        (byte) 0x10,//IPV6
+        (byte) 0x80,//IPV6
         (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
@@ -61,7 +61,7 @@ public class EthSegRParserTest {
         (byte) 0x04, (byte) 0x23,
         (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
         (byte) 0x04, (byte) 0x23,
         (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
         (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
-        (byte) 0x10,//IPV6
+        (byte) 0x80,//IPV6
         (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
index 40e260a692bda7b6a5c4bbdd52d9de229d0be85c..14339439622084068174461112e54ec2edb3dbd7 100644 (file)
@@ -41,11 +41,11 @@ public class IncMultEthTagRParserTest {
         (byte) 0x03, (byte) 0x11,
         (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
         (byte) 0x03, (byte) 0x11,
         (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
-        (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+        (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
     };
     private static final byte[] VALUE = {
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
     };
     private static final byte[] VALUE = {
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
-        (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+        (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
     };
     private IncMultEthTagRParser parser;
 
     };
     private IncMultEthTagRParser parser;
 
index 781d0a969890fce9fe094a302118dd83e6084926..b466121d9bad2972f442be3b3143aadaf78c2bf9 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
  */
 public final class Ipv4Util {
     public static final int IP4_LENGTH = 4;
  */
 public final class Ipv4Util {
     public static final int IP4_LENGTH = 4;
+    public static final int IP4_BITS_LENGTH = 32;
     private static final Ipv4Prefix EMPTY_PREFIX = new Ipv4Prefix("0.0.0.0/0");
 
     private Ipv4Util() {
     private static final Ipv4Prefix EMPTY_PREFIX = new Ipv4Prefix("0.0.0.0/0");
 
     private Ipv4Util() {
index effad46d4e19dbcff2b2f3edc61912228066cbcd..f25a3eccc078266490dbe8df450b45aaa80d8e38 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
  */
 public final class Ipv6Util {
     public static final int IPV6_LENGTH = 16;
  */
 public final class Ipv6Util {
     public static final int IPV6_LENGTH = 16;
+    public static final int IPV6_BITS_LENGTH = 128;
     private static final Ipv6Prefix EMPTY_PREFIX = new Ipv6Prefix("::/0");
 
     private Ipv6Util() {
     private static final Ipv6Prefix EMPTY_PREFIX = new Ipv6Prefix("::/0");
 
     private Ipv6Util() {