Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 1 | # |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 3 | # Common parameter parsing for pktgen scripts |
| 4 | # |
| 5 | |
| 6 | function usage() { |
| 7 | echo "" |
| 8 | echo "Usage: $0 [-vx] -i ethX" |
| 9 | echo " -i : (\$DEV) output interface/device (required)" |
| 10 | echo " -s : (\$PKT_SIZE) packet size" |
| 11 | echo " -d : (\$DEST_IP) destination IP" |
| 12 | echo " -m : (\$DST_MAC) destination MAC-addr" |
| 13 | echo " -t : (\$THREADS) threads to start" |
Tariq Toukan | e0e1667 | 2017-06-15 19:07:22 +0300 | [diff] [blame] | 14 | echo " -f : (\$F_THREAD) index of first thread (zero indexed CPU number)" |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 15 | echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB" |
Tariq Toukan | 69137ea | 2017-06-15 19:07:21 +0300 | [diff] [blame] | 16 | echo " -n : (\$COUNT) num messages to send per thread, 0 means indefinitely" |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 17 | echo " -b : (\$BURST) HW level bursting of SKBs" |
| 18 | echo " -v : (\$VERBOSE) verbose" |
| 19 | echo " -x : (\$DEBUG) debug" |
Martin KaFai Lau | 0f06a67 | 2016-07-20 15:48:43 -0700 | [diff] [blame] | 20 | echo " -6 : (\$IP6) IPv6" |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 21 | echo "" |
| 22 | } |
| 23 | |
| 24 | ## --- Parse command line arguments / parameters --- |
| 25 | ## echo "Commandline options:" |
Tariq Toukan | e0e1667 | 2017-06-15 19:07:22 +0300 | [diff] [blame] | 26 | while getopts "s:i:d:m:f:t:c:n:b:vxh6" option; do |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 27 | case $option in |
| 28 | i) # interface |
| 29 | export DEV=$OPTARG |
| 30 | info "Output device set to: DEV=$DEV" |
| 31 | ;; |
| 32 | s) |
| 33 | export PKT_SIZE=$OPTARG |
| 34 | info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes" |
| 35 | ;; |
| 36 | d) # destination IP |
| 37 | export DEST_IP=$OPTARG |
| 38 | info "Destination IP set to: DEST_IP=$DEST_IP" |
| 39 | ;; |
| 40 | m) # MAC |
| 41 | export DST_MAC=$OPTARG |
| 42 | info "Destination MAC set to: DST_MAC=$DST_MAC" |
| 43 | ;; |
Tariq Toukan | e0e1667 | 2017-06-15 19:07:22 +0300 | [diff] [blame] | 44 | f) |
| 45 | export F_THREAD=$OPTARG |
| 46 | info "Index of first thread (zero indexed CPU number): $F_THREAD" |
| 47 | ;; |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 48 | t) |
| 49 | export THREADS=$OPTARG |
Tariq Toukan | e0e1667 | 2017-06-15 19:07:22 +0300 | [diff] [blame] | 50 | info "Number of threads to start: $THREADS" |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 51 | ;; |
| 52 | c) |
| 53 | export CLONE_SKB=$OPTARG |
| 54 | info "CLONE_SKB=$CLONE_SKB" |
| 55 | ;; |
Tariq Toukan | 69137ea | 2017-06-15 19:07:21 +0300 | [diff] [blame] | 56 | n) |
| 57 | export COUNT=$OPTARG |
| 58 | info "COUNT=$COUNT" |
| 59 | ;; |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 60 | b) |
| 61 | export BURST=$OPTARG |
| 62 | info "SKB bursting: BURST=$BURST" |
| 63 | ;; |
| 64 | v) |
| 65 | export VERBOSE=yes |
| 66 | info "Verbose mode: VERBOSE=$VERBOSE" |
| 67 | ;; |
| 68 | x) |
| 69 | export DEBUG=yes |
| 70 | info "Debug mode: DEBUG=$DEBUG" |
| 71 | ;; |
Martin KaFai Lau | 0f06a67 | 2016-07-20 15:48:43 -0700 | [diff] [blame] | 72 | 6) |
| 73 | export IP6=6 |
| 74 | info "IP6: IP6=$IP6" |
| 75 | ;; |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 76 | h|?|*) |
| 77 | usage; |
| 78 | err 2 "[ERROR] Unknown parameters!!!" |
| 79 | esac |
| 80 | done |
| 81 | shift $(( $OPTIND - 1 )) |
| 82 | |
| 83 | if [ -z "$PKT_SIZE" ]; then |
| 84 | # NIC adds 4 bytes CRC |
| 85 | export PKT_SIZE=60 |
| 86 | info "Default packet size set to: set to: $PKT_SIZE bytes" |
| 87 | fi |
| 88 | |
Tariq Toukan | e0e1667 | 2017-06-15 19:07:22 +0300 | [diff] [blame] | 89 | if [ -z "$F_THREAD" ]; then |
| 90 | # First thread (F_THREAD) reference the zero indexed CPU number |
| 91 | export F_THREAD=0 |
| 92 | fi |
| 93 | |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 94 | if [ -z "$THREADS" ]; then |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 95 | export THREADS=1 |
| 96 | fi |
| 97 | |
Tariq Toukan | e0e1667 | 2017-06-15 19:07:22 +0300 | [diff] [blame] | 98 | export L_THREAD=$(( THREADS + F_THREAD - 1 )) |
| 99 | |
Jesper Dangaard Brouer | b64b0d1 | 2015-05-21 12:17:19 +0200 | [diff] [blame] | 100 | if [ -z "$DEV" ]; then |
| 101 | usage |
| 102 | err 2 "Please specify output device" |
| 103 | fi |
| 104 | |
| 105 | if [ -z "$DST_MAC" ]; then |
| 106 | warn "Missing destination MAC address" |
| 107 | fi |
| 108 | |
| 109 | if [ -z "$DEST_IP" ]; then |
| 110 | warn "Missing destination IP address" |
| 111 | fi |
| 112 | |
| 113 | if [ ! -d /proc/net/pktgen ]; then |
| 114 | info "Loading kernel module: pktgen" |
| 115 | modprobe pktgen |
| 116 | fi |