Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/selftests/drivers/net/microchip/ksz9477_qos.sh
26292 views
1
#!/bin/bash
2
# SPDX-License-Identifier: GPL-2.0
3
# Copyright (c) 2024 Pengutronix, Oleksij Rempel <[email protected]>
4
5
# The script is adopted to work with the Microchip KSZ switch driver.
6
7
ETH_FCS_LEN=4
8
9
WAIT_TIME=1
10
NUM_NETIFS=4
11
REQUIRE_JQ="yes"
12
REQUIRE_MZ="yes"
13
STABLE_MAC_ADDRS=yes
14
NETIF_CREATE=no
15
lib_dir=$(dirname $0)/../../../net/forwarding
16
source $lib_dir/tc_common.sh
17
source $lib_dir/lib.sh
18
19
require_command dcb
20
21
h1=${NETIFS[p1]}
22
swp1=${NETIFS[p2]}
23
swp2=${NETIFS[p3]}
24
h2=${NETIFS[p4]}
25
26
H1_IPV4="192.0.2.1"
27
H2_IPV4="192.0.2.2"
28
H1_IPV6="2001:db8:1::1"
29
H2_IPV6="2001:db8:1::2"
30
31
# On h1_ and h2_create do not set IP addresses to avoid interaction with the
32
# system, to keep packet counters clean.
33
h1_create()
34
{
35
simple_if_init $h1
36
sysctl_set net.ipv6.conf.${h1}.disable_ipv6 1
37
# Get the MAC address of the interface to use it with mausezahn
38
h1_mac=$(ip -j link show dev ${h1} | jq -e '.[].address')
39
}
40
41
h1_destroy()
42
{
43
sysctl_restore net.ipv6.conf.${h1}.disable_ipv6
44
simple_if_fini $h1
45
}
46
47
h2_create()
48
{
49
simple_if_init $h2
50
sysctl_set net.ipv6.conf.${h2}.disable_ipv6 1
51
h2_mac=$(ip -j link show dev ${h2} | jq -e '.[].address')
52
}
53
54
h2_destroy()
55
{
56
sysctl_restore net.ipv6.conf.${h2}.disable_ipv6
57
simple_if_fini $h2
58
}
59
60
switch_create()
61
{
62
ip link set ${swp1} up
63
ip link set ${swp2} up
64
sysctl_set net.ipv6.conf.${swp1}.disable_ipv6 1
65
sysctl_set net.ipv6.conf.${swp2}.disable_ipv6 1
66
67
# Ports should trust VLAN PCP even with vlan_filtering=0
68
ip link add br0 type bridge
69
ip link set ${swp1} master br0
70
ip link set ${swp2} master br0
71
ip link set br0 up
72
sysctl_set net.ipv6.conf.br0.disable_ipv6 1
73
}
74
75
switch_destroy()
76
{
77
sysctl_restore net.ipv6.conf.${swp2}.disable_ipv6
78
sysctl_restore net.ipv6.conf.${swp1}.disable_ipv6
79
80
ip link del br0
81
}
82
83
setup_prepare()
84
{
85
vrf_prepare
86
87
h1_create
88
h2_create
89
switch_create
90
}
91
92
cleanup()
93
{
94
pre_cleanup
95
96
h2_destroy
97
h1_destroy
98
switch_destroy
99
100
vrf_cleanup
101
}
102
103
set_apptrust_order()
104
{
105
local if_name=$1
106
local order=$2
107
108
dcb apptrust set dev ${if_name} order ${order}
109
}
110
111
# Function to extract a specified field from a given JSON stats string
112
extract_network_stat() {
113
local stats_json=$1
114
local field_name=$2
115
116
echo $(echo "$stats_json" | jq -r "$field_name")
117
}
118
119
run_test()
120
{
121
local test_name=$1;
122
local apptrust_order=$2;
123
local port_prio=$3;
124
local dscp_ipv=$4;
125
local dscp=$5;
126
local have_vlan=$6;
127
local pcp_ipv=$7;
128
local vlan_pcp=$8;
129
local ip_v6=$9
130
131
local rx_ipv
132
local tx_ipv
133
134
RET=0
135
136
# Send some packet to populate the switch MAC table
137
$MZ ${h2} -a ${h2_mac} -b ${h1_mac} -p 64 -t icmp echores -c 1
138
139
# Based on the apptrust order, set the expected Internal Priority values
140
# for the RX and TX paths.
141
if [ "${apptrust_order}" == "" ]; then
142
echo "Apptrust order not set."
143
rx_ipv=${port_prio}
144
tx_ipv=${port_prio}
145
elif [ "${apptrust_order}" == "dscp" ]; then
146
echo "Apptrust order is DSCP."
147
rx_ipv=${dscp_ipv}
148
tx_ipv=${dscp_ipv}
149
elif [ "${apptrust_order}" == "pcp" ]; then
150
echo "Apptrust order is PCP."
151
rx_ipv=${pcp_ipv}
152
tx_ipv=${pcp_ipv}
153
elif [ "${apptrust_order}" == "pcp dscp" ]; then
154
echo "Apptrust order is PCP DSCP."
155
if [ ${have_vlan} -eq 1 ]; then
156
rx_ipv=$((dscp_ipv > pcp_ipv ? dscp_ipv : pcp_ipv))
157
tx_ipv=${pcp_ipv}
158
else
159
rx_ipv=${dscp_ipv}
160
tx_ipv=${dscp_ipv}
161
fi
162
else
163
RET=1
164
echo "Error: Unknown apptrust order ${apptrust_order}"
165
log_test "${test_name}"
166
return
167
fi
168
169
# Most/all? of the KSZ switches do not provide per-TC counters. There
170
# are only tx_hi and rx_hi counters, which are used to count packets
171
# which are considered as high priority and most likely not assigned
172
# to the queue 0.
173
# On the ingress path, packets seem to get high priority status
174
# independently of the DSCP or PCP global mapping. On the egress path,
175
# the high priority status is assigned based on the DSCP or PCP global
176
# map configuration.
177
# The thresholds for the high priority status are not documented, but
178
# it seems that the switch considers packets as high priority on the
179
# ingress path if detected Internal Priority is greater than 0. On the
180
# egress path, the switch considers packets as high priority if
181
# detected Internal Priority is greater than 1.
182
if [ ${rx_ipv} -ge 1 ]; then
183
local expect_rx_high_prio=1
184
else
185
local expect_rx_high_prio=0
186
fi
187
188
if [ ${tx_ipv} -ge 2 ]; then
189
local expect_tx_high_prio=1
190
else
191
local expect_tx_high_prio=0
192
fi
193
194
# Use ip tool to get the current switch packet counters. ethool stats
195
# need to be recalculated to get the correct values.
196
local swp1_stats=$(ip -s -j link show dev ${swp1})
197
local swp2_stats=$(ip -s -j link show dev ${swp2})
198
local swp1_rx_packets_before=$(extract_network_stat "$swp1_stats" \
199
'.[0].stats64.rx.packets')
200
local swp1_rx_bytes_before=$(extract_network_stat "$swp1_stats" \
201
'.[0].stats64.rx.bytes')
202
local swp2_tx_packets_before=$(extract_network_stat "$swp2_stats" \
203
'.[0].stats64.tx.packets')
204
local swp2_tx_bytes_before=$(extract_network_stat "$swp2_stats" \
205
'.[0].stats64.tx.bytes')
206
local swp1_rx_hi_before=$(ethtool_stats_get ${swp1} "rx_hi")
207
local swp2_tx_hi_before=$(ethtool_stats_get ${swp2} "tx_hi")
208
209
# Assamble the mausezahn command based on the test parameters
210
# For the testis with ipv4 or ipv6, use icmp response packets,
211
# to avoid interaction with the system, to keep packet counters
212
# clean.
213
if [ ${ip_v6} -eq 0 ]; then
214
local ip="-a ${h1_mac} -b ${h2_mac} -A ${H1_IPV4} \
215
-B ${H2_IPV4} -t icmp unreach,code=1,dscp=${dscp}"
216
else
217
local ip="-6 -a ${h1_mac} -b ${h2_mac} -A ${H1_IPV6} \
218
-B ${H2_IPV6} -t icmp6 type=1,code=0,dscp=${dscp}"
219
fi
220
221
if [ ${have_vlan} -eq 1 ]; then
222
local vlan_pcp_opt="-Q ${vlan_pcp}:0"
223
else
224
local vlan_pcp_opt=""
225
fi
226
$MZ ${h1} ${ip} -c ${PING_COUNT} -d 10msec ${vlan_pcp_opt}
227
228
# Wait until the switch packet counters are updated
229
sleep 6
230
231
local swp1_stats=$(ip -s -j link show dev ${swp1})
232
local swp2_stats=$(ip -s -j link show dev ${swp2})
233
234
local swp1_rx_packets_after=$(extract_network_stat "$swp1_stats" \
235
'.[0].stats64.rx.packets')
236
local swp1_rx_bytes_after=$(extract_network_stat "$swp1_stats" \
237
'.[0].stats64.rx.bytes')
238
local swp2_tx_packets_after=$(extract_network_stat "$swp2_stats" \
239
'.[0].stats64.tx.packets')
240
local swp2_tx_bytes_after=$(extract_network_stat "$swp2_stats" \
241
'.[0].stats64.tx.bytes')
242
243
local swp1_rx_packets_diff=$((${swp1_rx_packets_after} - \
244
${swp1_rx_packets_before}))
245
local swp2_tx_packets_diff=$((${swp2_tx_packets_after} - \
246
${swp2_tx_packets_before}))
247
248
local swp1_rx_hi_after=$(ethtool_stats_get ${swp1} "rx_hi")
249
local swp2_tx_hi_after=$(ethtool_stats_get ${swp2} "tx_hi")
250
251
# Test if any packets were received on swp1, we will rx before and after
252
if [ ${swp1_rx_packets_diff} -lt ${PING_COUNT} ]; then
253
echo "Not expected amount of received packets on ${swp1}"
254
echo "before ${swp1_rx_packets_before} after ${swp1_rx_packets_after}"
255
RET=1
256
fi
257
258
# Test if any packets were transmitted on swp2, we will tx before and after
259
if [ ${swp2_tx_packets_diff} -lt ${PING_COUNT} ]; then
260
echo "Not expected amount of transmitted packets on ${swp2}"
261
echo "before ${swp2_tx_packets_before} after ${swp2_tx_packets_after}"
262
RET=1
263
fi
264
265
# tx/rx_hi counted in bytes. So, we need to compare the difference in bytes
266
local swp1_rx_bytes_diff=$(($swp1_rx_bytes_after - $swp1_rx_bytes_before))
267
local swp2_tx_bytes_diff=$(($swp2_tx_bytes_after - $swp2_tx_bytes_before))
268
local swp1_rx_hi_diff=$(($swp1_rx_hi_after - $swp1_rx_hi_before))
269
local swp2_tx_hi_diff=$(($swp2_tx_hi_after - $swp2_tx_hi_before))
270
271
if [ ${expect_rx_high_prio} -eq 1 ]; then
272
swp1_rx_hi_diff=$((${swp1_rx_hi_diff} - \
273
${swp1_rx_packets_diff} * ${ETH_FCS_LEN}))
274
if [ ${swp1_rx_hi_diff} -ne ${swp1_rx_bytes_diff} ]; then
275
echo "Not expected amount of high priority packets received on ${swp1}"
276
echo "RX hi diff: ${swp1_rx_hi_diff}, expected RX bytes diff: ${swp1_rx_bytes_diff}"
277
RET=1
278
fi
279
else
280
if [ ${swp1_rx_hi_diff} -ne 0 ]; then
281
echo "Unexpected amount of high priority packets received on ${swp1}"
282
echo "RX hi diff: ${swp1_rx_hi_diff}, expected 0"
283
RET=1
284
fi
285
fi
286
287
if [ ${expect_tx_high_prio} -eq 1 ]; then
288
swp2_tx_hi_diff=$((${swp2_tx_hi_diff} - \
289
${swp2_tx_packets_diff} * ${ETH_FCS_LEN}))
290
if [ ${swp2_tx_hi_diff} -ne ${swp2_tx_bytes_diff} ]; then
291
echo "Not expected amount of high priority packets transmitted on ${swp2}"
292
echo "TX hi diff: ${swp2_tx_hi_diff}, expected TX bytes diff: ${swp2_tx_bytes_diff}"
293
RET=1
294
fi
295
else
296
if [ ${swp2_tx_hi_diff} -ne 0 ]; then
297
echo "Unexpected amount of high priority packets transmitted on ${swp2}"
298
echo "TX hi diff: ${swp2_tx_hi_diff}, expected 0"
299
RET=1
300
fi
301
fi
302
303
log_test "${test_name}"
304
}
305
306
run_test_dscp()
307
{
308
# IPv4 test
309
run_test "$1" "$2" "$3" "$4" "$5" 0 0 0 0
310
# IPv6 test
311
run_test "$1" "$2" "$3" "$4" "$5" 0 0 0 1
312
}
313
314
run_test_dscp_pcp()
315
{
316
# IPv4 test
317
run_test "$1" "$2" "$3" "$4" "$5" 1 "$6" "$7" 0
318
# IPv6 test
319
run_test "$1" "$2" "$3" "$4" "$5" 1 "$6" "$7" 1
320
}
321
322
port_default_prio_get()
323
{
324
local if_name=$1
325
local prio
326
327
prio="$(dcb -j app show dev ${if_name} default-prio | \
328
jq '.default_prio[]')"
329
if [ -z "${prio}" ]; then
330
prio=0
331
fi
332
333
echo ${prio}
334
}
335
336
test_port_default()
337
{
338
local orig_apptrust=$(port_get_default_apptrust ${swp1})
339
local orig_prio=$(port_default_prio_get ${swp1})
340
local apptrust_order=""
341
342
RET=0
343
344
# Make sure no other priority sources will interfere with the test
345
set_apptrust_order ${swp1} "${apptrust_order}"
346
347
for val in $(seq 0 7); do
348
dcb app replace dev ${swp1} default-prio ${val}
349
if [ $val -ne $(port_default_prio_get ${swp1}) ]; then
350
RET=1
351
break
352
fi
353
354
run_test_dscp "Port-default QoS classification, prio: ${val}" \
355
"${apptrust_order}" ${val} 0 0
356
done
357
358
set_apptrust_order ${swp1} "${orig_apptrust}"
359
if [[ "$orig_apptrust" != "$(port_get_default_apptrust ${swp1})" ]]; then
360
RET=1
361
fi
362
363
dcb app replace dev ${swp1} default-prio ${orig_prio}
364
if [ $orig_prio -ne $(port_default_prio_get ${swp1}) ]; then
365
RET=1
366
fi
367
368
log_test "Port-default QoS classification"
369
}
370
371
port_get_default_apptrust()
372
{
373
local if_name=$1
374
375
dcb -j apptrust show dev ${if_name} | jq -r '.order[]' | \
376
tr '\n' ' ' | xargs
377
}
378
379
test_port_apptrust()
380
{
381
local original_dscp_prios_swp1=$(get_dscp_prios ${swp1})
382
local orig_apptrust=$(port_get_default_apptrust ${swp1})
383
local orig_port_prio=$(port_default_prio_get ${swp1})
384
local order_variants=("pcp dscp" "dscp" "pcp")
385
local apptrust_order
386
local port_prio
387
local dscp_prio
388
local pcp_prio
389
local dscp
390
local pcp
391
392
RET=0
393
394
# First, test if apptrust configuration as taken by the kernel
395
for order in "${order_variants[@]}"; do
396
set_apptrust_order ${swp1} "${order}"
397
if [[ "$order" != "$(port_get_default_apptrust ${swp1})" ]]; then
398
RET=1
399
break
400
fi
401
done
402
403
log_test "Apptrust, supported variants"
404
405
# To test if the apptrust configuration is working as expected, we need
406
# to set DSCP priorities for the switch port.
407
init_dscp_prios "${swp1}" "${original_dscp_prios_swp1}"
408
409
# Start with a simple test where all apptrust sources are disabled
410
# default port priority is 0, DSCP priority is mapped to 7.
411
# No high priority packets should be received or transmitted.
412
port_prio=0
413
dscp_prio=7
414
dscp=4
415
416
dcb app replace dev ${swp1} default-prio ${port_prio}
417
dcb app replace dev ${swp1} dscp-prio ${dscp}:${dscp_prio}
418
419
apptrust_order=""
420
set_apptrust_order ${swp1} "${apptrust_order}"
421
# Test with apptrust sources disabled, Packets should get port default
422
# priority which is 0
423
run_test_dscp "Apptrust, all disabled. DSCP-prio ${dscp}:${dscp_prio}" \
424
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp}
425
426
apptrust_order="pcp"
427
set_apptrust_order ${swp1} "${apptrust_order}"
428
# If PCP is enabled, packets should get PCP priority, which is not
429
# set in this test (no VLAN tags are present in the packet). No high
430
# priority packets should be received or transmitted.
431
run_test_dscp "Apptrust, PCP enabled. DSCP-prio ${dscp}:${dscp_prio}" \
432
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp}
433
434
apptrust_order="dscp"
435
set_apptrust_order ${swp1} "${apptrust_order}"
436
# If DSCP is enabled, packets should get DSCP priority which is set to 7
437
# in this test. High priority packets should be received and transmitted.
438
run_test_dscp "Apptrust, DSCP enabled. DSCP-prio ${dscp}:${dscp_prio}" \
439
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp}
440
441
apptrust_order="pcp dscp"
442
set_apptrust_order ${swp1} "${apptrust_order}"
443
# If PCP and DSCP are enabled, PCP would have higher apptrust priority
444
# so packets should get PCP priority. But in this test VLAN PCP is not
445
# set, so it should get DSCP priority which is set to 7. High priority
446
# packets should be received and transmitted.
447
run_test_dscp "Apptrust, PCP and DSCP are enabled. DSCP-prio ${dscp}:${dscp_prio}" \
448
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp}
449
450
# If VLAN PCP is set, it should have higher apptrust priority than DSCP
451
# so packets should get VLAN PCP priority. Send packets with VLAN PCP
452
# set to 0, DSCP set to 7. Packets should get VLAN PCP priority.
453
# No high priority packets should be transmitted. Due to nature of the
454
# switch, high priority packets will be received.
455
pcp_prio=0
456
pcp=0
457
run_test_dscp_pcp "Apptrust, PCP and DSCP are enabled. PCP ${pcp_prio}, DSCP-prio ${dscp}:${dscp_prio}" \
458
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp} ${pcp_prio} ${pcp}
459
460
# If VLAN PCP is set to 7, it should have higher apptrust priority than
461
# DSCP so packets should get VLAN PCP priority. Send packets with VLAN
462
# PCP set to 7, DSCP set to 7. Packets should get VLAN PCP priority.
463
# High priority packets should be received and transmitted.
464
pcp_prio=7
465
pcp=7
466
run_test_dscp_pcp "Apptrust, PCP and DSCP are enabled. PCP ${pcp_prio}, DSCP-prio ${dscp}:${dscp_prio}" \
467
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp} ${pcp_prio} ${pcp}
468
# Now make sure that the switch is able to handle the case where DSCP
469
# priority is set to 0 and PCP priority is set to 7. Packets should get
470
# PCP priority. High priority packets should be received and transmitted.
471
dscp_prio=0
472
dcb app replace dev ${swp1} dscp-prio ${dscp}:${dscp_prio}
473
run_test_dscp_pcp "Apptrust, PCP and DSCP are enabled. PCP ${pcp_prio}, DSCP-prio ${dscp}:${dscp_prio}" \
474
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp} ${pcp_prio} ${pcp}
475
# If both VLAN PCP and DSCP are set to 0, packets should get 0 priority.
476
# No high priority packets should be received or transmitted.
477
pcp_prio=0
478
pcp=0
479
run_test_dscp_pcp "Apptrust, PCP and DSCP are enabled. PCP ${pcp_prio}, DSCP-prio ${dscp}:${dscp_prio}" \
480
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp} ${pcp_prio} ${pcp}
481
482
# Restore original priorities
483
if ! restore_priorities "${swp1}" "${original_dscp_prios_swp1}"; then
484
RET=1
485
fi
486
487
set_apptrust_order ${swp1} "${orig_apptrust}"
488
if [ "$orig_apptrust" != "$(port_get_default_apptrust ${swp1})" ]; then
489
RET=1
490
fi
491
492
dcb app replace dev ${swp1} default-prio ${orig_port_prio}
493
if [ $orig_port_prio -ne $(port_default_prio_get ${swp1}) ]; then
494
RET=1
495
fi
496
497
log_test "Apptrust, restore original settings"
498
}
499
500
# Function to get current DSCP priorities
501
get_dscp_prios() {
502
local if_name=$1
503
dcb -j app show dev ${if_name} | jq -c '.dscp_prio'
504
}
505
506
# Function to set a specific DSCP priority on a device
507
replace_dscp_prio() {
508
local if_name=$1
509
local dscp=$2
510
local prio=$3
511
dcb app replace dev ${if_name} dscp-prio ${dscp}:${prio}
512
}
513
514
# Function to compare DSCP maps
515
compare_dscp_maps() {
516
local old_json=$1
517
local new_json=$2
518
local dscp=$3
519
local prio=$4
520
521
# Create a modified old_json with the expected change for comparison
522
local modified_old_json=$(echo "$old_json" |
523
jq --argjson dscp $dscp --argjson prio $prio \
524
'map(if .[0] == $dscp then [$dscp, $prio] else . end)' |
525
tr -d " \n")
526
527
# Compare new_json with the modified_old_json
528
if [[ "$modified_old_json" == "$new_json" ]]; then
529
return 0
530
else
531
return 1
532
fi
533
}
534
535
# Function to set DSCP priorities
536
set_and_verify_dscp() {
537
local port=$1
538
local dscp=$2
539
local new_prio=$3
540
541
local old_prios=$(get_dscp_prios $port)
542
543
replace_dscp_prio "$port" $dscp $new_prio
544
545
# Fetch current settings and compare
546
local current_prios=$(get_dscp_prios $port)
547
if ! compare_dscp_maps "$old_prios" "$current_prios" $dscp $new_prio; then
548
echo "Error: Unintended changes detected in DSCP map for $port after setting DSCP $dscp to $new_prio."
549
return 1
550
fi
551
return 0
552
}
553
554
# Function to restore original priorities
555
restore_priorities() {
556
local port=$1
557
local original_prios=$2
558
559
echo "Removing test artifacts for $port"
560
local current_prios=$(get_dscp_prios $port)
561
local prio_str=$(echo "$current_prios" |
562
jq -r 'map("\(.[0]):\(.[1])") | join(" ")')
563
dcb app del dev $port dscp-prio $prio_str
564
565
echo "Restoring original DSCP priorities for $port"
566
local restore_str=$(echo "$original_prios" |
567
jq -r 'map("\(.[0]):\(.[1])") | join(" ")')
568
dcb app add dev $port dscp-prio $restore_str
569
570
local current_prios=$(get_dscp_prios $port)
571
if [[ "$original_prios" != "$current_prios" ]]; then
572
echo "Error: Failed to restore original DSCP priorities for $port"
573
return 1
574
fi
575
return 0
576
}
577
578
# Initialize DSCP priorities. Set them to predictable values for testing.
579
init_dscp_prios() {
580
local port=$1
581
local original_prios=$2
582
583
echo "Removing any existing DSCP priority mappins for $port"
584
local prio_str=$(echo "$original_prios" |
585
jq -r 'map("\(.[0]):\(.[1])") | join(" ")')
586
dcb app del dev $port dscp-prio $prio_str
587
588
# Initialize DSCP priorities list
589
local dscp_prios=""
590
for dscp in {0..63}; do
591
dscp_prios+=("$dscp:0")
592
done
593
594
echo "Setting initial DSCP priorities map to 0 for $port"
595
dcb app add dev $port dscp-prio ${dscp_prios[@]}
596
}
597
598
# Main function to test global DSCP map across specified ports
599
test_global_dscp_map() {
600
local ports=("$swp1" "$swp2")
601
local original_dscp_prios_port0=$(get_dscp_prios ${ports[0]})
602
local orig_apptrust=$(port_get_default_apptrust ${swp1})
603
local orig_port_prio=$(port_default_prio_get ${swp1})
604
local apptrust_order="dscp"
605
local port_prio=0
606
local dscp_prio
607
local dscp
608
609
RET=0
610
611
set_apptrust_order ${swp1} "${apptrust_order}"
612
dcb app replace dev ${swp1} default-prio ${port_prio}
613
614
# Initialize DSCP priorities
615
init_dscp_prios "${ports[0]}" "$original_dscp_prios_port0"
616
617
# Loop over each DSCP index
618
for dscp in {0..63}; do
619
# and test each Internal Priority value
620
for dscp_prio in {0..7}; do
621
# do it for each port. This is to test if the global DSCP map
622
# is accessible from all ports.
623
for port in "${ports[@]}"; do
624
if ! set_and_verify_dscp "$port" $dscp $dscp_prio; then
625
RET=1
626
fi
627
done
628
629
# Test if the DSCP priority is correctly applied to the packets
630
run_test_dscp "DSCP (${dscp}) QoS classification, prio: ${dscp_prio}" \
631
"${apptrust_order}" ${port_prio} ${dscp_prio} ${dscp}
632
if [ ${RET} -eq 1 ]; then
633
break
634
fi
635
done
636
done
637
638
# Restore original priorities
639
if ! restore_priorities "${ports[0]}" "${original_dscp_prios_port0}"; then
640
RET=1
641
fi
642
643
set_apptrust_order ${swp1} "${orig_apptrust}"
644
if [[ "$orig_apptrust" != "$(port_get_default_apptrust ${swp1})" ]]; then
645
RET=1
646
fi
647
648
dcb app replace dev ${swp1} default-prio ${orig_port_prio}
649
if [ $orig_port_prio -ne $(port_default_prio_get ${swp1}) ]; then
650
RET=1
651
fi
652
653
log_test "DSCP global map"
654
}
655
656
trap cleanup EXIT
657
658
ALL_TESTS="
659
test_port_default
660
test_port_apptrust
661
test_global_dscp_map
662
"
663
664
setup_prepare
665
setup_wait
666
tests_run
667
668
exit $EXIT_STATUS
669
670