Quality of Service · Topic 1 of 4
HTB and the Queue Tree
Learn how RouterOS implements HTB with the queue tree: parents, children, leaf and inner queues, packet marks, global parents and where queues act.
- 5 min
- Includes a diagram
- HTB shares bandwidth between queues arranged as a tree.
- The queue tree is configured in
/queue tree, and every queue has aparent. - A parent can be an interface, a global parent or another queue.
What it is
HTB, the hierarchical token bucket, is the method RouterOS uses to share bandwidth between queues arranged as a tree.
A tree has a root, branches and leaves. The root is a parent such as an interface. Each branch can split its bandwidth between children, and each child can split it again.
The queue tree is the menu where you build such a tree by hand. You create each queue, say who its parent is, and say which packets it handles. The commands are in /queue tree.
How it works
The tree controls rates, and only leaf queues hold packets.
Parents
Every queue in the tree has a parent. The parent can be one of three things.
| Parent | Meaning |
|---|---|
| An interface name | The queue shapes traffic leaving that interface |
| global-in, global-out or global-total | A virtual parent that is not tied to one interface |
| Another queue | The new queue becomes a child of that queue |
A queue on an interface shapes traffic as it leaves that interface. This is why shaping for download is usually done on the LAN side interface, and shaping for upload on the WAN side.
A global parent attaches the queue at a fixed place in the packet flow, so one tree can cover traffic across several interfaces. global-in sits where packets enter, global-out where they leave, and global-total covers both directions together.
Leaf and inner queues
A queue that has children is an inner queue. A queue with no children is a leaf queue. Only leaf queues handle packets, so only leaf queues use a packet mark and a queue type.
/queue tree add name=total-down parent=ether2 max-limit=10M
/queue tree add name=web-down parent=total-down packet-mark=web-pkt limit-at=2M max-limit=8M queue=default
/queue tree add name=other-down parent=total-down packet-mark=other-pkt limit-at=2M max-limit=8M queue=default
The first queue is an inner queue with no packet mark. It only sets the total for its children. The next two are leaf queues, and each matches the packets that mangle marked.
Packet marks
A leaf queue takes traffic by its packet-mark. The mark is created in the mangle table, so the mangle rule must run before the queue sees the packet.
/ip firewall mangle add chain=forward out-interface=ether2 protocol=tcp dst-port=80,443 action=mark-packet new-packet-mark=web-pkt passthrough=no
Packets with no matching queue go to the interface's default queue. Without a catch all leaf, unmarked traffic is not limited by your tree.
Mark everything. Add a last mangle rule that marks all remaining traffic as other-pkt, and give it a leaf queue, so no traffic escapes the tree.
Queues act on outgoing traffic
Queues shape what leaves an interface. RouterOS cannot slow packets that have already arrived, but it can delay the packets it sends onward, which makes TCP senders back off. That is why a download limit is applied on the interface facing the clients.
Where the tree sits in the path
A queue tree with an interface parent is applied as the packet leaves, after postrouting. Because mangle runs before that, packet marks made in forward or postrouting are in time for the queue.
Fasttracked packets skip mangle, as covered in the connection tracking page, so they never receive the packet marks a leaf queue needs. If a queue shows no traffic, check that no fasttrack rule matches it.
Version differences
The queue tree works in both version 6 and version 7. The idea of parents, children and leaf queues is the same. The way marks and routing tables are named differs in mangle, but that does not change how the queue tree reads a packet mark.
What to remember for the exam
Eight facts cover most questions on this topic.
- HTB shares bandwidth between queues arranged as a tree.
- The queue tree is configured in
/queue tree, and every queue has aparent. - A parent can be an interface, a global parent or another queue.
- Only leaf queues hold packets, and only they use a packet mark and queue type.
- Inner queues only divide bandwidth between their children.
- Queues shape outgoing traffic, so download is shaped on the client facing interface.
- Packet marks come from mangle, and the mark must exist before the queue handles the packet.
- Fasttracked traffic skips mangle, so it gets no packet marks.
A queue tree with no matching packet marks does nothing. Check the mangle counters before you check the queue.
Common mistakes
These four mistakes appear often.
Adding a packet mark to an inner queue. Only leaf queues use marks, so the mark is wasted.
Shaping download on the WAN interface. Queues act on outgoing traffic, so use the interface facing the clients.
Forgetting unmarked traffic. It escapes the tree unless a catch all mark and leaf exist.
Ignoring fasttrack. The queue stays empty because fasttracked traffic skips the mangle rules that mark it.
Check yourself
Work through these three questions.
Which queues hold packets in an HTB tree?
Only leaf queues hold packets. Inner queues only divide bandwidth between their children.
Where do the packet marks for a queue tree come from?
They are set by
mark-packetrules in the mangle table.Why is download limited on the LAN facing interface?
Queues shape outgoing traffic, so the packets must be leaving through that interface.
Topic 1 of 4 in Quality of Service
Test yourself on Quality of Service
The full MikroTik MTCTCE question bank has 479 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by MikroTik. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.