this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, context, localTables, Collections.emptyMap(),
registerAppPeerListener);
this.effectiveRibInWriter = EffectiveRibInWriter
- .create(this.rib, this.rib.createPeerChain(this), this.peerIId,
- this.rib.getImportPolicyPeerTracker(), PeerRole.Internal,
- localTables);
+ .create(this.rib, this.rib.createPeerChain(this), this.peerIId, localTables);
this.bgpSessionState.registerMessagesCounter(this);
this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
}
}
addBgp4Support();
- this.effRibInWriter = EffectiveRibInWriter.create(this.rib,
- this.rib.createPeerChain(this),
- this.peerIId, this.rib.getImportPolicyPeerTracker(),
- this.peerRole,
- this.tables);
+ this.effRibInWriter = EffectiveRibInWriter.create(this.rib, this.rib.createPeerChain(this),
+ this.peerIId, this.tables);
registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
this.ribWriter = this.ribWriter.transform(this.peerId, this.rib.getRibSupportContext(), this.tables,
this.addPathTableMaps);
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.Interner;
-import com.google.common.collect.Interners;
-import com.google.common.collect.MapMaker;
-import java.util.concurrent.ConcurrentMap;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Attributes;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-
-/**
- * A caching decorator for {@link AbstractImportPolicy}. Performs caching of effective
- * attributes using an identity-and-hashCode-based map for fast lookup and reuse of resulting
- * objects.
- */
-@NotThreadSafe
-final class CachingImportPolicy extends AbstractImportPolicy {
-
- // A dummy ContainerNode, stored in the cache to indicate null effective attributes
- private static final ContainerNode MASKED_NULL = ImmutableNodes.containerNode(Attributes.QNAME);
-
- // We maintain a weak cache of returned effective attributes, so we end up reusing
- // the same instance when asked. We set concurrency level to 1, as we do not expect
- // the cache to be accessed from multiple threads. That may need to be changed
- // if we end up sharing the cache across peers.
- private final ConcurrentMap<ContainerNode, ContainerNode> cache =
- new MapMaker().concurrencyLevel(1).weakKeys().weakValues().makeMap();
-
- /*
- * The cache itself is weak, which means we end up with identity hash/comparisons.
- * That is good, but we want the cache to be effective even when equivalent attributes
- * are presented. For that purpose we maintain a weak interner, which will allow us
- * to map attributes to a canonical object without preventing garbage collection.
- */
- private final Interner<ContainerNode> interner = Interners.newWeakInterner();
-
- private final AbstractImportPolicy delegate;
-
- CachingImportPolicy(final AbstractImportPolicy delegate) {
- this.delegate = requireNonNull(delegate);
- }
-
- @Nonnull private static ContainerNode maskNull(@Nullable final ContainerNode unmasked) {
- return unmasked == null ? MASKED_NULL : unmasked;
- }
-
- @Nullable private static ContainerNode unmaskNull(@Nonnull final ContainerNode masked) {
- return MASKED_NULL.equals(masked) ? null : masked;
- }
-
- @Override
- public ContainerNode effectiveAttributes(final ContainerNode attributes) {
- ContainerNode ret = this.cache.get(attributes);
- if (ret != null) {
- return unmaskNull(ret);
- }
-
- /*
- * The cache returned empty. The reason for that may be that the attributes
- * passed in are not identical to the ones forming the cache's key. Intern
- * the passed attributes, which will result in a canonical reference.
- *
- * If the returned reference is different, attempt to look up in the cache
- * again. If the reference is the same, we have just populated the interner
- * and thus are on the path to create a new cache entry.
- */
- final ContainerNode interned = this.interner.intern(attributes);
- if (!interned.equals(attributes)) {
- final ContainerNode retry = this.cache.get(interned);
- if (retry != null) {
- return unmaskNull(retry);
- }
- }
-
- final ContainerNode effective = this.delegate.effectiveAttributes(interned);
-
- /*
- * Populate the cache. Note that this may have raced with another thread,
- * in which case we want to reuse the previous entry without replacing it.
- * Check the result of conditional put and return it unmasked if it happens
- * to be non-null. That will throw away the attributes we just created,
- * but that's fine, as they have not leaked to heap yet and will be GC'd
- * quickly.
- */
- final ContainerNode existing = this.cache.putIfAbsent(interned, maskNull(effective));
- return existing != null ? unmaskNull(existing) : effective;
-
- }
-}
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
-import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
return b.build();
}
- private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy,
+ private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport,
final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) {
LOG.debug("Process route {}", route.getIdentifier());
final YangInstanceIdentifier routeId = ribSupport.routePath(routesPath, route.getIdentifier());
// No-op
break;
case SUBTREE_MODIFIED:
- processModifiedRouteTables(child, childIdentifier, tx, ribSupport, EffectiveRibInWriter.this.importPolicy, childPath, childDataAfter);
+ processModifiedRouteTables(child, childIdentifier, tx, ribSupport, childPath, childDataAfter);
break;
case APPEARED:
case WRITE:
- writeRouteTables(child, childIdentifier, tx, ribSupport, EffectiveRibInWriter.this.importPolicy, childPath, childDataAfter);
+ writeRouteTables(child, childIdentifier, tx, ribSupport, childPath, childDataAfter);
break;
default:
}
private void processModifiedRouteTables(final DataTreeCandidateNode child, final PathArgument childIdentifier, final DOMDataWriteTransaction tx,
- final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier childPath, final Optional<NormalizedNode<?, ?>> childDataAfter) {
+ final RIBSupport ribSupport, final YangInstanceIdentifier childPath, final Optional<NormalizedNode<?, ?>> childDataAfter) {
if (TABLE_ROUTES.equals(childIdentifier)) {
for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) {
- processRoute(tx, ribSupport, policy, childPath, route);
+ processRoute(tx, ribSupport, childPath, route);
}
} else {
tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get());
}
}
- private void writeRouteTables(final DataTreeCandidateNode child, final PathArgument childIdentifier, final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier childPath, final Optional<NormalizedNode<?, ?>> childDataAfter) {
+ private void writeRouteTables(final DataTreeCandidateNode child, final PathArgument childIdentifier,
+ final DOMDataWriteTransaction tx, final RIBSupport ribSupport,
+ final YangInstanceIdentifier childPath, final Optional<NormalizedNode<?, ?>> childDataAfter) {
if (TABLE_ROUTES.equals(childIdentifier)) {
final Collection<DataTreeCandidateNode> changedRoutes = ribSupport.changedRoutes(child);
if (!changedRoutes.isEmpty()) {
// Routes are special, as they may end up being filtered. The previous put conveniently
// ensured that we have them in at target, so a subsequent delete will not fail :)
for (final DataTreeCandidateNode route : changedRoutes) {
- processRoute(tx, ribSupport, policy, childPath, route);
+ processRoute(tx, ribSupport, childPath, route);
}
}
}
}
private final AdjInTracker adjInTracker;
- private final AbstractImportPolicy importPolicy;
static EffectiveRibInWriter create(@Nonnull final RIB rib,
@Nonnull final DOMTransactionChain chain,
@Nonnull final YangInstanceIdentifier peerIId,
- @Nonnull final ImportPolicyPeerTracker importPolicyPeerTracker,
- final PeerRole peerRole,
@Nonnull final Set<TablesKey> tables) {
- return new EffectiveRibInWriter(rib, chain, peerIId, importPolicyPeerTracker, peerRole, tables);
+ return new EffectiveRibInWriter(rib, chain, peerIId, tables);
}
private EffectiveRibInWriter(final RIB rib, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
- final ImportPolicyPeerTracker importPolicyPeerTracker, final PeerRole peerRole, @Nonnull final Set<TablesKey> tables) {
- importPolicyPeerTracker.peerRoleChanged(peerIId, peerRole);
- this.importPolicy = importPolicyPeerTracker.policyFor(IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerIId.getLastPathArgument()));
+ @Nonnull final Set<TablesKey> tables) {
this.adjInTracker = new AdjInTracker(rib, chain, peerIId, tables);
}
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
import java.util.function.BiConsumer;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-
-/**
- * Import policy invoked on routes which we get from outside of our home AS.
- */
-final class FromExternalImportPolicy extends AbstractImportPolicy {
- @Override
- public ContainerNode effectiveAttributes(final ContainerNode attributes) {
- /*
- * Filter out non-transitive attributes, so they do not cross inter-AS
- * boundaries.
- *
- * FIXME: to be completely flexible, we need to allow for retaining
- * the MED attribute. @see https://tools.ietf.org/html/rfc4271#section-5.1.4.
- */
- return AttributeOperations.getInstance(attributes).transitiveAttributes(attributes);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Invoked on routes which we get from our normal home AS peers.
- */
-class FromInternalImportPolicy extends AbstractImportPolicy {
- private static final Logger LOG = LoggerFactory.getLogger(FromInternalImportPolicy.class);
- private final ClusterIdentifier clusterIdentifier;
- private final Ipv4Address bgpIdentifier;
-
- FromInternalImportPolicy(final Ipv4Address bgpIdentifier, final ClusterIdentifier clusterIdentifier) {
- this.bgpIdentifier = requireNonNull(bgpIdentifier);
- this.clusterIdentifier = requireNonNull(clusterIdentifier);
- }
-
- @Override
- public ContainerNode effectiveAttributes(final ContainerNode attributes) {
- final AttributeOperations oper = AttributeOperations.getInstance(attributes);
-
- /*
- * This is an implementation of https://tools.ietf.org/html/rfc4456#section-8
- *
- * We first check the ORIGINATOR_ID, if present. If it matches our BGP identifier,
- * we filter the route.
- */
- final Object originatorId = oper.getOriginatorId(attributes);
- if (this.bgpIdentifier.getValue().equals(originatorId)) {
- LOG.debug("Filtering route with our ORIGINATOR_ID {}", this.bgpIdentifier);
- return null;
- }
-
- /*
- * Second we check CLUSTER_LIST, if present. If it contains our CLUSTER_ID, we issue
- * a warning and ignore the route.
- */
- final LeafSetNode<?> clusterList = oper.getClusterList(attributes);
- if (clusterList != null) {
- for (final LeafSetEntryNode<?> node : clusterList.getValue()) {
- if (this.clusterIdentifier.getValue().equals(node.getValue())) {
- LOG.info("Received a route with our CLUSTER_ID {} in CLUSTER_LIST {}, filtering it", this.clusterIdentifier.getValue(), clusterList);
- return null;
- }
- }
- }
-
- return attributes;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
-
-/**
- * Invoked on routes which we get from our Internal peers. This is a special-case of
- * FromInternalImportPolicy.
- */
-final class FromInternalReflectorClientImportPolicy extends FromInternalImportPolicy {
- FromInternalReflectorClientImportPolicy(final Ipv4Address bgpIdentifier, final ClusterIdentifier clusterIdentifier) {
- super(bgpIdentifier, clusterIdentifier);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-
-/**
- * Invoked on routes which we get from our reflector peers. This is a special-case of
- * FromInternalImportPolicy.
- */
-final class FromReflectorClientImportPolicy extends FromInternalImportPolicy {
- FromReflectorClientImportPolicy(final Ipv4Address bgpIdentifier, final ClusterIdentifier clusterIdentifier) {
- super(bgpIdentifier, clusterIdentifier);
- }
-
- @Override
- public ContainerNode effectiveAttributes(final ContainerNode attributes) {
- // TODO: (defensiveness) verify ORIGINATOR_ID (should have been set)
-
- return super.effectiveAttributes(attributes);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
-import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
-import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class ImportPolicyPeerTrackerImpl implements ImportPolicyPeerTracker {
- private static final Logger LOG = LoggerFactory.getLogger(ImportPolicyPeerTrackerImpl.class);
-
- private final Map<PeerId, AbstractImportPolicy> policies = new ConcurrentHashMap<>();
- private final PolicyDatabase policyDatabase;
-
- protected ImportPolicyPeerTrackerImpl(final PolicyDatabase policyDatabase) {
- super();
- this.policyDatabase = requireNonNull(policyDatabase);
- }
-
- @Override
- public void peerRoleChanged(final YangInstanceIdentifier peerPath, final PeerRole role) {
- final PeerId peer = IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerPath.getLastPathArgument());
-
- if (role != null) {
- // Lookup policy based on role
- final AbstractImportPolicy policy = this.policyDatabase.importPolicyForRole(role);
-
- // Update lookup map
- this.policies.put(peer, policy);
- LOG.debug("Updating policy {} for peer {}", policy, peer);
- } else {
- this.policies.remove(peer);
- }
- }
-
- @Override
- public AbstractImportPolicy policyFor(final PeerId peerId) {
- LOG.trace("Peer ID : {}", peerId);
- return this.policies.get(peerId);
- }
-}
\ No newline at end of file
import java.util.EnumMap;
import java.util.Map;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
*/
final class PolicyDatabase {
private final Map<PeerRole, AbstractExportPolicy> exportPolicies = new EnumMap<>(PeerRole.class);
- private final Map<PeerRole, AbstractImportPolicy> importPolicies = new EnumMap<>(PeerRole.class);
PolicyDatabase(final Long localAs, final Ipv4Address bgpId, final ClusterIdentifier clusterId) {
this.exportPolicies.put(PeerRole.Ebgp, new ToExternalExportPolicy(localAs));
this.exportPolicies.put(PeerRole.Ibgp, new ToInternalExportPolicy(bgpId, clusterId));
this.exportPolicies.put(PeerRole.RrClient, new ToReflectorClientExportPolicy(bgpId, clusterId));
this.exportPolicies.put(PeerRole.Internal, new ToInternalReflectorClientExportPolicy(bgpId, clusterId));
-
- this.importPolicies.put(PeerRole.Ebgp, new FromExternalImportPolicy());
- this.importPolicies.put(PeerRole.Ibgp, new FromInternalImportPolicy(bgpId, clusterId));
- this.importPolicies.put(PeerRole.RrClient, new FromReflectorClientImportPolicy(bgpId, clusterId));
- this.importPolicies.put(PeerRole.Internal, new FromInternalReflectorClientImportPolicy(bgpId, clusterId));
}
AbstractExportPolicy exportPolicyForRole(final PeerRole peerRole) {
return this.exportPolicies.get(peerRole);
}
-
- AbstractImportPolicy importPolicyForRole(final PeerRole peerRole) {
- /*
- * TODO: this solution does not share equivalent attributes across
- * multiple peers. If we need to do that, consider carefully:
- * - whether the interner should be shared with RIBSupportContextImpl.writeRoutes()
- * - lookup/update contention of both the cache and the interner
- * - ability to share resulting attributes across import policies
- * - ability to share resulting attributes with export policies
- */
- return new CachingImportPolicy(this.importPolicies.get(peerRole));
- }
}
import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
private final DOMDataBrokerExtension service;
private final Map<TransactionChain<?, ?>, LocRibWriter> txChainToLocRibWriter = new HashMap<>();
private final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies;
- private final ImportPolicyPeerTracker importPolicyPeerTracker;
private final RibId ribId;
private final BGPPeerTracker peerTracker;
private final BGPRibRoutingPolicy ribPolicies;
final ClusterIdentifier cId = clusterId == null ? new ClusterIdentifier(localBgpId) : clusterId;
this.ribId = ribId;
final PolicyDatabase policyDatabase = new PolicyDatabase(this.localAs.getValue(), localBgpId, cId);
- this.importPolicyPeerTracker = new ImportPolicyPeerTrackerImpl(policyDatabase);
final ImmutableMap.Builder<TablesKey, ExportPolicyPeerTracker> exportPolicies = new ImmutableMap.Builder<>();
for (final BgpTableType t : this.localTables) {
return this.codecsRegistry;
}
- @Override
- public ImportPolicyPeerTracker getImportPolicyPeerTracker() {
- return this.importPolicyPeerTracker;
- }
-
@Override
public ExportPolicyPeerTracker getExportPolicyPeerTracker(final TablesKey tablesKey) {
return this.exportPolicyPeerTrackerMap.get(tablesKey);
import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
this.serviceRegistration = serviceRegistration;
}
- @Override
- public ImportPolicyPeerTracker getImportPolicyPeerTracker() {
- return this.ribImpl.getImportPolicyPeerTracker();
- }
-
@Override
public ExportPolicyPeerTracker getExportPolicyPeerTracker(final TablesKey tablesKey) {
return this.ribImpl.getExportPolicyPeerTracker(tablesKey);
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl.spi;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-
-/**
- * Defines the internal hooks invoked when a new route appears.
- */
-public abstract class AbstractImportPolicy {
- /**
- * Transform incoming attributes according to policy.
- *
- * @param attributes received attributes
- * @return Filtered attributes, or null if the advertisement should be ignored.
- */
- @Nullable public abstract ContainerNode effectiveAttributes(@Nonnull ContainerNode attributes);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.rib.impl.spi;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
-/**
- * Tracks import policy corresponding to a particular peer.
- */
-public interface ImportPolicyPeerTracker {
-
- /**
- * Invoked whenever a peer role changes.
- *
- * @param peerPath Peer's path
- * @param role Peer's new role, null indicates the peer has disappeared.
- */
- void peerRoleChanged(YangInstanceIdentifier peerPath, PeerRole role);
-
- AbstractImportPolicy policyFor(PeerId peerId);
-
-}
*/
DOMDataTreeChangeService getService();
- ImportPolicyPeerTracker getImportPolicyPeerTracker();
-
/**
* Returns ExportPolicyPeerTracker for specific tableKey, where peer can register himself
* as supporting the table. Same export policy can be used to check which peers support respective
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
-
-public class FromExternalImportPolicyTest {
-
- private static final QName DATA_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "attributes").intern();
- private static final QName LOCALPREF = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "local-pref").intern();
- private static final QName CLUSTERID = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "cluster-id").intern();
- private static final QName CLUSTER = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "cluster").intern();
- private static final QName ASPATH = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "as-path").intern();
- private static final QName SEGMENT = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "segments").intern();
- private static final QName UNRECOGNIZED = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "unrecognized-attributes");
- private static final QName NEXTHOP = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "c-next-hop").intern();
- private static final QName IPV4NH = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "ipv4-next-hop").intern();
- private static final QName ORIGINATOR = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "originator-id").intern();
- private static final QName MED = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "multi-exit-disc").intern();
- private static final QName ORIGIN = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2013-09-19", "origin").intern();
-
- @Test
- public void testEffectiveAttributes() {
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder = createContBuilder(DATA_QNAME);
- // local pref
- dataContBuilder.addChild(createContBuilder(LOCALPREF).addChild(createValueBuilder(100L, LOCALPREF, "pref").build()).build());
-
- // cluster pref
- String s = "404.40.40.40";
- LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
- new NodeWithValue<>(CLUSTER, s)).withValue(s).build();
-
- dataContBuilder.addChild(createContBuilder(CLUSTERID).addChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
- new NodeIdentifier(QName.create(CLUSTER, "cluster"))).withChild(entry1).build()).build());
-
- // as-path pref
- final ContainerNode asPath = createContBuilder(ASPATH).addChild(ImmutableUnkeyedListNodeBuilder.create()
- .withNodeIdentifier(new NodeIdentifier(SEGMENT)).build()).build();
- dataContBuilder.addChild(asPath);
-
- // unrecognized
- dataContBuilder.addChild(ImmutableNodes.mapNodeBuilder(UNRECOGNIZED).build());
-
- // c-next-hop pref
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> nextHop = Builders.choiceBuilder();
- nextHop.withNodeIdentifier(new NodeIdentifier(NEXTHOP));
- final ContainerNode cNextHop = createContBuilder(IPV4NH).addChild(createValueBuilder("199.20.160.41", IPV4NH, "global").build()).build();
- final ChoiceNode resultNextHop = nextHop.addChild(cNextHop).build();
- dataContBuilder.addChild(resultNextHop);
-
- // originator pref
- dataContBuilder.addChild(createContBuilder(ORIGINATOR).addChild(createValueBuilder("41.41.41.41", ORIGINATOR, "originator").build()).build());
-
- // origin pref
- final ContainerNode origin = createContBuilder(ORIGIN).addChild(createValueBuilder("igp", ORIGIN, "value").build()).build();
- dataContBuilder.addChild(origin);
-
- // multi-exit-disc pref
- dataContBuilder.addChild(createContBuilder(MED).addChild(createValueBuilder("0", MED, "med").build()).build());
- FromExternalImportPolicy importPol = new FromExternalImportPolicy();
- final ContainerNode result = importPol.effectiveAttributes(dataContBuilder.build());
-
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContExpected = createContBuilder(DATA_QNAME);
-
- dataContExpected.addChild(asPath);
- dataContExpected.addChild(resultNextHop);
- dataContExpected.addChild(origin);
-
- assertEquals(dataContExpected.build(), result);
- }
-
- private static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createContBuilder(final QName qname) {
- return ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(new NodeIdentifier(qname));
- }
-
- private static <T> ImmutableLeafNodeBuilder<T> createValueBuilder(final T value, final QName qname, final String localName) {
- final ImmutableLeafNodeBuilder<T> valueBuilder = new ImmutableLeafNodeBuilder<>();
- valueBuilder.withNodeIdentifier(new NodeIdentifier(QName.create(qname, localName))).withValue(value);
- return valueBuilder;
- }
-}
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPPeerTrackerImpl;
import org.opendaylight.protocol.bgp.rib.impl.DefaultRibPoliciesMockTest;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
@Mock
protected DOMDataWriteTransaction domDW;
@Mock
- private ImportPolicyPeerTracker importPolicyPeerTracker;
- @Mock
private DOMDataTreeChangeService dataTreeChangeService;
private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
.getInstanceIdentifier();
doReturn(this.domTx).when(this.rib).createPeerChain(any(TransactionChainListener.class));
doReturn(AS).when(this.rib).getLocalAs();
- doReturn(this.importPolicyPeerTracker).when(this.rib).getImportPolicyPeerTracker();
- doNothing().when(this.importPolicyPeerTracker)
- .peerRoleChanged(any(YangInstanceIdentifier.class), any(PeerRole.class));
- doReturn(mock(AbstractImportPolicy.class))
- .when(this.importPolicyPeerTracker).policyFor(any(PeerId.class));
doReturn(mock(RIBSupportContextRegistry.class)).when(this.rib).getRibSupportContext();
doReturn(Collections.emptySet()).when(this.rib).getLocalTablesKeys();
doNothing().when(this.domTx).close();
assertEquals("RIBImpl{}", ribImpl.toString());
assertEquals(Collections.singleton(new TablesKey(Ipv4AddressFamily.class,
UnicastSubsequentAddressFamily.class)), ribImpl.getLocalTablesKeys());
- assertNotNull(ribImpl.getImportPolicyPeerTracker());
assertNotNull(ribImpl.getService());
assertNotNull(ribImpl.getInstanceIdentifier());
assertEquals(AS, ribImpl.getLocalAs());
*
* @return Peer YangInstanceIdentifier
*/
- @Nullable
+ @Nonnull
YangInstanceIdentifier getPeerRibInstanceIdentifier();
/**