From 1a33492ff845cb4e9ab743dc02b2ad7a98a6c00d Mon Sep 17 00:00:00 2001 From: Nishant Sharma Date: Sun, 22 Apr 2018 12:49:46 +0530 Subject: [PATCH 1/7] mwan3: Packet Loss & Latency Check 1. Test link quality based on packet loss & latency w.r.t. pre-defined high and low watermark values. 2. Extended ubus support to provide packet loss & latency information per wan per track_ip Signed-off-by: Nishant Sharma --- net/mwan3/Makefile | 2 +- net/mwan3/files/etc/config/mwan3 | 5 ++ net/mwan3/files/usr/libexec/rpcd/mwan3 | 2 + net/mwan3/files/usr/sbin/mwan3track | 74 +++++++++++++++++++++----- 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 22a57824f..ff082cf75 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.6.14 +PKG_VERSION:=2.6.15 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2 diff --git a/net/mwan3/files/etc/config/mwan3 b/net/mwan3/files/etc/config/mwan3 index 2fd16bb29..91d9c4ead 100644 --- a/net/mwan3/files/etc/config/mwan3 +++ b/net/mwan3/files/etc/config/mwan3 @@ -5,6 +5,7 @@ config globals 'globals' config interface 'wan' option enabled '1' + option check_quality '1' list track_ip '8.8.4.4' list track_ip '8.8.8.8' list track_ip '208.67.222.222' @@ -13,6 +14,10 @@ config interface 'wan' option reliability '2' option count '1' option timeout '2' + option failure_latency '1000' + option recovery_latency '500' + option failure_loss '20' + option recovery_loss '5' option interval '5' option down '3' option up '8' diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index c30b6a1b9..eb5f98ce5 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -66,6 +66,8 @@ get_mwan3_status() { json_add_object json_add_string ip "${track}" json_add_string status "$(cat "${file}")" + json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")" + json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")" json_close_object fi done diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 3593d11a4..f84ccaec3 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -86,6 +86,11 @@ main() { config_get failure_interval $1 failure_interval $interval config_get_bool keep_failure_interval $1 keep_failure_interval 0 config_get recovery_interval $1 recovery_interval $interval + config_get_bool check_quality $1 check_quality 0 + config_get failure_latency $1 failure_latency 1000 + config_get recovery_latency $1 recovery_latency 500 + config_get failure_loss $1 failure_loss 40 + config_get recovery_loss $1 recovery_loss 10 local score=$(($down+$up)) local track_ips=$(echo $* | cut -d ' ' -f 5-99) @@ -93,6 +98,10 @@ main() { local lost=0 local sleep_time=0 local turn=0 + local result + local ping_result + local loss=0 + local latency=0 if [ "$STATUS" = "unknown" ]; then echo "unknown" > /var/run/mwan3track/$1/STATUS @@ -109,23 +118,64 @@ main() { if [ $host_up_count -lt $reliability ]; then case "$track_method" in ping) - ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null ;; + if [ $check_quality -eq 0 ]; then + ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null + result=$? + $LOG info "ping check result $track_ip on $1 ($2): $result" + else + ping_result=`ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2` + loss=`echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//'` + if [ "$loss" -eq 100 ]; then + latency=999999 + else + latency=`echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1` + fi + fi + ;; arping) - arping -I $DEVICE -c $count -w $timeout -q $track_ip &> /dev/null ;; + arping -I $DEVICE -c $count -w $timeout -q $track_ip &> /dev/null + result=$? + ;; httping) - httping -y $SRC_IP -c $count -t $timeout -q $track_ip &> /dev/null ;; + httping -y $SRC_IP -c $count -t $timeout -q $track_ip &> /dev/null + result=$? + ;; esac - if [ $? -eq 0 ]; then - let host_up_count++ - echo "up" > /var/run/mwan3track/$1/TRACK_${track_ip} - if [ $score -le $up ]; then - $LOG info "Check ($track_method) success for target \"$track_ip\" on interface $1 ($2)" + if [ $check_quality -eq 0 ]; then + if [ $result -eq 0 ]; then + let host_up_count++ + echo "up" > /var/run/mwan3track/$1/TRACK_${track_ip} + if [ $score -le $up ]; then + $LOG info "Check ($track_method) success for target \"$track_ip\" on interface $1 ($2)" + fi + else + let lost++ + echo "down" > /var/run/mwan3track/$1/TRACK_${track_ip} + if [ $score -gt $up ]; then + $LOG info "Check ($track_method) failed for target \"$track_ip\" on interface $1 ($2)" + fi fi else - let lost++ - echo "down" > /var/run/mwan3track/$1/TRACK_${track_ip} - if [ $score -gt $up ]; then - $LOG info "Check ($track_method) failed for target \"$track_ip\" on interface $1 ($2)" + if [ "$loss" -ge "$failure_loss" -o "$latency" -ge "$failure_latency" ]; then + let lost++ + echo "down" > /var/run/mwan3track/$1/TRACK_${track_ip} + echo "$latency" > /var/run/mwan3track/$1/LATENCY_${track_ip} + echo "$loss" > /var/run/mwan3track/$1/LOSS_${track_ip} + + if [ $score -gt $up ]; then + $LOG info "Failed: Latency=$latency ms Loss=$loss% for target \"$track_ip\" on interface $1 ($2)" + fi + elif [ "$loss" -le "$recovery_loss" -a "$latency" -le "$recovery_latency" ]; then + let host_up_count++ + echo "up" > /var/run/mwan3track/$1/TRACK_${track_ip} + echo "$latency" > /var/run/mwan3track/$1/LATENCY_${track_ip} + echo "$loss" > /var/run/mwan3track/$1/LOSS_${track_ip} + + if [ $score -le $up ]; then + $LOG info "Success: Latency=$latency ms Loss=$loss% for target \"$track_ip\" on interface $1 ($2)" + fi + else + echo "skipped" > /var/run/mwan3track/$1/TRACK_${track_ip} fi fi else From 5f068b7fb3576f458fc0a5a609a6b41aeec55a43 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 11 May 2018 08:24:03 +0200 Subject: [PATCH 2/7] net/mwan3: remove needless log output on mwan3track Remove needless log output this will pollute the logging. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/sbin/mwan3track | 1 - 1 file changed, 1 deletion(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index f84ccaec3..068e9cb14 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -121,7 +121,6 @@ main() { if [ $check_quality -eq 0 ]; then ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null result=$? - $LOG info "ping check result $track_ip on $1 ($2): $result" else ping_result=`ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2` loss=`echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//'` From 7962bfd3dfc506b4abe8a6388442f3a9adeafeab Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 11 May 2018 08:28:57 +0200 Subject: [PATCH 3/7] net/mwan3: replace legancy backticks Replace legancy backticks syntax shell execution with braces. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/sbin/mwan3track | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 068e9cb14..c70547904 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -122,12 +122,12 @@ main() { ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null result=$? else - ping_result=`ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2` - loss=`echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//'` + ping_result="$(ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2)" + loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" if [ "$loss" -eq 100 ]; then latency=999999 else - latency=`echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1` + latency="$(echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1)" fi fi ;; From 3b33e0179180beaffa10a2cfaa08621e18ae0113 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 11 May 2018 08:30:54 +0200 Subject: [PATCH 4/7] net/mwan3: fix indentation Fix indentation. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/sbin/mwan3track | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index c70547904..f445b146e 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -118,18 +118,18 @@ main() { if [ $host_up_count -lt $reliability ]; then case "$track_method" in ping) - if [ $check_quality -eq 0 ]; then - ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null - result=$? + if [ $check_quality -eq 0 ]; then + ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null + result=$? + else + ping_result="$(ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2)" + loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" + if [ "$loss" -eq 100 ]; then + latency=999999 else - ping_result="$(ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2)" - loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" - if [ "$loss" -eq 100 ]; then - latency=999999 - else - latency="$(echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1)" - fi + latency="$(echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1)" fi + fi ;; arping) arping -I $DEVICE -c $count -w $timeout -q $track_ip &> /dev/null From 21c42901e13ae38f7fbc4e0c51b24b45332efc11 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 11 May 2018 08:35:43 +0200 Subject: [PATCH 5/7] net/mwan3: update logging output Unify logging output for tracking methode ping. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/sbin/mwan3track | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index f445b146e..9bc17ed8d 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -162,7 +162,7 @@ main() { echo "$loss" > /var/run/mwan3track/$1/LOSS_${track_ip} if [ $score -gt $up ]; then - $LOG info "Failed: Latency=$latency ms Loss=$loss% for target \"$track_ip\" on interface $1 ($2)" + $LOG info "Check (${track_method}: latency=${latency}ms loss=${loss}%) failed for target \"$track_ip\" on interface $1 ($2)" fi elif [ "$loss" -le "$recovery_loss" -a "$latency" -le "$recovery_latency" ]; then let host_up_count++ @@ -171,7 +171,7 @@ main() { echo "$loss" > /var/run/mwan3track/$1/LOSS_${track_ip} if [ $score -le $up ]; then - $LOG info "Success: Latency=$latency ms Loss=$loss% for target \"$track_ip\" on interface $1 ($2)" + $LOG info "Check (${track_method}: latency=${latency}ms loss=${loss}%) success for target \"$track_ip\" on interface $1 ($2)" fi else echo "skipped" > /var/run/mwan3track/$1/TRACK_${track_ip} From bdff2e990b95415a74d13daa78a863e60e8b7c30 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 11 May 2018 08:38:38 +0200 Subject: [PATCH 6/7] net/mwan3: remove check_quality option from default config The normal situation should be to use ping without quality_check. If quality_check option is not set in the default option then ping quality_check is not performed during tracking. This is and should be the default situation. Signed-off-by: Florian Eckert --- net/mwan3/files/etc/config/mwan3 | 1 - 1 file changed, 1 deletion(-) diff --git a/net/mwan3/files/etc/config/mwan3 b/net/mwan3/files/etc/config/mwan3 index 91d9c4ead..b7f6c2c11 100644 --- a/net/mwan3/files/etc/config/mwan3 +++ b/net/mwan3/files/etc/config/mwan3 @@ -5,7 +5,6 @@ config globals 'globals' config interface 'wan' option enabled '1' - option check_quality '1' list track_ip '8.8.4.4' list track_ip '8.8.8.8' list track_ip '208.67.222.222' From 0d5dd6da4f555346f20b83a290a5bd3236a8a647 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 11 May 2018 09:00:57 +0200 Subject: [PATCH 7/7] net/mwan3: add missing local variables Signed-off-by: Florian Eckert --- net/mwan3/files/usr/sbin/mwan3track | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 9bc17ed8d..274a024cc 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -53,7 +53,8 @@ validate_track_method() { main() { local reliability count timeout interval failure_interval local recovery_interval down up size - local keep_failure_interval + local keep_failure_interval check_quality failure_latency + local recovery_latency failure_loss recovery_loss [ -z "$5" ] && echo "Error: should not be started manually" && exit 0