parameters.sh 2.5 KB

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