# # Common parameter parsing for pktgen scripts # proc usage { echo "" echo "Usage: $0 [-vx] -i ethX" echo " -i : (\$DEV) output interface/device (required)" echo " -s : (\$PKT_SIZE) packet size" echo " -d : (\$DEST_IP) destination IP" echo " -m : (\$DST_MAC) destination MAC-addr" echo " -t : (\$THREADS) threads to start" echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB" echo " -b : (\$BURST) HW level bursting of SKBs" echo " -v : (\$VERBOSE) verbose" echo " -x : (\$DEBUG) debug" echo " -6 : (\$IP6) IPv6" echo "" } ## --- Parse command line arguments / parameters --- ## echo "Commandline options:" while getopts "s:i:d:m:t:c:b:vxh6" option { match $option { with i # interface export DEV=$OPTARG info "Output device set to: DEV=$DEV" with s export PKT_SIZE=$OPTARG info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes" with d # destination IP export DEST_IP=$OPTARG info "Destination IP set to: DEST_IP=$DEST_IP" with m # MAC export DST_MAC=$OPTARG info "Destination MAC set to: DST_MAC=$DST_MAC" with t export THREADS=$OPTARG export CPU_THREADS=$OPTARG let "CPU_THREADS -= 1" info "Number of threads to start: $THREADS (0 to $CPU_THREADS)" with c export CLONE_SKB=$OPTARG info "CLONE_SKB=$CLONE_SKB" with b export BURST=$OPTARG info "SKB bursting: BURST=$BURST" with v export VERBOSE=yes info "Verbose mode: VERBOSE=$VERBOSE" with x export DEBUG=yes info "Debug mode: DEBUG=$DEBUG" with 6 export IP6=6 info "IP6: IP6=$IP6" with h|?|* usage; err 2 "[ERROR] Unknown parameters!!!" } } shift $shExpr(' $OPTIND - 1 ') if test -z $PKT_SIZE { # NIC adds 4 bytes CRC export PKT_SIZE=60 info "Default packet size set to: set to: $PKT_SIZE bytes" } if test -z $THREADS { # Zero CPU threads means one thread, because CPU numbers are zero indexed export CPU_THREADS=0 export THREADS=1 } if test -z $DEV { usage err 2 "Please specify output device" } if test -z $DST_MAC { warn "Missing destination MAC address" } if test -z $DEST_IP { warn "Missing destination IP address" } if test ! -d /proc/net/pktgen { info "Loading kernel module: pktgen" modprobe pktgen }