11d73ba16SJesper Dangaard Brouer#!/bin/bash 21d73ba16SJesper Dangaard Brouer# 31d73ba16SJesper Dangaard Brouer# Script for max single flow performance 41d73ba16SJesper Dangaard Brouer# - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2] 51d73ba16SJesper Dangaard Brouer# 61d73ba16SJesper Dangaard Brouer# Using pktgen "burst" option (use -b $N) 71d73ba16SJesper Dangaard Brouer# - To boost max performance 81d73ba16SJesper Dangaard Brouer# - Avail since: kernel v3.18 91d73ba16SJesper Dangaard Brouer# * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more") 101d73ba16SJesper Dangaard Brouer# - This avoids writing the HW tailptr on every driver xmit 111d73ba16SJesper Dangaard Brouer# - The performance boost is impressive, see commit and blog [2] 121d73ba16SJesper Dangaard Brouer# 131d73ba16SJesper Dangaard Brouer# Notice: On purpose generates a single (UDP) flow towards target, 141d73ba16SJesper Dangaard Brouer# reason behind this is to only overload/activate a single CPU on 151d73ba16SJesper Dangaard Brouer# target host. And no randomness for pktgen also makes it faster. 161d73ba16SJesper Dangaard Brouer# 171d73ba16SJesper Dangaard Brouer# Tuning see: 181d73ba16SJesper Dangaard Brouer# [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html 191d73ba16SJesper Dangaard Brouer# [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html 201d73ba16SJesper Dangaard Brouer# 211d73ba16SJesper Dangaard Brouerbasedir=`dirname $0` 221d73ba16SJesper Dangaard Brouersource ${basedir}/functions.sh 231d73ba16SJesper Dangaard Brouerroot_check_run_with_sudo "$@" 241d73ba16SJesper Dangaard Brouer 251d73ba16SJesper Dangaard Brouer# Parameter parsing via include 261d73ba16SJesper Dangaard Brouersource ${basedir}/parameters.sh 271d73ba16SJesper Dangaard Brouer# Set some default params, if they didn't get set 280f06a678SMartin KaFai Lauif [ -z "$DEST_IP" ]; then 290f06a678SMartin KaFai Lau [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1" 300f06a678SMartin KaFai Laufi 311d73ba16SJesper Dangaard Brouer[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff" 321d73ba16SJesper Dangaard Brouer[ -z "$BURST" ] && BURST=32 33*9efc44d7SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" # No need for clones when bursting 3469137ea6STariq Toukan[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely 351d73ba16SJesper Dangaard Brouer 361d73ba16SJesper Dangaard Brouer# Base Config 371d73ba16SJesper Dangaard BrouerDELAY="0" # Zero means max speed 381d73ba16SJesper Dangaard Brouer 391d73ba16SJesper Dangaard Brouer# General cleanup everything since last run 401d73ba16SJesper Dangaard Brouerpg_ctrl "reset" 411d73ba16SJesper Dangaard Brouer 421d73ba16SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS 43e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 441d73ba16SJesper Dangaard Brouer dev=${DEV}@${thread} 451d73ba16SJesper Dangaard Brouer 461d73ba16SJesper Dangaard Brouer # Add remove all other devices and add_device $dev to thread 471d73ba16SJesper Dangaard Brouer pg_thread $thread "rem_device_all" 481d73ba16SJesper Dangaard Brouer pg_thread $thread "add_device" $dev 491d73ba16SJesper Dangaard Brouer 501d73ba16SJesper Dangaard Brouer # Base config 511d73ba16SJesper Dangaard Brouer pg_set $dev "flag QUEUE_MAP_CPU" 521d73ba16SJesper Dangaard Brouer pg_set $dev "count $COUNT" 531d73ba16SJesper Dangaard Brouer pg_set $dev "clone_skb $CLONE_SKB" 541d73ba16SJesper Dangaard Brouer pg_set $dev "pkt_size $PKT_SIZE" 551d73ba16SJesper Dangaard Brouer pg_set $dev "delay $DELAY" 561d73ba16SJesper Dangaard Brouer pg_set $dev "flag NO_TIMESTAMP" 571d73ba16SJesper Dangaard Brouer 581d73ba16SJesper Dangaard Brouer # Destination 591d73ba16SJesper Dangaard Brouer pg_set $dev "dst_mac $DST_MAC" 600f06a678SMartin KaFai Lau pg_set $dev "dst$IP6 $DEST_IP" 611d73ba16SJesper Dangaard Brouer 621d73ba16SJesper Dangaard Brouer # Setup burst, for easy testing -b 0 disable bursting 631d73ba16SJesper Dangaard Brouer # (internally in pktgen default and minimum burst=1) 641d73ba16SJesper Dangaard Brouer if [[ ${BURST} -ne 0 ]]; then 651d73ba16SJesper Dangaard Brouer pg_set $dev "burst $BURST" 661d73ba16SJesper Dangaard Brouer else 671d73ba16SJesper Dangaard Brouer info "$dev: Not using burst" 681d73ba16SJesper Dangaard Brouer fi 691d73ba16SJesper Dangaard Brouerdone 701d73ba16SJesper Dangaard Brouer 711d73ba16SJesper Dangaard Brouer# Run if user hits control-c 721d73ba16SJesper Dangaard Brouerfunction control_c() { 731d73ba16SJesper Dangaard Brouer # Print results 74e0e16672STariq Toukan for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 751d73ba16SJesper Dangaard Brouer dev=${DEV}@${thread} 761d73ba16SJesper Dangaard Brouer echo "Device: $dev" 771d73ba16SJesper Dangaard Brouer cat /proc/net/pktgen/$dev | grep -A2 "Result:" 781d73ba16SJesper Dangaard Brouer done 791d73ba16SJesper Dangaard Brouer} 801d73ba16SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C) 811d73ba16SJesper Dangaard Brouertrap control_c SIGINT 821d73ba16SJesper Dangaard Brouer 831d73ba16SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2 841d73ba16SJesper Dangaard Brouerpg_ctrl "start" 85