From c71af613c925c2be8d5f73c49f6129424092f175 Mon Sep 17 00:00:00 2001 From: Yuichi Ito Date: Thu, 12 Dec 2013 15:33:29 +0900 Subject: 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 "", line 1, in 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 Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/ipv6.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ryu/lib/packet/ipv6.py b/ryu/lib/packet/ipv6.py index f5ee038e..9f04da5f 100644 --- a/ryu/lib/packet/ipv6.py +++ b/ryu/lib/packet/ipv6.py @@ -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) -- cgit v1.2.3