2018-04-17 22:30:34 +01:00
|
|
|
import datetime
|
2019-10-04 20:36:15 +01:00
|
|
|
import logging
|
2019-09-10 22:20:51 +01:00
|
|
|
import parser
|
2018-04-17 22:30:34 +01:00
|
|
|
|
2018-05-01 18:40:25 +01:00
|
|
|
from core.emulator.coreemu import CoreEmu
|
2018-10-09 20:46:27 +01:00
|
|
|
from core.emulator.emudata import IpPrefixes, NodeOptions
|
2019-09-10 22:20:51 +01:00
|
|
|
from core.emulator.enumerations import EventTypes, NodeTypes
|
2019-04-30 07:31:47 +01:00
|
|
|
from core.location.mobility import BasicRangeModel
|
2019-02-16 17:50:19 +00:00
|
|
|
|
2018-04-17 22:30:34 +01:00
|
|
|
|
2019-10-22 23:13:28 +01:00
|
|
|
def example(args):
|
2018-04-17 22:30:34 +01:00
|
|
|
# ip generator for example
|
2018-04-25 00:24:54 +01:00
|
|
|
prefixes = IpPrefixes("10.83.0.0/16")
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
# create emulator instance for creating sessions and utility methods
|
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
|
|
|
|
2018-04-25 18:55:48 +01:00
|
|
|
# must be in configuration state for nodes to start, when using "node_add" below
|
2018-04-26 00:33:58 +01:00
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
2018-04-25 18:55:48 +01:00
|
|
|
|
2018-04-17 22:30:34 +01:00
|
|
|
# create wlan network node
|
2018-04-25 18:55:48 +01:00
|
|
|
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
2018-06-13 19:59:50 +01:00
|
|
|
session.mobility.set_model(wlan, BasicRangeModel)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
2018-10-09 20:46:27 +01:00
|
|
|
# create nodes, must set a position for wlan basic range model
|
2019-10-22 23:13:28 +01:00
|
|
|
options = NodeOptions(model="mdr")
|
|
|
|
options.set_position(0, 0)
|
|
|
|
for _ in range(args.nodes):
|
2019-10-22 23:31:50 +01:00
|
|
|
node = session.add_node(options=options)
|
2018-04-25 18:55:48 +01:00
|
|
|
interface = prefixes.create_interface(node)
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node.id, wlan.id, interface_one=interface)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# get nodes for example run
|
2019-04-30 07:31:47 +01:00
|
|
|
first_node = session.get_node(2)
|
2019-10-22 23:13:28 +01:00
|
|
|
last_node = session.get_node(args.nodes + 1)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
2019-10-18 18:33:31 +01:00
|
|
|
logging.info("starting iperf server on node: %s", first_node.name)
|
2019-10-19 07:28:09 +01:00
|
|
|
first_node.cmd("iperf -s -D")
|
2018-04-25 00:24:54 +01:00
|
|
|
address = prefixes.ip4_address(first_node)
|
2019-10-18 18:33:31 +01:00
|
|
|
logging.info("node %s connecting to %s", last_node.name, address)
|
2019-10-22 23:13:28 +01:00
|
|
|
output = last_node.cmd(f"iperf -t {args.time} -c {address}")
|
|
|
|
logging.info(output)
|
2019-10-19 07:28:09 +01:00
|
|
|
first_node.cmd("killall -9 iperf")
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
# shutdown session
|
2018-04-25 00:24:54 +01:00
|
|
|
coreemu.shutdown()
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2019-10-04 20:36:15 +01:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2019-10-22 23:13:28 +01:00
|
|
|
args = parser.parse("wlan")
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
start = datetime.datetime.now()
|
2019-10-22 23:13:28 +01:00
|
|
|
logging.info("running wlan example: nodes(%s) time(%s)", args.nodes, args.time)
|
|
|
|
example(args)
|
2019-10-18 18:33:31 +01:00
|
|
|
logging.info("elapsed time: %s", datetime.datetime.now() - start)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|