Bug-7708: Invalid Route Distinguisher error while processing withdraw update containi...
[bgpcep.git] / bgp / labeled-unicast / src / test / java / org / opendaylight / protocol / bgp / labeled / unicast / LUNlriParserTest.java
old mode 100644 (file)
new mode 100755 (executable)
index 09b7044..a06b71a
@@ -11,21 +11,30 @@ import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.List;
+import java.util.Optional;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.LabelValue;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.LabeledUnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStack;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStackBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
@@ -39,6 +48,7 @@ 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.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
 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;
 
 public class LUNlriParserTest {
 
@@ -54,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,
@@ -62,6 +72,56 @@ 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:
+    * 1        <- Path Id
+    * 60       <- length 96
+    * 00 16 3  <- labelValue 355
+    * 0        <- etc&bottomBit 0
+    * 00 16 4  <- labelValue 356
+    * 0        <- etc&bottomBit 0
+    * 00 16 6  <- labelValue 357
+    * 1        <- bottomBit 1
+    * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+    */
+    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,
+        (byte) 0x00, (byte) 0x16, (byte) 0x40,
+        (byte) 0x00, (byte) 0x16, (byte) 0x51,
+        (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:
@@ -74,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,
@@ -85,13 +145,84 @@ 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:
+     * C8       <- length 200
+     * 00 16 3  <- labelValue 355
+     * 0        <- etc&bottomBit 0
+     * 00 16 4  <- labelValue 356
+     * 0        <- etc&bottomBit 0
+     * 00 16 6  <- labelValue 357
+     * 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_REACH_NLRI_IPv6_ADD_PATH = new byte[]{
+        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+        (byte) 0xC8,
+        (byte) 0x00, (byte) 0x16, (byte) 0x30,
+        (byte) 0x00, (byte) 0x16, (byte) 0x40,
+        (byte) 0x00, (byte) 0x16, (byte) 0x51,
+        (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 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 LabelValue(355)).build(),
-            new LabelStackBuilder().setLabelValue(new LabelValue(356)).build(),
-            new LabelStackBuilder().setLabelValue(new LabelValue(357)).build());
+        new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build(),
+        new LabelStackBuilder().setLabelValue(new MplsLabel(356L)).build(),
+        new LabelStackBuilder().setLabelValue(new MplsLabel(357L)).build());
 
     private static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
     private static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/128"));
+    private static final PathId PATH_ID = new PathId(1L);
+
+    @Mock
+    private PeerSpecificParserConstraint constraint;
+    @Mock
+    private MultiPathSupport muliPathSupport;
+
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any());
+        Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
+    }
 
     @Test
     public void testMpReachNlriIpv4() throws BGPParsingException {
@@ -101,23 +232,49 @@ public class LUNlriParserTest {
         mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
         final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
         mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
-                        new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
-                        .build())
-                        .build());
+            new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+                new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
         final MpReachNlri mpReachExpected = mpBuilder.build();
 
         //test parser
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4), testBuilder);
-        Assert.assertEquals(mpBuilder.build(), mpReachExpected);
+        testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        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));
+            new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
+        Assert.assertArrayEquals(LU_REACH_NLRI_IPv4, ByteArray.readAllBytes(output));
+    }
+
+    @Test
+    public void testMpReachNlriIpv4Constraint() throws BGPParsingException {
+        final LUNlriParser parser = new LUNlriParser();
+        final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+        mpBuilder.setAfi(Ipv4AddressFamily.class);
+        mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).setLabelStack
+            (LABEL_STACK).build();
+        mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+            new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+                new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
+        final MpReachNlri mpReachExpected = mpBuilder.build();
+
+        //test parser
+        final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
+        testBuilder.setAfi(Ipv4AddressFamily.class);
+        testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        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_REACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -126,25 +283,78 @@ 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(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_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(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
+    public void testMpUnreachNlriIpv4Constraint() throws BGPParsingException {
+        final LUNlriParser parser = new LUNlriParser();
+        final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
+        mpBuilder.setAfi(Ipv4AddressFamily.class);
+        mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+
+        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(lu1)).build())
+                .build()).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(lu)).build())
-                        .build())
-                        .build());
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.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.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);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4), testBuilder);
-        Assert.assertEquals(mpBuilder.build(), mpUnreachExpected);
+        testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        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, 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
@@ -154,24 +364,51 @@ public class LUNlriParserTest {
         mpBuilder.setAfi(Ipv6AddressFamily.class);
         mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
         final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
+        mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6LabeledUnicastCaseBuilder()
+            .setDestinationIpv6LabeledUnicast(new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
+            .build()).build());
+        final MpReachNlri mpReachExpected = mpBuilder.build();
+
+        //test parser
+        final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
+        testBuilder.setAfi(Ipv6AddressFamily.class);
+        testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        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_REACH_NLRI_IPv6, ByteArray.readAllBytes(output));
+    }
+
+    @Test
+    public void testMpReachNlriIpv6Constraint() throws BGPParsingException {
+        final LUNlriParser parser = new LUNlriParser();
+        final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+        mpBuilder.setAfi(Ipv6AddressFamily.class);
+        mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
         mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
-                        new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
-                        .build())
-                        .build());
+            new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
+                new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
+                .build())
+            .build());
         final MpReachNlri mpReachExpected = mpBuilder.build();
 
         //test parser
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
-        Assert.assertEquals(mpBuilder.build(), mpReachExpected);
+        testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        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, ByteArray.readAllBytes(output));
+            new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
+        Assert.assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -180,24 +417,86 @@ 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.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())
-                        .build())
-                        .build());
-        final MpUnreachNlri mpUnreachExpected = mpBuilder.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.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);
-        parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
-        Assert.assertEquals(mpBuilder.build(), mpUnreachExpected);
+        testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+        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
+    public void testMpUnreachNlriIpv6Constraint() throws BGPParsingException {
+        final LUNlriParser parser = new LUNlriParser();
+        final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
+        mpBuilder.setAfi(Ipv6AddressFamily.class);
+        mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+
+        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(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_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(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));
     }
 }