shaping and policing(整形和监管)为什么要使用整形和监管

1速率不匹配

2超出带宽

3所有流量并行

解决限速

shaping and policing对比

shaping把超出的包进行缓存,等速率降下来在发出去。

policing超出速率直接drop或打标记。

shaping比较平滑,最大化利用带宽shaping好。

policing超出drop。

shaping只能做在出方向,pocoming入和出都可以做

shaping减少tcp重传,pocoming会导致tcp重传,可以打标记。

token bucket令牌桶

限速

cir 承诺信息速率,速率单位。bytes bits

tc 承诺时间,默认125ms 1/8s s

bc 承诺的突发量byte bit

be 超出的突发量 byte bit

cir=bc/tc

令牌桶工作原理

路由器运行shaping或policing,就会有一个桶,就是令牌桶,默认情况下桶的大小就bc这么大,而默认每tc秒就会像这个桶加入多少个bc的令牌。过125ms这个桶就充满了,再放桶的令牌就会多出来,就丢掉,数据包过来就要到令牌桶中拿令牌,拿到令牌就转发,如果拿不到,如果做得是shaping多的包就缓存,policing就丢掉。

dual token bucket(双牌桶)

bc 第一个桶可以放的令牌

be 超出的突发量,第二个桶的大小

cir=bc/tc

一般默认配置bc=be

每tc秒像第一个桶放入bc个令牌,作为第二个tc秒令牌就会超出第一个桶的容量,多出来的就放入第2个桶,第三个tc秒又多出来,就多了令牌丢掉。在没有数据的时候,有bc+be个令牌。

be配成0就是1个桶,和bc一样大就是两个桶,配置只关心cir.

shaping技术(整形)

gts通用流量整形,任何接口都可以用

frts只能用在帧中继

cb shaping

policing 技术(监管)

car 承诺的数率

cb policing

gts通用流量整形

shaping和policing是工作在队列之间的。

shaping wfq缓存

gts 简介

1.gts只能使用wfq作为shaping queue

2当拿到令牌的就会到software queuing去排队。机制可以使用fifo,pq,cq,wfq.gts只能工作在出方向。

gts配置

router(config-if)#

traffic-shape rate bit-rate [burst-size [excess-burst-size]]

r1:

traffic-shape rate 64000(cir) 8000(bc建议是cir的1/8) 8000(be) 1000(shaping wfq的座位号)(限制为64k)

show traffic-shape

router(config-if)#

traffic-shape group access-list bit-rate [burst [excess-burst]](分类)

traffic-shape rate 和traffic-shape group不能同时在一个接口使用。

router#

show traffic-shape

router(config)#

show traffic-shape queue(查看shaping wfq的信息)

frame rely

fecn前向显示拥塞通告,

becn后项显示拥塞通告,

在frame relay包头中有字段fecn和becn的,然后设置fecn是否置为,如果置位就会有相应的效果,告诉路由器是否出现拥塞,然后做出相应的动作。

de位:合理丢弃位。也是帧中继头部字段,执1或0,执行相应动作,执1,用qos match de位,做相应动作,二层的标记。

例:

r1:

class map a

match fr-de

fecn和becn应用

当时tcp流量,帧中继发生拥塞,像接受者打上fecn,接收者回来的包会打上becn告知发送者。适应性整形,当发送发收到becn会把发送速率降低到3/4,再收再降,直到收不到,然后再升。

配置:

router(config-if)#

traffic-shape adaptive [bit-rate]

r1:

int s0/0

encapsulation frame-relay

show traffic-shape

traffic-shape adaptive 32000(建议是cir一半,降低的最低速率)

show traffic-shape

如果报文是ip或udp,没有回报,可以再接受者开启一个fecn到becn的传播位,当我收到fecn以后,由于没有回包,会自动发送一个叫q.922的测试帧,里面就打上了becn。

配置:

配置在速率较小的。

router(config-if)#traffic-shape fecn-adapt

int s0/0

traffic-shape fecn-adapt

frts(帧中继的流量整形)

frts 概述

frts 的shaping queue可以设置pq,cq,wfq.frts只能工作在出方向,软件queue很多资料说能够使用wfq,但是实际测试不行。只能使用先进先出。

r1:

frame-relay traffic-shaping

show traffic-shape

map-class frame-relay frts

frame-relay traffic-rate 64000(限制为64k)

int s0

frame-relay class frts

show traffic-shaping

针对某个pvc做调用

int s0

frame-relay interface-dlci 104

class frts

router(config-if)#

frame-relay traffic-shaping

router(config-if)#

frame-relay class map-class-name

router(config-if)#frame-relay interface-dlci dlci

class map-class-namegts和frts对比

1.gts可以调用到任何接口包括子接口,而frts只能工作在帧中继接口,

2.shape只能给予接口做,而virtual circuits可以基于vc来做。

3gts软件queuing可以使用任意的,frts只能使用fifo

4gts的shaping queue只能用wfq,而frts可以用cq,pq,wfq

修改shaping queue的配置命令:

router(config-map-class)#

frame-relay priority-group number

router(config-map-class)#

frame-relay custom-queue-list number

router(config-map-class)#

frame-relay fair cdt max-queue rsvp-queues max-buf

r1:

map-class frame-relay frts

frame-relay priority-group 1

show traffic-shape queuerouter(config-map-class)#

frame-relay [in|out] cir bit-rate

frame-relay [in|out] bc bits

frame-relay [in|out] be bits

router(config-map-class)#

frame-relay traffic-rate average-rate peak-rate

router(config-map-class)#

frame-relay adaptive-shaping becn

router(config-map-class)#

frame-relay mincir rate

r1:

map-class frame-relay frts

frame-relay adaptive-shaping becn

show traffic-shape

frame-relay mincir 32000

例:

interface s1/1

frame-relay traffic-shaping

inter s1/1.1 point-to-point

frame-relay interface-dlci 101

class slow_vcs

interface s1/1.2 point-to-point

frame-relay interface-dlci 102

class fast_vcs

map-class frame-relay fast_vcs

frame-relay custom-queue-list 1

frame-relay traffic-rate 32000 64000

map-class frame-relay slow_vcs

frame-relay priority-group 1

frame-relay traffic-rate 9600 16000

cb shaping

cb saping概述

cb shaping可以使用的队列,pq,cq,wfq.

物理接口的软件queing只能使用fifo

average rate平均速率:tc秒往桶里添加bc个令牌。

peak rate每tc秒放bc+be个令牌。

配置:

r1:

class-map tel

match access-group 100

policy-map cbshape

class tel

shape average 64000

int s0

service-policy output cbshpe

show policy-map interface

配置命令:

router(config-pmap-c)#

shape {average | peak }bit-rate [bc[be]]

router(config-pmap-c)#

shape max-buffers queue-limit(设置可以缓存多少个包)

router(config-pmap-c)#shape adaptive min-rate(针对帧中继做适应性整形)

例:

class-map shape

match access-group 123

policy-map shapeavg

class shape

shape average 16000 1024 2048

policy-map shapepeak

class shape

shape peak 16000 1024 2048

interface s0/0

service-policy output shapeavg

interface s0/1

service-policy output shapepeak

access-list 123 permit udp any any

show policy-map interface

policing 监管

car(承诺接入速率)

原理:

过来一个包,首先检查令牌桶,如果拿到令牌就转发,拿不到就丢弃,当然policing默认你拿不到令牌就应该丢弃,但是作为配置上可以选,你拿不到令牌还是可以发出去的,car还能做更强的处理,发出一个包后,还能打标记。

配置命令:

router(config-if)#rate-limit {input | output}

[access-group [rate-limit] #acl | qos-group number | dscp dscp]

mean-rate bc be

conform-action {drop | transmit | continut |

set-prec-transmit value | set-prec-continue value |

set-qos-transmit value | set-qos-continue value

set-dscp-transmit value | set-dscp-continue value|

set-mpls-transmit value | set-mpls-continue value }

exceed-action {drop | transmit | continue |

set-prec-transmit value | set-prec-continue value |

set-qos-transmit value | set-qos-continue value

set-dscp-transmit value | set-dscp-continue value |

set-mals-transmit value | set-mpls-continue value}

例1:

interface s0/0

rate-limit output 256000 4000 96000

conform-action(拿到令牌的)transmit exceed-action(拿不到令牌的) drop

shapcing设置bc和be的单位使用bit,而police使用的是byte

show interfaces rate-limit

例2:

interface s0/0

rate-limit output access-group 101 256000 4000 96000 conform-action transmit exceed-action drop

access-list 101 permit tcp any any eq www

例3:

interface s0/0

rate-limit intput 496000 62000 62000

conform-action  continne(匹配多条向下查找,匹配小范围的如www) exceed-action drop

rate-limit input access-group 101 400000 50000 50000

conform-action transmit exceed-action drop

access-list 101 permit tcp any any eq www

例4:

interface s0/0

rate-limit input 496000 62000 62000

conform-action set-prec-continue 3 exceed-action drop

rate-limit input access-group 101 496000 62000 62000

conform-action set-prec-transmit 5 exceed-action drop

access-list 101 permit udp any any range 16384 32767

show inter s0/0 rate-limit

cb policing

conforms:拿到第一个桶令牌。

exceeds:拿到第二个桶令牌。

violates:拿不到令牌。

配置命令:

router(config-pomap-c)#

police avg-rate [bc [be]] [conform-action [action]

[exceed-action [action] [violate-action [action]]]]

r1:

policy-map cbpolice

class tel

police 64000 conform-action transmit exceed-action transmit violate-action drop

局域网二层qos

主要区分了数据和语音。

交换机识别方式:

1.针对接口能支持多少队列

2.以及那个队列是强制优先的队列。

3.交换机是否支持丢弃机制,默认都是尾丢弃,

4.设置丢弃的阀值

交换机标识

2q2t:2个queues和2个丢弃的阀值

1p2q2t:1个queue是强制优先的queues

针对型号:

2950:1p3q,4q

3550:1p3q2t,4q2t

3750:发出4q3t,接收1p1q3t,2q3t

4000:发出11p3q2t,4q2t

6500:发出2q2t,1p2q2t,1p3q1t,1p2q1t,接收1q4t,1p1q4t,1p1q,1p1q8t.

wrr 加权循环

4q

默认可以把queue 4作为优先队列,把相关的语音放入第4个queue

switch(config)#

wrr-queue cos-map quid cos11 ... cosn

queue ip     cos values

   1                 0,1

   2                 2,3

   3                 4,5

   4                 6,7

qos扩展:

1lan qo: wrr-q

3550以上

接口

2950

全局

sw3550:

int f0/1

wrr-queue cos-map 4 5 6 7(把优先级为5,6,7放到第4个queue)

show mls qos interface f0/1 queueing

mls qos

int f0/1

priority-queue out (把第四个queue调成快速队列)

show ml qo int f0/1 queueing

int f0/1

wrr-queue bandwidth 80 19 1 1 (设置4个queue带宽比例调整)

sw2960:

wrr-queue cos-map 4 5 6 7

wrr-queue bandwidth 80 20 1 0(0代表快速队列)

show wrr-queue bandwidth

show wrr-queue cos-map

压缩

1.2层数据压缩,栈位压缩,提前压缩,mppc。

2.头部亚松,一般针对tcp和rtp头部压缩

串口hdlc只支持stacker压缩,ppp可以支持3钟,

配置:

r1:

int s0/0

compress stac

r2:

int s0/0

compress stac

show compress(查看压缩和解压缩)

头部压缩

r1:

ip tcp header-compression (tcp头部压缩)

r2:

ip tcp header-compression

show ip tcp header-comression

line vty 0 15

no login

r1:

telnet 12.1.1.2

show ip tcp header-comression

rtp头部压缩针对语音:

r1:

int s0/0

ip rtp header-compression

qos 预分类

用在vpn环境中

由于vpn做的广泛了,在打标记的时候,针对原始的包头,打了个qos为5的,当从vpn接口发出去的时候,这个路由器能不能认识到。识别tos位。preclassify允许可以分类,但是在分类之间是先加密还是先查qos字段,默认是先加密,在esp加密之前就做了,先把tos字段源ip目标ip读取出来。做完分类以后再去封装。

当封装了gre或esp包头以后,qos的features不能查看原始的包头了,不能进行分类了。而所有的包穿越过来都会打上一样的tunnel头,相当于所有的包都同样对待。

无论是做esp,ah,tunnel,默认情况下原始的tos字段会自动拷贝到gre的头部中,是tunnel头部做的。

1.如果做了相应的vpn,qos策略调用在tunnel或物理接口。

2.是否决定使用qos preclassify

gre封装命令

ipsec and gre configuration

crypto map static-crpt 1 ipsec-isakmp

qos pre-classify

set peer etc

interface tunnel 0

qos pre-classify

crypto map static-crypt

interface e0/1

service-policy output minbwtos

crypto map static-crypt

r1:

inter tunnel 0

qos pre-classify

如果是ipsec在isakmp 中做qos pre-classify

auto qos

工作过程:

auto qos一般配在相应的接口,它能够自动发现你工作的流量和提供的服务,然后对你相应的流量做qos处理。

他会自动生成一些初始的命令,或正在进行的qos策略。

它能够支持,分类、标记,拥塞管理,shaping,压缩。

启用aotu qos前提必须保证:

1开启cef

2开启nbar

例1:

interface s1/3

ip cef

bandwidth 1530

auto qos voip

show auto qos