From da603e93109584d86da7c27c62334c170f75d27c Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Tue, 8 Aug 2023 12:50:39 +0200 Subject: [PATCH] Add upload support to server speed test --- openmptcprouter/files/bin/omr-test-speed | 29 +++++++++---- .../files/bin/omr-test-speed-server | 42 ++++++++++++++----- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/openmptcprouter/files/bin/omr-test-speed b/openmptcprouter/files/bin/omr-test-speed index ab8e1a929..2aaf3b72b 100755 --- a/openmptcprouter/files/bin/omr-test-speed +++ b/openmptcprouter/files/bin/omr-test-speed @@ -1,19 +1,25 @@ #!/bin/sh -# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 : +# (c) Yannick Chabanois (ycarus@zugaina.org) for OpenMPTCProuter +# +# + FORCEVPS=false +FASTTEST=false if [ "$1" = "forcevps" ]; then - INTERFACE="$2" FORCEVPS=true -else - INTERFACE="$1" fi +if [ "$1" = "fasttest" ]; then + FASTTEST=true +fi +for i in $@; do :; done +INTERFACE="$i" [ -n "$INTERFACE" ] && [ ! -d "/sys/class/net/$INTERFACE" ] && { echo "You must use a real interface. You wan find them using 'ip a' for example" exit 0 } -echo "Select best test server..." +[ "$FASTTEST" ] || echo "Select best test server..." HOSTLST="http://scaleway.testdebit.info/10G.iso http://bordeaux.testdebit.info/10G.iso http://aix-marseille.testdebit.info/10G.iso http://lyon.testdebit.info/10G.iso http://lille.testdebit.info/10G.iso http://paris.testdebit.info/10G.iso http://appliwave.testdebit.info/10G/10G.iso http://speedtest.frankfurt.linode.com/garbage.php?ckSize=10000 http://speedtest.tokyo2.linode.com/garbage.php?ckSize=10000 http://speedtest.singapore.linode.com/garbage.php?ckSize=10000 http://speedtest.newark.linode.com/garbage.php?ckSize=10000 http://speedtest.atlanta.linode.com/garbage.php?ckSize=10000 http://speedtest.dallas.linode.com/garbage.php?ckSize=10000 http://speedtest.fremont.linode.com/garbage.php?ckSize=10000 https://speed.hetzner.de/10GB.bin http://ipv4.bouygues.testdebit.info/10G.iso http://par.download.datapacket.com/10000mb.bin http://nyc.download.datapacket.com/10000mb.bin http://ams.download.datapacket.com/10000mb.bin http://fra.download.datapacket.com/10000mb.bin http://lon.download.datapacket.com/10000mb.bin http://mad.download.datapacket.com/10000mb.bin http://prg.download.datapacket.com/10000mb.bin http://sto.download.datapacket.com/10000mb.bin http://vie.download.datapacket.com/10000mb.bin http://war.download.datapacket.com/10000mb.bin http://atl.download.datapacket.com/10000mb.bin http://chi.download.datapacket.com/10000mb.bin http://lax.download.datapacket.com/10000mb.bin http://mia.download.datapacket.com/10000mb.bin http://nyc.download.datapacket.com/10000mb.bin http://speedtest.milkywan.fr/files/10G.iso" bestping="9999" for pinghost in $HOSTLST; do @@ -23,7 +29,7 @@ for pinghost in $HOSTLST; do else ping=$(ping -4 -c1 -w2 -I $INTERFACE -B $domain | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') fi - echo "host: $domain - ping: $ping" + [ "$FASTTEST" ] || echo "host: $domain - ping: $ping" if [ -n "$ping" ] && [ "$ping" -lt "$bestping" ]; then bestping=$ping HOST=$pinghost @@ -32,11 +38,12 @@ done [ -z "$HOST" ] && HOST="https://speed.hetzner.de/10GB.bin" -echo "Best server is $HOST, running test:" +[ "$FASTTEST" ] || echo "Best server is $HOST, running test:" trap : HUP INT TERM if [ -z "$INTERFACE" ]; then curl -4 -o /dev/null $HOST || echo else + : /etc/init.d/sqm stop $INTERFACE domain=$(echo $HOST | awk -F/ '{print $3}') hostip=$(dig +nocmd +noall +answer A $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ') if [ -n "$(ipset list 2>/dev/null | grep ss_rules)" ]; then @@ -44,10 +51,16 @@ else ipset add ss_rules_dst_bypass_all $ip done fi - curl -4 -o /dev/null --interface $INTERFACE $HOST || echo + if [ "$FASTTEST" ]; then + avg_speed=$(curl -4 --max-time 10 -o /dev/null -qfsS -w '%{speed_download}' --interface $INTERFACE $HOST 2>/dev/null) + echo "$avg_speed" + else + curl -4 --max-time 4 -o /dev/null --interface $INTERFACE $HOST || echo + fi if [ -n "$(ipset list 2>/dev/null | grep ss_rules)" ]; then for ip in $hostip; do ipset del ss_rules_dst_bypass_all $ip done fi + : /etc/init.d/sqm start $INTERFACE fi diff --git a/openmptcprouter/files/bin/omr-test-speed-server b/openmptcprouter/files/bin/omr-test-speed-server index df61352ec..a937a6763 100755 --- a/openmptcprouter/files/bin/omr-test-speed-server +++ b/openmptcprouter/files/bin/omr-test-speed-server @@ -1,6 +1,10 @@ #!/bin/sh SERVER=$1 INTERFACE=$2 +[ "$3" = "upload" ] && UPLOAD=$3 +[ "$3" = "fasttest" ] && FASTTEST=$3 +[ "$4" = "upload" ] && UPLOAD=$4 +[ "$4" = "fasttest" ] && FASTTEST=$4 [ -z "$SERVER" ] && SERVER="vps" KEY=$(uci -q get openmptcprouter.$SERVER.token) HOST=$(uci -q get openmptcprouter.$SERVER.ip | awk '{print $1}') @@ -8,19 +12,37 @@ PORT=$(uci -q get openmptcprouter.$SERVER.port) MP=false if [ -n "$KEY" ] && [ -n "$HOST" ] && [ -n "$PORT" ]; then trap : HUP INT TERM - echo "Download test via server ${SERVER}:" + [ -z "$FASTTEST" ] && echo "Disable SQM bandwidth limit on $INTERFACE" + : /etc/init.d/sqm stop $INTERFACE 2>&1 >/dev/null + [ -z "$FASTTEST" ] && echo "Download test via server ${SERVER}:" if [ -n "$INTERFACE" ]; then - if [ "$(multipath ${INTERFACE} | grep default)" ]; then - MP=true - /etc/init.d/omr-tracker stop 2>&1 >/dev/null - multipath ${INTERFACE} off - fi - curl -k -o /dev/null --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo - if [ $MP ]; then - multipath ${INTERFACE} on - /etc/init.d/omr-tracker start & 2>&1 >/dev/null + #if [ "$(multipath ${INTERFACE} | grep default)" ]; then + # MP=true + # /etc/init.d/omr-tracker stop 2>&1 >/dev/null + # multipath ${INTERFACE} off + #fi + if [ -n "$FASTTEST" ]; then + if [ -n "$UPLOAD" ]; then + avg_speed=$(curl -k --max-time 30 -o /dev/null -qfsS -w '%{speed_upload}' -X POST -d @/boot/vmlinuz -d @/boot/vmlinuz --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest 2>/dev/null) + echo -n "$avg_speed" + else + avg_speed=$(curl -k --max-time 30 -o /dev/null -qfsS -w '%{speed_download}' --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest 2>/dev/null) + echo -n "$avg_speed" + fi + else + if [ -n "$UPLOAD" ]; then + curl -k -o /dev/null -X POST -d @/boot/vmlinuz -d @/boot/vmlinuz --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo + else + curl -k -o /dev/null --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo + fi fi + #if [ $MP ]; then + # multipath ${INTERFACE} on + # /etc/init.d/omr-tracker start & 2>&1 >/dev/null + #fi else curl -k -o /dev/null -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo fi + [ -z "$FASTTEST" ] && echo "Restart SQM on $INTERFACE" + : /etc/init.d/sqm start $INTERFACE 2>&1 >/dev/null fi \ No newline at end of file