pktgen_sample02_multiqueue.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Multiqueue: Using pktgen threads for sending on multiple CPUs
  5. # * adding devices to kernel threads
  6. # * notice the naming scheme for keeping device names unique
  7. # * nameing scheme: dev@thread_number
  8. # * flow variation via random UDP source port
  9. #
  10. basedir=`dirname $0`
  11. source ${basedir}/functions.sh
  12. root_check_run_with_sudo "$@"
  13. #
  14. # Required param: -i dev in $DEV
  15. source ${basedir}/parameters.sh
  16. [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
  17. # Base Config
  18. DELAY="0" # Zero means max speed
  19. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  20. # Flow variation random source port between min and max
  21. UDP_SRC_MIN=9
  22. UDP_SRC_MAX=109
  23. # (example of setting default params in your script)
  24. if [ -z "$DEST_IP" ]; then
  25. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  26. fi
  27. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  28. if [ -n "$DEST_IP" ]; then
  29. validate_addr${IP6} $DEST_IP
  30. read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
  31. fi
  32. if [ -n "$DST_PORT" ]; then
  33. read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
  34. validate_ports $UDP_DST_MIN $UDP_DST_MAX
  35. fi
  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. # The device name is extended with @name, using thread number to
  41. # make then unique, but any name will do.
  42. dev=${DEV}@${thread}
  43. # Add remove all other devices and add_device $dev to thread
  44. pg_thread $thread "rem_device_all"
  45. pg_thread $thread "add_device" $dev
  46. # Notice config queue to map to cpu (mirrors smp_processor_id())
  47. # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
  48. pg_set $dev "flag QUEUE_MAP_CPU"
  49. # Base config of dev
  50. pg_set $dev "count $COUNT"
  51. pg_set $dev "clone_skb $CLONE_SKB"
  52. pg_set $dev "pkt_size $PKT_SIZE"
  53. pg_set $dev "delay $DELAY"
  54. # Flag example disabling timestamping
  55. pg_set $dev "flag NO_TIMESTAMP"
  56. # 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. # Setup random UDP port src range
  67. pg_set $dev "flag UDPSRC_RND"
  68. pg_set $dev "udp_src_min $UDP_SRC_MIN"
  69. pg_set $dev "udp_src_max $UDP_SRC_MAX"
  70. done
  71. # start_run
  72. echo "Running... ctrl^C to stop" >&2
  73. pg_ctrl "start"
  74. echo "Done" >&2
  75. # Print results
  76. for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
  77. dev=${DEV}@${thread}
  78. echo "Device: $dev"
  79. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  80. done