From 866e13e0ef4e56f5da9655957b4e71a9c0ef6362 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Tue, 4 Feb 2020 09:48:37 -0800 Subject: [PATCH] removed usage of iperf in examples, to remove need of another dependency, renamed parser module examples used to avoid conflict with std library module --- .../examples/python/{parser.py => params.py} | 10 ++++---- daemon/examples/python/switch.py | 22 ++++++++---------- daemon/examples/python/wlan.py | 23 ++++++++----------- 3 files changed, 25 insertions(+), 30 deletions(-) rename daemon/examples/python/{parser.py => params.py} (74%) diff --git a/daemon/examples/python/parser.py b/daemon/examples/python/params.py similarity index 74% rename from daemon/examples/python/parser.py rename to daemon/examples/python/params.py index 28c81343..1fc64ca9 100644 --- a/daemon/examples/python/parser.py +++ b/daemon/examples/python/params.py @@ -15,18 +15,18 @@ def parse(name): help="number of nodes to create in this example", ) parser.add_argument( - "-t", - "--time", + "-c", + "--count", type=int, default=DEFAULT_TIME, - help="example iperf run time in seconds", + help="number of time to ping node", ) args = parser.parse_args() if args.nodes < 2: parser.error(f"invalid min number of nodes: {args.nodes}") - if args.time < 1: - parser.error(f"invalid test time: {args.time}") + if args.count < 1: + parser.error(f"invalid ping count({args.count}), count must be greater than 0") return args diff --git a/daemon/examples/python/switch.py b/daemon/examples/python/switch.py index 6277149c..afb7c472 100644 --- a/daemon/examples/python/switch.py +++ b/daemon/examples/python/switch.py @@ -1,7 +1,7 @@ -import datetime import logging -import parser +import time +import params from core.emulator.coreemu import CoreEmu from core.emulator.emudata import IpPrefixes from core.emulator.enumerations import EventTypes, NodeTypes @@ -33,14 +33,10 @@ def example(args): # get nodes to run example first_node = session.get_node(2) last_node = session.get_node(args.nodes + 1) - - logging.info("starting iperf server on node: %s", first_node.name) - first_node.cmd("iperf -s -D") first_node_address = prefixes.ip4_address(first_node) - logging.info("node %s connecting to %s", last_node.name, first_node_address) - output = last_node.cmd(f"iperf -t {args.time} -c {first_node_address}") + logging.info("node %s pinging %s", last_node.name, first_node_address) + output = last_node.cmd(f"ping -c {args.count} {first_node_address}") logging.info(output) - first_node.cmd("killall -9 iperf") # shutdown session coreemu.shutdown() @@ -48,11 +44,13 @@ def example(args): def main(): logging.basicConfig(level=logging.INFO) - args = parser.parse("switch") - start = datetime.datetime.now() - logging.info("running switch example: nodes(%s) time(%s)", args.nodes, args.time) + args = params.parse("switch") + start = time.perf_counter() + logging.info( + "running switch example: nodes(%s) ping count(%s)", args.nodes, args.count + ) example(args) - logging.info("elapsed time: %s", datetime.datetime.now() - start) + logging.info("elapsed time: %s", time.perf_counter() - start) if __name__ == "__main__": diff --git a/daemon/examples/python/wlan.py b/daemon/examples/python/wlan.py index 7c23d411..f601dced 100644 --- a/daemon/examples/python/wlan.py +++ b/daemon/examples/python/wlan.py @@ -1,7 +1,7 @@ -import datetime import logging -import parser +import time +import params from core.emulator.coreemu import CoreEmu from core.emulator.emudata import IpPrefixes, NodeOptions from core.emulator.enumerations import EventTypes, NodeTypes @@ -37,14 +37,10 @@ def example(args): # get nodes for example run first_node = session.get_node(2) last_node = session.get_node(args.nodes + 1) - - logging.info("starting iperf server on node: %s", first_node.name) - first_node.cmd("iperf -s -D") address = prefixes.ip4_address(first_node) - logging.info("node %s connecting to %s", last_node.name, address) - output = last_node.cmd(f"iperf -t {args.time} -c {address}") + logging.info("node %s pinging %s", last_node.name, address) + output = last_node.cmd(f"ping -c {args.count} {address}") logging.info(output) - first_node.cmd("killall -9 iperf") # shutdown session coreemu.shutdown() @@ -52,12 +48,13 @@ def example(args): def main(): logging.basicConfig(level=logging.INFO) - args = parser.parse("wlan") - - start = datetime.datetime.now() - logging.info("running wlan example: nodes(%s) time(%s)", args.nodes, args.time) + args = params.parse("wlan") + start = time.perf_counter() + logging.info( + "running wlan example: nodes(%s) ping count(%s)", args.nodes, args.count + ) example(args) - logging.info("elapsed time: %s", datetime.datetime.now() - start) + logging.info("elapsed time: %s", time.perf_counter() - start) if __name__ == "__main__":