although DHCP 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 dhcp
    msg1 = dhcp.dhcp(op=dhcp.DHCP_BOOT_REQUEST, chaddr='00:00:00:00:00:00', 
options=dhcp.options())
    print msg1
    jsondict = msg1.to_jsondict()
    msg2 = dhcp.dhcp.from_jsondict(jsondict['dhcp'])
    print msg2
    print str(msg1) == str(msg2)

before applying this patch:

    
dhcp(boot_file='',chaddr='00:00:00:00:00:00',ciaddr='0.0.0.0',flags=0,giaddr='0.0.0.0',hlen=17,hops=0,htype=1,op=1,options=options(magic_cookie='99.130.83.99',option_list=[],options_len=0),secs=0,siaddr='0.0.0.0',sname='',xid=2430470794,yiaddr='0.0.0.0')
    
dhcp(boot_file='',chaddr='00:00:00:00:00:00',ciaddr='0.0.0.0',flags=0,giaddr='0.0.0.0',hlen=17,hops=0,htype=1,op=1,options={'options':
 {'option_list': [], 'magic_cookie': '99.130.83.99', 'options_len': 
0}},secs=0,siaddr='0.0.0.0',sname='',xid=2430470794,yiaddr='0.0.0.0')
    False

after applying this patch:

    
dhcp(boot_file='',chaddr='00:00:00:00:00:00',ciaddr='0.0.0.0',flags=0,giaddr='0.0.0.0',hlen=17,hops=0,htype=1,op=1,options=options(magic_cookie='99.130.83.99',option_list=[],options_len=0),secs=0,siaddr='0.0.0.0',sname='',xid=1161619526,yiaddr='0.0.0.0')
    
dhcp(boot_file='',chaddr='00:00:00:00:00:00',ciaddr='0.0.0.0',flags=0,giaddr='0.0.0.0',hlen=17,hops=0,htype=1,op=1,options=options(magic_cookie='99.130.83.99',option_list=[],options_len=0),secs=0,siaddr='0.0.0.0',sname='',xid=1161619526,yiaddr='0.0.0.0')
    True

Signed-off-by: Yuichi Ito <[email protected]>
---
 ryu/lib/packet/dhcp.py |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/ryu/lib/packet/dhcp.py b/ryu/lib/packet/dhcp.py
index 6e0cab1..00d1de8 100644
--- a/ryu/lib/packet/dhcp.py
+++ b/ryu/lib/packet/dhcp.py
@@ -139,6 +139,7 @@ class dhcp(packet_base.PacketBase):
     _DHCP_PACK_STR = '!BBBBIHH4s4s4s4s16s64s128s'
     _DHCP_CHADDR_LEN = 16
     _HARDWARE_TYPE_ETHERNET = 1
+    _class_prefixes = ['options']

     def __init__(self, op, chaddr, options, htype=_HARDWARE_TYPE_ETHERNET,
                  hlen=0, hops=0, xid=None, secs=0, flags=0,
@@ -230,6 +231,7 @@ class options(stringify.StringifyMixin):
     # same magic cookie as is defined in RFC 1497
     _MAGIC_COOKIE = '99.130.83.99'
     _OPT_TAG_LEN_BYTE = 2
+    _class_prefixes = ['option']

     def __init__(self, option_list=None, options_len=0,
                  magic_cookie=_MAGIC_COOKIE):
-- 
1.7.10.4


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to