staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / qos_dscp_router.sh
blob9faf02e326270bc00ce20227f9f1b66ca748f8ca
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
36 lib_dir=$(dirname $0)/../../../net/forwarding
38 NUM_NETIFS=4
39 source $lib_dir/lib.sh
41 reprioritize()
43 local in=$1; shift
45 # This is based on rt_tos2priority in include/net/route.h. Assuming 1:1
46 # mapping between priorities and TOS, it yields a new priority for a
47 # packet with ingress priority of $in.
48 local -a reprio=(0 0 2 2 6 6 4 4)
50 echo ${reprio[$in]}
53 h1_create()
55 local dscp;
57 simple_if_init $h1 192.0.2.1/28
58 tc qdisc add dev $h1 clsact
59 dscp_capture_install $h1 0
60 ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
63 h1_destroy()
65 ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
66 dscp_capture_uninstall $h1 0
67 tc qdisc del dev $h1 clsact
68 simple_if_fini $h1 192.0.2.1/28
71 h2_create()
73 simple_if_init $h2 192.0.2.18/28
74 tc qdisc add dev $h2 clsact
75 dscp_capture_install $h2 0
76 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
79 h2_destroy()
81 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
82 dscp_capture_uninstall $h2 0
83 tc qdisc del dev $h2 clsact
84 simple_if_fini $h2 192.0.2.18/28
87 dscp_map()
89 local base=$1; shift
91 for prio in {0..7}; do
92 echo app=$prio,5,$((base + prio))
93 done
96 switch_create()
98 simple_if_init $swp1 192.0.2.2/28
99 __simple_if_init $swp2 v$swp1 192.0.2.17/28
101 lldptool -T -i $swp1 -V APP $(dscp_map 0) >/dev/null
102 lldptool -T -i $swp2 -V APP $(dscp_map 0) >/dev/null
103 lldpad_app_wait_set $swp1
104 lldpad_app_wait_set $swp2
107 switch_destroy()
109 lldptool -T -i $swp2 -V APP -d $(dscp_map 0) >/dev/null
110 lldptool -T -i $swp1 -V APP -d $(dscp_map 0) >/dev/null
111 lldpad_app_wait_del
113 __simple_if_fini $swp2 192.0.2.17/28
114 simple_if_fini $swp1 192.0.2.2/28
117 setup_prepare()
119 h1=${NETIFS[p1]}
120 swp1=${NETIFS[p2]}
122 swp2=${NETIFS[p3]}
123 h2=${NETIFS[p4]}
125 vrf_prepare
127 sysctl_set net.ipv4.ip_forward_update_priority 1
128 h1_create
129 h2_create
130 switch_create
133 cleanup()
135 pre_cleanup
137 switch_destroy
138 h2_destroy
139 h1_destroy
140 sysctl_restore net.ipv4.ip_forward_update_priority
142 vrf_cleanup
145 ping_ipv4()
147 ping_test $h1 192.0.2.18
150 dscp_ping_test()
152 local vrf_name=$1; shift
153 local sip=$1; shift
154 local dip=$1; shift
155 local prio=$1; shift
156 local reprio=$1; shift
157 local dev1=$1; shift
158 local dev2=$1; shift
160 local prio2=$($reprio $prio) # ICMP Request egress prio
161 local prio3=$($reprio $prio2) # ICMP Response egress prio
163 local dscp=$((prio << 2)) # ICMP Request ingress DSCP
164 local dscp2=$((prio2 << 2)) # ICMP Request egress DSCP
165 local dscp3=$((prio3 << 2)) # ICMP Response egress DSCP
167 RET=0
169 eval "local -A dev1_t0s=($(dscp_fetch_stats $dev1 0))"
170 eval "local -A dev2_t0s=($(dscp_fetch_stats $dev2 0))"
172 local ping_timeout=$((PING_TIMEOUT * 5))
173 ip vrf exec $vrf_name \
174 ${PING} -Q $dscp ${sip:+-I $sip} $dip \
175 -c 10 -i 0.5 -w $ping_timeout &> /dev/null
177 eval "local -A dev1_t1s=($(dscp_fetch_stats $dev1 0))"
178 eval "local -A dev2_t1s=($(dscp_fetch_stats $dev2 0))"
180 for i in {0..7}; do
181 local dscpi=$((i << 2))
182 local expect2=0
183 local expect3=0
185 if ((i == prio2)); then
186 expect2=10
188 if ((i == prio3)); then
189 expect3=10
192 local delta=$((dev2_t1s[$i] - dev2_t0s[$i]))
193 ((expect2 == delta))
194 check_err $? "DSCP $dscpi@$dev2: Expected to capture $expect2 packets, got $delta."
196 delta=$((dev1_t1s[$i] - dev1_t0s[$i]))
197 ((expect3 == delta))
198 check_err $? "DSCP $dscpi@$dev1: Expected to capture $expect3 packets, got $delta."
199 done
201 log_test "DSCP rewrite: $dscp-(prio $prio2)-$dscp2-(prio $prio3)-$dscp3"
204 __test_update()
206 local update=$1; shift
207 local reprio=$1; shift
209 sysctl_restore net.ipv4.ip_forward_update_priority
210 sysctl_set net.ipv4.ip_forward_update_priority $update
212 for prio in {0..7}; do
213 dscp_ping_test v$h1 192.0.2.1 192.0.2.18 $prio $reprio $h1 $h2
214 done
217 test_update()
219 __test_update 1 reprioritize
222 test_no_update()
224 __test_update 0 echo
227 trap cleanup EXIT
229 setup_prepare
230 setup_wait
232 tests_run
234 exit $EXIT_STATUS