summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYuichi Ito <ito.yuichi0@gmail.com>2013-12-12 15:33:29 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-12-12 18:21:59 +0900
commitc71af613c925c2be8d5f73c49f6129424092f175 (patch)
treedc5aac585e1538c8790d05b677c5139b030c481a
parentf460bc61a0a84f9a887f2c599e3e8e7d0006322e (diff)
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>
-rw-r--r--ryu/lib/packet/ipv6.py4
1 files changed, 4 insertions, 0 deletions
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)