use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.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.bgp.message.rev171207.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 synchronized 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.getShortValue()).build()).build()).build());
} else {
LOG.info("Closing PCEP session: {}", this);
}
closeChannel();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive in project bgpcep by opendaylight.
the class FSMTest method testBgpExtendedMessageCapability.
@Test
public void testBgpExtendedMessageCapability() {
this.clientSession.channelActive(null);
assertEquals(1, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(0) instanceof Open);
final List<BgpParameters> tlvs = Lists.newArrayList();
final List<OptionalCapabilities> capas = Lists.newArrayList();
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(30L)).build()).build()).build());
tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(1).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(tlvs).setBgpIdentifier(new Ipv4Address("1.1.1.2")).build());
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof Keepalive);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.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(keepAliveBMsg, ByteArray.getAllBytes(buffer));
final Notification not = this.registry.parseMessage(Unpooled.copiedBuffer(keepAliveBMsg), null);
assertTrue(not instanceof Keepalive);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.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.rev131007.Open)) {
return false;
}
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage o = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.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