import com.google.common.base.Preconditions;
-final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, BGPSessionImpl> {
+public final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, BGPSessionImpl> {
// 4 minutes recommended in http://tools.ietf.org/html/rfc4271#section-8.2.2
private static final int INITIAL_HOLDTIMER = 4;
*/
Idle,
/**
- * We have sent our Open message, and are waiting for the peer's Open
- * message.
+ * We have sent our Open message, and are waiting for the peer's Open message.
*/
OpenSent,
/**
- * We have received the peer's Open message, which is acceptable, and
- * we're waiting the acknowledgement of our Open message.
+ * We have received the peer's Open message, which is acceptable, and we're waiting the acknowledgement of our
+ * Open message.
*/
OpenConfirm,
/**
private State state = State.Idle;
private final short keepAlive = 15;
- BGPSessionNegotiator(final Timer timer, final Promise<BGPSessionImpl> promise, final Channel channel,
+ public BGPSessionNegotiator(final Timer timer, final Promise<BGPSessionImpl> promise, final Channel channel,
final BGPSessionPreferences initialPrefs, final BGPSessionListener listener) {
super(promise, channel);
this.listener = Preconditions.checkNotNull(listener);
@Override
protected void startNegotiation() {
- Preconditions.checkState(state == State.Idle);
- channel.writeAndFlush(new BGPOpenMessage(localPref.getMyAs(), (short) localPref.getHoldTime(), localPref.getBgpId(), localPref.getParams()));
- state = State.OpenSent;
+ Preconditions.checkState(this.state == State.Idle);
+ this.channel.writeAndFlush(new BGPOpenMessage(this.localPref.getMyAs(), (short) this.localPref.getHoldTime(), this.localPref.getBgpId(), this.localPref.getParams()));
+ this.state = State.OpenSent;
final Object lock = this;
- timer.newTimeout(new TimerTask() {
+ this.timer.newTimeout(new TimerTask() {
@Override
public void run(final Timeout timeout) throws Exception {
synchronized (lock) {
- if (state != State.Finished) {
+ if (BGPSessionNegotiator.this.state != State.Finished) {
negotiationFailed(new BGPDocumentedException("HoldTimer expired", BGPError.FSM_ERROR));
- state = State.Finished;
+ BGPSessionNegotiator.this.state = State.Finished;
}
}
}
@Override
protected synchronized void handleMessage(final BGPMessage msg) {
- logger.debug("Channel {} handling message in state {}", channel, state);
+ logger.debug("Channel {} handling message in state {}", this.channel, this.state);
- switch (state) {
+ switch (this.state) {
case Finished:
case Idle:
- throw new IllegalStateException("Unexpected state " + state);
+ throw new IllegalStateException("Unexpected state " + this.state);
case OpenConfirm:
if (msg instanceof BGPKeepAliveMessage) {
final BGPKeepAliveMessage ka = (BGPKeepAliveMessage) msg;
// FIXME: we miss some stuff over here
- negotiationSuccessful(new BGPSessionImpl(timer, listener, channel, keepAlive, remotePref));
- state = State.Finished;
+ negotiationSuccessful(new BGPSessionImpl(this.timer, this.listener, this.channel, this.keepAlive, this.remotePref));
+ this.state = State.Finished;
return;
} else if (msg instanceof BGPNotificationMessage) {
final BGPNotificationMessage ntf = (BGPNotificationMessage) msg;
negotiationFailed(new BGPDocumentedException("Peer refusal", ntf.getError()));
- state = State.Finished;
+ this.state = State.Finished;
return;
}
// TODO: validate the open message
- remotePref = open;
- channel.writeAndFlush(new BGPKeepAliveMessage());
- state = State.OpenConfirm;
- logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", channel, remotePref);
+ this.remotePref = open;
+ this.channel.writeAndFlush(new BGPKeepAliveMessage());
+ this.state = State.OpenConfirm;
+ logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
return;
}
break;
}
// Catch-all for unexpected message
- logger.warn("Channel {} state {} unexpected message {}", channel, state, msg);
- channel.writeAndFlush(new BGPNotificationMessage(BGPError.FSM_ERROR));
+ logger.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
+ this.channel.writeAndFlush(new BGPNotificationMessage(BGPError.FSM_ERROR));
negotiationFailed(new BGPDocumentedException("Unexpected message", BGPError.FSM_ERROR));
- state = State.Finished;
+ this.state = State.Finished;
}
}