parameters.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Common parameter parsing for pktgen scripts
  4. #
  5. function 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. CIDR (e.g. 198.18.0.0/15) is also allowed"
  11. echo " -m : (\$DST_MAC) destination MAC-addr"
  12. echo " -p : (\$DST_PORT) destination PORT range (e.g. 433-444) is also allowed"
  13. echo " -k : (\$UDP_CSUM) enable UDP tx checksum"
  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. ## --- Parse command line arguments / parameters ---
  27. ## echo "Commandline options:"
  28. while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6ak" option; do
  29. case $option in
  30. i) # interface
  31. export DEV=$OPTARG
  32. info "Output device set to: DEV=$DEV"
  33. ;;
  34. s)
  35. export PKT_SIZE=$OPTARG
  36. info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes"
  37. ;;
  38. d) # destination IP
  39. export DEST_IP=$OPTARG
  40. info "Destination IP set to: DEST_IP=$DEST_IP"
  41. ;;
  42. m) # MAC
  43. export DST_MAC=$OPTARG
  44. info "Destination MAC set to: DST_MAC=$DST_MAC"
  45. ;;
  46. p) # PORT
  47. export DST_PORT=$OPTARG
  48. info "Destination PORT set to: DST_PORT=$DST_PORT"
  49. ;;
  50. f)
  51. export F_THREAD=$OPTARG
  52. info "Index of first thread (zero indexed CPU number): $F_THREAD"
  53. ;;
  54. t)
  55. export THREADS=$OPTARG
  56. info "Number of threads to start: $THREADS"
  57. ;;
  58. c)
  59. export CLONE_SKB=$OPTARG
  60. info "CLONE_SKB=$CLONE_SKB"
  61. ;;
  62. n)
  63. export COUNT=$OPTARG
  64. info "COUNT=$COUNT"
  65. ;;
  66. b)
  67. export BURST=$OPTARG
  68. info "SKB bursting: BURST=$BURST"
  69. ;;
  70. w)
  71. export DELAY=$OPTARG
  72. info "DELAY=$DELAY"
  73. ;;
  74. v)
  75. export VERBOSE=yes
  76. info "Verbose mode: VERBOSE=$VERBOSE"
  77. ;;
  78. x)
  79. export DEBUG=yes
  80. info "Debug mode: DEBUG=$DEBUG"
  81. ;;
  82. 6)
  83. export IP6=6
  84. info "IP6: IP6=$IP6"
  85. ;;
  86. a)
  87. export APPEND=yes
  88. info "Append mode: APPEND=$APPEND"
  89. ;;
  90. k)
  91. export UDP_CSUM=yes
  92. info "UDP tx checksum: UDP_CSUM=$UDP_CSUM"
  93. ;;
  94. h|?|*)
  95. usage;
  96. err 2 "[ERROR] Unknown parameters!!!"
  97. esac
  98. done
  99. shift $(( $OPTIND - 1 ))
  100. if [ -z "$PKT_SIZE" ]; then
  101. # NIC adds 4 bytes CRC
  102. export PKT_SIZE=60
  103. info "Default packet size set to: set to: $PKT_SIZE bytes"
  104. fi
  105. if [ -z "$F_THREAD" ]; then
  106. # First thread (F_THREAD) reference the zero indexed CPU number
  107. export F_THREAD=0
  108. fi
  109. if [ -z "$THREADS" ]; then
  110. export THREADS=1
  111. fi
  112. # default DELAY
  113. [ -z "$DELAY" ] && export DELAY=0 # Zero means max speed
  114. export L_THREAD=$(( THREADS + F_THREAD - 1 ))
  115. if [ -z "$DEV" ]; then
  116. usage
  117. err 2 "Please specify output device"
  118. fi
  119. if [ -z "$DST_MAC" ]; then
  120. warn "Missing destination MAC address"
  121. fi
  122. if [ -z "$DEST_IP" ]; then
  123. warn "Missing destination IP address"
  124. fi
  125. if [ ! -d /proc/net/pktgen ]; then
  126. info "Loading kernel module: pktgen"
  127. modprobe pktgen
  128. fi