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
20if [ -n "$DST_PORT" ]; then
21    read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
22    validate_ports $UDP_DST_MIN $UDP_DST_MAX
23fi
24
25# NOTICE:  Script specific settings
26# =======
27# Limiting the number of concurrent flows ($FLOWS)
28# and also set how many packets each flow contains ($FLOWLEN)
29#
30[ -z "$FLOWS" ]     && FLOWS="8000"
31[ -z "$FLOWLEN" ]   && FLOWLEN="10"
32
33# Base Config
34DELAY="0"  # Zero means max speed
35
36if [[ -n "$BURST" ]]; then
37    err 1 "Bursting not supported for this mode"
38fi
39
40# General cleanup everything since last run
41pg_ctrl "reset"
42
43# Threads are specified with parameter -t value in $THREADS
44for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
45    dev=${DEV}@${thread}
46
47    # Add remove all other devices and add_device $dev to thread
48    pg_thread $thread "rem_device_all"
49    pg_thread $thread "add_device" $dev
50
51    # Base config
52    pg_set $dev "flag QUEUE_MAP_CPU"
53    pg_set $dev "count $COUNT"
54    pg_set $dev "clone_skb $CLONE_SKB"
55    pg_set $dev "pkt_size $PKT_SIZE"
56    pg_set $dev "delay $DELAY"
57    pg_set $dev "flag NO_TIMESTAMP"
58
59    # Single destination
60    pg_set $dev "dst_mac $DST_MAC"
61    pg_set $dev "dst $DEST_IP"
62
63    if [ -n "$DST_PORT" ]; then
64	# Single destination port or random port range
65	pg_set $dev "flag UDPDST_RND"
66	pg_set $dev "udp_dst_min $UDP_DST_MIN"
67	pg_set $dev "udp_dst_max $UDP_DST_MAX"
68    fi
69
70    # Randomize source IP-addresses
71    pg_set $dev "flag IPSRC_RND"
72    pg_set $dev "src_min 198.18.0.0"
73    pg_set $dev "src_max 198.19.255.255"
74
75    # Limit number of flows (max 65535)
76    pg_set $dev "flows $FLOWS"
77    #
78    # How many packets a flow will send, before flow "entry" is
79    # re-generated/setup.
80    pg_set $dev "flowlen $FLOWLEN"
81    #
82    # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
83    # being send back-to-back, before next flow is selected
84    # incrementally.  This helps lookup caches, and is more realistic.
85    #
86    pg_set $dev "flag FLOW_SEQ"
87
88done
89
90# Run if user hits control-c
91function print_result() {
92    # Print results
93    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
94	dev=${DEV}@${thread}
95	echo "Device: $dev"
96	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
97    done
98}
99# trap keyboard interrupt (Ctrl-C)
100trap true SIGINT
101
102echo "Running... ctrl^C to stop" >&2
103pg_ctrl "start"
104
105print_result
106