From 81fb5ff455b20939c64d358dedebf8253d51a858 Mon Sep 17 00:00:00 2001 From: Rohit Topno Date: Wed, 20 May 2020 15:12:16 +0530 Subject: [PATCH] qosmngr: Support for mapping IP packets to queue based on packet length. --- qosmngr/files/usr/libexec/rpcd/qos | 114 +++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 8 deletions(-) diff --git a/qosmngr/files/usr/libexec/rpcd/qos b/qosmngr/files/usr/libexec/rpcd/qos index c5f0aa206..bacd49a7a 100755 --- a/qosmngr/files/usr/libexec/rpcd/qos +++ b/qosmngr/files/usr/libexec/rpcd/qos @@ -3,25 +3,30 @@ . /usr/share/libubox/jshn.sh bcom_get_queue_stats() { - i=0 json_init json_add_array "queues" - + i=0 while : do - qid="q$i" - ifname=$(uci -q get qos.$qid.ifname) + ifname=$(uci -q get qos.@queue[$i].ifname) # if ifname is empty that is good enough to break if [ -z "$ifname" ];then break fi - order=$(uci -q get qos.$qid.precedence) + order=$(uci -q get qos.@queue[$i].precedence) stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $order)" + ret="$(echo $stats | awk '{print substr($0,0,5)}')" + + #check tmctl ERROR condition + if [ $ret == 'ERROR' ]; then + i=$((i + 1)) + continue + fi json_add_object "" - json_add_string "qid" "$qid" + json_add_string "qid" "$order" json_add_string "iface" "$ifname" IFS=$'\n' @@ -61,22 +66,115 @@ bcom_get_queue_stats() { json_dump } +bcom_get_eth_q_stats() { + + i=0 + key_ifname=$1 + key_queue=$2 + + json_init + json_add_array "queues" + + while : + do + ifname=$(uci -q get qos.@queue[$i].ifname) + + # if ifname is empty that is good enough to break + if [ -z "$ifname" ];then + break + fi + + order=$(uci -q get qos.@queue[$i].precedence) + #proceed only if given interface and queue matches + if [ $ifname != $key_ifname ] || [ $order != $key_queue ]; then + i=$((i + 1)) + continue + fi + stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $order)" + ret="$(echo $stats | awk '{print substr($0,0,5)}')" + + #check tmctl ERROR condition + if [ $ret == 'ERROR' ]; then + i=$((i + 1)) + continue + fi + json_add_object "" + json_add_string "qid" "$order" + json_add_string "iface" "$ifname" + + IFS=$'\n' + for stat in $stats; do + pname="$(echo $stat | awk '{print$1}')" + if [ $pname == 'ret' ]; then + continue + fi + + val="$(echo $stat | awk '{print$2}')" + + # remove trailing : from the name + pname="${pname::-1}" + + # convert to iopsyswrt names + case "$pname" in + txPackets) + json_add_string "tx_packets" "$val" + ;; + txBytes) + json_add_string "tx_bytes" "$val" + ;; + droppedPackets) + json_add_string "tx_dropped_packets" "$val" + ;; + droppedBytes) + json_add_string "tx_dropped_bytes" "$val" + ;; + esac + done + + json_close_object + i=$((i + 1)) + done + + json_close_array + json_dump +} + + get_queue_stats() { if [ "$(which tmctl)" ]; then bcom_get_queue_stats fi } - +get_eth_q_stats() { + if [ "$(which tmctl)" ]; then + param1=$1 + param2=$2 + echo "param1: $param1 param2: $param2" >> /usr/libexec/rpcd/output + bcom_get_eth_q_stats $param1 $param2 + fi +} case "$1" in list) - echo '{ "queue_stats" : {} }' + echo '{ "eth_q_stats": { "eth": "str", "queue": "str", }, "queue_stats": { } }' + ;; call) case "$2" in + eth_q_stats) + # read the arguments + read input; + json_load "$input" + json_get_var iface eth + json_get_var q queue + echo "arg1: $iface" > /usr/libexec/rpcd/output + echo "arg2: $q" >> /usr/libexec/rpcd/output + get_eth_q_stats $iface $q + ;; queue_stats) get_queue_stats ;; esac ;; esac +