diff --git a/ryu/lib/mac.py b/ryu/lib/mac.py index 05e1a738..88ab3363 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 6b880c2f..575da9d2 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 8537b44f..be41a531 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)