Skip to content

Instantly share code, notes, and snippets.

@isa
Forked from unverbraucht/gist:118117ab66ac142f4eda
Last active August 29, 2015 14:07
Show Gist options
  • Save isa/ec54bbe05dd176f3895c to your computer and use it in GitHub Desktop.
Save isa/ec54bbe05dd176f3895c to your computer and use it in GitHub Desktop.
#!/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