115f2cbbdSJesper Dangaard Brouer#!/bin/bash 215f2cbbdSJesper Dangaard Brouer# 315f2cbbdSJesper Dangaard Brouer# Script example for many flows testing 415f2cbbdSJesper Dangaard Brouer# 515f2cbbdSJesper Dangaard Brouer# Number of simultaneous flows limited by variable $FLOWS 615f2cbbdSJesper Dangaard Brouer# and number of packets per flow controlled by variable $FLOWLEN 715f2cbbdSJesper Dangaard Brouer# 815f2cbbdSJesper Dangaard Brouerbasedir=`dirname $0` 915f2cbbdSJesper Dangaard Brouersource ${basedir}/functions.sh 1015f2cbbdSJesper Dangaard Brouerroot_check_run_with_sudo "$@" 1115f2cbbdSJesper Dangaard Brouer 1215f2cbbdSJesper Dangaard Brouer# Parameter parsing via include 1315f2cbbdSJesper Dangaard Brouersource ${basedir}/parameters.sh 1415f2cbbdSJesper Dangaard Brouer# Set some default params, if they didn't get set 1515f2cbbdSJesper Dangaard Brouer[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42" 1615f2cbbdSJesper Dangaard Brouer[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff" 1715f2cbbdSJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" 18*69137ea6STariq Toukan[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely 1915f2cbbdSJesper Dangaard Brouer 2015f2cbbdSJesper Dangaard Brouer# NOTICE: Script specific settings 2115f2cbbdSJesper Dangaard Brouer# ======= 2215f2cbbdSJesper Dangaard Brouer# Limiting the number of concurrent flows ($FLOWS) 2315f2cbbdSJesper Dangaard Brouer# and also set how many packets each flow contains ($FLOWLEN) 2415f2cbbdSJesper Dangaard Brouer# 2515f2cbbdSJesper Dangaard Brouer[ -z "$FLOWS" ] && FLOWS="8000" 2615f2cbbdSJesper Dangaard Brouer[ -z "$FLOWLEN" ] && FLOWLEN="10" 2715f2cbbdSJesper Dangaard Brouer 2815f2cbbdSJesper Dangaard Brouer# Base Config 2915f2cbbdSJesper Dangaard BrouerDELAY="0" # Zero means max speed 3015f2cbbdSJesper Dangaard Brouer 3115f2cbbdSJesper Dangaard Brouerif [[ -n "$BURST" ]]; then 3215f2cbbdSJesper Dangaard Brouer err 1 "Bursting not supported for this mode" 3315f2cbbdSJesper Dangaard Brouerfi 3415f2cbbdSJesper Dangaard Brouer 3515f2cbbdSJesper Dangaard Brouer# General cleanup everything since last run 3615f2cbbdSJesper Dangaard Brouerpg_ctrl "reset" 3715f2cbbdSJesper Dangaard Brouer 3815f2cbbdSJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS 3915f2cbbdSJesper Dangaard Brouerfor ((thread = 0; thread < $THREADS; thread++)); do 4015f2cbbdSJesper Dangaard Brouer dev=${DEV}@${thread} 4115f2cbbdSJesper Dangaard Brouer 4215f2cbbdSJesper Dangaard Brouer # Add remove all other devices and add_device $dev to thread 4315f2cbbdSJesper Dangaard Brouer pg_thread $thread "rem_device_all" 4415f2cbbdSJesper Dangaard Brouer pg_thread $thread "add_device" $dev 4515f2cbbdSJesper Dangaard Brouer 4615f2cbbdSJesper Dangaard Brouer # Base config 4715f2cbbdSJesper Dangaard Brouer pg_set $dev "flag QUEUE_MAP_CPU" 4815f2cbbdSJesper Dangaard Brouer pg_set $dev "count $COUNT" 4915f2cbbdSJesper Dangaard Brouer pg_set $dev "clone_skb $CLONE_SKB" 5015f2cbbdSJesper Dangaard Brouer pg_set $dev "pkt_size $PKT_SIZE" 5115f2cbbdSJesper Dangaard Brouer pg_set $dev "delay $DELAY" 5215f2cbbdSJesper Dangaard Brouer pg_set $dev "flag NO_TIMESTAMP" 5315f2cbbdSJesper Dangaard Brouer 5415f2cbbdSJesper Dangaard Brouer # Single destination 5515f2cbbdSJesper Dangaard Brouer pg_set $dev "dst_mac $DST_MAC" 5615f2cbbdSJesper Dangaard Brouer pg_set $dev "dst $DEST_IP" 5715f2cbbdSJesper Dangaard Brouer 5815f2cbbdSJesper Dangaard Brouer # Randomize source IP-addresses 5915f2cbbdSJesper Dangaard Brouer pg_set $dev "flag IPSRC_RND" 6015f2cbbdSJesper Dangaard Brouer pg_set $dev "src_min 198.18.0.0" 6115f2cbbdSJesper Dangaard Brouer pg_set $dev "src_max 198.19.255.255" 6215f2cbbdSJesper Dangaard Brouer 6315f2cbbdSJesper Dangaard Brouer # Limit number of flows (max 65535) 6415f2cbbdSJesper Dangaard Brouer pg_set $dev "flows $FLOWS" 6515f2cbbdSJesper Dangaard Brouer # 6615f2cbbdSJesper Dangaard Brouer # How many packets a flow will send, before flow "entry" is 6715f2cbbdSJesper Dangaard Brouer # re-generated/setup. 6815f2cbbdSJesper Dangaard Brouer pg_set $dev "flowlen $FLOWLEN" 6915f2cbbdSJesper Dangaard Brouer # 7015f2cbbdSJesper Dangaard Brouer # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow 7115f2cbbdSJesper Dangaard Brouer # being send back-to-back, before next flow is selected 7215f2cbbdSJesper Dangaard Brouer # incrementally. This helps lookup caches, and is more realistic. 7315f2cbbdSJesper Dangaard Brouer # 7415f2cbbdSJesper Dangaard Brouer pg_set $dev "flag FLOW_SEQ" 7515f2cbbdSJesper Dangaard Brouer 7615f2cbbdSJesper Dangaard Brouerdone 7715f2cbbdSJesper Dangaard Brouer 7815f2cbbdSJesper Dangaard Brouer# Run if user hits control-c 7915f2cbbdSJesper Dangaard Brouerfunction print_result() { 8015f2cbbdSJesper Dangaard Brouer # Print results 8115f2cbbdSJesper Dangaard Brouer for ((thread = 0; thread < $THREADS; thread++)); do 8215f2cbbdSJesper Dangaard Brouer dev=${DEV}@${thread} 8315f2cbbdSJesper Dangaard Brouer echo "Device: $dev" 8415f2cbbdSJesper Dangaard Brouer cat /proc/net/pktgen/$dev | grep -A2 "Result:" 8515f2cbbdSJesper Dangaard Brouer done 8615f2cbbdSJesper Dangaard Brouer} 8715f2cbbdSJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C) 8815f2cbbdSJesper Dangaard Brouertrap true SIGINT 8915f2cbbdSJesper Dangaard Brouer 9015f2cbbdSJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2 9115f2cbbdSJesper Dangaard Brouerpg_ctrl "start" 9215f2cbbdSJesper Dangaard Brouer 9315f2cbbdSJesper Dangaard Brouerprint_result 94