From 9d206f736201e4054d01bb030e45e3ab3105d971 Mon Sep 17 00:00:00 2001 From: Rich Brown Date: Sat, 27 Jul 2019 14:44:02 -0400 Subject: [PATCH] betterspeedtest.sh - Add --idle parameter to measure latency without added traffic from the script tunnelbroker.sh - Update documentation for OpenWrt use --- README.md | 27 ++++++++--- betterspeedtest.sh | 113 +++++++++++++++++++++++++++++---------------- tunnelbroker.sh | 5 +- 3 files changed, 96 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index fcaa4e4..37bb385 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,12 @@ and netperf-eu (Denmark) * -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) +* -i | --idle: Don't send traffic, only measure idle latency 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. +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. + 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. 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 There are several steps: 1. Go to the Hurricane Electric [TunnelBroker.net](http://www.tunnelbroker.net/) site to set up your free account. -There are detailed instructions for setting up an account and an IPv6 tunnel -in the script itself, or at the -[IPv6 Tunnel page.](http://www.bufferbloat.net/projects/cerowrt/wiki/IPv6_Tunnel) -2. Edit the tunnelbroker.sh script to use the values supplied by Tunnelbroker.net. -The values from the "Tunnel Details" page go into the matching lines of the script. -3. ssh into the router and execute this script with these steps. +There are detailed instructions for setting up an account and an IPv6 tunnel in the script itself, or at the +[IPv6 Tunnel page](http://www.bufferbloat.net/projects/cerowrt/wiki/IPv6_Tunnel) of [bufferbloat.net](bufferbloat.net) +2. From the tunnelbroker main page, click "Create Regular Tunnel" + * Enter your IP address in "IPv4 Endpoint" (paste in the address you're "viewing from") + * Select a nearby Tunnel Server + * Click "Create Tunnel" + +3. On the resulting Tunnel Details page, click **Assign /48** to get a /48 prefix +4. From the Tunnel Details page, copy and paste the matching values into the `tunnel.sh` file. +The *User\_Name* is the name you used to create the account. +Find the *Update\_Key* on the Advanced Tab of the Tunnel Details page. + +5. ssh into the router and execute this script with these steps. ssh root@192.168.1.1 # use the address of your router cd /tmp cat > tunnel.sh [paste in the contents of this file, then hit ^D] + [edit the script to match your tunnelbroker values] sh tunnel.sh [Restart your router. This seems to make a difference.] -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` +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` diff --git a/betterspeedtest.sh b/betterspeedtest.sh index 8443ed8..f04a905 100755 --- a/betterspeedtest.sh +++ b/betterspeedtest.sh @@ -16,8 +16,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) +# -i | --idle: Don't send traffic, only measure idle latency -# Copyright (c) 2014 - Rich Brown rich.brown@blueberryhillsoftware.com +# Copyright (c) 2014-2019 - Rich Brown rich.brown@blueberryhillsoftware.com # GPLv2 # Summarize the contents of the ping's output file to show min, avg, median, max, etc. @@ -30,6 +31,11 @@ summarize_pings() { # awk builds an array of those values, and prints first & last (which are min, max) # and computes average. # If the number of samples is >= 10, also computes median, and 10th and 90th percentile readings + + # stop pinging and drawing dots + kill_pings + kill_dots + sed 's/^.*time=\([^ ]*\) ms/\1/' < $1 | grep -v "PING" | sort -n | \ awk 'BEGIN {numdrops=0; numrows=0;} \ { \ @@ -48,8 +54,12 @@ summarize_pings() { if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \ }; \ pktloss = numdrops/(numdrops+numrows) * 100; \ - 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] )\ + 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] )\ }' + + # and finally remove the PINGFILE + rm $1 + } # Print a line of dots as a progress indicator. @@ -83,21 +93,18 @@ kill_pings() { # ping command catches (and handles) first Ctrl-C, so you have to hit it again... kill_pings_and_dots_and_exit() { kill_dots + kill_pings echo "\nStopped" exit 1 } -# ------------ Measure speed and ping latency for one direction ---------------- -# -# Call measure_direction() with single parameter - "Download" or " Upload" -# The function gets other info from globals determined from command-line arguments +# ------------ start_pings() ---------------- +# Start printing dots, then start a ping process, saving the results to a PINGFILE -measure_direction() { +start_pings() { - # Create temp files + # Create temp file PINGFILE=`mktemp /tmp/measurepings.XXXXXX` || exit 1 - SPEEDFILE=`mktemp /tmp/netperfUL.XXXXXX` || exit 1 - DIRECTION=$1 # Start dots print_dots & @@ -113,7 +120,23 @@ measure_direction() { fi ping_pid=$! # echo "Ping PID: $ping_pid" + +} + +# ------------ Measure speed and ping latency for one direction ---------------- +# +# Call measure_direction() with single parameter - "Download" or " Upload" +# The function gets other info from globals determined from command-line arguments + +measure_direction() { + + # Create temp file + SPEEDFILE=`mktemp /tmp/netperfUL.XXXXXX` || exit 1 + DIRECTION=$1 + # start off the ping process + start_pings + # Start netperf with the proper direction if [ $DIRECTION = "Download" ]; then dir="TCP_MAERTS" @@ -141,26 +164,22 @@ measure_direction() { # Print TCP Download speed echo "" - echo " $1: " `awk '{s+=$1} END {print s}' $SPEEDFILE` Mbps + awk -v dir="$1" '{s+=$1} END {printf " %s: %1.2f Mbps", dir, s}' < $SPEEDFILE - # When netperf completes, stop the dots and the pings - kill_pings - kill_dots - - # Summarize the ping data + # When netperf completes, summarize the ping data summarize_pings $PINGFILE - rm $PINGFILE rm $SPEEDFILE } # ------- Start of the main routine -------- -# Usage: sh betterspeedtest.sh [ -4 -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-sessions ] +# Usage: sh betterspeedtest.sh [ -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) @@ -170,6 +189,7 @@ TESTDUR="60" PINGHOST="gstatic.com" MAXSESSIONS="5" TESTPROTO="-4" +IDLETEST=false # read the options @@ -178,28 +198,30 @@ while [ $# -gt 0 ] do case "$1" in -4|-6) TESTPROTO=$1 ; shift 1 ;; - -H|--host) - case "$2" in - "") echo "Missing hostname" ; exit 1 ;; - *) TESTHOST=$2 ; shift 2 ;; - esac ;; - -t|--time) + -H|--host) case "$2" in - "") echo "Missing duration" ; exit 1 ;; - *) TESTDUR=$2 ; shift 2 ;; - esac ;; - -p|--ping) - case "$2" in - "") echo "Missing ping host" ; exit 1 ;; - *) PINGHOST=$2 ; shift 2 ;; - esac ;; - -n|--number) - case "$2" in - "") echo "Missing number of simultaneous sessions" ; exit 1 ;; - *) MAXSESSIONS=$2 ; shift 2 ;; + "") echo "Missing hostname" ; exit 1 ;; + *) TESTHOST=$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 ]" ; exit 1 ;; + -t|--time) + case "$2" in + "") echo "Missing duration" ; exit 1 ;; + *) TESTDUR=$2 ; shift 2 ;; + esac ;; + -p|--ping) + case "$2" in + "") echo "Missing ping host" ; exit 1 ;; + *) PINGHOST=$2 ; shift 2 ;; + esac ;; + -n|--number) + case "$2" in + "") echo "Missing number of simultaneous sessions" ; exit 1 ;; + *) MAXSESSIONS=$2 ; shift 2 ;; + esac ;; + -i|--idle) + IDLETEST=true ; shift 1 ;; + --) shift ; break ;; + *) echo "Usage: sh betterspeedtest.sh [-4 -6] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -n simultaneous-sessions ] [ --idle ]" ; exit 1 ;; esac done @@ -212,11 +234,20 @@ else PROTO="ipv6" fi DATE=`date "+%Y-%m-%d %H:%M:%S"` -echo "$DATE Testing against $TESTHOST ($PROTO) with $MAXSESSIONS simultaneous sessions while pinging $PINGHOST ($TESTDUR seconds in each direction)" # Catch a Ctl-C and stop the pinging and the print_dots trap kill_pings_and_dots_and_exit HUP INT TERM -measure_direction "Download" -measure_direction " Upload" +if $IDLETEST +then + echo "$DATE Testing idle line while pinging $PINGHOST ($TESTDUR seconds)" + start_pings + sleep $TESTDUR + summarize_pings $PINGFILE + +else + echo "$DATE Testing against $TESTHOST ($PROTO) with $MAXSESSIONS simultaneous sessions while pinging $PINGHOST ($TESTDUR seconds in each direction)" + measure_direction "Download" + measure_direction " Upload" +fi diff --git a/tunnelbroker.sh b/tunnelbroker.sh index 54f4a5e..f252064 100644 --- a/tunnelbroker.sh +++ b/tunnelbroker.sh @@ -27,6 +27,7 @@ Update_Key=AbCDeF54321vWxYz # cd /tmp # cat > tunnel.sh # [paste in the contents of this file, then hit ^D] +# [edit the script to match your tunnelbroker values (see #4 above)] # sh tunnel.sh # [Restart your router. This seems to make a difference.] # @@ -90,4 +91,6 @@ echo 'Done. You could also restart the router now to ensure these take effect.' # --- end of script --- # # Final Steps: -# Hit Ctl-D, then type sh tunnel.sh +# 1) Hit Ctl-D +# 2) Edit six lines of the file (User_Name through Update_Key) to add your tunnelbroker values +# 3) Type: sh tunnel.sh