Skip to content

Commit

Permalink
Incorporate -Z passphrase option for betterspeedtest.sh and netperf…
Browse files Browse the repository at this point in the history
…runner.sh
  • Loading branch information
richb-hanover committed Oct 3, 2024
1 parent 736aab4 commit d1a5e7b
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 33 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Here's why that's important: If the data transfers do increase the latency/lag m

The betterspeedtest.sh script measures latency during file transfers. To invoke it:

sh betterspeedtest.sh [ -4 | -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -i ] [ -n simultaneous-streams ]
sh betterspeedtest.sh -Z passphrase [ -4 | -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -i ] [ -n simultaneous-streams ]

Options, if present, are:

Expand All @@ -178,6 +178,8 @@ and netperf-eu (Denmark)
* -p | --ping: Host to ping to measure latency (default - gstatic.com)
* -i | --idle: Don't send traffic, only measure idle latency
* -n | --number: Number of simultaneous sessions (default - 5 sessions)
* -Z passphrase: Required to use the default netperf.bufferbloat.net server.
Visit the site to get today's value.

The output shows separate (one-way) download and upload speed, along with a summary of latencies, including min, max, average, median, and 10th and 90th percentiles so you can get a sense of the distribution. The tool also displays the percent packet loss. The example below shows two measurements, bad and good.

Expand Down Expand Up @@ -231,7 +233,7 @@ and lets you measure both the total bandwidth and the latency of the link during

To invoke the script:

sh netperfrunner.sh [ -4 | -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [-n simultaneous-streams ]
sh netperfrunner.sh -Z passphrase [ -4 | -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [-n simultaneous-streams ]

Options, if present, are:

Expand All @@ -245,6 +247,8 @@ flent-fremont (also California)
* -t | --time: Duration for how long each direction's test should run - (default - 60 seconds)
* -p | --ping: Host to ping to measure latency (default - gstatic.com)
* -n | --number: Number of simultaneous sessions (default - 4 sessions)
* -Z passphrase: Required for netperf.bufferbloat.net
See `betterspeedtest.sh`

The output of the script looks like this:

Expand Down
41 changes: 31 additions & 10 deletions betterspeedtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
# -p | --ping: Host to ping to measure latency (default - gstatic.com)
# -i | --idle: Don't send traffic, only measure idle latency
# -n | --number: Number of simultaneous sessions (default - 5 sessions)
# -Z Required passphrase - see http://netperf.bufferbloat.net for today's value

# Copyright (c) 2014-2022 - Rich Brown [email protected]
# Copyright (c) 2014-2024 - Rich Brown [email protected]
# GPLv2

# Process the ping times from the passed-in file, and summarize the results
Expand Down Expand Up @@ -69,7 +70,6 @@ sed 's/^.*time=\([^ ]*\) ms/\1/'| \
}

# Print a line of dots as a progress indicator.

print_dots() {
while : ; do
printf "."
Expand All @@ -78,7 +78,6 @@ print_dots() {
}

# Stop the current print_dots() process

kill_dots() {
# echo "Pings: $ping_pid Dots: $dots_pid"
kill -9 "$dots_pid"
Expand All @@ -87,7 +86,6 @@ kill_dots() {
}

# Stop the current ping process

kill_pings() {
# echo "Pings: $ping_pid Dots: $dots_pid"
kill -9 "$ping_pid"
Expand All @@ -102,6 +100,7 @@ clean_up() {
kill_dots
rm "$PINGFILE"
rm "$SPEEDFILE"
rm "$ERRFILE"
}

# Stop the current pings and dots, and exit
Expand All @@ -116,6 +115,14 @@ catch_interrupt() {
exit 1
}

# Display "no passphrase" message and exit
no_passphrase() {
echo ""
echo "Missing passphrase - see netperf.bufferbloat.net"
echo ""
exit 1
}

# ------------ start_pings() ----------------
# Start printing dots, then start a ping process, saving the results to a PINGFILE

Expand Down Expand Up @@ -150,6 +157,7 @@ measure_direction() {

# Create temp file
SPEEDFILE=$(mktemp /tmp/netperfUL.XXXXXX) || exit 1
ERRFILE=$(mktemp /tmp/netperfErr.XXXXXX) || exit 1
DIRECTION=$1

# start off the ping process
Expand All @@ -166,10 +174,10 @@ measure_direction() {
# netperf writes the sole output value (in Mbps) to stdout when completed
for i in $( seq "$MAXSESSIONS" )
do
netperf "$TESTPROTO" -H "$TESTHOST" -t "$dir" -l "$TESTDUR" -v 0 -P 0 >> "$SPEEDFILE" &
netperf "$TESTPROTO" -H "$TESTHOST" -t "$dir" -l "$TESTDUR" -v 0 -P 0 $PASSPHRASEOPTION >> "$SPEEDFILE" 2>> $ERRFILE &
# echo "Starting PID $! params: $TESTPROTO -H $TESTHOST -t $dir -l $TESTDUR -v 0 -P 0 >> $SPEEDFILE"
done
done

# Wait until each of the background netperf processes completes
# echo "Process is $$"
# echo `pgrep -P $$ netperf `
Expand All @@ -180,7 +188,14 @@ measure_direction() {
wait "$i"
done

# Print TCP Download speed
# Check the length of the error file. If it's > 0, then there were errors
file_size=$(wc -c < "$ERRFILE")
if [ $file_size -gt 0 ]; then
clean_up # stop the machinery
no_passphrase # print the error and exit
fi

# Summarize the speed records and print them
echo ""
awk -v dir="$1" '{s+=$1} END {printf " %s: %1.2f Mbps", dir, s}' < "$SPEEDFILE"

Expand All @@ -193,14 +208,15 @@ measure_direction() {

# ------- Start of the main routine --------

# Usage: sh betterspeedtest.sh [ -4 -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -i ] [ -n simultaneous-sessions ]
# Usage: sh betterspeedtest.sh -Z passphrase [ -4 -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -i ] [ -n simultaneous-sessions ]

# “H” and “host” DNS or IP address of the netperf server host (default: netperf.bufferbloat.net)
# “t” and “time” Time to run the test in each direction (default: 60 seconds)
# “p” and “ping” Host to ping for latency measurements (default: gstatic.com)
# "i" and "idle" Don't send up/down traffic - just measure idle link latency
# "n" and "number" Number of simultaneous upload or download sessions (default: 5 sessions;
# 5 sessions chosen empirically because total didn't increase much after that number)
# "Z" Required passphrase - see netperf.bufferbloat.net

# set an initial values for defaults
TESTHOST="netperf.bufferbloat.net"
Expand Down Expand Up @@ -244,8 +260,13 @@ do
esac ;;
-i|--idle)
IDLETEST=true ; shift 1 ;;
-Z)
case "$2" in
"") no_passphrase ; exit 1 ;;
*) PASSPHRASEOPTION="-Z $2" ; shift 2 ;;
esac ;;
--) shift ; break ;;
*) echo "Usage: sh betterspeedtest.sh [-4 -6] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-sessions ] [ --idle ]" ; exit 1 ;;
*) echo "Usage: sh betterspeedtest.sh -Z passphrase [-4 -6] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-sessions ] [ --idle ]" ; exit 1 ;;
esac
done

Expand Down
114 changes: 93 additions & 21 deletions netperfrunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# a) total bandwidth available
# b) the distribution of ping latency

# Usage: sh netperfrunner.sh [ -4 -6 ] [ -H netperf-server ] [ -t duration ] [ -t host-to-ping ] [ -n simultaneous-streams ]
# Usage: sh netperfrunner.sh -Z passphrase [ -4 -6 ] [ -H netperf-server ] [ -t duration ] [ -t host-to-ping ] [ -n simultaneous-streams ]

# Options: If options are present:
#
Expand All @@ -23,8 +23,9 @@
# -t | --time: Duration for how long each direction's test should run - (default - 60 seconds)
# -p | --ping: Host to ping to measure latency (default - gstatic.com)
# -n | --number: Number of simultaneous sessions (default - 5 sessions)
# -Z passphrase: Passphrase required for netperf.bufferbloat.net

# Copyright (c) 2014-2022 - Rich Brown [email protected]
# Copyright (c) 2014-2024 - Rich Brown [email protected]
# GPLv2

# Process the ping times from the passed-in file, and summarize the results
Expand Down Expand Up @@ -74,6 +75,48 @@ sed 's/^.*time=\([^ ]*\) ms/\1/'| \
}'
}

# Print a line of dots as a progress indicator.
print_dots() {
while : ; do
printf "."
sleep 1
done
}

# Stop the current print_dots() process
kill_dots() {
# echo "Pings: $ping_pid Dots: $dots_pid"
kill -9 "$dots_pid"
wait "$dots_pid" 2>/dev/null
dots_pid=0
}

# Stop the current ping process
kill_pings() {
# echo "Pings: $ping_pid Dots: $dots_pid"
kill -9 "$ping_pid"
wait "$ping_pid" 2>/dev/null
ping_pid=0
}

# Clean up all the debris from the testing
clean_up() {
kill_pings
kill_dots
rm "$PINGFILE"
rm "$ULFILE"
rm "$DLFILE"
rm "$ERRFILE"
}

# Display "no passphrase" message and exit
no_passphrase() {
echo ""
echo "Missing passphrase - see netperf.bufferbloat.net"
echo ""
exit 1
}

# ------- Start of the main routine --------

# Usage: sh betterspeedtest.sh [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ]
Expand All @@ -100,6 +143,8 @@ TESTPROTO=-4
ULFILE=`mktemp /tmp/netperfUL.XXXXXX` || exit 1
DLFILE=`mktemp /tmp/netperfDL.XXXXXX` || exit 1
PINGFILE=`mktemp /tmp/measurepings.XXXXXX` || exit 1
ERRFILE=$(mktemp /tmp/netperfErr.XXXXXX) || exit 1

# echo $ULFILE $DLFILE $PINGFILE

# read the options
Expand Down Expand Up @@ -129,8 +174,13 @@ do
"") echo "Missing number of simultaneous sessions" ; exit 1 ;;
*) MAXSESSIONS=$2 ; shift 2 ;;
esac ;;
-Z)
case "$2" in
"") no_passphrase ; exit 1 ;;
*) PASSPHRASEOPTION="-Z $2" ; shift 2 ;;
esac ;;
--) shift ; break ;;
*) echo "Usage: sh Netperfrunner.sh [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-streams ]" ; exit 1 ;;
*) echo "Usage: sh Netperfrunner.sh -Z passphrase [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-streams ]" ; exit 1 ;;
esac
done

Expand All @@ -149,28 +199,45 @@ echo "$DATE Testing $TESTHOST ($PROTO) with $MAXSESSIONS streams down and up whi
# echo "This test is part of the CeroWrt project. To learn more, visit:"
# echo " http://bufferbloat.net/projects/cerowrt/"

# Start Ping
if [ $TESTPROTO -eq "-4" ]
then
"${PING4}" $PINGHOST > $PINGFILE &
else
"${PING6}" $PINGHOST > $PINGFILE &
fi
ping_pid=$!
# echo "Ping PID: $ping_pid"
# ------------ start_pings() ----------------
# Start printing dots, then start a ping process, saving the results to a PINGFILE

start_pings() {

# Create temp file
PINGFILE=$(mktemp /tmp/measurepings.XXXXXX) || exit 1

# Start dots
print_dots &
dots_pid=$!
# echo "Dots PID: $dots_pid"

# Start Ping
if [ "$TESTPROTO" -eq "-4" ]
then
"$PING4" "$PINGHOST" > "$PINGFILE" &
else
"$PING6" "$PINGHOST" > "$PINGFILE" &
fi
ping_pid=$!
# echo "Ping PID: $ping_pid"

}

start_pings

# Start $MAXSESSIONS upload datastreams from netperf client to the netperf server
# netperf writes the sole output value (in Mbps) to stdout when completed
for i in $( seq $MAXSESSIONS )
do
netperf $TESTPROTO -H $TESTHOST -t TCP_STREAM -l $TESTDUR -v 0 -P 0 >> $ULFILE &
netperf $TESTPROTO -H $TESTHOST -t TCP_STREAM -l $TESTDUR -v 0 -P 0 $PASSPHRASEOPTION >> $ULFILE 2>> $ERRFILE&
# echo "Starting upload #$i $!"
done

# Start $MAXSESSIONS download datastreams from netperf server to the client
for i in $( seq $MAXSESSIONS )
do
netperf $TESTPROTO -H $TESTHOST -t TCP_MAERTS -l $TESTDUR -v 0 -P 0 >> $DLFILE &
netperf $TESTPROTO -H $TESTHOST -t TCP_MAERTS -l $TESTDUR -v 0 -P 0 $PASSPHRASEOPTION >> $DLFILE 2>> $ERRFILE&
# echo "Starting download #$i $!"
done

Expand All @@ -184,17 +251,22 @@ do
wait $i
done

# Stop the pings after the netperf's are all done
kill -9 $ping_pid
wait $ping_pid 2>/dev/null
# Check the length of the error file. If it's > 0, then there were errors
file_size=$(wc -c < "$ERRFILE")
if [ $file_size -gt 0 ]; then
clean_up # stop the machinery
no_passphrase # print the error and exit
fi

# # Stop the pings after the netperf's are all done
# kill -9 $ping_pid
# wait $ping_pid 2>/dev/null

# sum up all the values (one line per netperf test) from $DLFILE and $ULFILE
# then summarize the ping stat's
echo ""
echo " Download: " `awk '{s+=$1} END {print s}' $DLFILE` Mbps
echo " Upload: " `awk '{s+=$1} END {print s}' $ULFILE` Mbps
summarize_pings $PINGFILE

# Clean up
rm $PINGFILE
rm $DLFILE
rm $ULFILE
clean_up

0 comments on commit d1a5e7b

Please sign in to comment.