mwan3: Packet Loss & Latency Check
authorNishant Sharma <redacted>
Sun, 22 Apr 2018 07:19:46 +0000 (12:49 +0530)
committerFlorian Eckert <redacted>
Fri, 11 May 2018 06:21:28 +0000 (08:21 +0200)
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 <redacted>
net/mwan3/Makefile
net/mwan3/files/etc/config/mwan3
net/mwan3/files/usr/libexec/rpcd/mwan3
net/mwan3/files/usr/sbin/mwan3track

index 22a57824f3da8b2927f1d055e8ce95f6dff5e48a..ff082cf75b6cdc60e890579b91e7bdefc5fdc32f 100644 (file)
@@ -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 <fe@dev.tdt.de>
 PKG_LICENSE:=GPLv2
index 2fd16bb297c4d385b946cb7b73e72389372bea56..91d9c4eadb4b06f23bf8316169579a63bb79a639 100644 (file)
@@ -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'
index c30b6a1b93b03249ec5fcf0432c0d67cb3514f14..eb5f98ce5d5988a87d229e29ad04db394c553d07 100755 (executable)
@@ -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
index 3593d11a438279557796f506cd5162cf1068543d..f84ccaec3901e19b7a4f66f70bc1caf118ffc3ab 100755 (executable)
@@ -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
git clone https://git.99rst.org/PROJECT