2 # SPDX-License-Identifier: GPL-2.0
4 # Test traffic distribution between two paths when using custom hash policy.
6 # +--------------------------------+
9 # | 198.51.100.{2-253}/24 | |
10 # | 2001:db8:1::{2-fd}/64 | |
11 # +-------------------------|------+
13 # +-------------------------|-------------------------+
17 # | 2001:db8:1::1/64 |
21 # | 192.0.2.1/28 | | 192.0.2.17/28 |
22 # | 2001:db8:2::1/64 | | 2001:db8:3::1/64 |
23 # +------------------|-------------|------------------+
25 # +------------------|-------------|------------------+
29 # | 192.0.2.2/28 192.0.2.18/28 |
30 # | 2001:db8:2::2/64 2001:db8:3::2/64 |
34 # | 203.0.113.1/24 | |
35 # | 2001:db8:4::1/64 | |
36 # +-------------------------|-------------------------+
38 # +-------------------------|------+
41 # | 203.0.113.{2-253}/24 |
42 # | 2001:db8:4::{2-fd}/64 |
43 # +--------------------------------+
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
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
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
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
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
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
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
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
174 ping_test $h1 203.0.113.2
179 ping6_test $h1 2001:db8:4::2
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"
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"
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"
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"
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"
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"
226 # Generate 16384 echo requests, each with a random flow label.
227 for _ in $(seq 1 16384); do
229 $PING6 2001:db8:4::2 -F 0 -c 1 -q >/dev/null 2>&1
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"
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"
249 local field="$1"; shift
250 local balanced="$1"; shift
251 local send_flows="$@"
255 local t0_rp11=$(link_stats_tx_packets_get $rp11)
256 local t0_rp12=$(link_stats_tx_packets_get $rp12)
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"
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
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
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.