drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / router_mpath_seed.sh
blob314cb906c1eb2d5ee48fc1cff0376c7dd4173a55
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # +-------------------------+ +-------------------------+
5 # | H1 | | H2 |
6 # | $h1 + | | + $h2 |
7 # | 192.0.2.1/28 | | | | 192.0.2.34/28 |
8 # | 2001:db8:1::1/64 | | | | 2001:db8:3::2/64 |
9 # +-------------------|-----+ +-|-----------------------+
10 # | |
11 # +-------------------|-----+ +-|-----------------------+
12 # | R1 | | | | R2 |
13 # | $rp11 + | | + $rp21 |
14 # | 192.0.2.2/28 | | 192.0.2.33/28 |
15 # | 2001:db8:1::2/64 | | 2001:db8:3::1/64 |
16 # | | | |
17 # | $rp12 + | | + $rp22 |
18 # | 192.0.2.17/28 | | | | 192.0.2.18..27/28 |
19 # | 2001:db8:2::17/64 | | | | 2001:db8:2::18..27/64 |
20 # +-------------------|-----+ +-|-----------------------+
21 # | |
22 # `----------'
24 ALL_TESTS="
25 ping_ipv4
26 ping_ipv6
27 test_mpath_seed_stability_ipv4
28 test_mpath_seed_stability_ipv6
29 test_mpath_seed_get
30 test_mpath_seed_ipv4
31 test_mpath_seed_ipv6
33 NUM_NETIFS=6
34 source lib.sh
36 h1_create()
38 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
39 ip -4 route add 192.0.2.32/28 vrf v$h1 nexthop via 192.0.2.2
40 ip -6 route add 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::2
43 h1_destroy()
45 ip -6 route del 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::2
46 ip -4 route del 192.0.2.32/28 vrf v$h1 nexthop via 192.0.2.2
47 simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
50 h2_create()
52 simple_if_init $h2 192.0.2.34/28 2001:db8:3::2/64
53 ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.33
54 ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:3::1
57 h2_destroy()
59 ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:3::1
60 ip -4 route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.33
61 simple_if_fini $h2 192.0.2.34/28 2001:db8:3::2/64
64 router1_create()
66 simple_if_init $rp11 192.0.2.2/28 2001:db8:1::2/64
67 __simple_if_init $rp12 v$rp11 192.0.2.17/28 2001:db8:2::17/64
70 router1_destroy()
72 __simple_if_fini $rp12 192.0.2.17/28 2001:db8:2::17/64
73 simple_if_fini $rp11 192.0.2.2/28 2001:db8:1::2/64
76 router2_create()
78 simple_if_init $rp21 192.0.2.33/28 2001:db8:3::1/64
79 __simple_if_init $rp22 v$rp21 192.0.2.18/28 2001:db8:2::18/64
80 ip -4 route add 192.0.2.0/28 vrf v$rp21 nexthop via 192.0.2.17
81 ip -6 route add 2001:db8:1::/64 vrf v$rp21 nexthop via 2001:db8:2::17
84 router2_destroy()
86 ip -6 route del 2001:db8:1::/64 vrf v$rp21 nexthop via 2001:db8:2::17
87 ip -4 route del 192.0.2.0/28 vrf v$rp21 nexthop via 192.0.2.17
88 __simple_if_fini $rp22 192.0.2.18/28 2001:db8:2::18/64
89 simple_if_fini $rp21 192.0.2.33/28 2001:db8:3::1/64
92 nexthops_create()
94 local i
95 for i in $(seq 10); do
96 ip nexthop add id $((1000 + i)) via 192.0.2.18 dev $rp12
97 ip nexthop add id $((2000 + i)) via 2001:db8:2::18 dev $rp12
98 done
100 ip nexthop add id 1000 group $(seq -s / 1001 1010) hw_stats on
101 ip nexthop add id 2000 group $(seq -s / 2001 2010) hw_stats on
102 ip -4 route add 192.0.2.32/28 vrf v$rp11 nhid 1000
103 ip -6 route add 2001:db8:3::/64 vrf v$rp11 nhid 2000
106 nexthops_destroy()
108 local i
110 ip -6 route del 2001:db8:3::/64 vrf v$rp11 nhid 2000
111 ip -4 route del 192.0.2.32/28 vrf v$rp11 nhid 1000
112 ip nexthop del id 2000
113 ip nexthop del id 1000
115 for i in $(seq 10 -1 1); do
116 ip nexthop del id $((2000 + i))
117 ip nexthop del id $((1000 + i))
118 done
121 setup_prepare()
123 h1=${NETIFS[p1]}
124 rp11=${NETIFS[p2]}
126 rp12=${NETIFS[p3]}
127 rp22=${NETIFS[p4]}
129 rp21=${NETIFS[p5]}
130 h2=${NETIFS[p6]}
132 sysctl_save net.ipv4.fib_multipath_hash_seed
134 vrf_prepare
136 h1_create
137 h2_create
138 router1_create
139 router2_create
141 forwarding_enable
144 cleanup()
146 pre_cleanup
148 forwarding_restore
150 nexthops_destroy
151 router2_destroy
152 router1_destroy
153 h2_destroy
154 h1_destroy
156 vrf_cleanup
158 sysctl_restore net.ipv4.fib_multipath_hash_seed
161 ping_ipv4()
163 ping_test $h1 192.0.2.34
166 ping_ipv6()
168 ping6_test $h1 2001:db8:3::2
171 test_mpath_seed_get()
173 RET=0
175 local i
176 for ((i = 0; i < 100; i++)); do
177 local seed_w=$((999331 * i))
178 sysctl -qw net.ipv4.fib_multipath_hash_seed=$seed_w
179 local seed_r=$(sysctl -n net.ipv4.fib_multipath_hash_seed)
180 ((seed_r == seed_w))
181 check_err $? "mpath seed written as $seed_w, but read as $seed_r"
182 done
184 log_test "mpath seed set/get"
187 nh_stats_snapshot()
189 local group_id=$1; shift
191 ip -j -s -s nexthop show id $group_id |
192 jq -c '[.[].group_stats | sort_by(.id) | .[].packets]'
195 get_active_nh()
197 local s0=$1; shift
198 local s1=$1; shift
200 jq -n --argjson s0 "$s0" --argjson s1 "$s1" -f /dev/stdin <<-"EOF"
201 [range($s0 | length)] |
202 map($s1[.] - $s0[.]) |
203 map(if . > 8 then 1 else 0 end) |
204 index(1)
208 probe_nh()
210 local group_id=$1; shift
211 local -a mz=("$@")
213 local s0=$(nh_stats_snapshot $group_id)
214 "${mz[@]}"
215 local s1=$(nh_stats_snapshot $group_id)
217 get_active_nh "$s0" "$s1"
220 probe_seed()
222 local group_id=$1; shift
223 local seed=$1; shift
224 local -a mz=("$@")
226 sysctl -qw net.ipv4.fib_multipath_hash_seed=$seed
227 probe_nh "$group_id" "${mz[@]}"
230 test_mpath_seed()
232 local group_id=$1; shift
233 local what=$1; shift
234 local -a mz=("$@")
235 local ii
237 RET=0
239 local -a tally=(0 0 0 0 0 0 0 0 0 0)
240 for ((ii = 0; ii < 100; ii++)); do
241 local act=$(probe_seed $group_id $((999331 * ii)) "${mz[@]}")
242 ((tally[act]++))
243 done
245 local tally_str="${tally[@]}"
246 for ((ii = 0; ii < ${#tally[@]}; ii++)); do
247 ((tally[ii] > 0))
248 check_err $? "NH #$ii not hit, tally='$tally_str'"
249 done
251 log_test "mpath seed $what"
252 sysctl -qw net.ipv4.fib_multipath_hash_seed=0
255 test_mpath_seed_ipv4()
257 test_mpath_seed 1000 IPv4 \
258 $MZ $h1 -A 192.0.2.1 -B 192.0.2.34 -q \
259 -p 64 -d 0 -c 10 -t udp
262 test_mpath_seed_ipv6()
264 test_mpath_seed 2000 IPv6 \
265 $MZ -6 $h1 -A 2001:db8:1::1 -B 2001:db8:3::2 -q \
266 -p 64 -d 0 -c 10 -t udp
269 check_mpath_seed_stability()
271 local seed=$1; shift
272 local act_0=$1; shift
273 local act_1=$1; shift
275 ((act_0 == act_1))
276 check_err $? "seed $seed: active NH moved from $act_0 to $act_1 after seed change"
279 test_mpath_seed_stability()
281 local group_id=$1; shift
282 local what=$1; shift
283 local -a mz=("$@")
285 RET=0
287 local seed_0=0
288 local seed_1=3221338814
289 local seed_2=3735928559
291 # Initial active NH before touching the seed at all.
292 local act_ini=$(probe_nh $group_id "${mz[@]}")
294 local act_0_0=$(probe_seed $group_id $seed_0 "${mz[@]}")
295 local act_1_0=$(probe_seed $group_id $seed_1 "${mz[@]}")
296 local act_2_0=$(probe_seed $group_id $seed_2 "${mz[@]}")
298 local act_0_1=$(probe_seed $group_id $seed_0 "${mz[@]}")
299 local act_1_1=$(probe_seed $group_id $seed_1 "${mz[@]}")
300 local act_2_1=$(probe_seed $group_id $seed_2 "${mz[@]}")
302 check_mpath_seed_stability initial $act_ini $act_0_0
303 check_mpath_seed_stability $seed_0 $act_0_0 $act_0_1
304 check_mpath_seed_stability $seed_1 $act_1_0 $act_1_1
305 check_mpath_seed_stability $seed_2 $act_2_0 $act_2_1
307 log_test "mpath seed stability $what"
308 sysctl -qw net.ipv4.fib_multipath_hash_seed=0
311 test_mpath_seed_stability_ipv4()
313 test_mpath_seed_stability 1000 IPv4 \
314 $MZ $h1 -A 192.0.2.1 -B 192.0.2.34 -q \
315 -p 64 -d 0 -c 10 -t udp
318 test_mpath_seed_stability_ipv6()
320 test_mpath_seed_stability 2000 IPv6 \
321 $MZ -6 $h1 -A 2001:db8:1::1 -B 2001:db8:3::2 -q \
322 -p 64 -d 0 -c 10 -t udp
325 trap cleanup EXIT
327 setup_prepare
328 setup_wait
329 nexthops_create
331 tests_run
333 exit $EXIT_STATUS