Example usage for io.netty.buffer PooledByteBufAllocator DEFAULT

List of usage examples for io.netty.buffer PooledByteBufAllocator DEFAULT

Introduction

In this page you can find the example usage for io.netty.buffer PooledByteBufAllocator DEFAULT.

Prototype

PooledByteBufAllocator DEFAULT

To view the source code for io.netty.buffer PooledByteBufAllocator DEFAULT.

Click Source Link

Usage

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactoryTest.java

License:Open Source License

/**
 * Test serializer not found scenario/*from  w ww . ja  v  a  2s  .  com*/
 */
@Test(expected = IllegalStateException.class)
public void testNotExistingSerializer() {
    SerializerRegistry registry = new SerializerRegistryImpl();
    registry.init();
    SerializationFactory factory = new SerializationFactory();
    factory.setSerializerTable(registry);
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    HelloInputBuilder helloBuilder = new HelloInputBuilder();
    helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    helloBuilder.setXid(123456L);
    helloBuilder.setElements(null);
    factory.messageToBuffer((short) 0, buffer, helloBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ListDeserializerTest.java

License:Open Source License

/**
 * Tests {@link ListDeserializer#deserializeList(short, int, ByteBuf, CodeKeyMaker, DeserializerRegistry)}
 */// w w  w. j a v  a  2s  .  c o m
@Test
public void test() {
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    List<DataObject> list = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, 42, buffer,
            keyMaker, registry);

    Assert.assertNull("List is not null", list);
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ListDeserializerTest.java

License:Open Source License

/**
 * Tests {@link ListDeserializer#deserializeHeaders(short, int, ByteBuf, CodeKeyMaker, DeserializerRegistry)}
 *//*from  w  w w  . j  av a2s  .  co m*/
@Test
public void test2() {
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    List<DataObject> list = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, 42, buffer,
            keyMaker, registry);

    Assert.assertNull("List is not null", list);
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ListSerializerTest.java

License:Open Source License

/**
 * Tests {@link ListSerializer#serializeHeaderList(List, TypeKeyMaker, SerializerRegistry, ByteBuf)}
 * with null List/* w ww  .j a v a  2s  .c om*/
 */
@Test
public void test() {
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    ListSerializer.serializeHeaderList(null, keyMaker, registry, buffer);

    Assert.assertEquals("Data written to buffer", 0, buffer.readableBytes());
}

From source file:org.opendaylight.openflowjava.util.ByteBufUtilsTest.java

License:Open Source License

/**
 * Buffer padding test//  w  w  w  . j  a  v  a2  s . c  om
 */
@Test
public void testPadBuffer() {
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
    ByteBufUtils.padBuffer(4, buf);
    Assert.assertEquals("Wrong padding", 0, buf.readUnsignedInt());
    ByteBufUtils.padBuffer(0, buf);
    Assert.assertTrue("Wrong padding", buf.readableBytes() == 0);
}

From source file:org.opendaylight.openflowjava.util.ByteBufUtilsTest.java

License:Open Source License

/**
 * Write OF header test//w  w w. j  a v  a 2  s .com
 */
@Test
public void testWriteHeader() {
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
    HelloInputBuilder helloBuilder = new HelloInputBuilder();
    helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    helloBuilder.setXid(12345L);
    helloBuilder.setElements(null);
    HelloInput helloInput = helloBuilder.build();
    ByteBufUtils.writeOFHeader((byte) 0, helloInput, buf, EncodeConstants.OFHEADER_SIZE);
    Assert.assertEquals("Wrong version", EncodeConstants.OF13_VERSION_ID, buf.readUnsignedByte());
    Assert.assertEquals("Wrong type", 0, buf.readUnsignedByte());
    Assert.assertEquals("Wrong length", EncodeConstants.OFHEADER_SIZE, buf.readUnsignedShort());
    Assert.assertEquals("Wrong xid", 12345, buf.readUnsignedInt());
    Assert.assertTrue("Unexpected data", buf.readableBytes() == 0);
}

From source file:org.opendaylight.openflowjava.util.ByteBufUtilsTest.java

License:Open Source License

/**
 * Test ipv4 address conversion//w w  w  .jav  a 2 s.c om
 */
@Test(expected = IndexOutOfBoundsException.class)
public void testReadIpv4Address() {
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeByte(10);
    buffer.writeByte(20);
    buffer.writeByte(30);
    buffer.writeByte(40);
    String ipv4Address = ByteBufUtils.readIpv4Address(buffer);
    Assert.assertEquals("Wrong conversion", "10.20.30.40", ipv4Address);
    Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0);

    ByteBuf buffer2 = PooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeByte(10);
    ipv4Address = ByteBufUtils.readIpv4Address(buffer2);
}

From source file:org.opendaylight.openflowjava.util.ByteBufUtilsTest.java

License:Open Source License

/**
 * Test ipv6 address conversion//from  ww w  .ja v a  2 s  .  c om
 */
@Test(expected = IndexOutOfBoundsException.class)
public void testReadIpv6Address() {
    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeShort(10);
    buffer.writeShort(65535);
    buffer.writeShort(4096);
    buffer.writeShort(0);
    buffer.writeShort(1024);
    buffer.writeShort(42);
    buffer.writeShort(2568);
    buffer.writeShort(45689);
    String ipv4Address = ByteBufUtils.readIpv6Address(buffer);
    Assert.assertEquals("Wrong conversion", "000A:FFFF:1000:0000:0400:002A:0A08:B279", ipv4Address);
    Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0);

    ByteBuf buffer2 = PooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeShort(10);
    ipv4Address = ByteBufUtils.readIpv6Address(buffer2);
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java

License:Open Source License

public static ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer,
        final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {/*from  w  w w.j  a  v a 2  s .c o m*/
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);

    serverBootstrap.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE));
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);

    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);

    if (serverBootstrap.group() == null) {
        serverBootstrap.group(bossGroup, workerGroup);
    }
    return serverBootstrap;
}

From source file:org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl.java

License:Open Source License

@Override
public ChannelFuture createServer(final InetSocketAddress address, final BmpSessionListenerFactory slf,
        final Optional<KeyMapping> keys) {
    Preconditions.checkNotNull(address);
    Preconditions.checkNotNull(slf);/*  w ww  .  j  av a  2s.  c  om*/

    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(final Channel ch) throws Exception {
            ch.pipeline().addLast(BmpDispatcherImpl.this.hf.getDecoders());
            ch.pipeline().addLast(BmpDispatcherImpl.this.sessionFactory.getSession(ch, slf));
        }
    });

    b.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
    } else {
        b.channel(NioServerSocketChannel.class);
    }

    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    b.group(this.bossGroup, this.workerGroup);
    final ChannelFuture f = b.bind(address);

    LOG.debug("Initiated BMP server {} at {}.", f, address);
    return f;
}