qosmngr: Support for mapping IP packets to queue based on packet length.

This commit is contained in:
Rohit Topno 2020-05-20 15:12:16 +05:30
parent 5d16d75162
commit 81fb5ff455

View file

@ -3,25 +3,30 @@
. /usr/share/libubox/jshn.sh . /usr/share/libubox/jshn.sh
bcom_get_queue_stats() { bcom_get_queue_stats() {
i=0
json_init json_init
json_add_array "queues" json_add_array "queues"
i=0
while : while :
do do
qid="q$i" ifname=$(uci -q get qos.@queue[$i].ifname)
ifname=$(uci -q get qos.$qid.ifname)
# if ifname is empty that is good enough to break # if ifname is empty that is good enough to break
if [ -z "$ifname" ];then if [ -z "$ifname" ];then
break break
fi 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)" 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_object ""
json_add_string "qid" "$qid" json_add_string "qid" "$order"
json_add_string "iface" "$ifname" json_add_string "iface" "$ifname"
IFS=$'\n' IFS=$'\n'
@ -61,22 +66,115 @@ bcom_get_queue_stats() {
json_dump 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() { get_queue_stats() {
if [ "$(which tmctl)" ]; then if [ "$(which tmctl)" ]; then
bcom_get_queue_stats bcom_get_queue_stats
fi 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 case "$1" in
list) list)
echo '{ "queue_stats" : {} }' echo '{ "eth_q_stats": { "eth": "str", "queue": "str", }, "queue_stats": { } }'
;; ;;
call) call)
case "$2" in 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) queue_stats)
get_queue_stats get_queue_stats
;; ;;
esac esac
;; ;;
esac esac