In python3, b'abc'[0] isn't a string but a int value and ord() should not
be used.

Signed-off-by: IWAMOTO Toshihiro <[email protected]>
---
 ryu/lib/mac.py            | 13 ++++++++++---
 ryu/lib/packet/bgp.py     |  2 +-
 ryu/ofproto/oxx_fields.py |  8 +++++++-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/ryu/lib/mac.py b/ryu/lib/mac.py
index 05e1a73..88ab336 100644
--- a/ryu/lib/mac.py
+++ b/ryu/lib/mac.py
@@ -14,8 +14,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import six
+
 from ryu.lib import addrconv
 
+if six.PY3:
+    _ord = int
+else:
+    _ord = ord
+
 # string representation
 HADDR_PATTERN = r'([0-9a-f]{2}:){5}[0-9a-f]{2}'
 
@@ -28,7 +35,7 @@ UNICAST = '01:00:00:00:00:00'
 
 
 def is_multicast(addr):
-    return bool(ord(addr[0]) & 0x01)
+    return bool(_ord(addr[0]) & 0x01)
 
 
 def haddr_to_str(addr):
@@ -52,5 +59,5 @@ def haddr_to_bin(string):
 
 
 def haddr_bitand(addr, mask):
-    return ''.join(chr(ord(a) & ord(m)) for (a, m)
-                   in zip(addr, mask))
+    return b''.join(six.int2byte(_ord(a) & _ord(m)) for (a, m)
+                    in zip(addr, mask))
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 6b880c2..575da9d 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -750,7 +750,7 @@ class _AddrPrefix(StringifyMixin):
             # clear trailing bits in the last octet.
             # rfc doesn't require this.
             mask = 0xff00 >> (self.length % 8)
-            last_byte = chr(ord(bin_addr[byte_length - 1]) & mask)
+            last_byte = chr(six.indexbytes(bin_addr, byte_length - 1) & mask)
             bin_addr = bin_addr[:byte_length - 1] + last_byte
         self.addr = self._from_bin(bin_addr)
 
diff --git a/ryu/ofproto/oxx_fields.py b/ryu/ofproto/oxx_fields.py
index 8537b44..be41a53 100644
--- a/ryu/ofproto/oxx_fields.py
+++ b/ryu/ofproto/oxx_fields.py
@@ -24,12 +24,18 @@
 #   mask is None if no mask.
 
 import itertools
+import six
 import struct
 
 from ryu.ofproto import ofproto_common
 from ryu.lib.pack_utils import msg_pack_into
 from ryu.lib import type_desc
 
+if six.PY3:
+    _ord = int
+else:
+    _ord = ord
+
 # 'OFPXXC_EXPERIMENTER' has not corresponding field in the specification.
 # This is transparently value for Experimenter class ID for OXM/OXS.
 OFPXXC_EXPERIMENTER = 0xffff
@@ -122,7 +128,7 @@ def _normalize_user(oxx, mod, k, uv):
         return (k, uv)
     # apply mask
     if m is not None:
-        v = ''.join(chr(ord(x) & ord(y)) for (x, y) in itertools.izip(v, m))
+        v = b''.join(six.int2byte(_ord(x) & _ord(y)) for (x, y) in zip(v, m))
     try:
         to_user = getattr(mod, oxx + '_to_user')
         (k2, uv2) = to_user(n, v, m)
-- 
2.1.4


------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to