Hi, > If value is not buildin type, some twist is necessary. recursion? > For icmp, icmpv6 and lldp.
If value is not buildin type like icmp.echo it changed to inheriting PacketBase too, I think. (2013/06/06 0:43), Isaku Yamahata wrote: > 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 >> > -- --------------------------------------- 渡邊 文隆(わたなべ ふみたか) TEL:043-211-3721 (内線:26-6886) Mail:[email protected] NTTコムウェア株式会社 NW事業本部 コアNW-S部 ノードBU ネットワークSE担当 --------------------------------------- ------------------------------------------------------------------------------ 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
