Path: blob/master/samples/pktgen/pktgen_sample02_multiqueue.sh
26278 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Multiqueue: Using pktgen threads for sending on multiple CPUs4# * adding devices to kernel threads5# * notice the naming scheme for keeping device names unique6# * nameing scheme: dev@thread_number7# * flow variation via random UDP source port8#9basedir=`dirname $0`10source ${basedir}/functions.sh11root_check_run_with_sudo "$@"12#13# Required param: -i dev in $DEV14source ${basedir}/parameters.sh1516# Trap EXIT first17trap_exit1819[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely2021# Base Config22[ -z "$CLONE_SKB" ] && CLONE_SKB="0"2324# Flow variation random source port between min and max25UDP_SRC_MIN=926UDP_SRC_MAX=1092728# (example of setting default params in your script)29if [ -z "$DEST_IP" ]; then30[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"31fi32[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"33if [ -n "$DEST_IP" ]; then34validate_addr${IP6} $DEST_IP35read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)36fi37if [ -n "$DST_PORT" ]; then38read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)39validate_ports $UDP_DST_MIN $UDP_DST_MAX40fi4142# General cleanup everything since last run43[ -z "$APPEND" ] && pg_ctrl "reset"4445# Threads are specified with parameter -t value in $THREADS46for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do47# The device name is extended with @name, using thread number to48# make then unique, but any name will do.49dev=${DEV}@${thread}5051# Add remove all other devices and add_device $dev to thread52[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"53pg_thread $thread "add_device" $dev5455# Notice config queue to map to cpu (mirrors smp_processor_id())56# It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number57pg_set $dev "flag QUEUE_MAP_CPU"5859# Base config of dev60pg_set $dev "count $COUNT"61pg_set $dev "clone_skb $CLONE_SKB"62pg_set $dev "pkt_size $PKT_SIZE"63pg_set $dev "delay $DELAY"6465# Flag example disabling timestamping66pg_set $dev "flag NO_TIMESTAMP"6768# Destination69pg_set $dev "dst_mac $DST_MAC"70pg_set $dev "dst${IP6}_min $DST_MIN"71pg_set $dev "dst${IP6}_max $DST_MAX"7273if [ -n "$DST_PORT" ]; then74# Single destination port or random port range75pg_set $dev "flag UDPDST_RND"76pg_set $dev "udp_dst_min $UDP_DST_MIN"77pg_set $dev "udp_dst_max $UDP_DST_MAX"78fi7980[ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"8182# Setup random UDP port src range83pg_set $dev "flag UDPSRC_RND"84pg_set $dev "udp_src_min $UDP_SRC_MIN"85pg_set $dev "udp_src_max $UDP_SRC_MAX"86done8788# Run if user hits control-c89function print_result() {90# Print results91for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do92dev=${DEV}@${thread}93echo "Device: $dev"94cat /proc/net/pktgen/$dev | grep -A2 "Result:"95done96}97# trap keyboard interrupt (Ctrl-C)98trap true SIGINT99100if [ -z "$APPEND" ]; then101# start_run102echo "Running... ctrl^C to stop" >&2103pg_ctrl "start"104echo "Done" >&2105106print_result107else108echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"109fi110111112