On Wed, Jun 05, 2013 at 01:57:34PM +0900, watanabe.fumitaka wrote:
> 
> Signed-off-by: WATANABE Fumitaka <[email protected]>
> ---
>  ryu/lib/packet/packet_base.py |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/ryu/lib/packet/packet_base.py b/ryu/lib/packet/packet_base.py
> index b0aeca0..07b5253 100644
> --- a/ryu/lib/packet/packet_base.py
> +++ b/ryu/lib/packet/packet_base.py
> @@ -17,6 +17,7 @@
>  class PacketBase(object):
>      """A base class for a protocol (ethernet, ipv4, ...) header."""
>      _TYPES = {}
> +    _STR_CONVERT = {}
> 
>      @classmethod
>      def get_packet_type(cls, type_):
> @@ -80,3 +81,20 @@ class PacketBase(object):
>          For example, *prev* is ipv4 or ipv6 for tcp.serialize.
>          """
>          pass
> +
> +    def __str__(self):
> +        buf = ''
> +
> +        for key, value in self.__dict__.items():
> +            if key == 'protocol_name':
> +                continue
> +            if key.startswith('_'):
> +                continue
> +            if key in self._STR_CONVERT:
> +                value = self._STR_CONVERT[key](value)
> +
> +            if buf != '':
> +                buf += ', '
> +            buf += '%s=%s' % (key, repr(value))  # repr() to escape binaries

If value is not buildin type, some twist is necessary. recursion?
For icmp, icmpv6 and lldp.

thanks,

> +        return '%s(%s)' % (self.protocol_name, buf)
> +    __repr__ = __str__  # note: str(list) uses __repr__ for elements
> -- 1.7.10.4
> 
> 
> ------------------------------------------------------------------------------
> How ServiceNow helps IT people transform IT departments:
> 1. A cloud service to automate IT design, transition and operations
> 2. Dashboards that offer high-level views of enterprise services
> 3. A single system of record for all IT processes
> http://p.sf.net/sfu/servicenow-d2d-j
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

-- 
yamahata

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to