Prior to this patch the code serialises an OFPMatch as:

   "OFPMatch": {
      "oxm_fields": {
         "arp_op": 1,
         ...
      }
   }

But the parser fails, complaining that "oxm_fields" is an unknown field name.

Resolve this by using the same JSON format as OF1.3:

   "OFPMatch": {
      "length": 329,
      "oxm_fields": [
         {
            "OXMTlv": {
               "field": "in_port",
               "mask": null,
               "value": 84281096
            }
         },
         ...
      }
   }

Signed-off-by: Simon Horman <[email protected]>
---
 ryu/ofproto/ofproto_v1_4_parser.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/ryu/ofproto/ofproto_v1_4_parser.py 
b/ryu/ofproto/ofproto_v1_4_parser.py
index 616e0f5..b366d9f 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -478,6 +478,32 @@ class OFPMatch(StringifyMixin):
     def stringify_attrs(self):
         yield "oxm_fields", dict(self._fields2)
 
+    def to_jsondict(self):
+        """
+        Returns a dict expressing the flow match.
+        """
+        body = {"oxm_fields": [ofproto.oxm_to_jsondict(k, uv) for k, uv
+                               in self._fields2],
+                "length": self.length,
+                "type": self.type}
+        return {self.__class__.__name__: body}
+
+    @classmethod
+    def from_jsondict(cls, dict_):
+        """
+        Returns an object which is generated from a dict.
+
+        Exception raises:
+        KeyError -- Unknown match field is defined in dict
+        """
+        fields = [ofproto.oxm_from_jsondict(f) for f
+                  in dict_['oxm_fields']]
+        o = OFPMatch()
+        # XXX old api compat
+        # serialize and parse to fill OFPMatch.fields
+        buf = bytearray()
+        o.serialize(buf, 0)
+        return OFPMatch.parser(str(buf), 0)
 
 class OFPPortDescPropUnknown(StringifyMixin):
     def __init__(self, type_=None, length=None, buf=None):
-- 
1.8.4


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to