1*282fb589SJesper Dangaard Brouer#!/bin/bash 2*282fb589SJesper Dangaard Brouer# 3*282fb589SJesper Dangaard Brouer# Multiqueue: Using pktgen threads for sending on multiple CPUs 4*282fb589SJesper Dangaard Brouer# * adding devices to kernel threads 5*282fb589SJesper Dangaard Brouer# * notice the naming scheme for keeping device names unique 6*282fb589SJesper Dangaard Brouer# * nameing scheme: dev@thread_number 7*282fb589SJesper Dangaard Brouer# * flow variation via random UDP source port 8*282fb589SJesper Dangaard Brouer# 9*282fb589SJesper Dangaard Brouerbasedir=`dirname $0` 10*282fb589SJesper Dangaard Brouersource ${basedir}/functions.sh 11*282fb589SJesper Dangaard Brouerroot_check_run_with_sudo "$@" 12*282fb589SJesper Dangaard Brouer# 13*282fb589SJesper Dangaard Brouer# Required param: -i dev in $DEV 14*282fb589SJesper Dangaard Brouersource ${basedir}/parameters.sh 15*282fb589SJesper Dangaard Brouer 16*282fb589SJesper Dangaard Brouer# Base Config 17*282fb589SJesper Dangaard BrouerDELAY="0" # Zero means max speed 18*282fb589SJesper Dangaard BrouerCOUNT="100000" # Zero means indefinitely 19*282fb589SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" 20*282fb589SJesper Dangaard Brouer 21*282fb589SJesper Dangaard Brouer# Flow variation random source port between min and max 22*282fb589SJesper Dangaard BrouerUDP_MIN=9 23*282fb589SJesper Dangaard BrouerUDP_MAX=109 24*282fb589SJesper Dangaard Brouer 25*282fb589SJesper Dangaard Brouer# (example of setting default params in your script) 26*282fb589SJesper Dangaard Brouer[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42" 27*282fb589SJesper Dangaard Brouer[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff" 28*282fb589SJesper Dangaard Brouer 29*282fb589SJesper Dangaard Brouer# General cleanup everything since last run 30*282fb589SJesper Dangaard Brouerpg_ctrl "reset" 31*282fb589SJesper Dangaard Brouer 32*282fb589SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS 33*282fb589SJesper Dangaard Brouerfor ((thread = 0; thread < $THREADS; thread++)); do 34*282fb589SJesper Dangaard Brouer # The device name is extended with @name, using thread number to 35*282fb589SJesper Dangaard Brouer # make then unique, but any name will do. 36*282fb589SJesper Dangaard Brouer dev=${DEV}@${thread} 37*282fb589SJesper Dangaard Brouer 38*282fb589SJesper Dangaard Brouer # Add remove all other devices and add_device $dev to thread 39*282fb589SJesper Dangaard Brouer pg_thread $thread "rem_device_all" 40*282fb589SJesper Dangaard Brouer pg_thread $thread "add_device" $dev 41*282fb589SJesper Dangaard Brouer 42*282fb589SJesper Dangaard Brouer # Notice config queue to map to cpu (mirrors smp_processor_id()) 43*282fb589SJesper Dangaard Brouer # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number 44*282fb589SJesper Dangaard Brouer pg_set $dev "flag QUEUE_MAP_CPU" 45*282fb589SJesper Dangaard Brouer 46*282fb589SJesper Dangaard Brouer # Base config of dev 47*282fb589SJesper Dangaard Brouer pg_set $dev "count $COUNT" 48*282fb589SJesper Dangaard Brouer pg_set $dev "clone_skb $CLONE_SKB" 49*282fb589SJesper Dangaard Brouer pg_set $dev "pkt_size $PKT_SIZE" 50*282fb589SJesper Dangaard Brouer pg_set $dev "delay $DELAY" 51*282fb589SJesper Dangaard Brouer 52*282fb589SJesper Dangaard Brouer # Flag example disabling timestamping 53*282fb589SJesper Dangaard Brouer pg_set $dev "flag NO_TIMESTAMP" 54*282fb589SJesper Dangaard Brouer 55*282fb589SJesper Dangaard Brouer # Destination 56*282fb589SJesper Dangaard Brouer pg_set $dev "dst_mac $DST_MAC" 57*282fb589SJesper Dangaard Brouer pg_set $dev "dst $DEST_IP" 58*282fb589SJesper Dangaard Brouer 59*282fb589SJesper Dangaard Brouer # Setup random UDP port src range 60*282fb589SJesper Dangaard Brouer pg_set $dev "flag UDPSRC_RND" 61*282fb589SJesper Dangaard Brouer pg_set $dev "udp_src_min $UDP_MIN" 62*282fb589SJesper Dangaard Brouer pg_set $dev "udp_src_max $UDP_MAX" 63*282fb589SJesper Dangaard Brouerdone 64*282fb589SJesper Dangaard Brouer 65*282fb589SJesper Dangaard Brouer# start_run 66*282fb589SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2 67*282fb589SJesper Dangaard Brouerpg_ctrl "start" 68*282fb589SJesper Dangaard Brouerecho "Done" >&2 69*282fb589SJesper Dangaard Brouer 70*282fb589SJesper Dangaard Brouer# Print results 71*282fb589SJesper Dangaard Brouerfor ((thread = 0; thread < $THREADS; thread++)); do 72*282fb589SJesper Dangaard Brouer dev=${DEV}@${thread} 73*282fb589SJesper Dangaard Brouer echo "Device: $dev" 74*282fb589SJesper Dangaard Brouer cat /proc/net/pktgen/$dev | grep -A2 "Result:" 75*282fb589SJesper Dangaard Brouerdone 76