Created
November 21, 2016 14:23
-
-
Save tchakabam/6502c867353ed60fc2af2764e839ffa3 to your computer and use it in GitHub Desktop.
Bandwidth / latency limiter for player development in Mac OSX
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/bash | |
# | |
# author: Stephan Hesse ([email protected]) | |
# | |
echo "" | |
echo "************ tape.tv CDN testing tool *************" | |
echo "" | |
echo "Author: Stephan Hesse <[email protected]>" | |
echo "" | |
echo "+++ Bandwidth / latency limiter for player development in Mac OSX +++" | |
echo "" | |
if [ -z "$2" ] | |
then | |
echo "Usage: <command> <bandwidth in Mbit/s> <half-trip latency in milliseconds>" | |
echo "Usage: <command> <bandwidth in Mbit/s> <half-trip latency in milliseconds> <entry point IP>" | |
echo "" | |
echo "To set up limitation upon ALL connections enter 'any' for the IP" | |
echo "" | |
echo "If no IP is specified, the hard-coded default entry point will be used." | |
echo "" | |
echo "" | |
echo "Not enough arguments, quitting ..." | |
echo "" | |
exit | |
fi | |
IP="37.44.5.5" | |
BANDWIDTH=$1 | |
BANDWIDTH+="Mbit/s" | |
LATENCY=$2 | |
LATENCY+="ms" | |
echo "> Limiting connection to CDN: $BANDWIDTH with $LATENCY delay / way" | |
echo "> Default entry point IP: $IP" | |
echo "> Flushing all existing ipfw rules ..." | |
sudo ipfw -q flush | |
if [ $1 -lt 0 ] | |
then | |
echo "> Not setting any new rules, bye." | |
exit | |
fi | |
echo "> Adding pipes for test server IPs" | |
if [ -n "$3" ] | |
then | |
echo "> Using IP from shell argument" | |
IP=$3 | |
else | |
echo "> Using default IP" | |
fi | |
echo "> Using duplex pipe on IP: $IP (two-way) " | |
if [ $IP = "any" ]; then | |
sudo ipfw add pipe 1 ip from any to $IP | |
else | |
sudo ipfw add pipe 1 ip from any to $IP | |
sudo ipfw add pipe 2 ip from $IP to any | |
fi | |
echo "> Applying bandwidth / latency rules to pipes" | |
if [ $IP = "any" ]; then | |
sudo ipfw pipe 1 config delay $LATENCY bw $BANDWIDTH plr 0.1 | |
else | |
sudo ipfw pipe 1 config delay $LATENCY bw $BANDWIDTH plr 0.1 | |
sudo ipfw pipe 2 config delay $LATENCY bw $BANDWIDTH plr 0.1 | |
fi | |
echo "> Done." | |
echo "" | |
echo "> Performing ping test to server ..." | |
echo "" | |
ping 37.44.5.5 | |
echo "" | |
echo "Quitting, bye." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment