Path: blob/master/samples/pktgen/pktgen_sample05_flow_per_thread.sh
26278 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Script will generate one flow per thread (-t N)4# - Same destination IP5# - Fake source IPs for each flow (fixed based on thread number)6#7# Useful for scale testing on receiver, to see whether silo'ing flows8# works and scales. For optimal scalability (on receiver) each9# separate-flow should not access shared variables/data. This script10# helps magnify any of these scaling issues by overloading the receiver.11#12basedir=`dirname $0`13source ${basedir}/functions.sh14root_check_run_with_sudo "$@"1516# Parameter parsing via include17source ${basedir}/parameters.sh1819# Trap EXIT first20trap_exit2122# Set some default params, if they didn't get set23if [ -z "$DEST_IP" ]; then24[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"25fi26[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"27[ -z "$CLONE_SKB" ] && CLONE_SKB="0"28[ -z "$BURST" ] && BURST=3229[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely30if [ -n "$DEST_IP" ]; then31validate_addr${IP6} $DEST_IP32read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)33fi34if [ -n "$DST_PORT" ]; then35read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)36validate_ports $UDP_DST_MIN $UDP_DST_MAX37fi3839# General cleanup everything since last run40[ -z "$APPEND" ] && pg_ctrl "reset"4142# Threads are specified with parameter -t value in $THREADS43for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do44dev=${DEV}@${thread}4546# Add remove all other devices and add_device $dev to thread47[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"48pg_thread $thread "add_device" $dev4950# Base config51pg_set $dev "flag QUEUE_MAP_CPU"52pg_set $dev "count $COUNT"53pg_set $dev "clone_skb $CLONE_SKB"54pg_set $dev "pkt_size $PKT_SIZE"55pg_set $dev "delay $DELAY"56pg_set $dev "flag NO_TIMESTAMP"5758# Single destination59pg_set $dev "dst_mac $DST_MAC"60pg_set $dev "dst${IP6}_min $DST_MIN"61pg_set $dev "dst${IP6}_max $DST_MAX"6263if [ -n "$DST_PORT" ]; then64# Single destination port or random port range65pg_set $dev "flag UDPDST_RND"66pg_set $dev "udp_dst_min $UDP_DST_MIN"67pg_set $dev "udp_dst_max $UDP_DST_MAX"68fi6970[ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"7172# Setup source IP-addresses based on thread number73pg_set $dev "src_min 198.18.$((thread+1)).1"74pg_set $dev "src_max 198.18.$((thread+1)).1"7576# Setup burst, for easy testing -b 0 disable bursting77# (internally in pktgen default and minimum burst=1)78if [[ ${BURST} -ne 0 ]]; then79pg_set $dev "burst $BURST"80else81info "$dev: Not using burst"82fi8384done8586# Run if user hits control-c87function print_result() {88# Print results89for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do90dev=${DEV}@${thread}91echo "Device: $dev"92cat /proc/net/pktgen/$dev | grep -A2 "Result:"93done94}95# trap keyboard interrupt (Ctrl-C)96trap true SIGINT9798if [ -z "$APPEND" ]; then99echo "Running... ctrl^C to stop" >&2100pg_ctrl "start"101102print_result103else104echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"105fi106107108