Bug-7708: Invalid Route Distinguisher error while processing withdraw update containi... 83/51283/7
authorAjay <ajayl.bro@gmail.com>
Wed, 1 Feb 2017 08:24:22 +0000 (08:24 +0000)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 6 Feb 2017 08:39:31 +0000 (08:39 +0000)
 - RFC 3107 says that label value in withdraw message should be 0x800000
   ref. https://tools.ietf.org/html/rfc3107#section-3
 - Changed code to correctly handle this value in withdraw message received from peer.
   Also ODL will now use this value when sending withdraw message to its peer
 - Updated unit-tests accordingly

Change-Id: Ie9d90779c32e9141f953a18b07a86d0624eaee5c
Signed-off-by: Ajay <ajayl.bro@gmail.com>
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnNlriParser.java
bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4NlriParserTest.java [changed mode: 0644->0755]
bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6NlriParserTest.java [changed mode: 0644->0755]
bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java
bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParser.java
bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParserTest.java [changed mode: 0644->0755]
bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupportTest.java
bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupportTest.java
util/src/main/java/org/opendaylight/protocol/util/MplsLabelUtil.java

index ea46f9e9f6bec84f4d69c8e22633c656f28a516e..b0414a34074cdb47f0d133097249d59feaa9ef75 100644 (file)
@@ -45,14 +45,14 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
 
     protected abstract AdvertizedRoutes getAdvertizedRoutesByDestination(List<VpnDestination> dst);
 
-    private static void serializeNlri(final List<VpnDestination> dests, final ByteBuf buffer) {
+    private static void serializeNlri(final List<VpnDestination> dests, final boolean isWithdrawnRoute, final ByteBuf buffer) {
         final ByteBuf nlriByteBuf = Unpooled.buffer();
         for (final VpnDestination dest : dests) {
             final List<LabelStack> labelStack = dest.getLabelStack();
             final IpPrefix prefix = dest.getPrefix();
             LOG.debug("Serializing Nlri: VpnDestination={}, IpPrefix={}", dest, prefix);
             AbstractVpnNlriParser.serializeLengtField(prefix, labelStack, nlriByteBuf);
-            LUNlriParser.serializeLabelStackEntries(labelStack, nlriByteBuf);
+            LUNlriParser.serializeLabelStackEntries(labelStack, isWithdrawnRoute, nlriByteBuf);
             RouteDistinguisherUtil.serializeRouteDistinquisher(dest.getRouteDistinguisher(), nlriByteBuf);
             Preconditions.checkArgument(prefix.getIpv6Prefix() != null || prefix.getIpv4Prefix() != null, "Ipv6 or Ipv4 prefix is missing.");
             LUNlriParser.serializePrefixField(prefix, nlriByteBuf);
@@ -85,8 +85,9 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
         while (nlri.isReadable()) {
             final VpnDestinationBuilder builder = new VpnDestinationBuilder();
             final short length = nlri.readUnsignedByte();
-            builder.setLabelStack(LUNlriParser.parseLabel(nlri));
-            final int labelNum = builder.getLabelStack().size();
+            final List<LabelStack> labels = LUNlriParser.parseLabel(nlri);
+            builder.setLabelStack(labels);
+            final int labelNum = labels != null ? labels.size() : 1;
             final int prefixLen = length - (LUNlriParser.LABEL_LENGTH * Byte.SIZE * labelNum) - (RouteDistinguisherUtil.RD_LENGTH * Byte.SIZE);
             builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
             Preconditions.checkState(prefixLen > 0, "A valid VPN IP prefix is required.");
@@ -103,6 +104,7 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
         final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class);
         final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class);
         List<VpnDestination> vpnDst = null;
+        boolean isWithdrawnRoute = false;
         if (pathAttributes1 != null) {
             final AdvertizedRoutes routes = (pathAttributes1.getMpReachNlri()).getAdvertizedRoutes();
             if (routes != null) {
@@ -112,10 +114,11 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
             final WithdrawnRoutes routes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes();
             if (routes != null) {
                 vpnDst = getWithdrawnVpnDestination(routes.getDestinationType());
+                isWithdrawnRoute = true;
             }
         }
         if (vpnDst != null) {
-            serializeNlri(vpnDst, byteAggregator);
+            serializeNlri(vpnDst, isWithdrawnRoute, byteAggregator);
         }
     }
 
old mode 100644 (file)
new mode 100755 (executable)
index a86ba0f..7c8c04a
@@ -42,17 +42,47 @@ public class VpnIpv4NlriParserTest {
 
     private static final VpnIpv4NlriParser PARSER = new VpnIpv4NlriParser();
 
-    private static final byte[] NLRI_TYPE1 = new byte[]{
+    /* Reach NLRI prefix value.
+    *
+    * prefix contents:
+    * 70          <- length 112
+    * 00 16 3     <- labelValue 355
+    * 1           <- bottomBit 1
+    * 00 01       <- routeDistinguisher Type=1
+    * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+    * 01 02       <- routeDistinguisher AS=258
+    * 22 01 16    <- prefixType IPV4=34.1.22.0/24
+    */
+    private static final byte[] REACH_NLRI = new byte[] {
         (byte) 0x70,
         (byte) 0x00, (byte) 0x16, (byte) 0x31,
         0, 1, 1, 2, 3, 4, 1, 2,
         (byte) 0x22, (byte) 0x01, (byte) 0x16,
     };
+
+    /* Unreach NLRI prefix value.
+    *
+    * prefix contents:
+    * 70          <- length 112
+    * 80 00 00    <- labelValue for withdraw
+    * 00 01       <- routeDistinguisher Type=1
+    * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+    * 01 02       <- routeDistinguisher AS=258
+    * 22 01 16    <- prefixType IPV4=34.1.22.0/24
+    */
+    private static final byte[] UNREACH_NLRI = new byte[] {
+        (byte) 0x70,
+        (byte) 0x80, (byte) 0x00, (byte) 0x00,
+        0, 1, 1, 2, 3, 4, 1, 2,
+        (byte) 0x22, (byte) 0x01, (byte) 0x16,
+    };
+
     static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
     static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
         new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
     static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258");
     static final VpnDestination IPV4_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
+    private static final VpnDestination IPV4_VPN_WITHOUT_LABELS = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv4_PREFIX).build();
 
     @Test
     public void testMpReachNlri() throws BGPParsingException {
@@ -70,7 +100,7 @@ public class VpnIpv4NlriParserTest {
 
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
-        PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
+        PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder);
         Assert.assertEquals(mpReachExpected, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
@@ -79,34 +109,43 @@ public class VpnIpv4NlriParserTest {
                 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
     }
 
     @Test
     public void testMpUnreachNlri() throws BGPParsingException {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv4AddressFamily.class);
+
         mpBuilder.setWithdrawnRoutes(
             new WithdrawnRoutesBuilder().setDestinationType(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(
-                    new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build()
+                    new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN_WITHOUT_LABELS)).build()
                 ).build()
             ).build()
         ).build();
+        final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
 
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+        mpBuilder.setWithdrawnRoutes(
+            new WithdrawnRoutesBuilder().setDestinationType(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(
+                    new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build()
+                ).build()
+            ).build()
+        ).build();
+        final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
 
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
-        PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
-        Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+        PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder);
+        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
         PARSER.serializeAttribute(
             new AttributesBuilder().addAugmentation(Attributes2.class,
-                new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()
+                new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 1f1cafd..64ead20
@@ -45,17 +45,47 @@ public class VpnIpv6NlriParserTest {
 
     private static final VpnIpv6NlriParser PARSER = new VpnIpv6NlriParser();
 
-    private static final byte[] NLRI_TYPE1 = new byte[]{
-        (byte) 0x88,    // length
-        (byte) 0x00, (byte) 0x16, (byte) 0x31,  // label
-        0, 1, 1, 2, 3, 4, 1, 2, // route distinguisher
-        (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89    // specify the IPv6 prefix here
+    /* Reach NLRI prefix value.
+    *
+    * prefix contents:
+    * 88          <- length 136
+    * 00 16 3     <- labelValue 355
+    * 01          <- bottomBit 1
+    * 00 01       <- routeDistinguisher Type=1
+    * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+    * 01 02       <- routeDistinguisher AS=258
+    * 20 01 23 45 56 89 <- prefixType IPV6=2001:2345:5689::/48
+    */
+    private static final byte[] REACH_NLRI = new byte[] {
+        (byte) 0x88,
+        (byte) 0x00, (byte) 0x16, (byte) 0x31,
+        0, 1, 1, 2, 3, 4, 1, 2,
+        (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89
     };
+
+    /* Unreach NLRI prefix value.
+    *
+    * prefix contents:
+    * 88          <- length 136
+    * 80 00 00    <- labelValue for withdraw
+    * 00 01       <- routeDistinguisher Type=1
+    * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+    * 01 02       <- routeDistinguisher AS=258
+    * 20 01 23 45 56 89 <- prefixType IPV6=2001:2345:5689::/48
+    */
+    private static final byte[] UNREACH_NLRI = new byte[] {
+        (byte) 0x88,
+        (byte) 0x80, (byte) 0x00, (byte) 0x00,
+        0, 1, 1, 2, 3, 4, 1, 2,
+        (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89
+    };
+
     static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:2345:5689::/48"));
     static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
         new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
     static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258");
     static final VpnDestination IPV6_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
+    private static final VpnDestination IPV6_VPN_WITHOUT_LABELS = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).build();
 
     @Test
     public void testMpReachNlri() throws BGPParsingException {
@@ -72,7 +102,7 @@ public class VpnIpv6NlriParserTest {
 
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
-        PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
+        PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder);
         Assert.assertEquals(mpReachExpected, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
@@ -81,34 +111,43 @@ public class VpnIpv6NlriParserTest {
                 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
     }
 
     @Test
     public void testMpUnreachNlri() throws BGPParsingException {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv6AddressFamily.class);
+
         mpBuilder.setWithdrawnRoutes(
             new WithdrawnRoutesBuilder().setDestinationType(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
-                    new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()
+                    new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN_WITHOUT_LABELS)).build()
                 ).build()
             ).build()
         ).build();
+        final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
 
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+        mpBuilder.setWithdrawnRoutes(
+            new WithdrawnRoutesBuilder().setDestinationType(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
+                    new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()
+                ).build()
+            ).build()
+        ).build();
+        final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
 
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
-        PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
-        Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+        PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder);
+        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
         PARSER.serializeAttribute(
             new AttributesBuilder().addAugmentation(Attributes2.class,
-                new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()
+                new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
     }
 }
index fc4a733406dcf1876bd9e02fd6efe7dc595cac07..102853f5c1200fd48adacadf7c1325e04e7fc301 100644 (file)
@@ -116,7 +116,7 @@ abstract class AbstractLabeledUnicastRIBSupport extends MultiPathAbstractRIBSupp
         final ByteBuf buffer = Unpooled.buffer();
 
         final CLabeledUnicastDestination dest = extractCLabeledUnicastDestination(labeledUnicast);
-        LUNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
+        LUNlriParser.serializeNlri(Collections.singletonList(dest), false, buffer);
         final String routeKeyValue = ByteArray.encodeBase64(buffer);
         final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = labeledUnicast.getChild(routePathIdNid());
         final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
index 214a543718823acd22f205bae735cd8789d7adae..38b74cdd05186277374e0e7e6ebdfcd4e4da4b94 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.protocol.bgp.labeled.unicast;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -51,11 +52,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 public class LUNlriParser implements NlriParser, NlriSerializer {
 
     public static final int LABEL_LENGTH = 3;
+    private static final byte[] WITHDRAW_LABEL_BYTE_ARRAY = { (byte) 0x80, (byte) 0x00, (byte) 0x00 };
+    private static final int WITHDRAW_LABEL_INT_VALUE = 0x800000;
 
     @Override
     public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
@@ -70,11 +74,11 @@ public class LUNlriParser implements NlriParser, NlriSerializer {
                 if ( destinationType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
                     .labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase){
                     final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase labeledUnicastCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase) routes.getDestinationType();
-                    serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+                    serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), false, byteAggregator);
                 } else if (destinationType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
                     .labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase) {
                     final  org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase labeledUnicastCase = ( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase) routes.getDestinationType();
-                    serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+                    serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), false, byteAggregator);
                 }
             }
         } else if (pathAttributes2 != null) {
@@ -83,41 +87,47 @@ public class LUNlriParser implements NlriParser, NlriSerializer {
                 final DestinationType destinationType = mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
                 if (destinationType instanceof DestinationLabeledUnicastCase) {
                     final DestinationLabeledUnicastCase labeledUnicastCase = (DestinationLabeledUnicastCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
-                    serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+                    serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), true, byteAggregator);
                 } else if(destinationType instanceof DestinationIpv6LabeledUnicastCase) {
                     final DestinationIpv6LabeledUnicastCase labeledUnicastCase = (DestinationIpv6LabeledUnicastCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
-                    serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+                    serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), true, byteAggregator);
                 }
             }
         }
     }
 
-    protected static void serializeNlri(final List<CLabeledUnicastDestination> dests, final ByteBuf buffer) {
+    protected static void serializeNlri(final List<CLabeledUnicastDestination> dests, final boolean isUnreachNlri,
+            final ByteBuf buffer) {
         final ByteBuf nlriByteBuf = Unpooled.buffer();
-        for (final CLabeledUnicastDestination dest: dests) {
+        for (final CLabeledUnicastDestination dest : dests) {
             PathIdUtil.writePathId(dest.getPathId(), buffer);
 
             final List<LabelStack> labelStack = dest.getLabelStack();
             final IpPrefix prefix = dest.getPrefix();
             // Serialize the length field
             // Length field contains one Byte which represents the length of label stack and prefix in bits
-            nlriByteBuf.writeByte(((LABEL_LENGTH * labelStack.size()) + getPrefixLength(prefix)) * Byte.SIZE);
+            nlriByteBuf.writeByte(((LABEL_LENGTH * (!isUnreachNlri ? labelStack.size() : 1)) + getPrefixLength(prefix)) * Byte.SIZE);
 
-            serializeLabelStackEntries(labelStack, nlriByteBuf);
+            serializeLabelStackEntries(labelStack, isUnreachNlri, nlriByteBuf);
             serializePrefixField(prefix, nlriByteBuf);
         }
         buffer.writeBytes(nlriByteBuf);
     }
 
-    public static void serializeLabelStackEntries(final List<LabelStack> stack, final ByteBuf buffer) {
-        int i = 1;
-        for (final LabelStack labelStackEntry : stack) {
-            if (i++ == stack.size()) {
-                //mark last label stack entry with bottom-bit
-                buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabelWithBottomBit(labelStackEntry.getLabelValue()));
-            } else {
-                buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabel(labelStackEntry.getLabelValue()));
+    public static void serializeLabelStackEntries(final List<LabelStack> stack, final boolean isUnreachNlri,
+            final ByteBuf buffer) {
+        if (!isUnreachNlri) {
+            int i = 1;
+            for (final LabelStack labelStackEntry : stack) {
+                if (i++ == stack.size()) {
+                    // mark last label stack entry with bottom-bit
+                    buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabelWithBottomBit(labelStackEntry.getLabelValue()));
+                } else {
+                    buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabel(labelStackEntry.getLabelValue()));
+                }
             }
+        } else {
+            buffer.writeBytes(WITHDRAW_LABEL_BYTE_ARRAY);
         }
     }
 
@@ -157,8 +167,9 @@ public class LUNlriParser implements NlriParser, NlriSerializer {
                 builder.setPathId(PathIdUtil.readPathId(nlri));
             }
             final short length = nlri.readUnsignedByte();
-            builder.setLabelStack(parseLabel(nlri));
-            final int labelNum = builder.getLabelStack().size();
+            final List<LabelStack> labels = parseLabel(nlri);
+            builder.setLabelStack(labels);
+            final int labelNum = labels != null ? labels.size() : 1;
             final int prefixLen = length - (LABEL_LENGTH * Byte.SIZE * labelNum);
             builder.setPrefix(parseIpPrefix(nlri, prefixLen, afi));
             dests.add(builder.build());
@@ -185,7 +196,11 @@ public class LUNlriParser implements NlriParser, NlriSerializer {
         do {
             final ByteBuf slice = nlri.readSlice(LABEL_LENGTH);
             bottomBit = MplsLabelUtil.getBottomBit(slice);
-            labels.add(new LabelStackBuilder().setLabelValue(MplsLabelUtil.mplsLabelForByteBuf(slice)).build());
+            final MplsLabel mplsLabel = MplsLabelUtil.mplsLabelForByteBuf(slice);
+            if (MplsLabelUtil.intForMplsLabel(mplsLabel) == WITHDRAW_LABEL_INT_VALUE) {
+                return null;
+            }
+            labels.add(new LabelStackBuilder().setLabelValue(mplsLabel).build());
         } while (!bottomBit);
         return labels;
     }
old mode 100644 (file)
new mode 100755 (executable)
index 9146a87..a06b71a
@@ -64,7 +64,7 @@ public class LUNlriParserTest {
      * 1        <- bottomBit 1
      * 22 01 16 <- prefixType IPV4=34.1.22.0/24
      */
-    private static final byte[] LU_NLRI_IPv4 = new byte[]{
+    private static final byte[] LU_REACH_NLRI_IPv4 = new byte[]{
         (byte) 0x60,
         (byte) 0x00, (byte) 0x16, (byte) 0x30,
         (byte) 0x00, (byte) 0x16, (byte) 0x40,
@@ -72,6 +72,19 @@ public class LUNlriParserTest {
         (byte) 0x22, (byte) 0x01, (byte) 0x16,
     };
 
+    /*label value for withdraw message.
+    *
+    * label stack:
+    * 30       <- length 48
+    * 80 00 00 <- labelValue for withdraw
+    * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+    */
+   private static final byte[] LU_UNREACH_NLRI_IPv4 = new byte[] {
+       (byte) 0x30,
+       (byte) 0x80, (byte) 0x00, (byte) 0x00,
+       (byte) 0x22, (byte) 0x01, (byte) 0x16,
+   };
+
     /*label stacks with multiple labels.
     *
     * label stack:
@@ -85,7 +98,7 @@ public class LUNlriParserTest {
     * 1        <- bottomBit 1
     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
     */
-    private static final byte[] LU_NLRI_IPv4_ADD_PATH = new byte[]{
+    private static final byte[] LU_REACH_NLRI_IPv4_ADD_PATH = new byte[]{
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
         (byte) 0x60,
         (byte) 0x00, (byte) 0x16, (byte) 0x30,
@@ -94,6 +107,21 @@ public class LUNlriParserTest {
         (byte) 0x22, (byte) 0x01, (byte) 0x16,
     };
 
+    /*label value for withdraw message.
+    *
+    * label stack:
+    * 1        <- Path Id
+    * 30       <- length 48
+    * 80 00 00 <- labelValue for withdraw
+    * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+    */
+    private static final byte[] LU_UNREACH_NLRI_IPv4_ADD_PATH = new byte[] {
+        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+        (byte) 0x30,
+        (byte) 0x80, (byte) 0x00, (byte) 0x00,
+        (byte) 0x22, (byte) 0x01, (byte) 0x16,
+    };
+
     /*label stacks with multiple labels.
      *
      * label stack:
@@ -106,7 +134,7 @@ public class LUNlriParserTest {
      * 1        <- bottomBit 1
      * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80  <- prefixType IPV6=2001:db8:1:2::/128
      */
-    private static final byte[] LU_NLRI_IPv6 = new byte[]{
+    private static final byte[] LU_REACH_NLRI_IPv6 = new byte[]{
         (byte) 0xC8,
         (byte) 0x00, (byte) 0x16, (byte) 0x30,
         (byte) 0x00, (byte) 0x16, (byte) 0x40,
@@ -117,6 +145,22 @@ public class LUNlriParserTest {
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     };
 
+    /*label value for withdraw message.
+    *
+    * label stack:
+    * 98       <- length 152
+    * 80 00 00 <- labelValue for withdraw
+    * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80  <- prefixType IPV6=2001:db8:1:2::/128
+    */
+   private static final byte[] LU_UNREACH_NLRI_IPv6 = new byte[] {
+       (byte) 0x98,
+       (byte) 0x80, (byte) 0x00, (byte) 0x00,
+       (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
+       (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
+       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+   };
+
     /*label stacks with multiple labels.
      *
      * label stack:
@@ -129,7 +173,7 @@ public class LUNlriParserTest {
      * 1        <- bottomBit 1
      * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80  <- prefixType IPV6=2001:db8:1:2::/128
      */
-    private static final byte[] LU_NLRI_IPv6_ADD_PATH = new byte[]{
+    private static final byte[] LU_REACH_NLRI_IPv6_ADD_PATH = new byte[]{
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
         (byte) 0xC8,
         (byte) 0x00, (byte) 0x16, (byte) 0x30,
@@ -140,6 +184,24 @@ public class LUNlriParserTest {
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     };
+
+    /*label value for withdraw message.
+    *
+    * label stack:
+    * 98       <- length 152
+    * 80 00 00 <- labelValue for withdraw
+    * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80  <- prefixType IPV6=2001:db8:1:2::/128
+    */
+   private static final byte[] LU_UNREACH_NLRI_IPv6_ADD_PATH = new byte[] {
+       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+       (byte) 0x98,
+       (byte) 0x80, (byte) 0x00, (byte) 0x00,
+       (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
+       (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
+       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+   };
+
     private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
         new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build(),
         new LabelStackBuilder().setLabelValue(new MplsLabel(356L)).build(),
@@ -178,14 +240,14 @@ public class LUNlriParserTest {
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4), testBuilder);
+        parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4), testBuilder);
         Assert.assertEquals(mpReachExpected, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
             new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv4, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(LU_REACH_NLRI_IPv4, ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -205,14 +267,14 @@ public class LUNlriParserTest {
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
+        parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
         Assert.assertEquals(mpReachExpected, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
             new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(LU_REACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -221,25 +283,38 @@ public class LUNlriParserTest {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv4AddressFamily.class);
         mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
+
+        final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).build();
+        mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build())
+                .build()).build());
+        final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+        final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
         mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build())
                 .build()).build());
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+        final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
 
         //test parser
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4), testBuilder);
-        Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+        parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4), testBuilder);
+        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
-            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv4, ByteArray.readAllBytes(output));
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output));
+
+        final ByteBuf output1 = Unpooled.buffer();
+        parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output1));
     }
 
     @Test
@@ -248,25 +323,38 @@ public class LUNlriParserTest {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv4AddressFamily.class);
         mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
+
+        final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).build();
         mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build())
                 .build()).build());
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+        final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+        final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
+        mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build())
+                .build()).build());
+        final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
 
         //test parser
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
-        Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+        parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
+        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
-            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
+
+        final ByteBuf output1 = Unpooled.buffer();
+        parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output1));
     }
 
     @Test
@@ -285,14 +373,14 @@ public class LUNlriParserTest {
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
+        parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6), testBuilder);
         Assert.assertEquals(mpReachExpected, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
             new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv6, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(LU_REACH_NLRI_IPv6, ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -313,14 +401,14 @@ public class LUNlriParserTest {
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
+        parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
         Assert.assertEquals(mpReachExpected, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
             new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
+        Assert.assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -329,27 +417,42 @@ public class LUNlriParserTest {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv6AddressFamily.class);
         mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
+
+        final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).build();
+        mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
+                .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
+                    .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
+                    .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
+        final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+        final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
         mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
                 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
                     .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
-                    .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+                    .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
+        final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
 
         //test parser
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
-        Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+        parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6), testBuilder);
+        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
-            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv6, ByteArray.readAllBytes(output));
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output));
+
+        final ByteBuf output1 = Unpooled.buffer();
+        parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output1));
     }
 
     @Test
@@ -358,27 +461,42 @@ public class LUNlriParserTest {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv6AddressFamily.class);
         mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).setLabelStack
-            (LABEL_STACK).build();
+
+        final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).build();
         mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
                 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
                     .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
-                    .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+                    .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
+        final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+        final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).setLabelStack
+                (LABEL_STACK).build();
+            mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
+                    .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
+                    new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
+                        .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
+                        .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
+            final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
 
         //test parser
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
         testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
-        Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+        parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
+        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
 
         //test serializer
         final ByteBuf output = Unpooled.buffer();
         parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
-            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
-        Assert.assertArrayEquals(LU_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
+
+        final ByteBuf output1 = Unpooled.buffer();
+        parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+            new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+        Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output1));
     }
 }
index 346a147963b309ae20c383c24fd5183de2347e1e..9d85840257154f2930ce1ac2177027fa9a2b35db 100644 (file)
@@ -81,7 +81,7 @@ public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest {
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
-        LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, buffer);
+        LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, false, buffer);
         LABEL_KEY = ByteArray.encodeBase64(buffer);
         ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY);
         ROUTE = new LabeledUnicastRouteBuilder().setKey(ROUTE_KEY).setPrefix(IPv4_PREFIX).setPathId(PATH_ID).setLabelStack(LABEL_STACK)
@@ -203,4 +203,4 @@ public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest {
         final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
         Assert.assertFalse(result.isEmpty());
     }
-}
\ No newline at end of file
+}
index 0aaf3795761993bb8fb554de2b1f5997e251d2f9..fe0c4a1e9576f30a1f98f6e41f451d1b44a09b53 100644 (file)
@@ -82,7 +82,7 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest {
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
-        LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, buffer);
+        LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, false, buffer);
         LABEL_KEY = ByteArray.encodeBase64(buffer);
         ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY);
         ROUTE = new LabeledUnicastRouteBuilder().setKey(ROUTE_KEY).setPrefix(IPv6_PREFIX).setPathId(PATH_ID).setLabelStack(LABEL_STACK)
@@ -204,4 +204,4 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest {
         final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
         Assert.assertFalse(result.isEmpty());
     }
-}
\ No newline at end of file
+}
index 018f6d72116c0b4bf7f19b7ff0042590b1528cd4..1788e05875a16ed8c2d2b1ae40077a82be8c5a31 100644 (file)
@@ -56,7 +56,7 @@ public final class MplsLabelUtil {
      * @param label object
      * @return shifted value
      */
-    private static int intForMplsLabel(final MplsLabel label) {
+    public static int intForMplsLabel(final MplsLabel label) {
         return label.getValue().intValue() << LABEL_OFFSET;
     }