+ @Holding("this")
+ private void handleGracefulEndOfRib() {
+ if (isLocalRestarting()) {
+ if (this.missingEOT.isEmpty()) {
+ createEffRibInWriter();
+ this.effRibInWriter.init();
+ registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
+ for (final TablesKey key : getAfiSafisAdvertized()) {
+ createAdjRibOutListener(key, true);
+ }
+ setLocalRestartingState(false);
+ setGracefulPreferences(false, Collections.emptySet());
+ }
+ }
+ }
+
+ @Override
+ public synchronized void onSessionUp(final BGPSession session) {
+ this.currentSession = session;
+ this.sessionUp = true;
+ this.bindingChain = this.rib.createPeerChain(this);
+ if (this.currentSession instanceof BGPSessionStateProvider) {
+ ((BGPSessionStateProvider) this.currentSession).registerMessagesCounter(this);
+ }
+ final GracefulRestartCapability advertisedGracefulRestartCapability =
+ session.getAdvertisedGracefulRestartCapability();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp
+ .capabilities.graceful.restart.capability.Tables> advertisedTables =
+ advertisedGracefulRestartCapability.getTables();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp
+ .capabilities.ll.graceful.restart.capability.Tables> 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 {}", this.name,
+ 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 (!isRestartingGracefully()) {
+ this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
+ this.peerId = RouterIds.createPeerId(session.getBgpId());
+ this.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.peerRibOutIId = peerIId.child(AdjRibOut.class);
+ 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.stream()
+ .filter(table -> table.getAfiFlags() != null)
+ .filter(table -> table.getAfiFlags().isForwardingState())
+ .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.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 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp
+ .capabilities.ll.graceful.restart.capability.Tables table : advertisedLLTables) {
+ 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) {
+ addBgp4Support();
+ 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());