Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10809783
  • 博文数量: 2905
  • 博客积分: 20098
  • 博客等级: 上将
  • 技术积分: 36298
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 05:00
文章存档

2012年(1)

2011年(3)

2009年(2901)

分类: LINUX

2009-03-23 11:37:47

一个10的接入带宽将被分配给home,office各另一个ISP,如下图所示:
家庭用户得到的带宽为1Mbps,office的带宽为4Mbps,另一个ISP的带宽为5Mbps.
首先,我们决定使用CBQ,需要在与客户端连接的eth1口添加root qdisc。
tc qdisc add dev eth1 root handle 10: cbq bandwidth 100Mbit avpkt 1000

接下来,需要在父类的基础上创建子类,其参数与父类相同。
tc class add dev eth1 parent 10:0 classid 10:10 cbq bandwidth 100Mbit rate \
100Mbit allot 1514 weight 10Mbit prio 5 maxburst 20 avpkt 1000 bounded

接下来,需要为每个客户端创建classes,qdiscs,filters,现在将先从home开始。
tc class add dev eth1 parent 10:10 classid 10:100 cbq bandwidth 100Mbit rate \
1Mbit allot 1514 weight 128Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:100 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.1.1 flowid 10:100
So we created the 10:100 class with a rate of 1Mbit and 128Kbit weight. Next, we attached an sfq qdisc and a u32 filter to match all traffic with the destination IP address 1.1.1.1. The bounded argument of the tc class add cbq command means
 
#the office
tc class add dev eth1 parent 10:10 classid 10:200 cbq bandwidth 100Mbit rate \
4Mbit allot 1514 weight 512Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:200 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.2.0/24 flowid 10:200

#the ISP
tc class add dev eth1 parent 10:10 classid 10:300 cbq bandwidth 100Mbit rate \
5Mbit allot 1514 weight 640Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:300 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.1.2 flowid 10:300
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.3.0/24 flowid 10:300

:~# tc class show dev eth1
class cbq 10: root rate 100000Kbit (bounded,isolated) prio no-transmit
class cbq 10:100 parent 10:10 leaf 806e: rate 1000Kbit (bounded) prio 5
class cbq 10:10 parent 10: rate 100000Kbit (bounded) prio 5
class cbq 10:200 parent 10:10 leaf 806f: rate 4000Kbit (bounded) prio 5
class cbq 10:300 parent 10:10 leaf 8070: rate 5000Kbit (bounded) prio 5
 
Now, to see that a class is actually shaping packets, we send three ping packets to 1.1.1.1, and check to see if the CBQ class matched those packets using tc –s class show dev eth1:
:~# tc -s class show dev eth1 | fgrep -A 2 10:100
class cbq 10:100 parent 10:10 leaf 806e: rate 1000Kbit (bounded) prio 5
Sent 294 bytes 3 pkts (dropped 0, overlimits 0)
borrowed 0 overactions 0 avgidle 184151 undertime 0

现在看起来所有的任务都已配置成功,现在将配置从CBQ转移到HTB上,在转移之前,我人需要删除CBQ的配置。
:~# tc qdisc del root dev eth1------删除eth1上队列。
 
使用HTB将比CBQ更加简单,操作如下:
:~# tc qdisc add dev eth1 root handle 10: htb
接下来创建子类( child class):
:~# tc class add dev eth1 parent 10:0 classid 10:10 htb rate 100Mbit
现在在子类上创建qdisc和filters的方法与CBQ类似,唯一不同的就是建立类,接下来看如何看home上创建class,qdisc和filter。
tc class add dev eth1 parent 10:10 classid 10:100 htb rate 1Mbit
tc qdisc add dev eth1 parent 10:100 sfq quantum 1514b perturb 15
tc filter add dev eth1 protocol ip parent 10:0 prio 5 u32 match ip dst 1.1.1.1 flowid 10:100
#the office
tc class add dev eth1 parent 10:10 classid 10:200 htb rate 4Mbit
tc qdisc add dev eth1 parent 10:200 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.2.0/24 flowid 10:200

#the ISP
tc class add dev eth1 parent 10:10 classid 10:300 htb rate 5Mbit
tc qdisc add dev eth1 parent 10:300 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst
1.1.1.2 flowid 10:300
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.3.0/24 flowid 10:300

在eth1上使用tc  class命令检验配置。
:~# tc class show dev eth1
class htb 10:10 root rate 100000Kbit ceil 100000Kbit burst 126575b cburst 126575b
class htb 10:100 parent 10:10 leaf 8072: prio 0 rate 1000Kbit ceil 1000Kbit burst 2849b cburst 2849b
class htb 10:200 parent 10:10 leaf 8073: prio 0 rate 4000Kbit ceil 4000Kbit burst 6599b cburst 6599b
class htb 10:300 parent 10:10 leaf 8074: prio 0 rate 5000Kbit ceil 5000Kbit burst 7849b cburst 7849b
and after sending three ping packets to 1.1.1.1, we should see them . the 10:100 class:
:~# tc -s class show dev eth1 | fgrep -A 4 10:100
class htb 10:100 parent 10:10 leaf 8072: prio 0 rate 1000Kbit ceil 1000Kbit burst 2849b cburst 2849b
Sent 294 bytes 3 pkts (dropped 0, overlimits 0)
rate 24bit
lended: 3 borrowed: 0 giants: 0
tokens: 18048 ctokens: 18048

阅读(1264) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~