2 # SPDX-License-Identifier: GPL-2.0
4 # Script example for many flows testing
6 # Number of simultaneous flows limited by variable $FLOWS
7 # and number of packets per flow controlled by variable $FLOWLEN
10 source ${basedir}/functions.sh
11 root_check_run_with_sudo "$@"
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
25 # NOTICE: Script specific settings
27 # Limiting the number of concurrent flows ($FLOWS)
28 # and also set how many packets each flow contains ($FLOWLEN)
30 [ -z "$FLOWS" ] && FLOWS="8000"
31 [ -z "$FLOWLEN" ] && FLOWLEN="10"
34 DELAY="0" # Zero means max speed
36 if [[ -n "$BURST" ]]; then
37 err 1 "Bursting not supported for this mode"
40 # General cleanup everything since last run
43 # Threads are specified with parameter -t value in $THREADS
44 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
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
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"
60 pg_set $dev "dst_mac $DST_MAC"
61 pg_set $dev "dst $DEST_IP"
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"
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"
75 # Limit number of flows (max 65535)
76 pg_set $dev "flows $FLOWS"
78 # How many packets a flow will send, before flow "entry" is
80 pg_set $dev "flowlen $FLOWLEN"
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.
86 pg_set $dev "flag FLOW_SEQ"
90 # Run if user hits control-c
91 function print_result() {
93 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
96 cat /proc/net/pktgen/$dev | grep -A2 "Result:"
99 # trap keyboard interrupt (Ctrl-C)
102 echo "Running... ctrl^C to stop" >&2