Search in sources :

Example 21 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.

the class PCEPSessionImplTest method testCloseSessionWithReason.

@Test
public void testCloseSessionWithReason() {
    this.session.close(TerminationReason.UNKNOWN);
    Assert.assertEquals(1, this.msgsSend.size());
    Assert.assertTrue(this.msgsSend.get(0) instanceof CloseMessage);
    final CloseMessage closeMsg = (CloseMessage) this.msgsSend.get(0);
    Assert.assertEquals(TerminationReason.UNKNOWN, TerminationReason.forValue(closeMsg.getCCloseMessage().getCClose().getReason()));
    Mockito.verify(this.channel, Mockito.times(1)).close();
}
Also used : CloseMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.CloseMessage) Test(org.junit.Test)

Example 22 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.

the class PCEPValidatorTest method testCloseMsg.

@Test
public void testCloseMsg() throws IOException, PCEPDeserializerException {
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin"));
    final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
    final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason(Uint8.valueOf(5)).setTlvs(new TlvsBuilder().build()).build()).build());
    assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(builder.build(), buf);
    assertArrayEquals(result.array(), buf.array());
    try {
        parser.serializeMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().build()).build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Close Object must be present in Close Message.", e.getMessage());
    }
}
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) PCEPCloseMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPCloseMessageParser) TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.c.close.TlvsBuilder) 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) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 23 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close 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 24 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close 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 25 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.

the class PCEPStatefulPeerProposalTest method setUp.

@Before
public void setUp() {
    tlvsBuilder = new TlvsBuilder().addAugmentation(new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(new Stateful1Builder().build()).build()).build());
    captor = ArgumentCaptor.forClass(DataTreeChangeListener.class);
    doReturn(listenerReg).when(dataBroker).registerDataTreeChangeListener(any(), captor.capture());
    doNothing().when(listenerReg).close();
}
Also used : DataTreeChangeListener(org.opendaylight.mdsal.binding.api.DataTreeChangeListener) TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder) StatefulBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.stateful.capability.tlv.StatefulBuilder) Tlvs1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Tlvs1Builder) Stateful1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.Stateful1Builder) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)25 InetSocketAddress (java.net.InetSocketAddress)11 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)9 Before (org.junit.Before)8 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)8 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)6 Optional (com.google.common.base.Optional)5 ChannelFuture (io.netty.channel.ChannelFuture)5 ChannelHandler (io.netty.channel.ChannelHandler)5 TimeUnit (java.util.concurrent.TimeUnit)5 Channel (io.netty.channel.Channel)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ExecutionException (java.util.concurrent.ExecutionException)4 MsgBuilderUtil.createLspTlvs (org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs)4 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)4 Notification (org.opendaylight.yangtools.yang.binding.Notification)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4