Mini-HOWTO for the Linux packet generator module.
1. Enable CONFIG_NET_PKTGEN to compile and build pktgen.o either in kernel
or as module. Module is preferred. insmod pktgen if needed.
2. For montoring and control pktgen creates. Inspect them!
/proc/net/pktgen/pgctrl
/proc/net/pktgen/kpktgend_X
/proc/net/pktgen/ethX
3. Extract the example script «pktgen.sh» (see below).
4. Edit script to set preferred device and destination MAC, and IP address.
5. Run in shell: «./pktgen.sh»
It does all the setup including sending. Also
«echo «start» > /proc/net/pktgen/pgctrl» Starts sends on all threads and devs
Use
«cat /proc/pktgen/eth[X]» X={1,n} to inspect an interfacee.
7. Use «pgset» change pktgen settings. See examples.
«pgset» to change generator parameters. F.e.
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 explicitly
stopped.
pgset «ipg 5000″ sets artificial gap inserted between packets
to 5000 nanoseconds
pgset «dst 10.0.0.1″ sets IP destination address
(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 «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.
cut here —————————————————————–
#!/bin/sh
# pktgen.sh — 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 old devices»
pgset «rem_device_all»
echo «Adding eth1 on CPU»
pgset «add_device eth1″
echo «Adding eth2 on CPU»
pgset «add_device eth2″
echo «Max pkts. before softirq 5000″
pgset «max_before_softirq 5000″
# Configure the individual devices
echo «Configuring devices»
PGDEV=/proc/net/pktgen/eth1
pgset «clone_skb 10000″
pgset «pkt_size 60″
pgset «dst 10.10.10.2″
pgset «dst_mac 00:02:B3:9F:B4:25″
pgset «count 1000000″
# Next dev
PGDEV=/proc/net/pktgen/eth2
pgset «clone_skb 10000″
pgset «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»
cut here —————————————————————–
And on SMP systems we can take advantage other CPU’s.
# Select CPU0
PGDEV=/proc/net/pktgen/kpktgend_0
.
.
pgset «add_device eth1″
# Select CPU1
PGDEV=/proc/net/pktgen/kpktgend_1
.
.
pgset «add_device eth2″
So CPU0 is used for eth1 and CPU1 for eth2. Note! A device can only belong
to one CPU.
Note when adding devices to a specific CPU there good idea to also assign
/proc/irq/XX/smp_affinity so the TX-interrupts gets bound to the same CPU.
Current commands and configuration options.
===========================================
Pgcontrol commands:
——————
start
stop
Thread commands:
—————-
add_device
rem_device_all
max_before_softirq
Interface commands:
——————-
count
clone_skb
debug
frags
ipg
src_mac_count
dst_mac_count
pkt_size
min_pkt_size
max_pkt_size
udp_src_min
udp_src_max
udp_dst_min
udp_dst_max
flag
IPSRC_RND
TXSIZE_RND
IPDST_RND
UDPSRC_RND
UDPDST_RND
MACSRC_RND
MACDST_RND
dst_min
dst_max
src_min
src_max
dst_mac
src_mac
clear_counters