Академический Документы
Профессиональный Документы
Культура Документы
Manual:HTB
From MikroTik Wiki
Contents Applies
to
RouterOS: 2.9, v3,
1 Theory v4
1.1 Structure
1.2 Dual Limitation
1.3 Priority
2 Examples
2.1 Structure
2.2 Example 1 : Usual case
2.3 Result of Example 1
2.4 Example 2 : Usual case with max-limit
2.5 Result of Example 2
2.6 Example 3 : Inner queue limit-at
2.7 Result of Example 3
2.8 Example 4 : Leaf queue limit-at
2.9 Result of Example 4
3 HTB configuration example
Theory
Structure
HTB (Hierarchical Token Bucket) is a classful queuing method that is useful for handling different kind of
traffic. We have to follow three basic steps to create HTB:
Match and mark traffic – classify traffic for further use. Consists of one or more matching parameters
to select packets for the specific class.
Create rules (policy) to mark traffic – put specific traffic class into specific queue and to define the
actions that are taken for each class.
Attach policy for specific interface(-s) – append policy for all interfaces (global-in, global-out or
global-total), for specific interface or for specific parent queue.
HTB allows to create a hierarchical queue structure and determine relations between queues, like "parent-child"
or "child-child".
As soon as queue has at least one child it becomes a inner queue, all queues without children - leaf queues.
Leaf queues make actual traffic consumption, Inner queues are responsible only for traffic distribution. All
leaf queues are treated on equal basis.
In RouterOS it is necessary to specify parent option to assign queue as a child to other queue
Dual Limitation
CIR (Committed Information Rate) – (limit-at in RouterOS) worst case scenario, flow will get this
amount of traffic no matter what (assuming we can actually send so much data)
https://wiki.mikrotik.com/wiki/Manual:HTB 1/8
3/17/2018 Manual:HTB - MikroTik Wiki
MIR (Maximal Information Rate) – (max-limit in RouterOS) best case scenario, rate that flow can get
up to, if there queue's parent has spare bandwidth
In other words, at first limit-at (CIR) of the all queues will be satisfied, only then child queues will try to
borrow the necessary data rate from their parents in order to reach their max-limit (MIR).
Note: CIR will be assigned to the corresponding queue no matter what. (even if max-limit of the parent is
exceeded)
That is why, to ensure optimal (as designed) usage of dual limitation feature, we suggest to stick to these rules:
Sum of committed rates of all children must be less or equal to amount of traffic that is available to
parent.
Maximal rate of any child must be less or equal to maximal rate of the parent
MIR (parent) ≥ MIR(child1) & MIR (parent) ≥ MIR(child2) & ... & MIR (parent) ≥ MIR(childN)
Priority
We already know that limit-at (CIR) to all queues will be given out no matter what.
Priority is responsible for distribution of remaining parent queues traffic to child queues so that they are able to
reach max-limit
Queue with higher priority will reach its max-limit before the queue with lower priority. 8 is the lowest
priority, 1 is the highest.
Examples
In this section we will analyze HTB in action. To do that we will take one HTB structure and will try to cover
all the possible situations and features, by changing the amount of incoming traffic that HTB have to recycle.
and changing some options.
Structure
Queue03, Queue04 and Queue05 are clients who require 10Mbps all the time Outgoing interface is able to
handle 10Mbps of traffic.
Result of Example 1
https://wiki.mikrotik.com/wiki/Manual:HTB 3/8
3/17/2018 Manual:HTB - MikroTik Wiki
Result of Example 2
Queue03 will receive 2Mbps
Queue04 will receive 6Mbps
Queue05 will receive 2Mbps
Clarification: After satisfying all limit-ats HTB will give throughput to queue with highest priority.
Result of Example 3
Queue03 will receive 2Mbps
Queue04 will receive 6Mbps
Queue05 will receive 2Mbps
Clarification: After satisfying all limit-ats HTB will give throughput to queue with highest priority. But
in this case inner queue Queue02 had limit-at specified, by doing so, it reserved 8Mbps of throughput
for queues Queue04 and Queue05. From these two Queue04 have highest priority, that is why it gets
additional throughput.
Result of Example 4
Queue03 will receive ~3Mbps
Queue04 will receive ~1Mbps
Queue05 will receive ~6Mbps
Clarification: Only by satisfying all limit-ats HTB was forced to allocate 20Mbps - 6Mbps to Queue03,
2Mbps to Queue04, 12Mbps to Queue05, but our output interface is able to handle 10Mbps. As output
interface queue is usually FIFO throughput allocation will keep ratio 6:2:12 or 3:1:6
Assume that we want to limit maximum download speed for subnet 10.1.1.0/24 to 2Mbps and distribute this
amount of traffic between the server and workstations using HTB (limit upload to 2Mbps). Since HTB works in
one direction and is implemented on outbound interface, HTB for download will be on ether2 and HTB for
upload will be on ether1.
https://wiki.mikrotik.com/wiki/Manual:HTB 6/8
3/17/2018 Manual:HTB - MikroTik Wiki
Mark traffic form/to server. The first rule we will mark the outgoing connection from server and with the
second one, all packets, which belong to this connection (download and upload packets for this connection):
Do the same for workstation too. Match all workstation connections, mark it with the same mark (new-
connection-mark=workstation_con) and after that mark all packets which belong to these workstation.
At the end create /queue tree for upload and download based on figure 8.8 and figure 8.9.
https://wiki.mikrotik.com/wiki/Manual:HTB 7/8
3/17/2018 Manual:HTB - MikroTik Wiki
https://wiki.mikrotik.com/wiki/Manual:HTB 8/8