Skip to content

Instantly share code, notes, and snippets.

@amarao
Last active December 25, 2015 14:59
Show Gist options
  • Save amarao/6995531 to your computer and use it in GitHub Desktop.
Save amarao/6995531 to your computer and use it in GitHub Desktop.
#!/bin/bash
#modprobe pktgen
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_0
echo "Removing all devices"
pgset "rem_device_all"
echo "Adding vnet0"
pgset "add_device vnet0"
echo "Setting max_before_softirq 10000"
pgset "max_before_softirq 10000"
#PGDEV=/proc/net/pktgen/kpktgend_1
# echo "Removing all devices"
# pgset "rem_device_all"
# echo "Adding eth2"
# pgset "add_device eth2"
# echo "Setting max_before_softirq 10000"
# pgset "max_before_softirq 10000"
# device config
# delay 0 means maximum speed.
CLONE_SKB="clone_skb 100"
# NIC adds 4 bytes CRC
PKT_SIZE="pkt_size 60"
# COUNT 0 means forever
#COUNT="count 0"
COUNT="count 10000000"
DELAY="delay 0"
PGDEV=/proc/net/pktgen/vnet0
echo "Configuring $PGDEV"
pgset "$COUNT"
pgset "$CLONE_SKB"
pgset "$PKT_SIZE"
pgset "$DELAY"
pgset "dst 192.168.30.101"
pgset "dst_mac 52:54:00:cd:fb:85"
#PGDEV=/proc/net/pktgen/eth2
# echo "Configuring $PGDEV"
# pgset "$COUNT"
# pgset "$CLONE_SKB"
# pgset "$PKT_SIZE"
# pgset "$DELAY"
# pgset "dst 192.168.30.100"
# pgset "dst_mac 52:54:00:14:d3:f1"
# 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[1,2]
cat /proc/net/pktgen/vnet0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment