pktgen.conf

本文介绍了一个使用pktgen进行网络性能测试的shell脚本实例。该脚本详细展示了如何配置pktgen来实现对两个网络接口(eth5和eth6)的连续数据包注入,包括设置数据包大小、目的地址、MAC地址等关键参数,以及如何启动和停止数据包生成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#! /bin/sh
# FileName: pktgen-eth5-eth6.conf
# 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
}
# 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 "Removing all devices"
pgset "rem_device_all"
echo "Adding eth5"
pgset "add_device eth5"
PGDEV=/proc/net/pktgen/kpktgend_3
echo "Removing all devices"
pgset "rem_device_all"
echo "Adding eth6"
pgset "add_device eth6"
# device config
# delay 0 means maximum speed.
CLONE_SKB="clone_skb 1000000"
# NIC adds 4 bytes CRC
PKT_SIZE="pkt_size 60"
# COUNT 0 means forever
#COUNT="count 0"
COUNT="count 0"
DELAY="delay 0"
PGDEV=/proc/net/pktgen/eth5
echo "Configuring $PGDEV"
pgset "$COUNT"
pgset "$CLONE_SKB"
pgset "$PKT_SIZE"
pgset "$DELAY"
pgset "dst 192.168.1.96"
pgset "dst_mac 00:0C:29:97:9B:BE"
PGDEV=/proc/net/pktgen/eth6
echo "Configuring $PGDEV"
pgset "$COUNT"
pgset "$CLONE_SKB"
pgset "$PKT_SIZE"
pgset "$DELAY"
pgset "dst 192.168.1.95"
pgset "dst_mac 00:0C:29:97:9B:B4"
# Time to run
PGDEV=/proc/net/pktgen/pgctrl
echo "Running... ctrl^C to stop"
pgset "start"
echo "Done"
# Result can be vieved in /proc/net/pktgen/eth[5,6]

 

 

 pgset "clone_skb 1"     sets the number of copies of the same packet
 pgset "clone_skb 0"     use single SKB for all transmits
 pgset "pkt_size 9014"   sets packet size to 9014
 pgset "frags 5"         packet will consist of 5 fragments
 pgset "count 200000"    sets number of packets to send, set to zero
                        for continious sends untill explicitl stopped.
 pgset "delay 5000"      adds delay to hard_start_xmit(). nanoseconds
 pgset "dst 10.0.0.1"    sets IP destination addres
                        (BEWARE! This generator is very aggressive!)
 pgset "dst_min 10.0.0.1"            Same as dst
 pgset "dst_max 10.0.0.254"          Set the maximum destination IP.
 pgset "src_min 10.0.0.1"            Set the minimum (or only) source IP.
 pgset "src_max 10.0.0.254"          Set the maximum source IP.
 pgset "dst6 fec0::1"     IPV6 destination address
 pgset "src6 fec0::2"     IPV6 source address
 pgset "dstmac 00:00:00:00:00:00"    sets MAC destination address
 pgset "srcmac 00:00:00:00:00:00"    sets MAC source address
 pgset "src_mac_count 1" Sets the number of MACs we'll range through.  
                        The 'minimum' MAC is what you set with srcmac.
 pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
                        The 'minimum' MAC is what you set with dstmac.
 pgset "flag [name]"     Set a flag to determine behaviour.  Current flags
                        are: IPSRC_RND #IP Source is random (between min/max),
                             IPDST_RND, UDPSRC_RND,
                             UDPDST_RND, MACSRC_RND, MACDST_RND 
  pgset "udp_src_min 9"   set UDP source port min, If < udp_src_max, then
                        cycle through the port range.
  pgset "udp_src_max 9"   set UDP source port max.
  pgset "udp_dst_min 9"   set UDP destination port min, If < udp_dst_max, then
                        cycle through the port range.
  pgset "udp_dst_max 9"   set UDP destination port max.
  pgset stop                  aborts injection. Also, ^C aborts generator.

 

#! /bin/sh
#pktgen.conf-1-1 sample
#modprobe pktgen
# 写虚拟文件系统的函数, 每次操作之前, 设置好要操作的设备 $PGDEV 为 pgctl/kpktgend_X/ehtX
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
}

# Config Start Here -----------------------------------------------------------


# thread config
# Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly.

# 移除线程中对应的所有网口, 再添加
PGDEV=/proc/net/pktgen/kpktgend_0
  echo "Removing all devices"
 pgset "rem_device_all" 
  echo "Adding eth1"
 pgset "add_device eth1" 
  echo "Setting max_before_softirq 10000"
 pgset "max_before_softirq 10000"


# device config
# ipg is inter packet gap. 0 means maximum speed.

CLONE_SKB="clone_skb 1000000"
# NIC adds 4 bytes CRC
PKT_SIZE="pkt_size 60"

# COUNT 0 means forever
#COUNT="count 0"
COUNT="count 10000000"
# ipg 参数在我实验的时候无效, 我从2.6.32的源码中也没有看到相关的设置, 可以将 ipg 相关的配置删掉
#IPG="ipg 0"

PGDEV=/proc/net/pktgen/eth1
  echo "Configuring $PGDEV"
 pgset "$COUNT"
 pgset "$CLONE_SKB"
 pgset "$PKT_SIZE"
 #pgset "$IPG"
 # 配置目标IP
 pgset "dst 10.10.11.2" 
 # 配置目标MAC
 pgset "dst_mac  00:04:23:08:91:dc"


# Time to run
PGDEV=/proc/net/pktgen/pgctrl
# 发送 start 给 pgctl, 让 pktgen 开始发包
 echo "Running... ctrl^C to stop"
 pgset "start" 
 echo "Done"

# Result can be vieved in /proc/net/pktgen/eth1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值