Extract routeKey/pathId from the identifier 18/78718/6
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Dec 2018 12:52:46 +0000 (13:52 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Dec 2018 23:42:52 +0000 (00:42 +0100)
Rather than mucking with old/new route content, extract the needed
information from the identifier, which is always available.

Change-Id: I7fedb4a7b4d670bc837388ef492d6d32ce3a244c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4RIBSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java
bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java
bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java
bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/AbstractL3vpnMcastIpRIBSupport.java
bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/unicast/AbstractVpnRIBSupport.java
bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java
bgp/extensions/mvpn/src/main/java/org/opendaylight/protocol/bgp/mvpn/impl/AbstractMvpnRIBSupport.java
bgp/extensions/route-target/src/main/java/org/opendaylight/protocol/bgp/route/targetcontrain/impl/RouteTargetConstrainRIBSupport.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/RIBSupport.java
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTestImp.java

index 0a9ee6001a3daa83bb9f132154d9b1b0697ccf49..651d56d2e7253bc83dce13ff8ee5f488d730ecc6 100644 (file)
@@ -164,4 +164,14 @@ final class EvpnRibSupport extends AbstractRIBSupport<EvpnRoutesCase, EvpnRoutes
     public List<EvpnRoute> routesFromContainer(final EvpnRoutes container) {
         return container.getEvpnRoute();
     }
+
+    @Override
+    public PathId extractPathId(final EvpnRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final EvpnRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 53fefc55365c5ff49a239ed66e642c5791b9a19d..fd1bae9963bf46670e528c63f4fc2610d9965c46 100644 (file)
@@ -91,4 +91,14 @@ public final class FlowspecIpv4RIBSupport
     public List<FlowspecRoute> routesFromContainer(final FlowspecRoutes container) {
         return container.getFlowspecRoute();
     }
+
+    @Override
+    public PathId extractPathId(final FlowspecRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final FlowspecRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 820bbfbf089552869b09fadabb6a7a4d1f1cd7af..ca7242e8b2c5fee60796e4598d0957c4795a19ad 100644 (file)
@@ -91,4 +91,14 @@ public final class FlowspecIpv6RIBSupport
     public List<FlowspecRoute> routesFromContainer(final FlowspecIpv6Routes container) {
         return container.getFlowspecRoute();
     }
+
+    @Override
+    public PathId extractPathId(final FlowspecRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final FlowspecRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index b46e3986d1a3d4a79cd096743da22d2ad330ad9b..56b7ed2b97b2fe509ff55131f24fd1f417cec8dc 100644 (file)
@@ -92,4 +92,14 @@ public final class FlowspecL3vpnIpv4RIBSupport
     public List<FlowspecL3vpnRoute> routesFromContainer(final FlowspecL3vpnIpv4Routes container) {
         return container.getFlowspecL3vpnRoute();
     }
+
+    @Override
+    public PathId extractPathId(final FlowspecL3vpnRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final FlowspecL3vpnRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 7b7798018c9bc31fec4945991faeb7fca4303545..6838a6a05768b0a7eb320209fc8745f78f774d1b 100644 (file)
@@ -92,4 +92,14 @@ public final class FlowspecL3vpnIpv6RIBSupport
     public List<FlowspecL3vpnRoute> routesFromContainer(final FlowspecL3vpnIpv6Routes container) {
         return container.getFlowspecL3vpnRoute();
     }
+
+    @Override
+    public PathId extractPathId(final FlowspecL3vpnRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final FlowspecL3vpnRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index d680be77beb5cee4cbb7c168cad7259c256e3adb..a73a5a83773ffd6a04d01563d5c12c934100f488 100644 (file)
@@ -119,4 +119,14 @@ final class IPv4RIBSupport extends AbstractIPRibSupport<Ipv4RoutesCase, Ipv4Rout
     public List<Ipv4Route> routesFromContainer(final Ipv4Routes container) {
         return container.getIpv4Route();
     }
+
+    @Override
+    public PathId extractPathId(final Ipv4RouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final Ipv4RouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 037432069ad4369f689017fbefb7cb54cb748276..8187849cd00e7cc8bcd578997bde06ef39a7c549 100644 (file)
@@ -115,4 +115,14 @@ final class IPv6RIBSupport extends AbstractIPRibSupport<Ipv6RoutesCase, Ipv6Rout
     public List<Ipv6Route> routesFromContainer(final Ipv6Routes container) {
         return container.getIpv6Route();
     }
+
+    @Override
+    public PathId extractPathId(final Ipv6RouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final Ipv6RouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 8c2635f7ce640bafd5a509d30060d325ad262cd8..9cb58c88f5fc5ab054f008fc3ca11baf1ed90d8b 100644 (file)
@@ -168,5 +168,16 @@ abstract class AbstractL3vpnMcastIpRIBSupport<
         return container.getL3vpnMcastRoute();
     }
 
+
+    @Override
+    public final PathId extractPathId(final L3vpnMcastRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final L3vpnMcastRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
+
     abstract NodeIdentifierWithPredicates createRouteKey(UnkeyedListEntryNode l3vpn);
 }
index 111660fa9d79eb615d1ad70f55aecbdfacd1b23f..8b97b7602a5c9c84a3f4644e0a43fcaed2731bfc 100644 (file)
@@ -191,4 +191,15 @@ public abstract class AbstractVpnRIBSupport<C extends Routes & DataObject, S ext
     public final List<VpnRoute> routesFromContainer(final S container) {
         return container.getVpnRoute();
     }
+
+
+    @Override
+    public PathId extractPathId(final VpnRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public final String extractRouteKey(final VpnRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 7ddffe0bc118536e08dec98f08ea4a84a4503479..bd0ae3372b21d7e58d656278364c8b79441ac048 100644 (file)
@@ -191,4 +191,15 @@ abstract class AbstractLabeledUnicastRIBSupport<
     public final List<LabeledUnicastRoute> routesFromContainer(final S container) {
         return container.getLabeledUnicastRoute();
     }
+
+
+    @Override
+    public final PathId extractPathId(final LabeledUnicastRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public final String extractRouteKey(final LabeledUnicastRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index a35fd31f363cae9cf06434a735f85ca8b72d2db2..41c611cf11c690327cfdfdff405fa0b71ffc5abc 100644 (file)
@@ -177,4 +177,14 @@ public final class LinkstateRIBSupport
     public List<LinkstateRoute> routesFromContainer(final LinkstateRoutes container) {
         return container.getLinkstateRoute();
     }
+
+    @Override
+    public PathId extractPathId(final LinkstateRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final LinkstateRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 7cd5d93b2f47f74eb3f06182bb580d4da5f3d14d..8ed3a84caa89371ed92daf486e7e3f6573428fc6 100644 (file)
@@ -143,5 +143,16 @@ abstract class AbstractMvpnRIBSupport<C extends Routes & DataObject & ChoiceIn<T
         return Collections.emptyList();
     }
 
+
+    @Override
+    public final PathId extractPathId(final MvpnRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public final String extractRouteKey(final MvpnRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
+
     abstract NodeIdentifierWithPredicates createRouteKey(UnkeyedListEntryNode mvpn);
 }
index fcf99241ad85521f555f3020066b4074baada798..d432f3a74d8306e94f2fde7c2b52e5fde4e503b1 100644 (file)
@@ -223,4 +223,14 @@ public final class RouteTargetConstrainRIBSupport
     public List<RouteTargetConstrainRoute> routesFromContainer(final RouteTargetConstrainRoutes container) {
         return container.getRouteTargetConstrainRoute();
     }
+
+    @Override
+    public PathId extractPathId(final RouteTargetConstrainRouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final RouteTargetConstrainRouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
index 1710fe6e172dd8d555280d1796081c0adeccd266..7271b3409f905fa59fe5e29ee9e632c38ee9e48f 100644 (file)
@@ -45,6 +45,7 @@ import org.opendaylight.protocol.bgp.rib.spi.entry.StaleBestPathRoute;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib;
@@ -285,32 +286,42 @@ final class LocRibWriter<C extends Routes & DataObject & ChoiceIn<Tables>, S ext
     private void updateRoutesEntries(final Collection<? extends DataObjectModification<?>> collection,
             final RouterId routerId, final Map<RouteUpdateKey, RouteEntry<C, S, R, I>> routes) {
         for (final DataObjectModification<? extends DataObject> route : collection) {
-            final R newRoute = (R) route.getDataAfter();
-            final R oldRoute = (R) route.getDataBefore();
-            String routeKey;
-            RouteEntry<C, S, R, I> entry;
-            if (newRoute != null) {
-                routeKey = newRoute.getRouteKey();
-                entry = this.routeEntries.get(routeKey);
-
-                if (entry == null) {
-                    entry = createEntry(routeKey);
-                }
+            if (!(route.getIdentifier() instanceof InstanceIdentifier.IdentifiableItem)) {
+                LOG.debug("Route {} already deleted", route.getIdentifier());
+                return;
+            }
+            final I routeListKey = (I) ((InstanceIdentifier.IdentifiableItem) route.getIdentifier()).getKey();
+            final String routeKey = ribSupport.extractRouteKey(routeListKey);
+            final PathId pathId = ribSupport.extractPathId(routeListKey);
 
-                entry.addRoute(routerId, newRoute.getPathId().getValue(), newRoute);
-                this.totalPathsCounter.increment();
-            } else {
-                routeKey = oldRoute.getRouteKey();
-                entry = this.routeEntries.get(routeKey);
-                if (entry != null) {
-                    this.totalPathsCounter.decrement();
-                    if (entry.removeRoute(routerId, oldRoute.getPathId().getValue())) {
-                        this.routeEntries.remove(routeKey);
-                        this.totalPrefixesCounter.decrement();
-                        LOG.trace("Removed route from {}", routerId);
+            RouteEntry<C, S, R, I> entry;
+            switch (route.getModificationType()) {
+                case DELETE:
+                    entry = this.routeEntries.get(routeKey);
+                    if (entry != null) {
+                        this.totalPathsCounter.decrement();
+                        if (entry.removeRoute(routerId, pathId.getValue())) {
+                            this.routeEntries.remove(routeKey);
+                            this.totalPrefixesCounter.decrement();
+                            LOG.trace("Removed route from {}", routerId);
+                        }
                     }
-                }
+                    break;
+                case SUBTREE_MODIFIED:
+                case WRITE:
+                    final R newRoute = (R) route.getDataAfter();
+                    entry = this.routeEntries.get(routeKey);
+                    if (entry == null) {
+                        entry = createEntry(routeKey);
+                    }
+
+                    entry.addRoute(routerId, pathId.getValue(), newRoute);
+                    this.totalPathsCounter.increment();
+                    break;
+                default:
+                    throw new IllegalStateException("Unhandled route modification " + route);
             }
+
             final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(routerId, routeKey);
             LOG.debug("Updated route {} entry {}", routeKey, entry);
             routes.put(routeUpdateKey, entry);
index 7a4fa5145694997a1ac9161e0c31e52b9b3cce69..40a89873270c11bce456f615188418ed12821f08 100644 (file)
@@ -299,4 +299,22 @@ public interface RIBSupport<
     default I createRouteListKey(@Nonnull final String routeKey) {
         return createRouteListKey(NON_PATH_ID, routeKey);
     }
+
+    /**
+     * Given a route list key, return the associated path ID.
+     *
+     * @param routeListKey Route list key
+     * @return Path ID
+     */
+    @Nonnull
+    PathId extractPathId(@Nonnull I routeListKey);
+
+    /**
+     * Given a route list key, return the associated path ID.
+     *
+     * @param routeListKey Route list key
+     * @return RouteKey
+     */
+    @Nonnull
+    String extractRouteKey(@Nonnull I routeListKey);
 }
index e9f0f0ec3a2f08b301de432cfb0190ce2b85f501..3c76f8a72a538f74815914865973df599cb5decf 100644 (file)
@@ -88,4 +88,14 @@ public final class RIBSupportTestImp extends AbstractRIBSupport<Ipv4RoutesCase,
     public List<Ipv4Route> routesFromContainer(final Ipv4Routes container) {
         return container.getIpv4Route();
     }
+
+    @Override
+    public PathId extractPathId(final Ipv4RouteKey routeListKey) {
+        return routeListKey.getPathId();
+    }
+
+    @Override
+    public String extractRouteKey(final Ipv4RouteKey routeListKey) {
+        return routeListKey.getRouteKey();
+    }
 }
\ No newline at end of file