Search in sources :

Example 6 with KeepaliveBuilder

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

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

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

the class PCEPParserTest method testMessageToByteEncoding.

@Test
public void testMessageToByteEncoding() {
    PCEPMessageToByteEncoder encoder = new PCEPMessageToByteEncoder(this.registry);
    ByteBuf out = Unpooled.buffer();
    encoder.encode(null, new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build(), out);
    assertArrayEquals(new byte[] { 32, 2, 0, 4 }, ByteArray.readAllBytes(out));
}
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) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 9 with KeepaliveBuilder

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

the class AbstractPCEPSessionTest method setUp.

@SuppressWarnings("unchecked")
@Before
public final void setUp() {
    MockitoAnnotations.initMocks(this);
    final ChannelFuture cfuture = new DefaultChannelPromise(this.channel);
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        AbstractPCEPSessionTest.this.msgsSend.add((Notification) args[0]);
        return cfuture;
    }).when(this.channel).writeAndFlush(any(Notification.class));
    doReturn(this.channelFuture).when(this.channel).closeFuture();
    doReturn(this.channelFuture).when(this.channelFuture).addListener(any(GenericFutureListener.class));
    doReturn("TestingChannel").when(this.channel).toString();
    doReturn(this.pipeline).when(this.channel).pipeline();
    doReturn(this.address).when(this.channel).localAddress();
    doReturn(this.address).when(this.channel).remoteAddress();
    doReturn(this.eventLoop).when(this.channel).eventLoop();
    doReturn(true).when(this.future).cancel(false);
    doReturn(this.future).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
    doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
    doReturn(this.pipeline).when(this.pipeline).addFirst(any(ChannelHandler.class));
    doReturn(true).when(this.channel).isActive();
    doReturn(mock(ChannelFuture.class)).when(this.channel).close();
    doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).remoteAddress();
    doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).localAddress();
    this.openMsg = new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder().setDeadTimer(DEADTIMER).setKeepalive(KEEP_ALIVE).setSessionId(Uint8.ZERO).build()).build()).build();
    this.kaMsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
    this.startTlsMsg = new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build();
    this.closeMsg = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(Uint8.valueOf(6)).build()).build()).build();
    this.listener = new SimpleSessionListener();
}
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) MockitoAnnotations(org.mockito.MockitoAnnotations) InetSocketAddress(java.net.InetSocketAddress) ChannelHandler(io.netty.channel.ChannelHandler) CCloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder) Notification(org.opendaylight.yangtools.yang.binding.Notification) OpenMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder) TimeUnit(java.util.concurrent.TimeUnit) 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) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) ChannelFuture(io.netty.channel.ChannelFuture) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder) StartTlsMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.start.tls.message.StartTlsMessageBuilder) StarttlsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.StarttlsBuilder) Mockito.doReturn(org.mockito.Mockito.doReturn) CCloseMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.message.CCloseMessageBuilder) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Before(org.junit.Before)

Example 10 with KeepaliveBuilder

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

the class BGPParserTest method testMessageToByteEncoding.

@Test
public void testMessageToByteEncoding() {
    final BGPMessageToByteEncoder encoder = new BGPMessageToByteEncoder(this.registry);
    final ByteBuf out = Unpooled.buffer();
    encoder.encode(null, new KeepaliveBuilder().build(), out);
    assertArrayEquals(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x13, 0x04 }, ByteArray.readAllBytes(out));
}
Also used : KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.KeepaliveBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 ByteBuf (io.netty.buffer.ByteBuf)6 KeepaliveBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.KeepaliveBuilder)6 KeepaliveBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder)5 KeepaliveMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.keepalive.message.KeepaliveMessageBuilder)4 Notification (org.opendaylight.yangtools.yang.binding.Notification)4 Mockito.doReturn (org.mockito.Mockito.doReturn)2 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)2 Keepalive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Keepalive)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandler (io.netty.channel.ChannelHandler)1 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1 InetSocketAddress (java.net.InetSocketAddress)1 Collections (java.util.Collections)1 TimeUnit (java.util.concurrent.TimeUnit)1 Before (org.junit.Before)1 MockitoAnnotations (org.mockito.MockitoAnnotations)1 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)1 BGPSessionListener (org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)1