BUG-6734: Generate correct L3VPN route key 37/46237/2
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 27 Sep 2016 07:59:24 +0000 (09:59 +0200)
committerMilos Fabian <milfabia@cisco.com>
Tue, 27 Sep 2016 22:23:08 +0000 (22:23 +0000)
VPN label should no be a part of the L3VPN route key

Change-Id: I004be87834f60bd4d10d7d2f64d9775a1d06bd3c
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
(cherry picked from commit 018100bab78fa6d9e2284df63ed9b604f9ad682a)

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/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupportTest.java
bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupportTest.java

index 11af537fc9dc85c49337289119b8020885d29e90..ea46f9e9f6bec84f4d69c8e22633c656f28a516e 100644 (file)
@@ -34,9 +34,6 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * @author Kevin Wang
- */
 public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerializer {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractVpnNlriParser.class);
 
@@ -48,15 +45,13 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
 
     protected abstract AdvertizedRoutes getAdvertizedRoutesByDestination(List<VpnDestination> dst);
 
-    public static void serializeNlri(final List<VpnDestination> dests, final ByteBuf buffer) {
+    private static void serializeNlri(final List<VpnDestination> dests, 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);
-            // Serialize the length field
-            // Length field contains one Byte which represents the length of label stack and prefix in bits
-            nlriByteBuf.writeByte(((LUNlriParser.LABEL_LENGTH * labelStack.size()) + LUNlriParser.getPrefixLength(prefix) + RouteDistinguisherUtil.RD_LENGTH) * Byte.SIZE);
+            AbstractVpnNlriParser.serializeLengtField(prefix, labelStack, nlriByteBuf);
             LUNlriParser.serializeLabelStackEntries(labelStack, nlriByteBuf);
             RouteDistinguisherUtil.serializeRouteDistinquisher(dest.getRouteDistinguisher(), nlriByteBuf);
             Preconditions.checkArgument(prefix.getIpv6Prefix() != null || prefix.getIpv4Prefix() != null, "Ipv6 or Ipv4 prefix is missing.");
@@ -65,6 +60,22 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize
         buffer.writeBytes(nlriByteBuf);
     }
 
+    /**
+     * Serialize the length field Length field contains one Byte which represents the length of label stack and prefix in bits
+     * @param prefix ipPrefix
+     * @param labelStack list of labelStack
+     * @param nlriByteBuf ByteBuf
+     */
+    static void serializeLengtField(final IpPrefix prefix, final List<LabelStack> labelStack, final ByteBuf nlriByteBuf) {
+        final int prefixLenght = LUNlriParser.getPrefixLength(prefix);
+        int labelStackLenght = 0;
+        if(labelStack != null) {
+            labelStackLenght = LUNlriParser.LABEL_LENGTH * labelStack.size();
+        }
+        nlriByteBuf.writeByte((labelStackLenght + prefixLenght + RouteDistinguisherUtil.RD_LENGTH) * Byte.SIZE);
+    }
+
+
     private static List<VpnDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi) {
         if (!nlri.isReadable()) {
             return null;
index 45d93290a68434b400998439e4027f4c47b4effc..deb7d8a6bb1416dc2217f6d1ccb918cb615f0177 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.bgp.l3vpn;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableCollection;
 import com.google.common.collect.ImmutableSet;
 import io.netty.buffer.ByteBuf;
@@ -17,7 +18,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
+import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser;
 import org.opendaylight.protocol.bgp.labeled.unicast.LabeledUnicastIpv4RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
 import org.opendaylight.protocol.util.ByteArray;
@@ -47,9 +50,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * @author Kevin Wang
- */
 public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractVpnRIBSupport.class);
     private final NodeIdentifier nlriRoutesListNid;
@@ -164,9 +164,20 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
 
     private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode l3vpn) {
         final ByteBuf buffer = Unpooled.buffer();
+        final VpnDestination dests = new VpnDestinationBuilder().setPrefix(extractPrefix(l3vpn, this.prefixTypeNid))
+            .setRouteDistinguisher(extractRouteDistinguisher(l3vpn)).build();
+        final ByteBuf nlriByteBuf = Unpooled.buffer();
+
+        for (final VpnDestination dest : Collections.singletonList(dests)) {
+            final IpPrefix prefix = dest.getPrefix();
+            LOG.debug("Serializing Nlri: VpnDestination={}, IpPrefix={}", dest, prefix);
+            AbstractVpnNlriParser.serializeLengtField(prefix, null, nlriByteBuf);
+            RouteDistinguisherUtil.serializeRouteDistinquisher(dest.getRouteDistinguisher(), nlriByteBuf);
+            Preconditions.checkArgument(prefix.getIpv6Prefix() != null || prefix.getIpv4Prefix() != null, "Ipv6 or Ipv4 prefix is missing.");
+            LUNlriParser.serializePrefixField(prefix, nlriByteBuf);
+        }
+        buffer.writeBytes(nlriByteBuf);
 
-        final VpnDestination dest = extractVpnDestination(l3vpn);
-        AbstractVpnNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
         return new NodeIdentifierWithPredicates(routeQName(), this.routeKey, ByteArray.encodeBase64(buffer));
     }
 }
index 51cc5f46e29c7a2610d7e7fec6b6fbd07d742749..47658aafd9a7c0f28fcff955e35768e5e2954b9d 100644 (file)
@@ -18,17 +18,11 @@ import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import java.util.Collection;
 import java.util.Collections;
 import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
-import org.opendaylight.protocol.util.ByteArray;
 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.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
@@ -62,22 +56,11 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest {
     private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.
         DestinationVpnIpv4Case UNREACH_NLRI = 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();
+    private static final VpnRouteKey ROUTE_KEY = new VpnRouteKey("WAABAQIDBAECIgEW");
 
-    private static final VpnRoute ROUTE;
-    private static final VpnIpv4Routes ROUTES;
-    private static final VpnRouteKey ROUTE_KEY;
-
-    static {
-        final BgpIpv4Activator act = new BgpIpv4Activator();
-        final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
-        act.start(context);
-        final ByteBuf buffer = Unpooled.buffer();
-        AbstractVpnNlriParser.serializeNlri(Collections.singletonList(IPV4_VPN), buffer);
-        ROUTE_KEY = new VpnRouteKey(ByteArray.encodeBase64(buffer));
-        ROUTE = new VpnRouteBuilder().setPathId(new PathId(NON_PATH_ID)).setAttributes(ATTRIBUTES).setPrefix(IPv4_PREFIX)
-            .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).setKey(ROUTE_KEY).build();
-        ROUTES = new VpnIpv4RoutesBuilder().setVpnRoute(Collections.singletonList(ROUTE)).build();
-    }
+    private static final VpnRoute ROUTE = new VpnRouteBuilder().setPathId(new PathId(NON_PATH_ID)).setAttributes(ATTRIBUTES).setPrefix(IPv4_PREFIX)
+        .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).setKey(ROUTE_KEY).build();
+    private static final VpnIpv4Routes ROUTES = new VpnIpv4RoutesBuilder().setVpnRoute(Collections.singletonList(ROUTE)).build();
 
     @Override
     public void setUp() throws Exception {
index 55b09764b78df816ae3e429ada5d8c7956eb9d3a..a947248e359d8c7d706b356b9f7c8ae740a32c11 100644 (file)
@@ -18,17 +18,11 @@ import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import java.util.Collection;
 import java.util.Collections;
 import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
-import org.opendaylight.protocol.util.ByteArray;
 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.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
@@ -62,22 +56,10 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest {
     private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.
         DestinationVpnIpv6Case UNREACH_NLRI = 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();
-
-    private static final VpnRoute ROUTE;
-    private static final VpnIpv6Routes ROUTES;
-    private static final VpnRouteKey ROUTE_KEY;
-
-    static {
-        final BgpIpv6Activator act = new BgpIpv6Activator();
-        final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
-        act.start(context);
-        final ByteBuf buffer = Unpooled.buffer();
-        AbstractVpnNlriParser.serializeNlri(Collections.singletonList(IPV6_VPN), buffer);
-        ROUTE_KEY = new VpnRouteKey(ByteArray.encodeBase64(buffer));
-        ROUTE = new VpnRouteBuilder().setPathId(new PathId(NON_PATH_ID)).setAttributes(ATTRIBUTES).setPrefix(IPv6_PREFIX)
-            .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).setKey(ROUTE_KEY).build();
-        ROUTES = new VpnIpv6RoutesBuilder().setVpnRoute(Collections.singletonList(ROUTE)).build();
-    }
+    private static final VpnRouteKey ROUTE_KEY = new VpnRouteKey("cAABAQIDBAECIAEjRVaJ");
+    private static final VpnRoute ROUTE = new VpnRouteBuilder().setPathId(new PathId(NON_PATH_ID)).setAttributes(ATTRIBUTES).setPrefix(IPv6_PREFIX)
+        .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).setKey(ROUTE_KEY).build();
+    private static final VpnIpv6Routes ROUTES = new VpnIpv6RoutesBuilder().setVpnRoute(Collections.singletonList(ROUTE)).build();
 
     @Override
     public void setUp() throws Exception {
@@ -99,7 +81,6 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest {
         assertEquals(ROUTE, route);
     }
 
-
     @Test
     public void testEmptyRoute() throws Exception {
         final Routes empty = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(new VpnIpv6RoutesBuilder().setVpnRoute(Collections.emptyList()).build()).build();