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
10 # +--------------------------------+
13 # | 198.51.100.{2-253}/24 | |
14 # | 2001:db8:1::{2-fd}/64 | |
15 # +-------------------------|------+
17 # +-------------------------|-------------------+
21 # | 2001:db8:1::1/64 |
24 # | loc=2001:db8:3::1 |
25 # | rem=2001:db8:3::2 -. |
29 # | | 2001:db8:10::1/64 |
30 # +---------------------|-----------------------+
32 # +---------------------|-----------------------+
35 # | 2001:db8:10::2/64 | |
37 # ! __________________+___ |
40 # | + $ul22.111 (vlan) + $ul22.222 (vlan) |
41 # | | 2001:db8:11::1/64 | 2001:db8:12::1/64 |
43 # +--|----------------------|-------------------+
45 # +--|----------------------|-------------------+
47 # | + $ul32.111 (vlan) + $ul32.222 (vlan) |
48 # | | 2001:db8:11::2/64 | 2001:db8:12::2/64 |
50 # | \__________________+___/ |
54 # | 2001:db8:13::1/64 | SW3 |
55 # +---------------------|-----------------------+
57 # +---------------------|-----------------------+
59 # | ^ 2001:db8:13::2/64 |
62 # | loc=2001:db8:3::2 | |
63 # | rem=2001:db8:3::1 -' |
67 # | 203.0.113.1/24 | |
68 # | 2001:db8:2::1/64 | SW4 |
69 # +-------------------------|-------------------+
71 # +-------------------------|------+
74 # | 203.0.113.{2-253}/24 |
75 # | 2001:db8:2::{2-fd}/64 H2 |
76 # +--------------------------------+
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
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
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 \
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
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
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
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
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
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
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
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 \
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
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
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
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
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
271 ping_test $h1 203.0.113.2
276 ping6_test $h1 2001:db8:2::2
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"
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"
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"
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"
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"
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"
323 # Generate 16384 echo requests, each with a random flow label.
324 for _ in $(seq 1 16384); do
326 $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1
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"
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"
346 local field="$1"; shift
347 local balanced="$1"; shift
348 local send_flows="$@"
352 local t0_111=$(tc_rule_stats_get $ul32 111 ingress)
353 local t0_222=$(tc_rule_stats_get $ul32 222 ingress)
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"
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
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
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
457 sysctl_restore net.ipv6.fib_multipath_hash_policy