initial toy code for future core api changes/improvements
This commit is contained in:
parent
7e03202ba4
commit
9fe57c6089
6 changed files with 372 additions and 0 deletions
54
daemon/examples/future/emane80211.py
Normal file
54
daemon/examples/future/emane80211.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/python -i
|
||||
#
|
||||
# Example CORE Python script that attaches N nodes to an EMANE 802.11abg network.
|
||||
|
||||
import datetime
|
||||
|
||||
import parser
|
||||
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||
from core.future.coreemu import FutureIpv4Prefix, CoreEmu
|
||||
|
||||
|
||||
def example(options):
|
||||
# ip generator for example
|
||||
prefix = FutureIpv4Prefix("10.83.0.0/16")
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
# create emane network node
|
||||
emane_network = session.create_emane_network(
|
||||
model=EmaneIeee80211abgModel,
|
||||
geo_reference=(47.57917, -122.13232, 2.00000)
|
||||
)
|
||||
emane_network.setposition(x=80, y=50)
|
||||
|
||||
# create nodes
|
||||
for i in xrange(options.nodes):
|
||||
node = session.create_emane_node()
|
||||
coreemu.add_interface(emane_network, node, prefix)
|
||||
node.setposition(x=150 * (i + 1), y=150)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
|
||||
# start a shell on the first node
|
||||
node = session.get_object(2)
|
||||
node.client.term("bash")
|
||||
|
||||
# shutdown session
|
||||
raw_input("press enter to exit...")
|
||||
session.shutdown()
|
||||
|
||||
|
||||
def main():
|
||||
options = parser.parse_options("emane80211")
|
||||
start = datetime.datetime.now()
|
||||
print "running emane 80211 example: nodes(%s) time(%s)" % (options.nodes, options.time)
|
||||
example(options)
|
||||
print "elapsed time: %s" % (datetime.datetime.now() - start)
|
||||
|
||||
|
||||
if __name__ == "__main__" or __name__ == "__builtin__":
|
||||
main()
|
41
daemon/examples/future/parser.py
Normal file
41
daemon/examples/future/parser.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
import argparse
|
||||
|
||||
DEFAULT_NODES = 2
|
||||
DEFAULT_TIME = 10
|
||||
DEFAULT_STEP = 1
|
||||
|
||||
|
||||
def parse_options(name):
|
||||
parser = argparse.ArgumentParser(description="Run %s example" % name)
|
||||
parser.add_argument("-n", "--nodes", type=int, default=DEFAULT_NODES,
|
||||
help="number of nodes to create in this example")
|
||||
parser.add_argument("-t", "--time", type=int, default=DEFAULT_TIME,
|
||||
help="example iperf run time in seconds")
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
# usagestr = "usage: %prog [-h] [options] [args]"
|
||||
# parser = optparse.OptionParser(usage=usagestr)
|
||||
#
|
||||
# parser.add_option("-n", "--nodes", dest="nodes", type=int, default=DEFAULT_NODES,
|
||||
# help="number of nodes to create in this example")
|
||||
#
|
||||
# parser.add_option("-t", "--time", dest="time", type=int, default=DEFAULT_TIME,
|
||||
# help="example iperf run time in seconds")
|
||||
|
||||
# def usage(msg=None, err=0):
|
||||
# print
|
||||
# if msg:
|
||||
# print "%s\n" % msg
|
||||
# parser.print_help()
|
||||
# sys.exit(err)
|
||||
|
||||
# parse command line options
|
||||
# options, args = parser.parse_args()
|
||||
|
||||
if options.nodes < 2:
|
||||
parser.error("invalid min number of nodes: %s" % options.nodes)
|
||||
if options.time < 1:
|
||||
parser.error("invalid test time: %s" % options.time)
|
||||
|
||||
return options
|
59
daemon/examples/future/switch.py
Normal file
59
daemon/examples/future/switch.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# 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 parser
|
||||
from core.future.coreemu import FutureIpv4Prefix, CoreEmu
|
||||
from core.netns.nodes import CoreNode, SwitchNode
|
||||
|
||||
|
||||
def example(options):
|
||||
# ip generator for example
|
||||
prefix = FutureIpv4Prefix("10.83.0.0/16")
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
# create switch network node
|
||||
switch_network = session.create_node(cls=SwitchNode)
|
||||
|
||||
# create nodes
|
||||
for _ in xrange(options.nodes):
|
||||
node = session.create_node(cls=CoreNode)
|
||||
coreemu.add_interface(switch_network, node, prefix)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
|
||||
# get nodes to run example
|
||||
first_node = session.get_object(2)
|
||||
last_node = session.get_object(options.nodes + 1)
|
||||
|
||||
print "starting iperf server on node: %s" % first_node.name
|
||||
first_node.cmd(["iperf", "-s", "-D"])
|
||||
address = str(prefix.addr(first_node.objid))
|
||||
print "node %s connecting to %s" % (last_node.name, address)
|
||||
last_node.client.icmd(["iperf", "-t", str(options.time), "-c", address])
|
||||
first_node.cmd(["killall", "-9", "iperf"])
|
||||
|
||||
# shutdown session
|
||||
session.shutdown()
|
||||
|
||||
|
||||
def main():
|
||||
options = parser.parse_options("switch")
|
||||
|
||||
start = datetime.datetime.now()
|
||||
print "running switch example: nodes(%s) time(%s)" % (options.nodes, options.time)
|
||||
example(options)
|
||||
print "elapsed time: %s" % (datetime.datetime.now() - start)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
66
daemon/examples/future/wlan.py
Normal file
66
daemon/examples/future/wlan.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# 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 parser
|
||||
from core.future.coreemu import FutureIpv4Prefix, CoreEmu
|
||||
from core.mobility import BasicRangeModel
|
||||
from core.netns.nodes import WlanNode, CoreNode
|
||||
|
||||
|
||||
def example(options):
|
||||
# ip generator for example
|
||||
prefix = FutureIpv4Prefix("10.83.0.0/16")
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
# create wlan network node
|
||||
wlan_network = session.create_node(cls=WlanNode)
|
||||
coreemu.set_wireless_model(wlan_network, BasicRangeModel)
|
||||
|
||||
# create nodes
|
||||
wireless_nodes = []
|
||||
for _ in xrange(options.nodes):
|
||||
node = session.create_node(cls=CoreNode)
|
||||
coreemu.add_interface(wlan_network, node, prefix)
|
||||
wireless_nodes.append(node)
|
||||
|
||||
# link all created nodes with the wireless network
|
||||
coreemu.wireless_link_all(wlan_network, wireless_nodes)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
|
||||
# get nodes for example run
|
||||
first_node = session.get_object(2)
|
||||
last_node = session.get_object(options.nodes + 1)
|
||||
|
||||
print "starting iperf server on node: %s" % first_node.name
|
||||
first_node.cmd(["iperf", "-s", "-D"])
|
||||
address = str(prefix.addr(first_node.objid))
|
||||
print "node %s connecting to %s" % (last_node.name, address)
|
||||
last_node.client.icmd(["iperf", "-t", str(options.time), "-c", address])
|
||||
first_node.cmd(["killall", "-9", "iperf"])
|
||||
|
||||
# shutdown session
|
||||
session.shutdown()
|
||||
|
||||
|
||||
def main():
|
||||
options = parser.parse_options("wlan")
|
||||
|
||||
start = datetime.datetime.now()
|
||||
print "running wlan example: nodes(%s) time(%s)" % (options.nodes, options.time)
|
||||
example(options)
|
||||
print "elapsed time: %s" % (datetime.datetime.now() - start)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue