On Fri, Jul 19, 2013 at 01:54:37PM +0900, watanabe.fumitaka wrote:
> Signed-off-by: WATANABE Fumitaka <[email protected]>
> ---
>  ryu/lib/packet/packet.py      |    4 ++++
>  ryu/lib/packet/packet_base.py |   23 ++++++++++++++++++++++-
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/ryu/lib/packet/packet.py b/ryu/lib/packet/packet.py
> index f80948a..785a28b 100644
> --- a/ryu/lib/packet/packet.py
> +++ b/ryu/lib/packet/packet.py
> @@ -127,3 +127,7 @@ class Packet(object):
>                  issubclass(protocol, packet_base.PacketBase)):
>              return protocol in [p.__class__ for p in self.protocols]
>          return protocol in self.protocols
> +
> +    def __str__(self):
> +        return ', '.join(repr(protocol) for protocol in self.protocols)
> +    __repr__ = __str__  # note: str(list) uses __repr__ for elements
> diff --git a/ryu/lib/packet/packet_base.py b/ryu/lib/packet/packet_base.py
> index e61e7ee..519cd2f 100644
> --- a/ryu/lib/packet/packet_base.py
> +++ b/ryu/lib/packet/packet_base.py
> @@ -14,9 +14,30 @@
>  # limitations under the License.
> 
>  import abc
> +from ryu.lib import stringify
> 
> 
> -class PacketBase(object):
> +class StringifyMixin(stringify.StringifyMixin):
> +
> +    def __init__(self):
> +        super(StringifyMixin, self).__init__()
> +
> +    def register_str_options(self, convert_list):
> +        # individual string conversion functions
> +        self._convert_list = getattr(self, '_convert_list', {})
> +        self._convert_list.update(convert_list)

Looks like conversion rules are class-wise static.
So it would work to add class attributes, _convert_list, to each
classes instead of dynamically adding conversion rule to each instances.


> +
> +    def stringify_attrs(self):
> +        attrs = super(StringifyMixin, self).stringify_attrs()
> +        convert_list = getattr(self, '_convert_list', {})
> +
> +        for k, v in attrs:
> +            if k in convert_list:
> +                v = convert_list[k](v)
> +            yield(k, v)
> +
> +
> +class PacketBase(StringifyMixin):
>      """A base class for a protocol (ethernet, ipv4, ...) header."""
>      __metaclass__ = abc.ABCMeta
>      _TYPES = {}
> -- 1.7.10.4
> 
> 
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

-- 
yamahata

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to