xref: /linux/samples/pktgen/pktgen_sample02_multiqueue.sh (revision 17cfcb68af3bc7d5e8ae08779b1853310a2949f3)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Multiqueue: Using pktgen threads for sending on multiple CPUs
5#  * adding devices to kernel threads
6#  * notice the naming scheme for keeping device names unique
7#  * nameing scheme: dev@thread_number
8#  * flow variation via random UDP source port
9#
10basedir=`dirname $0`
11source ${basedir}/functions.sh
12root_check_run_with_sudo "$@"
13#
14# Required param: -i dev in $DEV
15source ${basedir}/parameters.sh
16
17[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
18
19# Base Config
20DELAY="0"        # Zero means max speed
21[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
22
23# Flow variation random source port between min and max
24UDP_MIN=9
25UDP_MAX=109
26
27# (example of setting default params in your script)
28if [ -z "$DEST_IP" ]; then
29    [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
30fi
31[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
32if [ -n "$DST_PORT" ]; then
33    read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT)
34    validate_ports $DST_MIN $DST_MAX
35fi
36
37# General cleanup everything since last run
38pg_ctrl "reset"
39
40# Threads are specified with parameter -t value in $THREADS
41for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
42    # The device name is extended with @name, using thread number to
43    # make then unique, but any name will do.
44    dev=${DEV}@${thread}
45
46    # Add remove all other devices and add_device $dev to thread
47    pg_thread $thread "rem_device_all"
48    pg_thread $thread "add_device" $dev
49
50    # Notice config queue to map to cpu (mirrors smp_processor_id())
51    # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
52    pg_set $dev "flag QUEUE_MAP_CPU"
53
54    # Base config of dev
55    pg_set $dev "count $COUNT"
56    pg_set $dev "clone_skb $CLONE_SKB"
57    pg_set $dev "pkt_size $PKT_SIZE"
58    pg_set $dev "delay $DELAY"
59
60    # Flag example disabling timestamping
61    pg_set $dev "flag NO_TIMESTAMP"
62
63    # Destination
64    pg_set $dev "dst_mac $DST_MAC"
65    pg_set $dev "dst$IP6 $DEST_IP"
66
67    if [ -n "$DST_PORT" ]; then
68	# Single destination port or random port range
69	pg_set $dev "flag UDPDST_RND"
70	pg_set $dev "udp_dst_min $DST_MIN"
71	pg_set $dev "udp_dst_max $DST_MAX"
72    fi
73
74    # Setup random UDP port src range
75    pg_set $dev "flag UDPSRC_RND"
76    pg_set $dev "udp_src_min $UDP_MIN"
77    pg_set $dev "udp_src_max $UDP_MAX"
78done
79
80# start_run
81echo "Running... ctrl^C to stop" >&2
82pg_ctrl "start"
83echo "Done" >&2
84
85# Print results
86for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
87    dev=${DEV}@${thread}
88    echo "Device: $dev"
89    cat /proc/net/pktgen/$dev | grep -A2 "Result:"
90done
91