Don’t mix up TOS (Type of Service) and COS (Class of Service).
The first one is found in the header of an IP packet (layer 3) and the second one is found in the header of 802.1Q (layer 2). It’s used for Quality of Service on trunk links
The definition of ToS was changed entirely in RFC 2474, and it is now called Differentiated Service (DS). On the eight fields, the upper six bit contain value called Differentiated Services Code Point (DSCP). The last two bits are used for Explicit Congestion Notification and it is defined in RFC 3168.
Ping with ToS value 模拟 DSCP 值流量
Ping x.x.x.x tos 104
ToS Decimal _ DSCP Value _ Typical Servie
104 AF31 default value for UC signalling
136 AF41 default value for Video RTP
184 EF default value for Audio RTP
*TCP(四层) VS IP DSCP (三层) 的 拥塞控制 和 拥塞避免 的 同义词
Congestion Control(SS, SSthrosh, RTT timer, congestion avoidance, FastResend, FastRecovery) VS Soft Queue队列技术 (FIFO / Priority Queue / CBWFQ)
Congestion Avoidence(linear increase) VS Dropping(Taildrop / WERD)
使用 hold-queue 指令可修改 queue 长度,比如 要修 改 Egress Hardware Queue 长度,设定如下:
R2(config)#int ethernet 1/0
R2(config-if)#hold-queue 1000 out
Soft Queue:
priority
bandwidth
percentage
利用show policy-map interface 查看
如要修改,可以 random-detect precedence (IPP/DSCP)
R2(config-pmap-c)#random-detect dscp af11(DSCP值) 25(Minimum Threshold) 30(Probability Denominator) 20(Maximum Threshold)
Minimum Threshold
代表当 Queue 长度达到多少便开始执行 Drop。
Probability Denominator
要 Drop 多少个 Packet 呢?如把 Probability Denominator 设定为 10,意思是把 Queue 中每 10个 Packet 随机选 1 个 Drop 掉。如此类推。
Maximum Threshold
到 Queue 过了 Maximum Threshold,就强制发动Tail Drop 了。
Explict Congestion Notification (ECN)
虽然 Drop Packet 已经可以让 TCP Flow 被动地减 速,但除了 Drop Packet 之外,还有一个方法可让 TCP 主动减速,就是 Explicit Congestion Notification (ECN)。Software Queue 可在 Queue 即将被填满之前告诉 TCP Flow 的 Receiver Congestion 即将发生, Receiver 在收到此讯号後可 在发 TCP ACK 时告知 Sender 减速 (透过调校 Windows Size),前题是 TCP Flow 的两端 Host 都 ⽀缓 ECN。在介绍 Marking 的章节时说过 ToS 一共 有 8 Bits,DSCP 只用了前 6 Bits,最後两 Bits 就是 当作 ECN,分别是 ECN apable Transport (ECT) 和 Congestion Experienced (CE)。如 Sender 保持 ECN 则会把 ECT 设成 1,Queue 超过 Minimum Threshold 时,如 Software Queue 发现 ECT 是 1,则不 Drop Packet,反⽽会把 CE 设成 1 并传给 Receiver,藉此告知 Receiver 即将发动 Congestion。Receiver 收到 CE=1 後便会告诉 Sender 需要把传送速度降低。如 Host 不减缓 ECN (ECT=0),Software Queue 则依 WRED 设定 Drop Packet。要设定 ECN 只需在 policy-map 的 class ⾥加入 random-detect ecn。
Double policy-map in sub-interface
policy-map TRAFFIC-POLICING
class class-default
police rate 10000000
service-policy POLICY-INCOMING
When we use shaping we will buffer the traffic to a certain bitrate, policing will drop the traffic when it exceeds a certain bitrate. The difference between the two is that policing will drop the exceeding traffic and shaping will buffer it.
It’s also possible that they shape it down to 10 Mbit but shaping means they have to buffer data while policing means they can just throw it away. The 10 Mbit that we pay for is called the CIR (Commited Information Rate).
There are two reasons why you might want to configure shaping:
Instead of waiting for the policer of the ISP to drop your traffic, you might want to shape your outgoing traffic towards the ISP so that they don’t drop it.
To prevent egress blocking. When you go from a high speed interface to a low speed interface you might get packet loss (tail drop) in your outgoing queue. We can use shaping to make sure everything will be sent (until its buffer is full).
To check if traffic matches the traffic contract the policer will measure the cumulative byte-rate of arriving packets and the policer can take one of the following actions:
Allow the packet to pass.
Drop the packet.
Remark the packet with a different DSCP or IP precedence value.
When working with policing there are three categories that we can use to see if a packet conforms the traffic contract or not:
Conforming
Exceeding
Violating
LLQ (Low Latency Queuing) is an extension of CBWFQ (Class Based Weighted Fair Queuing) where we add a priority queue to the scheduler.
x% Bandwidth / Priority
Bandwidth command defines what is the minimum bandwidth reserved for a specific class when the network is congested.
Priority command defines what is the maximum bandwidth reserved for a specific class when the network is congested
DSCP值will pass onto IPSec 包头 if with Tunnel mode
DSCP值will pass into MPLS-VPN 标签 exp 值
整形和策略之间的主要区别就是补充令牌的速率。此部分将说明这一区别。
简而言之,整形和策略都使用了令牌桶这一比喻性概念。令牌桶本身没有丢弃或优先级策略。下面我们来看看令牌桶的工作原理:
令牌以一定的速率被放到桶。
每个令牌是来源的权限发送一定数量的位到网络。
要发送信息包,数据流调整器一定能从桶去除一定数量的令牌相等在表示法与信息包大小。
如果没有足够的令牌在发送信息包的桶,信息包二者之一等待,直到桶有足够的令牌(一旦成型机)或丢弃信息包或标得下来(一旦策略器)。
桶本身具有指定的容量。如果桶填装对容量,丢弃最近到达的令牌并且对将来信息包不是可用的。因此,在任何时间,最大破裂了来源能发送到网络是大致成比例的对桶的大小。令牌桶允许突变流量,但会对其进行限制。
有令牌桶比喻的念头,请查看多么整形和策略请添加令牌到桶。
整形增加令牌桶在计时的间隔使用比特/秒(bps)值。整形器使用以下公式:
Tc = Bc/CIR (in seconds)
在此等式中,Bc 表示承诺突发流量,CIR 表示承诺信息速率。Tc 值定义了为维持 CIR 的平均速率,要在其间发送 Bc 比特流量的时间间隔(以秒计)。
Tc 的范围在 10 毫秒到 125 毫秒之间。使用在Cisco 7500系列的分布式流量整形,最小数量Tc是4ms。路由器会基于 CIR 和 Bc 值在内部计算此值。如果Bc/CIR少于125ms,使用从该等式计算的Tc。如果 Bc/CIR 大于或等于 125 ms, 则Cisco IOS 认为较小的时间间隔会使数据流更稳定,则会使用内部 Tc 值。请使用show traffic-shape命令确定您的路由器是否使用您配置在命令行的一个内部值Tc或值。下面是 show traffic-shape 命令的示例输出
当 Burst Excess (Be) 跟被配置不为0时,成型机在桶允许令牌存储,至Bc+Be。令牌桶能达到的大价值是Bc+Be和溢出令牌丢弃。有的唯一方法更多比在桶的BC令牌是不使用所有BC令牌在一个或更多期间Tc。因为令牌桶被重新补充与BC令牌的每个Tc,您能累计未使用的令牌为以后使用至Bc+Be。
1 Byte == 8 Bits