aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-05-22 23:59:23 -0400
committerDavid S. Miller <davem@davemloft.net>2015-05-22 23:59:23 -0400
commitfa7912be967102cdbecd8ef172571b28eb22099e (patch)
tree18c3a483cbb1337c729d18cc5fd2006582b36739
parentfe593844957a7ce092ee14e085ee8ddfd6c3b73f (diff)
parent05a14d5e17c21817946b6a50140c4a45257ad592 (diff)
Merge branch 'pktgen-new-scripts'
Jesper Dangaard Brouer says: ==================== pktgen: cleanups and introducing new samples/pktgen scripts v3: - Aborted v2 send due it was not generating diff stat (this is a bug in stg-mail, if not in the root directory) v2: address nitpicks from Cong Wang - Remove useless cat's, but keep them for old pgset() - Comment on: Due to pgctrl, cannot use exit code $? from grep - Use arithmetic compare in pktgen_sample03_burst_single_flow.sh This patchset is focused on making pktgen easier to use and better documented. It contains a number of documentation updates and minor changes to pktgen. The major contribution is introduction of common helper function for sample scripts. Instead of the old pgset() function, three new shell functions for configuring the different components of pktgen are introduced: pg_ctrl(), pg_thread() and pg_set(). The new functions correspond to pktgens different components. * pg_ctrl() control "pgctrl" (/proc/net/pktgen/pgctrl) * pg_thread() control the kernel threads and binding to devices * pg_set() control setup of individual devices Helpers also provide consistent parameter parsing across the sample scripts. Usage example: ./pktgen_sample01_simple.sh -i eth41 -m 00:12:C0:02:AC:5A -d 192.168.41.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 -t : ($THREADS) threads to start -c : ($SKB_CLONE) SKB clones send before alloc new SKB -b : ($BURST) HW level bursting of SKBs -v : ($VERBOSE) verbose -x : ($DEBUG) debug These scripts are borrowed from: https://github.com/netoptimizer/network-testing/tree/master/pktgen ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/networking/pktgen.txt141
-rw-r--r--net/core/pktgen.c6
-rw-r--r--samples/pktgen/README.rst43
-rw-r--r--samples/pktgen/functions.sh121
-rw-r--r--samples/pktgen/parameters.sh97
-rwxr-xr-xsamples/pktgen/pktgen.conf-1-159
-rwxr-xr-xsamples/pktgen/pktgen.conf-2-166
-rwxr-xr-xsamples/pktgen/pktgen.conf-2-273
-rwxr-xr-xsamples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh86
-rwxr-xr-xsamples/pktgen/pktgen_sample01_simple.sh71
-rwxr-xr-xsamples/pktgen/pktgen_sample02_multiqueue.sh75
-rwxr-xr-xsamples/pktgen/pktgen_sample03_burst_single_flow.sh82
12 files changed, 678 insertions, 242 deletions
diff --git a/Documentation/networking/pktgen.txt b/Documentation/networking/pktgen.txt
index 747faccc4120..f4be85e96005 100644
--- a/Documentation/networking/pktgen.txt
+++ b/Documentation/networking/pktgen.txt
@@ -1,6 +1,6 @@
1 1
2 2
3 HOWTO for the linux packet generator 3 HOWTO for the linux packet generator
4 ------------------------------------ 4 ------------------------------------
5 5
6Enable CONFIG_NET_PKTGEN to compile and build pktgen either in-kernel 6Enable CONFIG_NET_PKTGEN to compile and build pktgen either in-kernel
@@ -50,17 +50,33 @@ For ixgbe use e.g. "30" resulting in approx 33K interrupts/sec (1/30*10^6):
50 # ethtool -C ethX rx-usecs 30 50 # ethtool -C ethX rx-usecs 30
51 51
52 52
53Viewing threads 53Kernel threads
54=============== 54==============
55/proc/net/pktgen/kpktgend_0 55Pktgen creates a thread for each CPU with affinity to that CPU.
56Name: kpktgend_0 max_before_softirq: 10000 56Which is controlled through procfile /proc/net/pktgen/kpktgend_X.
57Running: 57
58Stopped: eth1 58Example: /proc/net/pktgen/kpktgend_0
59Result: OK: max_before_softirq=10000 59
60 Running:
61 Stopped: eth4@0
62 Result: OK: add_device=eth4@0
63
64Most important are the devices assigned to the thread.
65
66The two basic thread commands are:
67 * add_device DEVICE@NAME -- adds a single device
68 * rem_device_all -- remove all associated devices
60 69
61Most important are the devices assigned to the thread. Note that a 70When adding a device to a thread, a corrosponding procfile is created
62device can only belong to one thread. 71which is used for configuring this device. Thus, device names need to
72be unique.
63 73
74To support adding the same device to multiple threads, which is useful
75with multi queue NICs, a the device naming scheme is extended with "@":
76 device@something
77
78The part after "@" can be anything, but it is custom to use the thread
79number.
64 80
65Viewing devices 81Viewing devices
66=============== 82===============
@@ -69,29 +85,32 @@ The Params section holds configured information. The Current section
69holds running statistics. The Result is printed after a run or after 85holds running statistics. The Result is printed after a run or after
70interruption. Example: 86interruption. Example:
71 87
72/proc/net/pktgen/eth1 88/proc/net/pktgen/eth4@0
73 89
74Params: count 10000000 min_pkt_size: 60 max_pkt_size: 60 90 Params: count 100000 min_pkt_size: 60 max_pkt_size: 60
75 frags: 0 delay: 0 clone_skb: 1000000 ifname: eth1 91 frags: 0 delay: 0 clone_skb: 64 ifname: eth4@0
76 flows: 0 flowlen: 0 92 flows: 0 flowlen: 0
77 dst_min: 10.10.11.2 dst_max: 93 queue_map_min: 0 queue_map_max: 0
78 src_min: src_max: 94 dst_min: 192.168.81.2 dst_max:
79 src_mac: 00:00:00:00:00:00 dst_mac: 00:04:23:AC:FD:82 95 src_min: src_max:
80 udp_src_min: 9 udp_src_max: 9 udp_dst_min: 9 udp_dst_max: 9 96 src_mac: 90:e2:ba:0a:56:b4 dst_mac: 00:1b:21:3c:9d:f8
81 src_mac_count: 0 dst_mac_count: 0 97 udp_src_min: 9 udp_src_max: 109 udp_dst_min: 9 udp_dst_max: 9
82 Flags: 98 src_mac_count: 0 dst_mac_count: 0
83Current: 99 Flags: UDPSRC_RND NO_TIMESTAMP QUEUE_MAP_CPU
84 pkts-sofar: 10000000 errors: 39664 100 Current:
85 started: 1103053986245187us stopped: 1103053999346329us idle: 880401us 101 pkts-sofar: 100000 errors: 0
86 seq_num: 10000011 cur_dst_mac_offset: 0 cur_src_mac_offset: 0 102 started: 623913381008us stopped: 623913396439us idle: 25us
87 cur_saddr: 0x10a0a0a cur_daddr: 0x20b0a0a 103 seq_num: 100001 cur_dst_mac_offset: 0 cur_src_mac_offset: 0
88 cur_udp_dst: 9 cur_udp_src: 9 104 cur_saddr: 192.168.8.3 cur_daddr: 192.168.81.2
105 cur_udp_dst: 9 cur_udp_src: 42
106 cur_queue_map: 0
89 flows: 0 107 flows: 0
90Result: OK: 13101142(c12220741+d880401) usec, 10000000 (60byte,0frags) 108 Result: OK: 15430(c15405+d25) usec, 100000 (60byte,0frags)
91 763292pps 390Mb/sec (390805504bps) errors: 39664 109 6480562pps 3110Mb/sec (3110669760bps) errors: 0
110
92 111
93Configuring threads and devices 112Configuring devices
94================================ 113===================
95This is done via the /proc interface, and most easily done via pgset 114This is done via the /proc interface, and most easily done via pgset
96as defined in the sample scripts. 115as defined in the sample scripts.
97 116
@@ -126,7 +145,7 @@ Examples:
126 To select queue 1 of a given device, 145 To select queue 1 of a given device,
127 use queue_map_min=1 and queue_map_max=1 146 use queue_map_min=1 and queue_map_max=1
128 147
129 pgset "src_mac_count 1" Sets the number of MACs we'll range through. 148 pgset "src_mac_count 1" Sets the number of MACs we'll range through.
130 The 'minimum' MAC is what you set with srcmac. 149 The 'minimum' MAC is what you set with srcmac.
131 150
132 pgset "dst_mac_count 1" Sets the number of MACs we'll range through. 151 pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
@@ -200,21 +219,36 @@ Examples:
200Sample scripts 219Sample scripts
201============== 220==============
202 221
203A collection of small tutorial scripts for pktgen is in the 222A collection of tutorial scripts and helpers for pktgen is in the
204samples/pktgen directory: 223samples/pktgen directory. The helper parameters.sh file support easy
224and consistant parameter parsing across the sample scripts.
225
226Usage example and help:
227 ./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2
228
229Usage: ./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
240The global variables being set are also listed. E.g. the required
241interface/device parameter "-i" sets variable $DEV. Copy the
242pktgen_sampleXX scripts and modify them to fit your own needs.
243
244The old scripts:
205 245
206pktgen.conf-1-1 # 1 CPU 1 dev
207pktgen.conf-1-2 # 1 CPU 2 dev 246pktgen.conf-1-2 # 1 CPU 2 dev
208pktgen.conf-2-1 # 2 CPU's 1 dev
209pktgen.conf-2-2 # 2 CPU's 2 dev
210pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS 247pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
211pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6 248pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
212pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS 249pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
213pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows. 250pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
214 251
215Run in shell: ./pktgen.conf-X-Y
216This does all the setup including sending.
217
218 252
219Interrupt affinity 253Interrupt affinity
220=================== 254===================
@@ -222,6 +256,9 @@ Note that when adding devices to a specific CPU it is a good idea to
222also assign /proc/irq/XX/smp_affinity so that the TX interrupts are bound 256also assign /proc/irq/XX/smp_affinity so that the TX interrupts are bound
223to the same CPU. This reduces cache bouncing when freeing skbs. 257to the same CPU. This reduces cache bouncing when freeing skbs.
224 258
259Plus using the device flag QUEUE_MAP_CPU, which maps the SKBs TX queue
260to the running threads CPU (directly from smp_processor_id()).
261
225Enable IPsec 262Enable IPsec
226============ 263============
227Default IPsec transformation with ESP encapsulation plus transport mode 264Default IPsec transformation with ESP encapsulation plus transport mode
@@ -242,18 +279,19 @@ Current commands and configuration options
242 279
243start 280start
244stop 281stop
282reset
245 283
246** Thread commands: 284** Thread commands:
247 285
248add_device 286add_device
249rem_device_all 287rem_device_all
250max_before_softirq
251 288
252 289
253** Device commands: 290** Device commands:
254 291
255count 292count
256clone_skb 293clone_skb
294burst
257debug 295debug
258 296
259frags 297frags
@@ -262,10 +300,17 @@ delay
262src_mac_count 300src_mac_count
263dst_mac_count 301dst_mac_count
264 302
265pkt_size 303pkt_size
266min_pkt_size 304min_pkt_size
267max_pkt_size 305max_pkt_size
268 306
307queue_map_min
308queue_map_max
309skb_priority
310
311tos (ipv4)
312traffic_class (ipv6)
313
269mpls 314mpls
270 315
271udp_src_min 316udp_src_min
@@ -274,6 +319,8 @@ udp_src_max
274udp_dst_min 319udp_dst_min
275udp_dst_max 320udp_dst_max
276 321
322node
323
277flag 324flag
278 IPSRC_RND 325 IPSRC_RND
279 IPDST_RND 326 IPDST_RND
@@ -294,6 +341,8 @@ flag
294 NODE_ALLOC 341 NODE_ALLOC
295 NO_TIMESTAMP 342 NO_TIMESTAMP
296 343
344spi (ipsec)
345
297dst_min 346dst_min
298dst_max 347dst_max
299 348
@@ -305,8 +354,10 @@ src_mac
305 354
306clear_counters 355clear_counters
307 356
308dst6
309src6 357src6
358dst6
359dst6_max
360dst6_min
310 361
311flows 362flows
312flowlen 363flowlen
@@ -316,6 +367,14 @@ ratep
316 367
317xmit_mode <start_xmit|netif_receive> 368xmit_mode <start_xmit|netif_receive>
318 369
370vlan_cfi
371vlan_id
372vlan_p
373
374svlan_cfi
375svlan_id
376svlan_p
377
319 378
320References: 379References:
321ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/ 380ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 62f979984a23..676550f34560 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -177,7 +177,7 @@
177#include <asm/dma.h> 177#include <asm/dma.h>
178#include <asm/div64.h> /* do_div */ 178#include <asm/div64.h> /* do_div */
179 179
180#define VERSION "2.74" 180#define VERSION "2.75"
181#define IP_NAME_SZ 32 181#define IP_NAME_SZ 32
182#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */ 182#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
183#define MPLS_STACK_BOTTOM htonl(0x00000100) 183#define MPLS_STACK_BOTTOM htonl(0x00000100)
@@ -512,7 +512,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,
512 pktgen_reset_all_threads(pn); 512 pktgen_reset_all_threads(pn);
513 513
514 else 514 else
515 pr_warn("Unknown command: %s\n", data); 515 return -EINVAL;
516 516
517 return count; 517 return count;
518} 518}
@@ -572,7 +572,7 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
572 " dst_min: %s dst_max: %s\n", 572 " dst_min: %s dst_max: %s\n",
573 pkt_dev->dst_min, pkt_dev->dst_max); 573 pkt_dev->dst_min, pkt_dev->dst_max);
574 seq_printf(seq, 574 seq_printf(seq,
575 " src_min: %s src_max: %s\n", 575 " src_min: %s src_max: %s\n",
576 pkt_dev->src_min, pkt_dev->src_max); 576 pkt_dev->src_min, pkt_dev->src_max);
577 } 577 }
578 578
diff --git a/samples/pktgen/README.rst b/samples/pktgen/README.rst
new file mode 100644
index 000000000000..8365c4e5c513
--- /dev/null
+++ b/samples/pktgen/README.rst
@@ -0,0 +1,43 @@
1Sample and benchmark scripts for pktgen (packet generator)
2==========================================================
3This directory contains some pktgen sample and benchmark scripts, that
4can easily be copied and adjusted for your own use-case.
5
6General doc is located in kernel: Documentation/networking/pktgen.txt
7
8Helper include files
9====================
10This directory contains two helper shell files, that can be "included"
11by shell source'ing. Namely "functions.sh" and "parameters.sh".
12
13Common parameters
14-----------------
15The parameters.sh file support easy and consistant parameter parsing
16across the sample scripts. Usage example is printed on errors::
17
18 Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX
19 -i : ($DEV) output interface/device (required)
20 -s : ($PKT_SIZE) packet size
21 -d : ($DEST_IP) destination IP
22 -m : ($DST_MAC) destination MAC-addr
23 -t : ($THREADS) threads to start
24 -c : ($SKB_CLONE) SKB clones send before alloc new SKB
25 -b : ($BURST) HW level bursting of SKBs
26 -v : ($VERBOSE) verbose
27 -x : ($DEBUG) debug
28
29The global variable being set is also listed. E.g. the required
30interface/device parameter "-i" sets variable $DEV.
31
32Common functions
33----------------
34The functions.sh file provides; Three different shell functions for
35configuring the different components of pktgen: pg_ctrl(), pg_thread()
36and pg_set().
37
38These functions correspond to pktgens different components.
39 * pg_ctrl() control "pgctrl" (/proc/net/pktgen/pgctrl)
40 * pg_thread() control the kernel threads and binding to devices
41 * pg_set() control setup of individual devices
42
43See sample scripts for usage examples.
diff --git a/samples/pktgen/functions.sh b/samples/pktgen/functions.sh
new file mode 100644
index 000000000000..205e4cde4601
--- /dev/null
+++ b/samples/pktgen/functions.sh
@@ -0,0 +1,121 @@
1#
2# Common functions used by pktgen scripts
3# - Depending on bash 3 (or higher) syntax
4#
5# Author: Jesper Dangaaard Brouer
6# License: GPL
7
8## -- General shell logging cmds --
9function err() {
10 local exitcode=$1
11 shift
12 echo "ERROR: $@" >&2
13 exit $exitcode
14}
15
16function warn() {
17 echo "WARN : $@" >&2
18}
19
20function info() {
21 if [[ -n "$VERBOSE" ]]; then
22 echo "INFO : $@" >&2
23 fi
24}
25
26## -- Pktgen proc config commands -- ##
27export PROC_DIR=/proc/net/pktgen
28#
29# Three different shell functions for configuring the different
30# components of pktgen:
31# pg_ctrl(), pg_thread() and pg_set().
32#
33# These functions correspond to pktgens different components.
34# * pg_ctrl() control "pgctrl" (/proc/net/pktgen/pgctrl)
35# * pg_thread() control the kernel threads and binding to devices
36# * pg_set() control setup of individual devices
37function pg_ctrl() {
38 local proc_file="pgctrl"
39 proc_cmd ${proc_file} "$@"
40}
41
42function pg_thread() {
43 local thread=$1
44 local proc_file="kpktgend_${thread}"
45 shift
46 proc_cmd ${proc_file} "$@"
47}
48
49function pg_set() {
50 local dev=$1
51 local proc_file="$dev"
52 shift
53 proc_cmd ${proc_file} "$@"
54}
55
56# More generic replacement for pgset(), that does not depend on global
57# variable for proc file.
58function proc_cmd() {
59 local result
60 local proc_file=$1
61 # after shift, the remaining args are contained in $@
62 shift
63 local proc_ctrl=${PROC_DIR}/$proc_file
64 if [[ ! -e "$proc_ctrl" ]]; then
65 err 3 "proc file:$proc_ctrl does not exists (dev added to thread?)"
66 else
67 if [[ ! -w "$proc_ctrl" ]]; then
68 err 4 "proc file:$proc_ctrl not writable, not root?!"
69 fi
70 fi
71
72 if [[ "$DEBUG" == "yes" ]]; then
73 echo "cmd: $@ > $proc_ctrl"
74 fi
75 # Quoting of "$@" is important for space expansion
76 echo "$@" > "$proc_ctrl"
77 local status=$?
78
79 result=$(grep "Result: OK:" $proc_ctrl)
80 # Due to pgctrl, cannot use exit code $? from grep
81 if [[ "$result" == "" ]]; then
82 grep "Result:" $proc_ctrl >&2
83 fi
84 if (( $status != 0 )); then
85 err 5 "Write error($status) occurred cmd: \"$@ > $proc_ctrl\""
86 fi
87}
88
89# Old obsolete "pgset" function, with slightly improved err handling
90function pgset() {
91 local result
92
93 if [[ "$DEBUG" == "yes" ]]; then
94 echo "cmd: $1 > $PGDEV"
95 fi
96 echo $1 > $PGDEV
97 local status=$?
98
99 result=`cat $PGDEV | fgrep "Result: OK:"`
100 if [[ "$result" == "" ]]; then
101 cat $PGDEV | fgrep Result:
102 fi
103 if (( $status != 0 )); then
104 err 5 "Write error($status) occurred cmd: \"$1 > $PGDEV\""
105 fi
106}
107
108## -- General shell tricks --
109
110function root_check_run_with_sudo() {
111 # Trick so, program can be run as normal user, will just use "sudo"
112 # call as root_check_run_as_sudo "$@"
113 if [ "$EUID" -ne 0 ]; then
114 if [ -x $0 ]; then # Directly executable use sudo
115 info "Not root, running with sudo"
116 sudo "$0" "$@"
117 exit $?
118 fi
119 err 4 "cannot perform sudo run of $0"
120 fi
121}
diff --git a/samples/pktgen/parameters.sh b/samples/pktgen/parameters.sh
new file mode 100644
index 000000000000..33b70fdd5a4a
--- /dev/null
+++ b/samples/pktgen/parameters.sh
@@ -0,0 +1,97 @@
1#
2# Common parameter parsing for pktgen scripts
3#
4
5function usage() {
6 echo ""
7 echo "Usage: $0 [-vx] -i ethX"
8 echo " -i : (\$DEV) output interface/device (required)"
9 echo " -s : (\$PKT_SIZE) packet size"
10 echo " -d : (\$DEST_IP) destination IP"
11 echo " -m : (\$DST_MAC) destination MAC-addr"
12 echo " -t : (\$THREADS) threads to start"
13 echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB"
14 echo " -b : (\$BURST) HW level bursting of SKBs"
15 echo " -v : (\$VERBOSE) verbose"
16 echo " -x : (\$DEBUG) debug"
17 echo ""
18}
19
20## --- Parse command line arguments / parameters ---
21## echo "Commandline options:"
22while getopts "s:i:d:m:t:c:b:vxh" option; do
23 case $option in
24 i) # interface
25 export DEV=$OPTARG
26 info "Output device set to: DEV=$DEV"
27 ;;
28 s)
29 export PKT_SIZE=$OPTARG
30 info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes"
31 ;;
32 d) # destination IP
33 export DEST_IP=$OPTARG
34 info "Destination IP set to: DEST_IP=$DEST_IP"
35 ;;
36 m) # MAC
37 export DST_MAC=$OPTARG
38 info "Destination MAC set to: DST_MAC=$DST_MAC"
39 ;;
40 t)
41 export THREADS=$OPTARG
42 export CPU_THREADS=$OPTARG
43 let "CPU_THREADS -= 1"
44 info "Number of threads to start: $THREADS (0 to $CPU_THREADS)"
45 ;;
46 c)
47 export CLONE_SKB=$OPTARG
48 info "CLONE_SKB=$CLONE_SKB"
49 ;;
50 b)
51 export BURST=$OPTARG
52 info "SKB bursting: BURST=$BURST"
53 ;;
54 v)
55 export VERBOSE=yes
56 info "Verbose mode: VERBOSE=$VERBOSE"
57 ;;
58 x)
59 export DEBUG=yes
60 info "Debug mode: DEBUG=$DEBUG"
61 ;;
62 h|?|*)
63 usage;
64 err 2 "[ERROR] Unknown parameters!!!"
65 esac
66done
67shift $(( $OPTIND - 1 ))
68
69if [ -z "$PKT_SIZE" ]; then
70 # NIC adds 4 bytes CRC
71 export PKT_SIZE=60
72 info "Default packet size set to: set to: $PKT_SIZE bytes"
73fi
74
75if [ -z "$THREADS" ]; then
76 # Zero CPU threads means one thread, because CPU numbers are zero indexed
77 export CPU_THREADS=0
78 export THREADS=1
79fi
80
81if [ -z "$DEV" ]; then
82 usage
83 err 2 "Please specify output device"
84fi
85
86if [ -z "$DST_MAC" ]; then
87 warn "Missing destination MAC address"
88fi
89
90if [ -z "$DEST_IP" ]; then
91 warn "Missing destination IP address"
92fi
93
94if [ ! -d /proc/net/pktgen ]; then
95 info "Loading kernel module: pktgen"
96 modprobe pktgen
97fi
diff --git a/samples/pktgen/pktgen.conf-1-1 b/samples/pktgen/pktgen.conf-1-1
deleted file mode 100755
index f91daad9e916..000000000000
--- a/samples/pktgen/pktgen.conf-1-1
+++ /dev/null
@@ -1,59 +0,0 @@
1#!/bin/bash
2
3#modprobe pktgen
4
5
6function pgset() {
7 local result
8
9 echo $1 > $PGDEV
10
11 result=`cat $PGDEV | fgrep "Result: OK:"`
12 if [ "$result" = "" ]; then
13 cat $PGDEV | fgrep Result:
14 fi
15}
16
17# Config Start Here -----------------------------------------------------------
18
19
20# thread config
21# Each CPU has its own thread. One CPU example. We add eth1.
22
23PGDEV=/proc/net/pktgen/kpktgend_0
24 echo "Removing all devices"
25 pgset "rem_device_all"
26 echo "Adding eth1"
27 pgset "add_device eth1"
28
29
30# device config
31# delay 0 means maximum speed.
32
33CLONE_SKB="clone_skb 1000000"
34# NIC adds 4 bytes CRC
35PKT_SIZE="pkt_size 60"
36
37# COUNT 0 means forever
38#COUNT="count 0"
39COUNT="count 10000000"
40DELAY="delay 0"
41
42PGDEV=/proc/net/pktgen/eth1
43 echo "Configuring $PGDEV"
44 pgset "$COUNT"
45 pgset "$CLONE_SKB"
46 pgset "$PKT_SIZE"
47 pgset "$DELAY"
48 pgset "dst 10.10.11.2"
49 pgset "dst_mac 00:04:23:08:91:dc"
50
51
52# Time to run
53PGDEV=/proc/net/pktgen/pgctrl
54
55 echo "Running... ctrl^C to stop"
56 trap true INT
57 pgset "start"
58 echo "Done"
59 cat /proc/net/pktgen/eth1
diff --git a/samples/pktgen/pktgen.conf-2-1 b/samples/pktgen/pktgen.conf-2-1
deleted file mode 100755
index e108e97d6d89..000000000000
--- a/samples/pktgen/pktgen.conf-2-1
+++ /dev/null
@@ -1,66 +0,0 @@
1#!/bin/bash
2
3#modprobe pktgen
4
5
6function pgset() {
7 local result
8
9 echo $1 > $PGDEV
10
11 result=`cat $PGDEV | fgrep "Result: OK:"`
12 if [ "$result" = "" ]; then
13 cat $PGDEV | fgrep Result:
14 fi
15}
16
17# Config Start Here -----------------------------------------------------------
18
19
20# thread config
21# Each CPU has its own thread. Two CPU example. We add eth1 to the first
22# and leave the second idle.
23
24PGDEV=/proc/net/pktgen/kpktgend_0
25 echo "Removing all devices"
26 pgset "rem_device_all"
27 echo "Adding eth1"
28 pgset "add_device eth1"
29
30# We need to remove old config since we dont use this thread. We can only
31# one NIC on one CPU due to affinity reasons.
32
33PGDEV=/proc/net/pktgen/kpktgend_1
34 echo "Removing all devices"
35 pgset "rem_device_all"
36
37# device config
38# delay 0 means maximum speed.
39
40CLONE_SKB="clone_skb 1000000"
41# NIC adds 4 bytes CRC
42PKT_SIZE="pkt_size 60"
43
44# COUNT 0 means forever
45#COUNT="count 0"
46COUNT="count 10000000"
47DELAY="delay 0"
48
49PGDEV=/proc/net/pktgen/eth1
50 echo "Configuring $PGDEV"
51 pgset "$COUNT"
52 pgset "$CLONE_SKB"
53 pgset "$PKT_SIZE"
54 pgset "$DELAY"
55 pgset "dst 10.10.11.2"
56 pgset "dst_mac 00:04:23:08:91:dc"
57
58
59# Time to run
60PGDEV=/proc/net/pktgen/pgctrl
61
62 echo "Running... ctrl^C to stop"
63 trap true INT
64 pgset "start"
65 echo "Done"
66 cat /proc/net/pktgen/eth1
diff --git a/samples/pktgen/pktgen.conf-2-2 b/samples/pktgen/pktgen.conf-2-2
deleted file mode 100755
index acea15503e71..000000000000
--- a/samples/pktgen/pktgen.conf-2-2
+++ /dev/null
@@ -1,73 +0,0 @@
1#!/bin/bash
2
3#modprobe pktgen
4
5
6function pgset() {
7 local result
8
9 echo $1 > $PGDEV
10
11 result=`cat $PGDEV | fgrep "Result: OK:"`
12 if [ "$result" = "" ]; then
13 cat $PGDEV | fgrep Result:
14 fi
15}
16
17# Config Start Here -----------------------------------------------------------
18
19
20# thread config
21# Each CPU has its own thread. Two CPU example. We add eth1, eth2 respectively.
22
23PGDEV=/proc/net/pktgen/kpktgend_0
24 echo "Removing all devices"
25 pgset "rem_device_all"
26 echo "Adding eth1"
27 pgset "add_device eth1"
28
29PGDEV=/proc/net/pktgen/kpktgend_1
30 echo "Removing all devices"
31 pgset "rem_device_all"
32 echo "Adding eth2"
33 pgset "add_device eth2"
34
35
36# device config
37# delay 0 means maximum speed.
38
39CLONE_SKB="clone_skb 1000000"
40# NIC adds 4 bytes CRC
41PKT_SIZE="pkt_size 60"
42
43# COUNT 0 means forever
44#COUNT="count 0"
45COUNT="count 10000000"
46DELAY="delay 0"
47
48PGDEV=/proc/net/pktgen/eth1
49 echo "Configuring $PGDEV"
50 pgset "$COUNT"
51 pgset "$CLONE_SKB"
52 pgset "$PKT_SIZE"
53 pgset "$DELAY"
54 pgset "dst 10.10.11.2"
55 pgset "dst_mac 00:04:23:08:91:dc"
56
57PGDEV=/proc/net/pktgen/eth2
58 echo "Configuring $PGDEV"
59 pgset "$COUNT"
60 pgset "$CLONE_SKB"
61 pgset "$PKT_SIZE"
62 pgset "$DELAY"
63 pgset "dst 192.168.2.2"
64 pgset "dst_mac 00:04:23:08:91:de"
65
66# Time to run
67PGDEV=/proc/net/pktgen/pgctrl
68
69 echo "Running... ctrl^C to stop"
70 trap true INT
71 pgset "start"
72 echo "Done"
73 cat /proc/net/pktgen/eth1 /proc/net/pktgen/eth2
diff --git a/samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh b/samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
new file mode 100755
index 000000000000..cb1590331b47
--- /dev/null
+++ b/samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
@@ -0,0 +1,86 @@
1#!/bin/bash
2#
3# Benchmark script:
4# - developed for benchmarking ingress qdisc path
5#
6# Script for injecting packets into RX path of the stack with pktgen
7# "xmit_mode netif_receive". With an invalid dst_mac this will only
8# measure the ingress code path as packets gets dropped in ip_rcv().
9#
10# This script don't really need any hardware. It benchmarks software
11# RX path just after NIC driver level. With bursting is also
12# "removes" the SKB alloc/free overhead.
13#
14# Setup scenarios for measuring ingress qdisc (with invalid dst_mac):
15# ------------------------------------------------------------------
16# (1) no ingress (uses static_key_false(&ingress_needed))
17#
18# (2) ingress on other dev (change ingress_needed and calls
19# handle_ing() but exit early)
20#
21# config: tc qdisc add dev $SOMEDEV handle ffff: ingress
22#
23# (3) ingress on this dev, handle_ing() -> tc_classify()
24#
25# config: tc qdisc add dev $DEV handle ffff: ingress
26#
27# (4) ingress on this dev + drop at u32 classifier/action.
28#
29basedir=`dirname $0`
30source ${basedir}/functions.sh
31root_check_run_with_sudo "$@"
32
33# Parameter parsing via include
34source ${basedir}/parameters.sh
35# Using invalid DST_MAC will cause the packets to get dropped in
36# ip_rcv() which is part of the test
37[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
38[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
39[ -z "$BURST" ] && BURST=1024
40
41# Base Config
42DELAY="0" # Zero means max speed
43COUNT="10000000" # Zero means indefinitely
44
45# General cleanup everything since last run
46pg_ctrl "reset"
47
48# Threads are specified with parameter -t value in $THREADS
49for ((thread = 0; thread < $THREADS; thread++)); do
50 # The device name is extended with @name, using thread number to
51 # make then unique, but any name will do.
52 dev=${DEV}@${thread}
53
54 # Add remove all other devices and add_device $dev to thread
55 pg_thread $thread "rem_device_all"
56 pg_thread $thread "add_device" $dev
57
58 # Base config of dev
59 pg_set $dev "flag QUEUE_MAP_CPU"
60 pg_set $dev "count $COUNT"
61 pg_set $dev "pkt_size $PKT_SIZE"
62 pg_set $dev "delay $DELAY"
63 pg_set $dev "flag NO_TIMESTAMP"
64
65 # Destination
66 pg_set $dev "dst_mac $DST_MAC"
67 pg_set $dev "dst $DEST_IP"
68
69 # Inject packet into RX path of stack
70 pg_set $dev "xmit_mode netif_receive"
71
72 # Burst allow us to avoid measuring SKB alloc/free overhead
73 pg_set $dev "burst $BURST"
74done
75
76# start_run
77echo "Running... ctrl^C to stop" >&2
78pg_ctrl "start"
79echo "Done" >&2
80
81# Print results
82for ((thread = 0; thread < $THREADS; thread++)); do
83 dev=${DEV}@${thread}
84 echo "Device: $dev"
85 cat /proc/net/pktgen/$dev | grep -A2 "Result:"
86done
diff --git a/samples/pktgen/pktgen_sample01_simple.sh b/samples/pktgen/pktgen_sample01_simple.sh
new file mode 100755
index 000000000000..8c9d318c221b
--- /dev/null
+++ b/samples/pktgen/pktgen_sample01_simple.sh
@@ -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#
7basedir=`dirname $0`
8source ${basedir}/functions.sh
9root_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
14source ${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
23DELAY="0" # Zero means max speed
24COUNT="100000" # Zero means indefinitely
25
26# Flow variation random source port between min and max
27UDP_MIN=9
28UDP_MAX=109
29
30# General cleanup everything since last run
31# (especially important if other threads were configured by other scripts)
32pg_ctrl "reset"
33
34# Add remove all other devices and add_device $DEV to thread 0
35thread=0
36pg_thread $thread "rem_device_all"
37pg_thread $thread "add_device" $DEV
38
39# How many packets to send (zero means indefinitely)
40pg_set $DEV "count $COUNT"
41
42# Reduce alloc cost by sending same SKB many times
43# - this obviously affects the randomness within the packet
44pg_set $DEV "clone_skb $CLONE_SKB"
45
46# Set packet size
47pg_set $DEV "pkt_size $PKT_SIZE"
48
49# Delay between packets (zero means max speed)
50pg_set $DEV "delay $DELAY"
51
52# Flag example disabling timestamping
53pg_set $DEV "flag NO_TIMESTAMP"
54
55# Destination
56pg_set $DEV "dst_mac $DST_MAC"
57pg_set $DEV "dst $DEST_IP"
58
59# Setup random UDP port src range
60pg_set $DEV "flag UDPSRC_RND"
61pg_set $DEV "udp_src_min $UDP_MIN"
62pg_set $DEV "udp_src_max $UDP_MAX"
63
64# start_run
65echo "Running... ctrl^C to stop" >&2
66pg_ctrl "start"
67echo "Done" >&2
68
69# Print results
70echo "Result device: $DEV"
71cat /proc/net/pktgen/$DEV
diff --git a/samples/pktgen/pktgen_sample02_multiqueue.sh b/samples/pktgen/pktgen_sample02_multiqueue.sh
new file mode 100755
index 000000000000..32467aea8e47
--- /dev/null
+++ b/samples/pktgen/pktgen_sample02_multiqueue.sh
@@ -0,0 +1,75 @@
1#!/bin/bash
2#
3# Multiqueue: Using pktgen threads for sending on multiple CPUs
4# * adding devices to kernel threads
5# * notice the naming scheme for keeping device names unique
6# * nameing scheme: dev@thread_number
7# * flow variation via random UDP source port
8#
9basedir=`dirname $0`
10source ${basedir}/functions.sh
11root_check_run_with_sudo "$@"
12#
13# Required param: -i dev in $DEV
14source ${basedir}/parameters.sh
15
16# Base Config
17DELAY="0" # Zero means max speed
18COUNT="100000" # Zero means indefinitely
19[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
20
21# Flow variation random source port between min and max
22UDP_MIN=9
23UDP_MAX=109
24
25# (example of setting default params in your script)
26[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
27[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
28
29# General cleanup everything since last run
30pg_ctrl "reset"
31
32# Threads are specified with parameter -t value in $THREADS
33for ((thread = 0; thread < $THREADS; thread++)); do
34 # The device name is extended with @name, using thread number to
35 # make then unique, but any name will do.
36 dev=${DEV}@${thread}
37
38 # Add remove all other devices and add_device $dev to thread
39 pg_thread $thread "rem_device_all"
40 pg_thread $thread "add_device" $dev
41
42 # Notice config queue to map to cpu (mirrors smp_processor_id())
43 # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
44 pg_set $dev "flag QUEUE_MAP_CPU"
45
46 # Base config of dev
47 pg_set $dev "count $COUNT"
48 pg_set $dev "clone_skb $CLONE_SKB"
49 pg_set $dev "pkt_size $PKT_SIZE"
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"
63done
64
65# start_run
66echo "Running... ctrl^C to stop" >&2
67pg_ctrl "start"
68echo "Done" >&2
69
70# Print results
71for ((thread = 0; thread < $THREADS; thread++)); do
72 dev=${DEV}@${thread}
73 echo "Device: $dev"
74 cat /proc/net/pktgen/$dev | grep -A2 "Result:"
75done
diff --git a/samples/pktgen/pktgen_sample03_burst_single_flow.sh b/samples/pktgen/pktgen_sample03_burst_single_flow.sh
new file mode 100755
index 000000000000..775f5d0a1e53
--- /dev/null
+++ b/samples/pktgen/pktgen_sample03_burst_single_flow.sh
@@ -0,0 +1,82 @@
1#!/bin/bash
2#
3# Script for max single flow performance
4# - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]
5#
6# Using pktgen "burst" option (use -b $N)
7# - To boost max performance
8# - Avail since: kernel v3.18
9# * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")
10# - This avoids writing the HW tailptr on every driver xmit
11# - The performance boost is impressive, see commit and blog [2]
12#
13# Notice: On purpose generates a single (UDP) flow towards target,
14# reason behind this is to only overload/activate a single CPU on
15# target host. And no randomness for pktgen also makes it faster.
16#
17# Tuning see:
18# [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
19# [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html
20#
21basedir=`dirname $0`
22source ${basedir}/functions.sh
23root_check_run_with_sudo "$@"
24
25# Parameter parsing via include
26source ${basedir}/parameters.sh
27# Set some default params, if they didn't get set
28[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
29[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
30[ -z "$BURST" ] && BURST=32
31[ -z "$CLONE_SKB" ] && CLONE_SKB="100000"
32
33# Base Config
34DELAY="0" # Zero means max speed
35COUNT="0" # Zero means indefinitely
36
37# General cleanup everything since last run
38pg_ctrl "reset"
39
40# Threads are specified with parameter -t value in $THREADS
41for ((thread = 0; thread < $THREADS; thread++)); do
42 dev=${DEV}@${thread}
43
44 # Add remove all other devices and add_device $dev to thread
45 pg_thread $thread "rem_device_all"
46 pg_thread $thread "add_device" $dev
47
48 # Base config
49 pg_set $dev "flag QUEUE_MAP_CPU"
50 pg_set $dev "count $COUNT"
51 pg_set $dev "clone_skb $CLONE_SKB"
52 pg_set $dev "pkt_size $PKT_SIZE"
53 pg_set $dev "delay $DELAY"
54 pg_set $dev "flag NO_TIMESTAMP"
55
56 # Destination
57 pg_set $dev "dst_mac $DST_MAC"
58 pg_set $dev "dst $DEST_IP"
59
60 # Setup burst, for easy testing -b 0 disable bursting
61 # (internally in pktgen default and minimum burst=1)
62 if [[ ${BURST} -ne 0 ]]; then
63 pg_set $dev "burst $BURST"
64 else
65 info "$dev: Not using burst"
66 fi
67done
68
69# Run if user hits control-c
70function control_c() {
71 # Print results
72 for ((thread = 0; thread < $THREADS; thread++)); do
73 dev=${DEV}@${thread}
74 echo "Device: $dev"
75 cat /proc/net/pktgen/$dev | grep -A2 "Result:"
76 done
77}
78# trap keyboard interrupt (Ctrl-C)
79trap control_c SIGINT
80
81echo "Running... ctrl^C to stop" >&2
82pg_ctrl "start"