added future library to support python2/3, updated xrange calls to leverage builtins range

This commit is contained in:
bharnden 2019-05-05 16:19:12 -07:00
parent e79fd6c7ce
commit e58cbe9421
15 changed files with 50 additions and 36 deletions

View file

@ -11,8 +11,10 @@ import shutil
import sys
import threading
import time
from builtins import range
from itertools import repeat
from core import utils
from core.api.tlv import coreapi, dataconversion, structutils
from core.config import ConfigShim
from core.emulator.data import ConfigData, ExceptionData
@ -38,7 +40,6 @@ from core.emulator.enumerations import NodeTypes
from core.emulator.enumerations import RegisterTlvs
from core.emulator.enumerations import SessionTlvs
from core.nodes import nodeutils
from core import utils
from core.services.coreservices import ServiceManager
from core.services.coreservices import ServiceShim
@ -79,7 +80,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
raise ValueError("invalid number of threads: %s" % num_threads)
logging.debug("launching core server handler threads: %s", num_threads)
for _ in xrange(num_threads):
for _ in range(num_threads):
thread = threading.Thread(target=self.handler_thread)
self.handler_threads.append(thread)
thread.start()

View file

@ -11,16 +11,17 @@ import signal
import socket
import string
import threading
from builtins import range
from socket import AF_INET, AF_INET6
from core import CoreCommandError, utils
from core import constants
from core.emulator.data import NodeData, LinkData
from core.emulator.enumerations import NodeTypes, LinkTypes
from core.nodes.ipaddress import MacAddress
from core.nodes import client, nodeutils, ipaddress
from core.nodes.interface import TunTap, CoreInterface
from core.nodes.interface import Veth
from core.nodes.ipaddress import MacAddress
_DEFAULT_MTU = 1500
@ -868,8 +869,8 @@ class CoreNode(CoreNodeBase):
:return: nothing
"""
tmplen = 8
tmp1 = "tmp." + "".join([random.choice(string.ascii_lowercase) for _ in xrange(tmplen)])
tmp2 = "tmp." + "".join([random.choice(string.ascii_lowercase) for _ in xrange(tmplen)])
tmp1 = "tmp." + "".join([random.choice(string.ascii_lowercase) for _ in range(tmplen)])
tmp2 = "tmp." + "".join([random.choice(string.ascii_lowercase) for _ in range(tmplen)])
utils.check_cmd([constants.IP_BIN, "link", "add", "name", tmp1, "type", "veth", "peer", "name", tmp2])
utils.check_cmd([constants.IP_BIN, "link", "set", tmp1, "netns", str(self.pid)])

View file

@ -4,6 +4,7 @@ virtual ethernet classes that implement the interfaces available under Linux.
import logging
import time
from builtins import range
from core import CoreCommandError, utils
from core import constants
@ -300,7 +301,7 @@ class TunTap(CoreInterface):
"""
delay = 0.01
result = False
for i in xrange(1, attempts + 1):
for i in range(1, attempts + 1):
r = func()
if r == 0:
result = True

View file

@ -6,6 +6,7 @@ import logging
import random
import socket
import struct
from builtins import range
from socket import AF_INET
from socket import AF_INET6
@ -154,7 +155,7 @@ class IpAddress(object):
return NotImplemented
tmp = [ord(x) for x in self.addr]
for i in xrange(len(tmp) - 1, -1, -1):
for i in range(len(tmp) - 1, -1, -1):
x = tmp[i] + carry
tmp[i] = x & 0xff
carry = x >> 8
@ -235,7 +236,7 @@ class IpPrefix(object):
addrbits = self.addrlen - self.prefixlen
netmask = ((1L << self.prefixlen) - 1) << addrbits
prefix = ""
for i in xrange(-1, -(addrbits >> 3) - 2, -1):
for i in range(-1, -(addrbits >> 3) - 2, -1):
prefix = chr(ord(self.prefix[i]) & (netmask & 0xff)) + prefix
netmask >>= 8
self.prefix = self.prefix[:i] + prefix
@ -319,7 +320,7 @@ class IpPrefix(object):
addr = ""
prefix_endpoint = -1
for i in xrange(-1, -(self.addrlen >> 3) - 1, -1):
for i in range(-1, -(self.addrlen >> 3) - 1, -1):
prefix_endpoint = i
addr = chr(ord(self.prefix[i]) | (tmp & 0xff)) + addr
tmp >>= 8

View file

@ -3,6 +3,7 @@
# Example CORE Python script that attaches N nodes to an EMANE 802.11abg network.
import datetime
from builtins import range
import parser
from core import load_logging_config
@ -33,7 +34,7 @@ def example(options):
emane_network.setposition(x=80, y=50)
# create nodes
for i in xrange(options.nodes):
for i in range(options.nodes):
node = session.create_wireless_node()
node.setposition(x=150 * (i + 1), y=150)
interface = prefixes.create_interface(node)

View file

@ -6,6 +6,7 @@
# nodestep
import datetime
from builtins import range
import parser
from core import load_logging_config
@ -31,7 +32,7 @@ def example(options):
switch = session.add_node(_type=NodeTypes.SWITCH)
# create nodes
for _ in xrange(options.nodes):
for _ in range(options.nodes):
node = session.add_node()
interface = prefixes.create_interface(node)
session.add_link(node.id, switch.id, interface_one=interface)

View file

@ -4,6 +4,8 @@
# n nodes are connected to a virtual wlan; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep
from builtins import range
from core import load_logging_config
from core.emulator.emudata import IpPrefixes
from core.emulator.enumerations import NodeTypes, EventTypes
@ -26,7 +28,7 @@ def example(nodes):
switch = session.add_node(_type=NodeTypes.SWITCH)
# create nodes
for _ in xrange(nodes):
for _ in range(nodes):
node = session.add_node()
interface = prefixes.create_interface(node)
session.add_link(node.id, switch.id, interface_one=interface)

View file

@ -6,6 +6,7 @@
# nodestep
import datetime
from builtins import range
import parser
from core import load_logging_config
@ -35,7 +36,7 @@ def example(options):
# create nodes, must set a position for wlan basic range model
node_options = NodeOptions()
node_options.set_position(0, 0)
for _ in xrange(options.nodes):
for _ in range(options.nodes):
node = session.add_node(node_options=node_options)
interface = prefixes.create_interface(node)
session.add_link(node.id, wlan.id, interface_one=interface)

View file

@ -1,4 +1,5 @@
import logging
from builtins import range
from core.api.grpc import client, core_pb2
@ -36,7 +37,7 @@ def main():
# helper to create interfaces
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/16")
for i in xrange(2):
for i in range(2):
# create node
position = core_pb2.Position(x=50 + 50 * i, y=50)
node = core_pb2.Node(position=position)

View file

@ -13,6 +13,7 @@
import datetime
import optparse
import sys
from builtins import range
import core.nodes.base
import core.nodes.network
@ -26,12 +27,11 @@ from core.emulator.enumerations import LinkTlvs
from core.emulator.enumerations import LinkTypes
from core.emulator.enumerations import MessageFlags
from core.emulator.enumerations import MessageTypes
from core.emulator.session import Session
from core.nodes import ipaddress
# declare classes for use with Broker
from core.emulator.session import Session
# node list (count from 1)
n = [None]
exec_num = 1
@ -148,7 +148,7 @@ def main():
print "creating %d remote nodes with addresses from %s" % (options.numnodes, prefix)
# create remote nodes via API
for i in xrange(1, number_of_nodes + 1):
for i in range(1, number_of_nodes + 1):
node = core.nodes.base.CoreNode(session=session, _id=i, name="n%d" % i, start=False)
node.setposition(x=150 * i, y=150)
node.server = daemon
@ -158,7 +158,7 @@ def main():
n.append(node)
# create remote links via API
for i in xrange(1, number_of_nodes + 1):
for i in range(1, number_of_nodes + 1):
tlvdata = coreapi.CoreLinkTlv.pack(LinkTlvs.N1_NUMBER.value, switch.id)
tlvdata += coreapi.CoreLinkTlv.pack(LinkTlvs.N2_NUMBER.value, i)
tlvdata += coreapi.CoreLinkTlv.pack(LinkTlvs.TYPE.value, LinkTypes.WIRED.value)

View file

@ -12,14 +12,15 @@
import datetime
import optparse
import sys
from builtins import range
import core.nodes.base
import core.nodes.network
from core import constants
from core.api.tlv import coreapi, dataconversion
from core.emulator.enumerations import CORE_API_PORT, EventTypes, EventTlvs, LinkTlvs, LinkTypes, MessageFlags
from core.nodes import ipaddress
from core.emulator.session import Session
from core.nodes import ipaddress
# node list (count from 1)
n = [None]
@ -80,7 +81,7 @@ def main():
num_remote = options.numnodes / 2 + options.numnodes % 2
print "creating %d (%d local / %d remote) nodes with addresses from %s" % \
(options.numnodes, num_local, num_remote, prefix)
for i in xrange(1, num_local + 1):
for i in range(1, num_local + 1):
node = session.create_node(cls=core.nodes.base.CoreNode, name="n%d" % i, _id=i)
node.newnetif(switch, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
node.cmd([constants.SYSCTL_BIN, "net.ipv4.icmp_echo_ignore_broadcasts=0"])
@ -91,7 +92,7 @@ def main():
session.broker.handlerawmsg(switch.tonodemsg(flags=flags))
# create remote nodes via API
for i in xrange(num_local + 1, options.numnodes + 1):
for i in range(num_local + 1, options.numnodes + 1):
node = core.nodes.base.CoreNode(session=session, _id=i, name="n%d" % i, start=False)
node.setposition(x=150 * i, y=150)
node.server = slave
@ -101,7 +102,7 @@ def main():
session.broker.handlerawmsg(node_message)
# create remote links via API
for i in xrange(num_local + 1, options.numnodes + 1):
for i in range(num_local + 1, options.numnodes + 1):
tlvdata = coreapi.CoreLinkTlv.pack(LinkTlvs.N1_NUMBER.value, switch.id)
tlvdata += coreapi.CoreLinkTlv.pack(LinkTlvs.N2_NUMBER.value, i)
tlvdata += coreapi.CoreLinkTlv.pack(LinkTlvs.TYPE.value, LinkTypes.WIRED.value)

View file

@ -13,15 +13,16 @@ import os
import random
import sys
import time
from builtins import range
from string import Template
import core.nodes.base
import core.nodes.network
from core.constants import QUAGGA_STATE_DIR
from core.nodes import ipaddress
from core.utils import check_cmd
# this is the /etc/core/core.conf default
from core.emulator.session import Session
from core.nodes import ipaddress
from core.utils import check_cmd
quagga_sbin_search = ("/usr/local/sbin", "/usr/sbin", "/usr/lib/quagga")
quagga_path = "zebra"
@ -243,14 +244,14 @@ class ManetExperiment(object):
self.session = Session(1)
# emulated network
self.net = self.session.create_node(cls=core.nodes.network.WlanNode)
for i in xrange(1, numnodes + 1):
for i in range(1, numnodes + 1):
addr = "%s/%s" % (prefix.addr(i), 32)
tmp = self.session.create_node(cls=ManetNode, ipaddr=addr, _id="%d" % i, name="n%d" % i)
tmp.newnetif(self.net, [addr])
self.nodes.append(tmp)
# connect nodes with probability linkprob
for i in xrange(numnodes):
for j in xrange(i + 1, numnodes):
for i in range(numnodes):
for j in range(i + 1, numnodes):
r = random.random()
if r < linkprob:
if self.verbose:
@ -265,7 +266,7 @@ class ManetExperiment(object):
self.net.link(self.nodes[i].netif(0), self.nodes[j].netif(0))
self.nodes[i].boot()
# run the boot.sh script on all nodes to start Quagga
for i in xrange(numnodes):
for i in range(numnodes):
self.nodes[i].cmd(["./%s" % self.nodes[i].bootsh])
def compareroutes(self, node, kr, zr):
@ -472,7 +473,7 @@ class ZebraRoutes(VtyshCmd):
args = "show ip route"
def parse(self):
for i in xrange(0, 3):
for i in range(0, 3):
# skip first three lines
self.out.readline()
r = []

View file

@ -43,8 +43,8 @@ from core import emane
from core.emane.bypass import EmaneBypassModel
from core.emane.nodes import EmaneNode
from core.emane.rfpipe import EmaneRfPipeModel
from core.nodes import ipaddress
from core.emulator.session import Session
from core.nodes import ipaddress
try:
import emaneeventservice
@ -416,7 +416,7 @@ class Experiment(object):
# emulated network
self.net = self.session.create_node(cls=core.nodes.network.WlanNode, name="wlan1")
prev = None
for i in xrange(1, numnodes + 1):
for i in range(1, numnodes + 1):
addr = "%s/%s" % (prefix.addr(i), 32)
tmp = self.session.create_node(cls=core.nodes.base.CoreNode, _id=i, name="n%d" % i)
tmp.newnetif(self.net, [addr])
@ -444,7 +444,7 @@ class Experiment(object):
self.net = self.session.create_node(cls=EmaneNode, _id=numnodes + 1, name="wlan1")
self.net.verbose = verbose
# self.session.emane.addobj(self.net)
for i in xrange(1, numnodes + 1):
for i in range(1, numnodes + 1):
addr = "%s/%s" % (prefix.addr(i), 32)
tmp = self.session.create_node(cls=core.nodes.base.CoreNode, _id=i, name="n%d" % i)
# tmp.setposition(i * 20, 50, None)
@ -461,7 +461,7 @@ class Experiment(object):
self.info("waiting %s sec (TAP bring-up)" % 2)
time.sleep(2)
for i in xrange(1, numnodes + 1):
for i in range(1, numnodes + 1):
tmp = self.nodes[i - 1]
self.session.services.boot_services(tmp)
self.staticroutes(i, prefix, numnodes)
@ -496,7 +496,7 @@ class Experiment(object):
self.warn("failed to add interface route: %s" % cmd)
# add static routes to all other nodes via left/right neighbors
for j in xrange(1, numnodes + 1):
for j in range(1, numnodes + 1):
if abs(j - i) < 2:
continue
addr = "%s" % prefix.addr(j)
@ -525,7 +525,7 @@ class Experiment(object):
otachannel=None)
old = False
for i in xrange(1, numnodes + 1):
for i in range(1, numnodes + 1):
rxnem = i
# inform rxnem that it can hear node to the left with 10dB noise
txnem = rxnem - 1

View file

@ -1,5 +1,6 @@
enum34==1.1.6
future==0.17.1
futures==3.2.0
grpcio==1.18.0
lxml==3.5.0
lxml==4.3.3
six==1.12.0

View file

@ -43,6 +43,7 @@ setup(
packages=find_packages(),
install_requires=[
"enum34",
"future",
"lxml"
],
tests_require=[