From 7a5b83daa6ea22938fcfbf177a94cacb4ff7aa7a Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Mon, 18 Aug 2014 09:19:06 +0900 Subject: [PATCH] bgp: move _TYPE declaration of IPAddrPrefix to the appropriate place. _IPAddrPrefix can be inherited by labeled addr prefix. In that case, variable 'addr' is tuple and not string. so declare to parse 'addr' in 'ascii' format in _IPAddrPrefix cause following error. this patch fix this bug. p = LabelledIPAddrPrefix(28, ([1], '192.168.0.0')) p.to_jsondict() Traceback (most recent call last): File "./parse_labeled_addr_prefix.py", line 11, in p.to_jsondict() File "/home/wataru/ryu/ryu/lib/stringify.py", line 210, in to_jsondict dict_[k] = encode(k, v) File "/home/wataru/ryu/ryu/lib/stringify.py", line 208, in encode = lambda k, x: self._encode_value(k, x, encode_string) File "/home/wataru/ryu/ryu/lib/stringify.py", line 155, in _encode_value return cls._get_encoder(k, encode_string)(v) File "/home/wataru/ryu/ryu/lib/stringify.py", line 56, in encode return unicode(v, 'ascii') TypeError: coercing to Unicode: need string or buffer, tuple found Signed-off-by: ISHIDA Wataru Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/bgp.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index 698d0fdb..0a96b42a 100644 --- a/ryu/lib/packet/bgp.py +++ b/ryu/lib/packet/bgp.py @@ -852,12 +852,6 @@ class _UnlabelledAddrPrefix(_AddrPrefix): class _IPAddrPrefix(_AddrPrefix): - _TYPE = { - 'ascii': [ - 'addr' - ] - } - @staticmethod def _prefix_to_bin(addr): (addr,) = addr @@ -869,12 +863,6 @@ class _IPAddrPrefix(_AddrPrefix): class _IP6AddrPrefix(_AddrPrefix): - _TYPE = { - 'ascii': [ - 'addr' - ] - } - @staticmethod def _prefix_to_bin(addr): (addr,) = addr @@ -923,6 +911,11 @@ class _VPNAddrPrefix(_AddrPrefix): class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix): ROUTE_FAMILY = RF_IPv4_UC + _TYPE = { + 'ascii': [ + 'addr' + ] + } @property def prefix(self): @@ -935,6 +928,11 @@ class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix): class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix): ROUTE_FAMILY = RF_IPv6_UC + _TYPE = { + 'ascii': [ + 'addr' + ] + } @property def prefix(self):