@@ -158,6 +158,82 @@ router2_destroy()
158158 vrf_destroy " vrf-r2"
159159}
160160
161+ multipath_eval ()
162+ {
163+ local weight_rp12=$1
164+ local weight_rp13=$2
165+ local packets_rp12=$3
166+ local packets_rp13=$4
167+ local weights_ratio packets_ratio diff
168+
169+ RET=0
170+
171+ if [[ " $weight_rp12 " -gt " $weight_rp13 " ]]; then
172+ weights_ratio=$( echo " scale=2; $weight_rp12 / $weight_rp13 " \
173+ | bc -l)
174+ packets_ratio=$( echo " scale=2; $packets_rp12 / $packets_rp13 " \
175+ | bc -l)
176+ else
177+ weights_ratio=$( echo " scale=2; $weight_rp13 / $weight_rp12 " | \
178+ bc -l)
179+ packets_ratio=$( echo " scale=2; $packets_rp13 / $packets_rp12 " | \
180+ bc -l)
181+ fi
182+
183+ diff=$( echo $weights_ratio - $packets_ratio | bc -l)
184+ diff=${diff# -}
185+
186+ test " $( echo " $diff / $weights_ratio > 0.1" | bc -l) " -eq 0
187+ check_err $? " Too large discrepancy between expected and measured ratios"
188+ log_test " Multipath"
189+ log_info " Expected ratio $weights_ratio Measured ratio $packets_ratio "
190+ }
191+
192+ multipath4_test ()
193+ {
194+ local weight_rp12=$1
195+ local weight_rp13=$2
196+ local t0_rp12 t0_rp13 t1_rp12 t1_rp13
197+ local packets_rp12 packets_rp13
198+ local hash_policy
199+
200+ # Transmit multiple flows from h1 to h2 and make sure they are
201+ # distributed between both multipath links (rp12 and rp13)
202+ # according to the configured weights.
203+ hash_policy=$( sysctl -n net.ipv4.fib_multipath_hash_policy)
204+ sysctl -q -w net.ipv4.fib_multipath_hash_policy=1
205+ ip route replace 198.51.100.0/24 vrf vrf-r1 \
206+ nexthop via 169.254.2.22 dev $rp12 weight $weight_rp12 \
207+ nexthop via 169.254.3.23 dev $rp13 weight $weight_rp13
208+
209+ t0_rp12=$( link_stats_tx_packets_get $rp12 )
210+ t0_rp13=$( link_stats_tx_packets_get $rp13 )
211+
212+ ip vrf exec vrf-h1 $MZ -q -p 64 -A 192.0.2.2 -B 198.51.100.2 \
213+ -d 1msec -t udp " sp=1024,dp=0-32768"
214+
215+ t1_rp12=$( link_stats_tx_packets_get $rp12 )
216+ t1_rp13=$( link_stats_tx_packets_get $rp13 )
217+
218+ let " packets_rp12 = $t1_rp12 - $t0_rp12 "
219+ let " packets_rp13 = $t1_rp13 - $t0_rp13 "
220+ multipath_eval $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
221+
222+ # Restore settings.
223+ ip route replace 198.51.100.0/24 vrf vrf-r1 \
224+ nexthop via 169.254.2.22 dev $rp12 \
225+ nexthop via 169.254.3.23 dev $rp13
226+ sysctl -q -w net.ipv4.fib_multipath_hash_policy=$hash_policy
227+ }
228+
229+ multipath_test ()
230+ {
231+ log_info " Running IPv4 multipath tests"
232+ multipath4_test 1 1
233+ multipath4_test 2 1
234+ multipath4_test 11 45
235+ }
236+
161237setup_prepare ()
162238{
163239 h1=${NETIFS[p1]}
@@ -205,5 +281,6 @@ setup_wait
205281
206282ping_test $h1 198.51.100.2
207283ping6_test $h1 2001:db8:2::2
284+ multipath_test
208285
209286exit $EXIT_STATUS
0 commit comments