[RFC PATCH net-next 06/12] selftests: forwarding: Test IPv4 weighted nexthops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use different weights for the multipath route configured on the first
router and check that the different flows generated by the first host
are distributed according to the provided weights.

Signed-off-by: Ido Schimmel <idosch@xxxxxxxxxxxx>
---
 tools/testing/selftests/forwarding/lib.sh          |  7 +++
 .../selftests/forwarding/router_multipath.sh       | 71 ++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git a/tools/testing/selftests/forwarding/lib.sh b/tools/testing/selftests/forwarding/lib.sh
index 11b6f6101d10..b814b5350378 100644
--- a/tools/testing/selftests/forwarding/lib.sh
+++ b/tools/testing/selftests/forwarding/lib.sh
@@ -165,6 +165,13 @@ mtu_change()
 	done
 }
 
+link_stats_tx_packets_get()
+{
+       local if_name=$1
+
+       ip -j -s link show dev $if_name | jq '.[]["stats644"]["tx"]["packets"]'
+}
+
 bridge_ageing_time_get()
 {
 	local ageing_time
diff --git a/tools/testing/selftests/forwarding/router_multipath.sh b/tools/testing/selftests/forwarding/router_multipath.sh
index 70f9f2c3794e..45c5fc0a6448 100755
--- a/tools/testing/selftests/forwarding/router_multipath.sh
+++ b/tools/testing/selftests/forwarding/router_multipath.sh
@@ -158,6 +158,75 @@ router2_destroy()
 	vrf_destroy "vrf-r2" 4
 }
 
+multipath_eval()
+{
+       local weight_rp12=$1 weight_rp13=$2 packets_rp12=$3 packets_rp13=$4
+       local weights_ratio packets_ratio diff
+
+       RET=0
+
+       if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
+               weights_ratio=$(echo $weight_rp12 / $weight_rp13 | bc -l)
+               packets_ratio=$(echo $packets_rp12 / $packets_rp13 | bc -l)
+       else
+               weights_ratio=$(echo $weight_rp13 / $weight_rp12 | bc -l)
+               packets_ratio=$(echo $packets_rp13 / $packets_rp12 | bc -l)
+       fi
+
+       echo "Expected ratio: $weights_ratio Measured ratio: $packets_ratio"
+
+       diff=$(echo $weights_ratio - $packets_ratio | bc -l)
+       diff=${diff#-}
+
+       test "$(echo "$diff / $weights_ratio > 0.1" | bc -l)" -eq 0
+       check_err $? "too large discrepancy between expected and measured ratios"
+       print_result "multipath"
+}
+
+multipath4_test()
+{
+       local t0_rp12 t0_rp13 t1_rp12 t1_rp13
+       local weight_rp12=$1 weight_rp13=$2
+       local packets_rp12 packets_rp13
+       local hash_policy
+
+       # Transmit multiple flows from h1 to h2 and make sure they are
+       # distributed between both multipath links (rp12 and rp13)
+       # according to the configured weights.
+       hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
+       sysctl -w -q net.ipv4.fib_multipath_hash_policy=1
+       ip route replace 198.51.100.0/24 vrf vrf-r1 \
+               nexthop via 169.254.2.22 dev $rp12 weight $weight_rp12 \
+               nexthop via 169.254.3.23 dev $rp13 weight $weight_rp13
+
+       t0_rp12=$(link_stats_tx_packets_get $rp12)
+       t0_rp13=$(link_stats_tx_packets_get $rp13)
+
+       ip vrf exec vrf-h1 mausezahn -q -p 64 -A 192.0.2.2 -B 198.51.100.2 \
+	       -d 1msec -t udp "sp=1024,dp=0-32768"
+
+       t1_rp12=$(link_stats_tx_packets_get $rp12)
+       t1_rp13=$(link_stats_tx_packets_get $rp13)
+
+       let "packets_rp12 = $t1_rp12 - $t0_rp12"
+       let "packets_rp13 = $t1_rp13 - $t0_rp13"
+       multipath_eval $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
+
+       # Restore settings.
+       ip route replace 198.51.100.0/24 vrf vrf-r1 \
+               nexthop via 169.254.2.22 dev $rp12 \
+               nexthop via 169.254.3.23 dev $rp13
+       sysctl -w -q net.ipv4.fib_multipath_hash_policy=$hash_policy
+}
+
+multipath_test()
+{
+       echo "Performing IPv4 multipath tests"
+       multipath4_test 1 1
+       multipath4_test 2 1
+       multipath4_test 11 45
+}
+
 setup_prepare()
 {
 	h1=${NETIFS[p1]}
@@ -212,4 +281,6 @@ ping_test "vrf-h1" 198.51.100.2
 ping_test "vrf-h1" 2001:db8:2::2
 mtu_change $old_mtu "${netifs_arr[@]}"
 
+multipath_test
+
 exit $EXIT_STATUS
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux