1*15f2cbbdSJesper Dangaard Brouer#!/bin/bash 2*15f2cbbdSJesper Dangaard Brouer# 3*15f2cbbdSJesper Dangaard Brouer# Script example for many flows testing 4*15f2cbbdSJesper Dangaard Brouer# 5*15f2cbbdSJesper Dangaard Brouer# Number of simultaneous flows limited by variable $FLOWS 6*15f2cbbdSJesper Dangaard Brouer# and number of packets per flow controlled by variable $FLOWLEN 7*15f2cbbdSJesper Dangaard Brouer# 8*15f2cbbdSJesper Dangaard Brouerbasedir=`dirname $0` 9*15f2cbbdSJesper Dangaard Brouersource ${basedir}/functions.sh 10*15f2cbbdSJesper Dangaard Brouerroot_check_run_with_sudo "$@" 11*15f2cbbdSJesper Dangaard Brouer 12*15f2cbbdSJesper Dangaard Brouer# Parameter parsing via include 13*15f2cbbdSJesper Dangaard Brouersource ${basedir}/parameters.sh 14*15f2cbbdSJesper Dangaard Brouer# Set some default params, if they didn't get set 15*15f2cbbdSJesper Dangaard Brouer[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42" 16*15f2cbbdSJesper Dangaard Brouer[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff" 17*15f2cbbdSJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" 18*15f2cbbdSJesper Dangaard Brouer 19*15f2cbbdSJesper Dangaard Brouer# NOTICE: Script specific settings 20*15f2cbbdSJesper Dangaard Brouer# ======= 21*15f2cbbdSJesper Dangaard Brouer# Limiting the number of concurrent flows ($FLOWS) 22*15f2cbbdSJesper Dangaard Brouer# and also set how many packets each flow contains ($FLOWLEN) 23*15f2cbbdSJesper Dangaard Brouer# 24*15f2cbbdSJesper Dangaard Brouer[ -z "$FLOWS" ] && FLOWS="8000" 25*15f2cbbdSJesper Dangaard Brouer[ -z "$FLOWLEN" ] && FLOWLEN="10" 26*15f2cbbdSJesper Dangaard Brouer 27*15f2cbbdSJesper Dangaard Brouer# Base Config 28*15f2cbbdSJesper Dangaard BrouerDELAY="0" # Zero means max speed 29*15f2cbbdSJesper Dangaard BrouerCOUNT="0" # Zero means indefinitely 30*15f2cbbdSJesper Dangaard Brouer 31*15f2cbbdSJesper Dangaard Brouerif [[ -n "$BURST" ]]; then 32*15f2cbbdSJesper Dangaard Brouer err 1 "Bursting not supported for this mode" 33*15f2cbbdSJesper Dangaard Brouerfi 34*15f2cbbdSJesper Dangaard Brouer 35*15f2cbbdSJesper Dangaard Brouer# General cleanup everything since last run 36*15f2cbbdSJesper Dangaard Brouerpg_ctrl "reset" 37*15f2cbbdSJesper Dangaard Brouer 38*15f2cbbdSJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS 39*15f2cbbdSJesper Dangaard Brouerfor ((thread = 0; thread < $THREADS; thread++)); do 40*15f2cbbdSJesper Dangaard Brouer dev=${DEV}@${thread} 41*15f2cbbdSJesper Dangaard Brouer 42*15f2cbbdSJesper Dangaard Brouer # Add remove all other devices and add_device $dev to thread 43*15f2cbbdSJesper Dangaard Brouer pg_thread $thread "rem_device_all" 44*15f2cbbdSJesper Dangaard Brouer pg_thread $thread "add_device" $dev 45*15f2cbbdSJesper Dangaard Brouer 46*15f2cbbdSJesper Dangaard Brouer # Base config 47*15f2cbbdSJesper Dangaard Brouer pg_set $dev "flag QUEUE_MAP_CPU" 48*15f2cbbdSJesper Dangaard Brouer pg_set $dev "count $COUNT" 49*15f2cbbdSJesper Dangaard Brouer pg_set $dev "clone_skb $CLONE_SKB" 50*15f2cbbdSJesper Dangaard Brouer pg_set $dev "pkt_size $PKT_SIZE" 51*15f2cbbdSJesper Dangaard Brouer pg_set $dev "delay $DELAY" 52*15f2cbbdSJesper Dangaard Brouer pg_set $dev "flag NO_TIMESTAMP" 53*15f2cbbdSJesper Dangaard Brouer 54*15f2cbbdSJesper Dangaard Brouer # Single destination 55*15f2cbbdSJesper Dangaard Brouer pg_set $dev "dst_mac $DST_MAC" 56*15f2cbbdSJesper Dangaard Brouer pg_set $dev "dst $DEST_IP" 57*15f2cbbdSJesper Dangaard Brouer 58*15f2cbbdSJesper Dangaard Brouer # Randomize source IP-addresses 59*15f2cbbdSJesper Dangaard Brouer pg_set $dev "flag IPSRC_RND" 60*15f2cbbdSJesper Dangaard Brouer pg_set $dev "src_min 198.18.0.0" 61*15f2cbbdSJesper Dangaard Brouer pg_set $dev "src_max 198.19.255.255" 62*15f2cbbdSJesper Dangaard Brouer 63*15f2cbbdSJesper Dangaard Brouer # Limit number of flows (max 65535) 64*15f2cbbdSJesper Dangaard Brouer pg_set $dev "flows $FLOWS" 65*15f2cbbdSJesper Dangaard Brouer # 66*15f2cbbdSJesper Dangaard Brouer # How many packets a flow will send, before flow "entry" is 67*15f2cbbdSJesper Dangaard Brouer # re-generated/setup. 68*15f2cbbdSJesper Dangaard Brouer pg_set $dev "flowlen $FLOWLEN" 69*15f2cbbdSJesper Dangaard Brouer # 70*15f2cbbdSJesper Dangaard Brouer # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow 71*15f2cbbdSJesper Dangaard Brouer # being send back-to-back, before next flow is selected 72*15f2cbbdSJesper Dangaard Brouer # incrementally. This helps lookup caches, and is more realistic. 73*15f2cbbdSJesper Dangaard Brouer # 74*15f2cbbdSJesper Dangaard Brouer pg_set $dev "flag FLOW_SEQ" 75*15f2cbbdSJesper Dangaard Brouer 76*15f2cbbdSJesper Dangaard Brouerdone 77*15f2cbbdSJesper Dangaard Brouer 78*15f2cbbdSJesper Dangaard Brouer# Run if user hits control-c 79*15f2cbbdSJesper Dangaard Brouerfunction print_result() { 80*15f2cbbdSJesper Dangaard Brouer # Print results 81*15f2cbbdSJesper Dangaard Brouer for ((thread = 0; thread < $THREADS; thread++)); do 82*15f2cbbdSJesper Dangaard Brouer dev=${DEV}@${thread} 83*15f2cbbdSJesper Dangaard Brouer echo "Device: $dev" 84*15f2cbbdSJesper Dangaard Brouer cat /proc/net/pktgen/$dev | grep -A2 "Result:" 85*15f2cbbdSJesper Dangaard Brouer done 86*15f2cbbdSJesper Dangaard Brouer} 87*15f2cbbdSJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C) 88*15f2cbbdSJesper Dangaard Brouertrap true SIGINT 89*15f2cbbdSJesper Dangaard Brouer 90*15f2cbbdSJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2 91*15f2cbbdSJesper Dangaard Brouerpg_ctrl "start" 92*15f2cbbdSJesper Dangaard Brouer 93*15f2cbbdSJesper Dangaard Brouerprint_result 94