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