CAKE and FQ-CoDel
CAKE and FQ-CoDel
Section titled “CAKE and FQ-CoDel”CAKE (Common Applications Kept Enhanced) and FQ-CoDel (Fair Queuing Controlled Delay) are modern Active Queue Management (AQM) algorithms designed to eliminate bufferbloat — the condition where oversized buffers cause high and variable latency under load.
Traditional queue types like PFIFO fill their buffers completely before dropping packets, which causes latency to spike from milliseconds to hundreds of milliseconds during congestion. AQM algorithms instead drop or mark packets proactively based on queuing delay, keeping buffers shallow and latency predictable.
Both algorithms are available in RouterOS 7.1 and later as kind=fq-codel and kind=cake.
CAKE is the recommended choice for most deployments — it is built on FQ-CoDel and adds
integrated shaping, overhead compensation, and diffserv prioritization.
Quick Start
Section titled “Quick Start”Apply CAKE to a WAN interface upload queue and a LAN bridge download queue:
/queue typeadd name=cake-wan kind=cake overhead-compensation=ethernet rtt=100ms \ flow=diffserv4 wash=yes
/queue treeadd name=wan-upload parent=ether1 queue=cake-wan max-limit=20Madd name=lan-download parent=bridge queue=cake-wan max-limit=100MAdjust max-limit to 90–95% of your subscribed bandwidth so CAKE controls the bottleneck
queue at your router rather than letting it form inside the ISP’s CPE.
FQ-CoDel
Section titled “FQ-CoDel”FQ-CoDel combines two mechanisms: Fair Queuing (FQ) hashes flows into separate sub-queues so that a bulk download cannot starve a VoIP call. CoDel monitors the time each packet spends waiting and begins dropping once that delay exceeds a target, signalling TCP senders to slow down before buffers are fully occupied.
Creating an FQ-CoDel Queue Type
Section titled “Creating an FQ-CoDel Queue Type”/queue typeadd name=fq-codel-wan kind=fq-codel \ fq-codel-target=5ms \ fq-codel-interval=100ms \ fq-codel-quantum=1514 \ fq-codel-limit=1024 \ fq-codel-ecn=noFQ-CoDel Parameters
Section titled “FQ-CoDel Parameters”| Parameter | Default | Description |
|---|---|---|
fq-codel-target | 5ms | Maximum acceptable queuing delay. CoDel begins dropping when a packet waits longer than this value. Lower values reduce latency at the cost of slightly more drops. |
fq-codel-interval | 100ms | Measurement window. CoDel only drops once target has been exceeded continuously for one interval. Prevents over-reaction to short bursts. |
fq-codel-quantum | 1514 | Bytes of credit given to each flow per scheduling round. Matches standard Ethernet MTU so each flow gets one full packet per turn. |
fq-codel-limit | 1024 | Total packet limit across all sub-queues. Packets beyond this are tail-dropped. |
fq-codel-ecn | no | Use ECN marking instead of dropping when supported by both endpoints. Reduces retransmits on ECN-capable paths. |
When to Use FQ-CoDel
Section titled “When to Use FQ-CoDel”FQ-CoDel is the lighter option: it reduces bufferbloat and provides flow fairness but does not include integrated shaping or overhead compensation. Use it when:
- You only need AQM without shaping (rate limiting handled separately by HTB or Simple Queue)
- The router hardware is constrained and the added CPU cost of CAKE matters
- You want a simpler baseline before tuning CAKE parameters
CAKE builds on FQ-CoDel and adds three capabilities that make standalone deployment practical:
- Integrated shaper — native rate limiting avoids double-queuing when combined with HTB or Simple Queue
- Overhead compensation — accounts for L2 framing bytes so the shaper rate matches what actually crosses the wire
- Diffserv tins — classifies traffic into priority buckets based on DSCP markings
Creating a CAKE Queue Type
Section titled “Creating a CAKE Queue Type”/queue typeadd name=cake-type kind=cake \ overhead-compensation=ethernet \ rtt=100ms \ flow=diffserv4 \ wash=yes \ ack-filter=defaultApply it in a Queue Tree entry with max-limit set to your link speed:
/queue treeadd name=isp-upload parent=ether1 queue=cake-type max-limit=20MOverhead Compensation
Section titled “Overhead Compensation”CAKE shapes traffic based on a bandwidth budget. If the shaper does not account for encapsulation headers, it either over-shapes (wastes bandwidth) or under-shapes (lets too much through, defeating AQM).
Set overhead-compensation to match your WAN connection type:
| Value | Overhead Added | Typical Use |
|---|---|---|
none | 0 bytes | Raw Ethernet, testing |
ethernet | 18 bytes | Ethernet with 802.1Q tag |
pppoe | ~8 bytes | PPPoE over Ethernet |
lte | variable | LTE/cellular uplink |
wireless | variable | Wi-Fi uplink |
Using the wrong preset causes systematic shaping error. A PPPoE connection with
overhead-compensation=none will allow ~0.5% more traffic than configured at 100 Mbps —
enough to push congestion back into the ISP’s queue and undo the bufferbloat fix.
RTT Estimation
Section titled “RTT Estimation”The rtt parameter tells CAKE the expected round-trip time on this path. CAKE uses it to
tune how aggressively CoDel responds to emerging congestion — a shorter RTT requires faster
intervention.
| Value | Typical Scenario |
|---|---|
10ms | LAN or metro fibre |
50ms | Good residential fibre/DOCSIS |
100ms | Typical residential DSL/cable |
200ms–300ms | Long-haul DSL |
600ms | Satellite internet |
Set rtt close to the actual idle RTT on the shaped path. Measure with ping to a nearby
target before adding the queue:
/tool ping address=8.8.8.8 count=10A misconfigured RTT does not break CAKE, but the right value improves responsiveness during congestion onset.
Diffserv Tins
Section titled “Diffserv Tins”CAKE can classify traffic into tins — separate sub-queues with different priority and
latency targets — using DSCP markings already in packet headers. Configure the tin scheme
with the flow parameter.
| Value | Tins | DSCP Mapping |
|---|---|---|
best-effort | 1 | All traffic equal; DSCP ignored |
diffserv4 | 4 | Bulk (CS1), Best Effort (CS0), Video (AF/CS2/CS3), Voice (EF/CS5/CS6/CS7) |
diffserv8 | 8 | Fine-grained; each DSCP class gets its own tin |
flows | — | Ignores DSCP entirely; pure per-flow fairness |
best-effort is the safe default when you do not control DSCP markings on your network
or traffic arrives from an untrusted upstream. All flows receive equal treatment.
diffserv4 is the recommended starting point for home routers and small offices. It
automatically elevates VoIP (EF), depresses background transfers (CS1), and keeps gaming
and video in distinct tins without any mangle rules.
flows disables tins and focuses entirely on fairness between individual flows. Use
it in multi-user scenarios where DSCP markings are absent or untrusted.
The wash Parameter
Section titled “The wash Parameter”With wash=yes, CAKE strips DSCP markings from packets as they leave the queue. This
prevents internally-set priority marks from leaking to downstream networks, which is
generally correct on an outbound WAN queue.
Set wash=no on internal LAN queues where downstream devices need to see the DSCP values.
ACK Filtering
Section titled “ACK Filtering”The ack-filter parameter reduces TCP ACK storms on asymmetric links where upload is much
slower than download:
| Value | Behaviour |
|---|---|
default | Standard ACK handling |
filter | Drop redundant/late ACKs to free upload capacity |
none | Disable ACK filtering |
ack-filter=filter helps on ADSL or DOCSIS links where 5–20 Mbps upload must carry ACKs
for a 100+ Mbps download stream. It is not needed on symmetric fibre links.
Practical Examples
Section titled “Practical Examples”Home Router — Cable or DSL
Section titled “Home Router — Cable or DSL”A typical home router with 100 Mbps download / 20 Mbps upload over PPPoE:
/queue typeadd name=cake-home kind=cake \ overhead-compensation=pppoe \ rtt=50ms \ flow=diffserv4 \ wash=yes \ ack-filter=filter
/queue treeadd name=wan-up parent=ether1 queue=cake-home max-limit=19Madd name=lan-down parent=bridge queue=cake-home max-limit=95MSet max-limit to 95% of the subscribed rate. This ensures CAKE holds the bottleneck
queue rather than the ISP’s equipment.
ISP Edge — PPPoE with VDSL Overhead
Section titled “ISP Edge — PPPoE with VDSL Overhead”ISP aggregation routers typically add 44 bytes of overhead per packet on VDSL2 PTM links (PPPoE + Ethernet + ATM cell padding). Specify this as a raw byte count:
/queue typeadd name=cake-vdsl kind=cake \ overhead-compensation=pppoe \ rtt=20ms \ flow=diffserv4 \ wash=yes
/queue treeadd name=subscriber-up parent=ether1 queue=cake-vdsl max-limit=18MFor precise per-subscriber shaping in ISP environments, pair CAKE with PCQ or use separate Queue Tree entries per subscriber marked with mangle packet marks.
FQ-CoDel with Existing HTB Shaper
Section titled “FQ-CoDel with Existing HTB Shaper”If you already have HTB queue trees for rate limiting, add FQ-CoDel on top for AQM without rebuilding the shaper:
/queue typeadd name=fq-codel-aqm kind=fq-codel fq-codel-target=5ms fq-codel-interval=100ms
/queue treeadd name=bulk-class parent=wan-shaper packet-mark=bulk-traffic \ queue=fq-codel-aqm max-limit=50M priority=8add name=interactive-class parent=wan-shaper packet-mark=interactive \ queue=fq-codel-aqm max-limit=50M priority=1Choosing Between CAKE and FQ-CoDel
Section titled “Choosing Between CAKE and FQ-CoDel”| CAKE | FQ-CoDel | |
|---|---|---|
| Integrated shaping | Yes | No |
| Overhead compensation | Yes | No |
| Diffserv prioritization | Yes (tins) | No |
| Per-flow fairness | Yes | Yes |
| AQM (delay-based drops) | Yes (CoDel) | Yes (CoDel) |
| Configuration complexity | Low–Medium | Low |
| CPU usage | Medium | Low |
Use CAKE when it is the only queue on a WAN interface — it replaces both the shaper and the AQM in a single queue type. Use FQ-CoDel when you already have shaping in place and only want to add AQM, or on resource-constrained hardware.
FastTrack Interaction
Section titled “FastTrack Interaction”Both CAKE and FQ-CoDel are bypassed by FastTrack connections. FastTracked packets skip the firewall and queue processing path entirely, so they are never submitted to the AQM.
Disable FastTrack on interfaces where you apply CAKE/FQ-CoDel, or explicitly exclude target traffic from FastTrack with a mangle rule:
/ip firewall mangleadd chain=forward action=mark-connection new-connection-mark=no-fasttrack \ passthrough=yes comment="Exclude LAN from FastTrack for CAKE"
/ip firewall filteradd chain=forward connection-mark=no-fasttrack action=fasttrack-connection \ disabled=yesThe simplest approach is to disable the default FastTrack rule when CAKE is deployed:
/ip firewall filterset [find comment="defconf: fasttrack"] disabled=yesMonitoring
Section titled “Monitoring”Check queue statistics to verify CAKE is active and shaping traffic:
/queue tree print statsKey fields to watch:
| Field | Meaning |
|---|---|
bytes | Total bytes processed — confirms traffic is flowing through the queue |
packets | Total packet count |
dropped | Packets dropped by AQM — low steady-state drops are normal and healthy |
queued-bytes | Current bytes buffered — should stay low under CAKE |
Under bufferbloat conditions, dropped will be non-zero but latency will remain stable.
A high queued-bytes with no drops indicates the queue is not controlling the bottleneck
(check max-limit and FastTrack).
Troubleshooting
Section titled “Troubleshooting”Latency does not improve after adding CAKE
- Verify the interface is carrying traffic:
queue tree print statsshould show incrementingbytes. - Check
max-limitis below your ISP link speed. If it equals or exceeds the ISP rate, the bottleneck queue is still inside the ISP’s equipment. - Confirm FastTrack is disabled for the shaped flows.
- Run a bufferbloat test (e.g., DSLReports Speed Test) before and after to compare latency under load.
Speed test shows lower throughput than expected
- Check
overhead-compensationmatches your connection type. An incorrect overhead preset under-shapes. - Set
max-limitto 90–95% of the subscribed rate, not 100%. - Verify the queue tree
parentpoints to the correct interface.
CAKE queue shows 0 bytes / packets
- Traffic may not be reaching the queue. Check that the
parentinterface or packet mark is correct. - Confirm that
max-limitis set — a queue tree entry with nomax-limitdoes not shape traffic.
Parameters Reference
Section titled “Parameters Reference”CAKE Parameters
Section titled “CAKE Parameters”| Parameter | Values | Description |
|---|---|---|
overhead-compensation | none, ethernet, pppoe, lte, wireless | L2 overhead preset for accurate bandwidth accounting |
rtt | duration (e.g. 100ms) | Expected RTT; tunes CoDel aggressiveness |
flow | best-effort, diffserv4, diffserv8, flows | Traffic classification and tin scheme |
wash | yes, no | Strip DSCP markings on egress |
ack-filter | default, filter, none | TCP ACK filtering for asymmetric links |
unlimited | yes, no | Disable rate limiting (AQM only mode) |
FQ-CoDel Parameters
Section titled “FQ-CoDel Parameters”| Parameter | Default | Description |
|---|---|---|
fq-codel-target | 5ms | Target queuing delay before drops start |
fq-codel-interval | 100ms | Measurement window for delay evaluation |
fq-codel-quantum | 1514 | Per-flow scheduling quantum in bytes |
fq-codel-limit | 1024 | Maximum queue depth in packets |
fq-codel-ecn | no | Enable ECN marking instead of drop |
Related Resources
Section titled “Related Resources”- Queue Types Overview — PCQ, SFQ, RED, HTB algorithm details
- Queue Tree — Hierarchical queue configuration
- Simple Queues — Per-client rate limiting
- Firewall Mangle — Packet marking for queue classification
- PFIFO, BFIFO — Simple FIFO queue types