use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class BGPPeer method onSessionUp.
@Override
public synchronized void onSessionUp(final BGPSession session) {
this.currentSession = session;
this.sessionUp = true;
this.ribOutChain = this.rib.createPeerDOMChain(new DOMTransactionChainListener() {
@Override
public void onTransactionChainSuccessful(final DOMTransactionChain chain) {
LOG.debug("RibOut transaction chain {} successful.", chain);
}
@Override
public void onTransactionChainFailed(final DOMTransactionChain chain, final DOMDataTreeTransaction transaction, final Throwable cause) {
onRibOutChainFailed(cause);
}
});
if (this.currentSession instanceof BGPSessionStateProvider) {
((BGPSessionStateProvider) this.currentSession).registerMessagesCounter(this);
}
final GracefulRestartCapability advertisedGracefulRestartCapability = session.getAdvertisedGracefulRestartCapability();
final var advertisedTables = advertisedGracefulRestartCapability.getTables();
final var advertisedLLTables = session.getAdvertisedLlGracefulRestartCapability().getTables();
final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", getName(), advertizedTableTypes, addPathTablesType);
final Set<TablesKey> setTables = advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toSet());
this.tables = ImmutableSet.copyOf(setTables);
this.addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
final boolean restartingLocally = isLocalRestarting();
if (!restartingLocally) {
addBgp4Support();
}
if (!isRestartingGracefully()) {
this.peerId = RouterIds.createPeerId(session.getBgpId());
final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer, PeerKey> peerIId = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer.class, new PeerKey(this.peerId));
this.peerPath = createPeerPath(this.peerId);
this.peerRibOutIId = peerPath.node(ADJRIBOUT_NID);
this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
createEffRibInWriter();
registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
this.effRibInWriter.init();
this.ribWriter = this.ribWriter.transform(this.peerId, this.peerPath, this.rib.getRibSupportContext(), this.tables, this.addPathTableMaps);
if (this.rpcRegistry != null) {
this.rpcRegistration = this.rpcRegistry.registerRpcImplementation(BgpPeerRpcService.class, new BgpPeerRpc(this, session, this.tables), ImmutableSet.of(this.rib.getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer.class, new PeerKey(this.peerId))));
}
} else {
final Set<TablesKey> forwardingTables;
if (advertisedTables == null) {
forwardingTables = Collections.emptySet();
} else {
forwardingTables = advertisedTables.values().stream().filter(table -> table.getAfiFlags() != null).filter(table -> table.getAfiFlags().getForwardingState()).map(table -> new TablesKey(table.getAfi(), table.getSafi())).collect(Collectors.toSet());
}
this.ribWriter.clearTables(Sets.difference(this.tables, forwardingTables));
if (restartingLocally) {
this.effRibInWriter.close();
this.peerRestartStopwatch = Stopwatch.createStarted();
handleSelectionReferralTimer();
this.missingEOT.addAll(this.tables);
}
}
if (advertisedTables == null || advertisedTables.isEmpty()) {
setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
} else {
setAdvertizedGracefulRestartTableTypes(advertisedTables.values().stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
}
setAfiSafiGracefulRestartState(advertisedGracefulRestartCapability.getRestartTime().toJava(), false, restartingLocally);
final Map<TablesKey, Integer> llTablesReceived;
if (advertisedLLTables != null) {
llTablesReceived = new HashMap<>();
for (var table : advertisedLLTables.values()) {
llTablesReceived.put(new TablesKey(table.getAfi(), table.getSafi()), table.getLongLivedStaleTime().getValue().intValue());
}
} else {
llTablesReceived = Collections.emptyMap();
}
setAdvertizedLlGracefulRestartTableTypes(llTablesReceived);
if (!llTablesReceived.isEmpty()) {
llgrSupport = true;
// FIXME: propagate preserved tables
} else {
// FIXME: clear preserved tables
llgrSupport = false;
}
if (!restartingLocally) {
if (!setTables.contains(IPV4_UCAST_TABLE_KEY)) {
createAdjRibOutListener(IPV4_UCAST_TABLE_KEY, false);
}
for (final TablesKey key : getAfiSafisAdvertized()) {
createAdjRibOutListener(key, true);
}
}
// SpotBugs does not grok Optional.ifPresent() and thinks we are using unsynchronized access
final Optional<RevisedErrorHandlingSupport> errorHandling = this.bgpPeer.getErrorHandling();
if (errorHandling.isPresent()) {
this.currentSession.addDecoderConstraint(RevisedErrorHandlingSupport.class, errorHandling.get());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class BGPPeer method setGracefulPreferences.
private synchronized void setGracefulPreferences(final boolean localRestarting, final Set<TablesKey> preservedTables) {
final Set<TablesKey> gracefulTables = this.tables.stream().filter(this::isGracefulRestartAdvertized).collect(Collectors.toSet());
final BgpParameters bgpParameters = GracefulRestartUtil.getGracefulBgpParameters(this.bgpPeer.getBgpFixedCapabilities(), gracefulTables, preservedTables, this.bgpPeer.getGracefulRestartTimer(), localRestarting, Collections.emptySet());
final BGPSessionPreferences oldPrefs = this.rib.getDispatcher().getBGPPeerRegistry().getPeerPreferences(getNeighborAddress());
final BGPSessionPreferences newPrefs = new BGPSessionPreferences(oldPrefs.getMyAs(), oldPrefs.getHoldTime(), oldPrefs.getBgpId(), oldPrefs.getExpectedRemoteAs(), Collections.singletonList(bgpParameters), oldPrefs.getMd5Password());
this.rib.getDispatcher().getBGPPeerRegistry().updatePeerPreferences(getNeighborAddress(), newPrefs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class GracefulRestartUtil method getLlGracefulTimers.
static Map<TablesKey, Integer> getLlGracefulTimers(final Collection<? extends AfiSafi> afiSafis, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
final Map<TablesKey, Integer> timers = new HashMap<>();
afiSafis.forEach(afiSafi -> {
final GracefulRestart gracefulRestart = afiSafi.getGracefulRestart();
if (gracefulRestart != null) {
final Config gracefulRestartConfig = gracefulRestart.getConfig();
if (gracefulRestartConfig != null) {
final LlGracefulRestart llGracefulRestart;
final Config1 peerAug = gracefulRestartConfig.augmentation(Config1.class);
if (peerAug != null) {
llGracefulRestart = peerAug.getLlGracefulRestart();
} else {
final Config2 neighborAug = gracefulRestartConfig.augmentation(Config2.class);
if (neighborAug != null) {
llGracefulRestart = neighborAug.getLlGracefulRestart();
} else {
return;
}
}
if (llGracefulRestart != null) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.ll.graceful.restart.Config config = llGracefulRestart.getConfig();
if (config != null) {
final Uint24 staleTime = config.getLongLivedStaleTime();
if (staleTime != null && staleTime.getValue().toJava() > 0) {
final TablesKey key = tableTypeRegistry.getTableKey(afiSafi.getAfiSafiName());
if (key != null) {
timers.put(key, staleTime.getValue().intValue());
} else {
LOG.debug("Skipping unsupported afi-safi {}", afiSafi.getAfiSafiName());
}
}
}
}
}
}
});
return timers;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class BGPSynchronization method updReceived.
/**
* For each received Update message, the upd sync variable needs to be updated to true, for particular AFI/SAFI
* combination. Currently we only assume Unicast SAFI. From the Update message we have to extract the AFI. Each
* Update message can contain BGP Object with one type of AFI. If the object is BGP Link, BGP Node or a BGPPrefix
* the AFI is Linkstate. In case of BGPRoute, the AFI depends on the IP Address of the prefix.
*
* @param msg received Update message
*/
public void updReceived(final Update msg) {
TablesKey type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
boolean isEOR = false;
if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
final Attributes attrs = msg.getAttributes();
if (attrs != null) {
if (attrs.augmentation(AttributesReach.class) != null) {
final AttributesReach pa = attrs.augmentation(AttributesReach.class);
if (pa.getMpReachNlri() != null) {
type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
}
} else if (attrs.augmentation(AttributesUnreach.class) != null) {
final AttributesUnreach pa = attrs.augmentation(AttributesUnreach.class);
if (pa.getMpUnreachNlri() != null) {
type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
}
if (pa.getMpUnreachNlri().getWithdrawnRoutes() == null) {
// EOR message contains only MPUnreach attribute and no NLRI
isEOR = true;
}
}
} else {
// true for empty Update Message
isEOR = true;
}
}
syncType(type, isEOR);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class EffectiveRibInWriter method deleteRoute.
private void deleteRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?> ribSupport, final YangInstanceIdentifier routeIdPath, final NormalizedNode route) {
handleRouteTarget(ModificationType.DELETE, ribSupport, routeIdPath, route);
tx.delete(LogicalDatastoreType.OPERATIONAL, routeIdPath);
LOG.debug("Route deleted. routeId={}", routeIdPath);
final TablesKey tablesKey = ribSupport.getTablesKey();
CountersUtil.decrement(this.prefixesInstalled.get(tablesKey), tablesKey);
}
Aggregations