From Fedora Project Wiki

Revision as of 16:39, 24 June 2011 by Fenris02 (talk | contribs) (Created page with "<code> #!/bin/bash # if [ $# -ne 2 ]; then cat -<<EOT Usage: $0 [BW Mbps] [RTT ms] Example: $0 1.5 51 EOT exit 1 fi # BANDWIDTH=$1 #M...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

#!/bin/bash
#
if [ $# -ne 2 ]; then
cat -<<EOT
Usage: $0 [BW Mbps] [RTT ms]
Example:
    $0 1.5 51
EOT
exit 1
fi
#
BANDWIDTH=$1                              #Mbps
RTT=$( echo "scale=3;  $2 / 1000." |bc )  #ms
#LOSS=$( echo "scale=3;  $3 / 100." |bc )  #percent
LOSS=$( echo "scale=3;  0.1 / 100." |bc )  # 0.1 percent
#
simplemath () {
    echo "" | awk 'END { exit ( !( '"$1"')); }'
}
buffcalc () {
    # $1 = Buffer size
    echo "scale=2; $1 * 8 / $RTT /1000/1000" |bc
}
mtucalc () {
    # $1 = MTU, $2 = Header size
    echo "scale=5; 0.7 * ( $1 - $2 ) * 8 / ( $RTT * sqrt($LOSS) ) /1000/1000" |bc -l
}

test1=$( echo "scale=2; 0.98 * $BANDWIDTH" |bc )
MAX1=$test1; MAX2=$test1; MAX3=$test1

test2a=$( buffcalc 17520 )
simplemath "$MAX1 > $test2a" && MAX1=$test2a
test2b=$( buffcalc 262144 )
test2c=$( buffcalc 4194304 )
simplemath "$MAX2 > $test2c" && MAX2=$test2c
test2d=$( echo "scale=2; $BANDWIDTH * 1000 * 1000 / 8 * $RTT" |bc)

test3a=$( mtucalc 1500 52 )
simplemath "$MAX1 > $test3a" && MAX1=$test3a
test3b=$( mtucalc 9000 52 )
simplemath "$MAX2 > $test3b" && MAX2=$test3b
test3c=$( echo "scale=5; ( $BANDWIDTH / 0.7 / 8 * $RTT * sqrt($LOSS) * 1000 * 1000 ) + 52" |bc -l)

test4a=$( mtucalc 1500 40 )
simplemath "$MAX3 > $test4a" && MAX3=$test4a
test4b=$( mtucalc 9000 40 )
simplemath "$MAX3 > $test4b" && MAX3=$test4b
test4c=$( echo "scale=5; ( $BANDWIDTH / 0.7 / 8 * $RTT * sqrt($LOSS) * 1000 * 1000 ) + 40" |bc -l)
simplemath "$MAX3 > $test4c" && MAX3=$test4c
test4d=$( buffcalc 65535 )
simplemath "$MAX3 > $test4d" && MAX3=$test4d

cat -<<EOT
Dependant upon physical line:
1) $test1 Mbps

Dependant upon buffer size and RTT:
2a) 17kB buffer: $test2a Mbps
2b) 262kB buffer: $test2b Mbps
2c) 4M buffer: $test2c Mbps
2d) Min buffer req to fill BW: $test2d

Dependant upon MTU, RTT, and LOSS: (window scaling enabled)
3a) default MTU: $test3a Mbps
3b) 9k MTU: $test3b Mbps
3c) Min MTU req to fill BW: $test3c

Dependant upon MTU, RTT, and LOSS: (window scaling disabled)
4a) default MTU: $test4a Mbps
4b) 9k MTU: $test4b Mbps
4c) Min MTU req to fill BW: $test4c
4d) Max buffer (64k): $test4d Mbps

Max throughput = $MAX1 Mbps (default) or $MAX2 Mbps (fully tuned) or $MAX3 Mbps (without scaling)
EOT

#EOF