GNU Linux-libre 4.14.251-gnu1
[releases.git] / samples / pktgen / pktgen_sample02_multiqueue.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # Multiqueue: Using pktgen threads for sending on multiple CPUs
5 #  * adding devices to kernel threads
6 #  * notice the naming scheme for keeping device names unique
7 #  * nameing scheme: dev@thread_number
8 #  * flow variation via random UDP source port
9 #
10 basedir=`dirname $0`
11 source ${basedir}/functions.sh
12 root_check_run_with_sudo "$@"
13 #
14 # Required param: -i dev in $DEV
15 source ${basedir}/parameters.sh
16
17 [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
18
19 # Base Config
20 DELAY="0"        # Zero means max speed
21 [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
22
23 # Flow variation random source port between min and max
24 UDP_MIN=9
25 UDP_MAX=109
26
27 # (example of setting default params in your script)
28 if [ -z "$DEST_IP" ]; then
29     [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
30 fi
31 [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
32
33 # General cleanup everything since last run
34 pg_ctrl "reset"
35
36 # Threads are specified with parameter -t value in $THREADS
37 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
38     # The device name is extended with @name, using thread number to
39     # make then unique, but any name will do.
40     dev=${DEV}@${thread}
41
42     # Add remove all other devices and add_device $dev to thread
43     pg_thread $thread "rem_device_all"
44     pg_thread $thread "add_device" $dev
45
46     # Notice config queue to map to cpu (mirrors smp_processor_id())
47     # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
48     pg_set $dev "flag QUEUE_MAP_CPU"
49
50     # Base config of dev
51     pg_set $dev "count $COUNT"
52     pg_set $dev "clone_skb $CLONE_SKB"
53     pg_set $dev "pkt_size $PKT_SIZE"
54     pg_set $dev "delay $DELAY"
55
56     # Flag example disabling timestamping
57     pg_set $dev "flag NO_TIMESTAMP"
58
59     # Destination
60     pg_set $dev "dst_mac $DST_MAC"
61     pg_set $dev "dst$IP6 $DEST_IP"
62
63     # Setup random UDP port src range
64     pg_set $dev "flag UDPSRC_RND"
65     pg_set $dev "udp_src_min $UDP_MIN"
66     pg_set $dev "udp_src_max $UDP_MAX"
67 done
68
69 # start_run
70 echo "Running... ctrl^C to stop" >&2
71 pg_ctrl "start"
72 echo "Done" >&2
73
74 # Print results
75 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
76     dev=${DEV}@${thread}
77     echo "Device: $dev"
78     cat /proc/net/pktgen/$dev | grep -A2 "Result:"
79 done