Path: blob/master/tools/testing/selftests/drivers/net/mlxsw/fib.sh
26292 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# This test is for checking the FIB offload API on top of mlxsw.45lib_dir=$(dirname $0)/../../../net/forwarding67ALL_TESTS="8ipv4_identical_routes9ipv4_tos10ipv4_metric11ipv4_replace12ipv4_delete13ipv4_plen14ipv4_replay15ipv4_flush16ipv4_local_replace17ipv6_add18ipv6_metric19ipv6_append_single20ipv6_replace_single21ipv6_metric_multipath22ipv6_append_multipath23ipv6_replace_multipath24ipv6_append_multipath_to_single25ipv6_delete_single26ipv6_delete_multipath27ipv6_replay_single28ipv6_replay_multipath29ipv6_local_replace30"31NUM_NETIFS=032source $lib_dir/lib.sh33source $lib_dir/devlink_lib.sh34source $lib_dir/fib_offload_lib.sh3536ipv4_identical_routes()37{38fib_ipv4_identical_routes_test "testns1"39}4041ipv4_tos()42{43fib_ipv4_tos_test "testns1"44}4546ipv4_metric()47{48fib_ipv4_metric_test "testns1"49}5051ipv4_replace()52{53fib_ipv4_replace_test "testns1"54}5556ipv4_delete()57{58fib_ipv4_delete_test "testns1"59}6061ipv4_plen()62{63fib_ipv4_plen_test "testns1"64}6566ipv4_replay_metric()67{68fib_ipv4_replay_metric_test "testns1" "$DEVLINK_DEV"69}7071ipv4_replay_tos()72{73fib_ipv4_replay_tos_test "testns1" "$DEVLINK_DEV"74}7576ipv4_replay_plen()77{78fib_ipv4_replay_plen_test "testns1" "$DEVLINK_DEV"79}8081ipv4_replay()82{83ipv4_replay_metric84ipv4_replay_tos85ipv4_replay_plen86}8788ipv4_flush()89{90fib_ipv4_flush_test "testns1"91}9293ipv4_local_replace()94{95local ns="testns1"9697RET=09899ip -n $ns link add name dummy1 type dummy100ip -n $ns link set dev dummy1 up101102ip -n $ns route add table local 192.0.2.1/32 dev dummy1103fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false104check_err $? "Local table route not in hardware when should"105106ip -n $ns route add table main 192.0.2.1/32 dev dummy1107fib4_trap_check $ns "table main 192.0.2.1/32 dev dummy1" true108check_err $? "Main table route in hardware when should not"109110fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false111check_err $? "Local table route was replaced when should not"112113# Test that local routes can replace routes in main table.114ip -n $ns route add table main 192.0.2.2/32 dev dummy1115fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" false116check_err $? "Main table route not in hardware when should"117118ip -n $ns route add table local 192.0.2.2/32 dev dummy1119fib4_trap_check $ns "table local 192.0.2.2/32 dev dummy1" false120check_err $? "Local table route did not replace route in main table when should"121122fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" true123check_err $? "Main table route was not replaced when should"124125log_test "IPv4 local table route replacement"126127ip -n $ns link del dev dummy1128}129130ipv6_add()131{132fib_ipv6_add_test "testns1"133}134135ipv6_metric()136{137fib_ipv6_metric_test "testns1"138}139140ipv6_append_single()141{142fib_ipv6_append_single_test "testns1"143}144145ipv6_replace_single()146{147fib_ipv6_replace_single_test "testns1"148}149150ipv6_metric_multipath()151{152fib_ipv6_metric_multipath_test "testns1"153}154155ipv6_append_multipath()156{157fib_ipv6_append_multipath_test "testns1"158}159160ipv6_replace_multipath()161{162fib_ipv6_replace_multipath_test "testns1"163}164165ipv6_append_multipath_to_single()166{167fib_ipv6_append_multipath_to_single_test "testns1"168}169170ipv6_delete_single()171{172fib_ipv6_delete_single_test "testns1"173}174175ipv6_delete_multipath()176{177fib_ipv6_delete_multipath_test "testns1"178}179180ipv6_replay_single()181{182fib_ipv6_replay_single_test "testns1" "$DEVLINK_DEV"183}184185ipv6_replay_multipath()186{187fib_ipv6_replay_multipath_test "testns1" "$DEVLINK_DEV"188}189190ipv6_local_replace()191{192local ns="testns1"193194RET=0195196ip -n $ns link add name dummy1 type dummy197ip -n $ns link set dev dummy1 up198199ip -n $ns route add table local 2001:db8:1::1/128 dev dummy1200fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false201check_err $? "Local table route not in hardware when should"202203ip -n $ns route add table main 2001:db8:1::1/128 dev dummy1204fib6_trap_check $ns "table main 2001:db8:1::1/128 dev dummy1" true205check_err $? "Main table route in hardware when should not"206207fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false208check_err $? "Local table route was replaced when should not"209210# Test that local routes can replace routes in main table.211ip -n $ns route add table main 2001:db8:1::2/128 dev dummy1212fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" false213check_err $? "Main table route not in hardware when should"214215ip -n $ns route add table local 2001:db8:1::2/128 dev dummy1216fib6_trap_check $ns "table local 2001:db8:1::2/128 dev dummy1" false217check_err $? "Local route route did not replace route in main table when should"218219fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" true220check_err $? "Main table route was not replaced when should"221222log_test "IPv6 local table route replacement"223224ip -n $ns link del dev dummy1225}226227fib_notify_on_flag_change_set()228{229local notify=$1; shift230231ip netns exec testns1 sysctl -qw net.ipv4.fib_notify_on_flag_change=$notify232ip netns exec testns1 sysctl -qw net.ipv6.fib_notify_on_flag_change=$notify233234log_info "Set fib_notify_on_flag_change to $notify"235}236237setup_prepare()238{239ip netns add testns1240if [ $? -ne 0 ]; then241echo "Failed to add netns \"testns1\""242exit 1243fi244245devlink dev reload $DEVLINK_DEV netns testns1246if [ $? -ne 0 ]; then247echo "Failed to reload into netns \"testns1\""248exit 1249fi250}251252cleanup()253{254pre_cleanup255devlink -N testns1 dev reload $DEVLINK_DEV netns $$256ip netns del testns1257}258259trap cleanup EXIT260261setup_prepare262263fib_notify_on_flag_change_set 1264tests_run265266fib_notify_on_flag_change_set 0267tests_run268269exit $EXIT_STATUS270271272