mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Update sqm autorate
This commit is contained in:
parent
8b270e7264
commit
ecf0b89798
6 changed files with 407 additions and 253 deletions
|
@ -31,14 +31,14 @@ _config_autorate() {
|
|||
[ "${min_upload}" == "0" ] || [ "${max_upload}" == "0" ] || [ "${upload}" == "0" ] && return
|
||||
# config_get interface "$1" interface
|
||||
# cp /usr/share/sqm-autorate/cake-autorate_template.sh /usr/share/sqm-autorate/cake-autorate_config.${interface}.sh
|
||||
cp /usr/share/sqm-autorate/cake-autorate_template.sh /usr/share/sqm-autorate/cake-autorate_config.$1.sh
|
||||
cp /usr/share/sqm-autorate/config_template.sh /usr/share/sqm-autorate/config.$1.sh
|
||||
}
|
||||
|
||||
_launch_autorate() {
|
||||
logger -t "SQM-autorate" "Launch..."
|
||||
procd_open_instance
|
||||
# shellcheck disable=SC2086
|
||||
procd_set_param command /usr/share/sqm-autorate/cake-autorate_launcher.sh
|
||||
procd_set_param command /usr/share/sqm-autorate/launcher.sh
|
||||
procd_set_param limits nofile="51200 51200"
|
||||
procd_set_param respawn 0 10 0
|
||||
procd_set_param stderr 1
|
||||
|
@ -46,16 +46,12 @@ _launch_autorate() {
|
|||
}
|
||||
|
||||
start_service() {
|
||||
rm -f /usr/share/sqm-autorate/config.*.sh
|
||||
config_load sqm
|
||||
config_foreach _config_autorate queue
|
||||
_launch_autorate
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
rm -f /usr/share/sqm-autorate/cake-autorate_config.*.sh
|
||||
pkill -9 cake-autorate
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@
|
|||
|
||||
INTERFACE=$(basename "$1" | cut -d. -f2)
|
||||
|
||||
cake_autorate_version="2.0.0"
|
||||
#cake_autorate_version="2.0.0"
|
||||
|
||||
# *** OUTPUT AND LOGGING OPTIONS ***
|
||||
|
||||
|
@ -46,7 +46,7 @@ ul_if=$(uci -q get sqm.${INTERFACE}.interface) # upload interface
|
|||
# fping - round robin pinging (rtts)
|
||||
# ping - (iputils-ping) individual pinging (rtts)
|
||||
# hping3 - individidual pinging (owds)
|
||||
pinger_binary=tsping
|
||||
pinger_binary=$(uci -q get sqm.${INTERFACE}.pinger || echo 'tsping')
|
||||
|
||||
# list of reflectors to use and number of pingers to initiate
|
||||
# pingers will be initiated with reflectors in the order specified in the list
|
||||
|
@ -77,12 +77,8 @@ reflector_ping_interval_s=$(uci -q get sqm.${INTERFACE}.reflector_ping_interval_
|
|||
# delay threshold in ms is the extent of OWD increase to classify as a delay
|
||||
# these are automatically adjusted based on maximum on the wire packet size
|
||||
# (adjustment significant at sub 12Mbit/s rates, else negligible)
|
||||
latency=$(uci -q get sqm.${INTERFACE}.delay_thr_ms)
|
||||
[ -z "$latency" ] && latency="$(($(ping -B -w 5 -c 5 -I ${ul_if} 1.1.1.1 | cut -d '/' -s -f6 | cut -d '.' -f1 | tr -d '\n' 2>/dev/null)+30))"
|
||||
[ -z "$latency" ] && latency="100"
|
||||
logger -t "sqm" "latency $INTERFACE: $latency"
|
||||
dl_delay_thr_ms="$latency" # (milliseconds)
|
||||
ul_delay_thr_ms="$latency" # (milliseconds)
|
||||
dl_delay_thr_ms=$(uci -q get sqm.${INTERFACE}.delay_thr_ms) || $(($(ping -B -w 5 -c 5 -I ${ul_if} 1.1.1.1 | cut -d '/' -s -f6 | cut -d '.' -f1 | tr -d '\n' 2>/dev/null)+30)) || echo 100 # (milliseconds)
|
||||
ul_delay_thr_ms=${dl_delay_thr_ms}
|
||||
|
||||
# Set either of the below to 0 to adjust one direction only
|
||||
# or alternatively set both to 0 to simply use cake-autorate to monitor a connection
|
||||
|
@ -195,7 +191,7 @@ reflector_misbehaving_detection_thr=3
|
|||
reflector_replacement_interval_mins=60 # how often to replace a random reflector from the present list
|
||||
|
||||
reflector_comparison_interval_mins=1 # how often to compare reflectors
|
||||
reflector_sum_owd_baseline_delta_thr_ms=30 # max increase from min sum owd baselines before reflector rotated
|
||||
#reflector_sum_owd_baseline_delta_thr_ms=30 # max increase from min sum owd baselines before reflector rotated
|
||||
reflector_owd_delta_ewma_delta_thr_ms=10 # mac increase from min delta ewma before reflector rotated
|
||||
|
||||
# stall is detected when the following two conditions are met:
|
|
@ -7,6 +7,8 @@
|
|||
# Author: @Lynx (OpenWrt forum)
|
||||
# Inspiration taken from: @moeller0 (OpenWrt forum)
|
||||
|
||||
INTERFACE=""
|
||||
|
||||
# *** OUTPUT AND LOGGING OPTIONS ***
|
||||
|
||||
output_processing_stats=1 # enable (1) or disable (0) output monitoring lines showing processing stats
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
cake_instances=(/usr/share/sqm-autorate/cake-autorate_config*sh)
|
||||
cake_instances=(/root/cake-autorate/config.*.sh)
|
||||
cake_instance_pids=()
|
||||
|
||||
trap kill_cake_instances INT TERM EXIT
|
||||
|
@ -20,7 +20,7 @@ kill_cake_instances()
|
|||
|
||||
for cake_instance in "${cake_instances[@]}"
|
||||
do
|
||||
/usr/share/sqm-autorate/cake-autorate.sh "${cake_instance}" &
|
||||
/root/cake-autorate/cake-autorate.sh "${cake_instance}" &
|
||||
cake_instance_pids+=(${!})
|
||||
done
|
||||
wait
|
|
@ -1,14 +1,63 @@
|
|||
#!/bin/bash
|
||||
# cake-autorate_lib.sh -- common functions for use by cake-autorate.sh
|
||||
|
||||
# lib.sh -- common functions for use by cake-autorate.sh
|
||||
#
|
||||
# This file is part of cake-autorate.
|
||||
|
||||
__set_e=0
|
||||
if [[ ! ${-} =~ e ]]; then
|
||||
if [[ ! ${-} =~ e ]]
|
||||
then
|
||||
set -e
|
||||
__set_e=1
|
||||
fi
|
||||
|
||||
exec {__sleep_fd}<> <(:) || true
|
||||
if [[ -z "${__sleep_fd:-}" ]]
|
||||
then
|
||||
exec {__sleep_fd}<> <(:)
|
||||
fi
|
||||
|
||||
typeof() {
|
||||
# typeof -- returns the type of a variable
|
||||
|
||||
local type_sig
|
||||
type_sig=$(declare -p "${1}" 2>/dev/null)
|
||||
if [[ "${type_sig}" =~ "declare --" ]]
|
||||
then
|
||||
str_type "${1}"
|
||||
elif [[ "${type_sig}" =~ "declare -a" ]]
|
||||
then
|
||||
printf "array"
|
||||
elif [[ "${type_sig}" =~ "declare -A" ]]
|
||||
then
|
||||
printf "map"
|
||||
else
|
||||
printf "none"
|
||||
fi
|
||||
}
|
||||
|
||||
str_type() {
|
||||
# str_type -- returns the type of a string
|
||||
|
||||
local -n str="${1}"
|
||||
|
||||
if [[ "${str}" =~ ^[0-9]+$ ]]
|
||||
then
|
||||
printf "integer"
|
||||
elif [[ "${str}" =~ ^[0-9]*\.[0-9]+$ ]]
|
||||
then
|
||||
printf "float"
|
||||
elif [[ "${str}" =~ ^-[0-9]+$ ]]
|
||||
then
|
||||
printf "negative-integer"
|
||||
elif [[ "${str}" =~ ^-[0-9]*\.[0-9]+$ ]]
|
||||
then
|
||||
printf "negative-float"
|
||||
else
|
||||
# technically not validated, user is just trusted to call
|
||||
# this function with valid strings
|
||||
printf "string"
|
||||
fi
|
||||
}
|
||||
|
||||
sleep_s()
|
||||
{
|
||||
|
@ -25,7 +74,7 @@ sleep_s()
|
|||
# - https://github.com/lynxthecat/cake-autorate/issues/174#issuecomment-1460074498
|
||||
|
||||
local sleep_duration_s=${1} # (seconds, e.g. 0.5, 1 or 1.5)
|
||||
read -r -t "${sleep_duration_s}" -u "${__sleep_fd}" || :
|
||||
read -r -t "${sleep_duration_s}" -u "${__sleep_fd}" || true
|
||||
}
|
||||
|
||||
sleep_us()
|
||||
|
@ -52,21 +101,10 @@ sleep_remaining_tick_time()
|
|||
fi
|
||||
}
|
||||
|
||||
get_remaining_tick_time()
|
||||
{
|
||||
# updates sleep_duration_s remaining to end of tick duration
|
||||
|
||||
local t_start_us=${1} # (microseconds)
|
||||
local tick_duration_us=${2} # (microseconds)
|
||||
|
||||
sleep_duration_us=$(( t_start_us + tick_duration_us - ${EPOCHREALTIME/./} ))
|
||||
((sleep_duration_us<0)) && sleep_duration_us=0
|
||||
sleep_duration_s=000000${sleep_duration_us}
|
||||
sleep_duration_s=$((10#${sleep_duration_s::-6})).${sleep_duration_s: -6}
|
||||
}
|
||||
|
||||
randomize_array()
|
||||
{
|
||||
# randomize the order of the elements of an array
|
||||
|
||||
local -n array=${1}
|
||||
|
||||
subset=("${array[@]}")
|
||||
|
@ -80,23 +118,6 @@ randomize_array()
|
|||
done
|
||||
}
|
||||
|
||||
lock()
|
||||
{
|
||||
local path=${1}
|
||||
|
||||
while true; do
|
||||
( set -o noclobber; echo "$$" > "${path:?}" ) 2> /dev/null && return 0
|
||||
sleep_us 100000
|
||||
done
|
||||
}
|
||||
|
||||
unlock()
|
||||
{
|
||||
local path=${1}
|
||||
|
||||
rm -f "${path:?}"
|
||||
}
|
||||
|
||||
terminate()
|
||||
{
|
||||
# Send regular kill to processes and monitor terminations;
|
||||
|
@ -105,7 +126,7 @@ terminate()
|
|||
# and, finally, call wait on all processes to reap any zombie processes.
|
||||
|
||||
local pids=("${@:-}")
|
||||
|
||||
|
||||
kill "${pids[@]}" 2> /dev/null
|
||||
|
||||
for((i=0; i<10; i++))
|
||||
|
@ -121,8 +142,8 @@ terminate()
|
|||
kill -9 "${pids[@]}" 2> /dev/null
|
||||
}
|
||||
|
||||
|
||||
if (( __set_e == 1 )); then
|
||||
if (( __set_e == 1 ))
|
||||
then
|
||||
set +e
|
||||
fi
|
||||
unset __set_e
|
Loading…
Add table
Add a link
Reference in a new issue