qosmngr: merging qosmngr to devel

This commit is contained in:
Rahul 2020-02-13 18:57:16 +05:30
parent a60fa6797a
commit dd00b7eb2e
5 changed files with 473 additions and 0 deletions

38
qosmngr/Makefile Normal file
View file

@ -0,0 +1,38 @@
#
# Copyright (C) 2013-2019 iopsys
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=qosmngr
PKG_VERSION:=1.0.0
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_LICENSE:=GPL-2.0-only
PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
define Package/qosmngr
CATEGORY:=Utilities
TITLE:=qos manager daemon
endef
define Package/qosmngr/description
Configures L2 QoS and collects queue statistics
endef
#define Build/Prepare
# $(CP) -rf ./qosmngr/* $(PKG_BUILD_DIR)/
#endef
define Build/Compile
endef
define Package/qosmngr/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,qosmngr))

View file

@ -0,0 +1,231 @@
config queue 'q0'
option ifname 'eth2'
option precedence 0
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 0
option weight 1
config queue 'q1'
option ifname 'eth2'
option precedence 1
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 1
option weight 1
config queue 'q2'
option ifname 'eth2'
option precedence 2
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 2
option weight 1
config queue 'q3'
option ifname 'eth2'
option precedence 3
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 3
option weight 1
config queue 'q4'
option ifname 'eth2'
option precedence 4
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 4
option weight 1
config queue 'q5'
option ifname 'eth2'
option precedence 5
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 5
option weight 1
config queue 'q6'
option ifname 'eth2'
option precedence 6
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 6
option weight 1
config queue 'q7'
option ifname 'eth2'
option precedence 7
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 7
option weight 1
config queue 'q8'
option ifname 'eth1'
option precedence 0
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 0
option weight 1
config queue 'q9'
option ifname 'eth1'
option precedence 1
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 1
option weight 1
config queue 'q10'
option ifname 'eth1'
option precedence 2
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 2
option weight 1
config queue 'q11'
option ifname 'eth1'
option precedence 3
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 3
option weight 1
config queue 'q12'
option ifname 'eth1'
option precedence 4
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 4
option weight 1
config queue 'q13'
option ifname 'eth1'
option precedence 5
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 5
option weight 1
config queue 'q14'
option ifname 'eth1'
option precedence 6
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 6
option weight 1
config queue 'q15'
option ifname 'eth1'
option precedence 7
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 7
option weight 1
config queue 'q16'
option ifname 'eth0'
option precedence 0
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 0
option weight 1
config queue 'q17'
option ifname 'eth0'
option precedence 1
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 1
option weight 1
config queue 'q18'
option ifname 'eth0'
option precedence 2
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 2
option weight 1
config queue 'q19'
option ifname 'eth0'
option precedence 3
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 3
option weight 1
config queue 'q20'
option ifname 'eth0'
option precedence 4
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 4
option weight 1
config queue 'q21'
option ifname 'eth0'
option precedence 5
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 5
option weight 1
config queue 'q22'
option ifname 'eth0'
option precedence 6
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 6
option weight 1
config queue 'q23'
option ifname 'eth0'
option precedence 7
option scheduling 'WRR'
option rate 0
option burst_size -1
option traffic_class 7
option weight 1
config shaper 's1'
option ifname 'eth2'
option rate 0
option burst_size -1
config shaper 's2'
option ifname 'eth1'
option rate 0
option burst_size -1
config shaper 's3'
option ifname 'eth0'
option rate 0
option burst_size -1

47
qosmngr/files/etc/init.d/qos Executable file
View file

@ -0,0 +1,47 @@
#!/bin/sh /etc/rc.common
# Uncomment this if functions need to called inside /lib/qos
# include /lib/qos
START=21
STOP=90
USE_PROCD=1
NAME=qosmngr
# This function checks the hardware and calls corresponding
# scripts as per the platform
configure_queue()
{
if [ "$(db get hw.board.tm)" == "1" ]; then
. /lib/qos/broadcom.sh
fi
}
start_service() {
# Call functions to configure queues
if [ -f "/etc/config/qos" ]; then
configure_queue
fi
# procd_open_instance
# start the daemon responsible for reading qos stats
# procd_set_param command "/sbin/qosmngr"
# procd_set_param respawn
# procd_close_instance
}
stop() {
#stop_service() is called after procd killed the service
echo ;
}
reload_service() {
# Call functions to configure queues
if [ -f "/etc/config/qos" ]; then
configure_queue
fi
# reload the daemon responsible for reading qos stats
# ubus -t 5 call qos reload
}

View file

@ -0,0 +1,75 @@
#!/bin/sh
for intf in $(db get hw.board.ethernetPortOrder); do
i=0
for i in 0 1 2 3 4 5 6 7; do
tmctl delqcfg --devtype 0 --if $intf --qid $i
done
done
for cmd in q pbit; do
i=0
while :
do
qid="q$i"
ifname=$(uci -q get qos.$qid.ifname)
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
break
fi
# it makes sense to read rest on the params only if port is present,
# which kind of indicates whether the config section is available
# or not
# lower the value, lower the priority of queue on this chip
order=$(uci -q get qos.$qid.precedence)
# on this chip, 8 queues per port exist so values larger than this
# cannot be supported
if [ $order -gt 7 ]; then
continue
fi
tc=$(uci -q get qos.$qid.traffic_class)
sc_alg=$(uci -q get qos.$qid.scheduling)
wgt=$(uci -q get qos.$qid.weight)
rate=$(uci -q get qos.$qid.rate)
bs=$(uci -q get qos.$qid.burst_size)
salg=1
if [ $sc_alg == 'WRR' ]; then
salg=2
fi
if [ $cmd == q ]; then
# Call tmctl which is a broadcomm command to configure queues on a port.
tmctl setqcfg --devtype 0 --if $ifname --qid $order --priority $order --weight $wgt --schedmode $salg --shapingrate $rate --burstsize $bs
else
# Now the mapping of p bit to a queue happens
IFS=,
for word in $tc; do
tmctl setpbittoq --devtype 0 --if $ifname --pbit $word --qid $order
done
fi
# Read the next configuration
i=$((i + 1))
done
done
i=0
while :
do
sid="s$i"
ifname=$(uci -q get qos.$sid.ifname)
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
break
fi
rate=$(uci -q get qos.$sid.rate)
bs=$(uci -q get qos.$sid.burst_size)
tmctl setportshaper --devtype 0 --if $ifname --shapingrate $rate --burstsize $bs
done

View file

@ -0,0 +1,82 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
bcom_get_queue_stats() {
i=0
json_init
json_add_array "queues"
while :
do
qid="q$i"
ifname=$(uci -q get qos.$qid.ifname)
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
break
fi
order=$(uci -q get qos.$qid.precedence)
stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $order)"
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
i=$((i + 1))
done
json_close_array
json_dump
}
get_queue_stats() {
if [ "$(db get hw.board.tm)" == "1" ]; then
bcom_get_queue_stats
fi
}
case "$1" in
list)
echo '{ "queue_stats" : {} }'
;;
call)
case "$2" in
queue_stats)
get_queue_stats
;;
esac
;;
esac