Skip to main content
Version: 7.26

CAKE

CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline that combines COBALT active queue management, a deficit-mode shaper, DRR++ flow isolation, simplified DiffServ handling, and link-layer overhead compensation.

CAKE is designed to maintain fairness and minimize bufferbloat with practical defaults and little tuning.

When to use CAKE​

Use CAKE on a shared bottleneck where bulk transfers increase latency or one host can dominate the available capacity. Typical examples include an Internet connection shared by several clients, a slow uplink, or an asymmetric connection.

CAKE can:

  • Keep latency low while the link is busy.
  • Share capacity between hosts and between their individual connections.
  • Shape for link-layer overhead.
  • Apply a simple DiffServ policy.
  • Filter redundant TCP acknowledgments on highly asymmetric links.

CAKE can control only traffic that passes through its queue. It cannot correct Wi-Fi interference, insufficient router CPU, or a queue elsewhere in the network unless its shaper is configured below that bottleneck's rate.

Use FQ-CoDel when you require per-flow fairness and active queue management with lower CPU use. Use CAKE when you also require per-host fairness, an integrated shaper with link-layer compensation, DiffServ handling, or ACK filtering.

Basic configuration​

CAKE is a queue type, not a complete traffic-matching rule. Creating a CAKE entry under /queue/type defines a reusable queue profile but does not process any traffic by itself. Assign that profile to a Simple Queue, Queue Tree, or Interface Queue. See the generated /queue/type CLI reference for the complete list of properties and accepted values.

The following example applies the same CAKE profile to both directions of a Simple Queue. HTB supplies the upload and download limits, so CAKE's internal shaper remains unlimited:

/queue/type
add name=cake-default kind=cake cake-bandwidth=0 cake-nat=yes

/queue/simple
add name=internet-cake target=192.168.88.0/24 max-limit=20M/100M queue=cake-default/cake-default

In max-limit=20M/100M and queue=cake-default/cake-default, the first value is upload and the second is download. Replace the target and rates with values appropriate for the network. FastTracked traffic bypasses this Simple Queue, so disable FastTrack for the traffic the queue must process.

note

Set cake-bandwidth only on queue types where kind=cake. It controls the shaper built into the CAKE qdisc.

Simple Queue and Queue Tree entries use HTB. Their limit-at (CIR) and max-limit (MIR) parameters control the rate at the HTB level. When you assign a CAKE queue type to one of these entries, CAKE operates as a leaf qdisc under HTB.

Leave cake-bandwidth=0 when HTB should control the traffic rate. This value leaves CAKE's shaper unlimited, but CAKE continues to provide active queue management, flow isolation, and DiffServ handling. Set cake-bandwidth when CAKE should also shape the traffic. If you configure both cake-bandwidth and an HTB rate limit, traffic passes through both shapers.

Shape upload on the WAN interface​

With cake-bandwidth set, CAKE shapes the traffic itself, and an interface queue is enough. An interface queue processes only the packets that the interface transmits, so this example shapes upload only. In the default configuration, the WAN interface is ether1:

/queue/type
add name=cake-up kind=cake cake-bandwidth=19M cake-nat=yes \
cake-overhead-scheme=ethernet
/queue/interface
set ether1 queue=cake-up

Check that the interface uses the queue type:

/queue/interface/print where interface=ether1
Columns: INTERFACE, QUEUE, ACTIVE-QUEUE
# INTERFACE QUEUE ACTIVE-QUEUE
0 ether1 cake-up cake-up

Shape both directions with a queue tree​

A queue tree with an interface as its parent limits the traffic that leaves the router through this interface. Upload leaves through the WAN interface, and download leaves through the LAN interface. packet-mark=no-mark matches the packets that have no packet mark, so this example needs no mangle rules. HTB supplies the rate limits, and cake-bandwidth stays at 0. The download queue does not limit traffic that the bridge forwards between its own ports.

In the default configuration, the WAN interface is ether1 and the LAN interface is bridge:

/queue/type
add name=cake-wan kind=cake cake-nat=yes
/queue/tree
add name=upload parent=ether1 packet-mark=no-mark max-limit=19M \
queue=cake-wan
add name=download parent=bridge packet-mark=no-mark max-limit=95M \
queue=cake-wan

Check that both queues count traffic:

/queue/tree/print stats
0 name="upload" parent=ether1 packet-mark=no-mark rate=931312 packet-rate=111
queued-bytes=0 queued-packets=0 bytes=740968 packets=644 dropped=0
1 name="download" parent=bridge packet-mark=no-mark rate=990664
packet-rate=103 queued-bytes=0 queued-packets=0 bytes=749418 packets=599
dropped=0

Memory limit​

The rate limit and the memory limit are different settings. Queue rate limits, described in Queues, use max-limit with HTB to control how fast packets leave the queue. cake-memlimit controls how much queued traffic the CAKE instance can hold in memory before it starts to drop packets.

CAKE can either drop excess packets or keep them queued in memory. When the memory limit is reached, CAKE drops packets. The cake-memlimit property selects the memory bound. It belongs to the queue type in /queue/type, not to /queue/simple.

A simple queue with CAKE uses an internal path that can buffer substantially more traffic than a queue tree with the same CAKE queue type and the same rate. On a device with limited RAM, this buffer can exhaust memory. Set an explicit limit when CAKE is used by a simple queue. The same property applies when CAKE is used by a queue tree or an interface queue.

A bidirectional simple queue has one CAKE instance per direction, so an 8 MiB limit can allow up to about 16 MiB in total. On a device with 256 MiB of RAM, start with about 8 MiB per CAKE instance. Adjust the value to the available RAM and to how much queueing delay is acceptable.

The following example defines a CAKE queue type with a memory limit and assigns it to both directions of a simple queue:

/queue/type
add name=cake-limited kind=cake cake-memlimit=8M

/queue/simple
add name=limited target=ether1 max-limit=45M/9M \
queue=cake-limited/cake-limited

A queue tree uses the same queue type:

/queue/tree
add name=limited parent=ether1 max-limit=9M queue=cake-limited \
packet-mark=no-mark

A limit that is too low causes earlier packet drops. This is normal active queue management (AQM) behavior. When cake-memlimit is not set, the effective buffer can be much larger. The packet-count queue size described in Queue size does not control CAKE memory use.

warning

On devices with limited RAM, an unconstrained CAKE queue can exhaust memory. Set cake-memlimit when CAKE is used on a simple queue.

Use caseRecommended starting configuration
Simple Queue or Queue Tree provides the rate limitLeave cake-bandwidth=0 and set the HTB max-limit. CAKE provides active queue management and fairness without adding a second shaper.
CAKE provides the rate limitSet cake-bandwidth below the real bottleneck rate and configure the correct link-layer overhead. Avoid a second HTB rate limit unless both shaping layers are intentional.
Router performs NATSet cake-nat=yes and keep the default triple-isolate flow mode. This lets one CAKE instance balance traffic between internal hosts and between their flows.
Download/upload ratio is greater than approximately 10:1Set cake-ack-filter=filter only on the transmit queue for the slower direction.
Ingress DSCP markings are not trustedSet cake-diffserv=besteffort to ignore them, or set cake-wash=yes to clear them after CAKE applies its priority decision.

Direction and queue placement​

A CAKE instance processes only the packets that pass through the queue where it is attached. It does not automatically process traffic in the reverse direction.

  • Interface Queue: An interface queue processes packets transmitted by that interface. For forwarded client traffic, CAKE on the WAN-facing transmit interface processes uploads, while CAKE on the LAN-facing transmit interface processes downloads. These are two separate CAKE instances. An interface queue does not process packets received by that interface.
  • Simple Queue: RouterOS determines upload and download relative to the configured target. The queue property selects the upload and download queue types in that order. Assign a CAKE queue type to both positions to process both directions.
  • Queue Tree: Each Queue Tree is one-directional. Its parent and packet selection determine which traffic passes through its CAKE leaf queue.

Configure a separate CAKE queue type for each direction when the upload and download rates or options differ. If the LAN uses several outgoing interfaces, an Interface Queue attached to only one of them does not process traffic transmitted by the others. A single CAKE instance can balance many hosts and flows that pass through it. Create separate per-client queues only when you require explicit per-client rate limits or HTB guarantees.

The cake-autorate-ingress name refers to CAKE's capacity-estimation mode. It does not make an Interface Queue process packets received by the interface or create a reverse-direction queue. Linux examples that redirect WAN ingress to an Intermediate Functional Block (IFB) create a separate transmit queueing point; they are not RouterOS Interface Queue configuration instructions.

Select the shaping rate​

The shaper must become the bottleneck to control queue delay. Start below the stable measured throughput, not at the advertised service rate. Ingress shaping usually requires more headroom because the upstream sender and ISP queue are outside the router's control. With correct overhead compensation, egress shaping can operate closer to the measured link rate.

Validate the rate under simultaneous upload and download load while you measure latency. A throughput-only speed test does not show whether interactive traffic, voice, or other hosts remain responsive. Reduced throughput for one flow can be the expected result when CAKE shares capacity between hosts and flows.

warning

A shaped CAKE instance does not divide its packet processing across multiple CPU cores. CPU exhaustion can reduce throughput and increase latency even when other cores are idle. Test the required shaping rate on the target device. Unlimited CAKE requires substantially less processing than shaped CAKE.

note

FastTracked traffic bypasses Simple Queues and Queue Trees with parent=global. Queue Trees parented directly to an interface can process FastTracked traffic. See FastTrack.

Overhead compensation​

CAKE must know how much time each packet occupies on the bottleneck link. The packet size visible to CAKE might exclude framing, encapsulation, or inter-packet overhead. Without compensation, the configured shaper can send slightly faster than the real link and allow a queue to build elsewhere.

Prefer a cake-overhead-scheme that matches the bottleneck technology. A scheme sets the related overhead, minimum packet unit (MPU), and ATM or PTM compensation. Use manual values only when the encapsulation is known and no preset matches it.

SchemeBehavior
rawDisables overhead compensation. Use it when the packet size visible to CAKE already represents the unit used by the bottleneck.
conservativeDeliberately overestimates unknown overhead. It is equivalent to 48 bytes of overhead with ATM compensation.
ethernetAccounts for the Ethernet preamble, inter-frame gap, and frame check sequence. It is equivalent to 38 bytes of overhead, an MPU of 84 bytes, and no ATM or PTM compensation.
via-ethernetAccepted alone or together with another scheme. It does not change cake-overhead, cake-mpu or cake-atm.
ether-vlanAdds 4 bytes for an IEEE 802.1Q VLAN header. Combine it with the applicable base scheme.
docsisMatches the Ethernet frame size used by DOCSIS head-end shaping and metering. It is equivalent to 18 bytes of overhead, an MPU of 64 bytes, and no ATM or PTM compensation.
ADSL schemesSelect ipoa-vcmux, ipoa-llcsnap, bridged-vcmux, bridged-llcsnap, pppoa-vcmux, pppoa-llc, pppoe-vcmux, or pppoe-llcsnap to match the encapsulation. These schemes include ATM cell compensation.
pppoe-ptm or bridged-ptmSelect the matching VDSL2 encapsulation. These schemes include PTM compensation.

For manual configuration, cake-overhead accepts values from -64 to 256 bytes. cake-mpu accepts values from 0 to 256 bytes and cannot be negative. Set cake-atm=atm for ATM cell framing or cake-atm=ptm for PTM encoding.

RTT Schemes​

The CAKE queue discipline uses the round-trip time (RTT) to tune its active queue management parameters. A new CAKE queue type has no scheme and cake-rtt=100ms, the same value as the internet scheme. Keep this value unless the typical traffic RTT is known. A shorter scheme reacts more quickly, but a value below the actual path RTT can reduce the throughput of long-lived flows, especially on low-rate links. The setting does not need to match every flow exactly; actual RTTs within approximately one order of magnitude generally work well.

Use metro rather than lan for most local networks. The aggressive time constants of lan can signal congestion prematurely, reduce throughput, and leave too little queued traffic for the fairness logic. Reserve it for controlled, pure Ethernet networks; do not use it when shaping an Internet access link.

Here are the RTT settings you can use, what they mean, and when you might use them:

  1. cake-rtt: Manually specifies the RTT, for example, cake-rtt=100ms.
  2. cake-rtt-scheme=datacentre: Assumes an RTT of 100 microseconds. Use it only for extremely high-performance data-center networks.
  3. cake-rtt-scheme=lan: Assumes an RTT of 1 millisecond. Use it only for controlled, pure Ethernet networks, not for an Internet access link.
  4. cake-rtt-scheme=metro: Assumes an RTT of 10 milliseconds. Use it for most local networks or traffic within a single city.
  5. cake-rtt-scheme=regional: Assumes an RTT of 30 milliseconds. Use it for traffic within a region or country.
  6. cake-rtt-scheme=internet: Assumes an RTT of 100 milliseconds. This is suitable for typical Internet traffic.
  7. cake-rtt-scheme=oceanic: Assumes an RTT of 300 milliseconds. Use it for Internet traffic with consistently above-average latency.
  8. cake-rtt-scheme=satellite: Assumes an RTT of 1000 milliseconds. Use it for geostationary satellite paths.
  9. cake-rtt-scheme=interplanetary: Assumes an RTT of 1000 seconds and almost completely disables Active Queue Management (AQM) actions. It is not intended for ordinary network configurations.

For satellite and other high-delay links, set the measured RTT when the preset does not match the path. The presets are starting points rather than measurements.

Flow isolation​

CAKE identifies flows by the source and destination addresses, transport protocol, and source and destination ports. It places flows into separate queues and schedules them fairly. Sparse, low-rate flows can then remain responsive when bulk flows use the same link.

  • cake-flowmode=triple-isolate: Applies fairness between source hosts, destination hosts, and individual flows. This is the default and the recommended starting point for a typical gateway.
  • cake-flowmode=dual-srchost: Applies fairness between source hosts, then between each host's flows. Use it when the source addresses identify the subscribers or devices to balance.
  • cake-flowmode=dual-dsthost: Applies fairness between destination hosts, then between each host's flows. Use it when the destination addresses identify the subscribers or devices to balance.
  • cake-flowmode=srchost: Applies fairness only between source addresses.
  • cake-flowmode=dsthost: Applies fairness only between destination addresses.
  • cake-flowmode=hosts: Applies fairness between source and destination host pairs.
  • cake-flowmode=flows: Applies fairness only between complete five-tuple flows.
  • cake-flowmode=flowblind: Disables flow isolation and places all traffic for each tin in one queue.

With flows, a host that opens many connections gets a larger share of the rate than a host with one connection. With dual-srchost and triple-isolate, the share of a host depends much less on the number of its connections.

When the router performs NAT, set cake-nat=yes so CAKE can isolate the internal addresses and ports. Keep triple-isolate unless the topology requires a specific directional mode. The commonly copied combination of dual-srchost for upload and dual-dsthost for download is mainly useful when CAKE can already see the required host addresses without a NAT lookup. The NAT lookup has no effect when another device performs NAT or when hardware-offloaded traffic bypasses CAKE.

ACK filter​

ACK filtering removes redundant TCP acknowledgment packets before they consume capacity on a narrow transmit link. Start with cake-ack-filter=filter; use cake-ack-filter=aggressive only after testing shows that the additional filtering does not reduce TCP performance. Set cake-ack-filter=none to disable it.

Enable ACK filtering only on the transmit queue for the slower side of a highly asymmetric connection. It becomes relevant when the download/upload ratio exceeds approximately 10:1. Do not enable it on the receive queue: ACK packets normally do not accumulate there, and the filter consumes additional CPU.

ACK filtering cannot inspect ACK packets inside encrypted traffic, such as a WireGuard or IPsec tunnel. Apply it where the plain TCP ACK packets are visible.

DiffServ​

Differentiated Services (DiffServ) classifies packets by their Differentiated Services Code Point (DSCP) and places them into CAKE traffic classes called tins. CAKE applies soft priority between tins: every tin receives service and can borrow unused capacity. The percentage thresholds are not fixed bandwidth limits. For example, Best Effort can use 100% of the link when the other tins are idle.

  • cake-diffserv=diffserv3 (default): Provides Bulk (CS1 and LE), Best Effort (general traffic), and Voice (CS7, CS6, EF, VA, and TOS4) tins. Their thresholds are 6.25%, 100%, and 25%. Voice uses a shorter CoDel interval.
  • cake-diffserv=diffserv4: Provides Bulk (CS1 and LE), Best Effort (general traffic), Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, and TOS1), and Voice (CS7, CS6, EF, VA, CS5, and CS4) tins. Their thresholds are 6.25%, 100%, 50%, and 25%.
  • cake-diffserv=diffserv8: Provides eight tins for networks with a deliberate, detailed DSCP policy.
  • cake-diffserv=besteffort: Disables priority queuing and places all traffic in one tin. Use this when DSCP markings are absent or must not affect scheduling.
  • cake-diffserv=precedence: Uses the legacy IP precedence interpretation. Avoid this mode on new configurations.

CAKE does not create trustworthy classifications by itself. Use the DiffServ modes only when you trust the received DSCP markings or set them with a consistent local policy. Incorrect high-priority markings can give traffic unintended service.

Wash​

The cake-wash=yes option clears DSCP markings after CAKE uses them for its priority decision. It does not clear Explicit Congestion Notification (ECN) bits.

Enable cake-wash=yes at a DiffServ domain boundary when the next network must not inherit the existing DSCP policy. If inbound markings are not trusted and should not affect scheduling, use cake-diffserv=besteffort; adding cake-wash=yes also clears those markings before forwarding the packets.

Autorate ingress​

The cake-autorate-ingress option estimates capacity from the arrival times of ingress packets and adjusts CAKE's internal shaper. An optional cake-bandwidth value supplies its initial estimate.

The estimator observes only traffic arriving at this CAKE instance. It cannot measure a bottleneck farther downstream, and it must receive enough traffic before it can increase its estimate. Links with large or rapid capacity changes, such as LTE and 5G, can therefore produce unstable or unexpectedly low rates.

warning

Test cake-autorate-ingress on the actual link before production use. It is CAKE's built-in estimator and is not the same as external adaptive-rate implementations that continuously measure delay and update the shaper. Use a fixed rate below the reliable link capacity when predictable latency and throughput are more important than following every capacity change.

Do not enable cake-autorate-ingress when HTB is intended to control the rate. The option changes CAKE's shaper, not the HTB max-limit.