pktgen_sample01_simple.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Simple example:
  5. # * pktgen sending with single thread and single interface
  6. # * flow variation via random UDP source port
  7. #
  8. basedir=`dirname $0`
  9. source ${basedir}/functions.sh
  10. root_check_run_with_sudo "$@"
  11. # Parameter parsing via include
  12. # - go look in parameters.sh to see which setting are avail
  13. # - required param is the interface "-i" stored in $DEV
  14. source ${basedir}/parameters.sh
  15. #
  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 "$CLONE_SKB" ] && CLONE_SKB="0"
  21. # Example enforce param "-m" for dst_mac
  22. [ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"
  23. [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
  24. # Base Config
  25. DELAY="0" # Zero means max speed
  26. # Flow variation random source port between min and max
  27. UDP_MIN=9
  28. UDP_MAX=109
  29. # General cleanup everything since last run
  30. # (especially important if other threads were configured by other scripts)
  31. pg_ctrl "reset"
  32. # Add remove all other devices and add_device $DEV to thread 0
  33. thread=0
  34. pg_thread $thread "rem_device_all"
  35. pg_thread $thread "add_device" $DEV
  36. # How many packets to send (zero means indefinitely)
  37. pg_set $DEV "count $COUNT"
  38. # Reduce alloc cost by sending same SKB many times
  39. # - this obviously affects the randomness within the packet
  40. pg_set $DEV "clone_skb $CLONE_SKB"
  41. # Set packet size
  42. pg_set $DEV "pkt_size $PKT_SIZE"
  43. # Delay between packets (zero means max speed)
  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. # start_run
  55. echo "Running... ctrl^C to stop" >&2
  56. pg_ctrl "start"
  57. echo "Done" >&2
  58. # Print results
  59. echo "Result device: $DEV"
  60. cat /proc/net/pktgen/$DEV