import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
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.multiprotocol.rev171207.SendReceive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.ApplicationRibId;
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;
private ListenerRegistration<ApplicationPeer> registration;
private final Set<NodeIdentifierWithPredicates> supportedTables = new HashSet<>();
private final BGPSessionStateImpl bgpSessionState = new BGPSessionStateImpl();
+ private PeerId peerId;
@FunctionalInterface
interface RegisterAppPeerListener {
this.name = applicationRibId.getValue();
final RIB targetRib = requireNonNull(rib);
this.rawIdentifier = InetAddresses.forString(ipAddress.getValue()).getAddress();
- final NodeIdentifierWithPredicates peerId = IdentifierUtils.domPeerId(RouterIds.createPeerId(ipAddress));
- this.peerIId = targetRib.getYangRibId().node(Peer.QNAME).node(peerId);
+ final NodeIdentifierWithPredicates peerIId = IdentifierUtils.domPeerId(RouterIds.createPeerId(ipAddress));
+ this.peerIId = targetRib.getYangRibId().node(Peer.QNAME).node(peerIId);
this.adjRibsInId = this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME);
this.rib = targetRib;
this.ipAddress = ipAddress;
this.writerChain = this.rib.createPeerChain(this);
final Optional<SimpleRoutingPolicy> simpleRoutingPolicy = Optional.of(SimpleRoutingPolicy.AnnounceNone);
- final PeerId peerId = RouterIds.createPeerId(this.ipAddress);
+ this.peerId = RouterIds.createPeerId(this.ipAddress);
final Set<TablesKey> localTables = this.rib.getLocalTablesKeys();
localTables.forEach(tablesKey -> {
final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(tablesKey);
if (exportTracker != null) {
- exportTracker.registerPeer(peerId, null, this.peerIId, PeerRole.Internal, simpleRoutingPolicy);
+ exportTracker.registerPeer(this.peerId, null, this.peerIId, PeerRole.Internal, simpleRoutingPolicy);
}
this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey));
});
}
}
};
- this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap(),
+ this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, context, localTables, Collections.emptyMap(),
registerAppPeerListener);
this.effectiveRibInWriter = EffectiveRibInWriter
.create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
tx.submit();
}
- /**
- * Applies modification under table routes based on modification type instead of only put. BUG 4438
- *
- * @param node
- * @param identifier
- * @param tx
- * @param routeTableIdentifier
- */
private synchronized void processRoutesTable(final DataTreeCandidateNode node,
final YangInstanceIdentifier identifier, final DOMDataWriteTransaction tx,
final YangInstanceIdentifier routeTableIdentifier) {
return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
}
+ @Override
+ public PeerId getPeerId() {
+ return this.peerId;
+ }
+
+ @Override
+ public boolean supportsAddPathSupported(final TablesKey tableKey) {
+ return false;
+ }
+
+ @Override
+ public SendReceive getSupportedAddPathTables(final TablesKey tableKey) {
+ return null;
+ }
+
+ @Override
+ public boolean supportsTable(final TablesKey tableKey) {
+ return this.rib.supportsTable(tableKey);
+ }
+
+ @Override
+ public YangInstanceIdentifier getPeerRibInstanceIdentifier() {
+ return this.peerIId;
+ }
+
+ @Override
+ public PeerRole getRole() {
+ return PeerRole.Internal;
+ }
+
@Override
public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
- final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+ final AsyncTransaction<?, ?> transaction, final Throwable cause) {
LOG.error("Transaction chain {} failed.", transaction != null ? transaction.getIdentifier() : null, cause);
}
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
private final Optional<SimpleRoutingPolicy> simpleRoutingPolicy;
@GuardedBy("this")
private final Set<AbstractRegistration> tableRegistration = new HashSet<>();
+ private final PeerId peerId;
+ private final YangInstanceIdentifier peerIId;
@GuardedBy("this")
private BGPSession session;
@GuardedBy("this")
@GuardedBy("this")
private EffectiveRibInWriter effRibInWriter;
private RoutedRpcRegistration<BgpPeerRpcService> rpcRegistration;
+ private Map<TablesKey, SendReceive> addPathTableMaps = Collections.emptyMap();
public BGPPeer(final IpAddress neighborAddress, final RIB rib, final PeerRole role,
final SimpleRoutingPolicy peerStatus, final RpcProviderRegistry rpcRegistry,
- @Nonnull final Set<TablesKey> afiSafisAdvertized,
- @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+ final Set<TablesKey> afiSafisAdvertized,
+ final Set<TablesKey> afiSafisGracefulAdvertized) {
//FIXME BUG-6971 Once Peer Group is implemented, pass it
super(rib.getInstanceIdentifier(), null, neighborAddress, afiSafisAdvertized,
afiSafisGracefulAdvertized);
this.rib = requireNonNull(rib);
this.name = Ipv4Util.toStringIP(neighborAddress);
this.rpcRegistry = rpcRegistry;
+ this.peerId = RouterIds.createPeerId(neighborAddress);
+ this.peerIId = this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
+ .bgp.rib.rev171207.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(this.peerId));
+
this.chain = rib.createPeerChain(this);
}
@VisibleForTesting
BGPPeer(final IpAddress neighborAddress, final RIB rib, final PeerRole role,
- final RpcProviderRegistry rpcRegistry, @Nonnull final Set<TablesKey> afiSafisAdvertized,
- @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+ final RpcProviderRegistry rpcRegistry, final Set<TablesKey> afiSafisAdvertized,
+ final Set<TablesKey> afiSafisGracefulAdvertized) {
this(neighborAddress, rib, role, null, rpcRegistry, afiSafisAdvertized, afiSafisGracefulAdvertized);
}
if (msg instanceof Update) {
onUpdateMessage((Update) msg);
} else {
- onRouteRefreshMessage((RouteRefresh) msg, session);
+ onRouteRefreshMessage((RouteRefresh) msg);
}
}
- private void onRouteRefreshMessage(final RouteRefresh message, final BGPSession session) {
+ private void onRouteRefreshMessage(final RouteRefresh message) {
final Class<? extends AddressFamily> rrAfi = message.getAfi();
final Class<? extends SubsequentAddressFamily> rrSafi = message.getSafi();
if (listener != null) {
listener.close();
this.adjRibOutListenerSet.remove(key);
- createAdjRibOutListener(RouterIds.createPeerId(session.getBgpId()), key, listener.isMpSupported());
+ createAdjRibOutListener(key, listener.isMpSupported());
} else {
LOG.info("Ignoring RouteRefresh message. Afi/Safi is not supported: {}, {}.", rrAfi, rrSafi);
}
// update AdjRibs
final Attributes attrs = message.getAttributes();
- MpReachNlri mpReach = null;
+ MpReachNlri mpReach;
final boolean isAnyNlriAnnounced = message.getNlri() != null;
if (isAnyNlriAnnounced) {
mpReach = prefixesToMpReach(message);
if (mpReach != null) {
this.ribWriter.updateRoutes(mpReach, nextHopToAttribute(attrs, mpReach));
}
- MpUnreachNlri mpUnreach = null;
+ MpUnreachNlri mpUnreach;
if (message.getWithdrawnRoutes() != null) {
mpUnreach = prefixesToMpUnreach(message, isAnyNlriAnnounced);
} else {
if (this.session instanceof BGPSessionStateProvider) {
((BGPSessionStateProvider) this.session).registerMessagesCounter(this);
}
-
final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
final List<BgpTableType> advertizedGracefulRestartTableTypes = session.getAdvertisedGracefulRestartTableTypes();
LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", this.name,
advertizedTableTypes, addPathTablesType);
this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
- final PeerId peerId = RouterIds.createPeerId(session.getBgpId());
-
this.tables.addAll(advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi()))
.collect(Collectors.toList()));
setAdvertizedGracefulRestartTableTypes(advertizedGracefulRestartTableTypes.stream()
.map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
final boolean announceNone = isAnnounceNone(this.simpleRoutingPolicy);
- final Map<TablesKey, SendReceive> addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
+ this.addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
if (!announceNone) {
for (final TablesKey key : this.tables) {
- createAdjRibOutListener(peerId, key, true);
+ createAdjRibOutListener(key, true);
}
}
- final YangInstanceIdentifier peerIId = this.rib.getYangRibId()
- .node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
- .bgp.rib.rev171207.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(peerId));
-
for(final TablesKey tablesKey :this.tables) {
final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(tablesKey);
if (exportTracker != null) {
- this.tableRegistration.add(exportTracker.registerPeer(peerId, addPathTableMaps.get(tablesKey),
- peerIId, this.peerRole, this.simpleRoutingPolicy));
+ this.tableRegistration.add(exportTracker.registerPeer(this.peerId, this.addPathTableMaps.get(tablesKey),
+ this.peerIId, this.peerRole, this.simpleRoutingPolicy));
}
}
- addBgp4Support(peerId, peerIId, announceNone);
+ addBgp4Support(announceNone);
if (!isLearnNone(this.simpleRoutingPolicy)) {
this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(),
this.rib.createPeerChain(this),
- peerIId, this.rib.getImportPolicyPeerTracker(),
+ this.peerIId, this.rib.getImportPolicyPeerTracker(),
this.rib.getRibSupportContext(),
this.peerRole,
this.tables);
registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
}
- this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables,
- addPathTableMaps);
+ this.ribWriter = this.ribWriter.transform(this.peerId, this.rib.getRibSupportContext(), this.tables,
+ this.addPathTableMaps);
if (this.rpcRegistry != null) {
this.rpcRegistration = this.rpcRegistry.addRoutedRpcImplementation(BgpPeerRpcService.class,
final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib
.rev171207.bgp.rib.rib.Peer, PeerKey> path = this.rib.getInstanceIdentifier()
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib
- .rib.Peer.class, new PeerKey(peerId));
+ .rib.Peer.class, new PeerKey(this.peerId));
this.rpcRegistration.registerPath(PeerContext.class, path);
}
}
//try to add a support for old-school BGP-4, if peer did not advertise IPv4-Unicast MP capability
- private void addBgp4Support(final PeerId peerId, final YangInstanceIdentifier peerIId, final boolean announceNone) {
+ private void addBgp4Support(final boolean announceNone) {
final TablesKey key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
if (this.tables.add(key) && !announceNone) {
- createAdjRibOutListener(peerId, key, false);
+ createAdjRibOutListener(key, false);
final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(key);
if (exportTracker != null) {
- this.tableRegistration.add(exportTracker.registerPeer(peerId, null, peerIId,
+ this.tableRegistration.add(exportTracker.registerPeer(peerId, null, this.peerIId,
this.peerRole, this.simpleRoutingPolicy));
}
}
}
- private synchronized void createAdjRibOutListener(final PeerId peerId, final TablesKey key,
+ private synchronized void createAdjRibOutListener(final TablesKey key,
final boolean mpSupport) {
final RIBSupportContext context = this.rib.getRibSupportContext().getRIBSupportContext(key);
// not particularly nice
if (context != null && this.session instanceof BGPSessionImpl) {
final ChannelOutputLimiter limiter = ((BGPSessionImpl) this.session).getLimiter();
- final AdjRibOutListener adjRibOut = AdjRibOutListener.create(peerId, key,
+ final AdjRibOutListener adjRibOut = AdjRibOutListener.create(this.peerId, key,
this.rib.getYangRibId(), this.rib.getCodecsRegistry(), context.getRibSupport(),
this.rib.getService(), limiter, mpSupport);
this.adjRibOutListenerSet.put(key, adjRibOut);
return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
}
+ @Override
+ public PeerId getPeerId() {
+ return this.peerId;
+ }
+
+ @Override
+ public SendReceive getSupportedAddPathTables(final TablesKey tableKey) {
+ return this.addPathTableMaps.get(tableKey);
+ }
+
+ @Override
+ public boolean supportsTable(final TablesKey tableKey) {
+ return this.tables.contains(tableKey);
+ }
+
+ @Override
+ public YangInstanceIdentifier getPeerRibInstanceIdentifier() {
+ return this.peerIId;
+ }
+
+ @Override
+ public PeerRole getRole() {
+ return this.peerRole;
+ }
+
@Override
public synchronized void onTransactionChainFailed(final TransactionChain<?, ?> chain,
final AsyncTransaction<?, ?> transaction, final Throwable cause) {
@Override
public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
- LOG.debug("Transaction chain {} successfull.", chain);
+ LOG.debug("Transaction chain {} successful.", chain);
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.spi;
+
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.protocol.concepts.AbstractRegistration;
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+/**
+ * Tracks Peers under RIB.
+ */
+public interface BGPPeerTracker {
+ /**
+ * Register Peer.
+ *
+ * @param peer Peer
+ * @return registration tickets
+ */
+ AbstractRegistration registerPeer(@Nonnull Peer peer);
+
+ /**
+ * Returns Peer
+ *
+ * @param peerId peer ID
+ * @return Peer
+ */
+ @Nullable
+ Peer getPeer(@Nonnull PeerId peerId);
+
+ /**
+ * Returns if peer supports table.
+ *
+ * @param peerIdOfNewPeer PeerId
+ * @param tableKey table
+ * @return true if Additional Path is supported for defined table
+ */
+ boolean supportsTable(@Nonnull PeerId peerIdOfNewPeer, @Nonnull TablesKey tableKey);
+
+ /**
+ * Returns map of PeerId per PeerRole.
+ * Role with none peerId will be filtered.
+ *
+ * @return Returns map of PeerId group by PeerRole
+ */
+ @Nonnull
+ Map<PeerRole, List<PeerId>> getRoles();
+
+ /**
+ * Returns if peer supports Additional Path for specific table.
+ *
+ * @param toPeer peer ID
+ * @param localTK table
+ * @return true if Additional Path is supported for defined table
+ */
+ boolean supportsAddPathSupported(@Nonnull PeerId toPeer, @Nonnull TablesKey localTK);
+
+ /**
+ * Returns role of specific peer if present.
+ *
+ * @param peerId peer identifier
+ * @return role
+ */
+ @Nullable
+ PeerRole getRole(@Nonnull PeerId peerId);
+
+ /**
+ * Returns YangInstanceIdentifier pointing peer under specific rib.
+ *
+ * @return Peer YangInstanceIdentifier
+ */
+ @Nullable
+ YangInstanceIdentifier getPeerRibInstanceIdentifier(@Nonnull PeerId peerId);
+}