removed usage of longs, updated int instance checking and octal constants to be 2/3 compliant
This commit is contained in:
parent
5b7453b906
commit
8d6bf54a16
11 changed files with 27 additions and 25 deletions
|
@ -4,17 +4,18 @@ import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
from Queue import Queue, Empty
|
from Queue import Queue, Empty
|
||||||
|
from builtins import int
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
from concurrent import futures
|
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
|
||||||
from core.api.grpc import core_pb2_grpc
|
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 import nodeutils
|
||||||
from core.nodes.ipaddress import MacAddress
|
from core.nodes.ipaddress import MacAddress
|
||||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
|
||||||
from core.services.coreservices import ServiceManager
|
from core.services.coreservices import ServiceManager
|
||||||
|
|
||||||
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
|
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
|
||||||
|
|
|
@ -788,7 +788,7 @@ class CoreMessage(object):
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
message_flags = []
|
message_flags = []
|
||||||
flag = 1L
|
flag = 1
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if self.flags & flag:
|
if self.flags & flag:
|
||||||
|
|
|
@ -8,12 +8,13 @@ import math
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from builtins import int
|
||||||
|
|
||||||
|
from core import utils
|
||||||
from core.config import ConfigGroup
|
from core.config import ConfigGroup
|
||||||
from core.config import ConfigurableOptions
|
from core.config import ConfigurableOptions
|
||||||
from core.config import Configuration
|
from core.config import Configuration
|
||||||
from core.config import ModelManager
|
from core.config import ModelManager
|
||||||
from core.nodes.base import CoreNodeBase
|
|
||||||
from core.emulator.data import EventData
|
from core.emulator.data import EventData
|
||||||
from core.emulator.data import LinkData
|
from core.emulator.data import LinkData
|
||||||
from core.emulator.enumerations import ConfigDataTypes
|
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 MessageTypes
|
||||||
from core.emulator.enumerations import NodeTlvs
|
from core.emulator.enumerations import NodeTlvs
|
||||||
from core.emulator.enumerations import RegisterTlvs
|
from core.emulator.enumerations import RegisterTlvs
|
||||||
from core import utils
|
from core.nodes.base import CoreNodeBase
|
||||||
from core.nodes.ipaddress import IpAddress
|
from core.nodes.ipaddress import IpAddress
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -559,7 +559,6 @@ class CoreNode(CoreNodeBase):
|
||||||
finally:
|
finally:
|
||||||
self.rmnodedir()
|
self.rmnodedir()
|
||||||
|
|
||||||
|
|
||||||
def cmd(self, args, wait=True):
|
def cmd(self, args, wait=True):
|
||||||
"""
|
"""
|
||||||
Runs shell command on node, with option to not wait for a result.
|
Runs shell command on node, with option to not wait for a result.
|
||||||
|
@ -928,10 +927,10 @@ class CoreNode(CoreNodeBase):
|
||||||
hostfilename = self.hostfilename(filename)
|
hostfilename = self.hostfilename(filename)
|
||||||
dirname, _basename = os.path.split(hostfilename)
|
dirname, _basename = os.path.split(hostfilename)
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.makedirs(dirname, mode=0755)
|
os.makedirs(dirname, mode=0o755)
|
||||||
return open(hostfilename, mode)
|
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.
|
Create a node file with a given mode.
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ virtual ethernet classes that implement the interfaces available under Linux.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
from builtins import int
|
||||||
from builtins import range
|
from builtins import range
|
||||||
|
|
||||||
from core import CoreCommandError, utils
|
from core import CoreCommandError, utils
|
||||||
|
|
|
@ -44,12 +44,12 @@ class MacAddress(object):
|
||||||
if not self.addr:
|
if not self.addr:
|
||||||
return IpAddress.from_string("::")
|
return IpAddress.from_string("::")
|
||||||
tmp = struct.unpack("!Q", "\x00\x00" + self.addr)[0]
|
tmp = struct.unpack("!Q", "\x00\x00" + self.addr)[0]
|
||||||
nic = long(tmp) & 0x000000FFFFFFL
|
nic = long(tmp) & 0x000000FFFFFF
|
||||||
oui = long(tmp) & 0xFFFFFF000000L
|
oui = long(tmp) & 0xFFFFFF000000
|
||||||
# toggle U/L bit
|
# toggle U/L bit
|
||||||
oui ^= 0x020000000000L
|
oui ^= 0x020000000000
|
||||||
# append EUI-48 octets
|
# append EUI-48 octets
|
||||||
oui = (oui << 16) | 0xFFFE000000L
|
oui = (oui << 16) | 0xFFFE000000
|
||||||
return IpAddress(AF_INET6, struct.pack("!QQ", 0xfe80 << 48, oui | nic))
|
return IpAddress(AF_INET6, struct.pack("!QQ", 0xfe80 << 48, oui | nic))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -234,7 +234,7 @@ class IpPrefix(object):
|
||||||
self.prefix = socket.inet_pton(self.af, tmp[0])
|
self.prefix = socket.inet_pton(self.af, tmp[0])
|
||||||
if self.addrlen > self.prefixlen:
|
if self.addrlen > self.prefixlen:
|
||||||
addrbits = self.addrlen - self.prefixlen
|
addrbits = self.addrlen - self.prefixlen
|
||||||
netmask = ((1L << self.prefixlen) - 1) << addrbits
|
netmask = ((1 << self.prefixlen) - 1) << addrbits
|
||||||
prefix = ""
|
prefix = ""
|
||||||
for i in range(-1, -(addrbits >> 3) - 2, -1):
|
for i in range(-1, -(addrbits >> 3) - 2, -1):
|
||||||
prefix = chr(ord(self.prefix[i]) & (netmask & 0xff)) + prefix
|
prefix = chr(ord(self.prefix[i]) & (netmask & 0xff)) + prefix
|
||||||
|
@ -376,7 +376,7 @@ class IpPrefix(object):
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
addrbits = self.addrlen - self.prefixlen
|
addrbits = self.addrlen - self.prefixlen
|
||||||
netmask = ((1L << self.prefixlen) - 1) << addrbits
|
netmask = ((1 << self.prefixlen) - 1) << addrbits
|
||||||
netmaskbytes = struct.pack("!L", netmask)
|
netmaskbytes = struct.pack("!L", netmask)
|
||||||
return IpAddress(af=AF_INET, address=netmaskbytes).__str__()
|
return IpAddress(af=AF_INET, address=netmaskbytes).__str__()
|
||||||
|
|
||||||
|
|
|
@ -234,12 +234,12 @@ class PhysicalNode(CoreNodeBase):
|
||||||
dirname = dirname.replace("/", ".")
|
dirname = dirname.replace("/", ".")
|
||||||
dirname = os.path.join(self.nodedir, dirname)
|
dirname = os.path.join(self.nodedir, dirname)
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.makedirs(dirname, mode=0755)
|
os.makedirs(dirname, mode=0o755)
|
||||||
|
|
||||||
hostfilename = os.path.join(dirname, basename)
|
hostfilename = os.path.join(dirname, basename)
|
||||||
return open(hostfilename, mode)
|
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:
|
with self.opennodefile(filename, "w") as node_file:
|
||||||
node_file.write(contents)
|
node_file.write(contents)
|
||||||
os.chmod(node_file.name, mode)
|
os.chmod(node_file.name, mode)
|
||||||
|
|
|
@ -520,7 +520,7 @@ class CoreServices(object):
|
||||||
src = src.split('\n')[0]
|
src = src.split('\n')[0]
|
||||||
src = utils.expand_corepath(src, node.session, node)
|
src = utils.expand_corepath(src, node.session, node)
|
||||||
# TODO: glob here
|
# TODO: glob here
|
||||||
node.nodefilecopy(filename, src, mode=0644)
|
node.nodefilecopy(filename, src, mode=0o644)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ ip forwarding
|
||||||
f.close()
|
f.close()
|
||||||
tmp = self.bootscript()
|
tmp = self.bootscript()
|
||||||
if tmp:
|
if tmp:
|
||||||
self.nodefile(self.bootsh, tmp, mode=0755)
|
self.nodefile(self.bootsh, tmp, mode=0o755)
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
self.config()
|
self.config()
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
|
from builtins import int
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
import pytest
|
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 import core_pb2
|
||||||
from core.api.grpc.client import CoreGrpcClient
|
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
|
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -491,7 +491,7 @@ class Ns3Session(Session):
|
||||||
net.mobility.setendtime()
|
net.mobility.setendtime()
|
||||||
net.mobility.refresh_ms = 300
|
net.mobility.refresh_ms = 300
|
||||||
net.mobility.empty_queue_stop = False
|
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.mobhelper.EnableAsciiAll(of)
|
||||||
self.mobilitytracethread = threading.Thread(
|
self.mobilitytracethread = threading.Thread(
|
||||||
target=self.mobilitytrace,
|
target=self.mobilitytrace,
|
||||||
|
|
Loading…
Add table
Reference in a new issue