Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples: pktgen: new append mode

To configure various complex flows we for sure can create custom
pktgen init scripts, but sometimes thats not that easy.

New "-a" (append) option in all the existing sample scripts allows
to append more "devices" into pktgen threads.

The most straightforward usecases for that are:
- using multiple devices. We have to generate full linerate on
all physical functions (ports) of our multiport device.
- pushing multiple flows (with different packet options)

Signed-off-by: Igor Russkikh <irusskikh@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Igor Russkikh and committed by
David S. Miller
c8fd4852 ef700f2e

+100 -49
+17
samples/pktgen/README.rst
··· 28 28 -b : ($BURST) HW level bursting of SKBs 29 29 -v : ($VERBOSE) verbose 30 30 -x : ($DEBUG) debug 31 + -6 : ($IP6) IPv6 31 32 -w : ($DELAY) Tx Delay value (ns) 33 + -a : ($APPEND) Script will not reset generator's state, but will append its config 32 34 33 35 The global variable being set is also listed. E.g. the required 34 36 interface/device parameter "-i" sets variable $DEV. 37 + 38 + "-a" parameter may be used to create different flows simultaneously. 39 + In this mode script will keep the existing config, will append its settings. 40 + In this mode you'll have to manually run traffic with "pg_ctrl start". 41 + 42 + For example you may use: 43 + 44 + source ./samples/pktgen/functions.sh 45 + pg_ctrl reset 46 + # add first device 47 + ./pktgen_sample06_numa_awared_queue_irq_affinity.sh -a -i ens1f0 -m 34:80:0d:a3:fc:c9 -t 8 48 + # add second device 49 + ./pktgen_sample06_numa_awared_queue_irq_affinity.sh -a -i ens1f1 -m 34:80:0d:a3:fc:c9 -t 8 50 + # run joint traffic on two devs 51 + pg_ctrl start 35 52 36 53 Common functions 37 54 ----------------
+6 -1
samples/pktgen/functions.sh
··· 108 108 fi 109 109 } 110 110 111 - [[ $EUID -eq 0 ]] && trap 'pg_ctrl "reset"' EXIT 111 + if [[ -z "$APPEND" ]]; then 112 + if [[ $EUID -eq 0 ]]; then 113 + # Cleanup pktgen setup on exit if thats not "append mode" 114 + trap 'pg_ctrl "reset"' EXIT 115 + fi 116 + fi 112 117 113 118 ## -- General shell tricks -- 114 119
+6 -1
samples/pktgen/parameters.sh
··· 20 20 echo " -x : (\$DEBUG) debug" 21 21 echo " -6 : (\$IP6) IPv6" 22 22 echo " -w : (\$DELAY) Tx Delay value (ns)" 23 + echo " -a : (\$APPEND) Script will not reset generator's state, but will append its config" 23 24 echo "" 24 25 } 25 26 26 27 ## --- Parse command line arguments / parameters --- 27 28 ## echo "Commandline options:" 28 - while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6" option; do 29 + while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6a" option; do 29 30 case $option in 30 31 i) # interface 31 32 export DEV=$OPTARG ··· 84 83 export IP6=6 85 84 info "IP6: IP6=$IP6" 86 85 ;; 86 + a) 87 + export APPEND=yes 88 + info "Append mode: APPEND=$APPEND" 89 + ;; 87 90 h|?|*) 88 91 usage; 89 92 err 2 "[ERROR] Unknown parameters!!!"
+13 -9
samples/pktgen/pktgen_sample01_simple.sh
··· 37 37 38 38 # General cleanup everything since last run 39 39 # (especially important if other threads were configured by other scripts) 40 - pg_ctrl "reset" 40 + [ -z "$APPEND" ] && pg_ctrl "reset" 41 41 42 42 # Add remove all other devices and add_device $DEV to thread 0 43 43 thread=0 44 - pg_thread $thread "rem_device_all" 44 + [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 45 45 pg_thread $thread "add_device" $DEV 46 46 47 47 # How many packets to send (zero means indefinitely) ··· 77 77 pg_set $DEV "udp_src_min $UDP_SRC_MIN" 78 78 pg_set $DEV "udp_src_max $UDP_SRC_MAX" 79 79 80 - # start_run 81 - echo "Running... ctrl^C to stop" >&2 82 - pg_ctrl "start" 83 - echo "Done" >&2 80 + if [ -z "$APPEND" ]; then 81 + # start_run 82 + echo "Running... ctrl^C to stop" >&2 83 + pg_ctrl "start" 84 + echo "Done" >&2 84 85 85 - # Print results 86 - echo "Result device: $DEV" 87 - cat /proc/net/pktgen/$DEV 86 + # Print results 87 + echo "Result device: $DEV" 88 + cat /proc/net/pktgen/$DEV 89 + else 90 + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 91 + fi
+16 -12
samples/pktgen/pktgen_sample02_multiqueue.sh
··· 38 38 fi 39 39 40 40 # General cleanup everything since last run 41 - pg_ctrl "reset" 41 + [ -z "$APPEND" ] && pg_ctrl "reset" 42 42 43 43 # Threads are specified with parameter -t value in $THREADS 44 44 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do ··· 47 47 dev=${DEV}@${thread} 48 48 49 49 # Add remove all other devices and add_device $dev to thread 50 - pg_thread $thread "rem_device_all" 50 + [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 51 51 pg_thread $thread "add_device" $dev 52 52 53 53 # Notice config queue to map to cpu (mirrors smp_processor_id()) ··· 81 81 pg_set $dev "udp_src_max $UDP_SRC_MAX" 82 82 done 83 83 84 - # start_run 85 - echo "Running... ctrl^C to stop" >&2 86 - pg_ctrl "start" 87 - echo "Done" >&2 84 + if [ -z "$APPEND" ]; then 85 + # start_run 86 + echo "Running... ctrl^C to stop" >&2 87 + pg_ctrl "start" 88 + echo "Done" >&2 88 89 89 - # Print results 90 - for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 91 - dev=${DEV}@${thread} 92 - echo "Device: $dev" 93 - cat /proc/net/pktgen/$dev | grep -A2 "Result:" 94 - done 90 + # Print results 91 + for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 92 + dev=${DEV}@${thread} 93 + echo "Device: $dev" 94 + cat /proc/net/pktgen/$dev | grep -A2 "Result:" 95 + done 96 + else 97 + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 98 + fi
+8 -4
samples/pktgen/pktgen_sample03_burst_single_flow.sh
··· 43 43 fi 44 44 45 45 # General cleanup everything since last run 46 - pg_ctrl "reset" 46 + [ -z "$APPEND" ] && pg_ctrl "reset" 47 47 48 48 # Threads are specified with parameter -t value in $THREADS 49 49 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 50 50 dev=${DEV}@${thread} 51 51 52 52 # Add remove all other devices and add_device $dev to thread 53 - pg_thread $thread "rem_device_all" 53 + [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 54 54 pg_thread $thread "add_device" $dev 55 55 56 56 # Base config ··· 94 94 # trap keyboard interrupt (Ctrl-C) 95 95 trap control_c SIGINT 96 96 97 - echo "Running... ctrl^C to stop" >&2 98 - pg_ctrl "start" 97 + if [ -z "$APPEND" ]; then 98 + echo "Running... ctrl^C to stop" >&2 99 + pg_ctrl "start" 100 + else 101 + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 102 + fi
+9 -5
samples/pktgen/pktgen_sample04_many_flows.sh
··· 42 42 read -r SRC_MIN SRC_MAX <<< $(parse_addr 198.18.0.0/15) 43 43 44 44 # General cleanup everything since last run 45 - pg_ctrl "reset" 45 + [ -z "$APPEND" ] && pg_ctrl "reset" 46 46 47 47 # Threads are specified with parameter -t value in $THREADS 48 48 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 49 49 dev=${DEV}@${thread} 50 50 51 51 # Add remove all other devices and add_device $dev to thread 52 - pg_thread $thread "rem_device_all" 52 + [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 53 53 pg_thread $thread "add_device" $dev 54 54 55 55 # Base config ··· 104 104 # trap keyboard interrupt (Ctrl-C) 105 105 trap true SIGINT 106 106 107 - echo "Running... ctrl^C to stop" >&2 108 - pg_ctrl "start" 107 + if [ -z "$APPEND" ]; then 108 + echo "Running... ctrl^C to stop" >&2 109 + pg_ctrl "start" 109 110 110 - print_result 111 + print_result 112 + else 113 + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 114 + fi
+9 -5
samples/pktgen/pktgen_sample05_flow_per_thread.sh
··· 32 32 fi 33 33 34 34 # General cleanup everything since last run 35 - pg_ctrl "reset" 35 + [ -z "$APPEND" ] && pg_ctrl "reset" 36 36 37 37 # Threads are specified with parameter -t value in $THREADS 38 38 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 39 39 dev=${DEV}@${thread} 40 40 41 41 # Add remove all other devices and add_device $dev to thread 42 - pg_thread $thread "rem_device_all" 42 + [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 43 43 pg_thread $thread "add_device" $dev 44 44 45 45 # Base config ··· 88 88 # trap keyboard interrupt (Ctrl-C) 89 89 trap true SIGINT 90 90 91 - echo "Running... ctrl^C to stop" >&2 92 - pg_ctrl "start" 91 + if [ -z "$APPEND" ]; then 92 + echo "Running... ctrl^C to stop" >&2 93 + pg_ctrl "start" 93 94 94 - print_result 95 + print_result 96 + else 97 + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 98 + fi
+16 -12
samples/pktgen/pktgen_sample06_numa_awared_queue_irq_affinity.sh
··· 44 44 fi 45 45 46 46 # General cleanup everything since last run 47 - pg_ctrl "reset" 47 + [ -z "$APPEND" ] && pg_ctrl "reset" 48 48 49 49 # Threads are specified with parameter -t value in $THREADS 50 50 for ((i = 0; i < $THREADS; i++)); do ··· 58 58 info "irq ${irq_array[$i]} is set affinity to `cat /proc/irq/${irq_array[$i]}/smp_affinity_list`" 59 59 60 60 # Add remove all other devices and add_device $dev to thread 61 - pg_thread $thread "rem_device_all" 61 + [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 62 62 pg_thread $thread "add_device" $dev 63 63 64 64 # select queue and bind the queue and $dev in 1:1 relationship ··· 99 99 done 100 100 101 101 # start_run 102 - echo "Running... ctrl^C to stop" >&2 103 - pg_ctrl "start" 104 - echo "Done" >&2 102 + if [ -z "$APPEND" ]; then 103 + echo "Running... ctrl^C to stop" >&2 104 + pg_ctrl "start" 105 + echo "Done" >&2 105 106 106 - # Print results 107 - for ((i = 0; i < $THREADS; i++)); do 108 - thread=${cpu_array[$((i+F_THREAD))]} 109 - dev=${DEV}@${thread} 110 - echo "Device: $dev" 111 - cat /proc/net/pktgen/$dev | grep -A2 "Result:" 112 - done 107 + # Print results 108 + for ((i = 0; i < $THREADS; i++)); do 109 + thread=${cpu_array[$((i+F_THREAD))]} 110 + dev=${DEV}@${thread} 111 + echo "Device: $dev" 112 + cat /proc/net/pktgen/$dev | grep -A2 "Result:" 113 + done 114 + else 115 + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 116 + fi