Example usage for io.netty.buffer UnpooledByteBufAllocator DEFAULT

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

Introduction

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

Prototype

UnpooledByteBufAllocator DEFAULT

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

Click Source Link

Document

Default instance which uses leak-detection for direct buffers.

Usage

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

License:Open Source License

/**
 * Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO
 * @throws Exception /*from  w ww . jav  a2 s  . c o m*/
 */
@Test
public void testGetAsyncReques() throws Exception {
    GetAsyncInputBuilder builder = new GetAsyncInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    GetAsyncInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    GetAsyncRequestMessageFactory factory = GetAsyncRequestMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);

    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPacketInMask(createPacketInMask());
    builder.setPortStatusMask(createPortStatusMask());
    builder.setFlowRemovedMask(createFlowRemowedMask());
    GetAsyncOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 32);
    Assert.assertEquals("Wrong packetInMask", 7, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong packetInMask", 0, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong portStatusMask", 7, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong portStatusMask", 0, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong flowRemovedMask", 15, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong flowRemovedMask", 0, serializedBuffer.readUnsignedInt());
}

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

License:Open Source License

@Test
public void testSetAsyncInputWithNullMasks() throws Exception {
    GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPacketInMask(null);/*from  w  ww. j  av a  2s.c om*/
    builder.setPortStatusMask(null);
    builder.setFlowRemovedMask(null);
    GetAsyncOutput message = builder.build();
    GetAsyncReplyMessageFactory serializer = new GetAsyncReplyMessageFactory();
    SerializerRegistry registry = new SerializerRegistryImpl();
    registry.init();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 8);
    Assert.assertTrue("Unexpected data", serializedBuffer.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO
 * @throws Exception //from   w w w. j a va 2  s .  c  om
 */
@Test
public void testV13() throws Exception {
    GetConfigInputBuilder gcib = new GetConfigInputBuilder();
    BufferHelper.setupHeader(gcib, EncodeConstants.OF13_VERSION_ID);
    GetConfigInput gci = gcib.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance();
    gcimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gci);

    BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
}

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

License:Open Source License

/**
 * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO
 * @throws Exception /*  w  ww. j av a 2s  .c  o m*/
 */
@Test
public void testV10() throws Exception {
    GetConfigInputBuilder gcib = new GetConfigInputBuilder();
    BufferHelper.setupHeader(gcib, EncodeConstants.OF10_VERSION_ID);
    GetConfigInput gci = gcib.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance();
    gcimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gci);

    BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    GetConfigOutputBuilder builder = new GetConfigOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(SwitchConfigFlag.forValue(2));
    builder.setMissSendLen(20);//ww  w  .j  a  v a  2 s  . c o  m
    GetConfigOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);

    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 12);
    Assert.assertEquals("Wrong Type", message.getFlags().getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong Code", message.getMissSendLen().intValue(), serializedBuffer.readShort());
}

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

License:Open Source License

/**
 * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO
 * @throws Exception //from  w w w . j  a v a 2 s  .  co  m
 */
@Test
public void testV13() throws Exception {
    GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder();
    BufferHelper.setupHeader(gfib, EncodeConstants.OF13_VERSION_ID);
    GetFeaturesInput gfi = gfib.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance();
    gfimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gfi);

    BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8);
}

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

License:Open Source License

/**
 * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO
 * @throws Exception //  w w  w  . ja va2s. co m
 */
@Test
public void testV10() throws Exception {
    GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder();
    BufferHelper.setupHeader(gfib, EncodeConstants.OF10_VERSION_ID);
    GetFeaturesInput gfi = gfib.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance();
    gfimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gfi);

    BufferHelper.checkHeaderV10(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setDatapathId(BigInteger.valueOf(1234L));
    builder.setBuffers(1234L);/*from   ww  w.  ja  v a  2  s . c o  m*/
    builder.setTables((short) 12);
    builder.setAuxiliaryId((short) 12);
    builder.setCapabilities(new Capabilities(true, false, true, false, true, false, true));
    builder.setReserved(1234L);
    GetFeaturesOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);

    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 32);
    Assert.assertEquals("Wrong DatapathId", message.getDatapathId().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong Buffer ID", message.getBuffers().longValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong auxiliary ID", message.getAuxiliaryId().shortValue(),
            serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(PADDING);
    Assert.assertEquals("Wrong Capabilities", message.getCapabilities(),
            createCapabilities(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong reserved", message.getReserved().longValue(), serializedBuffer.readInt());
}

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

License:Open Source License

/**
 * Testing of {@link GetQueueConfigInputMessageFactory} for correct translation from POJO
 * @throws Exception /*from  www. j a v  a2  s .  c om*/
 */
@Test
public void testGetQueueConfigInputMessage() throws Exception {
    GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPort(new PortNumber(0x00010203L));
    GetQueueConfigInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    GetQueueConfigInputMessageFactory factory = GetQueueConfigInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);

    BufferHelper.checkHeaderV13(out, GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE, 16);
    Assert.assertEquals("Wrong port", 0x00010203, out.readUnsignedInt());
    out.skipBytes(PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE);
}