brintos

brintos / linux-shallow public Read only

0
0
Text · 7.4 KiB · 67fafef Raw
335 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# +--------------------+                     +----------------------+5# | H1                 |                     |                   H2 |6# |                    |                     |                      |7# |          $h1.200 + |                     | + $h2.200            |8# |     192.0.2.1/28 | |                     | | 192.0.2.18/28      |9# | 2001:db8:1::1/64 | |                     | | 2001:db8:2::1/64   |10# |                  | |                     | |                    |11# |              $h1 + |                     | + $h2                |12# |                  | |                     | |                    |13# +------------------|-+                     +-|--------------------+14#                    |                         |15# +------------------|-------------------------|--------------------+16# | SW               |                         |                    |17# |                  |                         |                    |18# |             $rp1 +                         + $rp2               |19# |                  |                         |                    |20# |         $rp1.200 +                         + $rp2.200           |21# |     192.0.2.2/28                             192.0.2.17/28      |22# | 2001:db8:1::2/64                             2001:db8:2::2/64   |23# |                                                                 |24# +-----------------------------------------------------------------+25 26ALL_TESTS="27	ping_ipv428	ping_ipv629	test_stats_rx_ipv430	test_stats_tx_ipv431	test_stats_rx_ipv632	test_stats_tx_ipv633	respin_enablement34	test_stats_rx_ipv435	test_stats_tx_ipv436	test_stats_rx_ipv637	test_stats_tx_ipv638	reapply_config39	ping_ipv440	ping_ipv641	test_stats_rx_ipv442	test_stats_tx_ipv443	test_stats_rx_ipv644	test_stats_tx_ipv645	test_stats_report_rx46	test_stats_report_tx47	test_destroy_enabled48	test_double_enable49"50NUM_NETIFS=451lib_dir=$(dirname "$0")52source "$lib_dir"/../../../net/forwarding/lib.sh53source "$lib_dir"/../../../net/forwarding/tc_common.sh54 55h1_create()56{57	simple_if_init $h158	vlan_create $h1 200 v$h1 192.0.2.1/28 2001:db8:1::1/6459	ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.260	ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::261}62 63h1_destroy()64{65	ip -6 route del 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::266	ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.267	vlan_destroy $h1 20068	simple_if_fini $h169}70 71h2_create()72{73	simple_if_init $h274	vlan_create $h2 200 v$h2 192.0.2.18/28 2001:db8:2::1/6475	ip route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.1776	ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::277}78 79h2_destroy()80{81	ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::282	ip route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.1783	vlan_destroy $h2 20084	simple_if_fini $h285}86 87router_rp1_200_create()88{89	ip link add name $rp1.200 link $rp1 type vlan id 20090	ip link set dev $rp1.200 addrgenmode eui6491	ip link set dev $rp1.200 up92	ip address add dev $rp1.200 192.0.2.2/2893	ip address add dev $rp1.200 2001:db8:1::2/6494	ip stats set dev $rp1.200 l3_stats on95}96 97router_rp1_200_destroy()98{99	ip stats set dev $rp1.200 l3_stats off100	ip address del dev $rp1.200 2001:db8:1::2/64101	ip address del dev $rp1.200 192.0.2.2/28102	ip link del dev $rp1.200103}104 105router_create()106{107	ip link set dev $rp1 up108	router_rp1_200_create109 110	ip link set dev $rp2 up111	vlan_create $rp2 200 "" 192.0.2.17/28 2001:db8:2::2/64112}113 114router_destroy()115{116	vlan_destroy $rp2 200117	ip link set dev $rp2 down118 119	router_rp1_200_destroy120	ip link set dev $rp1 down121}122 123setup_prepare()124{125	h1=${NETIFS[p1]}126	rp1=${NETIFS[p2]}127 128	rp2=${NETIFS[p3]}129	h2=${NETIFS[p4]}130 131	rp1mac=$(mac_get $rp1)132	rp2mac=$(mac_get $rp2)133 134	vrf_prepare135 136	h1_create137	h2_create138 139	router_create140 141	forwarding_enable142}143 144cleanup()145{146	pre_cleanup147 148	forwarding_restore149 150	router_destroy151 152	h2_destroy153	h1_destroy154 155	vrf_cleanup156}157 158ping_ipv4()159{160	ping_test $h1.200 192.0.2.18 " IPv4"161}162 163ping_ipv6()164{165	ping_test $h1.200 2001:db8:2::1 " IPv6"166}167 168send_packets_rx_ipv4()169{170	# Send 21 packets instead of 20, because the first one might trap and go171	# through the SW datapath, which might not bump the HW counter.172	$MZ $h1.200 -c 21 -d 20msec -p 100 \173	    -a own -b $rp1mac -A 192.0.2.1 -B 192.0.2.18 \174	    -q -t udp sp=54321,dp=12345175}176 177send_packets_rx_ipv6()178{179	$MZ $h1.200 -6 -c 21 -d 20msec -p 100 \180	    -a own -b $rp1mac -A 2001:db8:1::1 -B 2001:db8:2::1 \181	    -q -t udp sp=54321,dp=12345182}183 184send_packets_tx_ipv4()185{186	$MZ $h2.200 -c 21 -d 20msec -p 100 \187	    -a own -b $rp2mac -A 192.0.2.18 -B 192.0.2.1 \188	    -q -t udp sp=54321,dp=12345189}190 191send_packets_tx_ipv6()192{193	$MZ $h2.200 -6 -c 21 -d 20msec -p 100 \194	    -a own -b $rp2mac -A 2001:db8:2::1 -B 2001:db8:1::1 \195	    -q -t udp sp=54321,dp=12345196}197 198___test_stats()199{200	local dir=$1; shift201	local prot=$1; shift202 203	local a204	local b205 206	a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets)207	send_packets_${dir}_${prot}208	"$@"209	b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \210		       hw_stats_get l3_stats $rp1.200 ${dir} packets)211	check_err $? "Traffic not reflected in the counter: $a -> $b"212}213 214__test_stats()215{216	local dir=$1; shift217	local prot=$1; shift218 219	RET=0220	___test_stats "$dir" "$prot"221	log_test "Test $dir packets: $prot"222}223 224test_stats_rx_ipv4()225{226	__test_stats rx ipv4227}228 229test_stats_tx_ipv4()230{231	__test_stats tx ipv4232}233 234test_stats_rx_ipv6()235{236	__test_stats rx ipv6237}238 239test_stats_tx_ipv6()240{241	__test_stats tx ipv6242}243 244# Make sure everything works well even after stats have been disabled and245# reenabled on the same device without touching the L3 configuration.246respin_enablement()247{248	log_info "Turning stats off and on again"249	ip stats set dev $rp1.200 l3_stats off250	ip stats set dev $rp1.200 l3_stats on251}252 253# For the initial run, l3_stats is enabled on a completely set up netdevice. Now254# do it the other way around: enabling the L3 stats on an L2 netdevice, and only255# then apply the L3 configuration.256reapply_config()257{258	log_info "Reapplying configuration"259 260	router_rp1_200_destroy261 262	ip link add name $rp1.200 link $rp1 type vlan id 200263	ip link set dev $rp1.200 addrgenmode none264	ip stats set dev $rp1.200 l3_stats on265	ip link set dev $rp1.200 addrgenmode eui64266	ip link set dev $rp1.200 up267	ip address add dev $rp1.200 192.0.2.2/28268	ip address add dev $rp1.200 2001:db8:1::2/64269}270 271__test_stats_report()272{273	local dir=$1; shift274	local prot=$1; shift275 276	local a277	local b278 279	RET=0280 281	a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets)282	send_packets_${dir}_${prot}283	ip address flush dev $rp1.200284	b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \285		       hw_stats_get l3_stats $rp1.200 ${dir} packets)286	check_err $? "Traffic not reflected in the counter: $a -> $b"287	log_test "Test ${dir} packets: stats pushed on loss of L3"288 289	ip stats set dev $rp1.200 l3_stats off290	ip link del dev $rp1.200291	router_rp1_200_create292}293 294test_stats_report_rx()295{296	__test_stats_report rx ipv4297}298 299test_stats_report_tx()300{301	__test_stats_report tx ipv4302}303 304test_destroy_enabled()305{306	RET=0307 308	ip link del dev $rp1.200309	router_rp1_200_create310 311	log_test "Destroy l3_stats-enabled netdev"312}313 314test_double_enable()315{316	RET=0317	___test_stats rx ipv4 \318		ip stats set dev $rp1.200 l3_stats on319	log_test "Test stat retention across a spurious enablement"320}321 322trap cleanup EXIT323 324setup_prepare325setup_wait326 327used=$(ip -j stats show dev $rp1.200 group offload subgroup hw_stats_info |328	   jq '.[].info.l3_stats.used')329[[ $used = true ]]330check_err $? "hw_stats_info.used=$used"331log_test "l3_stats offloaded"332tests_run333 334exit $EXIT_STATUS335