pktgen使用文档

更新时间:2024-03-03 10:02:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

使用pktgen测试GWN7000包转发率

思博伦通信Smartbits测试设备,做为专业的发包仪器非常不错,但唯一的缺点就是太贵.还好Linux为我们提供了一个先进的发包pktgen,这个工具以内核模块的形式存在,理论上性能应该比同等运行在应用层的工具性能要好,而且还是所谓的多核支持.

1.1 测试Swich模式下的LAN口间的包转发率

测试环境:

测试步骤如下:

步骤1),首先加载pktgen.

在Linux PC上运行modprobe pktgen 命令.

加载成功后, 会有对应的/proc/net/pktgen接口,pktgen是每一个cpu绑定一个内核线程,如果PC机有4个cpu,所以这里可以看到4个kpktgend_*文件(假设PC机是4核的): 1 2 3 4 5 6 7 8 9 [root@localhost ~]#modprobe pktgen [root@localhost ~]# cat /proc/cpuinfo | grep processor processor : 0 processor : 1 processor : 2 processor : 3 [root@localhost ~]#ls /proc/net/pktgen/ kpktgend_0 kpktgend_1 kpktgend_2 kpktgend_3 pgctrl 假如PC机一共有3个网口,拿其中的2个网口(eth1/eth2)用于pktgen测试. 可以先使用ethtool工具查看eth1/eth2网口的速率.

如果网口速率没有协商成1000M, 也可以使用如下命令进行修改. ethtool -s eth1 autoneg off speed 1000 duplex full ethtool -s eth2 autoneg off speed 1000 duplex full

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 [root@localhost pktgen]#ifconfig eth1 eth5 Link encap:Ethernet HWaddr 00:0C:29:97:9B:B4 inet addr:192.168.1.95 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:9bb4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:15044140 errors:0 dropped:0 overruns:0 frame:0 TX packets:14210498 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:903846363 (861.9 MiB) TX bytes:852636332 (813.1 MiB) [root@localhost pktgen]# ifconfig eth2 eth6 Link encap:Ethernet HWaddr 00:0C:29:97:9B:BE inet addr:192.168.1.96 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:9bbe/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14256340 errors:0 dropped:0 overruns:0 frame:0 TX packets:14998657 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:856589260 (816.9 MiB) TX bytes:899925597 (858.2 MiB) [root@localhost pktgen]# ethtool -s eth1 autoneg off speed 1000 duplex full [root@localhost pktgen]# ethtool -s eth2 autoneg off speed 1000 duplex full [root@localhost pktgen]# ethtool eth1 Settings foreth5: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: Unknown Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) Link detected: yes 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 [root@localhost pktgen]# ethtool eth2 Settings foreth6: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: Unknown Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) Link detected: yes [root@localhost pktgen]# 步骤2 ) 查看两个网口的中断号,并把eth1/eth2做亲和性绑定到特定的cpu.

注意:先关闭系统的irqbalance服务

[root@localhost ~]# cat /proc/interrupts | grep eth 16: 2586 540 1351588 4172554 IO-APIC-fasteoi Ensoniq AudioPCI, eth1 19: 5117 1949714 6098060 40 IO-APIC-fasteoi eth4, eth2 #说明:16和19 表示的是eth1和eth2的中断号 [root@localhost ~]# /etc/init.d/irqbalance stop Stopping irqbalance: [ OK ] #使用上面的命令停止irqbalance服务后,下面的语句就是绑定特定的cpu了: 注意: cpu的值对应关系如下: Binary Hex CPU 0 00000001 1 CPU 1 00000010 2 CPU 2 00000100 4 CPU 3 00001000 8 1 2 3 4 5 6 7 8 9 10 11 12 例如:如果我想把 IRQ 绑定到 CPU2 上就是 00000100=4: [root@localhost ~]# echo 4 > /proc/irq/19/smp_affinity [root@localhost ~]# echo 8 > /proc/irq/16/smp_affinity [root@localhost ~]# cat /proc/irq/19/smp_affinity 04 [root@localhost ~]# cat /proc/irq/16/smp_affinity 08

步骤3)在PC机上运行pktgen测试脚本:

脚本1:

2个网口(eth1/eth2))双向对发脚本. (即GWN7000的LAN1和LAN5之间双向对发数据测试) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #! /bin/sh # FileName: pktgen-eth1-eth2.conf # modprobe pktgen pgset() { local result echo $1 > $PGDEV result=`cat $PGDEV | fgrep \ if [ \ cat $PGDEV | fgrep Result: fi } pg() { echo inject > $PGDEV cat $PGDEV } # Config Start Here ----------------------------------------------------------- # thread config # Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly. 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 PGDEV=/proc/net/pktgen/kpktgend_2 echo \ pgset \ echo \ pgset \ PGDEV=/proc/net/pktgen/kpktgend_3 echo \ pgset \ echo \ pgset \ # device config # delay 0 means maximum speed. CLONE_SKB=\# NIC adds 4 bytes CRC PKT_SIZE=\ # COUNT 0 means forever #COUNT=\COUNT=\DELAY=\ PGDEV=/proc/net/pktgen/eth1 echo \ pgset \ pgset \ pgset \ pgset \ pgset \ pgset \ PGDEV=/proc/net/pktgen/eth2 echo \ pgset \ pgset \ pgset \ pgset \ pgset \ pgset \

# Time to run PGDEV=/proc/net/pktgen/pgctrl echo \ pgset \ echo \ # Result can be vieved in /proc/net/pktgen/eth[1,2] 脚本2:

2个网口之间单向发送测试脚本.(即GWN7000的LAN1向LAN5发数据测试) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #! /bin/sh # FileName: pktgen-eth1-eth2.conf # modprobe pktgen pgset() { local result echo $1 > $PGDEV result=`cat $PGDEV | fgrep \ if [ \ cat $PGDEV | fgrep Result: fi } pg() { echo inject > $PGDEV cat $PGDEV } # Config Start Here ----------------------------------------------------------- # thread config # Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly. PGDEV=/proc/net/pktgen/kpktgend_0 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 echo \ pgset \ echo \ pgset \ # device config # delay 0 means maximum speed. CLONE_SKB=\# NIC adds 4 bytes CRC PKT_SIZE=\ # COUNT 0 means forever #COUNT=\COUNT=\DELAY=\ PGDEV=/proc/net/pktgen/eth1 echo \ pgset \ pgset \ pgset \ pgset \ pgset \ pgset \ # Time to run PGDEV=/proc/net/pktgen/pgctrl echo \ pgset \ echo \ # Result can be vieved in /proc/net/pktgen/eth[1,2] 步骤4) 执行pktgen测试脚本的同时,查看发/收数据.

例如:将脚本保存到文件pktgen-eth1-eth2.sh中. 1 2 3 4 5 [root@localhost pktgen]# ./pktgen-eth1-eth2.sh Removing all devices Adding eth Removing all devices Adding eth6 6 7 8 Configuring /proc/net/pktgen/eth5 Configuring /proc/net/pktgen/eth6 Running... ctrl^C to stop 另开一个终端,执行mpstat命令查看cpu占用率,看网卡中断的处理是否正常: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@localhost ~]# mpstat -P 2,3 1 Linux 2.6.38.8 (localhost.localdomain) 01/15/2012 _x86_64_ (4 CPU) 09:13:16 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 09:13:17 AM 2 0.00 0.00 86.87 0.00 0.00 13.13 0.00 0.00 0.00 09:13:17 AM 3 0.00 0.00 74.23 0.00 0.00 25.77 0.00 0.00 0.00 09:13:18 AM 2 0.00 0.00 87.63 0.00 0.00 12.37 0.00 0.00 0.00 09:13:18 AM 3 0.00 0.00 76.53 0.00 0.00 23.47 0.00 0.00 0.00 09:13:19 AM 2 0.00 0.00 85.71 0.00 0.00 14.29 0.00 0.00 0.00 09:13:19 AM 3 0.00 0.00 75.51 0.00 0.00 24.49 0.00 0.00 0.00 09:13:20 AM 2 0.00 0.00 86.60 0.00 0.00 13.40 0.00 0.00 0.00 09:13:20 AM 3 0.00 0.00 70.10 0.00 0.00 29.90 0.00 0.00 0.00 ^C [root@localhost ~]# sar -n DEV 2 [root@localhost ~]# 执行一段时间后看统计数据: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [root@localhost pktgen]#cat /proc/net/pktgen/eth5 Params: count 0 min_pkt_size: 60 max_pkt_size: 60 frags: 0 delay: 0 clone_skb: 1000000 ifname: eth5 flows: 0 flowlen: 0 queue_map_min: 0 queue_map_max: 0 dst_min: 192.168.1.96 dst_max: src_min: src_max: src_mac: 00:0c:29:97:9b:b4 dst_mac: 00:0c:29:97:9b:be udp_src_min: 9 udp_src_max: 9 udp_dst_min: 9 udp_dst_max: 9 src_mac_count: 0 dst_mac_count: 0 Flags: Current: pkts-sofar: 4405203 errors: 0 started: 2423250036us stopped: 2570673239us idle: 61432us seq_num: 4405204 cur_dst_mac_offset: 0 cur_src_mac_offset: 0 cur_saddr: 0x5f01a8c0 cur_daddr: 0x6001a8c0 cur_udp_dst: 9 cur_udp_src: 9 cur_queue_map: 0 flows: 0 Result: OK: 147423202(c147361769+d61432) usec, 4405203 (60byte,0frags) 29881pps 14Mb/sec (14342880bps) errors: 0 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 [root@localhost pktgen]# cat /proc/net/pktgen/eth6 Params: count 0 min_pkt_size: 60 max_pkt_size: 60 frags: 0 delay: 0 clone_skb: 1000000 ifname: eth6 flows: 0 flowlen: 0 queue_map_min: 0 queue_map_max: 0 dst_min: 192.168.1.95 dst_max: src_min: src_max: src_mac: 00:0c:29:97:9b:be dst_mac: 00:0c:29:97:9b:b4 udp_src_min: 9 udp_src_max: 9 udp_dst_min: 9 udp_dst_max: 9 src_mac_count: 0 dst_mac_count: 0 Flags: Current: pkts-sofar: 2846965 errors: 0 started: 2423223982us stopped: 2570673243us idle: 45963us seq_num: 2846966 cur_dst_mac_offset: 0 cur_src_mac_offset: 0 cur_saddr: 0x6001a8c0 cur_daddr: 0x5f01a8c0 cur_udp_dst: 9 cur_udp_src: 9 cur_queue_map: 0 flows: 0 Result: OK: 147449261(c147403297+d45963) usec, 2846965 (60byte,0frags) 19308pps 9Mb/sec (9267840bps) errors: 0 [root@localhost pktgen]# 1.2 测试Nat模式下的包转发率

测试1: LAN->WAN发包

即PC机上的eth2口通过GWN7000的LAN1口向接在eth2口发包.

步骤1) 运行modprobe pktgen 命令,加载pktgen模块. 具体方法见链接. 步骤2) 并把eth1/eth2做亲和性绑定到特定的cpu. 具体方法见链接. 步骤3) 在linux PC上执行脚本:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #! /bin/sh # FileName: pktgen-eth5-eth6.conf # modprobe pktgen pgset() { local result echo $1 > $PGDEV result=`cat $PGDEV | fgrep \ if [ \ cat $PGDEV | fgrep Result: fi } pg() { echo inject > $PGDEV cat $PGDEV } # Config Start Here ----------------------------------------------------------- # thread config # Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly. PGDEV=/proc/net/pktgen/kpktgend_2 echo \ pgset \ echo \ pgset \ # device config # delay 0 means maximum speed. CLONE_SKB=\# NIC adds 4 bytes CRC PKT_SIZE=\ # COUNT 0 means forever #COUNT=\COUNT=\

本文来源:https://www.bwwdw.com/article/znva.html

Top