Path: blob/master/samples/pktgen/pktgen_sample04_many_flows.sh
26278 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Script example for many flows testing4#5# Number of simultaneous flows limited by variable $FLOWS6# and number of packets per flow controlled by variable $FLOWLEN7#8basedir=`dirname $0`9source ${basedir}/functions.sh10root_check_run_with_sudo "$@"1112# Parameter parsing via include13source ${basedir}/parameters.sh1415# Trap EXIT first16trap_exit1718# Set some default params, if they didn't get set19if [ -z "$DEST_IP" ]; then20[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"21fi22[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"23[ -z "$CLONE_SKB" ] && CLONE_SKB="0"24[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely25if [ -n "$DEST_IP" ]; then26validate_addr${IP6} $DEST_IP27read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)28fi29if [ -n "$DST_PORT" ]; then30read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)31validate_ports $UDP_DST_MIN $UDP_DST_MAX32fi3334# NOTICE: Script specific settings35# =======36# Limiting the number of concurrent flows ($FLOWS)37# and also set how many packets each flow contains ($FLOWLEN)38#39[ -z "$FLOWS" ] && FLOWS="8000"40[ -z "$FLOWLEN" ] && FLOWLEN="10"4142if [[ -n "$BURST" ]]; then43err 1 "Bursting not supported for this mode"44fi4546# 198.18.0.0 / 198.19.255.25547read -r SRC_MIN SRC_MAX <<< $(parse_addr 198.18.0.0/15)4849# General cleanup everything since last run50[ -z "$APPEND" ] && pg_ctrl "reset"5152# Threads are specified with parameter -t value in $THREADS53for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do54dev=${DEV}@${thread}5556# Add remove all other devices and add_device $dev to thread57[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"58pg_thread $thread "add_device" $dev5960# Base config61pg_set $dev "flag QUEUE_MAP_CPU"62pg_set $dev "count $COUNT"63pg_set $dev "clone_skb $CLONE_SKB"64pg_set $dev "pkt_size $PKT_SIZE"65pg_set $dev "delay $DELAY"66pg_set $dev "flag NO_TIMESTAMP"6768# Single destination69pg_set $dev "dst_mac $DST_MAC"70pg_set $dev "dst${IP6}_min $DST_MIN"71pg_set $dev "dst${IP6}_max $DST_MAX"7273if [ -n "$DST_PORT" ]; then74# Single destination port or random port range75pg_set $dev "flag UDPDST_RND"76pg_set $dev "udp_dst_min $UDP_DST_MIN"77pg_set $dev "udp_dst_max $UDP_DST_MAX"78fi7980[ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"8182# Randomize source IP-addresses83pg_set $dev "flag IPSRC_RND"84pg_set $dev "src_min $SRC_MIN"85pg_set $dev "src_max $SRC_MAX"8687# Limit number of flows (max 65535)88pg_set $dev "flows $FLOWS"89#90# How many packets a flow will send, before flow "entry" is91# re-generated/setup.92pg_set $dev "flowlen $FLOWLEN"93#94# Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow95# being send back-to-back, before next flow is selected96# incrementally. This helps lookup caches, and is more realistic.97#98pg_set $dev "flag FLOW_SEQ"99100done101102# Run if user hits control-c103function print_result() {104# Print results105for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do106dev=${DEV}@${thread}107echo "Device: $dev"108cat /proc/net/pktgen/$dev | grep -A2 "Result:"109done110}111# trap keyboard interrupt (Ctrl-C)112trap true SIGINT113114if [ -z "$APPEND" ]; then115echo "Running... ctrl^C to stop" >&2116pg_ctrl "start"117118print_result119else120echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"121fi122123124