aboutsummaryrefslogtreecommitdiffstats
path: root/examples/l4fwd/test/run_test.sh
blob: 431e9735cabe8918e2d94d3fd251a1323e7cd35a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#! /bin/bash

# readme section---------------------------------------------------------------

# usage: /bin/bash run_test.sh [-46alrh]
#
# Run all tests using nctxrx.sh. Report stored and printed
# after tests were done. For details about options run
# script with -h (help)
#
# User needs to specify following environment variables:
#  L4FWD_PATH	- path to l4fwd app binary
#  ETH_DEV	- for real NIC usage - ethernet device to be used on SUT by DPDK
#		- for tap interface - tap
#
# User needs to set following enviroment variables in case of real NIC usage:
#  REMOTE_HOST	- ip/hostname of DUT
#  REMOTE_IFACE	- interface name for the test-port on DUT
#  LOCAL_MAC	- MAC address used by DPDK
#
# Optional envirenment variables:
#  L4FWD_FECORE	- core on which l4fwd frontend should run
#  L4FWD_BECORE	- core on which l4fwd backend should run

# options which can be changed by user-----------------------------------------

# reorder settings
reorder_min=4
reorder_max=9
reorder_step=5

# loss settings
loss_min=0
loss_max=20
loss_step=20

# file for results storage
DIR=$(dirname $0)
result=${DIR}/result.out
echo -e "Test\t\tProtocol\tFile\t\t\tStatus\tTime" > ${result}

# how many times test file should be send during tests
nb=3

# variables used by script-----------------------------------------------------

# option parsing variables
run_loss=0
run_reorder=0
use_ip4=0
use_ip6=0

# track number of tests which have failed
error_count=0

SECONDS=0

# functions and calls----------------------------------------------------------

usage()
{
	echo -e "Usage:"
	echo -e "\t$0 [-alr46h]"
	echo -e "Options:"
	echo -e "\t-a Run all tests"
	echo -e "\t-l Perform loss tests"
	echo -e "\t-r Perform reorder tests"
	echo -e "\t-4 Use IPv4/TCP"
	echo -e "\t-6 Use IPv6/TCP"
	echo -e "\t-h Display this help"
	echo -e "Info:"
	echo -e "\tOptions [4/6] may be used together."
}

while getopts ":alr46h" opt
do
	case $opt in
		a)
			run_loss=1
			run_reorder=1
			;;
		l)
			run_loss=1
			;;
		r)
			run_reorder=1
			;;
		4)
			use_ip4=1
			;;
		6)
			use_ip6=1
			;;
		h)
			usage
			exit 0
			;;
		?)
			echo "Invalid option"
			usage
			exit 127
			;;
	esac
done

# check if tests to perform are specified
if [[ ${run_loss} -eq 0 && ${run_reorder} -eq 0 ]]
then
	echo -e "Error: No tests specified\n"
	usage
	exit 127
fi

# check if IP protocol was specified
if [[ ${use_ip4} -eq 0 && ${use_ip6} -eq 0 ]]
then
	echo -e "Error: No IP protocol specified\n"
	usage
	exit 127
fi

# get number of tests to perform
if [[ ${run_reorder} -eq 1 ]]
then
	nb_of_reorder=$(( $(( ${reorder_max} - ${reorder_min} )) \
		/ ${reorder_step} + 1 ))
else
	nb_of_reorder=0
fi

if [[ ${run_loss} -eq 1 ]]
then
	nb_of_loss=$(( $(( ${loss_max} - ${loss_min} )) / ${loss_step} + 1 ))
else
	nb_of_loss=0
fi

if [[ ${use_ip4} -eq 1 && ${use_ip6} -eq 1 ]]
then
	multiply=2
else
	multiply=1
fi

nb_of_tests=$(( $(( ${nb_of_loss} + ${nb_of_reorder} )) * ${multiply} ))
tests_performed=0

echo "Number of tests to run: ${nb_of_tests}"

# add intermediary data into result file
gather_data()
{
	test_case=$1
	test_value=$2
	protocol=$3

	length=$(expr length "${test_case} ${test_value}")
	if [[ ${length} -lt 8 ]]
	then
		tab="\t\t"
	else
		tab="\t"
	fi

	# add protocol used in test case which was invoked
	sed -i "s_.*_${protocol}\t\t&_" ${result}.tmp
	# add description of test case which was invoked (in first line)
	sed -i "1 s_.*_${test_case} ${test_value}${tab}&_" ${result}.tmp
	# add blank space to be aligned with first row
	sed -i "1 ! s_.*_\t\t&_" ${result}.tmp
	# add empty line befor each major test case
	sed -i "1 s_.*_\n&_" ${result}.tmp
	cat ${result}.tmp >> ${result}
	rm -f ${result}.tmp
}

# run all tests
while [[ ${use_ip4} -ne 0 || ${use_ip6} -ne 0 ]]
do
	#set protocol to be used in this round of tests
	if [[ ${use_ip4} -eq 1 ]]
	then
		proto="ipv4"
	elif [[ ${use_ip6} -eq 1 ]]
	then
		proto="ipv6"
	fi

	# check if reorder tests should be run
	if [[ ${run_reorder} -eq 1 ]]
	then
		# run test for all specified reorder values
		for reorder in $(seq ${reorder_min} \
				${reorder_step} \
				${reorder_max})
		do
			/bin/bash ${DIR}/nctxrx.sh \
				-p ${proto} \
				-n ${nb} \
				-r ${reorder} \
				-o ${result}.tmp \
				-v

			# check test status
			st=$?
			if [[ ${st} -eq 0 ]]
			then
				echo -e "\nTest for reorder: ${reorder}\t[OK]"
			else
				echo -e "\nTest for reorder: ${reorder}\t[FAIL]"
				error_count=$(expr ${error_count} + 1)
			fi

			# gather results
			gather_data "Reorder" ${reorder} ${proto}
			tests_performed=$(( ${tests_performed} + 1 ))
			echo -e "\n[PROGRESS] ${tests_performed} out of \
${nb_of_tests} done\n"
		done
	fi

	# check if loss tests should be run
	if [[ ${run_loss} -eq 1 ]]
	then
		# run test for all specified reorder values
		for loss in $(seq ${loss_min} ${loss_step} ${loss_max})
		do
			/bin/bash ${DIR}/nctxrx.sh \
				-p ${proto} \
				-n ${nb} \
				-l ${loss} \
				-o ${result}.tmp \
				-v

			# check test status
			st=$?
			if [[ ${st} -eq 0 ]]
			then
				echo -e "\nTest for loss: ${loss}\t[OK]"
			else
				echo -e "\nTest for loss: ${loss}\t[FAIL]"
				error_count=$(expr ${error_count} + 1)
			fi

			# gather results
			gather_data "Loss" ${loss} ${proto}
			tests_performed=$(( ${tests_performed} + 1 ))
			echo -e "\n[PROGRESS] ${tests_performed} out of \
${nb_of_tests} done\n"
		done
	fi

	# mark that tests were done for one of the protocols
	if [[ ${use_ip4} -eq 1 ]]
	then
		use_ip4=0
	elif [[ ${use_ip6} -eq 1 ]]
	then
		use_ip6=0
	fi
done

if [[ ${error_count} -eq 0 ]]
then
	echo -e "\nAll tests have ended successfully" >> ${result}
else
	echo -e "\n${error_count} tests have failed" >> ${result}
fi

if [[ $SECONDS -gt 60 ]]
then
	let "minutes=SECONDS/60"
	let "seconds=SECONDS%60"
	echo "All tests completed in $minutes minute(s) and $seconds second(s)"\
		>> ${result}
else
	echo "All tests completed in $SECONDS second(s)" >> ${result}
fi

# print report after all tests were done
echo -e "Report:\n"
cat ${result}