X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fserialization%2Ffactories%2FMultipartRequestInputFactory.java;h=29cc589818b8c057886730965299b348e7dc33c4;hb=60ad94454217d7d1f6f9e65f39f72ae111ecc845;hp=0fdeff1cdc19b5f4341964cb42ff1b3def8beea2;hpb=f9f2b07fad8b5ed6180445a9ff7997ecaffe8cf3;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java index 0fdeff1c..29cc5898 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java @@ -10,18 +10,21 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.keys.MatchEntrySerializerKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMaker; +import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory; +import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterMatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty; @@ -30,9 +33,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; @@ -68,12 +72,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas * @author michal.polkorab */ -public class MultipartRequestInputFactory implements OFSerializer { +public class MultipartRequestInputFactory implements OFSerializer, SerializerRegistryInjector { private static final byte MESSAGE_TYPE = 18; - private static final int MESSAGE_LENGTH = 16; private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; private static final byte TABLE_FEAT_HEADER_LENGTH = 4; - private static MultipartRequestInputFactory instance; private static final byte INSTRUCTIONS_CODE = 0; private static final byte INSTRUCTIONS_MISS_CODE = 1; private static final byte NEXT_TABLE_CODE = 2; @@ -88,17 +90,6 @@ public class MultipartRequestInputFactory implements OFSerializer tableFeatures = body.getTableFeatures(); - for (TableFeatures feature : tableFeatures) { - length += computeSingleTableFeatureLength(feature); - } + serializeExperimenterBody(message, outBuffer); } - return length; - } - - private static int computeSingleTableFeatureLength(TableFeatures feature) { - return TABLE_FEATURES_LENGTH + computeTableFeatPropsLength(feature); + ByteBufUtils.updateOFHeaderLength(outBuffer); } - private static int computeTableFeatPropsLength(TableFeatures feature) { - int length = 0; - List featureProperties = feature.getTableFeatureProperties(); - if (featureProperties != null) { - for (TableFeatureProperties featProp : featureProperties) { - length += TABLE_FEAT_HEADER_LENGTH; - if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) { - InstructionRelatedTableFeatureProperty property = - featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class); - length += property.getInstruction().size() * STRUCTURE_HEADER_LENGTH; - length += paddingNeeded(length); - } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) { - NextTableRelatedTableFeatureProperty property = - featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class); - length += property.getNextTableIds().size(); - length += paddingNeeded(length); - } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) { - ActionRelatedTableFeatureProperty property = - featProp.getAugmentation(ActionRelatedTableFeatureProperty.class); - length += property.getAction().size() * STRUCTURE_HEADER_LENGTH; - length += paddingNeeded(length); - } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) { - OxmRelatedTableFeatureProperty property = - featProp.getAugmentation(OxmRelatedTableFeatureProperty.class); - length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH; - length += paddingNeeded(length); - } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) { - ExperimenterRelatedTableFeatureProperty property = - featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); - length += 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - if (property.getData() != null) { - length += property.getData().length; - } - length += paddingNeeded(length); - } - } - } - return length; + private void serializeExperimenterBody(final MultipartRequestInput message, + final ByteBuf outBuffer) { + MultipartRequestExperimenterCase expCase = + (MultipartRequestExperimenterCase) message.getMultipartRequestBody(); + MultipartRequestExperimenter experimenter = expCase.getMultipartRequestExperimenter(); + OFSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartRequestExperimenter.class)); + serializer.serialize(experimenter, outBuffer); } - - - - private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { - int multipartRequestFlagsBitmask = 0; - Map multipartRequestFlagsMap = new HashMap<>(); - multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE()); - multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap); - return multipartRequestFlagsBitmask; + private static int createMultipartRequestFlagsBitmask(final MultipartRequestFlags flags) { + return ByteBufUtils.fillBitMask(0, flags.isOFPMPFREQMORE()); } /** * @param multipartRequestBody * @param output */ - private void encodeDescBody(MultipartRequestBody multipartRequestBody, - ByteBuf output) { + private void serializeDescBody(final MultipartRequestBody multipartRequestBody, + final ByteBuf output) { // The body of MultiPartRequestDesc is empty } @@ -296,8 +170,8 @@ public class MultipartRequestInputFactory implements OFSerializer serializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, Match.class)); + serializer.serialize(flow.getMatch(), output); } - private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private void serializeAggregateBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { MultipartRequestAggregateCase aggregateCase = (MultipartRequestAggregateCase) multipartRequestBody; MultipartRequestAggregate aggregate = aggregateCase.getMultipartRequestAggregate(); output.writeByte(aggregate.getTableId().byteValue()); @@ -360,64 +236,54 @@ public class MultipartRequestInputFactory implements OFSerializer serializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, Match.class)); + serializer.serialize(aggregate.getMatch(), output); } - private static void encodePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializePortStatsBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody; MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats(); output.writeInt(portstats.getPortNo().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY, output); } - private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeQueueBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody; MultipartRequestQueue queue = queueCase.getMultipartRequestQueue(); output.writeInt(queue.getPortNo().intValue()); output.writeInt(queue.getQueueId().intValue()); } - private static void encodeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeeGroupStatsBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { MultipartRequestGroupCase groupStatsCase = (MultipartRequestGroupCase) multipartRequestBody; MultipartRequestGroup groupStats = groupStatsCase.getMultipartRequestGroup(); output.writeInt(groupStats.getGroupId().getValue().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY, output); } - private static void encodeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeMeterBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { MultipartRequestMeterCase meterCase = (MultipartRequestMeterCase) multipartRequestBody; MultipartRequestMeter meter = meterCase.getMultipartRequestMeter(); output.writeInt(meter.getMeterId().getValue().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_BODY, output); } - private static void encodeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeMeterConfigBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { MultipartRequestMeterConfigCase meterConfigCase = (MultipartRequestMeterConfigCase) multipartRequestBody; MultipartRequestMeterConfig meterConfig = meterConfigCase.getMultipartRequestMeterConfig(); output.writeInt(meterConfig.getMeterId().getValue().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY, output); } - private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestExperimenterCase experimenterCase = (MultipartRequestExperimenterCase) multipartRequestBody; - MultipartRequestExperimenter experimenter = experimenterCase.getMultipartRequestExperimenter(); - output.writeInt(experimenter.getExperimenter().intValue()); - output.writeInt(experimenter.getExpType().intValue()); - byte[] data = experimenter.getData(); - if (data != null) { - output.writeBytes(data); - } - } - - private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private void serializeTableFeaturesBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) { if (multipartRequestBody != null) { MultipartRequestTableFeaturesCase tableFeaturesCase = (MultipartRequestTableFeaturesCase) multipartRequestBody; MultipartRequestTableFeatures tableFeatures = tableFeaturesCase.getMultipartRequestTableFeatures(); if(tableFeatures.getTableFeatures() != null) { for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) { - int length = computeSingleTableFeatureLength(currTableFeature); - length += paddingNeeded(length); - output.writeShort(length); + int tableFeatureLengthIndex = output.writerIndex(); + output.writeShort(EncodeConstants.EMPTY_LENGTH); output.writeByte(currTableFeature.getTableId()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY, output); output.writeBytes(currTableFeature.getName().getBytes()); @@ -427,12 +293,13 @@ public class MultipartRequestInputFactory implements OFSerializer props) { + private void writeTableFeatureProperties(final ByteBuf output, final List props) { if (props != null) { for (TableFeatureProperties property : props) { TableFeaturesPropType type = property.getType(); @@ -465,16 +332,16 @@ public class MultipartRequestInputFactory implements OFSerializer instructions = property. getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstruction(); @@ -490,7 +357,9 @@ public class MultipartRequestInputFactory implements OFSerializer keyMaker = TypeKeyMakerFactory + .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID); + ListSerializer.serializeHeaderList(instructions, keyMaker, registry, output); } else { padding = paddingNeeded(length); output.writeShort(length); @@ -498,8 +367,8 @@ public class MultipartRequestInputFactory implements OFSerializer nextTableIds = property. getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds(); @@ -513,13 +382,13 @@ public class MultipartRequestInputFactory implements OFSerializer actions = property. getAugmentation(ActionRelatedTableFeatureProperty.class).getAction(); @@ -546,7 +415,9 @@ public class MultipartRequestInputFactory implements OFSerializer keyMaker = TypeKeyMakerFactory + .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID); + ListSerializer.serializeHeaderList(actions, keyMaker, registry, output); } else { padding = paddingNeeded(length); output.writeShort(length); @@ -554,8 +425,8 @@ public class MultipartRequestInputFactory implements OFSerializer entries = property. getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntries(); @@ -566,7 +437,18 @@ public class MultipartRequestInputFactory implements OFSerializer key = new MatchEntrySerializerKey<>( + EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField()); + if (entry.getOxmClass().equals(ExperimenterClass.class)) { + key.setExperimenterId(entry.getAugmentation(ExperimenterMatchEntry.class).getExperimenter()); + } else { + key.setExperimenterId(null); + } + HeaderSerializer entrySerializer = registry.getSerializer(key); + entrySerializer.serializeHeader(entry, output); + } } else { padding = paddingNeeded(length); output.writeShort(length); @@ -574,35 +456,19 @@ public class MultipartRequestInputFactory implements OFSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TableFeatureProperties.class)); + serializer.serialize(property, output); } - private static int createTableConfigBitmask(TableConfig tableConfig) { - int tableConfigBitmask = 0; - Map tableConfigMap = new HashMap<>(); - tableConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK()); + private static int createTableConfigBitmask(final TableConfig tableConfig) { + return ByteBufUtils.fillBitMask(3, tableConfig.isOFPTCDEPRECATEDMASK()); + } - tableConfigBitmask = ByteBufUtils.fillBitMaskFromMap(tableConfigMap); - return tableConfigBitmask; + @Override + public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; } }