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 <[email protected]>
---
ryu/lib/packet/icmpv6.py | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/ryu/lib/packet/icmpv6.py b/ryu/lib/packet/icmpv6.py
index d4bb00b..ff38211 100644
--- a/ryu/lib/packet/icmpv6.py
+++ b/ryu/lib/packet/icmpv6.py
@@ -22,7 +22,6 @@ import binascii
from . import packet_base
from . import packet_utils
from ryu.lib import addrconv
-from ryu.lib import stringify
ICMPV6_DST_UNREACH = 1 # dest unreachable, codes:
ICMPV6_PACKET_TOO_BIG = 2 # packet too big
@@ -146,7 +145,7 @@ class icmpv6(packet_base.PacketBase):
@icmpv6.register_icmpv6_type(ND_NEIGHBOR_SOLICIT, ND_NEIGHBOR_ADVERT)
-class nd_neighbor(stringify.StringifyMixin):
+class nd_neighbor(packet_base.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Neighbor Solicitation and
Neighbor Advertisement messages. (RFC 4861)
@@ -220,7 +219,7 @@ class nd_neighbor(stringify.StringifyMixin):
@icmpv6.register_icmpv6_type(ND_ROUTER_SOLICIT)
-class nd_router_solicit(stringify.StringifyMixin):
+class nd_router_solicit(packet_base.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Router Solicitation messages.
(RFC 4861)
@@ -289,7 +288,7 @@ class nd_router_solicit(stringify.StringifyMixin):
@icmpv6.register_icmpv6_type(ND_ROUTER_ADVERT)
-class nd_router_advert(stringify.StringifyMixin):
+class nd_router_advert(packet_base.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Router Advertisement messages.
(RFC 4861)
@@ -373,7 +372,7 @@ class nd_router_advert(stringify.StringifyMixin):
return length
-class nd_option(stringify.StringifyMixin):
+class nd_option(packet_base.StringifyMixin):
__metaclass__ = abc.ABCMeta
@@ -590,7 +589,7 @@ class nd_option_pi(nd_option):
@icmpv6.register_icmpv6_type(ICMPV6_ECHO_REPLY, ICMPV6_ECHO_REQUEST)
-class echo(stringify.StringifyMixin):
+class echo(packet_base.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Echo Request and Echo Reply
messages.
@@ -642,3 +641,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)
--
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