CAKE QoS Script (OpenWrt)

each ip? or as

i'm not sure but i think you make go to overview and seeing your adress ipv4

then ipv4 adress exemple in script 192.168.1.10 you put 192.168.1.10

@elan can confirm ?

torrent box static ipv4

Capture d’écran 2022-01-23 à 03.06.35

1 Like

how can I restart the script because I see that I have traffic in the best effort class and I didn't put anything in that class

So BestEffort really is the internet's default and also what most applications and operating systems will use unless configured to do differently. So unless you have filtering rules that cover ALL packets and that map into different priority tiers you have to expect traffic in the best effort tin.

Prioritization is not a silver bullet, it is a tool that can help increasing responsiveness of some flows at the expense of other flows, sometimes that is sufficiently helpful to justify its use, but it will not fix each and every unrelated network issue.... Using prioritization is unfortunately not as simple as one would expect.

1 Like

I was playing CoD and using wireshark at the same time to see if the game class marked the ports with CS7, but apparently not, am I wrong?


CS6 and CS7 work the same in Cake. CS7 can bork some things in some switches or on ISPs that use that for urgent traffic only, so it's maybe a less good choice.

1 Like

I tried with CS4 the same

Quick questions:
a) Which interface was the packetcapture taken from?
b) What does the output of tc -s qdisc look like?
c) Not sure whether I consider citing from the revelation as helpful script output.

1 Like

interface : br-lan

root@OpenWrt:~# tc -s qdisc
qdisc noqueue 0: dev lo root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc cake 8016: dev eth0 root refcnt 6 bandwidth 23Mbit diffserv4 dual-srchost                                                                                                                                                              nat wash no-ack-filter split-gso rtt 40ms noatm overhead 18 mpu 64
 Sent 48662164 bytes 67359 pkt (dropped 54, overlimits 84524 requeues 0)
 backlog 0b 0p requeues 0
 memory used: 298496b of 4Mb
 capacity estimate: 23Mbit
 min/max network layer size:           28 /    1500
 min/max overhead-adjusted size:       64 /    1518
 average network hdr offset:           14

                   Bulk  Best Effort        Video        Voice
  thresh       1437Kbit       23Mbit    11500Kbit     5750Kbit
  target         12.6ms          2ms          2ms       3.16ms
  interval       50.6ms         40ms         40ms       41.2ms
  pk_delay        291us         16us        476us       1.15ms
  av_delay         20us          3us        107us         83us
  sp_delay          2us          2us          2us          3us
  backlog            0b           0b           0b           0b
  pkts              118         8610        58311          374
  bytes           13689       473749     48159215        93252
  way_inds            0            0         4458            0
  way_miss           31            5          208           54
  way_cols            0            0            0            0
  drops               0            0           54            0
  marks               0            0            0            0
  ack_drop            0            0            0            0
  sp_flows            0            0            0            1
  bk_flows            0            0            1            0
  un_flows            0            0            0            0
  max_len          1248          254        17736         1617
  quantum           300          701          350          300

qdisc fq_codel 0: dev eth1 root refcnt 2 limit 10240p flows 1024 quantum 1514 ta                                                                                                                                                             rget 5ms interval 100ms memory_limit 4Mb ecn drop_batch 64
 Sent 464560031 bytes 314908 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 3028 drop_overlimit 0 new_flow_count 7 ecn_mark 0
  new_flows_len 0 old_flows_len 0
qdisc fq_codel 0: dev eth2 root refcnt 2 limit 10240p flows 1024 quantum 1514 ta                                                                                                                                                             rget 5ms interval 100ms memory_limit 4Mb ecn drop_batch 64
 Sent 218877755 bytes 199540 pkt (dropped 0, overlimits 0 requeues 6)
 backlog 0b 0p requeues 6
  maxpacket 1478 drop_overlimit 0 new_flow_count 521 ecn_mark 0
  new_flows_len 0 old_flows_len 0
qdisc noqueue 0: dev lanbrport root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc cake 8015: dev lanveth root refcnt 2 bandwidth 103Mbit diffserv4 dual-dsth                                                                                                                                                             ost nonat nowash no-ack-filter split-gso rtt 40ms noatm overhead 18 mpu 64
 Sent 98309751 bytes 84787 pkt (dropped 26, overlimits 119496 requeues 0)
 backlog 0b 0p requeues 0
 memory used: 950176b of 4Mb
 capacity estimate: 103Mbit
 min/max network layer size:           28 /    1500
 min/max overhead-adjusted size:       64 /    1518
 average network hdr offset:           14

                   Bulk  Best Effort        Video        Voice
  thresh       6437Kbit      103Mbit    51500Kbit    25750Kbit
  target         2.82ms          2ms          2ms          2ms
  interval       40.8ms         40ms         40ms         40ms
  pk_delay         72us        5.5ms       1.41ms        225us
  av_delay          2us       2.16ms         90us         20us
  sp_delay          2us        278us          2us          1us
  backlog            0b           0b           0b           0b
  pkts               99        17026        67390          298
  bytes           18110     25156183     73077646        96384
  way_inds            0            0           11            0
  way_miss           17            3          166           21
  way_cols            0            0            0            0
  drops               0            2           24            0
  marks               0            0            0            0
  ack_drop            0            0            0            0
  sp_flows            1            2            1            1
  bk_flows            0            0            1            0
  un_flows            0            0            0            0
  max_len          1484         8868        19214         1621
  quantum           300         1514         1514          785

qdisc noqueue 0: dev br-lan root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0

OK, thanks, so at least the ingress marking will have been applied, not sure about egress marking at that stage.

BUT your packets clearly are DSCP marked, only AF31 instead of CS7, could you post the full set of marking rules again, please, maybe there is a higher priority rule for these packets and/or your CS7 rule is specified as "+CS7" which will only change packets that are BE/CS0.

1 Like

The tc results show that there are packets in all 4 tins, although most packets are in the video tin, which will work if the link is rarely saturated, but if under saturation most/all traffic is in the video tin, prioritization is not going to help anything. The number of drops and marks however indicates that you are not saturating the link that much/often.

1 Like

hello moller I would like to add a prioritization for the twitch packages apparently in cs3 would be ideal but I saw that it used the rtmp protocol how to do it and is it a good idea to put it in cs3 because currently I see all the packages marked in cs4 for tcp rtmp 1935, thanks

ipt46dscp -p tcp -m multiport --sports 1935 -j DSCP --set-dscp-class CS3 -m comment --comment "Live Streaming to $BROADCAST_VIDEO (TCPsrcTWITCH) - List 1"

ipt46dscp -p tcp -m multiport --dports 50000:65535 -j DSCP --set-dscp-class CS3 -m comment --comment "Live Streaming TWITCH (TCPdstTWITCH) - List 1"

ipt46dscp -p tcp -m multiport --sports 50000:65535 -j DSCP --set-dscp-class CS3 -m comment --comment "Livestreaming to TWITCH (TCPsrcTWITCH2) - List 2"

ipt46dscp -p tcp -m multiport --dports 1935 -j DSCP --set-dscp-class CS3 -m comment --comment "LiveStreaming to TWITCH (TCPdstTWITCH2) - List 2"

my game is very very good with the script but i tstream on twitch live

i have sensation at the slow conextion

or i have think like this

if [ "$BROADCAST_VIDEO" != "CS3" ] ; then
  ipt46dscp -p tcp -m multiport --sports 1935 -j DSCP --set-dscp-class $BROADCAST_VIDEO -m comment --comment "Live Streaming to $BROADCAST_VIDEO (TCPsrcTWITCH) - List 1"
fi
if [ "$BROADCAST_VIDEO" != "CS3" ] ; then
 ipt46dscp -p tcp -m multiport --dports 50000:65535 -j DSCP --set-dscp-class $BROADCAST_VIDEO -m comment --comment "PC Game Ports to $BROADCAST_VIDEO (TCPdstTWITCH) - List 1"
fi

PC Game Ports (List 2) - Used by PC games.
if [ "$BROADCAST_VIDEO" != "CS3" ] ; then
   ipt46dscp -p tcp -m multiport --sports 50000:65535 -j DSCP --set-dscp-class $BROADCAST_VIDEO -m comment --comment "PC Game Ports to $BROADCAST_VIDEO (TCPsrcTWITCH2) - List 2"
fi
if [ "$BROADCAST_VIDEO" != "CS3" ] ; then
   ipt46dscp -p tcp --dports 1935 -j DSCP --set-dscp-class $BROADCAST_VIDEO -m comment --comment "PC Game Ports to $BROADCAST_VIDEO (TCPdstTWITCH2) - List 2"
fi

So if I understand this correctly you are DSCP marking simply based on ports? If yes, why are you not just using qosify, which seems to offer a simpler configuration interface for purely port based DSCP re-marking?

But no matter which way you use, you should talk to users that actually use the same method, I do not do any router-based DSCP-remapping presently and hence can not offer first hand experience.

2 Likes
#!/bin/sh
############################################################


### Interfaces ###

## Go to: "Network -> Interfaces" and write the name of those interfaces here.

## Change this to the name of your "LAN interface", if you have altered it from the OpenWrt default.
LAN="br-lan"


## Change this to the name of your "WAN interface".
WAN="eth0"


############################################################


### Download methods ###

DOWN_METHOD="veth"  # Write: "veth" | "normal"
                    # "veth"   The 'DSCP marks' work on download and upload in "Cake".
                    # "normal" The 'DSCP marks' only work on upload in "Cake".


######################################################################################################################


### CAKE settings ###

DOWNRATE="95000"  # Change this to about 80-95% of your download speed (in kbit).
UPRATE="23000"     # Change this to about 80-95% of your upload speed (in kbit).
                   # Do a Speed Test: https://www.speedtest.net/
                   # Not recommendable: Don't write anything in "DOWNRATE" or "UPRATE" to use 'qdisc shaper' with no limit on the bandwidth ('unlimited' parameter).
                   # Not recommendable: Write "0" in "DOWNRATE" or "UPRATE" to disable 'qdisc shaper' on download or upload.

AUTORATE_INGRESS="no"  # Write: "yes" | "no"
                       # Enable CAKE automatic rate estimation for ingress.
                       # For it to work you need to write your bandwidth in "DOWNRATE" to specify an initial estimate.
                       # This is most likely to be useful with cellular links, which tend to change quality randomly.

## Make sure you set these parameters correctly for your connection type or don't write any value and use a presets or keywords below.
OVERHEAD="18"  # Write values between "-64" and "256"
MPU="64"       # Write values between "0" and "256"
FRAMING="noatm"   # Write: "ptm" | "atm" | "noatm"
             # These values overwrite the presets or keyboards below.
             # Read: https://openwrt.org/docs/guide-user/network/traffic-shaping/sqm#configuring_the_sqm_bufferbloat_packages
             # Read: https://openwrt.org/docs/guide-user/network/traffic-shaping/sqm-details#sqmlink_layer_adaptation_tab

## Only use these presets or keywords if you don't write a value above in OVERHEAD, MPU and FRAMING.
COMMON_LINK_PRESETS="docsis"  # Write the keyword below:
                                    # "conservative"     Failsafe     (overhead 48 - atm)
                                    # "ethernet"         Ethernet     (overhead 38 - mpu 84 - noatm)
                                    # "docsis"           Cable Modem  (overhead 18 - mpu 64 - noatm)
                                    # "pppoe-ptm"        VDSL2        (overhead 30 - ptm)
                                    # "bridged-ptm"      VDSL2        (overhead 22 - ptm)
                                    # "pppoa-vcmux"      ADSL         (overhead 10 - atm)
                                    # "pppoa-llc"        ADSL         (overhead 14 - atm)
                                    # "pppoe-vcmux"      ADSL         (overhead 32 - atm)
                                    # "pppoe-llcsnap"    ADSL         (overhead 40 - atm)
                                    # "bridged-vcmux"    ADSL         (overhead 24 - atm)
                                    # "bridged-llcsnap"  ADSL         (overhead 32 - atm)
                                    # "ipoa-vcmux"       ADSL         (overhead 8  - atm)
                                    # "ipoa-llcsnap"     ADSL         (overhead 16 - atm)
                                    # If you are unsure, then write "conservative" as a general safe value.
                                    # These keywords have been provided to represent a number of common link technologies.
                                    ######################################################################################
                                    # For true ATM links (ADSL), one often can measure the real per-packet overhead empirically,
                                    # see: https://github.com/moeller0/ATM_overhead_detector for further information how to do that.

## This keyword is not for standalone use, but act as a modifier to some previous presets or keywords.
ETHER_VLAN_KEYWORD=""  # Write values between "1" and "3" or don't write any value.
                       # In addition to those previous presets or keywords it is common to have VLAN tags (4 extra bytes) or PPPoE encapsulation (8 extra bytes).
                       # "1" Adds '4 bytes' to the overhead  (ether-vlan)
                       # "2" Adds '8 bytes' to the overhead  (ether-vlan ether-vlan)
                       # "3" Adds '12 bytes' to the overhead (ether-vlan ether-vlan ether-vlan)
                       # This keyword "ether-vlan" may be repeated as necessary in 'EXTRA PARAMETERS'.
                       # Read: https://man7.org/linux/man-pages/man8/tc-cake.8.html#OVERHEAD_COMPENSATION_PARAMETERS

DOWN_PRIORITY_QUEUE="diffserv4"  # Write: "besteffort" | "diffserv3" | "diffserv4" | "diffserv8"
UP_PRIORITY_QUEUE="diffserv4"    # Write: "besteffort" | "diffserv3" | "diffserv4" | "diffserv8"
                                 # CAKE can divide traffic into tins based on the Diffserv field.
                                 # "besteffort" only has 'one tin' or priority tier.
                                 # "diffserv3" has '3 tins' or different priority tiers.
                                 # "diffserv4" has '4 tins' or different priority tiers. <- Recommended
                                 # "diffserv8" has '8 tins' or different priority tiers.

PER_HOST_ISOLATION="yes"  # Write: "yes" | "no"
                          # Per-Host Isolation or 'dual-dsthost' (download) and 'dual-srchost' (upload), prevents a single host/client
                          # that has multiple connections (like when torrenting) from hogging all the bandwidth
                          # and provides better traffic management when multiple hosts/clients are using the internet at the same time.

DOWN_NAT="no"  # Write: "yes" | "no"
UP_NAT="no"   # Write: "yes" | "no"
               # Perform a NAT lookup before applying flow-isolation rules to improve fairness between hosts "inside" the NAT.
               # Don't use "nat" parameter in download when use 'Veth method' or flow-isolation stops working.
               # Only use "nat" parameter in download when use 'Normal method'.
               ## Recommendation: Don't use "nat" in download on the "Veth interfaces" and only use "nat" in download and upload on the "WAN interface".

DOWN_WASH="no"  # Write: "yes" | "no"
UP_WASH="yes"   # Write: "yes" | "no"
                # "wash" only clears all DSCP marks after the traffic has been tinned.
                # Don't wash incoming (download) DSCP marks, because also wash the custom DSCP marking from this script and the script already washes the marks below.
                # Wash outgoing (upload) DSCP marks to ISP, because may be mis-marked from ISP perspective.
                ## Recommendation: Don't use "wash" on ingress (download) so that "WMM" can make use of the custom DSCP marking and just use "wash" on egress (upload).

INGRESS_MODE="yes"  # Write: "yes" | "no"
                    # Enabling "ingress mode" ('ingress' parameter) will tune the AQM to always keep at least two packets queued *for each flow*.
                    # Basically will drop and/or delay packets in a way that the rate of packets leaving the shaper is smaller or equal to the configured shaper-rate.
                    # This leads to slightly more aggressive dropping, but this also ameliorates one issue we have with post-bottleneck shaping,
                    # namely the inherent dependency of the required bandwidth "sacrifice" with the expected number of concurrent bulk flows.
                    # Thus, being more lenient and keeping a minimum number of packets queued will improve throughput in cases
                    # where the number of active flows are so large that they saturate the bottleneck even at their minimum window size.

UP_ACK_FILTER="yes"  # Write: "yes" | "no" | "auto"
                      # Write "auto" or don't write anything, so that the script decide to use this parameter, depending on the bandwidth you wrote in "DOWNRATE" and "UPRATE".
                      # If your up/down bandwidth is at least 1x15 asymmetric, you can try the 'ack-filter' option.
                      # It doesn't help on your downlink, nor on symmetric links.
                      # 'ack-filter' only makes sense for egress (upload), so don't add 'ack-filter' keyword for the ingress side (download).
                      # Don't recommend turning it on more symmetrical link bandwidths the effect is negligible at best.

## Don't write 'ms', just write the number.
RTT=""  # Write values between "1" and "1000" or don't write any value to use the default value (100).
        # This parameter defines the time window that your shaper will give the endpoints to react to shaping signals (drops or ECN).
        # The default "100ms" is pretty decent that works for many people, assuming their packets don't always need to cross long distances.
        # If you are based in Europe and access data in California I would assume 200-300ms to be a better value.
        # The general trade off is higher RTTs cause higher bandwidth utilization at the cost of increased latency under load (or rather longer settling times).
        # If your game servers are "40ms" RTT away, you should configure cake accordingly (this will lead to some bandwidth sacrifices for flows with a longer RTT).
        # Again setting RTT too high will increase the latency under load (aka the Bufferbloat) while increasing bandwidth utilization.
        # You should measure the RTT for cake while your network is not loaded.
        # Use ping to measure the Round Trip Time (RTT) on servers you normally connect.
        # Example: ping -c 20 openwrt.org (Linux)
        # Example: ping -n 20 openwrt.org (Windows)

DOWN_EXTRA_PARAMETERS=""  # Add any custom parameters separated by spaces.
UP_EXTRA_PARAMETERS=""    # Add any custom parameters separated by spaces.
                          # These will be appended to the end of the CAKE options and take priority over the options above.
                          # There is no validation done on these options. Use carefully!
                          # Look: https://man7.org/linux/man-pages/man8/tc-cake.8.html


######################################################################################################################


### DSCP marks ###

## Before changing the DSCP marks, first look at the images of the post and read this:
## Information: https://datatracker.ietf.org/doc/html/rfc8325


## Wash all DSCP marks and now this is the default DSCP for all unmarked traffic.
STANDARD_DEFAULT="CS0"


## Network services
SSH="CS2"
NTP="CS2"
DNS="CS2"
ICMP="CS0"
DOT="AF41"  # DNS over TLS (DoT)


## Prioritize traffic
TELEPHONY="EF"                  # VoIP and VoWiFi (WiFi Calling).
MULTIMEDIA_CONFERENCING="AF41"  # Zoom, Microsoft Teams, Skype, GoToMeeting, Webex Meeting, Jitsi Meet, Google Meet, FaceTime and TeamViewer.
REAL_TIME_GAMING="CS4"          # PC Game Ports and Game Consoles (Need to be added below).
MULTIMEDIA_STREAMING="AF32"     # Browsing and Multimedia Streaming to Watch YouTube, Netflix, Twitch and QUIC Protocol (TCP/UDP ports 80, 443 and 8080).
BROADCAST_VIDEO="CS3"           # Live Streaming to YouTube Live, Twitch, Vimeo and LinkedIn Live.
HIGH_THROUGHPUT_DATA="AF11"     # Web Traffic (TCP ports 80, 443 and 8080).
LOW_PRIORITY_DATA="CS1"         # Bulk traffic such as BitTorrent, Usenet or TCP downloads that have transferred more than 10 seconds worth of packets.

                                ## The DSCP marks "LE" and "VA" (aka. "VOICE-ADMIT") don't work.
                                ## You can test changing the DSCP mark "CS4" to "EF" in the game category.


############################################################


### DSCP ports settings ###

## You can delete the ports below, because are just examples.


## PC Game Ports (List 1)
TCP_GAME_PORTS_LIST_1="3074"
UDP_GAME_PORTS_LIST_1="3074,30000:45000"
                       # Define a list of TCP and UDP ports used by PC Games.
                       # Use a comma to separate the values or ranges A:B as shown.
                       # Up to 15 ports can be specified. A port range (port:port) counts as two ports.

Odd I see no AF31 rules in there.

1 Like

i thought modifying classes would change something, but it's the same game ports are marked with CS0 and not with CS4

I would respectfully recommend to bring @elan back into the discussion, I have zero first hand experience and hence it would be a waste of time if I would try to reverse engineer that script, given that its author is an active and helpful poster in this forum.

2 Likes

it would be of great help

1 Like

i am very newbie using qosify I prioritize the ports that my game has but there is always a queue that takes the prioritization I do not know if I allow myself to understand