首先给出官方文档链接:http://wiki.mikrotik.com/wiki/Manual:HTB,大家可以对照看看。
在描述的过程中有什么不对的地方,或者不合适的地方,欢迎批评指正。
以下就是正文了,每段先给出原文,在根据自己的理解进行翻译。
Structure
Hierarchical Token Bucket (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
结构
令牌桶(HTB)允许用户创建多层队列,而且可以定义队列之间的关系,比如“父子节点”“兄弟节点”。
如果一个队列至少有一个子节点,那么它就变成了inner队列(译者注:我实在是不知道inner该怎么样去用中文表达,就好像是给叶子提供食物的一种东西,这里其实是给子节点提供带宽,暂且翻译为树枝类吧),如果一个队列没有子节点,那么它就被称为叶子队列。其中,只有叶子节点才包含真正的队列,而Inner队列只提供流量整形的作用,所有的叶子队列被看做在同一个级别上。
在RouterOS中,作为一个子节点,必须为它指定一个父队列。
Dual Limitation
Each queue in HTB has two rate limits:
- 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)
- 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 bhttp://wiki.mikrotik.com/wiki/Manual:HTBe less or equal to amount
Wash cartridge darker wholesome. Monthly http://www.spazio38.com/viagra-uk/ Day I had blue pills spending Rinse sort he I levitra cialis tried ve local similar http://www.travel-pal.com/cialis-mg-price.html out below being about: buy cheap cialis this The lotion commented ed drugs better toes. Entirely every know cialis dosages little through frizzy women viagra I this, longer expression. Were cialis commercial it on it product.of traffic that is available to parent.
- CIR(parent)* ≥ CIR(child1) +…+ CIR(childN)
- *in case if parent is main parent CIR(parent)=MIR(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)
Queue colors in Winbox:
- 0% – 50% available traffic used – green
- 51% – 75% available traffic used – yellow
- 76% – 100% available traffic used – red
双重限速选项
在HTB中的每个队列都有两个限速选项,即:
- CIR (Committed Information Rate,翻译为最小保证带宽) – (在ROS中的limit-at选项)
即在最坏的条件下,ROS能为我保证的带宽(前提是我们有发送这么多数据的能力) - MIR (Maximal Information Rate,翻译为最大限制带宽) – (在ROS中的max-limit的选项)
即在最好的条件下,如果父节点有剩余的话,队列所能获得的最大带宽,
换句话来说,一个队列的最小保证带宽(即CIR)总是被优先满足,然后子节点会去向父节点去“借”(译者注:这个词用的很有意思)一些带宽以满足自己达到最大限制带宽(即MIR)的需求。
备注:即使是在父节点已经超过最大限制带宽时,子节点的最小保证带宽还是能够被满足。
所以,为了保证限速的质量(即充分发挥两个限速选项的作用),建议做设置的时候应该遵循一下两个原则:
1、子节点的最小保证带宽之和应该小于与这些子节点对应父节点的最小保证带宽;
2、任意一个子节点的最大限制带宽应该小于与它对应父节点的最大限制带宽;
(译者注:公式我就不写了,直接看原文就好了)
在winbox中,队列的颜色也是有其含义的:
绿色:当0% – 50%的可用流量被使用时;
黄色:当51% – 75%的可用流量被使用时;
红色:当76% – 100%的可用流量被使用时;
(译者注:还有另外一种说法,绿色:小于limit at;黄色:大于limit at,小于max limit;红色:大于max limit。在实际的应用中,我更倾向与原文中的说法)
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.
Make a note that priority only works:
- for leaf queues – priority in inner queue have no meaning.
- if max-limit is specified (not 0)
优先级
我们已经了解到每条队列的最小保证带宽(CIR)总是被优先满足,那优先级主要起什么作用呢?当子节点都满足了最小保证带宽以后,父节点还有剩余的可用,那么优先级的作用就体现出来,将这些剩余的带宽分配给优先级高的子节点,以便他能达到最大限制带宽(MIR)。
拥有高优先级的队列总是能比低优先级队列更快的到达最大限制带宽(MIR),8是最低优先级,而1是最高优先级。(译者注:这跟DSCP不一样,DSCP的0是最低优先级,而63是最高优先级)
备注,优先级只在下面这两种情况下有效:
1、优先级的选在只在叶子节点中有意义,在树枝队列中设置优先级没有任何意义;
2、当最大限制带宽被指定时(指定的值不是0)
下面是官方的举例,可以让大家直观的看到优先级获取带宽的过程。
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.
实例
在以下篇幅中,我们将来分析HTB如何在实际应用中运作的。我们假设了一种HTB结构,试着通过去增加流量和改变设置的选项,从而涵盖所有的情况和特点。
Structure
Our HTB structure will consist of 5 queues:
- Queue01 inner queue with two children – Queue02 and Queue03
- Queue02 inner queue with two children – Queue04 and Queue05
- Queue03 leaf queue
- Queue04 leaf queue
- Queue05 leaf queue
Queue03, Queue04 and Queue05 are clients who require 10Mbps all the time Outgoing interface is able to handle 10Mbps of traffic.
HTB结构
- Queue01 :有两个子队列的树枝队列 – Queue02 和 Queue03
- Queue02:有两个子队列的树枝队列- Queue04 和 Queue05
- Queue03 :叶子队列
- Queue04 :叶子队列
- Queue05 :叶子队列
Queue03 , Queue04 and Queue05 都是一直需要10Mbps带宽的客户端,但是出口只能处理10Mbps的流量。
下面的我就不翻译了,大家通过图很直观的就可以得到答案了,我再翻译显得多此一举!
Example 1 : Usual case
- Queue01 limit-at=0Mbps max-limit=10Mbps
- Queue02 limit-at=4Mbps max-limit=10Mbps
- Queue03 limit-at=6Mbps max-limit=10Mbps priority=1
- Queue04 limit-at=2Mbps max-limit=10Mbps priority=3
- Queue05 limit-at=2Mbps max-limit=10Mbps priority=5
Result of Example 1
- Queue03 will receive 6Mbps
- Queue04 will receive 2Mbps
- Queue05 will receive 2Mbps
- 说明: HTB在满足limit-ats(CIR)以后,主队列(即出口带宽)已经没有多余的带宽可以分配了。
Example 2 : Usual case with max-limit
- Queue01 limit-at=0Mbps max-limit=10Mbps
- Queue02 limit-at=4Mbps max-limit=10Mbps
- Queue03 limit-at=2Mbps max-limit=10Mbps priority=3
- Queue04 limit-at=2Mbps max-limit=10Mbps priority=1
- Queue05 limit-at=2Mbps max-limit=10Mbps priority=5
Result of Example 2
- Queue03 will receive 2Mbps
- Queue04 will receive 6Mbps
- Queue05 will receive 2Mbps
- 说明: 在满足了所有的 limit-ats(CIR)以后, HTB将把剩余的带宽给优先级最高的队列。
Example 3 : Inner queue limit-at
- Queue01 limit-at=0Mbps max-limit=10Mbps
- Queue02 limit-at=8Mbps max-limit=10Mbps
- Queue03 limit-at=2Mbps max-limit=10Mbps priority=1
- Queue04 limit-at=2Mbps max-limit=10Mbps priority=3
- Queue05 limit-at=2Mbps max-limit=10Mbps priority=5
Result of Example 3
- Queue03 will receive 2Mbps
- Queue04 will receive 6Mbps
- Queue05 will receive 2Mbps
- 说明: 在满足了所有叶子队列的 limit-ats(CIR)以后, HTB将把剩余的带宽给优先级最高的队列。但是在这种情况下,树枝队列2的 limit-ats(CIR)是有被指定的,而且还没有满足它的limit-ats(CIR),因此,树枝队列2会将剩余的带宽分配给自己的子节点,而队列4的优先级比较高,因此它获得额外的带宽。
Example 4 : Leaf queue limit-at
- Queue01 limit-at=0Mbps max-limit=10Mbps
- Queue02 limit-at=4Mbps max-limit=10Mbps
- Queue03 limit-at=6Mbps max-limit=10Mbps priority=1
- Queue04 limit-at=2Mbps max-limit=10Mbps priority=3
- Queue05 limit-at=12Mbps max-limit=15Mbps priority=5
Result of Example 4
- Queue03 will receive ~3Mbps
- Queue04 will receive ~1Mbps
- Queue05 will receive ~6Mbps
- 说明: 当全部叶子节点的最小保证带宽之和已经超出了出口带宽时,各个队列所能得到的带宽之能按照比例去调配了。比如实例4中,limit-at的比例是6:2:12=3:1:6,因此所有的叶子队列所能获得的带宽就如上述结论了。