removed usage of longs, updated int instance checking and octal constants to be 2/3 compliant

This commit is contained in:
bharnden 2019-05-05 17:11:07 -07:00
parent 5b7453b906
commit 8d6bf54a16
11 changed files with 27 additions and 25 deletions

View file

@ -4,17 +4,18 @@ import os
import tempfile
import time
from Queue import Queue, Empty
from builtins import int
import grpc
from concurrent import futures
from core.emulator.emudata import NodeOptions, InterfaceData, LinkOptions
from core.emulator.enumerations import NodeTypes, EventTypes, LinkTypes
from core.api.grpc import core_pb2
from core.api.grpc import core_pb2_grpc
from core.emulator.emudata import NodeOptions, InterfaceData, LinkOptions
from core.emulator.enumerations import NodeTypes, EventTypes, LinkTypes
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.nodes import nodeutils
from core.nodes.ipaddress import MacAddress
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.services.coreservices import ServiceManager
_ONE_DAY_IN_SECONDS = 60 * 60 * 24

View file

@ -788,7 +788,7 @@ class CoreMessage(object):
:rtype: str
"""
message_flags = []
flag = 1L
flag = 1
while True:
if self.flags & flag:

View file

@ -8,12 +8,13 @@ import math
import os
import threading
import time
from builtins import int
from core import utils
from core.config import ConfigGroup
from core.config import ConfigurableOptions
from core.config import Configuration
from core.config import ModelManager
from core.nodes.base import CoreNodeBase
from core.emulator.data import EventData
from core.emulator.data import LinkData
from core.emulator.enumerations import ConfigDataTypes
@ -23,7 +24,7 @@ from core.emulator.enumerations import MessageFlags
from core.emulator.enumerations import MessageTypes
from core.emulator.enumerations import NodeTlvs
from core.emulator.enumerations import RegisterTlvs
from core import utils
from core.nodes.base import CoreNodeBase
from core.nodes.ipaddress import IpAddress

View file

@ -559,7 +559,6 @@ class CoreNode(CoreNodeBase):
finally:
self.rmnodedir()
def cmd(self, args, wait=True):
"""
Runs shell command on node, with option to not wait for a result.
@ -928,10 +927,10 @@ class CoreNode(CoreNodeBase):
hostfilename = self.hostfilename(filename)
dirname, _basename = os.path.split(hostfilename)
if not os.path.isdir(dirname):
os.makedirs(dirname, mode=0755)
os.makedirs(dirname, mode=0o755)
return open(hostfilename, mode)
def nodefile(self, filename, contents, mode=0644):
def nodefile(self, filename, contents, mode=0o644):
"""
Create a node file with a given mode.

View file

@ -4,6 +4,7 @@ virtual ethernet classes that implement the interfaces available under Linux.
import logging
import time
from builtins import int
from builtins import range
from core import CoreCommandError, utils

View file

@ -44,12 +44,12 @@ class MacAddress(object):
if not self.addr:
return IpAddress.from_string("::")
tmp = struct.unpack("!Q", "\x00\x00" + self.addr)[0]
nic = long(tmp) & 0x000000FFFFFFL
oui = long(tmp) & 0xFFFFFF000000L
nic = long(tmp) & 0x000000FFFFFF
oui = long(tmp) & 0xFFFFFF000000
# toggle U/L bit
oui ^= 0x020000000000L
oui ^= 0x020000000000
# append EUI-48 octets
oui = (oui << 16) | 0xFFFE000000L
oui = (oui << 16) | 0xFFFE000000
return IpAddress(AF_INET6, struct.pack("!QQ", 0xfe80 << 48, oui | nic))
@classmethod
@ -234,7 +234,7 @@ class IpPrefix(object):
self.prefix = socket.inet_pton(self.af, tmp[0])
if self.addrlen > self.prefixlen:
addrbits = self.addrlen - self.prefixlen
netmask = ((1L << self.prefixlen) - 1) << addrbits
netmask = ((1 << self.prefixlen) - 1) << addrbits
prefix = ""
for i in range(-1, -(addrbits >> 3) - 2, -1):
prefix = chr(ord(self.prefix[i]) & (netmask & 0xff)) + prefix
@ -376,7 +376,7 @@ class IpPrefix(object):
:rtype: str
"""
addrbits = self.addrlen - self.prefixlen
netmask = ((1L << self.prefixlen) - 1) << addrbits
netmask = ((1 << self.prefixlen) - 1) << addrbits
netmaskbytes = struct.pack("!L", netmask)
return IpAddress(af=AF_INET, address=netmaskbytes).__str__()

View file

@ -234,12 +234,12 @@ class PhysicalNode(CoreNodeBase):
dirname = dirname.replace("/", ".")
dirname = os.path.join(self.nodedir, dirname)
if not os.path.isdir(dirname):
os.makedirs(dirname, mode=0755)
os.makedirs(dirname, mode=0o755)
hostfilename = os.path.join(dirname, basename)
return open(hostfilename, mode)
def nodefile(self, filename, contents, mode=0644):
def nodefile(self, filename, contents, mode=0o644):
with self.opennodefile(filename, "w") as node_file:
node_file.write(contents)
os.chmod(node_file.name, mode)

View file

@ -520,7 +520,7 @@ class CoreServices(object):
src = src.split('\n')[0]
src = utils.expand_corepath(src, node.session, node)
# TODO: glob here
node.nodefilecopy(filename, src, mode=0644)
node.nodefilecopy(filename, src, mode=0o644)
return True
return False

View file

@ -84,7 +84,7 @@ ip forwarding
f.close()
tmp = self.bootscript()
if tmp:
self.nodefile(self.bootsh, tmp, mode=0755)
self.nodefile(self.bootsh, tmp, mode=0o755)
def boot(self):
self.config()

View file

@ -1,16 +1,16 @@
import time
from Queue import Queue
from builtins import int
import grpc
import pytest
from core.config import ConfigShim
from core.emulator.data import EventData
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.enumerations import NodeTypes, EventTypes, ConfigFlags, ExceptionLevels
from core.api.grpc import core_pb2
from core.api.grpc.client import CoreGrpcClient
from core.config import ConfigShim
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.data import EventData
from core.emulator.enumerations import NodeTypes, EventTypes, ConfigFlags, ExceptionLevels
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility

View file

@ -491,7 +491,7 @@ class Ns3Session(Session):
net.mobility.setendtime()
net.mobility.refresh_ms = 300
net.mobility.empty_queue_stop = False
of = ns.network.OutputStreamWrapper(filename, filemode=777)
of = ns.network.OutputStreamWrapper(filename, filemode=0o777)
self.mobhelper.EnableAsciiAll(of)
self.mobilitytracethread = threading.Thread(
target=self.mobilitytrace,