]>
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" | |
11 | echo " -d : (\$DEST_IP) destination IP" | |
12 | echo " -m : (\$DST_MAC) destination MAC-addr" | |
13 | echo " -t : (\$THREADS) threads to start" | |
e0e16672 | 14 | echo " -f : (\$F_THREAD) index of first thread (zero indexed CPU number)" |
b64b0d1e | 15 | echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB" |
69137ea6 | 16 | echo " -n : (\$COUNT) num messages to send per thread, 0 means indefinitely" |
b64b0d1e JDB |
17 | echo " -b : (\$BURST) HW level bursting of SKBs" |
18 | echo " -v : (\$VERBOSE) verbose" | |
19 | echo " -x : (\$DEBUG) debug" | |
0f06a678 | 20 | echo " -6 : (\$IP6) IPv6" |
b64b0d1e JDB |
21 | echo "" |
22 | } | |
23 | ||
24 | ## --- Parse command line arguments / parameters --- | |
25 | ## echo "Commandline options:" | |
e0e16672 | 26 | while getopts "s:i:d:m:f:t:c:n:b:vxh6" option; do |
b64b0d1e JDB |
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 | ;; | |
e0e16672 TT |
44 | f) |
45 | export F_THREAD=$OPTARG | |
46 | info "Index of first thread (zero indexed CPU number): $F_THREAD" | |
47 | ;; | |
b64b0d1e JDB |
48 | t) |
49 | export THREADS=$OPTARG | |
e0e16672 | 50 | info "Number of threads to start: $THREADS" |
b64b0d1e JDB |
51 | ;; |
52 | c) | |
53 | export CLONE_SKB=$OPTARG | |
54 | info "CLONE_SKB=$CLONE_SKB" | |
55 | ;; | |
69137ea6 TT |
56 | n) |
57 | export COUNT=$OPTARG | |
58 | info "COUNT=$COUNT" | |
59 | ;; | |
b64b0d1e JDB |
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 | ;; | |
0f06a678 MKL |
72 | 6) |
73 | export IP6=6 | |
74 | info "IP6: IP6=$IP6" | |
75 | ;; | |
b64b0d1e JDB |
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 | ||
e0e16672 TT |
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 | ||
b64b0d1e | 94 | if [ -z "$THREADS" ]; then |
b64b0d1e JDB |
95 | export THREADS=1 |
96 | fi | |
97 | ||
e0e16672 TT |
98 | export L_THREAD=$(( THREADS + F_THREAD - 1 )) |
99 | ||
b64b0d1e JDB |
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 |