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