| Crates.io | msg-sim |
| lib.rs | msg-sim |
| version | 0.1.5 |
| created_at | 2026-01-14 12:28:33.660364+00 |
| updated_at | 2026-01-14 12:28:33.660364+00 |
| description | A flexible and lightweight messaging library for distributed systems |
| homepage | https://github.com/chainbound/msg-rs |
| repository | https://github.com/chainbound/msg-rs |
| max_upload_size | |
| id | 2042699 |
| size | 23,622 |
msg-simThis 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.
On MacOS, we use a combination of the pfctl and dnctl tools.
pfctl is a tool to manage the packet filter device. dnctl can manage
the dummynet traffic shaper.
The general flow is as follows:
dnctl and configure it with bw, delay, plrExample:
sudo dnctl pipe 1 config bw 10Kbit/s delay 50 plr 0.1
ifconfig to simulate a different endpoint and
set the MTU to the usual value (1500)Example:
sudo ifconfig lo0 alias 127.0.0.3 up
sudo ifconfig lo0 mtu 1500
pfctl to create a rule to match traffic and send it through the pipeExample:
# 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
# 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
On Linux, we use dummy interfaces and tc with netem to simulate and shape traffic.