mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 13:56:09 +02:00
packet lib: sctp: fix reversibility about json
although SCTP is using internal classes, no class is registered into '_class_prefixes'.
therefore, AssertionError occurs in from_jsondict() when the argument 'param' was processed.
this patch makes from_jsondict() to work correctly by registering internal classes into '_class_prefixes'.
examination code:
from ryu.lib.packet import sctp
msg1 = sctp.sctp(chunks=[sctp.chunk_init(params=[sctp.param_cookie_preserve()])])
print msg1
jsondict = msg1.to_jsondict()
msg2 = sctp.sctp.from_jsondict(jsondict['sctp'])
print msg2
print str(msg1) == str(msg2)
before applying this patch:
sctp(chunks=[chunk_init(a_rwnd=0,flags=0,i_tsn=0,init_tag=0,length=0,mis=0,os=0,params=[param_cookie_preserve(length=0,value=0)])],csum=0,dst_port=0,src_port=0,vtag=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 291, in from_jsondict
kwargs = cls._restore_args(_mapdict_kv(decode, dict_))
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 46, in <lambda>
_mapdict_kv = lambda f, d: dict([(k, f(k, v)) for k, v in d.items()])
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 290, in <lambda>
decode = lambda k, x: cls._decode_value(k, x, decode_string)
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 234, in _decode_value
return cls._get_decoder(k, decode_string)(json_value)
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 242, in _decode
v = map(_decode, json_value)
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 245, in _decode
v = cls.obj_from_jsondict(json_value)
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 223, in obj_from_jsondict
return obj_cls.from_jsondict(v)
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/stringify.py", line 293, in from_jsondict
return cls(**dict(kwargs, **additional_args))
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/packet/sctp.py", line 273, in __init__
assert isinstance(one, param)
AssertionError
after applying this patch:
sctp(chunks=[chunk_init(a_rwnd=0,flags=0,i_tsn=0,init_tag=0,length=0,mis=0,os=0,params=[param_cookie_preserve(length=0,value=0)])],csum=0,dst_port=0,src_port=0,vtag=0)
sctp(chunks=[chunk_init(a_rwnd=0,flags=0,i_tsn=0,init_tag=0,length=0,mis=0,os=0,params=[param_cookie_preserve(length=0,value=0)])],csum=0,dst_port=0,src_port=0,vtag=0)
True
Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
e52b732840
commit
a1ebf2aeca
@ -257,6 +257,7 @@ class chunk_init_base(chunk):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
_PACK_STR = '!BBHIIHHI'
|
||||
_MIN_LEN = struct.calcsize(_PACK_STR)
|
||||
_class_prefixes = ['param_']
|
||||
|
||||
def __init__(self, flags=0, length=0, init_tag=0, a_rwnd=0, os=0,
|
||||
mis=0, i_tsn=0, params=None):
|
||||
@ -306,6 +307,7 @@ class chunk_init_base(chunk):
|
||||
class chunk_heartbeat_base(chunk):
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
_class_prefixes = ['param_']
|
||||
|
||||
def __init__(self, flags=0, length=0, info=None):
|
||||
super(chunk_heartbeat_base, self).__init__(
|
||||
@ -1448,6 +1450,7 @@ class cause_unresolvable_addr(cause_with_value):
|
||||
============== =====================================================
|
||||
"""
|
||||
|
||||
_class_prefixes = ['param_']
|
||||
_RECOGNIZED_PARAMS = {}
|
||||
|
||||
@staticmethod
|
||||
@ -1662,6 +1665,7 @@ class cause_restart_with_new_addr(cause_with_value):
|
||||
============== =====================================================
|
||||
"""
|
||||
|
||||
_class_prefixes = ['param_']
|
||||
_RECOGNIZED_PARAMS = {}
|
||||
|
||||
@staticmethod
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user