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;
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);
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);
@Override
protected final void processDestination(
- DOMDataWriteTransaction tx,
+ final DOMDataWriteTransaction tx,
final YangInstanceIdentifier routesPath,
final ContainerNode destination,
final ContainerNode attributes,
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);
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);
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);
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);
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);
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;
.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;
}
return null;
}
+
+ protected YangInstanceIdentifier routesYangInstanceIdentifier(final YangInstanceIdentifier routesPath) {
+ return this.routesPath.getUnchecked(routesPath);
+ }
}