xref: /linux/samples/pktgen/pktgen_sample03_burst_single_flow.sh (revision 1d73ba16ad3975a2eb27e47e52fc215c0c5b8d83)
1*1d73ba16SJesper Dangaard Brouer#!/bin/bash
2*1d73ba16SJesper Dangaard Brouer#
3*1d73ba16SJesper Dangaard Brouer# Script for max single flow performance
4*1d73ba16SJesper Dangaard Brouer#  - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]
5*1d73ba16SJesper Dangaard Brouer#
6*1d73ba16SJesper Dangaard Brouer# Using pktgen "burst" option (use -b $N)
7*1d73ba16SJesper Dangaard Brouer#  - To boost max performance
8*1d73ba16SJesper Dangaard Brouer#  - Avail since: kernel v3.18
9*1d73ba16SJesper Dangaard Brouer#   * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")
10*1d73ba16SJesper Dangaard Brouer#  - This avoids writing the HW tailptr on every driver xmit
11*1d73ba16SJesper Dangaard Brouer#  - The performance boost is impressive, see commit and blog [2]
12*1d73ba16SJesper Dangaard Brouer#
13*1d73ba16SJesper Dangaard Brouer# Notice: On purpose generates a single (UDP) flow towards target,
14*1d73ba16SJesper Dangaard Brouer#   reason behind this is to only overload/activate a single CPU on
15*1d73ba16SJesper Dangaard Brouer#   target host.  And no randomness for pktgen also makes it faster.
16*1d73ba16SJesper Dangaard Brouer#
17*1d73ba16SJesper Dangaard Brouer# Tuning see:
18*1d73ba16SJesper Dangaard Brouer#  [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
19*1d73ba16SJesper Dangaard Brouer#  [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html
20*1d73ba16SJesper Dangaard Brouer#
21*1d73ba16SJesper Dangaard Brouerbasedir=`dirname $0`
22*1d73ba16SJesper Dangaard Brouersource ${basedir}/functions.sh
23*1d73ba16SJesper Dangaard Brouerroot_check_run_with_sudo "$@"
24*1d73ba16SJesper Dangaard Brouer
25*1d73ba16SJesper Dangaard Brouer# Parameter parsing via include
26*1d73ba16SJesper Dangaard Brouersource ${basedir}/parameters.sh
27*1d73ba16SJesper Dangaard Brouer# Set some default params, if they didn't get set
28*1d73ba16SJesper Dangaard Brouer[ -z "$DEST_IP" ]   && DEST_IP="198.18.0.42"
29*1d73ba16SJesper Dangaard Brouer[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
30*1d73ba16SJesper Dangaard Brouer[ -z "$BURST" ]     && BURST=32
31*1d73ba16SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="100000"
32*1d73ba16SJesper Dangaard Brouer
33*1d73ba16SJesper Dangaard Brouer# Base Config
34*1d73ba16SJesper Dangaard BrouerDELAY="0"  # Zero means max speed
35*1d73ba16SJesper Dangaard BrouerCOUNT="0"  # Zero means indefinitely
36*1d73ba16SJesper Dangaard Brouer
37*1d73ba16SJesper Dangaard Brouer# General cleanup everything since last run
38*1d73ba16SJesper Dangaard Brouerpg_ctrl "reset"
39*1d73ba16SJesper Dangaard Brouer
40*1d73ba16SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
41*1d73ba16SJesper Dangaard Brouerfor ((thread = 0; thread < $THREADS; thread++)); do
42*1d73ba16SJesper Dangaard Brouer    dev=${DEV}@${thread}
43*1d73ba16SJesper Dangaard Brouer
44*1d73ba16SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
45*1d73ba16SJesper Dangaard Brouer    pg_thread $thread "rem_device_all"
46*1d73ba16SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
47*1d73ba16SJesper Dangaard Brouer
48*1d73ba16SJesper Dangaard Brouer    # Base config
49*1d73ba16SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
50*1d73ba16SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
51*1d73ba16SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
52*1d73ba16SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
53*1d73ba16SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
54*1d73ba16SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
55*1d73ba16SJesper Dangaard Brouer
56*1d73ba16SJesper Dangaard Brouer    # Destination
57*1d73ba16SJesper Dangaard Brouer    pg_set $dev "dst_mac $DST_MAC"
58*1d73ba16SJesper Dangaard Brouer    pg_set $dev "dst $DEST_IP"
59*1d73ba16SJesper Dangaard Brouer
60*1d73ba16SJesper Dangaard Brouer    # Setup burst, for easy testing -b 0 disable bursting
61*1d73ba16SJesper Dangaard Brouer    # (internally in pktgen default and minimum burst=1)
62*1d73ba16SJesper Dangaard Brouer    if [[ ${BURST} -ne 0 ]]; then
63*1d73ba16SJesper Dangaard Brouer	pg_set $dev "burst $BURST"
64*1d73ba16SJesper Dangaard Brouer    else
65*1d73ba16SJesper Dangaard Brouer	info "$dev: Not using burst"
66*1d73ba16SJesper Dangaard Brouer    fi
67*1d73ba16SJesper Dangaard Brouerdone
68*1d73ba16SJesper Dangaard Brouer
69*1d73ba16SJesper Dangaard Brouer# Run if user hits control-c
70*1d73ba16SJesper Dangaard Brouerfunction control_c() {
71*1d73ba16SJesper Dangaard Brouer    # Print results
72*1d73ba16SJesper Dangaard Brouer    for ((thread = 0; thread < $THREADS; thread++)); do
73*1d73ba16SJesper Dangaard Brouer	dev=${DEV}@${thread}
74*1d73ba16SJesper Dangaard Brouer	echo "Device: $dev"
75*1d73ba16SJesper Dangaard Brouer	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
76*1d73ba16SJesper Dangaard Brouer    done
77*1d73ba16SJesper Dangaard Brouer}
78*1d73ba16SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C)
79*1d73ba16SJesper Dangaard Brouertrap control_c SIGINT
80*1d73ba16SJesper Dangaard Brouer
81*1d73ba16SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2
82*1d73ba16SJesper Dangaard Brouerpg_ctrl "start"
83