Currently, there is different OFPActionExperimenter implementation of between 
of_parser_v14 and v13/5.
Because the implementation of v13/5 is better than v14, this patch fixes to 
of_parser_v14 for unification the implementation.

Signed-off-by: Minoru TAKAHASHI <[email protected]>
---
 ryu/ofproto/ofproto_v1_4_parser.py                 | 44 ++++++++++++++++++----
 .../of14/5-12-ofp_flow_stats_reply.packet.json     |  2 +-
 .../ofproto/json/of14/5-2-ofp_flow_mod.packet.json |  2 +-
 3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/ryu/ofproto/ofproto_v1_4_parser.py 
b/ryu/ofproto/ofproto_v1_4_parser.py
index 72bd212..53d3f1e 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -26,7 +26,9 @@ from ryu.lib.pack_utils import msg_pack_into
 from ryu import utils
 from ryu.ofproto.ofproto_parser import StringifyMixin, MsgBase, MsgInMsgBase, 
msg_str_attr
 from ryu.ofproto import ether
+from ryu.ofproto import nx_actions
 from ryu.ofproto import ofproto_parser
+from ryu.ofproto import ofproto_common
 from ryu.ofproto import ofproto_v1_4 as ofproto
 
 _MSG_PARSERS = {}
@@ -4987,12 +4989,11 @@ class OFPActionExperimenter(OFPAction):
         For the list of the supported Nicira experimenter actions,
         please refer to :ref:`ryu.ofproto.nx_actions <nx_actions_structures>`.
     """
-    def __init__(self, experimenter, data=None, type_=None, len_=None):
+    def __init__(self, experimenter):
         super(OFPActionExperimenter, self).__init__()
+        self.type = ofproto.OFPAT_EXPERIMENTER
         self.experimenter = experimenter
-        self.data = data
-        self.len = (utils.round_up(len(data), 8) +
-                    ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE)
+        self.len = None
 
     @classmethod
     def parser(cls, buf, offset):
@@ -5000,13 +5001,36 @@ class OFPActionExperimenter(OFPAction):
             ofproto.OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR, buf, offset)
         data = buf[(offset + ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE
                     ): offset + len_]
-        return cls(experimenter, data)
+        if experimenter == ofproto_common.NX_EXPERIMENTER_ID:
+            obj = NXAction.parse(data)
+        else:
+            obj = OFPActionExperimenterUnknown(experimenter, data)
+        obj.len = len_
+        return obj
 
     def serialize(self, buf, offset):
         msg_pack_into(ofproto.OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR,
                       buf, offset, self.type, self.len, self.experimenter)
-        if self.data:
-            buf += self.data
+
+
+class OFPActionExperimenterUnknown(OFPActionExperimenter):
+    def __init__(self, experimenter, data=None, type_=None, len_=None):
+        super(OFPActionExperimenterUnknown,
+              self).__init__(experimenter=experimenter)
+        self.data = data
+
+    def serialize(self, buf, offset):
+        # fixup
+        data = self.data
+        if data is None:
+            data = bytearray()
+        self.len = (utils.round_up(len(data), 8) +
+                    ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE)
+        super(OFPActionExperimenterUnknown, self).serialize(buf, offset)
+        msg_pack_into('!%ds' % len(self.data),
+                      buf,
+                      offset + ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE,
+                      self.data)
 
 
 @_register_parser
@@ -5625,3 +5649,9 @@ class OFPBundleAddMsg(MsgInMsgBase):
 
         # Finish
         self.buf += tail_buf
+
+
+nx_actions.generate(
+    'ryu.ofproto.ofproto_v1_4',
+    'ryu.ofproto.ofproto_v1_4_parser'
+)
diff --git 
a/ryu/tests/unit/ofproto/json/of14/5-12-ofp_flow_stats_reply.packet.json 
b/ryu/tests/unit/ofproto/json/of14/5-12-ofp_flow_stats_reply.packet.json
index a174876..4d7e027 100644
--- a/ryu/tests/unit/ofproto/json/of14/5-12-ofp_flow_stats_reply.packet.json
+++ b/ryu/tests/unit/ofproto/json/of14/5-12-ofp_flow_stats_reply.packet.json
@@ -253,7 +253,7 @@
                               }
                            },
                            {
-                              "OFPActionExperimenter": {
+                              "OFPActionExperimenterUnknown": {
                                  "len": 16,
                                  "data": "ZXhwX2RhdGE=",
                                  "experimenter": 98765432,
diff --git a/ryu/tests/unit/ofproto/json/of14/5-2-ofp_flow_mod.packet.json 
b/ryu/tests/unit/ofproto/json/of14/5-2-ofp_flow_mod.packet.json
index 2b4eaea..a884ce9 100644
--- a/ryu/tests/unit/ofproto/json/of14/5-2-ofp_flow_mod.packet.json
+++ b/ryu/tests/unit/ofproto/json/of14/5-2-ofp_flow_mod.packet.json
@@ -108,7 +108,7 @@
                      }
                   }, 
                   {
-                     "OFPActionExperimenter": {
+                     "OFPActionExperimenterUnknown": {
                         "data": "AAECAwQFBgc=", 
                         "experimenter": 101, 
                         "len": 16, 
-- 
1.9.1


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to