18c2ecf20Sopenharmony_ci#!/bin/bash 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# This test is for checking the FIB offload API on top of mlxsw. 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_cilib_dir=$(dirname $0)/../../../net/forwarding 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciALL_TESTS=" 98c2ecf20Sopenharmony_ci ipv4_identical_routes 108c2ecf20Sopenharmony_ci ipv4_tos 118c2ecf20Sopenharmony_ci ipv4_metric 128c2ecf20Sopenharmony_ci ipv4_replace 138c2ecf20Sopenharmony_ci ipv4_delete 148c2ecf20Sopenharmony_ci ipv4_plen 158c2ecf20Sopenharmony_ci ipv4_replay 168c2ecf20Sopenharmony_ci ipv4_flush 178c2ecf20Sopenharmony_ci ipv4_local_replace 188c2ecf20Sopenharmony_ci ipv6_add 198c2ecf20Sopenharmony_ci ipv6_metric 208c2ecf20Sopenharmony_ci ipv6_append_single 218c2ecf20Sopenharmony_ci ipv6_replace_single 228c2ecf20Sopenharmony_ci ipv6_metric_multipath 238c2ecf20Sopenharmony_ci ipv6_append_multipath 248c2ecf20Sopenharmony_ci ipv6_replace_multipath 258c2ecf20Sopenharmony_ci ipv6_append_multipath_to_single 268c2ecf20Sopenharmony_ci ipv6_delete_single 278c2ecf20Sopenharmony_ci ipv6_delete_multipath 288c2ecf20Sopenharmony_ci ipv6_replay_single 298c2ecf20Sopenharmony_ci ipv6_replay_multipath 308c2ecf20Sopenharmony_ci ipv6_local_replace 318c2ecf20Sopenharmony_ci" 328c2ecf20Sopenharmony_ciNUM_NETIFS=0 338c2ecf20Sopenharmony_cisource $lib_dir/lib.sh 348c2ecf20Sopenharmony_cisource $lib_dir/devlink_lib.sh 358c2ecf20Sopenharmony_cisource $lib_dir/fib_offload_lib.sh 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ciipv4_identical_routes() 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci fib_ipv4_identical_routes_test "testns1" 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciipv4_tos() 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci fib_ipv4_tos_test "testns1" 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciipv4_metric() 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci fib_ipv4_metric_test "testns1" 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciipv4_replace() 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci fib_ipv4_replace_test "testns1" 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciipv4_delete() 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci fib_ipv4_delete_test "testns1" 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciipv4_plen() 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci fib_ipv4_plen_test "testns1" 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciipv4_replay_metric() 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci fib_ipv4_replay_metric_test "testns1" "$DEVLINK_DEV" 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciipv4_replay_tos() 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci fib_ipv4_replay_tos_test "testns1" "$DEVLINK_DEV" 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciipv4_replay_plen() 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci fib_ipv4_replay_plen_test "testns1" "$DEVLINK_DEV" 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciipv4_replay() 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci ipv4_replay_metric 858c2ecf20Sopenharmony_ci ipv4_replay_tos 868c2ecf20Sopenharmony_ci ipv4_replay_plen 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciipv4_flush() 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci fib_ipv4_flush_test "testns1" 928c2ecf20Sopenharmony_ci} 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciipv4_local_replace() 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci local ns="testns1" 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci RET=0 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci ip -n $ns link add name dummy1 type dummy 1018c2ecf20Sopenharmony_ci ip -n $ns link set dev dummy1 up 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci ip -n $ns route add table local 192.0.2.1/32 dev dummy1 1048c2ecf20Sopenharmony_ci fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false 1058c2ecf20Sopenharmony_ci check_err $? "Local table route not in hardware when should" 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci ip -n $ns route add table main 192.0.2.1/32 dev dummy1 1088c2ecf20Sopenharmony_ci fib4_trap_check $ns "table main 192.0.2.1/32 dev dummy1" true 1098c2ecf20Sopenharmony_ci check_err $? "Main table route in hardware when should not" 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false 1128c2ecf20Sopenharmony_ci check_err $? "Local table route was replaced when should not" 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci # Test that local routes can replace routes in main table. 1158c2ecf20Sopenharmony_ci ip -n $ns route add table main 192.0.2.2/32 dev dummy1 1168c2ecf20Sopenharmony_ci fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" false 1178c2ecf20Sopenharmony_ci check_err $? "Main table route not in hardware when should" 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci ip -n $ns route add table local 192.0.2.2/32 dev dummy1 1208c2ecf20Sopenharmony_ci fib4_trap_check $ns "table local 192.0.2.2/32 dev dummy1" false 1218c2ecf20Sopenharmony_ci check_err $? "Local table route did not replace route in main table when should" 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" true 1248c2ecf20Sopenharmony_ci check_err $? "Main table route was not replaced when should" 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci log_test "IPv4 local table route replacement" 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci ip -n $ns link del dev dummy1 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ciipv6_add() 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci fib_ipv6_add_test "testns1" 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ciipv6_metric() 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci fib_ipv6_metric_test "testns1" 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ciipv6_append_single() 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci fib_ipv6_append_single_test "testns1" 1448c2ecf20Sopenharmony_ci} 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ciipv6_replace_single() 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci fib_ipv6_replace_single_test "testns1" 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ciipv6_metric_multipath() 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci fib_ipv6_metric_multipath_test "testns1" 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciipv6_append_multipath() 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci fib_ipv6_append_multipath_test "testns1" 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciipv6_replace_multipath() 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci fib_ipv6_replace_multipath_test "testns1" 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ciipv6_append_multipath_to_single() 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci fib_ipv6_append_multipath_to_single_test "testns1" 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ciipv6_delete_single() 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci fib_ipv6_delete_single_test "testns1" 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ciipv6_delete_multipath() 1778c2ecf20Sopenharmony_ci{ 1788c2ecf20Sopenharmony_ci fib_ipv6_delete_multipath_test "testns1" 1798c2ecf20Sopenharmony_ci} 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ciipv6_replay_single() 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci fib_ipv6_replay_single_test "testns1" "$DEVLINK_DEV" 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ciipv6_replay_multipath() 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci fib_ipv6_replay_multipath_test "testns1" "$DEVLINK_DEV" 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ciipv6_local_replace() 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci local ns="testns1" 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci RET=0 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci ip -n $ns link add name dummy1 type dummy 1988c2ecf20Sopenharmony_ci ip -n $ns link set dev dummy1 up 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci ip -n $ns route add table local 2001:db8:1::1/128 dev dummy1 2018c2ecf20Sopenharmony_ci fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false 2028c2ecf20Sopenharmony_ci check_err $? "Local table route not in hardware when should" 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci ip -n $ns route add table main 2001:db8:1::1/128 dev dummy1 2058c2ecf20Sopenharmony_ci fib6_trap_check $ns "table main 2001:db8:1::1/128 dev dummy1" true 2068c2ecf20Sopenharmony_ci check_err $? "Main table route in hardware when should not" 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false 2098c2ecf20Sopenharmony_ci check_err $? "Local table route was replaced when should not" 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci # Test that local routes can replace routes in main table. 2128c2ecf20Sopenharmony_ci ip -n $ns route add table main 2001:db8:1::2/128 dev dummy1 2138c2ecf20Sopenharmony_ci fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" false 2148c2ecf20Sopenharmony_ci check_err $? "Main table route not in hardware when should" 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci ip -n $ns route add table local 2001:db8:1::2/128 dev dummy1 2178c2ecf20Sopenharmony_ci fib6_trap_check $ns "table local 2001:db8:1::2/128 dev dummy1" false 2188c2ecf20Sopenharmony_ci check_err $? "Local route route did not replace route in main table when should" 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" true 2218c2ecf20Sopenharmony_ci check_err $? "Main table route was not replaced when should" 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci log_test "IPv6 local table route replacement" 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci ip -n $ns link del dev dummy1 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cisetup_prepare() 2298c2ecf20Sopenharmony_ci{ 2308c2ecf20Sopenharmony_ci ip netns add testns1 2318c2ecf20Sopenharmony_ci if [ $? -ne 0 ]; then 2328c2ecf20Sopenharmony_ci echo "Failed to add netns \"testns1\"" 2338c2ecf20Sopenharmony_ci exit 1 2348c2ecf20Sopenharmony_ci fi 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci devlink dev reload $DEVLINK_DEV netns testns1 2378c2ecf20Sopenharmony_ci if [ $? -ne 0 ]; then 2388c2ecf20Sopenharmony_ci echo "Failed to reload into netns \"testns1\"" 2398c2ecf20Sopenharmony_ci exit 1 2408c2ecf20Sopenharmony_ci fi 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cicleanup() 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci pre_cleanup 2468c2ecf20Sopenharmony_ci devlink -N testns1 dev reload $DEVLINK_DEV netns $$ 2478c2ecf20Sopenharmony_ci ip netns del testns1 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_citrap cleanup EXIT 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cisetup_prepare 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_citests_run 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ciexit $EXIT_STATUS 257