X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FOF10StatsReplyMessageFactory.java;h=ccea543fa11a234a1df449a4ba9e443f4e901825;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=4fc94355a91f5d710d414f8ce29b43361ce20a00;hpb=8d785e650476b80189b86f6ad44c5a24d5ccbf6d;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java index 4fc94355..ccea543f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java @@ -14,12 +14,21 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker; +import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory; +import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory; +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.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.oxm.rev130731.match.v10.grouping.MatchV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase; @@ -27,7 +36,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase; @@ -38,7 +46,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder; @@ -56,7 +63,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * Translates StatsReply messages (OpenFlow v1.0) * @author michal.polkorab */ -public class OF10StatsReplyMessageFactory implements OFDeserializer { +public class OF10StatsReplyMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { private static final int DESC_STR_LEN = 256; private static final int SERIAL_NUM_LEN = 32; @@ -67,52 +75,39 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer flowStatsList = new ArrayList<>(); while (input.readableBytes() > 0) { FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + int length = input.readUnsignedShort(); flowStatsBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(PADDING_IN_FLOW_STATS_HEADER); - flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input)); + OFDeserializer matchDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); + flowStatsBuilder.setMatchV10(matchDeserializer.deserialize(input)); flowStatsBuilder.setDurationSec(input.readUnsignedInt()); flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); flowStatsBuilder.setPriority(input.readUnsignedShort()); flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(cookie); - flowStatsBuilder.setCookie(new BigInteger(cookie)); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + flowStatsBuilder.setCookie(new BigInteger(1, cookie)); + byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(packetCount); - flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount)); + byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(byteCount); - flowStatsBuilder.setByteCount(new BigInteger(byteCount)); - flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input)); + flowStatsBuilder.setByteCount(new BigInteger(1, byteCount)); + CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID); + List actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, + length - LENGTH_OF_FLOW_STATS, input, keyMaker, registry); + flowStatsBuilder.setAction(actions); flowStatsList.add(flowStatsBuilder.build()); } flowBuilder.setFlowStats(flowStatsList); caseBuilder.setMultipartReplyFlow(flowBuilder.build()); return caseBuilder.build(); } - + private static MultipartReplyAggregateCase setAggregate(ByteBuf input) { MultipartReplyAggregateCaseBuilder caseBuilder = new MultipartReplyAggregateCaseBuilder(); MultipartReplyAggregateBuilder builder = new MultipartReplyAggregateBuilder(); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(packetCount); - builder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + builder.setPacketCount(new BigInteger(1, packetCount)); + byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(byteCount); - builder.setByteCount(new BigInteger(byteCount)); + builder.setByteCount(new BigInteger(1, byteCount)); builder.setFlowCount(input.readUnsignedInt()); input.skipBytes(PADDING_IN_AGGREGATE_HEADER); caseBuilder.setMultipartReplyAggregate(builder.build()); return caseBuilder.build(); } - + private static MultipartReplyTableCase setTable(ByteBuf input) { MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder(); List tableStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { + // TODO - replace ">= TABLE_STATS_LENGTH" with "> 0" after fix in OVS switch + while (input.readableBytes() >= TABLE_STATS_LENGTH) { TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); tableStatsBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(PADDING_IN_TABLE_HEADER); - tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); + tableStatsBuilder.setName(ByteBufUtils.decodeNullTerminatedString(input, MAX_TABLE_NAME_LENGTH)); + long wildcards = input.readUnsignedInt(); + tableStatsBuilder.setWildcards(OF10MatchDeserializer.createWildcards(wildcards)); + tableStatsBuilder.setNwSrcMask(OF10MatchDeserializer.decodeNwSrcMask(wildcards)); + tableStatsBuilder.setNwDstMask(OF10MatchDeserializer.decodeNwDstMask(wildcards)); + tableStatsBuilder.setMaxEntries(input.readUnsignedInt()); tableStatsBuilder.setActiveCount(input.readUnsignedInt()); - byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; + byte[] lookupCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(lookupCount); - tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); - byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; + tableStatsBuilder.setLookupCount(new BigInteger(1, lookupCount)); + byte[] matchedCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(matchedCount); - tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); + tableStatsBuilder.setMatchedCount(new BigInteger(1, matchedCount)); tableStatsList.add(tableStatsBuilder.build()); } + input.skipBytes(input.readableBytes()); builder.setTableStats(tableStatsList); caseBuilder.setMultipartReplyTable(builder.build()); return caseBuilder.build(); } - + private static MultipartReplyPortStatsCase setPortStats(ByteBuf input) { MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder(); MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder(); @@ -219,48 +226,49 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer