xref: /linux/samples/pktgen/pktgen_sample05_flow_per_thread.sh (revision b24413180f5600bcb3bb70fbed5cf186b60864bd)
1d25692e4SJesper Dangaard Brouer#!/bin/bash
2*b2441318SGreg 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
19d25692e4SJesper Dangaard Brouer# Set some default params, if they didn't get set
20d25692e4SJesper Dangaard Brouer[ -z "$DEST_IP" ]   && DEST_IP="198.18.0.42"
21d25692e4SJesper Dangaard Brouer[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
22d25692e4SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
23d25692e4SJesper Dangaard Brouer[ -z "$BURST" ]     && BURST=32
2469137ea6STariq Toukan[ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
25d25692e4SJesper Dangaard Brouer
26d25692e4SJesper Dangaard Brouer
27d25692e4SJesper Dangaard Brouer# Base Config
28d25692e4SJesper Dangaard BrouerDELAY="0"  # Zero means max speed
29d25692e4SJesper Dangaard Brouer
30d25692e4SJesper Dangaard Brouer# General cleanup everything since last run
31d25692e4SJesper Dangaard Brouerpg_ctrl "reset"
32d25692e4SJesper Dangaard Brouer
33d25692e4SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
34e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
35d25692e4SJesper Dangaard Brouer    dev=${DEV}@${thread}
36d25692e4SJesper Dangaard Brouer
37d25692e4SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
38d25692e4SJesper Dangaard Brouer    pg_thread $thread "rem_device_all"
39d25692e4SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
40d25692e4SJesper Dangaard Brouer
41d25692e4SJesper Dangaard Brouer    # Base config
42d25692e4SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
43d25692e4SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
44d25692e4SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
45d25692e4SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
46d25692e4SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
47d25692e4SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
48d25692e4SJesper Dangaard Brouer
49d25692e4SJesper Dangaard Brouer    # Single destination
50d25692e4SJesper Dangaard Brouer    pg_set $dev "dst_mac $DST_MAC"
51d25692e4SJesper Dangaard Brouer    pg_set $dev "dst $DEST_IP"
52d25692e4SJesper Dangaard Brouer
53d25692e4SJesper Dangaard Brouer    # Setup source IP-addresses based on thread number
54d25692e4SJesper Dangaard Brouer    pg_set $dev "src_min 198.18.$((thread+1)).1"
55d25692e4SJesper Dangaard Brouer    pg_set $dev "src_max 198.18.$((thread+1)).1"
56d25692e4SJesper Dangaard Brouer
57d25692e4SJesper Dangaard Brouer    # Setup burst, for easy testing -b 0 disable bursting
58d25692e4SJesper Dangaard Brouer    # (internally in pktgen default and minimum burst=1)
59d25692e4SJesper Dangaard Brouer    if [[ ${BURST} -ne 0 ]]; then
60d25692e4SJesper Dangaard Brouer	pg_set $dev "burst $BURST"
61d25692e4SJesper Dangaard Brouer    else
62d25692e4SJesper Dangaard Brouer	info "$dev: Not using burst"
63d25692e4SJesper Dangaard Brouer    fi
64d25692e4SJesper Dangaard Brouer
65d25692e4SJesper Dangaard Brouerdone
66d25692e4SJesper Dangaard Brouer
67d25692e4SJesper Dangaard Brouer# Run if user hits control-c
68d25692e4SJesper Dangaard Brouerfunction print_result() {
69d25692e4SJesper Dangaard Brouer    # Print results
70e0e16672STariq Toukan    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
71d25692e4SJesper Dangaard Brouer	dev=${DEV}@${thread}
72d25692e4SJesper Dangaard Brouer	echo "Device: $dev"
73d25692e4SJesper Dangaard Brouer	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
74d25692e4SJesper Dangaard Brouer    done
75d25692e4SJesper Dangaard Brouer}
76d25692e4SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C)
77d25692e4SJesper Dangaard Brouertrap true SIGINT
78d25692e4SJesper Dangaard Brouer
79d25692e4SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2
80d25692e4SJesper Dangaard Brouerpg_ctrl "start"
81d25692e4SJesper Dangaard Brouer
82d25692e4SJesper Dangaard Brouerprint_result
83