2012年3月1日星期四

Policing

Policing就是超出限速后将包直接丢弃,它通常是和filter结合在一起用。filter可以对包采取多种措施:

 - ok or pass     - 通常用于暂时禁用掉某个filter

 - continue         - 找不到匹配的filter,继续找其他的匹配

 - drop or shot   - 丢弃

 - reclassify        - 重新标记为Best Effort,默认的action

 如果qdisc没有实现policing,那么drop和reclassify会被当做continue,即不被处理。

有两种方式来做police:

1. kernel estimator,内核的estimator来统计Exponential Weighted Moving Average平滑后的速率(40ms统计一次,每秒有25次统计,然后再平滑),用来避免burst流量的影响,如果超出,就采取特定的措施,默认是reclassify。这种方式只需要一个参数avrate。

2. 使用token bucket filter。这种和tc-tbf一样,只是数据不会缓存,所以没有"limit/latency"的参数,可用的参数如下:

  - burst/buffer/maxburst,桶的容量

  - mtu/minburst, 第二个burst桶的容量,如果设置的太小,包有可能会过不去。

  - mpu,minium packet usage,每个包不管大小多大,都需要消耗token,这个值指定了一个包需
    要消耗的最小token量(字节)。

  - rate, 第一个桶token注入的速率

例子:

1) 限制icmp的流量为2kbit:

tc filter add dev $DEV parent ffff: protocol ip prio 20 u32 match ip protocol 1 0xff police rate 2kbit buffer 10k drop flowid :1


2)限制包大小不超过84byte:

tc filter add dev $DEV parent ffff: protocol ip prio 20 u32 match ip tos 0 0xff police mtu 84 drop flowid :1

3)丢弃所有的icmp包:

tc filter add dev $DEV parent ffff: protocol ip prio 20 u32 match ip protocol 1 0xff police mtu 1 drop flowid :1

没有评论:

发表评论