Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2987064
  • 博文数量: 272
  • 博客积分: 5544
  • 博客等级: 大校
  • 技术积分: 5496
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 00:48
个人简介

  每个人都要有一个骨灰级的爱好,不为金钱,而纯粹是为了在这个领域享受追寻真理的快乐。

文章分类

全部博文(272)

文章存档

2015年(2)

2014年(5)

2013年(25)

2012年(58)

2011年(182)

分类: BSD

2013-08-14 16:27:08

因业务需要, 需要网卡直接发送大量数据包测试转发性能, 这里netmap是一个很好的工具, website: ~luigi/netmap/
但是很艹蛋的是, 这个精简系统不支持SSH和TELNET, 太坑爹了.

在netmap源码目录的README中已经有如下说明:
  1. FreeBSD
  2.   --------
  3.   (FreeBSD HEAD and stable/9 already include netmap in the source tree
  4.   so you should not need the code in this distribution.)
  5.   + add 'device netmap' to your kernel config file and rebuild a kernel.
  6.     This will include the netmap module and netmap support in the device
  7.     drivers. Alternatively, you can build standalone modules
  8.     (netmap, ixgbe, em, lem, re, igb)

在9系列的稳定版中已经支持了netmap的源码, 只需要添加内核支持, 从建内核即可. 还支持intel的千兆, 万兆网卡驱动. 好吧, 装了个FreeBSD 9.1, 安装过程不表, 安装中一定要选择 src 支持, 也就是内核源码.
然后配置SSH选项运行root远程登录, 和允许密码校验.

SSH能连接上服务器后, 进入内核目录(安装时选择上src的话, 就可以进入):
cd /usr/src/sys/i386/conf  #注意32位是i386, 64位是amd64

编辑GENERIC文件:
vi GENERIC #在文件中任意处添加 "device netmap" 即可, 然后保存退出.

运行config命令来产生内核源代码:
config GENERIC

切换到建立内核的目录:
cd ../compile/GENERIC

编译内核:
make depend && make

安装新内核:
make install

OK, 到这里, 如果中间没有出现任何错误的话, 那么我们的内核心就已经安装成功了, reboot后就能够使用我们的新编译的内核了.
如果出现了错误, 那么请检查你的步骤是否跟上面的步骤一致, 同时要检查你的内核配置文件配置的是否正确, 一般编译不成功都是内核文件配置的问题, 请仔细检查.


重新启动后再查看确认一下:
  1. # dmesg | grep "netmap"
  2.     root@netmap.com:/usr/src/sys/i386/compile/GENERIC i386
  3. 001.000005 netmap_new_obj_allocator [425] objsize 1024 clustsize 4096 objects 4
  4. 001.000006 netmap_new_obj_allocator [503] Pre-allocated 128 clusters (4/512KB) for 'netmap_if'
  5. 001.000007 netmap_new_obj_allocator [425] objsize 36864 clustsize 36864 objects 1
  6. 001.000008 netmap_new_obj_allocator [503] Pre-allocated 200 clusters (36/7200KB) for 'netmap_ring'
  7. 001.000009 netmap_new_obj_allocator [425] objsize 2048 clustsize 4096 objects 2
  8. 001.000010 netmap_new_obj_allocator [503] Pre-allocated 50000 clusters (4/200000KB) for 'netmap_buf'
  9. 001.000011 netmap_memory_init [553] Have 512 KB for interfaces, 7200 KB for rings and 195 MB for buffers
  10. netmap: loaded module with 202 Mbytes
  11. 001.000014 netmap_attach [1016] ok for em0
  12. 001.000016 netmap_attach [1016] ok for em1
这里已经看到netmap已经成功被内核加载起来了.




下面就是编译安装pkt-gen发包工具了
首先进入内核工具目录:
cd /usr/src/tools/tools/netmap

该目录下就已经集成了一些发包工具源码:
Makefile        README          bridge.c        click-test.cfg  pcap.c          pkt-gen.c

编译:
make

不知道我哪里没设置正确, ixgbe的万兆网卡驱动被打成模块了, 需要kldload ixgbe手的那个加载, 写入开机自动运行里/etc/rc.d/local, 万兆网卡可以驱动了, 也没在深究.

这里有最新的netmap源码, 在example中有最新的pkt-gen工具, 比9.1带的要功能多一些. 同样直接上传到BSD下编译即可. 新版本可以指定发送还是接收:
  1. Usage:
  2. pkt-gen arguments
  3.         -i interface interface name
  4.         -f function tx rx ping pong
  5.         -n count number of iterations (can be 0)
  6.         -t pkts_to_send also forces tx mode
  7.         -r pkts_to_receive also forces rx mode
  8.         -l pkts_size in bytes excluding CRC
  9.         -d dst-ip end with %n to sweep n addresses
  10.         -s src-ip end with %n to sweep n addresses
  11.         -D dst-mac end with %n to sweep n addresses
  12.         -S src-mac end with %n to sweep n addresses
  13.         -a cpu_id use setaffinity
  14.         -b burst size testing, mostly
  15.         -c cores cores to use
  16.         -p threads processes/threads to use
  17.         -T report_ms milliseconds between reports
  18.         -w wait_for_link_time in seconds

发送端:
pkt-gen -i ix0 -f tx -l 64 -d 172.16.1.1 -D 00:16:31:ff:a6:aa

接收端:
pkt-gen -i ix1 -f rx

拓扑图:
发包机                           测试机
ix0(172.16.0.1)     -->     eth0(IP 172.16.0.2   MAC 00:16:31:FF:A6:AA)
                                    ↓
ix1(172.16.1.1)     <--     eth1(172.16.1.2)

#这样就可以在BSD的两张网卡上完成一个网卡发送, 一个网卡接收, 数据包流量通过测试机, 来测试转发性能.
#netmap通过RAW模式直接向目的MAC为00:16:31:FF:A6:AA的设备发送数据包, 无需查询路由表, 数据包达到测试机eth0后拆包, 发现目的地址在属于自己的接口路由, 那么通过协议栈, 数据包从eth1发出.
#这样发包机的数据包发送并未通过其内核, 发包效率提升很快. 而测试结的数据包经过内核协议栈, 可以对比发送流量和接收流量来衡量测试机的转发速率.

netmap.rar



阅读(8735) | 评论(1) | 转发(1) |
0

上一篇:taskset设置CPU亲和

下一篇:Perf使用教程

给主人留下些什么吧!~~

mming4242014-07-01 15:42:30

nice 正在学习中