2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS
="ping_ipv4 ping_ipv6 multipath_test"
11 ip link
set dev
$h1 master vrf-h1
13 ip link
set dev vrf-h1 up
14 ip link
set dev
$h1 up
16 ip address add
192.0.2.2/24 dev
$h1
17 ip address add
2001:db8
:1::2/64 dev
$h1
19 ip route add
198.51.100.0/24 vrf vrf-h1 nexthop via
192.0.2.1
20 ip route add
2001:db8
:2::/64 vrf vrf-h1 nexthop via
2001:db8
:1::1
25 ip route del
2001:db8
:2::/64 vrf vrf-h1
26 ip route del
198.51.100.0/24 vrf vrf-h1
28 ip address del
2001:db8
:1::2/64 dev
$h1
29 ip address del
192.0.2.2/24 dev
$h1
31 ip link
set dev
$h1 down
38 ip link
set dev
$h2 master vrf-h2
40 ip link
set dev vrf-h2 up
41 ip link
set dev
$h2 up
43 ip address add
198.51.100.2/24 dev
$h2
44 ip address add
2001:db8
:2::2/64 dev
$h2
46 ip route add
192.0.2.0/24 vrf vrf-h2 nexthop via
198.51.100.1
47 ip route add
2001:db8
:1::/64 vrf vrf-h2 nexthop via
2001:db8
:2::1
52 ip route del
2001:db8
:1::/64 vrf vrf-h2
53 ip route del
192.0.2.0/24 vrf vrf-h2
55 ip address del
2001:db8
:2::2/64 dev
$h2
56 ip address del
198.51.100.2/24 dev
$h2
58 ip link
set dev
$h2 down
65 ip link
set dev
$rp11 master vrf-r1
66 ip link
set dev
$rp12 master vrf-r1
67 ip link
set dev
$rp13 master vrf-r1
69 ip link
set dev vrf-r1 up
70 ip link
set dev
$rp11 up
71 ip link
set dev
$rp12 up
72 ip link
set dev
$rp13 up
74 ip address add
192.0.2.1/24 dev
$rp11
75 ip address add
2001:db8
:1::1/64 dev
$rp11
77 ip address add
169.254.2.12/24 dev
$rp12
78 ip address add fe80
:2::12/64 dev
$rp12
80 ip address add
169.254.3.13/24 dev
$rp13
81 ip address add fe80
:3::13/64 dev
$rp13
83 ip route add
198.51.100.0/24 vrf vrf-r1 \
84 nexthop via
169.254.2.22 dev
$rp12 \
85 nexthop via
169.254.3.23 dev
$rp13
86 ip route add
2001:db8
:2::/64 vrf vrf-r1 \
87 nexthop via fe80
:2::22 dev
$rp12 \
88 nexthop via fe80
:3::23 dev
$rp13
93 ip route del
2001:db8
:2::/64 vrf vrf-r1
94 ip route del
198.51.100.0/24 vrf vrf-r1
96 ip address del fe80
:3::13/64 dev
$rp13
97 ip address del
169.254.3.13/24 dev
$rp13
99 ip address del fe80
:2::12/64 dev
$rp12
100 ip address del
169.254.2.12/24 dev
$rp12
102 ip address del
2001:db8
:1::1/64 dev
$rp11
103 ip address del
192.0.2.1/24 dev
$rp11
105 ip link
set dev
$rp13 down
106 ip link
set dev
$rp12 down
107 ip link
set dev
$rp11 down
115 ip link
set dev
$rp21 master vrf-r2
116 ip link
set dev
$rp22 master vrf-r2
117 ip link
set dev
$rp23 master vrf-r2
119 ip link
set dev vrf-r2 up
120 ip link
set dev
$rp21 up
121 ip link
set dev
$rp22 up
122 ip link
set dev
$rp23 up
124 ip address add
198.51.100.1/24 dev
$rp21
125 ip address add
2001:db8
:2::1/64 dev
$rp21
127 ip address add
169.254.2.22/24 dev
$rp22
128 ip address add fe80
:2::22/64 dev
$rp22
130 ip address add
169.254.3.23/24 dev
$rp23
131 ip address add fe80
:3::23/64 dev
$rp23
133 ip route add
192.0.2.0/24 vrf vrf-r2 \
134 nexthop via
169.254.2.12 dev
$rp22 \
135 nexthop via
169.254.3.13 dev
$rp23
136 ip route add
2001:db8
:1::/64 vrf vrf-r2 \
137 nexthop via fe80
:2::12 dev
$rp22 \
138 nexthop via fe80
:3::13 dev
$rp23
143 ip route del
2001:db8
:1::/64 vrf vrf-r2
144 ip route del
192.0.2.0/24 vrf vrf-r2
146 ip address del fe80
:3::23/64 dev
$rp23
147 ip address del
169.254.3.23/24 dev
$rp23
149 ip address del fe80
:2::22/64 dev
$rp22
150 ip address del
169.254.2.22/24 dev
$rp22
152 ip address del
2001:db8
:2::1/64 dev
$rp21
153 ip address del
198.51.100.1/24 dev
$rp21
155 ip link
set dev
$rp23 down
156 ip link
set dev
$rp22 down
157 ip link
set dev
$rp21 down
167 local t0_rp12 t0_rp13 t1_rp12 t1_rp13
168 local packets_rp12 packets_rp13
170 # Transmit multiple flows from h1 to h2 and make sure they are
171 # distributed between both multipath links (rp12 and rp13)
172 # according to the configured weights.
173 sysctl_set net.ipv4.fib_multipath_hash_policy
1
174 ip route replace
198.51.100.0/24 vrf vrf-r1 \
175 nexthop via
169.254.2.22 dev
$rp12 weight
$weight_rp12 \
176 nexthop via
169.254.3.23 dev
$rp13 weight
$weight_rp13
178 t0_rp12
=$
(link_stats_tx_packets_get
$rp12)
179 t0_rp13
=$
(link_stats_tx_packets_get
$rp13)
181 ip vrf
exec vrf-h1
$MZ -q -p 64 -A 192.0.2.2 -B 198.51.100.2 \
182 -d 1msec
-t udp
"sp=1024,dp=0-32768"
184 t1_rp12
=$
(link_stats_tx_packets_get
$rp12)
185 t1_rp13
=$
(link_stats_tx_packets_get
$rp13)
187 let "packets_rp12 = $t1_rp12 - $t0_rp12"
188 let "packets_rp13 = $t1_rp13 - $t0_rp13"
189 multipath_eval
"$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
192 ip route replace
198.51.100.0/24 vrf vrf-r1 \
193 nexthop via
169.254.2.22 dev
$rp12 \
194 nexthop via
169.254.3.23 dev
$rp13
195 sysctl_restore net.ipv4.fib_multipath_hash_policy
203 local t0_rp12 t0_rp13 t1_rp12 t1_rp13
204 local packets_rp12 packets_rp13
206 # Transmit multiple flows from h1 to h2 and make sure they are
207 # distributed between both multipath links (rp12 and rp13)
208 # according to the configured weights.
209 sysctl_set net.ipv6.fib_multipath_hash_policy
1
211 ip route replace
2001:db8
:2::/64 vrf vrf-r1 \
212 nexthop via fe80
:2::22 dev
$rp12 weight
$weight_rp12 \
213 nexthop via fe80
:3::23 dev
$rp13 weight
$weight_rp13
215 t0_rp12
=$
(link_stats_tx_packets_get
$rp12)
216 t0_rp13
=$
(link_stats_tx_packets_get
$rp13)
218 $MZ $h1 -6 -q -p 64 -A 2001:db8
:1::2 -B 2001:db8
:2::2 \
219 -d 1msec
-t udp
"sp=1024,dp=0-32768"
221 t1_rp12
=$
(link_stats_tx_packets_get
$rp12)
222 t1_rp13
=$
(link_stats_tx_packets_get
$rp13)
224 let "packets_rp12 = $t1_rp12 - $t0_rp12"
225 let "packets_rp13 = $t1_rp13 - $t0_rp13"
226 multipath_eval
"$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
228 ip route replace
2001:db8
:2::/64 vrf vrf-r1 \
229 nexthop via fe80
:2::22 dev
$rp12 \
230 nexthop via fe80
:3::23 dev
$rp13
232 sysctl_restore net.ipv6.fib_multipath_hash_policy
240 local t0_rp12 t0_rp13 t1_rp12 t1_rp13
241 local packets_rp12 packets_rp13
243 ip route replace
2001:db8
:2::/64 vrf vrf-r1 \
244 nexthop via fe80
:2::22 dev
$rp12 weight
$weight_rp12 \
245 nexthop via fe80
:3::23 dev
$rp13 weight
$weight_rp13
247 t0_rp12
=$
(link_stats_tx_packets_get
$rp12)
248 t0_rp13
=$
(link_stats_tx_packets_get
$rp13)
250 # Generate 16384 echo requests, each with a random flow label.
251 for _
in $
(seq 1 16384); do
252 ip vrf
exec vrf-h1
$PING6 2001:db8
:2::2 -F 0 -c 1 -q &> /dev
/null
255 t1_rp12
=$
(link_stats_tx_packets_get
$rp12)
256 t1_rp13
=$
(link_stats_tx_packets_get
$rp13)
258 let "packets_rp12 = $t1_rp12 - $t0_rp12"
259 let "packets_rp13 = $t1_rp13 - $t0_rp13"
260 multipath_eval
"$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
262 ip route replace
2001:db8
:2::/64 vrf vrf-r1 \
263 nexthop via fe80
:2::22 dev
$rp12 \
264 nexthop via fe80
:3::23 dev
$rp13
269 log_info
"Running IPv4 multipath tests"
270 multipath4_test
"ECMP" 1 1
271 multipath4_test
"Weighted MP 2:1" 2 1
272 multipath4_test
"Weighted MP 11:45" 11 45
274 log_info
"Running IPv6 multipath tests"
275 multipath6_test
"ECMP" 1 1
276 multipath6_test
"Weighted MP 2:1" 2 1
277 multipath6_test
"Weighted MP 11:45" 11 45
279 log_info
"Running IPv6 L4 hash multipath tests"
280 multipath6_l4_test
"ECMP" 1 1
281 multipath6_l4_test
"Weighted MP 2:1" 2 1
282 multipath6_l4_test
"Weighted MP 11:45" 11 45
327 ping_test
$h1 198.51.100.2
332 ping6_test
$h1 2001:db8
:2::2