Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / drivers / net / ocelot / basic_qos.sh
blobc51c83421c61116f43bd76efcac98bc26d18db0e
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2022 NXP
5 # The script is mostly generic, with the exception of the
6 # ethtool per-TC counter names ("rx_green_prio_${tc}")
8 WAIT_TIME=1
9 NUM_NETIFS=4
10 STABLE_MAC_ADDRS=yes
11 NETIF_CREATE=no
12 lib_dir=$(dirname $0)/../../../net/forwarding
13 source $lib_dir/tc_common.sh
14 source $lib_dir/lib.sh
16 require_command dcb
18 h1=${NETIFS[p1]}
19 swp1=${NETIFS[p2]}
20 swp2=${NETIFS[p3]}
21 h2=${NETIFS[p4]}
23 H1_IPV4="192.0.2.1"
24 H2_IPV4="192.0.2.2"
25 H1_IPV6="2001:db8:1::1"
26 H2_IPV6="2001:db8:1::2"
28 h1_create()
30 simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
33 h1_destroy()
35 simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
38 h2_create()
40 simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
43 h2_destroy()
45 simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
48 h1_vlan_create()
50 local vid=$1
52 vlan_create $h1 $vid
53 simple_if_init $h1.$vid $H1_IPV4/24 $H1_IPV6/64
54 ip link set $h1.$vid type vlan \
55 egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \
56 ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
59 h1_vlan_destroy()
61 local vid=$1
63 simple_if_fini $h1.$vid $H1_IPV4/24 $H1_IPV6/64
64 vlan_destroy $h1 $vid
67 h2_vlan_create()
69 local vid=$1
71 vlan_create $h2 $vid
72 simple_if_init $h2.$vid $H2_IPV4/24 $H2_IPV6/64
73 ip link set $h2.$vid type vlan \
74 egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \
75 ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
78 h2_vlan_destroy()
80 local vid=$1
82 simple_if_fini $h2.$vid $H2_IPV4/24 $H2_IPV6/64
83 vlan_destroy $h2 $vid
86 vlans_prepare()
88 h1_vlan_create 100
89 h2_vlan_create 100
91 tc qdisc add dev ${h1}.100 clsact
92 tc filter add dev ${h1}.100 egress protocol ipv4 \
93 flower ip_proto icmp action skbedit priority 3
94 tc filter add dev ${h1}.100 egress protocol ipv6 \
95 flower ip_proto icmpv6 action skbedit priority 3
98 vlans_destroy()
100 tc qdisc del dev ${h1}.100 clsact
102 h1_vlan_destroy 100
103 h2_vlan_destroy 100
106 switch_create()
108 ip link set ${swp1} up
109 ip link set ${swp2} up
111 # Ports should trust VLAN PCP even with vlan_filtering=0
112 ip link add br0 type bridge
113 ip link set ${swp1} master br0
114 ip link set ${swp2} master br0
115 ip link set br0 up
118 switch_destroy()
120 ip link del br0
123 setup_prepare()
125 vrf_prepare
127 h1_create
128 h2_create
129 switch_create
132 cleanup()
134 pre_cleanup
136 h2_destroy
137 h1_destroy
138 switch_destroy
140 vrf_cleanup
143 dscp_cs_to_tos()
145 local dscp_cs=$1
147 # https://datatracker.ietf.org/doc/html/rfc2474
148 # 4.2.2.1 The Class Selector Codepoints
149 echo $((${dscp_cs} << 5))
152 run_test()
154 local test_name=$1; shift
155 local if_name=$1; shift
156 local tc=$1; shift
157 local tos=$1; shift
158 local counter_name="rx_green_prio_${tc}"
159 local ipv4_before
160 local ipv4_after
161 local ipv6_before
162 local ipv6_after
164 ipv4_before=$(ethtool_stats_get ${swp1} "${counter_name}")
165 ping_do ${if_name} $H2_IPV4 "-Q ${tos}"
166 ipv4_after=$(ethtool_stats_get ${swp1} "${counter_name}")
168 if [ $((${ipv4_after} - ${ipv4_before})) -lt ${PING_COUNT} ]; then
169 RET=1
170 else
171 RET=0
173 log_test "IPv4 ${test_name}"
175 ipv6_before=$(ethtool_stats_get ${swp1} "${counter_name}")
176 ping_do ${if_name} $H2_IPV6 "-Q ${tos}"
177 ipv6_after=$(ethtool_stats_get ${swp1} "${counter_name}")
179 if [ $((${ipv6_after} - ${ipv6_before})) -lt ${PING_COUNT} ]; then
180 RET=1
181 else
182 RET=0
184 log_test "IPv6 ${test_name}"
187 port_default_prio_get()
189 local if_name=$1
190 local prio
192 prio="$(dcb -j app show dev ${if_name} default-prio | \
193 jq '.default_prio[]')"
194 if [ -z "${prio}" ]; then
195 prio=0
198 echo ${prio}
201 test_port_default()
203 local orig=$(port_default_prio_get ${swp1})
204 local dmac=$(mac_get ${h2})
206 dcb app replace dev ${swp1} default-prio 5
208 run_test "Port-default QoS classification" ${h1} 5 0
210 dcb app replace dev ${swp1} default-prio ${orig}
213 test_vlan_pcp()
215 vlans_prepare
217 run_test "Trusted VLAN PCP QoS classification" ${h1}.100 3 0
219 vlans_destroy
222 test_ip_dscp()
224 local port_default=$(port_default_prio_get ${swp1})
225 local tos=$(dscp_cs_to_tos 4)
227 dcb app add dev ${swp1} dscp-prio CS4:4
228 run_test "Trusted DSCP QoS classification" ${h1} 4 ${tos}
229 dcb app del dev ${swp1} dscp-prio CS4:4
231 vlans_prepare
232 run_test "Untrusted DSCP QoS classification follows VLAN PCP" \
233 ${h1}.100 3 ${tos}
234 vlans_destroy
236 run_test "Untrusted DSCP QoS classification follows port default" \
237 ${h1} ${port_default} ${tos}
240 trap cleanup EXIT
242 ALL_TESTS="
243 test_port_default
244 test_vlan_pcp
245 test_ip_dscp
248 setup_prepare
249 setup_wait
251 tests_run
253 exit $EXIT_STATUS