Search in sources :

Example 1 with BmpSessionListenerFactory

use of org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory in project bgpcep by opendaylight.

the class BmpMockTest method testMainInPassiveMode.

@Test
public void testMainInPassiveMode() throws Exception {
    final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
    final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
    // create a local server in passive mode instead
    BmpMock.main(new String[] { "--local_address", InetSocketAddressUtil.toHostAndPort(serverAddr).toString(), "--peers_count", "3", "--pre_policy_routes", "3", "--passive" });
    final ChannelFuture futureServer = this.bmpDispatcher.createClient(serverAddr, bmpSessionListenerFactory, KeyMapping.getKeyMapping());
    waitFutureSuccess(futureServer);
    final Channel serverChannel;
    final int sessionUpWait;
    if (futureServer.isSuccess()) {
        serverChannel = futureServer.channel();
        sessionUpWait = 10;
    } else {
        serverChannel = null;
        // wait longer for the reconnection attempt
        sessionUpWait = 40;
    }
    verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(sessionUpWait))).onSessionUp(Mockito.any(BmpSession.class));
    // 1 * Initiate message + 3 * PeerUp Notification + 9 * Route Monitoring message
    verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10)).times(13)).onMessage(Mockito.any(Notification.class));
    if (serverChannel != null) {
        serverChannel.close().sync();
    }
}
Also used : BmpSessionListenerFactory(org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory) ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) BmpSession(org.opendaylight.protocol.bmp.api.BmpSession) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Example 2 with BmpSessionListenerFactory

use of org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory in project bgpcep by opendaylight.

the class BmpMockTest method testMain.

@Test
public void testMain() throws Exception {
    final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
    final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
    final ChannelFuture futureServer = this.bmpDispatcher.createServer(serverAddr, bmpSessionListenerFactory, KeyMapping.getKeyMapping());
    waitFutureSuccess(futureServer);
    final Channel serverChannel;
    final int sessionUpWait;
    if (futureServer.isSuccess()) {
        serverChannel = futureServer.channel();
        sessionUpWait = 10;
    } else {
        serverChannel = null;
        // wait longer for the reconnection attempt
        sessionUpWait = 40;
    }
    BmpMock.main(new String[] { "--remote_address", InetSocketAddressUtil.toHostAndPort(serverAddr).toString(), "--peers_count", "3", "--pre_policy_routes", "3" });
    verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(sessionUpWait))).onSessionUp(Mockito.any(BmpSession.class));
    // 1 * Initiate message + 3 * PeerUp Notification + 9 * Route Monitoring message
    verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10)).times(13)).onMessage(Mockito.any(Notification.class));
    if (serverChannel != null) {
        serverChannel.close().sync();
    }
}
Also used : BmpSessionListenerFactory(org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory) ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) BmpSession(org.opendaylight.protocol.bmp.api.BmpSession) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Aggregations

Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 BmpSession (org.opendaylight.protocol.bmp.api.BmpSession)2 BmpSessionListenerFactory (org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory)2 Notification (org.opendaylight.yangtools.yang.binding.Notification)2