When using from_jsondict() with unicoded values, OFPMatch and OFPActionSetField
of ofproto_v1_4_parser contain unicode strings.
On the other hand, any other classes, e.g. OFPPort and OFPTableFeaturesStats
contain usual strings.
>>> from ryu.ofproto.ofproto_v1_4_parser import OFPMatch,
OFPActionSetField, OFPPort, OFPTableFeaturesStats
>>> import json
>>> json_match =
json.loads('{"oxm_fields":[{"OXMTlv":{"field":"eth_dst","value":"22:22:22:22:22:00","mask":"ff:ff:ff:ff:ff:00"}}]}')
>>> print OFPMatch.from_jsondict(json_match)
OFPMatch(oxm_fields={u'eth_dst': (u'22:22:22:22:22:00',
u'ff:ff:ff:ff:ff:00')})
>>> json_sf =
json.loads('{"field":{"OXMTlv":{"field":"ipv4_src","value":"192.168.1.1"}}}')
>>> print OFPActionSetField.from_jsondict(json_sf)
OFPActionSetField(ipv4_src=u'192.168.1.1')
>>> json_port =
json.loads('{"port_no":2,"hw_addr":"11:11:11:11:11:11","name":"test"}')
>>> print OFPPort.from_jsondict(json_port)
OFPPort(config=None,hw_addr='11:11:11:11:11:11',length=None,name='test',port_no=2,properties=None,state=None)
>>> json_feature = json.loads('{"name":"test"}')
>>> print OFPTableFeaturesStats.from_jsondict(json_feature)
OFPTableFeaturesStats(config=None,length=None,max_entries=None,metadata_match=None,metadata_write=None,name='test',properties=None,table_id=None)
I think that from_jsondict() of OFPMatch and OFPActionSetField should convert
unicoded strings to usual strings automatically like other classes.
This patch fixes the issue by adding decoding processes into
oxm_fields.from_jsondict() which is used in OFPMatch and OFPActionSetField.
Any comments ?
Signed-off-by: Yuichi Ito <[email protected]>
---
ryu/ofproto/oxm_fields.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ryu/ofproto/oxm_fields.py b/ryu/ofproto/oxm_fields.py
index 1ca5f65..f00f8b4 100644
--- a/ryu/ofproto/oxm_fields.py
+++ b/ryu/ofproto/oxm_fields.py
@@ -296,6 +296,8 @@ def from_jsondict(j):
field = tlv['field']
value = tlv['value']
mask = tlv.get('mask')
+ field, value, mask = [data.encode('utf-8') if isinstance(data, unicode)
+ else data for data in [field, value, mask]]
if mask is None:
uv = value
else:
--
1.7.10.4
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel