});
@GuardedBy("this")
- private BGPSession session;
+ private BGPSession currentSession;
@GuardedBy("this")
private AdjRibInWriter ribWriter;
@GuardedBy("this")
private boolean sessionUp;
private boolean llgrSupport;
private Stopwatch peerRestartStopwatch;
- private long selectionDeferralTimerSeconds;
+ private long currentSelectionDeferralTimerSeconds;
private final List<TablesKey> missingEOT = new ArrayList<>();
public BGPPeer(
@Override
public synchronized void onSessionUp(final BGPSession session) {
- this.session = session;
+ this.currentSession = session;
this.sessionUp = true;
this.bindingChain = this.rib.createPeerChain(this);
- if (this.session instanceof BGPSessionStateProvider) {
- ((BGPSessionStateProvider) this.session).registerMessagesCounter(this);
+ if (this.currentSession instanceof BGPSessionStateProvider) {
+ ((BGPSessionStateProvider) this.currentSession).registerMessagesCounter(this);
}
final GracefulRestartCapability advertisedGracefulRestartCapability =
session.getAdvertisedGracefulRestartCapability();
// SpotBugs does not grok Optional.ifPresent() and thinks we are using unsynchronized access
final Optional<RevisedErrorHandlingSupport> errorHandling = this.bgpPeer.getErrorHandling();
if (errorHandling.isPresent()) {
- this.session.addDecoderConstraint(RevisedErrorHandlingSupport.class, errorHandling.get());
+ this.currentSession.addDecoderConstraint(RevisedErrorHandlingSupport.class, errorHandling.get());
}
}
final RIBSupport<?, ?, ?, ?> ribSupport = this.rib.getRibSupportContext().getRIBSupport(key);
// not particularly nice
- if (ribSupport != null && this.session instanceof BGPSessionImpl) {
- final ChannelOutputLimiter limiter = ((BGPSessionImpl) this.session).getLimiter();
+ if (ribSupport != null && this.currentSession instanceof BGPSessionImpl) {
+ final ChannelOutputLimiter limiter = ((BGPSessionImpl) this.currentSession).getLimiter();
final AdjRibOutListener adjRibOut = AdjRibOutListener.create(this.peerId, key,
this.rib.getYangRibId(), this.rib.getCodecsRegistry(), ribSupport,
this.rib.getService(), limiter, mpSupport);
}
@Override
- public synchronized void onSessionDown(final BGPSession session, final Exception e) {
- if (e.getMessage().equals(BGPSessionImpl.END_OF_INPUT)) {
+ public synchronized void onSessionDown(final BGPSession session, final Exception exc) {
+ if (exc.getMessage().equals(BGPSessionImpl.END_OF_INPUT)) {
LOG.info("Session with peer {} went down", this.name);
} else {
- LOG.info("Session with peer {} went down", this.name, e);
+ LOG.info("Session with peer {} went down", this.name, exc);
}
releaseConnectionGracefully();
}
}
releaseBindingChain();
- if (this.session != null) {
+ closeSession();
+ return future;
+ }
+
+ @GuardedBy("this")
+ @SuppressWarnings("checkstyle:illegalCatch")
+ private void closeSession() {
+ if (this.currentSession != null) {
try {
if (isRestartingGracefully()) {
- this.session.closeWithoutMessage();
+ this.currentSession.closeWithoutMessage();
} else {
- this.session.close();
+ this.currentSession.close();
}
} catch (final Exception e) {
LOG.warn("Error closing session with peer", e);
}
- this.session = null;
+ this.currentSession = null;
}
- return future;
}
private Set<TablesKey> getGracefulTables() {
final long elapsedNanos = this.peerRestartStopwatch.elapsed(TimeUnit.NANOSECONDS);
if (elapsedNanos >= peerRestartTimeNanos) {
setAfiSafiGracefulRestartState(0, false, false);
- onSessionTerminated(this.session, new BGPTerminationReason(BGPError.HOLD_TIMER_EXPIRED));
+ onSessionTerminated(this.currentSession, new BGPTerminationReason(BGPError.HOLD_TIMER_EXPIRED));
}
- this.session.schedule(this::handleRestartTimer, peerRestartTimeNanos - elapsedNanos, TimeUnit.NANOSECONDS);
+ currentSession.schedule(this::handleRestartTimer, peerRestartTimeNanos - elapsedNanos, TimeUnit.NANOSECONDS);
}
private synchronized void handleSelectionReferralTimer() {
return;
}
- final long referalTimerNanos = TimeUnit.SECONDS.toNanos(this.selectionDeferralTimerSeconds);
+ final long referalTimerNanos = TimeUnit.SECONDS.toNanos(this.currentSelectionDeferralTimerSeconds);
final long elapsedNanos = this.peerRestartStopwatch.elapsed(TimeUnit.NANOSECONDS);
if (elapsedNanos >= referalTimerNanos) {
this.missingEOT.clear();
handleGracefulEndOfRib();
}
- this.session.schedule(this::handleSelectionReferralTimer, referalTimerNanos - elapsedNanos,
+ currentSession.schedule(this::handleSelectionReferralTimer, referalTimerNanos - elapsedNanos,
TimeUnit.NANOSECONDS);
}
@Override
public synchronized BGPSessionState getBGPSessionState() {
- if (this.session instanceof BGPSessionStateProvider) {
- return ((BGPSessionStateProvider) this.session).getBGPSessionState();
+ if (this.currentSession instanceof BGPSessionStateProvider) {
+ return ((BGPSessionStateProvider) this.currentSession).getBGPSessionState();
}
return null;
}
@Override
public synchronized BGPTimersState getBGPTimersState() {
- if (this.session instanceof BGPSessionStateProvider) {
- return ((BGPSessionStateProvider) this.session).getBGPTimersState();
+ if (this.currentSession instanceof BGPSessionStateProvider) {
+ return ((BGPSessionStateProvider) this.currentSession).getBGPTimersState();
}
return null;
}
@Override
public synchronized BGPTransportState getBGPTransportState() {
- if (this.session instanceof BGPSessionStateProvider) {
- return ((BGPSessionStateProvider) this.session).getBGPTransportState();
+ if (this.currentSession instanceof BGPSessionStateProvider) {
+ return ((BGPSessionStateProvider) this.currentSession).getBGPTransportState();
}
return null;
}
"Peer is not capable of graceful restart"));
}
setGracefulPreferences(true, tablesToPreserve);
- this.selectionDeferralTimerSeconds = selectionDeferralTimerSeconds;
+ this.currentSelectionDeferralTimerSeconds = selectionDeferralTimerSeconds;
setLocalRestartingState(true);
return releaseConnection();
}