use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.
the class BGPSessionImplTest method testHandleOpenMsg.
@Test
public void testHandleOpenMsg() throws BGPDocumentedException {
this.bgpSession.handleMessage(this.classicOpen);
Assert.assertEquals(State.IDLE, this.bgpSession.getState());
Assert.assertEquals(1, this.receivedMsgs.size());
Assert.assertTrue(this.receivedMsgs.get(0) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(0);
Assert.assertEquals(BGPError.FSM_ERROR.getCode(), error.getErrorCode().shortValue());
Assert.assertEquals(BGPError.FSM_ERROR.getSubcode(), error.getErrorSubcode().shortValue());
Mockito.verify(this.speakerListener).close();
}
use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.
the class FSMTest method sendNotification.
@Test
public void sendNotification() {
this.clientSession.channelActive(null);
this.clientSession.handleMessage(this.classicOpen);
this.clientSession.handleMessage(new KeepaliveBuilder().build());
assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.FINISHED);
this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).build());
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Notify);
final Notification m = this.receivedMsgs.get(2);
assertEquals(BGPError.FSM_ERROR.getCode(), ((Notify) m).getErrorCode().shortValue());
assertEquals(BGPError.FSM_ERROR.getSubcode(), ((Notify) m).getErrorSubcode().shortValue());
}
use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.
the class BGPSessionImpl method handleMessage.
/**
* Handles incoming message based on their type.
*
* @param msg incoming message
*/
synchronized void handleMessage(final Notification msg) {
if (this.state == State.IDLE) {
return;
}
try {
// Update last reception time
this.lastMessageReceivedAt = System.nanoTime();
if (msg instanceof Open) {
// Open messages should not be present here
this.terminate(new BGPDocumentedException(null, BGPError.FSM_ERROR));
} else if (msg instanceof Notify) {
final Notify notify = (Notify) msg;
// Notifications are handled internally
LOG.info("Session closed because Notification message received: {} / {}, data={}", notify.getErrorCode(), notify.getErrorSubcode(), notify.getData() != null ? ByteBufUtil.hexDump(notify.getData()) : null);
notifyTerminationReasonAndCloseWithoutMessage(notify.getErrorCode(), notify.getErrorSubcode());
} else if (msg instanceof Keepalive) {
// Keepalives are handled internally
LOG.trace("Received KeepAlive message.");
this.kaCounter++;
if (this.kaCounter >= 2) {
this.sync.kaReceived();
}
} else if (msg instanceof RouteRefresh) {
this.listener.onMessage(this, msg);
} else if (msg instanceof Update) {
this.listener.onMessage(this, msg);
this.sync.updReceived((Update) msg);
} else {
LOG.warn("Ignoring unhandled message: {}.", msg.getClass());
}
this.sessionState.messageReceived(msg);
} catch (final BGPDocumentedException e) {
this.terminate(e);
}
}
use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.
the class ParserTest method testNotificationMsg.
@Test
public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(notMsg, bytes);
assertArrayEquals(notificationBMsg, ByteArray.subByte(bytes.array(), 0, bytes.writerIndex()));
Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
assertTrue(m instanceof Notify);
assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
assertArrayEquals(new byte[] { 4, 9 }, ((Notify) m).getData());
notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
bytes.clear();
ParserTest.reg.serializeMessage(notMsg, bytes);
m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
assertTrue(m instanceof Notify);
assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
assertNull(((Notify) m).getData());
}
use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.
the class AbstractBGPSessionNegotiator method handleMessage.
protected synchronized void handleMessage(final Notification msg) {
LOG.debug("Channel {} handling message in state {}, msg: {}", this.channel, this.state, msg);
switch(this.state) {
case FINISHED:
sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
return;
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(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);
return;
}
break;
default:
break;
}
// Catch-all for unexpected message
LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
negotiationFailed(new BGPDocumentedException("Unexpected message channel: " + this.channel + ", state: " + this.state + ", message: " + msg, BGPError.FSM_ERROR));
this.state = State.FINISHED;
}
Aggregations