parameters.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 " -t : (\$THREADS) threads to start"
  14. echo " -f : (\$F_THREAD) index of first thread (zero indexed CPU number)"
  15. echo " -c : (\$SKB_CLONE) SKB clones send before alloc new SKB"
  16. echo " -n : (\$COUNT) num messages to send per thread, 0 means indefinitely"
  17. echo " -b : (\$BURST) HW level bursting of SKBs"
  18. echo " -v : (\$VERBOSE) verbose"
  19. echo " -x : (\$DEBUG) debug"
  20. echo " -6 : (\$IP6) IPv6"
  21. echo ""
  22. }
  23. ## --- Parse command line arguments / parameters ---
  24. ## echo "Commandline options:"
  25. while getopts "s:i:d:m:p:f:t:c:n:b:vxh6" option; do
  26. case $option in
  27. i) # interface
  28. export DEV=$OPTARG
  29. info "Output device set to: DEV=$DEV"
  30. ;;
  31. s)
  32. export PKT_SIZE=$OPTARG
  33. info "Packet size set to: PKT_SIZE=$PKT_SIZE bytes"
  34. ;;
  35. d) # destination IP
  36. export DEST_IP=$OPTARG
  37. info "Destination IP set to: DEST_IP=$DEST_IP"
  38. ;;
  39. m) # MAC
  40. export DST_MAC=$OPTARG
  41. info "Destination MAC set to: DST_MAC=$DST_MAC"
  42. ;;
  43. p) # PORT
  44. export DST_PORT=$OPTARG
  45. info "Destination PORT set to: DST_PORT=$DST_PORT"
  46. ;;
  47. f)
  48. export F_THREAD=$OPTARG
  49. info "Index of first thread (zero indexed CPU number): $F_THREAD"
  50. ;;
  51. t)
  52. export THREADS=$OPTARG
  53. info "Number of threads to start: $THREADS"
  54. ;;
  55. c)
  56. export CLONE_SKB=$OPTARG
  57. info "CLONE_SKB=$CLONE_SKB"
  58. ;;
  59. n)
  60. export COUNT=$OPTARG
  61. info "COUNT=$COUNT"
  62. ;;
  63. b)
  64. export BURST=$OPTARG
  65. info "SKB bursting: BURST=$BURST"
  66. ;;
  67. v)
  68. export VERBOSE=yes
  69. info "Verbose mode: VERBOSE=$VERBOSE"
  70. ;;
  71. x)
  72. export DEBUG=yes
  73. info "Debug mode: DEBUG=$DEBUG"
  74. ;;
  75. 6)
  76. export IP6=6
  77. info "IP6: IP6=$IP6"
  78. ;;
  79. h|?|*)
  80. usage;
  81. err 2 "[ERROR] Unknown parameters!!!"
  82. esac
  83. done
  84. shift $(( $OPTIND - 1 ))
  85. if [ -z "$PKT_SIZE" ]; then
  86. # NIC adds 4 bytes CRC
  87. export PKT_SIZE=60
  88. info "Default packet size set to: set to: $PKT_SIZE bytes"
  89. fi
  90. if [ -z "$F_THREAD" ]; then
  91. # First thread (F_THREAD) reference the zero indexed CPU number
  92. export F_THREAD=0
  93. fi
  94. if [ -z "$THREADS" ]; then
  95. export THREADS=1
  96. fi
  97. export L_THREAD=$(( THREADS + F_THREAD - 1 ))
  98. if [ -z "$DEV" ]; then
  99. usage
  100. err 2 "Please specify output device"
  101. fi
  102. if [ -z "$DST_MAC" ]; then
  103. warn "Missing destination MAC address"
  104. fi
  105. if [ -z "$DEST_IP" ]; then
  106. warn "Missing destination IP address"
  107. fi
  108. if [ ! -d /proc/net/pktgen ]; then
  109. info "Loading kernel module: pktgen"
  110. modprobe pktgen
  111. fi