xref: /linux/tools/testing/selftests/drivers/net/mlxsw/qos_defprio.sh (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Test for port-default priority. Non-IP packets ingress $swp1 and are
5# prioritized according to the default priority specified at the port.
6# rx_octets_prio_* counters are used to verify the prioritization.
7#
8# +----------------------------------+
9# | H1                               |
10# |    + $h1                         |
11# |    | 192.0.2.1/28                |
12# +----|-----------------------------+
13#      |
14# +----|-----------------------------+
15# | SW |                             |
16# |    + $swp1                       |
17# |      192.0.2.2/28                |
18# |      dcb app default-prio <prio> |
19# +----------------------------------+
20
21ALL_TESTS="
22	ping_ipv4
23	test_defprio
24"
25
26lib_dir=$(dirname $0)/../../../net/forwarding
27
28NUM_NETIFS=2
29: ${HIT_TIMEOUT:=1000} # ms
30source $lib_dir/lib.sh
31
32h1_create()
33{
34	simple_if_init $h1 192.0.2.1/28
35}
36
37h1_destroy()
38{
39	simple_if_fini $h1 192.0.2.1/28
40}
41
42switch_create()
43{
44	ip link set dev $swp1 up
45	ip addr add dev $swp1 192.0.2.2/28
46}
47
48switch_destroy()
49{
50	dcb app flush dev $swp1 default-prio
51	ip addr del dev $swp1 192.0.2.2/28
52	ip link set dev $swp1 down
53}
54
55setup_prepare()
56{
57	h1=${NETIFS[p1]}
58	swp1=${NETIFS[p2]}
59
60	vrf_prepare
61
62	h1_create
63	switch_create
64}
65
66cleanup()
67{
68	pre_cleanup
69
70	switch_destroy
71	h1_destroy
72
73	vrf_cleanup
74}
75
76ping_ipv4()
77{
78	ping_test $h1 192.0.2.2
79}
80
81__test_defprio()
82{
83	local prio_install=$1; shift
84	local prio_observe=$1; shift
85	local key
86	local t1
87	local i
88
89	RET=0
90
91	dcb app add dev $swp1 default-prio $prio_install
92
93	local t0=$(ethtool_stats_get $swp1 rx_frames_prio_$prio_observe)
94	mausezahn -q $h1 -d 100m -c 10 -t arp reply
95	t1=$(busywait "$HIT_TIMEOUT" until_counter_is ">= $((t0 + 10))" \
96		ethtool_stats_get $swp1 rx_frames_prio_$prio_observe)
97
98	check_err $? "Default priority $prio_install/$prio_observe: Expected to capture 10 packets, got $((t1 - t0))."
99	log_test "Default priority $prio_install/$prio_observe"
100
101	dcb app del dev $swp1 default-prio $prio_install
102}
103
104test_defprio()
105{
106	local prio
107
108	for prio in {0..7}; do
109		__test_defprio $prio $prio
110	done
111
112	dcb app add dev $swp1 default-prio 3
113	__test_defprio 0 3
114	__test_defprio 1 3
115	__test_defprio 2 3
116	__test_defprio 4 4
117	__test_defprio 5 5
118	__test_defprio 6 6
119	__test_defprio 7 7
120	dcb app del dev $swp1 default-prio 3
121}
122
123trap cleanup EXIT
124
125setup_prepare
126setup_wait
127
128tests_run
129
130exit $EXIT_STATUS
131