pktgen_sample01_simple.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. #
  3. # Simple example:
  4. # * pktgen sending with single thread and single interface
  5. # * flow variation via random UDP source port
  6. #
  7. basedir=`dirname $0`
  8. source ${basedir}/functions.sh
  9. root_check_run_with_sudo "$@"
  10. # Parameter parsing via include
  11. # - go look in parameters.sh to see which setting are avail
  12. # - required param is the interface "-i" stored in $DEV
  13. source ${basedir}/parameters.sh
  14. #
  15. # Set some default params, if they didn't get set
  16. if [ -z "$DEST_IP" ]; then
  17. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  18. fi
  19. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  20. # Example enforce param "-m" for dst_mac
  21. [ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"
  22. # Base Config
  23. DELAY="0" # Zero means max speed
  24. COUNT="100000" # Zero means indefinitely
  25. # Flow variation random source port between min and max
  26. UDP_MIN=9
  27. UDP_MAX=109
  28. # General cleanup everything since last run
  29. # (especially important if other threads were configured by other scripts)
  30. pg_ctrl "reset"
  31. # Add remove all other devices and add_device $DEV to thread 0
  32. thread=0
  33. pg_thread $thread "rem_device_all"
  34. pg_thread $thread "add_device" $DEV
  35. # How many packets to send (zero means indefinitely)
  36. pg_set $DEV "count $COUNT"
  37. # Reduce alloc cost by sending same SKB many times
  38. # - this obviously affects the randomness within the packet
  39. pg_set $DEV "clone_skb $CLONE_SKB"
  40. # Set packet size
  41. pg_set $DEV "pkt_size $PKT_SIZE"
  42. # Delay between packets (zero means max speed)
  43. pg_set $DEV "delay $DELAY"
  44. # Flag example disabling timestamping
  45. pg_set $DEV "flag NO_TIMESTAMP"
  46. # Destination
  47. pg_set $DEV "dst_mac $DST_MAC"
  48. pg_set $DEV "dst$IP6 $DEST_IP"
  49. # Setup random UDP port src range
  50. pg_set $DEV "flag UDPSRC_RND"
  51. pg_set $DEV "udp_src_min $UDP_MIN"
  52. pg_set $DEV "udp_src_max $UDP_MAX"
  53. # start_run
  54. echo "Running... ctrl^C to stop" >&2
  55. pg_ctrl "start"
  56. echo "Done" >&2
  57. # Print results
  58. echo "Result device: $DEV"
  59. cat /proc/net/pktgen/$DEV