pktgen_sample01_simple.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. [ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
  17. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  18. # Example enforce param "-m" for dst_mac
  19. [ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"
  20. # Base Config
  21. DELAY="0" # Zero means max speed
  22. COUNT="100000" # Zero means indefinitely
  23. # Flow variation random source port between min and max
  24. UDP_MIN=9
  25. UDP_MAX=109
  26. # General cleanup everything since last run
  27. # (especially important if other threads were configured by other scripts)
  28. pg_ctrl "reset"
  29. # Add remove all other devices and add_device $DEV to thread 0
  30. thread=0
  31. pg_thread $thread "rem_device_all"
  32. pg_thread $thread "add_device" $DEV
  33. # How many packets to send (zero means indefinitely)
  34. pg_set $DEV "count $COUNT"
  35. # Reduce alloc cost by sending same SKB many times
  36. # - this obviously affects the randomness within the packet
  37. pg_set $DEV "clone_skb $CLONE_SKB"
  38. # Set packet size
  39. pg_set $DEV "pkt_size $PKT_SIZE"
  40. # Delay between packets (zero means max speed)
  41. pg_set $DEV "delay $DELAY"
  42. # Flag example disabling timestamping
  43. pg_set $DEV "flag NO_TIMESTAMP"
  44. # Destination
  45. pg_set $DEV "dst_mac $DST_MAC"
  46. pg_set $DEV "dst $DEST_IP"
  47. # Setup random UDP port src range
  48. pg_set $DEV "flag UDPSRC_RND"
  49. pg_set $DEV "udp_src_min $UDP_MIN"
  50. pg_set $DEV "udp_src_max $UDP_MAX"
  51. # start_run
  52. echo "Running... ctrl^C to stop" >&2
  53. pg_ctrl "start"
  54. echo "Done" >&2
  55. # Print results
  56. echo "Result device: $DEV"
  57. cat /proc/net/pktgen/$DEV