Move prio classes to function

This commit is contained in:
hk 2018-02-01 01:09:16 +01:00
parent dc515aea3f
commit 4ae592d477
1 changed files with 56 additions and 47 deletions

View File

@ -246,46 +246,31 @@ print_config () {
echo "" echo ""
} }
apply_egress_shaping () { add_prio_classes () {
# Disable tso and gso for lower bandwiths local IF_NAME=$1
${ETHTOOL} --offload ${IF_NAME} $(get_tx_offloads ${UP_RATE}) \ local CLASS_CONFIG=$2
> /dev/null 2>&1 || true local MAX_RATE=$3
local DEFAULT_PRIO=$4
# Add root handle and set default leaf
${TC} qdisc add dev ${IF_NAME} root handle 1: htb default 99
# Set the overall shaped rate of the interface
${TC} class add dev ${IF_NAME} parent 1: classid 1:1 htb \
rate ${UP_RATE}kbit \
quantum $(get_htb_quantum ${UP_RATE})
local DEFAULT_RATE=${UP_RATE}
local DEFAULT_PRIO=4
if [[ -n ${CLASS_CONFIG} ]]; then
local CLASSES=( $(echo "${CLASS_CONFIG}" | tr ',' ' ') ) local CLASSES=( $(echo "${CLASS_CONFIG}" | tr ',' ' ') )
for CLASS in ${CLASSES[@]}; do for CLASS in ${CLASSES[@]}; do
local CONFIG=( $(echo "${CLASS}" | tr ':' ' ') ) local CONFIG=( $(echo "${CLASS}" | tr ':' ' ') )
local FWMARK=${CONFIG[0]} local FWMARK=${CONFIG[0]}
local CLASS_RATE=$(convert_rate ${CONFIG[1]}) local CLASS_RATE=$(convert_rate ${CONFIG[1]})
local CEIL_RATE=$(convert_rate ${CONFIG[2]}) local CEIL_RATE=${MAX_RATE}
local PRIO=${CONFIG[3]} local PRIO=${DEFAULT_PRIO}
local CLASS_ID=${FWMARK} local CLASS_ID=${FWMARK}
if [[ -z ${CEIL_RATE} ]]; then [[ -n ${CONFIG[2]} ]] && CEIL_RATE=$(convert_rate ${CONFIG[2]})
CEIL_RATE=${UP_RATE} [[ -n ${CONFIG[3]} ]] && PRIO=${CONFIG[3]}
fi
if [[ -z ${PRIO} ]]; then if [[ ${CEIL_RATE} -gt ${MAX_RATE} ]]; then
PRIO=${DEFAULT_PRIO} echo "ERROR: ceiling value should not be larger than total max rate"
fi
if [[ ${CEIL_RATE} -gt ${UP_RATE} ]]; then
echo "ERROR: ceiling value should not be larger than total up rate"
exit 1 exit 1
fi fi
# Reduce the leftover default rate accordingly for each class' guaranteed rate
# This is used by the calling code, so ensure DEFAULT_RATE is defined there.
DEFAULT_RATE=$(( ${DEFAULT_RATE} - ${CLASS_RATE} )) DEFAULT_RATE=$(( ${DEFAULT_RATE} - ${CLASS_RATE} ))
if [[ ${DEFAULT_RATE} -le 0 ]]; then if [[ ${DEFAULT_RATE} -le 0 ]]; then
@ -310,6 +295,30 @@ apply_egress_shaping () {
${TC} filter add dev ${IF_NAME} parent 1: protocol all \ ${TC} filter add dev ${IF_NAME} parent 1: protocol all \
handle ${FWMARK} fw classid 1:${CLASS_ID} handle ${FWMARK} fw classid 1:${CLASS_ID}
done done
}
apply_egress_shaping () {
# Disable tso and gso for lower bandwiths
${ETHTOOL} --offload ${IF_NAME} $(get_tx_offloads ${UP_RATE}) \
> /dev/null 2>&1 || true
# Add root handle and set default leaf
${TC} qdisc add dev ${IF_NAME} root handle 1: htb default 99
# Set the overall shaped rate of the interface
${TC} class add dev ${IF_NAME} parent 1: classid 1:1 htb \
rate ${UP_RATE}kbit \
quantum $(get_htb_quantum ${UP_RATE})
local DEFAULT_RATE=${UP_RATE}
local DEFAULT_PRIO=4
if [[ -n ${CLASS_CONFIG} ]]; then
add_prio_classes \
${IF_NAME} \
"${CLASS_CONFIG}" \
${UP_RATE} \
${DEFAULT_PRIO}
fi fi
# Create class for the default priority # Create class for the default priority