use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive 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.message.rev181109.Keepalive in project bgpcep by opendaylight.
the class PCEPSessionImpl method close.
/**
* Closes PCEP session, cancels all timers, returns to state Idle, sends the Close Message. KeepAlive and DeadTimer
* are cancelled if the state of the session changes to IDLE. This method is used to close the PCEP session from
* inside the session or from the listener, therefore the parent of this session should be informed.
*/
@Override
public void close(final TerminationReason reason) {
if (this.closed.getAndSet(true)) {
LOG.debug("Session is already closed.");
return;
}
// only send close message when the reason is provided
if (reason != null) {
LOG.info("Closing PCEP session with reason {}: {}", reason, this);
sendMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getUintValue()).build()).build()).build());
} else {
LOG.info("Closing PCEP session: {}", this);
}
closeChannel();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive in project bgpcep by opendaylight.
the class AbstractMessageRegistryTest method testRegistry.
@Test
public void testRegistry() throws BGPDocumentedException, BGPParsingException {
final Notification keepAlive = new KeepaliveBuilder().build();
final ByteBuf buffer = Unpooled.buffer();
this.registry.serializeMessage(keepAlive, buffer);
assertArrayEquals(KEEPALIVE_BMSG, ByteArray.getAllBytes(buffer));
final Notification not = this.registry.parseMessage(Unpooled.copiedBuffer(KEEPALIVE_BMSG), null);
assertThat(not, instanceOf(Keepalive.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive in project bgpcep by opendaylight.
the class FiniteStateMachineTest method testSessionCharsAccMe.
/**
* Mock PCE does not accept session characteristics the first time.
*/
@Test
public void testSessionCharsAccMe() {
this.serverSession.channelActive(null);
assertEquals(1, this.msgsSend.size());
assertTrue(this.msgsSend.get(0) instanceof Open);
final Open remote = (Open) this.msgsSend.get(0);
this.serverSession.handleMessage(this.openMsg);
assertEquals(2, this.msgsSend.size());
assertTrue(this.msgsSend.get(1) instanceof Keepalive);
this.serverSession.handleMessage(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, remote.getOpenMessage().getOpen()));
assertEquals(3, this.msgsSend.size());
assertTrue(this.msgsSend.get(2) instanceof Open);
this.serverSession.handleMessage(this.kaMsg);
assertEquals(this.serverSession.getState(), DefaultPCEPSessionNegotiator.State.FINISHED);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive in project bgpcep by opendaylight.
the class AbstractPCEPSessionNegotiator method handleMessageOpenWait.
private boolean handleMessageOpenWait(final Message msg) {
if (!(msg instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open)) {
return false;
}
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessage o = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open) msg).getOpenMessage();
final Open open = o.getOpen();
if (isProposalAcceptable(open)) {
this.sendMessage(KEEPALIVE);
this.remotePrefs = open;
this.remoteOK = true;
if (this.localOK) {
negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
LOG.info("PCEP peer {} completed negotiation", this.channel);
this.state = State.FINISHED;
} else {
scheduleFailTimer();
this.state = State.KEEP_WAIT;
LOG.debug("Channel {} moved to KeepWait state with remoteOK=1", this.channel);
}
return true;
}
if (this.openRetry) {
sendErrorMessage(PCEPErrors.SECOND_OPEN_MSG);
negotiationFailed(new IllegalStateException("OPEN renegotiation failed"));
this.state = State.FINISHED;
return true;
}
final Open newPrefs = getCounterProposal(open);
if (newPrefs == null) {
sendErrorMessage(PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR);
negotiationFailed(new IllegalStateException("Peer sent unacceptable session parameters"));
this.state = State.FINISHED;
return true;
}
this.sendMessage(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, newPrefs));
this.openRetry = true;
this.state = this.localOK ? State.OPEN_WAIT : State.KEEP_WAIT;
scheduleFailTimer();
return true;
}
Aggregations