samples: pktgen: new append mode
[linux-2.6-block.git] / samples / pktgen / pktgen_sample04_many_flows.sh
CommitLineData
15f2cbbd 1#!/bin/bash
b2441318 2# SPDX-License-Identifier: GPL-2.0
15f2cbbd
JDB
3#
4# Script example for many flows testing
5#
6# Number of simultaneous flows limited by variable $FLOWS
7# and number of packets per flow controlled by variable $FLOWLEN
8#
9basedir=`dirname $0`
10source ${basedir}/functions.sh
11root_check_run_with_sudo "$@"
12
13# Parameter parsing via include
14source ${basedir}/parameters.sh
15# Set some default params, if they didn't get set
16[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
17[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
18[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
69137ea6 19[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely
40f843ee
DL
20if [ -n "$DEST_IP" ]; then
21 validate_addr $DEST_IP
22 read -r DST_MIN DST_MAX <<< $(parse_addr $DEST_IP)
23fi
6e32a74a 24if [ -n "$DST_PORT" ]; then
723d2904
DL
25 read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
26 validate_ports $UDP_DST_MIN $UDP_DST_MAX
6e32a74a 27fi
15f2cbbd
JDB
28
29# NOTICE: Script specific settings
30# =======
31# Limiting the number of concurrent flows ($FLOWS)
32# and also set how many packets each flow contains ($FLOWLEN)
33#
34[ -z "$FLOWS" ] && FLOWS="8000"
35[ -z "$FLOWLEN" ] && FLOWLEN="10"
36
15f2cbbd
JDB
37if [[ -n "$BURST" ]]; then
38 err 1 "Bursting not supported for this mode"
39fi
40
40f843ee
DL
41# 198.18.0.0 / 198.19.255.255
42read -r SRC_MIN SRC_MAX <<< $(parse_addr 198.18.0.0/15)
43
15f2cbbd 44# General cleanup everything since last run
c8fd4852 45[ -z "$APPEND" ] && pg_ctrl "reset"
15f2cbbd
JDB
46
47# Threads are specified with parameter -t value in $THREADS
e0e16672 48for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
15f2cbbd
JDB
49 dev=${DEV}@${thread}
50
51 # Add remove all other devices and add_device $dev to thread
c8fd4852 52 [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
15f2cbbd
JDB
53 pg_thread $thread "add_device" $dev
54
55 # Base config
56 pg_set $dev "flag QUEUE_MAP_CPU"
57 pg_set $dev "count $COUNT"
58 pg_set $dev "clone_skb $CLONE_SKB"
59 pg_set $dev "pkt_size $PKT_SIZE"
60 pg_set $dev "delay $DELAY"
61 pg_set $dev "flag NO_TIMESTAMP"
62
63 # Single destination
64 pg_set $dev "dst_mac $DST_MAC"
40f843ee
DL
65 pg_set $dev "dst_min $DST_MIN"
66 pg_set $dev "dst_max $DST_MAX"
15f2cbbd 67
6e32a74a
DL
68 if [ -n "$DST_PORT" ]; then
69 # Single destination port or random port range
70 pg_set $dev "flag UDPDST_RND"
723d2904
DL
71 pg_set $dev "udp_dst_min $UDP_DST_MIN"
72 pg_set $dev "udp_dst_max $UDP_DST_MAX"
6e32a74a
DL
73 fi
74
15f2cbbd
JDB
75 # Randomize source IP-addresses
76 pg_set $dev "flag IPSRC_RND"
40f843ee
DL
77 pg_set $dev "src_min $SRC_MIN"
78 pg_set $dev "src_max $SRC_MAX"
15f2cbbd
JDB
79
80 # Limit number of flows (max 65535)
81 pg_set $dev "flows $FLOWS"
82 #
83 # How many packets a flow will send, before flow "entry" is
84 # re-generated/setup.
85 pg_set $dev "flowlen $FLOWLEN"
86 #
87 # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow
88 # being send back-to-back, before next flow is selected
89 # incrementally. This helps lookup caches, and is more realistic.
90 #
91 pg_set $dev "flag FLOW_SEQ"
92
93done
94
95# Run if user hits control-c
96function print_result() {
97 # Print results
e0e16672 98 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
15f2cbbd
JDB
99 dev=${DEV}@${thread}
100 echo "Device: $dev"
101 cat /proc/net/pktgen/$dev | grep -A2 "Result:"
102 done
103}
104# trap keyboard interrupt (Ctrl-C)
105trap true SIGINT
106
c8fd4852
IR
107if [ -z "$APPEND" ]; then
108 echo "Running... ctrl^C to stop" >&2
109 pg_ctrl "start"
15f2cbbd 110
c8fd4852
IR
111 print_result
112else
113 echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
114fi