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.action.OF10SetVlanPcpActionDeserializer.java

License:Open Source License

@Override
public Action deserialize(ByteBuf input) {
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder builder = new ActionBuilder();
    input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    SetVlanPcpCaseBuilder caseBuilder = new SetVlanPcpCaseBuilder();
    SetVlanPcpActionBuilder actionBuilder = new SetVlanPcpActionBuilder();
    actionBuilder.setVlanPcp(input.readUnsignedByte());
    caseBuilder.setSetVlanPcpAction(actionBuilder.build());
    builder.setActionChoice(caseBuilder.build());
    input.skipBytes(ActionConstants.PADDING_IN_SET_VLAN_PCP_ACTION);
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13SetMplsTtlActionDeserializer.java

License:Open Source License

@Override
public Action deserialize(ByteBuf input) {
    ActionBuilder builder = new ActionBuilder();
    input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    SetMplsTtlCaseBuilder caseBuilder = new SetMplsTtlCaseBuilder();
    SetMplsTtlActionBuilder actionBuilder = new SetMplsTtlActionBuilder();
    actionBuilder.setMplsTtl(input.readUnsignedByte());
    caseBuilder.setSetMplsTtlAction(actionBuilder.build());
    builder.setActionChoice(caseBuilder.build());
    input.skipBytes(ActionConstants.SET_MPLS_TTL_PADDING);
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13SetNwTtlActionDeserializer.java

License:Open Source License

@Override
public Action deserialize(ByteBuf input) {
    ActionBuilder builder = new ActionBuilder();
    input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    SetNwTtlCaseBuilder caseBuilder = new SetNwTtlCaseBuilder();
    SetNwTtlActionBuilder actionBuilder = new SetNwTtlActionBuilder();
    actionBuilder.setNwTtl(input.readUnsignedByte());
    caseBuilder.setSetNwTtlAction(actionBuilder.build());
    builder.setActionChoice(caseBuilder.build());
    input.skipBytes(ActionConstants.SET_NW_TTL_PADDING);
    return builder.build();
}

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

License:Open Source License

/**
 * Transforms ByteBuf into correct POJO message
 * @param rawMessage //  ww w. ja v a 2  s .c  o m
 * @param version version decoded from OpenFlow protocol message
 * @return correct POJO as DataObject
 */
public static DataObject bufferToMessage(ByteBuf rawMessage, short version) {
    DataObject dataObject = null;
    short type = rawMessage.readUnsignedByte();
    rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);

    MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type);
    OFDeserializer<?> decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey);
    if (decoder != null) {
        dataObject = decoder.bufferToMessage(rawMessage, version);
    } else {
        LOGGER.warn("No correct decoder found in DecoderTable for arguments: " + msgTypeCodeKey.toString());
    }
    return dataObject;
}

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

License:Open Source License

@Override
public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {
    GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
    builder.setVersion(version);//ww w  .  jav a  2 s. c om
    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());
    builder.setAuxiliaryId(rawMessage.readUnsignedByte());
    rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);
    builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
    builder.setReserved(rawMessage.readUnsignedInt());
    return builder.build();
}

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

License:Open Source License

@Override
public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
    FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
    builder.setVersion(version);/*w w  w  . j a va  2 s  .c o m*/
    builder.setXid(rawMessage.readUnsignedInt());
    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()));
    builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
    builder.setDurationSec(rawMessage.readUnsignedInt());
    builder.setDurationNsec(rawMessage.readUnsignedInt());
    builder.setIdleTimeout(rawMessage.readUnsignedShort());
    builder.setHardTimeout(rawMessage.readUnsignedShort());
    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));
    builder.setMatch(MatchDeserializer.createMatch(rawMessage));
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory.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 flowRecordLength = input.readUnsignedShort();
        ByteBuf subInput = input.readSlice(flowRecordLength - EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        flowStatsBuilder.setTableId(subInput.readUnsignedByte());
        subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);
        flowStatsBuilder.setDurationSec(subInput.readUnsignedInt());
        flowStatsBuilder.setDurationNsec(subInput.readUnsignedInt());
        flowStatsBuilder.setPriority(subInput.readUnsignedShort());
        flowStatsBuilder.setIdleTimeout(subInput.readUnsignedShort());
        flowStatsBuilder.setHardTimeout(subInput.readUnsignedShort());
        flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(subInput.readUnsignedShort()));
        subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
        byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        subInput.readBytes(cookie);/*  ww  w  .ja  va2 s .c  o  m*/
        flowStatsBuilder.setCookie(new BigInteger(1, cookie));
        byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        subInput.readBytes(packetCount);
        flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
        byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        subInput.readBytes(byteCount);
        flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
        flowStatsBuilder.setMatch(MatchDeserializer.createMatch(subInput));
        flowStatsBuilder.setInstruction(
                InstructionsDeserializer.createInstructions(subInput, subInput.readableBytes()));
        flowStatsList.add(flowStatsBuilder.build());
    }
    flowBuilder.setFlowStats(flowStatsList);
    caseBuilder.setMultipartReplyFlow(flowBuilder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartReplyTableCase setTable(ByteBuf input) {
    MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();
    List<TableStats> tableStatsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();
        tableStatsBuilder.setTableId(input.readUnsignedByte());
        input.skipBytes(PADDING_IN_TABLE_HEADER);
        tableStatsBuilder.setActiveCount(input.readUnsignedInt());
        byte[] lookupCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(lookupCount);//from w  w w. j  av  a2s  .  c om
        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());
    }
    builder.setTableStats(tableStatsList);
    caseBuilder.setMultipartReplyTable(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static MultipartReplyTableFeaturesCase setTableFeatures(ByteBuf input) {
    MultipartReplyTableFeaturesCaseBuilder caseBuilder = new MultipartReplyTableFeaturesCaseBuilder();
    MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder();
    List<TableFeatures> features = new ArrayList<>();
    while (input.readableBytes() > 0) {
        TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder();
        int length = input.readUnsignedShort();
        featuresBuilder.setTableId(input.readUnsignedByte());
        input.skipBytes(PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES);
        featuresBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString());
        byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(metadataMatch);/*from  w w w .  jav  a2 s.co m*/
        featuresBuilder.setMetadataMatch(metadataMatch);
        byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(metadataWrite);
        featuresBuilder.setMetadataWrite(metadataWrite);
        featuresBuilder.setConfig(createTableConfig(input.readUnsignedInt()));
        featuresBuilder.setMaxEntries(input.readUnsignedInt());
        featuresBuilder.setTableFeatureProperties(
                createTableFeaturesProperties(input, length - MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH));
        features.add(featuresBuilder.build());
    }
    builder.setTableFeatures(features);
    caseBuilder.setMultipartReplyTableFeatures(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

private static List<TableFeatureProperties> createTableFeaturesProperties(ByteBuf input, int length) {
    List<TableFeatureProperties> properties = new ArrayList<>();
    int tableFeaturesLength = length;
    while (tableFeaturesLength > 0) {
        TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder();
        TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort());
        builder.setType(type);//from  w  w  w.j a v a 2  s. co m
        int propertyLength = input.readUnsignedShort();
        int paddingRemainder = propertyLength % EncodeConstants.PADDING;
        tableFeaturesLength -= propertyLength;
        if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)
                || type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) {
            InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder();
            insBuilder.setInstruction(InstructionsDeserializer.createInstructionIds(input,
                    propertyLength - COMMON_PROPERTY_LENGTH));
            builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build());
        } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)
                || type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) {
            propertyLength -= COMMON_PROPERTY_LENGTH;
            NextTableRelatedTableFeaturePropertyBuilder tableBuilder = new NextTableRelatedTableFeaturePropertyBuilder();
            List<NextTableIds> ids = new ArrayList<>();
            while (propertyLength > 0) {
                NextTableIdsBuilder nextTableIdsBuilder = new NextTableIdsBuilder();
                nextTableIdsBuilder.setTableId(input.readUnsignedByte());
                ids.add(nextTableIdsBuilder.build());
                propertyLength--;
            }
            tableBuilder.setNextTableIds(ids);
            builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, tableBuilder.build());
        } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS)
                || type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS)
                || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)
                || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) {
            ActionRelatedTableFeaturePropertyBuilder actionBuilder = new ActionRelatedTableFeaturePropertyBuilder();
            actionBuilder.setAction(
                    ActionsDeserializer.createActionIds(input, propertyLength - COMMON_PROPERTY_LENGTH));
            builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build());
        } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)
                || type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS)
                || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD)
                || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS)
                || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)
                || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) {
            OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder();
            oxmBuilder.setMatchEntries(
                    MatchDeserializer.createMatchIds(input, propertyLength - COMMON_PROPERTY_LENGTH));
            builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build());
        } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)
                || type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
            ExperimenterRelatedTableFeaturePropertyBuilder expBuilder = new ExperimenterRelatedTableFeaturePropertyBuilder();
            expBuilder.setExperimenter(input.readUnsignedInt());
            expBuilder.setExpType(input.readUnsignedInt());
            int dataLength = propertyLength - COMMON_PROPERTY_LENGTH - 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES;
            if (dataLength > 0) {
                byte[] data = new byte[dataLength];
                input.readBytes(data);
                expBuilder.setData(data);
            }
            builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expBuilder.build());
        }
        if (paddingRemainder != 0) {
            input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
            tableFeaturesLength -= EncodeConstants.PADDING - paddingRemainder;
        }
        properties.add(builder.build());
    }
    return properties;
}