drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / ip6gre_custom_multipath_hash.sh
blobe28b4a079e5250a44a70486932304a67ae6269dc
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test traffic distribution when there are multiple paths between an IPv6 GRE
5 # tunnel. The tunnel carries IPv4 and IPv6 traffic between multiple hosts.
6 # Multiple routes are in the underlay network. With the default multipath
7 # policy, SW2 will only look at the outer IP addresses, hence only a single
8 # route would be used.
10 # +--------------------------------+
11 # | H1 |
12 # | $h1 + |
13 # | 198.51.100.{2-253}/24 | |
14 # | 2001:db8:1::{2-fd}/64 | |
15 # +-------------------------|------+
16 # |
17 # +-------------------------|-------------------+
18 # | SW1 | |
19 # | $ol1 + |
20 # | 198.51.100.1/24 |
21 # | 2001:db8:1::1/64 |
22 # | |
23 # |+ g1 (ip6gre) |
24 # | loc=2001:db8:3::1 |
25 # | rem=2001:db8:3::2 -. |
26 # | tos=inherit | |
27 # | v |
28 # | + $ul1 |
29 # | | 2001:db8:10::1/64 |
30 # +---------------------|-----------------------+
31 # |
32 # +---------------------|-----------------------+
33 # | SW2 | |
34 # | $ul21 + |
35 # | 2001:db8:10::2/64 | |
36 # | | |
37 # ! __________________+___ |
38 # | / \ |
39 # | | | |
40 # | + $ul22.111 (vlan) + $ul22.222 (vlan) |
41 # | | 2001:db8:11::1/64 | 2001:db8:12::1/64 |
42 # | | | |
43 # +--|----------------------|-------------------+
44 # | |
45 # +--|----------------------|-------------------+
46 # | | | |
47 # | + $ul32.111 (vlan) + $ul32.222 (vlan) |
48 # | | 2001:db8:11::2/64 | 2001:db8:12::2/64 |
49 # | | | |
50 # | \__________________+___/ |
51 # | | |
52 # | | |
53 # | $ul31 + |
54 # | 2001:db8:13::1/64 | SW3 |
55 # +---------------------|-----------------------+
56 # |
57 # +---------------------|-----------------------+
58 # | + $ul4 |
59 # | ^ 2001:db8:13::2/64 |
60 # | | |
61 # |+ g2 (ip6gre) | |
62 # | loc=2001:db8:3::2 | |
63 # | rem=2001:db8:3::1 -' |
64 # | tos=inherit |
65 # | |
66 # | $ol4 + |
67 # | 203.0.113.1/24 | |
68 # | 2001:db8:2::1/64 | SW4 |
69 # +-------------------------|-------------------+
70 # |
71 # +-------------------------|------+
72 # | | |
73 # | $h2 + |
74 # | 203.0.113.{2-253}/24 |
75 # | 2001:db8:2::{2-fd}/64 H2 |
76 # +--------------------------------+
78 ALL_TESTS="
79 ping_ipv4
80 ping_ipv6
81 custom_hash
84 NUM_NETIFS=10
85 source lib.sh
87 h1_create()
89 simple_if_init $h1 198.51.100.2/24 2001:db8:1::2/64
90 ip route add vrf v$h1 default via 198.51.100.1 dev $h1
91 ip -6 route add vrf v$h1 default via 2001:db8:1::1 dev $h1
94 h1_destroy()
96 ip -6 route del vrf v$h1 default
97 ip route del vrf v$h1 default
98 simple_if_fini $h1 198.51.100.2/24 2001:db8:1::2/64
101 sw1_create()
103 simple_if_init $ol1 198.51.100.1/24 2001:db8:1::1/64
104 __simple_if_init $ul1 v$ol1 2001:db8:10::1/64
106 tunnel_create g1 ip6gre 2001:db8:3::1 2001:db8:3::2 tos inherit \
107 dev v$ol1
108 __simple_if_init g1 v$ol1 2001:db8:3::1/128
109 ip route add vrf v$ol1 2001:db8:3::2/128 via 2001:db8:10::2
111 ip route add vrf v$ol1 203.0.113.0/24 dev g1
112 ip -6 route add vrf v$ol1 2001:db8:2::/64 dev g1
115 sw1_destroy()
117 ip -6 route del vrf v$ol1 2001:db8:2::/64
118 ip route del vrf v$ol1 203.0.113.0/24
120 ip route del vrf v$ol1 2001:db8:3::2/128
121 __simple_if_fini g1 2001:db8:3::1/128
122 tunnel_destroy g1
124 __simple_if_fini $ul1 2001:db8:10::1/64
125 simple_if_fini $ol1 198.51.100.1/24 2001:db8:1::1/64
128 sw2_create()
130 simple_if_init $ul21 2001:db8:10::2/64
131 __simple_if_init $ul22 v$ul21
132 vlan_create $ul22 111 v$ul21 2001:db8:11::1/64
133 vlan_create $ul22 222 v$ul21 2001:db8:12::1/64
135 ip -6 route add vrf v$ul21 2001:db8:3::1/128 via 2001:db8:10::1
136 ip -6 route add vrf v$ul21 2001:db8:3::2/128 \
137 nexthop via 2001:db8:11::2 \
138 nexthop via 2001:db8:12::2
141 sw2_destroy()
143 ip -6 route del vrf v$ul21 2001:db8:3::2/128
144 ip -6 route del vrf v$ul21 2001:db8:3::1/128
146 vlan_destroy $ul22 222
147 vlan_destroy $ul22 111
148 __simple_if_fini $ul22
149 simple_if_fini $ul21 2001:db8:10::2/64
152 sw3_create()
154 simple_if_init $ul31 2001:db8:13::1/64
155 __simple_if_init $ul32 v$ul31
156 vlan_create $ul32 111 v$ul31 2001:db8:11::2/64
157 vlan_create $ul32 222 v$ul31 2001:db8:12::2/64
159 ip -6 route add vrf v$ul31 2001:db8:3::2/128 via 2001:db8:13::2
160 ip -6 route add vrf v$ul31 2001:db8:3::1/128 \
161 nexthop via 2001:db8:11::1 \
162 nexthop via 2001:db8:12::1
164 tc qdisc add dev $ul32 clsact
165 tc filter add dev $ul32 ingress pref 111 prot 802.1Q \
166 flower vlan_id 111 action pass
167 tc filter add dev $ul32 ingress pref 222 prot 802.1Q \
168 flower vlan_id 222 action pass
171 sw3_destroy()
173 tc qdisc del dev $ul32 clsact
175 ip -6 route del vrf v$ul31 2001:db8:3::1/128
176 ip -6 route del vrf v$ul31 2001:db8:3::2/128
178 vlan_destroy $ul32 222
179 vlan_destroy $ul32 111
180 __simple_if_fini $ul32
181 simple_if_fini $ul31 2001:db8:13::1/64
184 sw4_create()
186 simple_if_init $ol4 203.0.113.1/24 2001:db8:2::1/64
187 __simple_if_init $ul4 v$ol4 2001:db8:13::2/64
189 tunnel_create g2 ip6gre 2001:db8:3::2 2001:db8:3::1 tos inherit \
190 dev v$ol4
191 __simple_if_init g2 v$ol4 2001:db8:3::2/128
192 ip -6 route add vrf v$ol4 2001:db8:3::1/128 via 2001:db8:13::1
194 ip route add vrf v$ol4 198.51.100.0/24 dev g2
195 ip -6 route add vrf v$ol4 2001:db8:1::/64 dev g2
198 sw4_destroy()
200 ip -6 route del vrf v$ol4 2001:db8:1::/64
201 ip route del vrf v$ol4 198.51.100.0/24
203 ip -6 route del vrf v$ol4 2001:db8:3::1/128
204 __simple_if_fini g2 2001:db8:3::2/128
205 tunnel_destroy g2
207 __simple_if_fini $ul4 2001:db8:13::2/64
208 simple_if_fini $ol4 203.0.113.1/24 2001:db8:2::1/64
211 h2_create()
213 simple_if_init $h2 203.0.113.2/24 2001:db8:2::2/64
214 ip route add vrf v$h2 default via 203.0.113.1 dev $h2
215 ip -6 route add vrf v$h2 default via 2001:db8:2::1 dev $h2
218 h2_destroy()
220 ip -6 route del vrf v$h2 default
221 ip route del vrf v$h2 default
222 simple_if_fini $h2 203.0.113.2/24 2001:db8:2::2/64
225 setup_prepare()
227 h1=${NETIFS[p1]}
229 ol1=${NETIFS[p2]}
230 ul1=${NETIFS[p3]}
232 ul21=${NETIFS[p4]}
233 ul22=${NETIFS[p5]}
235 ul32=${NETIFS[p6]}
236 ul31=${NETIFS[p7]}
238 ul4=${NETIFS[p8]}
239 ol4=${NETIFS[p9]}
241 h2=${NETIFS[p10]}
243 vrf_prepare
244 h1_create
245 sw1_create
246 sw2_create
247 sw3_create
248 sw4_create
249 h2_create
251 forwarding_enable
254 cleanup()
256 pre_cleanup
258 forwarding_restore
260 h2_destroy
261 sw4_destroy
262 sw3_destroy
263 sw2_destroy
264 sw1_destroy
265 h1_destroy
266 vrf_cleanup
269 ping_ipv4()
271 ping_test $h1 203.0.113.2
274 ping_ipv6()
276 ping6_test $h1 2001:db8:2::2
279 send_src_ipv4()
281 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
282 -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \
283 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
286 send_dst_ipv4()
288 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
289 -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \
290 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
293 send_src_udp4()
295 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
296 -A 198.51.100.2 -B 203.0.113.2 \
297 -d $MZ_DELAY -t udp "sp=0-32768,dp=30000"
300 send_dst_udp4()
302 ip vrf exec v$h1 $MZ $h1 -q -p 64 \
303 -A 198.51.100.2 -B 203.0.113.2 \
304 -d $MZ_DELAY -t udp "sp=20000,dp=0-32768"
307 send_src_ipv6()
309 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
310 -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:2::2 \
311 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
314 send_dst_ipv6()
316 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
317 -A 2001:db8:1::2 -B "2001:db8:2::2-2001:db8:2::fd" \
318 -d $MZ_DELAY -c 50 -t udp "sp=20000,dp=30000"
321 send_flowlabel()
323 # Generate 16384 echo requests, each with a random flow label.
324 ip vrf exec v$h1 sh -c \
325 "for _ in {1..16384}; do \
326 $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1; \
327 done"
330 send_src_udp6()
332 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
333 -A 2001:db8:1::2 -B 2001:db8:2::2 \
334 -d $MZ_DELAY -t udp "sp=0-32768,dp=30000"
337 send_dst_udp6()
339 ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \
340 -A 2001:db8:1::2 -B 2001:db8:2::2 \
341 -d $MZ_DELAY -t udp "sp=20000,dp=0-32768"
344 custom_hash_test()
346 local field="$1"; shift
347 local balanced="$1"; shift
348 local send_flows="$@"
350 RET=0
352 local t0_111=$(tc_rule_stats_get $ul32 111 ingress)
353 local t0_222=$(tc_rule_stats_get $ul32 222 ingress)
355 $send_flows
357 local t1_111=$(tc_rule_stats_get $ul32 111 ingress)
358 local t1_222=$(tc_rule_stats_get $ul32 222 ingress)
360 local d111=$((t1_111 - t0_111))
361 local d222=$((t1_222 - t0_222))
363 local diff=$((d222 - d111))
364 local sum=$((d111 + d222))
366 local pct=$(echo "$diff / $sum * 100" | bc -l)
367 local is_balanced=$(echo "-20 <= $pct && $pct <= 20" | bc)
369 [[ ( $is_balanced -eq 1 && $balanced == "balanced" ) ||
370 ( $is_balanced -eq 0 && $balanced == "unbalanced" ) ]]
371 check_err $? "Expected traffic to be $balanced, but it is not"
373 log_test "Multipath hash field: $field ($balanced)"
374 log_info "Packets sent on path1 / path2: $d111 / $d222"
377 custom_hash_v4()
379 log_info "Running IPv4 overlay custom multipath hash tests"
381 # Prevent the neighbour table from overflowing, as different neighbour
382 # entries will be created on $ol4 when using different destination IPs.
383 sysctl_set net.ipv4.neigh.default.gc_thresh1 1024
384 sysctl_set net.ipv4.neigh.default.gc_thresh2 1024
385 sysctl_set net.ipv4.neigh.default.gc_thresh3 1024
387 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0040
388 custom_hash_test "Inner source IP" "balanced" send_src_ipv4
389 custom_hash_test "Inner source IP" "unbalanced" send_dst_ipv4
391 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0080
392 custom_hash_test "Inner destination IP" "balanced" send_dst_ipv4
393 custom_hash_test "Inner destination IP" "unbalanced" send_src_ipv4
395 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0400
396 custom_hash_test "Inner source port" "balanced" send_src_udp4
397 custom_hash_test "Inner source port" "unbalanced" send_dst_udp4
399 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0800
400 custom_hash_test "Inner destination port" "balanced" send_dst_udp4
401 custom_hash_test "Inner destination port" "unbalanced" send_src_udp4
403 sysctl_restore net.ipv4.neigh.default.gc_thresh3
404 sysctl_restore net.ipv4.neigh.default.gc_thresh2
405 sysctl_restore net.ipv4.neigh.default.gc_thresh1
408 custom_hash_v6()
410 log_info "Running IPv6 overlay custom multipath hash tests"
412 # Prevent the neighbour table from overflowing, as different neighbour
413 # entries will be created on $ol4 when using different destination IPs.
414 sysctl_set net.ipv6.neigh.default.gc_thresh1 1024
415 sysctl_set net.ipv6.neigh.default.gc_thresh2 1024
416 sysctl_set net.ipv6.neigh.default.gc_thresh3 1024
418 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0040
419 custom_hash_test "Inner source IP" "balanced" send_src_ipv6
420 custom_hash_test "Inner source IP" "unbalanced" send_dst_ipv6
422 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0080
423 custom_hash_test "Inner destination IP" "balanced" send_dst_ipv6
424 custom_hash_test "Inner destination IP" "unbalanced" send_src_ipv6
426 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0200
427 custom_hash_test "Inner flowlabel" "balanced" send_flowlabel
428 custom_hash_test "Inner flowlabel" "unbalanced" send_src_ipv6
430 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0400
431 custom_hash_test "Inner source port" "balanced" send_src_udp6
432 custom_hash_test "Inner source port" "unbalanced" send_dst_udp6
434 sysctl_set net.ipv6.fib_multipath_hash_fields 0x0800
435 custom_hash_test "Inner destination port" "balanced" send_dst_udp6
436 custom_hash_test "Inner destination port" "unbalanced" send_src_udp6
438 sysctl_restore net.ipv6.neigh.default.gc_thresh3
439 sysctl_restore net.ipv6.neigh.default.gc_thresh2
440 sysctl_restore net.ipv6.neigh.default.gc_thresh1
443 custom_hash()
445 # Test that when the hash policy is set to custom, traffic is
446 # distributed only according to the fields set in the
447 # fib_multipath_hash_fields sysctl.
449 # Each time set a different field and make sure traffic is only
450 # distributed when the field is changed in the packet stream.
452 sysctl_set net.ipv6.fib_multipath_hash_policy 3
454 custom_hash_v4
455 custom_hash_v6
457 sysctl_restore net.ipv6.fib_multipath_hash_policy
460 trap cleanup EXIT
462 setup_prepare
463 setup_wait
464 tests_run
466 exit $EXIT_STATUS