pktgen_sample05_flow_per_thread.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. #
  3. # Script will generate one flow per thread (-t N)
  4. # - Same destination IP
  5. # - Fake source IPs for each flow (fixed based on thread number)
  6. #
  7. # Useful for scale testing on receiver, to see whether silo'ing flows
  8. # works and scales. For optimal scalability (on receiver) each
  9. # separate-flow should not access shared variables/data. This script
  10. # helps magnify any of these scaling issues by overloading the receiver.
  11. #
  12. basedir=`dirname $0`
  13. source ${basedir}/functions.sh
  14. root_check_run_with_sudo "$@"
  15. # Parameter parsing via include
  16. source ${basedir}/parameters.sh
  17. # Set some default params, if they didn't get set
  18. [ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
  19. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  20. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  21. [ -z "$BURST" ] && BURST=32
  22. # Base Config
  23. DELAY="0" # Zero means max speed
  24. COUNT="0" # Zero means indefinitely
  25. # General cleanup everything since last run
  26. pg_ctrl "reset"
  27. # Threads are specified with parameter -t value in $THREADS
  28. for ((thread = 0; thread < $THREADS; thread++)); do
  29. dev=${DEV}@${thread}
  30. # Add remove all other devices and add_device $dev to thread
  31. pg_thread $thread "rem_device_all"
  32. pg_thread $thread "add_device" $dev
  33. # Base config
  34. pg_set $dev "flag QUEUE_MAP_CPU"
  35. pg_set $dev "count $COUNT"
  36. pg_set $dev "clone_skb $CLONE_SKB"
  37. pg_set $dev "pkt_size $PKT_SIZE"
  38. pg_set $dev "delay $DELAY"
  39. pg_set $dev "flag NO_TIMESTAMP"
  40. # Single destination
  41. pg_set $dev "dst_mac $DST_MAC"
  42. pg_set $dev "dst $DEST_IP"
  43. # Setup source IP-addresses based on thread number
  44. pg_set $dev "src_min 198.18.$((thread+1)).1"
  45. pg_set $dev "src_max 198.18.$((thread+1)).1"
  46. # Setup burst, for easy testing -b 0 disable bursting
  47. # (internally in pktgen default and minimum burst=1)
  48. if [[ ${BURST} -ne 0 ]]; then
  49. pg_set $dev "burst $BURST"
  50. else
  51. info "$dev: Not using burst"
  52. fi
  53. done
  54. # Run if user hits control-c
  55. function print_result() {
  56. # Print results
  57. for ((thread = 0; thread < $THREADS; thread++)); do
  58. dev=${DEV}@${thread}
  59. echo "Device: $dev"
  60. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  61. done
  62. }
  63. # trap keyboard interrupt (Ctrl-C)
  64. trap true SIGINT
  65. echo "Running... ctrl^C to stop" >&2
  66. pg_ctrl "start"
  67. print_result