linux_dsm_epyc7002/samples/pktgen/pktgen_sample01_simple.sh
Jesper Dangaard Brouer 6f09479758 pktgen: add sample script pktgen_sample01_simple.sh
Add the first basic pktgen samples script pktgen_sample01_simple.sh,
which demonstrates the a simple use of the helper functions.
Removing pktgen.conf-1-1 as that example should be covered now.

The naming scheme pktgen_sampleNN, where NN is a number, should encourage
reading the samples in a specific order.

Script cause pktgen sending with a single thread and single interface,
and introduce flow variation via random UDP source port.

Usage example and help:
 ./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2

Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX
  -i : ($DEV)       output interface/device (required)
  -s : ($PKT_SIZE)  packet size
  -d : ($DEST_IP)   destination IP
  -m : ($DST_MAC)   destination MAC-addr
  -c : ($SKB_CLONE) SKB clones send before alloc new SKB
  -v : ($VERBOSE)   verbose
  -x : ($DEBUG)     debug

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-05-22 23:59:17 -04:00

72 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
#
# Simple example:
# * pktgen sending with single thread and single interface
# * flow variation via random UDP source port
#
basedir=`dirname $0`
source ${basedir}/functions.sh
root_check_run_with_sudo "$@"
# Parameter parsing via include
# - go look in parameters.sh to see which setting are avail
# - required param is the interface "-i" stored in $DEV
source ${basedir}/parameters.sh
#
# Set some default params, if they didn't get set
[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
# Example enforce param "-m" for dst_mac
[ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"
# Base Config
DELAY="0" # Zero means max speed
COUNT="100000" # Zero means indefinitely
# Flow variation random source port between min and max
UDP_MIN=9
UDP_MAX=109
# General cleanup everything since last run
# (especially important if other threads were configured by other scripts)
pg_ctrl "reset"
# Add remove all other devices and add_device $DEV to thread 0
thread=0
pg_thread $thread "rem_device_all"
pg_thread $thread "add_device" $DEV
# How many packets to send (zero means indefinitely)
pg_set $DEV "count $COUNT"
# Reduce alloc cost by sending same SKB many times
# - this obviously affects the randomness within the packet
pg_set $DEV "clone_skb $CLONE_SKB"
# Set packet size
pg_set $DEV "pkt_size $PKT_SIZE"
# Delay between packets (zero means max speed)
pg_set $DEV "delay $DELAY"
# Flag example disabling timestamping
pg_set $DEV "flag NO_TIMESTAMP"
# Destination
pg_set $DEV "dst_mac $DST_MAC"
pg_set $DEV "dst $DEST_IP"
# Setup random UDP port src range
pg_set $DEV "flag UDPSRC_RND"
pg_set $DEV "udp_src_min $UDP_MIN"
pg_set $DEV "udp_src_max $UDP_MAX"
# start_run
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2
# Print results
echo "Result device: $DEV"
cat /proc/net/pktgen/$DEV