parameters.sh 2.4 KB

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