Skip to content

Testing with pktgen

ABC edited this page Nov 1, 2013 · 18 revisions

Networking stress test with pktgen. Pktgen have limitations, as it can generate UDP packets only (thus TCP is untested), and it can only inject outgoing packets into the device. To avoid second limitation I use KVM virtual box (where loaded ipt_NETFLOW.ko which needs to be tested).

On virtual box under KVM:

 virtual# ip addr
 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
     link/ether YY:YY:YY:YY:YY:YY brd ff:ff:ff:ff:ff:ff
     inet XX.X.XXX.XX/24 brd xx.x.xxx.255 scope global eth0

Pktgen generating UDP packets so system will naturally send ICMP (unreach) replies, which can saturate unnecessarily your intranet, to avoid these replies we should drop pktgen traffic after it's accounted in NETFLOW:

 virtual# iptables -I INPUT -s 10.0.0.0/8 -j DROP
 virtual# iptables -I OUTPUT -d 10.0.0.0/8 -j DROP

Note -I options. After that's done insert NETFLOW target so it goes before DROP target in INPUT chain.

On KVM host hardware node:

 hw_node# ip addr
 75: vnet2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500
     link/ether ZZ:YY:YY:YY:YY:YY brd ff:ff:ff:ff:ff:ff

Note that MAC address on the host interface will be not exactly the same as inside of virtual box.

pktgen script:

#!/bin/bash

set -e

dev=vnet2
dst_ip=XX.X.XXX.XX
dst_mac=YY:YY:YY:YY:YY:YY

pgset() {
  echo "$@"
  ctl=$1
  shift
  echo "$@" > /proc/net/pktgen/$ctl
}

pgset kpktgend_0 rem_device_all
pgset kpktgend_0 add_device $dev

pgset $dev count 0
pgset $dev flag IPSRC_RND
pgset $dev pkt_size 222

pgset $dev src_min 10.0.0.0
pgset $dev src_max 10.1.0.0

pgset $dev dst $dst_ip
pgset $dev dst_mac $dst_mac

pgset pgctrl start

Note that vnet2, XX.X.XXX.XX, and YY:YY:YY:YY:YY:YY should be replaced with appropriate strings. Also note to take MAC address string YY:YY:YY:YY:YY:YY from inside of virtual box, and not from hardware node interface, otherwise generated packets will not reach it.

This script will generate UDP packets on vnet2 device (which is device of particular virtual machine), source IP will be random in the network 10.0.0.0/16, destination IP will be virtual box's IP XX.X.XXX.XX. To stop script press ^C.

Et cetera

It could be useful (for testing) to even softirq load across cpus, I do something like this (for 4 cpu box):

 virtual# head /sys/class/net/*/queues/rx-*/rps_cpus
 virtual# echo f > /sys/class/net/eth0/queues/rx-0/rps_cpus
Clone this wiki locally