1212a37c2SIdo Schimmel#!/bin/bash 2212a37c2SIdo Schimmel# SPDX-License-Identifier: GPL-2.0 3212a37c2SIdo Schimmel# 4212a37c2SIdo Schimmel# This test is for checking the FIB offload API on top of mlxsw. 5212a37c2SIdo Schimmel 6212a37c2SIdo Schimmellib_dir=$(dirname $0)/../../../net/forwarding 7212a37c2SIdo Schimmel 8212a37c2SIdo SchimmelALL_TESTS=" 9212a37c2SIdo Schimmel ipv4_identical_routes 10212a37c2SIdo Schimmel ipv4_tos 11212a37c2SIdo Schimmel ipv4_metric 12212a37c2SIdo Schimmel ipv4_replace 13212a37c2SIdo Schimmel ipv4_delete 14212a37c2SIdo Schimmel ipv4_plen 15212a37c2SIdo Schimmel ipv4_replay 16212a37c2SIdo Schimmel ipv4_flush 176c05ca26SIdo Schimmel ipv4_local_replace 18212a37c2SIdo Schimmel ipv6_add 19212a37c2SIdo Schimmel ipv6_metric 20212a37c2SIdo Schimmel ipv6_append_single 21212a37c2SIdo Schimmel ipv6_replace_single 22212a37c2SIdo Schimmel ipv6_metric_multipath 23212a37c2SIdo Schimmel ipv6_append_multipath 24212a37c2SIdo Schimmel ipv6_replace_multipath 25212a37c2SIdo Schimmel ipv6_append_multipath_to_single 26212a37c2SIdo Schimmel ipv6_delete_single 27212a37c2SIdo Schimmel ipv6_delete_multipath 28212a37c2SIdo Schimmel ipv6_replay_single 29212a37c2SIdo Schimmel ipv6_replay_multipath 306c05ca26SIdo Schimmel ipv6_local_replace 31212a37c2SIdo Schimmel" 32212a37c2SIdo SchimmelNUM_NETIFS=0 33212a37c2SIdo Schimmelsource $lib_dir/lib.sh 34212a37c2SIdo Schimmelsource $lib_dir/devlink_lib.sh 35212a37c2SIdo Schimmelsource $lib_dir/fib_offload_lib.sh 36212a37c2SIdo Schimmel 37212a37c2SIdo Schimmelipv4_identical_routes() 38212a37c2SIdo Schimmel{ 39212a37c2SIdo Schimmel fib_ipv4_identical_routes_test "testns1" 40212a37c2SIdo Schimmel} 41212a37c2SIdo Schimmel 42212a37c2SIdo Schimmelipv4_tos() 43212a37c2SIdo Schimmel{ 44212a37c2SIdo Schimmel fib_ipv4_tos_test "testns1" 45212a37c2SIdo Schimmel} 46212a37c2SIdo Schimmel 47212a37c2SIdo Schimmelipv4_metric() 48212a37c2SIdo Schimmel{ 49212a37c2SIdo Schimmel fib_ipv4_metric_test "testns1" 50212a37c2SIdo Schimmel} 51212a37c2SIdo Schimmel 52212a37c2SIdo Schimmelipv4_replace() 53212a37c2SIdo Schimmel{ 54212a37c2SIdo Schimmel fib_ipv4_replace_test "testns1" 55212a37c2SIdo Schimmel} 56212a37c2SIdo Schimmel 57212a37c2SIdo Schimmelipv4_delete() 58212a37c2SIdo Schimmel{ 59212a37c2SIdo Schimmel fib_ipv4_delete_test "testns1" 60212a37c2SIdo Schimmel} 61212a37c2SIdo Schimmel 62212a37c2SIdo Schimmelipv4_plen() 63212a37c2SIdo Schimmel{ 64212a37c2SIdo Schimmel fib_ipv4_plen_test "testns1" 65212a37c2SIdo Schimmel} 66212a37c2SIdo Schimmel 67212a37c2SIdo Schimmelipv4_replay_metric() 68212a37c2SIdo Schimmel{ 69212a37c2SIdo Schimmel fib_ipv4_replay_metric_test "testns1" "$DEVLINK_DEV" 70212a37c2SIdo Schimmel} 71212a37c2SIdo Schimmel 72212a37c2SIdo Schimmelipv4_replay_tos() 73212a37c2SIdo Schimmel{ 74212a37c2SIdo Schimmel fib_ipv4_replay_tos_test "testns1" "$DEVLINK_DEV" 75212a37c2SIdo Schimmel} 76212a37c2SIdo Schimmel 77212a37c2SIdo Schimmelipv4_replay_plen() 78212a37c2SIdo Schimmel{ 79212a37c2SIdo Schimmel fib_ipv4_replay_plen_test "testns1" "$DEVLINK_DEV" 80212a37c2SIdo Schimmel} 81212a37c2SIdo Schimmel 82212a37c2SIdo Schimmelipv4_replay() 83212a37c2SIdo Schimmel{ 84212a37c2SIdo Schimmel ipv4_replay_metric 85212a37c2SIdo Schimmel ipv4_replay_tos 86212a37c2SIdo Schimmel ipv4_replay_plen 87212a37c2SIdo Schimmel} 88212a37c2SIdo Schimmel 89212a37c2SIdo Schimmelipv4_flush() 90212a37c2SIdo Schimmel{ 91212a37c2SIdo Schimmel fib_ipv4_flush_test "testns1" 92212a37c2SIdo Schimmel} 93212a37c2SIdo Schimmel 946c05ca26SIdo Schimmelipv4_local_replace() 956c05ca26SIdo Schimmel{ 966c05ca26SIdo Schimmel local ns="testns1" 976c05ca26SIdo Schimmel 986c05ca26SIdo Schimmel RET=0 996c05ca26SIdo Schimmel 1006c05ca26SIdo Schimmel ip -n $ns link add name dummy1 type dummy 1016c05ca26SIdo Schimmel ip -n $ns link set dev dummy1 up 1026c05ca26SIdo Schimmel 1036c05ca26SIdo Schimmel ip -n $ns route add table local 192.0.2.1/32 dev dummy1 1046c05ca26SIdo Schimmel fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false 1056c05ca26SIdo Schimmel check_err $? "Local table route not in hardware when should" 1066c05ca26SIdo Schimmel 1076c05ca26SIdo Schimmel ip -n $ns route add table main 192.0.2.1/32 dev dummy1 1086c05ca26SIdo Schimmel fib4_trap_check $ns "table main 192.0.2.1/32 dev dummy1" true 1096c05ca26SIdo Schimmel check_err $? "Main table route in hardware when should not" 1106c05ca26SIdo Schimmel 1116c05ca26SIdo Schimmel fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false 1126c05ca26SIdo Schimmel check_err $? "Local table route was replaced when should not" 1136c05ca26SIdo Schimmel 1146c05ca26SIdo Schimmel # Test that local routes can replace routes in main table. 1156c05ca26SIdo Schimmel ip -n $ns route add table main 192.0.2.2/32 dev dummy1 1166c05ca26SIdo Schimmel fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" false 1176c05ca26SIdo Schimmel check_err $? "Main table route not in hardware when should" 1186c05ca26SIdo Schimmel 1196c05ca26SIdo Schimmel ip -n $ns route add table local 192.0.2.2/32 dev dummy1 1206c05ca26SIdo Schimmel fib4_trap_check $ns "table local 192.0.2.2/32 dev dummy1" false 1216c05ca26SIdo Schimmel check_err $? "Local table route did not replace route in main table when should" 1226c05ca26SIdo Schimmel 1236c05ca26SIdo Schimmel fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" true 1246c05ca26SIdo Schimmel check_err $? "Main table route was not replaced when should" 1256c05ca26SIdo Schimmel 1266c05ca26SIdo Schimmel log_test "IPv4 local table route replacement" 1276c05ca26SIdo Schimmel 1286c05ca26SIdo Schimmel ip -n $ns link del dev dummy1 1296c05ca26SIdo Schimmel} 1306c05ca26SIdo Schimmel 131212a37c2SIdo Schimmelipv6_add() 132212a37c2SIdo Schimmel{ 133212a37c2SIdo Schimmel fib_ipv6_add_test "testns1" 134212a37c2SIdo Schimmel} 135212a37c2SIdo Schimmel 136212a37c2SIdo Schimmelipv6_metric() 137212a37c2SIdo Schimmel{ 138212a37c2SIdo Schimmel fib_ipv6_metric_test "testns1" 139212a37c2SIdo Schimmel} 140212a37c2SIdo Schimmel 141212a37c2SIdo Schimmelipv6_append_single() 142212a37c2SIdo Schimmel{ 143212a37c2SIdo Schimmel fib_ipv6_append_single_test "testns1" 144212a37c2SIdo Schimmel} 145212a37c2SIdo Schimmel 146212a37c2SIdo Schimmelipv6_replace_single() 147212a37c2SIdo Schimmel{ 148212a37c2SIdo Schimmel fib_ipv6_replace_single_test "testns1" 149212a37c2SIdo Schimmel} 150212a37c2SIdo Schimmel 151212a37c2SIdo Schimmelipv6_metric_multipath() 152212a37c2SIdo Schimmel{ 153212a37c2SIdo Schimmel fib_ipv6_metric_multipath_test "testns1" 154212a37c2SIdo Schimmel} 155212a37c2SIdo Schimmel 156212a37c2SIdo Schimmelipv6_append_multipath() 157212a37c2SIdo Schimmel{ 158212a37c2SIdo Schimmel fib_ipv6_append_multipath_test "testns1" 159212a37c2SIdo Schimmel} 160212a37c2SIdo Schimmel 161212a37c2SIdo Schimmelipv6_replace_multipath() 162212a37c2SIdo Schimmel{ 163212a37c2SIdo Schimmel fib_ipv6_replace_multipath_test "testns1" 164212a37c2SIdo Schimmel} 165212a37c2SIdo Schimmel 166212a37c2SIdo Schimmelipv6_append_multipath_to_single() 167212a37c2SIdo Schimmel{ 168212a37c2SIdo Schimmel fib_ipv6_append_multipath_to_single_test "testns1" 169212a37c2SIdo Schimmel} 170212a37c2SIdo Schimmel 171212a37c2SIdo Schimmelipv6_delete_single() 172212a37c2SIdo Schimmel{ 173212a37c2SIdo Schimmel fib_ipv6_delete_single_test "testns1" 174212a37c2SIdo Schimmel} 175212a37c2SIdo Schimmel 176212a37c2SIdo Schimmelipv6_delete_multipath() 177212a37c2SIdo Schimmel{ 178212a37c2SIdo Schimmel fib_ipv6_delete_multipath_test "testns1" 179212a37c2SIdo Schimmel} 180212a37c2SIdo Schimmel 181212a37c2SIdo Schimmelipv6_replay_single() 182212a37c2SIdo Schimmel{ 183212a37c2SIdo Schimmel fib_ipv6_replay_single_test "testns1" "$DEVLINK_DEV" 184212a37c2SIdo Schimmel} 185212a37c2SIdo Schimmel 186212a37c2SIdo Schimmelipv6_replay_multipath() 187212a37c2SIdo Schimmel{ 188212a37c2SIdo Schimmel fib_ipv6_replay_multipath_test "testns1" "$DEVLINK_DEV" 189212a37c2SIdo Schimmel} 190212a37c2SIdo Schimmel 1916c05ca26SIdo Schimmelipv6_local_replace() 1926c05ca26SIdo Schimmel{ 1936c05ca26SIdo Schimmel local ns="testns1" 1946c05ca26SIdo Schimmel 1956c05ca26SIdo Schimmel RET=0 1966c05ca26SIdo Schimmel 1976c05ca26SIdo Schimmel ip -n $ns link add name dummy1 type dummy 1986c05ca26SIdo Schimmel ip -n $ns link set dev dummy1 up 1996c05ca26SIdo Schimmel 2006c05ca26SIdo Schimmel ip -n $ns route add table local 2001:db8:1::1/128 dev dummy1 2016c05ca26SIdo Schimmel fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false 2026c05ca26SIdo Schimmel check_err $? "Local table route not in hardware when should" 2036c05ca26SIdo Schimmel 2046c05ca26SIdo Schimmel ip -n $ns route add table main 2001:db8:1::1/128 dev dummy1 2056c05ca26SIdo Schimmel fib6_trap_check $ns "table main 2001:db8:1::1/128 dev dummy1" true 2066c05ca26SIdo Schimmel check_err $? "Main table route in hardware when should not" 2076c05ca26SIdo Schimmel 2086c05ca26SIdo Schimmel fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false 2096c05ca26SIdo Schimmel check_err $? "Local table route was replaced when should not" 2106c05ca26SIdo Schimmel 2116c05ca26SIdo Schimmel # Test that local routes can replace routes in main table. 2126c05ca26SIdo Schimmel ip -n $ns route add table main 2001:db8:1::2/128 dev dummy1 2136c05ca26SIdo Schimmel fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" false 2146c05ca26SIdo Schimmel check_err $? "Main table route not in hardware when should" 2156c05ca26SIdo Schimmel 2166c05ca26SIdo Schimmel ip -n $ns route add table local 2001:db8:1::2/128 dev dummy1 2176c05ca26SIdo Schimmel fib6_trap_check $ns "table local 2001:db8:1::2/128 dev dummy1" false 2186c05ca26SIdo Schimmel check_err $? "Local route route did not replace route in main table when should" 2196c05ca26SIdo Schimmel 2206c05ca26SIdo Schimmel fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" true 2216c05ca26SIdo Schimmel check_err $? "Main table route was not replaced when should" 2226c05ca26SIdo Schimmel 2236c05ca26SIdo Schimmel log_test "IPv6 local table route replacement" 2246c05ca26SIdo Schimmel 2256c05ca26SIdo Schimmel ip -n $ns link del dev dummy1 2266c05ca26SIdo Schimmel} 2276c05ca26SIdo Schimmel 228*d1a7a489SAmit Cohenfib_notify_on_flag_change_set() 229*d1a7a489SAmit Cohen{ 230*d1a7a489SAmit Cohen local notify=$1; shift 231*d1a7a489SAmit Cohen 232*d1a7a489SAmit Cohen ip netns exec testns1 sysctl -qw net.ipv4.fib_notify_on_flag_change=$notify 233*d1a7a489SAmit Cohen ip netns exec testns1 sysctl -qw net.ipv6.fib_notify_on_flag_change=$notify 234*d1a7a489SAmit Cohen 235*d1a7a489SAmit Cohen log_info "Set fib_notify_on_flag_change to $notify" 236*d1a7a489SAmit Cohen} 237*d1a7a489SAmit Cohen 238212a37c2SIdo Schimmelsetup_prepare() 239212a37c2SIdo Schimmel{ 240212a37c2SIdo Schimmel ip netns add testns1 241212a37c2SIdo Schimmel if [ $? -ne 0 ]; then 242212a37c2SIdo Schimmel echo "Failed to add netns \"testns1\"" 243212a37c2SIdo Schimmel exit 1 244212a37c2SIdo Schimmel fi 245212a37c2SIdo Schimmel 246212a37c2SIdo Schimmel devlink dev reload $DEVLINK_DEV netns testns1 247212a37c2SIdo Schimmel if [ $? -ne 0 ]; then 248212a37c2SIdo Schimmel echo "Failed to reload into netns \"testns1\"" 249212a37c2SIdo Schimmel exit 1 250212a37c2SIdo Schimmel fi 251212a37c2SIdo Schimmel} 252212a37c2SIdo Schimmel 253212a37c2SIdo Schimmelcleanup() 254212a37c2SIdo Schimmel{ 255212a37c2SIdo Schimmel pre_cleanup 256212a37c2SIdo Schimmel devlink -N testns1 dev reload $DEVLINK_DEV netns $$ 257212a37c2SIdo Schimmel ip netns del testns1 258212a37c2SIdo Schimmel} 259212a37c2SIdo Schimmel 260212a37c2SIdo Schimmeltrap cleanup EXIT 261212a37c2SIdo Schimmel 262212a37c2SIdo Schimmelsetup_prepare 263212a37c2SIdo Schimmel 264*d1a7a489SAmit Cohenfib_notify_on_flag_change_set 1 265*d1a7a489SAmit Cohentests_run 266*d1a7a489SAmit Cohen 267*d1a7a489SAmit Cohenfib_notify_on_flag_change_set 0 268212a37c2SIdo Schimmeltests_run 269212a37c2SIdo Schimmel 270212a37c2SIdo Schimmelexit $EXIT_STATUS 271