pktgen_sample05_flow_per_thread.sh 2.9 KB

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