]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - samples/pktgen/pktgen_sample01_simple.sh
Merge tag 'microblaze-v5.15' of git://git.monstr.eu/linux-2.6-microblaze
[mirror_ubuntu-jammy-kernel.git] / samples / pktgen / pktgen_sample01_simple.sh
CommitLineData
6f094797 1#!/bin/bash
b2441318 2# SPDX-License-Identifier: GPL-2.0
6f094797
JDB
3#
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
0f06a678
MKL
18if [ -z "$DEST_IP" ]; then
19 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
20fi
6f094797
JDB
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"
69137ea6 24[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
40f843ee
DL
25if [ -n "$DEST_IP" ]; then
26 validate_addr${IP6} $DEST_IP
27 read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
28fi
6e32a74a 29if [ -n "$DST_PORT" ]; then
723d2904
DL
30 read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
31 validate_ports $UDP_DST_MIN $UDP_DST_MAX
6e32a74a 32fi
6f094797 33
6f094797 34# Flow variation random source port between min and max
723d2904
DL
35UDP_SRC_MIN=9
36UDP_SRC_MAX=109
6f094797
JDB
37
38# General cleanup everything since last run
39# (especially important if other threads were configured by other scripts)
c8fd4852 40[ -z "$APPEND" ] && pg_ctrl "reset"
6f094797
JDB
41
42# Add remove all other devices and add_device $DEV to thread 0
43thread=0
c8fd4852 44[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
6f094797
JDB
45pg_thread $thread "add_device" $DEV
46
47# How many packets to send (zero means indefinitely)
48pg_set $DEV "count $COUNT"
49
50# Reduce alloc cost by sending same SKB many times
51# - this obviously affects the randomness within the packet
52pg_set $DEV "clone_skb $CLONE_SKB"
53
54# Set packet size
55pg_set $DEV "pkt_size $PKT_SIZE"
56
57# Delay between packets (zero means max speed)
58pg_set $DEV "delay $DELAY"
59
60# Flag example disabling timestamping
61pg_set $DEV "flag NO_TIMESTAMP"
62
63# Destination
64pg_set $DEV "dst_mac $DST_MAC"
40f843ee
DL
65pg_set $DEV "dst${IP6}_min $DST_MIN"
66pg_set $DEV "dst${IP6}_max $DST_MAX"
6f094797 67
6e32a74a
DL
68if [ -n "$DST_PORT" ]; then
69 # Single destination port or random port range
70 pg_set $DEV "flag UDPDST_RND"
723d2904
DL
71 pg_set $DEV "udp_dst_min $UDP_DST_MIN"
72 pg_set $DEV "udp_dst_max $UDP_DST_MAX"
6e32a74a
DL
73fi
74
460a9aa2
LB
75[ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
76
6f094797
JDB
77# Setup random UDP port src range
78pg_set $DEV "flag UDPSRC_RND"
723d2904
DL
79pg_set $DEV "udp_src_min $UDP_SRC_MIN"
80pg_set $DEV "udp_src_max $UDP_SRC_MAX"
6f094797 81
6c882bdc
JK
82# Run if user hits control-c
83function print_result() {
84 # Print results
85 echo "Result device: $DEV"
86 cat /proc/net/pktgen/$DEV
87}
88# trap keyboard interrupt (Ctrl-C)
89trap true SIGINT
90
c8fd4852
IR
91if [ -z "$APPEND" ]; then
92 # start_run
93 echo "Running... ctrl^C to stop" >&2
94 pg_ctrl "start"
95 echo "Done" >&2
6f094797 96
6c882bdc 97 print_result
c8fd4852
IR
98else
99 echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
100fi