Merge "Fix junit dependencies in poms. Reuse existing from parent, add missing ones."
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionNegotiator.java
index c837d15a25b0f22a400b7f1d1f35d4d0bc88b369..e536ba54f7e18157fc43767ae62a982063c34681 100644 (file)
@@ -119,9 +119,9 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                switch (this.state) {
                case Finished:
                case Idle:
-                       final Notify fsm_error = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
+                       final Notify fsmError = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
                                        BGPError.FSM_ERROR.getSubcode()).build();
-                       this.channel.writeAndFlush(fsm_error);
+                       this.channel.writeAndFlush(fsmError);
                case OpenConfirm:
                        if (msg instanceof Keepalive) {
                                negotiationSuccessful(this.session);
@@ -134,30 +134,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                case OpenSent:
                        if (msg instanceof Open) {
                                final Open openObj = (Open) msg;
-
-                               final List<BgpParameters> prefs = openObj.getBgpParameters();
-                               if (prefs != null && !prefs.isEmpty()) {
-                                       for (final BgpParameters param : openObj.getBgpParameters()) {
-                                               final CParameters cap = param.getCParameters();
-                                               if (cap instanceof CMultiprotocol) {
-                                                       if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
-                                                                       && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
-                                                               this.remotePref = openObj;
-                                                               this.channel.writeAndFlush(new KeepaliveBuilder().build());
-                                                               this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
-                                                               this.state = State.OpenConfirm;
-                                                               logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
-                                                               return;
-                                                       }
-                                               }
-                                       }
-                               }
-                               final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
-                                               BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
-                               this.channel.writeAndFlush(ntf);
-                               negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
-                                               ntf.getErrorCode(), ntf.getErrorSubcode())));
-                               this.state = State.Finished;
+                               handleOpen(openObj);
                                return;
                        }
                        break;
@@ -171,6 +148,31 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                this.state = State.Finished;
        }
 
+       private void handleOpen(final Open openObj) {
+               final List<BgpParameters> prefs = openObj.getBgpParameters();
+               if (prefs != null && !prefs.isEmpty()) {
+                       for (final BgpParameters param : openObj.getBgpParameters()) {
+                               final CParameters cap = param.getCParameters();
+                               if (cap instanceof CMultiprotocol
+                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
+                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
+                                       this.remotePref = openObj;
+                                       this.channel.writeAndFlush(new KeepaliveBuilder().build());
+                                       this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
+                                       this.state = State.OpenConfirm;
+                                       logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
+                                       return;
+                               }
+                       }
+               }
+               final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
+                               BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
+               this.channel.writeAndFlush(ntf);
+               negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
+                               ntf.getErrorCode(), ntf.getErrorSubcode())));
+               this.state = State.Finished;
+       }
+
        public synchronized State getState() {
                return this.state;
        }