pktgen_sample04_many_flows.sh 3.4 KB

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