From d110c542a87fca9c342c1cd8e672781fa2e6ed0e Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Wed, 1 Jun 2016 10:35:48 +0200 Subject: [PATCH] BUG-5983: Fix wrong representation of Ip length Ip Length representation is in bits for Ethernet Segment Route, Inclusive Multicast Ethernet Tag Route. Change-Id: I5c3057acb83ab4881d0889d8684d6ea4c405a385 Signed-off-by: Claudio D. Gasparini --- .../bgp/evpn/impl/esi/types/ArbitraryParser.java | 5 +++-- .../protocol/bgp/evpn/impl/nlri/EthSegRParser.java | 10 +++++----- .../protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java | 8 ++++---- .../protocol/bgp/evpn/impl/nlri/EthSegRParserTest.java | 8 ++++---- .../bgp/evpn/impl/nlri/IncMultEthTagRParserTest.java | 4 ++-- .../java/org/opendaylight/protocol/util/Ipv4Util.java | 1 + .../java/org/opendaylight/protocol/util/Ipv6Util.java | 1 + 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ArbitraryParser.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ArbitraryParser.java index b2c784c941..2583f8370c 100644 --- a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ArbitraryParser.java +++ b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ArbitraryParser.java @@ -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 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; @@ -40,7 +41,7 @@ final class ArbitraryParser extends AbstractEsiType { @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(); } } diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParser.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParser.java index 0ffe8683e5..936e3a4251 100644 --- a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParser.java +++ b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParser.java @@ -79,10 +79,10 @@ final class EthSegRParser extends AbstractEvpnNlri { } 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)); - } else if (ipLength == Ipv4Util.IP4_LENGTH) { + } else if (ipLength == Ipv4Util.IP4_BITS_LENGTH) { 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) { - body.writeByte(Ipv4Util.IP4_LENGTH); + body.writeByte(Ipv4Util.IP4_BITS_LENGTH); 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); diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java index 062405f8b4..4295769a2e 100644 --- a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java +++ b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java @@ -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) { - 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.writeByte(Ipv6Util.IPV6_LENGTH * BITS_SIZE); + body.writeByte(Ipv6Util.IPV6_BITS_LENGTH); 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(); - if (ipLength == Ipv6Util.IPV6_LENGTH * BITS_SIZE) { + if (ipLength == Ipv6Util.IPV6_BITS_LENGTH) { 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; diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParserTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParserTest.java index 65a7b9d654..3020cb818e 100644 --- a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParserTest.java +++ b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthSegRParserTest.java @@ -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, - (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, - (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, - (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, @@ -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) 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, diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParserTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParserTest.java index 40e260a692..1433943962 100644 --- a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParserTest.java +++ b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParserTest.java @@ -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) 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, - (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01 + (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01 }; private IncMultEthTagRParser parser; diff --git a/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java b/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java index 781d0a9698..b466121d9b 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java +++ b/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java @@ -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 static final int IP4_BITS_LENGTH = 32; private static final Ipv4Prefix EMPTY_PREFIX = new Ipv4Prefix("0.0.0.0/0"); private Ipv4Util() { diff --git a/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java b/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java index effad46d4e..f25a3eccc0 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java +++ b/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java @@ -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 static final int IPV6_BITS_LENGTH = 128; private static final Ipv6Prefix EMPTY_PREFIX = new Ipv6Prefix("::/0"); private Ipv6Util() { -- 2.36.6