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