Remove "six" library

This patch also removes some unneeded imported libraries.

Story: #2010182
Task: #45863
Change-Id: Ife9d349eb9c92f2a39719e76e82fe20c010fe230
This commit is contained in:
Rodolfo Alonso Hernandez 2022-07-21 13:18:40 +02:00 committed by Rodolfo Alonso
parent 2495ebdff9
commit abb436deb3
80 changed files with 655 additions and 857 deletions

View File

@ -37,8 +37,6 @@ import logging
import time
import random
import six
from os_ken.base import app_manager
from os_ken.controller import event
from os_ken.controller import ofp_event
@ -231,7 +229,7 @@ class BFDSession(object):
BFD packet receiver.
"""
LOG.debug("[BFD][%s][RECV] BFD Control received: %s",
hex(self._local_discr), six.binary_type(bfd_pkt))
hex(self._local_discr), bytes(bfd_pkt))
self._remote_discr = bfd_pkt.my_discr
self._remote_state = bfd_pkt.state
self._remote_demand_mode = bfd_pkt.flags & bfd.BFD_FLAG_DEMAND

View File

@ -14,14 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from os_ken.lib import addrconv
if six.PY3:
_ord = int
else:
_ord = ord
import struct
# string representation
HADDR_PATTERN = r'([0-9a-f]{2}:){5}[0-9a-f]{2}'
@ -35,7 +29,7 @@ UNICAST = '01:00:00:00:00:00'
def is_multicast(addr):
return bool(_ord(addr[0]) & 0x01)
return bool(int(addr[0]) & 0x01)
def haddr_to_str(addr):
@ -68,5 +62,5 @@ def haddr_to_bin(string):
def haddr_bitand(addr, mask):
return b''.join(six.int2byte(_ord(a) & _ord(m)) for (a, m)
return b''.join(struct.Struct(">B").pack(int(a) & int(m)) for (a, m)
in zip(addr, mask))

View File

@ -23,9 +23,6 @@ import logging
import struct
import time
import netaddr
import six
from os_ken.lib import addrconv
from os_ken.lib import ip
from os_ken.lib import stringify
@ -37,8 +34,8 @@ from os_ken.lib.packet import ospf
LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class MrtRecord(stringify.StringifyMixin, type_desc.TypeDisp):
class MrtRecord(stringify.StringifyMixin, type_desc.TypeDisp,
metaclass=abc.ABCMeta):
"""
MRT record.
"""
@ -87,7 +84,7 @@ class MrtRecord(stringify.StringifyMixin, type_desc.TypeDisp):
@classmethod
def parse_pre(cls, buf):
buf = six.binary_type(buf) # for convenience
buf = bytes(buf) # for convenience
header_fields, _ = cls.parse_common_header(buf)
# timestamp = header_fields[0]
@ -105,7 +102,7 @@ class MrtRecord(stringify.StringifyMixin, type_desc.TypeDisp):
@classmethod
def parse(cls, buf):
buf = six.binary_type(buf) # for convenience
buf = bytes(buf) # for convenience
header_fields, rest = cls.parse_common_header(buf)
# timestamp = header_fields[0]
@ -205,8 +202,8 @@ class ExtendedTimestampMrtRecord(MrtRecord):
self.ms_timestamp)
@six.add_metaclass(abc.ABCMeta)
class MrtMessage(stringify.StringifyMixin, type_desc.TypeDisp):
class MrtMessage(stringify.StringifyMixin, type_desc.TypeDisp,
metaclass=abc.ABCMeta):
"""
MRT Message in record.
"""
@ -310,8 +307,7 @@ class Ospf2MrtRecord(MrtCommonRecord):
Ospf2MrtMessage._UNKNOWN_TYPE = Ospf2MrtMessage
@six.add_metaclass(abc.ABCMeta)
class TableDumpMrtMessage(MrtMessage):
class TableDumpMrtMessage(MrtMessage, metaclass=abc.ABCMeta):
"""
MRT Message for the TABLE_DUMP Type.
"""
@ -425,8 +421,7 @@ class TableDumpAfiIPv6MrtMessage(TableDumpMrtMessage):
HEADER_SIZE = struct.calcsize(_HEADER_FMT)
@six.add_metaclass(abc.ABCMeta)
class TableDump2MrtMessage(MrtMessage):
class TableDump2MrtMessage(MrtMessage, metaclass=abc.ABCMeta):
"""
MRT Message for the TABLE_DUMP_V2 Type.
"""
@ -617,8 +612,8 @@ class MrtPeer(stringify.StringifyMixin):
return buf + ip_addr + as_num
@six.add_metaclass(abc.ABCMeta)
class TableDump2AfiSafiSpecificRibMrtMessage(TableDump2MrtMessage):
class TableDump2AfiSafiSpecificRibMrtMessage(TableDump2MrtMessage,
metaclass=abc.ABCMeta):
"""
MRT Message for the TABLE_DUMP_V2 Type and the AFI/SAFI-specific
RIB subtypes.
@ -956,8 +951,7 @@ class MrtRibEntry(stringify.StringifyMixin):
self.attr_len) + bgp_attrs_bin
@six.add_metaclass(abc.ABCMeta)
class Bgp4MpMrtMessage(MrtMessage):
class Bgp4MpMrtMessage(MrtMessage, metaclass=abc.ABCMeta):
"""
MRT Message for the BGP4MP Type.
"""

View File

@ -17,7 +17,6 @@ import base64
import logging
import netaddr
import six
from os_ken.lib import dpid
from os_ken.lib import hub
@ -178,7 +177,7 @@ def to_match_vid(value, ofpvid_present):
# applied. OTOH, If it is described as hexadecimal string,
# treated as values of oxm_value (including OFPVID_PRESENT
# bit), and OFPVID_PRESENT bit is NOT automatically applied
if isinstance(value, six.integer_types):
if isinstance(value, int):
# described as decimal int value
return value | ofpvid_present

View File

@ -12,11 +12,9 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import abc
import logging
from abc import ABCMeta, abstractmethod
import six
from os_ken.lib.packet import packet
@ -38,12 +36,11 @@ def packet_in_filter(cls, args=None, logging=False):
return _packet_in_filter
@six.add_metaclass(ABCMeta)
class PacketInFilterBase(object):
class PacketInFilterBase(object, metaclass=abc.ABCMeta):
def __init__(self, args):
self.args = args
@abstractmethod
@abc.abstractmethod
def filter(self, pkt):
pass

View File

@ -25,8 +25,6 @@ import re
import sys
import weakref
import six
import ovs.db.data
import ovs.db.parser
import ovs.db.schema
@ -883,7 +881,7 @@ class VSCtlContext(object):
for ovsrec_row in self.idl.tables[
vsctl_row_id.table].rows.values():
name = getattr(ovsrec_row, vsctl_row_id.name_column)
assert isinstance(name, (list, str, six.text_type))
assert isinstance(name, (list, str, str))
if not isinstance(name, list) and name == record_id:
if referrer:
vsctl_fatal('multiple rows in %s match "%s"' %

View File

@ -75,14 +75,12 @@ format of types:
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
"""
import binascii
import hashlib
import random
import six
import operator
import struct
from . import packet_base
from os_ken.lib import addrconv
from os_ken.lib import stringify
BFD_STATE_ADMIN_DOWN = 0
@ -238,7 +236,7 @@ class bfd(packet_base.PacketBase):
flags = flags & 0x3f
if flags & BFD_FLAG_AUTH_PRESENT:
auth_type = six.indexbytes(buf, cls._PACK_STR_LEN)
auth_type = operator.getitem(buf, cls._PACK_STR_LEN)
auth_cls = cls._auth_parsers[auth_type].\
parser(buf[cls._PACK_STR_LEN:])[0]
else:
@ -394,7 +392,7 @@ class SimplePassword(BFDAuth):
(auth_type, auth_len) = cls.parser_hdr(buf)
assert auth_type == cls.auth_type
auth_key_id = six.indexbytes(buf, cls._PACK_HDR_STR_LEN)
auth_key_id = operator.getitem(buf, cls._PACK_HDR_STR_LEN)
password = buf[cls._PACK_HDR_STR_LEN + cls._PACK_STR_LEN:auth_len]

View File

@ -30,12 +30,12 @@ import functools
import io
import itertools
import math
import operator
import re
import socket
import struct
import netaddr
import six
from os_ken.lib.stringify import StringifyMixin
from os_ken.lib.packet import afi as addr_family
@ -52,7 +52,6 @@ from os_ken.lib.pack_utils import msg_pack_into
from os_ken.utils import binary_str
from os_ken.utils import import_module
reduce = six.moves.reduce
TCP_SERVER_PORT = 179
@ -187,7 +186,7 @@ class _Value(object):
@classmethod
def parse_value(cls, buf):
values = struct.unpack_from(cls._VALUE_PACK_STR, six.binary_type(buf))
values = struct.unpack_from(cls._VALUE_PACK_STR, bytes(buf))
return dict(zip(cls._VALUE_FIELDS, values))
def serialize_value(self):
@ -625,7 +624,7 @@ class _RouteDistinguisher(StringifyMixin, TypeDisp, _Value):
@classmethod
def parser(cls, buf):
assert len(buf) == 8
(type_,) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf))
(type_,) = struct.unpack_from(cls._PACK_STR, bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
subcls = cls._lookup_type(type_)
return subcls(**subcls.parse_value(rest))
@ -650,7 +649,7 @@ class _RouteDistinguisher(StringifyMixin, TypeDisp, _Value):
value = self.serialize_value()
buf = bytearray()
msg_pack_into(self._PACK_STR, buf, 0, self.type)
return six.binary_type(buf + value)
return bytes(buf + value)
@property
def formatted_str(self):
@ -709,8 +708,7 @@ class BGPFourOctetAsRD(_RouteDistinguisher):
self.do_init(BGPFourOctetAsRD, self, kwargs)
@six.add_metaclass(abc.ABCMeta)
class _AddrPrefix(StringifyMixin):
class _AddrPrefix(StringifyMixin, metaclass=abc.ABCMeta):
_PACK_STR = '!B' # length
def __init__(self, length, addr, prefixes=None, **kwargs):
@ -737,7 +735,7 @@ class _AddrPrefix(StringifyMixin):
@classmethod
def parser(cls, buf):
(length, ) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf))
(length, ) = struct.unpack_from(cls._PACK_STR, bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
byte_length = (length + 7) // 8
addr = cls._from_bin(rest[:byte_length])
@ -754,8 +752,8 @@ class _AddrPrefix(StringifyMixin):
# clear trailing bits in the last octet.
# rfc doesn't require this.
mask = 0xff00 >> (self.length % 8)
last_byte = six.int2byte(
six.indexbytes(bin_addr, byte_length - 1) & mask)
last_byte = struct.Struct(">B").pack(
operator.getitem(bin_addr, byte_length - 1) & mask)
bin_addr = bin_addr[:byte_length - 1] + last_byte
self.addr = self._from_bin(bin_addr)
@ -818,12 +816,12 @@ class _LabelledAddrPrefix(_AddrPrefix):
(label & 0xff0000) >> 16,
(label & 0x00ff00) >> 8,
(label & 0x0000ff) >> 0)
return six.binary_type(buf)
return bytes(buf)
@classmethod
def _label_from_bin(cls, label):
(b1, b2, b3) = struct.unpack_from(cls._LABEL_PACK_STR,
six.binary_type(label))
bytes(label))
rest = label[struct.calcsize(cls._LABEL_PACK_STR):]
return (b1 << 16) | (b2 << 8) | b3, rest
@ -835,8 +833,9 @@ class _LabelledAddrPrefix(_AddrPrefix):
if labels and labels[-1] not in cls._WITHDRAW_LABELS:
labels[-1] |= 1 # bottom of stack
bin_labels = list(cls._label_to_bin(l) for l in labels)
return bytes(reduce(lambda x, y: x + y, bin_labels,
bytearray()) + cls._prefix_to_bin(rest))
return bytes(
functools.reduce(lambda x, y: x + y, bin_labels,
bytearray()) + cls._prefix_to_bin(rest))
@classmethod
def _has_no_label(cls, bin_):
@ -1067,14 +1066,14 @@ class EvpnEsi(StringifyMixin, TypeDisp, _Value):
@classmethod
def parser(cls, buf):
(esi_type,) = struct.unpack_from(
cls._PACK_STR, six.binary_type(buf))
cls._PACK_STR, bytes(buf))
subcls = cls._lookup_type(esi_type)
return subcls(**subcls.parse_value(buf[1:cls._ESI_LEN]))
def serialize(self):
buf = bytearray()
msg_pack_into(EvpnEsi._PACK_STR, buf, 0, self.type)
return six.binary_type(buf + self.serialize_value())
return bytes(buf + self.serialize_value())
@property
def formatted_str(self):
@ -1357,7 +1356,7 @@ class EvpnNLRI(StringifyMixin, TypeDisp):
@classmethod
def parser(cls, buf):
(route_type, length) = struct.unpack_from(
cls._PACK_STR, six.binary_type(buf))
cls._PACK_STR, bytes(buf))
offset = cls._PACK_STR_SIZE + length
subcls = cls._lookup_type(route_type)
values = subcls.parse_value(buf[cls._PACK_STR_SIZE:offset])
@ -1381,7 +1380,7 @@ class EvpnNLRI(StringifyMixin, TypeDisp):
@staticmethod
def _rd_to_bin(rd):
return six.binary_type(rd.serialize())
return bytes(rd.serialize())
@staticmethod
def _esi_from_bin(buf):
@ -1393,7 +1392,7 @@ class EvpnNLRI(StringifyMixin, TypeDisp):
@staticmethod
def _ethernet_tag_id_from_bin(buf):
return type_desc.Int4.to_user(six.binary_type(buf[:4])), buf[4:]
return type_desc.Int4.to_user(bytes(buf[:4])), buf[4:]
@staticmethod
def _ethernet_tag_id_to_bin(tag_id):
@ -1401,7 +1400,7 @@ class EvpnNLRI(StringifyMixin, TypeDisp):
@staticmethod
def _mac_addr_len_from_bin(buf):
return type_desc.Int1.to_user(six.binary_type(buf[:1])), buf[1:]
return type_desc.Int1.to_user(bytes(buf[:1])), buf[1:]
@staticmethod
def _mac_addr_len_to_bin(mac_len):
@ -1418,7 +1417,7 @@ class EvpnNLRI(StringifyMixin, TypeDisp):
@staticmethod
def _ip_addr_len_from_bin(buf):
return type_desc.Int1.to_user(six.binary_type(buf[:1])), buf[1:]
return type_desc.Int1.to_user(bytes(buf[:1])), buf[1:]
@staticmethod
def _ip_addr_len_to_bin(ip_len):
@ -1444,7 +1443,7 @@ class EvpnNLRI(StringifyMixin, TypeDisp):
@staticmethod
def _vni_from_bin(buf):
return vxlan.vni_from_bin(six.binary_type(buf[:3])), buf[3:]
return vxlan.vni_from_bin(bytes(buf[:3])), buf[3:]
@staticmethod
def _vni_to_bin(vni):
@ -2033,7 +2032,7 @@ class _FlowSpecNLRIBase(StringifyMixin, TypeDisp):
@classmethod
def parser(cls, buf):
(length,) = struct.unpack_from(
cls._LENGTH_LONG_FMT, six.binary_type(buf))
cls._LENGTH_LONG_FMT, bytes(buf))
if length < cls._LENGTH_THRESHOLD:
length >>= 8
@ -2512,7 +2511,7 @@ class _FlowSpecComponentBase(StringifyMixin, TypeDisp):
@classmethod
def parse_header(cls, rest, afi):
(type_,) = struct.unpack_from(
cls._BASE_STR, six.binary_type(rest))
cls._BASE_STR, bytes(rest))
rest = rest[cls._BASE_STR_SIZE:]
return cls._lookup_type(type_, afi), rest
@ -2641,7 +2640,7 @@ class _FlowSpecIPv6PrefixBase(_FlowSpecIPv6Component, IP6AddrPrefix):
@classmethod
def parser(cls, buf):
(length, offset) = struct.unpack_from(
cls._PACK_STR, six.binary_type(buf))
cls._PACK_STR, bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
byte_length = (length + 7) // 8
addr = cls._from_bin(rest[:byte_length])
@ -2694,7 +2693,7 @@ class _FlowSpecL2VPNPrefixBase(_FlowSpecL2VPNComponent):
@classmethod
def parse_body(cls, buf):
(length, addr) = struct.unpack_from(
cls._PACK_STR, six.binary_type(buf))
cls._PACK_STR, bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
addr = addrconv.mac.bin_to_text(addr)
return cls(length=length, addr=addr), rest
@ -2787,7 +2786,7 @@ class _FlowSpecOperatorBase(_FlowSpecComponentBase):
@classmethod
def parse_body(cls, rest):
(operator,) = struct.unpack_from(cls._OPE_PACK_STR,
six.binary_type(rest))
bytes(rest))
rest = rest[cls._OPE_PACK_STR_SIZE:]
length = 1 << ((operator & cls._LENGTH_BIT_MASK) >> 4)
value_type = type_desc.IntDescr(length)
@ -3303,7 +3302,7 @@ class RouteTargetMembershipNLRI(StringifyMixin):
def _is_valid_asn(self, asn):
"""Returns True if the given AS number is Two or Four Octet."""
if isinstance(asn, six.integer_types) and 0 <= asn <= 0xffffffff:
if isinstance(asn, int) and 0 <= asn <= 0xffffffff:
return True
else:
return False
@ -3418,7 +3417,7 @@ class _OptParam(StringifyMixin, TypeDisp, _Value):
@classmethod
def parser(cls, buf):
(type_, length) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf))
bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
value = bytes(rest[:length])
rest = rest[length:]
@ -3471,7 +3470,7 @@ class _OptParamCapability(_OptParam, TypeDisp):
caps = []
while len(buf) > 0:
(code, length) = struct.unpack_from(cls._CAP_HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
value = buf[struct.calcsize(cls._CAP_HDR_PACK_STR):]
buf = buf[length + 2:]
kwargs = {
@ -3542,7 +3541,7 @@ class BGPOptParamCapabilityGracefulRestart(_OptParamCapability):
@classmethod
def parse_cap_value(cls, buf):
(restart, ) = struct.unpack_from(cls._CAP_PACK_STR,
six.binary_type(buf))
bytes(buf))
buf = buf[2:]
l = []
while len(buf) >= 4:
@ -3572,7 +3571,7 @@ class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
@classmethod
def parse_cap_value(cls, buf):
(as_number, ) = struct.unpack_from(cls._CAP_PACK_STR,
six.binary_type(buf))
bytes(buf))
return {'as_number': as_number}
def serialize_cap_value(self):
@ -3594,7 +3593,7 @@ class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
@classmethod
def parse_cap_value(cls, buf):
(afi, reserved, safi,) = struct.unpack_from(cls._CAP_PACK_STR,
six.binary_type(buf))
bytes(buf))
return {
'afi': afi,
'reserved': reserved,
@ -3638,13 +3637,13 @@ class _PathAttribute(StringifyMixin, TypeDisp, _Value):
@classmethod
def parser(cls, buf):
(flags, type_) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf))
bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
if (flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) != 0:
len_pack_str = cls._PACK_STR_EXT_LEN
else:
len_pack_str = cls._PACK_STR_LEN
(length,) = struct.unpack_from(len_pack_str, six.binary_type(rest))
(length,) = struct.unpack_from(len_pack_str, bytes(rest))
rest = rest[struct.calcsize(len_pack_str):]
value = bytes(rest[:length])
rest = rest[length:]
@ -3755,7 +3754,7 @@ class _BGPPathAttributeAsPathCommon(_PathAttribute):
while buf:
(type_, num_as) = struct.unpack_from(cls._SEG_HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
if type_ is not cls._AS_SET and type_ is not cls._AS_SEQUENCE:
return False
@ -3780,12 +3779,12 @@ class _BGPPathAttributeAsPathCommon(_PathAttribute):
while buf:
(type_, num_as) = struct.unpack_from(cls._SEG_HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
buf = buf[struct.calcsize(cls._SEG_HDR_PACK_STR):]
l = []
for _ in range(0, num_as):
(as_number,) = struct.unpack_from(as_pack_str,
six.binary_type(buf))
bytes(buf))
buf = buf[struct.calcsize(as_pack_str):]
l.append(as_number)
if type_ == cls._AS_SET:
@ -3861,7 +3860,7 @@ class BGPPathAttributeNextHop(_PathAttribute):
@classmethod
def parse_value(cls, buf):
(ip_addr,) = struct.unpack_from(cls._VALUE_PACK_STR,
six.binary_type(buf))
bytes(buf))
return {
'value': addrconv.ipv4.bin_to_text(ip_addr),
}
@ -3914,7 +3913,7 @@ class _BGPPathAttributeAggregatorCommon(_PathAttribute):
@classmethod
def parse_value(cls, buf):
(as_number, addr) = struct.unpack_from(cls._VALUE_PACK_STR,
six.binary_type(buf))
bytes(buf))
return {
'as_number': as_number,
'addr': addrconv.ipv4.bin_to_text(addr),
@ -3982,7 +3981,7 @@ class BGPPathAttributeCommunities(_PathAttribute):
elem_size = struct.calcsize(cls._VALUE_PACK_STR)
while len(rest) >= elem_size:
(comm, ) = struct.unpack_from(cls._VALUE_PACK_STR,
six.binary_type(rest))
bytes(rest))
communities.append(comm)
rest = rest[elem_size:]
return {
@ -4044,7 +4043,7 @@ class BGPPathAttributeOriginatorId(_PathAttribute):
@classmethod
def parse_value(cls, buf):
(originator_id,) = struct.unpack_from(cls._VALUE_PACK_STR,
six.binary_type(buf))
bytes(buf))
return {
'value': addrconv.ipv4.bin_to_text(originator_id),
}
@ -4076,7 +4075,7 @@ class BGPPathAttributeClusterList(_PathAttribute):
elem_size = struct.calcsize(cls._VALUE_PACK_STR)
while len(rest) >= elem_size:
(cluster_id, ) = struct.unpack_from(
cls._VALUE_PACK_STR, six.binary_type(rest))
cls._VALUE_PACK_STR, bytes(rest))
cluster_list.append(addrconv.ipv4.bin_to_text(cluster_id))
rest = rest[elem_size:]
return {
@ -4819,7 +4818,7 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
@classmethod
def parse_value(cls, buf):
(afi, safi, next_hop_len,) = struct.unpack_from(
cls._VALUE_PACK_STR, six.binary_type(buf))
cls._VALUE_PACK_STR, bytes(buf))
rest = buf[cls._VALUE_PACK_SIZE:]
next_hop_bin = rest[:next_hop_len]
@ -4946,7 +4945,7 @@ class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
@classmethod
def parse_value(cls, buf):
(afi, safi,) = struct.unpack_from(
cls._VALUE_PACK_STR, six.binary_type(buf))
cls._VALUE_PACK_STR, bytes(buf))
nlri_bin = buf[struct.calcsize(cls._VALUE_PACK_STR):]
addr_cls = _get_addr_class(afi, safi)
@ -5177,7 +5176,7 @@ class PmsiTunnelIdIngressReplication(_PmsiTunnelId):
def parser(cls, buf):
(tunnel_endpoint_ip, ) = struct.unpack_from(
cls._VALUE_PACK_STR % len(buf),
six.binary_type(buf))
bytes(buf))
return cls(tunnel_endpoint_ip=ip.bin_to_text(tunnel_endpoint_ip))
def serialize(self):
@ -5228,7 +5227,7 @@ class BGPMessage(packet_base.PacketBase, TypeDisp):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._HDR_LEN))
(marker, len_, type_) = struct.unpack_from(cls._HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
msglen = len_
if len(buf) < msglen:
raise stream_parser.StreamParser.TooSmallException(
@ -5325,7 +5324,7 @@ class BGPOpen(BGPMessage):
hold_time,
bgp_identifier,
opt_param_len) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf))
bytes(buf))
rest = buf[struct.calcsize(cls._PACK_STR):]
binopts = rest[:opt_param_len]
opt_param = []
@ -5425,7 +5424,7 @@ class BGPUpdate(BGPMessage):
@classmethod
def parser(cls, buf):
offset = 0
buf = six.binary_type(buf)
buf = bytes(buf)
(withdrawn_routes_len,) = struct.unpack_from('!H', buf, offset)
binroutes = buf[offset + 2:
offset + 2 + withdrawn_routes_len]
@ -5586,7 +5585,7 @@ class BGPNotification(BGPMessage):
@classmethod
def parser(cls, buf):
(error_code, error_subcode,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf))
bytes(buf))
data = bytes(buf[2:])
return {
"error_code": error_code,
@ -5641,7 +5640,7 @@ class BGPRouteRefresh(BGPMessage):
@classmethod
def parser(cls, buf):
(afi, demarcation, safi,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf))
bytes(buf))
return {
"afi": afi,
"safi": safi,

View File

@ -19,14 +19,13 @@ BGP Monitoring Protocol draft-ietf-grow-bmp-07
import struct
import six
from os_ken.lib import addrconv
from os_ken.lib.packet import packet_base
from os_ken.lib.packet import stream_parser
from os_ken.lib.packet.bgp import BGPMessage
from os_ken.lib.type_desc import TypeDisp
VERSION = 3
BMP_MSG_ROUTE_MONITORING = 0
@ -101,7 +100,7 @@ class BMPMessage(packet_base.PacketBase, TypeDisp):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._HDR_LEN))
(version, len_, type_) = struct.unpack_from(cls._HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
return version, len_, type_
@ -200,7 +199,7 @@ class BMPPeerMessage(BMPMessage):
(peer_type, peer_flags, peer_distinguisher,
peer_address, peer_as, peer_bgp_id,
timestamp1, timestamp2) = struct.unpack_from(cls._PEER_HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
rest = buf[struct.calcsize(cls._PEER_HDR_PACK_STR):]
@ -369,7 +368,7 @@ class BMPStatisticsReport(BMPPeerMessage):
def parser(cls, buf):
kwargs, rest = super(BMPStatisticsReport, cls).parser(buf)
stats_count, = struct.unpack_from('!I', six.binary_type(rest))
stats_count, = struct.unpack_from('!I', bytes(rest))
buf = rest[struct.calcsize('!I'):]
@ -380,7 +379,7 @@ class BMPStatisticsReport(BMPPeerMessage):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._MIN_LEN))
(type_, len_) = struct.unpack_from(cls._TLV_PACK_STR,
six.binary_type(buf))
bytes(buf))
if len(buf) < (cls._MIN_LEN + len_):
raise stream_parser.StreamParser.TooSmallException(
@ -395,12 +394,12 @@ class BMPStatisticsReport(BMPPeerMessage):
type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_PATH_LOOP or \
type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_ORIGINATOR_ID or \
type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_CONFED_LOOP:
value, = struct.unpack_from('!I', six.binary_type(value))
value, = struct.unpack_from('!I', bytes(value))
elif type_ == BMP_STAT_TYPE_ADJ_RIB_IN or \
type_ == BMP_STAT_TYPE_LOC_RIB or \
type_ == BMP_STAT_TYPE_ADJ_RIB_OUT or \
type_ == BMP_STAT_TYPE_EXPORT_RIB:
value, = struct.unpack_from('!Q', six.binary_type(value))
value, = struct.unpack_from('!Q', bytes(value))
buf = buf[cls._MIN_LEN + len_:]
@ -482,13 +481,13 @@ class BMPPeerDownNotification(BMPPeerMessage):
@classmethod
def parser(cls, buf):
kwargs, buf = super(BMPPeerDownNotification, cls).parser(buf)
reason, = struct.unpack_from('!B', six.binary_type(buf))
reason, = struct.unpack_from('!B', bytes(buf))
buf = buf[struct.calcsize('!B'):]
if reason == BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION:
data, _, rest = BGPMessage.parser(buf)
elif reason == BMP_PEER_DOWN_REASON_LOCAL_NO_NOTIFICATION:
data = struct.unpack_from('!H', six.binary_type(buf))
data = struct.unpack_from('!H', bytes(buf))
elif reason == BMP_PEER_DOWN_REASON_REMOTE_BGP_NOTIFICATION:
data, _, rest = BGPMessage.parser(buf)
elif reason == BMP_PEER_DOWN_REASON_REMOTE_NO_NOTIFICATION:
@ -583,7 +582,7 @@ class BMPPeerUpNotification(BMPPeerMessage):
kwargs, rest = super(BMPPeerUpNotification, cls).parser(buf)
(local_address, local_port,
remote_port) = struct.unpack_from(cls._PACK_STR, six.binary_type(rest))
remote_port) = struct.unpack_from(cls._PACK_STR, bytes(rest))
if '.' in kwargs['peer_address']:
local_address = addrconv.ipv4.bin_to_text(local_address[-4:])
@ -657,7 +656,7 @@ class BMPInitiation(BMPMessage):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._MIN_LEN))
(type_, len_) = struct.unpack_from(cls._TLV_PACK_STR,
six.binary_type(buf))
bytes(buf))
if len(buf) < (cls._MIN_LEN + len_):
raise stream_parser.StreamParser.TooSmallException(
@ -721,7 +720,7 @@ class BMPTermination(BMPMessage):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._MIN_LEN))
(type_, len_) = struct.unpack_from(cls._TLV_PACK_STR,
six.binary_type(buf))
bytes(buf))
if len(buf) < (cls._MIN_LEN + len_):
raise stream_parser.StreamParser.TooSmallException(
@ -731,7 +730,7 @@ class BMPTermination(BMPMessage):
if type_ == BMP_TERM_TYPE_STRING:
value = value.decode('utf-8')
elif type_ == BMP_TERM_TYPE_REASON:
value, = struct.unpack_from('!H', six.binary_type(value))
value, = struct.unpack_from('!H', bytes(value))
buf = buf[cls._MIN_LEN + len_:]

View File

@ -14,7 +14,6 @@
# limitations under the License.
import abc
import six
import struct
from os_ken.lib import addrconv
from os_ken.lib import stringify
@ -123,8 +122,7 @@ class cfm(packet_base.PacketBase):
return len(self.op)
@six.add_metaclass(abc.ABCMeta)
class operation(stringify.StringifyMixin):
class operation(stringify.StringifyMixin, metaclass=abc.ABCMeta):
_TLV_TYPES = {}
_END_TLV_LEN = 1
@ -310,9 +308,9 @@ class cc_message(operation):
# ascii to text
if md_name_format == cls._MD_FMT_DOMAIN_NAME_BASED_STRING or \
md_name_format == cls._MD_FMT_CHARACTER_STRING:
md_name = b"".join(map(six.int2byte, md_name))
md_name = b"".join(map(struct.Struct(">B").pack, md_name))
if short_ma_name_format == cls._SHORT_MA_FMT_CHARACTER_STRING:
short_ma_name = b"".join(map(six.int2byte, short_ma_name))
short_ma_name = b"".join(map(struct.Struct(">B").pack, short_ma_name))
return cls(md_lv, version, rdi, interval, seq_num, mep_id,
md_name_format, md_name_length,
md_name,
@ -667,8 +665,7 @@ class link_trace_reply(link_trace):
cfm.set_classes(cfm._CFM_OPCODE)
@six.add_metaclass(abc.ABCMeta)
class tlv(stringify.StringifyMixin):
class tlv(stringify.StringifyMixin, metaclass=abc.ABCMeta):
_TYPE_LEN = 1
_LENGTH_LEN = 2

View File

@ -16,8 +16,6 @@
import abc
import struct
import six
from . import packet_base
from . import packet_utils
from os_ken.lib import stringify
@ -126,8 +124,7 @@ class icmp(packet_base.PacketBase):
return self._MIN_LEN + len(self.data)
@six.add_metaclass(abc.ABCMeta)
class _ICMPv4Payload(stringify.StringifyMixin):
class _ICMPv4Payload(stringify.StringifyMixin, metaclass=abc.ABCMeta):
"""
Base class for the payload of ICMPv4 packet.
"""

View File

@ -15,10 +15,6 @@
import abc
import struct
import six
import sys
import array
import binascii
from . import packet_base
from . import packet_utils
@ -153,8 +149,7 @@ class icmpv6(packet_base.PacketBase):
return self._MIN_LEN + len(self.data)
@six.add_metaclass(abc.ABCMeta)
class _ICMPv6Payload(stringify.StringifyMixin):
class _ICMPv6Payload(stringify.StringifyMixin, metaclass=abc.ABCMeta):
"""
Base class for the payload of ICMPv6 packet.
"""
@ -232,7 +227,7 @@ class nd_neighbor(_ICMPv6Payload):
hdr.extend(self.option.serialize())
else:
hdr.extend(self.option)
return six.binary_type(hdr)
return bytes(hdr)
def __len__(self):
length = self._MIN_LEN
@ -303,7 +298,7 @@ class nd_router_solicit(_ICMPv6Payload):
hdr.extend(self.option.serialize())
else:
hdr.extend(self.option)
return six.binary_type(hdr)
return bytes(hdr)
def __len__(self):
length = self._MIN_LEN
@ -390,7 +385,7 @@ class nd_router_advert(_ICMPv6Payload):
hdr.extend(option.serialize())
else:
hdr.extend(option)
return six.binary_type(hdr)
return bytes(hdr)
def __len__(self):
length = self._MIN_LEN
@ -399,8 +394,7 @@ class nd_router_advert(_ICMPv6Payload):
return length
@six.add_metaclass(abc.ABCMeta)
class nd_option(stringify.StringifyMixin):
class nd_option(stringify.StringifyMixin, metaclass=abc.ABCMeta):
@classmethod
@abc.abstractmethod
def option_type(cls):
@ -462,7 +456,7 @@ class nd_option_la(nd_option):
if 0 == self.length:
self.length = len(buf) // 8
struct.pack_into('!B', buf, 1, self.length)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
length = self._MIN_LEN
@ -620,7 +614,7 @@ class nd_option_pi(nd_option):
if 0 == self.length:
self.length = len(hdr) // 8
struct.pack_into('!B', hdr, 1, self.length)
return six.binary_type(hdr)
return bytes(hdr)
@nd_router_advert.register_nd_option_type
@ -664,7 +658,7 @@ class nd_option_mtu(nd_option):
def serialize(self):
buf = bytearray(struct.pack(
self._PACK_STR, self.option_type(), self._OPTION_LEN, 0, self.mtu))
return six.binary_type(buf)
return bytes(buf)
@icmpv6.register_icmpv6_type(ICMPV6_ECHO_REPLY, ICMPV6_ECHO_REQUEST)
@ -858,7 +852,7 @@ class mldv2_query(mld):
if 0 == self.num:
self.num = len(self.srcs)
struct.pack_into('!H', buf, 22, self.num)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
return self._MIN_LEN + len(self.srcs) * 16
@ -918,7 +912,7 @@ class mldv2_report(mld):
if 0 == self.record_num:
self.record_num = len(self.records)
struct.pack_into('!H', buf, 2, self.record_num)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
records_len = 0
@ -1006,12 +1000,12 @@ class mldv2_report_group(stringify.StringifyMixin):
mod = len(self.aux) % 4
if mod:
self.aux += bytearray(4 - mod)
self.aux = six.binary_type(self.aux)
self.aux = bytes(self.aux)
buf.extend(self.aux)
if 0 == self.aux_len:
self.aux_len = len(self.aux) // 4
struct.pack_into('!B', buf, 1, self.aux_len)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
return self._MIN_LEN + len(self.srcs) * 16 + self.aux_len * 4

View File

@ -114,7 +114,6 @@ Where each Group Record has the following internal format::
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
"""
import six
import struct
from math import trunc
@ -308,7 +307,7 @@ class igmpv3_query(igmp):
if 0 == self.csum:
self.csum = packet_utils.checksum(buf)
struct.pack_into('!H', buf, 2, self.csum)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
return self._MIN_LEN + len(self.srcs) * 4
@ -381,7 +380,7 @@ class igmpv3_report(igmp):
if 0 == self.csum:
self.csum = packet_utils.checksum(buf)
struct.pack_into('!H', buf, 2, self.csum)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
records_len = 0
@ -472,12 +471,12 @@ class igmpv3_report_group(stringify.StringifyMixin):
mod = len(self.aux) % 4
if mod:
self.aux += bytearray(4 - mod)
self.aux = six.binary_type(self.aux)
self.aux = bytes(self.aux)
buf.extend(self.aux)
if 0 == self.aux_len:
self.aux_len = len(self.aux) // 4
struct.pack_into('!B', buf, 1, self.aux_len)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
return self._MIN_LEN + len(self.srcs) * 4 + self.aux_len * 4

View File

@ -14,7 +14,6 @@
# limitations under the License.
import abc
import six
import struct
from . import packet_base
from . import icmpv6
@ -151,8 +150,7 @@ ipv6.register_packet_type(sctp.sctp, inet.IPPROTO_SCTP)
ipv6.register_packet_type(gre.gre, inet.IPPROTO_GRE)
@six.add_metaclass(abc.ABCMeta)
class header(stringify.StringifyMixin):
class header(stringify.StringifyMixin, metaclass=abc.ABCMeta):
"""extension header abstract class."""
def __init__(self, nxt):

View File

@ -15,8 +15,6 @@
import struct
import six
from . import packet_base
from os_ken.lib import type_desc
@ -78,7 +76,7 @@ def label_from_bin(buf):
:return: MPLS Label and BoS bit.
"""
mpls_label = type_desc.Int3.to_user(six.binary_type(buf))
mpls_label = type_desc.Int3.to_user(bytes(buf))
return mpls_label >> 4, mpls_label & 1

View File

@ -21,8 +21,6 @@ from functools import reduce
import logging
import struct
import six
from os_ken.lib import addrconv
from os_ken.lib.packet import packet_base
from os_ken.lib.packet import packet_utils
@ -113,7 +111,7 @@ class LSAHeader(StringifyMixin):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._HDR_LEN))
(ls_age, options, type_, id_, adv_router, ls_seqnum, checksum,
length,) = struct.unpack_from(cls._HDR_PACK_STR, six.binary_type(buf))
length,) = struct.unpack_from(cls._HDR_PACK_STR, bytes(buf))
adv_router = addrconv.ipv4.bin_to_text(adv_router)
rest = buf[cls._HDR_LEN:]
lsacls = LSA._lookup_type(type_)
@ -244,7 +242,7 @@ class RouterLSA(LSA):
link = buf[:cls._PACK_LEN]
rest = buf[cls._PACK_LEN:]
(id_, data, type_, tos, metric) = \
struct.unpack_from(cls._PACK_STR, six.binary_type(link))
struct.unpack_from(cls._PACK_STR, bytes(link))
id_ = addrconv.ipv4.bin_to_text(id_)
data = addrconv.ipv4.bin_to_text(data)
return cls(id_, data, type_, tos, metric), rest
@ -272,7 +270,7 @@ class RouterLSA(LSA):
hdr = buf[:cls._PACK_LEN]
buf = buf[cls._PACK_LEN:]
(flags, _, num) = struct.unpack_from(cls._PACK_STR,
six.binary_type(hdr))
bytes(hdr))
while buf:
link, buf = cls.Link.parser(buf)
links.append(link)
@ -313,14 +311,14 @@ class NetworkLSA(LSA):
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._PACK_LEN))
binmask = buf[:cls._PACK_LEN]
(mask,) = struct.unpack_from(cls._PACK_STR, six.binary_type(binmask))
(mask,) = struct.unpack_from(cls._PACK_STR, bytes(binmask))
mask = addrconv.ipv4.bin_to_text(mask)
buf = buf[cls._PACK_LEN:]
routers = []
while buf:
binrouter = buf[:cls._PACK_LEN]
(router,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(binrouter))
bytes(binrouter))
router = addrconv.ipv4.bin_to_text(router)
routers.append(router)
buf = buf[cls._PACK_LEN:]
@ -359,7 +357,7 @@ class SummaryLSA(LSA):
'%d < %d' % (len(buf), cls._PACK_LEN))
buf = buf[:cls._PACK_LEN]
(mask, tos, metric) = struct.unpack_from(
cls._PACK_STR, six.binary_type(buf))
cls._PACK_STR, bytes(buf))
mask = addrconv.ipv4.bin_to_text(mask)
metric = type_desc.Int3.to_user(metric)
return {
@ -401,7 +399,7 @@ class ASExternalLSA(LSA):
ext_nw = buf[:cls._PACK_LEN]
rest = buf[cls._PACK_LEN:]
(mask, flags, metric, fwd_addr,
tag) = struct.unpack_from(cls._PACK_STR, six.binary_type(ext_nw))
tag) = struct.unpack_from(cls._PACK_STR, bytes(ext_nw))
mask = addrconv.ipv4.bin_to_text(mask)
metric = type_desc.Int3.to_user(metric)
fwd_addr = addrconv.ipv4.bin_to_text(fwd_addr)
@ -536,7 +534,7 @@ class OpaqueBody(StringifyMixin, type_desc.TypeDisp):
class ExtendedPrefixOpaqueBody(OpaqueBody):
@classmethod
def parser(cls, buf):
buf = six.binary_type(buf)
buf = bytes(buf)
tlvs = []
while buf:
(type_, length) = struct.unpack_from('!HH', buf)
@ -555,7 +553,7 @@ class ExtendedPrefixOpaqueBody(OpaqueBody):
class ExtendedLinkOpaqueBody(OpaqueBody):
@classmethod
def parser(cls, buf):
buf = six.binary_type(buf)
buf = bytes(buf)
tlvs = []
while buf:
(type_, length) = struct.unpack_from('!HH', buf)
@ -652,7 +650,7 @@ class OSPFMessage(packet_base.PacketBase, type_desc.TypeDisp):
'%d < %d' % (len(buf), cls._HDR_LEN))
(version, type_, length, router_id, area_id, checksum, au_type,
authentication) = struct.unpack_from(cls._HDR_PACK_STR,
six.binary_type(buf))
bytes(buf))
# Exclude checksum and authentication field for checksum validation.
if packet_utils.checksum(buf[:12] + buf[14:16] + buf[cls._HDR_LEN:]) \
@ -729,7 +727,7 @@ class OSPFHello(OSPFMessage):
def parser(cls, buf):
(mask, hello_interval, options, priority, dead_interval,
designated_router, backup_router) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf))
bytes(buf))
mask = addrconv.ipv4.bin_to_text(mask)
designated_router = addrconv.ipv4.bin_to_text(designated_router)
backup_router = addrconv.ipv4.bin_to_text(backup_router)
@ -737,7 +735,7 @@ class OSPFHello(OSPFMessage):
binneighbors = buf[cls._PACK_LEN:len(buf)]
while binneighbors:
n = binneighbors[:4]
n = addrconv.ipv4.bin_to_text(six.binary_type(n))
n = addrconv.ipv4.bin_to_text(bytes(n))
binneighbors = binneighbors[4:]
neighbors.append(n)
return {
@ -793,7 +791,7 @@ class OSPFDBDesc(OSPFMessage):
@classmethod
def parser(cls, buf):
(mtu, options, flags,
sequence_number) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf))
sequence_number) = struct.unpack_from(cls._PACK_STR, bytes(buf))
i_flag = (flags >> 2) & 0x1
m_flag = (flags >> 1) & 0x1
ms_flag = flags & 0x1
@ -848,7 +846,7 @@ class OSPFLSReq(OSPFMessage):
link = buf[:cls._PACK_LEN]
rest = buf[cls._PACK_LEN:]
(type_, id_, adv_router) = struct.unpack_from(cls._PACK_STR,
six.binary_type(link))
bytes(link))
id_ = addrconv.ipv4.bin_to_text(id_)
adv_router = addrconv.ipv4.bin_to_text(adv_router)
return cls(type_, id_, adv_router), rest
@ -900,7 +898,7 @@ class OSPFLSUpd(OSPFMessage):
@classmethod
def parser(cls, buf):
binnum = buf[:cls._PACK_LEN]
(num,) = struct.unpack_from(cls._PACK_STR, six.binary_type(binnum))
(num,) = struct.unpack_from(cls._PACK_STR, bytes(binnum))
buf = buf[cls._PACK_LEN:]
lsas = []

View File

@ -17,8 +17,6 @@ import inspect
import struct
import base64
import six
from . import packet_base
from . import ethernet
@ -70,7 +68,7 @@ class Packet(StringifyMixin):
rest_data = self.data
while cls:
# Ignores an empty buffer
if not six.binary_type(rest_data).strip(b'\x00'):
if not bytes(rest_data).strip(b'\x00'):
break
try:
proto, cls, rest_data = cls.parser(rest_data)
@ -79,7 +77,7 @@ class Packet(StringifyMixin):
if proto:
self.protocols.append(proto)
# If rest_data is all padding, we ignore rest_data
if rest_data and six.binary_type(rest_data).strip(b'\x00'):
if rest_data and bytes(rest_data).strip(b'\x00'):
self.protocols.append(rest_data)
def serialize(self):
@ -98,7 +96,7 @@ class Packet(StringifyMixin):
prev = r[i + 1]
data = p.serialize(self.data, prev)
else:
data = six.binary_type(p)
data = bytes(p)
self.data = bytearray(data + self.data)
@classmethod

View File

@ -14,12 +14,10 @@
# limitations under the License.
import abc
import six
from os_ken.lib import stringify
@six.add_metaclass(abc.ABCMeta)
class PacketBase(stringify.StringifyMixin):
class PacketBase(stringify.StringifyMixin, metaclass=abc.ABCMeta):
"""A base class for a protocol (ethernet, ipv4, ...) header."""
_TYPES = {}

View File

@ -14,7 +14,6 @@
# limitations under the License.
import array
import six
import socket
import struct
from os_ken.lib import addrconv
@ -26,7 +25,7 @@ def carry_around_add(a, b):
def checksum(data):
data = six.binary_type(data) # input can be bytearray.
data = bytes(data) # input can be bytearray.
if len(data) % 2:
data += b'\x00'

View File

@ -14,7 +14,6 @@
# limitations under the License.
import abc
import six
import struct
from os_ken.lib import addrconv
@ -138,7 +137,7 @@ class sctp(packet_base.PacketBase):
if self.csum == 0:
self.csum = self._checksum(buf)
struct.pack_into('!I', buf, 8, self.csum)
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
length = self._MIN_LEN
@ -228,8 +227,7 @@ class sctp(packet_base.PacketBase):
# Chunk Types
#
# =======================================================================
@six.add_metaclass(abc.ABCMeta)
class chunk(stringify.StringifyMixin):
class chunk(stringify.StringifyMixin, metaclass=abc.ABCMeta):
_PACK_STR = '!BBH'
_MIN_LEN = struct.calcsize(_PACK_STR)
@ -252,8 +250,7 @@ class chunk(stringify.StringifyMixin):
return self.length
@six.add_metaclass(abc.ABCMeta)
class chunk_init_base(chunk):
class chunk_init_base(chunk, metaclass=abc.ABCMeta):
_PACK_STR = '!BBHIIHHI'
_MIN_LEN = struct.calcsize(_PACK_STR)
_class_prefixes = ['param_']
@ -300,11 +297,10 @@ class chunk_init_base(chunk):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@six.add_metaclass(abc.ABCMeta)
class chunk_heartbeat_base(chunk):
class chunk_heartbeat_base(chunk, metaclass=abc.ABCMeta):
_class_prefixes = ['param_']
def __init__(self, flags=0, length=0, info=None):
@ -333,11 +329,10 @@ class chunk_heartbeat_base(chunk):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@six.add_metaclass(abc.ABCMeta)
class chunk_ack_base(chunk):
class chunk_ack_base(chunk, metaclass=abc.ABCMeta):
def __init__(self, flags=0, length=0):
super(chunk_ack_base, self).__init__(self.chunk_type(), length)
self.flags = flags
@ -356,8 +351,7 @@ class chunk_ack_base(chunk):
return buf
@six.add_metaclass(abc.ABCMeta)
class chunk_ecn_base(chunk):
class chunk_ecn_base(chunk, metaclass=abc.ABCMeta):
_PACK_STR = '!BBHI'
_MIN_LEN = struct.calcsize(_PACK_STR)
@ -459,7 +453,7 @@ class chunk_data(chunk):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@sctp.register_chunk_type
@ -659,7 +653,7 @@ class chunk_sack(chunk):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@sctp.register_chunk_type
@ -827,7 +821,7 @@ class chunk_abort(chunk):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@sctp.register_chunk_type
@ -986,7 +980,7 @@ class chunk_error(chunk):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@sctp.register_chunk_type
@ -1048,7 +1042,7 @@ class chunk_cookie_echo(chunk):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
@sctp.register_chunk_type
@ -1201,8 +1195,7 @@ class chunk_shutdown_complete(chunk):
# Cause Code
#
# =======================================================================
@six.add_metaclass(abc.ABCMeta)
class cause(stringify.StringifyMixin):
class cause(stringify.StringifyMixin, metaclass=abc.ABCMeta):
_PACK_STR = '!HH'
_MIN_LEN = struct.calcsize(_PACK_STR)
@ -1234,8 +1227,7 @@ class cause(stringify.StringifyMixin):
return length
@six.add_metaclass(abc.ABCMeta)
class cause_with_value(cause):
class cause_with_value(cause, metaclass=abc.ABCMeta):
def __init__(self, value=None, length=0):
super(cause_with_value, self).__init__(length)
self.value = value
@ -1260,7 +1252,7 @@ class cause_with_value(cause):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
@chunk_abort.register_cause_code
@ -1381,7 +1373,7 @@ class cause_missing_param(cause):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
@chunk_abort.register_cause_code
@ -1514,7 +1506,7 @@ class cause_unresolvable_addr(cause_with_value):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
@chunk_abort.register_cause_code
@ -1755,7 +1747,7 @@ class cause_restart_with_new_addr(cause_with_value):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
@chunk_abort.register_cause_code
@ -1825,8 +1817,7 @@ class cause_protocol_violation(cause_with_value):
# Chunk Parameter Types
#
# =======================================================================
@six.add_metaclass(abc.ABCMeta)
class param(stringify.StringifyMixin):
class param(stringify.StringifyMixin, metaclass=abc.ABCMeta):
_PACK_STR = '!HH'
_MIN_LEN = struct.calcsize(_PACK_STR)
@ -1859,7 +1850,7 @@ class param(stringify.StringifyMixin):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
def __len__(self):
length = self.length
@ -2134,7 +2125,7 @@ class param_supported_addr(param):
mod = len(buf) % 4
if mod:
buf.extend(bytearray(4 - mod))
return six.binary_type(buf)
return bytes(buf)
@chunk_init.register_param_type
@ -2191,7 +2182,7 @@ class param_ipv4(param):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)
@chunk_init.register_param_type
@ -2248,4 +2239,4 @@ class param_ipv6(param):
if 0 == self.length:
self.length = len(buf)
struct.pack_into('!H', buf, 2, self.length)
return six.binary_type(buf)
return bytes(buf)

View File

@ -14,13 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from abc import ABCMeta, abstractmethod
import six
import abc
@six.add_metaclass(ABCMeta)
class StreamParser(object):
class StreamParser(object, metaclass=abc.ABCMeta):
"""Streaming parser base class.
An instance of a subclass of this class is used to extract messages
@ -60,7 +57,7 @@ class StreamParser(object):
msgs.append(msg)
return msgs
@abstractmethod
@abc.abstractmethod
def try_parse(self, q):
"""Try to extract a message from the given bytes.

View File

@ -16,8 +16,6 @@
import struct
import logging
import six
from os_ken.lib import stringify
from . import packet_base
from . import packet_utils
@ -187,7 +185,7 @@ class tcp(packet_base.PacketBase):
self.csum = packet_utils.checksum_ip(prev, total_length,
h + payload)
struct.pack_into('!H', h, 16, self.csum)
return six.binary_type(h)
return bytes(h)
class TCPOption(stringify.StringifyMixin):

View File

@ -14,7 +14,6 @@
# limitations under the License.
import abc
import six
import struct
from . import packet_base
from . import arp
@ -28,8 +27,7 @@ from . import cfm
from . import ether_types as ether
@six.add_metaclass(abc.ABCMeta)
class _vlan(packet_base.PacketBase):
class _vlan(packet_base.PacketBase, metaclass=abc.ABCMeta):
_PACK_STR = "!HH"
_MIN_LEN = struct.calcsize(_PACK_STR)

View File

@ -16,8 +16,6 @@
import struct
import logging
import six
from . import packet_base
from os_ken.lib import type_desc
@ -80,7 +78,7 @@ def vni_from_bin(buf):
:param buf: binary representation of VNI.
:return: VNI integer.
"""
return type_desc.Int3.to_user(six.binary_type(buf))
return type_desc.Int3.to_user(bytes(buf))
def vni_to_bin(vni):

View File

@ -26,7 +26,6 @@ import logging
import netaddr
from packaging import version as packaging_version
import six
from os_ken import flags as cfg_flags # For loading 'zapi' option definition
from os_ken.cfg import CONF
@ -597,8 +596,8 @@ class InterfaceLinkParams(stringify.StringifyMixin):
return buf
@six.add_metaclass(abc.ABCMeta)
class _NextHop(type_desc.TypeDisp, stringify.StringifyMixin):
class _NextHop(type_desc.TypeDisp, stringify.StringifyMixin,
metaclass=abc.ABCMeta):
"""
Base class for Zebra Nexthop structure.
"""
@ -651,8 +650,7 @@ class _NextHop(type_desc.TypeDisp, stringify.StringifyMixin):
return struct.pack(self._HEADER_FMT, self.type) + self._serialize()
@six.add_metaclass(abc.ABCMeta)
class _FrrNextHop(_NextHop):
class _FrrNextHop(_NextHop, metaclass=abc.ABCMeta):
"""
Base class for Zebra Nexthop structure for translating nexthop types
on FRRouting.
@ -1103,7 +1101,7 @@ class ZebraMessage(packet_base.PacketBase):
@classmethod
def _parser_impl(cls, buf, from_zebra=False):
buf = six.binary_type(buf)
buf = bytes(buf)
(length, version, vrf_id, command,
body_buf) = cls.parse_header(buf)
@ -1233,8 +1231,7 @@ class ZebraUnknownMessage(_ZebraMessageBody):
return self.buf
@six.add_metaclass(abc.ABCMeta)
class _ZebraInterface(_ZebraMessageBody):
class _ZebraInterface(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_INTERFACE_ADD, ZEBRA_INTERFACE_DELETE,
ZEBRA_INTERFACE_UP and ZEBRA_INTERFACE_DOWN message body.
@ -1362,7 +1359,7 @@ class _ZebraInterface(_ZebraMessageBody):
raise struct.error(
'Unsupported Zebra protocol version: %d'
% version)
ifname = str(six.text_type(ifname.strip(b'\x00'), 'ascii'))
ifname = str(str(ifname.strip(b'\x00'), 'ascii'))
hw_addr_len = min(hw_addr_len, INTERFACE_HWADDR_MAX)
hw_addr_bin = rest[:hw_addr_len]
@ -1468,8 +1465,7 @@ class ZebraInterfaceDelete(_ZebraInterface):
"""
@six.add_metaclass(abc.ABCMeta)
class _ZebraInterfaceAddress(_ZebraMessageBody):
class _ZebraInterfaceAddress(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_INTERFACE_ADDRESS_ADD and
ZEBRA_INTERFACE_ADDRESS_DELETE message body.
@ -1568,8 +1564,7 @@ class ZebraInterfaceDown(_ZebraInterface):
"""
@six.add_metaclass(abc.ABCMeta)
class _ZebraIPRoute(_ZebraMessageBody):
class _ZebraIPRoute(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_IPV4_ROUTE_* and ZEBRA_IPV6_ROUTE_*
message body.
@ -1742,7 +1737,7 @@ class _ZebraIPRoute(_ZebraMessageBody):
if from_zebra:
ifindexes = ifindexes or []
for ifindex in ifindexes:
assert isinstance(ifindex, six.integer_types)
assert isinstance(ifindex, int)
self.ifindexes = ifindexes
else:
self.ifindexes = None
@ -1973,8 +1968,7 @@ class ZebraIPv4RouteIPv6NexthopAdd(_ZebraIPv4Route):
"""
@six.add_metaclass(abc.ABCMeta)
class _ZebraRedistribute(_ZebraMessageBody):
class _ZebraRedistribute(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_REDISTRIBUTE_ADD and ZEBRA_REDISTRIBUTE_DELETE
message body.
@ -2047,8 +2041,7 @@ class ZebraRedistributeDelete(_ZebraRedistribute):
"""
@six.add_metaclass(abc.ABCMeta)
class _ZebraRedistributeDefault(_ZebraMessageBody):
class _ZebraRedistributeDefault(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_REDISTRIBUTE_DEFAULT_ADD and
ZEBRA_REDISTRIBUTE_DEFAULT_DELETE message body.
@ -2071,8 +2064,7 @@ class ZebraRedistributeDefaultDelete(_ZebraRedistribute):
"""
@six.add_metaclass(abc.ABCMeta)
class _ZebraIPNexthopLookup(_ZebraMessageBody):
class _ZebraIPNexthopLookup(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_IPV4_NEXTHOP_LOOKUP and
ZEBRA_IPV6_NEXTHOP_LOOKUP message body.
@ -2152,8 +2144,7 @@ class ZebraIPv6NexthopLookup(_ZebraIPNexthopLookup):
ADDR_LEN = 16
@six.add_metaclass(abc.ABCMeta)
class _ZebraIPImportLookup(_ZebraMessageBody):
class _ZebraIPImportLookup(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_IPV4_IMPORT_LOOKUP and
ZEBRA_IPV6_IMPORT_LOOKUP message body.
@ -2385,8 +2376,7 @@ class ZebraHello(_ZebraMessageBody):
% version)
@six.add_metaclass(abc.ABCMeta)
class _ZebraIPNexthopLookupMRib(_ZebraMessageBody):
class _ZebraIPNexthopLookupMRib(_ZebraMessageBody, metaclass=abc.ABCMeta):
"""
Base class for ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB (and
ZEBRA_IPV6_NEXTHOP_LOOKUP_MRIB) message body.
@ -2891,7 +2881,7 @@ class _ZebraBfdDestination(_ZebraMessageBody):
else:
(ifname_len,) = struct.unpack_from(cls._FOOTER_FMT, rest)
ifname_bin = rest[cls.FOOTER_SIZE:cls.FOOTER_SIZE + ifname_len]
ifname = str(six.text_type(ifname_bin.strip(b'\x00'), 'ascii'))
ifname = str(str(ifname_bin.strip(b'\x00'), 'ascii'))
return cls(pid, dst_family, dst_prefix,
min_rx_timer, min_tx_timer, detect_mult,
@ -3027,7 +3017,7 @@ class ZebraBfdDestinationDeregister(_ZebraMessageBody):
else:
(ifname_len,) = struct.unpack_from(cls._FOOTER_FMT, rest)
ifname_bin = rest[cls.FOOTER_SIZE:cls.FOOTER_SIZE + ifname_len]
ifname = str(six.text_type(ifname_bin.strip(b'\x00'), 'ascii'))
ifname = str(str(ifname_bin.strip(b'\x00'), 'ascii'))
return cls(pid, dst_family, dst_prefix,
multi_hop, src_family, src_prefix,
@ -3144,7 +3134,7 @@ class _ZebraVrf(_ZebraMessageBody):
@classmethod
def parse(cls, buf, version=_DEFAULT_FRR_VERSION):
vrf_name_bin = buf[:VRF_NAMSIZ]
vrf_name = str(six.text_type(vrf_name_bin.strip(b'\x00'), 'ascii'))
vrf_name = str(str(vrf_name_bin.strip(b'\x00'), 'ascii'))
return cls(vrf_name)

View File

@ -24,7 +24,6 @@ from collections import deque
import select
import msgpack
import six
class MessageType(object):
@ -50,7 +49,7 @@ class MessageEncoder(object):
return this_id
def create_request(self, method, params):
assert isinstance(method, (str, six.binary_type))
assert isinstance(method, (str, bytes))
assert isinstance(params, list)
msgid = self._create_msgid()
return (self._packer.pack(
@ -63,7 +62,7 @@ class MessageEncoder(object):
return self._packer.pack([MessageType.RESPONSE, msgid, error, result])
def create_notification(self, method, params):
assert isinstance(method, (str, six.binary_type))
assert isinstance(method, (str, bytes))
assert isinstance(params, list)
return self._packer.pack([MessageType.NOTIFY, method, params])

View File

@ -13,10 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import logging
import six
from os_ken.lib import hub, alert
from os_ken.base import app_manager
@ -95,7 +93,7 @@ class SnortLib(app_manager.OSKenApp):
hub.spawn(self._recv_loop_nw_sock, conn, addr)
def _recv_loop_nw_sock(self, conn, addr):
buf = six.binary_type()
buf = bytes()
while True:
ret = conn.recv(BUFSIZE)
if len(ret) == 0:

View File

@ -17,8 +17,6 @@
import base64
import inspect
import six
# Some arguments to __init__ is mangled in order to avoid name conflicts
# with builtin names.
# The standard mangling is to append '_' in order to avoid name clashes
@ -36,7 +34,10 @@ import six
# 'len', 'property', 'set', 'type'
# A bit more generic way is adopted
_RESERVED_KEYWORD = dir(six.moves.builtins)
import builtins
_RESERVED_KEYWORD = dir(builtins)
_mapdict = lambda f, d: dict([(k, f(v)) for k, v in d.items()])
_mapdict_key = lambda f, d: dict([(f(k), v) for k, v in d.items()])
@ -53,21 +54,19 @@ class AsciiStringType(TypeDescr):
# TODO: AsciiStringType data should probably be stored as
# text_type in class data. This isinstance() check exists
# because OFPDescStats violates this.
if six.PY3 and isinstance(v, six.text_type):
if isinstance(v, str):
return v
return six.text_type(v, 'ascii')
return str(v, 'ascii')
@staticmethod
def decode(v):
if six.PY3:
return v
return v.encode('ascii')
return v
class Utf8StringType(TypeDescr):
@staticmethod
def encode(v):
return six.text_type(v, 'utf-8')
return str(v, 'utf-8')
@staticmethod
def decode(v):
@ -173,7 +172,7 @@ class StringifyMixin(object):
if len(dict_) != 1:
return False
k = list(dict_.keys())[0]
if not isinstance(k, (bytes, six.text_type)):
if not isinstance(k, (bytes, str)):
return False
for p in cls._class_prefixes:
if k.startswith(p):
@ -205,12 +204,11 @@ class StringifyMixin(object):
@classmethod
def _get_default_encoder(cls, encode_string):
def _encode(v):
if isinstance(v, (bytes, six.text_type)):
if isinstance(v, six.text_type):
if isinstance(v, (bytes, str)):
if isinstance(v, str):
v = v.encode('utf-8')
json_value = encode_string(v)
if six.PY3:
json_value = json_value.decode('ascii')
json_value = json_value.decode('ascii')
elif isinstance(v, list):
json_value = [_encode(ve) for ve in v]
elif isinstance(v, dict):
@ -293,7 +291,7 @@ class StringifyMixin(object):
@classmethod
def _get_default_decoder(cls, decode_string):
def _decode(json_value, **additional_args):
if isinstance(json_value, (bytes, six.text_type)):
if isinstance(json_value, (bytes, str)):
v = decode_string(json_value)
elif isinstance(json_value, list):
v = [_decode(jv) for jv in json_value]

View File

@ -15,8 +15,7 @@
# limitations under the License.
import base64
import six
import struct
from os_ken.lib import addrconv
@ -40,7 +39,7 @@ class IntDescr(TypeDescr):
def from_user(self, i):
binary = b''
for _ in range(self.size):
binary = six.int2byte(i & 255) + binary
binary = struct.Struct(">B").pack(i & 255) + binary
i //= 256
return binary
@ -87,7 +86,7 @@ class IntDescrMlt(TypeDescr):
for i in li:
b = b''
for _ in range(self.length):
b = six.int2byte(i & 255) + b
b = struct.Struct(">B").pack(i & 255) + b
i //= 256
binary += b
return binary
@ -118,10 +117,7 @@ class UnknownType(TypeDescr):
@staticmethod
def to_user(data):
if six.PY3:
return base64.b64encode(data).decode('ascii')
else:
return base64.b64encode(data)
return base64.b64encode(data).decode('ascii')
from_user = staticmethod(base64.b64decode)

View File

@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
import struct
from os_ken import utils
@ -397,7 +395,7 @@ def generate(ofp_name, ofpp_name):
hdr_data = bytearray()
n = ofp.oxm_from_user_header(self.dst)
ofp.oxm_serialize_header(n, hdr_data, 0)
(dst_num,) = struct.unpack_from('!I', six.binary_type(hdr_data), 0)
(dst_num,) = struct.unpack_from('!I', bytes(hdr_data), 0)
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
@ -520,7 +518,7 @@ def generate(ofp_name, ofpp_name):
def serialize_body(self):
assert isinstance(self.note, (tuple, list))
for n in self.note:
assert isinstance(n, six.integer_types)
assert isinstance(n, int)
pad = (len(self.note) + nicira_ext.NX_ACTION_HEADER_0_SIZE) % 8
if pad:
@ -887,7 +885,7 @@ def generate(ofp_name, ofpp_name):
ofp.oxm_serialize_header(oxm, src, 0),
msg_pack_into(self._fmt_str, data, 0,
self.ofs_nbits,
six.binary_type(src),
bytes(src),
self.max_len)
return data
@ -968,7 +966,7 @@ def generate(ofp_name, ofpp_name):
msg_pack_into(self._fmt_str, data, 0,
self.ofs_nbits,
self.max_len,
six.binary_type(oxm_data))
bytes(oxm_data))
offset = len(data)
msg_pack_into("!%dx" % (14 - offset), data, offset)
return data
@ -1611,7 +1609,7 @@ def generate(ofp_name, ofpp_name):
def serialize_body(self):
assert isinstance(self.cnt_ids, (tuple, list))
for i in self.cnt_ids:
assert isinstance(i, six.integer_types)
assert isinstance(i, int)
controllers = len(self.cnt_ids)
@ -1968,7 +1966,7 @@ def generate(ofp_name, ofpp_name):
ofp.oxm_serialize_header(oxm, oxm_data, 0)
msg_pack_into(self._fmt_str, data, 0,
self.start,
six.binary_type(oxm_data),
bytes(oxm_data),
self.end)
offset = len(data)
msg_pack_into("!%dx" % (12 - offset), data, offset)
@ -2419,7 +2417,7 @@ def generate(ofp_name, ofpp_name):
self.max_link,
self.arg,
self.ofs_nbits,
six.binary_type(dst))
bytes(dst))
return data
@ -2444,7 +2442,7 @@ def generate(ofp_name, ofpp_name):
assert isinstance(slaves, (list, tuple))
for s in slaves:
assert isinstance(s, six.integer_types)
assert isinstance(s, int)
self.slaves = slaves
@ -2724,7 +2722,7 @@ def generate(ofp_name, ofpp_name):
# If zone_src is zero, zone_ofs_nbits is zone_imm
if not self.zone_src:
zone_src = b'\x00' * 4
elif isinstance(self.zone_src, six.integer_types):
elif isinstance(self.zone_src, int):
zone_src = struct.pack("!I", self.zone_src)
else:
zone_src = bytearray()
@ -2733,7 +2731,7 @@ def generate(ofp_name, ofpp_name):
msg_pack_into(self._fmt_str, data, 0,
self.flags,
six.binary_type(zone_src),
bytes(zone_src),
self.zone_ofs_nbits,
self.recirc_table,
self.alg)

View File

@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
import base64
import collections
import logging
@ -30,16 +28,12 @@ from os_ken.ofproto import ofproto_common
LOG = logging.getLogger('os_ken.ofproto.ofproto_parser')
# This is merely for API compatibility on python2
if six.PY3:
buffer = bytes
def header(buf):
assert len(buf) >= ofproto_common.OFP_HEADER_SIZE
# LOG.debug('len %d bufsize %d', len(buf), ofproto.OFP_HEADER_SIZE)
return struct.unpack_from(ofproto_common.OFP_HEADER_PACK_STR,
six.binary_type(buf))
bytes(buf))
_MSG_PARSERS = {}
@ -225,11 +219,11 @@ class MsgBase(StringifyMixin):
self.xid = xid
def set_buf(self, buf):
self.buf = buffer(buf)
self.buf = bytes(buf)
def __str__(self):
def hexify(x):
return hex(x) if isinstance(x, six.integer_types) else x
return hex(x) if isinstance(x, int) else x
buf = 'version=%s,msg_type=%s,msg_len=%s,xid=%s,' %\
(hexify(self.version), hexify(self.msg_type),
hexify(self.msg_len), hexify(self.xid))

View File

@ -21,7 +21,6 @@ Decoder/Encoder implementations of OpenFlow 1.0.
import struct
import base64
import six
import netaddr
from os_ken.ofproto.ofproto_parser import StringifyMixin, MsgBase
@ -219,7 +218,7 @@ class OFPMatch(StringifyMixin):
self.dl_src = mac.DONTCARE
else:
wc &= ~ofproto.OFPFW_DL_SRC
if (isinstance(dl_src, (six.text_type, str)) and
if (isinstance(dl_src, (str, str)) and
netaddr.valid_mac(dl_src)):
dl_src = addrconv.mac.text_to_bin(dl_src)
if dl_src == 0:
@ -231,7 +230,7 @@ class OFPMatch(StringifyMixin):
self.dl_dst = mac.DONTCARE
else:
wc &= ~ofproto.OFPFW_DL_DST
if (isinstance(dl_dst, (six.text_type, str)) and
if (isinstance(dl_dst, (str, str)) and
netaddr.valid_mac(dl_dst)):
dl_dst = addrconv.mac.text_to_bin(dl_dst)
if dl_dst == 0:
@ -528,7 +527,7 @@ class OFPActionStripVlan(OFPAction):
class OFPActionDlAddr(OFPAction):
def __init__(self, dl_addr):
super(OFPActionDlAddr, self).__init__()
if (isinstance(dl_addr, (six.text_type, str)) and
if (isinstance(dl_addr, (str, str)) and
netaddr.valid_mac(dl_addr)):
dl_addr = addrconv.mac.text_to_bin(dl_addr)
self.dl_addr = dl_addr
@ -1258,7 +1257,7 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
if isinstance(data, six.string_types):
if isinstance(data, str):
data = data.encode('ascii')
self.data = data
@ -2134,7 +2133,7 @@ class OFPStatsReply(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, flags = struct.unpack_from(ofproto.OFP_STATS_MSG_PACK_STR,
six.binary_type(buf),
bytes(buf),
ofproto.OFP_HEADER_SIZE)
stats_type_cls = cls._STATS_MSG_TYPES.get(type_)
msg = stats_type_cls.parser_stats(
@ -2448,7 +2447,7 @@ class OFPVendorStatsReply(OFPStatsReply):
def parser_stats(cls, datapath, version, msg_type, msg_len, xid,
buf):
(type_,) = struct.unpack_from(
ofproto.OFP_VENDOR_STATS_MSG_PACK_STR, six.binary_type(buf),
ofproto.OFP_VENDOR_STATS_MSG_PACK_STR, bytes(buf),
ofproto.OFP_STATS_MSG_SIZE)
cls_ = cls._STATS_VENDORS.get(type_)
@ -2509,7 +2508,7 @@ class NXStatsReply(OFPStatsReply):
def parser(cls, datapath, version, msg_type, msg_len, xid, buf,
offset):
(type_,) = struct.unpack_from(
ofproto.NX_STATS_MSG_PACK_STR, six.binary_type(buf), offset)
ofproto.NX_STATS_MSG_PACK_STR, bytes(buf), offset)
offset += ofproto.NX_STATS_MSG0_SIZE
cls_ = cls._NX_STATS_TYPES.get(type_)

View File

@ -21,8 +21,6 @@ Decoder/Encoder implementations of OpenFlow 1.2.
import struct
import base64
import six
from os_ken.lib import addrconv
from os_ken.lib import mac
from os_ken.lib.pack_utils import msg_pack_into
@ -141,7 +139,7 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
if isinstance(data, six.string_types):
if isinstance(data, str):
data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
@ -150,7 +148,7 @@ class OFPErrorMsg(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, = struct.unpack_from('!H', six.binary_type(buf),
type_, = struct.unpack_from('!H', bytes(buf),
ofproto.OFP_HEADER_SIZE)
msg = super(OFPErrorMsg, cls).parser(datapath, version, msg_type,
msg_len, xid, buf)
@ -1612,7 +1610,7 @@ class OFPActionSetField(OFPAction):
assert len(kwargs) == 1
key = list(kwargs.keys())[0]
value = kwargs[key]
assert isinstance(key, (str, six.text_type))
assert isinstance(key, (str, str))
assert not isinstance(value, tuple) # no mask
self.key = key
self.value = value
@ -1675,7 +1673,7 @@ class OFPActionSetField(OFPAction):
# serialize and parse to fill old attributes
buf = bytearray()
o.serialize(buf, 0)
return OFPActionSetField.parser(six.binary_type(buf), 0)
return OFPActionSetField.parser(bytes(buf), 0)
# XXX old api compat
def __str__(self):
@ -1686,7 +1684,7 @@ class OFPActionSetField(OFPAction):
# serialize and parse to fill new fields
buf = bytearray()
o2.serialize(buf, 0)
o = OFPActionSetField.parser(six.binary_type(buf), 0)
o = OFPActionSetField.parser(bytes(buf), 0)
else:
o = self
return super(OFPActionSetField, o).__str__()
@ -3597,7 +3595,7 @@ class OFPMatch(StringifyMixin):
# serialize and parse to fill OFPMatch._fields2
buf = bytearray()
o2.serialize(buf, 0)
o = OFPMatch.parser(six.binary_type(buf), 0)
o = OFPMatch.parser(bytes(buf), 0)
else:
o = self
@ -3622,7 +3620,7 @@ class OFPMatch(StringifyMixin):
# serialize and parse to fill OFPMatch.fields
buf = bytearray()
o.serialize(buf, 0)
return OFPMatch.parser(six.binary_type(buf), 0)
return OFPMatch.parser(bytes(buf), 0)
def __str__(self):
# XXX old api compat
@ -3633,7 +3631,7 @@ class OFPMatch(StringifyMixin):
# serialize and parse to fill OFPMatch._fields2
buf = bytearray()
o2.serialize(buf, 0)
o = OFPMatch.parser(six.binary_type(buf), 0)
o = OFPMatch.parser(bytes(buf), 0)
else:
o = self
return super(OFPMatch, o).__str__()

View File

@ -43,8 +43,6 @@ The following extensions are not implemented yet.
import struct
import base64
import six
from os_ken.lib import addrconv
from os_ken.lib import mac
from os_ken.lib.pack_utils import msg_pack_into
@ -252,7 +250,7 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
if isinstance(data, six.string_types):
if isinstance(data, str):
data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
@ -261,7 +259,7 @@ class OFPErrorMsg(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, = struct.unpack_from('!H', six.binary_type(buf),
type_, = struct.unpack_from('!H', bytes(buf),
ofproto.OFP_HEADER_SIZE)
msg = super(OFPErrorMsg, cls).parser(datapath, version, msg_type,
msg_len, xid, buf)
@ -931,7 +929,7 @@ class OFPMatch(StringifyMixin):
# serialize and parse to fill OFPMatch._fields2
buf = bytearray()
o2.serialize(buf, 0)
o = OFPMatch.parser(six.binary_type(buf), 0)
o = OFPMatch.parser(bytes(buf), 0)
else:
o = self
@ -956,7 +954,7 @@ class OFPMatch(StringifyMixin):
# serialize and parse to fill OFPMatch.fields
buf = bytearray()
o.serialize(buf, 0)
return OFPMatch.parser(six.binary_type(buf), 0)
return OFPMatch.parser(bytes(buf), 0)
def __str__(self):
# XXX old api compat
@ -967,7 +965,7 @@ class OFPMatch(StringifyMixin):
# serialize and parse to fill OFPMatch._fields2
buf = bytearray()
o2.serialize(buf, 0)
o = OFPMatch.parser(six.binary_type(buf), 0)
o = OFPMatch.parser(bytes(buf), 0)
else:
o = self
return super(OFPMatch, o).__str__()
@ -3385,7 +3383,7 @@ class OFPActionSetField(OFPAction):
assert len(kwargs) == 1
key = list(kwargs.keys())[0]
value = kwargs[key]
assert isinstance(key, (str, six.text_type))
assert isinstance(key, (str, str))
assert not isinstance(value, tuple) # no mask
self.key = key
self.value = value
@ -3449,7 +3447,7 @@ class OFPActionSetField(OFPAction):
# serialize and parse to fill old attributes
buf = bytearray()
o.serialize(buf, 0)
return OFPActionSetField.parser(six.binary_type(buf), 0)
return OFPActionSetField.parser(bytes(buf), 0)
# XXX old api compat
def __str__(self):
@ -3460,7 +3458,7 @@ class OFPActionSetField(OFPAction):
# serialize and parse to fill new fields
buf = bytearray()
o2.serialize(buf, 0)
o = OFPActionSetField.parser(six.binary_type(buf), 0)
o = OFPActionSetField.parser(bytes(buf), 0)
else:
o = self
return super(OFPActionSetField, o).__str__()
@ -3933,7 +3931,7 @@ class OFPMultipartReply(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, flags = struct.unpack_from(
ofproto.OFP_MULTIPART_REPLY_PACK_STR, six.binary_type(buf),
ofproto.OFP_MULTIPART_REPLY_PACK_STR, bytes(buf),
ofproto.OFP_HEADER_SIZE)
stats_type_cls = cls._STATS_MSG_TYPES.get(type_)
msg = super(OFPMultipartReply, stats_type_cls).parser( # pytype: disable=attribute-error
@ -5320,7 +5318,7 @@ class OFPInstructionId(StringifyMixin):
@classmethod
def parse(cls, buf):
(type_, len_,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf), 0)
bytes(buf), 0)
rest = buf[len_:]
return cls(type_=type_, len_=len_), rest
@ -5374,7 +5372,7 @@ class OFPTableFeaturePropNextTables(OFPTableFeatureProp):
ids = []
while rest:
(i,) = struct.unpack_from(cls._TABLE_ID_PACK_STR,
six.binary_type(rest), 0)
bytes(rest), 0)
rest = rest[struct.calcsize(cls._TABLE_ID_PACK_STR):]
ids.append(i)
return cls(table_ids=ids)
@ -5408,7 +5406,7 @@ class OFPActionId(StringifyMixin):
@classmethod
def parse(cls, buf):
(type_, len_,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf), 0)
bytes(buf), 0)
rest = buf[len_:]
return cls(type_=type_, len_=len_), rest
@ -5484,7 +5482,7 @@ class OFPOxmId(StringifyMixin):
@classmethod
def parse(cls, buf):
(oxm,) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf), 0)
(oxm,) = struct.unpack_from(cls._PACK_STR, bytes(buf), 0)
# oxm (32 bit) == class (16) | field (7) | hasmask (1) | length (8)
# in case of experimenter OXMs, another 32 bit value
# (experimenter id) follows.
@ -5495,7 +5493,7 @@ class OFPOxmId(StringifyMixin):
class_ = oxm >> (7 + 1 + 8)
if class_ == ofproto.OFPXMC_EXPERIMENTER:
(exp_id,) = struct.unpack_from(cls._EXPERIMENTER_ID_PACK_STR,
six.binary_type(rest), 0)
bytes(rest), 0)
rest = rest[struct.calcsize(cls._EXPERIMENTER_ID_PACK_STR):]
subcls = OFPExperimenterOxmId
return subcls(type_=type_, exp_id=exp_id, hasmask=hasmask,

View File

@ -21,8 +21,6 @@ Decoder/Encoder implementations of OpenFlow 1.4.
import struct
import base64
import six
from os_ken.lib import addrconv
from os_ken.lib.pack_utils import msg_pack_into
from os_ken.lib.packet import packet
@ -272,7 +270,7 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
if isinstance(data, six.string_types):
if isinstance(data, str):
data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
@ -281,7 +279,7 @@ class OFPErrorMsg(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, = struct.unpack_from('!H', six.binary_type(buf),
type_, = struct.unpack_from('!H', bytes(buf),
ofproto.OFP_HEADER_SIZE)
msg = super(OFPErrorMsg, cls).parser(datapath, version, msg_type,
msg_len, xid, buf)
@ -1662,7 +1660,7 @@ class OFPMultipartReply(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, flags = struct.unpack_from(
ofproto.OFP_MULTIPART_REPLY_PACK_STR, six.binary_type(buf),
ofproto.OFP_MULTIPART_REPLY_PACK_STR, bytes(buf),
ofproto.OFP_HEADER_SIZE)
stats_type_cls = cls._STATS_MSG_TYPES.get(type_)
msg = super(OFPMultipartReply, stats_type_cls).parser(
@ -1841,7 +1839,7 @@ class OFPInstructionId(StringifyMixin):
@classmethod
def parse(cls, buf):
(type_, len_,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf), 0)
bytes(buf), 0)
rest = buf[len_:]
return cls(type_=type_, len_=len_), rest
@ -1893,7 +1891,7 @@ class OFPActionId(StringifyMixin):
@classmethod
def parse(cls, buf):
(type_, len_,) = struct.unpack_from(cls._PACK_STR,
six.binary_type(buf), 0)
bytes(buf), 0)
rest = buf[len_:]
return cls(type_=type_, len_=len_), rest
@ -1949,7 +1947,7 @@ class OFPTableFeaturePropNextTables(OFPTableFeatureProp):
ids = []
while rest:
(i,) = struct.unpack_from(cls._TABLE_ID_PACK_STR,
six.binary_type(rest), 0)
bytes(rest), 0)
rest = rest[struct.calcsize(cls._TABLE_ID_PACK_STR):]
ids.append(i)
return cls(table_ids=ids)
@ -2000,7 +1998,7 @@ class OFPOxmId(StringifyMixin):
@classmethod
def parse(cls, buf):
(oxm,) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf), 0)
(oxm,) = struct.unpack_from(cls._PACK_STR, bytes(buf), 0)
# oxm (32 bit) == class (16) | field (7) | hasmask (1) | length (8)
# in case of experimenter OXMs, another 32 bit value
# (experimenter id) follows.
@ -2011,7 +2009,7 @@ class OFPOxmId(StringifyMixin):
class_ = oxm >> (7 + 1 + 8)
if class_ == ofproto.OFPXMC_EXPERIMENTER:
(exp_id,) = struct.unpack_from(cls._EXPERIMENTER_ID_PACK_STR,
six.binary_type(rest), 0)
bytes(rest), 0)
rest = rest[struct.calcsize(cls._EXPERIMENTER_ID_PACK_STR):]
subcls = OFPExperimenterOxmId
return subcls(type_=type_, exp_id=exp_id, hasmask=hasmask,
@ -5050,7 +5048,7 @@ class OFPActionSetField(OFPAction):
assert len(kwargs) == 1
key = list(kwargs.keys())[0]
value = kwargs[key]
assert isinstance(key, (str, six.text_type))
assert isinstance(key, (str, str))
assert not isinstance(value, tuple) # no mask
self.key = key
self.value = value

View File

@ -21,8 +21,6 @@ Decoder/Encoder implementations of OpenFlow 1.5.
import struct
import base64
import six
from os_ken.lib import addrconv
from os_ken.lib.pack_utils import msg_pack_into
from os_ken.lib.packet import packet
@ -272,7 +270,7 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
if isinstance(data, six.string_types):
if isinstance(data, str):
data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
@ -281,7 +279,7 @@ class OFPErrorMsg(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, = struct.unpack_from('!H', six.binary_type(buf),
type_, = struct.unpack_from('!H', bytes(buf),
ofproto.OFP_HEADER_SIZE)
msg = super(OFPErrorMsg, cls).parser(datapath, version, msg_type,
msg_len, xid, buf)
@ -1232,7 +1230,7 @@ class OFPPortDescPropRecirculate(OFPPortDescProp):
nos = []
while rest:
(n,) = struct.unpack_from(cls._PORT_NO_PACK_STR,
six.binary_type(rest), 0)
bytes(rest), 0)
rest = rest[struct.calcsize(cls._PORT_NO_PACK_STR):]
nos.append(n)
return cls(port_nos=nos)
@ -1898,7 +1896,7 @@ class OFPMultipartReply(MsgBase):
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
type_, flags = struct.unpack_from(
ofproto.OFP_MULTIPART_REPLY_PACK_STR, six.binary_type(buf),
ofproto.OFP_MULTIPART_REPLY_PACK_STR, bytes(buf),
ofproto.OFP_HEADER_SIZE)
stats_type_cls = cls._STATS_MSG_TYPES.get(type_)
msg = super(OFPMultipartReply, stats_type_cls).parser(
@ -2080,7 +2078,7 @@ class OFPInstructionId(StringifyMixin):
@classmethod
def parse(cls, buf):
(type_, len_,) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf), 0)
(type_, len_,) = struct.unpack_from(cls._PACK_STR, bytes(buf), 0)
rest = buf[len_:]
return cls(type_=type_, len_=len_), rest
@ -2131,7 +2129,7 @@ class OFPActionId(StringifyMixin):
@classmethod
def parse(cls, buf):
(type_, len_,) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf), 0)
(type_, len_,) = struct.unpack_from(cls._PACK_STR, bytes(buf), 0)
rest = buf[len_:]
return cls(type_=type_, len_=len_), rest
@ -2186,7 +2184,7 @@ class OFPTableFeaturePropNextTables(OFPTableFeatureProp):
rest = cls.get_rest(buf)
ids = []
while rest:
(i,) = struct.unpack_from(cls._TABLE_ID_PACK_STR, six.binary_type(rest), 0)
(i,) = struct.unpack_from(cls._TABLE_ID_PACK_STR, bytes(rest), 0)
rest = rest[struct.calcsize(cls._TABLE_ID_PACK_STR):]
ids.append(i)
return cls(table_ids=ids)
@ -2241,7 +2239,7 @@ class OFPOxmId(StringifyMixin):
@classmethod
def parse(cls, buf):
(oxm,) = struct.unpack_from(cls._PACK_STR, six.binary_type(buf), 0)
(oxm,) = struct.unpack_from(cls._PACK_STR, bytes(buf), 0)
# oxm (32 bit) == class (16) | field (7) | hasmask (1) | length (8)
# in case of experimenter OXMs, another 32 bit value
# (experimenter id) follows.
@ -2252,7 +2250,7 @@ class OFPOxmId(StringifyMixin):
class_ = oxm >> (7 + 1 + 8)
if class_ == ofproto.OFPXMC_EXPERIMENTER:
(exp_id,) = struct.unpack_from(cls._EXPERIMENTER_ID_PACK_STR,
six.binary_type(rest), 0)
bytes(rest), 0)
rest = rest[struct.calcsize(cls._EXPERIMENTER_ID_PACK_STR):]
subcls = OFPExperimenterOxmId
return subcls(type_=type_, exp_id=exp_id, hasmask=hasmask,
@ -5935,7 +5933,7 @@ class OFPActionSetField(OFPAction):
assert len(kwargs) == 1
key = list(kwargs.keys())[0]
value = kwargs[key]
assert isinstance(key, (str, six.text_type))
assert isinstance(key, (str, str))
self.key = key
self.value = value
@ -6061,7 +6059,7 @@ class OFPActionCopyField(OFPAction):
if isinstance(i, OFPOxmId):
i.hasmask = False # fixup
self.oxm_ids.append(i)
elif isinstance(i, six.text_type):
elif isinstance(i, str):
self.oxm_ids.append(OFPOxmId(i, hasmask=False))
else:
raise ValueError('invalid value for oxm_ids: %s' % oxm_ids)

View File

@ -23,17 +23,12 @@
# value and mask are on-wire bytes.
# mask is None if no mask.
import six
import struct
from os_ken.ofproto import ofproto_common
from os_ken.lib.pack_utils import msg_pack_into
from os_ken.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.
@ -85,7 +80,7 @@ def _get_field_info_by_number(oxx, num_to_field, n):
name = f.name
except KeyError:
t = type_desc.UnknownType
if isinstance(n, six.integer_types):
if isinstance(n, int):
name = 'field_%d' % (n,)
else:
raise KeyError('unknown %s field number: %s' % (oxx.upper(), n))
@ -130,7 +125,7 @@ def _normalize_user(oxx, mod, k, uv):
return (k, uv)
# apply mask
if m is not None:
v = b''.join(six.int2byte(_ord(x) & _ord(y)) for (x, y) in zip(v, m))
v = b''.join(struct.Struct(">B").pack(int(x) & int(y)) for (x, y) in zip(v, m))
try:
to_user = getattr(mod, oxx + '_to_user')
(k2, uv2) = to_user(n, v, m)

View File

@ -25,7 +25,6 @@ import traceback
import weakref
import netaddr
import six
from os_ken.lib import hub
from os_ken.lib import sockopt
@ -139,8 +138,7 @@ class ActivityException(BGPSException):
pass
@six.add_metaclass(abc.ABCMeta)
class Activity(object):
class Activity(object, metaclass=abc.ABCMeta):
"""Base class for a thread of execution that provides some custom settings.
Activity is also a container of other activities or threads that it has

View File

@ -25,7 +25,6 @@ from copy import copy
import logging
import functools
import netaddr
import six
from os_ken.lib.packet.bgp import RF_IPv4_UC
from os_ken.lib.packet.bgp import RouteTargetMembershipNLRI
@ -44,8 +43,7 @@ from os_ken.services.protocols.bgp.processor import BPR_UNKNOWN
LOG = logging.getLogger('bgpspeaker.info_base.base')
@six.add_metaclass(ABCMeta)
class Table(object):
class Table(object, metaclass=abc.ABCMeta):
"""A container for holding information about destination/prefixes.
Routing information base for a particular afi/safi.
@ -276,8 +274,7 @@ class NonVrfPathProcessingMixin(object):
self._sent_routes = {}
@six.add_metaclass(ABCMeta)
class Destination(object):
class Destination(object, metaclass=abc.ABCMeta):
"""State about a particular destination.
For example, an IP prefix. This is the data-structure that is hung of the
@ -688,8 +685,7 @@ class Destination(object):
return str(self) >= str(other)
@six.add_metaclass(ABCMeta)
class Path(object):
class Path(object, metaclass=abc.ABCMeta):
"""Represents a way of reaching an IP destination.
Also contains other meta-data given to us by a specific source (such as a
@ -861,8 +857,7 @@ class Path(object):
self._path_attr_map, self._nexthop, self._is_withdraw))
@six.add_metaclass(ABCMeta)
class Filter(object):
class Filter(object, metaclass=abc.ABCMeta):
"""Represents a general filter for in-bound and out-bound filter
================ ==================================================

View File

@ -19,7 +19,6 @@
import abc
import logging
import six
from os_ken.lib.packet.bgp import RF_L2_EVPN
from os_ken.services.protocols.bgp.info_base.base import Destination
@ -57,8 +56,7 @@ class VpnTable(Table):
)
@six.add_metaclass(abc.ABCMeta)
class VpnPath(Path):
class VpnPath(Path, metaclass=abc.ABCMeta):
ROUTE_FAMILY = None
VRF_PATH_CLASS = None
NLRI_CLASS = None
@ -90,8 +88,7 @@ class VpnPath(Path):
return vrf_path
@six.add_metaclass(abc.ABCMeta)
class VpnDest(Destination, NonVrfPathProcessingMixin):
class VpnDest(Destination, NonVrfPathProcessingMixin, metaclass=abc.ABCMeta):
"""Base class for VPN destinations."""
def _best_path_lost(self):

View File

@ -19,7 +19,6 @@
import abc
import logging
import six
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
@ -59,8 +58,7 @@ from os_ken.services.protocols.bgp.utils.stats import RESOURCE_NAME
LOG = logging.getLogger('bgpspeaker.info_base.vrf')
@six.add_metaclass(abc.ABCMeta)
class VrfTable(Table):
class VrfTable(Table, metaclass=abc.ABCMeta):
"""Virtual Routing and Forwarding information base.
Keeps destination imported to given vrf in represents.
"""
@ -362,8 +360,7 @@ class VrfTable(Table):
return super(VrfTable, self).clean_uninteresting_paths(interested_rts)
@six.add_metaclass(abc.ABCMeta)
class VrfDest(Destination):
class VrfDest(Destination, metaclass=abc.ABCMeta):
"""Base class for VRF destination."""
def __init__(self, table, nlri):
@ -520,8 +517,7 @@ class VrfDest(Destination):
'with attribute label_list got %s' % path)
@six.add_metaclass(abc.ABCMeta)
class VrfPath(Path):
class VrfPath(Path, metaclass=abc.ABCMeta):
"""Represents a way of reaching an IP destination with a VPN.
"""
__slots__ = ('_label_list', '_puid')

View File

@ -20,7 +20,6 @@
import abc
import logging
import six
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
@ -39,8 +38,7 @@ from os_ken.services.protocols.bgp.utils.bgp import create_rt_extended_community
LOG = logging.getLogger('bgpspeaker.info_base.vrffs')
@six.add_metaclass(abc.ABCMeta)
class VRFFlowSpecTable(VrfTable):
class VRFFlowSpecTable(VrfTable, metaclass=abc.ABCMeta):
"""Virtual Routing and Forwarding information base.
Keeps destination imported to given VRF Flow Specification
in represents.
@ -80,13 +78,11 @@ class VRFFlowSpecTable(VrfTable):
self._signal_bus.dest_changed(eff_dest)
@six.add_metaclass(abc.ABCMeta)
class VRFFlowSpecDest(VrfDest):
class VRFFlowSpecDest(VrfDest, metaclass=abc.ABCMeta):
"""Base class for VRF Flow Specification."""
@six.add_metaclass(abc.ABCMeta)
class VRFFlowSpecPath(VrfPath):
class VRFFlowSpecPath(VrfPath, metaclass=abc.ABCMeta):
"""Represents a way of reaching an IP destination with
a VPN Flow Specification.
"""

View File

@ -3,7 +3,7 @@ import json
import logging
import pprint
import re
import six
(STATUS_OK, STATUS_ERROR) = range(2)
@ -110,7 +110,7 @@ class Command(object):
if resp.status == STATUS_OK:
if type(resp.value) in (str, bool, int, float, six.text_type):
if type(resp.value) in (str, bool, int, float, str):
return str(resp.value)
ret = ''

View File

@ -1,4 +1,4 @@
import six
import io
class RouteFormatterMixin(object):
@ -17,7 +17,7 @@ class RouteFormatterMixin(object):
@classmethod
def _format_family(cls, dest_list):
msg = six.StringIO()
msg = io.StringIO()
def _append_path_info(buff, path, is_best, show_prefix):
aspath = path.get('aspath')

View File

@ -1,8 +1,6 @@
import importlib
import inspect
import six
class Field(object):
def __init__(self, field_name):
@ -21,7 +19,7 @@ class RelatedViewField(Field):
def _operator_view_class(self):
if inspect.isclass(self.__operator_view_class):
return self.__operator_view_class
elif isinstance(self.__operator_view_class, six.string_types):
elif isinstance(self.__operator_view_class, str):
try:
module_name, class_name =\
self.__operator_view_class.rsplit('.', 1)

View File

@ -15,14 +15,14 @@
"""
BGP peer related classes and utils.
"""
from collections import namedtuple
import itertools
import logging
import socket
import time
import traceback
from six.moves import zip_longest
from os_ken.services.protocols.bgp.base import Activity
from os_ken.services.protocols.bgp.base import Sink
from os_ken.services.protocols.bgp.base import Source
@ -888,7 +888,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
new_as_path_list = []
tmp_list = []
for as_path, as4_path in zip_longest(org_as_path_list, as4_path_list):
for as_path, as4_path in itertools.zip_longest(org_as_path_list,
as4_path_list):
if as4_path is None:
if isinstance(as_path, int):
tmp_list.insert(0, as_path)

View File

@ -17,13 +17,10 @@
Module defines protocol based classes and utils.
"""
from abc import ABCMeta
from abc import abstractmethod
import six
import abc
@six.add_metaclass(ABCMeta)
class Protocol(object):
class Protocol(object, metaclass=abc.ABCMeta):
"""Interface for various protocols.
Protocol usually encloses a transport/connection/socket to
@ -34,7 +31,7 @@ class Protocol(object):
appropriate.
"""
@abstractmethod
@abc.abstractmethod
def data_received(self, data):
"""Handler for date received over connection/transport.
@ -44,7 +41,7 @@ class Protocol(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def connection_made(self):
"""Called when connection has been established according to protocol.
@ -53,7 +50,7 @@ class Protocol(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def connection_lost(self, reason):
"""Handler called when connection to peer/remote according to protocol
has been lost.
@ -63,8 +60,7 @@ class Protocol(object):
pass
@six.add_metaclass(ABCMeta)
class Factory(object):
class Factory(object, metaclass=abc.ABCMeta):
"""This is a factory which produces protocols.
Can also act as context for protocols.
@ -73,7 +69,7 @@ class Factory(object):
# Put a subclass of Protocol here:
protocol = None
@abstractmethod
@abc.abstractmethod
def build_protocol(self, socket):
"""Create an instance of a subclass of Protocol.
@ -81,7 +77,7 @@ class Factory(object):
"""
raise NotImplementedError()
@abstractmethod
@abc.abstractmethod
def start_protocol(self, socket):
"""Launch protocol instance to handle input on an incoming connection.
"""

View File

@ -16,6 +16,7 @@
"""
Running or runtime configuration base classes.
"""
import abc
from abc import ABCMeta
from abc import abstractmethod
import functools
@ -23,8 +24,6 @@ import numbers
import logging
import uuid
import six
from os_ken.services.protocols.bgp.base import add_bgp_error_metadata
from os_ken.services.protocols.bgp.base import BGPSException
from os_ken.services.protocols.bgp.base import get_validator
@ -154,8 +153,7 @@ class ConfigValueError(RuntimeConfigError):
# Configuration base classes.
# =============================================================================
@six.add_metaclass(ABCMeta)
class BaseConf(object):
class BaseConf(object, metaclass=abc.ABCMeta):
"""Base class for a set of configuration values.
Configurations can be required or optional. Also acts as a container of
@ -436,8 +434,7 @@ class ConfWithStats(BaseConf):
**kwargs)
@six.add_metaclass(ABCMeta)
class BaseConfListener(object):
class BaseConfListener(object, metaclass=abc.ABCMeta):
"""Base class of all configuration listeners."""
def __init__(self, base_conf):
@ -756,7 +753,7 @@ def validate_soo_list(soo_list):
@validate(name=MAX_PREFIXES)
def validate_max_prefixes(max_prefixes):
if not isinstance(max_prefixes, six.integer_types):
if not isinstance(max_prefixes, int):
raise ConfigTypeError(desc='Max. prefixes value should be of type '
'int or long but found %s' % type(max_prefixes))
if max_prefixes < 0:

View File

@ -13,9 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
if six.PY3:
from sys import intern
from sys import intern
class CircularListType(object):

View File

@ -15,7 +15,6 @@
import collections
import errno
import six
import uuid
from ovs import jsonrpc
@ -174,14 +173,14 @@ def _filter_schema(schema, schema_tables, exclude_table_columns):
if key and isinstance(key, dict):
ref_tbl = key.get('refTable')
if ref_tbl and isinstance(ref_tbl,
six.string_types):
str):
if ref_tbl not in schema_tables:
continue
value = type_.get('value')
if value and isinstance(value, dict):
ref_tbl = value.get('refTable')
if ref_tbl and isinstance(ref_tbl,
six.string_types):
str):
if ref_tbl not in schema_tables:
continue

View File

@ -21,7 +21,6 @@ VRRPManager creates/deletes VRRPRounter instances dynamically.
"""
import abc
import six
from os_ken.base import app_manager
from os_ken.controller import event
@ -104,8 +103,7 @@ class VRRPParams(object):
return (3.0 * self.master_adver_interval) + self.skew_time
@six.add_metaclass(abc.ABCMeta)
class VRRPState(object):
class VRRPState(object, metaclass=abc.ABCMeta):
def __init__(self, vrrp_router):
super(VRRPState, self).__init__()
self.vrrp_router = vrrp_router

View File

@ -24,7 +24,7 @@ import subprocess
import time
import netaddr
import six
LOG = logging.getLogger(__name__)
@ -114,8 +114,8 @@ class Command(object):
stdout=p_stdout,
stderr=p_stderr)
__stdout, __stderr = pop.communicate()
_stdout = six.text_type(__stdout, 'utf-8')
_stderr = six.text_type(__stderr, 'utf-8')
_stdout = str(__stdout, 'utf-8')
_stderr = str(__stderr, 'utf-8')
out = CommandOut(_stdout, _stderr, cmd, pop.returncode)
return out

View File

@ -3,8 +3,7 @@
import getopt
import os
import re
import six
from six.moves import socketserver
import socketserver
import subprocess
import sys
import tempfile
@ -17,12 +16,8 @@ from os_ken.ofproto import ofproto_v1_5
from os_ken.ofproto import ofproto_v1_5_parser
from os_ken.ofproto import ofproto_protocol
if six.PY3:
TimeoutExpired = subprocess.TimeoutExpired
else:
# As python2 doesn't have timeout for subprocess.call,
# this script may hang.
TimeoutExpired = None
TimeoutExpired = subprocess.TimeoutExpired
STD_MATCH = [
'in_port=43981',

View File

@ -21,7 +21,6 @@ import math
import netaddr
import os
import signal
import six
import sys
import time
import traceback
@ -963,7 +962,7 @@ class OfTester(app_manager.OSKenApp):
def _diff_packets(cls, model_pkt, rcv_pkt):
msg = []
for rcv_p in rcv_pkt.protocols:
if not isinstance(rcv_p, six.binary_type):
if not isinstance(rcv_p, bytes):
model_protocols = model_pkt.get_protocols(type(rcv_p))
if len(model_protocols) == 1:
model_p = model_protocols[0]
@ -990,7 +989,7 @@ class OfTester(app_manager.OSKenApp):
else:
model_p = ''
for p in model_pkt.protocols:
if isinstance(p, six.binary_type):
if isinstance(p, bytes):
model_p = p
break
if model_p != rcv_p:
@ -1370,7 +1369,7 @@ class TestFile(stringify.StringifyMixin):
try:
json_list = json.loads(buf)
for test_json in json_list:
if isinstance(test_json, six.text_type):
if isinstance(test_json, str):
self.description = test_json
else:
self._normalize_test_json(test_json)
@ -1393,7 +1392,7 @@ class Test(stringify.StringifyMixin):
def __test_pkt_from_json(test):
data = eval('/'.join(test))
data.serialize()
return six.binary_type(data.data)
return bytes(data.data)
# create Datapath instance using user-specified versions
target_dp = DummyDatapath(OfTester.target_ver)

View File

@ -13,10 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import six
import binascii
import unittest
import struct
@ -28,9 +24,6 @@ from os_ken.ofproto import ofproto_v1_0, ofproto_v1_0_parser
import logging
LOG = logging.getLogger(__name__)
if six.PY3:
buffer = bytes
class TestOfproto_Parser(unittest.TestCase):
def setUp(self):
@ -171,7 +164,7 @@ class TestMsgBase(unittest.TestCase):
self.assertEqual(msg_type, res.msg_type)
self.assertEqual(msg_len, res.msg_len)
self.assertEqual(xid, res.xid)
self.assertEqual(buffer(buf), res.buf)
self.assertEqual(bytes(buf), res.buf)
# test __str__()
list_ = ('version', 'msg_type', 'msg_len', 'xid')

View File

@ -14,8 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import operator
import os.path
import six
import sys
import unittest
import testscenarios
@ -224,8 +224,8 @@ class Test_Parser(testscenarios.WithScenarios, unittest.TestCase):
if buf1 != buf2:
msg = 'EOF in either data'
for i in range(0, min(len(buf1), len(buf2))):
c1 = six.indexbytes(six.binary_type(buf1), i)
c2 = six.indexbytes(six.binary_type(buf2), i)
c1 = operator.getitem(bytes(buf1), i)
c2 = operator.getitem(bytes(buf2), i)
if c1 != c2:
msg = 'differs at chr %d, %d != %d' % (i, c1, c2)
break

View File

@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
import unittest
import testscenarios
@ -140,5 +139,5 @@ class Test_Parser_Compat(testscenarios.WithScenarios, unittest.TestCase):
# a parsed object can be inspected by old and new api
check(ofpp.OFPMatch.parser(six.binary_type(new_buf), 0))
check(ofpp.OFPMatch.parser(bytes(new_buf), 0))
check(ofpp.OFPMatch.from_jsondict(list(new_jsondict.values())[0]))

View File

@ -16,7 +16,6 @@
import functools
import itertools
import six
import unittest
import testscenarios
@ -258,7 +257,7 @@ class Test_Parser_OFPMatch(testscenarios.WithScenarios, unittest.TestCase):
match = ofpp.OFPMatch(**d)
b = bytearray()
match.serialize(b, 0)
match2 = match.parser(six.binary_type(b), 0)
match2 = match.parser(bytes(b), 0)
for k, v in d.items():
self.assertTrue(k in match)
self.assertTrue(k in match2)

View File

@ -15,7 +15,6 @@
from functools import reduce
import six
import unittest
import testscenarios
@ -175,7 +174,7 @@ class Test_Parser_OFPStats(testscenarios.WithScenarios, unittest.TestCase):
stats = ofpp.OFPStats(**d)
b = bytearray()
stats.serialize(b, 0)
stats2 = stats.parser(six.binary_type(b), 0)
stats2 = stats.parser(bytes(b), 0)
for k, v in d.items():
self.assertTrue(k in stats)
self.assertTrue(k in stats2)

View File

@ -13,11 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
from os_ken.ofproto.ofproto_v1_0_parser import *
from os_ken.ofproto.nx_actions import *
from os_ken.ofproto import ofproto_v1_0_parser
@ -208,7 +205,7 @@ class TestOFPMatch(unittest.TestCase):
c.serialize(buf, 0)
fmt = ofproto.OFP_MATCH_PACK_STR
res = struct.unpack_from(fmt, six.binary_type(buf))
res = struct.unpack_from(fmt, bytes(buf))
self.assertEqual(self.wildcards['val'], res[0])
self.assertEqual(self.in_port['val'], res[1])
@ -273,7 +270,7 @@ class TestOFPActionHeader(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type['val'], res[0])
self.assertEqual(self.len['val'], res[1])
@ -338,7 +335,7 @@ class TestOFPActionOutput(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -403,7 +400,7 @@ class TestOFPActionVlanVid(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_VLAN_VID_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -466,7 +463,7 @@ class TestOFPActionVlanPcp(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_VLAN_PCP_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -585,7 +582,7 @@ class TestOFPActionSetDlSrc(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_DL_ADDR_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -657,7 +654,7 @@ class TestOFPActionSetDlDst(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_DL_ADDR_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -726,7 +723,7 @@ class TestOFPActionSetNwSrc(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_NW_ADDR_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -795,7 +792,7 @@ class TestOFPActionSetNwDst(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_NW_ADDR_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -858,7 +855,7 @@ class TestOFPActionSetNwTos(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_NW_TOS_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -932,7 +929,7 @@ class TestOFPActionSetTpSrc(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_TP_PORT_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1006,7 +1003,7 @@ class TestOFPActionSetTpDst(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_TP_PORT_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1076,7 +1073,7 @@ class TestOFPActionEnqueue(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_ENQUEUE_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1129,7 +1126,7 @@ class TestNXActionResubmit(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_RESUBMIT_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1185,7 +1182,7 @@ class TestNXActionResubmitTable(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_RESUBMIT_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1238,7 +1235,7 @@ class TestNXActionSetTunnel(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_SET_TUNNEL_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1291,7 +1288,7 @@ class TestNXActionSetQueue(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_SET_QUEUE_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1341,7 +1338,7 @@ class TestNXActionPopQueue(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_POP_QUEUE_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1413,7 +1410,7 @@ class TestNXActionRegMove(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_REG_MOVE_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1482,7 +1479,7 @@ class TestNXActionRegLoad(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_REG_LOAD_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1539,7 +1536,7 @@ class TestNXActionSetTunnel64(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_SET_TUNNEL64_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1628,7 +1625,7 @@ class TestNXActionMultipath(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_MULTIPATH_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1742,7 +1739,7 @@ class TestNXActionBundle(unittest.TestCase):
+ ofproto.NX_ACTION_BUNDLE_PACK_STR.replace('!', '') \
+ 'HH4x'
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1856,7 +1853,7 @@ class TestNXActionBundleLoad(unittest.TestCase):
+ ofproto.NX_ACTION_BUNDLE_PACK_STR.replace('!', '') \
+ 'HH4x'
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1927,7 +1924,7 @@ class TestNXActionOutputReg(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_OUTPUT_REG_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -1979,7 +1976,7 @@ class TestNXActionExit(unittest.TestCase):
self.c.serialize(buf, 0)
fmt = ofproto.NX_ACTION_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(self.type_['val'], res[0])
self.assertEqual(self.len_['val'], res[1])
@ -2600,7 +2597,7 @@ class TestOFPHello(unittest.TestCase):
self.assertEqual(msg_type, res.msg_type)
self.assertEqual(msg_len, res.msg_len)
self.assertEqual(xid, res.xid)
self.assertEqual(six.binary_type(buf), six.binary_type(res.buf))
self.assertEqual(bytes(buf), bytes(res.buf))
def test_serialize(self):
@ -2686,7 +2683,7 @@ class TestOFPErrorMsg(unittest.TestCase):
+ ofproto.OFP_ERROR_MSG_PACK_STR.replace('!', '') \
+ str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_ERROR, res[1])
self.assertEqual(len(c.buf), res[2])
@ -2756,7 +2753,7 @@ class TestOFPEchoRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_ECHO_REQUEST, res[1])
self.assertEqual(len(c.buf), res[2])
@ -2824,7 +2821,7 @@ class TestOFPEchoReply(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_ECHO_REPLY, res[1])
self.assertEqual(len(c.buf), res[2])
@ -2899,7 +2896,7 @@ class TestOFPVendor(unittest.TestCase):
+ ofproto.OFP_VENDOR_HEADER_PACK_STR.replace('!', '') \
+ str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
self.assertEqual(len(c.buf), res[2])
@ -2952,7 +2949,7 @@ class TestNiciraHeader(unittest.TestCase):
+ ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
+ str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
self.assertEqual(len(c.buf), res[2])
@ -3002,7 +2999,7 @@ class TestNXTSetFlowFormat(unittest.TestCase):
+ ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
+ ofproto.NX_SET_FLOW_FORMAT_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
self.assertEqual(len(c.buf), res[2])
@ -3102,7 +3099,7 @@ class TestNXTFlowMod(unittest.TestCase):
+ ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
+ ofproto.NX_FLOW_MOD_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
self.assertEqual(len(c.buf), res[2])
@ -3133,7 +3130,7 @@ class TestNXTFlowMod(unittest.TestCase):
+ ofproto.NX_FLOW_MOD_PACK_STR.replace('!', '') \
+ ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
self.assertEqual(len(c.buf), res[2])
@ -3197,7 +3194,7 @@ class TestNXTRoleRequest(unittest.TestCase):
+ ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
+ ofproto.NX_ROLE_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
@ -3249,7 +3246,7 @@ class TestNXTFlowModTableId(unittest.TestCase):
+ ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
+ ofproto.NX_FLOW_MOD_TABLE_ID_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_VENDOR, res[1])
self.assertEqual(len(self.c.buf), res[2])
@ -4565,7 +4562,7 @@ class TestOFPFeaturesRequest(unittest.TestCase):
fmt = ofproto.OFP_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_FEATURES_REQUEST, res[1])
self.assertEqual(len(self.c.buf), res[2])
@ -4604,7 +4601,7 @@ class TestOFPGetConfigRequest(unittest.TestCase):
fmt = ofproto.OFP_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_GET_CONFIG_REQUEST, res[1])
self.assertEqual(len(self.c.buf), res[2])
@ -4653,7 +4650,7 @@ class TestOFPSetConfig(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_SWITCH_CONFIG_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_SET_CONFIG, res[1])
self.assertEqual(len(self.c.buf), res[2])
@ -4720,7 +4717,7 @@ class TestOFPPacketOut(unittest.TestCase):
+ ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '') \
+ str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -4866,7 +4863,7 @@ class TestOFPFlowMod(unittest.TestCase):
+ ofproto.OFP_FLOW_MOD_PACK_STR0.replace('!', '') \
+ ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -4938,7 +4935,7 @@ class TestOFPBarrierRequest(unittest.TestCase):
fmt = ofproto.OFP_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_BARRIER_REQUEST, res[1])
self.assertEqual(len(self.c.buf), res[2])
@ -4985,7 +4982,7 @@ class TestOFPQueueGetConfigRequest(unittest.TestCase):
b = ofproto.OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR.replace('!', '')
fmt = '!' + a + b
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST, res[1])
self.assertEqual(len(self.c.buf), res[2])
@ -5030,7 +5027,7 @@ class TestOFPDescStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -5132,7 +5129,7 @@ class TestOFPFlowStatsRequest(unittest.TestCase):
+ ofproto.OFP_MATCH_PACK_STR.replace('!', '') \
+ ofproto.OFP_FLOW_STATS_REQUEST_ID_PORT_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -5253,7 +5250,7 @@ class TestOFPAggregateStatsRequest(unittest.TestCase):
+ ofproto.OFP_MATCH_PACK_STR.replace('!', '') \
+ ofproto.OFP_FLOW_STATS_REQUEST_ID_PORT_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -5322,7 +5319,7 @@ class TestOFPTableStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -5380,7 +5377,7 @@ class TestOFPPortStatsRequest(unittest.TestCase):
+ ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
+ ofproto.OFP_PORT_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -5444,7 +5441,7 @@ class TestOFPQueueStatsRequest(unittest.TestCase):
+ ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
+ ofproto.OFP_QUEUE_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])
@ -5511,7 +5508,7 @@ class TestOFPVendorStatsRequest(unittest.TestCase):
+ ofproto.OFP_VENDOR_STATS_MSG_PACK_STR.replace('!', '') \
+ str(len(self.specific_data)) + 's'
res = struct.unpack(fmt, six.binary_type(self.c.buf))
res = struct.unpack(fmt, bytes(self.c.buf))
# OFP_HEADER_PACK_STR
self.assertEqual(ofproto.OFP_VERSION, res[0])

View File

@ -15,7 +15,6 @@
import unittest
import logging
import six
import socket
from struct import *
from os_ken.ofproto.ofproto_v1_2_parser import *
@ -135,7 +134,7 @@ class TestOFPHello(unittest.TestCase):
self.assertEqual(msg_type, res.msg_type)
self.assertEqual(msg_len, res.msg_len)
self.assertEqual(xid, res.xid)
self.assertEqual(six.binary_type(buf), six.binary_type(res.buf))
self.assertEqual(bytes(buf), bytes(res.buf))
def test_parser_xid_min(self):
xid = 0
@ -809,7 +808,7 @@ class TestOFPErrorMsg(unittest.TestCase):
+ ofproto.OFP_ERROR_MSG_PACK_STR.replace('!', '') \
+ str(len(c.data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_ERROR)
@ -1330,7 +1329,7 @@ class TestOFPEchoRequest(unittest.TestCase):
if data is not None:
fmt += str(len(c.data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_ECHO_REQUEST)
@ -1416,7 +1415,7 @@ class TestOFPEchoReply(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ str(len(c.data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_ECHO_REPLY)
@ -1780,7 +1779,7 @@ class TestOFPFeaturesRequest(unittest.TestCase):
fmt = ofproto.OFP_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_FEATURES_REQUEST)
@ -1892,7 +1891,7 @@ class TestOFPGetConfigRequest(unittest.TestCase):
fmt = ofproto.OFP_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_GET_CONFIG_REQUEST)
self.assertEqual(res[2], len(c.buf))
@ -1998,7 +1997,7 @@ class TestOFPSetConfig(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_SWITCH_CONFIG_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_SET_CONFIG)
@ -2081,7 +2080,7 @@ class TestOFPPacketIn(unittest.TestCase):
buf_match = bytearray()
match = OFPMatch()
match.serialize(buf_match, 0)
buf += six.binary_type(buf_match)
buf += bytes(buf_match)
# data
buf += b'\x00' * 2
@ -2191,7 +2190,7 @@ class TestOFPFlowRemoved(unittest.TestCase):
buf_match = bytearray()
match.serialize(buf_match, 0)
buf += six.binary_type(buf_match)
buf += bytes(buf_match)
res = OFPFlowRemoved.parser(object, version, msg_type,
msg_len, xid, buf)
@ -2483,7 +2482,7 @@ class TestOFPPacketOut(unittest.TestCase):
if data is not None:
fmt += str(len(data)) + 's'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_PACKET_OUT)
@ -2612,7 +2611,7 @@ class TestOFPFlowMod(unittest.TestCase):
+ MTEthType.pack_str[1:] + '6x' \
+ ofproto.OFP_INSTRUCTION_GOTO_TABLE_PACK_STR[1:] * inst_cnt
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_FLOW_MOD)
@ -2810,7 +2809,7 @@ class TestOFPInstructionGotoTable(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], table_id)
@ -2883,7 +2882,7 @@ class TestOFPInstructionWriteMetadata(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], metadata)
@ -2928,7 +2927,7 @@ class TestOFPInstructionActions(unittest.TestCase):
buf_actions = bytearray()
actions[0].serialize(buf_actions, 0)
buf += six.binary_type(buf_actions)
buf += bytes(buf_actions)
def test_init(self):
c = OFPInstructionActions(self.type_, self.actions)
@ -2953,7 +2952,7 @@ class TestOFPInstructionActions(unittest.TestCase):
actions.append(action)
buf_actions = bytearray()
actions[a].serialize(buf_actions, 0)
buf += six.binary_type(buf_actions)
buf += bytes(buf_actions)
res = OFPInstructionActions.parser(buf, 0)
@ -3001,7 +3000,7 @@ class TestOFPInstructionActions(unittest.TestCase):
for a in range(action_cnt):
fmt += ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], len_)
@ -3054,7 +3053,7 @@ class TestOFPActionHeader(unittest.TestCase):
c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(res[0], type_)
self.assertEqual(res[1], len_)
@ -3132,7 +3131,7 @@ class TestOFPActionOutput(unittest.TestCase):
c.serialize(buf, 0)
fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], port)
@ -3198,7 +3197,7 @@ class TestOFPActionGroup(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], group_id)
@ -3252,7 +3251,7 @@ class TestOFPActionSetQueue(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], queue_id)
@ -3306,7 +3305,7 @@ class TestOFPActionSetMplsTtl(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], mpls_ttl)
@ -3341,7 +3340,7 @@ class TestOFPActionDecMplsTtl(unittest.TestCase):
buf = bytearray()
self.c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
@ -3385,7 +3384,7 @@ class TestOFPActionSetNwTtl(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], nw_ttl)
@ -3420,7 +3419,7 @@ class TestOFPActionDecNwTtl(unittest.TestCase):
buf = bytearray()
self.c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
@ -3444,7 +3443,7 @@ class TestOFPActionCopyTtlOut(unittest.TestCase):
buf = bytearray()
self.c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
@ -3471,7 +3470,7 @@ class TestOFPActionCopyTtlIn(unittest.TestCase):
buf = bytearray()
self.c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
@ -3513,7 +3512,7 @@ class TestOFPActionPushVlan(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], ethertype)
@ -3565,7 +3564,7 @@ class TestOFPActionPushMpls(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], ethertype)
@ -3601,7 +3600,7 @@ class TestOFPActionPopVlan(unittest.TestCase):
buf = bytearray()
self.c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
@ -3643,7 +3642,7 @@ class TestOFPActionPopMpls(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], ethertype)
@ -3690,7 +3689,7 @@ class TestOFPActionSetField(unittest.TestCase):
buf = bytearray()
self.c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
@ -3739,7 +3738,7 @@ class TestOFPActionExperimenter(unittest.TestCase):
buf = bytearray()
c.serialize(buf, 0)
res = struct.unpack(self.fmt, six.binary_type(buf))
res = struct.unpack(self.fmt, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.len_)
self.assertEqual(res[2], experimenter)
@ -3799,7 +3798,7 @@ class TestOFPBucket(unittest.TestCase):
actions.append(action)
buf_actions = bytearray()
actions[a].serialize(buf_actions, 0)
buf += six.binary_type(buf_actions)
buf += bytes(buf_actions)
res = OFPBucket.parser(buf, 0)
@ -3863,7 +3862,7 @@ class TestOFPBucket(unittest.TestCase):
fmt = ofproto.OFP_BUCKET_PACK_STR
for a in range(action_cnt):
fmt += ofproto.OFP_ACTION_OUTPUT_PACK_STR[1:]
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(res[0], len_)
self.assertEqual(res[1], weight)
@ -3965,7 +3964,7 @@ class TestOFPGroupMod(unittest.TestCase):
fmt += ofproto.OFP_BUCKET_PACK_STR[1:] \
+ ofproto.OFP_ACTION_OUTPUT_PACK_STR[1:]
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
msg_len = ofproto.OFP_GROUP_MOD_SIZE \
+ (len_ * bucket_cnt)
@ -4066,7 +4065,7 @@ class TestOFPPortMod(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_PORT_MOD_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_PORT_MOD)
@ -4253,7 +4252,7 @@ class TestOFPTableMod(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_TABLE_MOD_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_TABLE_MOD)
@ -4309,7 +4308,7 @@ class TestOFPStatsRequest(unittest.TestCase):
self.c._serialize_body()
fmt = ofproto.OFP_STATS_REQUEST_PACK_STR
res = struct.unpack_from(fmt, six.binary_type(self.c.buf),
res = struct.unpack_from(fmt, bytes(self.c.buf),
ofproto.OFP_HEADER_SIZE)
self.assertEqual(res[0], self.type_)
@ -4476,7 +4475,7 @@ class TestOFPDescStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -4572,7 +4571,7 @@ class TestOFPFlowStatsRequest(unittest.TestCase):
+ 'HHHBB' \
+ MTEthType.pack_str[1:] + '6x'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -4683,7 +4682,7 @@ class TestOFPFlowStats(unittest.TestCase):
match.set_dl_type(dl_type)
match_buf = bytearray()
match.serialize(match_buf, 0)
buf += six.binary_type(match_buf)
buf += bytes(match_buf)
# instructions
# 56 + 8 + 8 * inst_cnt <= 65535
@ -4692,7 +4691,7 @@ class TestOFPFlowStats(unittest.TestCase):
inst = OFPInstructionGotoTable(1)
inst_buf = bytearray()
inst.serialize(inst_buf, 0)
buf += six.binary_type(inst_buf)
buf += bytes(inst_buf)
# parse
res = OFPFlowStats.parser(buf, 0)
@ -4795,7 +4794,7 @@ class TestOFPAggregateStatsRequest(unittest.TestCase):
+ 'HHHBB' \
+ MTEthType.pack_str[1:] + '6x'
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
self.assertEqual(res[2], len(c.buf))
@ -4902,7 +4901,7 @@ class TestOFPTableStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -5295,7 +5294,7 @@ class TestOFPPortStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '') \
+ ofproto.OFP_PORT_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -5532,7 +5531,7 @@ class TestOFPQueueStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '') \
+ ofproto.OFP_QUEUE_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -5735,7 +5734,7 @@ class TestOFPGroupStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '') \
+ ofproto.OFP_GROUP_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -5873,7 +5872,7 @@ class TestOFPGroupDescStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -5935,7 +5934,7 @@ class TestOFPGroupDescStats(unittest.TestCase):
buckets.append(bucket)
buf_buckets = bytearray()
buckets[b].serialize(buf_buckets, 0)
buf += six.binary_type(buf_buckets)
buf += bytes(buf_buckets)
res = OFPGroupDescStats.parser(buf, 0)
@ -5994,7 +5993,7 @@ class TestOFPGroupFeaturesStatsRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_STATS_REQUEST)
@ -6131,7 +6130,7 @@ class TestOFPQueueGetConfigRequest(unittest.TestCase):
fmt = ofproto.OFP_HEADER_PACK_STR \
+ ofproto.OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR[1:]
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(res[0], ofproto.OFP_VERSION)
self.assertEqual(res[1], ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST)
self.assertEqual(res[2], len(c.buf))
@ -6170,7 +6169,7 @@ class TestOFPQueuePropHeader(unittest.TestCase):
c.serialize(buf, 0)
fmt = ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR
res = struct.unpack(fmt, six.binary_type(buf))
res = struct.unpack(fmt, bytes(buf))
self.assertEqual(res[0], property_)
self.assertEqual(res[1], len_)
@ -6396,7 +6395,7 @@ class TestOFPBarrierRequest(unittest.TestCase):
self.assertEqual(0, c.xid)
fmt = ofproto.OFP_HEADER_PACK_STR
res = unpack(fmt, six.binary_type(c.buf))
res = unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_BARRIER_REQUEST, res[1])
self.assertEqual(len(c.buf), res[2])
@ -6458,7 +6457,7 @@ class TestOFPRoleRequest(unittest.TestCase):
+ ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
+ ofproto.OFP_ROLE_REQUEST_PACK_STR.replace('!', '')
res = struct.unpack(fmt, six.binary_type(c.buf))
res = struct.unpack(fmt, bytes(c.buf))
self.assertEqual(ofproto.OFP_VERSION, res[0])
self.assertEqual(ofproto.OFPT_ROLE_REQUEST, res[1])
@ -6630,7 +6629,7 @@ class TestOFPMatch(unittest.TestCase):
if mask and len(buf) > calcsize(fmt):
fmt += pack_str
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
res = list(unpack_from(fmt, bytes(buf), 0)[3:])
if type(value) is list:
res_value = res[:calcsize(pack_str) // 2]
self.assertEqual(res_value, value)
@ -6648,7 +6647,7 @@ class TestOFPMatch(unittest.TestCase):
self.assertEqual(res_mask, mask)
# parser
res = match.parser(six.binary_type(buf), 0)
res = match.parser(bytes(buf), 0)
self.assertEqual(res.type, ofproto.OFPMT_OXM)
self.assertEqual(res.fields[0].header, header)
self.assertEqual(res.fields[0].value, value)
@ -6674,7 +6673,7 @@ class TestOFPMatch(unittest.TestCase):
pack_utils.msg_pack_into('!IH', buf, 10, header, 1)
match = OFPMatch()
res = match.parser(six.binary_type(buf), 0)
res = match.parser(bytes(buf), 0)
# set_in_port
def _test_set_in_port(self, in_port):
@ -6860,12 +6859,12 @@ class TestOFPMatch(unittest.TestCase):
length = match.serialize(buf, 0)
self.assertEqual(length, len(buf))
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
res = list(unpack_from(fmt, bytes(buf), 0)[3:])
res_value = res.pop(0)
self.assertEqual(res_value, value)
# parser
res = match.parser(six.binary_type(buf), 0)
res = match.parser(bytes(buf), 0)
self.assertEqual(res.type, ofproto.OFPMT_OXM)
self.assertEqual(res.fields[0].header, header)
self.assertEqual(res.fields[0].value, value)

View File

@ -13,11 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import socket
from struct import *
from os_ken.ofproto.ofproto_v1_3_parser import *
@ -56,7 +53,7 @@ class TestOFPMatch(unittest.TestCase):
if mask and len(buf) > calcsize(fmt):
fmt += pack_str
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
res = list(unpack_from(fmt, bytes(buf), 0)[3:])
if type(value) is list:
res_value = res[:calcsize(pack_str) // 2]
self.assertEqual(res_value, value)
@ -74,7 +71,7 @@ class TestOFPMatch(unittest.TestCase):
self.assertEqual(res_mask, mask)
# parser
res = match.parser(six.binary_type(buf), 0)
res = match.parser(bytes(buf), 0)
self.assertEqual(res.type, ofproto.OFPMT_OXM)
self.assertEqual(res.fields[0].header, header)
self.assertEqual(res.fields[0].value, value)
@ -116,12 +113,12 @@ class TestOFPMatch(unittest.TestCase):
length = match.serialize(buf, 0)
self.assertEqual(length, len(buf))
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
res = list(unpack_from(fmt, bytes(buf), 0)[3:])
res_value = res.pop(0)
self.assertEqual(res_value, value)
# parser
res = match.parser(six.binary_type(buf), 0)
res = match.parser(bytes(buf), 0)
self.assertEqual(res.type, ofproto.OFPMT_OXM)
self.assertEqual(res.fields[0].header, header)
self.assertEqual(res.fields[0].value, value)

View File

@ -17,7 +17,6 @@
import unittest
import logging
import inspect
import six
import struct
from os_ken.lib import addrconv
@ -227,7 +226,7 @@ class Test_cfm(unittest.TestCase):
self.test_init()
def test_parser(self):
_res = self.ins.parser(six.binary_type(self.buf))
_res = self.ins.parser(bytes(self.buf))
if type(_res) is tuple:
res = _res[0]
@ -264,7 +263,7 @@ class Test_cfm(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ins.serialize(data, prev)
cc_message = cfm.cc_message.parser(six.binary_type(buf))
cc_message = cfm.cc_message.parser(bytes(buf))
self.assertEqual(repr(self.message), repr(cc_message))
def test_serialize_with_loopback_message(self):
@ -273,7 +272,7 @@ class Test_cfm(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ins.serialize(data, prev)
loopback_message = cfm.loopback_message.parser(six.binary_type(buf))
loopback_message = cfm.loopback_message.parser(bytes(buf))
self.assertEqual(repr(self.message), repr(loopback_message))
def test_serialize_with_loopback_reply(self):
@ -282,7 +281,7 @@ class Test_cfm(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ins.serialize(data, prev)
loopback_reply = cfm.loopback_reply.parser(six.binary_type(buf))
loopback_reply = cfm.loopback_reply.parser(bytes(buf))
self.assertEqual(repr(self.message), repr(loopback_reply))
def test_serialize_with_link_trace_message(self):
@ -291,7 +290,7 @@ class Test_cfm(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ins.serialize(data, prev)
link_trace_message = cfm.link_trace_message.parser(six.binary_type(buf))
link_trace_message = cfm.link_trace_message.parser(bytes(buf))
self.assertEqual(repr(self.message), repr(link_trace_message))
def test_serialize_with_link_trace_reply(self):
@ -300,7 +299,7 @@ class Test_cfm(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ins.serialize(data, prev)
link_trace_reply = cfm.link_trace_reply.parser(six.binary_type(buf))
link_trace_reply = cfm.link_trace_reply.parser(bytes(buf))
self.assertEqual(repr(self.message), repr(link_trace_reply))
def test_to_string(self):
@ -511,7 +510,7 @@ class Test_cc_message(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -545,7 +544,7 @@ class Test_cc_message(unittest.TestCase):
self.tlvs
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -580,7 +579,7 @@ class Test_cc_message(unittest.TestCase):
self.tlvs
)
buf = ins.serialize()
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -602,7 +601,7 @@ class Test_cc_message(unittest.TestCase):
def test_default_args(self):
ins = cfm.cc_message()
buf = ins.serialize()
res = struct.unpack_from(cfm.cc_message._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.cc_message._PACK_STR, bytes(buf))
self.assertEqual(res[0] >> 5, 0)
self.assertEqual(res[0] & 0x1f, 0)
self.assertEqual(res[1], 1)
@ -666,7 +665,7 @@ class Test_loopback_message(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -683,7 +682,7 @@ class Test_loopback_message(unittest.TestCase):
ins = cfm.loopback_message()
buf = ins.serialize()
res = struct.unpack_from(cfm.loopback_message._PACK_STR,
six.binary_type(buf))
bytes(buf))
self.assertEqual(res[0] >> 5, 0)
self.assertEqual(res[0] & 0x1f, 0)
self.assertEqual(res[1], 3)
@ -743,7 +742,7 @@ class Test_loopback_reply(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -759,7 +758,7 @@ class Test_loopback_reply(unittest.TestCase):
def test_default_args(self):
ins = cfm.loopback_reply()
buf = ins.serialize()
res = struct.unpack_from(cfm.loopback_reply._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.loopback_reply._PACK_STR, bytes(buf))
self.assertEqual(res[0] >> 5, 0)
self.assertEqual(res[0] & 0x1f, 0)
self.assertEqual(res[1], 2)
@ -838,7 +837,7 @@ class Test_link_trace_message(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -857,7 +856,7 @@ class Test_link_trace_message(unittest.TestCase):
def test_default_args(self):
ins = cfm.link_trace_message()
buf = ins.serialize()
res = struct.unpack_from(cfm.link_trace_message._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.link_trace_message._PACK_STR, bytes(buf))
self.assertEqual(res[0] >> 5, 0)
self.assertEqual(res[0] & 0x1f, 0)
self.assertEqual(res[1], 5)
@ -944,7 +943,7 @@ class Test_link_trace_reply(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.md_lv, res[0] >> 5)
self.assertEqual(self.version, res[0] & 0x1f)
self.assertEqual(self.opcode, res[1])
@ -964,7 +963,7 @@ class Test_link_trace_reply(unittest.TestCase):
def test_default_args(self):
ins = cfm.link_trace_reply()
buf = ins.serialize()
res = struct.unpack_from(cfm.link_trace_reply._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.link_trace_reply._PACK_STR, bytes(buf))
self.assertEqual(res[0] >> 5, 0)
self.assertEqual(res[0] & 0x1f, 0)
self.assertEqual(res[1], 4)
@ -1043,7 +1042,7 @@ class Test_sender_id_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.chassis_id_length, res[2])
@ -1062,7 +1061,7 @@ class Test_sender_id_tlv(unittest.TestCase):
)
buf = ins.serialize()
form = '!BHBB1sB2sB'
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(7, res[1])
self.assertEqual(self.chassis_id_length, res[2])
@ -1079,7 +1078,7 @@ class Test_sender_id_tlv(unittest.TestCase):
)
buf = ins.serialize()
form = '!BHBB2sB3s'
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(8, res[1])
self.assertEqual(0, res[2])
@ -1095,7 +1094,7 @@ class Test_sender_id_tlv(unittest.TestCase):
)
buf = ins.serialize()
form = '!BHBB1sB'
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(4, res[1])
self.assertEqual(self.chassis_id_length, res[2])
@ -1109,7 +1108,7 @@ class Test_sender_id_tlv(unittest.TestCase):
)
buf = ins.serialize()
form = '!BHBB2sB'
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(5, res[1])
self.assertEqual(0, res[2])
@ -1129,7 +1128,7 @@ class Test_sender_id_tlv(unittest.TestCase):
self.ma,
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.chassis_id_length, res[2])
@ -1147,7 +1146,7 @@ class Test_sender_id_tlv(unittest.TestCase):
def test_default_args(self):
ins = cfm.sender_id_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.sender_id_tlv._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.sender_id_tlv._PACK_STR, bytes(buf))
self.assertEqual(res[0], cfm.CFM_SENDER_ID_TLV)
self.assertEqual(res[1], 1)
self.assertEqual(res[2], 0)
@ -1189,7 +1188,7 @@ class Test_port_status_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.port_status, res[2])
@ -1201,7 +1200,7 @@ class Test_port_status_tlv(unittest.TestCase):
def test_default_args(self):
ins = cfm.port_status_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.port_status_tlv._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.port_status_tlv._PACK_STR, bytes(buf))
self.assertEqual(res[0], cfm.CFM_PORT_STATUS_TLV)
self.assertEqual(res[1], 1)
self.assertEqual(res[2], 2)
@ -1243,7 +1242,7 @@ class Test_data_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.data_value, res[2])
@ -1254,7 +1253,7 @@ class Test_data_tlv(unittest.TestCase):
self.data_value
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.data_value, res[2])
@ -1266,7 +1265,7 @@ class Test_data_tlv(unittest.TestCase):
def test_default_args(self):
ins = cfm.data_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.data_tlv._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.data_tlv._PACK_STR, bytes(buf))
self.assertEqual(res[0], cfm.CFM_DATA_TLV)
self.assertEqual(res[1], 0)
@ -1307,7 +1306,7 @@ class Test_interface_status_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.interface_status, res[2])
@ -1319,7 +1318,7 @@ class Test_interface_status_tlv(unittest.TestCase):
def test_default_args(self):
ins = cfm.interface_status_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.interface_status_tlv._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.interface_status_tlv._PACK_STR, bytes(buf))
self.assertEqual(res[0], cfm.CFM_INTERFACE_STATUS_TLV)
self.assertEqual(res[1], 1)
self.assertEqual(res[2], 1)
@ -1366,7 +1365,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.egress_id_ui, res[2])
@ -1379,7 +1378,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase):
self.egress_id_mac
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.egress_id_ui, res[2])
@ -1393,7 +1392,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase):
ins = cfm.ltm_egress_identifier_tlv()
buf = ins.serialize()
res = struct.unpack_from(
cfm.ltm_egress_identifier_tlv._PACK_STR, six.binary_type(buf))
cfm.ltm_egress_identifier_tlv._PACK_STR, bytes(buf))
self.assertEqual(res[0], cfm.CFM_LTM_EGRESS_IDENTIFIER_TLV)
self.assertEqual(res[1], 8)
self.assertEqual(res[2], 0)
@ -1449,7 +1448,7 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.last_egress_id_ui, res[2])
@ -1465,7 +1464,7 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase):
self.next_egress_id_mac
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.last_egress_id_ui, res[2])
@ -1481,7 +1480,7 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase):
ins = cfm.ltr_egress_identifier_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.ltr_egress_identifier_tlv._PACK_STR,
six.binary_type(buf))
bytes(buf))
self.assertEqual(res[0], cfm.CFM_LTR_EGRESS_IDENTIFIER_TLV)
self.assertEqual(res[1], 16)
self.assertEqual(res[2], 0)
@ -1534,7 +1533,7 @@ class Test_organization_specific_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.oui, res[2])
@ -1548,7 +1547,7 @@ class Test_organization_specific_tlv(unittest.TestCase):
self.value
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.oui, res[2])
@ -1563,7 +1562,7 @@ class Test_organization_specific_tlv(unittest.TestCase):
ins = cfm.organization_specific_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.organization_specific_tlv._PACK_STR,
six.binary_type(buf))
bytes(buf))
self.assertEqual(res[0], cfm.CFM_ORGANIZATION_SPECIFIC_TLV)
self.assertEqual(res[1], 4)
self.assertEqual(res[2], b"\x00\x00\x00")
@ -1623,7 +1622,7 @@ class Test_reply_ingress_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.action, res[2])
@ -1641,7 +1640,7 @@ class Test_reply_ingress_tlv(unittest.TestCase):
self.port_id
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.action, res[2])
@ -1657,7 +1656,7 @@ class Test_reply_ingress_tlv(unittest.TestCase):
def test_default_args(self):
ins = cfm.reply_ingress_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.reply_ingress_tlv._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(cfm.reply_ingress_tlv._PACK_STR, bytes(buf))
self.assertEqual(res[0], cfm.CFM_REPLY_INGRESS_TLV)
self.assertEqual(res[1], 7)
self.assertEqual(res[2], 1)
@ -1718,7 +1717,7 @@ class Test_reply_egress_tlv(unittest.TestCase):
def test_serialize(self):
buf = self.ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.action, res[2])
@ -1736,7 +1735,7 @@ class Test_reply_egress_tlv(unittest.TestCase):
self.port_id
)
buf = ins.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self._type, res[0])
self.assertEqual(self.length, res[1])
self.assertEqual(self.action, res[2])
@ -1753,7 +1752,7 @@ class Test_reply_egress_tlv(unittest.TestCase):
ins = cfm.reply_egress_tlv()
buf = ins.serialize()
res = struct.unpack_from(cfm.reply_egress_tlv._PACK_STR,
six.binary_type(buf))
bytes(buf))
self.assertEqual(res[0], cfm.CFM_REPLY_EGRESS_TLV)
self.assertEqual(res[1], 7)
self.assertEqual(res[2], 1)

View File

@ -19,8 +19,6 @@ import logging
import struct
import unittest
import six
from os_ken.lib import addrconv
from os_ken.lib.packet import dhcp
@ -136,7 +134,7 @@ class Test_dhcp_offer(unittest.TestCase):
self.assertTrue(isinstance(pkt.options, dhcp.options))
for opt in pkt.options.option_list[:-1]:
self.assertTrue(isinstance(opt, dhcp.option))
self.assertTrue(isinstance(pkt.options.option_list[-1], six.binary_type))
self.assertTrue(isinstance(pkt.options.option_list[-1], bytes))
buf = pkt.serialize()
self.assertEqual(str(buf), str(corrupt_buf))
@ -146,7 +144,7 @@ class Test_dhcp_offer(unittest.TestCase):
buf = self.dh.serialize()
res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR,
six.binary_type(buf))
bytes(buf))
self.assertEqual(self.op, res[0])
self.assertEqual(self.htype, res[1])

View File

@ -13,17 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import struct
import netaddr
from struct import *
from os_ken.ofproto import ether, inet
from os_ken.lib.packet.ethernet import ethernet
from os_ken.lib.packet.packet import Packet
from os_ken.lib.packet.arp import arp
from os_ken.lib import addrconv
@ -89,7 +84,7 @@ class Test_ethernet(unittest.TestCase):
def test_default_args(self):
e = ethernet()
buf = e.serialize(bytearray(), None)
res = struct.unpack(e._PACK_STR, six.binary_type(buf))
res = struct.unpack(e._PACK_STR, bytes(buf))
self.assertEqual(res[0], addrconv.mac.text_to_bin('ff:ff:ff:ff:ff:ff'))
self.assertEqual(res[1], addrconv.mac.text_to_bin('00:00:00:00:00:00'))

View File

@ -16,7 +16,6 @@
import inspect
import logging
import six
import struct
import unittest
@ -128,7 +127,7 @@ class Test_icmp(unittest.TestCase):
self.test_init()
def test_parser(self):
_res = icmp.icmp.parser(six.binary_type(self.buf))
_res = icmp.icmp.parser(bytes(self.buf))
if type(_res) is tuple:
res = _res[0]
else:
@ -156,7 +155,7 @@ class Test_icmp(unittest.TestCase):
prev = None
buf = self.ic.serialize(data, prev)
res = struct.unpack_from(icmp.icmp._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(icmp.icmp._PACK_STR, bytes(buf))
self.assertEqual(self.type_, res[0])
self.assertEqual(self.code, res[1])
@ -169,7 +168,7 @@ class Test_icmp(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ic.serialize(data, prev)
echo = icmp.echo.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
echo = icmp.echo.parser(bytes(buf), icmp.icmp._MIN_LEN)
self.assertEqual(repr(self.data), repr(echo))
def test_serialize_with_dest_unreach(self):
@ -179,7 +178,7 @@ class Test_icmp(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ic.serialize(data, prev)
unreach = icmp.dest_unreach.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
unreach = icmp.dest_unreach.parser(bytes(buf), icmp.icmp._MIN_LEN)
self.assertEqual(repr(self.data), repr(unreach))
def test_serialize_with_TimeExceeded(self):
@ -189,7 +188,7 @@ class Test_icmp(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ic.serialize(data, prev)
te = icmp.TimeExceeded.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
te = icmp.TimeExceeded.parser(bytes(buf), icmp.icmp._MIN_LEN)
self.assertEqual(repr(self.data), repr(te))
def test_to_string(self):
@ -220,7 +219,7 @@ class Test_icmp(unittest.TestCase):
def test_default_args(self):
ic = icmp.icmp()
buf = ic.serialize(bytearray(), None)
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmp.icmp._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], 8)
self.assertEqual(res[1], 0)
@ -229,7 +228,7 @@ class Test_icmp(unittest.TestCase):
# with data
ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach())
buf = ic.serialize(bytearray(), None)
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmp.icmp._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], 3)
self.assertEqual(res[1], 0)
@ -286,7 +285,7 @@ class Test_echo(unittest.TestCase):
def test_serialize(self):
buf = self.echo.serialize()
res = struct.unpack_from('!HH', six.binary_type(buf))
res = struct.unpack_from('!HH', bytes(buf))
self.assertEqual(self.id_, res[0])
self.assertEqual(self.seq, res[1])
self.assertEqual(self.data, buf[struct.calcsize('!HH'):])
@ -294,7 +293,7 @@ class Test_echo(unittest.TestCase):
def test_default_args(self):
ec = icmp.echo()
buf = ec.serialize()
res = struct.unpack(icmp.echo._PACK_STR, six.binary_type(buf))
res = struct.unpack(icmp.echo._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -328,7 +327,7 @@ class Test_dest_unreach(unittest.TestCase):
def test_serialize(self):
buf = self.dest_unreach.serialize()
res = struct.unpack_from('!xBH', six.binary_type(buf))
res = struct.unpack_from('!xBH', bytes(buf))
self.assertEqual(self.data_len, res[0])
self.assertEqual(self.mtu, res[1])
self.assertEqual(self.data, buf[struct.calcsize('!xBH'):])
@ -336,7 +335,7 @@ class Test_dest_unreach(unittest.TestCase):
def test_default_args(self):
du = icmp.dest_unreach()
buf = du.serialize()
res = struct.unpack(icmp.dest_unreach._PACK_STR, six.binary_type(buf))
res = struct.unpack(icmp.dest_unreach._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -367,13 +366,13 @@ class Test_TimeExceeded(unittest.TestCase):
def test_serialize(self):
buf = self.te.serialize()
res = struct.unpack_from('!xBxx', six.binary_type(buf))
res = struct.unpack_from('!xBxx', bytes(buf))
self.assertEqual(self.data_len, res[0])
self.assertEqual(self.data, buf[struct.calcsize('!xBxx'):])
def test_default_args(self):
te = icmp.TimeExceeded()
buf = te.serialize()
res = struct.unpack(icmp.TimeExceeded._PACK_STR, six.binary_type(buf))
res = struct.unpack(icmp.TimeExceeded._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)

View File

@ -13,17 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import struct
import inspect
from os_ken.ofproto import ether, inet
from os_ken.lib.packet.ethernet import ethernet
from os_ken.lib.packet.packet import Packet
from os_ken.lib.packet import icmpv6
from os_ken.lib.packet.ipv6 import ipv6
from os_ken.lib.packet import packet_utils
@ -77,7 +74,7 @@ class Test_icmpv6_header(unittest.TestCase):
prev = ipv6(6, 0, 0, 4, 58, 255, src_ipv6, dst_ipv6)
buf = self.icmp.serialize(bytearray(), prev)
(type_, code, csum) = struct.unpack(self.icmp._PACK_STR, six.binary_type(buf))
(type_, code, csum) = struct.unpack(self.icmp._PACK_STR, bytes(buf))
self.assertEqual(type_, self.type_)
self.assertEqual(code, self.code)
@ -92,7 +89,7 @@ class Test_icmpv6_header(unittest.TestCase):
ic = icmpv6.icmpv6()
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -152,7 +149,7 @@ class Test_icmpv6_echo_request(unittest.TestCase):
echo = icmpv6.echo(self.id_, self.seq, echo_data)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, echo)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
(id_, seq) = struct.unpack_from(echo._PACK_STR, buf, icmp._MIN_LEN)
@ -202,13 +199,13 @@ class Test_icmpv6_echo_request(unittest.TestCase):
type_=icmpv6.ICMPV6_ECHO_REQUEST, data=icmpv6.echo())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ICMPV6_ECHO_REQUEST)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.echo._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.echo._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -233,13 +230,13 @@ class Test_icmpv6_echo_reply(Test_icmpv6_echo_request):
type_=icmpv6.ICMPV6_ECHO_REPLY, data=icmpv6.echo())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ICMPV6_ECHO_REPLY)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.echo._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.echo._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -302,7 +299,7 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase):
nd_csum = icmpv6_csum(prev, self.buf)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, nd)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
(res, dst) = struct.unpack_from(nd._PACK_STR, buf, icmp._MIN_LEN)
@ -322,7 +319,7 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase):
nd_csum = icmpv6_csum(prev, self.buf + self.data)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, nd)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
(res, dst) = struct.unpack_from(nd._PACK_STR, buf, icmp._MIN_LEN)
@ -378,13 +375,13 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase):
type_=icmpv6.ND_NEIGHBOR_SOLICIT, data=icmpv6.nd_neighbor())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_NEIGHBOR_SOLICIT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
@ -397,20 +394,20 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase):
option=icmpv6.nd_option_sla()))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_NEIGHBOR_SOLICIT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR,
six.binary_type(buf[4:24]))
bytes(buf[4:24]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR,
six.binary_type(buf[24:]))
bytes(buf[24:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_SLA)
self.assertEqual(res[1], len(icmpv6.nd_option_sla()) // 8)
@ -447,7 +444,7 @@ class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solicit):
nd_csum = icmpv6_csum(prev, self.buf + self.data)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, nd)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
(res, dst) = struct.unpack_from(nd._PACK_STR, buf, icmp._MIN_LEN)
@ -503,13 +500,13 @@ class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solicit):
type_=icmpv6.ND_NEIGHBOR_ADVERT, data=icmpv6.nd_neighbor())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_NEIGHBOR_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
@ -522,20 +519,20 @@ class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solicit):
option=icmpv6.nd_option_tla()))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_NEIGHBOR_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR,
six.binary_type(buf[4:24]))
bytes(buf[4:24]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
res = struct.unpack(icmpv6.nd_option_tla._PACK_STR,
six.binary_type(buf[24:]))
bytes(buf[24:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_TLA)
self.assertEqual(res[1], len(icmpv6.nd_option_tla()) // 8)
@ -594,7 +591,7 @@ class Test_icmpv6_router_solicit(unittest.TestCase):
rs_csum = icmpv6_csum(prev, self.buf)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, rs)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
res = struct.unpack_from(rs._PACK_STR, buf, icmp._MIN_LEN)
@ -613,7 +610,7 @@ class Test_icmpv6_router_solicit(unittest.TestCase):
rs_csum = icmpv6_csum(prev, self.buf + self.data)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, rs)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
res = struct.unpack_from(rs._PACK_STR, buf, icmp._MIN_LEN)
@ -667,14 +664,14 @@ class Test_icmpv6_router_solicit(unittest.TestCase):
type_=icmpv6.ND_ROUTER_SOLICIT, data=icmpv6.nd_router_solicit())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_SOLICIT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR,
six.binary_type(buf[4:]))
bytes(buf[4:]))
self.assertEqual(res[0], 0)
@ -686,19 +683,19 @@ class Test_icmpv6_router_solicit(unittest.TestCase):
option=icmpv6.nd_option_sla()))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_SOLICIT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR,
six.binary_type(buf[4:8]))
bytes(buf[4:8]))
self.assertEqual(res[0], 0)
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR,
six.binary_type(buf[8:]))
bytes(buf[8:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_SLA)
self.assertEqual(res[1], len(icmpv6.nd_option_sla()) // 8)
@ -727,14 +724,14 @@ class Test_icmpv6_router_advert(unittest.TestCase):
type_=icmpv6.ND_ROUTER_ADVERT, data=icmpv6.nd_router_advert())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_advert._PACK_STR,
six.binary_type(buf[4:]))
bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -750,14 +747,14 @@ class Test_icmpv6_router_advert(unittest.TestCase):
options=[icmpv6.nd_option_sla()]))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_advert._PACK_STR,
six.binary_type(buf[4:16]))
bytes(buf[4:16]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -766,7 +763,7 @@ class Test_icmpv6_router_advert(unittest.TestCase):
self.assertEqual(res[4], 0)
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR,
six.binary_type(buf[16:]))
bytes(buf[16:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_SLA)
self.assertEqual(res[1], len(icmpv6.nd_option_sla()) // 8)
@ -780,14 +777,14 @@ class Test_icmpv6_router_advert(unittest.TestCase):
options=[icmpv6.nd_option_pi()]))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_advert._PACK_STR,
six.binary_type(buf[4:16]))
bytes(buf[4:16]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -796,7 +793,7 @@ class Test_icmpv6_router_advert(unittest.TestCase):
self.assertEqual(res[4], 0)
res = struct.unpack(icmpv6.nd_option_pi._PACK_STR,
six.binary_type(buf[16:]))
bytes(buf[16:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_PI)
self.assertEqual(res[1], 4)
@ -815,14 +812,14 @@ class Test_icmpv6_router_advert(unittest.TestCase):
options=[icmpv6.nd_option_sla(), icmpv6.nd_option_pi()]))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_advert._PACK_STR,
six.binary_type(buf[4:16]))
bytes(buf[4:16]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -831,14 +828,14 @@ class Test_icmpv6_router_advert(unittest.TestCase):
self.assertEqual(res[4], 0)
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR,
six.binary_type(buf[16:24]))
bytes(buf[16:24]))
self.assertEqual(res[0], icmpv6.ND_OPTION_SLA)
self.assertEqual(res[1], len(icmpv6.nd_option_sla()) // 8)
self.assertEqual(res[2], addrconv.mac.text_to_bin('00:00:00:00:00:00'))
res = struct.unpack(icmpv6.nd_option_pi._PACK_STR,
six.binary_type(buf[24:]))
bytes(buf[24:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_PI)
self.assertEqual(res[1], len(icmpv6.nd_option_pi()) // 8)
@ -870,7 +867,7 @@ class Test_icmpv6_nd_option_la(unittest.TestCase):
def test_default_args(self):
la = icmpv6.nd_option_sla()
buf = la.serialize()
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, six.binary_type(buf))
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, bytes(buf))
self.assertEqual(res[0], icmpv6.ND_OPTION_SLA)
self.assertEqual(res[1], len(icmpv6.nd_option_sla()) // 8)
@ -884,20 +881,20 @@ class Test_icmpv6_nd_option_la(unittest.TestCase):
option=icmpv6.nd_option_tla()))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_NEIGHBOR_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_neighbor._PACK_STR,
six.binary_type(buf[4:24]))
bytes(buf[4:24]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
res = struct.unpack(icmpv6.nd_option_tla._PACK_STR,
six.binary_type(buf[24:]))
bytes(buf[24:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_TLA)
self.assertEqual(res[1], len(icmpv6.nd_option_tla()) // 8)
@ -911,19 +908,19 @@ class Test_icmpv6_nd_option_la(unittest.TestCase):
option=icmpv6.nd_option_sla()))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_SOLICIT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR,
six.binary_type(buf[4:8]))
bytes(buf[4:8]))
self.assertEqual(res[0], 0)
res = struct.unpack(icmpv6.nd_option_sla._PACK_STR,
six.binary_type(buf[8:]))
bytes(buf[8:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_SLA)
self.assertEqual(res[1], len(icmpv6.nd_option_sla()) // 8)
@ -941,7 +938,7 @@ class Test_icmpv6_nd_option_pi(unittest.TestCase):
def test_default_args(self):
pi = icmpv6.nd_option_pi()
buf = pi.serialize()
res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, six.binary_type(buf))
res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, bytes(buf))
self.assertEqual(res[0], icmpv6.ND_OPTION_PI)
self.assertEqual(res[1], len(icmpv6.nd_option_pi()) // 8)
@ -960,14 +957,14 @@ class Test_icmpv6_nd_option_pi(unittest.TestCase):
options=[icmpv6.nd_option_pi()]))
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.ND_ROUTER_ADVERT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.nd_router_advert._PACK_STR,
six.binary_type(buf[4:16]))
bytes(buf[4:16]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -976,7 +973,7 @@ class Test_icmpv6_nd_option_pi(unittest.TestCase):
self.assertEqual(res[4], 0)
res = struct.unpack(icmpv6.nd_option_pi._PACK_STR,
six.binary_type(buf[16:]))
bytes(buf[16:]))
self.assertEqual(res[0], icmpv6.ND_OPTION_PI)
self.assertEqual(res[1], 4)
@ -1027,7 +1024,7 @@ class Test_icmpv6_membership_query(unittest.TestCase):
mld = icmpv6.mld(self.maxresp, self.address)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, mld)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR, buf, 0)
(maxresp, address) = struct.unpack_from(
@ -1068,13 +1065,13 @@ class Test_icmpv6_membership_query(unittest.TestCase):
type_=icmpv6.MLD_LISTENER_QUERY, data=icmpv6.mld())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.MLD_LISTENER_QUERY)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.mld._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.mld._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
@ -1215,9 +1212,9 @@ class Test_mldv2_query(unittest.TestCase):
buf = icmp.serialize(bytearray(), prev)
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR,
six.binary_type(buf))
bytes(buf))
(maxresp, address, s_qrv, qqic, num) = struct.unpack_from(
self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN)
self.mld._PACK_STR, bytes(buf), icmp._MIN_LEN)
self.assertEqual(type_, self.type_)
self.assertEqual(code, self.code)
@ -1242,11 +1239,11 @@ class Test_mldv2_query(unittest.TestCase):
buf = icmp.serialize(bytearray(), prev)
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR,
six.binary_type(buf))
bytes(buf))
(maxresp, address, s_qrv, qqic, num) = struct.unpack_from(
self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN)
self.mld._PACK_STR, bytes(buf), icmp._MIN_LEN)
(addr1, addr2) = struct.unpack_from(
'!16s16s', six.binary_type(buf), icmp._MIN_LEN + self.mld._MIN_LEN)
'!16s16s', bytes(buf), icmp._MIN_LEN + self.mld._MIN_LEN)
self.assertEqual(type_, self.type_)
self.assertEqual(code, self.code)
@ -1361,13 +1358,13 @@ class Test_mldv2_query(unittest.TestCase):
type_=icmpv6.MLD_LISTENER_QUERY, data=icmpv6.mldv2_query())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.MLD_LISTENER_QUERY)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.mldv2_query._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.mldv2_query._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
@ -1380,7 +1377,7 @@ class Test_mldv2_query(unittest.TestCase):
que = icmpv6.mldv2_query(srcs=srcs)
buf = que.serialize()
res = struct.unpack_from(
icmpv6.mldv2_query._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_query._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], addrconv.ipv6.text_to_bin('::'))
@ -1389,7 +1386,7 @@ class Test_mldv2_query(unittest.TestCase):
self.assertEqual(res[4], len(srcs))
(src1, src2, src3) = struct.unpack_from(
'16s16s16s', six.binary_type(buf), icmpv6.mldv2_query._MIN_LEN)
'16s16s16s', bytes(buf), icmpv6.mldv2_query._MIN_LEN)
self.assertEqual(src1, addrconv.ipv6.text_to_bin(srcs[0]))
self.assertEqual(src2, addrconv.ipv6.text_to_bin(srcs[1]))
@ -1497,9 +1494,9 @@ class Test_mldv2_report(unittest.TestCase):
buf = icmp.serialize(bytearray(), prev)
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR,
six.binary_type(buf))
bytes(buf))
(record_num, ) = struct.unpack_from(
self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN)
self.mld._PACK_STR, bytes(buf), icmp._MIN_LEN)
self.assertEqual(type_, self.type_)
self.assertEqual(code, self.code)
@ -1514,12 +1511,12 @@ class Test_mldv2_report(unittest.TestCase):
mld_csum = icmpv6_csum(prev, self.buf)
icmp = icmpv6.icmpv6(self.type_, self.code, 0, self.mld)
buf = six.binary_type(icmp.serialize(bytearray(), prev))
buf = bytes(icmp.serialize(bytearray(), prev))
(type_, code, csum) = struct.unpack_from(icmp._PACK_STR,
six.binary_type(buf))
bytes(buf))
(record_num, ) = struct.unpack_from(
self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN)
self.mld._PACK_STR, bytes(buf), icmp._MIN_LEN)
offset = icmp._MIN_LEN + self.mld._MIN_LEN
rec1 = icmpv6.mldv2_report_group.parser(buf[offset:])
offset += len(rec1)
@ -1646,13 +1643,13 @@ class Test_mldv2_report(unittest.TestCase):
type_=icmpv6.MLDV2_LISTENER_REPORT, data=icmpv6.mldv2_report())
prev.serialize(ic, None)
buf = ic.serialize(bytearray(), prev)
res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4]))
res = struct.unpack(icmpv6.icmpv6._PACK_STR, bytes(buf[:4]))
self.assertEqual(res[0], icmpv6.MLDV2_LISTENER_REPORT)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], icmpv6_csum(prev, buf))
res = struct.unpack(icmpv6.mldv2_report._PACK_STR, six.binary_type(buf[4:]))
res = struct.unpack(icmpv6.mldv2_report._PACK_STR, bytes(buf[4:]))
self.assertEqual(res[0], 0)
@ -1666,12 +1663,12 @@ class Test_mldv2_report(unittest.TestCase):
rep = icmpv6.mldv2_report(records=records)
buf = rep.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report._PACK_STR, bytes(buf))
self.assertEqual(res[0], len(records))
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf),
icmpv6.mldv2_report_group._PACK_STR, bytes(buf),
icmpv6.mldv2_report._MIN_LEN)
self.assertEqual(res[0], icmpv6.MODE_IS_INCLUDE)
@ -1680,7 +1677,7 @@ class Test_mldv2_report(unittest.TestCase):
self.assertEqual(res[3], addrconv.ipv6.text_to_bin('ff00::1'))
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf),
icmpv6.mldv2_report_group._PACK_STR, bytes(buf),
icmpv6.mldv2_report._MIN_LEN +
icmpv6.mldv2_report_group._MIN_LEN)
@ -1690,7 +1687,7 @@ class Test_mldv2_report(unittest.TestCase):
self.assertEqual(res[3], addrconv.ipv6.text_to_bin('ff00::2'))
res = struct.unpack_from(
'16s16s', six.binary_type(buf),
'16s16s', bytes(buf),
icmpv6.mldv2_report._MIN_LEN +
icmpv6.mldv2_report_group._MIN_LEN +
icmpv6.mldv2_report_group._MIN_LEN)
@ -1822,7 +1819,7 @@ class Test_mldv2_report_group(unittest.TestCase):
def test_serialize(self):
buf = self.mld.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -1833,9 +1830,9 @@ class Test_mldv2_report_group(unittest.TestCase):
self.setUp_with_srcs()
buf = self.mld.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
(src1, src2, src3) = struct.unpack_from(
'16s16s16s', six.binary_type(buf), icmpv6.mldv2_report_group._MIN_LEN)
'16s16s16s', bytes(buf), icmpv6.mldv2_report_group._MIN_LEN)
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
self.assertEqual(res[2], self.num)
@ -1848,9 +1845,9 @@ class Test_mldv2_report_group(unittest.TestCase):
self.setUp_with_aux()
buf = self.mld.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
(aux, ) = struct.unpack_from(
'%ds' % (self.aux_len * 4), six.binary_type(buf),
'%ds' % (self.aux_len * 4), bytes(buf),
icmpv6.mldv2_report_group._MIN_LEN)
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -1862,11 +1859,11 @@ class Test_mldv2_report_group(unittest.TestCase):
self.setUp_with_srcs_and_aux()
buf = self.mld.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
(src1, src2, src3) = struct.unpack_from(
'16s16s16s', six.binary_type(buf), icmpv6.mldv2_report_group._MIN_LEN)
'16s16s16s', bytes(buf), icmpv6.mldv2_report_group._MIN_LEN)
(aux, ) = struct.unpack_from(
'%ds' % (self.aux_len * 4), six.binary_type(buf),
'%ds' % (self.aux_len * 4), bytes(buf),
icmpv6.mldv2_report_group._MIN_LEN + 16 * 3)
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -1973,7 +1970,7 @@ class Test_mldv2_report_group(unittest.TestCase):
rep = icmpv6.mldv2_report_group()
buf = rep.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -1986,7 +1983,7 @@ class Test_mldv2_report_group(unittest.TestCase):
buf = rep.serialize()
LOG.info(repr(buf))
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -1994,7 +1991,7 @@ class Test_mldv2_report_group(unittest.TestCase):
self.assertEqual(res[3], addrconv.ipv6.text_to_bin('::'))
(src1, src2, src3) = struct.unpack_from(
'16s16s16s', six.binary_type(buf), icmpv6.mldv2_report_group._MIN_LEN)
'16s16s16s', bytes(buf), icmpv6.mldv2_report_group._MIN_LEN)
self.assertEqual(src1, addrconv.ipv6.text_to_bin(srcs[0]))
self.assertEqual(src2, addrconv.ipv6.text_to_bin(srcs[1]))
@ -2004,7 +2001,7 @@ class Test_mldv2_report_group(unittest.TestCase):
rep = icmpv6.mldv2_report_group(aux=b'\x01\x02\x03')
buf = rep.serialize()
res = struct.unpack_from(
icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf))
icmpv6.mldv2_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 1)

View File

@ -13,12 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import inspect
import logging
import six
from struct import pack, unpack_from, pack_into
from os_ken.ofproto import ether
@ -87,7 +84,7 @@ class Test_igmp(unittest.TestCase):
prev = None
buf = self.g.serialize(data, prev)
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
res = unpack_from(igmp._PACK_STR, bytes(buf))
self.assertEqual(res[0], self.msgtype)
self.assertEqual(res[1], self.maxresp)
@ -154,7 +151,7 @@ class Test_igmp(unittest.TestCase):
def test_default_args(self):
ig = igmp()
buf = ig.serialize(bytearray(), None)
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
res = unpack_from(igmp._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0x11)
self.assertEqual(res[1], 0)
@ -254,7 +251,7 @@ class Test_igmpv3_query(unittest.TestCase):
prev = None
buf = self.g.serialize(data, prev)
res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_query._PACK_STR, bytes(buf))
self.assertEqual(res[0], self.msgtype)
self.assertEqual(res[1], self.maxresp)
@ -270,8 +267,8 @@ class Test_igmpv3_query(unittest.TestCase):
prev = None
buf = self.g.serialize(data, prev)
res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
res = unpack_from(igmpv3_query._PACK_STR, bytes(buf))
(src1, src2, src3) = unpack_from('4s4s4s', bytes(buf),
igmpv3_query._MIN_LEN)
self.assertEqual(res[0], self.msgtype)
@ -389,7 +386,7 @@ class Test_igmpv3_query(unittest.TestCase):
g = igmpv3_query()
prev.serialize(g, None)
buf = g.serialize(bytearray(), prev)
res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_query._PACK_STR, bytes(buf))
buf = bytearray(buf)
pack_into('!H', buf, 2, 0)
@ -407,7 +404,7 @@ class Test_igmpv3_query(unittest.TestCase):
g = igmpv3_query(srcs=srcs)
prev.serialize(g, None)
buf = g.serialize(bytearray(), prev)
res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_query._PACK_STR, bytes(buf))
buf = bytearray(buf)
pack_into('!H', buf, 2, 0)
@ -419,7 +416,7 @@ class Test_igmpv3_query(unittest.TestCase):
self.assertEqual(res[5], 0)
self.assertEqual(res[6], len(srcs))
res = unpack_from('4s4s4s', six.binary_type(buf), igmpv3_query._MIN_LEN)
res = unpack_from('4s4s4s', bytes(buf), igmpv3_query._MIN_LEN)
self.assertEqual(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
self.assertEqual(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
@ -493,7 +490,7 @@ class Test_igmpv3_report(unittest.TestCase):
self.test_init()
def test_parser(self):
_res = self.g.parser(six.binary_type(self.buf))
_res = self.g.parser(bytes(self.buf))
if type(_res) is tuple:
res = _res[0]
else:
@ -513,7 +510,7 @@ class Test_igmpv3_report(unittest.TestCase):
prev = None
buf = self.g.serialize(data, prev)
res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report._PACK_STR, bytes(buf))
self.assertEqual(res[0], self.msgtype)
self.assertEqual(res[1], checksum(self.buf))
@ -523,7 +520,7 @@ class Test_igmpv3_report(unittest.TestCase):
self.setUp_with_records()
data = bytearray()
prev = None
buf = six.binary_type(self.g.serialize(data, prev))
buf = bytes(self.g.serialize(data, prev))
res = unpack_from(igmpv3_report._PACK_STR, buf)
offset = igmpv3_report._MIN_LEN
@ -657,7 +654,7 @@ class Test_igmpv3_report(unittest.TestCase):
g = igmpv3_report()
prev.serialize(g, None)
buf = g.serialize(bytearray(), prev)
res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report._PACK_STR, bytes(buf))
buf = bytearray(buf)
pack_into('!H', buf, 2, 0)
@ -681,7 +678,7 @@ class Test_igmpv3_report(unittest.TestCase):
g = igmpv3_report(records=records)
prev.serialize(g, None)
buf = g.serialize(bytearray(), prev)
res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report._PACK_STR, bytes(buf))
buf = bytearray(buf)
pack_into('!H', buf, 2, 0)
@ -808,7 +805,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
def test_serialize(self):
buf = self.g.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -818,8 +815,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
def test_serialize_with_srcs(self):
self.setUp_with_srcs()
buf = self.g.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
(src1, src2, src3) = unpack_from('4s4s4s', bytes(buf),
igmpv3_report_group._MIN_LEN)
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -832,8 +829,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
def test_serialize_with_aux(self):
self.setUp_with_aux()
buf = self.g.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), bytes(buf),
igmpv3_report_group._MIN_LEN)
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -844,10 +841,10 @@ class Test_igmpv3_report_group(unittest.TestCase):
def test_serialize_with_srcs_and_aux(self):
self.setUp_with_srcs_and_aux()
buf = self.g.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
(src1, src2, src3) = unpack_from('4s4s4s', bytes(buf),
igmpv3_report_group._MIN_LEN)
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), bytes(buf),
igmpv3_report_group._MIN_LEN + 12)
self.assertEqual(res[0], self.type_)
self.assertEqual(res[1], self.aux_len)
@ -953,7 +950,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
def test_default_args(self):
rep = igmpv3_report_group()
buf = rep.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
@ -964,14 +961,14 @@ class Test_igmpv3_report_group(unittest.TestCase):
srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
rep = igmpv3_report_group(srcs=srcs)
buf = rep.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 0)
self.assertEqual(res[2], len(srcs))
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
res = unpack_from('4s4s4s', six.binary_type(buf),
res = unpack_from('4s4s4s', bytes(buf),
igmpv3_report_group._MIN_LEN)
self.assertEqual(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
@ -982,7 +979,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
aux = b'abcde'
rep = igmpv3_report_group(aux=aux)
buf = rep.serialize()
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
res = unpack_from(igmpv3_report_group._PACK_STR, bytes(buf))
self.assertEqual(res[0], 0)
self.assertEqual(res[1], 2)

View File

@ -13,17 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import struct
from struct import *
from os_ken.ofproto import ether, inet
from os_ken.ofproto import inet
from os_ken.lib.packet import packet_utils
from os_ken.lib.packet.ethernet import ethernet
from os_ken.lib.packet.packet import Packet
from os_ken.lib.packet.ipv4 import ipv4
from os_ken.lib.packet.tcp import tcp
from os_ken.lib import addrconv
@ -107,7 +103,7 @@ class Test_ipv4(unittest.TestCase):
def test_serialize(self):
buf = self.ip.serialize(bytearray(), None)
res = struct.unpack_from(ipv4._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(ipv4._PACK_STR, bytes(buf))
option = buf[ipv4._MIN_LEN:ipv4._MIN_LEN + len(self.option)]
self.assertEqual(res[0], self.ver_hlen)

View File

@ -13,11 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import logging
import inspect
import six
import struct
from os_ken.lib import addrconv
@ -262,7 +260,7 @@ class Test_ipv6(unittest.TestCase):
self.test_init()
def test_parser(self):
_res = self.ip.parser(six.binary_type(self.buf))
_res = self.ip.parser(bytes(self.buf))
if type(_res) is tuple:
res = _res[0]
else:
@ -307,7 +305,7 @@ class Test_ipv6(unittest.TestCase):
prev = None
buf = self.ip.serialize(data, prev)
res = struct.unpack_from(ipv6.ipv6._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(ipv6.ipv6._PACK_STR, bytes(buf))
self.assertEqual(self.v_tc_flow, res[0])
self.assertEqual(self.payload_length, res[1])
@ -323,7 +321,7 @@ class Test_ipv6(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ip.serialize(data, prev)
hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
hop_opts = ipv6.hop_opts.parser(bytes(buf[ipv6.ipv6._MIN_LEN:]))
self.assertEqual(repr(self.hop_opts), repr(hop_opts))
def test_serialize_with_dst_opts(self):
@ -333,7 +331,7 @@ class Test_ipv6(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ip.serialize(data, prev)
dst_opts = ipv6.dst_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
dst_opts = ipv6.dst_opts.parser(bytes(buf[ipv6.ipv6._MIN_LEN:]))
self.assertEqual(repr(self.dst_opts), repr(dst_opts))
def test_serialize_with_routing_type3(self):
@ -343,7 +341,7 @@ class Test_ipv6(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ip.serialize(data, prev)
routing = ipv6.routing.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
routing = ipv6.routing.parser(bytes(buf[ipv6.ipv6._MIN_LEN:]))
self.assertEqual(repr(self.routing), repr(routing))
def test_serialize_with_fragment(self):
@ -353,7 +351,7 @@ class Test_ipv6(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ip.serialize(data, prev)
fragment = ipv6.fragment.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
fragment = ipv6.fragment.parser(bytes(buf[ipv6.ipv6._MIN_LEN:]))
self.assertEqual(repr(self.fragment), repr(fragment))
def test_serialize_with_auth(self):
@ -363,7 +361,7 @@ class Test_ipv6(unittest.TestCase):
data = bytearray()
prev = None
buf = self.ip.serialize(data, prev)
auth = ipv6.auth.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
auth = ipv6.auth.parser(bytes(buf[ipv6.ipv6._MIN_LEN:]))
self.assertEqual(repr(self.auth), repr(auth))
def test_serialize_with_multi_headers(self):
@ -374,9 +372,9 @@ class Test_ipv6(unittest.TestCase):
prev = None
buf = self.ip.serialize(data, prev)
offset = ipv6.ipv6._MIN_LEN
hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[offset:]))
hop_opts = ipv6.hop_opts.parser(bytes(buf[offset:]))
offset += len(hop_opts)
auth = ipv6.auth.parser(six.binary_type(buf[offset:]))
auth = ipv6.auth.parser(bytes(buf[offset:]))
self.assertEqual(repr(self.hop_opts), repr(hop_opts))
self.assertEqual(repr(self.auth), repr(auth))
@ -448,7 +446,7 @@ class Test_ipv6(unittest.TestCase):
def test_default_args(self):
ip = ipv6.ipv6()
buf = ip.serialize(bytearray(), None)
res = struct.unpack(ipv6.ipv6._PACK_STR, six.binary_type(buf))
res = struct.unpack(ipv6.ipv6._PACK_STR, bytes(buf))
self.assertEqual(res[0], 6 << 28)
self.assertEqual(res[1], 0)
@ -464,7 +462,7 @@ class Test_ipv6(unittest.TestCase):
ipv6.option(5, 2, b'\x00\x00'),
ipv6.option(1, 0, None)])])
buf = ip.serialize(bytearray(), None)
res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', six.binary_type(buf))
res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', bytes(buf))
self.assertEqual(res[0], 6 << 28)
self.assertEqual(res[1], 8)
@ -546,17 +544,17 @@ class Test_hop_opts(unittest.TestCase):
def test_serialize(self):
buf = self.hop.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.nxt, res[0])
self.assertEqual(self.size, res[1])
offset = struct.calcsize(self.form)
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt1 = ipv6.option.parser(bytes(buf[offset:]))
offset += len(opt1)
opt2 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt2 = ipv6.option.parser(bytes(buf[offset:]))
offset += len(opt2)
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt3 = ipv6.option.parser(bytes(buf[offset:]))
offset += len(opt3)
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt4 = ipv6.option.parser(bytes(buf[offset:]))
self.assertEqual(5, opt1.type_)
self.assertEqual(2, opt1.len_)
self.assertEqual(b'\x00\x00', opt1.data)
@ -576,12 +574,12 @@ class Test_hop_opts(unittest.TestCase):
def test_default_args(self):
hdr = ipv6.hop_opts()
buf = hdr.serialize()
res = struct.unpack('!BB', six.binary_type(buf[:2]))
res = struct.unpack('!BB', bytes(buf[:2]))
self.assertEqual(res[0], 6)
self.assertEqual(res[1], 0)
opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
self.assertEqual(six.binary_type(buf[2:]), opt.serialize())
self.assertEqual(bytes(buf[2:]), opt.serialize())
class Test_dst_opts(unittest.TestCase):
@ -626,17 +624,17 @@ class Test_dst_opts(unittest.TestCase):
def test_serialize(self):
buf = self.dst.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.nxt, res[0])
self.assertEqual(self.size, res[1])
offset = struct.calcsize(self.form)
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt1 = ipv6.option.parser(bytes(buf[offset:]))
offset += len(opt1)
opt2 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt2 = ipv6.option.parser(bytes(buf[offset:]))
offset += len(opt2)
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt3 = ipv6.option.parser(bytes(buf[offset:]))
offset += len(opt3)
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
opt4 = ipv6.option.parser(bytes(buf[offset:]))
self.assertEqual(5, opt1.type_)
self.assertEqual(2, opt1.len_)
self.assertEqual(b'\x00\x00', opt1.data)
@ -656,12 +654,12 @@ class Test_dst_opts(unittest.TestCase):
def test_default_args(self):
hdr = ipv6.dst_opts()
buf = hdr.serialize()
res = struct.unpack('!BB', six.binary_type(buf[:2]))
res = struct.unpack('!BB', bytes(buf[:2]))
self.assertEqual(res[0], 6)
self.assertEqual(res[1], 0)
opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
self.assertEqual(six.binary_type(buf[2:]), opt.serialize())
self.assertEqual(bytes(buf[2:]), opt.serialize())
class Test_option(unittest.TestCase):
@ -860,7 +858,7 @@ class Test_routing_type3(unittest.TestCase):
def test_serialize(self):
buf = self.routing.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.nxt, res[0])
self.assertEqual(self.size, res[1])
self.assertEqual(self.type_, res[2])
@ -914,7 +912,7 @@ class Test_routing_type3(unittest.TestCase):
cmpe, pad)
buf = routing.serialize()
form = '!BBBBBB2x'
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(nxt, res[0])
self.assertEqual(size, res[1])
self.assertEqual(type_, res[2])
@ -978,7 +976,7 @@ class Test_routing_type3(unittest.TestCase):
nxt, size, type_, seg, cmpi, cmpe, adrs)
buf = routing.serialize()
form = '!BBBBBB2x8s8s8s'
res = struct.unpack_from(form, six.binary_type(buf))
res = struct.unpack_from(form, bytes(buf))
self.assertEqual(nxt, res[0])
self.assertEqual(size, res[1])
self.assertEqual(type_, res[2])
@ -997,7 +995,7 @@ class Test_routing_type3(unittest.TestCase):
hdr = ipv6.routing_type3()
buf = hdr.serialize()
LOG.info(repr(buf))
res = struct.unpack_from(ipv6.routing_type3._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(ipv6.routing_type3._PACK_STR, bytes(buf))
LOG.info(res)
self.assertEqual(res[0], 6)
@ -1041,7 +1039,7 @@ class Test_fragment(unittest.TestCase):
def test_serialize(self):
buf = self.fragment.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.nxt, res[0])
self.assertEqual(self.off_m, res[1])
self.assertEqual(self.id_, res[2])
@ -1094,7 +1092,7 @@ class Test_auth(unittest.TestCase):
def test_serialize(self):
buf = self.auth.serialize()
res = struct.unpack_from(self.form, six.binary_type(buf))
res = struct.unpack_from(self.form, bytes(buf))
self.assertEqual(self.nxt, res[0])
self.assertEqual(self.size, res[1])
self.assertEqual(self.spi, res[2])
@ -1115,7 +1113,7 @@ class Test_auth(unittest.TestCase):
hdr = ipv6.auth()
buf = hdr.serialize()
LOG.info(repr(buf))
res = struct.unpack_from(ipv6.auth._PACK_STR, six.binary_type(buf))
res = struct.unpack_from(ipv6.auth._PACK_STR, bytes(buf))
LOG.info(res)
self.assertEqual(res[0], 6)

View File

@ -13,11 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import struct
import inspect
@ -340,7 +337,7 @@ class TestLLDPOptionalTLV(unittest.TestCase):
pkt.serialize()
# self.data has many organizationally specific TLVs
data = six.binary_type(pkt.data[:-2])
data = bytes(pkt.data[:-2])
self.assertEqual(data, self.data[:len(data)])
def test_to_string(self):

View File

@ -19,7 +19,6 @@ import unittest
import logging
import struct
import inspect
import six
from os_ken.ofproto import ether, inet
from os_ken.lib.packet import arp
from os_ken.lib.packet import bpdu
@ -1507,14 +1506,13 @@ class TestPacket(unittest.TestCase):
if k in llc_values])
llc_str = '%s(%s)' % (llc.llc.__name__, _llc_str)
_long = int if six.PY3 else long
bpdu_values = {'flags': 0,
'root_priority': _long(32768),
'root_system_id_extension': _long(0),
'root_priority': int(32768),
'root_system_id_extension': int(0),
'root_mac_address': self.src_mac,
'root_path_cost': 0,
'bridge_priority': _long(32768),
'bridge_system_id_extension': _long(0),
'bridge_priority': int(32768),
'bridge_system_id_extension': int(0),
'bridge_mac_address': self.dst_mac,
'port_priority': 128,
'port_number': 4,

View File

@ -13,10 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import inspect
import logging
import six
import struct
import unittest
@ -587,7 +585,7 @@ class Test_sctp(unittest.TestCase):
self.test_init()
def test_parser(self):
_res = self.sc.parser(six.binary_type(self.buf))
_res = self.sc.parser(bytes(self.buf))
if type(_res) is tuple:
res = _res[0]
else:

View File

@ -13,11 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import struct
from struct import *
from os_ken.ofproto import inet
@ -96,7 +93,7 @@ class Test_tcp(unittest.TestCase):
t = tcp.tcp(self.src_port, self.dst_port, self.seq, self.ack,
offset, self.bits, self.window_size, csum, self.urgent)
buf = t.serialize(bytearray(), prev)
res = struct.unpack(tcp.tcp._PACK_STR, six.binary_type(buf))
res = struct.unpack(tcp.tcp._PACK_STR, bytes(buf))
self.assertEqual(res[0], self.src_port)
self.assertEqual(res[1], self.dst_port)

View File

@ -14,11 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import unittest
import logging
import six
import struct
import inspect
@ -107,7 +104,7 @@ class Test_vrrpv2(unittest.TestCase):
buf = vrrp_.serialize(bytearray(), prev)
pack_str = vrrp.vrrpv2._PACK_STR + '4sII'
pack_len = struct.calcsize(pack_str)
res = struct.unpack(pack_str, six.binary_type(buf))
res = struct.unpack(pack_str, bytes(buf))
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V2, type_))
self.assertEqual(res[1], vrid)
self.assertEqual(res[2], priority)
@ -132,7 +129,7 @@ class Test_vrrpv2(unittest.TestCase):
primary_ip = '192.168.0.2'
p0 = self.vrrpv2.create_packet(primary_ip)
p0.serialize()
p1 = packet.Packet(six.binary_type(p0.data))
p1 = packet.Packet(bytes(p0.data))
p1.serialize()
self.assertEqual(p0.data, p1.data)
@ -269,7 +266,7 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
print(len(buf), type(buf), buf)
pack_str = vrrp.vrrpv3._PACK_STR + '4s'
pack_len = struct.calcsize(pack_str)
res = struct.unpack(pack_str, six.binary_type(buf))
res = struct.unpack(pack_str, bytes(buf))
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
self.assertEqual(res[1], vrid)
self.assertEqual(res[2], priority)
@ -296,7 +293,7 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
primary_ip = '192.168.0.2'
p0 = self.vrrpv3.create_packet(primary_ip)
p0.serialize()
p1 = packet.Packet(six.binary_type(p0.data))
p1 = packet.Packet(bytes(p0.data))
p1.serialize()
self.assertEqual(p0.data, p1.data)
@ -433,7 +430,7 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
print(len(buf), type(buf), buf)
pack_str = vrrp.vrrpv3._PACK_STR + '16s'
pack_len = struct.calcsize(pack_str)
res = struct.unpack(pack_str, six.binary_type(buf))
res = struct.unpack(pack_str, bytes(buf))
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
self.assertEqual(res[1], vrid)
self.assertEqual(res[2], priority)
@ -461,7 +458,7 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
p0 = self.vrrpv3.create_packet(primary_ip)
p0.serialize()
print(len(p0.data), p0.data)
p1 = packet.Packet(six.binary_type(p0.data))
p1 = packet.Packet(bytes(p0.data))
p1.serialize()
print(len(p0.data), p0.data)
print(len(p1.data), p1.data)

View File

@ -19,8 +19,6 @@ import sys
import unittest
from unittest import mock
import six
from os_ken.lib import pcaplib
from os_ken.lib.packet import packet
from os_ken.lib.packet import zebra
@ -54,7 +52,7 @@ class Test_zebra(unittest.TestCase):
self.assertTrue(isinstance(zebra_pkt, zebra.ZebraMessage),
'Failed to parse Zebra message: %s' % pkt)
self.assertTrue(not isinstance(pkt.protocols[-1],
(six.binary_type, bytearray)),
(bytes, bytearray)),
'Some messages could not be parsed in %s: %s' % (f, pkt))
# Checks if Zebra message can be serialized as expected.

View File

@ -14,7 +14,6 @@
# limitations under the License.
import logging
import six
import struct
import time
from os_ken import cfg
@ -465,10 +464,10 @@ class LLDPPacket(object):
def lldp_parse(data):
pkt = packet.Packet(data)
i = iter(pkt)
eth_pkt = six.next(i)
eth_pkt = next(i)
assert type(eth_pkt) == ethernet.ethernet
lldp_pkt = six.next(i)
lldp_pkt = next(i)
if type(lldp_pkt) != lldp.lldp:
raise LLDPPacket.LLDPUnknownFormat()

View File

@ -19,8 +19,6 @@ import logging
import os
import sys
import six
LOG = logging.getLogger('os_ken.utils')
@ -107,7 +105,7 @@ def round_up(x, y):
def hex_array(data):
"""
Convert six.binary_type or bytearray into array of hexes to be printed.
Convert bytes or bytearray into array of hexes to be printed.
"""
# convert data into bytearray explicitly
return ' '.join('0x%02x' % byte for byte in bytearray(data))
@ -115,7 +113,7 @@ def hex_array(data):
def binary_str(data):
"""
Convert six.binary_type or bytearray into str to be printed.
Convert bytes or bytearray into str to be printed.
"""
# convert data into bytearray explicitly
return ''.join('\\x%02x' % byte for byte in bytearray(data))

View File

@ -15,5 +15,4 @@ oslo.config>=5.1.0
ovs>=2.8.0 # OVSDB
packaging>=20.4 # Apache-2.0
Routes>=2.3.1 # MIT
six>=1.10.0
WebOb>=1.8.2 # wsgi

View File

@ -4,5 +4,4 @@ netaddr>=0.7.18
oslo.config>=5.1.0
ovs>=2.8.0 # OVSDB
Routes>=2.3.1 # wsgi
six>=1.10.0
WebOb>=1.8.2 # wsgi