Search in sources :

Example 1 with KeepaliveMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.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);
    }
}
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 2 with KeepaliveMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.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());
}
Also used : KeepaliveMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.keepalive.message.KeepaliveMessageBuilder) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder) KeepaliveMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.KeepaliveMessage) Test(org.junit.Test)

Example 3 with KeepaliveMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.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;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) KeepaliveMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.keepalive.message.KeepaliveMessageBuilder) CCloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder) Date(java.util.Date) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive) OpenMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OpenMessage) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KeepaliveMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.KeepaliveMessage) PcerrMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) InetAddress(java.net.InetAddress) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors) Objects.requireNonNull(java.util.Objects.requireNonNull) ChannelFutureListener(io.netty.channel.ChannelFutureListener) LinkedList(java.util.LinkedList) PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) PCEPSessionListener(org.opendaylight.protocol.pcep.PCEPSessionListener) CCloseMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.message.CCloseMessageBuilder) TerminationReason(org.opendaylight.protocol.pcep.TerminationReason) Messages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.Messages) CloseMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.CloseMessage) Tlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.Tlvs) Logger(org.slf4j.Logger) MoreObjects(com.google.common.base.MoreObjects) LocalPref(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.LocalPref) IOException(java.io.IOException) Ticker(com.google.common.base.Ticker) InetSocketAddress(java.net.InetSocketAddress) CloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.CloseBuilder) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Util(org.opendaylight.protocol.pcep.impl.spi.Util) PCEPSession(org.opendaylight.protocol.pcep.PCEPSession) GuardedBy(org.checkerframework.checker.lock.qual.GuardedBy) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Queue(java.util.Queue) Future(io.netty.util.concurrent.Future) PeerPref(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.PeerPref) PcerrMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage) KeepaliveMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.KeepaliveMessage)

Aggregations

KeepaliveMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.KeepaliveMessage)3 PCEPCloseTermination (org.opendaylight.protocol.pcep.PCEPCloseTermination)2 KeepaliveBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder)2 CloseMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.CloseMessage)2 OpenMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OpenMessage)2 PcerrMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage)2 KeepaliveMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.keepalive.message.KeepaliveMessageBuilder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects (com.google.common.base.MoreObjects)1 ToStringHelper (com.google.common.base.MoreObjects.ToStringHelper)1 Ticker (com.google.common.base.Ticker)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 Future (io.netty.util.concurrent.Future)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1