Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Script example for many flows testing
0005 #
0006 # Number of simultaneous flows limited by variable $FLOWS
0007 # and number of packets per flow controlled by variable $FLOWLEN
0008 #
0009 basedir=`dirname $0`
0010 source ${basedir}/functions.sh
0011 root_check_run_with_sudo "$@"
0012 
0013 # Parameter parsing via include
0014 source ${basedir}/parameters.sh
0015 # Set some default params, if they didn't get set
0016 if [ -z "$DEST_IP" ]; then
0017     [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
0018 fi
0019 [ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
0020 [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
0021 [ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
0022 if [ -n "$DEST_IP" ]; then
0023     validate_addr${IP6} $DEST_IP
0024     read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
0025 fi
0026 if [ -n "$DST_PORT" ]; then
0027     read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
0028     validate_ports $UDP_DST_MIN $UDP_DST_MAX
0029 fi
0030 
0031 # NOTICE:  Script specific settings
0032 # =======
0033 # Limiting the number of concurrent flows ($FLOWS)
0034 # and also set how many packets each flow contains ($FLOWLEN)
0035 #
0036 [ -z "$FLOWS" ]     && FLOWS="8000"
0037 [ -z "$FLOWLEN" ]   && FLOWLEN="10"
0038 
0039 if [[ -n "$BURST" ]]; then
0040     err 1 "Bursting not supported for this mode"
0041 fi
0042 
0043 # 198.18.0.0 / 198.19.255.255
0044 read -r SRC_MIN SRC_MAX <<< $(parse_addr 198.18.0.0/15)
0045 
0046 # General cleanup everything since last run
0047 [ -z "$APPEND" ] && pg_ctrl "reset"
0048 
0049 # Threads are specified with parameter -t value in $THREADS
0050 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
0051     dev=${DEV}@${thread}
0052 
0053     # Add remove all other devices and add_device $dev to thread
0054     [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
0055     pg_thread $thread "add_device" $dev
0056 
0057     # Base config
0058     pg_set $dev "flag QUEUE_MAP_CPU"
0059     pg_set $dev "count $COUNT"
0060     pg_set $dev "clone_skb $CLONE_SKB"
0061     pg_set $dev "pkt_size $PKT_SIZE"
0062     pg_set $dev "delay $DELAY"
0063     pg_set $dev "flag NO_TIMESTAMP"
0064 
0065     # Single destination
0066     pg_set $dev "dst_mac $DST_MAC"
0067     pg_set $dev "dst${IP6}_min $DST_MIN"
0068     pg_set $dev "dst${IP6}_max $DST_MAX"
0069 
0070     if [ -n "$DST_PORT" ]; then
0071         # Single destination port or random port range
0072         pg_set $dev "flag UDPDST_RND"
0073         pg_set $dev "udp_dst_min $UDP_DST_MIN"
0074         pg_set $dev "udp_dst_max $UDP_DST_MAX"
0075     fi
0076 
0077     [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
0078 
0079     # Randomize source IP-addresses
0080     pg_set $dev "flag IPSRC_RND"
0081     pg_set $dev "src_min $SRC_MIN"
0082     pg_set $dev "src_max $SRC_MAX"
0083 
0084     # Limit number of flows (max 65535)
0085     pg_set $dev "flows $FLOWS"
0086     #
0087     # How many packets a flow will send, before flow "entry" is
0088     # re-generated/setup.
0089     pg_set $dev "flowlen $FLOWLEN"
0090     #
0091     # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
0092     # being send back-to-back, before next flow is selected
0093     # incrementally.  This helps lookup caches, and is more realistic.
0094     #
0095     pg_set $dev "flag FLOW_SEQ"
0096 
0097 done
0098 
0099 # Run if user hits control-c
0100 function print_result() {
0101     # Print results
0102     for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
0103         dev=${DEV}@${thread}
0104         echo "Device: $dev"
0105         cat /proc/net/pktgen/$dev | grep -A2 "Result:"
0106     done
0107 }
0108 # trap keyboard interrupt (Ctrl-C)
0109 trap true SIGINT
0110 
0111 if [ -z "$APPEND" ]; then
0112     echo "Running... ctrl^C to stop" >&2
0113     pg_ctrl "start"
0114 
0115     print_result
0116 else
0117     echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
0118 fi