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