removed session manager, since CoreEmu does this now, set future examples to serve as API examples, removed netns examples that are replaced by these API variations

This commit is contained in:
Blake J. Harnden 2018-04-26 13:06:18 -07:00
parent 8644e9d61e
commit dc751dde2b
18 changed files with 12 additions and 996 deletions

View file

@ -113,8 +113,8 @@ class IdGen(object):
class FutureSession(Session):
def __init__(self, session_id, config=None, persistent=True, mkdir=True):
super(FutureSession, self).__init__(session_id, config, persistent, mkdir)
def __init__(self, session_id, config=None, mkdir=True):
super(FutureSession, self).__init__(session_id, config, mkdir)
# object management
self.node_id_gen = IdGen()

View file

@ -3,7 +3,6 @@ session.py: defines the Session class used by the core-daemon daemon program
that manages a CORE session.
"""
import atexit
import os
import pprint
import random
@ -52,68 +51,17 @@ node_map = nodemaps.NODES
nodeutils.set_node_map(node_map)
class SessionManager(object):
"""
Manages currently known sessions.
"""
sessions = set()
session_lock = threading.Lock()
@classmethod
def add(cls, session):
"""
Add a session to the manager.
:param Session session: session to add
:return: nothing
"""
with cls.session_lock:
logger.info("adding session to manager: %s", session.session_id)
cls.sessions.add(session)
@classmethod
def remove(cls, session):
"""
Remove session from the manager.
:param Session session: session to remove
:return: nothing
"""
with cls.session_lock:
logger.info("removing session from manager: %s", session.session_id)
if session in cls.sessions:
cls.sessions.remove(session)
else:
logger.info("session was already removed: %s", session.session_id)
@classmethod
def on_exit(cls):
"""
Method used to shutdown all currently known sessions, in case of unexpected exit.
:return: nothing
"""
logger.info("caught program exit, shutting down all known sessions")
while cls.sessions:
with cls.session_lock:
session = cls.sessions.pop()
logger.error("WARNING: automatically shutting down non-persistent session %s - %s",
session.session_id, session.name)
session.shutdown()
class Session(object):
"""
CORE session manager.
"""
def __init__(self, session_id, config=None, persistent=False, mkdir=True):
def __init__(self, session_id, config=None, mkdir=True):
"""
Create a Session instance.
:param int session_id: session id
:param dict config: session configuration
:param bool persistent: flag is session is considered persistent
:param bool mkdir: flag to determine if a directory should be made
"""
self.session_id = session_id
@ -152,9 +100,6 @@ class Session(object):
self.add_state_hook(state=EventTypes.RUNTIME_STATE.value, hook=self.runtime_state_hook)
if not persistent:
SessionManager.add(self)
self.master = False
# handlers for broadcasting information
@ -227,9 +172,6 @@ class Session(object):
for handler in self.shutdown_handlers:
handler(self)
# remove this session from the manager
SessionManager.remove(self)
def broadcast_event(self, event_data):
"""
Handle event data that should be provided to event handler.
@ -1514,7 +1456,3 @@ class SessionMetaData(ConfigurableManager):
:return: configuration items iterator
"""
return self.configs.iteritems()
# configure the program exit function to run
atexit.register(SessionManager.on_exit)

View file

@ -1,109 +0,0 @@
#!/usr/bin/python
#
# Copyright (c)2011-2012 the Boeing Company.
# See the LICENSE file included in this distribution.
#
# Test 3D range calculation of the BasicRangeModel by adding n nodes to a WLAN
# stacked 100 units above each other (using z-axis).
#
import datetime
import optparse
import sys
import time
from core.misc import ipaddress
from core.mobility import BasicRangeModel
from core.netns.nodes import WlanNode
from core.netns.vnet import EbtablesQueue
from core.netns.vnode import LxcNode
from core.session import Session
# node list - global so you can play using 'python -i'
# e.g. >>> n[0].session.shutdown()
n = []
def test(options):
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
session = Session(1, persistent=True)
if options.enablesdt:
# GUI default
session.location.setrefgeo(47.57917, -122.13232, 50.0)
session.location.refscale = 100.0
session.options.enablesdt = True
session.options.sdturl = options.sdturl
wlanid = options.numnodes + 1
net = session.add_object(
cls=WlanNode,
name="wlan%d" % wlanid,
objid=wlanid
)
values = list(BasicRangeModel.getdefaultvalues())
# values[0] = 5000000 # 5000km range
net.setmodel(BasicRangeModel, values)
for i in xrange(1, options.numnodes + 1):
node = session.add_object(cls=LxcNode, name="n%d" % i, objid=i)
address = "%s/%s" % (prefix.addr(i), prefix.prefixlen)
print "setting node address: %s - %s" % (node.objid, address)
node.newnetif(net, [address])
# set increasing Z coordinates
node.setposition(10, 10, 100)
n.append(node)
# example setting node n2 to a high altitude
# n[1].setposition(10, 10, 2000000) # 2000km
# session.sdt.updatenode(n[1].objid, 0, 10, 10, 2000000)
# launches terminal for the first node
n[0].client.icmd(["ping", "-c", "5", "127.0.0.1"])
# wait for rate seconds to allow ebtables commands to commit
time.sleep(EbtablesQueue.rate)
raw_input("press enter to exit")
session.shutdown()
def main():
usagestr = "usage: %prog [-h] [options] [args]"
parser = optparse.OptionParser(usage=usagestr)
parser.set_defaults(numnodes=2, enablesdt=False, sdturl="tcp://127.0.0.1:50000/")
parser.add_option(
"-n", "--numnodes", dest="numnodes", type=int,
help="number of nodes to test; default = %s" % parser.defaults["numnodes"]
)
parser.add_option("-s", "--sdt", dest="enablesdt", action="store_true", help="enable SDT output")
parser.add_option(
"-u", "--sdturl", dest="sdturl", type="string",
help="URL for SDT connection, default = %s" % parser.defaults["sdturl"]
)
def usage(msg=None, err=0):
sys.stdout.write("\n")
if msg:
sys.stdout.write(msg + "\n\n")
parser.print_help()
sys.exit(err)
# parse command line options
(options, args) = parser.parse_args()
if options.numnodes < 2:
usage("invalid number of nodes: %s" % options.numnodes)
for a in args:
sys.stderr.write("ignoring command line argument: '%s'\n" % a)
start = datetime.datetime.now()
test(options)
print >> sys.stderr, "elapsed time: %s" % (datetime.datetime.now() - start)
if __name__ == "__main__":
main()

View file

@ -105,7 +105,7 @@ def main():
start = datetime.datetime.now()
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
session = Session(1, persistent=True)
session = Session(1)
if "server" in globals():
server.addsession(session)
@ -125,7 +125,6 @@ def main():
# Set the local session id to match the port.
# Not necessary but seems neater.
# session.sessionid = session.broker.getserver("localhost")[2].getsockname()[1]
session.broker.setupserver(daemon)
# We do not want the recvloop running as we will deal ourselves

View file

@ -55,7 +55,7 @@ def main():
start = datetime.datetime.now()
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
session = Session(1, persistent=True)
session = Session(1)
if 'server' in globals():
server.addsession(session)

View file

@ -1,102 +0,0 @@
#!/usr/bin/python -i
# Copyright (c)2010-2014 the Boeing Company.
# See the LICENSE file included in this distribution.
# Example CORE Python script that attaches N nodes to an EMANE 802.11abg
# network. One of the parameters is changed, the pathloss mode.
import datetime
import optparse
import sys
from core import constants
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emane.nodes import EmaneNode
from core.misc import ipaddress
from core.netns import nodes
# node list (count from 1)
from core.session import Session
n = [None]
def main():
usagestr = "usage: %prog [-h] [options] [args]"
parser = optparse.OptionParser(usage=usagestr)
parser.set_defaults(numnodes=5)
parser.add_option("-n", "--numnodes", dest="numnodes", type=int,
help="number of nodes")
def usage(msg=None, err=0):
sys.stdout.write("\n")
if msg:
sys.stdout.write(msg + "\n\n")
parser.print_help()
sys.exit(err)
# parse command line options
(options, args) = parser.parse_args()
if options.numnodes < 1:
usage("invalid number of nodes: %s" % options.numnodes)
for a in args:
sys.stderr.write("ignoring command line argument: '%s'\n" % a)
start = datetime.datetime.now()
# IP subnet
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
# session with some EMANE initialization
cfg = {'verbose': 'false'}
session = Session(1, config=cfg, persistent=True)
session.master = True
session.location.setrefgeo(47.57917, -122.13232, 2.00000)
session.location.refscale = 150.0
session.config['emane_models'] = "RfPipe, Ieee80211abg, Bypass"
session.emane.loadmodels()
if 'server' in globals():
server.addsession(session)
# EMANE WLAN
print "creating EMANE WLAN wlan1"
wlan = session.add_object(cls=EmaneNode, name="wlan1")
wlan.setposition(x=80, y=50)
names = EmaneIeee80211abgModel.getnames()
values = list(EmaneIeee80211abgModel.getdefaultvalues())
# TODO: change any of the EMANE 802.11 parameter values here
for i in range(0, len(names)):
print "EMANE 80211 \"%s\" = \"%s\"" % (names[i], values[i])
try:
values[names.index('pathlossmode')] = '2ray'
except ValueError:
values[names.index('propagationmodel')] = '2ray'
session.emane.setconfig(wlan.objid, EmaneIeee80211abgModel.name, values)
services_str = "zebra|OSPFv3MDR|IPForward"
print "creating %d nodes with addresses from %s" % \
(options.numnodes, prefix)
for i in xrange(1, options.numnodes + 1):
tmp = session.add_object(cls=nodes.CoreNode, name="n%d" % i, objid=i)
tmp.newnetif(wlan, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
tmp.cmd([constants.SYSCTL_BIN, "net.ipv4.icmp_echo_ignore_broadcasts=0"])
tmp.setposition(x=150 * i, y=150)
session.services.addservicestonode(tmp, "", services_str)
n.append(tmp)
# this starts EMANE, etc.
session.node_count = str(options.numnodes + 1)
session.instantiate()
# start a shell on node 1
n[1].client.term("bash")
print "elapsed time: %s" % (datetime.datetime.now() - start)
if __name__ == "__main__" or __name__ == "__builtin__":
main()

View file

@ -106,7 +106,7 @@ def main():
parser.print_help()
sys.exit(err)
(options, args) = parser.parse_args()
options, args = parser.parse_args()
for a in args:
sys.stderr.write("ignoring command line argument: %s\n" % a)
@ -117,8 +117,7 @@ def main():
print "Testing how many network namespace nodes this machine can create."
print " - %s" % linuxversion()
mem = memfree()
print " - %.02f GB total memory (%.02f GB swap)" % \
(mem["total"] / GBD, mem["stotal"] / GBD)
print " - %.02f GB total memory (%.02f GB swap)" % (mem["total"] / GBD, mem["stotal"] / GBD)
print " - using IPv4 network prefix %s" % prefix
print " - using wait time of %s" % options.waittime
print " - using %d nodes per bridge" % options.bridges
@ -135,7 +134,7 @@ def main():
lfp.write("# numnodes,%s\n" % ",".join(MEMKEYS))
lfp.flush()
session = Session(1, persistent=True)
session = Session(1)
switch = session.add_object(cls=nodes.SwitchNode)
switchlist.append(switch)
print "Added bridge %s (%d)." % (switch.brname, len(switchlist))
@ -146,15 +145,14 @@ def main():
i += 1
# optionally add a bridge (options.bridges nodes per bridge)
try:
if options.bridges > 0 and switch.numnetif() >= options.bridges:
if 0 < options.bridges <= switch.numnetif():
switch = session.add_object(cls=nodes.SwitchNode)
switchlist.append(switch)
print "\nAdded bridge %s (%d) for node %d." % \
(switch.brname, len(switchlist), i)
print "\nAdded bridge %s (%d) for node %d." % (switch.brname, len(switchlist), i)
except Exception, e:
print "At %d bridges (%d nodes) caught exception:\n%s\n" % \
(len(switchlist), i - 1, e)
print "At %d bridges (%d nodes) caught exception:\n%s\n" % (len(switchlist), i - 1, e)
break
# create a node
try:
n = session.add_object(cls=nodes.LxcNode, name="n%d" % i)

View file

@ -1,103 +0,0 @@
#!/usr/bin/python
# Copyright (c)2013 the Boeing Company.
# See the LICENSE file included in this distribution.
# This script creates a CORE session, that will connect n nodes together
# in a chain, with static routes between nodes
# number of nodes / number of hops
# 2 0
# 3 1
# 4 2
# n n - 2
#
# Use core-cleanup to clean up after this script as the session is left running.
#
import datetime
import optparse
import sys
from core import constants
from core.misc import ipaddress
from core.netns import nodes
# node list (count from 1)
from core.session import Session
n = [None]
def main():
usagestr = "usage: %prog [-h] [options] [args]"
parser = optparse.OptionParser(usage=usagestr)
parser.set_defaults(numnodes=5)
parser.add_option("-n", "--numnodes", dest="numnodes", type=int,
help="number of nodes")
def usage(msg=None, err=0):
sys.stdout.write("\n")
if msg:
sys.stdout.write(msg + "\n\n")
parser.print_help()
sys.exit(err)
# parse command line options
(options, args) = parser.parse_args()
if options.numnodes < 1:
usage("invalid number of nodes: %s" % options.numnodes)
if options.numnodes >= 255:
usage("invalid number of nodes: %s" % options.numnodes)
for a in args:
sys.stderr.write("ignoring command line argument: '%s'\n" % a)
start = datetime.datetime.now()
session = Session(1, persistent=True)
if 'server' in globals():
server.addsession(session)
print "creating %d nodes" % options.numnodes
left = None
prefix = None
for i in xrange(1, options.numnodes + 1):
tmp = session.add_object(cls=nodes.CoreNode, name="n%d" % i, objid=i)
if left:
tmp.newnetif(left, ["%s/%s" % (prefix.addr(2), prefix.prefixlen)])
# limit: i < 255
prefix = ipaddress.Ipv4Prefix("10.83.%d.0/24" % i)
right = session.add_object(cls=nodes.PtpNet)
tmp.newnetif(right, ["%s/%s" % (prefix.addr(1), prefix.prefixlen)])
tmp.cmd([constants.SYSCTL_BIN, "net.ipv4.icmp_echo_ignore_broadcasts=0"])
tmp.cmd([constants.SYSCTL_BIN, "net.ipv4.conf.all.forwarding=1"])
tmp.cmd([constants.SYSCTL_BIN, "net.ipv4.conf.default.rp_filter=0"])
tmp.setposition(x=100 * i, y=150)
n.append(tmp)
left = right
prefixes = map(lambda (x): ipaddress.Ipv4Prefix("10.83.%d.0/24" % x),
xrange(1, options.numnodes + 1))
# set up static routing in the chain
for i in xrange(1, options.numnodes + 1):
for j in xrange(1, options.numnodes + 1):
if j < i - 1:
gw = prefixes[i - 2].addr(1)
elif j > i:
if i > len(prefixes) - 1:
continue
gw = prefixes[i - 1].addr(2)
else:
continue
net = prefixes[j - 1]
n[i].cmd([constants.IP_BIN, "route", "add", str(net), "via", str(gw)])
print "elapsed time: %s" % (datetime.datetime.now() - start)
if __name__ == "__main__" or __name__ == "__builtin__":
main()

View file

@ -1,290 +0,0 @@
#!/bin/sh -e
#
# iperf-performance.sh
#
# (c)2013 the Boeing Company
# authors: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
#
# Utility script to automate several iperf runs.
#
# number of iperf runs per test
NUMRUNS=10
# number of seconds per run (10s is iperf default)
RUNTIME=10
# logging
LOG=/tmp/${0}.log
STAMP=`date +%Y%m%d%H%M%S`
#
# client---(loopback)---server
#
loopbacktest () {
killall iperf 2> /dev/null || true
echo ">> loopback iperf test"
echo "loopback" > ${LOG}
# start an iperf server in the background
# -s = server
# -y c = CSV output
echo "starting local iperf server"
iperf -s -y c >> ${LOG} &
# run an iperf client NUMRUNS times
i=1
while [ $i -le $NUMRUNS ]; do
echo "run $i/$NUMRUNS:"
iperf -t ${RUNTIME} -c localhost
sleep 0.3
i=$((i+1))
done
sleep 1
echo "stopping local iperf server"
killall -v iperf
}
#
# lxc1( client )---veth-pair---lxc2( server )
#
lxcvethtest () {
SERVERIP=10.0.0.1
CLIENTIP=10.0.0.2
SERVER=/tmp/${0}-server
CLIENT=/tmp/${0}-client
echo ">> lxc veth iperf test"
echo "lxcveth" >> ${LOG}
echo "starting lxc iperf server"
vnoded -l $SERVER.log -p $SERVER.pid -c $SERVER
ip link add name veth0.1 type veth peer name veth0
ip link set veth0 netns `cat $SERVER.pid` up
vcmd -c $SERVER -- ip link set lo up
vcmd -c $SERVER -- ip addr add $SERVERIP/24 dev veth0
vcmd -c $SERVER -- iperf -s -y c >> ${LOG} &
echo "starting lxc iperf client"
vnoded -l $CLIENT.log -p $CLIENT.pid -c $CLIENT
ip link set veth0.1 netns `cat $CLIENT.pid` up
vcmd -c $CLIENT -- ip link set lo up
vcmd -c $CLIENT -- ip addr add $CLIENTIP/24 dev veth0.1
i=1
while [ $i -le $NUMRUNS ]; do
echo "run $i/$NUMRUNS:"
vcmd -c $CLIENT -- iperf -t ${RUNTIME} -c ${SERVERIP}
sleep 0.3
i=$((i+1))
done
sleep 1
echo "stopping lxc iperf server"
vcmd -c $SERVER -- killall -v iperf
echo "stopping containers"
kill -9 `cat $SERVER.pid`
kill -9 `cat $CLIENT.pid`
echo "cleaning up"
rm -f ${SERVER}*
rm -f ${CLIENT}*
}
#
# lxc1( client veth:):veth---bridge---veth:(:veth server )lxc2
#
lxcbrtest () {
SERVERIP=10.0.0.1
CLIENTIP=10.0.0.2
SERVER=/tmp/${0}-server
CLIENT=/tmp/${0}-client
BRIDGE="lxcbrtest"
echo ">> lxc bridge iperf test"
echo "lxcbr" >> ${LOG}
echo "building bridge"
brctl addbr $BRIDGE
brctl stp $BRIDGE off # disable spanning tree protocol
brctl setfd $BRIDGE 0 # disable forwarding delay
ip link set $BRIDGE up
echo "starting lxc iperf server"
vnoded -l $SERVER.log -p $SERVER.pid -c $SERVER
ip link add name veth0.1 type veth peer name veth0
ip link set veth0 netns `cat $SERVER.pid` up
vcmd -c $SERVER -- ip link set lo up
vcmd -c $SERVER -- ip addr add $SERVERIP/24 dev veth0
brctl addif $BRIDGE veth0.1
ip link set veth0.1 up
vcmd -c $SERVER -- iperf -s -y c >> ${LOG} &
echo "starting lxc iperf client"
vnoded -l $CLIENT.log -p $CLIENT.pid -c $CLIENT
ip link add name veth1.1 type veth peer name veth1
ip link set veth1 netns `cat $CLIENT.pid` up
vcmd -c $CLIENT -- ip link set lo up
vcmd -c $CLIENT -- ip addr add $CLIENTIP/24 dev veth1
brctl addif $BRIDGE veth1.1
ip link set veth1.1 up
i=1
while [ $i -le $NUMRUNS ]; do
echo "run $i/$NUMRUNS:"
vcmd -c $CLIENT -- iperf -t ${RUNTIME} -c ${SERVERIP}
sleep 0.3
i=$((i+1))
done
sleep 1
echo "stopping lxc iperf server"
vcmd -c $SERVER -- killall -v iperf
echo "stopping containers"
kill -9 `cat $SERVER.pid`
kill -9 `cat $CLIENT.pid`
echo "cleaning up"
ip link set $BRIDGE down
brctl delbr $BRIDGE
rm -f ${SERVER}*
rm -f ${CLIENT}*
}
#
# n1---n2---n3--- ... ---nN
# N nodes (N-2 hops) in chain with static routing
#
chaintest () {
NUMNODES=$1
SERVERIP=10.83.$NUMNODES.1
if [ -d /tmp/pycore.* ]; then
echo "/tmp/pycore.* already exists, skipping chaintest $NUMNODES"
return
fi
echo ">> n=$NUMNODES node chain iperf test"
echo "chain$NUMNODES" >> ${LOG}
echo "running external chain CORE script with '-n $NUMNODES'"
python iperf-performance-chain.py -n $NUMNODES
echo "starting lxc iperf server on node $NUMNODES"
vcmd -c /tmp/pycore.*/n$NUMNODES -- iperf -s -y c >> ${LOG} &
echo "starting lxc iperf client"
i=1
while [ $i -le $NUMRUNS ]; do
echo "run $i/$NUMRUNS:"
vcmd -c /tmp/pycore.*/n1 -- iperf -t ${RUNTIME} -c ${SERVERIP}
sleep 0.3
i=$((i+1))
done
sleep 1
echo "stopping lxc iperf server"
vcmd -c /tmp/pycore.*/n$NUMNODES -- killall -v iperf
echo "cleaning up"
core-cleanup
}
if [ "z$1" != "z" ]; then
echo "This script takes no parameters and must be run as root."
exit 1
fi
if [ `id -u` != 0 ]; then
echo "This script must be run as root."
exit 1
fi
#
# N lxc clients >---bridge---veth:(:veth server )
#
clientstest () {
NUMCLIENTS=$1
SERVERIP=10.0.0.1
SERVER=/tmp/${0}-server
BRIDGE="lxcbrtest"
echo ">> n=$NUMCLIENTS clients iperf test"
echo "clients$NUMCLIENTS" >> ${LOG}
echo "building bridge"
brctl addbr $BRIDGE
brctl stp $BRIDGE off # disable spanning tree protocol
brctl setfd $BRIDGE 0 # disable forwarding delay
ip link set $BRIDGE up
echo "starting lxc iperf server"
vnoded -l $SERVER.log -p $SERVER.pid -c $SERVER
ip link add name veth0.1 type veth peer name veth0
ip link set veth0 netns `cat $SERVER.pid` up
vcmd -c $SERVER -- ip link set lo up
vcmd -c $SERVER -- ip addr add $SERVERIP/24 dev veth0
brctl addif $BRIDGE veth0.1
ip link set veth0.1 up
vcmd -c $SERVER -- iperf -s -y c >> ${LOG} &
i=1
CLIENTS=""
while [ $i -le $NUMCLIENTS ]; do
echo "starting lxc iperf client $i/$NUMCLIENTS"
CLIENT=/tmp/${0}-client$i
CLIENTIP=10.0.0.1$i
vnoded -l $CLIENT.log -p $CLIENT.pid -c $CLIENT
ip link add name veth1.$i type veth peer name veth1
ip link set veth1 netns `cat $CLIENT.pid` up
vcmd -c $CLIENT -- ip link set lo up
vcmd -c $CLIENT -- ip addr add $CLIENTIP/24 dev veth1
brctl addif $BRIDGE veth1.$i
ip link set veth1.$i up
i=$((i+1))
CLIENTS="$CLIENTS $CLIENT"
done
j=1
while [ $j -le $NUMRUNS ]; do
echo "run $j/$NUMRUNS iperf:"
for CLIENT in $CLIENTS; do
vcmd -c $CLIENT -- iperf -t ${RUNTIME} -c ${SERVERIP} &
done
sleep ${RUNTIME} 1
j=$((j+1))
done
sleep 1
echo "stopping lxc iperf server"
vcmd -c $SERVER -- killall -v iperf
echo "stopping containers"
kill -9 `cat $SERVER.pid`
for CLIENT in $CLIENTS; do
kill -9 `cat $CLIENT.pid`
done
# time needed for processes/containers to shut down
sleep 2
echo "cleaning up"
ip link set $BRIDGE down
brctl delbr $BRIDGE
rm -f ${SERVER}*
rm -f /tmp/${0}-client*
# time needed for bridge clean-up
sleep 1
}
#
# run all tests
#
loopbacktest
lxcvethtest
lxcbrtest
chaintest 5
chaintest 10
clientstest 5
clientstest 10
clientstest 15
mv ${LOG} ${PWD}/${0}-${STAMP}.log
echo "===> results in ${PWD}/${0}-${STAMP}.log"

View file

@ -1,76 +0,0 @@
#!/usr/bin/python -i
# Copyright (c)2010-2013 the Boeing Company.
# See the LICENSE file included in this distribution.
# connect n nodes to a virtual switch/hub
import datetime
import optparse
import sys
from core import constants
from core.misc import ipaddress
from core.netns import nodes
# node list (count from 1)
from core.session import Session
n = [None]
def main():
usagestr = "usage: %prog [-h] [options] [args]"
parser = optparse.OptionParser(usage=usagestr)
parser.set_defaults(numnodes=5)
parser.add_option("-n", "--numnodes", dest="numnodes", type=int,
help="number of nodes")
def usage(msg=None, err=0):
sys.stdout.write("\n")
if msg:
sys.stdout.write(msg + "\n\n")
parser.print_help()
sys.exit(err)
# parse command line options
(options, args) = parser.parse_args()
if options.numnodes < 1:
usage("invalid number of nodes: %s" % options.numnodes)
for a in args:
sys.stderr.write("ignoring command line argument: '%s'\n" % a)
start = datetime.datetime.now()
# IP subnet
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
session = Session(1, persistent=True)
if 'server' in globals():
server.addsession(session)
# emulated Ethernet switch
switch = session.add_object(cls=nodes.SwitchNode, name="switch")
switch.setposition(x=80, y=50)
print "creating %d nodes with addresses from %s" % (options.numnodes, prefix)
for i in xrange(1, options.numnodes + 1):
tmp = session.add_object(cls=nodes.CoreNode, name="n%d" % i, objid=i)
tmp.newnetif(switch, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
tmp.cmd([constants.SYSCTL_BIN, "net.ipv4.icmp_echo_ignore_broadcasts=0"])
tmp.setposition(x=150 * i, y=150)
n.append(tmp)
session.node_count = str(options.numnodes + 1)
session.instantiate()
print "elapsed time: %s" % (datetime.datetime.now() - start)
# start a shell on node 1
n[1].client.term("bash")
raw_input("press enter to exit")
session.shutdown()
if __name__ == "__main__" or __name__ == "__builtin__":
main()

View file

@ -1,104 +0,0 @@
#!/usr/bin/python
# Copyright (c)2010-2012 the Boeing Company.
# See the LICENSE file included in this distribution.
# run iperf to measure the effective throughput between two nodes when
# n nodes are connected to a virtual hub/switch; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep
import datetime
import optparse
import sys
from core.misc import ipaddress
from core.misc.utils import check_cmd
from core.netns import nodes
from core.session import Session
try:
check_cmd(["iperf", "-v"])
except OSError:
sys.stderr.write("ERROR: running iperf failed\n")
sys.exit(1)
def test(numnodes, testsec):
# node list
n = []
# IP subnet
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
session = Session(1)
# emulated network
net = session.add_object(cls=nodes.SwitchNode)
for i in xrange(1, numnodes + 1):
tmp = session.add_object(cls=nodes.LxcNode, name="n%d" % i)
tmp.newnetif(net, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
n.append(tmp)
n[0].cmd(["iperf", "-s", "-D"])
n[-1].client.icmd(["iperf", "-t", str(int(testsec)), "-c", str(prefix.addr(1))])
n[0].cmd(["killall", "-9", "iperf"])
raw_input("press enter to exit")
session.shutdown()
def main():
usagestr = "usage: %prog [-h] [options] [args]"
parser = optparse.OptionParser(usage=usagestr)
parser.set_defaults(minnodes=2)
parser.add_option("-m", "--minnodes", dest="minnodes", type=int,
help="min number of nodes to test; default = %s" %
parser.defaults["minnodes"])
parser.set_defaults(maxnodes=2)
parser.add_option("-n", "--maxnodes", dest="maxnodes", type=int,
help="max number of nodes to test; default = %s" %
parser.defaults["maxnodes"])
parser.set_defaults(testsec=10)
parser.add_option("-t", "--testsec", dest="testsec", type=int,
help="test time in seconds; default = %s" %
parser.defaults["testsec"])
parser.set_defaults(nodestep=1)
parser.add_option("-s", "--nodestep", dest="nodestep", type=int,
help="number of nodes step size; default = %s" %
parser.defaults["nodestep"])
def usage(msg=None, err=0):
sys.stdout.write("\n")
if msg:
sys.stdout.write(msg + "\n\n")
parser.print_help()
sys.exit(err)
# parse command line options
(options, args) = parser.parse_args()
if options.minnodes < 2:
usage("invalid min number of nodes: %s" % options.minnodes)
if options.maxnodes < options.minnodes:
usage("invalid max number of nodes: %s" % options.maxnodes)
if options.testsec < 1:
usage("invalid test time: %s" % options.testsec)
if options.nodestep < 1:
usage("invalid node step: %s" % options.nodestep)
for a in args:
sys.stderr.write("ignoring command line argument: '%s'\n" % a)
start = datetime.datetime.now()
for i in xrange(options.minnodes, options.maxnodes + 1, options.nodestep):
print >> sys.stderr, "%s node test:" % i
test(i, options.testsec)
print >> sys.stderr, ""
print >> sys.stderr, "elapsed time: %s" % (datetime.datetime.now() - start)
if __name__ == "__main__":
main()

View file

@ -1,33 +0,0 @@
#!/bin/sh -e
# Below is a transcript of creating two emulated nodes and connecting them
# together with a wired link. You can run the core-cleanup script to clean
# up after this script.
# create node 1 namespace container
vnoded -c /tmp/n1.ctl -l /tmp/n1.log -p /tmp/n1.pid
# create a virtual Ethernet (veth) pair, installing one end into node 1
ip link add name n1.0.1 type veth peer name n1.0
ip link set n1.0 netns `cat /tmp/n1.pid`
vcmd -c /tmp/n1.ctl -- /bin/sh -e -c \
"ip link set lo up && ip link set n1.0 name eth0 up && ip addr add 10.0.0.1/24 dev eth0"
# create node 2 namespace container
vnoded -c /tmp/n2.ctl -l /tmp/n2.log -p /tmp/n2.pid
# create a virtual Ethernet (veth) pair, installing one end into node 2
ip link add name n2.0.1 type veth peer name n2.0
ip link set n2.0 netns `cat /tmp/n2.pid`
vcmd -c /tmp/n2.ctl -- /bin/sh -e -c \
"ip link set lo up && ip link set n2.0 name eth0 up && ip addr add 10.0.0.2/24 dev eth0"
# bridge together nodes 1 and 2 using the other end of each veth pair
brctl addbr b.1.1
brctl setfd b.1.1 0
brctl addif b.1.1 n1.0.1
brctl addif b.1.1 n2.0.1
ip link set n1.0.1 up
ip link set n2.0.1 up
ip link set b.1.1 up
# display connectivity and ping from node 1 to node 2
brctl show
vcmd -c /tmp/n1.ctl -- ping 10.0.0.2

View file

@ -1,102 +0,0 @@
#!/usr/bin/python
# Copyright (c)2010-2012 the Boeing Company.
# See the LICENSE file included in this distribution.
# run iperf to measure the effective throughput between two nodes when
# n nodes are connected to a virtual wlan; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep
import datetime
import optparse
import sys
from core.misc import ipaddress
from core.misc.utils import check_cmd
from core.netns import nodes
from core.session import Session
try:
check_cmd(["iperf", "-v"])
except OSError:
sys.stderr.write("ERROR: running iperf failed\n")
sys.exit(1)
def test(numnodes, testsec):
# node list
n = []
# IP subnet
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
session = Session(1)
# emulated network
net = session.add_object(cls=nodes.WlanNode)
for i in xrange(1, numnodes + 1):
tmp = session.add_object(cls=nodes.LxcNode, objid="%d" % i, name="n%d" % i)
tmp.newnetif(net, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
n.append(tmp)
net.link(n[0].netif(0), n[-1].netif(0))
n[0].cmd(["iperf", "-s", "-D"])
n[-1].client.icmd(["iperf", "-t", str(int(testsec)), "-c", str(prefix.addr(1))])
n[0].cmd(["killall", "-9", "iperf"])
session.shutdown()
def main():
usagestr = "usage: %prog [-h] [options] [args]"
parser = optparse.OptionParser(usage=usagestr)
parser.set_defaults(minnodes=2)
parser.add_option("-m", "--minnodes", dest="minnodes", type=int,
help="min number of nodes to test; default = %s" % parser.defaults["minnodes"])
parser.set_defaults(maxnodes=2)
parser.add_option("-n", "--maxnodes", dest="maxnodes", type=int,
help="max number of nodes to test; default = %s" %
parser.defaults["maxnodes"])
parser.set_defaults(testsec=10)
parser.add_option("-t", "--testsec", dest="testsec", type=int,
help="test time in seconds; default = %s" %
parser.defaults["testsec"])
parser.set_defaults(nodestep=1)
parser.add_option("-s", "--nodestep", dest="nodestep", type=int,
help="number of nodes step size; default = %s" %
parser.defaults["nodestep"])
def usage(msg=None, err=0):
sys.stdout.write("\n")
if msg:
sys.stdout.write(msg + "\n\n")
parser.print_help()
sys.exit(err)
# parse command line options
(options, args) = parser.parse_args()
if options.minnodes < 2:
usage("invalid min number of nodes: %s" % options.minnodes)
if options.maxnodes < options.minnodes:
usage("invalid max number of nodes: %s" % options.maxnodes)
if options.testsec < 1:
usage("invalid test time: %s" % options.testsec)
if options.nodestep < 1:
usage("invalid node step: %s" % options.nodestep)
for a in args:
sys.stderr.write("ignoring command line argument: '%s'\n" % a)
start = datetime.datetime.now()
for i in xrange(options.minnodes, options.maxnodes + 1, options.nodestep):
print >> sys.stderr, "%s node test:" % i
test(i, options.testsec)
print >> sys.stderr, ""
print >> sys.stderr, "elapsed time: %s" % (datetime.datetime.now() - start)
if __name__ == "__main__":
main()