Linux Audio

Check our new training course

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