Bug 6337 - Handle string route-key from App Routes when Binary route-key is expected 46/43946/3
authorMilos Fabian <milfabia@cisco.com>
Tue, 9 Aug 2016 09:49:10 +0000 (11:49 +0200)
committerMilos Fabian <milfabia@cisco.com>
Mon, 29 Aug 2016 12:46:43 +0000 (12:46 +0000)
Change binary typed route keys to string. Modify RIB support extensions to
encode key with Base64.

The binary type is decoded with Base64, where length is restricted.
The BGP application RIB allows user to originate a route
and binary typed route key is limiting user defined route keys to a
specific length (cut-off when does not fit).
Also using plain text for binary typed route keys is not correct.

The route-key type change is invisible in restconf output.

Change-Id: Ieab24705ceebe0b527b4ddae81a4109c9c250de0
Signed-off-by: Milos Fabian <milfabia@cisco.com>
(cherry picked from commit eca666c067d809426fcb5936d559b3e08271f48f)

bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java
bgp/evpn/src/main/yang/bgp-evpn.yang
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupportTest.java
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java
bgp/l3vpn/src/main/yang/bgp-vpn.yang
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
bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java
bgp/labeled-unicast/src/main/yang/bgp-labeled-unicast.yang
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

index d39be19a050320d1516d2e2be5d59ccdb428957d..58fa84907d2b747c3f344886023f5929c032dd2b 100644 (file)
@@ -119,7 +119,7 @@ final class EvpnRibSupport extends AbstractRIBSupport {
         final ByteBuf buffer = Unpooled.buffer();
         final EvpnDestination dest = EvpnNlriParser.extractRouteKeyDestination(evpn);
         EvpnNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
-        return new NodeIdentifierWithPredicates(routeQName(), ROUTE_KEY, ByteArray.readAllBytes(buffer));
+        return new NodeIdentifierWithPredicates(routeQName(), ROUTE_KEY, ByteArray.encodeBase64(buffer));
     }
 
 }
index 80056bd931e54eb64190390757a6fd04de5d378e..30a676a15cd649e07da0801575c5b811b2639f32 100644 (file)
@@ -382,7 +382,7 @@ module odl-bgp-evpn {
         container evpn-routes {
             list evpn-route {
                 leaf route-key {
-                    type binary;
+                    type string;
                 }
                 key "route-key";
                 uses evpn;
index 2e6dc976ea0d932b75639994dd62f720390d74a0..57b4b3d1efca2726190d55fc5171a76ab14c79e6 100644 (file)
@@ -27,8 +27,6 @@ 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.evpn.rev160321.EvpnSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.L2vpnAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.destination.EvpnDestination;
@@ -73,9 +71,8 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest {
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
         EvpnNlriParser.serializeNlri(Collections.singletonList(new EvpnDestinationBuilder().setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE_KEY).build()), buffer);
-        final byte[] arrayKey = ByteArray.readAllBytes(buffer);
-        ROUTE_KEY = new EvpnRouteKey(arrayKey);
-        ROUTE = new EvpnRouteBuilder().setRouteKey(arrayKey).setAttributes(ATTRIBUTES).setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build();
+        ROUTE_KEY = new EvpnRouteKey(ByteArray.encodeBase64(buffer));
+        ROUTE = new EvpnRouteBuilder().setRouteKey(ROUTE_KEY.getRouteKey()).setAttributes(ATTRIBUTES).setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build();
         EVPN_ROUTES = new EvpnRoutesBuilder().setEvpnRoute(Collections.singletonList(ROUTE)).build();
     }
 
index 23e9ef61547f8a08721e40c996bca28fa577923c..45d93290a68434b400998439e4027f4c47b4effc 100644 (file)
@@ -69,23 +69,23 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
      * @param containerClass Binding class of the container in routes choice, must not be null.
      * @param listClass      Binding class of the route list, nust not be null;
      */
-    protected AbstractVpnRIBSupport(Class<? extends Routes> cazeClass, Class<? extends DataObject> containerClass, Class<? extends Route> listClass,
-        Class<? extends AddressFamily> afiClass, final QName vpnDstContainerClassQname) {
+    protected AbstractVpnRIBSupport(final Class<? extends Routes> cazeClass, final Class<? extends DataObject> containerClass, final Class<? extends Route> listClass,
+        final Class<? extends AddressFamily> afiClass, final QName vpnDstContainerClassQname) {
         super(cazeClass, containerClass, listClass, afiClass, MplsLabeledVpnSubsequentAddressFamily.class, vpnDstContainerClassQname);
         final QName classQname = BindingReflections.findQName(containerClass).intern();
-        routeKey = QName.create(routeQName(), "route-key").intern();
+        this.routeKey = QName.create(routeQName(), "route-key").intern();
         final QName vpnDstClassQname = QName.create(classQname, VpnDestination.QNAME.getLocalName());
-        nlriRoutesListNid = NodeIdentifier.create(vpnDstClassQname);
-        prefixTypeNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "prefix").intern());
-        labelStackNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "label-stack").intern());
-        lvNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "label-value").intern());
-        rdNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "route-distinguisher").intern());
+        this.nlriRoutesListNid = NodeIdentifier.create(vpnDstClassQname);
+        this.prefixTypeNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "prefix").intern());
+        this.labelStackNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "label-stack").intern());
+        this.lvNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "label-value").intern());
+        this.rdNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "route-distinguisher").intern());
     }
 
-    private VpnDestination extractVpnDestination(DataContainerNode<? extends PathArgument> route) {
+    private VpnDestination extractVpnDestination(final DataContainerNode<? extends PathArgument> route) {
         final VpnDestination dst = new VpnDestinationBuilder()
-            .setPrefix(extractPrefix(route, prefixTypeNid))
-            .setLabelStack(LabeledUnicastIpv4RIBSupport.extractLabel(route, labelStackNid, lvNid))
+            .setPrefix(extractPrefix(route, this.prefixTypeNid))
+            .setLabelStack(LabeledUnicastIpv4RIBSupport.extractLabel(route, this.labelStackNid, this.lvNid))
             .setRouteDistinguisher(extractRouteDistinguisher(route))
             .build();
         return dst;
@@ -94,8 +94,8 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
     protected abstract IpPrefix extractPrefix(final DataContainerNode<? extends PathArgument> route, final NodeIdentifier prefixTypeNid);
 
     private RouteDistinguisher extractRouteDistinguisher(final DataContainerNode<? extends YangInstanceIdentifier.PathArgument> route) {
-        if (route.getChild(rdNid).isPresent()) {
-            return RouteDistinguisherBuilder.getDefaultInstance((String) route.getChild(rdNid).get().getValue());
+        if (route.getChild(this.rdNid).isPresent()) {
+            return RouteDistinguisherBuilder.getDefaultInstance((String) route.getChild(this.rdNid).get().getValue());
         }
         return null;
     }
@@ -145,7 +145,7 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
             if (maybeRoutes.isPresent()) {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
-                    UnkeyedListNode routeListNode = (UnkeyedListNode) routes;
+                    final UnkeyedListNode routeListNode = (UnkeyedListNode) routes;
                     LOG.debug("{} routes are found", routeListNode.getSize());
                     final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
                     for (final UnkeyedListEntryNode e : routeListNode.getValue()) {
@@ -167,6 +167,6 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
 
         final VpnDestination dest = extractVpnDestination(l3vpn);
         AbstractVpnNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
-        return new NodeIdentifierWithPredicates(routeQName(), this.routeKey, ByteArray.readAllBytes(buffer));
+        return new NodeIdentifierWithPredicates(routeQName(), this.routeKey, ByteArray.encodeBase64(buffer));
     }
 }
index 56e261cbe664e6c93016ee34662e77768d5f0a0f..e26e9f5d207c17670833b45b0e6c1a2a61620603 100644 (file)
@@ -42,7 +42,7 @@ module bgp-vpn {
         list vpn-route {
             key "route-key";
             leaf route-key {
-                type binary;
+                type string;
             }
             uses l3vpn;
             uses bgp-rib:route;
index e6f4550c7184891927e30922e4a5cb73e9f5c228..51cc5f46e29c7a2610d7e7fec6b6fbd07d742749 100644 (file)
@@ -73,8 +73,7 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest {
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
         AbstractVpnNlriParser.serializeNlri(Collections.singletonList(IPV4_VPN), buffer);
-        final byte[] arrayKey = ByteArray.readAllBytes(buffer);
-        ROUTE_KEY = new VpnRouteKey(arrayKey);
+        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();
index b35701f6d58b920f5675fb0cf29cbb9c4bc1ce6f..55b09764b78df816ae3e429ada5d8c7956eb9d3a 100644 (file)
@@ -73,8 +73,7 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest {
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
         AbstractVpnNlriParser.serializeNlri(Collections.singletonList(IPV6_VPN), buffer);
-        final byte[] arrayKey = ByteArray.readAllBytes(buffer);
-        ROUTE_KEY = new VpnRouteKey(arrayKey);
+        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();
index 565f5dd5dfd8fdc3c6ee88d5a09a4d186df44f82..fc4a733406dcf1876bd9e02fd6efe7dc595cac07 100644 (file)
@@ -117,7 +117,7 @@ abstract class AbstractLabeledUnicastRIBSupport extends MultiPathAbstractRIBSupp
 
         final CLabeledUnicastDestination dest = extractCLabeledUnicastDestination(labeledUnicast);
         LUNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
-        final byte[] routeKeyValue = ByteArray.readAllBytes(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);
         return routeKey;
index 64569f8b6013674daa626578e90e994ebceba817..54754158795df545be1d19a52028e1a91b68458b 100644 (file)
@@ -78,7 +78,7 @@ module bgp-labeled-unicast {
     grouping labeled-unicast-routes-list {
         list labeled-unicast-route {
             leaf route-key {
-                type binary;
+                type string;
             }
             key "route-key path-id";
             uses labeled-unicast;
index caf3d7854e9527d473098ccb74ee699d809dba85..346a147963b309ae20c383c24fd5183de2347e1e 100644 (file)
@@ -64,7 +64,7 @@ public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest {
     private static final LabeledUnicastRoute ROUTE;
     private static final LabeledUnicastRoutes ROUTES;
     private static final LabeledUnicastRouteKey ROUTE_KEY;
-    private static final byte[] LABEL_KEY;
+    private static final String LABEL_KEY;
     private static final PathId PATH_ID = new PathId(1L);
     private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
     private static final List<CLabeledUnicastDestination> LABELED_DESTINATION_LIST = Collections.singletonList(new CLabeledUnicastDestinationBuilder()
@@ -82,7 +82,7 @@ public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest {
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
         LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, buffer);
-        LABEL_KEY = ByteArray.readAllBytes(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)
             .setAttributes(new AttributesBuilder().build()).build();
index 8553fa504891cb08bd50a46378449f9f4f8460c5..0aaf3795761993bb8fb554de2b1f5997e251d2f9 100644 (file)
@@ -64,7 +64,7 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest {
     private static final LabeledUnicastRoute ROUTE;
     private static final LabeledUnicastIpv6Routes ROUTES;
     private static final LabeledUnicastRouteKey ROUTE_KEY;
-    private static final byte[] LABEL_KEY;
+    private static final String LABEL_KEY;
     private static final PathId PATH_ID = new PathId(1L);
     private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
     private static final List<CLabeledUnicastDestination> LABELED_DESTINATION_LIST = Collections.singletonList(new CLabeledUnicastDestinationBuilder()
@@ -83,7 +83,7 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest {
         act.start(context);
         final ByteBuf buffer = Unpooled.buffer();
         LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, buffer);
-        LABEL_KEY = ByteArray.readAllBytes(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)
             .setAttributes(new AttributesBuilder().build()).build();