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.GroupModInputMessageFactoryTest.java

License:Open Source License

/**
 * @throws Exception//from w w w  . j  a  v  a 2s.  c  o  m
 * Testing of {@link GroupModInputMessageFactory} for correct translation from POJO
 */
@Test
public void testGroupModInputMessage() throws Exception {
    GroupModInputBuilder builder = new GroupModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setCommand(GroupModCommand.forValue(2));
    builder.setType(GroupType.forValue(3));
    builder.setGroupId(new GroupId(256L));
    List<BucketsList> exp = createBucketsList();
    builder.setBucketsList(exp);
    GroupModInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort());
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte());
    out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE);
    Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt());
    List<BucketsList> rec = createBucketsListFromBufer(out);
    Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray());
}

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

License:Open Source License

/**
 * Testing of {@link HelloInputMessageFactory} for correct translation from POJO
 * @throws Exception //www  .j av  a 2  s  .c o  m
 */
@Test
public void testWithoutElementsSet() throws Exception {
    HelloInputBuilder hib = new HelloInputBuilder();
    BufferHelper.setupHeader(hib, EncodeConstants.OF13_VERSION_ID);
    HelloInput hi = hib.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();
    himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);

    BufferHelper.checkHeaderV13(out, himf.getMessageType(), himf.computeLength(hi));
}

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

License:Open Source License

/**
 * Testing of {@link HelloInputMessageFactory} for correct translation from POJO
 * @throws Exception //  www  . j  a  v a 2 s .c o m
 */
@Test
public void testWith4BitVersionBitmap() throws Exception {
    int lengthOfBitmap = 4;
    HelloInputBuilder builder = new HelloInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    List<Elements> expectedElement = createElement(lengthOfBitmap);
    builder.setElements(expectedElement);
    HelloInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
    LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out));

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Elements element = readElement(out).get(0);
    Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
    Elements comparation = createComparationElement(lengthOfBitmap).get(0);
    Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(),
            element.getVersionBitmap().toArray());
}

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

License:Open Source License

/**
 * Testing of {@link HelloInputMessageFactory} for correct translation from POJO
 * @throws Exception /*from  w w  w .ja v  a2 s.  c om*/
 */
@Test
public void testWith64BitVersionBitmap() throws Exception {
    int lengthOfBitmap = 64;
    HelloInputBuilder builder = new HelloInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    List<Elements> expectedElement = createElement(lengthOfBitmap);
    builder.setElements(expectedElement);
    HelloInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
    LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out));

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Elements element = readElement(out).get(0);
    Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
    Elements comparation = createComparationElement(lengthOfBitmap).get(0);
    Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(),
            element.getVersionBitmap().toArray());
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    HelloMessageBuilder builder = new HelloMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    HelloMessage message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 8);
}

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

License:Open Source License

/**
 * @throws Exception /*from  www  . j av a2 s . c o m*/
 * Testing of {@link MeterModInputMessageFactory} for correct translation from POJO
 */
@Test
public void testMeterModInputMessage() throws Exception {
    MeterModInputBuilder builder = new MeterModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setCommand(MeterModCommand.forValue(1));
    builder.setFlags(new MeterFlags(false, true, true, false));
    builder.setMeterId(new MeterId(2248L));
    builder.setBands(createBandsList());
    MeterModInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), 64);
    Assert.assertEquals("Wrong meterModCommand", message.getCommand().getIntValue(), out.readUnsignedShort());
    Assert.assertEquals("Wrong meterFlags", message.getFlags(), decodeMeterModFlags(out.readShort()));
    Assert.assertEquals("Wrong meterId", message.getMeterId().getValue().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong bands", message.getBands(), decodeBandsList(out));
}

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

License:Open Source License

/**
 * Testing OF10StatsRequestInputFactory (Experimenter) for correct serialization
 * @throws Exception//  www.ja va 2  s.  c  om
 */
@Test
public void testExperimenter() throws Exception {
    Mockito.when(mockRegistry
            .getSerializer(Matchers.<ExperimenterIdTypeSerializerKey<ExperimenterDataOfChoice>>any()))
            .thenReturn(serializer);
    MultipartRequestInputFactory multipartFactory = new MultipartRequestInputFactory();
    multipartFactory.injectSerializerRegistry(mockRegistry);
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPEXPERIMENTER);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder();
    MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder();
    expBuilder.setExperimenter(new ExperimenterId(42L));
    expBuilder.setExpType(21L);
    expBuilder.setExperimenterDataOfChoice(vendorData);
    caseBuilder.setMultipartRequestExperimenter(expBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 24);
    Assert.assertEquals("Wrong type", 65535, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    Mockito.verify(serializer, Mockito.times(1)).serialize(vendorData, out);
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - GroupDesc case
 * @throws Exception//from   w ww .ja v a 2  s .  com
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPGROUPDESC);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestGroupDescCaseBuilder caseBuilder = new MultipartRequestGroupDescCaseBuilder();
    MultipartRequestGroupDescBuilder descBuilder = new MultipartRequestGroupDescBuilder();
    descBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestGroupDesc(descBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 7, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - GroupFeatures case
 * @throws Exception//from  w  w w . ja va 2  s. c o  m
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPGROUPFEATURES);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestGroupFeaturesCaseBuilder caseBuilder = new MultipartRequestGroupFeaturesCaseBuilder();
    MultipartRequestGroupFeaturesBuilder featuresBuilder = new MultipartRequestGroupFeaturesBuilder();
    featuresBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestGroupFeatures(featuresBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - MeterFeatures case
 * @throws Exception/*w w  w  . j  a v a  2  s . c  o  m*/
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPMETERFEATURES);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestMeterFeaturesCaseBuilder caseBuilder = new MultipartRequestMeterFeaturesCaseBuilder();
    MultipartRequestMeterFeaturesBuilder featuresBuilder = new MultipartRequestMeterFeaturesBuilder();
    featuresBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestMeterFeatures(featuresBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 11, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}