2019-10-04 20:36:15 +01:00
|
|
|
import logging
|
2020-02-04 17:48:37 +00:00
|
|
|
import time
|
2018-04-17 22:30:34 +01:00
|
|
|
|
2020-02-04 17:48:37 +00:00
|
|
|
import params
|
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-25 00:24:54 +01:00
|
|
|
address = prefixes.ip4_address(first_node)
|
2020-02-04 17:48:37 +00:00
|
|
|
logging.info("node %s pinging %s", last_node.name, address)
|
|
|
|
output = last_node.cmd(f"ping -c {args.count} {address}")
|
2019-10-22 23:13:28 +01:00
|
|
|
logging.info(output)
|
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)
|
2020-02-04 17:48:37 +00:00
|
|
|
args = params.parse("wlan")
|
|
|
|
start = time.perf_counter()
|
|
|
|
logging.info(
|
|
|
|
"running wlan example: nodes(%s) ping count(%s)", args.nodes, args.count
|
|
|
|
)
|
2019-10-22 23:13:28 +01:00
|
|
|
example(args)
|
2020-02-04 17:48:37 +00:00
|
|
|
logging.info("elapsed time: %s", time.perf_counter() - start)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|