pktgen_sample04_many_flows.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. #
  3. # Script example for many flows testing
  4. #
  5. # Number of simultaneous flows limited by variable $FLOWS
  6. # and number of packets per flow controlled by variable $FLOWLEN
  7. #
  8. basedir=`dirname $0`
  9. source ${basedir}/functions.sh
  10. root_check_run_with_sudo "$@"
  11. # Parameter parsing via include
  12. source ${basedir}/parameters.sh
  13. # Set some default params, if they didn't get set
  14. [ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
  15. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  16. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  17. # NOTICE: Script specific settings
  18. # =======
  19. # Limiting the number of concurrent flows ($FLOWS)
  20. # and also set how many packets each flow contains ($FLOWLEN)
  21. #
  22. [ -z "$FLOWS" ] && FLOWS="8000"
  23. [ -z "$FLOWLEN" ] && FLOWLEN="10"
  24. # Base Config
  25. DELAY="0" # Zero means max speed
  26. COUNT="0" # Zero means indefinitely
  27. if [[ -n "$BURST" ]]; then
  28. err 1 "Bursting not supported for this mode"
  29. fi
  30. # General cleanup everything since last run
  31. pg_ctrl "reset"
  32. # Threads are specified with parameter -t value in $THREADS
  33. for ((thread = 0; thread < $THREADS; thread++)); do
  34. dev=${DEV}@${thread}
  35. # Add remove all other devices and add_device $dev to thread
  36. pg_thread $thread "rem_device_all"
  37. pg_thread $thread "add_device" $dev
  38. # Base config
  39. pg_set $dev "flag QUEUE_MAP_CPU"
  40. pg_set $dev "count $COUNT"
  41. pg_set $dev "clone_skb $CLONE_SKB"
  42. pg_set $dev "pkt_size $PKT_SIZE"
  43. pg_set $dev "delay $DELAY"
  44. pg_set $dev "flag NO_TIMESTAMP"
  45. # Single destination
  46. pg_set $dev "dst_mac $DST_MAC"
  47. pg_set $dev "dst $DEST_IP"
  48. # Randomize source IP-addresses
  49. pg_set $dev "flag IPSRC_RND"
  50. pg_set $dev "src_min 198.18.0.0"
  51. pg_set $dev "src_max 198.19.255.255"
  52. # Limit number of flows (max 65535)
  53. pg_set $dev "flows $FLOWS"
  54. #
  55. # How many packets a flow will send, before flow "entry" is
  56. # re-generated/setup.
  57. pg_set $dev "flowlen $FLOWLEN"
  58. #
  59. # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
  60. # being send back-to-back, before next flow is selected
  61. # incrementally. This helps lookup caches, and is more realistic.
  62. #
  63. pg_set $dev "flag FLOW_SEQ"
  64. done
  65. # Run if user hits control-c
  66. function print_result() {
  67. # Print results
  68. for ((thread = 0; thread < $THREADS; thread++)); do
  69. dev=${DEV}@${thread}
  70. echo "Device: $dev"
  71. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  72. done
  73. }
  74. # trap keyboard interrupt (Ctrl-C)
  75. trap true SIGINT
  76. echo "Running... ctrl^C to stop" >&2
  77. pg_ctrl "start"
  78. print_result