Skip to content

feat: Write nix flake #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv
/target
Cargo.lock
__pycache__
Expand Down
1 change: 1 addition & 0 deletions netsim/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
59 changes: 59 additions & 0 deletions netsim/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions netsim/flake.nix
Original file line number Diff line number Diff line change
@@ -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
'';
};
});
}
18 changes: 15 additions & 3 deletions netsim/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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()
Expand All @@ -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')

Expand Down
18 changes: 9 additions & 9 deletions netsim/setup.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
63 changes: 63 additions & 0 deletions netsim/sims/repro/iroh.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
Loading