Created
August 1, 2012 07:40
-
-
Save andrewdolce/3224674 to your computer and use it in GitHub Desktop.
ipfw jitter test script
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 | |
MIN_LAG=25 | |
MAX_LAG=50 | |
(( LAG_RANGE = MAX_LAG - MIN_LAG )) | |
TIME=600 # total test time (in seconds) | |
INTERVAL=0.1 # time in between changes in latency (in seconds) | |
STEPS=6000 # TIME / INTERVAL | |
# set up a pipe to add latency, which matches only *incoming* | |
# traffic from the localhost to the localhost | |
ipfw add 100 pipe 1 ip from 127.0.0.1 to 127.0.0.1 in | |
ipfw add 100 allow ip from 127.0.0.1 to 127.0.0.1 out | |
# set up initial random delay | |
(( delay = RANDOM % LAG_RANGE + MIN_LAG )) | |
echo "setting delay to" $delay "ms" | |
ipfw pipe 1 config delay ${delay}ms | |
# start ping background process and stash result in a file | |
ping -i 0.05 localhost > ping_out & | |
PING_PID=$! # remember the PID so we can kill it later | |
for ((i=0; i < STEPS; i++)) | |
do | |
sleep $INTERVAL | |
# change the delay to a new random value | |
(( delay = RANDOM % LAG_RANGE + MIN_LAG )) | |
ipfw pipe 1 config delay ${delay}ms | |
echo "setting delay to" $delay "ms" | |
done | |
# kill the ping process | |
kill $PING_PID | |
# remove the pipe and the associated rule | |
ipfw delete 100 | |
ipfw pipe 1 delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment