-
Notifications
You must be signed in to change notification settings - Fork 14
msg-sim revamp, Linux support only
#152
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
ac4ed3b
feat(msg-sim): linux stub
thedevbirb 35d082b
chore(msg-sim): remove macos target; support only linux
thedevbirb 89c52ec
feat(msg-sim): simulation network stub
thedevbirb f197870
chore(msg-sim): refactor network stub
thedevbirb 69093db
feat(msg-sim): command utilities
thedevbirb 863c6fe
fix(msg-sim): types, subnet
thedevbirb 86e6a52
fix(msg-sim): avoid mask config
thedevbirb ee1d393
check
thedevbirb 02b7f91
chore(msg-sim): refactor
thedevbirb e159181
chore(msg-sim): refactor
thedevbirb 35579a7
feat(msg-sim): refactor with rtnetlink and new architecture
thedevbirb b05e0e6
feat(msg-sim): dyn task
thedevbirb 3c1a71e
feat(msg-sim): running code in namespace works
thedevbirb 7771d65
chore(msg-sim): add test using req/rep
thedevbirb 7a7b9d6
feat(msg-sim): bring lo up; tc stub
thedevbirb 75f9d00
refactor
thedevbirb 5be66ed
stub tc
thedevbirb 62e0141
ugly but works
thedevbirb c5f8213
fix(msg-sim): latency and jitter computation
thedevbirb e26834a
chore(msg-sim): refactor
thedevbirb 52fe245
feat(msg-sim): generic context attempt
thedevbirb acb2d38
chore(msg-sim): refactor, comments
thedevbirb 5c2c9b9
fix(msg-sim): don't build the crate on macos
thedevbirb 3d4a4f8
fix(msg-sim): tokio fs feature, bump rtnetlink
thedevbirb 9f73a0a
fix(msg-sim): ci, remove simulation from pubsub it
thedevbirb 8bec9ca
stub
thedevbirb 8aa8742
feat(msg-sim): use drr for adding classes dynamically; refactor
thedevbirb ab4a6ff
chore(msg-sim): document notable paths
thedevbirb e769af1
chore: shear deps
thedevbirb f8b6335
chore: bump MSRV to 1.86.0
thedevbirb 593f2c6
chore: update ci with privileges for running msg-sim tests
thedevbirb 7f2d13d
Merge branch 'main' of https://github.com/chainbound/msg-rs into lore…
thedevbirb 591f8e9
chore(msg-sim): update readme
thedevbirb 2442bf3
feat(msg-sim): Cast trait
thedevbirb d429e4e
fix(msg-sim): doc comments
thedevbirb ab0f6b4
chore(msg-sim): move scripts to separate folder; highlight limitation…
thedevbirb 7442cf7
chore(msg-sim): example sim_multi_region
thedevbirb 0d3a3de
chore(msg-sim): builder pattern for impairments
thedevbirb f6babf0
chore(msg-sim): address review
thedevbirb 0c40910
chore: update CLAUDE.md
thedevbirb b9e172d
Merge branch 'main' of https://github.com/chainbound/msg-rs into lore…
thedevbirb fee3b9a
fix(msg-sim): ci
thedevbirb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,15 @@ | ||
| # `msg-sim` | ||
|
|
||
| ## Overview | ||
| This crate provides functionality to simulate real-world network conditions | ||
| locally to and from a specific endpoint for testing and benchmarking purposes. | ||
| It only works on MacOS and Linux. | ||
| todo: update README.md | ||
|
|
||
| ## Implementation | ||
| #### How to run tests | ||
|
|
||
| ### MacOS | ||
| On MacOS, we use a combination of the `pfctl` and `dnctl` tools. | ||
| [`pfctl`](https://man.freebsd.org/cgi/man.cgi?query=pfctl&apropos=0&sektion=8&manpath=FreeBSD+14.0-RELEASE+and+Ports&arch=default&format=html) is a tool to manage the packet filter device. [`dnctl`](https://man.freebsd.org/cgi/man.cgi?query=dnctl&sektion=8&format=html) can manage | ||
| the [dummynet](http://info.iet.unipi.it/~luigi/papers/20100304-ccr.pdf) traffic shaper. | ||
| Given that the tests require root privileges to modify the networking stack, | ||
| you can run them with the following command: | ||
|
|
||
| The general flow is as follows: | ||
|
|
||
| * Create a dummynet pipe with `dnctl` and configure it with `bw`, `delay`, `plr` | ||
|
|
||
| Example: | ||
| ```bash | ||
| sudo dnctl pipe 1 config bw 10Kbit/s delay 50 plr 0.1 | ||
| ``` | ||
|
|
||
| * Create a loopback alias with `ifconfig` to simulate a different endpoint and | ||
| set the MTU to the usual value (1500) | ||
|
|
||
| Example: | ||
| ```bash | ||
| sudo ifconfig lo0 alias 127.0.0.3 up | ||
| sudo ifconfig lo0 mtu 1500 | ||
| ``` | ||
|
|
||
| * Use `pfctl` to create a rule to match traffic and send it through the pipe | ||
|
|
||
| Example: | ||
| ```bash | ||
| # Create an anchor (a named container for rules, close to a namespace) | ||
| (cat /etc/pf.conf && echo "dummynet-anchor \"msg-sim\"" && \ | ||
| echo "anchor \"msg-sim\"") | sudo pfctl -f - | ||
|
|
||
| # Create a rule to match traffic from any to the alias and send it through the pipe | ||
| echo 'dummynet in from any to 127.0.0.3 pipe 1' | sudo pfctl -a msg-sim -f - | ||
|
|
||
| # Enable the packet filter | ||
| sudo pfctl -E | ||
| ``` | ||
|
|
||
| * Remove the rules and the pipe | ||
| ```bash | ||
| # Apply the default configuration | ||
| sudo pfctl -f /etc/pf.conf | ||
| # Disable the packet filter | ||
| sudo pfctl -d | ||
| # Remove the alias & reset the MTU | ||
| sudo ifconfig lo0 -alias 127.0.0.3 | ||
| sudo ifconfig lo0 mtu 16384 | ||
| # Remove the dummynet pipes | ||
| sudo dnctl pipe delete 1 | ||
| sudo HOME=$HOME $(which cargo) test # add your arguments here | ||
| ``` | ||
|
|
||
| ### Questions | ||
| - Do we need to create 2 pipes to simulate a bidirectional link? MAN page seems to say so. | ||
|
|
||
| ### Linux | ||
| On Linux, we use dummy interfaces and `tc` with `netem` to simulate and shape traffic. | ||
| We need to provide the `$HOME` environment variable to `sudo` to ensure that | ||
| it can find the Rust toolchain, and then we also need to provide the path of `cargo`. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super liking this - isn't there a better way? Maybe asking capabilities from the kernel? Or elevate priviledges inside the binary
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear that. This has been a forever pain point since I started using namespaces. Using plain sudo is just bad and I know. But you need the capabilities to fiddle with the networking stack, like
CAP_NET_ADMIN(and something more). So an approach I tried briefly is to first compile the test binaries (--no-runflag), identify them, grant privileges with sudo, and then run them.Still not incredible DX, so I'm postponing the problem for now until I think of something better.