Skip to content

Commit

Permalink
Merge pull request #345 from Ysurac/develop
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
suyuan168 authored Aug 22, 2023
2 parents d2ca5c1 + 229f723 commit 8f8fa6e
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 67 deletions.
2 changes: 1 addition & 1 deletion glorytun/init
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ start_instance() {
retry count -1 const 5000000 \
timeout ${timeout} \
keepalive count 5 idle 20 interval 2 \
buffer-size 327680
buffer-size 65536

procd_set_param respawn 0 30 0
procd_set_param file /tmp/${PROG_NAME}-${1}.key
Expand Down
4 changes: 2 additions & 2 deletions luci-app-mlvpn/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

include $(TOPDIR)/rules.mk

LUCI_TITLE:=LuCI Interface to Glorytun TCP
LUCI_DEPENDS:=+glorytun
LUCI_TITLE:=LuCI Interface to MLVPN
LUCI_DEPENDS:=+mlvpn

PKG_LICENSE:=GPLv3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ function wizard_add()
vpn_intf = "mlvpn0"
ucic:set("network","omrvpn","proto","dhcp")
elseif default_vpn == "ubond" then
vpn_port = 65201
vpn_port = 65251
vpn_intf = "ubond0"
ucic:set("network","omrvpn","proto","dhcp")
elseif default_vpn == "dsvpn" then
Expand Down Expand Up @@ -1003,7 +1003,7 @@ function wizard_add()
local ubond_password = luci.http.formvalue("ubond_password")
if ubond_password ~= "" then
ucic:set("ubond","general","password",ubond_password)
ucic:set("ubond","general","firstport","65201")
ucic:set("ubond","general","firstport","65251")
ucic:set("ubond","general","interface_name","ubond0")
else
--ucic:set("ubond","general","enable",0)
Expand Down Expand Up @@ -1054,7 +1054,7 @@ function wizard_add()
luci.sys.call("/etc/init.d/glorytun restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/glorytun-udp restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/mlvpn restart >/dev/null 2>/dev/null")
--luci.sys.call("/etc/init.d/ubond restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/ubond restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/mptcpovervpn restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/openvpn restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/openvpnbonding restart >/dev/null 2>/dev/null")
Expand All @@ -1063,6 +1063,7 @@ function wizard_add()
luci.sys.call("/etc/init.d/omr-6in4 restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/vnstat restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/v2ray restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/sqm restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/sqm-autorate restart >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/sysntpd restart >/dev/null 2>/dev/null")
luci.http.redirect(luci.dispatcher.build_url("admin/system/" .. menuentry:lower() .. "/status"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ <h3><%=ifname%></h3>
<div class="cbi-value" data-index="19">
<label class="cbi-value-title"><%:Calculate speed%></label>
<div class="cbi-value-field">
<input class="cbi-input-checkbox" type="checkbox" name="cbid.sqm.<%=ifname%>.testspeed" value="1" <% if uci:get("openmptcprouter",ifname,"testspeed") == "1" or uci:get("openmptcprouter",ifname,"testspeed") == nil then %>checked<% end %> />
<input class="cbi-input-checkbox" type="checkbox" name="cbid.sqm.<%=ifname%>.testspeed" value="1" <% if uci:get("openmptcprouter",ifname,"testspeed") == "1" then %>checked<% end %> />
<br />
<div class="cbi-value-description">
<%:Run an automatic speedtest to calculate max download & upload speed.%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ return view.extend({
o.depends("autorate","1");

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 = s.taboption("tab_autorate", form.Flag, "enable_sleep_function", _("Sleep functionnality"));
Expand Down
88 changes: 69 additions & 19 deletions luci-app-sqm-autorate/root/usr/share/sqm-autorate/cake-autorate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Author and maintainer: lynxthecat
# 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:
## main - main process
Expand Down Expand Up @@ -157,7 +157,7 @@ print_headers()
{
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}"
((terminal)) && printf '%s\n' "${header}"

Expand All @@ -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"
((log_to_file)) && printf '%s\n' "${header}" >> "${log_file_path}"
((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
Expand Down Expand Up @@ -374,9 +378,18 @@ update_shaper_rate()
*bb*)
if (( t_start_us > (t_last_bufferbloat_us["${direction}"]+bufferbloat_refractory_period_us) ))
then
adjusted_achieved_rate_kbps=$(( (achieved_rate_kbps["${direction}"]*achieved_rate_adjust_down_bufferbloat)/1000 ))
adjusted_shaper_rate_kbps=$(( (shaper_rate_kbps["${direction}"]*shaper_rate_adjust_down_bufferbloat)/1000 ))
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 ))
if (( avg_owd_delta_thr_us["${direction}"] == 0 ))
then
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/./}"
fi
;;
Expand Down Expand Up @@ -1543,12 +1556,14 @@ update_max_wire_packet_compensation()
# Compensate for delays imposed by active traffic shaper
# This will serve to increase the delay thr at rates below around 12Mbit/s

# compensated OWD delay thresholds in microseconds
compensated_dl_delay_thr_us=$(( dl_delay_thr_us + (1000*dl_max_wire_packet_size_bits)/shaper_rate_kbps[dl] ))
compensated_ul_delay_thr_us=$(( ul_delay_thr_us + (1000*ul_max_wire_packet_size_bits)/shaper_rate_kbps[ul] ))
dl_compensation_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] ))

printf "SET_VAR compensated_dl_delay_thr_us %s\n" "${compensated_dl_delay_thr_us}" >&"${maintain_pingers_fd}"
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 ))
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] ))

Expand Down Expand Up @@ -1926,13 +1941,14 @@ verify_ifs_up

# 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 ul_delay_thr_us %.0f "${ul_delay_thr_ms}e3"
printf -v dl_owd_delta_thr_us %.0f "${dl_owd_delta_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_decrease %.0f "${alpha_baseline_decrease}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_adjust_down_bufferbloat %.0f "${shaper_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_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_up_load_low %.0f "${shaper_rate_adjust_up_load_low}e3"
Expand Down Expand Up @@ -1976,6 +1992,10 @@ declare -A min_shaper_rate_kbps
declare -A max_shaper_rate_kbps
declare -A interface
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[ul]="${base_ul_shaper_rate_kbps}"
Expand Down Expand Up @@ -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 "${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 "ul"

Expand All @@ -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 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
sum_dl_delays=0
sum_ul_delays=0
sum_dl_owd_deltas_us=0
sum_ul_owd_deltas_us=0

if ((debug))
then
Expand Down Expand Up @@ -2142,18 +2172,32 @@ do
continue
fi

# Keep track of number of delays across detection window
# Keep track of delays across detection window

# .. for download:
(( 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++))

(( 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
(( 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++))

(( 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
(( 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[ul]=$(( sum_ul_delays >= bufferbloat_detection_thr ? 1 : 0 ))

Expand All @@ -2171,10 +2215,16 @@ do

if (( output_processing_stats ))
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}"
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 (( enable_sleep_function ))
then
Expand Down Expand Up @@ -2204,7 +2254,7 @@ do

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
# and therefore resume normal operation
Expand Down
Loading

0 comments on commit 8f8fa6e

Please sign in to comment.