Search in sources :

Example 1 with BmpHandlerFactory

use of org.opendaylight.protocol.bmp.impl.BmpHandlerFactory in project bgpcep by opendaylight.

the class BmpMonitorImplTest method connectTestClient.

private static Channel connectTestClient(final String routerIp, final BmpMessageRegistry msgRegistry) throws InterruptedException {
    final BmpHandlerFactory hf = new BmpHandlerFactory(msgRegistry);
    final Bootstrap b = new Bootstrap();
    final EventLoopGroup workerGroup;
    if (Epoll.isAvailable()) {
        b.channel(EpollSocketChannel.class);
        workerGroup = new EpollEventLoopGroup();
    } else {
        b.channel(NioSocketChannel.class);
        workerGroup = new NioEventLoopGroup();
    }
    b.group(workerGroup);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(final SocketChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getDecoders());
            ch.pipeline().addLast(hf.getEncoders());
        }
    });
    b.localAddress(new InetSocketAddress(routerIp, 0));
    b.option(ChannelOption.SO_REUSEADDR, true);
    final ChannelFuture future = b.connect(new InetSocketAddress(MONITOR_LOCAL_ADDRESS, MONITOR_LOCAL_PORT)).sync();
    waitFutureSuccess(future);
    return future.channel();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) InetSocketAddress(java.net.InetSocketAddress) Bootstrap(io.netty.bootstrap.Bootstrap) BmpHandlerFactory(org.opendaylight.protocol.bmp.impl.BmpHandlerFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 InetSocketAddress (java.net.InetSocketAddress)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 BmpHandlerFactory (org.opendaylight.protocol.bmp.impl.BmpHandlerFactory)1