CCIE知识点总结——QoS

1、为什么需要QoS?

网络设备都是尽最大努力传输数据,提供最大化服务的网络被称为尽力而为服务的网络。
在尽力而为服务的网络中,所有的数据都被看成是同等重要的,用户的数据有时无法得到保证,所以在某些时候,必须让网络通过放弃传输相对不重要的数据来保证用户的重要数据和传输。因此,就需要在网络中实施Quality of Service,即QoS。
任何业务都按实际信息量来占用资源,使网络资源得到最大限度的利用。
网络融合,各种通信流量都采用网络来传递,如电信网、广播电视网、互联网的三网融合。

2、QoS 模型

(1)Best-Effort Service:尽力而为服务模型
在尽力而为服务模型中,所有网络设备全部都是尽自己最大努力传输数据,所有数据尽管传,不需要得到许可,有多少传多少,任何数据都不能得到保证,延迟也无法预计,所以尽力而为服务模型,其实并没有实施任何QoS,默认的网络都工作在这种模型下。
(2)Integrated Service:综合服务模型,简称Intserv
在实施了综合服务模型QoS的网络中,应用程序在发送数据之前,必须先向网络申请带宽。 但是如果某些程序在连接之前没有向网络申请带宽,那么它的流量只能得到尽力而为的服务。在综合服务模型中,重要的数据可以通过申请带宽而得到保证,但是在传送之前必须申请,也需要耗费额外一些时间。在申请带宽时,所用到的协议为Resource Reservation Protocol (RSVP) 。在现有的网络中,综合服务模型的QoS通常并不被采用。
(3)Differentiated Service:区分服务模型,简称Diffserv
在实施了区分服务模型QoS的网络中,网络将根据不同数据提供不同服务,因此,所有数据都被分成不同的类别,或者设置为不同的优先级,在网络发生拥塞时,网络总是先保证传输高优先级的数据,从而放弃传输低优先级的数据,但是在网络没有拥塞时,所有数据全部照常传输。现在的网络中,实施QoS时通常采用区分服务模型。

3、实现QoS策略的方法

(1)CLI:一种传统的方法,非模块化,不能通过定义策略分离流量。
例如:

interface Multilink1
 ip address 10.1.61.1 255.255.255.0
 ip tcp header-compression iphc-format   TCP头部压缩
 load-interval 30
 custom-queue-list 1
 ppp multilink
 ppp multilink fragment-delay 10
 ppp multilink interleave
 multilink-group 1
 ip rtp header-compression iphc-format     RTP头部压缩

(2)MQC:模块化QoS
MQC可以配置对特定的数据采取特定的动作,步骤为三步:定义流量(class-map)、设置策略(policy-map)、应用策略(service-policy)。
例如:

class-map VoIP-RTP
 match access-group 100
class-map VoIP-Control
 match access-group 101
!
policy-map QoS-Policy
 class VoIP-RTP
  priority 100
 class VoIP-Control
  bandwidth 8
 class class-default
  fair-queue
!
interface serial 0/0
 service-policy output QoS-Policy
!
access-list 100 permit ip any any precedence 5
access-list 101 permit tcp any host 10.1.10.20 range 2000 2002

(3)AutoQoS VoIP (Voice QoS)
Auto QoS支持在LAN和WAN环境部署,路由器可以部署企业应用QoS策略处理语音,视频和数据流量,交换机可以通过单条命令部署QoS策略。

4、区分服务模型 Differentiated Services Model

区分服务模型描述了与流量分类相关的服务。
在网络边缘执行复杂的分类机制,使用DSCP来标记。
在这里插入图片描述
DiffServ字段:IPv4 和 IPv6头部中的8位-RFC 2474。
取前3bit定义IP优先级。
取前6bit定义DSCP值。

为不同标记的流量设置策略-PHB(per-hop behaviors)。
DSCP差分服务代码点(Differentiated Services Code Point)
在这里插入图片描述
当需要使用MQC的方式去部署QoS时,对流量分类之后,需要为不同的数据包打上不同的优先级,当路由器收到带有优先级的数据包,可以根据这些优先级来决定数据转发的优先顺序。
如何在数据包的包头去标记这个优先级,使用DSCP进行标记。
当路由器收到带有优先级的数据包,根据数据包不同的优先级,执行不同的策略,这种行为叫做PHB(每一跳行为)。
ToS:type of service总共是8bit,用于标识IP包头数据包的优先级【网络层】
CoS:class of service总共是8bit,用于标识数据帧头的优先级【数据链路层】
ToS字段,用2种方式来标记:
(1)IPP:使用高3bit,剩余5bit都为0。可以表示8种(2^3),0~7来表示。
IPP0 IPP1 IPP2 IPP3….IPP7,值越大 优先级就越大,优先被转发。
(2)DSCP:使用高6bit,剩余2bit都为0,高6bit中,最后一个bit始终为0。
1)default PHB:6个bit全0,1个类别。
2)EF:101110,1 个类别(Expedited Forwarding 加速转发)

-确保最小的时延(Voice、实时流量)
-保证带宽(保证该类别流量带宽,可优先转发)
-管制带宽(该类别流量不能超过保证带宽,超过的流量将被丢弃)
3)AF:12个类别(Assured Forwarding 保证转发)

−保证带宽
−当网络没有发生拥塞时,允许占用额外的带宽
−四个标准类(af1, af2, af3, and af4)
– AF1:001010、001100、001110 AF11 AF12 AF13
– AF2:010010、001100、001110
– AF3:011010、001100、001110
– AF4:100010、001100、001110
每个AF类使用三个DSCP值。每个AF类有独立的转发机制和带宽保证。后面两个值越大,丢弃的可能性就越高。
4)CS (Class-Selector),兼容IP Precedence,也使用高3bit,其余为0,8个类别。是IP优先级和DSCP值的映射,CS值越大,转发时间越小。
在这里插入图片描述
0~7,CS0、CS1、CS2…CS7 值越大 优先级就越大,优先被转发。
ToS=IPP * 32=DSCP * 4
(3)汇总

5、QoS机制

(1)Classification 分类:将数据分为不同的类别

分类是识别和分离不同类别的流量。流量可以通过各种方式进行分类,包括DSCP。Modular QoS CLI 允许通过执行策略进行分类。
配置如下:

router(config)# class-map [match-any | match-all] class-map-name
router(config-cmap)# match condition
router(config-cmap)# match class-map class-map
router(config-cmap)# match not match-criteria
router(config-cmap)# match any

例如:

class-map Well-known-services
  match access-group 100
!
Class-map Unknown-services
  match not class-map Well-known-services
!
Class-map All-services
  match any
!
access-list 100 permit tcp any any lt 1024
access-list 100 permit tcp any lt 1024 any
router(config-cmap)# match input-interface interface-name

例如:

class-map match-any Ethernets
  match input-interface Ethernet0/0
  match input-interface Ethernet0/1
!
class-map match-any FastEthernets
  match input-interface FastEthernet1/0
  match input-interface FastEthernet1/1
!
class-map match-any Serials
  match input-interface Serial2/0
  match input-interface Serial2/1
  match input-interface Serial2/2
  match input-interface Serial2/3
router(config-cmap)# match cos cos-value [cos-value cos-value cos-value]

例如:

class-map Strict-priority
  match cos 5
!
class-map High-priority
  match cos 4 6 7
!
class-map Low-priority
  match cos 0 1 2 3
router(config-cmap)# match access-group {number | name} [name]

例如:

class-map Telnet
  match access-group 100
!
access-list 100 permit tcp any any eq 23
access-list 100 permit tcp any eq 23 any
router(config-cmap)# match ip precedence ip-prec-value [ip-prec [ip-prec [ip-prec]]]

例如:

class-map VoIP
  match ip precedence 5
!
class-map Mission-Critical
  match ip precedence 3 4
!
class-map Transactional
  match ip precedence 1 2
!
class-map Best-Effort
  match ip precedence routine
router(config-cmap)# match ip dscp ip-dscp-value [ip-dscp-value ...]

例如:

class-map Voice
  match ip dscp ef cs5
!
class-map Mission-Critical
  match ip dscp af31 af32 af33 cs3
!
class-map Transactional
  match ip dscp af21 af22 af23 cs2
!
class-map Bulk
  match ip dscp af11 af12 af13 cs1
!
class-map Best-Effort
  match ip dscp default
router(config-cmap)# match ip rtp starting-port-number port-range

例如:

class-map RTP
  match ip rtp 16384 16383
router# show class-map [class-map-name]

例如:

router#show class-map
 Class Map match-any class-default (id 0)
   Match any 

 Class Map match-all Well-known-services (id 2)
   Match access-group  100 

 Class Map match-any All-services (id 4)
   Match class-map Well-known-services
   Match class-map Unknown-services

 Class Map match-all Unknown-services (id 3)
   Match not class-map Well-known-services

NBAR:Network-Based Application Recognition
NBAR 基于网络层的应用识别。
NBAR 解决了如何分类client/server 和 web-based applications的问题。
NBAR 执行以下功能:识别应用和协议 (Layer 4 to Layer 7),协议发现,提供流量统计。
通过 NBAR对流量进行归类,能够对这些类执行random early detection, class-based queuing, and policing QoS 的PHP行为。新的应用程序很容易支持加载PDLM(数据包描述语言模块)。
NBAR 可以用于分类的的应用程序:
1)静态分配的TCP和UDP端口号。
2)非UDP和非TCP IP协议。
3)连接建立过程中协商动态分配的TCP和UDP端口号(需要状态检测)。
4)子端口分类:HTTP分类(URLs MIME or host names …) 。
5)MIME:多用途互联网邮件扩展类型,设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开,多用于指定一些客户端自定义的文件名,以及一些媒体文件。
6)分类基于深度包检测和多个应用程序特定的属性(RTP payload classification)。
PDLM(Packet Description Language Module):
PDLM从路由器的闪存种加载,对新的协议或应用程序的识别。
可以在运行时加载扩展PDLM,用于识别新的协议和应用。
可用于增强现有的协议识别能力。
PDLMs允许NBAR在不使用新的IOS下,进行识别新的协议。
PDLMs 必须有思科工程师进行生产。
目前可提供的PDLMs包括:
1)Peer-to-peer file-sharing applications – KaZaa, Morpheus, Grokster, and Gnutella
2)Citrix
3)Novadigm Enterprise Desktop Manager
协议发现Protocol Discovery:
协议发现实时分析应用流量模式,发现在网络上运行的流量。
提供双向,每个接口,每个协议的统计信息:
5-minute bit rate (bps),Packet counts,Byte counts。
重要的监测工具(支持Cisco QoS管理工具)。
生成实时应用统计。
在关键网络位置提供流量分布信息。
配置协议发现:

router(config-if)# ip nbar protocol-discovery

监控协议发现:

Router# show ip nbar protocol-discovery

为状态化的协议配置NBAR:

router(config-cmap)# match protocol protocol
router(config)# ip nbar port-map protocol [tcp | udp] new-port [new-port ...]
router(config)# ip nbar pdlm pdlm-file
R1#show ip nbar port-map 
port-map bgp                      udp 179 
port-map bgp                      tcp 179 
port-map dhcp                     udp 67 68 
port-map dns                      udp 53 
port-map dns                      tcp 53
port-map pop3                     udp 110 
port-map pop3                     tcp 110 
port-map rip                      udp 520 

R1(config-cmap)#match protocol ?
  aarp              AppleTalk ARP
  appletalk         AppleTalk
  arp               IP ARP
  bgp               Border Gateway Protocol
  bittorrent        bittorrent
  bridge            Bridging
  bstun             Block Serial Tunnel
  cdp               Cisco Discovery Protocol
router(config-cmap)# match protocol http url url-string
router(config-cmap)# match protocol http host hostname-string
router(config-cmap)# match protocol http mime MIME-type
router(config-cmap)# match protocol fasttrack file-transfer "regular-expression"
router(config-cmap)# match protocol rtp [audio | video | payload-type payload-string]

例如:

(2)Marking 标记:将数据设置为不同的优先级

标记,也被称为着色(coloring)。根据不同类别的流量给每个数据包标记,使得分类的流量在网络种传输时,能够被快速识别。
Class-based marking 是与MQC提供一个额外的工具,它允许静态分类标记的数据包。
它可以用来标记入站或出站数据包。 它可以结合任何其它出方向的QoS 特性。它可以结合任何其它进方向基于类的管制。先在接口上配置CEF,才能保证基于类的数​​据包标记的功能都可以使用。
数据包可以打上以下标志之一:IP precedence;IP DSCP;QoS group;MPLS experimental bits;IEEE 802.1Q or ISL CoS/priority bits;Frame Relay DE bit;ATM CLP bit。
配置基于类的标记:(基于类的标记可以标记进入的包和出去的包,CEF必须开启)

router(config)# class-map {match-any | match-all} class-map-name
router(config)# policy-map policy-map-name
router(config-if)# service-policy {input | output} policy-map-name

例如:

class-map Well-known-services
  match access-group 100
!
class-map Unknown-services
  match not class-map Well-known-services
!
policy-map set-DSCP
  class Well-known-services
    set DSCP AF21
  class Unknown-services
    set DSCP 0
!
access-list 100 permit tcp any any lt 1024
access-list 100 permit tcp any lt 1024 any
!
Interface ethernet 0/0
 service-policy input set-DSCP

配置基于CoS的标记:

router(config-pmap-c)# set cos cos-value

例如:

policy-map SetCoS
 class Class1
  set cos 1
 class Class2
  set cos 2  
 class Class3
  set cos 3

配置IP Precedence标记:

router(config-pmap-c)# set ip precedence ip-precedence-value

例如:

policy-map SetPrec
 class Class1
  set ip precedence priority
 class Class2
  set ip precedence flash
 class Class3
  set ip precedence 5

配置IP DSCP标记:

router(config-pmap-c)# set [ip] dscp ip-dscp-value

例如:

policy-map SetDSCP
 class Class1
  set ip dscp af11
 class Class2
  set ip dscp af21
 class Class3
  set ip dscp ef

监控基于类的标记:

Router# show policy-map [policy-map]
Router# show policy-map interface interface-name

例如:

router#show policy-map

Policy Map SetCoS
    Class Class1
      set cos 1
    Class Class2
      set cos 2
    Class Class3
      set cos 3
    Class Class4
      set cos 4
    Class Class5
      set cos 5
    Class Class6
      set cos 6
    Class Class7
      set cos 7

router#show policy-map interface serial 0/0
 Serial0/0
  Service-policy input: SetMPLS (1837)
    Class-map: Class1 (match-any) (1839/12)
      0 packets, 0 bytes
      30 second offered rate 0 bps, drop rate 0 bps
      Match: qos-group 1 (1843)
        0 packets, 0 bytes
        30 second rate 0 bps
      QoS Set
                mpls experimental 1

(3)Congestion Management 拥塞管理

每个接口有一个队列机制,当网络拥塞发生时,规定数据以什么样的先后顺序传输。每个物理接口,有1个硬件队列和N个软件队列。当网络产生拥塞时,决定如何从软件队列调度数据包到硬件队列拥塞管理是根据每个数据包上的标记,以确定在哪个队列放置数据包。拥塞管理一般采用先进的队列技术,如WFQ和LLQ,以确保对时间敏感型的流量能够被优先传送,例如语音流量被首先发送。
队列算法:FIFO;PQ;Round robin;WRR;DRR;WFQ;CBWFQ;LLQ。
(1)FIFO:先进先出,只有一个队列,所有数据包都是平等,硬件队列始终使用FIFO的队列技术。缺点:当网络产生拥塞时,不能保证关键业务数据被优先发送。
(2)PQ:优先级队列,多个队列,有优先级,解决FIFO的问题,当网络产生拥塞时,可以优先调度高优先级的数据。缺点:如果高优先级队列一直存在数据包,可能导致低优先级的队列出现饿死的现象。
PQ队列用于传输对时延比较敏感的流量,例如Voice流量。
(3)RR 轮询队列
有多个队列,但是没有优先级,可以解决PQ队列的问题,可以保证每个队列都能够被调度。缺点:太公平了,调度的时候无法保证调度更多的关键业务的流量
(4)WRR 基于权重轮询队列
多个队列,也有优先级概念,调度的时候,每个队列调度的数据包个数不同。可以保证重要数据每次调度时,比普通流量调度的更多。调度时,可以基于字节数或者数据包的个数来进行调度。缺点:调度不精确。
(5)DRR 赤字轮询队列
能够缓解调度不精确的问题,但不能根本上去解决。
(6)WFQ 加权公平队列
共享带宽,系统自动分配队列,根据不同的数据流,通过hash函数,将不同的数据流放入到不同的队列。根据队列的优先级,分配带宽。
队列算法是通过在共享带宽之间公平的流动:高优先级分配带宽多,低优先级分配带宽少,各优先级队列都能分配到带宽。为交互式流量(QQ telnet)缩短响应时间,将它们安排到队列的前面。WFQ在根据IP优先级给数据包分配带宽时,是基于流(flow)来分配的,防止占用高带宽的流量占用整个接口。不公平是通过引入权重比例,给予高优先级更多的带宽流量。相同流的数据包最终在同一个队列中。ToS字段是可能改变的唯一参数,让相同流量的数据包进入不同的队列。
配置基于每个流队列一个固定传输值,利用哈希函数将每个数据流转化为一个队列号,系统包(8个队列)和RSVP流量(如果配置)被映射到不同的队列。可以将两个或更多的流量可以映射到相同的队列中,从而降低每个流的带宽。配置队列的数目必须大于流的预期数目。
HQO(hold-queue out):是WFQ系统可以容纳的最大数量是数据包,出接口buffer大小。 HQO默认是1000,Output queue: 0/1000/64/0 (size/max total/threshold/drops)。
CDT(congestion discard threshold):拥塞丢弃门限 WFQ开启选择性丢弃流量的一个阀值。
Finish Time计算:第1个数据包的FT:FT=到达的时刻加上包长;第2个数据包的FT:FT=等于第1个数据包的FT值加上第2个数据包的包长。
基于权重的Finish Time计算:第1个数据包的FT:FT=到达的时刻加上虚拟包长;第2个数据包的FT:FT=等于第1个数据包的FT值加上第2个数据包的虚拟包长。
WFQ的丢弃策略:
WFQ有两种丢弃模式:
0~CDT:不丢弃。
CDT~HQO选择性丢弃:如果到达的数据包具备最大的FT值,则丢弃,否则不丢弃。
大于HQO,始终要丢弃:如果到达的数据包具备最大的FT值,则丢弃。如果到达的数据包不具备最大的FT值,丢弃队列中FT值最大的数据包。
注:数据包越大,FT值就越大。
优先级高的数据包,长度越长,导致它的FT值更大
优先级低的数据包,长度较短,导致他的FT值更小
则容易造成高优先级的数据包被优先丢弃
解决方法:
通过虚拟包长,丢弃低优先级的流量
虚拟包长=实际包长/(优先级+1)
(分母是1~8,有可能会出现除不尽,使用32384 最小公倍数来解决)
默认情况下,如果接口带宽小于2.048M,运行WFQ,如果大于2.048M,运行FIFO。
异常的丢弃机制:
1)数据包分类到一个空的子队列将永不丢弃。
2)数据包的优先级对丢弃方案没有影响。
WFQ的配置:

router(config-intf)# fair-queue [cdt [dynamic-queues [reservable-queues]]]
router(config-if)# hold-queue max-limit out
router# show interface interface
router# show queue interface-name interface-number

例如:

Router(config-if)#fair-queue 100 512 修改CDT值为100,修改动态队列个数为512
Router(config-if)#hold-queue 2000 out 修改HQO值为2000 
Router(config)#int f0/0
Router(config-if)#fair-queue 定义该接口队列使用WFQ

WFQ的优点:
1)配置简单 (不需要配置分类,系统自动进行hash分类);
2)保证所有流量的吞吐量;
3)丢弃FT值最大的数据包;
4)支持大多数平台;
5)支持所有的IOS版本。
WFQ的缺点:
1)多个流可以在一个队列中,或者一个流在多个队列种(TOS值不同);
2)不支持配置分类;
3)不能提供固定的带宽保证;
4)复杂的分类和调度机制。
(7)CBWFQ 基于类的加权公平队列
CBWFQ 能够用于提供固定带宽保证。CBWFQ扩展了标准WFQ功能,提供用户自定义流量类别的支持。 可以基于用户定义的匹配条件进行分类。数据包满足匹配条件构成了流量的类别。 队列是保留给每一个类,属于同一类的流量被引导到优先级队列。
CBWFQ的配置:

router(config-pmap-c)# bandwidth bandwidth
router(config-pmap-c)# bandwidth percent percent
router(config-pmap-c)# bandwidth remaining percent percent
router(config-pmap-c)# queue-limit queue-limit
router(config-pmap-c)# fair-queue [number-of-dynamic-queues]
router# show policy-map interface [interface]

例如:

Router(config)# access-list 101 permit udp host 10.10.10.10 	host 10.10.10.20 range 16384 20000
Router(config-if)# access-list 101 permit udp host 	10.10.10.10 host 10.10.10.20 range 53000 56000
Router(config)# class-map class1
Router(config-cmap)# match access-group 101
Router(config-cmap)# exit
Router(config-cmap)# class-map class2
Router(config-cmap)# match access-group 102
Router(config-cmap)# exit

Router(config)# policy-map policy1
Router(config-pmap)# class class1
Router(config-pmap-c)# bandwidth 3000
Router(config-pmap-c)# queue-limit 30
Router(config-pmap-c)# exit
Router(config-pmap)# class class2
Router(config-pmap-c)# bandwidth 2000
Router(config-pmap-c)# exit

router#show policy-map interface
 FastEthernet0/0
  Service-policy output: Policy1
    Class-map: Class1 (match-any)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any
      Weighted Fair Queueing
        Output Queue: Conversation 265
        Bandwidth remaining 20 (%) Max Threshold 64 (packets)
        (pkts matched/bytes matched) 0/0
        (depth/total drops/no-buffer drops) 0/0/0
    Class-map: class-default (match-any)
      42 packets, 4439 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any

(8)LLQ(Low-Latency Queuing)低延迟队列
LLQ的配置:

router(config-pmap-c)# priority bandwidth [burst]
router(config-pmap-c)# priority percent percentage [burst]
router# show policy-map interface interface

例如:

class-map voip
 match ip precedence 5
!
class-map mission-critical
 match ip precedence 3 4
!
class-map transactional
 match ip precedence 1 2
!
policy-map Policy1
  class voip
   priority percent 10
  class mission-critical
   bandwidth percent 30
   random-detect
  class transactional
   bandwidth percent 20
   random-detect
  class class-default
   fair-queue
   random-detect

Router#show policy-map interface fastethernet 0/0
 FastEthernet0/0
  Service-policy output: LLQ
    Class-map: LLQ (match-any)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any
      Weighted Fair Queueing
        Strict Priority
        Output Queue: Conversation 264
        Bandwidth 1000 (kbps) Burst 25000 (Bytes)
        (pkts matched/bytes matched) 0/0
        (total drops/bytes drops) 0/0

    Class-map: class-default (match-any)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any

(4)Congestion Avoidance 拥塞避免

当网络发送拥塞时,如何丢弃数据包,避免网络产生拥塞。当预先定义的队列达到所限制的阀值,拥塞避免可能随机丢弃数据包。在“更早的时候”开始丢包,拥塞避免有助于防止网络中的下游瓶颈。
当路由器接口输出队列已满时,接口发生拥塞,后续传入的数据包将被尾丢弃。
尾丢弃有显著的缺点,被丢弃的数据包可能会导致重要应用程序的性能下降。
(1)RED(Random Early Detection)随机早期检测
如果可以防止队列拥塞,则可以避免尾丢弃。RED 就是在队列满之前,进行随机丢弃数据包的机制。RED 当平均队列长度增加时,丢弃率也随着增加。
RED的结果:放慢TCP的会话,发送数据包的速率接近出口带宽速率。减小平均队列(比最大队列大小要少得多)。通告随机丢弃,能够避免大量TCP会话同步。
(2)WRED(Weighted Random Early Detection)基于权重的随机早期检测
每个profile包含有:最小阈值,最大阈值,最大丢弃概率。
CB-WRED(Class-based Weighted Random Early Detection)的配置:

router(config)# class-map [match-any | match-all] class-name
router(config)# policy-map policy-name
router(config-if)# service-policy {input | output} policy-map-name
router(config-pmap-c)# random-detect
router(config-pmap-c)# random-detect precedence precedence min-threshold max-threshold mark-prob-denominator
router(config-pmap-c)# random-detect exponential-weighting-constant n

基于IPP的CB-WRED示例:

基于DSCP的CB-WRED配置:

router(config-pmap-c)# random-detect dscp-based
router(config-pmap-c)# random-detect dscp dscpvalue min-threshold max-threshold mark-prob-denominator

基于DSCP的CB-WRED配置:

验证CB-WRED:

router# show policy-map interface interface-name

例如:

router#show policy-map interface Ethernet 0/0
 Ethernet0/0
  Service-policy output: Policy1
    Class-map: Mission-critical (match-all)
      0 packets, 0 bytes  5 minute offered rate 0 bps, drop rate 0 bps
      Match: ip precedence 2  Match: ip dscp 18  20  22
      Weighted Fair Queueing
        Output Queue: Conversation 265
        Bandwidth 30 (%)  Bandwidth 3000 (kbps)
        (pkts matched/bytes matched) 0/0
        (depth/total drops/no-buffer drops) 0/0/0
        exponential weight: 9
        mean queue depth: 0
    Dscp     Transmitted Random drop Tail drop   Minimum   Maximum     Mark
    (Prec)   pkts/bytes  pkts/bytes  pkts/bytes  threshold threshold probability
      0(0)       0/0	0/0	0/0         20        40       1/10
      1          0/0	0/0 	0/0         22        40       1/10
      2          0/0	0/0 	0/0         24        40       1/10

(3)ECN(Explicit Congestion Notification)
ECN 显示拥塞通知。TCP拥塞控制不适合那些对时延敏感数据包的应用程序。 当平均队列长度超过特定阈值时,ECN是标记数据包并不是丢弃数据包。路由器和终端主机可以使用ECN标记作为一个信号,即在网络拥塞,以较慢的速度发送数据包。
ECN 是对WRED的扩展。WRED的拥塞,是当平均队列长度超过一个特定的阈值。如果数据包在队列中的数量低于最小阈值时,数据包被发送。如果数据包在队列中的数量高于最大阈值时,数据包被尾丢弃。
如果数据包在队列中的数字为最小和最大阈值之间,三种情形之一可能会发生:
1)终端主机支持ECN,(ECT=1,CE=0 或者ECT=0,CE=1)并且是基于WRED,则该数据包的丢弃率将下降。将数据包的ECT 和CE 位置为1 ,数据包被发送. 这是因为ECN被启用,数据包被标记代替了被丢弃。
2)终端主机不支持ECN:数据包的ECT 和CE 位置为0.该数据包可以根据WRED的丢弃概率被丢弃。这是当WRED上没有启用ECN的路由器上,收到的数据包受到相同的待遇
3)网络出现拥塞,如果数据包的ECT=1,CE=1,则数据包被传递。
ECN-Enabled WRED的配置:

router(config-pmap-c)# random-detect ecn
show policy-map [policy-map]
show policy-map interface interface-name

例如:

router(config)# policy-map MyPolicy 
router(config-pmap)# class class-default 
router(config-pmap-c)# bandwidth percent 70 
router(config-pmap-c)# random-detect 
router(config-pmap-c)# random-detect ecn

(5)Policing and Shaping 管制和整形

当用户超过额定带宽,超过的带宽不能被传输,采用其它方式来处理。管制:丢弃超出的带宽;整形:缓存超出的带宽。在流量管制和整形之前,必须先对报文进行分类。流量整形队列中多余的数据包,以保持所需的流量速率。 流量管制丢弃或标记超额流量,保持在一个流量速率限制。管制和整形不是拥塞管理机制,即使没有产生拥塞,也能生效。
管制和整形的对比:

1)管制
目的:限制访问资源的高速接入;限制访问某些应用程序或业务类的流量速率;第2层或第3层超过的流量做标记。
令牌桶:
在实施QoS策略时,可以将用户的数据限制在特定的带宽,当用户的流量超过额定带宽时,超过的带宽将采取其它方式来处理。要衡量流量是否超过额定的带宽,网络设备并不是采用单纯的数字加减法来决定的。比如带宽为100K,而用户发来的流量为110K,网络设备并不是靠110K减去100K等于10K,就认为用户超过流量10K。
当网络设备衡量流量是否超过额定带宽时,需要查看令牌桶,而令牌桶中会放置一定数量的令牌,一个令牌允许接口发送或接收1bit数据(有时是1 Byty数据),当接口通过1bit数据后,同时也要从桶中移除一个令牌。当桶里没有令牌的时候,任何流量都被视为超过额定带宽,只有当桶中有令牌时,数据才可以通过接口。
如果有足够的令牌可用(conform action):从桶中取出令牌相当于分组大小,该分组被发送。如果没有足够的令牌可用(exceed action):丢弃(或标记)数据包。
单速率单桶:

Bc(Burst size):令牌桶的大小。
Tc (Time interval):加令牌的时间,多久加一次令牌。
CIR:每秒钟往桶里令牌的速率,这个速率也就决定了用户流量。CIR = Bc / Tc。
单速率双桶:

Be:超出的突发数量(多余的数量)。
Tc:在Bc令牌桶的令牌。
Te:在Be令牌桶的令牌。
返回值是conform or exceed or violate。
由于使用了两个桶,所以用户的流量也会出现三种结果:
小于或等于CIR(也就是符合CIR)(conform)。
大于CIR并小于或等于CIR与Be之和(也就是符合两个桶令牌之和)(exceed)。
超过CIR与Be之和(也就是超过两个桶令牌之和)(violate)。
双速率双桶:

Tc:Token in CIR bucket。
Tp:Token in PIR bucket,PIR>CIR,Be>Bc。
根据两个不同的速率实施流量监管:Committed Information Rate 承诺信息速率,Peak Information Rate 峰值信息速率。
然而这两个桶是相互独立的,并不会将第一个桶未用的令牌放入第二个桶。
第一个桶与以往的算法相同,也就是每秒都有CIR的数量,第二个桶可以直接设置为CIR+Be之和,称为PIR, 第二个桶总是比第一个桶要大,用户的流量总是以第二个桶的大小传输。当用户的数据通过接口时,总是先检查第二个桶的最大速率,即PIR,如果超出则采取动作,如果未超出,再检查是是否符合第一个桶的CIR,如果超出CIR,则采取相应动作,如果未超过,则正常传输。
配置单速率基于类的管制:

router(config-pmap-c)# police avg-rate [BC [BE]] [conform-action action] [exceed-action action] [violate-action action]

单速率单桶例:

单速率双桶例:


配置基于类的双速率管制:

router(config-pmap-c)# police {cir cir} [bc conform-burst] {pir pir} [be peak-burst] [conform-action action] [exceed-action action] [violate-action action]


双速率双桶配置基于类的百分比管制:

router(config-pmap-c)# police cir percent percent [bc conform-burst-in-msec] [pir percent percent] [be peak-burst-in-msec] [conform-action action] [exceed-action action] [violate-action action]
router#show policy interface Ethernet 0/0

例如:

policy-map police1
 class bulk-ftp
  police cir percent 20 pir percent 40 conform-action set-dscp-transmit af11 exceed-action set-dscp-    transmit 0  
  violate-action drop
!
interface Ethernet 0/0
 service-policy input police1
!
interface Serial 0/0
 service-policy input police1

2)整形
目的:预防和管理在ATM和在帧中继网络中,非对称带宽的流量路径;在帧中继或ATM网络中,规范发送流量速率。
基于类的整形:

每隔Tc,往桶里注入Bc个token,是一次性注入,不是匀速注入。然后shaper gate open,而在桶里没有token的时候就关闭了,然后在下一个Tc开始的时候在打开并一次性注入Bc个token。
配置基于类的整形:

router(config-pmap-c)# shape {average | peak} average-bit-rate [Bc] [Be]
router(config-pmap-c)# shape {average | peak} percent [Bc] [Be]

示例平均速率、峰值速率:

Class-Based Shaping with CBWFQ:

policy-map shape-cbwfq 
!
class cust1 
 shape average 384000 
 bandwidth 256 
!
interface Serial 0/0 
  service-policy output shape-cbwfq

Class-Based Shaping Hierarchical Policy Maps:

验证Class-Based Shaping:

router# show policy-map policy-map-name
router# show policy-map interface s0/0

Frame Relay Refresher:
FECN 前向显示拥塞通告,BECN 后向显示拥塞通告。
基于类的整形可以通过整合BECN信号动态地适应现有帧中继宽:
当接收到的BECN报文,通过拥塞通知知道帧中继网络产生拥塞,则降低数据流发送的速率。 当拥塞不再存在(不再接收到BECN),增加数据流发送的速率。
Frame Relay Adaptive Class-Based Shaping的配置:

router(config-pmap-c)# shape adaptive min-rate
router(config-pmap-c)# shape fecn-adapt
router#show policy-map interface 

例如:

policy-map child-cbwfq
 class interactive
  bandwidth 32
 class bulk
  bandwidth 24
!
policy-map parent-shape
 class class-default
  shape average 192000
  shape adaptive 96000
  service-policy child-cbwfq
!
interface serial0/0
encapsulation frame-relay
!
interface serial0/0.1 point-to-point
ip address 192.168.1.1 255.255.255.0
frame-relay interface-dlci 100
class shape
!
map-class frame-relay shape
 service-policy output parent-shape
policy-map child-cbwfq
 class interactive
  bandwidth 32
 class bulk
  bandwidth 24
!
policy-map parent-shape
 class class-default
  shape average 192000
  shape adaptive 96000
  service-policy child-cbwfq 
!
interface Serial0/1
 ip address 10.1.1.1 255.255.255.0
 encapsulation frame-relay
 frame-relay class shape
 frame-relay map ip 10.1.1.2 102 broadcast
 frame-relay map ip 10.1.1.3 103 broadcast
 frame-relay map ip 10.1.1.4 104 broadcast
!
map-class frame-relay shape
 service-policy output parent-shape 

(6)Link Efficiency 链路效率

通过头部压缩或链路分段,提高带宽效率。报头压缩可以显着降低与语音传输相关的开销。在一个IP数据流中,数据报头中很多信息是保持不变,这就为报头压缩提供基础。发送方只需在开始时,传送一个完整的报头,随后不变的部分可以不传。
链路有效机制往往部署在低速的广域网链路,以增加吞吐量,降低时延和抖动。
载荷压缩减少了有效载荷的大小,报头压缩降低了头开销,压缩增加吞吐量,降低时延。
L2载荷压缩降低了帧的有效载荷的大小。 软件压缩由于其复杂性,将增加延迟。硬件压缩降低了压缩延迟。 串行化延迟降低,整体延迟可能会减少。
配置压缩:

R1(config)#interface serial 1/1
R1(config-if)#frame-relay payload-compression ?
  FRF9              FRF9 encapsulation
  data-stream       cisco proprietary encapsulation
  packet-by-packet  cisco proprietary encapsulation

R1(config)#interface serial 1/2
R1(config-if)#encapsulation ppp
R1(config-if)#compress ?
  lzs        lzs compression type
  mppc       MPPC compression type
  predictor  predictor compression type
  stac       stac compression algorithm

R1(config)#interface serial 2/1
R1(config-if)#encapsulation hdlc 
R1(config-if)#compress ?
  stac  stac compression algorithm

报头压缩减少了数据包报头的大小,有效载荷大小不被改变。例如:(基于类的)的TCP和(基于类的)RTP头压缩。报头压缩增加延迟并降低串行化的延迟。
TCP报头压缩和基于类的TCP报头压缩:
压缩IP和TCP报头;用来降低TCP报文段的开销;对传输小型有效载荷和许多TCP会话连接非常有效(例如,远程登录)。大多数Internet应用程序使用TCP作为传输协议。
将IP协议的20 bytes和TCP协议的20 bytes共40 bytes压缩。
TCP报头压缩可以压缩到3~~5个字节。基于类的TCP报头压缩允许基于流量分类来压缩。基于类的TCP报头压缩是通过MQC配置。
RTP报头压缩和基于类的RTP头压缩:压缩的IP,UDP和RTP报头;用于RTP,减少延迟并提高吞吐量;提高语音质量;最有效的慢速链接。
基于类的头部压缩配置:router(config-pmap-c)# compression header ip [rtp | tcp ]
例如:

class-map interactive
 match protocol telnet
!
policy-map cust1
 class interactive 
 bandwidth 64
 compression header ip tcp
!
<output omitted>
!
int s0/0
service-policy output cust1
<output omitted>

class-map voip
 match protocol rtp
!
policy-map cust1
!
class voip
 priority 384
 compression header ip rtp
!
<output omitted>
!
int s0/0
service-policy output cust1
<output omitted>

show policy-map interface interface-name

配置multilink PPP:

router(config-if)# ppp multilink
router(config-if)# ppp multilink interleave
router(config-if)# ppp multilink fragment-delay delay
Router# show interfaces multilink interface-number 
router# debug ppp multilink fragments

例如:

interface Multilink1 
 ip address 172.22.130.1 255.255.255.252
 ppp multilink 
 multilink-group 1
 ppp multilink fragment-delay 10 
 ppp multilink interleave
 bandwidth 128
 service-policy output llq-policy
! 
interface Serial0/0
 no ip address
 encapsulation ppp
 ppp multilink
 multilink-group 1

帧中继分片的配置:

router(config)# map-class frame-relay map-class-name
router(config-map-class)# frame-relay fragment fragment-size
router(config-if)# | (config-subif)# | (config-fr-dlci)# frame-relay class name
Router# show frame-relay fragment [interface interface [DLCI]]
router# show frame-relay pvc [interface interface] [dlci]

例如:

interface serial 0/0
  encapsulation frame-relay
  frame-relay traffic-shaping
!
interface serial 0/0.1 point-to-point
 frame-relay interface-dlci 100
  class FRF12
! 
map-class frame-relay FRF12
 frame-relay fragment 80    
!
FRTS parameters
 frame-relay cir 64000
 frame-relay bc 2600
 frame-relay fair-queue

interface serial 0/0
  encapsulation frame-relay
  frame-relay traffic-shaping
!
interface serial 0/0.1 point-to-point
 frame-relay interface-dlci 100
  class FRF12
! 
map-class frame-relay FRF12
 frame-relay fragment 80
!
FRTS parameters
 frame-relay cir 64000
 frame-relay bc 640
 frame-relay mincir 64000
 service-policy output llq-policy

(7)将QoS应用于入接口与出接口的策略


(8)QoS配置示例

Access-list 100 permit ip 192.168.1.0 0.0.0.255 any
!
Class-map match-any C1    匹配其中的一个条件
 Match access-group 100
 Match ip pre 5

Class-map match-all C1     匹配所有的条件
 Match access-group 100
 Match not ip pre 5


1、Access list

class-map Well-known-services
  match access-group 100 
!
access-list 100 permit tcp any any lt 1024      /--lt 1024 小于等于1024的端口--/
access-list 100 permit  协议 源地址 eq  端口号 目的地址 eq 目的端口号

2、IP precedence value

class-map test
  match ip precedence <0-7> 

class-map  match-any test  匹配优先级为0或者为1的流量
  match ip precedence 0
 match ip precedence 1

3、IP DSCP value

class-map test 3
  match dscp 1        /--匹配IPv4 和IPv6 dscp值为1--/
  match ip dscp 1     /--匹配IPv4 的dscp值为1--/

class-map Mission-Critical
  match ip dscp af31 af32 af33 cs3      /--CS3兼容IPP3--/   或的关系

4、QoS group number
(路由器内部使用标签,不会在网络种传递,而其它DSCP IPP都能够往下传递。
流量进入,打上Qos Group标记,匹配该标记的流量,做策略。这样可以保证Qos Group标记不会传递下去。)

access-list 100 permit icmp host 1.1.1.1 host 2.2.2.2
class-map qosgroup
  match access-group 100
policy-map qosgroup
  class qosgroup
  set qos-group 123
interface FastEthernet0/0
 service-policy input qosgroup

将1.1.1.1 ping 2.2.2.2的流量设置为qos-group 123

class-map 100k
  match qos-group 123
policy-map 100k
  class 100k
  bandwidth 100
interface FastEthernet0/0
 service-policy output 100k

R1#show policy-map interface f0/0

5、MPLS experimental bits

policy-map x
 class qosgroup
  set mpls experimental topmost 5

class-map test
 match mpls experimental topmost 5   匹配EXP的顶层标签 

6、Protocol (including NBAR)

class-map test
 match protocol …….

7、Using another class map

Class-map Unknown-services
  match not class-map Well-known-services 

8、Frame Relay DE bit

class-map test
 match fr-de

9、IEEE 802.1Q/ISL CoS/Priority values

class-map test
 match cos <0-7>

10、Input interface

class-map match-any Ethernets
  match input-interface Ethernet0/0
  match input-interface Ethernet0/1 

11、Source MAC address

class-map test
 match source-address mac aaaa.bbbb.cccc

12、Destination MAC address

class-map test
 match destination-address mac aaaa.bbbb.cccc

13、RTP (UDP) port range

match ip rtp starting-port-number port-range
class-map RTP
  match ip rtp 16384 16383  范围
(RTP 承载语音视频流量,实际上匹配的是UDP端口号)

14、Any packet

Class-map All-services
  match any 
发布了219 篇原创文章 · 获赞 603 · 访问量 129万+

猜你喜欢

转载自blog.csdn.net/gongxifacai_believe/article/details/89716997