GNU Linux-libre 5.4.257-gnu1
[releases.git] / samples / pktgen / pktgen_sample04_many_flows.sh
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 #
9 basedir=`dirname $0`
10 source ${basedir}/functions.sh
11 root_check_run_with_sudo "$@"
12
13 # Parameter parsing via include
14 source ${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 if [ -n "$DST_PORT" ]; then
21     read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT)
22     validate_ports $DST_MIN $DST_MAX
23 fi
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
34 DELAY="0"  # Zero means max speed
35
36 if [[ -n "$BURST" ]]; then
37     err 1 "Bursting not supported for this mode"
38 fi
39
40 # General cleanup everything since last run
41 pg_ctrl "reset"
42
43 # Threads are specified with parameter -t value in $THREADS
44 for ((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 $DST_MIN"
67         pg_set $dev "udp_dst_max $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
88 done
89
90 # Run if user hits control-c
91 function 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)
100 trap true SIGINT
101
102 echo "Running... ctrl^C to stop" >&2
103 pg_ctrl "start"
104
105 print_result