Path: blob/master/tools/testing/selftests/drivers/net/mlxsw/fib_offload.sh
26292 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Test unicast FIB offload indication.45lib_dir=$(dirname $0)/../../../net/forwarding67ALL_TESTS="8ipv6_route_add9ipv6_route_replace10ipv6_route_nexthop_group_share11ipv6_route_rate12"13NUM_NETIFS=414source $lib_dir/lib.sh15source $lib_dir/devlink_lib.sh1617tor1_create()18{19simple_if_init $tor1_p1 2001:db8:1::2/128 2001:db8:1::3/12820}2122tor1_destroy()23{24simple_if_fini $tor1_p1 2001:db8:1::2/128 2001:db8:1::3/12825}2627tor2_create()28{29simple_if_init $tor2_p1 2001:db8:2::2/128 2001:db8:2::3/12830}3132tor2_destroy()33{34simple_if_fini $tor2_p1 2001:db8:2::2/128 2001:db8:2::3/12835}3637spine_create()38{39ip link set dev $spine_p1 up40ip link set dev $spine_p2 up4142__addr_add_del $spine_p1 add 2001:db8:1::1/6443__addr_add_del $spine_p2 add 2001:db8:2::1/6444}4546spine_destroy()47{48__addr_add_del $spine_p2 del 2001:db8:2::1/6449__addr_add_del $spine_p1 del 2001:db8:1::1/645051ip link set dev $spine_p2 down52ip link set dev $spine_p1 down53}5455ipv6_offload_check()56{57local pfx="$1"; shift58local expected_num=$1; shift59local num6061# Try to avoid races with route offload62sleep .16364num=$(ip -6 route show match ${pfx} | grep "offload" | wc -l)6566if [ $num -eq $expected_num ]; then67return 068fi6970return 171}7273ipv6_route_add_prefix()74{75RET=07677# Add a prefix route and check that it is offloaded.78ip -6 route add 2001:db8:3::/64 dev $spine_p1 metric 10079ipv6_offload_check "2001:db8:3::/64 dev $spine_p1 metric 100" 180check_err $? "prefix route not offloaded"8182# Append an identical prefix route with an higher metric and check that83# offload indication did not change.84ip -6 route append 2001:db8:3::/64 dev $spine_p1 metric 20085ipv6_offload_check "2001:db8:3::/64 dev $spine_p1 metric 100" 186check_err $? "lowest metric not offloaded after append"87ipv6_offload_check "2001:db8:3::/64 dev $spine_p1 metric 200" 088check_err $? "highest metric offloaded when should not"8990# Prepend an identical prefix route with lower metric and check that91# it is offloaded and the others are not.92ip -6 route append 2001:db8:3::/64 dev $spine_p1 metric 1093ipv6_offload_check "2001:db8:3::/64 dev $spine_p1 metric 10" 194check_err $? "lowest metric not offloaded after prepend"95ipv6_offload_check "2001:db8:3::/64 dev $spine_p1 metric 100" 096check_err $? "mid metric offloaded when should not"97ipv6_offload_check "2001:db8:3::/64 dev $spine_p1 metric 200" 098check_err $? "highest metric offloaded when should not"99100# Delete the routes and add the same route with a different nexthop101# device. Check that it is offloaded.102ip -6 route flush 2001:db8:3::/64 dev $spine_p1103ip -6 route add 2001:db8:3::/64 dev $spine_p2104ipv6_offload_check "2001:db8:3::/64 dev $spine_p2" 1105106log_test "IPv6 prefix route add"107108ip -6 route flush 2001:db8:3::/64109}110111ipv6_route_add_mpath()112{113RET=0114115# Add a multipath route and check that it is offloaded.116ip -6 route add 2001:db8:3::/64 metric 100 \117nexthop via 2001:db8:1::2 dev $spine_p1 \118nexthop via 2001:db8:2::2 dev $spine_p2119ipv6_offload_check "2001:db8:3::/64 metric 100" 2120check_err $? "multipath route not offloaded when should"121122# Append another nexthop and check that it is offloaded as well.123ip -6 route append 2001:db8:3::/64 metric 100 \124nexthop via 2001:db8:1::3 dev $spine_p1125ipv6_offload_check "2001:db8:3::/64 metric 100" 3126check_err $? "appended nexthop not offloaded when should"127128# Mimic route replace by removing the route and adding it back with129# only two nexthops.130ip -6 route del 2001:db8:3::/64131ip -6 route add 2001:db8:3::/64 metric 100 \132nexthop via 2001:db8:1::2 dev $spine_p1 \133nexthop via 2001:db8:2::2 dev $spine_p2134ipv6_offload_check "2001:db8:3::/64 metric 100" 2135check_err $? "multipath route not offloaded after delete & add"136137# Append a nexthop with an higher metric and check that the offload138# indication did not change.139ip -6 route append 2001:db8:3::/64 metric 200 \140nexthop via 2001:db8:1::3 dev $spine_p1141ipv6_offload_check "2001:db8:3::/64 metric 100" 2142check_err $? "lowest metric not offloaded after append"143ipv6_offload_check "2001:db8:3::/64 metric 200" 0144check_err $? "highest metric offloaded when should not"145146# Prepend a nexthop with a lower metric and check that it is offloaded147# and the others are not.148ip -6 route append 2001:db8:3::/64 metric 10 \149nexthop via 2001:db8:1::3 dev $spine_p1150ipv6_offload_check "2001:db8:3::/64 metric 10" 1151check_err $? "lowest metric not offloaded after prepend"152ipv6_offload_check "2001:db8:3::/64 metric 100" 0153check_err $? "mid metric offloaded when should not"154ipv6_offload_check "2001:db8:3::/64 metric 200" 0155check_err $? "highest metric offloaded when should not"156157log_test "IPv6 multipath route add"158159ip -6 route flush 2001:db8:3::/64160}161162ipv6_route_add()163{164ipv6_route_add_prefix165ipv6_route_add_mpath166}167168ipv6_route_replace()169{170RET=0171172# Replace prefix route with prefix route.173ip -6 route add 2001:db8:3::/64 metric 100 dev $spine_p1174ipv6_offload_check "2001:db8:3::/64 metric 100" 1175check_err $? "prefix route not offloaded when should"176ip -6 route replace 2001:db8:3::/64 metric 100 dev $spine_p2177ipv6_offload_check "2001:db8:3::/64 metric 100" 1178check_err $? "prefix route not offloaded after replace"179180# Replace prefix route with multipath route.181ip -6 route replace 2001:db8:3::/64 metric 100 \182nexthop via 2001:db8:1::2 dev $spine_p1 \183nexthop via 2001:db8:2::2 dev $spine_p2184ipv6_offload_check "2001:db8:3::/64 metric 100" 2185check_err $? "multipath route not offloaded after replace"186187# Replace multipath route with prefix route. A prefix route cannot188# replace a multipath route, so it is appended.189ip -6 route replace 2001:db8:3::/64 metric 100 dev $spine_p1190ipv6_offload_check "2001:db8:3::/64 metric 100 dev $spine_p1" 0191check_err $? "prefix route offloaded after 'replacing' multipath route"192ipv6_offload_check "2001:db8:3::/64 metric 100" 2193check_err $? "multipath route not offloaded after being 'replaced' by prefix route"194195# Replace multipath route with multipath route.196ip -6 route replace 2001:db8:3::/64 metric 100 \197nexthop via 2001:db8:1::3 dev $spine_p1 \198nexthop via 2001:db8:2::3 dev $spine_p2199ipv6_offload_check "2001:db8:3::/64 metric 100" 2200check_err $? "multipath route not offloaded after replacing multipath route"201202# Replace a non-existing multipath route with a multipath route and203# check that it is appended and not offloaded.204ip -6 route replace 2001:db8:3::/64 metric 200 \205nexthop via 2001:db8:1::3 dev $spine_p1 \206nexthop via 2001:db8:2::3 dev $spine_p2207ipv6_offload_check "2001:db8:3::/64 metric 100" 2208check_err $? "multipath route not offloaded after non-existing route was 'replaced'"209ipv6_offload_check "2001:db8:3::/64 metric 200" 0210check_err $? "multipath route offloaded after 'replacing' non-existing route"211212log_test "IPv6 route replace"213214ip -6 route flush 2001:db8:3::/64215}216217ipv6_route_nexthop_group_share()218{219RET=0220221# The driver consolidates identical nexthop groups in order to reduce222# the resource usage in its adjacency table. Check that the deletion223# of one multipath route using the group does not affect the other.224ip -6 route add 2001:db8:3::/64 \225nexthop via 2001:db8:1::2 dev $spine_p1 \226nexthop via 2001:db8:2::2 dev $spine_p2227ip -6 route add 2001:db8:4::/64 \228nexthop via 2001:db8:1::2 dev $spine_p1 \229nexthop via 2001:db8:2::2 dev $spine_p2230ipv6_offload_check "2001:db8:3::/64" 2231check_err $? "multipath route not offloaded when should"232ipv6_offload_check "2001:db8:4::/64" 2233check_err $? "multipath route not offloaded when should"234ip -6 route del 2001:db8:3::/64235ipv6_offload_check "2001:db8:4::/64" 2236check_err $? "multipath route not offloaded after deletion of route sharing the nexthop group"237238# Check that after unsharing a nexthop group the routes are still239# marked as offloaded.240ip -6 route add 2001:db8:3::/64 \241nexthop via 2001:db8:1::2 dev $spine_p1 \242nexthop via 2001:db8:2::2 dev $spine_p2243ip -6 route del 2001:db8:4::/64 \244nexthop via 2001:db8:1::2 dev $spine_p1245ipv6_offload_check "2001:db8:4::/64" 1246check_err $? "singlepath route not offloaded after unsharing the nexthop group"247ipv6_offload_check "2001:db8:3::/64" 2248check_err $? "multipath route not offloaded after unsharing the nexthop group"249250log_test "IPv6 nexthop group sharing"251252ip -6 route flush 2001:db8:3::/64253ip -6 route flush 2001:db8:4::/64254}255256ipv6_route_rate()257{258local batch_dir=$(mktemp -d)259local num_rts=$((40 * 1024))260local num_nhs=16261local total262local start263local diff264local end265local nhs266local i267268RET=0269270# Prepare 40K /64 multipath routes with 16 nexthops each and check how271# long it takes to add them. A limit of 60 seconds is set. It is much272# higher than insertion should take and meant to flag a serious273# regression.274total=$((nums_nhs * num_rts))275276for i in $(seq 1 $num_nhs); do277ip -6 address add 2001:db8:1::10:$i/128 dev $tor1_p1278nexthops+=" nexthop via 2001:db8:1::10:$i dev $spine_p1"279done280281for i in $(seq 1 $num_rts); do282echo "route add 2001:db8:8:$(printf "%x" $i)::/64$nexthops" \283>> $batch_dir/add.batch284echo "route del 2001:db8:8:$(printf "%x" $i)::/64$nexthops" \285>> $batch_dir/del.batch286done287288start=$(date +%s.%N)289290ip -batch $batch_dir/add.batch291count=$(ip -6 route show | grep offload | wc -l)292while [ $count -lt $total ]; do293sleep .01294count=$(ip -6 route show | grep offload | wc -l)295done296297end=$(date +%s.%N)298299diff=$(echo "$end - $start" | bc -l)300test "$(echo "$diff > 60" | bc -l)" -eq 0301check_err $? "route insertion took too long"302log_info "inserted $num_rts routes in $diff seconds"303304log_test "IPv6 routes insertion rate"305306ip -batch $batch_dir/del.batch307for i in $(seq 1 $num_nhs); do308ip -6 address del 2001:db8:1::10:$i/128 dev $tor1_p1309done310rm -rf $batch_dir311}312313setup_prepare()314{315spine_p1=${NETIFS[p1]}316tor1_p1=${NETIFS[p2]}317318spine_p2=${NETIFS[p3]}319tor2_p1=${NETIFS[p4]}320321vrf_prepare322forwarding_enable323324tor1_create325tor2_create326spine_create327}328329cleanup()330{331pre_cleanup332333spine_destroy334tor2_destroy335tor1_destroy336337forwarding_restore338vrf_cleanup339}340341trap cleanup EXIT342343setup_prepare344setup_wait345346tests_run347348exit $EXIT_STATUS349350351