Path: blob/master/samples/pktgen/pktgen_sample01_simple.sh
26278 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Simple example:4# * pktgen sending with single thread and single interface5# * flow variation via random UDP source port6#7basedir=`dirname $0`8source ${basedir}/functions.sh9root_check_run_with_sudo "$@"1011# Parameter parsing via include12# - go look in parameters.sh to see which setting are avail13# - required param is the interface "-i" stored in $DEV14source ${basedir}/parameters.sh1516# Trap EXIT first17trap_exit1819#20# Set some default params, if they didn't get set21if [ -z "$DEST_IP" ]; then22[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"23fi24[ -z "$CLONE_SKB" ] && CLONE_SKB="0"25# Example enforce param "-m" for dst_mac26[ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"27[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely28if [ -n "$DEST_IP" ]; then29validate_addr${IP6} $DEST_IP30read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)31fi32if [ -n "$DST_PORT" ]; then33read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)34validate_ports $UDP_DST_MIN $UDP_DST_MAX35fi3637# Flow variation random source port between min and max38UDP_SRC_MIN=939UDP_SRC_MAX=1094041# General cleanup everything since last run42# (especially important if other threads were configured by other scripts)43[ -z "$APPEND" ] && pg_ctrl "reset"4445# Add remove all other devices and add_device $DEV to thread 046thread=047[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"48pg_thread $thread "add_device" $DEV4950# How many packets to send (zero means indefinitely)51pg_set $DEV "count $COUNT"5253# Reduce alloc cost by sending same SKB many times54# - this obviously affects the randomness within the packet55pg_set $DEV "clone_skb $CLONE_SKB"5657# Set packet size58pg_set $DEV "pkt_size $PKT_SIZE"5960# Delay between packets (zero means max speed)61pg_set $DEV "delay $DELAY"6263# Flag example disabling timestamping64pg_set $DEV "flag NO_TIMESTAMP"6566# Destination67pg_set $DEV "dst_mac $DST_MAC"68pg_set $DEV "dst${IP6}_min $DST_MIN"69pg_set $DEV "dst${IP6}_max $DST_MAX"7071if [ -n "$DST_PORT" ]; then72# Single destination port or random port range73pg_set $DEV "flag UDPDST_RND"74pg_set $DEV "udp_dst_min $UDP_DST_MIN"75pg_set $DEV "udp_dst_max $UDP_DST_MAX"76fi7778[ ! -z "$UDP_CSUM" ] && pg_set $DEV "flag UDPCSUM"7980# Setup random UDP port src range81pg_set $DEV "flag UDPSRC_RND"82pg_set $DEV "udp_src_min $UDP_SRC_MIN"83pg_set $DEV "udp_src_max $UDP_SRC_MAX"8485# Run if user hits control-c86function print_result() {87# Print results88echo "Result device: $DEV"89cat /proc/net/pktgen/$DEV90}91# trap keyboard interrupt (Ctrl-C)92trap true SIGINT9394if [ -z "$APPEND" ]; then95# start_run96echo "Running... ctrl^C to stop" >&297pg_ctrl "start"98echo "Done" >&299100print_result101else102echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"103fi104105