pktgen

The pktgen is a popular Linux tool for generating high-speed packets traffic to test network equipment for stress, throughput and stability behavior. Pktgen is included in the Linux kernel, thereby making it possible to generate packets with very little processing overhead. You can create a high-performance traffic generator/analyzer using Linux PC.

Prerequisites for using pktgen:

- Enable CONFIG_NET_PKTGEN to compile and build pktgen.o either in kernel
or as module. Module is preferred.

Example of script to generate IPv4 from Linux Eth1 network interface with the following parameters:

-packet size: 124 bytes;
-destination IP-address: 10.10.10.2;
-destination MAC-address: 00:00:00:00:01:02
- "delay 0" means no interpacket gap between the frames - highest speed
- "count 0" means that traffic will run untill Ctrl^C


#!/bin/sh
## pktgen.conf -- configuration for send on devices

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
}

## Settings for pktgen params

echo "Adding devices to run".

PGDEV=/proc/net/pktgen/kpktgend_0
pgset "rem_device_all"

pgset "add_device eth1"
pgset "max_before_softirq 10000"

## Configure the individual devices
echo "Configuring devices"
PGDEV=/proc/net/pktgen/eth1
pgset "clone_skb 10000"
pgset "pkt_size 124"
pgset "dst 10.10.10.2"
pgset "dst_mac 00:00:00:00:01:02"
pgset "count 0"
pgset "delay 0"

# Time to run

PGDEV=/proc/net/pktgen/pgctrl

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

pgset "start"

echo "Done"


The statistics can be viewed after run or after stop:
 
/proc/net/pktgen/eth1       
 
Params: count 10000000  min_pkt_size: 124  max_pkt_size: 124
  frags: 0  delay: 0  clone_skb: 10000   ifname: eth1
  flows: 0 flowlen: 0
  dst_min: 10.10.10.2  dst_max: 
  src_min:   src_max: 
  src_mac: 00:00:00:00:00:00  dst_mac: 00:00:00:00:01:02
  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: 10000000  errors: 39664
  started: 110304545187us  stopped: 110563999329us idle: 886401us
  seq_num: 10004445  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
  cur_saddr: 0x10a0a0a  cur_daddr: 0x20b0a0a
  cur_udp_dst: 9  cur_udp_src: 9
  flows: 0
Result: OK: 1334142(c12220741+d880401) usec, 10000000 (124byte,0frags)
   763292pps 390Mb/sec (390805504bps) errors: 39664

1 comment: