R#14453 - Integrate DSCP2P-bit support in qosmngr and TR181

This commit is contained in:
Rohit Topno 2024-06-05 10:01:00 +00:00 committed by Rahul Thakur
parent f0d9a40f59
commit 1ae6eb33e9
2 changed files with 88 additions and 3 deletions

View file

@ -43,6 +43,7 @@ sort_classify_by_order() {
handle_classify() {
local corder_file="/tmp/qos/classify.order"
local interf=""
while read -r line; do
line_cid=${line#*_}
@ -60,6 +61,19 @@ handle_classify() {
handle_policer_rules $line_cid
fi
done < "$corder_file"
# Handling config for DSCP to pbit conversion:
# For a given port there can be 64 dscp2pbit mapping and each mapping is
# represented by one UCI config classify section. So there can be 64 possible
# config classify.
#
# For each port, traverse all config classify section and
# extract DSCP to P-bit conversion info.
# generate, dscp2pbit mapping list.
# Then apply dscp2pbit rule
for interf in $(jsonfilter -i /etc/board.json -e @.network.lan.ports[*] -e @.network.lan.device -e @.network.wan.device | xargs); do
handle_ebtables_dscp2pbit "$interf"
[ -n "$BR_RULE_DSCP2PBIT" ] && broute_apply_dscp2pbit_rule
done
}
# Configure classifier based on UCI subtree 'qos.classify'
@ -107,7 +121,7 @@ setup_qos() {
touch /tmp/qos/qos
cp /etc/config/qos /tmp/qos/qos
fi
create_ebtables_chains
create_iptables_chains
}

View file

@ -3,12 +3,19 @@
BR_RULE=""
BR6_RULE=""
BR_RULE_DSCP2PBIT=""
DSCP2PBIT_MAPPING=""
init_broute_rule() {
BR_RULE=""
BR6_RULE=""
}
init_broute_dscp2pbit_rule() {
BR_RULE_DSCP2PBIT=""
DSCP2PBIT_MAPPING=""
}
broute_filter_on_src_if() {
BR_RULE="$BR_RULE --in-if $1"
}
@ -103,7 +110,7 @@ ebt_match_ip_icmp_type() {
ebt_match_ipv6_protocol() {
#when ethertype is not configured by user then both proto rules of ipv4
#and ipv6 to be installed so update BR6_RULE string as well otherwise
#update BR_RULE only for installation of ipv6 proto rule only.
#update BR_RULE only for installation of ipv6 proto rule only.
if [ -n "$BR6_RULE" ]; then
BR6_RULE="$BR6_RULE --ip6-proto $1"
else
@ -147,6 +154,11 @@ broute_append_rule() {
fi
}
broute_apply_dscp2pbit_rule() {
# Write dscp2pbit broute rule to classify.ebtables file
echo "ebtables --concurrent -t broute -A dscp2pbits -p 0x8100 $BR_RULE_DSCP2PBIT" >> /tmp/qos/classify.ebtables
}
set_ip_addr()
{
local cid="$1"
@ -234,6 +246,12 @@ handle_ebtables_rules() {
local protocol=""
local ip_version=""
config_get pcp_mark "$sid" "pcp_mark"
# return if its a classfy section for DSCP to p-bit mapping or p-bit translation.
if [ -n "$pcp_mark" ]; then
return
fi
init_broute_rule
config_get src_if "$sid" "ifname"
@ -406,8 +424,60 @@ handle_ebtables_rules() {
[ -n "$BR_RULE" ] && broute_append_rule
}
handle_ebtables_dscp2pbit() {
local in_if=$1
local dscp_filter=""
local pcp_mark=""
local ifname=""
local dscp2pbit_mapping_list=""
local corder_file="/tmp/qos/classify.order"
if [ -z "$in_if" ]; then
return
fi
init_broute_dscp2pbit_rule
while read -r line; do
line_cid=${line#*_}
config_get dscp_filter "$line_cid" "dscp_filter"
config_get pcp_mark "$line_cid" "pcp_mark"
# return if not a dscp to p-bit rule
if [ -z "$dscp_filter" ] || [ -z "$pcp_mark" ]; then
continue
fi
config_get ifname "$line_cid" "ifname"
# return if this config is not for the currently processing interface (in_if)
if [ -n "$ifname" ] && [ "$ifname" != "$in_if" ]; then
continue
fi
dscp2pbit_mapping_list="$dscp2pbit_mapping_list,$dscp_filter=$pcp_mark"
done < "$corder_file"
# if not dscp2pbit config found for our interface, return
[ -z "$dscp2pbit_mapping_list" ] && return
# remove first character(comma) from the dscp2pbit_mapping_list, not required.
dscp2pbit_mapping_list="${dscp2pbit_mapping_list:1}"
# construct ebtables rule:
BR_RULE_DSCP2PBIT=" -i $in_if -j dscp2pbit --dscp2pbit-mapping $dscp2pbit_mapping_list --dscp2pbit-target CONTINUE"
}
create_ebtables_chains() {
ebtables --concurrent -t broute -N qos 2> /dev/null
ebtables --concurrent -t broute -N dscp2pbits -P RETURN 2> /dev/null
ret=$?
if [ $ret -eq 0 ]; then
ebtables --concurrent -t broute -A BROUTING -j dscp2pbits
else
ebtables --concurrent -t broute -D BROUTING -j dscp2pbits
ebtables --concurrent -t broute -A BROUTING -j dscp2pbits
fi
ebtables --concurrent -t broute -N qos -P RETURN 2> /dev/null
ret=$?
if [ $ret -eq 0 ]; then
ebtables --concurrent -t broute -A BROUTING -j qos
@ -419,5 +489,6 @@ create_ebtables_chains() {
flush_ebtables_chains() {
echo "ebtables -t broute -F qos" > /tmp/qos/classify.ebtables
echo "ebtables -t broute -F dscp2pbits" >> /tmp/qos/classify.ebtables
}