unix_girl 发表于 2013-03-20 13:21

请教ipfw+dummynet 实现流量控制


在freebsd下使用ipfw+dummynet 实现流量控制


两条queue
192.168.1.11->192.168.2.100
192.168.1.21->192.168.2.100
udp packet,weight 设置为1:2

通过ipfw命令添加相关的pipe和queue
命令如下:
ipfw add 18002queue 4 udp from 192.168.1.11 to any in via eth0
ipfw add 18008queue 8 udp from 192.168.1.21 to any in via eth0
ipfw pipe 10 config bw 30Mbits/s
ipfw queue 4 config pipe 10 weight 1
ipfw queue 8 config pipe 10 weight 2

ipfw add 18006queue 5 udp from any to 192.168.1.11in via eth1
ipfw add 18008queue 9 udp from any to 192.168.1.21in via eth1
ipfw pipe 20 config bw 512Kbits/s
ipfw queue 5 config pipe 20 weight 1
ipfw queue 9 config pipe 20 weight 2

添加之后ipfw结果如下:

ipfw show
180020    0 queue 4 udp from 192.168.1.11 to any in recv eth0
180040    0 queue 5 udp from any to 192.168.1.11 in recv eth1
180060    0 queue 8 udp from 192.168.1.21 to any in recv eth0
180080    0 queue 9 udp from any to 192.168.1.21 in recv eth1

# ipfw pipe list
00010:   3.000 Mbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
00020: 512.000 Kbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
q00004: weight 1 pipe 10   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 udp   192.168.1.11/1693    192.168.2.100/2516405856332984 5368   0
q00005: weight 1 pipe 20   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 udp    192.168.2.100/2516   192.168.1.11/1693   713    427600    0   0
q00008: weight 2 pipe 10   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 udp   192.168.1.21/2062    192.168.2.100/25157476 103779770    0   0
q00009: weight 2 pipe 20   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 udp    192.168.2.100/2515   192.168.1.21/20621315    788800    0   0

问题是:
如果将pipe bw设置为3Mbit/s, 那么wfq调度成功,按照1:2分享3M带宽,从上面显示pipe list的流量显示也可以看出来,
pipe bw 设置为30Mbit/s,wfq调度失败,不能实现预期的1:2的bw分配,请问这是什么原因呢?

还请高手指导一下

lsstarboy 发表于 2013-03-20 13:54

30M跑满了吗?

lsstarboy 发表于 2013-03-20 13:55

30M跑满了吗?

unix_girl 发表于 2013-03-20 14:15

回复 3# lsstarboy


有跑满的,我试过不限速打可以达到50几M,而且这个时候实现限速基本是准的(29M),但是wfq不生效

unix_girl 发表于 2013-03-20 14:22

回复 3# lsstarboy


    另外,我想请问一下
# ipfw pipe list
00010:30.000 Mbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
00020:30.000 Mbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
q00004: weight 1 pipe 10   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 udp   192.168.1.21/61       192.168.2.52/61    12427259 12377549362 50 49800 9748181
q00005: weight 1 pipe 20   50 sl. 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
q00008: weight 2 pipe 10   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 udp   192.168.1.11/62       192.168.2.52/62    12427272 12377562296 47 46812 7069241
q00009: weight 2 pipe 20   50 sl. 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000

查看每个queue的流量的时候,应该是(Tot_pkt/bytes -Drp)/时间 这样的对吗?

lsstarboy 发表于 2013-03-22 19:23

应该差不多,pipe/queue只对当前连接下的数据包进行统计,但是我观察的结果,不是很准确。
另外你的mask设置为0x00/0x00,你测试一下,是不是应该是双向的流量?一般不这样设置,最好加上mask,用来区分方向。

unix_girl 发表于 2013-03-25 16:10

lsstarboy 发表于 2013-03-22 19:23 static/image/common/back.gif
应该差不多,pipe/queue只对当前连接下的数据包进行统计,但是我观察的结果,不是很准确。
另外你的mask设 ...

多谢回复
我是设了两条pipe
pipe 10 上行 192.168.1.x->192.168.2.x
pipe 20 下行 192.168.2.x->192.168.1.x
queue 4, queue 8 挂在pipe 10(限带宽30M)下
queue 5, queue 9 挂在pipe 20下

所以我觉得双向的流量看起来不太会走到同一个pipe。

再请教一下,如果wfq调度生效的时候,drop这个栏位是不是应该有显示才表示这个queue打满了?
queue length这个参数调成多少比较合适
对于大包这个参数造成delay不知道有没有影响?

lsstarboy 发表于 2013-03-25 17:09

drop栏有显示就是开始限速了。
queue length越大,速度会快一点,但是延迟会加大。
pipe和queue对延迟加大很严重,如果考虑到网游,最好不要pipe。

unix_girl 发表于 2013-03-26 09:21

lsstarboy 发表于 2013-03-25 17:09 static/image/common/back.gif
drop栏有显示就是开始限速了。
queue length越大,速度会快一点,但是延迟会加大。
pipe和queue对延迟加大 ...


看起来有些奇怪的是,我这边drop栏位一直都没有显示,可是确实是有限速的
是不是应该把queue length(50)调小一些呢?

另外,不使用pipe的情况下要怎么限速呢,求教
多谢

lsstarboy 发表于 2013-03-26 14:43

pipe是高速公路限速120
queue是车道,60-90靠右走。
页: [1] 2
查看完整版本: 请教ipfw+dummynet 实现流量控制