Search in sources :

Example 6 with Keepalive

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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);
    }
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) OpenMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OpenMessage) PcerrMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage) CloseMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.CloseMessage) KeepaliveMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.KeepaliveMessage)

Example 7 with Keepalive

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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();
}
Also used : CCloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder) CloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.CloseBuilder) CCloseMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.message.CCloseMessageBuilder) CCloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder)

Example 8 with Keepalive

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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));
}
Also used : Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Keepalive) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.KeepaliveBuilder) ByteBuf(io.netty.buffer.ByteBuf) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Example 9 with Keepalive

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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);
}
Also used : Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open) Test(org.junit.Test)

Example 10 with Keepalive

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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;
}
Also used : Preconditions(com.google.common.base.Preconditions) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open)

Aggregations

Keepalive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Keepalive)6 Test (org.junit.Test)4 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)4 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)3 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 KeepaliveBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.KeepaliveBuilder)2 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify)2 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)2 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)2 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open)2 Notification (org.opendaylight.yangtools.yang.binding.Notification)2 Preconditions (com.google.common.base.Preconditions)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)1 BGPTerminationReason (org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason)1 PCEPCloseTermination (org.opendaylight.protocol.pcep.PCEPCloseTermination)1 UnknownObject (org.opendaylight.protocol.pcep.spi.UnknownObject)1