xref: /linux/samples/pktgen/pktgen_sample03_burst_single_flow.sh (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
11d73ba16SJesper Dangaard Brouer#!/bin/bash
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
31d73ba16SJesper Dangaard Brouer#
41d73ba16SJesper Dangaard Brouer# Script for max single flow performance
51d73ba16SJesper Dangaard Brouer#  - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]
61d73ba16SJesper Dangaard Brouer#
71d73ba16SJesper Dangaard Brouer# Using pktgen "burst" option (use -b $N)
81d73ba16SJesper Dangaard Brouer#  - To boost max performance
91d73ba16SJesper Dangaard Brouer#  - Avail since: kernel v3.18
101d73ba16SJesper Dangaard Brouer#   * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")
111d73ba16SJesper Dangaard Brouer#  - This avoids writing the HW tailptr on every driver xmit
121d73ba16SJesper Dangaard Brouer#  - The performance boost is impressive, see commit and blog [2]
131d73ba16SJesper Dangaard Brouer#
141d73ba16SJesper Dangaard Brouer# Notice: On purpose generates a single (UDP) flow towards target,
151d73ba16SJesper Dangaard Brouer#   reason behind this is to only overload/activate a single CPU on
161d73ba16SJesper Dangaard Brouer#   target host.  And no randomness for pktgen also makes it faster.
171d73ba16SJesper Dangaard Brouer#
181d73ba16SJesper Dangaard Brouer# Tuning see:
191d73ba16SJesper Dangaard Brouer#  [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
201d73ba16SJesper Dangaard Brouer#  [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html
211d73ba16SJesper Dangaard Brouer#
221d73ba16SJesper Dangaard Brouerbasedir=`dirname $0`
231d73ba16SJesper Dangaard Brouersource ${basedir}/functions.sh
241d73ba16SJesper Dangaard Brouerroot_check_run_with_sudo "$@"
251d73ba16SJesper Dangaard Brouer
261d73ba16SJesper Dangaard Brouer# Parameter parsing via include
271d73ba16SJesper Dangaard Brouersource ${basedir}/parameters.sh
28*a27ac539SJ.J. Martzki
29*a27ac539SJ.J. Martzki# Trap EXIT first
30*a27ac539SJ.J. Martzkitrap_exit
31*a27ac539SJ.J. Martzki
321d73ba16SJesper Dangaard Brouer# Set some default params, if they didn't get set
330f06a678SMartin KaFai Lauif [ -z "$DEST_IP" ]; then
340f06a678SMartin KaFai Lau    [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
350f06a678SMartin KaFai Laufi
361d73ba16SJesper Dangaard Brouer[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
371d73ba16SJesper Dangaard Brouer[ -z "$BURST" ]     && BURST=32
389efc44d7SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" # No need for clones when bursting
3969137ea6STariq Toukan[ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
4040f843eeSDaniel T. Leeif [ -n "$DEST_IP" ]; then
4140f843eeSDaniel T. Lee    validate_addr${IP6} $DEST_IP
4240f843eeSDaniel T. Lee    read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
4340f843eeSDaniel T. Leefi
446e32a74aSDaniel T. Leeif [ -n "$DST_PORT" ]; then
45723d2904SDaniel T. Lee    read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
46723d2904SDaniel T. Lee    validate_ports $UDP_DST_MIN $UDP_DST_MAX
476e32a74aSDaniel T. Leefi
481d73ba16SJesper Dangaard Brouer
491d73ba16SJesper Dangaard Brouer# General cleanup everything since last run
50c8fd4852SIgor Russkikh[ -z "$APPEND" ] && pg_ctrl "reset"
511d73ba16SJesper Dangaard Brouer
521d73ba16SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
53e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
541d73ba16SJesper Dangaard Brouer    dev=${DEV}@${thread}
551d73ba16SJesper Dangaard Brouer
561d73ba16SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
57c8fd4852SIgor Russkikh    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
581d73ba16SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
591d73ba16SJesper Dangaard Brouer
601d73ba16SJesper Dangaard Brouer    # Base config
611d73ba16SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
621d73ba16SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
631d73ba16SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
641d73ba16SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
651d73ba16SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
661d73ba16SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
671d73ba16SJesper Dangaard Brouer
681d73ba16SJesper Dangaard Brouer    # Destination
691d73ba16SJesper Dangaard Brouer    pg_set $dev "dst_mac $DST_MAC"
7040f843eeSDaniel T. Lee    pg_set $dev "dst${IP6}_min $DST_MIN"
7140f843eeSDaniel T. Lee    pg_set $dev "dst${IP6}_max $DST_MAX"
721d73ba16SJesper Dangaard Brouer
736e32a74aSDaniel T. Lee    if [ -n "$DST_PORT" ]; then
746e32a74aSDaniel T. Lee	# Single destination port or random port range
756e32a74aSDaniel T. Lee	pg_set $dev "flag UDPDST_RND"
76723d2904SDaniel T. Lee	pg_set $dev "udp_dst_min $UDP_DST_MIN"
77723d2904SDaniel T. Lee	pg_set $dev "udp_dst_max $UDP_DST_MAX"
786e32a74aSDaniel T. Lee    fi
796e32a74aSDaniel T. Lee
80460a9aa2SLorenzo Bianconi    [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
81460a9aa2SLorenzo Bianconi
821d73ba16SJesper Dangaard Brouer    # Setup burst, for easy testing -b 0 disable bursting
831d73ba16SJesper Dangaard Brouer    # (internally in pktgen default and minimum burst=1)
841d73ba16SJesper Dangaard Brouer    if [[ ${BURST} -ne 0 ]]; then
851d73ba16SJesper Dangaard Brouer	pg_set $dev "burst $BURST"
861d73ba16SJesper Dangaard Brouer    else
871d73ba16SJesper Dangaard Brouer	info "$dev: Not using burst"
881d73ba16SJesper Dangaard Brouer    fi
891d73ba16SJesper Dangaard Brouerdone
901d73ba16SJesper Dangaard Brouer
911d73ba16SJesper Dangaard Brouer# Run if user hits control-c
92c0e9422cSJuhee Kangfunction print_result() {
931d73ba16SJesper Dangaard Brouer    # Print results
94e0e16672STariq Toukan    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
951d73ba16SJesper Dangaard Brouer	dev=${DEV}@${thread}
961d73ba16SJesper Dangaard Brouer	echo "Device: $dev"
971d73ba16SJesper Dangaard Brouer	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
981d73ba16SJesper Dangaard Brouer    done
991d73ba16SJesper Dangaard Brouer}
1001d73ba16SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C)
101c0e9422cSJuhee Kangtrap true SIGINT
1021d73ba16SJesper Dangaard Brouer
103c8fd4852SIgor Russkikhif [ -z "$APPEND" ]; then
1041d73ba16SJesper Dangaard Brouer    echo "Running... ctrl^C to stop" >&2
1051d73ba16SJesper Dangaard Brouer    pg_ctrl "start"
106c0e9422cSJuhee Kang
107c0e9422cSJuhee Kang    print_result
108c8fd4852SIgor Russkikhelse
109c8fd4852SIgor Russkikh    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
110c8fd4852SIgor Russkikhfi
111