mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 13:56:09 +02:00
packet lib: ipv6: fix reversibility about json
although IPv6 is using internal classes, no class is registered into '_class_prefixes'.
therefore, AssertionError occurs in from_jsondict() when the argument 'ext_hdrs' was processed.
this patch makes from_jsondict() to work correctly by registering internal classes into '_class_prefixes'.
examination code:
from ryu.lib.packet import ipv6
msg1 = ipv6.ipv6(ext_hdrs=[ipv6.hop_opts()])
print msg1
jsondict = msg1.to_jsondict()
msg2 = ipv6.ipv6.from_jsondict(jsondict['ipv6'])
print msg2
print str(msg1) == str(msg2)
before applying this patch:
ipv6(dst='::',ext_hdrs=[hop_opts(data=None,nxt=6,size=0)],flow_label=0,hop_limit=255,nxt=6,payload_length=0,src='::',traffic_class=0,version=6)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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/ipv6.py", line 86, in __init__
assert isinstance(ext_hdr, header)
AssertionError
after applying this patch:
ipv6(dst='::',ext_hdrs=[hop_opts(data=None,nxt=6,size=0)],flow_label=0,hop_limit=255,nxt=6,payload_length=0,src='::',traffic_class=0,version=6)
ipv6(dst='::',ext_hdrs=[hop_opts(data=None,nxt=6,size=0)],flow_label=0,hop_limit=255,nxt=6,payload_length=0,src='::',traffic_class=0,version=6)
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
f460bc61a0
commit
c71af613c9
@ -173,6 +173,7 @@ class opt_header(header):
|
||||
_PACK_STR = '!BB'
|
||||
_MIN_LEN = struct.calcsize(_PACK_STR)
|
||||
_FIX_SIZE = 8
|
||||
_class_prefixes = ['option']
|
||||
|
||||
@abc.abstractmethod
|
||||
def __init__(self, nxt, size, data):
|
||||
@ -434,3 +435,6 @@ class auth(header):
|
||||
|
||||
def __len__(self):
|
||||
return auth._get_size(self.size)
|
||||
|
||||
|
||||
ipv6.set_classes(ipv6._IPV6_EXT_HEADER_TYPE)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user