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 <[email protected]>
---
 ryu/lib/packet/ipv6.py |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/ryu/lib/packet/ipv6.py b/ryu/lib/packet/ipv6.py
index f5ee038..d51c039 100644
--- a/ryu/lib/packet/ipv6.py
+++ b/ryu/lib/packet/ipv6.py
@@ -22,7 +22,6 @@ from . import udp
 from . import sctp
 from ryu.ofproto import inet
 from ryu.lib import addrconv
-from ryu.lib import stringify


 IPV6_ADDRESS_PACK_STR = '!16s'
@@ -142,7 +141,7 @@ ipv6.register_packet_type(udp.udp, inet.IPPROTO_UDP)
 ipv6.register_packet_type(sctp.sctp, inet.IPPROTO_SCTP)


-class header(stringify.StringifyMixin):
+class header(packet_base.StringifyMixin):
     """extension header abstract class."""

     __metaclass__ = abc.ABCMeta
@@ -173,6 +172,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):
@@ -266,7 +266,7 @@ class dst_opts(opt_header):
         super(dst_opts, self).__init__(nxt, size, data)


-class option(stringify.StringifyMixin):
+class option(packet_base.StringifyMixin):
     """IPv6 (RFC 2460) Options header encoder/decoder class.

     This is used with ryu.lib.packet.ipv6.hop_opts or
@@ -434,3 +434,6 @@ class auth(header):

     def __len__(self):
         return auth._get_size(self.size)
+
+
+ipv6.set_classes(ipv6._IPV6_EXT_HEADER_TYPE)
-- 
1.7.10.4


------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to