BUG-5966: Remove received path Id from routeKey 28/39528/1
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 24 May 2016 13:29:33 +0000 (15:29 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 27 May 2016 13:28:08 +0000 (15:28 +0200)
When we map received routes on locRibwriter is required to remove
received pathId to identify the key value (prefix, key-value)as a key.
Otherwise is identifying the combination  of key+path id
as a new route and not as a new path.
This step is only required on extension which support Multiple Path

Change-Id: Ia4d6e86cc187a5db71ecfb66c745b9a2420732da
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupport.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupport.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java

index 2d0c9eaaf12dec897dcbc95c0dafdaec95b9a1f1..f4aedc34f4a653cacd3028723d043342010121c5 100644 (file)
@@ -62,9 +62,11 @@ public final class PathIdUtil {
      * @return The path identifier from data change
      */
     public static Long extractPathId(final NormalizedNode<?, ?> data, final NodeIdentifier pathNii) {
-        final Long pathId = (Long) NormalizedNodes.findNode(data, pathNii).get().getValue();
-        Preconditions.checkNotNull(pathId);
-        return pathId;
+        final NormalizedNode<?, ?> pathId = NormalizedNodes.findNode(data, pathNii).orNull();
+        if (pathId == null) {
+            return null;
+        }
+        return (Long) pathId.getValue();
     }
 
     /**
@@ -74,18 +76,28 @@ public final class PathIdUtil {
      * @param routeId Route Id value
      * @param routeQname route QName provided per each RibSupport
      * @param pathidQname Path Id QName provided per each RibSupport
-     * @param prefixQname Prefix QName provided per each RibSupport
+     * @param routeKeyQname Prefix QName provided per each RibSupport
      * @return Route Key Nid
      */
     public static PathArgument createNidKey(final long pathId, final PathArgument routeId, final QName routeQname, final QName pathidQname,
-        final QName prefixQname) {
-        final String prefix = (String) (((NodeIdentifierWithPredicates) routeId).getKeyValues()).get(prefixQname);
-        return createNodeIdentifierWithPredicates(routeQname, pathidQname, pathId, prefixQname, prefix);
+        final QName routeKeyQname) {
+        return createNodeIdentifierWithPredicates(routeQname, pathidQname, pathId, routeKeyQname, getObjectKey(routeId, routeKeyQname));
+    }
+
+    /**
+     * Get route key object ( prefgit stat  ix / key-value/ .. )
+     *
+     * @param routeId PathArgument containing the key
+     * @param routeKeyQname routeKey Qname
+     * @return key
+     */
+    public static Object getObjectKey(final PathArgument routeId, final QName routeKeyQname) {
+        return (((NodeIdentifierWithPredicates) routeId).getKeyValues()).get(routeKeyQname);
     }
 
-    private static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname, final QName pathidQname, final Object pathId,
-        final QName prefixQname, final Object prefix) {
-        final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(pathidQname, pathId, prefixQname, prefix);
+    public static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname, final QName pathidQname, final Object pathId,
+        final QName routeKeyQname, final Object keyObject) {
+        final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(pathidQname, pathId, routeKeyQname, keyObject);
         return new NodeIdentifierWithPredicates(routeQname, keyValues);
     }
 
@@ -98,7 +110,7 @@ public final class PathIdUtil {
      */
     public static PathId buildPathId(final DataContainerNode<? extends PathArgument> routesCont, final NodeIdentifier pathIdNii) {
         final Long pathIdVal = PathIdUtil.extractPathId(routesCont, pathIdNii);
-        return new PathId(pathIdVal);
+        return pathIdVal == null ? null : new PathId(pathIdVal);
     }
 
     /**
index fbb7ae5b577f37a490bab9772f3eb287965e7627..dd738f2a4c665bbc6239102f804dc323f0a4ec50 100644 (file)
@@ -63,7 +63,7 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry {
             this.values = newAttributes;
             this.offsets = newOffsets;
             this.pathsId = newPathsId;
-            this.offsets.setValue(this.pathsId, offset, this.pathIdCounter++);
+            this.offsets.setValue(this.pathsId, offset, ++this.pathIdCounter);
         }
         this.offsets.setValue(this.values, offset, attributes);
         LOG.trace("Added route from {} attributes {}", key.getRouteId(), attributes);
index 00ce32a162310d081f5a283f650f7396228bca9f..f2121264d2d5b12c3392ee7bfd2790eb7d631563 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 
 /**
  * Class supporting IPv4 unicast RIBs.
@@ -44,7 +45,7 @@ final class IPv4RIBSupport extends AbstractIPRIBSupport {
     private List<Ipv4Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
         final List<Ipv4Prefixes> prefs = new ArrayList<>(routes.size());
         for (final MapEntryNode route : routes) {
-            final String prefix = (String) route.getChild(this.routePrefixIdentifier()).get().getValue();
+            final String prefix = (String) NormalizedNodes.findNode(route, this.routePrefixIdentifier()).get().getValue();
             final Ipv4PrefixesBuilder prefixBuilder = new Ipv4PrefixesBuilder().setPrefix(new Ipv4Prefix(prefix));
             prefixBuilder.setPathId(PathIdUtil.buildPathId(route, this.routePathIdNid()));
             prefs.add(prefixBuilder.build());
index 4c5d516c904342d66991988fe330ac5d610c57a1..5f5b49bc60f00e8adef6d025769c185fec5a8bb8 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 
 /**
  * Class supporting IPv6 unicast RIBs.
@@ -57,9 +58,9 @@ final class IPv6RIBSupport extends AbstractIPRIBSupport {
 
     private List<Ipv6Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
         final List<Ipv6Prefixes> prefs = new ArrayList<>(routes.size());
-        for (final MapEntryNode ipv6Route : routes) {
-            final String prefix = (String) ipv6Route.getChild(this.routePrefixIdentifier()).get().getValue();
-            prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(ipv6Route, this.routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build());
+        for (final MapEntryNode route : routes) {
+            final String prefix = (String) NormalizedNodes.findNode(route, this.routePrefixIdentifier()).get().getValue();
+            prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, this.routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build());
         }
         return prefs;
     }
index 1f6668e8ac77d01cb998e8c085b32c718ebdcc52..9b0457d300e7781de1f0796dfe7e874c99c93aab 100644 (file)
@@ -254,7 +254,7 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
         final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
         final Collection<DataTreeCandidateNode> modifiedRoutes = this.ribSupport.changedRoutes(child);
         for (final DataTreeCandidateNode route : modifiedRoutes) {
-            final PathArgument routeId = route.getIdentifier();
+            final PathArgument routeId = this.ribSupport.createRouteKeyPathArgument(route.getIdentifier());
             RouteEntry entry = this.routeEntries.get(routeId);
             final Optional<NormalizedNode<?, ?>> maybeData = route.getDataAfter();
             final Optional<NormalizedNode<?, ?>> maybeDataBefore = route.getDataBefore();
index 46867bcc7057c98922aa8ef7af711a37e7e3330d..98599036fec00cfda2d6a03094997dbf10929075 100644 (file)
@@ -41,4 +41,14 @@ interface AddPathRibSupport {
     @Nullable default PathArgument getRouteIdAddPath(long pathId, PathArgument routeId) {
         return null;
     }
+
+    /**
+     * Create a new Path Argument for route Key removing remove Path Id from key
+     * For non extension which doesnt support Multiple Path this step is not required
+     * @param routeKeyPathArgument  routeKey Path Argument
+     * @return new route Key
+     */
+    default PathArgument createRouteKeyPathArgument(PathArgument routeKeyPathArgument) {
+        return routeKeyPathArgument;
+    }
 }
index d2e9256d78890b7bfc8363bc3e3f8fbeedfc1961..3abebeed011530d6fc715f912c2b278749d28317 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.protocol.bgp.rib.spi;
 
+import com.google.common.collect.ImmutableMap;
 import javax.annotation.Nonnull;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
@@ -17,6 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 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.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -33,11 +35,12 @@ public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
      * node in instantiations of the rib grouping. It is assumed that this container is defined by
      * the same model which populates it with route grouping instantiation, and by extension with
      * the route attributes container.
+     *
      * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null
      * @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;
-     * @param addressFamilyClass  address Family Class
-     * @param safiClass  SubsequentAddressFamily
+     * @param addressFamilyClass address Family Class
+     * @param safiClass SubsequentAddressFamily
      * @param routeKeyNaming Route Key name (prefix/ route-key / etc..)
      * @param destinationQname destination Qname
      */
@@ -62,6 +65,15 @@ public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
         return this.routeKeyQname;
     }
 
+    @Override
+    public final Long extractPathId(final NormalizedNode<?, ?> data) {
+        final Long pathId = PathIdUtil.extractPathId(data, this.routePathIdNid());
+        if(pathId == null) {
+            return PathIdUtil.NON_PATH_ID;
+        }
+        return pathId;
+    }
+
     @Nonnull
     @Override
     public final PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) {
@@ -69,7 +81,9 @@ public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
     }
 
     @Override
-    public final Long extractPathId(final NormalizedNode<?, ?> data) {
-        return PathIdUtil.extractPathId(data, this.routePathIdNid());
+    public PathArgument createRouteKeyPathArgument(PathArgument routeKey) {
+        final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(routeKeyQName(), PathIdUtil.getObjectKey(routeKey, routeKeyQName()));
+        return new NodeIdentifierWithPredicates(routeQName(), keyValues);
     }
+
 }