Help me update my HFSC shaper scripts for fw4/nftables

you dont need veth with the r6s.

#!/bin/sh

##############################
# General settings
##############################

# "atm" for old-school DSL, "DOCSIS" for cable modem, or "other" for anything else
LINKTYPE="ethernet" 
WAN=pppoe-wan # Change this to your WAN device name
LAN=br-lan # Change to your LAN device if you don't use veth/bridge, leave it alone if you use veth
DOWNRATE=800000 # Change this to about 80% of your download speed (in kbps)
UPRATE=100000 # Change this to your kbps upload speed
OH=44 # Number of bytes of Overhead on your line


##############################
# Veth-specific settings (only adjust if using the Veth setup)
##############################

USEVETHDOWN=no # Set to "yes" to use Veth for downstream traffic shaping
LANBR=br-lan # LAN bridge interface name, only relevant if USEVETHDOWN is set to "yes"

These are my current settings, ive increased my download, yet still keeping bufferbloat under control. USEVETHDOWN=no

So I can use the script even tho I occupy both ports on the 6s? Also can you tell me why you changed to use ethernet kmod 8125 and not 8169?

Kmod 8125

Based on the above , Immortal Firmware uses 8125 by default, ive found i was having issues using 8169, So ive stuck with 8125 for now.

Also, not sure if you do try https://forum.openwrt.org/t/nanopi-r6s-with-openwrt/167611/91
these will improve the performace on the R6S IMHO, on Immortal Firmware use

#IMMORTAL BUILD
	
friendlyarm,nanopi-r6s)
	set_interface_core 1 "eth0"
	echo 2 > /sys/class/net/eth0/queues/rx-0/rps_cpus
	echo 2 > /sys/class/net/eth0/queues/tx-0/xps_cpus
	set_interface_core 4 "eth1-0"
	set_interface_core 4 "eth1-1"
	set_interface_core 4 "eth1-2"
	set_interface_core 4 "eth1-3"
	set_interface_core 4 "eth1-16"
	set_interface_core 4 "eth1-18"
	echo f0 > /sys/class/net/eth1/queues/rx-0/rps_cpus #10
	echo f0 > /sys/class/net/eth1/queues/tx-0/xps_cpus #20
	set_interface_core 8 "eth2-0"
	set_interface_core 8 "eth2-16"
	set_interface_core 8 "eth2-18"
	echo f0 > /sys/class/net/eth2/queues/rx-0/rps_cpus #40
	echo f0 > /sys/class/net/eth2/queues/tx-0/xps_cpus #80	
	;;

I noticed the net core default qdisc is fq codel. Do you know what file this setting is stored in to change to cake for immortalwrt? And yes I did try it but for some reason my max ping spikes and jitter still spike. I guess it’s cause I’m in an area where the node is over loaded with many users. The only internet service in my neighborhood is cable Xfinity :confused:

The new update you did to the script does work very well. Sadly when I do bufferbloat tests my scores are bad

Should be under /etc/sysctl.conf

# cake default qdisc
net.core.default_qdisc=cake

Thanks!

Could you provide a bit more information?

  1. Could you show the results of a bufferbloat test?
  2. What type of connection are you using?
  3. What is your bandwidth without SQM/QoS enabled? What bandwidth are you actually receiving from your ISP?
  4. What settings have you configured in the script?

So I receive about 943mb down and 250 up from my isp. I have been battling consistent ping and jitter spikes for ages. For first 2 tests my unloaded ping stays 12-13 then maxes to 23-25 for like another 5-10 tests with my max ping reaching 50-100ms on download. My upload is fine since I have Xfinity and they have enabled docsis pie on upstream on the modem. For downstream they have it enabled at the cmts. What I did notice just now is that if I use no queues on my Ethernet interfaces using tc qdisc I get better hit reg but still suffer from real time delay. I’m assuming my node is overfilled with users causing this phenomenon. Sadly I do not have the option for fiber as my HOA is under a bulk agreement with comcrap Xfinity. I still would love to hear some insight on potential improvements that I can do. IF there is any…

And oh yeah my actual plan speed is 2 gig down 250 up if that helps. My gaming rig is connected to the r6s on a 1 gig port where my AP is connected to the 2.5G port as well as my wan being a 2.5G port.

Can you show us how you setup the script?

Are you running the tests on your gaming rig? trying plugging it into the LAN 2.5g. Just to rule it out. (ignore the 1gig LAN)

I use the WAN and LAN 2.5g on my R6S, have a switch plugged into LAN and my AP from there with some Wired clients.

Well I had ended up doing a reset to default so I will have to run the script again and configure so I def will show when I’m back in town as I will be gone for about 2 days. But this issue while running the script and the issue is without it too but just running the usually SQM cake set up from the GUI

Yeah I did run a similar set up a while ago. My AP is the GT-AX11000 PRO from asus and it has a built in switch so for a while I was running my pc off of there but I still had similar results. I guess I might just need to get a dedicated switch.

This script doesn't prioritize browser traffic nearly as much as it prioritizes game traffic. So bufferbloat tests just don't show you what your game traffic is doing. They intentionally will be worse than gaming traffic. The script will see all that browser saturating speed test traffic as stuff it can happily delay in order to deliver game traffic, but that of course makes the bufferbloat test show bad results.

While running a speed test you can try a command line low volume UDP iperf test or similar and it will show you what gaming traffic does.

Hi I'm not a gamer but I share my internet with 2 other apartments. I can only use WiFi in my apt. there is no chance of using cat cable to join to the ISP router, I have done the math and decided that I set this up for 80000kb down and 12000kb up everything works fine now no one can complain that I am using all the bandwidth and the conversation/argument should end there.

I just use the internet for browsing news sites and youtube is probably the only thing that I do a few times a day that will use the most bandwidth.

At fist I set the script SimpleHFSCgamerscript.sh to use the default setting of pfifo and it worked good as far as I can tell, I just changed that to fq_codel and really don't notice any difference.

I guess what I'm trying to ask in my long winded post is whats the best settings for my situation.

Here is my current settings in SimpleHFSCgamerscript.sh.

# "atm" for old-school DSL, "DOCSIS" for cable modem, or "other" for anything else
LINKTYPE="other"
# LINKTYPE="ethernet"
WAN=phy1-sta0 # Change this to your WAN device name
LAN=br-lan # Change to your LAN device if you don't use veth/bridge, leave it alone if you use veth
DOWNRATE=65000 # Change this to about 80% of your download speed (in kbps)
UPRATE=10000 # Change this to your kbps upload speed
OH=44 # Number of bytes of Overhead on your line

USEVETHDOWN=yes # Set to "yes" to use Veth for downstream traffic shaping
LANBR=br-lan # LAN bridge interface name, only relevant if USEVETHDOWN is set to "yes"

BWMAXRATIO=20 ## prevent ack floods by limiting download to at most
              ## upload times this amount... ratio somewhere between
              ## 10 and 20 probably optimal. we down-prioritize
              ## certain ACKs to reduce the chance of a flood as well.

if [ $((DOWNRATE > UPRATE*BWMAXRATIO)) -eq 1 ]; then
    echo "We limit the downrate to at most $BWMAXRATIO times the upstream rate to ensure no upstream ACK floods occur which can cause game packet drops"
    DOWNRATE=$((BWMAXRATIO*UPRATE))
fi

GAMEUP=$((UPRATE*15/100+400))
GAMEDOWN=$((DOWNRATE*15/100+400))

## you can try setting GAMEUP and GAMEDOWN manually, some report this works well for CoD
#GAMEUP=400
#GAMEDOWN=800


gameqdisc="fq_codel"

PFIFOMIN=5 ## Minimum number of packets in pfifo
PACKETSIZE=350 # Bytes per game packet avg
MAXDEL=25 # Ms we try to keep max delay below for game packets after burst

netemdelayms="1"
netemjitterms="7"
netemdist="normal"

pktlossp="none" # set to "none" for no packet loss, or use a fraction
                # like 0.015 for 1.5% packet loss in the realtime UDP
                # streams
if [ $gameqdisc != "fq_codel" -a $gameqdisc != "red" -a $gameqdisc != "pfifo" -a $gameqdisc != "netem" ]; then
    echo "Other qdiscs are not tested and do not work on OpenWrt yet anyway, reverting to red"
    gameqdisc="red"
fi

UDPBULKPORT="21822"
TCPBULKPORT="21822,6881-6889"
VIDCONFPORTS="10000,3478-3479,8801-8802,19302-19309,5938,53"
REALTIME4="192.168.1.12" # example, just add all your game console here
LOWPRIOLAN4="192.168.1.11" # example, add your low priority lan machines here

ACKRATE="$(($UPRATE * 5 / 100))" # auto moode - or set manual
#ACKRATE="300"  ## 300-600 ist a good starting point - or leave blank to disable

FIRST500MS=$((DOWNRATE * 500 / 8)) # downrate * 500/8
FIRST10S=$((DOWNRATE * 10000 / 8)) # downrate * 10000/8

WASHDSCPUP="yes"
WASHDSCPDOWN="yes"

Thank you for reading this
EDIT: In case it matters ny my router is a TP-Link TL-WDR4300 v1

In your case there is no real gaming traffic, which is expected to be UDP on a precise clock tick. You're talking about regular browsing and streaming type traffic. So it doesn't matter the game qdisc since no traffic should be going to the game qdisc.

SimpleHFSCGamerscript will set up a series of buckets for various browsing type traffic and will share this traffic through fq_codel, so it should give you very good "bandwidth sharing" for an apartment or shared dorm etc out of the box.

1 Like

Oh I see. The script works well but I still experience horrible gameplay. I just believe it’s because I am under a CGNAT and that is resulting into slower response times in my network.

I've made several changes to the script that should further simplify the setup and logic of the script and pushed them to my github repo.

In addition to fixing a few bugs, I've implemented a new method for shaping inbound traffic (ingress) without the need for a virtual Ethernet (veth) interface, and it works even when there are multiple ports/bridges/including Wi-Fi on the LAN side,. This new method uses tc-ctinfo.
Simply put, DSCP markings are saved in conntrack during upload (egress) and then restored during download (ingress). This new way of shaping download traffic could potentially make the veth method and the method where traffic control is applied directly on the LAN interface obsolete. However, the function that allows me to easily store the DSCPs in conntrack:

ct mark set ip dscp or 128 counter

only works from nftables version 1.0.8 onwards, and since I don't know if every user has this version yet, there are now three options for shaping download traffic:

DOWNSHAPING_METHOD="ctinfo" # Options: "veth", "ctinfo", "lan"

The init script should ideally check whether kmod-sched-ctinfo is installed at startup. To determine whether your version of nftables is compatible, you can execute the following command: nft --version

Ctinfo should even work if DSCPs are being washed during upload or download. At least it did when I tested it...

Special thanks to @Lynx. cake-qos-simple was a big help.

2 Likes

@Hudra I really appreciate your effort on making updates on these scripts and simply making it easier for those who can’t adjust to their situations. Please keep these updates coming as I’ve been testing more and more with each update and my gaming experience seems to become more easier and enjoyable! Just want you to know that your effort has not gone unnoticed. Thank you for your commitment on this script. But also a big thanks to @dlakelan for creating this script for those who want to prioritize certain traffic and devices. Without him it wouldn’t even be possible. Thank you guys.

3 Likes

Great Work @Hudra.

Could we ammend

"DOCSIS")
tc qdisc replace dev $DEV stab overhead **${OH}** linklayer ethernet handle 1: root hfsc default 13
;;
*)
tc qdisc replace dev $DEV stab overhead **${OH**} linklayer ethernet handle 1: root hfsc default 13
;;

esac`

so that when we change - OH=44 # Number of bytes of Overhead on your line

its aligned?

Thanks

@Hudra im getting

Cannot find device "ifb-pppoe-wan"

when i run the script from ssh, any ideas?