python3: Use integer division where appropriate
Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
7681cf91ea
commit
4ee2f054d2
@ -735,14 +735,14 @@ class _AddrPrefix(StringifyMixin):
|
||||
def parser(cls, buf):
|
||||
(length, ) = struct.unpack_from(cls._PACK_STR, buffer(buf))
|
||||
rest = buf[struct.calcsize(cls._PACK_STR):]
|
||||
byte_length = (length + 7) / 8
|
||||
byte_length = (length + 7) // 8
|
||||
addr = cls._from_bin(rest[:byte_length])
|
||||
rest = rest[byte_length:]
|
||||
return cls(length=length, addr=addr), rest
|
||||
|
||||
def serialize(self):
|
||||
# fixup
|
||||
byte_length = (self.length + 7) / 8
|
||||
byte_length = (self.length + 7) // 8
|
||||
bin_addr = self._to_bin(self.addr)
|
||||
if (self.length % 8) == 0:
|
||||
bin_addr = bin_addr[:byte_length]
|
||||
|
@ -449,7 +449,7 @@ class nd_option_la(nd_option):
|
||||
if mod:
|
||||
buf.extend(bytearray(8 - mod))
|
||||
if 0 == self.length:
|
||||
self.length = len(buf) / 8
|
||||
self.length = len(buf) // 8
|
||||
struct.pack_into('!B', buf, 1, self.length)
|
||||
return str(buf)
|
||||
|
||||
@ -607,7 +607,7 @@ class nd_option_pi(nd_option):
|
||||
res1, self.val_l, self.pre_l, self.res2,
|
||||
addrconv.ipv6.text_to_bin(self.prefix)))
|
||||
if 0 == self.length:
|
||||
self.length = len(hdr) / 8
|
||||
self.length = len(hdr) // 8
|
||||
struct.pack_into('!B', hdr, 1, self.length)
|
||||
return str(hdr)
|
||||
|
||||
@ -933,7 +933,7 @@ class mldv2_report_group(stringify.StringifyMixin):
|
||||
self.aux = str(self.aux)
|
||||
buf.extend(self.aux)
|
||||
if 0 == self.aux_len:
|
||||
self.aux_len = len(self.aux) / 4
|
||||
self.aux_len = len(self.aux) // 4
|
||||
struct.pack_into('!B', buf, 1, self.aux_len)
|
||||
return str(buf)
|
||||
|
||||
|
@ -460,7 +460,7 @@ class igmpv3_report_group(stringify.StringifyMixin):
|
||||
self.aux = str(self.aux)
|
||||
buf.extend(self.aux)
|
||||
if 0 == self.aux_len:
|
||||
self.aux_len = len(self.aux) / 4
|
||||
self.aux_len = len(self.aux) // 4
|
||||
struct.pack_into('!B', buf, 1, self.aux_len)
|
||||
return str(buf)
|
||||
|
||||
|
@ -462,7 +462,7 @@ class routing_type3(header):
|
||||
def serialize(self):
|
||||
if self.size == 0:
|
||||
self.size = ((len(self.adrs) - 1) * (16 - self.cmpi) +
|
||||
(16 - self.cmpe) + self._pad) / 8
|
||||
(16 - self.cmpe) + self._pad) // 8
|
||||
buf = struct.pack(self._PACK_STR, self.nxt, self.size,
|
||||
self.type_, self.seg, (self.cmpi << 4) | self.cmpe,
|
||||
self._pad << 4)
|
||||
|
@ -355,7 +355,7 @@ class vrrp(packet_base.PacketBase):
|
||||
inet.IPPROTO_VRRP, VRRP_IPV6_HOP_LIMIT,
|
||||
primary_ip_address, VRRP_IPV6_DST_ADDRESS)
|
||||
else:
|
||||
header_length = ipv4.ipv4._MIN_LEN / 4 # XXX _MIN_LEN
|
||||
header_length = ipv4.ipv4._MIN_LEN // 4 # XXX _MIN_LEN
|
||||
total_length = 0
|
||||
tos = 0xc0 # set tos to internetwork control
|
||||
identification = self.get_identification()
|
||||
@ -574,7 +574,7 @@ class vrrpv3(vrrp):
|
||||
max_adver_int &= VRRP_V3_MAX_ADVER_INT_MASK
|
||||
|
||||
offset = cls._MIN_LEN
|
||||
address_len = (len(buf) - offset) / count_ip
|
||||
address_len = (len(buf) - offset) // count_ip
|
||||
# Address version (IPv4 or IPv6) is determined by network layer
|
||||
# header type.
|
||||
# Unfortunately it isn't available. Guess it by vrrp packet length.
|
||||
|
@ -1105,7 +1105,7 @@ def nxm_put(buf, offset, header, rule):
|
||||
|
||||
|
||||
def round_up(length):
|
||||
return (length + 7) / 8 * 8 # Round up to a multiple of 8
|
||||
return (length + 7) // 8 * 8 # Round up to a multiple of 8
|
||||
|
||||
|
||||
class NXMatch(object):
|
||||
|
@ -1605,7 +1605,7 @@ class NXTPacketIn(NiciraHeader):
|
||||
- ofproto.NICIRA_HEADER_SIZE)
|
||||
|
||||
match = nx_match.NXMatch.parser(buf, offset, match_len)
|
||||
offset += (match_len + 7) / 8 * 8
|
||||
offset += (match_len + 7) // 8 * 8
|
||||
frame = buf[offset:]
|
||||
if total_len < len(frame):
|
||||
frame = frame[:total_len]
|
||||
|
@ -785,7 +785,7 @@ def oxm_tlv_header_extract_hasmask(header):
|
||||
|
||||
def oxm_tlv_header_extract_length(header):
|
||||
if oxm_tlv_header_extract_hasmask(header):
|
||||
length = (header & 0xff) / 2
|
||||
length = (header & 0xff) // 2
|
||||
else:
|
||||
length = header & 0xff
|
||||
return length
|
||||
|
@ -1135,7 +1135,7 @@ def oxm_tlv_header_extract_hasmask(header):
|
||||
|
||||
def oxm_tlv_header_extract_length(header):
|
||||
if oxm_tlv_header_extract_hasmask(header):
|
||||
length = (header & 0xff) / 2
|
||||
length = (header & 0xff) // 2
|
||||
else:
|
||||
length = header & 0xff
|
||||
return length
|
||||
|
@ -342,7 +342,7 @@ def oxm_tlv_header_extract_hasmask(header):
|
||||
|
||||
def oxm_tlv_header_extract_length(header):
|
||||
if oxm_tlv_header_extract_hasmask(header):
|
||||
length = (header & 0xff) / 2
|
||||
length = (header & 0xff) // 2
|
||||
else:
|
||||
length = header & 0xff
|
||||
return length
|
||||
|
@ -379,7 +379,7 @@ def oxm_tlv_header_extract_hasmask(header):
|
||||
|
||||
def oxm_tlv_header_extract_length(header):
|
||||
if oxm_tlv_header_extract_hasmask(header):
|
||||
length = (header & 0xff) / 2
|
||||
length = (header & 0xff) // 2
|
||||
else:
|
||||
length = header & 0xff
|
||||
return length
|
||||
|
@ -41,7 +41,7 @@ class Memory(Command):
|
||||
|
||||
# Total size in MB
|
||||
|
||||
total_size = total_size / 1000000
|
||||
total_size = total_size // 1000000
|
||||
ret = {
|
||||
'unreachable': unreachable,
|
||||
'total': total_size,
|
||||
@ -49,7 +49,7 @@ class Memory(Command):
|
||||
|
||||
for class_name, s in size.items():
|
||||
# Calculate size in MB
|
||||
size_mb = s / 1000000
|
||||
size_mb = s // 1000000
|
||||
# We are only interested in class which take-up more than a MB
|
||||
if size_mb > 0:
|
||||
ret['summary'].append(
|
||||
|
@ -508,7 +508,7 @@ class BgpProtocol(Protocol, Activity):
|
||||
self._holdtime = neg_timer
|
||||
self._keepalive = self._create_timer('Keepalive Timer',
|
||||
self._send_keepalive)
|
||||
interval = self._holdtime / 3
|
||||
interval = self._holdtime // 3
|
||||
self._keepalive.start(interval, now=False)
|
||||
# Setup the expire timer.
|
||||
self._expiry = self._create_timer('Holdtime Timer', self._expired)
|
||||
|
@ -377,14 +377,14 @@ class RouterIPV4OpenFlow(RouterIPV4):
|
||||
# _ARP_TABLE > _DROP_TABLE
|
||||
# to gurantee that responding arp can be disabled
|
||||
_ARP_TABLE = 0
|
||||
_ARP_PRIORITY = _DROP_PRIORITY / 2
|
||||
_ARP_PRIORITY = _DROP_PRIORITY // 2
|
||||
|
||||
# it must be that
|
||||
# _ROUTEING_TABLE < _ARP_TABLE or
|
||||
# _ROUTING_TABLE > _ARP_TABLE
|
||||
# to gurantee that routing can be disabled
|
||||
_ROUTING_TABLE = 0
|
||||
_ROUTING_PRIORITY = _ARP_PRIORITY / 2
|
||||
_ROUTING_PRIORITY = _ARP_PRIORITY // 2
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RouterIPV4OpenFlow, self).__init__(*args, **kwargs)
|
||||
|
@ -6638,10 +6638,10 @@ class TestOFPMatch(unittest.TestCase):
|
||||
|
||||
res = list(unpack_from(fmt, str(buf), 0)[3:])
|
||||
if type(value) is list:
|
||||
res_value = res[:calcsize(pack_str) / 2]
|
||||
res_value = res[:calcsize(pack_str) // 2]
|
||||
eq_(res_value, value)
|
||||
if mask:
|
||||
res_mask = res[calcsize(pack_str) / 2:]
|
||||
res_mask = res[calcsize(pack_str) // 2:]
|
||||
eq_(res_mask, mask)
|
||||
else:
|
||||
res_value = res.pop(0)
|
||||
@ -7547,7 +7547,7 @@ class TestOFPMatchField(unittest.TestCase):
|
||||
res = OFPMatchField(header)
|
||||
|
||||
eq_(res.header, header)
|
||||
eq_(res.n_bytes, (header & 0xff) / 2)
|
||||
eq_(res.n_bytes, (header & 0xff) // 2)
|
||||
eq_(res.length, 0)
|
||||
|
||||
def test_init_hasmask_false(self):
|
||||
|
@ -63,10 +63,10 @@ class TestOFPMatch(unittest.TestCase):
|
||||
|
||||
res = list(unpack_from(fmt, str(buf), 0)[3:])
|
||||
if type(value) is list:
|
||||
res_value = res[:calcsize(pack_str) / 2]
|
||||
res_value = res[:calcsize(pack_str) // 2]
|
||||
eq_(res_value, value)
|
||||
if mask:
|
||||
res_mask = res[calcsize(pack_str) / 2:]
|
||||
res_mask = res[calcsize(pack_str) // 2:]
|
||||
eq_(res_mask, mask)
|
||||
else:
|
||||
res_value = res.pop(0)
|
||||
|
@ -738,7 +738,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
|
||||
def setUp_with_aux(self):
|
||||
self.aux = '\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||
self.aux_len = len(self.aux) / 4
|
||||
self.aux_len = len(self.aux) // 4
|
||||
self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
|
||||
self.aux_len, self.num,
|
||||
addrconv.ipv4.text_to_bin(self.address))
|
||||
@ -751,7 +751,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||
self.num = len(self.srcs)
|
||||
self.aux = '\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||
self.aux_len = len(self.aux) / 4
|
||||
self.aux_len = len(self.aux) // 4
|
||||
self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
|
||||
self.aux_len, self.num,
|
||||
addrconv.ipv4.text_to_bin(self.address))
|
||||
@ -936,7 +936,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
@raises
|
||||
def test_aux_len_larger_than_aux(self):
|
||||
self.aux = '\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||
self.aux_len = len(self.aux) / 4 + 1
|
||||
self.aux_len = len(self.aux) // 4 + 1
|
||||
self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
|
||||
self.aux_len, self.num,
|
||||
addrconv.ipv4.text_to_bin(self.address))
|
||||
@ -949,7 +949,7 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
@raises
|
||||
def test_aux_len_smaller_than_aux(self):
|
||||
self.aux = '\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||
self.aux_len = len(self.aux) / 4 - 1
|
||||
self.aux_len = len(self.aux) // 4 - 1
|
||||
self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
|
||||
self.aux_len, self.num,
|
||||
addrconv.ipv4.text_to_bin(self.address))
|
||||
|
@ -95,7 +95,7 @@ def import_module(modname):
|
||||
|
||||
|
||||
def round_up(x, y):
|
||||
return ((x + y - 1) / y) * y
|
||||
return ((x + y - 1) // y) * y
|
||||
|
||||
|
||||
def _str_to_hex(data):
|
||||
|
Loading…
Reference in New Issue
Block a user