Bugfix - match, actions, instructions 45/2645/1
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 12 Nov 2013 08:24:12 +0000 (09:24 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 12 Nov 2013 08:37:00 +0000 (09:37 +0100)
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java

index 58f8941b2f1dd25087bfd0510c5e4c2c278747e9..9a82c776695e288774f0581f8362988da81ebacd 100644 (file)
@@ -92,7 +92,7 @@ public class OF10FeaturesReplyMessageFactory implements OFDeserializer<GetFeatur
     }\r
     \r
     private static void deserializePort(ByteBuf rawMessage, GetFeaturesOutputBuilder builder) {\r
-        builder.setPortNo(new Long(rawMessage.readUnsignedShort()));\r
+        builder.setPortNo((long) rawMessage.readUnsignedShort());\r
         StringBuffer macToString = new StringBuffer();\r
         for(int i = 0; i < MAC_ADDRESS_LENGTH; i++){\r
             short mac = rawMessage.readUnsignedByte();\r
index 1a198ebe9d8317a16b2d3feac56482a2fbf2f143..c04457f1dabebf9e0d93f8b74d8c45a04b634645 100644 (file)
@@ -90,7 +90,7 @@ public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMe
     }\r
     \r
     private static void deserializePort(ByteBuf rawMessage, PortStatusMessageBuilder builder) {\r
-        builder.setPortNo(new Long(rawMessage.readUnsignedShort()));\r
+        builder.setPortNo((long) rawMessage.readUnsignedShort());\r
         StringBuffer macToString = new StringBuffer();\r
         for(int i = 0; i < MAC_ADDRESS_LENGTH; i++){\r
             short mac = rawMessage.readUnsignedByte();\r
index eced791beec65bec3fc2bc552eb146fe385ab695..10e9e397cf4ff07179af664ffb26068554b0721a 100644 (file)
@@ -54,7 +54,7 @@ public class OF10QueueGetConfigReplyMessageFactory implements OFDeserializer<Get
         GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder();\r
         builder.setVersion(version);\r
         builder.setXid((rawMessage.readUnsignedInt()));\r
-        builder.setPort(new PortNumber(new Long(rawMessage.readUnsignedShort())));\r
+        builder.setPort(new PortNumber((long) rawMessage.readUnsignedShort()));\r
         rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER);\r
         builder.setQueues(createQueuesList(rawMessage));\r
         return builder.build();\r
index 198f3ca6b5e239b674102d8238d06e8d219b4906..b18efb446c880f8097d7531447260dc0bcf9bd26 100644 (file)
@@ -189,7 +189,7 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer<MultipartRep
         PortStatsBuilder portStatsBuilder = new PortStatsBuilder();\r
         List<PortStats> portStatsList = new ArrayList<>();\r
         while (input.readableBytes() > 0) {\r
-            portStatsBuilder.setPortNo(new Long(input.readUnsignedShort()));\r
+            portStatsBuilder.setPortNo((long) input.readUnsignedShort());\r
             input.skipBytes(PADDING_IN_PORT_STATS_HEADER);\r
             \r
             byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE];\r
@@ -253,7 +253,7 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer<MultipartRep
         List<QueueStats> queueStatsList = new ArrayList<>();\r
         \r
         while (input.readableBytes() > 0) {\r
-            queueStatsBuilder.setPortNo(new Long(input.readUnsignedShort()));\r
+            queueStatsBuilder.setPortNo((long) input.readUnsignedShort());\r
             input.skipBytes(PADDING_IN_QUEUE_HEADER);\r
             queueStatsBuilder.setQueueId(input.readUnsignedInt());\r
 \r
index afed9255b092657c7dd3e1f3864b651db3e851d1..154a18143979eac4b7f6394a28adac712a83071f 100644 (file)
@@ -54,7 +54,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
  * @author michal.polkorab\r
  */\r
 public abstract class ActionsDeserializer {\r
-    final static byte PAD_ACTION_LENGTH = 2;\r
     private static ActionBuilder actionBuilder = new ActionBuilder();\r
     private static ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
     private static List<ActionsList> actionsList = new ArrayList<>();\r
@@ -66,6 +65,7 @@ public abstract class ActionsDeserializer {
      */\r
     public static List<ActionsList> createActionsList(ByteBuf input, int bucketsLength) {\r
         final byte BUCKET_HEADER_LENGTH = 16;\r
+        final byte ACTION_HEADER_LENGTH = 4;\r
         int bucketsCurrentLength = BUCKET_HEADER_LENGTH;\r
         int actionsLength = 0;\r
             \r
@@ -136,7 +136,8 @@ public abstract class ActionsDeserializer {
                         \r
                 case 25:\r
                         actionsLength = input.readUnsignedShort();//8\r
-                        actionsList.add(ActionsDeserializer.createSetFieldAction(input, actionsLength));\r
+                        actionsList.add(ActionsDeserializer.createSetFieldAction(input,\r
+                                actionsLength - ACTION_HEADER_LENGTH));\r
                         break; \r
                 case 26: \r
                          actionsLength = input.readUnsignedShort();//8\r
@@ -166,7 +167,8 @@ public abstract class ActionsDeserializer {
      * @param in input ByteBuf \r
      * @return Action\r
      */\r
-    private static ActionsList createEmptyHeader(Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Action> action, ByteBuf in) {\r
+    private static ActionsList createEmptyHeader(Class<? extends org.opendaylight.yang.gen.v1.\r
+            urn.opendaylight.openflow.common.types.rev130731.Action> action, ByteBuf in) {\r
         final byte PADDING_IN_ACTIONS_HEADER = 4;\r
         \r
         actionBuilder.setType(action);\r
@@ -377,7 +379,7 @@ public abstract class ActionsDeserializer {
     public static ActionsList createSetFieldAction(ByteBuf in, int actionLength) {\r
         actionBuilder.setType(SetField.class);\r
         OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();\r
-        matchEntries.setMatchEntries(MatchDeserializer.createMatchEntries(in, actionLength - 4));\r
+        matchEntries.setMatchEntries(MatchDeserializer.createMatchEntries(in, actionLength));\r
         actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build());\r
         actionsListBuilder.setAction(actionBuilder.build());\r
         \r
index 892857c726d218eb8c57e38e96945470d91d4d22..61f8a9705bb5b630f24f6e5dcad8d292516c7c45 100644 (file)
@@ -4,6 +4,8 @@ package org.opendaylight.openflowjava.protocol.impl.util;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;\r
@@ -46,6 +48,7 @@ public class InstructionsDeserializer {
                 InstructionsBuilder builder = new InstructionsBuilder();\r
                 int type = input.readUnsignedShort();\r
                 int instructionLength = input.readUnsignedShort();\r
+                lengthOfInstructions -= instructionLength;\r
                 switch (type) {\r
                 case 1:\r
                     createGotoTableInstruction(builder, input);\r
@@ -55,15 +58,15 @@ public class InstructionsDeserializer {
                     break;\r
                 case 3:\r
                     builder.setType(WriteActions.class);\r
-                    createActionRelatedInstruction(input, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);\r
+                    createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);\r
                     break;\r
                 case 4:\r
                     builder.setType(ApplyActions.class);\r
-                    createActionRelatedInstruction(input, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);\r
+                    createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);\r
                     break;\r
                 case 5:\r
                     builder.setType(ClearActions.class);\r
-                    createActionRelatedInstruction(input, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);\r
+                    createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);\r
                     break;\r
                 case 6:\r
                     builder.setType(Meter.class);\r
@@ -76,9 +79,12 @@ public class InstructionsDeserializer {
                     builder.setType(Experimenter.class);\r
                     ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder();\r
                     expBuilder.setExperimenter(input.readUnsignedInt());\r
-                    byte[] data = new byte[instructionLength - EXPERIMENTER_HEADER_LENGTH];\r
-                    input.readBytes(data);\r
-                    expBuilder.setData(data);\r
+                    int dataLength = instructionLength - EXPERIMENTER_HEADER_LENGTH;\r
+                    if (dataLength > 0) {\r
+                        byte[] data = new byte[dataLength];\r
+                        input.readBytes(data);\r
+                        expBuilder.setData(data);\r
+                    }\r
                     builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build());\r
                     break;\r
                 default:\r
@@ -90,13 +96,6 @@ public class InstructionsDeserializer {
         return instructions;\r
     }\r
 \r
-    private static void createActionRelatedInstruction(ByteBuf input,\r
-            int instructionLength) {\r
-        final byte ACTIONS_RELATED_INSTRUCTION_PADDING = 4;\r
-        input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING);\r
-        ActionsDeserializer.createActionsList(input, instructionLength);\r
-    }\r
-\r
     private static void createGotoTableInstruction(InstructionsBuilder builder,\r
             ByteBuf input) {\r
         final byte GOTO_TABLE_PADDING = 3;\r
@@ -121,5 +120,14 @@ public class InstructionsDeserializer {
         metadataBuilder.setMetadata(metadata_mask);\r
         builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());\r
     }\r
+    \r
+    private static void createActionRelatedInstruction(ByteBuf input,\r
+            InstructionsBuilder builder, int instructionLength) {\r
+        final byte ACTIONS_RELATED_INSTRUCTION_PADDING = 4;\r
+        input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING);\r
+        ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();\r
+        actionsBuilder.setActionsList(ActionsDeserializer.createActionsList(input, instructionLength));\r
+        builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());\r
+    }\r
 \r
 }\r
index 40df5d4f0cfef67e7ee88378806e6cbb99392d20..54478ebf6663a9a4f41dee27f06cea8cc174fa24 100644 (file)
@@ -39,14 +39,16 @@ public abstract class InstructionsSerializer {
                 if (type.equals(GotoTable.class)) {\r
                     final byte GOTO_TABLE_TYPE = 1;\r
                     final byte GOTO_TABLE_LENGTH = 8;\r
+                    final byte PADDING_IN_GOTO_TABLE = 3;\r
                     writeTypeAndLength(out, GOTO_TABLE_TYPE, GOTO_TABLE_LENGTH);\r
                     out.writeByte(instruction.getAugmentation(TableIdInstruction.class).getTableId());\r
-                    ByteBufUtils.padBuffer(3, out);\r
+                    ByteBufUtils.padBuffer(PADDING_IN_GOTO_TABLE, out);\r
                 } else if (type.equals(WriteMetadata.class)) {\r
                     final byte WRITE_METADATA_TYPE = 2;\r
                     final byte WRITE_METADATA_LENGTH = 24;\r
+                    final byte PADDING_IN_WRITE_METADATA = 4;\r
                     writeTypeAndLength(out, WRITE_METADATA_TYPE, WRITE_METADATA_LENGTH);\r
-                    ByteBufUtils.padBuffer(4, out);\r
+                    ByteBufUtils.padBuffer(PADDING_IN_WRITE_METADATA, out);\r
                     MetadataInstruction metadata = instruction.getAugmentation(MetadataInstruction.class);\r
                     out.writeBytes(metadata.getMetadata());\r
                     out.writeBytes(metadata.getMetadataMask());\r
@@ -59,8 +61,9 @@ public abstract class InstructionsSerializer {
                 } else if (type.equals(ClearActions.class)) {\r
                     final byte CLEAR_ACTIONS_TYPE = 5;\r
                     final byte CLEAR_ACTIONS_LENGTH = 8;\r
+                    final byte PADDING_IN_CLEAR_ACTIONS = 4;\r
                     writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, CLEAR_ACTIONS_LENGTH);\r
-                    ByteBufUtils.padBuffer(4, out);\r
+                    ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, out);\r
                 } else if (type.equals(Meter.class)) {\r
                     final byte METER_TYPE = 6;\r
                     final byte METER_LENGTH = 8;\r
@@ -87,10 +90,12 @@ public abstract class InstructionsSerializer {
 \r
     private static void writeActionsInstruction(ByteBuf out,\r
             Instructions instruction, int type) {\r
+        final byte ACTIONS_INSTRUCTION_LENGTH = 8;\r
+        final byte PADDING_IN_ACTIONS_INSTRUCTION = 4;\r
         out.writeShort(type);\r
         List<ActionsList> actions = instruction.getAugmentation(ActionsInstruction.class).getActionsList();\r
-        out.writeShort(ActionsSerializer.computeLengthOfActions(actions));\r
-        ByteBufUtils.padBuffer(4, out);\r
+        out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions));\r
+        ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);\r
         ActionsSerializer.encodeActions(actions, out);\r
     }\r
     \r
@@ -111,10 +116,12 @@ public abstract class InstructionsSerializer {
                     final byte WRITE_METADATA_LENGTH = 24;\r
                     length += WRITE_METADATA_LENGTH;\r
                 } else if (type.equals(WriteActions.class)) {\r
-                    length += ActionsSerializer.computeLengthOfActions(\r
+                    final byte WRITE_ACTIONS_LENGTH = 8;\r
+                    length += WRITE_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions(\r
                             instruction.getAugmentation(ActionsInstruction.class).getActionsList());\r
                 } else if (type.equals(ApplyActions.class)) {\r
-                    length += ActionsSerializer.computeLengthOfActions(\r
+                    final byte APPLY_ACTIONS_LENGTH = 8;\r
+                    length += APPLY_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions(\r
                             instruction.getAugmentation(ActionsInstruction.class).getActionsList());\r
                 } else if (type.equals(ClearActions.class)) {\r
                     final byte CLEAR_ACTIONS_LENGTH = 8;\r
@@ -124,7 +131,9 @@ public abstract class InstructionsSerializer {
                     length += METER_LENGTH;\r
                 } else if (type.equals(Experimenter.class)) {\r
                     final byte EXPERIMENTER_LENGTH = 8;\r
-                    length += EXPERIMENTER_LENGTH;\r
+                    ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class);\r
+                    byte[] data = experimenter.getData();\r
+                    length += EXPERIMENTER_LENGTH + data.length;\r
                 }\r
             }\r
         }\r
index c600fbf5103c6939fc5acb62bedf330e2f686046..4567a7b31da810ae907ca79b76272d7218abba58 100644 (file)
@@ -135,7 +135,7 @@ public abstract class MatchDeserializer {
     \r
     /**\r
      * Creates match\r
-     * @param in inputu ByteBuf\r
+     * @param in input ByteBuf\r
      * @return ofp_match\r
      */\r
     public static Match createMatch(ByteBuf in) {\r
@@ -157,7 +157,7 @@ public abstract class MatchDeserializer {
             builder.setMatchEntries(createMatchEntries(in, length - 2 * (Short.SIZE / Byte.SIZE)));\r
             int paddingRemainder = length % EncodeConstants.PADDING;\r
             if (paddingRemainder != 0) {\r
-                in.skipBytes(paddingRemainder);\r
+                in.skipBytes(EncodeConstants.PADDING - paddingRemainder);\r
             }\r
             return builder.build();\r
         }\r
@@ -166,15 +166,12 @@ public abstract class MatchDeserializer {
     \r
     /**\r
      * @param in input ByteBuf\r
-     * @param matchArrayLength to infer size of array\r
+     * @param matchLength to infer size of array\r
      * @return MatchEntriesList\r
      */\r
-    public static List<MatchEntries> createMatchEntries(ByteBuf in, int matchArrayLength) {\r
-        int currMatchLength = 0;\r
-        LOGGER.debug("createMatchEntries");\r
-        LOGGER.debug("matcharraylength: " + matchArrayLength);\r
-        while(currMatchLength < matchArrayLength) {\r
-            LOGGER.debug("creating new match entry");\r
+    public static List<MatchEntries> createMatchEntries(ByteBuf in, int matchLength) {\r
+        int currLength = 0;\r
+        while(currLength < matchLength) {\r
             switch (in.readUnsignedShort()) { \r
             case 0x0000:\r
                         matchEntriesBuilder.setOxmClass(Nxm0Class.class);\r
@@ -184,7 +181,6 @@ public abstract class MatchDeserializer {
                         break;\r
             case 0x8000:\r
                         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
-                        LOGGER.debug("ofbasicclass");\r
                         break;\r
             case 0xFFFF:\r
                         matchEntriesBuilder.setOxmClass(ExperimenterClass.class);\r
@@ -193,9 +189,11 @@ public abstract class MatchDeserializer {
                         break;\r
             }\r
 \r
-            int matchField = in.readUnsignedByte() >>> 1;\r
-            short matchEntryLength = in.readUnsignedByte();\r
-            currMatchLength = currMatchLength + SIZE_OF_SHORT_IN_BYTES + (2 * SIZE_OF_BYTE_IN_BYTES) + matchEntryLength;\r
+            int fieldAndMask = in.readUnsignedByte();\r
+            boolean hasMask = (fieldAndMask & 1) != 0;\r
+            int matchField =  fieldAndMask >> 1;\r
+            int matchEntryLength = in.readUnsignedByte();\r
+            currLength += SIZE_OF_SHORT_IN_BYTES + (2 * SIZE_OF_BYTE_IN_BYTES) + matchEntryLength;\r
             \r
             switch(matchField) {\r
             case 0: \r
@@ -213,25 +211,22 @@ public abstract class MatchDeserializer {
             case 2:\r
                 matchEntriesBuilder.setOxmMatchField(Metadata.class);\r
                 addMetadataAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_LONG_IN_BYTES);\r
                 }\r
                 break;\r
             case 3:\r
                 matchEntriesBuilder.setOxmMatchField(EthDst.class);\r
                 addMacAddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_LONG_IN_BYTES);\r
                 }\r
                 break;\r
             case 4:\r
                 matchEntriesBuilder.setOxmMatchField(EthSrc.class);\r
                 addMacAddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_LONG_IN_BYTES);\r
                 }\r
                 break;\r
             case 5:\r
@@ -247,9 +242,8 @@ public abstract class MatchDeserializer {
                 vlanVidBuilder.setCfiBit((vidEntryValue & 1) != 0);\r
                 vlanVidBuilder.setVlanVid(vidEntryValue >> 1);\r
                 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());\r
-                matchEntryLength -= SIZE_OF_SHORT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_SHORT_IN_BYTES);\r
                 }\r
                 break;\r
             case 7:\r
@@ -281,9 +275,8 @@ public abstract class MatchDeserializer {
                 // TODO - ipv4address - check format with tests\r
                 LOGGER.warn("IPV4address(ipv4src): received but possible wrong deserialization");\r
                 addIpv4AddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_INT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_INT_IN_BYTES);\r
                 }\r
                 break;\r
             case 12:\r
@@ -291,9 +284,8 @@ public abstract class MatchDeserializer {
                 // TODO - ipv4address - check format with tests\r
                 LOGGER.warn("IPV4address(ipv4dst): received but possible wrong deserialization");\r
                 addIpv4AddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_INT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_INT_IN_BYTES);\r
                 }\r
                 break;\r
             case 13:\r
@@ -343,9 +335,8 @@ public abstract class MatchDeserializer {
                 // TODO - ipv4address - check format with tests\r
                 LOGGER.warn("IPV4address(arpspa): received but possible wrong deserialization");\r
                 addIpv4AddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_INT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_INT_IN_BYTES);\r
                 }\r
                 break;\r
             case 23:\r
@@ -353,25 +344,22 @@ public abstract class MatchDeserializer {
                 // TODO - ipv4address - check format with tests\r
                 LOGGER.warn("IPV4address(arptpa): received but possible wrong deserialization");\r
                 addIpv4AddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_INT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_INT_IN_BYTES);\r
                 }\r
                 break;\r
             case 24:\r
                 matchEntriesBuilder.setOxmMatchField(ArpSha.class);\r
                 addMacAddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_LONG_IN_BYTES);\r
                 }\r
                 break;\r
             case 25:\r
                 matchEntriesBuilder.setOxmMatchField(ArpTha.class);\r
                 addMacAddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_LONG_IN_BYTES);\r
                 }\r
                 break;\r
             case 26:\r
@@ -379,9 +367,8 @@ public abstract class MatchDeserializer {
                 // TODO - ipv6address - check format with tests\r
                 LOGGER.warn("IPV6address(Ipv6Src): received but possible wrong deserialization");\r
                 addIpv6AddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
                 }\r
                 break;\r
             case 27:\r
@@ -389,9 +376,8 @@ public abstract class MatchDeserializer {
                 // TODO - ipv6address - check format with tests\r
                 LOGGER.warn("IPV6address(Ipv6Dst): received but possible wrong deserialization");\r
                 addIpv6AddressAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
                 }\r
                 break;\r
             case 28:\r
@@ -399,9 +385,8 @@ public abstract class MatchDeserializer {
                 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();\r
                 ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(in.readUnsignedInt()));\r
                 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());\r
-                matchEntryLength -= SIZE_OF_INT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_INT_IN_BYTES);\r
                 }\r
                 break;\r
             case 29:\r
@@ -457,17 +442,15 @@ public abstract class MatchDeserializer {
                 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();\r
                 isidBuilder.setIsid(in.readUnsignedInt());\r
                 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());\r
-                matchEntryLength -= SIZE_OF_INT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_INT_IN_BYTES);\r
                 }\r
                 break;\r
             case 38:\r
                 matchEntriesBuilder.setOxmMatchField(TunnelId.class);\r
                 addMetadataAugmentation(matchEntriesBuilder, in);\r
-                matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_LONG_IN_BYTES);\r
                 }\r
                 break;\r
             case 39:\r
@@ -485,9 +468,8 @@ public abstract class MatchDeserializer {
                 final Boolean UNSEQ = ((bitmap) & (1<<8)) != 0;\r
                 pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));\r
                 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());\r
-                matchEntryLength -= SIZE_OF_SHORT_IN_BYTES;\r
-                if (matchEntryLength > 0) {\r
-                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                if (hasMask) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, SIZE_OF_SHORT_IN_BYTES);\r
                 }\r
                 break;\r
             default: \r
index 6bf6a063f9d8533019d87ca5654febd9044d9de1..bb2bb5b06af4aab69202b170a9134d01ceb04971 100644 (file)
@@ -527,20 +527,15 @@ public class MatchSerializer {
                 } else if (field.equals(InPhyPort.class)) {\r
                     length += Integer.SIZE / Byte.SIZE;\r
                 } else if (field.equals(Metadata.class)) {\r
-                    computeMetadataRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(EthDst.class)) {\r
-                    computeMacAddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(EthSrc.class)) {\r
-                    computeMacAddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(EthType.class)) {\r
                     length += Short.SIZE / Byte.SIZE;\r
                 } else if (field.equals(VlanVid.class)) {\r
-                    if (entry.isHasMask()) {\r
-                        byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-                        length += Short.SIZE / Byte.SIZE + mask.length;\r
-                    } else {\r
-                        length += Short.SIZE / Byte.SIZE;\r
-                    }\r
+                    length += computePossibleMaskEntryLength(entry, Short.SIZE / Byte.SIZE);\r
                 } else if (field.equals(VlanPcp.class)) {\r
                     length += Byte.SIZE / Byte.SIZE;\r
                 } else if (field.equals(IpDscp.class)) {\r
@@ -550,9 +545,9 @@ public class MatchSerializer {
                 } else if (field.equals(IpProto.class)) {\r
                     length += Byte.SIZE / Byte.SIZE;\r
                 } else if (field.equals(Ipv4Src.class)) {\r
-                    computeIpv4AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Integer.SIZE / Byte.SIZE);\r
                 } else if (field.equals(Ipv4Dst.class)) {\r
-                    computeIpv4AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Integer.SIZE / Byte.SIZE);\r
                 } else if (field.equals(TcpSrc.class)) {\r
                     length += Short.SIZE / Byte.SIZE;\r
                 } else if (field.equals(TcpDst.class)) {\r
@@ -572,34 +567,29 @@ public class MatchSerializer {
                 } else if (field.equals(ArpOp.class)) {\r
                     length += Short.SIZE / Byte.SIZE;\r
                 } else if (field.equals(ArpSpa.class)) {\r
-                    computeIpv4AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Integer.SIZE / Byte.SIZE);\r
                 } else if (field.equals(ArpTpa.class)) {\r
-                    computeIpv4AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Integer.SIZE / Byte.SIZE);\r
                 } else if (field.equals(ArpSha.class)) {\r
-                    computeMacAddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(ArpTha.class)) {\r
-                    computeMacAddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(Ipv6Src.class)) {\r
-                    computeIpv6AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, 8 * (Short.SIZE / Byte.SIZE));\r
                 } else if (field.equals(Ipv6Dst.class)) {\r
-                    computeIpv6AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, 8 * (Short.SIZE / Byte.SIZE));\r
                 } else if (field.equals(Ipv6Flabel.class)) {\r
-                    if (entry.isHasMask()) {\r
-                        byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-                        length += Integer.SIZE / Byte.SIZE + mask.length; // 20 b + mask [OF 1.3.2 spec]\r
-                    } else {\r
-                        length += Integer.SIZE / Byte.SIZE;\r
-                    }\r
+                    length += computePossibleMaskEntryLength(entry, Integer.SIZE / Byte.SIZE);\r
                 } else if (field.equals(Icmpv6Type.class)) {\r
                     length += Byte.SIZE / Byte.SIZE;\r
                 } else if (field.equals(Icmpv6Code.class)) {\r
                     length += Byte.SIZE / Byte.SIZE;\r
                 } else if (field.equals(Ipv6NdTarget.class)) {\r
-                    computeIpv6AddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, 8 * (Short.SIZE / Byte.SIZE));\r
                 } else if (field.equals(Ipv6NdSll.class)) {\r
-                    computeMacAddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(Ipv6NdTll.class)) {\r
-                    computeMacAddressRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(MplsLabel.class)) {\r
                     length += Integer.SIZE / Byte.SIZE;\r
                 } else if (field.equals(MplsTc.class)) {\r
@@ -607,57 +597,23 @@ public class MatchSerializer {
                 } else if (field.equals(MplsBos.class)) {\r
                     length += Byte.SIZE / Byte.SIZE;\r
                 } else if (field.equals(PbbIsid.class)) {\r
-                    if (entry.isHasMask()) {\r
-                        byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-                        length += Long.SIZE / Byte.SIZE + mask.length;\r
-                    } else {\r
-                        length += Long.SIZE / Byte.SIZE;\r
-                    }\r
+                    length += computePossibleMaskEntryLength(entry, Integer.SIZE / Byte.SIZE);\r
                 } else if (field.equals(TunnelId.class)) {\r
-                    computeMetadataRelatedEntryLength(entry);\r
+                    length += computePossibleMaskEntryLength(entry, Long.SIZE / Byte.SIZE);\r
                 } else if (field.equals(Ipv6Exthdr.class)) {\r
-                    if (entry.isHasMask()) {\r
-                        byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-                        length += Short.SIZE / Byte.SIZE + mask.length;\r
-                    } else {\r
-                        length += Short.SIZE / Byte.SIZE;\r
-                    }\r
+                    length += computePossibleMaskEntryLength(entry, Short.SIZE / Byte.SIZE);\r
                 }\r
             }\r
         }\r
         return length;\r
     }\r
-    \r
-    private static int computeMetadataRelatedEntryLength(MatchEntries entry) {\r
-        if (entry.isHasMask()) {\r
-            byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-            return Long.SIZE / Byte.SIZE + mask.length;\r
-        }\r
-        return Long.SIZE / Byte.SIZE;\r
-    }\r
-    \r
-    private static int computeMacAddressRelatedEntryLength(MatchEntries entry) {\r
-        if (entry.isHasMask()) {\r
-            byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-            return (Integer.SIZE + Short.SIZE) / Byte.SIZE + mask.length; // 48 b + mask [OF 1.3.2 spec]\r
-        }\r
-        return (Integer.SIZE + Short.SIZE) / Byte.SIZE; // 48 b [OF 1.3.2 spec]\r
-    }\r
-    \r
-    private static int computeIpv4AddressRelatedEntryLength(MatchEntries entry) {\r
-        if (entry.isHasMask()) {\r
-            byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-            return Integer.SIZE / Byte.SIZE + mask.length;\r
-        }\r
-        return Integer.SIZE / Byte.SIZE;\r
-    }\r
-    \r
-    private static int computeIpv6AddressRelatedEntryLength(MatchEntries entry) {\r
+\r
+    private static int computePossibleMaskEntryLength(MatchEntries entry, int length) {\r
+        int entryLength = length;\r
         if (entry.isHasMask()) {\r
-            byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
-            return (8 * Short.SIZE) / Byte.SIZE + mask.length;\r
+            entryLength *= 2;\r
         }\r
-        return (8 * Short.SIZE) / Byte.SIZE;\r
+        return entryLength;\r
     }\r
 \r
 }\r
index a361fc761af452b968bdf8c91578e36a88673c36..27bcafd681dd97f5927ef09550dc4b5a2c2a7a41 100644 (file)
@@ -249,7 +249,7 @@ public class OF10ActionsDeserializer {
     \r
     private static void createPortAugmentation(ByteBuf input, ActionBuilder actionBuilder) {\r
         PortActionBuilder portBuilder = new PortActionBuilder();\r
-        portBuilder.setPort(new PortNumber(new Long(input.readUnsignedShort())));\r
+        portBuilder.setPort(new PortNumber((long) input.readUnsignedShort()));\r
         actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
     }\r
 \r