Path: blob/master/samples/pktgen/pktgen_sample03_burst_single_flow.sh
26278 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Script for max single flow performance4# - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]5#6# Using pktgen "burst" option (use -b $N)7# - To boost max performance8# - Avail since: kernel v3.189# * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")10# - This avoids writing the HW tailptr on every driver xmit11# - The performance boost is impressive, see commit and blog [2]12#13# Notice: On purpose generates a single (UDP) flow towards target,14# reason behind this is to only overload/activate a single CPU on15# target host. And no randomness for pktgen also makes it faster.16#17# Tuning see:18# [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html19# [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html20#21basedir=`dirname $0`22source ${basedir}/functions.sh23root_check_run_with_sudo "$@"2425# Parameter parsing via include26source ${basedir}/parameters.sh2728# Trap EXIT first29trap_exit3031# Set some default params, if they didn't get set32if [ -z "$DEST_IP" ]; then33[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"34fi35[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"36[ -z "$BURST" ] && BURST=3237[ -z "$CLONE_SKB" ] && CLONE_SKB="0" # No need for clones when bursting38[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely39if [ -n "$DEST_IP" ]; then40validate_addr${IP6} $DEST_IP41read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)42fi43if [ -n "$DST_PORT" ]; then44read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)45validate_ports $UDP_DST_MIN $UDP_DST_MAX46fi4748# General cleanup everything since last run49[ -z "$APPEND" ] && pg_ctrl "reset"5051# Threads are specified with parameter -t value in $THREADS52for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do53dev=${DEV}@${thread}5455# Add remove all other devices and add_device $dev to thread56[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"57pg_thread $thread "add_device" $dev5859# Base config60pg_set $dev "flag QUEUE_MAP_CPU"61pg_set $dev "count $COUNT"62pg_set $dev "clone_skb $CLONE_SKB"63pg_set $dev "pkt_size $PKT_SIZE"64pg_set $dev "delay $DELAY"65pg_set $dev "flag NO_TIMESTAMP"6667# Destination68pg_set $dev "dst_mac $DST_MAC"69pg_set $dev "dst${IP6}_min $DST_MIN"70pg_set $dev "dst${IP6}_max $DST_MAX"7172if [ -n "$DST_PORT" ]; then73# Single destination port or random port range74pg_set $dev "flag UDPDST_RND"75pg_set $dev "udp_dst_min $UDP_DST_MIN"76pg_set $dev "udp_dst_max $UDP_DST_MAX"77fi7879[ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"8081# Setup burst, for easy testing -b 0 disable bursting82# (internally in pktgen default and minimum burst=1)83if [[ ${BURST} -ne 0 ]]; then84pg_set $dev "burst $BURST"85else86info "$dev: Not using burst"87fi88done8990# Run if user hits control-c91function print_result() {92# Print results93for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do94dev=${DEV}@${thread}95echo "Device: $dev"96cat /proc/net/pktgen/$dev | grep -A2 "Result:"97done98}99# trap keyboard interrupt (Ctrl-C)100trap true SIGINT101102if [ -z "$APPEND" ]; then103echo "Running... ctrl^C to stop" >&2104pg_ctrl "start"105106print_result107else108echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"109fi110111112