Search in sources :

Example 1 with CodeKeyMaker

use of org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker in project openflowplugin by opendaylight.

the class MultipartRequestInputMessageFactory method createTableFeaturesProperties.

private List<TableFeatureProperties> createTableFeaturesProperties(ByteBuf input, int length) {
    List<TableFeatureProperties> properties = new ArrayList<>();
    int tableFeaturesLength = length;
    while (tableFeaturesLength > 0) {
        int propStartIndex = input.readerIndex();
        TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder();
        TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort());
        builder.setType(type);
        int propertyLength = input.readUnsignedShort();
        int paddingRemainder = propertyLength % EncodeConstants.PADDING;
        tableFeaturesLength -= propertyLength;
        if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS) || type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) {
            InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder();
            CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
            List<Instruction> instructions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry);
            insBuilder.setInstruction(instructions);
            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();
            CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
            List<Action> actions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry);
            actionBuilder.setAction(actions);
            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();
            CodeKeyMaker keyMaker = CodeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
            List<MatchEntry> entries = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry);
            oxmBuilder.setMatchEntry(entries);
            builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build());
        } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER) || type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
            long expId = input.readUnsignedInt();
            input.readerIndex(propStartIndex);
            OFDeserializer<TableFeatureProperties> propDeserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMultipartReplyTFDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId));
            TableFeatureProperties expProp = propDeserializer.deserialize(input);
            properties.add(expProp);
            continue;
        }
        if (paddingRemainder != 0) {
            input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
            tableFeaturesLength -= EncodeConstants.PADDING - paddingRemainder;
        }
        properties.add(builder.build());
    }
    return properties;
}
Also used : TableFeaturesPropType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) NextTableIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.table.features.properties.container.table.feature.properties.NextTableIdsBuilder) OxmRelatedTableFeatureProperty(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeatureProperty) TableFeatureProperties(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties) ArrayList(java.util.ArrayList) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) NextTableRelatedTableFeaturePropertyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeaturePropertyBuilder) NextTableRelatedTableFeatureProperty(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeatureProperty) InstructionRelatedTableFeaturePropertyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeaturePropertyBuilder) ActionRelatedTableFeaturePropertyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeaturePropertyBuilder) TableFeaturePropertiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) List(java.util.List) ArrayList(java.util.ArrayList) OxmRelatedTableFeaturePropertyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeaturePropertyBuilder)

Example 2 with CodeKeyMaker

use of org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker in project openflowplugin by opendaylight.

the class OF10FlowModInputMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowModInput deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    FlowModInputBuilder builder = new FlowModInputBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
    builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookie);
    builder.setCookie(new BigInteger(1, cookie));
    builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedShort()));
    builder.setIdleTimeout(rawMessage.readUnsignedShort());
    builder.setHardTimeout(rawMessage.readUnsignedShort());
    builder.setPriority(rawMessage.readUnsignedShort());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setOutPort(new PortNumber((long) rawMessage.readUnsignedShort()));
    builder.setFlagsV10(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort()));
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
    List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry);
    builder.setAction(actions);
    return builder.build();
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BigInteger(java.math.BigInteger) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) MatchV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with CodeKeyMaker

use of org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker in project openflowplugin by opendaylight.

the class PacketOutInputMessageFactory method deserialize.

@Override
public PacketOutInput deserialize(ByteBuf rawMessage) {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setInPort(new PortNumber(rawMessage.readUnsignedInt()));
    int actionsLen = rawMessage.readShort();
    rawMessage.skipBytes(PADDING);
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actionsLen, rawMessage, keyMaker, registry);
    builder.setAction(actions);
    byte[] data = new byte[rawMessage.readableBytes()];
    rawMessage.readBytes(data);
    builder.setData(data);
    return builder.build();
}
Also used : PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)

Example 4 with CodeKeyMaker

use of org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactory method setGroupDesc.

private MultipartReplyGroupDescCase setGroupDesc(final ByteBuf input) {
    MultipartReplyGroupDescCaseBuilder caseBuilder = new MultipartReplyGroupDescCaseBuilder();
    MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();
    List<GroupDesc> groupDescsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        GroupDescBuilder groupDescBuilder = new GroupDescBuilder();
        final 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();
            final int bucketsLength = input.readUnsignedShort();
            bucketsBuilder.setWeight(input.readUnsignedShort());
            bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt()));
            bucketsBuilder.setWatchGroup(input.readUnsignedInt());
            input.skipBytes(PADDING_IN_BUCKETS_HEADER);
            CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
            List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, bucketsLength - BUCKETS_HEADER_LENGTH, input, keyMaker, registry);
            bucketsBuilder.setAction(actions);
            bucketsList.add(bucketsBuilder.build());
            actualLength += bucketsLength;
        }
        groupDescBuilder.setBucketsList(bucketsList);
        groupDescsList.add(groupDescBuilder.build());
    }
    builder.setGroupDesc(groupDescsList);
    caseBuilder.setMultipartReplyGroupDesc(builder.build());
    return caseBuilder.build();
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) ArrayList(java.util.ArrayList) MultipartReplyGroupDescCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) GroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) MultipartReplyGroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder) GroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder) MultipartReplyGroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder)

Example 5 with CodeKeyMaker

use of org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactory method setFlow.

private MultipartReplyFlowCase setFlow(final 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);
        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));
        OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
        flowStatsBuilder.setMatch(matchDeserializer.deserialize(subInput));
        CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
        List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, subInput.readableBytes(), subInput, keyMaker, registry);
        flowStatsBuilder.setInstruction(instructions);
        flowStatsList.add(flowStatsBuilder.build());
    }
    flowBuilder.setFlowStats(flowStatsList);
    caseBuilder.setMultipartReplyFlow(flowBuilder.build());
    return caseBuilder.build();
}
Also used : ArrayList(java.util.ArrayList) MultipartReplyFlowCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match) FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) FlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BigInteger(java.math.BigInteger) MultipartReplyFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder)

Aggregations

CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)11 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)9 ArrayList (java.util.ArrayList)6 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)6 BigInteger (java.math.BigInteger)4 MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)4 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction)4 BucketsList (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 List (java.util.List)2 ActionRelatedTableFeaturePropertyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeaturePropertyBuilder)2 InstructionRelatedTableFeaturePropertyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeaturePropertyBuilder)2 NextTableRelatedTableFeatureProperty (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeatureProperty)2 NextTableRelatedTableFeaturePropertyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeaturePropertyBuilder)2 OxmRelatedTableFeatureProperty (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeatureProperty)2 OxmRelatedTableFeaturePropertyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeaturePropertyBuilder)2 NextTableIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.table.features.properties.container.table.feature.properties.NextTableIdsBuilder)2 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)2 TableFeaturesPropType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType)2 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)2