- }
- sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
- break;
- case OPEN_CONFIRM:
- if (msg instanceof Keepalive) {
- negotiationSuccessful(this.session);
- LOG.info("BGP Session with peer {} established successfully.", this.channel);
- } else if (msg instanceof Notify) {
- final Notify ntf = (Notify) msg;
- negotiationFailed(new BGPDocumentedException("Peer refusal", BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
- }
- this.state = State.FINISHED;
- return;
- case OPEN_SENT:
- if (msg instanceof Open) {
- handleOpen((Open) msg);
+ case IDLE:
+ // to avoid race condition when Open message was sent by the peer before startNegotiation could be
+ // executed
+ if (msg instanceof Open) {
+ startNegotiation();
+ handleOpen((Open) msg);
+ return;
+ }
+ sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
+ break;
+ case OPEN_CONFIRM:
+ if (msg instanceof Keepalive) {
+ negotiationSuccessful();
+ LOG.info("BGP Session with peer {} established successfully.", this.channel);
+ } else if (msg instanceof Notify) {
+ final Notify ntf = (Notify) msg;
+ negotiationFailed(new BGPDocumentedException("Peer refusal",
+ BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
+ }
+ this.state = State.FINISHED;