From 4ee870f22b1f9202a0f337ff0100022729a6ce26 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 20 Apr 2023 16:30:28 +0530 Subject: [PATCH] iperf test --- .gitignore | 1 + cowmesh_iperf_test.py | 107 ++++++++++++++++++ ...esh_network_test.py => cowmesh_scp_test.py | 2 +- run.md | 2 + 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 cowmesh_iperf_test.py rename cowmesh_network_test.py => cowmesh_scp_test.py (98%) create mode 100644 run.md diff --git a/.gitignore b/.gitignore index 518a987..9ae7dbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ download.png test.png .idea +secrets.json diff --git a/cowmesh_iperf_test.py b/cowmesh_iperf_test.py new file mode 100644 index 0000000..c66f994 --- /dev/null +++ b/cowmesh_iperf_test.py @@ -0,0 +1,107 @@ +""" +script to do a basic holistic test of the cowmesh network, +testing internet connection speed using iperf, +between all nodes in the mesh +""" +import os +import re +import time +import asyncio, asyncssh, sys +import paramiko +import subprocess +import json + +PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) +SECRETS_PATH = os.path.join(PROJECT_PATH, "secrets.json") +with open(SECRETS_PATH, 'r') as f: + SECRETS = json.loads(f.read()) + +nodes = [ + "jaaga", + # "new-gazebo", + "redcottage", + "kotemanetp", + "guard" +] + +host_to_ip = { + "jaaga": "10.56.121.19", + "redcottage": "10.56.58.194", + "new-gazebo": "10.56.113.2", + "guard": "10.56.121.73", + "kotemanetp": "10.56.40.113" +} + +results = {} + + +def test_between_two_nodes(node_a, node_b): + print("running test from {} to {}".format(node_a, node_b)) + u_name = 'root' + pswd = SECRETS["ROUTER_PASSWORD"] + + myconn = paramiko.SSHClient() + myconn.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + session = myconn.connect(node_a, username =u_name, password=pswd) + + ip = host_to_ip[node_b] + + remote_cmd = 'iperf -c {ip} -p 5001'.format(ip=ip) + (stdin, stdout, stderr) = myconn.exec_command(remote_cmd) + output = str(stdout.read()) + print("output: {}".format(output)) + print("errors: {}".format(stderr.read())) + myconn.close() + + match = re.search("(\S+) Mbits", output) + if match: + to_return = match.group(1) + else: + to_return = None + + return to_return + + +async def start_iperf_servers(): + for node in nodes: + print("starting iperf server on {}".format(node)) + u_name = 'root' + pswd = SECRETS["ROUTER_PASSWORD"] + + myconn = paramiko.SSHClient() + myconn.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + session = myconn.connect(node, username=u_name, password=pswd) + + remote_cmd = 'iperf -s &' + (stdin, stdout, stderr) = myconn.exec_command(remote_cmd) + print("{}".format(stdout.read())) + print("{}".format(type(myconn))) + print("Options available to deal with the connectios are many like\n{}".format(dir(myconn))) + myconn.close() + +async def run_test(): + + await start_iperf_servers() + + for node_a in nodes: + for node_b in nodes: + if node_a == node_b: + print("skip self") + continue + + r = test_between_two_nodes(node_a, node_b) + result_key = "{} -> {}".format(node_a, node_b) + results[result_key] = r + + +try: + asyncio.get_event_loop().run_until_complete(run_test()) + + print("** final results **") + for test_name, result in results.items(): + print("{}: {} mbps".format(test_name, result)) + +except (OSError, asyncssh.Error) as exc: + sys.exit('SSH connection failed: ' + str(exc)) \ No newline at end of file diff --git a/cowmesh_network_test.py b/cowmesh_scp_test.py similarity index 98% rename from cowmesh_network_test.py rename to cowmesh_scp_test.py index 126f7e5..ec5ef2c 100644 --- a/cowmesh_network_test.py +++ b/cowmesh_scp_test.py @@ -155,7 +155,7 @@ def run_laptop_test(): try: asyncio.get_event_loop().run_until_complete(run_test()) - run_laptop_test() + # run_laptop_test() print("** final results **") file_size = 13476 diff --git a/run.md b/run.md new file mode 100644 index 0000000..2121d70 --- /dev/null +++ b/run.md @@ -0,0 +1,2 @@ +python3 cowmesh_iperf_test.py +python3 cowmesh_scp_test.py