2 # SPDX-License-Identifier: GPL-2.0
4 # Test traffic distribution when there are multiple paths between an IPv4 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 |
25 # | rem=192.0.2.2 --. |
30 # +---------------------|----------------------+
32 # +---------------------|----------------------+
37 # ! __________________+___ |
40 # | + $ul22.111 (vlan) + $ul22.222 (vlan) |
41 # | | 192.0.2.33/28 | 192.0.2.49/28 |
43 # +--|----------------------|------------------+
45 # +--|----------------------|------------------+
47 # | + $ul32.111 (vlan) + $ul32.222 (vlan) |
48 # | | 192.0.2.34/28 | 192.0.2.50/28 |
50 # | \__________________+___/ |
54 # | 192.0.2.65/28 | SW3 |
55 # +---------------------|----------------------+
57 # +---------------------|----------------------+
63 # | rem=192.0.2.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 192.0.2.17/28
106 tunnel_create g1 gre
192.0.2.1 192.0.2.2 tos inherit dev v
$ol1
107 __simple_if_init g1 v
$ol1 192.0.2.1/32
108 ip route add vrf v
$ol1 192.0.2.2/32 via
192.0.2.18
110 ip route add vrf v
$ol1 203.0.113.0/24 dev g1
111 ip
-6 route add vrf v
$ol1 2001:db8
:2::/64 dev g1
116 ip
-6 route del vrf v
$ol1 2001:db8
:2::/64
117 ip route del vrf v
$ol1 203.0.113.0/24
119 ip route del vrf v
$ol1 192.0.2.2/32
120 __simple_if_fini g1
192.0.2.1/32
123 __simple_if_fini
$ul1 192.0.2.17/28
124 simple_if_fini
$ol1 198.51.100.1/24 2001:db8
:1::1/64
129 simple_if_init
$ul21 192.0.2.18/28
130 __simple_if_init
$ul22 v
$ul21
131 vlan_create
$ul22 111 v
$ul21 192.0.2.33/28
132 vlan_create
$ul22 222 v
$ul21 192.0.2.49/28
134 ip route add vrf v
$ul21 192.0.2.1/32 via
192.0.2.17
135 ip route add vrf v
$ul21 192.0.2.2/32 \
136 nexthop via
192.0.2.34 \
137 nexthop via
192.0.2.50
142 ip route del vrf v
$ul21 192.0.2.2/32
143 ip route del vrf v
$ul21 192.0.2.1/32
145 vlan_destroy
$ul22 222
146 vlan_destroy
$ul22 111
147 __simple_if_fini
$ul22
148 simple_if_fini
$ul21 192.0.2.18/28
153 simple_if_init
$ul31 192.0.2.65/28
154 __simple_if_init
$ul32 v
$ul31
155 vlan_create
$ul32 111 v
$ul31 192.0.2.34/28
156 vlan_create
$ul32 222 v
$ul31 192.0.2.50/28
158 ip route add vrf v
$ul31 192.0.2.2/32 via
192.0.2.66
159 ip route add vrf v
$ul31 192.0.2.1/32 \
160 nexthop via
192.0.2.33 \
161 nexthop via
192.0.2.49
163 tc qdisc add dev
$ul32 clsact
164 tc filter add dev
$ul32 ingress pref
111 prot
802.1Q \
165 flower vlan_id
111 action pass
166 tc filter add dev
$ul32 ingress pref
222 prot
802.1Q \
167 flower vlan_id
222 action pass
172 tc qdisc del dev
$ul32 clsact
174 ip route del vrf v
$ul31 192.0.2.1/32
175 ip route del vrf v
$ul31 192.0.2.2/32
177 vlan_destroy
$ul32 222
178 vlan_destroy
$ul32 111
179 __simple_if_fini
$ul32
180 simple_if_fini
$ul31 192.0.2.65/28
185 simple_if_init
$ol4 203.0.113.1/24 2001:db8
:2::1/64
186 __simple_if_init
$ul4 v
$ol4 192.0.2.66/28
188 tunnel_create g2 gre
192.0.2.2 192.0.2.1 tos inherit dev v
$ol4
189 __simple_if_init g2 v
$ol4 192.0.2.2/32
190 ip route add vrf v
$ol4 192.0.2.1/32 via
192.0.2.65
192 ip route add vrf v
$ol4 198.51.100.0/24 dev g2
193 ip
-6 route add vrf v
$ol4 2001:db8
:1::/64 dev g2
198 ip
-6 route del vrf v
$ol4 2001:db8
:1::/64
199 ip route del vrf v
$ol4 198.51.100.0/24
201 ip route del vrf v
$ol4 192.0.2.1/32
202 __simple_if_fini g2
192.0.2.2/32
205 __simple_if_fini
$ul4 192.0.2.66/28
206 simple_if_fini
$ol4 203.0.113.1/24 2001:db8
:2::1/64
211 simple_if_init
$h2 203.0.113.2/24 2001:db8
:2::2/64
212 ip route add vrf v
$h2 default via
203.0.113.1 dev
$h2
213 ip
-6 route add vrf v
$h2 default via
2001:db8
:2::1 dev
$h2
218 ip
-6 route del vrf v
$h2 default
219 ip route del vrf v
$h2 default
220 simple_if_fini
$h2 203.0.113.2/24 2001:db8
:2::2/64
269 ping_test
$h1 203.0.113.2
274 ping6_test
$h1 2001:db8
:2::2
279 ip vrf
exec v
$h1 $MZ $h1 -q -p 64 \
280 -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \
281 -d $MZ_DELAY -c 50 -t udp
"sp=20000,dp=30000"
286 ip vrf
exec v
$h1 $MZ $h1 -q -p 64 \
287 -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \
288 -d $MZ_DELAY -c 50 -t udp
"sp=20000,dp=30000"
293 ip vrf
exec v
$h1 $MZ $h1 -q -p 64 \
294 -A 198.51.100.2 -B 203.0.113.2 \
295 -d $MZ_DELAY -t udp
"sp=0-32768,dp=30000"
300 ip vrf
exec v
$h1 $MZ $h1 -q -p 64 \
301 -A 198.51.100.2 -B 203.0.113.2 \
302 -d $MZ_DELAY -t udp
"sp=20000,dp=0-32768"
307 ip vrf
exec v
$h1 $MZ -6 $h1 -q -p 64 \
308 -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8
:2::2 \
309 -d $MZ_DELAY -c 50 -t udp
"sp=20000,dp=30000"
314 ip vrf
exec v
$h1 $MZ -6 $h1 -q -p 64 \
315 -A 2001:db8
:1::2 -B "2001:db8:2::2-2001:db8:2::fd" \
316 -d $MZ_DELAY -c 50 -t udp
"sp=20000,dp=30000"
321 # Generate 16384 echo requests, each with a random flow label.
322 ip vrf
exec v
$h1 sh
-c \
323 "for _ in {1..16384}; do \
324 $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1; \
330 ip vrf
exec v
$h1 $MZ -6 $h1 -q -p 64 \
331 -A 2001:db8
:1::2 -B 2001:db8
:2::2 \
332 -d $MZ_DELAY -t udp
"sp=0-32768,dp=30000"
337 ip vrf
exec v
$h1 $MZ -6 $h1 -q -p 64 \
338 -A 2001:db8
:1::2 -B 2001:db8
:2::2 \
339 -d $MZ_DELAY -t udp
"sp=20000,dp=0-32768"
344 local field
="$1"; shift
345 local balanced
="$1"; shift
346 local send_flows
="$@"
350 local t0_111
=$
(tc_rule_stats_get
$ul32 111 ingress
)
351 local t0_222
=$
(tc_rule_stats_get
$ul32 222 ingress
)
355 local t1_111
=$
(tc_rule_stats_get
$ul32 111 ingress
)
356 local t1_222
=$
(tc_rule_stats_get
$ul32 222 ingress
)
358 local d111
=$
((t1_111
- t0_111
))
359 local d222
=$
((t1_222
- t0_222
))
361 local diff=$
((d222
- d111
))
362 local sum=$
((d111
+ d222
))
364 local pct
=$
(echo "$diff / $sum * 100" |
bc -l)
365 local is_balanced
=$
(echo "-20 <= $pct && $pct <= 20" |
bc)
367 [[ ( $is_balanced -eq 1 && $balanced == "balanced" ) ||
368 ( $is_balanced -eq 0 && $balanced == "unbalanced" ) ]]
369 check_err $?
"Expected traffic to be $balanced, but it is not"
371 log_test
"Multipath hash field: $field ($balanced)"
372 log_info
"Packets sent on path1 / path2: $d111 / $d222"
377 log_info
"Running IPv4 overlay custom multipath hash tests"
379 # Prevent the neighbour table from overflowing, as different neighbour
380 # entries will be created on $ol4 when using different destination IPs.
381 sysctl_set net.ipv4.neigh.default.gc_thresh1
1024
382 sysctl_set net.ipv4.neigh.default.gc_thresh2
1024
383 sysctl_set net.ipv4.neigh.default.gc_thresh3
1024
385 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0040
386 custom_hash_test
"Inner source IP" "balanced" send_src_ipv4
387 custom_hash_test
"Inner source IP" "unbalanced" send_dst_ipv4
389 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0080
390 custom_hash_test
"Inner destination IP" "balanced" send_dst_ipv4
391 custom_hash_test
"Inner destination IP" "unbalanced" send_src_ipv4
393 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0400
394 custom_hash_test
"Inner source port" "balanced" send_src_udp4
395 custom_hash_test
"Inner source port" "unbalanced" send_dst_udp4
397 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0800
398 custom_hash_test
"Inner destination port" "balanced" send_dst_udp4
399 custom_hash_test
"Inner destination port" "unbalanced" send_src_udp4
401 sysctl_restore net.ipv4.neigh.default.gc_thresh3
402 sysctl_restore net.ipv4.neigh.default.gc_thresh2
403 sysctl_restore net.ipv4.neigh.default.gc_thresh1
408 log_info
"Running IPv6 overlay custom multipath hash tests"
410 # Prevent the neighbour table from overflowing, as different neighbour
411 # entries will be created on $ol4 when using different destination IPs.
412 sysctl_set net.ipv6.neigh.default.gc_thresh1
1024
413 sysctl_set net.ipv6.neigh.default.gc_thresh2
1024
414 sysctl_set net.ipv6.neigh.default.gc_thresh3
1024
416 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0040
417 custom_hash_test
"Inner source IP" "balanced" send_src_ipv6
418 custom_hash_test
"Inner source IP" "unbalanced" send_dst_ipv6
420 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0080
421 custom_hash_test
"Inner destination IP" "balanced" send_dst_ipv6
422 custom_hash_test
"Inner destination IP" "unbalanced" send_src_ipv6
424 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0200
425 custom_hash_test
"Inner flowlabel" "balanced" send_flowlabel
426 custom_hash_test
"Inner flowlabel" "unbalanced" send_src_ipv6
428 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0400
429 custom_hash_test
"Inner source port" "balanced" send_src_udp6
430 custom_hash_test
"Inner source port" "unbalanced" send_dst_udp6
432 sysctl_set net.ipv4.fib_multipath_hash_fields
0x0800
433 custom_hash_test
"Inner destination port" "balanced" send_dst_udp6
434 custom_hash_test
"Inner destination port" "unbalanced" send_src_udp6
436 sysctl_restore net.ipv6.neigh.default.gc_thresh3
437 sysctl_restore net.ipv6.neigh.default.gc_thresh2
438 sysctl_restore net.ipv6.neigh.default.gc_thresh1
443 # Test that when the hash policy is set to custom, traffic is
444 # distributed only according to the fields set in the
445 # fib_multipath_hash_fields sysctl.
447 # Each time set a different field and make sure traffic is only
448 # distributed when the field is changed in the packet stream.
450 sysctl_set net.ipv4.fib_multipath_hash_policy
3
455 sysctl_restore net.ipv4.fib_multipath_hash_policy