parameters.sh 2.9 KB

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