xref: /openbmc/linux/samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
16fd980acSJohn Fastabend#!/bin/bash
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
36fd980acSJohn Fastabend#
46fd980acSJohn Fastabend# Benchmark script:
56fd980acSJohn Fastabend#  - developed for benchmarking egress qdisc path, derived (more
66fd980acSJohn Fastabend#    like cut'n'pasted) from ingress benchmark script.
76fd980acSJohn Fastabend#
86fd980acSJohn Fastabend# Script for injecting packets into egress qdisc path of the stack
96fd980acSJohn Fastabend# with pktgen "xmit_mode queue_xmit".
106fd980acSJohn Fastabend#
116fd980acSJohn Fastabendbasedir=`dirname $0`
126fd980acSJohn Fastabendsource ${basedir}/functions.sh
136fd980acSJohn Fastabendroot_check_run_with_sudo "$@"
146fd980acSJohn Fastabend
156fd980acSJohn Fastabend# Parameter parsing via include
166fd980acSJohn Fastabendsource ${basedir}/parameters.sh
17*a27ac539SJ.J. Martzki
18*a27ac539SJ.J. Martzki# Trap EXIT first
19*a27ac539SJ.J. Martzkitrap_exit
20*a27ac539SJ.J. Martzki
210f06a678SMartin KaFai Lauif [ -z "$DEST_IP" ]; then
220f06a678SMartin KaFai Lau    [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
230f06a678SMartin KaFai Laufi
246fd980acSJohn Fastabend[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
256fd980acSJohn Fastabend
266fd980acSJohn Fastabend# Burst greater than 1 are invalid for queue_xmit mode
276fd980acSJohn Fastabendif [[ -n "$BURST" ]]; then
286fd980acSJohn Fastabend    err 1 "Bursting not supported for this mode"
296fd980acSJohn Fastabendfi
3069137ea6STariq Toukan[ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely
3140f843eeSDaniel T. Leeif [ -n "$DEST_IP" ]; then
3240f843eeSDaniel T. Lee    validate_addr${IP6} $DEST_IP
3340f843eeSDaniel T. Lee    read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
3440f843eeSDaniel T. Leefi
356e32a74aSDaniel T. Leeif [ -n "$DST_PORT" ]; then
36723d2904SDaniel T. Lee    read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
37723d2904SDaniel T. Lee    validate_ports $UDP_DST_MIN $UDP_DST_MAX
386e32a74aSDaniel T. Leefi
396fd980acSJohn Fastabend
406fd980acSJohn Fastabend# General cleanup everything since last run
416fd980acSJohn Fastabendpg_ctrl "reset"
426fd980acSJohn Fastabend
436fd980acSJohn Fastabend# Threads are specified with parameter -t value in $THREADS
44e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
456fd980acSJohn Fastabend    # The device name is extended with @name, using thread number to
466fd980acSJohn Fastabend    # make then unique, but any name will do.
476fd980acSJohn Fastabend    dev=${DEV}@${thread}
486fd980acSJohn Fastabend
496fd980acSJohn Fastabend    # Add remove all other devices and add_device $dev to thread
506fd980acSJohn Fastabend    pg_thread $thread "rem_device_all"
516fd980acSJohn Fastabend    pg_thread $thread "add_device" $dev
526fd980acSJohn Fastabend
536fd980acSJohn Fastabend    # Base config of dev
546fd980acSJohn Fastabend    pg_set $dev "flag QUEUE_MAP_CPU"
556fd980acSJohn Fastabend    pg_set $dev "count $COUNT"
566fd980acSJohn Fastabend    pg_set $dev "pkt_size $PKT_SIZE"
576fd980acSJohn Fastabend    pg_set $dev "delay $DELAY"
586fd980acSJohn Fastabend    pg_set $dev "flag NO_TIMESTAMP"
596fd980acSJohn Fastabend
606fd980acSJohn Fastabend    # Destination
616fd980acSJohn Fastabend    pg_set $dev "dst_mac $DST_MAC"
6240f843eeSDaniel T. Lee    pg_set $dev "dst${IP6}_min $DST_MIN"
6340f843eeSDaniel T. Lee    pg_set $dev "dst${IP6}_max $DST_MAX"
646fd980acSJohn Fastabend
656e32a74aSDaniel T. Lee    if [ -n "$DST_PORT" ]; then
666e32a74aSDaniel T. Lee	# Single destination port or random port range
676e32a74aSDaniel T. Lee	pg_set $dev "flag UDPDST_RND"
68723d2904SDaniel T. Lee	pg_set $dev "udp_dst_min $UDP_DST_MIN"
69723d2904SDaniel T. Lee	pg_set $dev "udp_dst_max $UDP_DST_MAX"
706e32a74aSDaniel T. Lee    fi
716e32a74aSDaniel T. Lee
726fd980acSJohn Fastabend    # Inject packet into TX qdisc egress path of stack
736fd980acSJohn Fastabend    pg_set $dev "xmit_mode queue_xmit"
746fd980acSJohn Fastabenddone
756fd980acSJohn Fastabend
766c882bdcSJuhee Kang# Run if user hits control-c
776c882bdcSJuhee Kangfunction print_result {
786fd980acSJohn Fastabend    # Print results
79e0e16672STariq Toukan    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
806fd980acSJohn Fastabend        dev=${DEV}@${thread}
816fd980acSJohn Fastabend        echo "Device: $dev"
826fd980acSJohn Fastabend        cat /proc/net/pktgen/$dev | grep -A2 "Result:"
836fd980acSJohn Fastabend    done
846c882bdcSJuhee Kang}
856c882bdcSJuhee Kang# trap keyboard interrupt (Ctrl-C)
866c882bdcSJuhee Kangtrap true SIGINT
876c882bdcSJuhee Kang
886c882bdcSJuhee Kang# start_run
896c882bdcSJuhee Kangecho "Running... ctrl^C to stop" >&2
906c882bdcSJuhee Kangpg_ctrl "start"
916c882bdcSJuhee Kangecho "Done" >&2
926c882bdcSJuhee Kang
936c882bdcSJuhee Kangprint_result
94