Skip to content

Commit 6f09479

Browse files
netoptimizerdavem330
authored andcommitted
pktgen: add sample script pktgen_sample01_simple.sh
Add the first basic pktgen samples script pktgen_sample01_simple.sh, which demonstrates the a simple use of the helper functions. Removing pktgen.conf-1-1 as that example should be covered now. The naming scheme pktgen_sampleNN, where NN is a number, should encourage reading the samples in a specific order. Script cause pktgen sending with a single thread and single interface, and introduce flow variation via random UDP source port. Usage example and help: ./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2 Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX -i : ($DEV) output interface/device (required) -s : ($PKT_SIZE) packet size -d : ($DEST_IP) destination IP -m : ($DST_MAC) destination MAC-addr -c : ($SKB_CLONE) SKB clones send before alloc new SKB -v : ($VERBOSE) verbose -x : ($DEBUG) debug Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b64b0d1 commit 6f09479

3 files changed

Lines changed: 94 additions & 65 deletions

File tree

‎Documentation/networking/pktgen.txt‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,30 @@ Examples:
219219
Sample scripts
220220
==============
221221

222-
A collection of small tutorial scripts for pktgen is in the
223-
samples/pktgen directory:
222+
A collection of tutorial scripts and helpers for pktgen is in the
223+
samples/pktgen directory. The helper parameters.sh file support easy
224+
and consistant parameter parsing across the sample scripts.
225+
226+
Usage example and help:
227+
./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2
228+
229+
Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX
230+
-i : ($DEV) output interface/device (required)
231+
-s : ($PKT_SIZE) packet size
232+
-d : ($DEST_IP) destination IP
233+
-m : ($DST_MAC) destination MAC-addr
234+
-t : ($THREADS) threads to start
235+
-c : ($SKB_CLONE) SKB clones send before alloc new SKB
236+
-b : ($BURST) HW level bursting of SKBs
237+
-v : ($VERBOSE) verbose
238+
-x : ($DEBUG) debug
239+
240+
The global variables being set are also listed. E.g. the required
241+
interface/device parameter "-i" sets variable $DEV. Copy the
242+
pktgen_sampleXX scripts and modify them to fit your own needs.
243+
244+
The old scripts:
224245

225-
pktgen.conf-1-1 # 1 CPU 1 dev
226246
pktgen.conf-1-2 # 1 CPU 2 dev
227247
pktgen.conf-2-1 # 2 CPU's 1 dev
228248
pktgen.conf-2-2 # 2 CPU's 2 dev
@@ -231,9 +251,6 @@ pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
231251
pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
232252
pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
233253

234-
Run in shell: ./pktgen.conf-X-Y
235-
This does all the setup including sending.
236-
237254

238255
Interrupt affinity
239256
===================

‎samples/pktgen/pktgen.conf-1-1‎

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
#
3+
# Simple example:
4+
# * pktgen sending with single thread and single interface
5+
# * flow variation via random UDP source port
6+
#
7+
basedir=`dirname $0`
8+
source ${basedir}/functions.sh
9+
root_check_run_with_sudo "$@"
10+
11+
# Parameter parsing via include
12+
# - go look in parameters.sh to see which setting are avail
13+
# - required param is the interface "-i" stored in $DEV
14+
source ${basedir}/parameters.sh
15+
#
16+
# Set some default params, if they didn't get set
17+
[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
18+
[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
19+
# Example enforce param "-m" for dst_mac
20+
[ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"
21+
22+
# Base Config
23+
DELAY="0" # Zero means max speed
24+
COUNT="100000" # Zero means indefinitely
25+
26+
# Flow variation random source port between min and max
27+
UDP_MIN=9
28+
UDP_MAX=109
29+
30+
# General cleanup everything since last run
31+
# (especially important if other threads were configured by other scripts)
32+
pg_ctrl "reset"
33+
34+
# Add remove all other devices and add_device $DEV to thread 0
35+
thread=0
36+
pg_thread $thread "rem_device_all"
37+
pg_thread $thread "add_device" $DEV
38+
39+
# How many packets to send (zero means indefinitely)
40+
pg_set $DEV "count $COUNT"
41+
42+
# Reduce alloc cost by sending same SKB many times
43+
# - this obviously affects the randomness within the packet
44+
pg_set $DEV "clone_skb $CLONE_SKB"
45+
46+
# Set packet size
47+
pg_set $DEV "pkt_size $PKT_SIZE"
48+
49+
# Delay between packets (zero means max speed)
50+
pg_set $DEV "delay $DELAY"
51+
52+
# Flag example disabling timestamping
53+
pg_set $DEV "flag NO_TIMESTAMP"
54+
55+
# Destination
56+
pg_set $DEV "dst_mac $DST_MAC"
57+
pg_set $DEV "dst $DEST_IP"
58+
59+
# Setup random UDP port src range
60+
pg_set $DEV "flag UDPSRC_RND"
61+
pg_set $DEV "udp_src_min $UDP_MIN"
62+
pg_set $DEV "udp_src_max $UDP_MAX"
63+
64+
# start_run
65+
echo "Running... ctrl^C to stop" >&2
66+
pg_ctrl "start"
67+
echo "Done" >&2
68+
69+
# Print results
70+
echo "Result device: $DEV"
71+
cat /proc/net/pktgen/$DEV

0 commit comments

Comments
 (0)