WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / qos_dscp_router.sh
blob4cb2aa65278a01686a0c80c63e1680f85fefcec1
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test for DSCP prioritization in the router.
6 # With ip_forward_update_priority disabled, the packets are expected to keep
7 # their DSCP (which in this test uses only values 0..7) intact as they are
8 # forwarded by the switch. That is verified at $h2. ICMP responses are formed
9 # with the same DSCP as the requests, and likewise pass through the switch
10 # intact, which is verified at $h1.
12 # With ip_forward_update_priority enabled, router reprioritizes the packets
13 # according to the table in reprioritize(). Thus, say, DSCP 7 maps to priority
14 # 4, which on egress maps back to DSCP 4. The response packet then gets
15 # reprioritized to 6, getting DSCP 6 on egress.
17 # +----------------------+ +----------------------+
18 # | H1 | | H2 |
19 # | + $h1 | | $h2 + |
20 # | | 192.0.2.1/28 | | 192.0.2.18/28 | |
21 # +----|-----------------+ +----------------|-----+
22 # | |
23 # +----|----------------------------------------------------------------|-----+
24 # | SW | | |
25 # | + $swp1 $swp2 + |
26 # | 192.0.2.2/28 192.0.2.17/28 |
27 # | APP=0,5,0 .. 7,5,7 APP=0,5,0 .. 7,5,7 |
28 # +---------------------------------------------------------------------------+
30 ALL_TESTS="
31 ping_ipv4
32 test_update
33 test_no_update
34 test_pedit_norewrite
35 test_dscp_leftover
38 lib_dir=$(dirname $0)/../../../net/forwarding
40 NUM_NETIFS=4
41 source $lib_dir/lib.sh
43 reprioritize()
45 local in=$1; shift
47 # This is based on rt_tos2priority in include/net/route.h. Assuming 1:1
48 # mapping between priorities and TOS, it yields a new priority for a
49 # packet with ingress priority of $in.
50 local -a reprio=(0 0 2 2 6 6 4 4)
52 echo ${reprio[$in]}
55 zero()
57 echo 0
60 three()
62 echo 3
65 h1_create()
67 simple_if_init $h1 192.0.2.1/28
68 tc qdisc add dev $h1 clsact
69 dscp_capture_install $h1 0
70 ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
73 h1_destroy()
75 ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
76 dscp_capture_uninstall $h1 0
77 tc qdisc del dev $h1 clsact
78 simple_if_fini $h1 192.0.2.1/28
81 h2_create()
83 simple_if_init $h2 192.0.2.18/28
84 tc qdisc add dev $h2 clsact
85 dscp_capture_install $h2 0
86 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
89 h2_destroy()
91 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
92 dscp_capture_uninstall $h2 0
93 tc qdisc del dev $h2 clsact
94 simple_if_fini $h2 192.0.2.18/28
97 dscp_map()
99 local base=$1; shift
100 local prio
102 for prio in {0..7}; do
103 echo app=$prio,5,$((base + prio))
104 done
107 switch_create()
109 simple_if_init $swp1 192.0.2.2/28
110 __simple_if_init $swp2 v$swp1 192.0.2.17/28
112 tc qdisc add dev $swp1 clsact
113 tc qdisc add dev $swp2 clsact
115 lldptool -T -i $swp1 -V APP $(dscp_map 0) >/dev/null
116 lldptool -T -i $swp2 -V APP $(dscp_map 0) >/dev/null
117 lldpad_app_wait_set $swp1
118 lldpad_app_wait_set $swp2
121 switch_destroy()
123 lldptool -T -i $swp2 -V APP -d $(dscp_map 0) >/dev/null
124 lldptool -T -i $swp1 -V APP -d $(dscp_map 0) >/dev/null
125 lldpad_app_wait_del
127 tc qdisc del dev $swp2 clsact
128 tc qdisc del dev $swp1 clsact
130 __simple_if_fini $swp2 192.0.2.17/28
131 simple_if_fini $swp1 192.0.2.2/28
134 setup_prepare()
136 h1=${NETIFS[p1]}
137 swp1=${NETIFS[p2]}
139 swp2=${NETIFS[p3]}
140 h2=${NETIFS[p4]}
142 vrf_prepare
144 sysctl_set net.ipv4.ip_forward_update_priority 1
145 h1_create
146 h2_create
147 switch_create
150 cleanup()
152 pre_cleanup
154 switch_destroy
155 h2_destroy
156 h1_destroy
157 sysctl_restore net.ipv4.ip_forward_update_priority
159 vrf_cleanup
162 ping_ipv4()
164 ping_test $h1 192.0.2.18
167 dscp_ping_test()
169 local vrf_name=$1; shift
170 local sip=$1; shift
171 local dip=$1; shift
172 local prio=$1; shift
173 local reprio=$1; shift
174 local dev1=$1; shift
175 local dev2=$1; shift
176 local i
178 local prio2=$($reprio $prio) # ICMP Request egress prio
179 local prio3=$($reprio $prio2) # ICMP Response egress prio
181 local dscp=$((prio << 2)) # ICMP Request ingress DSCP
182 local dscp2=$((prio2 << 2)) # ICMP Request egress DSCP
183 local dscp3=$((prio3 << 2)) # ICMP Response egress DSCP
185 RET=0
187 eval "local -A dev1_t0s=($(dscp_fetch_stats $dev1 0))"
188 eval "local -A dev2_t0s=($(dscp_fetch_stats $dev2 0))"
190 local ping_timeout=$((PING_TIMEOUT * 5))
191 ip vrf exec $vrf_name \
192 ${PING} -Q $dscp ${sip:+-I $sip} $dip \
193 -c 10 -i 0.5 -w $ping_timeout &> /dev/null
195 eval "local -A dev1_t1s=($(dscp_fetch_stats $dev1 0))"
196 eval "local -A dev2_t1s=($(dscp_fetch_stats $dev2 0))"
198 for i in {0..7}; do
199 local dscpi=$((i << 2))
200 local expect2=0
201 local expect3=0
203 if ((i == prio2)); then
204 expect2=10
206 if ((i == prio3)); then
207 expect3=10
210 local delta=$((dev2_t1s[$i] - dev2_t0s[$i]))
211 ((expect2 == delta))
212 check_err $? "DSCP $dscpi@$dev2: Expected to capture $expect2 packets, got $delta."
214 delta=$((dev1_t1s[$i] - dev1_t0s[$i]))
215 ((expect3 == delta))
216 check_err $? "DSCP $dscpi@$dev1: Expected to capture $expect3 packets, got $delta."
217 done
219 log_test "DSCP rewrite: $dscp-(prio $prio2)-$dscp2-(prio $prio3)-$dscp3"
222 __test_update()
224 local update=$1; shift
225 local reprio=$1; shift
226 local prio
228 sysctl_restore net.ipv4.ip_forward_update_priority
229 sysctl_set net.ipv4.ip_forward_update_priority $update
231 for prio in {0..7}; do
232 dscp_ping_test v$h1 192.0.2.1 192.0.2.18 $prio $reprio $h1 $h2
233 done
236 test_update()
238 echo "Test net.ipv4.ip_forward_update_priority=1"
239 __test_update 1 reprioritize
242 test_no_update()
244 echo "Test net.ipv4.ip_forward_update_priority=0"
245 __test_update 0 echo
248 # Test that when DSCP is updated in pedit, the DSCP rewrite is turned off.
249 test_pedit_norewrite()
251 echo "Test no DSCP rewrite after DSCP is updated by pedit"
253 tc filter add dev $swp1 ingress handle 101 pref 1 prot ip flower \
254 action pedit ex munge ip dsfield set $((3 << 2)) retain 0xfc \
255 action skbedit priority 3
257 __test_update 0 three
259 tc filter del dev $swp1 ingress pref 1
262 # Test that when the last APP rule is removed, the prio->DSCP map is properly
263 # set to zeroes, and that the last APP rule does not stay active in the ASIC.
264 test_dscp_leftover()
266 echo "Test that last removed DSCP rule is deconfigured correctly"
268 lldptool -T -i $swp2 -V APP -d $(dscp_map 0) >/dev/null
269 lldpad_app_wait_del
271 __test_update 0 zero
273 lldptool -T -i $swp2 -V APP $(dscp_map 0) >/dev/null
274 lldpad_app_wait_set $swp2
277 trap cleanup EXIT
279 setup_prepare
280 setup_wait
282 tests_run
284 exit $EXIT_STATUS