Example usage for io.netty.buffer ByteBuf readUnsignedByte

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

Introduction

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

Prototype

public abstract short readUnsignedByte();

Source Link

Document

Gets an unsigned byte at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private static MultipartReplyMeterFeaturesCase setMeterFeatures(ByteBuf input) {
    MultipartReplyMeterFeaturesCaseBuilder caseBuilder = new MultipartReplyMeterFeaturesCaseBuilder();
    MultipartReplyMeterFeaturesBuilder builder = new MultipartReplyMeterFeaturesBuilder();
    builder.setMaxMeter(input.readUnsignedInt());
    builder.setBandTypes(createMeterBandsBitmap(input.readUnsignedInt()));
    builder.setCapabilities(createMeterFlags(input.readUnsignedInt()));
    builder.setMaxBands(input.readUnsignedByte());
    builder.setMaxColor(input.readUnsignedByte());
    input.skipBytes(PADDING_IN_METER_FEATURES_HEADER);
    caseBuilder.setMultipartReplyMeterFeatures(builder.build());
    return caseBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private static MultipartReplyMeterConfigCase setMeterConfig(ByteBuf input) {
    MultipartReplyMeterConfigCaseBuilder caseBuilder = new MultipartReplyMeterConfigCaseBuilder();
    MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();
    List<MeterConfig> meterConfigList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder();
        int meterConfigBodyLength = input.readUnsignedShort();
        meterConfigBuilder.setFlags(createMeterFlags(input.readUnsignedShort()));
        meterConfigBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
        int actualLength = METER_CONFIG_LENGTH;
        List<Bands> bandsList = new ArrayList<>();
        while (actualLength < meterConfigBodyLength) {
            BandsBuilder bandsBuilder = new BandsBuilder();
            int bandType = input.readUnsignedShort();
            switch (bandType) {
            case 1:
                MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
                MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
                bandDropBuilder.setType(MeterBandType.forValue(bandType));
                actualLength += input.readUnsignedShort();
                bandDropBuilder.setRate(input.readUnsignedInt());
                bandDropBuilder.setBurstSize(input.readUnsignedInt());
                input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
                bandDropCaseBuilder.setMeterBandDrop(bandDropBuilder.build());
                bandsBuilder.setMeterBand(bandDropCaseBuilder.build());
                break;
            case 2:
                MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
                MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
                bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));
                actualLength += input.readUnsignedShort();
                bandDscpRemarkBuilder.setRate(input.readUnsignedInt());
                bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt());
                bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte());
                input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
                bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build());
                bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build());
                break;
            case 0xFFFF:
                MeterBandExperimenterCaseBuilder bandExperimenterCaseBuilder = new MeterBandExperimenterCaseBuilder();
                MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder();
                bandExperimenterBuilder.setType(MeterBandType.forValue(bandType));
                actualLength += input.readUnsignedShort();
                bandExperimenterBuilder.setRate(input.readUnsignedInt());
                bandExperimenterBuilder.setBurstSize(input.readUnsignedInt());
                bandExperimenterBuilder.setExperimenter(input.readUnsignedInt());
                bandExperimenterCaseBuilder.setMeterBandExperimenter(bandExperimenterBuilder.build());
                bandsBuilder.setMeterBand(bandExperimenterCaseBuilder.build());
                break;
            default:
                break;
            }/*  w w  w .j a v  a 2 s.c  om*/
            bandsList.add(bandsBuilder.build());
        }
        meterConfigBuilder.setBands(bandsList);
        meterConfigList.add(meterConfigBuilder.build());
    }
    builder.setMeterConfig(meterConfigList);
    caseBuilder.setMultipartReplyMeterConfig(builder.build());
    return caseBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private static MultipartReplyGroupDescCase setGroupDesc(ByteBuf input) {
    MultipartReplyGroupDescCaseBuilder caseBuilder = new MultipartReplyGroupDescCaseBuilder();
    MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();
    List<GroupDesc> groupDescsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        GroupDescBuilder groupDescBuilder = new GroupDescBuilder();
        int bodyLength = input.readUnsignedShort();
        groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte()));
        input.skipBytes(PADDING_IN_GROUP_DESC_HEADER);
        groupDescBuilder.setGroupId(new GroupId(input.readUnsignedInt()));
        int actualLength = GROUP_DESC_HEADER_LENGTH;
        List<BucketsList> bucketsList = new ArrayList<>();
        while (actualLength < bodyLength) {
            BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
            int bucketsLength = input.readUnsignedShort();
            bucketsBuilder.setWeight(input.readUnsignedShort());
            bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt()));
            bucketsBuilder.setWatchGroup(input.readUnsignedInt());
            input.skipBytes(PADDING_IN_BUCKETS_HEADER);
            List<Action> actionsList = ActionsDeserializer.createActions(input,
                    bucketsLength - BUCKETS_HEADER_LENGTH);
            bucketsBuilder.setAction(actionsList);
            bucketsList.add(bucketsBuilder.build());
            actualLength += bucketsLength;
        }// ww w  . j  a  v a  2s  . c om
        groupDescBuilder.setBucketsList(bucketsList);
        groupDescsList.add(groupDescBuilder.build());
    }
    builder.setGroupDesc(groupDescsList);
    caseBuilder.setMultipartReplyGroupDesc(builder.build());
    return caseBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory.java

License:Open Source License

@Override
public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {
    GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
    builder.setVersion(version);//from   www .  j a va  2 s.c o m
    builder.setXid(rawMessage.readUnsignedInt());
    byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(datapathId);
    builder.setDatapathId(new BigInteger(1, datapathId));
    builder.setBuffers(rawMessage.readUnsignedInt());
    builder.setTables(rawMessage.readUnsignedByte());
    rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);
    builder.setCapabilitiesV10(createCapabilitiesV10(rawMessage.readUnsignedInt()));
    builder.setActionsV10(createActionsV10(rawMessage.readUnsignedInt()));
    List<PhyPort> ports = new ArrayList<>();
    while (rawMessage.readableBytes() > 0) {
        ports.add(deserializePort(rawMessage));
    }
    builder.setPhyPort(ports);
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory.java

License:Open Source License

@Override
public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
    FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
    builder.setVersion(version);//from   w  w w  .j  av a 2  s.com
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage));
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookie);
    builder.setCookie(new BigInteger(1, cookie));
    builder.setPriority(rawMessage.readUnsignedShort());
    builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
    rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
    builder.setDurationSec(rawMessage.readUnsignedInt());
    builder.setDurationNsec(rawMessage.readUnsignedInt());
    builder.setIdleTimeout(rawMessage.readUnsignedShort());
    rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
    byte[] packet_count = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(packet_count);
    builder.setPacketCount(new BigInteger(1, packet_count));
    byte[] byte_count = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(byte_count);
    builder.setByteCount(new BigInteger(1, byte_count));
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory.java

License:Open Source License

@Override
public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {
    PacketInMessageBuilder builder = new PacketInMessageBuilder();
    builder.setVersion(version);/* w  ww  . j  a va  2  s  .  c o m*/
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setTotalLen(rawMessage.readUnsignedShort());
    builder.setInPort(rawMessage.readUnsignedShort());
    builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
    rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        builder.setData(rawMessage.readBytes(remainingBytes).array());
    }
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory.java

License:Open Source License

@Override
public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) {
    PortStatusMessageBuilder builder = new PortStatusMessageBuilder();
    builder.setVersion(version);//ww  w  .  j a v  a2s  .c  o  m
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte()));
    rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
    deserializePort(rawMessage, builder);
    return builder.build();
}

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

License:Open Source License

private static MultipartReplyFlowCase setFlow(ByteBuf input) {
    MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
    MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
    List<FlowStats> flowStatsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
        int length = input.readUnsignedShort();
        flowStatsBuilder.setTableId(input.readUnsignedByte());
        input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);
        flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input));
        flowStatsBuilder.setDurationSec(input.readUnsignedInt());
        flowStatsBuilder.setDurationNsec(input.readUnsignedInt());
        flowStatsBuilder.setPriority(input.readUnsignedShort());
        flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());
        flowStatsBuilder.setHardTimeout(input.readUnsignedShort());
        input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
        byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(cookie);/*  w  w  w.j av  a2  s  . co  m*/
        flowStatsBuilder.setCookie(new BigInteger(1, cookie));
        byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(packetCount);
        flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
        byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(byteCount);
        flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
        flowStatsBuilder
                .setAction(OF10ActionsDeserializer.createActionsList(input, length - LENGTH_OF_FLOW_STATS));
        flowStatsList.add(flowStatsBuilder.build());
    }
    flowBuilder.setFlowStats(flowStatsList);
    caseBuilder.setMultipartReplyFlow(flowBuilder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartReplyTableCase setTable(ByteBuf input) {
    MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();
    List<TableStats> tableStatsList = new ArrayList<>();
    // TODO - replace ">= TABLE_STATS_LENGTH" with "> 0" after fix in OVS switch
    while (input.readableBytes() >= TABLE_STATS_LENGTH) {
        TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();
        tableStatsBuilder.setTableId(input.readUnsignedByte());
        input.skipBytes(PADDING_IN_TABLE_HEADER);
        tableStatsBuilder.setName(ByteBufUtils.decodeNullTerminatedString(input, MAX_TABLE_NAME_LENGTH));
        long wildcards = input.readUnsignedInt();
        tableStatsBuilder.setWildcards(OF10MatchDeserializer.createWildcards(wildcards));
        tableStatsBuilder.setNwSrcMask(OF10MatchDeserializer.decodeNwSrcMask(wildcards));
        tableStatsBuilder.setNwDstMask(OF10MatchDeserializer.decodeNwDstMask(wildcards));
        tableStatsBuilder.setMaxEntries(input.readUnsignedInt());
        tableStatsBuilder.setActiveCount(input.readUnsignedInt());
        byte[] lookupCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(lookupCount);/*ww w.  ja v  a 2 s . c  o  m*/
        tableStatsBuilder.setLookupCount(new BigInteger(1, lookupCount));
        byte[] matchedCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(matchedCount);
        tableStatsBuilder.setMatchedCount(new BigInteger(1, matchedCount));
        tableStatsList.add(tableStatsBuilder.build());
    }
    input.skipBytes(input.readableBytes());
    builder.setTableStats(tableStatsList);
    caseBuilder.setMultipartReplyTable(builder.build());
    return caseBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory.java

License:Open Source License

@Override
public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {
    PacketInMessageBuilder builder = new PacketInMessageBuilder();
    builder.setVersion(version);/*from ww  w  . j  a  v a2 s. c o m*/
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setTotalLen(rawMessage.readUnsignedShort());
    builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
    builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookie);
    builder.setCookie(new BigInteger(1, cookie));
    builder.setMatch(MatchDeserializer.createMatch(rawMessage));
    rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
    builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());
    return builder.build();
}