drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / custom_multipath_hash.sh
blob7d531f7091e6f4a6f7a726f662d40ba8886711e0
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test traffic distribution between two paths when using custom hash policy.
6 # +--------------------------------+
7 # | H1 |
8 # | $h1 + |
9 # | 198.51.100.{2-253}/24 | |
10 # | 2001:db8:1::{2-fd}/64 | |
11 # +-------------------------|------+
12 # |
13 # +-------------------------|-------------------------+
14 # | SW1 | |
15 # | $rp1 + |
16 # | 198.51.100.1/24 |
17 # | 2001:db8:1::1/64 |
18 # | |
19 # | |
20 # | $rp11 + + $rp12 |
21 # | 192.0.2.1/28 | | 192.0.2.17/28 |
22 # | 2001:db8:2::1/64 | | 2001:db8:3::1/64 |
23 # +------------------|-------------|------------------+
24 # | |
25 # +------------------|-------------|------------------+
26 # | SW2 | | |
27 # | | | |
28 # | $rp21 + + $rp22 |
29 # | 192.0.2.2/28 192.0.2.18/28 |
30 # | 2001:db8:2::2/64 2001:db8:3::2/64 |
31 # | |
32 # | |
33 # | $rp2 + |
34 # | 203.0.113.1/24 | |
35 # | 2001:db8:4::1/64 | |
36 # +-------------------------|-------------------------+
37 # |
38 # +-------------------------|------+
39 # | H2 | |
40 # | $h2 + |
41 # | 203.0.113.{2-253}/24 |
42 # | 2001:db8:4::{2-fd}/64 |
43 # +--------------------------------+
45 ALL_TESTS="
46 ping_ipv4
47 ping_ipv6
48 custom_hash
51 NUM_NETIFS=8
52 source lib.sh
54 h1_create()
56 simple_if_init $h1 198.51.100.2/24 2001:db8:1::2/64
57 ip route add vrf v$h1 default via 198.51.100.1 dev $h1
58 ip -6 route add vrf v$h1 default via 2001:db8:1::1 dev $h1
61 h1_destroy()
63 ip -6 route del vrf v$h1 default
64 ip route del vrf v$h1 default
65 simple_if_fini $h1 198.51.100.2/24 2001:db8:1::2/64
68 sw1_create()
70 simple_if_init $rp1 198.51.100.1/24 2001:db8:1::1/64
71 __simple_if_init $rp11 v$rp1 192.0.2.1/28 2001:db8:2::1/64
72 __simple_if_init $rp12 v$rp1 192.0.2.17/28 2001:db8:3::1/64
74 ip route add vrf v$rp1 203.0.113.0/24 \
75 nexthop via 192.0.2.2 dev $rp11 \
76 nexthop via 192.0.2.18 dev $rp12
78 ip -6 route add vrf v$rp1 2001:db8:4::/64 \
79 nexthop via 2001:db8:2::2 dev $rp11 \
80 nexthop via 2001:db8:3::2 dev $rp12
83 sw1_destroy()
85 ip -6 route del vrf v$rp1 2001:db8:4::/64
87 ip route del vrf v$rp1 203.0.113.0/24
89 __simple_if_fini $rp12 192.0.2.17/28 2001:db8:3::1/64
90 __simple_if_fini $rp11 192.0.2.1/28 2001:db8:2::1/64
91 simple_if_fini $rp1 198.51.100.1/24 2001:db8:1::1/64
94 sw2_create()
96 simple_if_init $rp2 203.0.113.1/24 2001:db8:4::1/64
97 __simple_if_init $rp21 v$rp2 192.0.2.2/28 2001:db8:2::2/64
98 __simple_if_init $rp22 v$rp2 192.0.2.18/28 2001:db8:3::2/64
100 ip route add vrf v$rp2 198.51.100.0/24 \
101 nexthop via 192.0.2.1 dev $rp21 \
102 nexthop via 192.0.2.17 dev $rp22
104 ip -6 route add vrf v$rp2 2001:db8:1::/64 \
105 nexthop via 2001:db8:2::1 dev $rp21 \
106 nexthop via 2001:db8:3::1 dev $rp22
109 sw2_destroy()
111 ip -6 route del vrf v$rp2 2001:db8:1::/64
113 ip route del vrf v$rp2 198.51.100.0/24
115 __simple_if_fini $rp22 192.0.2.18/28 2001:db8:3::2/64
116 __simple_if_fini $rp21 192.0.2.2/28 2001:db8:2::2/64
117 simple_if_fini $rp2 203.0.113.1/24 2001:db8:4::1/64
120 h2_create()
122 simple_if_init $h2 203.0.113.2/24 2001:db8:4::2/64
123 ip route add vrf v$h2 default via 203.0.113.1 dev $h2
124 ip -6 route add vrf v$h2 default via 2001:db8:4::1 dev $h2
127 h2_destroy()
129 ip -6 route del vrf v$h2 default
130 ip route del vrf v$h2 default
131 simple_if_fini $h2 203.0.113.2/24 2001:db8:4::2/64
134 setup_prepare()
136 h1=${NETIFS[p1]}
138 rp1=${NETIFS[p2]}
140 rp11=${NETIFS[p3]}
141 rp21=${NETIFS[p4]}
143 rp12=${NETIFS[p5]}
144 rp22=${NETIFS[p6]}
146 rp2=${NETIFS[p7]}
148 h2=${NETIFS[p8]}
150 vrf_prepare
151 h1_create
152 sw1_create
153 sw2_create
154 h2_create
156 forwarding_enable
159 cleanup()
161 pre_cleanup
163 forwarding_restore
165 h2_destroy
166 sw2_destroy
167 sw1_destroy
168 h1_destroy
169 vrf_cleanup
172 ping_ipv4()
174 ping_test $h1 203.0.113.2
177 ping_ipv6()
179 ping6_test $h1 2001:db8:4::2
182 send_src_ipv4()
184 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
185 -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \
186 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
189 send_dst_ipv4()
191 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
192 -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \
193 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
196 send_src_udp4()
198 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
199 -A 198.51.100.2 -B 203.0.113.2 \
200 -d $MZ_DELAY -t udp "sp=0-32768,dp=30000"
203 send_dst_udp4()
205 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
206 -A 198.51.100.2 -B 203.0.113.2 \
207 -d $MZ_DELAY -t udp "sp=20000,dp=0-32768"
210 send_src_ipv6()
212 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
213 -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:4::2 \
214 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
217 send_dst_ipv6()
219 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
220 -A 2001:db8:1::2 -B "2001:db8:4::2-2001:db8:4::fd" \
221 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
224 send_flowlabel()
226 # Generate 16384 echo requests, each with a random flow label.
227 ip vrf exec v$h1 sh -c \
228 "for _ in {1..16384}; do \
229 $PING6 2001:db8:4::2 -F 0 -c 1 -q >/dev/null 2>&1; \
230 done"
233 send_src_udp6()
235 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
236 -A 2001:db8:1::2 -B 2001:db8:4::2 \
237 -d $MZ_DELAY -t udp "sp=0-32768,dp=30000"
240 send_dst_udp6()
242 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
243 -A 2001:db8:1::2 -B 2001:db8:4::2 \
244 -d $MZ_DELAY -t udp "sp=20000,dp=0-32768"
247 custom_hash_test()
249 local field="$1"; shift
250 local balanced="$1"; shift
251 local send_flows="$@"
253 RET=0
255 local t0_rp11=$(link_stats_tx_packets_get $rp11)
256 local t0_rp12=$(link_stats_tx_packets_get $rp12)
258 $send_flows
260 local t1_rp11=$(link_stats_tx_packets_get $rp11)
261 local t1_rp12=$(link_stats_tx_packets_get $rp12)
263 local d_rp11=$((t1_rp11 - t0_rp11))
264 local d_rp12=$((t1_rp12 - t0_rp12))
266 local diff=$((d_rp12 - d_rp11))
267 local sum=$((d_rp11 + d_rp12))
269 local pct=$(echo "$diff / $sum * 100" | bc -l)
270 local is_balanced=$(echo "-20 <= $pct && $pct <= 20" | bc)
272 [[ ( $is_balanced -eq 1 && $balanced == "balanced" ) ||
273 ( $is_balanced -eq 0 && $balanced == "unbalanced" ) ]]
274 check_err $? "Expected traffic to be $balanced, but it is not"
276 log_test "Multipath hash field: $field ($balanced)"
277 log_info "Packets sent on path1 / path2: $d_rp11 / $d_rp12"
280 custom_hash_v4()
282 log_info "Running IPv4 custom multipath hash tests"
284 sysctl_set net.ipv4.fib_multipath_hash_policy 3
286 # Prevent the neighbour table from overflowing, as different neighbour
287 # entries will be created on $ol4 when using different destination IPs.
288 sysctl_set net.ipv4.neigh.default.gc_thresh1 1024
289 sysctl_set net.ipv4.neigh.default.gc_thresh2 1024
290 sysctl_set net.ipv4.neigh.default.gc_thresh3 1024
292 sysctl_set net.ipv4.fib_multipath_hash_fields 0x0001
293 custom_hash_test "Source IP" "balanced" send_src_ipv4
294 custom_hash_test "Source IP" "unbalanced" send_dst_ipv4
296 sysctl_set net.ipv4.fib_multipath_hash_fields 0x0002
297 custom_hash_test "Destination IP" "balanced" send_dst_ipv4
298 custom_hash_test "Destination IP" "unbalanced" send_src_ipv4
300 sysctl_set net.ipv4.fib_multipath_hash_fields 0x0010
301 custom_hash_test "Source port" "balanced" send_src_udp4
302 custom_hash_test "Source port" "unbalanced" send_dst_udp4
304 sysctl_set net.ipv4.fib_multipath_hash_fields 0x0020
305 custom_hash_test "Destination port" "balanced" send_dst_udp4
306 custom_hash_test "Destination port" "unbalanced" send_src_udp4
308 sysctl_restore net.ipv4.neigh.default.gc_thresh3
309 sysctl_restore net.ipv4.neigh.default.gc_thresh2
310 sysctl_restore net.ipv4.neigh.default.gc_thresh1
312 sysctl_restore net.ipv4.fib_multipath_hash_policy
315 custom_hash_v6()
317 log_info "Running IPv6 custom multipath hash tests"
319 sysctl_set net.ipv6.fib_multipath_hash_policy 3
321 # Prevent the neighbour table from overflowing, as different neighbour
322 # entries will be created on $ol4 when using different destination IPs.
323 sysctl_set net.ipv6.neigh.default.gc_thresh1 1024
324 sysctl_set net.ipv6.neigh.default.gc_thresh2 1024
325 sysctl_set net.ipv6.neigh.default.gc_thresh3 1024
327 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0001
328 custom_hash_test "Source IP" "balanced" send_src_ipv6
329 custom_hash_test "Source IP" "unbalanced" send_dst_ipv6
331 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0002
332 custom_hash_test "Destination IP" "balanced" send_dst_ipv6
333 custom_hash_test "Destination IP" "unbalanced" send_src_ipv6
335 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0008
336 custom_hash_test "Flowlabel" "balanced" send_flowlabel
337 custom_hash_test "Flowlabel" "unbalanced" send_src_ipv6
339 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0010
340 custom_hash_test "Source port" "balanced" send_src_udp6
341 custom_hash_test "Source port" "unbalanced" send_dst_udp6
343 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0020
344 custom_hash_test "Destination port" "balanced" send_dst_udp6
345 custom_hash_test "Destination port" "unbalanced" send_src_udp6
347 sysctl_restore net.ipv6.neigh.default.gc_thresh3
348 sysctl_restore net.ipv6.neigh.default.gc_thresh2
349 sysctl_restore net.ipv6.neigh.default.gc_thresh1
351 sysctl_restore net.ipv6.fib_multipath_hash_policy
354 custom_hash()
356 # Test that when the hash policy is set to custom, traffic is
357 # distributed only according to the fields set in the
358 # fib_multipath_hash_fields sysctl.
360 # Each time set a different field and make sure traffic is only
361 # distributed when the field is changed in the packet stream.
362 custom_hash_v4
363 custom_hash_v6
366 trap cleanup EXIT
368 setup_prepare
369 setup_wait
370 tests_run
372 exit $EXIT_STATUS