0001
0002
0003
0004
0005
0006 function usage() {
0007 echo ""
0008 echo "Usage: $0 [-vx] -i ethX"
0009 echo " -i : (\$DEV) output interface/device (required)"
0010 echo " -s : (\$PKT_SIZE) packet size"
0011 echo " -d : (\$DEST_IP) destination IP. CIDR (e.g. 198.18.0.0/15) is also allowed"
0012 echo " -m : (\$DST_MAC) destination MAC-addr"
0013 echo " -p : (\$DST_PORT) destination PORT range (e.g. 433-444) is also allowed"
0014 echo " -k : (\$UDP_CSUM) enable UDP tx checksum"
0015 echo " -t : (\$THREADS) threads to start"
0016 echo " -f : (\$F_THREAD) index of first thread (zero indexed CPU number)"
0017 echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB"
0018 echo " -n : (\$COUNT) num messages to send per thread, 0 means indefinitely"
0019 echo " -b : (\$BURST) HW level bursting of SKBs"
0020 echo " -v : (\$VERBOSE) verbose"
0021 echo " -x : (\$DEBUG) debug"
0022 echo " -6 : (\$IP6) IPv6"
0023 echo " -w : (\$DELAY) Tx Delay value (ns)"
0024 echo " -a : (\$APPEND) Script will not reset generator's state, but will append its config"
0025 echo ""
0026 }
0027
0028
0029
0030 while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6ak" option; do
0031 case $option in
0032 i)
0033 export DEV=$OPTARG
0034 info "Output device set to: DEV=$DEV"
0035 ;;
0036 s)
0037 export PKT_SIZE=$OPTARG
0038 info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes"
0039 ;;
0040 d)
0041 export DEST_IP=$OPTARG
0042 info "Destination IP set to: DEST_IP=$DEST_IP"
0043 ;;
0044 m)
0045 export DST_MAC=$OPTARG
0046 info "Destination MAC set to: DST_MAC=$DST_MAC"
0047 ;;
0048 p)
0049 export DST_PORT=$OPTARG
0050 info "Destination PORT set to: DST_PORT=$DST_PORT"
0051 ;;
0052 f)
0053 export F_THREAD=$OPTARG
0054 info "Index of first thread (zero indexed CPU number): $F_THREAD"
0055 ;;
0056 t)
0057 export THREADS=$OPTARG
0058 info "Number of threads to start: $THREADS"
0059 ;;
0060 c)
0061 export CLONE_SKB=$OPTARG
0062 info "CLONE_SKB=$CLONE_SKB"
0063 ;;
0064 n)
0065 export COUNT=$OPTARG
0066 info "COUNT=$COUNT"
0067 ;;
0068 b)
0069 export BURST=$OPTARG
0070 info "SKB bursting: BURST=$BURST"
0071 ;;
0072 w)
0073 export DELAY=$OPTARG
0074 info "DELAY=$DELAY"
0075 ;;
0076 v)
0077 export VERBOSE=yes
0078 info "Verbose mode: VERBOSE=$VERBOSE"
0079 ;;
0080 x)
0081 export DEBUG=yes
0082 info "Debug mode: DEBUG=$DEBUG"
0083 ;;
0084 6)
0085 export IP6=6
0086 info "IP6: IP6=$IP6"
0087 ;;
0088 a)
0089 export APPEND=yes
0090 info "Append mode: APPEND=$APPEND"
0091 ;;
0092 k)
0093 export UDP_CSUM=yes
0094 info "UDP tx checksum: UDP_CSUM=$UDP_CSUM"
0095 ;;
0096 h|?|*)
0097 usage;
0098 err 2 "[ERROR] Unknown parameters!!!"
0099 esac
0100 done
0101 shift $(( $OPTIND - 1 ))
0102
0103 if [ -z "$PKT_SIZE" ]; then
0104
0105 export PKT_SIZE=60
0106 info "Default packet size set to: set to: $PKT_SIZE bytes"
0107 fi
0108
0109 if [ -z "$F_THREAD" ]; then
0110
0111 export F_THREAD=0
0112 fi
0113
0114 if [ -z "$THREADS" ]; then
0115 export THREADS=1
0116 fi
0117
0118
0119 [ -z "$DELAY" ] && export DELAY=0
0120
0121 export L_THREAD=$(( THREADS + F_THREAD - 1 ))
0122
0123 if [ -z "$DEV" ]; then
0124 usage
0125 err 2 "Please specify output device"
0126 fi
0127
0128 if [ -z "$DST_MAC" ]; then
0129 warn "Missing destination MAC address"
0130 fi
0131
0132 if [ -z "$DEST_IP" ]; then
0133 warn "Missing destination IP address"
0134 fi
0135
0136 if [ ! -d /proc/net/pktgen ]; then
0137 info "Loading kernel module: pktgen"
0138 modprobe pktgen
0139 fi