-
Notifications
You must be signed in to change notification settings - Fork 13
/
tc_tests_common.sh
418 lines (379 loc) · 11.8 KB
/
tc_tests_common.sh
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/bin/bash
function check_num_rules() {
local num=$1
local itf=$2
title "- Verify $num rules"
RES=`tc -s filter show dev $itf ingress | grep handle | wc -l`
if (( RES == $num )); then success; else err "Found $RES rules but expected $num"; fi
}
function check_num_offloaded_rules() {
local num=$1
local offload_count=$2
local block=$3
title "- Verify $num rules with in_hw_count=$offload_count"
RES=`tc -s filter show block $block ingress | grep "in_hw in_hw_count $offload_count" | wc -l`
if (( RES == $num )); then
success
else
err
fi
}
function check_num_actions() {
local count=$1
local type=$2
title "- Verify $count actions"
RES=`tc -s actions ls action $type | grep order | wc -l`
if (( RES == $count )); then success; else err "Found $RES actions but expected $count"; fi
}
function tc_batch() {
local dup=$1
local dev_block=$2
local total=$3
local rules_per_file=$4
local cls=$5
local _action=${action:-drop}
local n=0
local count=0
local handle=0
local prio=1
local once=0
TC_OUT=/tmp/tc-$$
[ "$incr_prio" == 1 ] && prio=0
rm -fr $TC_OUT
mkdir -p $TC_OUT
for ((i = 0; i < 99; i++)); do
for ((j = 0; j < 99; j++)); do
for ((k = 0; k < 99; k++)); do
for ((l = 0; l < 99; l++)); do
SMAC="e4:11:$i:$j:$k:$l"
DMAC="e4:12:$i:$j:$k:$l"
((handle+=1))
[ "$no_handle" == 1 ] && handle=0
[ "$incr_prio" == 1 ] && ((prio+=1))
rule="$dev_block \
protocol ip \
ingress \
prio $prio \
handle $handle \
flower \
$skip \
src_mac $SMAC \
dst_mac $DMAC \
$cls \
action $_action $act_flags"
[ $once = "0" ] && once=1 && echo "type of rules: $rule"
echo "filter add $rule" >> ${TC_OUT}/add.$n
echo "filter change $rule" >> ${TC_OUT}/ovr.$n
echo "filter del $rule" >> ${TC_OUT}/del.$n
((count+=1))
let p=count%${rules_per_file}
if ((p==0)); then
((n++))
if (($dup==1)); then
handle=0
fi
fi
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
}
function tc_batch_vxlan() {
local dev_block=$1
local total=$2
local rules_per_file=$3
local cls=$4
local id=$5
local local_ip=$6
local remote_ip=$7
local dst_port=$8
local mirred_dev=$9
local extra_action=${10}
local n=0
local count=0
local handle=0
local prio=1
local once=0
TC_OUT=/tmp/tc-$$
[ "$incr_prio" == 1 ] && prio=0
rm -fr $TC_OUT
mkdir -p $TC_OUT
for ((i = 0; i < 99; i++)); do
for ((j = 0; j < 99; j++)); do
for ((k = 0; k < 99; k++)); do
for ((l = 0; l < 99; l++)); do
SMAC="e4:11:$i:$j:$k:$l"
DMAC="e4:12:$i:$j:$k:$l"
((handle+=1))
[ "$no_handle" == 1 ] && handle=0
[ "$incr_prio" == 1 ] && ((prio+=1))
rule="$dev_block \
protocol ip \
ingress \
prio $prio \
handle $handle \
flower \
$skip \
src_mac $SMAC \
dst_mac $DMAC \
$cls \
$extra_action \
action tunnel_key set id $id src_ip ${local_ip} dst_ip ${remote_ip} dst_port ${dst_port} $act_flags \
action mirred egress redirect dev $mirred_dev $act_flags"
[ $once = "0" ] && once=1 && echo "type of rules: $rule"
echo "filter add $rule" >> ${TC_OUT}/add.$n
echo "filter change $rule" >> ${TC_OUT}/ovr.$n
echo "filter del $rule" >> ${TC_OUT}/del.$n
((count+=1))
let p=count%${rules_per_file}
if ((p==0)); then
((n++))
fi
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
}
function tc_batch_vxlan_multiple_encap_multiple_neigh() {
local dev_block=$1
local total=$2
local rules_per_file=$3
local cls=$4
local id=$5
local local_ip=$6
local remote_ip_net=$7
local remote_ip_host=$8
local dst_port=$9
local mirred_dev=${10}
local encaps_per_file=${11}
local add_pedit=${12}
local pedit_act=""
local remote_ip_start=$8
local n=0
local count=0
local handle=0
local prio=1
local once=0
local rules_per_encap=$((rules_per_file/encaps_per_file))
TC_OUT=/tmp/tc-$$
[ "$incr_prio" == 1 ] && prio=0
if [ $encaps_per_file -gt $rules_per_file ]; then
local rules_per_encap=$rules_per_file
fi
[ $rules_per_encap == 0 ] && fail "rules_per_encap cannot be 0"
rm -fr $TC_OUT
mkdir -p $TC_OUT
for ((i = 0; i < 99; i++)); do
for ((j = 0; j < 99; j++)); do
for ((k = 0; k < 99; k++)); do
for ((l = 0; l < 99; l++)); do
SMAC="e4:11:$i:$j:$k:$l"
DMAC="e4:12:$i:$j:$k:$l"
((handle+=1))
[ "$no_handle" == 1 ] && handle=0
[ "$incr_prio" == 1 ] && ((prio+=1))
[ "$add_pedit" == 1 ] && pedit_act="action pedit ex munge ip src set ${remote_ip_net}${remote_ip_host}"
rule="$dev_block \
protocol ip \
ingress \
prio $prio \
handle $handle \
flower \
$skip \
src_mac $SMAC \
dst_mac $DMAC \
$cls \
$pedit_act \
action tunnel_key set id $id src_ip ${local_ip} dst_ip ${remote_ip_net}${remote_ip_host} dst_port ${dst_port} $act_flags \
action mirred egress redirect dev $mirred_dev $act_flags"
[ $once = "0" ] && once=1 && echo "type of rules: $rule"
echo "filter add $rule" >> ${TC_OUT}/add.$n
echo "filter change $rule" >> ${TC_OUT}/ovr.$n
echo "filter del $rule" >> ${TC_OUT}/del.$n
((count+=1))
let p=count%${rules_per_file}
let e=count%${rules_per_encap}
if ((p==0)); then
((n++))
remote_ip_host=$remote_ip_start
elif ((e==0)); then
((remote_ip_host++))
fi
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
}
function tc_batch_vxlan_multiple_encap_single_neigh() {
local dev_block=$1
local total=$2
local rules_per_file=$3
local cls=$4
local id=$5
local local_ip_net=$6
local local_ip_host=$7
local remote_ip_net=$8
local dst_port=$9
local mirred_dev=${10}
local encaps_per_file=${11}
local add_pedit=${12}
local pedit_act=""
local local_ip_start=$7
local n=0
local count=0
local handle=0
local prio=1
local once=0
local rules_per_encap=$((rules_per_file/encaps_per_file))
TC_OUT=/tmp/tc-$$
[ "$incr_prio" == 1 ] && prio=0
if [ $encaps_per_file -gt $rules_per_file ]; then
local rules_per_encap=$rules_per_file
fi
[ $rules_per_encap == 0 ] && fail "rules_per_encap cannot be 0"
rm -fr $TC_OUT
mkdir -p $TC_OUT
for ((i = 0; i < 99; i++)); do
for ((j = 0; j < 99; j++)); do
for ((k = 0; k < 99; k++)); do
for ((l = 0; l < 99; l++)); do
SMAC="e4:11:$i:$j:$k:$l"
DMAC="e4:12:$i:$j:$k:$l"
((handle+=1))
[ "$no_handle" == 1 ] && handle=0
[ "$incr_prio" == 1 ] && ((prio+=1))
[ "$add_pedit" == 1 ] && pedit_act="action pedit ex munge ip src set ${remote_ip}"
rule="$dev_block \
protocol ip \
ingress \
prio $prio \
handle $handle \
flower \
$skip \
src_mac $SMAC \
dst_mac $DMAC \
$cls \
$pedit_act \
action tunnel_key set id $id src_ip ${local_ip_net}${local_ip_host} dst_ip ${remote_ip} dst_port ${dst_port} $act_flags \
action mirred egress redirect dev $mirred_dev $act_flags"
[ $once = "0" ] && once=1 && echo "type of rules: $rule"
echo "filter add $rule" >> ${TC_OUT}/add.$n
echo "filter change $rule" >> ${TC_OUT}/ovr.$n
echo "filter del $rule" >> ${TC_OUT}/del.$n
((count+=1))
let p=count%${rules_per_file}
let e=count%${rules_per_encap}
if ((p==0)); then
((n++))
local_ip_host=$local_ip_start
elif ((e==0)); then
((local_ip_host++))
fi
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
if ((count>=total)); then
break;
fi
done
}
declare -A current
declare -A goal
function key_val_to_array() {
local -n arr=$1
local key
local value
while IFS== read -r key value; do
arr[$key]=$value
done
}
function check_test_results() {
local -n arr1=$1
local -n arr2=$2
for m in "${!arr1[@]}"; do
# Calculate absolute difference between baseline time and this test run (per cent).
read abs_diff <<< $(awk -v v1="${arr2[$m]}" -v v2="${arr1[$m]}" 'BEGIN{diff=(v2-v1)/v1 * 100;abs=diff<0?-diff:diff; printf "%.0f", abs}')
if ((abs_diff > 10)); then
err "Measured value for $m (current=${arr2[$m]} reference=${arr1[$m]}) differs by $abs_diff per cent"
else
success "Measured value for $m (current=${arr2[$m]} reference=${arr1[$m]}) differs by $abs_diff per cent"
fi
done
}
function run_perf_test() {
local input_file="$1"
local test_type="$2"
local num_rules="$3"
local num_instances="$4"
local flower_flags="$5"
local action_flags="$6"
# Skip all test output until results
local res
res=`$DIR/test-tc-perf-update.sh "$test_type" "$num_rules" "$num_instances" "$flower_flags" "$action_flags"`
local rc=$?
if [ $rc -ne 0 ]; then
fail "Perf update test failed"
fi
res=`echo -e "$res" | sed -n '/^RESULTS:$/,$p' | tail -n +2`
if [ -z "$res" ]; then
fail "Empty result"
fi
local input_res
if [ -f "$input_file" ]; then
input_res=`cat $input_file`
fi
if [ -n "$input_res" ]; then
key_val_to_array current < <(echo -e "$res")
key_val_to_array goal < "$input_file"
check_test_results goal current
else
title "No input file found. Create file $input_file."
echo -e "$res" > "$input_file" || fail "Failed to write results"
fail "Please re-run the test"
fi
}