Skip to content

Instantly share code, notes, and snippets.

@nathan-muir
Forked from jedp/gist:4611182
Created July 18, 2013 07:29
Show Gist options
  • Save nathan-muir/6027389 to your computer and use it in GitHub Desktop.
Save nathan-muir/6027389 to your computer and use it in GitHub Desktop.
#!/bin/sh
tc qdisc del dev eth0 root 2> /dev/null
if [ "z$1" = "zdialup" ] ; then
echo "Brace yourself, enabling dialup preset..."
BANDWIDTH=56kbit
LATENCY=200msec
elif [ "z$1" = "z2g" ] ; then
echo "Enabling 2G preset..."
BANDWIDTH=112kbit
LATENCY=150msec
elif [ "z$1" = "zedge" ] ; then
echo "Enabling EDGE preset..."
BANDWIDTH=384kbit
LATENCY=100msec
elif [ "z$1" = "znone" ] ; then
echo "Throttling disabled."
exit 0;
else
echo "Usage: $0 (dialup|2g|edge|none) [lossy]"
exit 0;
fi
PACKET_LOSS=2%
if [ "z$2" = "zlossy" ] ; then
echo "...on a very lossy connection"
PACKET_LOSS=20%
fi
tc qdisc add dev eth0 root handle 1:0 netem delay $LATENCY loss $PACKET_LOSS
tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate $BANDWIDTH burst $BANDWIDTH latency $LATENCY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment