Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 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 | |
| 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 |
Martin KaFai Lau | 0f06a67 | 2016-07-20 15:48:43 -0700 | [diff] [blame] | 17 | if [ -z "$DEST_IP" ]; then |
| 18 | [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1" |
| 19 | fi |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 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 | |
| 24 | # Base Config |
| 25 | DELAY="0" # Zero means max speed |
| 26 | COUNT="100000" # Zero means indefinitely |
| 27 | |
| 28 | # Flow variation random source port between min and max |
| 29 | UDP_MIN=9 |
| 30 | UDP_MAX=109 |
| 31 | |
| 32 | # General cleanup everything since last run |
| 33 | # (especially important if other threads were configured by other scripts) |
| 34 | pg_ctrl "reset" |
| 35 | |
| 36 | # Add remove all other devices and add_device $DEV to thread 0 |
| 37 | thread=0 |
| 38 | pg_thread $thread "rem_device_all" |
| 39 | pg_thread $thread "add_device" $DEV |
| 40 | |
| 41 | # How many packets to send (zero means indefinitely) |
| 42 | pg_set $DEV "count $COUNT" |
| 43 | |
| 44 | # Reduce alloc cost by sending same SKB many times |
| 45 | # - this obviously affects the randomness within the packet |
| 46 | pg_set $DEV "clone_skb $CLONE_SKB" |
| 47 | |
| 48 | # Set packet size |
| 49 | pg_set $DEV "pkt_size $PKT_SIZE" |
| 50 | |
| 51 | # Delay between packets (zero means max speed) |
| 52 | pg_set $DEV "delay $DELAY" |
| 53 | |
| 54 | # Flag example disabling timestamping |
| 55 | pg_set $DEV "flag NO_TIMESTAMP" |
| 56 | |
| 57 | # Destination |
| 58 | pg_set $DEV "dst_mac $DST_MAC" |
Martin KaFai Lau | 0f06a67 | 2016-07-20 15:48:43 -0700 | [diff] [blame] | 59 | pg_set $DEV "dst$IP6 $DEST_IP" |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 60 | |
| 61 | # Setup random UDP port src range |
| 62 | pg_set $DEV "flag UDPSRC_RND" |
| 63 | pg_set $DEV "udp_src_min $UDP_MIN" |
| 64 | pg_set $DEV "udp_src_max $UDP_MAX" |
| 65 | |
| 66 | # start_run |
| 67 | echo "Running... ctrl^C to stop" >&2 |
| 68 | pg_ctrl "start" |
| 69 | echo "Done" >&2 |
| 70 | |
| 71 | # Print results |
| 72 | echo "Result device: $DEV" |
| 73 | cat /proc/net/pktgen/$DEV |