-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Bostoen
committed
Jan 7, 2024
1 parent
488ad32
commit da30b36
Showing
6 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# `msg-sim` | ||
|
||
## Overview | ||
This crate provides functionality to simulate real-world network conditions over an interface (e.g. `lo0`) for testing and benchmarking purposes. | ||
It only works on MacOS and Linux. | ||
|
||
## Implementation | ||
|
||
### MacOS | ||
* https://gist.github.com/tellyworth/2ce28add99fe743c702c090c8144355e | ||
|
||
* `dnctl` for creating a dummynet pipe | ||
|
||
Example: | ||
```bash | ||
dnctl pipe 1 config bw 10Kbit/s delay 300 plr 0.1 noerror` | ||
``` | ||
|
||
* `pfctl` for creating a rule to match traffic and send it through the pipe | ||
|
||
Example: | ||
```bash | ||
echo "dummynet out proto tcp from any to any pipe 1" | sudo pfctl -f - | ||
pfctl -e | ||
``` |
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! This module contains all the commands necessary to start and stop a simulation. | ||
//! | ||
//! ## Implementation | ||
//! Under the hood, this module uses the `pfctl` command. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[cfg(target_os = "linux")] | ||
pub mod linux; | ||
|
||
#[cfg(target_os = "macos")] | ||
pub mod macos; |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[derive(Debug, Clone, Copy)] | ||
#[allow(clippy::upper_case_acronyms)] | ||
pub enum Protocol { | ||
TCP, | ||
UDP, | ||
ICMP, | ||
} | ||
|
||
impl From<&str> for Protocol { | ||
fn from(s: &str) -> Self { | ||
match s { | ||
"tcp" => Self::TCP, | ||
"udp" => Self::UDP, | ||
"icmp" => Self::ICMP, | ||
_ => panic!("invalid protocol"), | ||
} | ||
} | ||
} |