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