1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 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 18if [ -z "$DEST_IP" ]; then 19 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1" 20fi 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 25if [ -n "$DST_PORT" ]; then 26 read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT) 27 validate_ports $DST_MIN $DST_MAX 28fi 29 30# Base Config 31DELAY="0" # Zero means max speed 32 33# Flow variation random source port between min and max 34UDP_MIN=9 35UDP_MAX=109 36 37# General cleanup everything since last run 38# (especially important if other threads were configured by other scripts) 39pg_ctrl "reset" 40 41# Add remove all other devices and add_device $DEV to thread 0 42thread=0 43pg_thread $thread "rem_device_all" 44pg_thread $thread "add_device" $DEV 45 46# How many packets to send (zero means indefinitely) 47pg_set $DEV "count $COUNT" 48 49# Reduce alloc cost by sending same SKB many times 50# - this obviously affects the randomness within the packet 51pg_set $DEV "clone_skb $CLONE_SKB" 52 53# Set packet size 54pg_set $DEV "pkt_size $PKT_SIZE" 55 56# Delay between packets (zero means max speed) 57pg_set $DEV "delay $DELAY" 58 59# Flag example disabling timestamping 60pg_set $DEV "flag NO_TIMESTAMP" 61 62# Destination 63pg_set $DEV "dst_mac $DST_MAC" 64pg_set $DEV "dst$IP6 $DEST_IP" 65 66if [ -n "$DST_PORT" ]; then 67 # Single destination port or random port range 68 pg_set $DEV "flag UDPDST_RND" 69 pg_set $DEV "udp_dst_min $DST_MIN" 70 pg_set $DEV "udp_dst_max $DST_MAX" 71fi 72 73# Setup random UDP port src range 74pg_set $DEV "flag UDPSRC_RND" 75pg_set $DEV "udp_src_min $UDP_MIN" 76pg_set $DEV "udp_src_max $UDP_MAX" 77 78# start_run 79echo "Running... ctrl^C to stop" >&2 80pg_ctrl "start" 81echo "Done" >&2 82 83# Print results 84echo "Result device: $DEV" 85cat /proc/net/pktgen/$DEV 86