pktgen_sample04_many_flows.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # Base Config
  37. DELAY="0" # Zero means max speed
  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. 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. 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. # Randomize source IP-addresses
  69. pg_set $dev "flag IPSRC_RND"
  70. pg_set $dev "src_min $SRC_MIN"
  71. pg_set $dev "src_max $SRC_MAX"
  72. # Limit number of flows (max 65535)
  73. pg_set $dev "flows $FLOWS"
  74. #
  75. # How many packets a flow will send, before flow "entry" is
  76. # re-generated/setup.
  77. pg_set $dev "flowlen $FLOWLEN"
  78. #
  79. # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
  80. # being send back-to-back, before next flow is selected
  81. # incrementally. This helps lookup caches, and is more realistic.
  82. #
  83. pg_set $dev "flag FLOW_SEQ"
  84. done
  85. # Run if user hits control-c
  86. function print_result() {
  87. # Print results
  88. for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
  89. dev=${DEV}@${thread}
  90. echo "Device: $dev"
  91. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  92. done
  93. }
  94. # trap keyboard interrupt (Ctrl-C)
  95. trap true SIGINT
  96. echo "Running... ctrl^C to stop" >&2
  97. pg_ctrl "start"
  98. print_result