Handle Path Id under Evpn nlri 59/71359/1
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 25 Apr 2018 19:48:56 +0000 (21:48 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 25 Apr 2018 20:13:03 +0000 (22:13 +0200)
Change-Id: Id28defea49d0d444ce2313a90652e4cd0074c255
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EvpnNlriParser.java
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupportTest.java
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EvpnNlriParserTest.java

index fbd2b6e542b6da6213ee9c87680ddbb4ed6ddca6..5a65692225f3cdd886ee9c6e9807457d80cb4d74 100644 (file)
@@ -20,8 +20,11 @@ import javax.annotation.Nullable;
 import org.opendaylight.protocol.bgp.evpn.spi.EvpnRegistry;
 import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEvpnNlriRegistry;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
+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.evpn.rev180329.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.EvpnChoice;
@@ -40,7 +43,10 @@ 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.WithdrawnRoutes;
 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.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
 import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
@@ -51,26 +57,30 @@ import org.slf4j.LoggerFactory;
 public final class EvpnNlriParser implements NlriParser, NlriSerializer {
     private static final Logger LOG = LoggerFactory.getLogger(EvpnNlriParser.class);
     private static final NodeIdentifier EVPN_CHOICE_NID = new NodeIdentifier(EvpnChoice.QNAME);
+    private static final NodeIdentifier  PATH_ID_NID =
+            new NodeIdentifier(QName.create(EvpnChoice.QNAME, "path-id").intern());
 
     @FunctionalInterface
     private interface ExtractionInterface {
         EvpnChoice check(EvpnRegistry reg, ChoiceNode cont);
     }
 
-    public static EvpnDestination extractEvpnDestination(final DataContainerNode<? extends PathArgument> evpnChoice) {
-        return extractDestination(evpnChoice, EvpnRegistry::serializeEvpnModel);
+    public static EvpnDestination extractEvpnDestination(final DataContainerNode<? extends PathArgument> route) {
+        return extractDestination(route, EvpnRegistry::serializeEvpnModel);
     }
 
-    private static EvpnDestination extractDestination(final DataContainerNode<? extends PathArgument> evpnChoice,
+    private static EvpnDestination extractDestination(final DataContainerNode<? extends PathArgument> route,
             final ExtractionInterface extract) {
         final EvpnRegistry reg = SimpleEvpnNlriRegistry.getInstance();
-        final ChoiceNode cont = (ChoiceNode) evpnChoice.getChild(EVPN_CHOICE_NID).get();
+        final ChoiceNode cont = (ChoiceNode) route.getChild(EVPN_CHOICE_NID).get();
         final EvpnChoice evpnValue = extract.check(reg, cont);
         if (evpnValue == null) {
             LOG.warn("Unrecognized Nlri {}", cont);
             return null;
         }
-        return new EvpnDestinationBuilder().setRouteDistinguisher(extractRouteDistinguisher(evpnChoice))
+        return new EvpnDestinationBuilder()
+                .setRouteDistinguisher(extractRouteDistinguisher(route))
+                .setPathId(PathIdUtil.buildPathId(route, PATH_ID_NID))
                 .setEvpnChoice(evpnValue).build();
     }
 
@@ -85,7 +95,7 @@ public final class EvpnNlriParser implements NlriParser, NlriSerializer {
         if (!nlri.isReadable()) {
             return;
         }
-        final List<EvpnDestination> dst = parseNlri(nlri);
+        final List<EvpnDestination> dst = parseNlri(nlri, constraint, builder.getAfi(), builder.getSafi());
 
         builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.update.attributes
@@ -101,7 +111,7 @@ public final class EvpnNlriParser implements NlriParser, NlriSerializer {
         if (!nlri.isReadable()) {
             return;
         }
-        final List<EvpnDestination> dst = parseNlri(nlri);
+        final List<EvpnDestination> dst = parseNlri(nlri, constraint, builder.getAfi(), builder.getSafi());
 
         builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
             new DestinationEvpnCaseBuilder().setDestinationEvpn(new DestinationEvpnBuilder()
@@ -109,7 +119,8 @@ public final class EvpnNlriParser implements NlriParser, NlriSerializer {
     }
 
     @Nullable
-    private static List<EvpnDestination> parseNlri(final ByteBuf nlri) {
+    private static List<EvpnDestination> parseNlri(final ByteBuf nlri, final PeerSpecificParserConstraint constraints,
+            final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
         if (!nlri.isReadable()) {
             return null;
         }
@@ -117,6 +128,9 @@ public final class EvpnNlriParser implements NlriParser, NlriSerializer {
 
         while (nlri.isReadable()) {
             final EvpnDestinationBuilder builder = new EvpnDestinationBuilder();
+            if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) {
+                builder.setPathId(PathIdUtil.readPathId(nlri));
+            }
             final NlriType type = NlriType.forValue(nlri.readUnsignedByte());
             final int length = nlri.readUnsignedByte();
             final ByteBuf nlriBuf = nlri.readSlice(length);
index c4f492fe2cd82ef79ff94dc7b97f6519a8ef77e1..bb81a87d7f3e22cc64b3d4ed94004210a8cbbb82 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertNull;
 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.RD;
 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE;
 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE_KEY;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
 
 import com.google.common.collect.ImmutableSet;
 import io.netty.buffer.ByteBuf;
@@ -55,8 +56,11 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest {
     private static final EvpnRibSupport RIB_SUPPORT = EvpnRibSupport.getInstance();
     private static final EvpnRoute ROUTE;
     private static final EvpnRouteKey ROUTE_KEY;
-    private static final EvpnDestination EVPN_DESTINATION = new EvpnDestinationBuilder().setRouteDistinguisher(RD)
-            .setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build();
+    private static final EvpnDestination EVPN_DESTINATION = new EvpnDestinationBuilder()
+            .setRouteDistinguisher(RD)
+            .setEvpnChoice(ETHERNET_AD_ROUTE_CASE)
+            .setPathId(NON_PATH_ID)
+            .build();
     private static final DestinationEvpnCase REACH_NLRI = new DestinationEvpnCaseBuilder()
             .setDestinationEvpn(new DestinationEvpnBuilder()
                     .setEvpnDestination(Collections.singletonList(EVPN_DESTINATION)).build()).build();
index 731adc69a1d039b8145b830121e5c6caf5b1eb2d..80762f54cb2ffad8eef9a5abd11a5ccd17e904c3 100644 (file)
@@ -25,6 +25,8 @@ import org.junit.Test;
 import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EvpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.L2vpnAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.EvpnChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.destination.EvpnDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.destination.EvpnDestinationBuilder;
@@ -77,12 +79,16 @@ public class EvpnNlriParserTest {
     @Test
     public void testMpUnreach() throws BGPParsingException {
         final MpUnreachNlriBuilder mpReach = new MpUnreachNlriBuilder();
+        mpReach.setAfi(L2vpnAddressFamily.class);
+        mpReach.setSafi(EvpnSubsequentAddressFamily.class);
         this.parser.parseNlri(Unpooled.wrappedBuffer(IncMultEthTagRParserTest.RESULT), mpReach, null);
         assertEquals(createUnreach(), mpReach.build());
     }
 
     private MpUnreachNlri createUnreach() {
         final MpUnreachNlriBuilder mpReachExpected = new MpUnreachNlriBuilder();
+        mpReachExpected.setAfi(L2vpnAddressFamily.class);
+        mpReachExpected.setSafi(EvpnSubsequentAddressFamily.class);
         final WithdrawnRoutes wd = new WithdrawnRoutesBuilder().setDestinationType(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.update
                         .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCaseBuilder()
@@ -96,9 +102,13 @@ public class EvpnNlriParserTest {
     @Test
     public void testMpReach() throws BGPParsingException {
         final MpReachNlriBuilder mpReach = new MpReachNlriBuilder();
+        mpReach.setAfi(L2vpnAddressFamily.class);
+        mpReach.setSafi(EvpnSubsequentAddressFamily.class);
         this.parser.parseNlri(Unpooled.wrappedBuffer(IncMultEthTagRParserTest.RESULT), mpReach, null);
 
         final MpReachNlriBuilder mpReachExpected = new MpReachNlriBuilder();
+        mpReachExpected.setAfi(L2vpnAddressFamily.class);
+        mpReachExpected.setSafi(EvpnSubsequentAddressFamily.class);
         final AdvertizedRoutes wd = new AdvertizedRoutesBuilder().setDestinationType(new DestinationEvpnCaseBuilder()
                 .setDestinationEvpn(new DestinationEvpnBuilder().setEvpnDestination(this.dest).build())
                 .build()).build();