Commit | Line | Data |
---|---|---|
b64b0d1e | 1 | # |
b2441318 | 2 | # SPDX-License-Identifier: GPL-2.0 |
b64b0d1e JDB |
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" | |
40f843ee | 11 | echo " -d : (\$DEST_IP) destination IP. CIDR (e.g. 198.18.0.0/15) is also allowed" |
b64b0d1e | 12 | echo " -m : (\$DST_MAC) destination MAC-addr" |
6e32a74a | 13 | echo " -p : (\$DST_PORT) destination PORT range (e.g. 433-444) is also allowed" |
b64b0d1e | 14 | echo " -t : (\$THREADS) threads to start" |
e0e16672 | 15 | echo " -f : (\$F_THREAD) index of first thread (zero indexed CPU number)" |
b64b0d1e | 16 | echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB" |
69137ea6 | 17 | echo " -n : (\$COUNT) num messages to send per thread, 0 means indefinitely" |
b64b0d1e JDB |
18 | echo " -b : (\$BURST) HW level bursting of SKBs" |
19 | echo " -v : (\$VERBOSE) verbose" | |
20 | echo " -x : (\$DEBUG) debug" | |
0f06a678 | 21 | echo " -6 : (\$IP6) IPv6" |
ef700f2e | 22 | echo " -w : (\$DELAY) Tx Delay value (ns)" |
b64b0d1e JDB |
23 | echo "" |
24 | } | |
25 | ||
26 | ## --- Parse command line arguments / parameters --- | |
27 | ## echo "Commandline options:" | |
ef700f2e | 28 | while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6" option; do |
b64b0d1e JDB |
29 | case $option in |
30 | i) # interface | |
31 | export DEV=$OPTARG | |
32 | info "Output device set to: DEV=$DEV" | |
33 | ;; | |
34 | s) | |
35 | export PKT_SIZE=$OPTARG | |
36 | info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes" | |
37 | ;; | |
38 | d) # destination IP | |
39 | export DEST_IP=$OPTARG | |
40 | info "Destination IP set to: DEST_IP=$DEST_IP" | |
41 | ;; | |
42 | m) # MAC | |
43 | export DST_MAC=$OPTARG | |
44 | info "Destination MAC set to: DST_MAC=$DST_MAC" | |
45 | ;; | |
6e32a74a DL |
46 | p) # PORT |
47 | export DST_PORT=$OPTARG | |
48 | info "Destination PORT set to: DST_PORT=$DST_PORT" | |
49 | ;; | |
e0e16672 TT |
50 | f) |
51 | export F_THREAD=$OPTARG | |
52 | info "Index of first thread (zero indexed CPU number): $F_THREAD" | |
53 | ;; | |
b64b0d1e JDB |
54 | t) |
55 | export THREADS=$OPTARG | |
e0e16672 | 56 | info "Number of threads to start: $THREADS" |
b64b0d1e JDB |
57 | ;; |
58 | c) | |
59 | export CLONE_SKB=$OPTARG | |
60 | info "CLONE_SKB=$CLONE_SKB" | |
61 | ;; | |
69137ea6 TT |
62 | n) |
63 | export COUNT=$OPTARG | |
64 | info "COUNT=$COUNT" | |
65 | ;; | |
b64b0d1e JDB |
66 | b) |
67 | export BURST=$OPTARG | |
68 | info "SKB bursting: BURST=$BURST" | |
69 | ;; | |
ef700f2e IR |
70 | w) |
71 | export DELAY=$OPTARG | |
72 | info "DELAY=$DELAY" | |
73 | ;; | |
b64b0d1e JDB |
74 | v) |
75 | export VERBOSE=yes | |
76 | info "Verbose mode: VERBOSE=$VERBOSE" | |
77 | ;; | |
78 | x) | |
79 | export DEBUG=yes | |
80 | info "Debug mode: DEBUG=$DEBUG" | |
81 | ;; | |
0f06a678 MKL |
82 | 6) |
83 | export IP6=6 | |
84 | info "IP6: IP6=$IP6" | |
85 | ;; | |
b64b0d1e JDB |
86 | h|?|*) |
87 | usage; | |
88 | err 2 "[ERROR] Unknown parameters!!!" | |
89 | esac | |
90 | done | |
91 | shift $(( $OPTIND - 1 )) | |
92 | ||
93 | if [ -z "$PKT_SIZE" ]; then | |
94 | # NIC adds 4 bytes CRC | |
95 | export PKT_SIZE=60 | |
96 | info "Default packet size set to: set to: $PKT_SIZE bytes" | |
97 | fi | |
98 | ||
e0e16672 TT |
99 | if [ -z "$F_THREAD" ]; then |
100 | # First thread (F_THREAD) reference the zero indexed CPU number | |
101 | export F_THREAD=0 | |
102 | fi | |
103 | ||
b64b0d1e | 104 | if [ -z "$THREADS" ]; then |
b64b0d1e JDB |
105 | export THREADS=1 |
106 | fi | |
107 | ||
ef700f2e IR |
108 | # default DELAY |
109 | [ -z "$DELAY" ] && export DELAY=0 # Zero means max speed | |
110 | ||
e0e16672 TT |
111 | export L_THREAD=$(( THREADS + F_THREAD - 1 )) |
112 | ||
b64b0d1e JDB |
113 | if [ -z "$DEV" ]; then |
114 | usage | |
115 | err 2 "Please specify output device" | |
116 | fi | |
117 | ||
118 | if [ -z "$DST_MAC" ]; then | |
119 | warn "Missing destination MAC address" | |
120 | fi | |
121 | ||
122 | if [ -z "$DEST_IP" ]; then | |
123 | warn "Missing destination IP address" | |
124 | fi | |
125 | ||
126 | if [ ! -d /proc/net/pktgen ]; then | |
127 | info "Loading kernel module: pktgen" | |
128 | modprobe pktgen | |
129 | fi |