Fix linkstate Route Distinguishers model 60/71160/4
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 20 Apr 2018 09:32:17 +0000 (11:32 +0200)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Mon, 23 Apr 2018 06:24:23 +0000 (06:24 +0000)
actual model do no correspond with
https://tools.ietf.org/html/rfc4364#section-4.2.
- Fix by use correct existent model.
- Remove duplicated grouping models

Change-Id: I870d100d3ce441aa2d7c197be3fb4243ab1846d8
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/concepts/src/main/yang/bgp-types.yang
bgp/evpn/src/main/yang/odl-bgp-evpn.yang
bgp/flowspec/src/main/yang/bgp-flowspec.yang
bgp/l3vpn/src/main/yang/bgp-vpn.yang
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java
bgp/linkstate/src/main/yang/bgp-linkstate.yang
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/UriBuilder.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/UriBuilderTest.java

index 8c56c45cfbdb5c575f8525101c1ee4fb5c6ff015..ece9ceb65fa48b79b02fb640e9019e2feee55341 100644 (file)
@@ -457,4 +457,18 @@ module bgp-types {
             type inet:as-number;
         }
     }
+
+    grouping route-distinguisher-grouping {
+        leaf route-distinguisher {
+            type route-distinguisher;
+            mandatory true;
+        }
+    }
+
+    grouping orig-route-ip-grouping {
+        leaf orig-route-ip {
+            type inet:ip-address;
+            mandatory true;
+        }
+    }
 }
index 0061e98898b1804d73e1e5571a29e6104d39c601..cb5b79786015eaa55e52d8639313d995b76f0846 100644 (file)
@@ -223,13 +223,6 @@ module odl-bgp-evpn {
         }
     }
 
-    grouping route-distinguisher {
-        leaf route-distinguisher {
-            type bgp-t:route-distinguisher;
-            mandatory true;
-        }
-    }
-
     grouping ethernet-a-d-route {
         container ethernet-a-d-route {
             reference "https://tools.ietf.org/html/rfc7432#section-7.1";
@@ -274,9 +267,7 @@ module odl-bgp-evpn {
             description "Inclusive Multicast Ethernet Tag route";
 
             uses ethernet-tag-id;
-            leaf orig-route-ip {
-                type inet:ip-address;
-            }
+            uses bgp-t:orig-route-ip-grouping;
         }
     }
 
@@ -286,10 +277,7 @@ module odl-bgp-evpn {
             description "Ethernet Segment route";
 
             uses esi;
-            leaf orig-route-ip {
-                type inet:ip-address;
-                mandatory true;
-            }
+            uses bgp-t:orig-route-ip-grouping;
         }
     }
 
@@ -477,7 +465,7 @@ module odl-bgp-evpn {
             mandatory true;
         }
 
-        uses route-distinguisher;
+        uses bgp-t:route-distinguisher-grouping;
     }
 
     augment "/bgp-msg:update/bgp-msg:attributes" {
index 24bb86242269e051f0ef736f28e0700e74a15644..1738714fc5f9d315e35eb4ce6f473eb48c7d6aed 100644 (file)
@@ -301,16 +301,9 @@ module bgp-flowspec {
         }
     }
 
-    grouping flowspec-l3vpn-rd {
-        reference "https://tools.ietf.org/html/rfc5575#section-8";
-        leaf route-distinguisher {
-            type bgp-t:route-distinguisher;
-        }
-    }
-
     grouping flowspec-l3vpn-destination-ipv4 {
         container destination-flowspec-l3vpn-ipv4 {
-            uses flowspec-l3vpn-rd;
+            uses bgp-t:route-distinguisher-grouping;
             uses flowspec-destination-group-ipv4;
             uses bgp-msg:path-id-grouping;
         }
@@ -318,7 +311,7 @@ module bgp-flowspec {
 
     grouping flowspec-l3vpn-destination-ipv6 {
         container destination-flowspec-l3vpn-ipv6 {
-            uses flowspec-l3vpn-rd;
+            uses bgp-t:route-distinguisher-grouping;
             uses flowspec-destination-group-ipv6;
             uses bgp-msg:path-id-grouping;
         }
@@ -488,7 +481,7 @@ module bgp-flowspec {
         list flowspec-l3vpn-route {
             key "route-key path-id";
             uses flowspec-ipv4-route-list;
-            uses flowspec-l3vpn-rd;
+            uses bgp-t:route-distinguisher-grouping;
         }
     }
 
@@ -508,7 +501,7 @@ module bgp-flowspec {
         list flowspec-l3vpn-route {
             key "route-key path-id";
             uses flowspec-ipv6-route-list;
-            uses flowspec-l3vpn-rd;
+            uses bgp-t:route-distinguisher-grouping;
         }
     }
 
index 51ecf1e3a5e8a4cd491a0b5adf0a54cbca2c8539..646d446a4386b5e3c00ac980f41272830acdf2d6 100644 (file)
@@ -35,9 +35,7 @@ module bgp-vpn {
 
     grouping l3vpn {
         uses bgp-lu:labeled-unicast;
-        leaf route-distinguisher {
-            type bgp-t:route-distinguisher;
-        }
+        uses bgp-t:route-distinguisher-grouping;
     }
 
     grouping l3vpn-ip-destination-type {
index ee5e8dfd86f7caa61bc836f8dda9915d0ed3e024..60e5e98caf02ceffe493435b9a42a1703be2f3e2 100644 (file)
@@ -14,6 +14,7 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
+import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
 import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
@@ -21,7 +22,6 @@ import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Identifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestinationBuilder;
@@ -82,7 +82,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
     @VisibleForTesting
     public static final NodeIdentifier IDENTIFIER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "identifier").intern());
     @VisibleForTesting
-    private static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "distinguisher").intern());
+    private static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "route-distinguisher").intern());
     private final SimpleNlriTypeRegistry nlriTypeReg = SimpleNlriTypeRegistry.getInstance();
 
 
@@ -212,7 +212,8 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
     private static void serializeNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) {
         final NodeCaseBuilder nodeBuilder = new NodeCaseBuilder();
         // node descriptors
-        nodeBuilder.setNodeDescriptors(NodeNlriParser.serializeNodeDescriptors((ContainerNode) objectType.getChild(NODE_DESCRIPTORS_NID).get()));
+        nodeBuilder.setNodeDescriptors(NodeNlriParser
+                .serializeNodeDescriptors((ContainerNode) objectType.getChild(NODE_DESCRIPTORS_NID).get()));
         builder.setObjectType(nodeBuilder.build());
     }
 
@@ -251,7 +252,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         // serialize common parts
         final Optional<DataContainerChild<? extends PathArgument, ?>> distinguisher = linkstate.getChild(DISTINGUISHER_NID);
         if (distinguisher.isPresent()) {
-            builder.setDistinguisher(new RouteDistinguisher((BigInteger) distinguisher.get().getValue()));
+            builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(distinguisher.get().getValue()));
         }
         final Optional<DataContainerChild<? extends PathArgument, ?>> protocolId = linkstate.getChild(PROTOCOL_ID_NID);
         // DOM representation contains values as are in the model, not as are in generated enum
index a80fcfa1e1a52eab2a9bb5f2ec604f27b544784c..287f5727453bb9904dd1c0941ec6a2833a986320 100644 (file)
@@ -156,10 +156,6 @@ module bgp-linkstate {
         }
     }
 
-    typedef route-distinguisher {
-        type uint64;
-    }
-
     typedef identifier {
         type uint64;
     }
@@ -321,8 +317,10 @@ module bgp-linkstate {
     }
 
     grouping linkstate {
-        leaf distinguisher {
-            type route-distinguisher;
+        uses bgp-t:route-distinguisher-grouping {
+            refine route-distinguisher {
+                mandatory false;
+            }
         }
         leaf protocol-id {
             type protocol-id;
index 7d6cbdd1f7a78c6b1af7ba355644e3a9d072d640..3941abf975eaea74c124bc64ed911f18a0c8cdf1 100644 (file)
@@ -163,7 +163,7 @@ public class LinkstateNlriParserTest {
         setUp(this.nodeNlri);
 
         // test BA form
-        assertNull(this.dest.getDistinguisher());
+        assertNull(this.dest.getRouteDistinguisher());
         assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
         assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
         final NodeCase nCase = ((NodeCase) this.dest.getObjectType());
@@ -244,7 +244,7 @@ public class LinkstateNlriParserTest {
         setUp(this.linkNlri);
 
         // test BA form
-        assertNull(this.dest.getDistinguisher());
+        assertNull(this.dest.getRouteDistinguisher());
         assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
         assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
 
@@ -404,7 +404,7 @@ public class LinkstateNlriParserTest {
         setUp(this.prefixNlri);
 
         // test BA form
-        assertNull(this.dest.getDistinguisher());
+        assertNull(this.dest.getRouteDistinguisher());
         assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
         assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
 
@@ -508,7 +508,7 @@ public class LinkstateNlriParserTest {
     public void testTELspNlri() throws BGPParsingException {
         setUp(this.teLspNlri);
         // test BA form
-        assertNull(this.dest.getDistinguisher());
+        assertNull(this.dest.getRouteDistinguisher());
         assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
         assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
         final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
index b4672358f880feba37cbe0f911cbcf3d1246d34a..a531c9a66ca62b497281bc9b543c55fa15b22f9a 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.isis.lan.identifier.IsIsRouterIdentifierBuilder;
@@ -58,6 +57,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RdTwoOctetAs;
+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.network.concepts.rev131125.IsoSystemIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -82,10 +83,10 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest {
                 .setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 0, 0, 0, (byte) 0x39})).build()).setPsn((short) 5).build()).build())
         .setDomainId(new DomainIdentifier(28282828L)).build()).build();
 
-    private static final RouteDistinguisher RD = new RouteDistinguisher(BigInteger.ONE);
+    private static final RouteDistinguisher RD = new RouteDistinguisher(new RdTwoOctetAs("0:5:3"));
     private static final Identifier ID = new Identifier(BigInteger.ONE);
     private static final CLinkstateDestination LINKSTATE_DESTINATION = new CLinkstateDestinationBuilder()
-        .setDistinguisher(RD)
+        .setRouteDistinguisher(RD)
         .setIdentifier(ID)
         .setObjectType(OBJECT_TYPE2)
         .setProtocolId(ProtocolId.IsisLevel1).build();
@@ -108,8 +109,9 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest {
         SimpleNlriTypeRegistry.getInstance().serializeNlriType(LINKSTATE_DESTINATION, buffer);
         final byte[] arrayKey = ByteArray.readAllBytes(buffer);
         ROUTE_KEY = new LinkstateRouteKey(PATH_ID, Arrays.toString(arrayKey));
-        ROUTE = new LinkstateRouteBuilder().setKey(ROUTE_KEY).setDistinguisher(RD).setIdentifier(ID).setObjectType(OBJECT_TYPE2)
-            .setProtocolId(ProtocolId.IsisLevel1).setAttributes(new AttributesBuilder().build()).build();
+        ROUTE = new LinkstateRouteBuilder().setKey(ROUTE_KEY).setRouteDistinguisher(RD)
+                .setIdentifier(ID).setObjectType(OBJECT_TYPE2)
+                .setProtocolId(ProtocolId.IsisLevel1).setAttributes(new AttributesBuilder().build()).build();
         ROUTES = new LinkstateRoutesBuilder().setLinkstateRoute(Collections.singletonList(ROUTE)).build();
     }
 
index 7a2dd3c1fa5133a5ba35a86fecc297ab4e4d1bb3..0d3d2bd22a8535c068ba90fd36b667790774fcf4 100644 (file)
@@ -40,8 +40,16 @@ final class UriBuilder {
     UriBuilder(final LinkstateRoute route) {
         this.sb = new StringBuilder("bgpls://");
 
-        if (route.getDistinguisher() != null) {
-            this.sb.append(route.getDistinguisher().getValue().toString()).append(':');
+        if (route.getRouteDistinguisher() != null) {
+            String rd;
+            if (route.getRouteDistinguisher().getRdAs() != null) {
+                rd = route.getRouteDistinguisher().getRdAs().getValue();
+            } else if (route.getRouteDistinguisher().getRdIpv4() != null) {
+                rd = route.getRouteDistinguisher().getRdIpv4().getValue();
+            } else  {
+                rd = route.getRouteDistinguisher().getRdTwoOctetAs().getValue();
+            }
+            this.sb.append(rd).append(':');
         }
 
         this.sb.append(route.getProtocolId().toString()).append(':')
index 3ee0084b04151a9dd658c39be807912f6bbce4f8..c0f0bfefbbe86c8e2655249ed4e2ffe167c1db60 100644 (file)
@@ -17,7 +17,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Identifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Ipv4InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.TopologyIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.isis.lan.identifier.IsIsRouterIdentifierBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.LinkCaseBuilder;
@@ -29,9 +28,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
+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.network.concepts.rev131125.IsoSystemIdentifier;
 
 public class UriBuilderTest {
+    private static final RouteDistinguisher DISTINGUISHER
+            = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258");
 
     @Test
     public void test() {
@@ -40,12 +43,12 @@ public class UriBuilderTest {
         final UriBuilder a = new UriBuilder(routeB.build());
         assertEquals("bgpls://Direct:10/", a.toString());
 
-        routeB.setDistinguisher(new RouteDistinguisher(BigInteger.ONE));
+        routeB.setRouteDistinguisher(DISTINGUISHER);
         final UriBuilder b = new UriBuilder(routeB.build());
-        assertEquals("bgpls://1:Direct:10/", b.toString());
+        assertEquals("bgpls://1.2.3.4:258:Direct:10/", b.toString());
 
         final UriBuilder c = new UriBuilder(b, "foo");
-        assertEquals("bgpls://1:Direct:10/type=foo", c.toString());
+        assertEquals("bgpls://1.2.3.4:258:Direct:10/type=foo", c.toString());
 
         a.add("foo", 25L);
         assertEquals("bgpls://Direct:10/&foo=25", a.toString());
@@ -69,8 +72,8 @@ public class UriBuilderTest {
                         .build()).setPsn((short) 2).build()).build());
         linkB.setRemoteNodeDescriptors(nodeR.build());
         c.add(linkB.build());
-        assertEquals("bgpls://1:Direct:10/type=foo&local-as=12&local-domain=15&local-area=17&local-router=22"
-                + "&remote-router=0102.0304.0506.02&ipv4-iface=127.0.0.1&ipv4-neigh=20.20.20.20&mt=55&local-id=1&"
-                + "remote-id=2", c.toString());
+        assertEquals("bgpls://1.2.3.4:258:Direct:10/type=foo&local-as=12&local-domain=15&local-area=17&"
+                + "local-router=22&remote-router=0102.0304.0506.02&ipv4-iface=127.0.0.1&ipv4-neigh=20.20.20.20&m"
+                + "t=55&local-id=1&remote-id=2", c.toString());
     }
 }