xref: /linux/samples/pktgen/pktgen_sample02_multiqueue.sh (revision 40f843ee5e17673780c0969c8248b31a8d926b17)
1282fb589SJesper Dangaard Brouer#!/bin/bash
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3282fb589SJesper Dangaard Brouer#
4282fb589SJesper Dangaard Brouer# Multiqueue: Using pktgen threads for sending on multiple CPUs
5282fb589SJesper Dangaard Brouer#  * adding devices to kernel threads
6282fb589SJesper Dangaard Brouer#  * notice the naming scheme for keeping device names unique
7282fb589SJesper Dangaard Brouer#  * nameing scheme: dev@thread_number
8282fb589SJesper Dangaard Brouer#  * flow variation via random UDP source port
9282fb589SJesper Dangaard Brouer#
10282fb589SJesper Dangaard Brouerbasedir=`dirname $0`
11282fb589SJesper Dangaard Brouersource ${basedir}/functions.sh
12282fb589SJesper Dangaard Brouerroot_check_run_with_sudo "$@"
13282fb589SJesper Dangaard Brouer#
14282fb589SJesper Dangaard Brouer# Required param: -i dev in $DEV
15282fb589SJesper Dangaard Brouersource ${basedir}/parameters.sh
16282fb589SJesper Dangaard Brouer
1769137ea6STariq Toukan[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
1869137ea6STariq Toukan
19282fb589SJesper Dangaard Brouer# Base Config
20282fb589SJesper Dangaard BrouerDELAY="0"        # Zero means max speed
21282fb589SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
22282fb589SJesper Dangaard Brouer
23282fb589SJesper Dangaard Brouer# Flow variation random source port between min and max
24723d2904SDaniel T. LeeUDP_SRC_MIN=9
25723d2904SDaniel T. LeeUDP_SRC_MAX=109
26282fb589SJesper Dangaard Brouer
27282fb589SJesper Dangaard Brouer# (example of setting default params in your script)
280f06a678SMartin KaFai Lauif [ -z "$DEST_IP" ]; then
290f06a678SMartin KaFai Lau    [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
300f06a678SMartin KaFai Laufi
31282fb589SJesper Dangaard Brouer[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
32*40f843eeSDaniel T. Leeif [ -n "$DEST_IP" ]; then
33*40f843eeSDaniel T. Lee    validate_addr${IP6} $DEST_IP
34*40f843eeSDaniel T. Lee    read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
35*40f843eeSDaniel T. Leefi
366e32a74aSDaniel T. Leeif [ -n "$DST_PORT" ]; then
37723d2904SDaniel T. Lee    read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
38723d2904SDaniel T. Lee    validate_ports $UDP_DST_MIN $UDP_DST_MAX
396e32a74aSDaniel T. Leefi
40282fb589SJesper Dangaard Brouer
41282fb589SJesper Dangaard Brouer# General cleanup everything since last run
42282fb589SJesper Dangaard Brouerpg_ctrl "reset"
43282fb589SJesper Dangaard Brouer
44282fb589SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
45e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
46282fb589SJesper Dangaard Brouer    # The device name is extended with @name, using thread number to
47282fb589SJesper Dangaard Brouer    # make then unique, but any name will do.
48282fb589SJesper Dangaard Brouer    dev=${DEV}@${thread}
49282fb589SJesper Dangaard Brouer
50282fb589SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
51282fb589SJesper Dangaard Brouer    pg_thread $thread "rem_device_all"
52282fb589SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
53282fb589SJesper Dangaard Brouer
54282fb589SJesper Dangaard Brouer    # Notice config queue to map to cpu (mirrors smp_processor_id())
55282fb589SJesper Dangaard Brouer    # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
56282fb589SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
57282fb589SJesper Dangaard Brouer
58282fb589SJesper Dangaard Brouer    # Base config of dev
59282fb589SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
60282fb589SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
61282fb589SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
62282fb589SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
63282fb589SJesper Dangaard Brouer
64282fb589SJesper Dangaard Brouer    # Flag example disabling timestamping
65282fb589SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
66282fb589SJesper Dangaard Brouer
67282fb589SJesper Dangaard Brouer    # Destination
68282fb589SJesper 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"
71282fb589SJesper 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
79282fb589SJesper Dangaard Brouer    # Setup random UDP port src range
80282fb589SJesper Dangaard Brouer    pg_set $dev "flag UDPSRC_RND"
81723d2904SDaniel T. Lee    pg_set $dev "udp_src_min $UDP_SRC_MIN"
82723d2904SDaniel T. Lee    pg_set $dev "udp_src_max $UDP_SRC_MAX"
83282fb589SJesper Dangaard Brouerdone
84282fb589SJesper Dangaard Brouer
85282fb589SJesper Dangaard Brouer# start_run
86282fb589SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2
87282fb589SJesper Dangaard Brouerpg_ctrl "start"
88282fb589SJesper Dangaard Brouerecho "Done" >&2
89282fb589SJesper Dangaard Brouer
90282fb589SJesper Dangaard Brouer# Print results
91e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
92282fb589SJesper Dangaard Brouer    dev=${DEV}@${thread}
93282fb589SJesper Dangaard Brouer    echo "Device: $dev"
94282fb589SJesper Dangaard Brouer    cat /proc/net/pktgen/$dev | grep -A2 "Result:"
95282fb589SJesper Dangaard Brouerdone
96