Bug 2756 - Action model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / MultipartRequestInputFactory.java
index 0fdeff1cdc19b5f4341964cb42ff1b3def8beea2..7afb253b4bc50d524d9faa4b59427d34c5f5cd96 100644 (file)
@@ -10,30 +10,32 @@ 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.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.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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter;
+
+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.keys.MessageTypeKey;
+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.openflowjava.util.ExperimenterSerializerKeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeatureProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdTableFeatureProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeatureProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeatureProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeatureProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.table.features.properties.container.table.feature.properties.NextTableIds;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
 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.oxm.fields.grouping.MatchEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase;
@@ -68,12 +70,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * @author timotej.kubas
  * @author michal.polkorab
  */
-public class MultipartRequestInputFactory implements OFSerializer<MultipartRequestInput> {
+public class MultipartRequestInputFactory implements OFSerializer<MultipartRequestInput>, 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,18 +87,6 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
     private static final byte WRITE_SETFIELD_MISS_CODE = 13;
     private static final byte APPLY_SETFIELD_CODE = 14;
     private static final byte APPLY_SETFIELD_MISS_CODE = 15;
-    private static final int EXPERIMENTER_CODE = 65534; // 0xFFFE
-    private static final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF
-    private static final byte FLOW_BODY_LENGTH = 32;
-    private static final byte AGGREGATE_BODY_LENGTH = 32;
-    private static final byte PORT_STATS_BODY_LENGTH = 8;
-    private static final byte QUEUE_BODY_LENGTH = 8;
-    private static final byte GROUP_BODY_LENGTH = 8;
-    private static final byte METER_BODY_LENGTH = 8;
-    private static final byte METER_CONFIG_BODY_LENGTH = 8;
-    private static final byte EXPERIMENTER_BODY_LENGTH = 8;
-    private static final byte TABLE_FEATURES_LENGTH = 64;
-    private static final byte STRUCTURE_HEADER_LENGTH = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
     private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01 = 3;
@@ -109,186 +96,70 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
     private static final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5;
-    
-
-
-    private MultipartRequestInputFactory() {
-        // singleton
-    }
-
-    /**
-     * @return singleton factory
-     */
-    public static synchronized MultipartRequestInputFactory getInstance() {
-        if (instance == null) {
-            instance = new MultipartRequestInputFactory();
-        }
-        return instance;
-    }
+    private SerializerRegistry registry;
 
     @Override
-    public void messageToBuffer(short version, ByteBuf out,
-            MultipartRequestInput message) {
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeShort(message.getType().getIntValue());
-        out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
-        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, out);
+    public void serialize(final MultipartRequestInput message, final ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+        outBuffer.writeShort(message.getType().getIntValue());
+        outBuffer.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
+        outBuffer.writeZero(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
 
         if (message.getMultipartRequestBody() instanceof MultipartRequestDescCase){
-            encodeDescBody(message.getMultipartRequestBody(), out);
+            serializeDescBody();
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlowCase) {
-            encodeFlowBody(message.getMultipartRequestBody(), out);
+            serializeFlowBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregateCase) {
-            encodeAggregateBody(message.getMultipartRequestBody(), out);
+            serializeAggregateBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableCase) {
-            encodeTableBody(message.getMultipartRequestBody(), out);
+            serializeTableBody();
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase) {
-            encodePortStatsBody(message.getMultipartRequestBody(), out);
+            serializePortStatsBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueueCase) {
-            encodeQueueBody(message.getMultipartRequestBody(), out);
+            serializeQueueBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupCase) {
-            encodeGroupStatsBody(message.getMultipartRequestBody(), out);
+            serializeeGroupStatsBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupDescCase) {
-            encodeGroupDescBody(message.getMultipartRequestBody(), out);
+            serializeGroupDescBody();
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupFeaturesCase) {
-            encodeGroupFeaturesBody(message.getMultipartRequestBody(), out);
+            serializeGroupFeaturesBody();
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterCase) {
-            encodeMeterBody(message.getMultipartRequestBody(), out);
+            serializeMeterBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfigCase) {
-            encodeMeterConfigBody(message.getMultipartRequestBody(), out);
+            serializeMeterConfigBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterFeaturesCase) {
-            encodeMeterFeaturesBody(message.getMultipartRequestBody(), out);
+            serializeMeterFeaturesBody();
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeaturesCase) {
-            encodeTableFeaturesBody(message.getMultipartRequestBody(), out);
+            serializeTableFeaturesBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortDescCase) {
-            encodePortDescBody(message.getMultipartRequestBody(), out);
+            serializePortDescBody();
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenterCase) {
-            encodeExperimenterBody(message.getMultipartRequestBody(), out);
-        }
-    }
-
-    @Override
-    public int computeLength(MultipartRequestInput message) {
-        return MESSAGE_LENGTH + computeBodyLength(message);
-    }
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
-
-    /**
-     *
-     * @param message
-     * @return length of MultipartRequestMessage
-     */
-    public int computeBodyLength(MultipartRequestInput message) {
-        int length = 0;
-        MultipartType type = message.getType();
-        if (type.equals(MultipartType.OFPMPFLOW)) {
-            MultipartRequestFlowCase bodyCase = (MultipartRequestFlowCase) message.getMultipartRequestBody();
-            MultipartRequestFlow body = bodyCase.getMultipartRequestFlow();
-            length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
-        } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {
-            MultipartRequestAggregateCase bodyCase = (MultipartRequestAggregateCase) message.getMultipartRequestBody();
-            MultipartRequestAggregate body = bodyCase.getMultipartRequestAggregate();
-            length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
-        } else if (type.equals(MultipartType.OFPMPPORTSTATS)) {
-            length += PORT_STATS_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPQUEUE)) {
-            length += QUEUE_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPGROUP)) {
-            length += GROUP_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPMETER)) {
-            length += METER_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) {
-            length += METER_CONFIG_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) {
-            MultipartRequestTableFeaturesCase bodyCase = (MultipartRequestTableFeaturesCase) message.getMultipartRequestBody();
-            MultipartRequestTableFeatures body = bodyCase.getMultipartRequestTableFeatures();
-            length += computeTableFeaturesLength(body);
-        } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {
-            MultipartRequestExperimenterCase bodyCase = (MultipartRequestExperimenterCase) message.getMultipartRequestBody();
-            MultipartRequestExperimenter body = bodyCase.getMultipartRequestExperimenter();
-            length += EXPERIMENTER_BODY_LENGTH;
-            if (body.getData() != null) {
-                length += body.getData().length;
-            }
+               serializeExperimenterBody(message, outBuffer);
         }
-        return length;
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
-    private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) {
-        int length = 0;
-        if (body != null && body.getTableFeatures() != null) {
-            List<TableFeatures> tableFeatures = body.getTableFeatures();
-            for (TableFeatures feature : tableFeatures) {
-                length += computeSingleTableFeatureLength(feature);
-            }
-        }
-        return length;
-    }
-    
-    private static int computeSingleTableFeatureLength(TableFeatures feature) {
-        return TABLE_FEATURES_LENGTH + computeTableFeatPropsLength(feature);
-    }
-
-    private static int computeTableFeatPropsLength(TableFeatures feature) {
-        int length = 0;
-        List<TableFeatureProperties> 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();
+        long expId = experimenter.getAugmentation(ExperimenterIdMultipartRequest.class).getExperimenter().getValue();
+        OFSerializer<MultipartRequestExperimenterCase> serializer = registry.getSerializer(
+                ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey(
+                        EncodeConstants.OF13_VERSION_ID, expId));
+        serializer.serialize(expCase, outBuffer);
     }
-    
-    
 
-    private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) {
-        int multipartRequestFlagsBitmask = 0;
-        Map<Integer, Boolean> 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() {
         // The body of MultiPartRequestDesc is empty
     }
 
@@ -296,8 +167,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeTableBody(MultipartRequestBody multipartRequestBody,
-            ByteBuf out) {
+    private void serializeTableBody() {
      // The body of MultiPartTable is empty
     }
 
@@ -305,8 +175,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeGroupDescBody(MultipartRequestBody multipartRequestBody,
-            ByteBuf out) {
+    private void serializeGroupDescBody() {
      // The body of MultiPartRequestGroupDesc is empty
     }
 
@@ -314,8 +183,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeGroupFeaturesBody(
-            MultipartRequestBody multipartRequestBody, ByteBuf out) {
+    private void serializeGroupFeaturesBody() {
      // The body of MultiPartRequestGroupFeatures is empty
     }
 
@@ -323,8 +191,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeMeterFeaturesBody(
-            MultipartRequestBody multipartRequestBody, ByteBuf out) {
+    private void serializeMeterFeaturesBody() {
      // The body of MultiPartMeterFeatures is empty
     }
 
@@ -332,107 +199,99 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodePortDescBody(MultipartRequestBody multipartRequestBody,
-            ByteBuf out) {
+    private void serializePortDescBody() {
      // The body of MultiPartPortDesc is empty
     }
 
-    private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+    private void serializeFlowBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
         MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
         MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
         output.writeByte(flow.getTableId().byteValue());
-        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01, output);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01);
         output.writeInt(flow.getOutPort().intValue());
         output.writeInt(flow.getOutGroup().intValue());
-        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02, output);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02);
         output.writeLong(flow.getCookie().longValue());
         output.writeLong(flow.getCookieMask().longValue());
-        MatchSerializer.encodeMatch(flow.getMatch(), output);
+        OFSerializer<Match> 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());
-        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01, output);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01);
         output.writeInt(aggregate.getOutPort().intValue());
         output.writeInt(aggregate.getOutGroup().intValue());
-        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02, output);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02);
         output.writeLong(aggregate.getCookie().longValue());
         output.writeLong(aggregate.getCookieMask().longValue());
-        MatchSerializer.encodeMatch(aggregate.getMatch(), output);
+        OFSerializer<Match> 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);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY);
     }
 
-    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);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY);
     }
 
-    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);
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_METER_BODY);
     }
 
-    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);
-        }
+        output.writeZero(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY);
     }
 
-    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.writeZero(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY);
                     output.writeBytes(currTableFeature.getName().getBytes());
-                    ByteBufUtils.padBuffer((32 - currTableFeature.getName().getBytes().length), output);
+                    output.writeZero(32 - currTableFeature.getName().getBytes().length);
                     output.writeLong(currTableFeature.getMetadataMatch().longValue());
                     output.writeLong(currTableFeature.getMetadataWrite().longValue());
                     output.writeInt(createTableConfigBitmask(currTableFeature.getConfig()));
                     output.writeInt(currTableFeature.getMaxEntries().intValue());
                     writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties());
+                    output.setShort(tableFeatureLengthIndex, output.writerIndex() - tableFeatureLengthIndex);
                 }
             }
         }
     }
 
-    private static void writeTableFeatureProperties(ByteBuf output, List<TableFeatureProperties> props) {
+    private void writeTableFeatureProperties(final ByteBuf output, final List<TableFeatureProperties> props) {
         if (props != null) {
             for (TableFeatureProperties property : props) {
                 TableFeaturesPropType type = property.getType();
@@ -465,61 +324,51 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
                 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) {
                     writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_MISS_CODE);
                 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) {
-                    writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_CODE);
+                    writeExperimenterRelatedTableProperty(output, property);
                 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
-                    writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_MISS_CODE);
+                    writeExperimenterRelatedTableProperty(output, property);
                 }
             }
         }
     }
 
-    private static void writeInstructionRelatedTableProperty(ByteBuf output,
-            TableFeatureProperties property, byte code) {
+    private void writeInstructionRelatedTableProperty(final ByteBuf output,
+            final TableFeatureProperties property, final byte code) {
+        int startIndex = output.writerIndex();
         output.writeShort(code);
+        int lengthIndex = output.writerIndex();
+        output.writeShort(EncodeConstants.EMPTY_LENGTH);
         List<Instruction> instructions = property.
                 getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstruction();
-        int length = TABLE_FEAT_HEADER_LENGTH;
-        int padding = 0;
         if (instructions != null) {
-            for (Instruction instruction : instructions) {
-                if (instruction.getType().isAssignableFrom(Experimenter.class)) {
-                    length += EncodeConstants.EXPERIMENTER_IDS_LENGTH;
-                } else {
-                    length += STRUCTURE_HEADER_LENGTH;
-                }
-            }
-            padding = paddingNeeded(length);
-            output.writeShort(length);
-            InstructionsSerializer.encodeInstructionIds(instructions, output);
-        } else {
-            padding = paddingNeeded(length);
-            output.writeShort(length);
+            TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory
+                    .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
+            ListSerializer.serializeHeaderList(instructions, keyMaker, registry, output);
         }
-        ByteBufUtils.padBuffer(padding, output);
+        int length = output.writerIndex() - startIndex;
+        output.setShort(lengthIndex, length);
+        output.writeZero(paddingNeeded(length));
     }
 
-    private static void writeNextTableRelatedTableProperty(ByteBuf output,
-            TableFeatureProperties property, byte code) {
+    private static void writeNextTableRelatedTableProperty(final ByteBuf output,
+            final TableFeatureProperties property, final byte code) {
+        int startIndex = output.writerIndex();
         output.writeShort(code);
+        int lengthIndex = output.writerIndex();
+        output.writeShort(EncodeConstants.EMPTY_LENGTH);
         List<NextTableIds> nextTableIds = property.
                 getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds();
-        int length = TABLE_FEAT_HEADER_LENGTH;
-        int padding = 0;
         if (nextTableIds != null) {
-            length += nextTableIds.size();
-            padding = paddingNeeded(length);
-            output.writeShort(length);
             for (NextTableIds next : nextTableIds) {
                 output.writeByte(next.getTableId());
             }
-        } else {
-            padding = paddingNeeded(length); 
-            output.writeShort(length + padding);
         }
-        ByteBufUtils.padBuffer(padding, output);
+        int length = output.writerIndex() - startIndex;
+        output.setShort(lengthIndex, length);
+        output.writeZero(paddingNeeded(length));
     }
 
-    private static int paddingNeeded(int length) {
+    private static int paddingNeeded(final int length) {
         int paddingRemainder = length % EncodeConstants.PADDING;
         int result = 0;
         if (paddingRemainder != 0) {
@@ -528,81 +377,57 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
         return result;
     }
 
-    private static void writeActionsRelatedTableProperty(ByteBuf output,
-            TableFeatureProperties property, byte code) {
+    private void writeActionsRelatedTableProperty(final ByteBuf output,
+            final TableFeatureProperties property, final byte code) {
+        int startIndex = output.writerIndex();
         output.writeShort(code);
+        int lengthIndex = output.writerIndex();
+        output.writeShort(EncodeConstants.EMPTY_LENGTH);
         List<Action> actions = property.
                 getAugmentation(ActionRelatedTableFeatureProperty.class).getAction();
-        int length = TABLE_FEAT_HEADER_LENGTH;
-        int padding = 0;
         if (actions != null) {
-            for (Action action : actions) {
-                if (action.getType().isAssignableFrom(Experimenter.class)) {
-                    length += EncodeConstants.EXPERIMENTER_IDS_LENGTH;
-                } else {
-                    length += STRUCTURE_HEADER_LENGTH;
-                }
-            }
-            length += actions.size() * STRUCTURE_HEADER_LENGTH;
-            padding += paddingNeeded(length);
-            output.writeShort(length);
-            ActionsSerializer.encodeActionIds(actions, output);
-        } else {
-            padding = paddingNeeded(length);
-            output.writeShort(length);
+            TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory
+                    .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
+            ListSerializer.serializeHeaderList(actions, keyMaker, registry, output);
         }
-        ByteBufUtils.padBuffer(padding, output);
+        int length = output.writerIndex() - startIndex;
+        output.setShort(lengthIndex, length);
+        output.writeZero(paddingNeeded(length));
     }
 
-    private static void writeOxmRelatedTableProperty(ByteBuf output,
-            TableFeatureProperties property, byte code) {
+    private void writeOxmRelatedTableProperty(final ByteBuf output,
+            final TableFeatureProperties property, final byte code) {
+        int startIndex = output.writerIndex();
         output.writeShort(code);
-        List<MatchEntries> entries = property.
-                getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntries();
-        int length = TABLE_FEAT_HEADER_LENGTH;
-        int padding = 0;
+        int lengthIndex = output.writerIndex();
+        output.writeShort(EncodeConstants.EMPTY_LENGTH);
+        List<MatchEntry> entries = property.
+                getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntry();
         if (entries != null) {
-            // experimenter length / definition ?
-            length += entries.size() * STRUCTURE_HEADER_LENGTH;
-            padding = paddingNeeded(length);
-            output.writeShort(length);
-            MatchSerializer.encodeMatchIds(entries, output);
-        } else {
-            padding = paddingNeeded(length);
-            output.writeShort(length);
+            TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory
+                    .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
+            ListSerializer.serializeHeaderList(entries, keyMaker, registry, output);
         }
-        ByteBufUtils.padBuffer(padding, output);
+        int length = output.writerIndex() - startIndex;
+        output.setShort(lengthIndex, length);
+        output.writeZero(paddingNeeded(length));
     }
 
-    private static void writeExperimenterRelatedTableProperty(ByteBuf output,
-            TableFeatureProperties property, int code) {
-        output.writeShort(code);
-        ExperimenterRelatedTableFeatureProperty exp = property.
-                getAugmentation(ExperimenterRelatedTableFeatureProperty.class);
-        byte[] data = exp.getData();
-        int length = TABLE_FEAT_HEADER_LENGTH + 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES);
-        int padding = 0;
-        if (data != null) {
-            output.writeShort(length + data.length);
-            padding = paddingNeeded(length + data.length);
-            output.writeInt(exp.getExperimenter().intValue());
-            output.writeInt(exp.getExpType().intValue());
-            output.writeBytes(data);
-        } else {
-            output.writeShort(length);
-            padding = paddingNeeded(length);
-            output.writeInt(exp.getExperimenter().intValue());
-            output.writeInt(exp.getExpType().intValue());
-        }
-        ByteBufUtils.padBuffer(padding, output);
+    private void writeExperimenterRelatedTableProperty(final ByteBuf output,
+            final TableFeatureProperties property) {
+        long expId = property.getAugmentation(ExperimenterIdTableFeatureProperty.class).getExperimenter().getValue();
+        OFSerializer<TableFeatureProperties> serializer = registry.getSerializer(
+                ExperimenterSerializerKeyFactory.createMultipartRequestTFSerializerKey(
+                        EncodeConstants.OF13_VERSION_ID, expId));
+        serializer.serialize(property, output);
     }
 
-    private static int createTableConfigBitmask(TableConfig tableConfig) {
-        int tableConfigBitmask = 0;
-        Map<Integer, Boolean> 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;
     }
 }