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