qosmngr: update ubus call for queue stats

Update the rpcd to enable fetching stats for particular queue of an
interface.
Also, move all broadcom specific functions to broadcom.sh so that the
rpcd is soc agnostic.
This commit is contained in:
Rahul 2020-05-20 17:12:50 +05:30
parent 81fb5ff455
commit 9108848387
2 changed files with 137 additions and 163 deletions

View file

@ -278,3 +278,129 @@ configure_qos() {
sh /tmp/qos/classify.ebtables
sh /tmp/qos/classify.iptables
}
get_queue_stats() {
json_init
json_add_array "queues"
i=0
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)
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_eth_q_stats() {
json_init
json_add_array "queues"
ifname="$1"
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
return
fi
qid="$2"
if [ -z "$qid" ];then
return
fi
stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $qid)"
ret="$(echo $stats | awk '{print substr($0,0,5)}')"
#check tmctl ERROR condition
if [ $ret == 'ERROR' ]; then
return
fi
json_add_object ""
json_add_string "qid" "$qid"
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
json_close_array
json_dump
}

View file

@ -1,178 +1,26 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
bcom_get_queue_stats() {
json_init
json_add_array "queues"
i=0
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)
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
}
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
}
. /lib/functions.sh
include /lib/qos
case "$1" in
list)
echo '{ "eth_q_stats": { "eth": "str", "queue": "str", }, "queue_stats": { } }'
echo '{ "queue_stats": { "ifname":"string", "qid":"string" } }'
;;
call)
case "$2" in
eth_q_stats)
# read the arguments
queue_stats)
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
json_get_var iface ifname
json_get_var qid qid
if [ -n "$iface" -a -n "$qid" ]; then
get_eth_q_stats $iface $qid
else
get_queue_stats
fi
;;
esac
;;