BUG-54 : switched channel pipeline to be protocol specific.
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionNegotiator.java
index 970729429af9fce8ac06aac8faa39c16b03f02d4..718a0d4b8fbaf722e4cb94f6180ab19632b94004 100644 (file)
@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
 
 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;
 
@@ -39,13 +39,12 @@ final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, B
                 */
                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,
                /**
@@ -62,7 +61,7 @@ final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, B
        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);
@@ -72,18 +71,18 @@ final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, B
 
        @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;
                                        }
                                }
                        }
@@ -92,25 +91,25 @@ final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, B
 
        @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;
                        }
 
@@ -121,19 +120,19 @@ final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, B
 
                                // 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;
        }
 }