use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage in project bgpcep by opendaylight.
the class PCEPTestingToolTest method testSimpleSessionListener.
@Test
public void testSimpleSessionListener() {
final TestingSessionListener ssl = new TestingSessionListener();
assertEquals(0, ssl.messages().size());
ssl.onMessage(null, new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build());
assertEquals(1, ssl.messages().size());
assertTrue(ssl.messages().get(0) instanceof KeepaliveMessage);
assertFalse(ssl.isUp());
ssl.onSessionUp(null);
assertTrue(ssl.isUp());
ssl.onSessionDown(null, null);
assertFalse(ssl.isUp());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage in project bgpcep by opendaylight.
the class PCEPSessionImpl method handleMessage.
/**
* Handles incoming message. If the session is up, it notifies the user. The user is notified about every message
* except KeepAlive.
*
* @param msg incoming message
*/
public synchronized void handleMessage(final Message msg) {
if (this.closed.get()) {
LOG.debug("PCEP Session {} is already closed, skip handling incoming message {}", this, msg);
return;
}
// Update last reception time
this.lastMessageReceivedAt = TICKER.read();
this.sessionState.updateLastReceivedMsg();
if (!(msg instanceof KeepaliveMessage)) {
LOG.debug("PCEP message {} received.", msg);
}
// Internal message handling. The user does not see these messages
if (msg instanceof KeepaliveMessage) {
// Do nothing, the timer has been already reset
} else if (msg instanceof OpenMessage) {
this.sendErrorMessage(PCEPErrors.ATTEMPT_2ND_SESSION);
} else if (msg instanceof CloseMessage) {
/*
* Session is up, we are reporting all messages to user. One notable
* exception is CLOSE message, which needs to be converted into a
* session DOWN event.
*/
close();
this.listener.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.forValue(((CloseMessage) msg).getCCloseMessage().getCClose().getReason())));
} else {
// This message needs to be handled by the user
if (msg instanceof PcerrMessage) {
this.sessionState.setLastReceivedError(msg);
}
this.listener.onMessage(this, msg);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage in project bgpcep by opendaylight.
the class PCEPSessionImpl method sendMessage.
/**
* Sends message to serialization.
*
* @param msg to be sent
*/
@Override
public Future<Void> sendMessage(final Message msg) {
final ChannelFuture f = this.channel.writeAndFlush(msg);
this.lastMessageSentAt = TICKER.read();
this.sessionState.updateLastSentMsg();
if (!(msg instanceof KeepaliveMessage)) {
LOG.debug("PCEP Message enqueued: {}", msg);
}
if (msg instanceof PcerrMessage) {
this.sessionState.setLastSentError(msg);
}
f.addListener((ChannelFutureListener) arg -> {
if (arg.isSuccess()) {
LOG.trace("Message sent to socket: {}", msg);
} else {
LOG.debug("Message not sent: {}", msg, arg.cause());
}
});
return f;
}
Aggregations