Skip to content

Commit

Permalink
Add script
Browse files Browse the repository at this point in the history
Add Description
  • Loading branch information
azhaocn committed Jun 30, 2018
1 parent 8b57fd1 commit 60a7d08
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# pktgen

Pktgen.sh is a script to use Linux pktgen module to generate packet. this example script has been tested on Ubuntu 18.04.
the script hard code the ip and mac address, please change it as your testing environment.

# Requirement
Change the RX and TX setting of the testing NIC.
>ethtool -C enp68s0f1 rx-usecs 30
>ethtool -G enp68s0f1 rx 4096
>ethtool -G enp68s0f1 tx 4096
>ip link set enp68s0f1 mtu 9014
# Usage
./pktgen.sh enp68s0f1 9000

# Note
Suggested to consider the cpu affinity, and you have to check the NUMA node of the testing NIC.

76 changes: 76 additions & 0 deletions pktgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#! /bin/bash
set +e

#modprobe pktgen

if [[ `lsmod | grep pktgen` == "" ]];then
modprobe pktgen
fi

if [[ $1 == "" ]];then
echo "need a device!"
exit
else
devif=$1
fi

if [[ $2 == "" ]];then
pktsize=1500
else
pktsize=$2
fi

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 ens3, ens3

PGDEV=/proc/net/pktgen/pgctrl
pgset "reset"

echo "Adding devices to run".
PGDEV=/proc/net/pktgen/kpktgend_1
pgset "rem_device_all"
pgset "add_device $devif"
#pgset "max_before_softirq 1000"

# Configure the individual devices
echo "Configuring devices"

PGDEV=/proc/net/pktgen/$devif
pgset "clone_skb 1000"
pgset "delay 0"
pgset "pkt_size $pktsize"
pgset "min_pkt_size $pktsize"
pgset "max_pkt_size $pktsize"
#pgset "rate 10G"
pgset "src_mac 90:e2:ba:83:81:85"
pgset "flag IPSRC_RND"
pgset "src_min 192.168.1.11"
pgset "dst 192.168.1.12"
pgset "dst_mac 90:e2:ba:8a:30:11"
pgset "count 0"

# Time to run

PGDEV=/proc/net/pktgen/pgctrl
echo "pkgsize:$pktsize"
echo "Running... ctrl^C to stop"

pgset "start"

echo "Done"

0 comments on commit 60a7d08

Please sign in to comment.