added front-end and back-end support for automatic speedtest and also separated up...
authorChristopher Nagy <christopher.nagy@inteno.se>
Wed, 12 Oct 2016 12:44:42 +0000 (14:44 +0200)
committerSukru Senli <sukru.senli@inteno.se>
Thu, 20 Oct 2016 08:12:52 +0000 (10:12 +0200)
plugins/juci-diagnostics/access.json
plugins/juci-diagnostics/scripts/tptest-run
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.html
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.js
plugins/juci-diagnostics/ubus/juci.speedtest

index 3627c96..ea73645 100644 (file)
@@ -4,7 +4,8 @@
                "read": {
                        "ubus": {
                                "juci.speedtest": [
-                                       "run"
+                                       "run",
+                                       "get_packet_size"
                                ],
                                "juci.diagnostics": [
                                        "ping",
index dd4cbbd..d33c413 100755 (executable)
@@ -10,17 +10,29 @@ local received="none"
 local label="success"
 
 json_load "$args"
+json_get_var auto auto "1"
 json_get_var testmode testmode "up_down"
-json_get_var packetsize packetsize 50000
+json_get_var packetsize_up packetsize_up 50000
+json_get_var packetsize_down packetsize_down 50000
 json_get_var address address
 json_get_var port port
 
 case "$testmode" in
-       *up*) sent=$(tptest -n 1 -m tcp-send 60 $packetsize -v 2 $address $port | awk '/Throughput/{print($2)}') ;;
+       *up*)
+               if [ "$auto" == "1" ]; then
+                       sent=$(tptest -n 1 -m tcp-send-auto -v 1 $address $port | awk '/TCP Send/{print($3)}')
+               else
+                       sent=$(tptest -n 1 -m tcp-send 60 $packetsize_up -v 2 $address $port | awk '/Throughput/{print($2)}')
+               fi
 esac
 
 case "$testmode" in
-       *down*) received=$(tptest -n 1 -m tcp-receive 60 $packetsize -v 2 $address $port | awk '/Throughput/{print($2)}') ;;
+       *down*)
+               if [ "$auto" == "1" ]; then
+                       received=$(tptest -n 1 -m tcp-receive-auto -v 1 $address $port | awk '/TCP Recv/{print($3)}')
+               else
+                       received=$(tptest -n 1 -m tcp-receive 60 $packetsize_down -v 2 $address $port | awk '/Throughput/{print($2)}')
+               fi
 esac
 
 if [ -z "$received" -o -z "$sent" ]; then
@@ -29,4 +41,3 @@ if [ -z "$received" -o -z "$sent" ]; then
 fi
 
 ubus send juci.utils.speedtest "{\"status\":$SUCCESS, \"upstream\":\"$sent\",\"downstream\":\"$received\",\"label\":\"$label\"}"
-
index c56bf33..24eded9 100644 (file)
@@ -4,10 +4,19 @@
                        <juci-config-line title="{{'Direction'|translate}}">
                                <juci-select ng-model="data.test_type" ng-items="testType"/>
                        </juci-config-line>
-                       <juci-config-line title="{{'Bytes to transfer'|translate}}">
+                       <juci-config-line title="{{'Set transfer size manually'|translate}}">
                                <div class="input-group">
-                                       <input type="number" step="5" class="form-control" ng-model="data.packagesize" />
-                                       <span class="input-group-addon">Mbyte</span>
+                                       <switch class="green" ng-model="data.manually" />
+                               </div>
+                       </juci-config-line>
+                       <juci-config-line ng-show="data.manually && (data.test_type=='down' || data.test_type=='up_down')" title="{{'Downstream packet size'|translate}}">
+                               <div class="input-group">
+                                       <input type="number" min="0" max="500" step="5" class="form-control" ng-model="data.downsize" placeholder="[Mbyte]" />
+                               </div>
+                       </juci-config-line>
+                       <juci-config-line ng-show="data.manually && (data.test_type=='up' || data.test_type=='up_down')" title="{{'Upstream packet size'|translate}}">
+                               <div class="input-group">
+                                       <input type="number" min="0" max="500" step="5" class="form-control" ng-model="data.upsize" placeholder="[Mbyte]" />
                                </div>
                        </juci-config-line>
                        <juci-config-line title="{{'Speedtest Server' | translate}}">
index 163ed45..caf14f0 100644 (file)
@@ -11,16 +11,23 @@ JUCI.app
 })
 .controller("diagnosticsWidget90Speedtest", function($scope, $rpc, $events, $uci, utilsAddTestserverPicker, $tr, gettext){
        $scope.data = {
-               packagesize: 50,
                test_type: "up_down",
                result: "",
-               state: ""
+               state: "",
+               manually: false
        }; 
-       var min = 1; 
-       var max = 100; 
-       $scope.$watch('data.packagesize', function(new_value){
-               if(new_value < min)$scope.data.packagesize = min;
-               if(new_value > max)$scope.data.packagesize = max;
+       
+       function getDefaultPacketSize(){
+               $rpc.$call("juci.speedtest", "get_packet_size").done(function(data){
+                       $scope.data.downsize = parseInt(data.packetsize_down);
+                       $scope.data.upsize = parseInt(data.packetsize_up);
+                       $scope.$apply();
+               }).fail(function(e){ console.log(e); });
+       }
+       getDefaultPacketSize();
+       
+       $scope.$watch('data.manually', function(new_value){
+               if(new_value === true){ getDefaultPacketSize(); }
        }, false);
 
        function getServers(){
@@ -35,9 +42,9 @@ JUCI.app
        }
 
        $scope.testType = [
-               {value:"up_down", label: $tr(gettext("Up and Down")) }, 
+               {value:"down", label: $tr(gettext("Down")) },
                {value:"up", label: $tr(gettext("Up")) }, 
-               {value:"down", label: $tr(gettext("Down")) } 
+               {value:"up_down", label: $tr(gettext("Down and Up")) }
        ];
 
        $uci.$sync("speedtest").done(function(){
@@ -47,6 +54,8 @@ JUCI.app
        });
 
        $scope.runTest = function(){
+               if($scope.data.test_type.indexOf("up") !== -1 && !$scope.data.upsize){ alert("Upstream packet size missing"); return; }
+               if($scope.data.test_type.indexOf("down") !==-1 && !$scope.data.downsize){ alert("Downstream packet size missing"); return; }
                if(!$scope.testServers.length){
                        window.alert($tr(gettext("Server and port is mandatory")));
                        return;
@@ -59,12 +68,21 @@ JUCI.app
                var port = server.port.value;
                var address = server.server.value;
                $scope.data.state="running";
-               $rpc.$call("juci.speedtest", "run", {
+               var speedtestArgs = {
+                       "auto": !$scope.data.manually,
                        "testmode": $scope.data.test_type,
                        "port": port,
-                       "packetsize": $scope.data.packagesize * 1000000,
                        "address": address
-               }).done(function(response){
+               };
+
+               if($scope.data.test_type.indexOf("up") !== -1){
+                       speedtestArgs.packetsize_up = $scope.data.upsize * 1000000;
+               }
+               if($scope.data.test_type.indexOf("down") !== -1){
+                       speedtestArgs.packetsize_down = $scope.data.downsize * 1000000;
+               }
+
+               $rpc.$call("juci.speedtest", "run", speedtestArgs).done(function(response){
                        if(response && response.message=="success"){
                                $scope.data.state="running";
                        }else{
index 5eea0c9..dcf392e 100755 (executable)
@@ -1,10 +1,68 @@
-#!/bin/sh
+#!/bin/sh 
 
-. /usr/share/libubox/jshn.sh
+. /usr/share/libubox/jshn.sh 
+. /lib/functions.sh
+
+ifaces="ethernet vdsl adsl"
+
+get_packet_sizes () {
+       local option="$1"
+       local packetsizes
+
+#      config_load speedtest
+#      config_get packetsizes packetsize $option
+       packetsizes=$(uci -q get speedtest.@packetsize[0].$option)
+
+       if [ "$packetsizes" ]; then
+               packetsize_down=${packetsizes%/*}
+               packetsize_up=${packetsizes#*/}
+       else
+               case "$option" in
+                       ethernet)
+                               packetsize_up=5
+                               packetsize_down=100
+                               ;;
+                       vdsl)
+                               packetsize_up=3
+                               packetsize_down=50
+                               ;;
+                       adsl)
+                               packetsize_up=1
+                               packetsize_down=25
+                               ;;
+                       *)
+                               packetsize_up=1
+                               packetsize_down=25
+               esac
+       fi
+}
+
+get_iface () {
+       iface=$(ip route | awk '/default via/{print $5}')
+       case "$iface" in
+               eth*)
+                       iface="ethernet"
+               ;;
+               atm*)
+                       iface="adsl"
+               ;;
+               ptm*)
+                       iface="vdsl"
+               ;;
+               wwan*)
+                       iface="vdsl"
+               ;;
+               br-*)
+                       iface="ethernet"
+               ;;
+               *)
+                       iface="ethernet"
+       esac
+}
 
 case "$1" in
        list)
-               echo '{ "run" : {"testmode":"str","packetsize":32,"address":"str","port":32} }'
+               echo '{ "run" : {"testmode":"str","packetsize_up":32,"packetsize_down":32,"address":"str","port":32}, "get_packet_size" : {} }'
        ;;
        call)
                case "$2" in
@@ -23,6 +81,20 @@ case "$1" in
                                        json_dump
                                fi
                        ;;
+                       get_packet_size)
+                               get_iface
+
+                               for i in $ifaces; do
+                                       if [ $iface == "$i" ]; then
+                                               get_packet_sizes $iface
+                                               json_init
+                                               json_add_string "packetsize_up" "$packetsize_up"
+                                               json_add_string "packetsize_down" "$packetsize_down"
+                                               json_dump
+                                               return
+                                       fi
+                               done
+                       ;;
                esac
        ;;
 esac