parameters.sh 2.9 KB

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