Skip to content

Commit 9d206f7

Browse files
committed
betterspeedtest.sh - Add --idle parameter to measure latency without added traffic from the script
tunnelbroker.sh - Update documentation for OpenWrt use
1 parent 7e07b82 commit 9d206f7

File tree

3 files changed

+95
-48
lines changed

3 files changed

+95
-48
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ and netperf-eu (Denmark)
127127
* -t | --time: Duration for how long each direction's test should run - (default - 60 seconds)
128128
* -p | --ping: Host to ping to measure latency (default - gstatic.com)
129129
* -n | --number: Number of simultaneous sessions (default - 5 sessions)
130+
* -i | --idle: Don't send traffic, only measure idle latency
130131

131132
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.
132133

134+
The Idle test uses the same process to measure latency of the line, but without any additional traffic from this script. It runs for the specified --time.
135+
133136
On the left is a test run without SQM. Note that the latency gets huge (greater than 5 seconds), meaning that network performance would be terrible for anyone else using the network.
134137

135138
On the right is a test using SQM: the latency goes up a little (less than 23 msec under load), and network performance remains good.
@@ -216,19 +219,29 @@ It's an easy way to become familiar with IPv6 if your ISP doesn't offer native I
216219
There are several steps:
217220

218221
1. Go to the Hurricane Electric [TunnelBroker.net](http://www.tunnelbroker.net/) site to set up your free account.
219-
There are detailed instructions for setting up an account and an IPv6 tunnel
220-
in the script itself, or at the
221-
[IPv6 Tunnel page.](http://www.bufferbloat.net/projects/cerowrt/wiki/IPv6_Tunnel)
222-
2. Edit the tunnelbroker.sh script to use the values supplied by Tunnelbroker.net.
223-
The values from the "Tunnel Details" page go into the matching lines of the script.
224-
3. ssh into the router and execute this script with these steps.
222+
There are detailed instructions for setting up an account and an IPv6 tunnel in the script itself, or at the
223+
[IPv6 Tunnel page](http://www.bufferbloat.net/projects/cerowrt/wiki/IPv6_Tunnel) of [bufferbloat.net](bufferbloat.net)
224+
2. From the tunnelbroker main page, click "Create Regular Tunnel"
225+
* Enter your IP address in "IPv4 Endpoint" (paste in the address you're "viewing from")
226+
* Select a nearby Tunnel Server
227+
* Click "Create Tunnel"
228+
229+
3. On the resulting Tunnel Details page, click **Assign /48** to get a /48 prefix
230+
4. From the Tunnel Details page, copy and paste the matching values into the `tunnel.sh` file.
231+
The *User\_Name* is the name you used to create the account.
232+
Find the *Update\_Key* on the Advanced Tab of the Tunnel Details page.
233+
234+
5. ssh into the router and execute this script with these steps.
225235

226236
ssh [email protected] # use the address of your router
227237
cd /tmp
228238
cat > tunnel.sh
229239
[paste in the contents of this file, then hit ^D]
240+
[edit the script to match your tunnelbroker values]
230241
sh tunnel.sh
231242
[Restart your router. This seems to make a difference.]
232243

233-
Presto! Your tunnel is up! Your computer should get a global IPv6 address, and should be able to communicate directly with IPv6 devices on the Internet. To test it, try: `ping6 ivp6.google.com`
244+
Presto! Your tunnel is up!
245+
Your computer should get a global IPv6 address, and should be able to communicate directly with IPv6 devices on the Internet.
246+
To test it, try: `ping6 ivp6.google.com`
234247

betterspeedtest.sh

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
# -t | --time: Duration for how long each direction's test should run - (default - 60 seconds)
1717
# -p | --ping: Host to ping to measure latency (default - gstatic.com)
1818
# -n | --number: Number of simultaneous sessions (default - 5 sessions)
19+
# -i | --idle: Don't send traffic, only measure idle latency
1920

20-
# Copyright (c) 2014 - Rich Brown [email protected]
21+
# Copyright (c) 2014-2019 - Rich Brown [email protected]
2122
# GPLv2
2223

2324
# Summarize the contents of the ping's output file to show min, avg, median, max, etc.
@@ -30,6 +31,11 @@ summarize_pings() {
3031
# awk builds an array of those values, and prints first & last (which are min, max)
3132
# and computes average.
3233
# If the number of samples is >= 10, also computes median, and 10th and 90th percentile readings
34+
35+
# stop pinging and drawing dots
36+
kill_pings
37+
kill_dots
38+
3339
sed 's/^.*time=\([^ ]*\) ms/\1/' < $1 | grep -v "PING" | sort -n | \
3440
awk 'BEGIN {numdrops=0; numrows=0;} \
3541
{ \
@@ -48,8 +54,12 @@ summarize_pings() {
4854
if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \
4955
}; \
5056
pktloss = numdrops/(numdrops+numrows) * 100; \
51-
printf(" Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\
57+
printf("\n Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\
5258
}'
59+
60+
# and finally remove the PINGFILE
61+
rm $1
62+
5363
}
5464

5565
# Print a line of dots as a progress indicator.
@@ -83,21 +93,18 @@ kill_pings() {
8393
# ping command catches (and handles) first Ctrl-C, so you have to hit it again...
8494
kill_pings_and_dots_and_exit() {
8595
kill_dots
96+
kill_pings
8697
echo "\nStopped"
8798
exit 1
8899
}
89100

90-
# ------------ Measure speed and ping latency for one direction ----------------
91-
#
92-
# Call measure_direction() with single parameter - "Download" or " Upload"
93-
# The function gets other info from globals determined from command-line arguments
101+
# ------------ start_pings() ----------------
102+
# Start printing dots, then start a ping process, saving the results to a PINGFILE
94103

95-
measure_direction() {
104+
start_pings() {
96105

97-
# Create temp files
106+
# Create temp file
98107
PINGFILE=`mktemp /tmp/measurepings.XXXXXX` || exit 1
99-
SPEEDFILE=`mktemp /tmp/netperfUL.XXXXXX` || exit 1
100-
DIRECTION=$1
101108

102109
# Start dots
103110
print_dots &
@@ -113,7 +120,23 @@ measure_direction() {
113120
fi
114121
ping_pid=$!
115122
# echo "Ping PID: $ping_pid"
123+
124+
}
125+
126+
# ------------ Measure speed and ping latency for one direction ----------------
127+
#
128+
# Call measure_direction() with single parameter - "Download" or " Upload"
129+
# The function gets other info from globals determined from command-line arguments
130+
131+
measure_direction() {
132+
133+
# Create temp file
134+
SPEEDFILE=`mktemp /tmp/netperfUL.XXXXXX` || exit 1
135+
DIRECTION=$1
116136

137+
# start off the ping process
138+
start_pings
139+
117140
# Start netperf with the proper direction
118141
if [ $DIRECTION = "Download" ]; then
119142
dir="TCP_MAERTS"
@@ -141,26 +164,22 @@ measure_direction() {
141164

142165
# Print TCP Download speed
143166
echo ""
144-
echo " $1: " `awk '{s+=$1} END {print s}' $SPEEDFILE` Mbps
145-
146-
# When netperf completes, stop the dots and the pings
147-
kill_pings
148-
kill_dots
167+
awk -v dir="$1" '{s+=$1} END {printf " %s: %1.2f Mbps", dir, s}' < $SPEEDFILE
149168

150-
# Summarize the ping data
169+
# When netperf completes, summarize the ping data
151170
summarize_pings $PINGFILE
152171

153-
rm $PINGFILE
154172
rm $SPEEDFILE
155173
}
156174

157175
# ------- Start of the main routine --------
158176

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

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

@@ -170,6 +189,7 @@ TESTDUR="60"
170189
PINGHOST="gstatic.com"
171190
MAXSESSIONS="5"
172191
TESTPROTO="-4"
192+
IDLETEST=false
173193

174194
# read the options
175195

@@ -178,28 +198,30 @@ while [ $# -gt 0 ]
178198
do
179199
case "$1" in
180200
-4|-6) TESTPROTO=$1 ; shift 1 ;;
181-
-H|--host)
182-
case "$2" in
183-
"") echo "Missing hostname" ; exit 1 ;;
184-
*) TESTHOST=$2 ; shift 2 ;;
185-
esac ;;
186-
-t|--time)
201+
-H|--host)
187202
case "$2" in
188-
"") echo "Missing duration" ; exit 1 ;;
189-
*) TESTDUR=$2 ; shift 2 ;;
190-
esac ;;
191-
-p|--ping)
192-
case "$2" in
193-
"") echo "Missing ping host" ; exit 1 ;;
194-
*) PINGHOST=$2 ; shift 2 ;;
195-
esac ;;
196-
-n|--number)
203+
"") echo "Missing hostname" ; exit 1 ;;
204+
*) TESTHOST=$2 ; shift 2 ;;
205+
esac ;;
206+
-t|--time)
207+
case "$2" in
208+
"") echo "Missing duration" ; exit 1 ;;
209+
*) TESTDUR=$2 ; shift 2 ;;
210+
esac ;;
211+
-p|--ping)
197212
case "$2" in
198-
"") echo "Missing number of simultaneous sessions" ; exit 1 ;;
199-
*) MAXSESSIONS=$2 ; shift 2 ;;
213+
"") echo "Missing ping host" ; exit 1 ;;
214+
*) PINGHOST=$2 ; shift 2 ;;
200215
esac ;;
201-
--) shift ; break ;;
202-
*) echo "Usage: sh betterspeedtest.sh [-4 -6] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-sessions ]" ; exit 1 ;;
216+
-n|--number)
217+
case "$2" in
218+
"") echo "Missing number of simultaneous sessions" ; exit 1 ;;
219+
*) MAXSESSIONS=$2 ; shift 2 ;;
220+
esac ;;
221+
-i|--idle)
222+
IDLETEST=true ; shift 1 ;;
223+
--) shift ; break ;;
224+
*) echo "Usage: sh betterspeedtest.sh [-4 -6] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-sessions ] [ --idle ]" ; exit 1 ;;
203225
esac
204226
done
205227

@@ -212,11 +234,20 @@ else
212234
PROTO="ipv6"
213235
fi
214236
DATE=`date "+%Y-%m-%d %H:%M:%S"`
215-
echo "$DATE Testing against $TESTHOST ($PROTO) with $MAXSESSIONS simultaneous sessions while pinging $PINGHOST ($TESTDUR seconds in each direction)"
216237

217238
# Catch a Ctl-C and stop the pinging and the print_dots
218239
trap kill_pings_and_dots_and_exit HUP INT TERM
219240

220-
measure_direction "Download"
221-
measure_direction " Upload"
241+
if $IDLETEST
242+
then
243+
echo "$DATE Testing idle line while pinging $PINGHOST ($TESTDUR seconds)"
244+
start_pings
245+
sleep $TESTDUR
246+
summarize_pings $PINGFILE
247+
248+
else
249+
echo "$DATE Testing against $TESTHOST ($PROTO) with $MAXSESSIONS simultaneous sessions while pinging $PINGHOST ($TESTDUR seconds in each direction)"
250+
measure_direction "Download"
251+
measure_direction " Upload"
252+
fi
222253

tunnelbroker.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Update_Key=AbCDeF54321vWxYz
2727
# cd /tmp
2828
# cat > tunnel.sh
2929
# [paste in the contents of this file, then hit ^D]
30+
# [edit the script to match your tunnelbroker values (see #4 above)]
3031
# sh tunnel.sh
3132
# [Restart your router. This seems to make a difference.]
3233
#
@@ -90,4 +91,6 @@ echo 'Done. You could also restart the router now to ensure these take effect.'
9091
# --- end of script ---
9192
#
9293
# Final Steps:
93-
# Hit Ctl-D, then type sh tunnel.sh
94+
# 1) Hit Ctl-D
95+
# 2) Edit six lines of the file (User_Name through Update_Key) to add your tunnelbroker values
96+
# 3) Type: sh tunnel.sh

0 commit comments

Comments
 (0)