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 | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/ryu/lib/packet/dhcp.py b/ryu/lib/packet/dhcp.py
index 6e0cab1..75a6d9c 100644
--- a/ryu/lib/packet/dhcp.py
+++ b/ryu/lib/packet/dhcp.py
@@ -58,7 +58,6 @@ import struct
from . import packet_base
from ryu.lib import addrconv
-from ryu.lib import stringify
DHCP_BOOT_REQUEST = 1
@@ -139,6 +138,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,
@@ -203,7 +203,7 @@ class dhcp(packet_base.PacketBase):
self.sname, self.boot_file, seri_opt)
-class options(stringify.StringifyMixin):
+class options(packet_base.StringifyMixin):
"""DHCP (RFC 2132) options encoder/decoder class.
This is used with ryu.lib.packet.dhcp.dhcp.
@@ -230,6 +230,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):
@@ -266,7 +267,7 @@ class options(stringify.StringifyMixin):
return seri_opt
-class option(stringify.StringifyMixin):
+class option(packet_base.StringifyMixin):
"""DHCP (RFC 2132) options encoder/decoder class.
This is used with ryu.lib.packet.dhcp.dhcp.options.
--
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