1
0
Fork 0
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:
Ycarus (Yannick Chabanois) 2023-08-22 12:46:35 +02:00
parent 765a1307fb
commit 8eabafb541
4 changed files with 127 additions and 60 deletions

View file

@ -273,7 +273,7 @@ return view.extend({
o.depends("autorate","1"); o.depends("autorate","1");
o = s.taboption("tab_autorate", form.Value, "delay_thr_ms",_("delay threshold in ms:")); o = s.taboption("tab_autorate", form.Value, "delay_thr_ms",_("delay threshold in ms:"));
o.default = "25"; o.default = "25.0";
o.depends("autorate","1"); o.depends("autorate","1");
o = s.taboption("tab_autorate", form.Flag, "enable_sleep_function", _("Sleep functionnality")); o = s.taboption("tab_autorate", form.Flag, "enable_sleep_function", _("Sleep functionnality"));

View file

@ -14,7 +14,7 @@
# Author and maintainer: lynxthecat # Author and maintainer: lynxthecat
# Contributors: rany2; moeller0; richb-hanover # Contributors: rany2; moeller0; richb-hanover
cake_autorate_version="2.0.0" cake_autorate_version="3.1.0-PRERELEASE"
## cake-autorate uses multiple asynchronous processes including: ## cake-autorate uses multiple asynchronous processes including:
## main - main process ## main - main process
@ -157,7 +157,7 @@ print_headers()
{ {
log_msg "DEBUG" "Starting: ${FUNCNAME[0]} with PID: ${BASHPID}" log_msg "DEBUG" "Starting: ${FUNCNAME[0]} with PID: ${BASHPID}"
header="DATA_HEADER; LOG_DATETIME; LOG_TIMESTAMP; PROC_TIME_US; DL_ACHIEVED_RATE_KBPS; UL_ACHIEVED_RATE_KBPS; DL_LOAD_PERCENT; UL_LOAD_PERCENT; RTT_TIMESTAMP; REFLECTOR; SEQUENCE; DL_OWD_BASELINE; DL_OWD_US; DL_OWD_DELTA_EWMA_US; DL_OWD_DELTA_US; DL_ADJ_DELAY_THR; UL_OWD_BASELINE; UL_OWD_US; UL_OWD_DELTA_EWMA_US; UL_OWD_DELTA_US; UL_ADJ_DELAY_THR; SUM_DL_DELAYS; SUM_UL_DELAYS; DL_LOAD_CONDITION; UL_LOAD_CONDITION; CAKE_DL_RATE_KBPS; CAKE_UL_RATE_KBPS" header="DATA_HEADER; LOG_DATETIME; LOG_TIMESTAMP; PROC_TIME_US; DL_ACHIEVED_RATE_KBPS; UL_ACHIEVED_RATE_KBPS; DL_LOAD_PERCENT; UL_LOAD_PERCENT; ICMP_TIMESTAMP; REFLECTOR; SEQUENCE; DL_OWD_BASELINE; DL_OWD_US; DL_OWD_DELTA_EWMA_US; DL_OWD_DELTA_US; DL_ADJ_DELAY_THR; UL_OWD_BASELINE; UL_OWD_US; UL_OWD_DELTA_EWMA_US; UL_OWD_DELTA_US; UL_ADJ_DELAY_THR; DL_SUM_DELAYS; DL_AVG_OWD_DELTA_US; DL_ADJ_OWD_DELTA_THR_US; UL_SUM_DELAYS; UL_AVG_OWD_DELTA; UL_ADJ_OWD_DELTA_THR_US; DL_LOAD_CONDITION; UL_LOAD_CONDITION; CAKE_DL_RATE_KBPS; CAKE_UL_RATE_KBPS"
((log_to_file)) && printf '%s\n' "${header}" >> "${log_file_path}" ((log_to_file)) && printf '%s\n' "${header}" >> "${log_file_path}"
((terminal)) && printf '%s\n' "${header}" ((terminal)) && printf '%s\n' "${header}"
@ -168,6 +168,10 @@ print_headers()
header="REFLECTOR_HEADER; LOG_DATETIME; LOG_TIMESTAMP; PROC_TIME_US; REFLECTOR; MIN_SUM_OWD_BASELINES_US; SUM_OWD_BASELINES_US; SUM_OWD_BASELINES_DELTA_US; SUM_OWD_BASELINES_DELTA_THR_US; MIN_DL_DELTA_EWMA_US; DL_DELTA_EWMA_US; DL_DELTA_EWMA_DELTA_US; DL_DELTA_EWMA_DELTA_THR; MIN_UL_DELTA_EWMA_US; UL_DELTA_EWMA_US; UL_DELTA_EWMA_DELTA_US; UL_DELTA_EWMA_DELTA_THR" header="REFLECTOR_HEADER; LOG_DATETIME; LOG_TIMESTAMP; PROC_TIME_US; REFLECTOR; MIN_SUM_OWD_BASELINES_US; SUM_OWD_BASELINES_US; SUM_OWD_BASELINES_DELTA_US; SUM_OWD_BASELINES_DELTA_THR_US; MIN_DL_DELTA_EWMA_US; DL_DELTA_EWMA_US; DL_DELTA_EWMA_DELTA_US; DL_DELTA_EWMA_DELTA_THR; MIN_UL_DELTA_EWMA_US; UL_DELTA_EWMA_US; UL_DELTA_EWMA_DELTA_US; UL_DELTA_EWMA_DELTA_THR"
((log_to_file)) && printf '%s\n' "${header}" >> "${log_file_path}" ((log_to_file)) && printf '%s\n' "${header}" >> "${log_file_path}"
((terminal)) && printf '%s\n' "${header}" ((terminal)) && printf '%s\n' "${header}"
header="SUMMARY_HEADER; LOG_DATETIME; LOG_TIMESTAMP; DL_ACHIEVED_RATE_KBPS; UL_ACHIEVED_RATE_KBPS; DL_SUM_DELAYS; UL_SUM_DELAYS; DL_AVG_OWD_DELTA_US; UL_AVG_OWD_DELTA_US; DL_LOAD_CONDITION; UL_LOAD_CONDITION; CAKE_DL_RATE_KBPS; CAKE_UL_RATE_KBPS"
((log_to_file)) && printf '%s\n' "${header}" >> "${log_file_path}"
((terminal)) && printf '%s\n' "${header}"
} }
# MAINTAIN_LOG_FILE + HELPER FUNCTIONS # MAINTAIN_LOG_FILE + HELPER FUNCTIONS
@ -374,9 +378,18 @@ update_shaper_rate()
*bb*) *bb*)
if (( t_start_us > (t_last_bufferbloat_us["${direction}"]+bufferbloat_refractory_period_us) )) if (( t_start_us > (t_last_bufferbloat_us["${direction}"]+bufferbloat_refractory_period_us) ))
then then
adjusted_achieved_rate_kbps=$(( (achieved_rate_kbps["${direction}"]*achieved_rate_adjust_down_bufferbloat)/1000 )) if (( avg_owd_delta_thr_us["${direction}"] == 0 ))
adjusted_shaper_rate_kbps=$(( (shaper_rate_kbps["${direction}"]*shaper_rate_adjust_down_bufferbloat)/1000 )) then
shaper_rate_kbps["${direction}"]=$(( adjusted_achieved_rate_kbps > min_shaper_rate_kbps["${direction}"] && adjusted_achieved_rate_kbps < adjusted_shaper_rate_kbps ? adjusted_achieved_rate_kbps : adjusted_shaper_rate_kbps )) shaper_rate_adjust_down_bufferbloat_factor=1000
elif (( avg_owd_delta_us["${direction}"] > 0 ))
then
shaper_rate_adjust_down_bufferbloat_factor=$(( (1000*avg_owd_delta_us["${direction}"])/compensated_avg_owd_delta_thr_us["${direction}"] ))
(( shaper_rate_adjust_down_bufferbloat_factor > 1000 )) && shaper_rate_adjust_down_bufferbloat_factor=1000
else
shaper_rate_adjust_down_bufferbloat_factor=0
fi
shaper_rate_adjust_down_bufferbloat=$(( 1000000-shaper_rate_adjust_down_bufferbloat_factor*(1000-shaper_rate_max_adjust_down_bufferbloat) ))
shaper_rate_kbps["${direction}"]=$(( (shaper_rate_kbps["${direction}"]*shaper_rate_adjust_down_bufferbloat)/1000000 ))
t_last_bufferbloat_us["${direction}"]="${EPOCHREALTIME/./}" t_last_bufferbloat_us["${direction}"]="${EPOCHREALTIME/./}"
fi fi
;; ;;
@ -1543,12 +1556,14 @@ update_max_wire_packet_compensation()
# Compensate for delays imposed by active traffic shaper # Compensate for delays imposed by active traffic shaper
# This will serve to increase the delay thr at rates below around 12Mbit/s # This will serve to increase the delay thr at rates below around 12Mbit/s
# compensated OWD delay thresholds in microseconds dl_compensation_us=$(( (1000*dl_max_wire_packet_size_bits)/shaper_rate_kbps[dl] ))
compensated_dl_delay_thr_us=$(( dl_delay_thr_us + (1000*dl_max_wire_packet_size_bits)/shaper_rate_kbps[dl] )) ul_compensation_us=$(( (1000*ul_max_wire_packet_size_bits)/shaper_rate_kbps[ul] ))
compensated_ul_delay_thr_us=$(( ul_delay_thr_us + (1000*ul_max_wire_packet_size_bits)/shaper_rate_kbps[ul] ))
printf "SET_VAR compensated_dl_delay_thr_us %s\n" "${compensated_dl_delay_thr_us}" >&"${maintain_pingers_fd}" compensated_owd_delta_thr_us[dl]=$(( dl_owd_delta_thr_us + dl_compensation_us ))
printf "SET_VAR compensated_dl_delay_thr_us %s\n" "${compensated_dl_delay_thr_us}" >&"${maintain_pingers_fd}" compensated_owd_delta_thr_us[ul]=$(( ul_owd_delta_thr_us + ul_compensation_us ))
compensated_avg_owd_delta_thr_us[dl]=$(( dl_avg_owd_delta_thr_us + dl_compensation_us ))
compensated_avg_owd_delta_thr_us[ul]=$(( ul_avg_owd_delta_thr_us + ul_compensation_us ))
max_wire_packet_rtt_us=$(( (1000*dl_max_wire_packet_size_bits)/shaper_rate_kbps[dl] + (1000*ul_max_wire_packet_size_bits)/shaper_rate_kbps[ul] )) max_wire_packet_rtt_us=$(( (1000*dl_max_wire_packet_size_bits)/shaper_rate_kbps[dl] + (1000*ul_max_wire_packet_size_bits)/shaper_rate_kbps[ul] ))
@ -1926,13 +1941,14 @@ verify_ifs_up
# Convert human readable parameters to values that work with integer arithmetic # Convert human readable parameters to values that work with integer arithmetic
printf -v dl_delay_thr_us %.0f "${dl_delay_thr_ms}e3" printf -v dl_owd_delta_thr_us %.0f "${dl_owd_delta_thr_ms}e3"
printf -v ul_delay_thr_us %.0f "${ul_delay_thr_ms}e3" printf -v ul_owd_delta_thr_us %.0f "${ul_owd_delta_thr_ms}e3"
printf -v dl_avg_owd_delta_thr_us %.0f "${dl_avg_owd_delta_thr_ms}e3"
printf -v ul_avg_owd_delta_thr_us %.0f "${ul_avg_owd_delta_thr_ms}e3"
printf -v alpha_baseline_increase %.0f "${alpha_baseline_increase}e6" printf -v alpha_baseline_increase %.0f "${alpha_baseline_increase}e6"
printf -v alpha_baseline_decrease %.0f "${alpha_baseline_decrease}e6" printf -v alpha_baseline_decrease %.0f "${alpha_baseline_decrease}e6"
printf -v alpha_delta_ewma %.0f "${alpha_delta_ewma}e6" printf -v alpha_delta_ewma %.0f "${alpha_delta_ewma}e6"
printf -v achieved_rate_adjust_down_bufferbloat %.0f "${achieved_rate_adjust_down_bufferbloat}e3" printf -v shaper_rate_max_adjust_down_bufferbloat %.0f "${shaper_rate_max_adjust_down_bufferbloat}e3"
printf -v shaper_rate_adjust_down_bufferbloat %.0f "${shaper_rate_adjust_down_bufferbloat}e3"
printf -v shaper_rate_adjust_up_load_high %.0f "${shaper_rate_adjust_up_load_high}e3" printf -v shaper_rate_adjust_up_load_high %.0f "${shaper_rate_adjust_up_load_high}e3"
printf -v shaper_rate_adjust_down_load_low %.0f "${shaper_rate_adjust_down_load_low}e3" printf -v shaper_rate_adjust_down_load_low %.0f "${shaper_rate_adjust_down_load_low}e3"
printf -v shaper_rate_adjust_up_load_low %.0f "${shaper_rate_adjust_up_load_low}e3" printf -v shaper_rate_adjust_up_load_low %.0f "${shaper_rate_adjust_up_load_low}e3"
@ -1976,6 +1992,10 @@ declare -A min_shaper_rate_kbps
declare -A max_shaper_rate_kbps declare -A max_shaper_rate_kbps
declare -A interface declare -A interface
declare -A adjust_shaper_rate declare -A adjust_shaper_rate
declare -A avg_owd_delta_us
declare -A avg_owd_delta_thr_us
declare -A compensated_owd_delta_thr_us
declare -A compensated_avg_owd_delta_thr_us
base_shaper_rate_kbps[dl]="${base_dl_shaper_rate_kbps}" base_shaper_rate_kbps[dl]="${base_dl_shaper_rate_kbps}"
base_shaper_rate_kbps[ul]="${base_ul_shaper_rate_kbps}" base_shaper_rate_kbps[ul]="${base_ul_shaper_rate_kbps}"
@ -2003,6 +2023,12 @@ ul_max_wire_packet_size_bits=0
get_max_wire_packet_size_bits "${dl_if}" dl_max_wire_packet_size_bits get_max_wire_packet_size_bits "${dl_if}" dl_max_wire_packet_size_bits
get_max_wire_packet_size_bits "${ul_if}" ul_max_wire_packet_size_bits get_max_wire_packet_size_bits "${ul_if}" ul_max_wire_packet_size_bits
avg_owd_delta_us[dl]=0
avg_owd_delta_us[ul]=0
avg_owd_delta_thr_us[dl]="${dl_avg_owd_delta_thr_us}"
avg_owd_delta_thr_us[ul]="${ul_avg_owd_delta_thr_us}"
set_shaper_rate "dl" set_shaper_rate "dl"
set_shaper_rate "ul" set_shaper_rate "ul"
@ -2023,10 +2049,14 @@ reflectors_last_timestamp_us="${EPOCHREALTIME/./}"
mapfile -t dl_delays < <(for ((i=1; i <= bufferbloat_detection_window; i++)); do echo 0; done) mapfile -t dl_delays < <(for ((i=1; i <= bufferbloat_detection_window; i++)); do echo 0; done)
mapfile -t ul_delays < <(for ((i=1; i <= bufferbloat_detection_window; i++)); do echo 0; done) mapfile -t ul_delays < <(for ((i=1; i <= bufferbloat_detection_window; i++)); do echo 0; done)
mapfile -t dl_owd_deltas_us < <(for ((i=1; i <= bufferbloat_detection_window; i++)); do echo 0; done)
mapfile -t ul_owd_deltas_us < <(for ((i=1; i <= bufferbloat_detection_window; i++)); do echo 0; done)
delays_idx=0 delays_idx=0
sum_dl_delays=0 sum_dl_delays=0
sum_ul_delays=0 sum_ul_delays=0
sum_dl_owd_deltas_us=0
sum_ul_owd_deltas_us=0
if ((debug)) if ((debug))
then then
@ -2142,18 +2172,32 @@ do
continue continue
fi fi
# Keep track of number of delays across detection window # Keep track of delays across detection window
# .. for download: # .. for download:
(( dl_delays[delays_idx] )) && ((sum_dl_delays--)) (( dl_delays[delays_idx] )) && ((sum_dl_delays--))
dl_delays[delays_idx]=$(( dl_owd_delta_us > compensated_dl_delay_thr_us ? 1 : 0 )) dl_delays[delays_idx]=$(( dl_owd_delta_us > compensated_owd_delta_thr_us[dl] ? 1 : 0 ))
((dl_delays[delays_idx])) && ((sum_dl_delays++)) ((dl_delays[delays_idx])) && ((sum_dl_delays++))
(( sum_dl_owd_deltas_us -= dl_owd_deltas_us[delays_idx] ))
(( dl_owd_deltas_us[delays_idx] = dl_owd_delta_us ))
(( sum_dl_owd_deltas_us += dl_owd_delta_us ))
# .. for upload # .. for upload
(( ul_delays[delays_idx] )) && ((sum_ul_delays--)) (( ul_delays[delays_idx] )) && ((sum_ul_delays--))
ul_delays[delays_idx]=$(( ul_owd_delta_us > compensated_ul_delay_thr_us ? 1 : 0 )) ul_delays[delays_idx]=$(( ul_owd_delta_us > compensated_owd_delta_thr_us[ul] ? 1 : 0 ))
((ul_delays[delays_idx])) && ((sum_ul_delays++)) ((ul_delays[delays_idx])) && ((sum_ul_delays++))
(( sum_ul_owd_deltas_us -= ul_owd_deltas_us[delays_idx] ))
(( ul_owd_deltas_us[delays_idx] = ul_owd_delta_us ))
(( sum_ul_owd_deltas_us += ul_owd_delta_us ))
# .. and move index on # .. and move index on
(( delays_idx=(delays_idx+1)%bufferbloat_detection_window )) (( delays_idx=(delays_idx+1)%bufferbloat_detection_window ))
(( avg_owd_delta_us[dl] = sum_dl_owd_deltas_us / bufferbloat_detection_window ))
(( avg_owd_delta_us[ul] = sum_ul_owd_deltas_us / bufferbloat_detection_window ))
bufferbloat_detected[dl]=$(( sum_dl_delays >= bufferbloat_detection_thr ? 1 : 0 )) bufferbloat_detected[dl]=$(( sum_dl_delays >= bufferbloat_detection_thr ? 1 : 0 ))
bufferbloat_detected[ul]=$(( sum_ul_delays >= bufferbloat_detection_thr ? 1 : 0 )) bufferbloat_detected[ul]=$(( sum_ul_delays >= bufferbloat_detection_thr ? 1 : 0 ))
@ -2171,10 +2215,16 @@ do
if (( output_processing_stats )) if (( output_processing_stats ))
then then
printf -v processing_stats '%s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s' "${EPOCHREALTIME}" "${achieved_rate_kbps[dl]}" "${achieved_rate_kbps[ul]}" "${load_percent[dl]}" "${load_percent[ul]}" "${timestamp}" "${reflector}" "${seq}" "${dl_owd_baseline_us}" "${dl_owd_us}" "${dl_owd_delta_ewma_us}" "${dl_owd_delta_us}" "${compensated_dl_delay_thr_us}" "${ul_owd_baseline_us}" "${ul_owd_us}" "${ul_owd_delta_ewma_us}" "${ul_owd_delta_us}" "${compensated_ul_delay_thr_us}" "${sum_dl_delays}" "${sum_ul_delays}" "${load_condition[dl]}" "${load_condition[ul]}" "${shaper_rate_kbps[dl]}" "${shaper_rate_kbps[ul]}" printf -v processing_stats '%s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s' "${EPOCHREALTIME}" "${achieved_rate_kbps[dl]}" "${achieved_rate_kbps[ul]}" "${load_percent[dl]}" "${load_percent[ul]}" "${timestamp}" "${reflector}" "${seq}" "${dl_owd_baseline_us}" "${dl_owd_us}" "${dl_owd_delta_ewma_us}" "${dl_owd_delta_us}" "${compensated_owd_delta_thr_us[dl]}" "${ul_owd_baseline_us}" "${ul_owd_us}" "${ul_owd_delta_ewma_us}" "${ul_owd_delta_us}" "${compensated_owd_delta_thr_us[ul]}" "${sum_dl_delays}" "${avg_owd_delta_us[dl]}" "${compensated_avg_owd_delta_thr_us[dl]}" "${sum_ul_delays}" "${avg_owd_delta_us[ul]}" "${compensated_avg_owd_delta_thr_us[ul]}" "${load_condition[dl]}" "${load_condition[ul]}" "${shaper_rate_kbps[dl]}" "${shaper_rate_kbps[ul]}"
log_msg "DATA" "${processing_stats}" log_msg "DATA" "${processing_stats}"
fi fi
if (( output_summary_stats ))
then
printf -v summary_stats '%s; %s; %s; %s; %s; %s; %s; %s; %s; %s' "${achieved_rate_kbps[dl]}" "${achieved_rate_kbps[ul]}" "${sum_dl_delays}" "${sum_ul_delays}" "${avg_owd_delta_us[dl]}" "${avg_owd_delta_us[ul]}" "${load_condition[dl]}" "${load_condition[ul]}" "${shaper_rate_kbps[dl]}" "${shaper_rate_kbps[ul]}"
log_msg "SUMMARY" "${summary_stats}"
fi
# If base rate is sustained, increment sustained base rate timer (and break out of processing loop if enough time passes) # If base rate is sustained, increment sustained base rate timer (and break out of processing loop if enough time passes)
if (( enable_sleep_function )) if (( enable_sleep_function ))
then then
@ -2204,7 +2254,7 @@ do
log_msg "DEBUG" "Warning: no reflector response within: ${stall_detection_timeout_s} seconds. Checking loads." log_msg "DEBUG" "Warning: no reflector response within: ${stall_detection_timeout_s} seconds. Checking loads."
#log_msg "DEBUG" "load check is: (( ${achieved_rate_kbps[dl]} kbps > ${connection_stall_thr_kbps} kbps for download && ${achieved_rate_kbps[ul]} kbps > ${connection_stall_thr_kbps} kbps for upload ))" log_msg "DEBUG" "load check is: (( ${achieved_rate_kbps[dl]} kbps > ${connection_stall_thr_kbps} kbps for download && ${achieved_rate_kbps[ul]} kbps > ${connection_stall_thr_kbps} kbps for upload ))"
# non-zero load so despite no reflector response within stall interval, the connection not considered to have stalled # non-zero load so despite no reflector response within stall interval, the connection not considered to have stalled
# and therefore resume normal operation # and therefore resume normal operation

View file

@ -15,6 +15,7 @@ INTERFACE=$(basename "$1" | cut -d. -f2)
output_processing_stats=$(uci -q get sqm.${INTERFACE}.output_processing_stats || echo '0') # enable (1) or disable (0) output monitoring lines showing processing stats output_processing_stats=$(uci -q get sqm.${INTERFACE}.output_processing_stats || echo '0') # enable (1) or disable (0) output monitoring lines showing processing stats
output_load_stats=$(uci -q get sqm.${INTERFACE}.output_load_stats || echo '0') # enable (1) or disable (0) output monitoring lines showing achieved loads output_load_stats=$(uci -q get sqm.${INTERFACE}.output_load_stats || echo '0') # enable (1) or disable (0) output monitoring lines showing achieved loads
output_reflector_stats=$(uci -q get sqm.${INTERFACE}.output_reflector_stats || echo '0') # enable (1) or disable (0) output monitoring lines showing reflector stats output_reflector_stats=$(uci -q get sqm.${INTERFACE}.output_reflector_stats || echo '0') # enable (1) or disable (0) output monitoring lines showing reflector stats
output_summary_stats=1 # enable (1) or disable (0) output monitoring lines showing summary stats
output_cake_changes=$(uci -q get sqm.${INTERFACE}.output_cake_changes || echo '0') # enable (1) or disable (0) output monitoring lines showing cake bandwidth changes output_cake_changes=$(uci -q get sqm.${INTERFACE}.output_cake_changes || echo '0') # enable (1) or disable (0) output monitoring lines showing cake bandwidth changes
debug=$(uci -q get sqm.${INTERFACE}.debug || echo '0') # enable (1) or disable (0) out of debug lines debug=$(uci -q get sqm.${INTERFACE}.debug || echo '0') # enable (1) or disable (0) out of debug lines
@ -77,8 +78,14 @@ reflector_ping_interval_s=$(uci -q get sqm.${INTERFACE}.reflector_ping_interval_
# these are automatically adjusted based on maximum on the wire packet size # these are automatically adjusted based on maximum on the wire packet size
# (adjustment significant at sub 12Mbit/s rates, else negligible) # (adjustment significant at sub 12Mbit/s rates, else negligible)
#logger -t "sqm-autorate" "ping for ${INTERFACE} (${ul_if}): $(echo $(/sbin/uci -q get sqm.${INTERFACE}.delay_thr_ms || echo '100'))" #logger -t "sqm-autorate" "ping for ${INTERFACE} (${ul_if}): $(echo $(/sbin/uci -q get sqm.${INTERFACE}.delay_thr_ms || echo '100'))"
dl_delay_thr_ms=$(echo $(uci -q get sqm.${INTERFACE}.delay_thr_ms || echo $(($(/usr/bin/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) dl_owd_delta_thr_ms=$(echo $(echo $(uci -q get sqm.${INTERFACE}.delay_thr_ms || echo $(($(/usr/bin/ping -B -w 5 -c 5 -I ${ul_if} 1.1.1.1 | cut -d '/' -s -f6 | tr -d '\n' 2>/dev/null)+30)) || echo "100")) + "0.1" | bc) # (milliseconds)
ul_delay_thr_ms=${dl_delay_thr_ms} ul_owd_delta_thr_ms=${dl_owd_delta_thr_ms}
# average owd delta threshold in ms at which maximum adjust_down_bufferbloat is applied
# set value(s) to 0 to disable and always apply maximum adjust_down_bufferbloat
dl_avg_owd_delta_thr_ms=$(echo "$dl_owd_delta_thr_ms * 2" | bc) # (milliseconds)
ul_avg_owd_delta_thr_ms=$(echo "$ul_owd_delta_thr_ms * 2" | bc) # (milliseconds)
# Set either of the below to 0 to adjust one direction only # 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 # or alternatively set both to 0 to simply use cake-autorate to monitor a connection
adjust_dl_shaper_rate=1 # enable (1) or disable (0) actually changing the dl shaper rate adjust_dl_shaper_rate=1 # enable (1) or disable (0) actually changing the dl shaper rate
@ -159,8 +166,7 @@ alpha_delta_ewma=0.095
# bufferbloat adjustment works with the lower of the adjusted achieved rate and adjusted shaper rate # bufferbloat adjustment works with the lower of the adjusted achieved rate and adjusted shaper rate
# to exploit that transfer rates during bufferbloat provide an indication of line capacity # to exploit that transfer rates during bufferbloat provide an indication of line capacity
# otherwise shaper rate is adjusted up on load high, and down on load idle or low # otherwise shaper rate is adjusted up on load high, and down on load idle or low
achieved_rate_adjust_down_bufferbloat=0.9 # how rapidly to reduce achieved rate upon detection of bufferbloat #shaper_rate_adjust_down_bufferbloat=0.75 # how rapidly to reduce shaper rate upon detection of bufferbloat
shaper_rate_adjust_down_bufferbloat=0.9 # how rapidly to reduce shaper rate upon detection of bufferbloat
shaper_rate_adjust_up_load_high=1.01 # how rapidly to increase shaper rate upon high load detected shaper_rate_adjust_up_load_high=1.01 # how rapidly to increase shaper rate upon high load detected
shaper_rate_adjust_down_load_low=0.99 # how rapidly to return down to base shaper rate upon idle or low load detected shaper_rate_adjust_down_load_low=0.99 # how rapidly to return down to base shaper rate upon idle or low load detected
shaper_rate_adjust_up_load_low=1.01 # how rapidly to return up to base shaper rate upon idle or low load detected shaper_rate_adjust_up_load_low=1.01 # how rapidly to return up to base shaper rate upon idle or low load detected
@ -191,7 +197,7 @@ reflector_replacement_interval_mins=60 # how often to replace a random reflector
reflector_comparison_interval_mins=1 # how often to compare reflectors 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 reflector_owd_delta_ewma_delta_thr_ms=10.0 # mac increase from min delta ewma before reflector rotated
# stall is detected when the following two conditions are met: # stall is detected when the following two conditions are met:
# 1) no reflector responses within $stall_detection_thr*$ping_response_interval_us; and # 1) no reflector responses within $stall_detection_thr*$ping_response_interval_us; and
@ -199,7 +205,7 @@ reflector_owd_delta_ewma_delta_thr_ms=10 # mac increase from min delta ewma be
stall_detection_thr=5 stall_detection_thr=5
connection_stall_thr_kbps=10 connection_stall_thr_kbps=10
global_ping_response_timeout_s=${dl_delay_thr_ms} # timeout to set shaper rates to min on no ping response whatsoever (seconds) global_ping_response_timeout_s=${dl_owd_delta_thr_ms} # timeout to set shaper rates to min on no ping response whatsoever (seconds)
if_up_check_interval_s=10.0 # time to wait before re-checking if rx/tx bytes files exist (e.g. from boot state or sleep recovery) if_up_check_interval_s=10.0 # time to wait before re-checking if rx/tx bytes files exist (e.g. from boot state or sleep recovery)

View file

@ -1,11 +1,17 @@
#!/bin/bash #!/bin/bash
# cake-autorate automatically adjusts bandwidth for CAKE in dependence on detected load and RTT # defaults.sh -- default configuration values for cake-autorate.sh
#
# cake-autorate_config.sh is a script that sets up defaults for cake-autorate # This file is part of cake-autorate.
#
# Author: @Lynx (OpenWrt forum) # CAKE-AUTORATE IS HIGHLY CONFIGURABLE AND THIS FILE MAY BE
# Inspiration taken from: @moeller0 (OpenWrt forum) # CONSULTED IN RESPECT OF OVERRIDING VARIABLES IN A CONFIG FILE.
#
# DO NOT MODIFY THIS FILE. ANY CHANGES NEED TO BE MADE TO
# THE CONFIG FILE FOR A GIVEN INSTANCE OF CAKE-AUTORATE.
# MODIFYING THIS FILE WILL RESULT IN THE LOSS OF ANY CHANGES
# DURING AN UPDATE OR UNEXPECTED BEHAVIOR AFTER AN UPDATE
# IF THE OLD DEFAULT FILE WAS IN USE.
INTERFACE="" INTERFACE=""
@ -14,15 +20,16 @@ INTERFACE=""
output_processing_stats=1 # enable (1) or disable (0) output monitoring lines showing processing stats output_processing_stats=1 # enable (1) or disable (0) output monitoring lines showing processing stats
output_load_stats=1 # enable (1) or disable (0) output monitoring lines showing achieved loads output_load_stats=1 # enable (1) or disable (0) output monitoring lines showing achieved loads
output_reflector_stats=1 # enable (1) or disable (0) output monitoring lines showing reflector stats output_reflector_stats=1 # enable (1) or disable (0) output monitoring lines showing reflector stats
output_summary_stats=1 # enable (1) or disable (0) output monitoring lines showing summary stats
output_cake_changes=0 # enable (1) or disable (0) output monitoring lines showing cake bandwidth changes output_cake_changes=0 # enable (1) or disable (0) output monitoring lines showing cake bandwidth changes
debug=1 # enable (1) or disable (0) out of debug lines debug=1 # enable (1) or disable (0) out of debug lines
# This can generate a LOT of records so be careful: # This can generate a LOT of records so be careful:
log_DEBUG_messages_to_syslog=0 # enable (1) or disable (0) logging of all DEBUG records into the system log. log_DEBUG_messages_to_syslog=0 # enable (1) or disable (0) logging of all DEBUG records into the system log.
# ** Take care with these settings to ensure you won't run into OOM issues on your router *** # ** Take care with these settings to ensure you won't run into OOM issues on your router ***
# every write the cumulative write time and bytes associated with each log line are checked # every write the cumulative write time and bytes associated with each log line are checked
# and if either exceeds the configured values below, the log log file is rotated # and if either exceeds the configured values below, the log file is rotated
log_to_file=1 # enable (1) or disable (0) output logging to file (/tmp/cake-autorate.log) log_to_file=1 # enable (1) or disable (0) output logging to file (/tmp/cake-autorate.log)
log_file_max_time_mins=10 # maximum time between log file rotations log_file_max_time_mins=10 # maximum time between log file rotations
log_file_max_size_KB=2000 # maximum KB (i.e. bytes/1024) worth of log lines between log file rotations log_file_max_size_KB=2000 # maximum KB (i.e. bytes/1024) worth of log lines between log file rotations
@ -33,21 +40,21 @@ log_file_path_override=""
# *** STANDARD CONFIGURATION OPTIONS *** # *** STANDARD CONFIGURATION OPTIONS ***
### For multihomed setups, it is the responsibility of the user to ensure that the probes ### For multihomed setups, it is the responsibility of the user to ensure that the probes
### sent by this instance of cake-autorate actually travel through these interfaces. ### sent by this instance of cake-autorate actually travel through these interfaces.
### See ping_extra_args and ping_prefix_string ### See ping_extra_args and ping_prefix_string
dl_if=ifb-wan # download interface dl_if=ifb-wan # download interface
ul_if=wan # upload interface ul_if=wan # upload interface
# pinger selection can be any of: # pinger binary selection can be any of:
# fping - round robin pinging (rtts) # fping - round robin pinging (rtts)
# tsping - round robin pinging using ICMP type 13 (owds)
# ping - (iputils-ping) individual pinging (rtts) # ping - (iputils-ping) individual pinging (rtts)
# hping3 - individidual pinging (owds)
pinger_binary=fping pinger_binary=fping
# list of reflectors to use and number of pingers to initiate # list of reflectors to use and number of pingers to initiate
# pingers will be initiated with reflectors in the order specified in the list # pingers will be initiated with reflectors in the order specified in the list
# additional reflectors will be used to replace any reflectors that go stale # additional reflectors will be used to replace any reflectors that go stale
# so e.g. if 6 reflectors are specified and the number of pingers is set to 4, the first 4 reflectors will be used initially # so e.g. if 6 reflectors are specified and the number of pingers is set to 4, the first 4 reflectors will be used initially
# and the remaining 2 reflectors in the list will be used in the event any of the first 4 go bad # and the remaining 2 reflectors in the list will be used in the event any of the first 4 go bad
@ -71,13 +78,18 @@ randomize_reflectors=1 # enable (1) or disable (0) randomization of reflectors o
no_pingers=6 # number of pingers to maintain no_pingers=6 # number of pingers to maintain
reflector_ping_interval_s=0.3 # (seconds, e.g. 0.2s or 2s) reflector_ping_interval_s=0.3 # (seconds, e.g. 0.2s or 2s)
# delay threshold in ms is the extent of OWD increase to classify as a delay # owd delta 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 # these are automatically adjusted based on maximum on the wire packet size
# (adjustment significant at sub 12Mbit/s rates, else negligible) # (adjustment significant at sub 12Mbit/s rates, else negligible)
dl_delay_thr_ms=30 # (milliseconds) dl_owd_delta_thr_ms=30.0 # (milliseconds)
ul_delay_thr_ms=30 # (milliseconds) ul_owd_delta_thr_ms=30.0 # (milliseconds)
# Set either of the below to 0 to adjust one direction only # average owd delta threshold in ms at which maximum adjust_down_bufferbloat is applied
# set value(s) to 0 to disable and always apply maximum adjust_down_bufferbloat
dl_avg_owd_delta_thr_ms=60.0 # (milliseconds)
ul_avg_owd_delta_thr_ms=60.0 # (milliseconds)
# 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 # or alternatively set both to 0 to simply use cake-autorate to monitor a connection
adjust_dl_shaper_rate=1 # enable (1) or disable (0) actually changing the dl shaper rate adjust_dl_shaper_rate=1 # enable (1) or disable (0) actually changing the dl shaper rate
adjust_ul_shaper_rate=1 # enable (1) or disable (0) actually changing the ul shaper rate adjust_ul_shaper_rate=1 # enable (1) or disable (0) actually changing the ul shaper rate
@ -92,7 +104,7 @@ max_ul_shaper_rate_kbps=35000 # maximum bandwidth for upload (Kbit/s)
# sleep functionality saves unecessary pings and CPU cycles by # sleep functionality saves unecessary pings and CPU cycles by
# pausing all active pingers when connection is not in active use # pausing all active pingers when connection is not in active use
enable_sleep_function=1 # enable (1) or disable (0) sleep functonality enable_sleep_function=1 # enable (1) or disable (0) sleep functonality
connection_active_thr_kbps=1000 # threshold in Kbit/s below which dl/ul is considered idle connection_active_thr_kbps=1000 # threshold in Kbit/s below which dl/ul is considered idle
sustained_idle_sleep_thr_s=60.0 # time threshold to put pingers to sleep on sustained dl/ul achieved rate < idle_thr (seconds) sustained_idle_sleep_thr_s=60.0 # time threshold to put pingers to sleep on sustained dl/ul achieved rate < idle_thr (seconds)
@ -135,8 +147,8 @@ ping_prefix_string=""
# interval in ms for monitoring achieved rx/tx rates # interval in ms for monitoring achieved rx/tx rates
# this is automatically adjusted based on maximum on the wire packet size # this is automatically adjusted based on maximum on the wire packet size
# (adjustment significant at sub 12Mbit/s rates, else negligible) # (adjustment significant at sub 12Mbit/s rates, else negligible)
monitor_achieved_rates_interval_ms=200 # (milliseconds) monitor_achieved_rates_interval_ms=200 # (milliseconds)
# bufferbloat is detected when (bufferbloat_detection_thr) samples # bufferbloat is detected when (bufferbloat_detection_thr) samples
# out of the last (bufferbloat detection window) samples are delayed # out of the last (bufferbloat detection window) samples are delayed
@ -153,21 +165,20 @@ alpha_baseline_decrease=0.9 # how rapidly baseline RTT is allowed to decrease
# OWD delta from baseline is tracked using ewma with alpha set below # OWD delta from baseline is tracked using ewma with alpha set below
alpha_delta_ewma=0.095 alpha_delta_ewma=0.095
# rate adjustment parameters # rate adjustment parameters
# bufferbloat adjustment works with the lower of the adjusted achieved rate and adjusted shaper rate # shaper rate is adjusted by a maximum of shaper_rate_max_adjust_down_bufferbloat on detection of bufferbloat
# to exploit that transfer rates during bufferbloat provide an indication of line capacity # and this is scaled by the average delta owd / average owd delta threshold
# otherwise shaper rate is adjusted up on load high, and down on load idle or low # otherwise shaper rate is adjusted up on load high, and down on load idle or low
achieved_rate_adjust_down_bufferbloat=0.9 # how rapidly to reduce achieved rate upon detection of bufferbloat shaper_rate_max_adjust_down_bufferbloat=0.75 # how rapidly to reduce shaper rate upon detection of bufferbloat
shaper_rate_adjust_down_bufferbloat=0.9 # how rapidly to reduce shaper rate upon detection of bufferbloat shaper_rate_adjust_up_load_high=1.01 # how rapidly to increase shaper rate upon high load detected
shaper_rate_adjust_up_load_high=1.01 # how rapidly to increase shaper rate upon high load detected shaper_rate_adjust_down_load_low=0.99 # how rapidly to return down to base shaper rate upon idle or low load detected
shaper_rate_adjust_down_load_low=0.99 # how rapidly to return down to base shaper rate upon idle or low load detected shaper_rate_adjust_up_load_low=1.01 # how rapidly to return up to base shaper rate upon idle or low load detected
shaper_rate_adjust_up_load_low=1.01 # how rapidly to return up to base shaper rate upon idle or low load detected
# the load is categoried as low if < high_load_thr and high if > high_load_thr relative to the current shaper rate # the load is categoried as low if < high_load_thr and high if > high_load_thr relative to the current shaper rate
high_load_thr=0.75 # % of currently set bandwidth for detecting high load high_load_thr=0.75 # % of currently set bandwidth for detecting high load
# refractory periods between successive bufferbloat/decay rate changes # refractory periods between successive bufferbloat/decay rate changes
# the bufferbloat refractory period should be greater than the # the bufferbloat refractory period should be greater than the
# average time it would take to replace the bufferbloat # average time it would take to replace the bufferbloat
# detection window with new samples upon a bufferbloat event # detection window with new samples upon a bufferbloat event
bufferbloat_refractory_period_ms=300 # (milliseconds) bufferbloat_refractory_period_ms=300 # (milliseconds)
@ -181,15 +192,15 @@ reflector_response_deadline_s=1.0 # (seconds)
# reflector misbehaving is detected when $reflector_misbehaving_detection_thr samples # reflector misbehaving is detected when $reflector_misbehaving_detection_thr samples
# out of the last (reflector misbehaving detection window) samples are offences # out of the last (reflector misbehaving detection window) samples are offences
# thus with a 1s interval, window 60 and detection_thr 3, this is tantamount to # thus with a 1s interval, window 60 and detection_thr 3, this is tantamount to
# 3 offences within the last 60s # 3 offences within the last 60s
reflector_misbehaving_detection_window=60 reflector_misbehaving_detection_window=60
reflector_misbehaving_detection_thr=3 reflector_misbehaving_detection_thr=3
reflector_replacement_interval_mins=60 # how often to replace a random reflector from the present list 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_comparison_interval_mins=1 # how often to compare reflectors
reflector_sum_owd_baselines_delta_thr_ms=20 # max increase from min sum owd baselines before reflector rotated reflector_sum_owd_baselines_delta_thr_ms=20.0 # max increase from min sum owd baselines before reflector rotated
reflector_owd_delta_ewma_delta_thr_ms=10 # max increase from min delta ewma before reflector rotated reflector_owd_delta_ewma_delta_thr_ms=10.0 # max increase from min delta ewma before reflector rotated
# stall is detected when the following two conditions are met: # stall is detected when the following two conditions are met:
# 1) no reflector responses within $stall_detection_thr*$ping_response_interval_us; and # 1) no reflector responses within $stall_detection_thr*$ping_response_interval_us; and
@ -197,7 +208,7 @@ reflector_owd_delta_ewma_delta_thr_ms=10 # max increase from min delta ewma befo
stall_detection_thr=5 stall_detection_thr=5
connection_stall_thr_kbps=10 connection_stall_thr_kbps=10
global_ping_response_timeout_s=10 # timeout to set shaper rates to min on no ping response whatsoever (seconds) global_ping_response_timeout_s=10.0 # timeout to set shaper rates to min on no ping response whatsoever (seconds)
if_up_check_interval_s=10.0 # time to wait before re-checking if rx/tx bytes files exist (e.g. from boot state or sleep recovery) if_up_check_interval_s=10.0 # time to wait before re-checking if rx/tx bytes files exist (e.g. from boot state or sleep recovery)