xref: /linux/samples/pktgen/pktgen_sample05_flow_per_thread.sh (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1d25692e4SJesper Dangaard Brouer#!/bin/bash
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3d25692e4SJesper Dangaard Brouer#
4d25692e4SJesper Dangaard Brouer# Script will generate one flow per thread (-t N)
5d25692e4SJesper Dangaard Brouer#  - Same destination IP
6d25692e4SJesper Dangaard Brouer#  - Fake source IPs for each flow (fixed based on thread number)
7d25692e4SJesper Dangaard Brouer#
8d25692e4SJesper Dangaard Brouer# Useful for scale testing on receiver, to see whether silo'ing flows
9d25692e4SJesper Dangaard Brouer# works and scales.  For optimal scalability (on receiver) each
10d25692e4SJesper Dangaard Brouer# separate-flow should not access shared variables/data. This script
11d25692e4SJesper Dangaard Brouer# helps magnify any of these scaling issues by overloading the receiver.
12d25692e4SJesper Dangaard Brouer#
13d25692e4SJesper Dangaard Brouerbasedir=`dirname $0`
14d25692e4SJesper Dangaard Brouersource ${basedir}/functions.sh
15d25692e4SJesper Dangaard Brouerroot_check_run_with_sudo "$@"
16d25692e4SJesper Dangaard Brouer
17d25692e4SJesper Dangaard Brouer# Parameter parsing via include
18d25692e4SJesper Dangaard Brouersource ${basedir}/parameters.sh
19*a27ac539SJ.J. Martzki
20*a27ac539SJ.J. Martzki# Trap EXIT first
21*a27ac539SJ.J. Martzkitrap_exit
22*a27ac539SJ.J. Martzki
23d25692e4SJesper Dangaard Brouer# Set some default params, if they didn't get set
240f0c4f1bSJuhee Kangif [ -z "$DEST_IP" ]; then
250f0c4f1bSJuhee Kang    [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
260f0c4f1bSJuhee Kangfi
27d25692e4SJesper Dangaard Brouer[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
28d25692e4SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
29d25692e4SJesper Dangaard Brouer[ -z "$BURST" ]     && BURST=32
3069137ea6STariq Toukan[ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
3140f843eeSDaniel T. Leeif [ -n "$DEST_IP" ]; then
320f0c4f1bSJuhee Kang    validate_addr${IP6} $DEST_IP
330f0c4f1bSJuhee Kang    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
39d25692e4SJesper Dangaard Brouer
40d25692e4SJesper Dangaard Brouer# General cleanup everything since last run
41c8fd4852SIgor Russkikh[ -z "$APPEND" ] && pg_ctrl "reset"
42d25692e4SJesper Dangaard Brouer
43d25692e4SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
44e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
45d25692e4SJesper Dangaard Brouer    dev=${DEV}@${thread}
46d25692e4SJesper Dangaard Brouer
47d25692e4SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
48c8fd4852SIgor Russkikh    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
49d25692e4SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
50d25692e4SJesper Dangaard Brouer
51d25692e4SJesper Dangaard Brouer    # Base config
52d25692e4SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
53d25692e4SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
54d25692e4SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
55d25692e4SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
56d25692e4SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
57d25692e4SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
58d25692e4SJesper Dangaard Brouer
59d25692e4SJesper Dangaard Brouer    # Single destination
60d25692e4SJesper Dangaard Brouer    pg_set $dev "dst_mac $DST_MAC"
610f0c4f1bSJuhee Kang    pg_set $dev "dst${IP6}_min $DST_MIN"
620f0c4f1bSJuhee Kang    pg_set $dev "dst${IP6}_max $DST_MAX"
63d25692e4SJesper Dangaard Brouer
646e32a74aSDaniel T. Lee    if [ -n "$DST_PORT" ]; then
656e32a74aSDaniel T. Lee	# Single destination port or random port range
666e32a74aSDaniel T. Lee	pg_set $dev "flag UDPDST_RND"
67723d2904SDaniel T. Lee	pg_set $dev "udp_dst_min $UDP_DST_MIN"
68723d2904SDaniel T. Lee	pg_set $dev "udp_dst_max $UDP_DST_MAX"
696e32a74aSDaniel T. Lee    fi
706e32a74aSDaniel T. Lee
71460a9aa2SLorenzo Bianconi    [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
72460a9aa2SLorenzo Bianconi
73d25692e4SJesper Dangaard Brouer    # Setup source IP-addresses based on thread number
74d25692e4SJesper Dangaard Brouer    pg_set $dev "src_min 198.18.$((thread+1)).1"
75d25692e4SJesper Dangaard Brouer    pg_set $dev "src_max 198.18.$((thread+1)).1"
76d25692e4SJesper Dangaard Brouer
77d25692e4SJesper Dangaard Brouer    # Setup burst, for easy testing -b 0 disable bursting
78d25692e4SJesper Dangaard Brouer    # (internally in pktgen default and minimum burst=1)
79d25692e4SJesper Dangaard Brouer    if [[ ${BURST} -ne 0 ]]; then
80d25692e4SJesper Dangaard Brouer	pg_set $dev "burst $BURST"
81d25692e4SJesper Dangaard Brouer    else
82d25692e4SJesper Dangaard Brouer	info "$dev: Not using burst"
83d25692e4SJesper Dangaard Brouer    fi
84d25692e4SJesper Dangaard Brouer
85d25692e4SJesper Dangaard Brouerdone
86d25692e4SJesper Dangaard Brouer
87d25692e4SJesper Dangaard Brouer# Run if user hits control-c
88d25692e4SJesper Dangaard Brouerfunction print_result() {
89d25692e4SJesper Dangaard Brouer    # Print results
90e0e16672STariq Toukan    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
91d25692e4SJesper Dangaard Brouer	dev=${DEV}@${thread}
92d25692e4SJesper Dangaard Brouer	echo "Device: $dev"
93d25692e4SJesper Dangaard Brouer	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
94d25692e4SJesper Dangaard Brouer    done
95d25692e4SJesper Dangaard Brouer}
96d25692e4SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C)
97d25692e4SJesper Dangaard Brouertrap true SIGINT
98d25692e4SJesper Dangaard Brouer
99c8fd4852SIgor Russkikhif [ -z "$APPEND" ]; then
100d25692e4SJesper Dangaard Brouer    echo "Running... ctrl^C to stop" >&2
101d25692e4SJesper Dangaard Brouer    pg_ctrl "start"
102d25692e4SJesper Dangaard Brouer
103d25692e4SJesper Dangaard Brouer    print_result
104c8fd4852SIgor Russkikhelse
105c8fd4852SIgor Russkikh    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
106c8fd4852SIgor Russkikhfi
107