-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Description
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |