lynxthecat / cake-autorate

Eliminate the excess latency and jitter terrorizing your 4G, 5G, LTE, Starlink or other variable rate connection!
https://www.bufferbloat.net
GNU General Public License v2.0
263 stars 24 forks source link

Add remaining Asus Merlin fixes to installer #299

Closed lynxthecat closed 3 months ago

lynxthecat commented 4 months ago

@LiveWire1968 any chance you could test the latest code on this asus-merlin branch and we'll add any necessary remaining fixes?

I think(?) the installation instructions should be something like:

Make sure these are installed: entware; bash; iputils-ping; and fping.

And then run:

wget https://raw.githubusercontent.com/lynxthecat/cake-autorate/asus-merlin/setup.sh
chmod +x ./setup.sh
./setup.sh lynxthecat/cake-autorate asus-merlin

And then edit the config file to specify the correct interfaces:

dl_if=ifb4eth0 # download interface
ul_if=eth0     # upload interface

and bandwidths (change according to your connection specifics):

min_dl_shaper_rate_kbps=5000   # minimum bandwidth for download (Kbit/s)
base_dl_shaper_rate_kbps=60000 # steady state bandwidth for download (Kbit/s)
max_dl_shaper_rate_kbps=100000 # maximum bandwidth for download (Kbit/s)

min_ul_shaper_rate_kbps=20000  # minimum bandwidth for upload (Kbit/s)
base_ul_shaper_rate_kbps=30000 # steady state bandwidth for upload (KBit/s)
max_ul_shaper_rate_kbps=35000  # maximum bandwidth for upload (Kbit/s)[/CODE]

And also enable logging:

output_summary_stats=1    # enable (1) or disable (0) output monitoring lines showing summary stats

And then try running manually:

./cake-autorate.sh

Does it work?

LiveWire1968 commented 4 months ago

@lynxthecat I still need to change the shebang to bash, besides that it seems to work.

lynxthecat commented 4 months ago

@LiveWire1968 does the launcher and suggested lines to post-mount work? I have updated the guidance now to:

"asuswrt")
    printf '%s\n' "Launch script on boot with:"
    printf '%s\n\n' "   echo ${SCRIPT_PREFIX}/launcher.sh >> /jffs/scripts/post-mount"
    ;;

Regarding the shebang, why isn't: #!/bin/sh correct? Does Asus Merlin not include /bin/sh?

rany2 commented 4 months ago

Regarding the shebang, why isn't: #!/bin/sh correct? Does Asus Merlin not include /bin/sh?

It's correct but the busybox version they ship is old and has bugs. You could see one of the bug fixes I made with the set -e; . /etc/os-release; set +e trickery I had to do.

LiveWire1968 commented 4 months ago

@lynxthecat rany said its a bug with busybox sh, I thought i saw he had did a change on it, but i cant find it again. echo /jffs/scripts/launcher.sh >> /jffs/scripts/post-mount needs changed to echo /jffs/scripts/cake-autorate/launcher.sh >> /jffs/scripts/post-mount . and launcher.sh needs chmod +x

LiveWire1968 commented 4 months ago

Regarding the shebang, why isn't: #!/bin/sh correct? Does Asus Merlin not include /bin/sh?

It's correct but the busybox version they ship is old and has bugs. You could see one of the bug fixes I made with the set -e; . /etc/os-release; set +e trickery I had to do.

@rany2 the set -e doesnt seem to work

rany2 commented 4 months ago

@LiveWire1968 it's the opposite, should be set +e; . /etc/os-release; set -e

LiveWire1968 commented 4 months ago

admin@RT-AX86U-D7D0:/tmp/home/root# sh -x setup.sh

Doesnt go farther

rany2 commented 4 months ago

@LiveWire1968 replace the . with source maybe?

LiveWire1968 commented 4 months ago

@LiveWire1968 replace the . with source maybe?

there is no /etc/os-release

rany2 commented 4 months ago

I know but it shouldn't be a fatal error, but I presume that you tried to use source instead and it didn't work either

LiveWire1968 commented 4 months ago

I know but it shouldn't be a fatal error, but I presume that you tried to use source instead and it didn't work either

weird bash works even with the error

rany2 commented 4 months ago

yeah it's another busybox sh bug, i guess it might be worth it to just guard that with a test -a check

rany2 commented 4 months ago

I'm curious does AsusWRT-Merlin ship with another sh? Does /usr/bin/env sh ./setup.sh behave differently?

LiveWire1968 commented 4 months ago

I'm curious does AsusWRT-Merlin ship with another sh? Does /usr/bin/env sh ./setup.sh behave differently?

env sh is still the same busybox, so this doesnt work either, there is no other sh

rany2 commented 4 months ago

yeah it's another busybox sh bug, i guess it might be worth it to just guard that with a test -a check

@lynxthecat just do that then

lynxthecat commented 4 months ago

test -a seems to be bash specific.

Perhaps this would work:

 33         # Check if OS is OpenWRT or derivative
 34         unset ID_LIKE
 35
 36         [ -f "/etc/os-release" ] && . /etc/os-release
rany2 commented 4 months ago

@lynxthecat use -e instead, some OpenWRT versions have os-release with executable bit set

lynxthecat commented 4 months ago

@LiveWire1968 could you test again and verify all is working (including the revised post-mount guidance)?

LiveWire1968 commented 4 months ago

@LiveWire1968 could you test again and verify all is working (including the revised post-mount guidance)?

@lynxthecat this seems to work now, the echo looks correct. Launcher.sh still needs to be excutable.

lynxthecat commented 4 months ago

Hopefully works now (we now set executable bit)?

rany2 commented 4 months ago

For the record the only reason why the previous PR took time is because I wanted to make a proper entware service for cake-autorate NOT this hack in post-mount

lynxthecat commented 4 months ago

For the record the only reason why the previous PR took time is because I wanted to make a proper entware service for cake-autorate NOT this hack in post-mount

I guess this is the Asus Merlin way though:

https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts

rany2 commented 4 months ago

For the record the only reason why the previous PR took time is because I wanted to make a proper entware service for cake-autorate NOT this hack in post-mount

I guess this is the Asus Merlin way though:

https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts

It's not proper though, take a look at https://github.com/RMerl/asuswrt-merlin.ng/blob/master/release/src-rt-5.02axhnd/targets/fs.src/rom/etc/init.d/mount-fs.sh. The issue with our init.d right now is that it's sourcing rc.common, we need to make it work for both or create a different ASUSWRT variant. I can't find another link atm but there is another package that does this properly too..

lynxthecat commented 4 months ago

@RMerl any thoughts on how we are doing things here? It seems that we've got something that pretty much works now in terms of getting cake-autorate to work in Asus Merlin.

By way of a brief introduction, cake-autorate was developed with help from a couple of the cake developers to adjust the bandwidth for cake on the fly based on transfer rate monitoring and latency measurements. It is in a pretty mature state now in that it is very tried and tested on many different connections (data, plots and detailed discussion can be seen on the OpenWrt forum threads - see e.g. here) and it generally just works.

For a quick visual demonstration, see the graphics on this page here:

https://github.com/lynxthecat/cake-autorate/blob/master/ANALYSIS.md

rany2 commented 4 months ago

IMO the URL you linked to is meant for trivial one-liner scripts, not cake-autorate :)

LiveWire1968 commented 4 months ago

IMO the URL you linked to is meant for trivial one-liner scripts, not cake-autorate :) @rany there are some fairly complicated asus-merlin script packages, they all get started out of one of the startup scripts in /jffs/scripts never init.d

rany2 commented 4 months ago

there are some fairly complicated asus-merlin script packages, they all get started out of one of the startup scripts in /jffs/scripts never init.d

how would you restart them/handle failure? you need some kind of process monitor at a minimum, it seems shortsighted/too simple to just fork from that file and call it a day but I guess given that this is the norm at AsusWRT-Merlin you could just do this too...

RMerl commented 4 months ago

Why not use qos-start? That script gets called whenever QoS is initialized. That means you will be able to have it only configure things if QoS is starting with Cake actually enabled as the scheduler.

lynxthecat commented 4 months ago

Could you elaborate? What does qos-start look like these days?

RMerl commented 4 months ago

Could you elaborate? What does qos-start look like these days?

It doesn't look like anything. It's a script that a user can create to launch tasks whenever QoS gets initialized.

https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#qos-start

rany2 commented 4 months ago

@lynxthecat it's the same exact thing but the conditions are different, instead of running on post-mount it runs at qos-start :)

lynxthecat commented 4 months ago

I was thinking of:

https://www.snbforums.com/threads/cake-test-cake-experiments-for-386-2-beta.71271/#post-674445

But if I'm understanding correctly, then we can give this guidance:

"asuswrt")
    printf '%s\n' "Launch script on boot with:"
    printf '%s\n\n' "   echo ${SCRIPT_PREFIX}/launcher.sh >> /jffs/scripts/qos-start"
    ;;
rany2 commented 4 months ago

@RMerl Personally, I would have preferred a regular service file as I want cake-autorate to be monitored and for cake-autorate to be restartable for when it's updated, etc. It's a bit strange that this is just not encouraged in AsusWRT-Merlin but I guess it's a simplicity vs robustness trade-off. Just forking will always be more straightforward !

lynxthecat commented 4 months ago

I agree with you @rany2, but perhaps this is OK for now and can be revisited later.

@LiveWire1968 / @RMerl have we missed anything else? Hopefully this is good now?

LiveWire1968 commented 4 months ago

Could you elaborate? What does qos-start look like these days?

It doesn't look like anything. It's a script that a user can create to launch tasks whenever QoS gets initialized.

https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#qos-start

It needs entware, why i recommended post-mount

RMerl commented 4 months ago

@RMerl Personally, I would have preferred a regular service file as I want cake-autorate to be monitored and for cake-autorate to be restartable for when it's updated, etc. It's a bit strange that this is just not encouraged in AsusWRT-Merlin but I guess it's a simplicity vs robustness trade-off. Just forking will always be more straightforward !

Asuswrt is simply not designed around a SysV init system, the entire operating system is monolithic. Having hooks like these scripts is the only way to interface with it.

rany2 commented 4 months ago

@RMerl Personally, I would have preferred a regular service file as I want cake-autorate to be monitored and for cake-autorate to be restartable for when it's updated, etc. It's a bit strange that this is just not encouraged in AsusWRT-Merlin but I guess it's a simplicity vs robustness trade-off. Just forking will always be more straightforward !

Asuswrt is simply not designed around a SysV init system, the entire operating system is monolithic. Having hooks like these scripts is the only way to interface with it.

Oh, I thought that I could adapt my init script to not call rc.common as a workaround to have it work on Asuswrt. I didn't know that this was just not possible. It's a shame.

lynxthecat commented 4 months ago

@LiveWire1968 do the installation instructions for Asus Merlin look OK to you?

LiveWire1968 commented 3 months ago

@lynxthecat I was testing this again this morning. I cannot get the latest cake-autorate.sh or launcher.sh to start from qos-start or post-mount, cant get any log of it when booting the router.

What is working

echo /jffs/scripts/cake-autorate/launcher.sh >/opt/etc/init.d/S99cake-autorate chmod +x /opt/etc/init.d/S99cake-autorate

Then everything starts up fine....

lynxthecat commented 3 months ago

Permissions issue? Could you maybe come on #asuswrt?

rany2 commented 3 months ago

@lynxthecat most likely, read https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#creating-scripts

lynxthecat commented 3 months ago

So just need to add suggestion to chmod +x at:

https://github.com/lynxthecat/cake-autorate/blob/a45dbf3e4a80be8a311ae325d2acb39596c91055/setup.sh#L237

@LiveWire1968 would simple chmod +x there fix it?

rany2 commented 3 months ago

@lynxthecat they specifically suggest chmod a+rx most likely because of a default restrictive umask, so he should try that not chmod +x

LiveWire1968 commented 3 months ago

So just need to add suggestion to chmod +x at:

https://github.com/lynxthecat/cake-autorate/blob/a45dbf3e4a80be8a311ae325d2acb39596c91055/setup.sh#L237

@LiveWire1968 would simple chmod +x there fix it?

no, i had it set excutable, i put a test in qos-start, its working fine

LiveWire1968 commented 3 months ago

and fyi, its not working from post-mount either, which is where entware and other scripts startup.. Id guess another environment problem, but i havent figured it out

lynxthecat commented 3 months ago

Did you try the chmod a+rx?

lynxthecat commented 3 months ago

Could you also try adding inside qos-start or post-mount the line:

env > /tmp/env_output.txt 

And paste the output from that?

For a certain OpenWrt startup script I needed:

export PATH=/usr/sbin:/usr/bin:/sbin:/bin
LiveWire1968 commented 3 months ago

admin@RT-AX86U-D7D0:/tmp# cat env_output.txt router=100.64.0.1 subnet=255.192.0.0 USER=root staticroutes=192.168.100.1/32 0.0.0.0 34.120.255.244/32 0.0.0.0 0.0.0.0/0 100.64.0.1 SHLVL=1 LD_LIBRARY_PATH=/lib:/usr/lib:/lib/aarch64 HOME=/ ENV=/etc/profile interface=eth0 dns=1.1.1.1 8.8.8.8 siaddr=10.10.10.10 serverid=100.64.0.1 TERM=vt100 mtu=1500 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/sbin:/opt/bin ip=100.74.88.2 lease=300 mask=10 SHELL=/bin/sh PWD=/tmp/bwdpi opt53=05 TZ=GMT5 TMOUT=0

lynxthecat commented 3 months ago

And you definitely tried chmod a+rx?

Any other thoughts @rany2?

lynxthecat commented 3 months ago

@RMerl I wonder whether you can advise here?