找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 20512|回复: 43

[其它] 带宽控制-分层标记桶(HTB)介绍--Ros官方文档翻译(原创)

[复制链接]
发表于 2006-12-9 15:21:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
Introduction to HTB
HTB (Hierarchical Token Bucket) is a classful queuing discipline that is useful for applying different handling for different kinds of traffic. Generally, we can set only one queue for an interface, but in routeros queues are attached to the main Hierarchical Token Bucket (HTB) and thus have some properties derived from that parent queue. For example, we can set a maximum data rate for a workgroup and then distribute that amount of traffic between the members of that workgroup.
HTB qdisc in detail:
HTB介绍
HTB(分层标记桶)是一种有助于对不同类型的流实现不同处理的分级排队规则通常,我们可以为一个界面只设置一个队列,但在RouterOS中,队列附属于主HTB
,从而带有一些来自父队列的属性。例如,我们可以为一个工作组设置最大传输率然后在工作组成员之间分配带宽。

  
HTB qdisc in detail:
HTB排队规则详述:

                               
登录/注册后可看大图

HTB terms:

  • queuing discipline (qdisc) - an algorithm that holds and maintains a queue of packets. It specifies the order of the outgoing packets (it means that queuing discipline can reorder packets). Qdisc also decides which packets to drop if there is no space for them
  • filter - a procedure that classifies packets. The filter is responsible for classifying packets so that they are put in the corresponding qdiscs
  • level - position of a class in the hierarchy
  • inner class - a class that has one or more child-classes attached to it. Inner classes do not store any packets, but they do traffic shaping. The class also does not have its own priority
  • leaf class - a class that has a parent but does not have any child-classes. Leaf classes are always located at level 0 of the hierarchy. Each leaf class has a qdisc, attached to it
  • self feed - an object that represents the exit for the packets from all the classes active at its level of the hierarchy. It consists of 8 self slots
  • self slot - an element of a self feed that corresponds to each particular priority. All classes, active at the same level, of one priority are attached to one self slot that they are using to send packets out through
  • active class (at a particular level) - a class that is attached to a self slot at the given level
  • inner feed - similar to self feed object, which consists of inner self slots, present on each inner class
  • inner feed slot - similar to self slot. Each inner feed consists of inner slots which represent a priority

Each class has a parent and may have one or more children. Classes that do not have children, are put at level 0, where queues are maintained, and are called 'leaf classes'


HTB术语:

    排队规则(qdisc):保存和保持一列数据包的算法。它确定了流出的包的次序(这意味着排队规则可以对包重新排序)。当空间已满,qdisc也确定丢弃哪个个包。
    过滤器(filter):分类包的过程。filter负责把包分类,使他们放入相应的排队规则中。
    层(level):在分层制中一个类所处的层次。
    内部类(Inner class):包含一个或一个以上子类的类。内部类不储存包,但它们做流量调整。他们自己没有优先级。
    叶类(leaf class):有父类,但是没有子类的类。Leaf class在分层制中总处于第0层(level 0),每个 leaf class都附有一个排队规则(qdisc)。
    自载入流(self feed):代表从活动在它所在层的所有的类中流出包的对象。它由8self slot组成(对应于8个优先级)。
    自接口(self slot):self feed的组成部分,它对应于每个优先级。所有处于同一层次的同一优先级的类,附属于同一self slot,并通过它来送出数据包。
    (在特定层中的)活动类(active class):在指定层中属于某个self slot的类。
    内部载入流(inner feed):类似于self feed对象,由inner feed slot组成,是每个Inner class的入口
    内部载入接口(inner feed slot):类似于self slot。每个inner feed由代表各自优先级的inner slot们组成。

每个类有一个父类,可能有一个或一个以上的子类。没有子类的类被放在第0层(level 0),类里存有队列,并被称为“叶类”。



Each class in the hierarchy can prioritize and shape traffic. There are 2 main parameters in Routeros which refer to shaping and one - to prioritizing:

  • limit-at - data rate that is guaranteed to a class (CIR)
  • max-limit - maximal data rate that is allowed for a class to reach (MIR)
  • priority - order in which classes are served at the same level (8 is the lowest priority, 1 is the highest)
在层次中的每个类可以重排和调整流量。在RouteROS中有2个参数涉及调整,一个涉及到重排:

       Limit-at确保给一个类的传输率。(CIR)

       Max-limit允许一个类所能达到的最大传输率(MIR)
       Priority在同一层次中类被处理的次序(8是最低的优先级,1最高)



Each HTB class can be in one of 3 states, depending on data rate that it consumes:

  • green - a class the actual rate of which is equal or less than limit-at. At this state, the class is attached to self slot at the corresponding priority at its level, and is allowed to satisfy its limit-at limitation regardless of what limitations its parents have. For example, if we have a leaf class with limit-at=512000 and its parent has max-limit=limit-at=128000, the class will get its 512kbps!
  • yellow - a class the actual rate of which is greater than limit-at and equal or less than max-limit. At this state, the class is attached to the inner slot of the corresponding priority of its parent's inner feed, which, in turn, may be attached to either its parent's inner slot of the same priority (in case the parent is also yellow), or to its own level self slot of the same priority (in case the parent is green). Upon the transition to this state, the class 'disconnects' from self feed of its level, and 'connects' to its parent's inner feed
  • red - a class the actual rate of which exceeds max-limit. This class cannot borrow rate from its parent class

根据所耗用的带宽,每个HTB类可能处与3种状态之一。
    绿色:类的实际带宽小于等于其limit-at带宽。在这种状态下,类被附在它所在层的相应优先级的inner slot上,并被允许满足其limit-at带宽,无论它父类的限制带宽是多少。例如:如果有一个leaf classlimit-at=512000,它父类的max-limit=limit-at=128000,leaf class可以达到512kbps!
    黄色:类的实际带宽大于其limit-at,但小于等于max-limit。在此状态下,类被附于它父类inner feed的与它优先级相应的inner slot上;而父类的inner feed可能附于“祖父类”的相应优先级的inner slot(在父类也是黄色状态时)或者它(父类)所在层相应优先级的self slot(在父类是绿色状态时)上。在转换为这种状态时,类与他所在层的self feed“断开”,与他父类的inner feed“连接”。
    红色:类的实际带宽超过max-limit。这个类不能从其父类处借用带宽。




[ 本帖最后由 lemonl 于 2006-12-9 17:58 编辑 ]
routeros
 楼主| 发表于 2006-12-9 15:25:58 | 显示全部楼层

优先级

Priorities
When a leaf class wants to send some traffic (as they are the only classes that hold packets), HTB checks its priority. It will begin with the highest priority and the lowest level and proceed until the lowest priority at highest level is reached:

优先级
当一个叶类需要发送信息时(它们是唯一有数据包的一类类),HTB检查它的优先级。它从最低层的最高优先级开始处理,直到到达最高层的最低优先级。


                               
登录/注册后可看大图


As you can see from the picture, leaf-classes which are at the green state, will always have a higher priority than those which are borrowing because their priority is at a lower level (level0). In this picture, Leaf1 will be served only after Leaf2, although it has a higher priority (7) than Leaf1 (8).

In case of equal priorities and equal states, HTB serves these classes, using round robin algorithm.

如图所示,绿色状态的叶类比借用来的带宽有更高的优先级,因为他们的优先级在更低的层次(0层)。在这张图中,Leaf1将排在Leaf2之后处理,尽管他的优先级(7)高于Leaf2的(8)

在同样优先级同样状态时,HTB用依次轮流的算法服务这些队列。

[ 本帖最后由 lemonl 于 2006-12-9 15:49 编辑 ]
routeros
回复

使用道具 举报

发表于 2006-12-9 15:39:56 | 显示全部楼层
此帖必顶!
routeros
回复

使用道具 举报

 楼主| 发表于 2006-12-9 15:52:30 | 显示全部楼层

其实有部分我没看懂

谢谢版主!

谢谢vipe,借用了你的图片,呵呵

看了半天才把HTB术语大概搞懂了 ,但是HTB黄色状态部分不大懂~~
------------------
又看了一遍,HTB黄色状态也看懂了!更正了一下

[ 本帖最后由 lemonl 于 2006-12-9 17:56 编辑 ]
routeros
回复

使用道具 举报

发表于 2006-12-9 16:12:22 | 显示全部楼层
up
routeros
回复

使用道具 举报

发表于 2006-12-9 16:47:13 | 显示全部楼层
非常不错!
routeros
回复

使用道具 举报

发表于 2006-12-9 19:36:45 | 显示全部楼层
不错,但我没有多大用,我局域网有vpn网关,正在想怎样把各种数据流分开,数据被esp封装,不能分辨web、ftp、voice等
routeros
回复

使用道具 举报

发表于 2006-12-9 20:39:39 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2006-12-9 21:35:31 | 显示全部楼层
有点不明,但先顶再看吧!
routeros
回复

使用道具 举报

 楼主| 发表于 2006-12-9 22:36:02 | 显示全部楼层

带宽控制的一些概念

SFQ
Stochastic Fairness Queuing (SFQ) cannot limit traffic at all. Its main idea is to equalize traffic flows (TCP sessions or UDP streams) when your link is completely full.
The fairness of SFQ is ensured by hashing and round-robin algorithms. Hashing algorithm divides the session traffic over a limited number of subqueues. After sfq-perturb seconds the hashing algorithm changes and divides the session traffic to other subqueues. The round-robin algorithm dequeues pcq-allot bytes from each subqueue in a turn.

随机公平队列(SFQ)不能限制流量。它的主旨是在连接满载时平均流量(TCP过程或UDP流)。
SFQ的公平由散列法和循环算法保证。散列算法把流量过程分为有限的子队列。在sfq管道(sfq-perturb)时刻后散列算法改变并分割流量过程给其他子队列。循环算法按轮流顺序从每个子队列中提取pcq份额(pcq-allot)。

                               
登录/注册后可看大图

The whole SFQ queue can contain 128 packets and there are 1024 subqueues available for these packets.
Use SFQ for congested links to ensure that some connections do not starve

整个SFQ队列能容纳128个数据包,这些包可以使用1024个子队列。
在拥堵的连接上使用SFQ算法可以保证连接不被“饿死”。

PCQ

To solve some SFQ imperfectness, Per Connection Queuing (PCQ) was created. It is the only classless queuing type that can do limitation. It is an improved version of SFQ without its stohastic nature. PCQ also creates subqueues, regarding the pcq-classifier parameter. Each subqueue has a data rate limit of pcq-rate and size of pcq-limit packets. The total size of a PCQ queue cannot be greater than pcq-total-limit packets.

The following example demonstrates the usage of PCQ with packets, classified by their source address.

为了解决SFQ的缺陷,每连接队列(PCQ)被创造出来。它是唯一一种能限速的非分层队列类型。它是SFQ的改进版,去除了SFQ的随机性。PCQ也产生子队列,参见pcq-classifier参数。每个子队列有流量限制(pcq-rate)和大小限制(以包为单位的pcq-limit)。整个PCQ队列的大小不能超过pcq-total-limit数目的包。

以下例子演示了用源地址(src-address)分类时,PCQ对数据包的处理。

                               
登录/注册后可看大图

If you classify the packets by src-address then all packets with different source IP addresses will be grouped into different subqueues. Now you can do the limitation or equalization for each subqueue with the pcq-rate parameter. Perhaps, the most significant part is to decide to which interface should we attach this queue. If we will attach it to the Local interface, all traffic from the Public interface will be grouped by src-address (probably it's not what we want), but if we attach it to the Public interface, all traffic from our clients will be grouped by src-address - so we can easily limit or equalize upload for clients.

To equalize rate among subqueues, classified by the pcq-classifier, set the pcq-rate to 0!

PCQ can be used to dynamically equalize or shape traffic for multiple users, using little administration.

当用源地址(src-address)分类时,所有源地址不同的包被分到不同的子队列中。现在你可以用pcq-rate参数对每个子队列限速或平均分配。也许最重要的一步是确定应将该队列附在哪个网络界面上。如果附在内网界面,所有来自公网界面的的流量将被按源地址分组(这或许不是我们需要的),但如果把它附于公网界面,所有来自客户机的流量将被按源地址分组-这样就可以方便的限制或平均客户机的上传流量。

如要在子队列间平均流量,需要用pcq-classifier分类,并将pcq-rate设为0

PCQ可用于对多个用户动态平均或限制流量,并且基本不需管理。


[ 本帖最后由 lemonl 于 2006-12-9 22:42 编辑 ]

sfq

sfq

pcq

pcq
routeros
回复

使用道具 举报

发表于 2006-12-10 10:37:51 | 显示全部楼层
学习中。。。。
routeros
回复

使用道具 举报

发表于 2006-12-10 11:00:59 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2006-12-10 13:31:10 | 显示全部楼层
学以致用
routeros
回复

使用道具 举报

发表于 2006-12-10 19:09:53 | 显示全部楼层
不错的技术贴
routeros
回复

使用道具 举报

发表于 2006-12-10 19:35:13 | 显示全部楼层
学习学习
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-11-22 06:28 , Processed in 0.087227 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表