xref: /openbmc/linux/samples/pktgen/parameters.sh (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1b64b0d1eSJesper Dangaard Brouer#
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3b64b0d1eSJesper Dangaard Brouer# Common parameter parsing for pktgen scripts
4b64b0d1eSJesper Dangaard Brouer#
5b64b0d1eSJesper Dangaard Brouer
6b64b0d1eSJesper Dangaard Brouerfunction usage() {
7b64b0d1eSJesper Dangaard Brouer    echo ""
8b64b0d1eSJesper Dangaard Brouer    echo "Usage: $0 [-vx] -i ethX"
9b64b0d1eSJesper Dangaard Brouer    echo "  -i : (\$DEV)       output interface/device (required)"
10b64b0d1eSJesper Dangaard Brouer    echo "  -s : (\$PKT_SIZE)  packet size"
1140f843eeSDaniel T. Lee    echo "  -d : (\$DEST_IP)   destination IP. CIDR (e.g. 198.18.0.0/15) is also allowed"
12b64b0d1eSJesper Dangaard Brouer    echo "  -m : (\$DST_MAC)   destination MAC-addr"
136e32a74aSDaniel T. Lee    echo "  -p : (\$DST_PORT)  destination PORT range (e.g. 433-444) is also allowed"
14*460a9aa2SLorenzo Bianconi    echo "  -k : (\$UDP_CSUM)  enable UDP tx checksum"
15b64b0d1eSJesper Dangaard Brouer    echo "  -t : (\$THREADS)   threads to start"
16e0e16672STariq Toukan    echo "  -f : (\$F_THREAD)  index of first thread (zero indexed CPU number)"
17b64b0d1eSJesper Dangaard Brouer    echo "  -c : (\$SKB_CLONE) SKB clones send before alloc new SKB"
1869137ea6STariq Toukan    echo "  -n : (\$COUNT)     num messages to send per thread, 0 means indefinitely"
19b64b0d1eSJesper Dangaard Brouer    echo "  -b : (\$BURST)     HW level bursting of SKBs"
20b64b0d1eSJesper Dangaard Brouer    echo "  -v : (\$VERBOSE)   verbose"
21b64b0d1eSJesper Dangaard Brouer    echo "  -x : (\$DEBUG)     debug"
220f06a678SMartin KaFai Lau    echo "  -6 : (\$IP6)       IPv6"
23ef700f2eSIgor Russkikh    echo "  -w : (\$DELAY)     Tx Delay value (ns)"
24c8fd4852SIgor Russkikh    echo "  -a : (\$APPEND)    Script will not reset generator's state, but will append its config"
25b64b0d1eSJesper Dangaard Brouer    echo ""
26b64b0d1eSJesper Dangaard Brouer}
27b64b0d1eSJesper Dangaard Brouer
28b64b0d1eSJesper Dangaard Brouer##  --- Parse command line arguments / parameters ---
29b64b0d1eSJesper Dangaard Brouer## echo "Commandline options:"
30*460a9aa2SLorenzo Bianconiwhile getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6ak" option; do
31b64b0d1eSJesper Dangaard Brouer    case $option in
32b64b0d1eSJesper Dangaard Brouer        i) # interface
33b64b0d1eSJesper Dangaard Brouer          export DEV=$OPTARG
34b64b0d1eSJesper Dangaard Brouer	  info "Output device set to: DEV=$DEV"
35b64b0d1eSJesper Dangaard Brouer          ;;
36b64b0d1eSJesper Dangaard Brouer        s)
37b64b0d1eSJesper Dangaard Brouer          export PKT_SIZE=$OPTARG
38b64b0d1eSJesper Dangaard Brouer	  info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes"
39b64b0d1eSJesper Dangaard Brouer          ;;
40b64b0d1eSJesper Dangaard Brouer        d) # destination IP
41b64b0d1eSJesper Dangaard Brouer          export DEST_IP=$OPTARG
42b64b0d1eSJesper Dangaard Brouer	  info "Destination IP set to: DEST_IP=$DEST_IP"
43b64b0d1eSJesper Dangaard Brouer          ;;
44b64b0d1eSJesper Dangaard Brouer        m) # MAC
45b64b0d1eSJesper Dangaard Brouer          export DST_MAC=$OPTARG
46b64b0d1eSJesper Dangaard Brouer	  info "Destination MAC set to: DST_MAC=$DST_MAC"
47b64b0d1eSJesper Dangaard Brouer          ;;
486e32a74aSDaniel T. Lee        p) # PORT
496e32a74aSDaniel T. Lee          export DST_PORT=$OPTARG
506e32a74aSDaniel T. Lee	  info "Destination PORT set to: DST_PORT=$DST_PORT"
516e32a74aSDaniel T. Lee          ;;
52e0e16672STariq Toukan        f)
53e0e16672STariq Toukan	  export F_THREAD=$OPTARG
54e0e16672STariq Toukan	  info "Index of first thread (zero indexed CPU number): $F_THREAD"
55e0e16672STariq Toukan          ;;
56b64b0d1eSJesper Dangaard Brouer        t)
57b64b0d1eSJesper Dangaard Brouer	  export THREADS=$OPTARG
58e0e16672STariq Toukan	  info "Number of threads to start: $THREADS"
59b64b0d1eSJesper Dangaard Brouer          ;;
60b64b0d1eSJesper Dangaard Brouer        c)
61b64b0d1eSJesper Dangaard Brouer	  export CLONE_SKB=$OPTARG
62b64b0d1eSJesper Dangaard Brouer	  info "CLONE_SKB=$CLONE_SKB"
63b64b0d1eSJesper Dangaard Brouer          ;;
6469137ea6STariq Toukan        n)
6569137ea6STariq Toukan	  export COUNT=$OPTARG
6669137ea6STariq Toukan	  info "COUNT=$COUNT"
6769137ea6STariq Toukan          ;;
68b64b0d1eSJesper Dangaard Brouer        b)
69b64b0d1eSJesper Dangaard Brouer	  export BURST=$OPTARG
70b64b0d1eSJesper Dangaard Brouer	  info "SKB bursting: BURST=$BURST"
71b64b0d1eSJesper Dangaard Brouer          ;;
72ef700f2eSIgor Russkikh        w)
73ef700f2eSIgor Russkikh	  export DELAY=$OPTARG
74ef700f2eSIgor Russkikh	  info "DELAY=$DELAY"
75ef700f2eSIgor Russkikh          ;;
76b64b0d1eSJesper Dangaard Brouer        v)
77b64b0d1eSJesper Dangaard Brouer          export VERBOSE=yes
78b64b0d1eSJesper Dangaard Brouer          info "Verbose mode: VERBOSE=$VERBOSE"
79b64b0d1eSJesper Dangaard Brouer          ;;
80b64b0d1eSJesper Dangaard Brouer        x)
81b64b0d1eSJesper Dangaard Brouer          export DEBUG=yes
82b64b0d1eSJesper Dangaard Brouer          info "Debug mode: DEBUG=$DEBUG"
83b64b0d1eSJesper Dangaard Brouer          ;;
840f06a678SMartin KaFai Lau	6)
850f06a678SMartin KaFai Lau	  export IP6=6
860f06a678SMartin KaFai Lau	  info "IP6: IP6=$IP6"
870f06a678SMartin KaFai Lau	  ;;
88c8fd4852SIgor Russkikh        a)
89c8fd4852SIgor Russkikh          export APPEND=yes
90c8fd4852SIgor Russkikh          info "Append mode: APPEND=$APPEND"
91c8fd4852SIgor Russkikh          ;;
92*460a9aa2SLorenzo Bianconi        k)
93*460a9aa2SLorenzo Bianconi          export UDP_CSUM=yes
94*460a9aa2SLorenzo Bianconi          info "UDP tx checksum: UDP_CSUM=$UDP_CSUM"
95*460a9aa2SLorenzo Bianconi          ;;
96b64b0d1eSJesper Dangaard Brouer        h|?|*)
97b64b0d1eSJesper Dangaard Brouer          usage;
98b64b0d1eSJesper Dangaard Brouer          err 2 "[ERROR] Unknown parameters!!!"
99b64b0d1eSJesper Dangaard Brouer    esac
100b64b0d1eSJesper Dangaard Brouerdone
101b64b0d1eSJesper Dangaard Brouershift $(( $OPTIND - 1 ))
102b64b0d1eSJesper Dangaard Brouer
103b64b0d1eSJesper Dangaard Brouerif [ -z "$PKT_SIZE" ]; then
104b64b0d1eSJesper Dangaard Brouer    # NIC adds 4 bytes CRC
105b64b0d1eSJesper Dangaard Brouer    export PKT_SIZE=60
106b64b0d1eSJesper Dangaard Brouer    info "Default packet size set to: set to: $PKT_SIZE bytes"
107b64b0d1eSJesper Dangaard Brouerfi
108b64b0d1eSJesper Dangaard Brouer
109e0e16672STariq Toukanif [ -z "$F_THREAD" ]; then
110e0e16672STariq Toukan    # First thread (F_THREAD) reference the zero indexed CPU number
111e0e16672STariq Toukan    export F_THREAD=0
112e0e16672STariq Toukanfi
113e0e16672STariq Toukan
114b64b0d1eSJesper Dangaard Brouerif [ -z "$THREADS" ]; then
115b64b0d1eSJesper Dangaard Brouer    export THREADS=1
116b64b0d1eSJesper Dangaard Brouerfi
117b64b0d1eSJesper Dangaard Brouer
118ef700f2eSIgor Russkikh# default DELAY
119ef700f2eSIgor Russkikh[ -z "$DELAY" ] && export DELAY=0 # Zero means max speed
120ef700f2eSIgor Russkikh
121e0e16672STariq Toukanexport L_THREAD=$(( THREADS + F_THREAD - 1 ))
122e0e16672STariq Toukan
123b64b0d1eSJesper Dangaard Brouerif [ -z "$DEV" ]; then
124b64b0d1eSJesper Dangaard Brouer    usage
125b64b0d1eSJesper Dangaard Brouer    err 2 "Please specify output device"
126b64b0d1eSJesper Dangaard Brouerfi
127b64b0d1eSJesper Dangaard Brouer
128b64b0d1eSJesper Dangaard Brouerif [ -z "$DST_MAC" ]; then
129b64b0d1eSJesper Dangaard Brouer    warn "Missing destination MAC address"
130b64b0d1eSJesper Dangaard Brouerfi
131b64b0d1eSJesper Dangaard Brouer
132b64b0d1eSJesper Dangaard Brouerif [ -z "$DEST_IP" ]; then
133b64b0d1eSJesper Dangaard Brouer    warn "Missing destination IP address"
134b64b0d1eSJesper Dangaard Brouerfi
135b64b0d1eSJesper Dangaard Brouer
136b64b0d1eSJesper Dangaard Brouerif [ ! -d /proc/net/pktgen ]; then
137b64b0d1eSJesper Dangaard Brouer    info "Loading kernel module: pktgen"
138b64b0d1eSJesper Dangaard Brouer    modprobe pktgen
139b64b0d1eSJesper Dangaard Brouerfi
140