brintos

brintos / linux-shallow public Read only

0
0
Text · 3.2 KiB · 507b285 Raw
133 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3nh_stats_do_test()4{5	local what=$1; shift6	local nh1_id=$1; shift7	local nh2_id=$1; shift8	local group_id=$1; shift9	local stats_get=$1; shift10	local mz="$@"11 12	local dp13 14	RET=015 16	sleep 217	for ((dp=0; dp < 60000; dp += 10000)); do18		local dd19		local t0_rp12=$(link_stats_tx_packets_get $rp12)20		local t0_rp13=$(link_stats_tx_packets_get $rp13)21		local t0_nh1=$($stats_get $group_id $nh1_id)22		local t0_nh2=$($stats_get $group_id $nh2_id)23 24		ip vrf exec vrf-h1 \25			$mz -q -p 64 -d 0 -t udp \26				"sp=1024,dp=$((dp))-$((dp + 10000))"27		sleep 228 29		local t1_rp12=$(link_stats_tx_packets_get $rp12)30		local t1_rp13=$(link_stats_tx_packets_get $rp13)31		local t1_nh1=$($stats_get $group_id $nh1_id)32		local t1_nh2=$($stats_get $group_id $nh2_id)33 34		local d_rp12=$((t1_rp12 - t0_rp12))35		local d_rp13=$((t1_rp13 - t0_rp13))36		local d_nh1=$((t1_nh1 - t0_nh1))37		local d_nh2=$((t1_nh2 - t0_nh2))38 39		dd=$(absval $((d_rp12 - d_nh1)))40		((dd < 10))41		check_err $? "Discrepancy between link and $stats_get: d_rp12=$d_rp12 d_nh1=$d_nh1"42 43		dd=$(absval $((d_rp13 - d_nh2)))44		((dd < 10))45		check_err $? "Discrepancy between link and $stats_get: d_rp13=$d_rp13 d_nh2=$d_nh2"46	done47 48	log_test "NH stats test $what"49}50 51nh_stats_test_dispatch_swhw()52{53	local what=$1; shift54	local nh1_id=$1; shift55	local nh2_id=$1; shift56	local group_id=$1; shift57	local mz="$@"58 59	nh_stats_do_test "$what" "$nh1_id" "$nh2_id" "$group_id" \60			 nh_stats_get "${mz[@]}"61 62	xfail_on_veth $rp11 \63		nh_stats_do_test "HW $what" "$nh1_id" "$nh2_id" "$group_id" \64				 nh_stats_get_hw "${mz[@]}"65}66 67nh_stats_test_dispatch()68{69	local nhgtype=$1; shift70	local what=$1; shift71	local nh1_id=$1; shift72	local nh2_id=$1; shift73	local group_id=$1; shift74	local mz="$@"75 76	local enabled77 78	if ! ip nexthop help 2>&1 | grep -q hw_stats; then79		log_test_skip "NH stats test: ip doesn't support HW stats"80		return81	fi82 83	ip nexthop replace id $group_id group $nh1_id/$nh2_id \84			   hw_stats on type $nhgtype85	enabled=$(ip -s -j -d nexthop show id $group_id |86		      jq '.[].hw_stats.enabled')87	if [[ $enabled == true ]]; then88		nh_stats_test_dispatch_swhw "$what" "$nh1_id" "$nh2_id" \89					    "$group_id" "${mz[@]}"90	elif [[ $enabled == false ]]; then91		check_err 1 "HW stats still disabled after enabling"92		log_test "NH stats test"93	else94		log_test_skip "NH stats test: ip doesn't report hw_stats info"95	fi96 97	ip nexthop replace id $group_id group $nh1_id/$nh2_id \98			   hw_stats off type $nhgtype99}100 101__nh_stats_test_v4()102{103	local nhgtype=$1; shift104 105	sysctl_set net.ipv4.fib_multipath_hash_policy 1106	nh_stats_test_dispatch $nhgtype "IPv4" 101 102 103 \107			       $MZ $h1 -A 192.0.2.2 -B 198.51.100.2108	sysctl_restore net.ipv4.fib_multipath_hash_policy109}110 111__nh_stats_test_v6()112{113	local nhgtype=$1; shift114 115	sysctl_set net.ipv6.fib_multipath_hash_policy 1116	nh_stats_test_dispatch $nhgtype "IPv6" 104 105 106 \117			       $MZ -6 $h1 -A 2001:db8:1::2 -B 2001:db8:2::2118	sysctl_restore net.ipv6.fib_multipath_hash_policy119}120 121check_nhgw16()122{123	local nhid=$1; shift124 125	ip nexthop replace id 9999 group "$nhid,65535" &>/dev/null126	if (( $? )); then127		log_test_skip "16-bit multipath tests" \128			      "iproute2 or the kernel do not support 16-bit next hop weights"129		return 1130	fi131	ip nexthop del id 9999 ||:132}133