pktgen_sample04_many_flows.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if [ -z "$DEST_IP" ]; then
  16. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  17. fi
  18. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  19. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  20. [ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely
  21. if [ -n "$DEST_IP" ]; then
  22. validate_addr${IP6} $DEST_IP
  23. read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
  24. fi
  25. if [ -n "$DST_PORT" ]; then
  26. read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
  27. validate_ports $UDP_DST_MIN $UDP_DST_MAX
  28. fi
  29. # NOTICE: Script specific settings
  30. # =======
  31. # Limiting the number of concurrent flows ($FLOWS)
  32. # and also set how many packets each flow contains ($FLOWLEN)
  33. #
  34. [ -z "$FLOWS" ] && FLOWS="8000"
  35. [ -z "$FLOWLEN" ] && FLOWLEN="10"
  36. if [[ -n "$BURST" ]]; then
  37. err 1 "Bursting not supported for this mode"
  38. fi
  39. # 198.18.0.0 / 198.19.255.255
  40. read -r SRC_MIN SRC_MAX <<< $(parse_addr 198.18.0.0/15)
  41. # General cleanup everything since last run
  42. [ -z "$APPEND" ] && pg_ctrl "reset"
  43. # Threads are specified with parameter -t value in $THREADS
  44. for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
  45. dev=${DEV}@${thread}
  46. # Add remove all other devices and add_device $dev to thread
  47. [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
  48. pg_thread $thread "add_device" $dev
  49. # Base config
  50. pg_set $dev "flag QUEUE_MAP_CPU"
  51. pg_set $dev "count $COUNT"
  52. pg_set $dev "clone_skb $CLONE_SKB"
  53. pg_set $dev "pkt_size $PKT_SIZE"
  54. pg_set $dev "delay $DELAY"
  55. pg_set $dev "flag NO_TIMESTAMP"
  56. # Single destination
  57. pg_set $dev "dst_mac $DST_MAC"
  58. pg_set $dev "dst${IP6}_min $DST_MIN"
  59. pg_set $dev "dst${IP6}_max $DST_MAX"
  60. if [ -n "$DST_PORT" ]; then
  61. # Single destination port or random port range
  62. pg_set $dev "flag UDPDST_RND"
  63. pg_set $dev "udp_dst_min $UDP_DST_MIN"
  64. pg_set $dev "udp_dst_max $UDP_DST_MAX"
  65. fi
  66. [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
  67. # Randomize source IP-addresses
  68. pg_set $dev "flag IPSRC_RND"
  69. pg_set $dev "src_min $SRC_MIN"
  70. pg_set $dev "src_max $SRC_MAX"
  71. # Limit number of flows (max 65535)
  72. pg_set $dev "flows $FLOWS"
  73. #
  74. # How many packets a flow will send, before flow "entry" is
  75. # re-generated/setup.
  76. pg_set $dev "flowlen $FLOWLEN"
  77. #
  78. # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
  79. # being send back-to-back, before next flow is selected
  80. # incrementally. This helps lookup caches, and is more realistic.
  81. #
  82. pg_set $dev "flag FLOW_SEQ"
  83. done
  84. # Run if user hits control-c
  85. function print_result() {
  86. # Print results
  87. for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
  88. dev=${DEV}@${thread}
  89. echo "Device: $dev"
  90. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  91. done
  92. }
  93. # trap keyboard interrupt (Ctrl-C)
  94. trap true SIGINT
  95. if [ -z "$APPEND" ]; then
  96. echo "Running... ctrl^C to stop" >&2
  97. pg_ctrl "start"
  98. print_result
  99. else
  100. echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
  101. fi