pktgen_sample02_multiqueue.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #
  3. # Multiqueue: Using pktgen threads for sending on multiple CPUs
  4. # * adding devices to kernel threads
  5. # * notice the naming scheme for keeping device names unique
  6. # * nameing scheme: dev@thread_number
  7. # * flow variation via random UDP source port
  8. #
  9. basedir=`dirname $0`
  10. source ${basedir}/functions.sh
  11. root_check_run_with_sudo "$@"
  12. #
  13. # Required param: -i dev in $DEV
  14. source ${basedir}/parameters.sh
  15. # Base Config
  16. DELAY="0" # Zero means max speed
  17. COUNT="100000" # Zero means indefinitely
  18. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  19. # Flow variation random source port between min and max
  20. UDP_MIN=9
  21. UDP_MAX=109
  22. # (example of setting default params in your script)
  23. if [ -z "$DEST_IP" ]; then
  24. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  25. fi
  26. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  27. # General cleanup everything since last run
  28. pg_ctrl "reset"
  29. # Threads are specified with parameter -t value in $THREADS
  30. for ((thread = 0; thread < $THREADS; thread++)); do
  31. # The device name is extended with @name, using thread number to
  32. # make then unique, but any name will do.
  33. dev=${DEV}@${thread}
  34. # Add remove all other devices and add_device $dev to thread
  35. pg_thread $thread "rem_device_all"
  36. pg_thread $thread "add_device" $dev
  37. # Notice config queue to map to cpu (mirrors smp_processor_id())
  38. # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
  39. pg_set $dev "flag QUEUE_MAP_CPU"
  40. # Base config of dev
  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. # Flag example disabling timestamping
  46. pg_set $dev "flag NO_TIMESTAMP"
  47. # Destination
  48. pg_set $dev "dst_mac $DST_MAC"
  49. pg_set $dev "dst$IP6 $DEST_IP"
  50. # Setup random UDP port src range
  51. pg_set $dev "flag UDPSRC_RND"
  52. pg_set $dev "udp_src_min $UDP_MIN"
  53. pg_set $dev "udp_src_max $UDP_MAX"
  54. done
  55. # start_run
  56. echo "Running... ctrl^C to stop" >&2
  57. pg_ctrl "start"
  58. echo "Done" >&2
  59. # Print results
  60. for ((thread = 0; thread < $THREADS; thread++)); do
  61. dev=${DEV}@${thread}
  62. echo "Device: $dev"
  63. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  64. done