Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 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 | |
| 12 | # Parameter parsing via include |
| 13 | # - go look in parameters.sh to see which setting are avail |
| 14 | # - required param is the interface "-i" stored in $DEV |
| 15 | source ${basedir}/parameters.sh |
| 16 | # |
| 17 | # Set some default params, if they didn't get set |
Martin KaFai Lau | 0f06a67 | 2016-07-20 15:48:43 -0700 | [diff] [blame] | 18 | if [ -z "$DEST_IP" ]; then |
| 19 | [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1" |
| 20 | fi |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 21 | [ -z "$CLONE_SKB" ] && CLONE_SKB="0" |
| 22 | # Example enforce param "-m" for dst_mac |
| 23 | [ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac" |
Tariq Toukan | 69137ea | 2017-06-15 19:07:21 +0300 | [diff] [blame] | 24 | [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely |
Daniel T. Lee | 40f843e | 2019-10-05 17:25:09 +0900 | [diff] [blame] | 25 | if [ -n "$DEST_IP" ]; then |
| 26 | validate_addr${IP6} $DEST_IP |
| 27 | read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP) |
| 28 | fi |
Daniel T. Lee | 6e32a74 | 2019-06-29 22:33:58 +0900 | [diff] [blame] | 29 | if [ -n "$DST_PORT" ]; then |
Daniel T. Lee | 723d290 | 2019-10-05 17:25:06 +0900 | [diff] [blame] | 30 | read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT) |
| 31 | validate_ports $UDP_DST_MIN $UDP_DST_MAX |
Daniel T. Lee | 6e32a74 | 2019-06-29 22:33:58 +0900 | [diff] [blame] | 32 | fi |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 33 | |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 34 | # Flow variation random source port between min and max |
Daniel T. Lee | 723d290 | 2019-10-05 17:25:06 +0900 | [diff] [blame] | 35 | UDP_SRC_MIN=9 |
| 36 | UDP_SRC_MAX=109 |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 37 | |
| 38 | # General cleanup everything since last run |
| 39 | # (especially important if other threads were configured by other scripts) |
Igor Russkikh | c8fd485 | 2021-03-11 11:32:53 +0100 | [diff] [blame] | 40 | [ -z "$APPEND" ] && pg_ctrl "reset" |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 41 | |
| 42 | # Add remove all other devices and add_device $DEV to thread 0 |
| 43 | thread=0 |
Igor Russkikh | c8fd485 | 2021-03-11 11:32:53 +0100 | [diff] [blame] | 44 | [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 45 | pg_thread $thread "add_device" $DEV |
| 46 | |
| 47 | # How many packets to send (zero means indefinitely) |
| 48 | pg_set $DEV "count $COUNT" |
| 49 | |
| 50 | # Reduce alloc cost by sending same SKB many times |
| 51 | # - this obviously affects the randomness within the packet |
| 52 | pg_set $DEV "clone_skb $CLONE_SKB" |
| 53 | |
| 54 | # Set packet size |
| 55 | pg_set $DEV "pkt_size $PKT_SIZE" |
| 56 | |
| 57 | # Delay between packets (zero means max speed) |
| 58 | pg_set $DEV "delay $DELAY" |
| 59 | |
| 60 | # Flag example disabling timestamping |
| 61 | pg_set $DEV "flag NO_TIMESTAMP" |
| 62 | |
| 63 | # Destination |
| 64 | pg_set $DEV "dst_mac $DST_MAC" |
Daniel T. Lee | 40f843e | 2019-10-05 17:25:09 +0900 | [diff] [blame] | 65 | pg_set $DEV "dst${IP6}_min $DST_MIN" |
| 66 | pg_set $DEV "dst${IP6}_max $DST_MAX" |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 67 | |
Daniel T. Lee | 6e32a74 | 2019-06-29 22:33:58 +0900 | [diff] [blame] | 68 | if [ -n "$DST_PORT" ]; then |
| 69 | # Single destination port or random port range |
| 70 | pg_set $DEV "flag UDPDST_RND" |
Daniel T. Lee | 723d290 | 2019-10-05 17:25:06 +0900 | [diff] [blame] | 71 | pg_set $DEV "udp_dst_min $UDP_DST_MIN" |
| 72 | pg_set $DEV "udp_dst_max $UDP_DST_MAX" |
Daniel T. Lee | 6e32a74 | 2019-06-29 22:33:58 +0900 | [diff] [blame] | 73 | fi |
| 74 | |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 75 | # Setup random UDP port src range |
| 76 | pg_set $DEV "flag UDPSRC_RND" |
Daniel T. Lee | 723d290 | 2019-10-05 17:25:06 +0900 | [diff] [blame] | 77 | pg_set $DEV "udp_src_min $UDP_SRC_MIN" |
| 78 | pg_set $DEV "udp_src_max $UDP_SRC_MAX" |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 79 | |
Igor Russkikh | c8fd485 | 2021-03-11 11:32:53 +0100 | [diff] [blame] | 80 | if [ -z "$APPEND" ]; then |
| 81 | # start_run |
| 82 | echo "Running... ctrl^C to stop" >&2 |
| 83 | pg_ctrl "start" |
| 84 | echo "Done" >&2 |
Jesper Dangaard Brouer | 6f09479 | 2015-05-21 12:17:33 +0200 | [diff] [blame] | 85 | |
Igor Russkikh | c8fd485 | 2021-03-11 11:32:53 +0100 | [diff] [blame] | 86 | # Print results |
| 87 | echo "Result device: $DEV" |
| 88 | cat /proc/net/pktgen/$DEV |
| 89 | else |
| 90 | echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" |
| 91 | fi |