srTCM和trTCM介绍

本文是用于QoS Meter功能的算法的RFC的阅读笔记。DPDK的QoS_meter示例程序用的就是这个算法。

srTCM

srTCM的英文全称是Single Rate Three Color Marker,单速率三颜色标记

Configuration

该算法要预先在系统中设定三个参数,三个参数如下:

  • Committed Information Rate(CIR),提交信息率。
  • Committed Burst Size(CBS),提交Burst大小。
  • Excess Burst Size(EBS),超量Burst大小。

CIR用于表示每秒IP包的字节数,header包括在内。bytes of IP packets per second, it includes the IP header

CBS和EBS以字节为单位。必须被设置。推荐值:它们之一必须大于0,且若大于0的CBS和EBS,值要大于MTU。

颜色有三种:绿、黄、红。简单来说,颜色与参数的对应关系是这样的:

  • 如果没有超过CBS就是绿的。
  • 超过了CBS但没有超过EBS就是黄的。
  • 超过了EBS就是红的。

Metering & Marking

算法流程图长这样:

                +------------+
                |   Result   |
                |            V
            +-------+    +--------+
            |       |    |        |
Packet Stream ===>| Meter |===>| Marker |===> Marked Stream
            |       |    |        |
            +-------+    +--------+

Meter(限速器)用于限速,具体的逻辑因不同的具体设定而异(例如,红色丢包,黄色正常发送,绿色往特定队列发送等)。而且Meter会对每一个packet进行计算,将得到的结果交给Marker(标记器)。Marker收到的是每一个packet和其对应的结果值,根据计算结果在所有packet的IP header的DS field中标记上不同的“颜色”(上色,mark,或者说tag)。

Meter有两种工作模式:

  1. 色盲模式(Color-Blind mode),假定所有incoming packet是无色的。
  2. 非色盲模式(Color-Aware mode),假定所有incoming packet已经被先前的网络元素上了色。如果Meter工作在非色盲模式,它会认为每一个packet都有一种颜色,要么绿要么黄要么红。

Meter动作由两个令牌桶来表示(C和E)。C和E有共同的CIR。令牌桶的C的size是CBS,E的size是EBS。

用Tc(t)表示t时刻,令牌桶C中有的令牌数量,Te(t)同理。起始时,Tc(0)=CBS,Te(0)=EBS。

之后,每秒钟都执行CIR次如下操作:若令牌桶不满,则令牌数量自增1,先增加Tc后增加Te:

  • If Tc is less than CBS, Tc is incremented by one, else
  • if Te is less then EBS, Te is incremented by one, else
  • neither Tc nor Te is incremented.

Meter的工作算法如下:

如果工作在色盲模式下,且大小为B字节的包在t时间到达,算法工作如下:若令牌桶C足以让B通过,则tag此包为绿色,并减去对应的Tc;若C不足以让B通过而E足以让B通过,则tag此包为黄色,并减去对应的Te;否则tag此包为红色。

  • If Tc(t)-B >= 0, the packet is green and Tc is decremented by B down to the minimum value of 0, else
  • if Te(t)-B >= 0, the packets is yellow and Te is decremented by B down to the minimum value of 0, else
  • the packet is red and neither Tc nor Te is decremented.

如果工作在非色盲模式下,大小为B字节的包在t时间到达,算法工作如下:若包先前tag成绿色,且令牌桶C足以让B通过,则此包依旧tag成绿色,减去对应的Tc;若令牌桶C不足以让B通过,且该包先前tag的是绿色或黄色,且令牌桶E足以让B通过,就tag成黄色,并减去对应的Te;否则(两种情况:先前此包tag成红色或令牌桶E不足以让B通过)tag为红色。

  • If the packet has been precolored as green and Tc(t)-B >= 0, the packet is green and Tc is decremented by B down to the minimum value of 0, else
  • If the packet has been precolored as green or yellow and if Te(t)-B >= 0, the packets is yellow and Te is decremented by B down to the minimum value of 0, else
  • the packet is red and neither Tc nor Te is decremented.

trTCM

全称 Two Rate Three Color Marker ,双速率三颜色标记。基本思路和srTCM相同,有一些细节上的差异。

Configuration

四个参数

  1. Peak Information Rate (PIR),峰值信息率。
  2. Peak Burst Size (PBS),峰值Burst大小。
  3. Committed Information Rate (CIR),提交信息率。
  4. Committed Burst Size (CBS),提交Burst大小。

PIR和CIR用于表示每秒IP包的字节数。PBS和CBS以字节为单位,必须大于0,推荐设置成大于当前路径MTU。

简单来说,pkt的颜色和四个参数的对应关系是:若packet超过PIR,则标记为红色。若没有超过PIR,则看packet是否超过了CIR,若超过,则标记为黄色;若没有超过则标记为绿色。

A packet is marked red if it exceeds the Peak Information Rate (PIR). Otherwise it is marked either yellow or green depending on whether it exceeds or doesn't exceed the Committed Information Rate (CIR).

Metering & Marking

Meter同样分为色盲模式和非色盲模式。

由两个令牌桶来表示,P和C。P和C的速率分别是PIR和CIR,大小分别是PBS和CBS。起始时,Tp(0)=PBS,Tc(0)=CBS。之后,若令牌桶没满,则桶P递增1,每秒PIR次。桶C递增1,每秒CIR次。

Thereafter, the token count Tp is incremented by one PIR times per second up to PBS and the token count Tc is incremented by one CIR times per second up to CBS.

工作算法如下:

如果工作在色盲模式下,且大小为B字节的包在t时间到达,算法工作如下:若令牌桶P不足以让B通过,则tag为红色,否则:若令牌桶C不足以让B通过,则tag为黄色且扣除桶P的令牌;若令牌桶C足以让B通过,则tag为绿色且同时扣除桶C和桶P的令牌。

  • If Tp(t)-B < 0, the packet is red, else
  • if Tc(t)-B < 0, the packet is yellow and Tp is decremented by B, else
  • the packet is green and both Tp and Tc are decremented by B.

如果工作在非色盲模式下,大小为B字节的包在t时间到达,算法工作如下:若先前tag成红色,或令牌桶P不足以让B通过,则tag为红色,否则:若先前tag成黄色,或令牌桶C不足以让B通过,则tag为黄色且扣除桶P的令牌;若令牌桶C足以让B通过且先前标记成绿色,则tag为绿色且同时扣除桶C和桶P的令牌。

  • If the packet has been precolored as red or if Tp(t)-B < 0, the packet is red, else
  • if the packet has been precolored as yellow or if Tc(t)-B < 0, the packet is yellow and Tp is decremented by B, else
  • the packet is green and both Tp and Tc are decremented by B.

Service Example

实际的QoS Meter实现可能仅是对RFC的参照而不一定完全一样(The actual implementation of a Meter doesn't need to be modeled according to the above formal specification.)

应用程序可以根据 DS field 里 tag 上的 color 对 packet 做合适的调度,例如:

For example, a service may discard all red packets, because they exceeded both the committed and excess burst sizes, forward yellow packets as best effort, and forward green packets with a low drop probability.

总结

可以看出srTCM算法是根据 length of burst 来进行限速的。“单速率”指的是这个算法里两个令牌桶的增长速率都是一样的每秒CIR。两个令牌桶拥有不同的大小,就好像一条数轴用两个点分成了三个阶段,对应绿、黄、红。

trTCM的“双速率”是指两个令牌桶有不同的增长速率。增长的较慢的令牌桶是发放绿色标记的较为严苛的指标,增长的较快的令牌桶是一个下限,若这个令牌桶也handle不过来的流量就要无情的tag为红色,两者之间的就是黄色。

Reference

RFC 2697 and 2698

posted @ 2018-08-09 21:44  畅畅1  阅读(4609)  评论(0编辑  收藏  举报