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