import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
\r
@Override\r
public int computeLength(MultipartRequestMessage message) {\r
- // TODO\r
- return MESSAGE_LENGTH;\r
+ return MESSAGE_LENGTH + computeBodyLength(message);\r
}\r
@Override\r
public byte getMessageType() {\r
return MESSAGE_TYPE;\r
- } \r
+ }\r
+ \r
+ /**\r
+ * \r
+ * @param message\r
+ * @return length of MultipartRequestMessage\r
+ */\r
+ public int computeBodyLength(MultipartRequestMessage message) {\r
+ int length = 0;\r
+ MultipartType type = message.getType();\r
+ if (type.equals(MultipartType.OFPMPFLOW)) {\r
+ final byte FLOW_BODY_LENGTH = 32;\r
+ MultipartRequestFlow body = (MultipartRequestFlow) message.getMultipartRequestBody();\r
+ length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());\r
+ } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {\r
+ final byte AGGREGATE_BODY_LENGTH = 32;\r
+ MultipartRequestAggregate body = (MultipartRequestAggregate) message.getMultipartRequestBody();\r
+ length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());\r
+ } else if (type.equals(MultipartType.OFPMPPORTSTATS)) {\r
+ final byte PORT_STATS_BODY_LENGTH = 8;\r
+ length += PORT_STATS_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPQUEUE)) {\r
+ final byte QUEUE_BODY_LENGTH = 8;\r
+ length += QUEUE_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPGROUP)) {\r
+ final byte GROUP_BODY_LENGTH = 8;\r
+ length += GROUP_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPMETER)) {\r
+ final byte METER_BODY_LENGTH = 8;\r
+ length += METER_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) {\r
+ final byte METER_CONFIG_BODY_LENGTH = 8;\r
+ length += METER_CONFIG_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) {\r
+ MultipartRequestTableFeatures body = (MultipartRequestTableFeatures) message.getMultipartRequestBody();\r
+ length += computeTableFeaturesLength(body);\r
+ } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {\r
+ final byte EXPERIMENTER_BODY_LENGTH = 8;\r
+ MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody();\r
+ length += EXPERIMENTER_BODY_LENGTH;\r
+ if (body.getData() != null) {\r
+ length += body.getData().length;\r
+ }\r
+ }\r
+ return length;\r
+ }\r
+\r
+ private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) {\r
+ final byte TABLE_FEATURES_LENGTH = 64;\r
+ final byte STRUCTURE_HEADER_LENGTH = 4;\r
+ int length = 0;\r
+ if (body != null) {\r
+ List<TableFeatures> tableFeatures = body.getTableFeatures();\r
+ for (TableFeatures feature : tableFeatures) {\r
+ length += TABLE_FEATURES_LENGTH;\r
+ List<TableFeatureProperties> featureProperties = feature.getTableFeatureProperties();\r
+ if (featureProperties != null) {\r
+ for (TableFeatureProperties featProp : featureProperties) {\r
+ length += TABLE_FEAT_HEADER_LENGTH;\r
+ if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) {\r
+ InstructionRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class);\r
+ length += property.getInstructions().size() * STRUCTURE_HEADER_LENGTH;\r
+ } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) {\r
+ NextTableRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class);\r
+ length += property.getNextTableIds().size();\r
+ } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) {\r
+ ActionRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(ActionRelatedTableFeatureProperty.class);\r
+ length += property.getActionsList().size() * STRUCTURE_HEADER_LENGTH;\r
+ } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) {\r
+ OxmRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(OxmRelatedTableFeatureProperty.class);\r
+ length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH;\r
+ } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) {\r
+ ExperimenterRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class);\r
+ length += 2 * (Integer.SIZE / Byte.SIZE);\r
+ if (property.getData() != null) {\r
+ length += property.getData().length;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return length;\r
+ }\r
\r
private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) {\r
int multipartRequestFlagsBitmask = 0;\r
MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody;\r
output.writeInt(experimenter.getExperimenter().intValue());\r
output.writeInt(experimenter.getExpType().intValue());\r
- output.writeBytes(experimenter.getData());\r
+ byte[] data = experimenter.getData();\r
+ if (data != null) {\r
+ output.writeBytes(data);\r
+ }\r
}\r
\r
private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {\r