packet lib: icmpv6: fix reversibility about json

although ICMPv6 is using internal classes, no class is registered into '_class_prefixes'.
therefore, from_jsondict() does not work correctly.
this patch makes from_jsondict() to work correctly by registering internal classes into '_class_prefixes'.

examination code:

    from ryu.lib.packet import icmpv6
    msg1 = icmpv6.icmpv6(data=icmpv6.nd_neighbor())
    print msg1
    jsondict = msg1.to_jsondict()
    msg2 = icmpv6.icmpv6.from_jsondict(jsondict['icmpv6'])
    print msg2
    print str(msg1) == str(msg2)

before applying this patch:

    icmpv6(code=0,csum=0,data=nd_neighbor(dst='::',option=None,res=0),type_=0)
    icmpv6(code=0,csum=0,data={'nd_neighbor': {'res': 0, 'dst': '::', 'option': None}},type_=0)
    False

after applying this patch:

    icmpv6(code=0,csum=0,data=nd_neighbor(dst='::',option=None,res=0),type_=0)
    icmpv6(code=0,csum=0,data=nd_neighbor(dst='::',option=None,res=0),type_=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:
Yuichi Ito 2013-12-12 15:33:05 +09:00 committed by FUJITA Tomonori
parent 3731f46ba2
commit f460bc61a0

View File

@ -642,3 +642,9 @@ class echo(stringify.StringifyMixin):
if self.data is not None:
length += len(self.data)
return length
icmpv6.set_classes(icmpv6._ICMPV6_TYPES)
nd_neighbor.set_classes(nd_neighbor._ND_OPTION_TYPES)
nd_router_solicit.set_classes(nd_router_solicit._ND_OPTION_TYPES)
nd_router_advert.set_classes(nd_router_advert._ND_OPTION_TYPES)