Cache Instance identifier to table/(choice routes)/(map of route) 06/73006/1
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 14 Jun 2018 13:47:15 +0000 (15:47 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 14 Jun 2018 13:59:28 +0000 (15:59 +0200)
Change-Id: I7e765f53410b17100a5ff1790c1a038ce66140a3
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java
bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRibSupport.java
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/AbstractL3vpnMcastIpRIBSupport.java
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/unicast/AbstractVpnRIBSupport.java
bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java
bgp/mvpn/src/main/java/org/opendaylight/protocol/bgp/mvpn/impl/AbstractMvpnRIBSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java

index 7be057a1debeadae4e15d019e2c7b96c22b0ffee..ceb82223b340a0812b0dc85a12a4dfc0fba843c5 100644 (file)
@@ -10,9 +10,15 @@ package org.opendaylight.protocol.bgp.flowspec;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 import com.google.common.collect.Iterables;
+import com.google.common.primitives.UnsignedInteger;
 import java.util.Collection;
 import java.util.Optional;
+import java.util.Set;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
@@ -88,7 +94,8 @@ public abstract class AbstractFlowspecRIBSupport<
         final ApplyRoute function
     ) {
         if (destination != null) {
-            final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
+            final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
+
             final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf
                     = destination.getChild(routePathIdNid());
             final String routeKeyValue = this.nlriParser.stringNlri(destination);
index 2141b4c74a2ae4d0893fbcb1739b57ed587c7993..56d44103edf606347f9df628cf6f0cbae873ea33 100644 (file)
@@ -85,8 +85,7 @@ abstract class AbstractIPRibSupport<
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
                     // Instance identifier to table/(choice routes)/(map of route)
-                    // FIXME: cache on per-table basis (in TableContext, for example)
-                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
+                    final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
                     for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
                         final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
                         function.apply(tx, base, routeKey, e, attributes);
index 304283ee6aafa26c6914c6af61a1717a3f56c1f4..dd1ff75820f213bbd7af3ff9cb30558dbe908f08 100644 (file)
@@ -119,7 +119,7 @@ abstract class AbstractL3vpnMcastIpRIBSupport<
 
     @Override
     protected final void processDestination(
-            DOMDataWriteTransaction tx,
+            final DOMDataWriteTransaction tx,
             final YangInstanceIdentifier routesPath,
             final ContainerNode destination,
             final ContainerNode attributes,
@@ -130,7 +130,7 @@ abstract class AbstractL3vpnMcastIpRIBSupport<
             if (maybeRoutes.isPresent()) {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
-                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
+                    final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
                     for (final UnkeyedListEntryNode l3vpnDest : ((UnkeyedListNode) routes).getValue()) {
                         final YangInstanceIdentifier.NodeIdentifierWithPredicates routeKey = createRouteKey(l3vpnDest);
                         function.apply(tx, base, routeKey, l3vpnDest, attributes);
index 08da8b7640583cba26c830ef96a707333a47fa41..a4a0b39de6bb88ad5adfc497388bfe2977286067 100644 (file)
@@ -124,7 +124,7 @@ public abstract class AbstractVpnRIBSupport<C extends Routes & DataObject, S ext
                 if (routes instanceof UnkeyedListNode) {
                     final UnkeyedListNode routeListNode = (UnkeyedListNode) routes;
                     LOG.debug("{} routes are found", routeListNode.getSize());
-                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
+                    final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
                     for (final UnkeyedListEntryNode e : routeListNode.getValue()) {
                         final NodeIdentifierWithPredicates key = createRouteKey(e);
                         LOG.debug("Route {} is processed.", key);
index 57be87a87758f2bea7adfc5971cb651e398f4b67..5451b491dd39fac1bddc9cf5cc548a33d5b0c79d 100644 (file)
@@ -98,7 +98,7 @@ abstract class AbstractLabeledUnicastRIBSupport<
             if (maybeRoutes.isPresent()) {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
-                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
+                    final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
                     for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
                         final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
                         function.apply(tx, base, routeKey, e, attributes);
index b35b8c2ced5ee2cc53e653d668a38584561855c0..42438199d6870f20e554b0a6ac9351bb652a6605 100644 (file)
@@ -109,7 +109,7 @@ public final class LinkstateRIBSupport
         if (maybeRoutes.isPresent()) {
             final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
             if (routes instanceof UnkeyedListNode) {
-                final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
+                final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
                 for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
                     final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
                     function.apply(tx, base, routeKey, e, attributes);
index dc28372154034d6535e421ecd696e5c50b173e5a..a35a49df1df7edc1ad97c16435d1ee5172a83cf0 100644 (file)
@@ -118,7 +118,7 @@ abstract class AbstractMvpnRIBSupport<C extends Routes & DataObject & ChoiceIn<T
             if (maybeRoutes.isPresent()) {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
-                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
+                    final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
                     for (final UnkeyedListEntryNode mvpnDest : ((UnkeyedListNode) routes).getValue()) {
                         final NodeIdentifierWithPredicates routeKey = createRouteKey(mvpnDest);
                         function.apply(tx, base, routeKey, mvpnDest, attributes);
index 60f7998c6610e7bad3089fa1d2871dd40af1aa48..6b141b3fce7bde846dfa1ac32109a185e50236de 100644 (file)
@@ -10,9 +10,13 @@ package org.opendaylight.protocol.bgp.rib.spi;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Optional;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
@@ -89,6 +93,14 @@ public abstract class AbstractRIBSupport<
             .child(Rib.class).child(LocRib.class).child(Tables.class);
     private static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
     private static final ApplyRoute DELETE_ROUTE = new DeleteRoute();
+    // Instance identifier to table/(choice routes)/(map of route)
+    private final LoadingCache<YangInstanceIdentifier, YangInstanceIdentifier> routesPath = CacheBuilder.newBuilder()
+            .weakValues().build(new CacheLoader<YangInstanceIdentifier, YangInstanceIdentifier>() {
+                @Override
+                public YangInstanceIdentifier load(@Nonnull final YangInstanceIdentifier routesPath) {
+                    return routesPath.node(routesContainerIdentifier()).node(routeQName());
+                }
+            });
     private final NodeIdentifier routesContainerIdentifier;
     private final NodeIdentifier routesListIdentifier;
     private final NodeIdentifier routeAttributesIdentifier;
@@ -495,4 +507,8 @@ public abstract class AbstractRIBSupport<
         }
         return null;
     }
+
+    protected YangInstanceIdentifier routesYangInstanceIdentifier(final YangInstanceIdentifier routesPath) {
+        return this.routesPath.getUnchecked(routesPath);
+    }
 }