blob: a4e250b45dcead5f9ae8904cd6963d1eb34a9ad5 [file] [log] [blame]
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +02001#!/bin/bash
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +02003#
4# Simple example:
5# * pktgen sending with single thread and single interface
6# * flow variation via random UDP source port
7#
8basedir=`dirname $0`
9source ${basedir}/functions.sh
10root_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
15source ${basedir}/parameters.sh
16#
17# Set some default params, if they didn't get set
Martin KaFai Lau0f06a672016-07-20 15:48:43 -070018if [ -z "$DEST_IP" ]; then
19 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
20fi
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020021[ -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 Toukan69137ea2017-06-15 19:07:21 +030024[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
Daniel T. Lee40f843e2019-10-05 17:25:09 +090025if [ -n "$DEST_IP" ]; then
26 validate_addr${IP6} $DEST_IP
27 read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
28fi
Daniel T. Lee6e32a742019-06-29 22:33:58 +090029if [ -n "$DST_PORT" ]; then
Daniel T. Lee723d2902019-10-05 17:25:06 +090030 read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
31 validate_ports $UDP_DST_MIN $UDP_DST_MAX
Daniel T. Lee6e32a742019-06-29 22:33:58 +090032fi
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020033
34# Base Config
35DELAY="0" # Zero means max speed
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020036
37# Flow variation random source port between min and max
Daniel T. Lee723d2902019-10-05 17:25:06 +090038UDP_SRC_MIN=9
39UDP_SRC_MAX=109
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020040
41# General cleanup everything since last run
42# (especially important if other threads were configured by other scripts)
43pg_ctrl "reset"
44
45# Add remove all other devices and add_device $DEV to thread 0
46thread=0
47pg_thread $thread "rem_device_all"
48pg_thread $thread "add_device" $DEV
49
50# How many packets to send (zero means indefinitely)
51pg_set $DEV "count $COUNT"
52
53# Reduce alloc cost by sending same SKB many times
54# - this obviously affects the randomness within the packet
55pg_set $DEV "clone_skb $CLONE_SKB"
56
57# Set packet size
58pg_set $DEV "pkt_size $PKT_SIZE"
59
60# Delay between packets (zero means max speed)
61pg_set $DEV "delay $DELAY"
62
63# Flag example disabling timestamping
64pg_set $DEV "flag NO_TIMESTAMP"
65
66# Destination
67pg_set $DEV "dst_mac $DST_MAC"
Daniel T. Lee40f843e2019-10-05 17:25:09 +090068pg_set $DEV "dst${IP6}_min $DST_MIN"
69pg_set $DEV "dst${IP6}_max $DST_MAX"
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020070
Daniel T. Lee6e32a742019-06-29 22:33:58 +090071if [ -n "$DST_PORT" ]; then
72 # Single destination port or random port range
73 pg_set $DEV "flag UDPDST_RND"
Daniel T. Lee723d2902019-10-05 17:25:06 +090074 pg_set $DEV "udp_dst_min $UDP_DST_MIN"
75 pg_set $DEV "udp_dst_max $UDP_DST_MAX"
Daniel T. Lee6e32a742019-06-29 22:33:58 +090076fi
77
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020078# Setup random UDP port src range
79pg_set $DEV "flag UDPSRC_RND"
Daniel T. Lee723d2902019-10-05 17:25:06 +090080pg_set $DEV "udp_src_min $UDP_SRC_MIN"
81pg_set $DEV "udp_src_max $UDP_SRC_MAX"
Jesper Dangaard Brouer6f094792015-05-21 12:17:33 +020082
83# start_run
84echo "Running... ctrl^C to stop" >&2
85pg_ctrl "start"
86echo "Done" >&2
87
88# Print results
89echo "Result device: $DEV"
90cat /proc/net/pktgen/$DEV