Match and actions (de)serialization + fix 91/2391/2
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 4 Nov 2013 08:07:34 +0000 (09:07 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 5 Nov 2013 14:35:32 +0000 (15:35 +0100)
YANG files - added missing instructions in some messages
YANG files - unified bucketslist, actionslist

Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
Change-Id: Ia2865fdf389248554c4fdea8a0d84e9705c8086e

19 files changed:
openflow-protocol-api/src/main/yang/openflow-action.yang
openflow-protocol-api/src/main/yang/openflow-augments.yang
openflow-protocol-api/src/main/yang/openflow-extensible-match.yang
openflow-protocol-api/src/main/yang/openflow-protocol.yang
openflow-protocol-api/src/main/yang/openflow-types.yang
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java [moved from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionCreator.java with 72% similarity]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntriesCreator.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntriesDeserializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java
pom.xml

index 2b244ac98c4fcecf1fef6adbf13e4f13aa63fdcc..77dca25ee3aa1eb3c9ba8d468e7c4188a6b54e16 100644 (file)
@@ -76,10 +76,16 @@ module openflow-action {
         description "";
         base oft:action;
     }
-
+    
     container actions-container {
         uses action-header;
     }
+    
+    grouping actions {
+        list actions-list {
+            uses action-header;
+        }
+    }
 
     grouping action-header {
         container action {
index 75c6590b96c6e6d032f6a4d9d029394a105d23ad..a62f91ac0ffc026a39ba5cbe02358c268055e6ea 100644 (file)
@@ -77,12 +77,6 @@ module openflow-augments {
              type uint8;\r
          }\r
      }\r
-     augment "/oxm:oxm-container/oxm:match-entries" {\r
-         ext:augment-identifier "ipv4-prefix-match-entry";\r
-         leaf ipv4-prefix {\r
-             type inet:ipv4-prefix;\r
-         }\r
-     }\r
      augment "/oxm:oxm-container/oxm:match-entries" {\r
          ext:augment-identifier "port-match-entry";\r
          leaf port {\r
@@ -107,12 +101,6 @@ module openflow-augments {
              type uint16;\r
          }\r
      }\r
-     augment "/oxm:oxm-container/oxm:match-entries" {\r
-         ext:augment-identifier "ipv6-prefix-match-entry";\r
-         leaf ipv6-prefix {\r
-             type inet:ipv6-prefix;\r
-         }\r
-     }\r
      augment "/oxm:oxm-container/oxm:match-entries" {\r
          ext:augment-identifier "ipv6-flabel-match-entry";\r
          leaf ipv6-flabel {\r
@@ -137,6 +125,12 @@ module openflow-augments {
              type inet:ipv6-address;\r
          }\r
      }\r
+     augment "/oxm:oxm-container/oxm:match-entries" {\r
+         ext:augment-identifier "ipv4-address-match-entry";\r
+         leaf ipv4-address {\r
+             type inet:ipv4-address;\r
+         }\r
+     }\r
      augment "/oxm:oxm-container/oxm:match-entries" {\r
          ext:augment-identifier "mpls-label-match-entry";\r
          leaf mpls-label {\r
@@ -209,7 +203,7 @@ module openflow-augments {
      augment "/ofaction:actions-container/ofaction:action" {\r
          ext:augment-identifier "port-action";\r
          leaf port {\r
-             type oft:any-port-number;\r
+             type oft:port-number;\r
          }\r
      }\r
      augment "/ofaction:actions-container/ofaction:action" {\r
index 05afce9f6f40df62794036f68c49d0f84758b25c..46849a7f42aece6cd77e7d58b8fc650849300c6e 100644 (file)
@@ -223,6 +223,9 @@ module openflow-extensible-match {
                         base match-field;
                     }
                 }
+                leaf has-mask {
+                    type boolean;
+                } 
             }
         }
         
index cca7011f2b0d79466c31c3530f2b4971e15bffb3..7f65a22b444aca36113425f860750d289359dd7d 100644 (file)
@@ -80,6 +80,26 @@ module openflow-protocol {
             uses oxm:oxm-fields;\r
         }\r
 \r
+        grouping buckets {\r
+                list buckets-list {\r
+                    uses bucket;\r
+                }\r
+            }\r
+            \r
+            grouping bucket {\r
+                leaf weight {\r
+                    type uint16;\r
+                }\r
+                leaf watch-port {\r
+                    type oft:port-number;\r
+                }\r
+                leaf watch-group {\r
+                    type uint32;\r
+                }\r
+                \r
+                uses ofaction:actions;\r
+            }\r
+            \r
         container table-features-properties-container {\r
             uses table-features-properties;\r
         }\r
@@ -339,14 +359,11 @@ module openflow-protocol {
                 \r
                 uses ofHeader;\r
                 \r
-                list actions-list {\r
-                    uses ofaction:action-header;\r
-                    \r
-                    leaf data {\r
-                        type binary;\r
-                    }\r
-                }\r
+                uses ofaction:actions;\r
                 \r
+                leaf data {\r
+                    type binary;\r
+                }\r
                 leaf buffer-id {\r
                     type uint32;\r
                 }\r
@@ -396,6 +413,8 @@ module openflow-protocol {
                 container match {\r
                     uses match;\r
                 }\r
+                \r
+                uses ofinstruction:instructions;\r
             } \r
             grouping group-mod {\r
                 // reference "OFPT_GROUP_MOD message in Openflow Switch 1.3 Spec"\r
@@ -413,24 +432,9 @@ module openflow-protocol {
                     type uint32;\r
                 }\r
                 \r
-                list buckets-list {\r
-                    uses bucket;\r
-                }\r
-            }\r
-            grouping bucket {\r
-                leaf weight {\r
-                    type uint16;\r
-                }\r
-                leaf watch-port {\r
-                    type oft:port-number;\r
-                }\r
-                leaf watch-group {\r
-                    type uint32;\r
-                }\r
-                list actions-list {\r
-                    uses ofaction:action-header;\r
-                }\r
+                uses buckets;\r
             }\r
+            \r
             grouping port-mod {\r
                 // reference "OFPT_PORT_MOD message in Openflow Switch 1.3 Spec"\r
                 /* Controller/switch message */\r
@@ -647,6 +651,8 @@ module openflow-protocol {
                             container match {\r
                                 uses match;\r
                             }\r
+                            \r
+                            uses ofinstruction:instructions;\r
                         }\r
                     }\r
                     case multipart-reply-aggregate {\r
@@ -789,9 +795,7 @@ module openflow-protocol {
                             leaf group-id {\r
                                 type uint32;\r
                             }\r
-                            list buckets-list {\r
-                                uses bucket;\r
-                            }\r
+                            uses buckets;\r
                         }\r
                     }\r
                     case multipart-reply-group-features {\r
@@ -804,12 +808,8 @@ module openflow-protocol {
                         leaf-list max_groups {\r
                             type uint32;\r
                         }\r
-                        //leaf-list actions {\r
-                        //    type ofaction:action-type;\r
-                        //}\r
-                        list actions-list {\r
-                            uses ofaction:action-header;\r
-                        }\r
+                        \r
+                        uses ofaction:actions;\r
                     }\r
                     case multipart-reply-meter {\r
                         list meter-stats {\r
@@ -891,6 +891,7 @@ module openflow-protocol {
                             leaf max-entries {\r
                                 type uint32;\r
                             }\r
+                            uses table-features-properties;\r
                         }\r
                     }\r
                     case multipart-reply-port-desc {\r
index f2254db73c2b4d2a3f1b6f1fde6458197422bffb..a2b11ddb6c05312198c11826782b870bf911ff72 100644 (file)
@@ -185,13 +185,13 @@ module openflow-types {
         base oft:match-type-base;
     }
 
-    typedef match-type {
-        //type identityref {
-        //    base oft:match-type-base;
-        //}
+    typedef oxm-match-type {
+        type identityref {
+            base oft:match-type-base;
+        }
         
         //TODO: use identityref, when generating available
-        type string;
+        //type string;
     }
 
     identity instruction {
index a8011b81506e4289687c29f9ed7bfe5a3e81a13d..2a2bba56a9d9cf040b7ebbde1f77f42d76b49ba7 100644 (file)
@@ -8,10 +8,13 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ActionCreator;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+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.types.rev130731.FlowModFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterModCommand;\r
@@ -23,10 +26,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.bucket.ActionsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.MultipartReplyBody;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc;\r
@@ -39,6 +44,7 @@ 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.MultipartReplyGroupBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeter;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig;\r
@@ -59,8 +65,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.multipart.reply.group.GroupStatsBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc.GroupDesc;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc.GroupDescBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc.group.desc.BucketsList;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc.group.desc.BucketsListBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.group.stats.BucketStats;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.group.stats.BucketStatsBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.MeterStats;\r
@@ -111,8 +115,6 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         builder.setType(MultipartType.forValue(rawMessage.readUnsignedShort()));\r
         builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0));\r
         rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER);\r
-        // TODO - implement body\r
-        //mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
 \r
         switch (builder.getType().getIntValue()) {\r
         case 0:  builder.setMultipartReplyBody(setDesc(rawMessage));\r
@@ -131,9 +133,11 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
                  break;\r
         case 7:  builder.setMultipartReplyBody(setGroupDesc(rawMessage));\r
                  break;\r
+        case 8:  builder.setMultipartReplyBody(setGroupFeatures(rawMessage));\r
+                 break;\r
         case 9:  builder.setMultipartReplyBody(setMeter(rawMessage));\r
                  break;\r
-        case 10:  builder.setMultipartReplyBody(setMeterConfig(rawMessage));\r
+        case 10: builder.setMultipartReplyBody(setMeterConfig(rawMessage));\r
                  break;\r
         case 11: builder.setMultipartReplyBody(setMeterFeatures(rawMessage));\r
                  break;\r
@@ -212,11 +216,11 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
     }\r
     \r
     private static FlowModFlags createFlowModFalgsFromBitmap(short input){\r
-        final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) > 0;\r
-        final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) > 0;\r
-        final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) > 0; \r
-        final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) > 0;\r
-        final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) > 0;\r
+        final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) != 0;\r
+        final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) != 0;\r
+        final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) != 0; \r
+        final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) != 0;\r
+        final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) != 0;\r
         return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM);\r
     }\r
     \r
@@ -416,10 +420,10 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
     }\r
     \r
     private static MeterFlags decodeMeterModFlags(int input){\r
-        final Boolean _oFPMFKBPS = (input & (1 << 0)) > 0;\r
-        final Boolean _oFPMFPKTPS = (input & (1 << 1)) > 0;\r
-        final Boolean _oFPMFBURST = (input & (1 << 2)) > 0; \r
-        final Boolean _oFPMFSTATS = (input & (1 << 3)) > 0;\r
+        final Boolean _oFPMFKBPS = (input & (1 << 0)) != 0;\r
+        final Boolean _oFPMFPKTPS = (input & (1 << 1)) != 0;\r
+        final Boolean _oFPMFBURST = (input & (1 << 2)) != 0; \r
+        final Boolean _oFPMFSTATS = (input & (1 << 3)) != 0;\r
         return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS);\r
     }\r
     \r
@@ -478,7 +482,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();\r
         List<MeterConfig> meterConfigList = new ArrayList<>();\r
         MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder();\r
-        List<Bands> bandsList = new ArrayList<Bands>();\r
+        List<Bands> bandsList = new ArrayList<>();\r
         BandsBuilder bandsBuilder = new BandsBuilder();\r
         \r
         while (input.readableBytes() > 0) {\r
@@ -620,6 +624,37 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
                 _40gbFd, _100gbFd, _1tbFd, _other, _copper, _fiber, _autoneg, _pause, _pauseAsym);\r
     }\r
     \r
+    private static MultipartReplyBody setGroupFeatures(ByteBuf rawMessage) {\r
+        final int SIZE_OF_MAX_GROUPS = 4;\r
+        MultipartReplyGroupFeaturesBuilder featuresBuilder = new MultipartReplyGroupFeaturesBuilder();\r
+        featuresBuilder.setTypes(createGroupType(rawMessage.readUnsignedInt()));\r
+        featuresBuilder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));\r
+        List<Long> maxGroupsList = new ArrayList<>();\r
+        for (int i = 0; i < SIZE_OF_MAX_GROUPS ; i++) {\r
+            maxGroupsList.add(rawMessage.readUnsignedInt());\r
+        }\r
+        featuresBuilder.setMaxGroups(maxGroupsList);\r
+        // TODO - groupfeatures - actions bitmap\r
+        rawMessage.skipBytes(4);\r
+        return featuresBuilder.build();\r
+    }\r
+\r
+    private static GroupCapabilities createCapabilities(long input) {\r
+        final Boolean OFOFPGFC_SELECT_WEIGHT = ((input) & (1<<0)) != 0;\r
+        final Boolean OFPGFC_SELECT_LIVENESS = ((input) & (1<<1)) != 0;\r
+        final Boolean OFPGFC_CHAINING = ((input) & (1<<2)) != 0;\r
+        final Boolean OFPGFC_CHAINING_CHECKS = ((input) & (1<<3)) != 0;\r
+        return new GroupCapabilities(OFPGFC_CHAINING, OFPGFC_CHAINING_CHECKS, OFPGFC_SELECT_LIVENESS, OFOFPGFC_SELECT_WEIGHT);\r
+    }\r
+\r
+    private static GroupTypes createGroupType(long input) {\r
+        final Boolean OFPGT_ALL = ((input) & (1<<0)) != 0;\r
+        final Boolean OFPGT_SELECT = ((input) & (1<<1)) != 0;\r
+        final Boolean OFPGT_INDIRECT = ((input) & (1<<2)) != 0;\r
+        final Boolean OFPGT_FF = ((input) & (1<<3)) != 0;\r
+        return new GroupTypes(OFPGT_ALL, OFPGT_FF, OFPGT_INDIRECT, OFPGT_SELECT);\r
+    }\r
+    \r
     private static MultipartReplyGroupDesc setGroupDesc(ByteBuf input) {\r
         final byte PADDING_IN_GROUP_DESC_HEADER = 1;\r
         final byte PADDING_IN_BUCKETS_HEADER = 4;\r
@@ -652,7 +687,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
                 bucketsBuilder.setWatchGroup(input.readUnsignedInt());\r
                 input.skipBytes(PADDING_IN_BUCKETS_HEADER);\r
                 bucketsCurrentLength = bucketsLength;\r
-                actionsList = ActionCreator.createActionsList(input, bucketsLength);\r
+                actionsList = ActionsDeserializer.createActionsList(input, bucketsLength);\r
                 bucketsBuilder.setActionsList(new ArrayList<>(actionsList));\r
                 actionsList.clear();\r
                 bucketsList.add(bucketsBuilder.build());\r
index 0148ffb920d311781a559d3f7662f38e9070862b..1413063f87f3dc3235d84ba72cc49ab64d4cd385 100644 (file)
@@ -22,6 +22,7 @@ public interface OFSerializer <E extends DataObject> {
     \r
     /**\r
      * Compute length of received message\r
+     * @param message TODO\r
      * @return computed length\r
      */\r
     public abstract int computeLength(E message);\r
index 0a914269d2bbbc4c22bb26bc7a9c66ac5a2df177..6fa791d3f53574761161eb509e6e04c9066c1555 100644 (file)
@@ -3,13 +3,13 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 \r
 import io.netty.buffer.ByteBuf;\r
 \r
-import java.util.Iterator;\r
 import java.util.List;\r
 \r
 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;\r
 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList;\r
 \r
 /**\r
  * @author timotej.kubas\r
@@ -18,9 +18,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class GroupModInputMessageFactory implements OFSerializer<GroupModInput> {\r
     private static final byte MESSAGE_TYPE = 15;\r
     private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;\r
-    private static final int MESSAGE_LENGTH = 16; \r
+    private static final int MESSAGE_LENGTH = 16;\r
+    private static final byte LENGTH_OF_BUCKET_STRUCTURE = 16;\r
     private static GroupModInputMessageFactory instance;\r
-    \r
+\r
     private GroupModInputMessageFactory() {\r
         // singleton\r
     }\r
@@ -48,7 +49,7 @@ public class GroupModInputMessageFactory implements OFSerializer<GroupModInput>
 \r
     @Override\r
     public int computeLength(GroupModInput message) {\r
-        return MESSAGE_LENGTH;\r
+        return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList());\r
     }\r
 \r
     @Override\r
@@ -58,16 +59,35 @@ public class GroupModInputMessageFactory implements OFSerializer<GroupModInput>
     \r
     private static void encodeBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {\r
         final byte PADDING_IN_BUCKET = 4;\r
-        \r
-        for (Iterator<BucketsList> iterator = buckets.iterator(); iterator.hasNext();) {\r
-            BucketsList currentBucket = iterator.next();\r
-            // TODO get method for field length missing\r
-            outBuffer.writeShort(currentBucket.getWeight().intValue());\r
-            outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());\r
-            outBuffer.writeInt(currentBucket.getWatchGroup().intValue());\r
-            ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);\r
-            // TODO actions structure missing\r
+        if (buckets != null) {\r
+            for (BucketsList currentBucket : buckets) {\r
+                outBuffer.writeShort(computeLengthOfBucket(currentBucket));\r
+                outBuffer.writeShort(currentBucket.getWeight().shortValue());\r
+                outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());\r
+                outBuffer.writeInt(currentBucket.getWatchGroup().intValue());\r
+                ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);\r
+                ActionsSerializer.encodeActions(currentBucket.getActionsList(), outBuffer);\r
+            }\r
+        }\r
+    }\r
+    \r
+    private static int computeLengthOfBucket(BucketsList bucket) {\r
+        int lengthOfBuckets = 0;\r
+        if (bucket != null) {\r
+            lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(bucket.getActionsList());\r
         }\r
+        return lengthOfBuckets;\r
+    }\r
+    \r
+    private static int computeLengthOfBuckets(List<BucketsList> buckets) {\r
+        int lengthOfBuckets = 0;\r
+        if (buckets != null) {\r
+            for (BucketsList currentBucket : buckets) {\r
+                lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(currentBucket.getActionsList());\r
+            }\r
+        }\r
+        return lengthOfBuckets;\r
     }\r
 \r
+    \r
 }\r
index d2b7f33ce080a2d7dd307c4cba8923d681c143d7..e6877ccc9ff1a1d744de4f74c2ad7321d21b067d 100644 (file)
@@ -22,6 +22,7 @@ public class HelloInputMessageFactory implements OFSerializer<HelloInput>{
     /** Code type of Hello message */\r
     private static final byte MESSAGE_TYPE = 0;\r
     private static int MESSAGE_LENGTH = 8;\r
+    /** Size of hello element header (in bytes) */\r
     public static final byte HELLO_ELEMENT_HEADER_SIZE = 4;\r
     private static HelloInputMessageFactory instance;\r
     \r
index dd3f72b22d5703a6cc67f874fa54e2fbe68ecb96..a05aefe3066135d3c33ca18841dfc8494e01e653 100644 (file)
@@ -4,6 +4,7 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 \r
 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;\r
 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
 \r
@@ -40,11 +41,10 @@ public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput
         out.writeInt(message.getBufferId().intValue());\r
         out.writeInt(message.getInPort().getValue().intValue());\r
         ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);\r
+        ActionsSerializer.encodeActions(message.getActionsList(), out);\r
         // TODO - finish implementation after Action serialization is done\r
         //out.writeShort(message.getActions().size());\r
-        // TODO - data field is not clearly defined\r
-        \r
-       \r
+        //out.writeBytes(message.getData());\r
     }\r
 \r
     @Override\r
similarity index 72%
rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionCreator.java
rename to openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java
index 3610d73535d588bd6b95b8c0dc95e338d65cea91..b92b30cd2a6ac5186d2107b01b2f5aa16743c499 100644 (file)
@@ -42,137 +42,121 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.action.header.ActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.AnyPortNumber;\r
+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.action.rev130731.actions.ActionsListBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.bucket.ActionsList;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.bucket.ActionsListBuilder;\r
 \r
 /**\r
- * Class for easy creation of actions\r
+ * Class for easy deserialization of actions\r
  * \r
  * @author timotej.kubas\r
  * @author michal.polkorab\r
  */\r
-public abstract class ActionCreator {\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
-/**\r
- * @param inp input ByteBuf\r
- * @param bucketsLength length of buckets\r
- * @return ActionsList\r
- */\r
-    public static List<ActionsList> createActionsList(ByteBuf inp, int bucketsLength) {\r
+    \r
+    /**\r
+     * @param input input ByteBuf\r
+     * @param bucketsLength length of buckets\r
+     * @return ActionsList\r
+     */\r
+    public static List<ActionsList> createActionsList(ByteBuf input, int bucketsLength) {\r
         final byte BUCKET_HEADER_LENGTH = 16;\r
         int bucketsCurrentLength = BUCKET_HEADER_LENGTH;\r
         int actionsLength = 0;\r
             \r
             while (bucketsCurrentLength < bucketsLength) {\r
-                switch(inp.readUnsignedShort()) {\r
-                case 0: actionsLength = inp.readUnsignedShort(); //outputActionLength\r
-                        actionsList.add(ActionCreator.createOutputAction(inp));\r
-                        bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                switch(input.readUnsignedShort()) {\r
+                case 0: actionsLength = input.readUnsignedShort(); //outputActionLength\r
+                        actionsList.add(ActionsDeserializer.createOutputAction(input));\r
                         break;\r
                 case 11: \r
-                         actionsLength = inp.readUnsignedShort();//empty header length\r
-                         actionsList.add(ActionCreator.createCopyTtlOutAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//empty header length\r
+                         actionsList.add(ActionsDeserializer.createCopyTtlOutAction(input));\r
                          break;\r
                          \r
                 case 12: \r
-                         actionsLength = inp.readUnsignedShort();//empty header length\r
-                         actionsList.add(ActionCreator.createCopyTtlInAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//empty header length\r
+                         actionsList.add(ActionsDeserializer.createCopyTtlInAction(input));\r
                          break;\r
                 \r
                 case 15: \r
-                         actionsLength = inp.readUnsignedShort();//empty header length\r
-                         actionsList.add(ActionCreator.createSetMplsTtlAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//empty header length\r
+                         actionsList.add(ActionsDeserializer.createSetMplsTtlAction(input));\r
                          break;\r
                          \r
                 case 16:                              \r
-                         actionsLength = inp.readUnsignedShort();//empty header length\r
-                         actionsList.add(ActionCreator.createDecMplsTtlOutAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//empty header length\r
+                         actionsList.add(ActionsDeserializer.createDecMplsTtlOutAction(input));\r
                          break;\r
                          \r
                 case 17: \r
-                         actionsLength = inp.readUnsignedShort();\r
-                         actionsList.add(ActionCreator.createPushVlanAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();\r
+                         actionsList.add(ActionsDeserializer.createPushVlanAction(input));\r
                          break;\r
                          \r
                 case 18:                              \r
-                         actionsLength = inp.readUnsignedShort();//empty header length\r
-                         actionsList.add(ActionCreator.createPopVlanAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//empty header length\r
+                         actionsList.add(ActionsDeserializer.createPopVlanAction(input));\r
                          break;\r
                          \r
                 case 19: \r
-                         actionsLength = inp.readUnsignedShort();//8\r
-                         actionsList.add(ActionCreator.createPushMplsAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//8\r
+                         actionsList.add(ActionsDeserializer.createPushMplsAction(input));\r
                          break;\r
                          \r
                 case 20: \r
-                         actionsLength = inp.readUnsignedShort();//8\r
-                         actionsList.add(ActionCreator.createPopMplsAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//8\r
+                         actionsList.add(ActionsDeserializer.createPopMplsAction(input));\r
                          break;\r
                          \r
                 case 21: \r
-                         actionsLength = inp.readUnsignedShort();\r
-                         actionsList.add(ActionCreator.createSetQueueAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();\r
+                         actionsList.add(ActionsDeserializer.createSetQueueAction(input));\r
                          break;\r
                          \r
                 case 22: \r
-                        actionsLength = inp.readUnsignedShort();//8\r
-                        actionsList.add(ActionCreator.createGroupAction(inp));\r
-                        bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                        actionsLength = input.readUnsignedShort();//8\r
+                        actionsList.add(ActionsDeserializer.createGroupAction(input));\r
                         break;\r
                         \r
                 case 23: \r
-                         actionsLength = inp.readUnsignedShort();//8\r
-                         actionsList.add(ActionCreator.createSetNwTtlAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//8\r
+                         actionsList.add(ActionsDeserializer.createSetNwTtlAction(input));\r
                          break;\r
                         \r
                 case 24:                              \r
-                        actionsLength = inp.readUnsignedShort();//empty header length\r
-                        actionsList.add(ActionCreator.createDecNwTtlAction(inp));\r
-                        bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                        actionsLength = input.readUnsignedShort();//empty header length\r
+                        actionsList.add(ActionsDeserializer.createDecNwTtlAction(input));\r
                         break;\r
                         \r
                 case 25:\r
-                        actionsLength = inp.readUnsignedShort();//8\r
+                        actionsLength = input.readUnsignedShort();//8\r
                         //TODO field\r
-                        actionsList.add(ActionCreator.createSetFieldAction(inp, actionsLength));\r
-                        bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                        actionsList.add(ActionsDeserializer.createSetFieldAction(input, actionsLength));\r
                         break; \r
                 case 26: \r
-                         actionsLength = inp.readUnsignedShort();//8\r
-                         actionsList.add(ActionCreator.createPushPbbAction(inp));\r
-                         bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                         actionsLength = input.readUnsignedShort();//8\r
+                         actionsList.add(ActionsDeserializer.createPushPbbAction(input));\r
                          break;\r
                          \r
                 case 27:                              \r
-                        actionsLength = inp.readUnsignedShort();//empty header length\r
-                        actionsList.add(ActionCreator.createPopPbbAction(inp));\r
-                        bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                        actionsLength = input.readUnsignedShort();//empty header length\r
+                        actionsList.add(ActionsDeserializer.createPopPbbAction(input));\r
                         break;\r
                         \r
                 case 0xFFFF: \r
-                        actionsLength = inp.readUnsignedShort();\r
-                        actionsList.add(ActionCreator.createExperimenterAction(inp));\r
-                        bucketsCurrentLength = bucketsCurrentLength + actionsLength;\r
+                        actionsLength = input.readUnsignedShort();\r
+                        actionsList.add(ActionsDeserializer.createExperimenterAction(input));\r
                         break;\r
                 default: \r
                          break;\r
                 }\r
+                bucketsCurrentLength += actionsLength;\r
             } \r
         return actionsList;\r
     }\r
@@ -249,7 +233,7 @@ public abstract class ActionCreator {
         \r
         actionBuilder.setType(Output.class);\r
         PortActionBuilder port = new PortActionBuilder();\r
-        port.setPort(new AnyPortNumber(new PortNumber(in.readUnsignedInt())));\r
+        port.setPort(new PortNumber(in.readUnsignedInt()));\r
         actionBuilder.addAugmentation(PortAction.class, port.build());\r
         MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();\r
         maxLen.setMaxLength(in.readUnsignedShort());\r
@@ -394,7 +378,7 @@ public abstract class ActionCreator {
     public static ActionsList createSetFieldAction(ByteBuf in, int actionLength) {\r
         actionBuilder.setType(SetField.class);\r
         OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();\r
-        matchEntries.setMatchEntries(MatchEntriesCreator.createMatchEntry(in, actionLength - 4));\r
+        matchEntries.setMatchEntries(MatchEntriesDeserializer.createMatchEntry(in, actionLength - 4));\r
         actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build());\r
         actionsListBuilder.setAction(actionBuilder.build());\r
         \r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java
new file mode 100644 (file)
index 0000000..c95cb4b
--- /dev/null
@@ -0,0 +1,267 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.action.header.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * Class for easy serialization of actions\r
+ * \r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public abstract class ActionsSerializer {\r
+\r
+    private static final Logger LOGGER = LoggerFactory.getLogger(ActionsSerializer.class);\r
+\r
+    /**\r
+     * Encodes actions to ByteBuf\r
+     * @param actionsList list of actions to be encoded\r
+     * @param outBuffer output ByteBuf\r
+     */\r
+    public static void encodeActions(List<ActionsList> actionsList, ByteBuf outBuffer) {\r
+        if (actionsList == null) {\r
+            return;\r
+        }\r
+        for (ActionsList list : actionsList) {\r
+            Action action = list.getAction();\r
+            if (action.getType().equals(Output.class)) {\r
+                encodeOutputAction(action, outBuffer);\r
+            } else if (action.getType().equals(CopyTtlOut.class)) {\r
+                encodeCopyTtlOutAction(outBuffer);\r
+            } else if (action.getType().equals(CopyTtlIn.class)) {\r
+                encodeCopyTtlInAction(outBuffer);\r
+            } else if (action.getType().equals(SetMplsTtl.class)) {\r
+                encodeSetMplsTtltAction(action, outBuffer);\r
+            } else if (action.getType().equals(DecMplsTtl.class)) {\r
+                encodeDecMplsTtlAction(outBuffer);\r
+            } else if (action.getType().equals(PushVlan.class)) {\r
+                encodePushVlanAction(action, outBuffer);\r
+            } else if (action.getType().equals(PopVlan.class)) {\r
+                encodePopVlanAction(outBuffer);\r
+            } else if (action.getType().equals(PushMpls.class)) {\r
+                encodePushMplsAction(action, outBuffer);\r
+            } else if (action.getType().equals(PopMpls.class)) {\r
+                encodePopMplsAction(action, outBuffer);\r
+            } else if (action.getType().equals(SetQueue.class)) {\r
+                encodeSetQueueAction(action, outBuffer);\r
+            } else if (action.getType().equals(Group.class)) {\r
+                encodeGroupAction(action, outBuffer);\r
+            } else if (action.getType().equals(SetNwTtl.class)) {\r
+                encodeSetNwTtlAction(action, outBuffer);\r
+            } else if (action.getType().equals(DecNwTtl.class)) {\r
+                encodeDecNwTtlAction(outBuffer);\r
+            } else if (action.getType().equals(SetField.class)) {\r
+                encodeSetFieldAction(action, outBuffer);\r
+            } else if (action.getType().equals(PushPbb.class)) {\r
+                encodePushPbbAction(action, outBuffer);\r
+            } else if (action.getType().equals(PopPbb.class)) {\r
+                encodePopPbbAction(outBuffer);\r
+            } else if (action.getType().equals(Experimenter.class)) {\r
+                encodeExperimenterAction(action, outBuffer);\r
+            } \r
+        }\r
+    }\r
+\r
+    private static void encodeOutputAction(Action action, ByteBuf outBuffer) {\r
+        final byte OUTPUT_CODE = 0;\r
+        final byte OUTPUT_LENGTH = 16;\r
+        final byte OUTPUT_PADDING = 6;\r
+        outBuffer.writeShort(OUTPUT_CODE);\r
+        outBuffer.writeShort(OUTPUT_LENGTH);\r
+        PortAction port = action.getAugmentation(PortAction.class);\r
+        outBuffer.writeInt(port.getPort().getValue().intValue());\r
+        MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class);\r
+        outBuffer.writeShort(maxlength.getMaxLength());\r
+        ByteBufUtils.padBuffer(OUTPUT_PADDING, outBuffer);\r
+    }\r
+\r
+    private static void encodeCopyTtlOutAction(ByteBuf outBuffer) {\r
+        final byte COPY_TTL_OUT_CODE = 11;\r
+        outBuffer.writeShort(COPY_TTL_OUT_CODE);\r
+        encodeRestOfActionHeader(outBuffer);\r
+    }\r
+    \r
+    private static void encodeCopyTtlInAction(ByteBuf outBuffer) {\r
+        final byte COPY_TTL_IN_CODE = 12;\r
+        outBuffer.writeShort(COPY_TTL_IN_CODE);\r
+        encodeRestOfActionHeader(outBuffer);\r
+    }\r
+    \r
+    private static void encodeSetMplsTtltAction(Action action, ByteBuf outBuffer) {\r
+        final byte SET_MPLS_TTL_CODE = 15;\r
+        final byte SET_MPLS_TTL_LENGTH = 8;\r
+        final byte SET_MPLS_TTL_PADDING = 3;\r
+        outBuffer.writeShort(SET_MPLS_TTL_CODE);\r
+        outBuffer.writeShort(SET_MPLS_TTL_LENGTH);\r
+        MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class);\r
+        outBuffer.writeByte(mplsTtl.getMplsTtl());\r
+        ByteBufUtils.padBuffer(SET_MPLS_TTL_PADDING, outBuffer);\r
+    }\r
+    \r
+    private static void encodeDecMplsTtlAction(ByteBuf outBuffer) {\r
+        final byte DEC_MPLS_TTL_CODE = 16;\r
+        outBuffer.writeShort(DEC_MPLS_TTL_CODE);\r
+        encodeRestOfActionHeader(outBuffer);\r
+    }\r
+    \r
+    private static void encodePushVlanAction(Action action, ByteBuf outBuffer) {\r
+        final byte PUSH_VLAN_CODE = 17;\r
+        outBuffer.writeShort(PUSH_VLAN_CODE);\r
+        encodeCommonEthertype(action, outBuffer);\r
+    }\r
+\r
+    private static void encodePopVlanAction(ByteBuf outBuffer) {\r
+        final byte POP_VLAN_CODE = 18;\r
+        outBuffer.writeShort(POP_VLAN_CODE);\r
+        encodeRestOfActionHeader(outBuffer);\r
+    }\r
+    \r
+    private static void encodePushMplsAction(Action action, ByteBuf outBuffer) {\r
+        final byte PUSH_MPLS_CODE = 19;\r
+        outBuffer.writeShort(PUSH_MPLS_CODE);\r
+        encodeCommonEthertype(action, outBuffer);\r
+    }\r
+    \r
+    private static void encodePopMplsAction(Action action, ByteBuf outBuffer) {\r
+        final byte POP_MPLS_CODE = 20;\r
+        outBuffer.writeShort(POP_MPLS_CODE);\r
+        encodeCommonEthertype(action, outBuffer);\r
+    }\r
+    \r
+    private static void encodeSetQueueAction(Action action, ByteBuf outBuffer) {\r
+        final byte SET_QUEUE_CODE = 21;\r
+        final byte SET_QUEUE_LENGTH = 8;\r
+        outBuffer.writeShort(SET_QUEUE_CODE);\r
+        outBuffer.writeShort(SET_QUEUE_LENGTH);\r
+        QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);\r
+        outBuffer.writeInt(queueId.getQueueId().intValue());\r
+    }\r
+\r
+    private static void encodeGroupAction(Action action, ByteBuf outBuffer) {\r
+        final byte GROUP_CODE = 22;\r
+        final byte GROUP_LENGTH = 8;\r
+        outBuffer.writeShort(GROUP_CODE);\r
+        outBuffer.writeShort(GROUP_LENGTH);\r
+        GroupIdAction groupId = action.getAugmentation(GroupIdAction.class);\r
+        outBuffer.writeInt(groupId.getGroupId().intValue());\r
+    }\r
+    \r
+    private static void encodeSetNwTtlAction(Action action, ByteBuf outBuffer) {\r
+        final byte SET_NW_TTL_CODE = 23;\r
+        final byte SET_NW_TTL_LENGTH = 8;\r
+        final byte SET_NW_TTL_PADDING = 3;\r
+        outBuffer.writeShort(SET_NW_TTL_CODE);\r
+        outBuffer.writeShort(SET_NW_TTL_LENGTH);\r
+        NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class);\r
+        outBuffer.writeByte(nwTtl.getNwTtl());\r
+        ByteBufUtils.padBuffer(SET_NW_TTL_PADDING, outBuffer);\r
+    }\r
+    \r
+    private static void encodeDecNwTtlAction(ByteBuf outBuffer) {\r
+        final byte DEC_NW_TTL_CODE = 24;\r
+        outBuffer.writeShort(DEC_NW_TTL_CODE);\r
+        encodeRestOfActionHeader(outBuffer);\r
+    }\r
+    \r
+    private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) {\r
+        final int SET_FIELD_CODE = 25; // 0xFFFF\r
+        final byte SET_FIELD_LENGTH = 8;\r
+        // TODO - figure out definition from testing + check length\r
+        LOGGER.warn("Received set-field action - possible wrong or no implementation");\r
+        outBuffer.writeShort(SET_FIELD_CODE);\r
+        outBuffer.writeShort(SET_FIELD_LENGTH);\r
+        ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);\r
+        outBuffer.writeInt(experimenter.getExperimenter().intValue());\r
+    }\r
+    \r
+    private static void encodePushPbbAction(Action action, ByteBuf outBuffer) {\r
+        final byte PUSH_PBB_CODE = 26;\r
+        outBuffer.writeShort(PUSH_PBB_CODE);\r
+        encodeCommonEthertype(action, outBuffer);\r
+    }\r
+    \r
+    private static void encodePopPbbAction(ByteBuf outBuffer) {\r
+        final byte POP_PBB_CODE = 27;\r
+        outBuffer.writeShort(POP_PBB_CODE);\r
+        encodeRestOfActionHeader(outBuffer);\r
+    }\r
+\r
+    private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) {\r
+        final int EXPERIMENTER_CODE = 65535; // 0xFFFF\r
+        final byte EXPERIMENTER_LENGTH = 8;\r
+        outBuffer.writeShort(EXPERIMENTER_CODE);\r
+        outBuffer.writeShort(EXPERIMENTER_LENGTH);\r
+        ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);\r
+        outBuffer.writeInt(experimenter.getExperimenter().intValue());\r
+    }\r
+    \r
+    private static void encodeRestOfActionHeader(ByteBuf outBuffer) {\r
+        final byte ACTION_HEADER_LENGTH = 8;\r
+        final byte PADDING_IN_ACTION_HEADER = 4;\r
+        outBuffer.writeShort(ACTION_HEADER_LENGTH);\r
+        ByteBufUtils.padBuffer(PADDING_IN_ACTION_HEADER, outBuffer);\r
+    }\r
+    \r
+    private static void encodeCommonEthertype(Action action, ByteBuf outBuffer) {\r
+        final byte LENGTH_OF_ETHERTYPE_ACTION = 8;\r
+        final byte ETHERTYPE_ACTION_PADDING = 2;\r
+        outBuffer.writeShort(LENGTH_OF_ETHERTYPE_ACTION);\r
+        EthertypeAction ethertype = action.getAugmentation(EthertypeAction.class);\r
+        outBuffer.writeShort(ethertype.getEthertype().getValue());\r
+        ByteBufUtils.padBuffer(ETHERTYPE_ACTION_PADDING, outBuffer);\r
+    }\r
+    \r
+    /**\r
+     * Computes length of actions\r
+     * @param actionsList list of actions\r
+     * @return actions length\r
+     */\r
+    public static int computeLengthOfActions(List<ActionsList> actionsList) {\r
+        final byte OUTPUT_LENGTH = 16;\r
+        final byte LENGTH_OF_OTHER_ACTIONS = 8;\r
+        int lengthOfActions = 0;\r
+        if (actionsList != null) {\r
+            for (ActionsList list : actionsList) {\r
+                Action action = list.getAction();\r
+                if (action.getType().equals(Output.class)) {\r
+                    lengthOfActions += OUTPUT_LENGTH;\r
+                } else {\r
+                    lengthOfActions += LENGTH_OF_OTHER_ACTIONS;\r
+                }\r
+            }\r
+        }\r
+        return lengthOfActions;\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntriesCreator.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntriesCreator.java
deleted file mode 100644 (file)
index 7d5456c..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;\r
-\r
-/**\r
- * To create matches\r
- * @author timotej.kubas\r
- * @author michal.polkorab\r
- */\r
-public abstract class MatchEntriesCreator {\r
-    private static List<MatchEntries> matchEntriesList = new ArrayList<>();\r
-    private static MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); \r
-    \r
-    /**\r
-     * @param in input ByteBuf\r
-     * @param matchArrayLength to infer size of array\r
-     * @return MatchEntriesList\r
-     */\r
-    public static List<MatchEntries> createMatchEntry(ByteBuf in, int matchArrayLength) {\r
-        int currMatchLength = 0;\r
-        final byte MATCH_LENGTH = 1;\r
-        \r
-        while(currMatchLength < matchArrayLength) {\r
-            \r
-            switch (in.readUnsignedShort()) { \r
-            case 0x0000:\r
-                        matchEntriesBuilder.setOxmClass(Nxm0Class.class);\r
-                        break;\r
-            case 0x0001:\r
-                        matchEntriesBuilder.setOxmClass(Nxm1Class.class);\r
-                        break;\r
-            case 0x8000:\r
-                        matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
-                        break;\r
-            case 0xFFFF:\r
-                        matchEntriesBuilder.setOxmClass(ExperimenterClass.class);\r
-                        break;\r
-            default:\r
-                        break;\r
-            }\r
-            currMatchLength = currMatchLength +2;\r
-            \r
-            int matchField = in.readUnsignedByte() >>> 1;\r
-            in.skipBytes(MATCH_LENGTH);\r
-            \r
-            currMatchLength = currMatchLength + 2;\r
-            \r
-            switch(matchField) {\r
-            case 0: \r
-                matchEntriesBuilder.setOxmMatchField(InPort.class);\r
-                PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();\r
-                port.setPortNumber(new PortNumber(in.readUnsignedInt())); \r
-                matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());\r
-                currMatchLength = currMatchLength + 4;\r
-                break;\r
-            case 1:\r
-                matchEntriesBuilder.setOxmMatchField(InPhyPort.class);\r
-                PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder();\r
-                phyPort.setPortNumber(new PortNumber(in.readUnsignedInt())); \r
-                matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build());\r
-                currMatchLength = currMatchLength + 4;\r
-                break;\r
-            case 2:\r
-                matchEntriesBuilder.setOxmMatchField(Metadata.class);\r
-                MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder();\r
-                byte[] metadataBytes = new byte[Long.SIZE/Byte.SIZE];\r
-                in.readBytes(metadataBytes);\r
-                metadata.setMetadata(metadataBytes); \r
-                matchEntriesBuilder.addAugmentation(MetadataMatchEntry.class, metadata.build());\r
-                currMatchLength = currMatchLength + 8;\r
-                break;\r
-            case 3:\r
-                matchEntriesBuilder.setOxmMatchField(EthDst.class);\r
-                MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();\r
-                StringBuffer macToString = new StringBuffer();\r
-                final int macAddressLength = 6;\r
-                for(int i=0; i<macAddressLength ; i++){\r
-                    short mac = 0;\r
-                    mac = in.readUnsignedByte();\r
-                    macToString.append(String.format("%02X", mac));\r
-                }\r
-                macAddress.setMacAddress(new MacAddress(macToString.toString())); \r
-                matchEntriesBuilder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());\r
-                currMatchLength = currMatchLength + 8;\r
-                break;\r
-            default: \r
-                break;\r
-            }\r
-          matchEntriesList.add(matchEntriesBuilder.build());\r
-        }\r
-        \r
-        return matchEntriesList;\r
-    }\r
-}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntriesDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntriesDeserializer.java
new file mode 100644 (file)
index 0000000..fe9ba90
--- /dev/null
@@ -0,0 +1,520 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\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
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import com.google.common.base.Joiner;\r
+\r
+/**\r
+ * Class for easy creation of matches\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class MatchEntriesDeserializer {\r
+    private static final Logger LOGGER = LoggerFactory.getLogger(MatchEntriesDeserializer.class);\r
+    private static final byte SIZE_OF_LONG_IN_BYTES = Long.SIZE / Byte.SIZE;\r
+    private static final byte SIZE_OF_INT_IN_BYTES = Integer.SIZE / Byte.SIZE;\r
+    private static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE;\r
+    private static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE;\r
+    private static final byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = (8 * Short.SIZE) / Byte.SIZE;\r
+    private static List<MatchEntries> matchEntriesList = new ArrayList<>();\r
+    private static MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); \r
+    \r
+    /**\r
+     * @param in input ByteBuf\r
+     * @param matchArrayLength to infer size of array\r
+     * @return MatchEntriesList\r
+     */\r
+    public static List<MatchEntries> createMatchEntry(ByteBuf in, int matchArrayLength) {\r
+        int currMatchLength = 0;\r
+        while(currMatchLength < matchArrayLength) {\r
+            switch (in.readUnsignedShort()) { \r
+            case 0x0000:\r
+                        matchEntriesBuilder.setOxmClass(Nxm0Class.class);\r
+                        break;\r
+            case 0x0001:\r
+                        matchEntriesBuilder.setOxmClass(Nxm1Class.class);\r
+                        break;\r
+            case 0x8000:\r
+                        matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
+                        break;\r
+            case 0xFFFF:\r
+                        matchEntriesBuilder.setOxmClass(ExperimenterClass.class);\r
+                        break;\r
+            default:\r
+                        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
+            \r
+            switch(matchField) {\r
+            case 0: \r
+                matchEntriesBuilder.setOxmMatchField(InPort.class);\r
+                PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();\r
+                port.setPortNumber(new PortNumber(in.readUnsignedInt())); \r
+                matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());\r
+                break;\r
+            case 1:\r
+                matchEntriesBuilder.setOxmMatchField(InPhyPort.class);\r
+                PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder();\r
+                phyPort.setPortNumber(new PortNumber(in.readUnsignedInt())); \r
+                matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build());\r
+                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
+                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\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
+                }\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
+                }\r
+                break;\r
+            case 5:\r
+                matchEntriesBuilder.setOxmMatchField(EthType.class);\r
+                EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();\r
+                ethertypeBuilder.setEthType(new EtherType(in.readUnsignedShort()));\r
+                matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());\r
+                break;\r
+            case 6:\r
+                matchEntriesBuilder.setOxmMatchField(VlanVid.class);\r
+                VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();\r
+                vlanVidBuilder.setVlanVid(in.readUnsignedShort());\r
+                matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());\r
+                matchEntryLength -= SIZE_OF_SHORT_IN_BYTES;\r
+                if (matchEntryLength > 0) {\r
+                    addMaskAugmentation(matchEntriesBuilder, in, matchEntryLength);\r
+                }\r
+                break;\r
+            case 7:\r
+                matchEntriesBuilder.setOxmMatchField(VlanPcp.class);\r
+                VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();\r
+                vlanPcpBuilder.setVlanPcp(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());\r
+                break;\r
+            case 8:\r
+                matchEntriesBuilder.setOxmMatchField(IpDscp.class);\r
+                DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();\r
+                dscpBuilder.setDscp(new Dscp(in.readUnsignedByte()));\r
+                matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());\r
+                break;\r
+            case 9:\r
+                matchEntriesBuilder.setOxmMatchField(IpEcn.class);\r
+                EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();\r
+                ecnBuilder.setEcn(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());\r
+                break;\r
+            case 10:\r
+                matchEntriesBuilder.setOxmMatchField(IpProto.class);\r
+                ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();\r
+                protoNumberBuilder.setProtocolNumber(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());\r
+                break;\r
+            case 11:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv4Src.class);\r
+                // 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
+                }\r
+                break;\r
+            case 12:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class);\r
+                // 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
+                }\r
+                break;\r
+            case 13:\r
+                matchEntriesBuilder.setOxmMatchField(TcpSrc.class);\r
+                addPortAugmentation(null, in);\r
+                break;\r
+            case 14:\r
+                matchEntriesBuilder.setOxmMatchField(TcpDst.class);\r
+                addPortAugmentation(null, in);\r
+                break;\r
+            case 15:\r
+                matchEntriesBuilder.setOxmMatchField(UdpSrc.class);\r
+                addPortAugmentation(null, in);\r
+                break;\r
+            case 16:\r
+                matchEntriesBuilder.setOxmMatchField(UdpDst.class);\r
+                addPortAugmentation(null, in);\r
+                break;\r
+            case 17:\r
+                matchEntriesBuilder.setOxmMatchField(SctpSrc.class);\r
+                addPortAugmentation(null, in);\r
+                break;\r
+            case 18:\r
+                matchEntriesBuilder.setOxmMatchField(SctpDst.class);\r
+                addPortAugmentation(null, in);\r
+                break;\r
+            case 19:\r
+                matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);\r
+                Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();\r
+                icmpv4TypeBuilder.setIcmpv4Type(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());\r
+                break;\r
+            case 20:\r
+                matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);\r
+                Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();\r
+                icmpv4CodeBuilder.setIcmpv4Code(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());\r
+                break;\r
+            case 21:\r
+                matchEntriesBuilder.setOxmMatchField(ArpOp.class);\r
+                OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();\r
+                opcodeBuilder.setOpCode(in.readUnsignedShort());\r
+                matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());\r
+                break;\r
+            case 22:\r
+                matchEntriesBuilder.setOxmMatchField(ArpSpa.class);\r
+                // 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
+                }\r
+                break;\r
+            case 23:\r
+                matchEntriesBuilder.setOxmMatchField(ArpTpa.class);\r
+                // 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
+                }\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
+                }\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
+                }\r
+                break;\r
+            case 26:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6Src.class);\r
+                // 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
+                }\r
+                break;\r
+            case 27:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class);\r
+                // 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
+                }\r
+                break;\r
+            case 28:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);\r
+                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
+                }\r
+                break;\r
+            case 29:\r
+                matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);\r
+                Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();\r
+                icmpv6TypeBuilder.setIcmpv6Type(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());\r
+                break;\r
+            case 30:\r
+                matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);\r
+                Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();\r
+                icmpv6CodeBuilder.setIcmpv6Code(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());\r
+                break;\r
+            case 31:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);\r
+                // TODO - ipv6address - check format with tests\r
+                LOGGER.warn("IPV6address(Ipv6NdTarget): received but possible wrong deserialization");\r
+                addIpv6AddressAugmentation(matchEntriesBuilder, in);\r
+                break;\r
+            case 32:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class);\r
+                addMacAddressAugmentation(matchEntriesBuilder, in);\r
+                break;\r
+            case 33:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class);\r
+                addMacAddressAugmentation(matchEntriesBuilder, in);\r
+                break;\r
+            case 34:\r
+                matchEntriesBuilder.setOxmMatchField(MplsLabel.class);\r
+                MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();\r
+                mplsLabelBuilder.setMplsLabel(in.readUnsignedInt());\r
+                matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());\r
+                break;\r
+            case 35:\r
+                matchEntriesBuilder.setOxmMatchField(MplsTc.class);\r
+                TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();\r
+                tcBuilder.setTc(in.readUnsignedByte());\r
+                matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());\r
+                break;\r
+            case 36:\r
+                matchEntriesBuilder.setOxmMatchField(MplsBos.class);\r
+                BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();\r
+                if (in.readUnsignedByte() != 0) {\r
+                    bosBuilder.setBos(true);\r
+                } else {\r
+                    bosBuilder.setBos(false);\r
+                }\r
+                matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());\r
+                break;\r
+            case 37:\r
+                matchEntriesBuilder.setOxmMatchField(PbbIsid.class);\r
+                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
+                }\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
+                }\r
+                break;\r
+            case 39:\r
+                matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);\r
+                PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();\r
+                int bitmap = in.readUnsignedShort();\r
+                final Boolean NONEXT = ((bitmap) & (1<<0)) != 0;\r
+                final Boolean ESP = ((bitmap) & (1<<1)) != 0;\r
+                final Boolean AUTH = ((bitmap) & (1<<2)) != 0;\r
+                final Boolean DEST = ((bitmap) & (1<<3)) != 0;\r
+                final Boolean FRAG = ((bitmap) & (1<<4)) != 0;\r
+                final Boolean ROUTER = ((bitmap) & (1<<5)) != 0;\r
+                final Boolean HOP = ((bitmap) & (1<<6)) != 0;\r
+                final Boolean UNREP = ((bitmap) & (1<<7)) != 0;\r
+                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
+                }\r
+                break;\r
+            default: \r
+                break;\r
+            }\r
+          matchEntriesList.add(matchEntriesBuilder.build());\r
+        }\r
+        \r
+        return matchEntriesList;\r
+    }\r
+\r
+    private static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf in, int matchEntryLength) {\r
+//         TODO - check if matchEntryLength is in bytes\r
+        MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
+        byte[] mask = new byte[matchEntryLength];\r
+        in.readBytes(mask);\r
+        maskBuilder.setMask(mask);\r
+        builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+    }\r
+\r
+    private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) {\r
+        final byte GROUPS_IN_IPV6_ADDRESS = 8;\r
+        Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();\r
+        List<String> groups = new ArrayList<>();\r
+        for (int i = 0; i < GROUPS_IN_IPV6_ADDRESS; i++) {\r
+            groups.add(String.format("X", in.readUnsignedShort()));\r
+        }\r
+        Joiner joiner = Joiner.on(":");\r
+        ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups)));\r
+        builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());\r
+    }\r
+    \r
+    private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf in) {\r
+        MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder();\r
+        byte[] metadataBytes = new byte[Long.SIZE/Byte.SIZE];\r
+        in.readBytes(metadataBytes);\r
+        metadata.setMetadata(metadataBytes); \r
+        builder.addAugmentation(MetadataMatchEntry.class, metadata.build());\r
+    }\r
+\r
+    private static void addIpv4AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) {\r
+        final byte GROUPS_IN_IPV4_ADDRESS = 4;\r
+        Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();\r
+        StringBuffer sb = new StringBuffer();\r
+        for (int i = 0; i < GROUPS_IN_IPV4_ADDRESS; i++) {\r
+            sb.append(in.readUnsignedByte());\r
+        }\r
+        ipv4AddressBuilder.setIpv4Address(new Ipv4Address(sb.toString()));\r
+        builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());\r
+    }\r
+\r
+    private static void addMacAddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) {\r
+        MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();\r
+        StringBuffer macToString = new StringBuffer();\r
+        final int macAddressLength = 6;\r
+        for(int i=0; i<macAddressLength ; i++){\r
+            short mac = 0;\r
+            mac = in.readUnsignedByte();\r
+            macToString.append(String.format("%02X", mac));\r
+        }\r
+        macAddress.setMacAddress(new MacAddress(macToString.toString())); \r
+        builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());\r
+    }\r
+    \r
+    private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf in) {\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.\r
+                xml.ns.yang.ietf.inet.types.rev100924.PortNumber(in.readUnsignedShort()));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.build());\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java
new file mode 100644 (file)
index 0000000..59c4ec6
--- /dev/null
@@ -0,0 +1,315 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.flow.mod.Match;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class MatchSerializer {\r
+    \r
+    private static final Logger LOGGER = LoggerFactory.getLogger(MatchSerializer.class);\r
+\r
+    /**\r
+     * Encodes OF match\r
+     * @param match ofp_match object\r
+     * @param out output ByteBuf\r
+     */\r
+    public static void encodeMatch(Match match, ByteBuf out) {\r
+        final byte PADDING_IN_OFP_MATCH = 4;\r
+        encodeType(match, out);\r
+        //TODO - compute length\r
+        encodeMatchEntries(match.getMatchEntries(), out);\r
+        ByteBufUtils.padBuffer(PADDING_IN_OFP_MATCH, out);\r
+        \r
+    }\r
+\r
+    private static void encodeType(Match match, ByteBuf out) {\r
+        final byte STANDARD_MATCH_TYPE_CODE = 0;\r
+        final byte OXM_MATCH_TYPE_CODE = 1;\r
+        if (match.getType().equals(StandardMatchType.class)) {\r
+            out.writeShort(STANDARD_MATCH_TYPE_CODE);\r
+        } else if (match.getType().equals(OxmMatchType.class)) {\r
+            out.writeShort(OXM_MATCH_TYPE_CODE);\r
+        }\r
+    }\r
+\r
+    private static void encodeMatchEntries(List<MatchEntries> matchEntries, ByteBuf out) {\r
+        if (matchEntries == null) {\r
+            LOGGER.warn("Match entry is null");\r
+            return;\r
+        }\r
+        for (MatchEntries entry : matchEntries) {\r
+            encodeClass(entry.getOxmClass(), out);\r
+            encodeRest(entry, null);\r
+        }\r
+    }\r
+\r
+    private static void encodeClass(Class<? extends Clazz> clazz, ByteBuf out) {\r
+        final int NXM0_CLASS_CODE = 0x0000;\r
+        final int NXM1_CLASS_CODE = 0x0001;\r
+        final int OPENFLOW_BASIC_CLASS_CODE = 0x8000;\r
+        final int EXPERIMENTER_CLASS_CODE = 0xFFFF;\r
+        if (Nxm0Class.class.equals(clazz)) {\r
+            out.writeShort(NXM0_CLASS_CODE);\r
+        } else if (Nxm1Class.class.equals(clazz)) {\r
+            out.writeShort(NXM1_CLASS_CODE);\r
+        } else if (OpenflowBasicClass.class.equals(clazz)) {\r
+            out.writeShort(OPENFLOW_BASIC_CLASS_CODE);\r
+        } else if (ExperimenterClass.class.equals(clazz)) {\r
+            out.writeShort(EXPERIMENTER_CLASS_CODE);\r
+        }\r
+    }\r
+    \r
+    private static void encodeRest(MatchEntries entry, ByteBuf out) {\r
+        int fieldValue = 0;\r
+        Class<? extends MatchField> field = entry.getOxmMatchField();\r
+        if (field.equals(InPort.class)) {\r
+            fieldValue = 0;\r
+            writeOxmFieldAndLength(out, fieldValue, Integer.SIZE / Byte.SIZE);\r
+            out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
+        } else if (field.equals(InPhyPort.class)) {\r
+            fieldValue = 1;\r
+            writeOxmFieldAndLength(out, fieldValue, Integer.SIZE / Byte.SIZE);\r
+            out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
+        } else if (field.equals(Metadata.class)) {\r
+            fieldValue = 2;\r
+            fieldValue = fieldValue << 1;\r
+            if (entry.isHasMask()) {\r
+                fieldValue = fieldValue | 1;\r
+                out.writeByte(fieldValue);\r
+                byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
+                out.writeByte(Long.SIZE / Byte.SIZE + mask.length);\r
+                out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata());\r
+                out.writeBytes(mask);\r
+            } else {\r
+                out.writeByte(fieldValue);\r
+                out.writeByte(Long.SIZE / Byte.SIZE);\r
+                out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata());\r
+            }\r
+        } else if (field.equals(EthDst.class)) {\r
+            fieldValue = 3;\r
+            fieldValue = fieldValue << 1;\r
+            if (entry.isHasMask()) {\r
+                fieldValue = fieldValue | 1;\r
+                out.writeByte(fieldValue);\r
+                byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
+                out.writeByte((Integer.SIZE + Short.SIZE) / Byte.SIZE + mask.length);\r
+                out.writeBytes(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue().getBytes());\r
+                out.writeBytes(entry.getAugmentation(MaskMatchEntry.class).getMask());\r
+            } else {\r
+                out.writeByte(fieldValue);\r
+                out.writeByte(Long.SIZE / Byte.SIZE);\r
+                out.writeBytes(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue().getBytes());\r
+            }\r
+        } else if (field.equals(EthSrc.class)) {\r
+            fieldValue = 4;\r
+            fieldValue = fieldValue << 1;\r
+            if (entry.isHasMask()) {\r
+                fieldValue = fieldValue | 1;\r
+                out.writeByte(fieldValue);\r
+                byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
+                out.writeByte(Long.SIZE / Byte.SIZE + mask.length);\r
+                out.writeBytes(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue().getBytes());\r
+                out.writeBytes(mask);\r
+            } else {\r
+                out.writeByte(fieldValue);\r
+                out.writeByte(Long.SIZE / Byte.SIZE);\r
+                out.writeBytes(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue().getBytes());\r
+            }\r
+        } else if (field.equals(EthType.class)) {\r
+            fieldValue = 5;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue());\r
+        } else if (field.equals(VlanVid.class)) {\r
+            fieldValue = 6;\r
+            fieldValue = fieldValue << 1;\r
+            if (entry.isHasMask()) {\r
+                fieldValue = fieldValue | 1;\r
+                out.writeByte(fieldValue);\r
+                byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
+                out.writeByte(Short.SIZE / Byte.SIZE + mask.length);\r
+                out.writeShort(entry.getAugmentation(VlanVidMatchEntry.class).getVlanVid());\r
+                out.writeBytes(mask);\r
+            } else {\r
+                writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+                out.writeShort(entry.getAugmentation(VlanVidMatchEntry.class).getVlanVid());\r
+            }\r
+        } else if (field.equals(VlanPcp.class)) {\r
+            fieldValue = 7;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue());\r
+        } else if (field.equals(IpDscp.class)) {\r
+            fieldValue = 8;\r
+        } else if (field.equals(IpEcn.class)) {\r
+            fieldValue = 9;\r
+        } else if (field.equals(IpProto.class)) {\r
+            fieldValue = 10;\r
+        } else if (field.equals(Ipv4Src.class)) {\r
+            fieldValue = 11;\r
+        } else if (field.equals(Ipv4Dst.class)) {\r
+            fieldValue = 12;\r
+        } else if (field.equals(TcpSrc.class)) {\r
+            fieldValue = 13;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+        } else if (field.equals(TcpDst.class)) {\r
+            fieldValue = 14;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+        } else if (field.equals(UdpSrc.class)) {\r
+            fieldValue = 15;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+        } else if (field.equals(UdpDst.class)) {\r
+            fieldValue = 16;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+        } else if (field.equals(SctpSrc.class)) {\r
+            fieldValue = 17;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+        } else if (field.equals(SctpDst.class)) {\r
+            fieldValue = 18;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+        } else if (field.equals(Icmpv4Type.class)) {\r
+            fieldValue = 19;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type());\r
+        } else if (field.equals(Icmpv4Code.class)) {\r
+            fieldValue = 20;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code());\r
+        } else if (field.equals(ArpOp.class)) {\r
+            fieldValue = 21;\r
+            writeOxmFieldAndLength(out, fieldValue, Short.SIZE / Byte.SIZE);\r
+            out.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode());\r
+        } else if (field.equals(ArpSpa.class)) {\r
+            fieldValue = 22;\r
+        } else if (field.equals(ArpTpa.class)) {\r
+            fieldValue = 23;\r
+        } else if (field.equals(ArpSha.class)) {\r
+            fieldValue = 24;\r
+        } else if (field.equals(ArpTha.class)) {\r
+            fieldValue = 25;\r
+        } else if (field.equals(Ipv6Src.class)) {\r
+            fieldValue = 26;\r
+        } else if (field.equals(Ipv6Dst.class)) {\r
+            fieldValue = 27;\r
+        } else if (field.equals(Ipv6Flabel.class)) {\r
+            fieldValue = 28;\r
+        } else if (field.equals(Icmpv6Type.class)) {\r
+            fieldValue = 29;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type());\r
+        } else if (field.equals(Icmpv6Code.class)) {\r
+            fieldValue = 30;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code());\r
+        } else if (field.equals(Ipv6NdTarget.class)) {\r
+            fieldValue = 31;\r
+        } else if (field.equals(Ipv6NdSll.class)) {\r
+            fieldValue = 32;\r
+        } else if (field.equals(Ipv6NdTll.class)) {\r
+            fieldValue = 33;\r
+        } else if (field.equals(MplsLabel.class)) {\r
+            fieldValue = 34;\r
+            writeOxmFieldAndLength(out, fieldValue, Integer.SIZE / Byte.SIZE);\r
+            out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue());\r
+        } else if (field.equals(MplsTc.class)) {\r
+            fieldValue = 35;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc());\r
+        } else if (field.equals(MplsBos.class)) {\r
+            fieldValue = 36;\r
+            writeOxmFieldAndLength(out, fieldValue, Byte.SIZE / Byte.SIZE);\r
+            out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue());\r
+        } else if (field.equals(PbbIsid.class)) {\r
+            fieldValue = 37;\r
+        } else if (field.equals(TunnelId.class)) {\r
+            fieldValue = 38;\r
+        } else if (field.equals(Ipv6Exthdr.class)) {\r
+            fieldValue = 39;\r
+        }\r
+    }\r
+\r
+    private static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, int length) {\r
+        int fieldAndMask = fieldValue << 1;\r
+        out.writeByte(fieldAndMask);\r
+        out.writeByte(length);\r
+    }\r
+    \r
+}\r
index e96b05b8b13930efc2adebe0ae4dd33468c07cb7..df0ac6f0503294adec4d413743790296f60ac44a 100644 (file)
@@ -535,6 +535,9 @@ public class MultipartReplyMessageFactoryTest {
                 message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());\r
     }\r
     \r
+    /**\r
+     * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
+     */\r
     @Test\r
     public void testMultipartReplyMeterBodyMulti(){\r
         ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+\r
@@ -935,7 +938,7 @@ public class MultipartReplyMessageFactoryTest {
         Assert.assertEquals("Wrong outputPort", 4351, \r
                 message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0).\r
                 getAction().getAugmentation(PortAction.class).\r
-                getPort().getPortNumber().getValue().intValue());\r
+                getPort().getValue().intValue());\r
         \r
         Assert.assertEquals("Wrong outputMaxLen", 65535, \r
                 message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0).\r
index 3b2136484ae19ac87a80f531c43deb4bce37c353..4c447fc3441430860b3effe02ffb696d08b5255f 100644 (file)
@@ -24,6 +24,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public class QueueGetConfigReplyMessageFactoryTest {\r
 \r
+    /**\r
+     * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO\r
+     */\r
     @Test\r
     public void test(){\r
         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00");\r
@@ -33,7 +36,7 @@ public class QueueGetConfigReplyMessageFactoryTest {
         Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList());\r
     }\r
     \r
-    public List<Queues> createQueuesList(){\r
+    private static List<Queues> createQueuesList(){\r
         List<Queues> queuesList = new ArrayList<>();\r
         QueuesBuilder qb = new QueuesBuilder();\r
         qb.setQueueId(new QueueId(1L));\r
@@ -44,7 +47,7 @@ public class QueueGetConfigReplyMessageFactoryTest {
         return queuesList;\r
     }\r
     \r
-    public List<Properties> createPropertiesList(){\r
+    private static List<Properties> createPropertiesList(){\r
         List<Properties> propertiesList = new ArrayList<>();\r
         PropertiesBuilder pb = new PropertiesBuilder();\r
         pb.setProperty(QueueProperty.values()[2]);\r
index bc5950fda4793cb599b967ed25fc1cc05580e1df..d42d52553bf34a2cdf7e72b95e74ba0b363799d4 100644 (file)
@@ -7,8 +7,7 @@ import io.netty.buffer.UnpooledByteBufAllocator;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
-import junit.framework.Assert;\r
-\r
+import org.junit.Assert;\r
 import org.junit.Test;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
@@ -17,8 +16,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsList;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsListBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder;\r
 \r
 /**\r
  * @author timotej.kubas\r
@@ -38,7 +37,8 @@ public class GroupModInputMessageFactoryTest {
         builder.setCommand(GroupModCommand.forValue(2));\r
         builder.setType(GroupType.forValue(3));\r
         builder.setGroupId(256L);\r
-        builder.setBucketsList(createBucketsList());\r
+        List<BucketsList> exp = createBucketsList();\r
+        builder.setBucketsList(exp);\r
         GroupModInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
@@ -46,11 +46,12 @@ public class GroupModInputMessageFactoryTest {
         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
         \r
         BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));\r
-        Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readShort());\r
-        Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readByte());\r
+        Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte());\r
         out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE);\r
         Assert.assertEquals("Wrong groupId", message.getGroupId().intValue(), out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong bucketList", createBucketsList(), createBucketsListFromBufer(out));\r
+        List<BucketsList> rec = createBucketsListFromBufer(out);\r
+        Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray());\r
     }\r
     \r
     private static List<BucketsList> createBucketsList(){\r
@@ -69,7 +70,8 @@ public class GroupModInputMessageFactoryTest {
         List<BucketsList> bucketsList = new ArrayList<>();\r
         BucketsListBuilder bucketsBuilder = new BucketsListBuilder();\r
         BucketsList bucket;\r
-        bucketsBuilder.setWeight((int) out.readShort());\r
+        out.skipBytes(Short.SIZE / Byte.SIZE);\r
+        bucketsBuilder.setWeight(out.readUnsignedShort());\r
         bucketsBuilder.setWatchPort(new PortNumber(out.readUnsignedInt()));\r
         bucketsBuilder.setWatchGroup(out.readUnsignedInt());\r
         out.skipBytes(4);\r
diff --git a/pom.xml b/pom.xml
index 9e26b860a373de8feb64b5dfd5dad6148013b324..f446c0931a1f1565ede8b41bdb1021b0dc8f609b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
         <yang.prototype.version>1.0-SNAPSHOT</yang.prototype.version>
         <maven.bundle.version>2.4.0</maven.bundle.version>
         <guava.version>14.0.1</guava.version> 
+        <netty.version>4.0.10.Final</netty.version>
     </properties>
 
     <pluginRepositories>
             <dependency>
                 <groupId>io.netty</groupId>
                 <artifactId>netty-handler</artifactId>
-                <version>4.0.8.Final</version>
+                <version>${netty.version}</version>
             </dependency>
             <dependency>
             <groupId>com.google.guava</groupId>