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.netide.openflowjava.protocol.impl.serialization.factories.OF10PacketInMessageFactoryTest.java

License:Open Source License

@Test
public void testSerialize() {
    OF10PacketInMessageFactory serializer = new OF10PacketInMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 34);
    Assert.assertEquals("Wrong buffer id", message.getBufferId().longValue(),
            serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong total len", message.getTotalLen().intValue(),
            serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong port in", message.getInPort().intValue(), serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);//w w w.  j  a  v  a  2 s  .com
    Assert.assertArrayEquals("Wrong data", message.getData(),
            serializedBuffer.readBytes(serializedBuffer.readableBytes()).array());
}

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

License:Open Source License

@Test
public void testSerialize() {
    OF10PortStatusMessageFactory serializer = new OF10PortStatusMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 64);
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(7);//  w  w w  .j av  a  2 s. c  o  m
    Assert.assertEquals("Wrong port No", message.getPortNo().intValue(), serializedBuffer.readShort());
    byte[] address = new byte[6];
    serializedBuffer.readBytes(address);
    Assert.assertEquals("Wrong MacAddress", message.getHwAddr().getValue().toLowerCase(),
            new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
    byte[] name = new byte[16];
    serializedBuffer.readBytes(name);
    Assert.assertEquals("Wrong name", message.getName(), new String(name).trim());
    Assert.assertEquals("Wrong config", message.getConfigV10(), createPortConfig(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong state", message.getStateV10(), createPortState(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong current", message.getCurrentFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong advertised", message.getAdvertisedFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong supported", message.getSupportedFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong peer", message.getPeerFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
}

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

License:Open Source License

@Override
public void serialize(GetQueueConfigOutput message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeShort(message.getPort().getValue().intValue());
    outBuffer.writeZero(PADDING);/*  w ww  .j av  a  2  s . co  m*/
    for (Queues queue : message.getQueues()) {
        ByteBuf queueBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        queueBuff.writeInt(queue.getQueueId().getValue().intValue());
        queueBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        queueBuff.writeZero(QUEUE_PADDING);
        for (QueueProperty queueProperty : queue.getQueueProperty()) {
            ByteBuf queuePropertyBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
            queuePropertyBuff.writeShort(queueProperty.getProperty().getIntValue());
            queuePropertyBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
            queuePropertyBuff.writeZero(4);
            if (queueProperty.getProperty() == QueueProperties.OFPQTMINRATE) {
                RateQueueProperty body = queueProperty.getAugmentation(RateQueueProperty.class);
                queuePropertyBuff.writeShort(body.getRate().intValue());
                queuePropertyBuff.writeZero(QUEUE_PROPERTY_PADDING);
            }
            queuePropertyBuff.setShort(QUEUE_PROPERTY_LENGTH_INDEX, queuePropertyBuff.readableBytes());
            queueBuff.writeBytes(queuePropertyBuff);
        }
        queueBuff.setShort(QUEUE_LENGTH_INDEX, queueBuff.readableBytes());
        outBuffer.writeBytes(queueBuff);
    }

    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

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

License:Open Source License

@Test
public void testSerialize() {
    OF10QueueGetConfigReplyMessageFactory serializer = new OF10QueueGetConfigReplyMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 40);
    Assert.assertEquals("Wrong port", message.getPort().getValue().longValue(), serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);/*  w ww  .  j a  v a  2  s .com*/
    Assert.assertEquals("Wrong queue Id", message.getQueues().get(0).getQueueId().getValue().longValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong length", 24, serializedBuffer.readShort());
    serializedBuffer.skipBytes(2);
    List<QueueProperty> properties = message.getQueues().get(0).getQueueProperty();
    Assert.assertEquals("Wrong property", properties.get(0).getProperty().getIntValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong property length", 16, serializedBuffer.readShort());
    serializedBuffer.skipBytes(4);
    RateQueueProperty rateQueueProperty = properties.get(0).getAugmentation(RateQueueProperty.class);
    Assert.assertEquals("Wrong rate", rateQueueProperty.getRate().intValue(), serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);
}

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

License:Open Source License

private void serializeQueueBody(MultipartReplyBody body, ByteBuf outBuffer) {
    MultipartReplyQueueCase queueCase = (MultipartReplyQueueCase) body;
    MultipartReplyQueue queue = queueCase.getMultipartReplyQueue();
    for (QueueStats queueStats : queue.getQueueStats()) {
        ByteBuf queueStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        queueStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        queueStatsBuff.writeZero(QUEUE_PADDING);
        queueStatsBuff.writeInt(queueStats.getQueueId().intValue());
        queueStatsBuff.writeLong(queueStats.getTxBytes().longValue());
        queueStatsBuff.writeLong(queueStats.getTxPackets().longValue());
        queueStatsBuff.writeLong(queueStats.getTxErrors().longValue());
        queueStatsBuff.setShort(QUEUE_STATS_LENGTH_INDEX, queueStatsBuff.readableBytes());
        outBuffer.writeBytes(queueStatsBuff);
    }//w  ww  .  j a  va2s  .  c  o m
}

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

License:Open Source License

private void serializeFlowBody(MultipartReplyBody body, ByteBuf outBuffer, MultipartReplyMessage message) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    for (FlowStats flowStats : flow.getFlowStats()) {
        ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        flowStatsBuff.writeByte(new Long(flowStats.getTableId()).byteValue());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
        OFSerializer<MatchV10> matchSerializer = registry
                .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class));
        matchSerializer.serialize(flowStats.getMatchV10(), flowStatsBuff);
        flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
        flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
        flowStatsBuff.writeShort(flowStats.getPriority());
        flowStatsBuff.writeShort(flowStats.getIdleTimeout());
        flowStatsBuff.writeShort(flowStats.getHardTimeout());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
        flowStatsBuff.writeLong(flowStats.getCookie().longValue());
        flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
        flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
        ListSerializer.serializeList(flowStats.getAction(), ACTION_KEY_MAKER, registry, flowStatsBuff);
        flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
        outBuffer.writeBytes(flowStatsBuff);
    }/*from w w  w  .  j a  v  a 2 s.  c om*/
}

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

License:Open Source License

@Test
public void testDescBodySerialize() {
    builder.setType(MultipartType.forValue(0));
    MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder();
    MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder();
    desc.setMfrDesc("Test");
    desc.setHwDesc("Test");
    desc.setSwDesc("Test");
    desc.setSerialNum("12345");
    desc.setDpDesc("Test");
    descCase.setMultipartReplyDesc(desc.build());
    builder.setMultipartReplyBody(descCase.build());
    message = builder.build();/*from  w  w w.j  a v a 2s .c o m*/
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 1068);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPDESC.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong desc body", message.getMultipartReplyBody(), decodeDescBody(serializedBuffer));
}

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

License:Open Source License

@Test
public void testFlowBodySerialize() {
    builder.setType(MultipartType.forValue(1));
    MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder();
    MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder();
    flow.setFlowStats(createFlowStats());
    flowCase.setMultipartReplyFlow(flow.build());
    builder.setMultipartReplyBody(flowCase.build());
    message = builder.build();//from w  w  w .  j  av  a 2  s  . co  m
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 108);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    FlowStats flowStats = flow.getFlowStats().get(0);
    Assert.assertEquals("Wrong length", 96, serializedBuffer.readShort());
    Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(),
            serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort());
    byte[] dlSrc = new byte[6];
    serializedBuffer.readBytes(dlSrc);
    Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
    byte[] dlDst = new byte[6];
    serializedBuffer.readBytes(dlDst);
    Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
    Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(2);
    Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(),
            serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong port", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong maxlength", 50, serializedBuffer.readUnsignedShort());
}

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

License:Open Source License

@Test
public void testAggregateBodySerialize() {
    builder.setType(MultipartType.forValue(2));
    MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder();
    MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder();
    aggregate.setPacketCount(BigInteger.valueOf(1234L));
    aggregate.setByteCount(BigInteger.valueOf(1234L));
    aggregate.setFlowCount(1L);//from ww w.  j a v  a  2s  .  c om
    aggregateCase.setMultipartReplyAggregate(aggregate.build());
    builder.setMultipartReplyBody(aggregateCase.build());
    message = builder.build();
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 36);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong Packet count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong flow count", 1L, serializedBuffer.readInt());
    serializedBuffer.skipBytes(4);
}

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

License:Open Source License

@Test
public void testTableBodySerialize() {
    builder.setType(MultipartType.forValue(3));
    MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder table = new MultipartReplyTableBuilder();
    table.setTableStats(createTableStats());
    tableCase.setMultipartReplyTable(table.build());
    builder.setMultipartReplyBody(tableCase.build());
    message = builder.build();//from   ww w  . j av a 2s  .c o  m
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 60);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong table id", 1, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertEquals("Wrong name", "Table name",
            ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 16));
    Assert.assertEquals("Wrong wildcards", 3145983, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong max entries", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong active count", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong lookup count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong matched count", 1234L, serializedBuffer.readLong());
}