xref: /linux/samples/pktgen/pktgen_sample03_burst_single_flow.sh (revision 40f843ee5e17673780c0969c8248b31a8d926b17)
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
281d73ba16SJesper Dangaard Brouer# Set some default params, if they didn't get set
290f06a678SMartin KaFai Lauif [ -z "$DEST_IP" ]; then
300f06a678SMartin KaFai Lau    [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
310f06a678SMartin KaFai Laufi
321d73ba16SJesper Dangaard Brouer[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
331d73ba16SJesper Dangaard Brouer[ -z "$BURST" ]     && BURST=32
349efc44d7SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" # No need for clones when bursting
3569137ea6STariq Toukan[ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
36*40f843eeSDaniel T. Leeif [ -n "$DEST_IP" ]; then
37*40f843eeSDaniel T. Lee    validate_addr${IP6} $DEST_IP
38*40f843eeSDaniel T. Lee    read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
39*40f843eeSDaniel T. Leefi
406e32a74aSDaniel T. Leeif [ -n "$DST_PORT" ]; then
41723d2904SDaniel T. Lee    read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
42723d2904SDaniel T. Lee    validate_ports $UDP_DST_MIN $UDP_DST_MAX
436e32a74aSDaniel T. Leefi
441d73ba16SJesper Dangaard Brouer
451d73ba16SJesper Dangaard Brouer# Base Config
461d73ba16SJesper Dangaard BrouerDELAY="0"  # Zero means max speed
471d73ba16SJesper Dangaard Brouer
481d73ba16SJesper Dangaard Brouer# General cleanup everything since last run
491d73ba16SJesper Dangaard Brouerpg_ctrl "reset"
501d73ba16SJesper Dangaard Brouer
511d73ba16SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
52e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
531d73ba16SJesper Dangaard Brouer    dev=${DEV}@${thread}
541d73ba16SJesper Dangaard Brouer
551d73ba16SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
561d73ba16SJesper Dangaard Brouer    pg_thread $thread "rem_device_all"
571d73ba16SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
581d73ba16SJesper Dangaard Brouer
591d73ba16SJesper Dangaard Brouer    # Base config
601d73ba16SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
611d73ba16SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
621d73ba16SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
631d73ba16SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
641d73ba16SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
651d73ba16SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
661d73ba16SJesper Dangaard Brouer
671d73ba16SJesper Dangaard Brouer    # Destination
681d73ba16SJesper Dangaard Brouer    pg_set $dev "dst_mac $DST_MAC"
69*40f843eeSDaniel T. Lee    pg_set $dev "dst${IP6}_min $DST_MIN"
70*40f843eeSDaniel T. Lee    pg_set $dev "dst${IP6}_max $DST_MAX"
711d73ba16SJesper Dangaard Brouer
726e32a74aSDaniel T. Lee    if [ -n "$DST_PORT" ]; then
736e32a74aSDaniel T. Lee	# Single destination port or random port range
746e32a74aSDaniel T. Lee	pg_set $dev "flag UDPDST_RND"
75723d2904SDaniel T. Lee	pg_set $dev "udp_dst_min $UDP_DST_MIN"
76723d2904SDaniel T. Lee	pg_set $dev "udp_dst_max $UDP_DST_MAX"
776e32a74aSDaniel T. Lee    fi
786e32a74aSDaniel T. Lee
791d73ba16SJesper Dangaard Brouer    # Setup burst, for easy testing -b 0 disable bursting
801d73ba16SJesper Dangaard Brouer    # (internally in pktgen default and minimum burst=1)
811d73ba16SJesper Dangaard Brouer    if [[ ${BURST} -ne 0 ]]; then
821d73ba16SJesper Dangaard Brouer	pg_set $dev "burst $BURST"
831d73ba16SJesper Dangaard Brouer    else
841d73ba16SJesper Dangaard Brouer	info "$dev: Not using burst"
851d73ba16SJesper Dangaard Brouer    fi
861d73ba16SJesper Dangaard Brouerdone
871d73ba16SJesper Dangaard Brouer
881d73ba16SJesper Dangaard Brouer# Run if user hits control-c
891d73ba16SJesper Dangaard Brouerfunction control_c() {
901d73ba16SJesper Dangaard Brouer    # Print results
91e0e16672STariq Toukan    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
921d73ba16SJesper Dangaard Brouer	dev=${DEV}@${thread}
931d73ba16SJesper Dangaard Brouer	echo "Device: $dev"
941d73ba16SJesper Dangaard Brouer	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
951d73ba16SJesper Dangaard Brouer    done
961d73ba16SJesper Dangaard Brouer}
971d73ba16SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C)
981d73ba16SJesper Dangaard Brouertrap control_c SIGINT
991d73ba16SJesper Dangaard Brouer
1001d73ba16SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2
1011d73ba16SJesper Dangaard Brouerpg_ctrl "start"
102