the variable '_class_prefixes' of stringify.StringifyMixin is used to help the 
method 'from_jsondict()' to create the class instance.
'_class_prefixes' requires a list of the class names.
some classes have another list of the class names alreadly.
this patch adds a method which makes '_class_prefixes' by using the existing 
list.

before applying this patch:
(e.g. ryu.lib.packet.ipv6)

    # append the name to another list
    @ipv6.register_header_type(inet.IPPROTO_HOPOPTS)
    class hop_opts(opt_header):
    ...

    @ipv6.register_header_type(inet.IPPROTO_DSTOPTS)
    class dst_opts(opt_header):
    ....

    # append the name again
    ipv6._class_prefixes = ['hop_opts', 'dst_opts', ...]

after applying this patch:
(e.g. ryu.lib.packet.ipv6)

    # append the name to another list
    @ipv6.register_header_type(inet.IPPROTO_HOPOPTS)
    class hop_opts(opt_header):
    ...

    @ipv6.register_header_type(inet.IPPROTO_DSTOPTS)
    class dst_opts(opt_header):
    ....

    # create the new list from another list
    ipv6.set_classes(ipv6._IPV6_EXT_HEADER_TYPE)

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

diff --git a/ryu/lib/packet/packet_base.py b/ryu/lib/packet/packet_base.py
index cbc213f..71a9d2d 100644
--- a/ryu/lib/packet/packet_base.py
+++ b/ryu/lib/packet/packet_base.py
@@ -17,7 +17,17 @@ import abc
 from ryu.lib import stringify


-class PacketBase(stringify.StringifyMixin):
+class StringifyMixin(stringify.StringifyMixin):
+
+    @classmethod
+    def set_classes(cls, registed_dict):
+        cls._class_prefixes = []
+        for cls_ in registed_dict.values():
+            cls._class_prefixes.append(cls_.__name__)
+        cls._class_prefixes = sorted(set(cls._class_prefixes))
+
+
+class PacketBase(StringifyMixin):
     """A base class for a protocol (ethernet, ipv4, ...) header."""
     __metaclass__ = abc.ABCMeta
     _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

Reply via email to