pktgen 测试网速

配置参照:http://blog.csdn.net/chengfangang/article/details/8123572

http://blog.csdn.net/chengfangang/article/details/8123678


$ lsmod | grep pktgen

$ modprobe pktgen

$ ps aux | grep pktgen

 然后,pktgen.txt上说可以检测下面三个文件的信息来了解pktgen

/proc/net/pktgen/pgctrl
/proc/net/pktgen/kpktgend_X
/proc/net/pktgen/ethX


若没有ethX,说明没有驱动,可以借助pktgen.conf-1-1进行驱动,需要把eth1改成eth0


参照http://www.linuxfoundation.org/collaborate/workgroups/networking/pktgen中的pktgen.sh写脚本,然后用  . pktgen.sh执行脚本, 通过cat /proc/net/pktgen/eth0来查看结果。

注意:测试千兆网时,如果网速达不到千兆(通过ethtool eth0看的),可以用命令修改网卡的设置:

# ethtool -s eth0 speed 1000 duplex full autoneg on


举例:

pktgen.sh代码如下

root@**:/home/
**/**# cat pktgen.sh
#!/bin/sh
# pktgen.conf -- Sample configuration for send on two devices on a UP system

#modprobe pktgen

function pgset() {
    local result

    echo $1 > $PGDEV

    result=`cat $PGDEV | fgrep "Result: OK:"`
    if [ "$result" = "" ]; then
         cat $PGDEV | fgrep Result:
    fi
}

function pg() {
    echo inject > $PGDEV
    cat $PGDEV
}

# On UP systems only one thread exists -- so just add devices 
# We use eth1, eth2

echo "Adding devices to run". 

PGDEV=/proc/net/pktgen/kpktgend_0
echo "Removing all devices"
pgset "rem_device_all" 
echo "add_device eth0"
pgset "add_device eth0" 
pgset "max_before_softirq 10000"

#pgset "max_before_softirq 10000"


# Configure the individual devices
echo "Configuring devices"

PGDEV=/proc/net/pktgen/eth0

#sets the number of copies of the same packet
pgset "clone_skb 10000" 

echo "dst 192.168.0.**"
pgset "dst 192.168.0.**"
echo "pkt_size 64"
pgset "pkt_size 64"
echo "count 1000000"
pgset "count 1000000"

#pgset "min_pkt_size 60" 
#pgset "max_pkt_size 60" 
#pgset "dst 10.10.10.2" 
#pgset "dst_mac 00:02:B3:9F:B4:25" 
#pgset "count 1000000"

# Time to run

PGDEV=/proc/net/pktgen/pgctrl

echo "Running... ctrl^C to stop"

pgset "start" 

echo "Done"

测试结果如下

root@**:/proc/net/pktgen# cat eth0
Params: count 1000000  min_pkt_size: 64  max_pkt_size: 64
     frags: 0  delay: 0  clone_skb: 10000  ifname: eth0
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min: 192.168.0.12  dst_max: 
        src_min:   src_max: 
     src_mac: 00:00:1a:1b:01:5d dst_mac: 00:00:00:00:00:00
     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: 1000000  errors: 0
     started: 66114240095us  stopped: 66116567003us idle: 1547us
     seq_num: 1000001  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 0x3700a8c0  cur_daddr: 0xc00a8c0
     cur_udp_dst: 9  cur_udp_src: 9
     cur_queue_map: 0
     flows: 0
Result: OK: 2326907(c2325360+d1547) usec, 1000000 (64byte,0frags)
  429754pps 220Mb/sec (220034048bps) errors: 0
root@**:/proc/net/pktgen# 



你可能感兴趣的:(pktgen 测试网速)