Skip to content

Commit

Permalink
Merge pull request #44 from lynxthecat/next-generation
Browse files Browse the repository at this point in the history
Merge 'next-generation' to 'main'
  • Loading branch information
lynxthecat authored Sep 28, 2022
2 parents 37653b3 + feea654 commit 930cc1e
Show file tree
Hide file tree
Showing 5 changed files with 544 additions and 176 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ bandwidth settings by measuring traffic load and RTT times.
Read the [README](./README.md) file for more details.
This is the history of changes.

## 2022-08-21 - Version 1.0.0
## 2022-09-28 - Version 1.1

Implemented several new features such as:

- Switch default pinger binary to fping - it was identified that using concurrent instances of iputils-ping resulted in drift between ICMP requests, and fping solves this because it offers round robin pinging to multiple reflectors with tightly controlled timing between requests
- Generalised pinger functions to support wrappers for different ping binaries - fping and iputils-ping now specifically supported and handled, and new ping binaries can easily be added by including appropriate wrapper functions.
- Generalised code to work with one way delays (OWDs) from RTTs in preparation to use ICMP type 13 requests
- Only use capacity estimate on bufferbloat detection where the adjusted shaper rate based thereon would exceed the minimum configured shaper rate (avoiding the situation where e.g. idle load on download during upload-related bufferbloat would cause download shaper rate to get punished all the way down to the minimum)
- Stall detection and handling
- Much better log file handling including defaulting to logging, supporting logging even when running from console, log file rotation on configured time elapsed or configured bytes written to

## 2022-08-21 - Version 1.0

- New installer script - cake-autorate-setup.sh - now installs all required files
- Installer checks for presence of previous config and asks whether to overwrite
Expand Down
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

CAKE is an algorithm that manages the buffering of data being sent/received by a device such as an [OpenWrt router](https://openwrt.org) so that no more data is queued than is necessary, minimizing the latency ("bufferbloat") and improving the responsiveness of a network.

Present version is 1.1.0 - please see [the changelog](https://github.com/lynxthecat/cake-autorate/blob/9b19f8a7f9a47fe80ed1532e584647e6182b9c48/CHANGELOG.md) for details.

## The Problem: CAKE on Variable Connections forces an Unpalatable Compromise

The CAKE algorithm always uses fixed upload and download bandwidth settings to manage its queues. Variable bandwidth connections present a challenge because the actual bandwidth at any given moment is not known.
Expand Down Expand Up @@ -48,8 +50,16 @@ There is a detailed and fun discussion with plenty of sketches relating to the d

## Required packages

Only requires:

- **bash** for its builtins, arithmetic and array handling
- **iputils-ping** for more advanced ping with sub 1s ping frequency

A pinger binary chosen from:

- **fping** round robin pinging to multiple reflectors with tightly controlled timings (default selection)
- **iputils-ping** advanced pinging than the default busybox ping with sub 1s ping frequency

The pinger binary that cake-autorate uses is set using the $pinger_binary variable in the config file.

## Installation on OpenWrt

Expand Down Expand Up @@ -84,36 +94,34 @@ copying and pasting each of the commands below:
| Base | `base_dl_shaper_rate_kbps` | `base_ul_shaper_rate_kbps` |
| Max. | `max_dl_shaper_rate_kbps` | `max_ul_shaper_rate_kbps` |
- Two variables control logging:
- The following variables control logging:

| Variable | Setting |
|----: | :-------- |
| `output_processing_stats` | If non-zero, log the results of every iteration through the process |
| `output_cake_changes` | If non-zero, only log when changes are made to CAKE settings via `tc`. This shows when CAKE-autorate is adjusting the shaper. |
For long-term use, we recommend that `output_processing_stats` be set to zero (0);
`output_cake_changes` can be set to zero for minimal

| `output_cake_changes` | If non-zero, log when changes are made to CAKE settings via `tc` - this shows when CAKE-autorate is adjusting the shaper |
| `debug` | If non-zero, debug lines will be output |
| `log_to_file` | If non-zero, log lines will be sent to /tmp/cake-autorate.log regardless of whether printing to console and after every write the log file will be rotated f either `log_file_max_time_mins` have elapsed or `log_file_max_size_KB` has been exceeded |
| `log_file_max_time_mins` | Number of minutes to elapse between log file rotaton |
| `log_file_max_size_KB` | Number of KB (i.e. bytes/1024) worth of log lines between log file rotations |

## Example Starlink Configuration

- OpenWrt forum member @gba has kindly shared [his Starlink config](https://github.com/lynxthecat/cake-autorate/blob/main/Example_Starlink_config.sh).
- OpenWrt forum member @gba has kindly shared [his Starlink config](https://github.com/lynxthecat/cake-autorate/blob/main/Example_Starlink_config.sh). This ought to provide a helpful starting point for adjusting the present configuration file format for Startlink users.
- See discussion on OpenWrt thread from [around this post](https://forum.openwrt.org/t/cake-w-adaptive-bandwidth/108848/3100?u=lynx).
- This might be a good starting point for Starlink users.

## Manual testing

To run the `cake-autorate.sh` script:

- In `cake-autorate-config.sh`, set `output_processing_stats` to '0'
and `output_cake_changes` to '1'. Then run:
- run:

```bash
cd /root/cake-autorate # to the cake-autorate directory
bash ./cake-autorate.sh
./cake-autorate.sh
```

- This will output a line everytime CAKE-autorate adjusts a parameter
Monitor the script output to see how it adjusts the download
and upload rates as you use the connection.
- Monitor the script output to see how it adjusts the download and upload rates as you use the connection.
- Press ^C to halt the process.

## Install as a service
Expand All @@ -132,7 +140,7 @@ To do this:

When running as a service, the `cake-autorate.sh` script outputs to `/tmp/cake-autorate.log`.

WARNING: Consider setting **output\_processing\_stats** to '0' in `cake-autorate-config.sh` to minimize the volume of log messages.
WARNING: Take care to ensure sufficient free memory exists in router to handle selected logging parameters.

## Preserving CAKE-autorate files for backup or upgrades

Expand All @@ -149,4 +157,4 @@ so they will be saved in backups and preserved across snapshot upgrades.

## A Request to Testers

If you use this script I have just one ask. Please post your experience on this [OpenWrt Forum thread](https://forum.openwrt.org/t/cake-w-adaptive-bandwidth/108848/). Your feedback will help improve the script for the benefit of others.
If you use this script I have just one ask. Please post your experience on this [OpenWrt Forum thread](https://forum.openwrt.org/t/cake-w-adaptive-bandwidth/135379/). Your feedback will help improve the script for the benefit of others.
43 changes: 32 additions & 11 deletions cake-autorate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@
# Author: @Lynx (OpenWrt forum)
# Inspiration taken from: @moeller0 (OpenWrt forum)

cake_autorate_version="1.0.0"
cake_autorate_version="1.1.0"

# *** OUTPUT OPTIONS ***
# *** OUTPUT AND LOGGING OPTIONS ***

output_processing_stats=1 # enable (1) or disable (0) output monitoring lines showing processing stats
output_cake_changes=0 # enable (1) or disable (0) output monitoring lines showing cake bandwidth changes
debug=0 # enable (1) or disable (0) out of debug lines
debug=1 # enable (1) or disable (0) out of debug lines

# ** 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
# and if either exceeds the configured values below, the log log file is rotated
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_size_KB=2000 # maximum KB (i.e. bytes/1024) worth of log lines between log file rotations

# *** STANDARD CONFIGURATION OPTIONS ***

dl_if=ifb-wg-pbr # download interface
ul_if=wan # upload interface
dl_if=ifb-dl # download interface
ul_if=ifb-ul # upload interface

# pinger selection can be any of:
# fping - round robin pinging (rtts)
# ping - (iputils-ping) individual pinging (rtts)
# hping3 - individidual pinging (owds)
pinger_binary=fping

reflector_ping_interval_s=0.2 # (seconds, e.g. 0.2s or 2s)

Expand Down Expand Up @@ -52,8 +65,14 @@ sustained_idle_sleep_thr_s=60 # time threshold to put pingers to sleep on susta

startup_wait_s=0 # number of seconds to wait on startup (e.g. to wait for things to settle on router reboot)


# *** ADVANCED CONFIGURATION OPTIONS ***

# extra arguments for ping
# e.g., when using mwan3, set up the correct outgoing interface and the firewall mark
# ping_extra_args=(-I wwan0 -m $((0x300)))
ping_extra_args=()

# interval in ms for monitoring achieved rx/tx rates
# this is automatically adjusted based on maximum on the wire packet size
# (adjustment significant at sub 12Mbit/s rates, else negligible)
Expand Down Expand Up @@ -105,11 +124,16 @@ reflector_response_deadline_s=1 # (seconds)
reflector_misbehaving_detection_window=60
reflector_misbehaving_detection_thr=3

# stall is detected when the following two conditions are met:
# 1) no reflector responses within $stall_detection_thr*$ping_response_interval_us; and
# 2) either $rx_achieved_rate or $tx_achieved_rate < $connection_stall_thr
stall_detection_thr=5
connection_stall_thr_kbps=10

global_ping_response_timeout_s=10 # timeout to set shaper rates to min on no ping response whatsoever (seconds)

if_up_check_interval_s=10 # time to wait before re-checking if rx/tx bytes files exist (e.g. from boot state)


# Starlink satellite switch (sss) compensation options
sss_compensation=0 # enable (1) or disable (0) Starlink handling
# satellite switch compensation start times in seconds of each minute
Expand All @@ -126,7 +150,7 @@ case "${dl_if}" in
rx_bytes_path="/sys/class/net/${dl_if}/statistics/tx_bytes"
;;
*)
rx_bytes_path="/sys/class/net/${dl_if}/statistics/rx_bytes"
rx_bytes_path="/sys/class/net/${dl_if}/statistics/tx_bytes"
;;
esac

Expand All @@ -142,7 +166,4 @@ case "${ul_if}" in
;;
esac

if (( $debug )) ; then
echo "DEBUG rx_bytes_path: $rx_bytes_path"
echo "DEBUG tx_bytes_path: $tx_bytes_path"
fi
config_file_check="cake-autorate"
6 changes: 3 additions & 3 deletions cake-autorate-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
# https://www.shellcheck.net/ is your friend

SRC_DIR="https://raw.githubusercontent.com/lynxthecat/CAKE-autorate/main/"
# SRC_DIR="https://raw.githubusercontent.com/richb-hanover/cake-autorate/setup-script/"
DOC_URL="https://github.com/lynxthecat/CAKE-autorate#installation-on-openwrt"

# Retrieve required packages
opkg update
opkg install bash iputils-ping
opkg install bash iputils-ping fping

# Set up CAKE-autorate files
# cd to the /root directory
Expand All @@ -29,7 +28,7 @@ wget -q "$SRC_DIR"cake-autorate.sh

# Check if the configuration script exists, and ask whether to keep it

editmsg=$(printf "\nNow edit the cake-autorate-config.sh file as described in:\n $DOC_URL")
editmsg="\nNow edit the cake-autorate-config.sh file as described in:\n $DOC_URL"

if [ -f cake-autorate-config.sh ]; then
printf "Previous configuration present - keep it? [Y/n] "
Expand All @@ -43,6 +42,7 @@ if [ -f cake-autorate-config.sh ]; then
else
wget -q "$SRC_DIR"cake-autorate-config.sh
fi

# make both .sh files executable
chmod +x *.sh

Expand Down
Loading

0 comments on commit 930cc1e

Please sign in to comment.