Move prio classes to function
This commit is contained in:
parent
dc515aea3f
commit
4ae592d477
65
src/tc-gen
65
src/tc-gen
|
|
@ -246,46 +246,31 @@ print_config () {
|
|||
echo ""
|
||||
}
|
||||
|
||||
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 () {
|
||||
local IF_NAME=$1
|
||||
local CLASS_CONFIG=$2
|
||||
local MAX_RATE=$3
|
||||
local DEFAULT_PRIO=$4
|
||||
local CLASSES=( $(echo "${CLASS_CONFIG}" | tr ',' ' ') )
|
||||
|
||||
for CLASS in ${CLASSES[@]}; do
|
||||
local CONFIG=( $(echo "${CLASS}" | tr ':' ' ') )
|
||||
local FWMARK=${CONFIG[0]}
|
||||
local CLASS_RATE=$(convert_rate ${CONFIG[1]})
|
||||
local CEIL_RATE=$(convert_rate ${CONFIG[2]})
|
||||
local PRIO=${CONFIG[3]}
|
||||
local CEIL_RATE=${MAX_RATE}
|
||||
local PRIO=${DEFAULT_PRIO}
|
||||
local CLASS_ID=${FWMARK}
|
||||
|
||||
if [[ -z ${CEIL_RATE} ]]; then
|
||||
CEIL_RATE=${UP_RATE}
|
||||
fi
|
||||
[[ -n ${CONFIG[2]} ]] && CEIL_RATE=$(convert_rate ${CONFIG[2]})
|
||||
[[ -n ${CONFIG[3]} ]] && PRIO=${CONFIG[3]}
|
||||
|
||||
if [[ -z ${PRIO} ]]; then
|
||||
PRIO=${DEFAULT_PRIO}
|
||||
fi
|
||||
|
||||
if [[ ${CEIL_RATE} -gt ${UP_RATE} ]]; then
|
||||
echo "ERROR: ceiling value should not be larger than total up rate"
|
||||
if [[ ${CEIL_RATE} -gt ${MAX_RATE} ]]; then
|
||||
echo "ERROR: ceiling value should not be larger than total max rate"
|
||||
exit 1
|
||||
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} ))
|
||||
|
||||
if [[ ${DEFAULT_RATE} -le 0 ]]; then
|
||||
|
|
@ -310,6 +295,30 @@ apply_egress_shaping () {
|
|||
${TC} filter add dev ${IF_NAME} parent 1: protocol all \
|
||||
handle ${FWMARK} fw classid 1:${CLASS_ID}
|
||||
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
|
||||
|
||||
# Create class for the default priority
|
||||
|
|
|
|||
Loading…
Reference in New Issue