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