pktgen_sample04_many_flows.sh 2.5 KB

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