Skip to content

Commit

Permalink
refactor: netsim (#66)
Browse files Browse the repository at this point in the history
* refactor: netsim

* cleanup sims (shorter names)

* make sure we abort on failure

* CR
  • Loading branch information
Arqu authored Sep 18, 2024
1 parent b018e27 commit 4961c40
Show file tree
Hide file tree
Showing 36 changed files with 2,404 additions and 1,987 deletions.
39 changes: 3 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
[package]
name = "chuck"
version = "0.0.1"
edition = "2021"
authors = ["arqu <[email protected]>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/n0-computer/chuck"
description = "iroh test tools"
rust-version = "1.65"
[workspace]
members = ["chuck"]

[dependencies]
anyhow = { version = "1", features = ["backtrace"] }
clap = { version = "4.0.9", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
bincode = "1.3.3"
tempfile = "3.4.0"
futures = "0.3.21"
bytes = "1.1.0"
rand = "0.8.5"

axum = "0.6.2"
tower = { version = "0.4", features = ["util"] }
tower-http = { version = "0.3.0", features = ["fs", "trace"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
axum-server = { version = "0.3", features = ["tls-rustls"] }
reqwest = { version = "0.11.10", default-features = false, features = ["rustls-tls"] }

#iroh-api = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-util = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-share = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-one = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-rpc-types = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1", default-features = false}
#iroh-rpc-client = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1", default-features = false}

iroh = { git = "https://github.com/n0-computer/iroh", rev = "2149bc8c6819b044833f5af0b8fdac567ef93650", default-features = false }
resolver = "2"
37 changes: 37 additions & 0 deletions chuck/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "chuck"
version = "0.0.1"
edition = "2021"
authors = ["arqu <[email protected]>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/n0-computer/chuck"
description = "iroh test tools"
rust-version = "1.65"

[dependencies]
anyhow = { version = "1", features = ["backtrace"] }
clap = { version = "4.0.9", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
bincode = "1.3.3"
tempfile = "3.4.0"
futures = "0.3.21"
bytes = "1.1.0"
rand = "0.8.5"

axum = "0.6.2"
tower = { version = "0.4", features = ["util"] }
tower-http = { version = "0.3.0", features = ["fs", "trace"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
axum-server = { version = "0.3", features = ["tls-rustls"] }
reqwest = { version = "0.11.10", default-features = false, features = ["rustls-tls"] }

#iroh-api = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-util = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-share = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-one = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1"}
#iroh-rpc-types = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1", default-features = false}
#iroh-rpc-client = { git = "https://github.com/n0-computer/iroh", rev = "0e06dd7f70e21955f735ecd54464c7527fbf72c1", default-features = false}

iroh = { git = "https://github.com/n0-computer/iroh", rev = "2149bc8c6819b044833f5af0b8fdac567ef93650", default-features = false }
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 23 additions & 9 deletions netsim/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# Netsim

## Requirements
- `sudo ./setup.sh`
- Linux machine, tested on ubuntu 20.04 & 22.04

- `ubuntu`
- `python3`
- `sudo apt install mininet`
- `sudo apt install openvswitch-testcontroller`
- `/var/lib/netsim`
- `dd if=/dev/urandom of=128MB.bin bs=64M count=2 iflag=fullblock`
- `dd if=/dev/urandom of=1GB.bin bs=64M count=16 iflag=fullblock`
- `iperf`
### Warning:
- Requires root access
- Dirties your system python dependencies

## Locally

You can also do this locally on a linux machine. With a few modifications you don’t even need to do much as root:

- clone [**iroh**](https://github.com/n0-computer/iroh) and [**chuck**](https://github.com/n0-computer/chuck) into the same directory.
- Check `chuck/netsim/scripts/ubuntu_deps.sh`to find what the system dependencies are
- `cd chuck/netsim`
- Create a virtual environment:
- `python -m venv .venv`
- `source .venv/bin/activate`
- `./scripts/python_deps.sh`
- Run `./scripts/project_deps` to configure the project structure and generate fixtures
- Continue with in the iroh repo, build iroh and copy it into chuck/netsim/bins. I found building in release mode to be sufficient, not release-optimized like what CI does. `cargo build --release && cp ./target/release/iroh ../chuck/netsim/bins/`
- Do not run kill, these are services managed by systemd
- Run `main.py` as root, using the python from your virtualenv:
- `./venv/bin/python main.py --integrations sims/mini`

## Run

Expand All @@ -19,4 +33,4 @@
## Notes

- `https://github.com/mininet/mininet/wiki/Introduction-to-Mininet`
- `sudo kill -9 $(pgrep ovs)`
- `sudo kill -9 $(pgrep ovs)` - when stuck with weird errors due to the process failing mid way on a simulation
13 changes: 12 additions & 1 deletion netsim/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ rm -rf viz/*
sudo mn --clean
sudo kill -9 $(pgrep iroh)
sudo kill -9 $(pgrep derper)
sudo kill -9 $(pgrep ovs)
sudo kill -9 $(pgrep ovs)


# we use shorter interface names due to size constraints, which means we need to have a custom cleanup too
echo "Cleaning up interfaces"
links=$(ip link show | egrep -o '([-_.[:alnum:]]+-e[[:digit:]]+)')
for link in $links; do
# Run your command with $link as a parameter
echo "Deleting $link"
# Example command: sudo ip link delete $link
sudo ip link delete $link
done
Loading

0 comments on commit 4961c40

Please sign in to comment.