免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3951 | 回复: 10
打印 上一主题 下一主题

[FreeBSD] 请教ipfw+dummynet 实现流量控制 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-03-20 13:21 |只看该作者 |倒序浏览

在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 18002  queue 4 udp from 192.168.1.11 to any in via eth0
ipfw add 18008  queue 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 18006  queue 5 udp from any to 192.168.1.11  in via eth1
ipfw add 18008  queue 9 udp from any to 192.168.1.21  in 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
18002  0    0 queue 4 udp from 192.168.1.11 to any in recv eth0
18004  0    0 queue 5 udp from any to 192.168.1.11 in recv eth1
18006  0    0 queue 8 udp from 192.168.1.21 to any in recv eth0
18008  0    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/2516  4058  5633298  4 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    42760  0    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/2515  7476 10377977  0    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/2062  1315    78880  0    0   0

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

还请高手指导一下

论坛徽章:
54
2017金鸡报晓
日期:2017-02-08 10:39:42操作系统版块每日发帖之星
日期:2016-03-08 06:20:00操作系统版块每日发帖之星
日期:2016-03-07 06:20:00操作系统版块每日发帖之星
日期:2016-02-22 06:20:00操作系统版块每日发帖之星
日期:2016-01-29 06:20:00操作系统版块每日发帖之星
日期:2016-01-27 06:20:00操作系统版块每日发帖之星
日期:2016-01-20 06:20:00操作系统版块每日发帖之星
日期:2016-01-06 06:20:0015-16赛季CBA联赛之江苏
日期:2015-12-21 20:00:24操作系统版块每日发帖之星
日期:2015-12-21 06:20:00IT运维版块每日发帖之星
日期:2015-11-17 06:20:002015亚冠之广州恒大
日期:2015-11-12 10:58:02
2 [报告]
发表于 2013-03-20 13:54 |只看该作者
30M跑满了吗?

论坛徽章:
54
2017金鸡报晓
日期:2017-02-08 10:39:42操作系统版块每日发帖之星
日期:2016-03-08 06:20:00操作系统版块每日发帖之星
日期:2016-03-07 06:20:00操作系统版块每日发帖之星
日期:2016-02-22 06:20:00操作系统版块每日发帖之星
日期:2016-01-29 06:20:00操作系统版块每日发帖之星
日期:2016-01-27 06:20:00操作系统版块每日发帖之星
日期:2016-01-20 06:20:00操作系统版块每日发帖之星
日期:2016-01-06 06:20:0015-16赛季CBA联赛之江苏
日期:2015-12-21 20:00:24操作系统版块每日发帖之星
日期:2015-12-21 06:20:00IT运维版块每日发帖之星
日期:2015-11-17 06:20:002015亚冠之广州恒大
日期:2015-11-12 10:58:02
3 [报告]
发表于 2013-03-20 13:55 |只看该作者
30M跑满了吗?

论坛徽章:
0
4 [报告]
发表于 2013-03-20 14:15 |只看该作者
回复 3# lsstarboy


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

论坛徽章:
0
5 [报告]
发表于 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)/时间 这样的对吗?

论坛徽章:
54
2017金鸡报晓
日期:2017-02-08 10:39:42操作系统版块每日发帖之星
日期:2016-03-08 06:20:00操作系统版块每日发帖之星
日期:2016-03-07 06:20:00操作系统版块每日发帖之星
日期:2016-02-22 06:20:00操作系统版块每日发帖之星
日期:2016-01-29 06:20:00操作系统版块每日发帖之星
日期:2016-01-27 06:20:00操作系统版块每日发帖之星
日期:2016-01-20 06:20:00操作系统版块每日发帖之星
日期:2016-01-06 06:20:0015-16赛季CBA联赛之江苏
日期:2015-12-21 20:00:24操作系统版块每日发帖之星
日期:2015-12-21 06:20:00IT运维版块每日发帖之星
日期:2015-11-17 06:20:002015亚冠之广州恒大
日期:2015-11-12 10:58:02
6 [报告]
发表于 2013-03-22 19:23 |只看该作者
应该差不多,pipe/queue只对当前连接下的数据包进行统计,但是我观察的结果,不是很准确。
另外你的mask设置为0x00/0x00,你测试一下,是不是应该是双向的流量?一般不这样设置,最好加上mask,用来区分方向。

论坛徽章:
0
7 [报告]
发表于 2013-03-25 16:10 |只看该作者
lsstarboy 发表于 2013-03-22 19:23
应该差不多,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不知道有没有影响?

论坛徽章:
54
2017金鸡报晓
日期:2017-02-08 10:39:42操作系统版块每日发帖之星
日期:2016-03-08 06:20:00操作系统版块每日发帖之星
日期:2016-03-07 06:20:00操作系统版块每日发帖之星
日期:2016-02-22 06:20:00操作系统版块每日发帖之星
日期:2016-01-29 06:20:00操作系统版块每日发帖之星
日期:2016-01-27 06:20:00操作系统版块每日发帖之星
日期:2016-01-20 06:20:00操作系统版块每日发帖之星
日期:2016-01-06 06:20:0015-16赛季CBA联赛之江苏
日期:2015-12-21 20:00:24操作系统版块每日发帖之星
日期:2015-12-21 06:20:00IT运维版块每日发帖之星
日期:2015-11-17 06:20:002015亚冠之广州恒大
日期:2015-11-12 10:58:02
8 [报告]
发表于 2013-03-25 17:09 |只看该作者
drop栏有显示就是开始限速了。
queue length越大,速度会快一点,但是延迟会加大。
pipe和queue对延迟加大很严重,如果考虑到网游,最好不要pipe。

论坛徽章:
0
9 [报告]
发表于 2013-03-26 09:21 |只看该作者
lsstarboy 发表于 2013-03-25 17:09
drop栏有显示就是开始限速了。
queue length越大,速度会快一点,但是延迟会加大。
pipe和queue对延迟加大 ...



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

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

论坛徽章:
54
2017金鸡报晓
日期:2017-02-08 10:39:42操作系统版块每日发帖之星
日期:2016-03-08 06:20:00操作系统版块每日发帖之星
日期:2016-03-07 06:20:00操作系统版块每日发帖之星
日期:2016-02-22 06:20:00操作系统版块每日发帖之星
日期:2016-01-29 06:20:00操作系统版块每日发帖之星
日期:2016-01-27 06:20:00操作系统版块每日发帖之星
日期:2016-01-20 06:20:00操作系统版块每日发帖之星
日期:2016-01-06 06:20:0015-16赛季CBA联赛之江苏
日期:2015-12-21 20:00:24操作系统版块每日发帖之星
日期:2015-12-21 06:20:00IT运维版块每日发帖之星
日期:2015-11-17 06:20:002015亚冠之广州恒大
日期:2015-11-12 10:58:02
10 [报告]
发表于 2013-03-26 14:43 |只看该作者
pipe是高速公路限速120
queue是车道,60-90靠右走。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP