Hello,
I agree about six.text_type -- but I'm not exactly sure where to fix this:
'ofpport' is actually an instance of
'ryu.ofproto.ofproto_v1_3_parser.OFPPort', which is AFAIK an immutable
tuple subclass containing the deserialized struct field data.
The description of the field ryu.ofproto.ofproto_v1_3_parser.OFPPort.name
says that it's a "Null-terminated string containing a human-readable name"
(i.e. a raw C-style string) so I think it might be ok for it to remain a
bytearray (Since OpenFlow doesn't specify the encoding either).
How about doing the conversion within Port.__init__? This way the
type/encoding is consistent between Python2/3 (str, utf-8) and the native
encoding remains unaffected ('name' remains a bytearray). Alternatively, we
could do this conversion in OFPPort.parser instead.
Greetings,
-Fadi Moukayed
--
>From a152299acfabf8a6f480a382dad88c0583dc4635 Mon Sep 17 00:00:00 2001
From: Fadi Moukayed <[email protected]>
Date: Thu, 8 Oct 2015 13:16:55 +0200
Subject: [PATCH] Python 3: Explicitly convert OFPPort.name from bytearray to
str (UTF8)
Signed-off-by: Fadi Moukayed <[email protected]>
---
ryu/topology/switches.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py
index 5fe5d26..f774279 100644
--- a/ryu/topology/switches.py
+++ b/ryu/topology/switches.py
@@ -69,7 +69,7 @@ class Port(object):
self.port_no = ofpport.port_no
self.hw_addr = ofpport.hw_addr
- self.name = ofpport.name
+ self.name = six.text_type(ofpport.name, 'utf-8')
def is_reserved(self):
return self.port_no > self._ofproto.OFPP_MAX
--
1.9.1
2015-10-08 10:53 GMT+02:00 IWAMOTO Toshihiro <[email protected]>:
> At Wed, 7 Oct 2015 13:09:03 +0200,
> Fadi Moukayed wrote:
> >
> > Signed-off-by: Fadi Moukayed <[email protected]>
> > ---
> > ryu/topology/switches.py | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py
> > index 5fe5d26..20d04fd 100644
> > --- a/ryu/topology/switches.py
> > +++ b/ryu/topology/switches.py
> > @@ -87,7 +87,7 @@ class Port(object):
> > return {'dpid': dpid_to_str(self.dpid),
> > 'port_no': port_no_to_str(self.port_no),
> > 'hw_addr': self.hw_addr,
> > - 'name': self.name.rstrip('\0')}
> > + 'name': self.name.decode('UTF-8').rstrip('\0')}
> >
> > # for Switch.del_port()
> > def __eq__(self, other):
>
> Hi,
>
> I think it's better to pass text_type to Port.__init__.
>
> How about changing Switches._get_switch to the following?
> (I haven't tested at all)
>
> def _get_switch(self, dpid):
> if dpid in self.dps:
> switch = Switch(self.dps[dpid])
> for ofpport in self.port_state[dpid].values():
> switch.add_port(six.text_type(ofpport, 'utf-8'))
> return switch
>
> --
> IWAMOTO Toshihiro
>
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel