@@ -11,7 +11,7 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
1111 ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics \
1212 ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \
1313 ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \
14- ipv4_mpath_list ipv6_mpath_list"
14+ ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance "
1515
1616VERBOSE=0
1717PAUSE_ON_FAIL=no
@@ -1085,6 +1085,35 @@ route_setup()
10851085 set +e
10861086}
10871087
1088+ forwarding_cleanup ()
1089+ {
1090+ cleanup_ns $ns3
1091+
1092+ route_cleanup
1093+ }
1094+
1095+ # extend route_setup with an ns3 reachable through ns2 over both devices
1096+ forwarding_setup ()
1097+ {
1098+ forwarding_cleanup
1099+
1100+ route_setup
1101+
1102+ setup_ns ns3
1103+
1104+ ip link add veth5 netns $ns3 type veth peer name veth6 netns $ns2
1105+ ip -netns $ns3 link set veth5 up
1106+ ip -netns $ns2 link set veth6 up
1107+
1108+ ip -netns $ns3 -4 addr add dev veth5 172.16.105.1/24
1109+ ip -netns $ns2 -4 addr add dev veth6 172.16.105.2/24
1110+ ip -netns $ns3 -4 route add 172.16.100.0/22 via 172.16.105.2
1111+
1112+ ip -netns $ns3 -6 addr add dev veth5 2001:db8:105::1/64 nodad
1113+ ip -netns $ns2 -6 addr add dev veth6 2001:db8:105::2/64 nodad
1114+ ip -netns $ns3 -6 route add 2001:db8:101::/33 via 2001:db8:105::2
1115+ }
1116+
10881117# assumption is that basic add of a single path route works
10891118# otherwise just adding an address on an interface is broken
10901119ipv6_rt_add ()
@@ -2600,6 +2629,93 @@ ipv6_mpath_list_test()
26002629 route_cleanup
26012630}
26022631
2632+ tc_set_flower_counter__saddr_syn () {
2633+ tc_set_flower_counter $1 $2 $3 " src_ip $4 ip_proto tcp tcp_flags 0x2"
2634+ }
2635+
2636+ ip_mpath_balance_dep_check ()
2637+ {
2638+ if [ ! -x " $( command -v socat) " ]; then
2639+ echo " socat command not found. Skipping test"
2640+ return 1
2641+ fi
2642+
2643+ if [ ! -x " $( command -v jq) " ]; then
2644+ echo " jq command not found. Skipping test"
2645+ return 1
2646+ fi
2647+ }
2648+
2649+ ip_mpath_balance () {
2650+ local -r ipver=$1
2651+ local -r daddr=$2
2652+ local -r num_conn=20
2653+
2654+ for i in $( seq 1 $num_conn ) ; do
2655+ ip netns exec $ns3 socat $ipver TCP-LISTEN:8000 STDIO > /dev/null &
2656+ sleep 0.02
2657+ echo -n a | ip netns exec $ns1 socat $ipver STDIO TCP:$daddr :8000
2658+ done
2659+
2660+ local -r syn0=" $( tc_get_flower_counter $ns1 veth1) "
2661+ local -r syn1=" $( tc_get_flower_counter $ns1 veth3) "
2662+ local -r syns=$(( syn0 + syn1 ))
2663+
2664+ [ " $VERBOSE " = " 1" ] && echo " multipath: syns seen: ($syn0 ,$syn1 )"
2665+
2666+ [[ $syns -ge $num_conn ]] && [[ $syn0 -gt 0 ]] && [[ $syn1 -gt 0 ]]
2667+ }
2668+
2669+ ipv4_mpath_balance_test ()
2670+ {
2671+ echo
2672+ echo " IPv4 multipath load balance test"
2673+
2674+ ip_mpath_balance_dep_check || return 1
2675+ forwarding_setup
2676+
2677+ $IP route add 172.16.105.1 \
2678+ nexthop via 172.16.101.2 \
2679+ nexthop via 172.16.103.2
2680+
2681+ ip netns exec $ns1 \
2682+ sysctl -q -w net.ipv4.fib_multipath_hash_policy=1
2683+
2684+ tc_set_flower_counter__saddr_syn $ns1 4 veth1 172.16.101.1
2685+ tc_set_flower_counter__saddr_syn $ns1 4 veth3 172.16.103.1
2686+
2687+ ip_mpath_balance -4 172.16.105.1
2688+
2689+ log_test $? 0 " IPv4 multipath loadbalance"
2690+
2691+ forwarding_cleanup
2692+ }
2693+
2694+ ipv6_mpath_balance_test ()
2695+ {
2696+ echo
2697+ echo " IPv6 multipath load balance test"
2698+
2699+ ip_mpath_balance_dep_check || return 1
2700+ forwarding_setup
2701+
2702+ $IP route add 2001:db8:105::1\
2703+ nexthop via 2001:db8:101::2 \
2704+ nexthop via 2001:db8:103::2
2705+
2706+ ip netns exec $ns1 \
2707+ sysctl -q -w net.ipv6.fib_multipath_hash_policy=1
2708+
2709+ tc_set_flower_counter__saddr_syn $ns1 6 veth1 2001:db8:101::1
2710+ tc_set_flower_counter__saddr_syn $ns1 6 veth3 2001:db8:103::1
2711+
2712+ ip_mpath_balance -6 " [2001:db8:105::1]"
2713+
2714+ log_test $? 0 " IPv6 multipath loadbalance"
2715+
2716+ forwarding_cleanup
2717+ }
2718+
26032719# ###############################################################################
26042720# usage
26052721
26832799 fib6_gc_test|ipv6_gc) fib6_gc_test;;
26842800 ipv4_mpath_list) ipv4_mpath_list_test;;
26852801 ipv6_mpath_list) ipv6_mpath_list_test;;
2802+ ipv4_mpath_balance) ipv4_mpath_balance_test;;
2803+ ipv6_mpath_balance) ipv6_mpath_balance_test;;
26862804
26872805 help) echo " Test names: $TESTS " ; exit 0;;
26882806 esac
0 commit comments