Last active
January 24, 2023 18:16
-
-
Save unverbraucht/118117ab66ac142f4eda to your computer and use it in GitHub Desktop.
Script for OpenWRT that adds delay, bandwidth limiting and packet loss to a Wi-Fi router connection. See http://kevin-read.com/post/86601925386/simulating-a-slow-network-connection-when-testing-on for details
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
#!/bin/sh | |
# The bandwidth to simulate, here about 56kilobit per second. This is layer 2 bandwidth, so TCP/UDP and IP overhead will apply | |
BW="56kbps" | |
# _Half_ the latency that we aim for. Since this applies to both the WAN port and Wi-Fi, the delay is applied twice, so this actually puts it at around 120+ms | |
LATENCY="60ms" | |
# Chance of packet loss. Also applied to both interfaces, so it is 1%. | |
LOSS="0.5%" | |
# The device name of your wifi device. | |
WIFI="wlan0" | |
# The device name of your wan port | |
WAN="eth0.2" | |
# Delete existing traffic control rules | |
tc qdisc del root dev $WIFI | |
tc qdisc del root dev $WAN | |
# Create a basic tc rule for wifi | |
tc qdisc add dev $WIFI root handle 1: htb default 12 | |
# First apply the rate limiting through a HTC scheduler | |
tc class add dev $WIFI parent 1:1 classid 1:12 htb rate $BW ceil $BW | |
# Then apply the netem scheduler which handles delay and packet loss | |
tc qdisc add dev $WIFI parent 1:12 netem delay $LATENCY 10ms 25% loss $LOSS | |
# The same for WAN | |
tc qdisc add dev $WAN root handle 2: htb default 12 | |
tc class add dev $WAN parent 2:1 classid 2:12 htb rate $BW ceil $BW | |
tc qdisc add dev $WAN parent 2:12 netem delay $LATENCY 10ms 25% loss $LOSS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@unverbraucht How difficult would it be to control those parameters via a web browser? I have zero experience with OpenWRT.