diff --git a/.gitignore b/.gitignore index 024fb98..bfe67c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.venv /target Cargo.lock __pycache__ diff --git a/netsim/.envrc b/netsim/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/netsim/.envrc @@ -0,0 +1 @@ +use flake diff --git a/netsim/flake.lock b/netsim/flake.lock new file mode 100644 index 0000000..336fc27 --- /dev/null +++ b/netsim/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1719223410, + "narHash": "sha256-jtIo8xR0Zp4SalIwmD+OdCwHF4l7OU6PD63UUK4ckt4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "efb39c6052f3ce51587cf19733f5f4e5d515aa13", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/netsim/flake.nix b/netsim/flake.nix new file mode 100644 index 0000000..e906632 --- /dev/null +++ b/netsim/flake.nix @@ -0,0 +1,49 @@ +{ + description = "A flake to set up netsim temporary environment"; + + inputs = { utils.url = "github:numtide/flake-utils"; }; + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + + ovsScripts = "${pkgs.openvswitch}/share/openvswitch/scripts"; + + pyPkgs = with pkgs.python3Packages; [ + pyshark + drawsvg + dpkt + humanfriendly + mininet-python + ]; + + netsim = pkgs.writeScriptBin "netsim" '' + #!/bin/sh + + echo "Running with PYTHONPATH: $PYTHONPATH" + sudo PYTHONPATH=$PYTHONPATH python3 main.py $@ + ''; + + in { + devShell = pkgs.mkShell { + buildInputs = with pkgs; + [ inetutils mininet openvswitch iperf tshark python3 netsim ] + ++ pyPkgs; + + shellHook = '' + export OVS_DBDIR=$(pwd) + sudo ${ovsScripts}/ovs-ctl start \ + --db-file="$OVS_DBDIR/conf.db" \ + --system-id=random + + sudo ovs-vsctl show + + cleanup() { + sudo ${ovsScripts}/ovs-ctl stop + sudo rm $OVS_DBDIR/conf.db + } + trap cleanup EXIT + ''; + }; + }); +} diff --git a/netsim/main.py b/netsim/main.py index 4042660..c42d7ee 100644 --- a/netsim/main.py +++ b/netsim/main.py @@ -15,7 +15,7 @@ from network import StarTopo from process_sniff import run_viz -TIMEOUT = 60 * 5 +TIMEOUT = 20 # 60 * 5 def logs_on_error(nodes, prefix, code=1, message=None): node_counts = {} @@ -151,10 +151,22 @@ def run(nodes, prefix, args, debug=False, visualize=False): # CLI(net) process_errors = [] + some_error = False for i in range(TIMEOUT): time.sleep(1) - if not any(p.poll() is None for (n, p) in p_short_box): + + for (node_name, p) in p_short_box: + r = p.poll() + print('Supervisor(%s): Process still running after %d seconds.' % (node_name, i + 1)) + if r is not None and r != 0: + print('Supervisor(%s): Process finished %s with exit code %d' % (node_name, prefix, r)) + process_errors.append('Process has failed: %s with exit code: %d for node: %s' % (prefix, r, node_name)) + some_error = True + break + + if not any(p.poll() is None for (_, p) in p_short_box) or some_error: break + for (node_name, p) in p_short_box: if integration: r = p.poll() @@ -167,9 +179,9 @@ def run(nodes, prefix, args, debug=False, visualize=False): p.terminate() if process_errors: + logs_on_error(nodes, prefix) for error in process_errors: print(error) - logs_on_error(nodes, prefix) cleanup_tmp_dirs(temp_dirs) raise Exception('Netsim run failed') diff --git a/netsim/setup.sh b/netsim/setup.sh index 679e2ed..4167326 100755 --- a/netsim/setup.sh +++ b/netsim/setup.sh @@ -1,12 +1,12 @@ -sudo apt install mininet -sudo apt install openvswitch-testcontroller -sudo apt install iperf -# sudo apt install wireshark -sudo apt install tshark -sudo pip3 install pyshark -sudo pip3 install drawsvg -sudo pip3 install dpkt -sudo pip3 install humanfriendly +# sudo apt install mininet +# sudo apt install openvswitch-testcontroller +# sudo apt install iperf +# # sudo apt install wireshark +# sudo apt install tshark +# pip3 install pyshark +# pip3 install drawsvg +# pip3 install dpkt +# pip3 install humanfriendly mkdir -p logs mkdir -p report mkdir -p data diff --git a/netsim/sims/repro/iroh.json b/netsim/sims/repro/iroh.json new file mode 100644 index 0000000..dffbdec --- /dev/null +++ b/netsim/sims/repro/iroh.json @@ -0,0 +1,63 @@ +{ + "name": "iroh", + "cases": [ + { + "name": "2_to_10", + "description": "", + "nodes": [ + { + "name": "iroh_srv", + "count": 2, + "cmd": "./bins/iroh start --add data/1G.bin", + "type": "public", + "wait": 10, + "connect": { + "strategy": "none" + }, + "param_parser": "iroh_ticket" + }, + { + "name": "iroh_get", + "count": 10, + "cmd": "time ./bins/iroh blob get --start %s --out STDOUT > /dev/null", + "type": "public", + "connect": { + "strategy": "params", + "node": "iroh_srv" + }, + "process": "short", + "parser": "iroh_1gb" + } + ] + }, + { + "name": "2_to_10", + "description": "", + "nodes": [ + { + "name": "iroh_srv", + "count": 2, + "cmd": "./bins/iroh start --add data/1G.bin", + "type": "public", + "wait": 10, + "connect": { + "strategy": "none" + }, + "param_parser": "iroh_ticket" + }, + { + "name": "iroh_get", + "count": 10, + "cmd": "time ./bins/iroh blob get --start %s --out STDOUT > /dev/null", + "type": "public", + "connect": { + "strategy": "params", + "node": "iroh_srv" + }, + "process": "short", + "parser": "iroh_1gb" + } + ] + } + ] +} \ No newline at end of file