Example usage for io.netty.buffer ByteBuf readUnsignedInt

List of usage examples for io.netty.buffer ByteBuf readUnsignedInt

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readUnsignedInt.

Prototype

public abstract long readUnsignedInt();

Source Link

Document

Gets an unsigned 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

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

License:Open Source License

@Test
public void testPortDescSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(13));
    MultipartReplyPortDescCaseBuilder portDescCase = new MultipartReplyPortDescCaseBuilder();
    MultipartReplyPortDescBuilder portDesc = new MultipartReplyPortDescBuilder();
    portDesc.setPorts(createPortList());
    portDescCase.setMultipartReplyPortDesc(portDesc.build());
    builder.setMultipartReplyBody(portDescCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 80);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTDESC.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    MultipartReplyPortDescCase body = (MultipartReplyPortDescCase) message.getMultipartReplyBody();
    MultipartReplyPortDesc messageOutput = body.getMultipartReplyPortDesc();
    Ports port = messageOutput.getPorts().get(0);
    Assert.assertEquals("Wrong PortNo", port.getPortNo().intValue(), serializedBuffer.readUnsignedInt());
    serializedBuffer.skipBytes(4);/*from  www . j a v a2s  .  co m*/
    byte[] address = new byte[6];
    serializedBuffer.readBytes(address);
    Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(),
            new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
    serializedBuffer.skipBytes(2);
    byte[] name = new byte[16];
    serializedBuffer.readBytes(name);
    Assert.assertEquals("Wrong name", port.getName(), new String(name).trim());
    Assert.assertEquals("Wrong config", port.getConfig(), createPortConfig(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong state", port.getState(), createPortState(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong current", port.getCurrentFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong advertised", port.getAdvertisedFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong supported", port.getSupportedFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong peer", port.getPeerFeatures(), createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong Current speed", port.getCurrSpeed().longValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong Max speed", port.getMaxSpeed().longValue(), serializedBuffer.readInt());
}

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

License:Open Source License

@Test
public void testGroupDescSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(7));
    MultipartReplyGroupDescCaseBuilder groupCase = new MultipartReplyGroupDescCaseBuilder();
    MultipartReplyGroupDescBuilder group = new MultipartReplyGroupDescBuilder();
    group.setGroupDesc(createGroupDesc());
    groupCase.setMultipartReplyGroupDesc(group.build());
    builder.setMultipartReplyBody(groupCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 64);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUPDESC.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    MultipartReplyGroupDescCase body = (MultipartReplyGroupDescCase) message.getMultipartReplyBody();
    MultipartReplyGroupDesc messageOutput = body.getMultipartReplyGroupDesc();
    GroupDesc groupDesc = messageOutput.getGroupDesc().get(0);
    Assert.assertEquals("Wrong length", 48, serializedBuffer.readShort());
    Assert.assertEquals("Wrong type", groupDesc.getType().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);//w w w . j a v a  2s.  c  o  m
    Assert.assertEquals("Wrong group id", groupDesc.getGroupId().getValue().intValue(),
            serializedBuffer.readInt());
    BucketsList bucketList = groupDesc.getBucketsList().get(0);
    Assert.assertEquals("Wrong length", 40, serializedBuffer.readShort());
    Assert.assertEquals("Wrong weight", bucketList.getWeight().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong watch port", bucketList.getWatchPort().getValue().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong watch group", bucketList.getWatchGroup().intValue(), serializedBuffer.readInt());
    serializedBuffer.skipBytes(4);

    Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertTrue("Not all data were read", serializedBuffer.readableBytes() == 0);
}

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

License:Open Source License

@Test
public void testQueueSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(5));
    MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder();
    MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder();
    queue.setQueueStats(createQueueStats());
    queueCase.setMultipartReplyQueue(queue.build());
    builder.setMultipartReplyBody(queueCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 56);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody();
    MultipartReplyQueue messageOutput = body.getMultipartReplyQueue();
    QueueStats queueStats = messageOutput.getQueueStats().get(0);
    Assert.assertEquals("Wrong PortNo", queueStats.getPortNo().intValue(), serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(),
            serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong duration sec", queueStats.getDurationSec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", queueStats.getDurationNsec().intValue(),
            serializedBuffer.readInt());
}

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

License:Open Source License

private static List<Bands> decodeBandsList(ByteBuf input) {
    List<Bands> bandsList = new ArrayList<>();
    BandsBuilder bandsBuilder = new BandsBuilder();
    MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
    MeterBandDropBuilder dropBand = new MeterBandDropBuilder();
    dropBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
    input.skipBytes(Short.SIZE / Byte.SIZE);
    dropBand.setRate(input.readUnsignedInt());
    dropBand.setBurstSize(input.readUnsignedInt());
    dropCaseBuilder.setMeterBandDrop(dropBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dropCaseBuilder.build()).build());
    MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
    MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder();
    dscpRemarkBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
    input.skipBytes(Short.SIZE / Byte.SIZE);
    dscpRemarkBand.setRate(input.readUnsignedInt());
    dscpRemarkBand.setBurstSize(input.readUnsignedInt());
    dscpRemarkBand.setPrecLevel((short) 3);
    dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
    return bandsList;
}

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

License:Open Source License

private static MultipartRequestFlowCase decodeRequestFlow(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
    final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
    MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder();
    MultipartRequestFlowBuilder builder = new MultipartRequestFlowBuilder();
    builder.setTableId(output.readUnsignedByte());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01);
    builder.setOutPort(output.readUnsignedInt());
    builder.setOutGroup(output.readUnsignedInt());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02);
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookie);//from  ww w . ja v a 2  s  . c om
    builder.setCookie(new BigInteger(1, cookie));
    byte[] cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookieMask);
    builder.setCookieMask(new BigInteger(1, cookieMask));
    caseBuilder.setMultipartRequestFlow(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartRequestAggregateCase decodeRequestAggregate(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01 = 3;
    final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02 = 4;
    MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder();
    MultipartRequestAggregateBuilder builder = new MultipartRequestAggregateBuilder();
    builder.setTableId(output.readUnsignedByte());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01);
    builder.setOutPort(output.readUnsignedInt());
    builder.setOutGroup(output.readUnsignedInt());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02);
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookie);/*w w w  . ja  v a 2s  .  c  o m*/
    builder.setCookie(new BigInteger(1, cookie));
    byte[] cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookieMask);
    builder.setCookieMask(new BigInteger(1, cookieMask));
    caseBuilder.setMultipartRequestAggregate(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartRequestPortStatsCase decodeRequestPortStats(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4;
    MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
    MultipartRequestPortStatsBuilder builder = new MultipartRequestPortStatsBuilder();
    builder.setPortNo(output.readUnsignedInt());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY);
    caseBuilder.setMultipartRequestPortStats(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartRequestQueueCase decodeRequestQueue(ByteBuf output) {
    MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
    MultipartRequestQueueBuilder builder = new MultipartRequestQueueBuilder();
    builder.setPortNo(output.readUnsignedInt());
    builder.setQueueId(output.readUnsignedInt());
    caseBuilder.setMultipartRequestQueue(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartRequestGroupCase decodeRequestGroup(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4;
    MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
    MultipartRequestGroupBuilder builder = new MultipartRequestGroupBuilder();
    builder.setGroupId(new GroupId(output.readUnsignedInt()));
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY);
    caseBuilder.setMultipartRequestGroup(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartRequestMeterCase decodeRequestMeter(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4;
    MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
    MultipartRequestMeterBuilder builder = new MultipartRequestMeterBuilder();
    builder.setMeterId(new MeterId(output.readUnsignedInt()));
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_BODY);
    caseBuilder.setMultipartRequestMeter(builder.build());
    return caseBuilder.build();
}