Merge tag 'iio-fixes-for-5.8a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23...
[linux/fpc-iii.git] / samples / pktgen / pktgen_sample01_simple.sh
bloba4e250b45dcead5f9ae8904cd6963d1eb34a9ad5
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Simple example:
5 # * pktgen sending with single thread and single interface
6 # * flow variation via random UDP source port
8 basedir=`dirname $0`
9 source ${basedir}/functions.sh
10 root_check_run_with_sudo "$@"
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
17 # Set some default params, if they didn't get set
18 if [ -z "$DEST_IP" ]; then
19 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
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"
24 [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
25 if [ -n "$DEST_IP" ]; then
26 validate_addr${IP6} $DEST_IP
27 read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
29 if [ -n "$DST_PORT" ]; then
30 read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
31 validate_ports $UDP_DST_MIN $UDP_DST_MAX
34 # Base Config
35 DELAY="0" # Zero means max speed
37 # Flow variation random source port between min and max
38 UDP_SRC_MIN=9
39 UDP_SRC_MAX=109
41 # General cleanup everything since last run
42 # (especially important if other threads were configured by other scripts)
43 pg_ctrl "reset"
45 # Add remove all other devices and add_device $DEV to thread 0
46 thread=0
47 pg_thread $thread "rem_device_all"
48 pg_thread $thread "add_device" $DEV
50 # How many packets to send (zero means indefinitely)
51 pg_set $DEV "count $COUNT"
53 # Reduce alloc cost by sending same SKB many times
54 # - this obviously affects the randomness within the packet
55 pg_set $DEV "clone_skb $CLONE_SKB"
57 # Set packet size
58 pg_set $DEV "pkt_size $PKT_SIZE"
60 # Delay between packets (zero means max speed)
61 pg_set $DEV "delay $DELAY"
63 # Flag example disabling timestamping
64 pg_set $DEV "flag NO_TIMESTAMP"
66 # Destination
67 pg_set $DEV "dst_mac $DST_MAC"
68 pg_set $DEV "dst${IP6}_min $DST_MIN"
69 pg_set $DEV "dst${IP6}_max $DST_MAX"
71 if [ -n "$DST_PORT" ]; then
72 # Single destination port or random port range
73 pg_set $DEV "flag UDPDST_RND"
74 pg_set $DEV "udp_dst_min $UDP_DST_MIN"
75 pg_set $DEV "udp_dst_max $UDP_DST_MAX"
78 # Setup random UDP port src range
79 pg_set $DEV "flag UDPSRC_RND"
80 pg_set $DEV "udp_src_min $UDP_SRC_MIN"
81 pg_set $DEV "udp_src_max $UDP_SRC_MAX"
83 # start_run
84 echo "Running... ctrl^C to stop" >&2
85 pg_ctrl "start"
86 echo "Done" >&2
88 # Print results
89 echo "Result device: $DEV"
90 cat /proc/net/pktgen/$DEV