2 # SPDX-License-Identifier: GPL-2.0
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
11 source ${basedir}/functions.sh
12 root_check_run_with_sudo
"$@"
14 # Required param: -i dev in $DEV
15 source ${basedir}/parameters.sh
17 [ -z "$COUNT" ] && COUNT
="100000" # Zero means indefinitely
20 DELAY
="0" # Zero means max speed
21 [ -z "$CLONE_SKB" ] && CLONE_SKB
="0"
23 # Flow variation random source port between min and max
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"
31 [ -z "$DST_MAC" ] && DST_MAC
="90:e2:ba:ff:ff:ff"
32 if [ -n "$DEST_IP" ]; then
33 validate_addr
${IP6} $DEST_IP
34 read -r DST_MIN DST_MAX
<<< $
(parse_addr
${IP6} $DEST_IP)
36 if [ -n "$DST_PORT" ]; then
37 read -r UDP_DST_MIN UDP_DST_MAX
<<< $
(parse_ports
$DST_PORT)
38 validate_ports
$UDP_DST_MIN $UDP_DST_MAX
41 # General cleanup everything since last run
44 # Threads are specified with parameter -t value in $THREADS
45 for ((thread
= $F_THREAD; thread
<= $L_THREAD; thread
++)); do
46 # The device name is extended with @name, using thread number to
47 # make then unique, but any name will do.
50 # Add remove all other devices and add_device $dev to thread
51 pg_thread
$thread "rem_device_all"
52 pg_thread
$thread "add_device" $dev
54 # Notice config queue to map to cpu (mirrors smp_processor_id())
55 # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
56 pg_set
$dev "flag QUEUE_MAP_CPU"
59 pg_set
$dev "count $COUNT"
60 pg_set
$dev "clone_skb $CLONE_SKB"
61 pg_set
$dev "pkt_size $PKT_SIZE"
62 pg_set
$dev "delay $DELAY"
64 # Flag example disabling timestamping
65 pg_set
$dev "flag NO_TIMESTAMP"
68 pg_set
$dev "dst_mac $DST_MAC"
69 pg_set
$dev "dst${IP6}_min $DST_MIN"
70 pg_set
$dev "dst${IP6}_max $DST_MAX"
72 if [ -n "$DST_PORT" ]; then
73 # Single destination port or random port range
74 pg_set
$dev "flag UDPDST_RND"
75 pg_set
$dev "udp_dst_min $UDP_DST_MIN"
76 pg_set
$dev "udp_dst_max $UDP_DST_MAX"
79 # Setup random UDP port src range
80 pg_set
$dev "flag UDPSRC_RND"
81 pg_set
$dev "udp_src_min $UDP_SRC_MIN"
82 pg_set
$dev "udp_src_max $UDP_SRC_MAX"
86 echo "Running... ctrl^C to stop" >&2
91 for ((thread
= $F_THREAD; thread
<= $L_THREAD; thread
++)); do
94 cat /proc
/net
/pktgen
/$dev |
grep -A2 "Result:"