Example usage for io.netty.buffer ByteBuf readUnsignedShort

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

Introduction

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

Prototype

public abstract int readUnsignedShort();

Source Link

Document

Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

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

License:Open Source License

private static MultipartReplyMeterCase setMeter(ByteBuf input) {
    MultipartReplyMeterCaseBuilder caseBuilder = new MultipartReplyMeterCaseBuilder();
    MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder();
    List<MeterStats> meterStatsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
        meterStatsBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
        int meterStatsBodyLength = input.readUnsignedShort();
        input.skipBytes(PADDING_IN_METER_STATS_HEADER);
        meterStatsBuilder.setFlowCount(input.readUnsignedInt());
        byte[] packetInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(packetInCount);//from ww w.j a v  a  2  s  .  c om
        meterStatsBuilder.setPacketInCount(new BigInteger(1, packetInCount));
        byte[] byteInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(byteInCount);
        meterStatsBuilder.setByteInCount(new BigInteger(1, byteInCount));
        meterStatsBuilder.setDurationSec(input.readUnsignedInt());
        meterStatsBuilder.setDurationNsec(input.readUnsignedInt());
        int actualLength = METER_BODY_LENGTH;
        List<MeterBandStats> meterBandStatsList = new ArrayList<>();
        while (actualLength < meterStatsBodyLength) {
            MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
            byte[] packetBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
            input.readBytes(packetBandCount);
            meterBandStatsBuilder.setPacketBandCount(new BigInteger(1, packetBandCount));
            byte[] byteBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
            input.readBytes(byteBandCount);
            meterBandStatsBuilder.setByteBandCount(new BigInteger(1, byteBandCount));
            meterBandStatsList.add(meterBandStatsBuilder.build());
            actualLength += METER_BAND_STATS_LENGTH;
        }
        meterStatsBuilder.setMeterBandStats(meterBandStatsList);
        meterStatsList.add(meterStatsBuilder.build());
    }
    builder.setMeterStats(meterStatsList);
    caseBuilder.setMultipartReplyMeter(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;
            }/*from   w w  w .j  a  v a2 s . com*/
            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;
        }/*from ww  w . ja  v a2s.co  m*/
        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.OF10ErrorMessageFactory.java

License:Open Source License

@Override
public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) {
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion(version);//from  w  w w . j  a va 2s. co  m
    builder.setXid(rawMessage.readUnsignedInt());
    int type = rawMessage.readUnsignedShort();
    ErrorTypeV10 errorType = ErrorTypeV10.forValue(type);
    decodeType(builder, errorType, type);
    decodeCode(rawMessage, builder, errorType);
    if (rawMessage.readableBytes() > 0) {
        builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());
    }
    return builder.build();
}

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

License:Open Source License

private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder, ErrorTypeV10 type) {
    int code = rawMessage.readUnsignedShort();
    if (type != null) {
        switch (type) {
        case HELLOFAILED: {
            HelloFailedCodeV10 errorCode = HelloFailedCodeV10.forValue(code);
            if (errorCode != null) {
                setCode(builder, errorCode.getIntValue(), errorCode.name());
            } else {
                setUnknownCode(builder, code);
            }/* w w w  . java2 s .  co  m*/
            break;
        }
        case BADREQUEST: {
            BadRequestCodeV10 errorCode = BadRequestCodeV10.forValue(code);
            if (errorCode != null) {
                setCode(builder, errorCode.getIntValue(), errorCode.name());
            } else {
                setUnknownCode(builder, code);
            }
            break;
        }
        case BADACTION: {
            BadActionCodeV10 errorCode = BadActionCodeV10.forValue(code);
            if (errorCode != null) {
                setCode(builder, errorCode.getIntValue(), errorCode.name());
            } else {
                setUnknownCode(builder, code);
            }
            break;
        }
        case FLOWMODFAILED: {
            FlowModFailedCodeV10 errorCode = FlowModFailedCodeV10.forValue(code);
            if (errorCode != null) {
                setCode(builder, errorCode.getIntValue(), errorCode.name());
            } else {
                setUnknownCode(builder, code);
            }
            break;
        }
        case PORTMODFAILED: {
            PortModFailedCodeV10 errorCode = PortModFailedCodeV10.forValue(code);
            if (errorCode != null) {
                setCode(builder, errorCode.getIntValue(), errorCode.name());
            } else {
                setUnknownCode(builder, code);
            }
            break;
        }
        case QUEUEOPFAILED: {
            QueueOpFailedCodeV10 errorCode = QueueOpFailedCodeV10.forValue(code);
            if (errorCode != null) {
                setCode(builder, errorCode.getIntValue(), errorCode.name());
            } else {
                setUnknownCode(builder, code);
            }
            break;
        }
        default:
            setUnknownCode(builder, code);
            break;
        }
    } else {
        setUnknownCode(builder, code);
    }
}

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

License:Open Source License

private static PhyPort deserializePort(ByteBuf rawMessage) {
    PhyPortBuilder builder = new PhyPortBuilder();
    builder.setPortNo((long) rawMessage.readUnsignedShort());
    byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
    rawMessage.readBytes(address);//from w w w.  ja  va 2s  .c o  m
    builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address)));
    builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
    builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));
    builder.setStateV10(createPortState(rawMessage.readUnsignedInt()));
    builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
    builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
    builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
    builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));
    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);// w  ww  .  ja  v  a  2 s .  c o m
    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.OF10GetConfigReplyMessageFactory.java

License:Open Source License

@Override
public GetConfigOutput deserialize(ByteBuf rawMessage) {
    GetConfigOutputBuilder builder = new GetConfigOutputBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setFlags(SwitchConfigFlag.forValue(rawMessage.readUnsignedShort()));
    builder.setMissSendLen(rawMessage.readUnsignedShort());
    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);/*ww  w.  ja  va2  s  .co 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.OF10PacketOutInputMessageFactory.java

License:Open Source License

@Override
public PacketOutInput deserialize(ByteBuf rawMessage) {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setInPort(new PortNumber((long) rawMessage.readUnsignedShort()));
    int actions_len = rawMessage.readShort();
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
    List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, actions_len,
            rawMessage, keyMaker, registry);
    builder.setAction(actions);/*from  w  w w.j  a va  2s.  c  o  m*/

    byte[] data = new byte[rawMessage.readableBytes()];
    rawMessage.readBytes(data);

    if (data != null) {

        builder.setData(data);
    }
    return builder.build();
}