brintos

brintos / linux-shallow public Read only

0
0
Text · 5.4 KiB · dcbf32b Raw
271 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# This test is for checking the FIB offload API on top of mlxsw.5 6lib_dir=$(dirname $0)/../../../net/forwarding7 8ALL_TESTS="9	ipv4_identical_routes10	ipv4_tos11	ipv4_metric12	ipv4_replace13	ipv4_delete14	ipv4_plen15	ipv4_replay16	ipv4_flush17	ipv4_local_replace18	ipv6_add19	ipv6_metric20	ipv6_append_single21	ipv6_replace_single22	ipv6_metric_multipath23	ipv6_append_multipath24	ipv6_replace_multipath25	ipv6_append_multipath_to_single26	ipv6_delete_single27	ipv6_delete_multipath28	ipv6_replay_single29	ipv6_replay_multipath30	ipv6_local_replace31"32NUM_NETIFS=033source $lib_dir/lib.sh34source $lib_dir/devlink_lib.sh35source $lib_dir/fib_offload_lib.sh36 37ipv4_identical_routes()38{39	fib_ipv4_identical_routes_test "testns1"40}41 42ipv4_tos()43{44	fib_ipv4_tos_test "testns1"45}46 47ipv4_metric()48{49	fib_ipv4_metric_test "testns1"50}51 52ipv4_replace()53{54	fib_ipv4_replace_test "testns1"55}56 57ipv4_delete()58{59	fib_ipv4_delete_test "testns1"60}61 62ipv4_plen()63{64	fib_ipv4_plen_test "testns1"65}66 67ipv4_replay_metric()68{69	fib_ipv4_replay_metric_test "testns1" "$DEVLINK_DEV"70}71 72ipv4_replay_tos()73{74	fib_ipv4_replay_tos_test "testns1" "$DEVLINK_DEV"75}76 77ipv4_replay_plen()78{79	fib_ipv4_replay_plen_test "testns1" "$DEVLINK_DEV"80}81 82ipv4_replay()83{84	ipv4_replay_metric85	ipv4_replay_tos86	ipv4_replay_plen87}88 89ipv4_flush()90{91	fib_ipv4_flush_test "testns1"92}93 94ipv4_local_replace()95{96	local ns="testns1"97 98	RET=099 100	ip -n $ns link add name dummy1 type dummy101	ip -n $ns link set dev dummy1 up102 103	ip -n $ns route add table local 192.0.2.1/32 dev dummy1104	fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false105	check_err $? "Local table route not in hardware when should"106 107	ip -n $ns route add table main 192.0.2.1/32 dev dummy1108	fib4_trap_check $ns "table main 192.0.2.1/32 dev dummy1" true109	check_err $? "Main table route in hardware when should not"110 111	fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false112	check_err $? "Local table route was replaced when should not"113 114	# Test that local routes can replace routes in main table.115	ip -n $ns route add table main 192.0.2.2/32 dev dummy1116	fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" false117	check_err $? "Main table route not in hardware when should"118 119	ip -n $ns route add table local 192.0.2.2/32 dev dummy1120	fib4_trap_check $ns "table local 192.0.2.2/32 dev dummy1" false121	check_err $? "Local table route did not replace route in main table when should"122 123	fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" true124	check_err $? "Main table route was not replaced when should"125 126	log_test "IPv4 local table route replacement"127 128	ip -n $ns link del dev dummy1129}130 131ipv6_add()132{133	fib_ipv6_add_test "testns1"134}135 136ipv6_metric()137{138	fib_ipv6_metric_test "testns1"139}140 141ipv6_append_single()142{143	fib_ipv6_append_single_test "testns1"144}145 146ipv6_replace_single()147{148	fib_ipv6_replace_single_test "testns1"149}150 151ipv6_metric_multipath()152{153	fib_ipv6_metric_multipath_test "testns1"154}155 156ipv6_append_multipath()157{158	fib_ipv6_append_multipath_test "testns1"159}160 161ipv6_replace_multipath()162{163	fib_ipv6_replace_multipath_test "testns1"164}165 166ipv6_append_multipath_to_single()167{168	fib_ipv6_append_multipath_to_single_test "testns1"169}170 171ipv6_delete_single()172{173	fib_ipv6_delete_single_test "testns1"174}175 176ipv6_delete_multipath()177{178	fib_ipv6_delete_multipath_test "testns1"179}180 181ipv6_replay_single()182{183	fib_ipv6_replay_single_test "testns1" "$DEVLINK_DEV"184}185 186ipv6_replay_multipath()187{188	fib_ipv6_replay_multipath_test "testns1" "$DEVLINK_DEV"189}190 191ipv6_local_replace()192{193	local ns="testns1"194 195	RET=0196 197	ip -n $ns link add name dummy1 type dummy198	ip -n $ns link set dev dummy1 up199 200	ip -n $ns route add table local 2001:db8:1::1/128 dev dummy1201	fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false202	check_err $? "Local table route not in hardware when should"203 204	ip -n $ns route add table main 2001:db8:1::1/128 dev dummy1205	fib6_trap_check $ns "table main 2001:db8:1::1/128 dev dummy1" true206	check_err $? "Main table route in hardware when should not"207 208	fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false209	check_err $? "Local table route was replaced when should not"210 211	# Test that local routes can replace routes in main table.212	ip -n $ns route add table main 2001:db8:1::2/128 dev dummy1213	fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" false214	check_err $? "Main table route not in hardware when should"215 216	ip -n $ns route add table local 2001:db8:1::2/128 dev dummy1217	fib6_trap_check $ns "table local 2001:db8:1::2/128 dev dummy1" false218	check_err $? "Local route route did not replace route in main table when should"219 220	fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" true221	check_err $? "Main table route was not replaced when should"222 223	log_test "IPv6 local table route replacement"224 225	ip -n $ns link del dev dummy1226}227 228fib_notify_on_flag_change_set()229{230	local notify=$1; shift231 232	ip netns exec testns1 sysctl -qw net.ipv4.fib_notify_on_flag_change=$notify233	ip netns exec testns1 sysctl -qw net.ipv6.fib_notify_on_flag_change=$notify234 235	log_info "Set fib_notify_on_flag_change to $notify"236}237 238setup_prepare()239{240	ip netns add testns1241	if [ $? -ne 0 ]; then242		echo "Failed to add netns \"testns1\""243		exit 1244	fi245 246	devlink dev reload $DEVLINK_DEV netns testns1247	if [ $? -ne 0 ]; then248		echo "Failed to reload into netns \"testns1\""249		exit 1250	fi251}252 253cleanup()254{255	pre_cleanup256	devlink -N testns1 dev reload $DEVLINK_DEV netns $$257	ip netns del testns1258}259 260trap cleanup EXIT261 262setup_prepare263 264fib_notify_on_flag_change_set 1265tests_run266 267fib_notify_on_flag_change_set 0268tests_run269 270exit $EXIT_STATUS271