1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Script example for many flows testing
5#
6# Number of simultaneous flows limited by variable $FLOWS
7# and number of packets per flow controlled by variable $FLOWLEN
8#
9basedir=`dirname $0`
10source ${basedir}/functions.sh
11root_check_run_with_sudo "$@"
12
13# Parameter parsing via include
14source ${basedir}/parameters.sh
15# Set some default params, if they didn't get set
16[ -z "$DEST_IP" ]   && DEST_IP="198.18.0.42"
17[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
18[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
19[ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
20
21# NOTICE:  Script specific settings
22# =======
23# Limiting the number of concurrent flows ($FLOWS)
24# and also set how many packets each flow contains ($FLOWLEN)
25#
26[ -z "$FLOWS" ]     && FLOWS="8000"
27[ -z "$FLOWLEN" ]   && FLOWLEN="10"
28
29# Base Config
30DELAY="0"  # Zero means max speed
31
32if [[ -n "$BURST" ]]; then
33    err 1 "Bursting not supported for this mode"
34fi
35
36# General cleanup everything since last run
37pg_ctrl "reset"
38
39# Threads are specified with parameter -t value in $THREADS
40for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
41    dev=${DEV}@${thread}
42
43    # Add remove all other devices and add_device $dev to thread
44    pg_thread $thread "rem_device_all"
45    pg_thread $thread "add_device" $dev
46
47    # Base config
48    pg_set $dev "flag QUEUE_MAP_CPU"
49    pg_set $dev "count $COUNT"
50    pg_set $dev "clone_skb $CLONE_SKB"
51    pg_set $dev "pkt_size $PKT_SIZE"
52    pg_set $dev "delay $DELAY"
53    pg_set $dev "flag NO_TIMESTAMP"
54
55    # Single destination
56    pg_set $dev "dst_mac $DST_MAC"
57    pg_set $dev "dst $DEST_IP"
58
59    # Randomize source IP-addresses
60    pg_set $dev "flag IPSRC_RND"
61    pg_set $dev "src_min 198.18.0.0"
62    pg_set $dev "src_max 198.19.255.255"
63
64    # Limit number of flows (max 65535)
65    pg_set $dev "flows $FLOWS"
66    #
67    # How many packets a flow will send, before flow "entry" is
68    # re-generated/setup.
69    pg_set $dev "flowlen $FLOWLEN"
70    #
71    # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
72    # being send back-to-back, before next flow is selected
73    # incrementally.  This helps lookup caches, and is more realistic.
74    #
75    pg_set $dev "flag FLOW_SEQ"
76
77done
78
79# Run if user hits control-c
80function print_result() {
81    # Print results
82    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
83	dev=${DEV}@${thread}
84	echo "Device: $dev"
85	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
86    done
87}
88# trap keyboard interrupt (Ctrl-C)
89trap true SIGINT
90
91echo "Running... ctrl^C to stop" >&2
92pg_ctrl "start"
93
94print_result
95