Added support for OF 1.0
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / MatchDeserializer.java
index c2d571ea794e3f25aa20953945dec60ec0201e63..c600fbf5103c6939fc5acb62bedf330e2f686046 100644 (file)
@@ -6,6 +6,7 @@ import io.netty.buffer.ByteBuf;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EncodeConstants;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
@@ -139,23 +140,25 @@ public abstract class MatchDeserializer {
      */\r
     public static Match createMatch(ByteBuf in) {\r
         if (in.readableBytes() > 0) {\r
-            final byte PADDING_IN_MATCH = 4;\r
             MatchBuilder builder = new MatchBuilder();\r
             int type = in.readUnsignedShort();\r
             int length = in.readUnsignedShort();\r
+            LOGGER.debug("length: " + length);\r
             switch (type) {\r
             case 0:\r
                 builder.setType(StandardMatchType.class);\r
-                builder.setMatchEntries(createMatchEntries(in, length - 2 * Short.SIZE));\r
                 break;\r
             case 1:\r
                 builder.setType(OxmMatchType.class);\r
-                builder.setMatchEntries(createMatchEntries(in, length - 2 * Short.SIZE));\r
                 break;\r
             default:\r
                 break;\r
             }\r
-            in.skipBytes(PADDING_IN_MATCH);\r
+            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
+            }\r
             return builder.build();\r
         }\r
         return null;\r
@@ -168,7 +171,10 @@ public abstract class MatchDeserializer {
      */\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
             switch (in.readUnsignedShort()) { \r
             case 0x0000:\r
                         matchEntriesBuilder.setOxmClass(Nxm0Class.class);\r
@@ -178,6 +184,7 @@ 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
@@ -205,7 +212,6 @@ public abstract class MatchDeserializer {
                 break;\r
             case 2:\r
                 matchEntriesBuilder.setOxmMatchField(Metadata.class);\r
-                currMatchLength = matchEntryLength;\r
                 addMetadataAugmentation(matchEntriesBuilder, in);\r
                 matchEntryLength -= SIZE_OF_LONG_IN_BYTES;\r
                 if (matchEntryLength > 0) {\r
@@ -489,7 +495,6 @@ public abstract class MatchDeserializer {
             }\r
           matchEntriesList.add(matchEntriesBuilder.build());\r
         }\r
-        \r
         return matchEntriesList;\r
     }\r
 \r