Handle path Id under L3vpn 11/71311/1
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 25 Apr 2018 12:39:53 +0000 (14:39 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 25 Apr 2018 12:54:10 +0000 (14:54 +0200)
Change-Id: Ibaf99870f2c2d775315471cb62a48a65deb2acf3
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnNlriParser.java
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/VpnDestinationUtil.java
bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4NlriParserTest.java
bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6NlriParserTest.java

index a61e82b701ab1f6498585857473ba0f0f3cd7f3b..d41b9fef70a69b68e975a97684847c3375c63741 100644 (file)
@@ -13,7 +13,6 @@ import io.netty.buffer.Unpooled;
 import java.util.List;
 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
@@ -106,21 +105,23 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
 
     @Override
     public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder,
-            final PeerSpecificParserConstraint constraint) throws BGPParsingException {
+        final PeerSpecificParserConstraint constraint) {
         if (!nlri.isReadable()) {
             return;
         }
-        final List<VpnDestination> dst = VpnDestinationUtil.parseNlri(nlri, builder.getAfi());
+        final List<VpnDestination> dst = VpnDestinationUtil.parseNlri(nlri, constraint,
+                builder.getAfi(), builder.getSafi());
         builder.setWithdrawnRoutes(getWithdrawnRoutesByDestination(dst));
     }
 
     @Override
     public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder,
-            final PeerSpecificParserConstraint constraint) throws BGPParsingException {
+        final PeerSpecificParserConstraint constraint) {
         if (!nlri.isReadable()) {
             return;
         }
-        final List<VpnDestination> dst = VpnDestinationUtil.parseNlri(nlri, builder.getAfi());
+        final List<VpnDestination> dst = VpnDestinationUtil.parseNlri(nlri, constraint,
+                builder.getAfi(), builder.getSafi());
         builder.setAdvertizedRoutes(getAdvertizedRoutesByDestination(dst));
     }
 }
index eb1e2df24ad86fc0c018a9a9039ff93193c234ea..39e7b0796ed558ecc206c86238361d7b4012e6c3 100644 (file)
@@ -80,12 +80,12 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport<VpnRoute,
     }
 
     private VpnDestination extractVpnDestination(final DataContainerNode<? extends PathArgument> route) {
-        final VpnDestination dst = new VpnDestinationBuilder()
-            .setPrefix(createPrefix(extractPrefix(route)))
-            .setLabelStack(LabeledUnicastIpv4RIBSupport.extractLabel(route, this.labelStackNid, this.lvNid))
-            .setRouteDistinguisher(extractRouteDistinguisher(route))
-            .build();
-        return dst;
+        return new VpnDestinationBuilder()
+                .setPrefix(createPrefix(extractPrefix(route)))
+                .setLabelStack(LabeledUnicastIpv4RIBSupport.extractLabel(route, this.labelStackNid, this.lvNid))
+                .setRouteDistinguisher(extractRouteDistinguisher(route))
+                .setPathId(PathIdUtil.buildPathId(route, routePathIdNid()))
+                .build();
     }
 
     protected abstract IpPrefix createPrefix(String prefix);
index c8da0b86e680dda2f7cf21cb2dec06116c8fd10b..32f3c0cb80af133fc4f1ff8e32bd485ff6a62809 100644 (file)
@@ -14,8 +14,13 @@ import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStack;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestinationBuilder;
 
@@ -24,7 +29,11 @@ final class VpnDestinationUtil {
         throw new UnsupportedOperationException();
     }
 
-    static List<VpnDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi) {
+    static List<VpnDestination> parseNlri(
+            final ByteBuf nlri,
+            final PeerSpecificParserConstraint constraints,
+            final Class<? extends AddressFamily> afi,
+            final Class<? extends SubsequentAddressFamily> safi) {
         if (!nlri.isReadable()) {
             return null;
         }
@@ -32,6 +41,9 @@ final class VpnDestinationUtil {
 
         while (nlri.isReadable()) {
             final VpnDestinationBuilder builder = new VpnDestinationBuilder();
+            if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) {
+                builder.setPathId(PathIdUtil.readPathId(nlri));
+            }
             final short length = nlri.readUnsignedByte();
             final List<LabelStack> labels = LUNlriParser.parseLabel(nlri);
             builder.setLabelStack(labels);
index e7870a64f2938a96c183072c94aa82cee5dc2cdd..4db1be504cd38caa756c85960928dbc54777f387 100755 (executable)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.protocol.bgp.l3vpn.ipv4;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.Collections;
 import java.util.List;
-import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
@@ -32,6 +35,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.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.MplsLabeledVpnSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisherBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.l3vpn.ipv4.destination.VpnIpv4DestinationBuilder;
@@ -84,7 +88,7 @@ public class VpnIpv4NlriParserTest {
     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();
+            .setPrefix(IPV4_PREFIX).setPathId(NON_PATH_ID).setLabelStack(LABEL_STACK).build();
     private static final VpnDestination IPV4_VPN_WITHOUT_LABELS = new VpnDestinationBuilder()
             .setRouteDistinguisher(DISTINGUISHER).setPrefix(IPV4_PREFIX).build();
 
@@ -92,19 +96,22 @@ public class VpnIpv4NlriParserTest {
     public void testMpReachNlri() throws BGPParsingException {
         final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
         mpBuilder.setAfi(Ipv4AddressFamily.class);
+        mpBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
         mpBuilder.setAdvertizedRoutes(
             new AdvertizedRoutesBuilder().setDestinationType(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.update
                         .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4CaseBuilder()
                         .setVpnIpv4Destination(new VpnIpv4DestinationBuilder().setVpnDestination(
-                                Collections.singletonList(IPV4_VPN)).build()).build()).build()).build();
+                                Collections.singletonList(new VpnDestinationBuilder(IPV4_VPN).setPathId(null)
+                                        .build())).build()).build()).build()).build();
 
         final MpReachNlri mpReachExpected = mpBuilder.build();
 
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
+        testBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
         PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder, null);
-        Assert.assertEquals(mpReachExpected, testBuilder.build());
+        assertEquals(mpReachExpected, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
         PARSER.serializeAttribute(
@@ -112,13 +119,14 @@ public class VpnIpv4NlriParserTest {
                 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
+        assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
     }
 
     @Test
     public void testMpUnreachNlri() throws BGPParsingException {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv4AddressFamily.class);
+        mpBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
 
         mpBuilder.setWithdrawnRoutes(
             new WithdrawnRoutesBuilder().setDestinationType(
@@ -138,8 +146,9 @@ public class VpnIpv4NlriParserTest {
 
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv4AddressFamily.class);
+        testBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
         PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder, null);
-        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
+        assertEquals(mpUnreachExpected1, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
         PARSER.serializeAttribute(
@@ -147,6 +156,6 @@ public class VpnIpv4NlriParserTest {
                 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
+        assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
     }
 }
index a46dc0c4e305fdf238ae0f150097595d33ac2236..88e30a61307af18d9a8134122125a06343af5e53 100755 (executable)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.protocol.bgp.l3vpn.ipv6;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.Collections;
 import java.util.List;
-import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
@@ -32,6 +35,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.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.MplsLabeledVpnSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisherBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.destination.VpnIpv6DestinationBuilder;
@@ -84,7 +88,8 @@ public class VpnIpv6NlriParserTest {
     static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder
             .getDefaultInstance("1.2.3.4:258");
     static final VpnDestination IPV6_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER)
-            .setPrefix(IPV6PREFIX).setLabelStack(LABEL_STACK).build();
+            .setPrefix(IPV6PREFIX).setLabelStack(LABEL_STACK).setPathId(NON_PATH_ID)
+            .build();
     private static final VpnDestination IPV6_VPN_WITHOUT_LABELS = new VpnDestinationBuilder()
             .setRouteDistinguisher(DISTINGUISHER).setPrefix(IPV6PREFIX).build();
 
@@ -92,18 +97,21 @@ public class VpnIpv6NlriParserTest {
     public void testMpReachNlri() throws BGPParsingException {
         final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
         mpBuilder.setAfi(Ipv6AddressFamily.class);
+        mpBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
         mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.update
                     .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6CaseBuilder()
                     .setVpnIpv6Destination(new VpnIpv6DestinationBuilder().setVpnDestination(
-                            Collections.singletonList(IPV6_VPN)).build()).build()).build()).build();
+                            Collections.singletonList(new VpnDestinationBuilder(IPV6_VPN).setPathId(null).build()))
+                            .build()).build()).build()).build();
 
         final MpReachNlri mpReachExpected = mpBuilder.build();
 
         final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
+        testBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
         PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder, null);
-        Assert.assertEquals(mpReachExpected, testBuilder.build());
+        assertEquals(mpReachExpected, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
         PARSER.serializeAttribute(
@@ -111,13 +119,14 @@ public class VpnIpv6NlriParserTest {
                 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
+        assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
     }
 
     @Test
     public void testMpUnreachNlri() throws BGPParsingException {
         final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
         mpBuilder.setAfi(Ipv6AddressFamily.class);
+        mpBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
 
         mpBuilder.setWithdrawnRoutes(
             new WithdrawnRoutesBuilder().setDestinationType(
@@ -137,8 +146,9 @@ public class VpnIpv6NlriParserTest {
 
         final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
         testBuilder.setAfi(Ipv6AddressFamily.class);
+        testBuilder.setSafi(MplsLabeledVpnSubsequentAddressFamily.class);
         PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder, null);
-        Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
+        assertEquals(mpUnreachExpected1, testBuilder.build());
 
         final ByteBuf output = Unpooled.buffer();
         PARSER.serializeAttribute(
@@ -146,6 +156,6 @@ public class VpnIpv6NlriParserTest {
                 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
             ).build(), output
         );
-        Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
+        assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
     }
 }