13dd91570SIdo Schimmel#!/bin/bash 23dd91570SIdo Schimmel# SPDX-License-Identifier: GPL-2.0 33dd91570SIdo Schimmel 43dd91570SIdo Schimmel# This test is for checking the A-TCAM and C-TCAM operation in Spectrum-2. 53dd91570SIdo Schimmel# It tries to exercise as many code paths in the eRP state machine as 63dd91570SIdo Schimmel# possible. 73dd91570SIdo Schimmel 83dd91570SIdo Schimmellib_dir=$(dirname $0)/../../../../net/forwarding 93dd91570SIdo Schimmel 103dd91570SIdo SchimmelALL_TESTS="single_mask_test identical_filters_test two_masks_test \ 11095c7208SNir Dotan multiple_masks_test ctcam_edge_cases_test delta_simple_test \ 12c478d3c3SJiri Pirko delta_two_masks_one_key_test delta_simple_rehash_test \ 136d6eeabcSAmit Cohen bloom_simple_test bloom_complex_test bloom_delta_test \ 1475d8d7a6SIdo Schimmel max_erp_entries_test max_group_size_test collision_test" 153dd91570SIdo SchimmelNUM_NETIFS=2 162cca8751SPetr Machatasource $lib_dir/lib.sh 173dd91570SIdo Schimmelsource $lib_dir/tc_common.sh 18c478d3c3SJiri Pirkosource $lib_dir/devlink_lib.sh 193dd91570SIdo Schimmel 203dd91570SIdo Schimmeltcflags="skip_hw" 213dd91570SIdo Schimmel 223dd91570SIdo Schimmelh1_create() 233dd91570SIdo Schimmel{ 243dd91570SIdo Schimmel simple_if_init $h1 192.0.2.1/24 198.51.100.1/24 253dd91570SIdo Schimmel} 263dd91570SIdo Schimmel 273dd91570SIdo Schimmelh1_destroy() 283dd91570SIdo Schimmel{ 293dd91570SIdo Schimmel simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24 303dd91570SIdo Schimmel} 313dd91570SIdo Schimmel 323dd91570SIdo Schimmelh2_create() 333dd91570SIdo Schimmel{ 343dd91570SIdo Schimmel simple_if_init $h2 192.0.2.2/24 198.51.100.2/24 353dd91570SIdo Schimmel tc qdisc add dev $h2 clsact 363dd91570SIdo Schimmel} 373dd91570SIdo Schimmel 383dd91570SIdo Schimmelh2_destroy() 393dd91570SIdo Schimmel{ 403dd91570SIdo Schimmel tc qdisc del dev $h2 clsact 413dd91570SIdo Schimmel simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24 423dd91570SIdo Schimmel} 433dd91570SIdo Schimmel 441eadbd3aSJiri Pirkotp_record() 451eadbd3aSJiri Pirko{ 461eadbd3aSJiri Pirko local tracepoint=$1 471eadbd3aSJiri Pirko local cmd=$2 481eadbd3aSJiri Pirko 491eadbd3aSJiri Pirko perf record -q -e $tracepoint $cmd 501eadbd3aSJiri Pirko return $? 511eadbd3aSJiri Pirko} 521eadbd3aSJiri Pirko 531eadbd3aSJiri Pirkotp_record_all() 541eadbd3aSJiri Pirko{ 551eadbd3aSJiri Pirko local tracepoint=$1 561eadbd3aSJiri Pirko local seconds=$2 571eadbd3aSJiri Pirko 581eadbd3aSJiri Pirko perf record -a -q -e $tracepoint sleep $seconds 591eadbd3aSJiri Pirko return $? 601eadbd3aSJiri Pirko} 611eadbd3aSJiri Pirko 621eadbd3aSJiri Pirko__tp_hit_count() 631eadbd3aSJiri Pirko{ 641eadbd3aSJiri Pirko local tracepoint=$1 651eadbd3aSJiri Pirko 661eadbd3aSJiri Pirko local perf_output=`perf script -F trace:event,trace` 671eadbd3aSJiri Pirko return `echo $perf_output | grep "$tracepoint:" | wc -l` 681eadbd3aSJiri Pirko} 691eadbd3aSJiri Pirko 701eadbd3aSJiri Pirkotp_check_hits() 711eadbd3aSJiri Pirko{ 721eadbd3aSJiri Pirko local tracepoint=$1 731eadbd3aSJiri Pirko local count=$2 741eadbd3aSJiri Pirko 751eadbd3aSJiri Pirko __tp_hit_count $tracepoint 761eadbd3aSJiri Pirko if [[ "$?" -ne "$count" ]]; then 771eadbd3aSJiri Pirko return 1 781eadbd3aSJiri Pirko fi 791eadbd3aSJiri Pirko return 0 801eadbd3aSJiri Pirko} 811eadbd3aSJiri Pirko 821eadbd3aSJiri Pirkotp_check_hits_any() 831eadbd3aSJiri Pirko{ 841eadbd3aSJiri Pirko local tracepoint=$1 851eadbd3aSJiri Pirko 861eadbd3aSJiri Pirko __tp_hit_count $tracepoint 871eadbd3aSJiri Pirko if [[ "$?" -eq "0" ]]; then 881eadbd3aSJiri Pirko return 1 891eadbd3aSJiri Pirko fi 901eadbd3aSJiri Pirko return 0 911eadbd3aSJiri Pirko} 921eadbd3aSJiri Pirko 933dd91570SIdo Schimmelsingle_mask_test() 943dd91570SIdo Schimmel{ 953dd91570SIdo Schimmel # When only a single mask is required, the device uses the master 963dd91570SIdo Schimmel # mask and not the eRP table. Verify that under this mode the right 973dd91570SIdo Schimmel # filter is matched 983dd91570SIdo Schimmel 993dd91570SIdo Schimmel RET=0 1003dd91570SIdo Schimmel 1013dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 1023dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 1033dd91570SIdo Schimmel 1043dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 1053dd91570SIdo Schimmel -t ip -q 1063dd91570SIdo Schimmel 1073dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 101 1 1083dd91570SIdo Schimmel check_err $? "Single filter - did not match" 1093dd91570SIdo Schimmel 1103dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 1113dd91570SIdo Schimmel $tcflags dst_ip 198.51.100.2 action drop 1123dd91570SIdo Schimmel 1133dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 1143dd91570SIdo Schimmel -t ip -q 1153dd91570SIdo Schimmel 1163dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 101 2 1173dd91570SIdo Schimmel check_err $? "Two filters - did not match highest priority" 1183dd91570SIdo Schimmel 1193dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 198.51.100.1 -B 198.51.100.2 \ 1203dd91570SIdo Schimmel -t ip -q 1213dd91570SIdo Schimmel 1223dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 102 1 1233dd91570SIdo Schimmel check_err $? "Two filters - did not match lowest priority" 1243dd91570SIdo Schimmel 1253dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 1263dd91570SIdo Schimmel 1273dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 198.51.100.1 -B 198.51.100.2 \ 1283dd91570SIdo Schimmel -t ip -q 1293dd91570SIdo Schimmel 1303dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 102 2 1313dd91570SIdo Schimmel check_err $? "Single filter - did not match after delete" 1323dd91570SIdo Schimmel 1333dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 1343dd91570SIdo Schimmel 1353dd91570SIdo Schimmel log_test "single mask test ($tcflags)" 1363dd91570SIdo Schimmel} 1373dd91570SIdo Schimmel 1383dd91570SIdo Schimmelidentical_filters_test() 1393dd91570SIdo Schimmel{ 1403dd91570SIdo Schimmel # When two filters that only differ in their priority are used, 1413dd91570SIdo Schimmel # one needs to be inserted into the C-TCAM. This test verifies 1423dd91570SIdo Schimmel # that filters are correctly spilled to C-TCAM and that the right 1433dd91570SIdo Schimmel # filter is matched 1443dd91570SIdo Schimmel 1453dd91570SIdo Schimmel RET=0 1463dd91570SIdo Schimmel 1473dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 1483dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 1493dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 1503dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 1513dd91570SIdo Schimmel 1523dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 1533dd91570SIdo Schimmel -t ip -q 1543dd91570SIdo Schimmel 1553dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 101 1 1563dd91570SIdo Schimmel check_err $? "Did not match A-TCAM filter" 1573dd91570SIdo Schimmel 1583dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 1593dd91570SIdo Schimmel 1603dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 1613dd91570SIdo Schimmel -t ip -q 1623dd91570SIdo Schimmel 1633dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 102 1 1643dd91570SIdo Schimmel check_err $? "Did not match C-TCAM filter after A-TCAM delete" 1653dd91570SIdo Schimmel 1663dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ 1673dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 1683dd91570SIdo Schimmel 1693dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 1703dd91570SIdo Schimmel -t ip -q 1713dd91570SIdo Schimmel 1723dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 102 2 1733dd91570SIdo Schimmel check_err $? "Did not match C-TCAM filter after A-TCAM add" 1743dd91570SIdo Schimmel 1753dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 1763dd91570SIdo Schimmel 1773dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 1783dd91570SIdo Schimmel -t ip -q 1793dd91570SIdo Schimmel 1803dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 103 1 1813dd91570SIdo Schimmel check_err $? "Did not match A-TCAM filter after C-TCAM delete" 1823dd91570SIdo Schimmel 1833dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower 1843dd91570SIdo Schimmel 1853dd91570SIdo Schimmel log_test "identical filters test ($tcflags)" 1863dd91570SIdo Schimmel} 1873dd91570SIdo Schimmel 1883dd91570SIdo Schimmeltwo_masks_test() 1893dd91570SIdo Schimmel{ 1903dd91570SIdo Schimmel # When more than one mask is required, the eRP table is used. This 1913dd91570SIdo Schimmel # test verifies that the eRP table is correctly allocated and used 1923dd91570SIdo Schimmel 1933dd91570SIdo Schimmel RET=0 1943dd91570SIdo Schimmel 1953dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 1963dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 1973dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ 19836107c48SJiri Pirko $tcflags dst_ip 192.0.0.0/8 action drop 1993dd91570SIdo Schimmel 2003dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 2013dd91570SIdo Schimmel -t ip -q 2023dd91570SIdo Schimmel 2033dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 101 1 2043dd91570SIdo Schimmel check_err $? "Two filters - did not match highest priority" 2053dd91570SIdo Schimmel 2063dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 2073dd91570SIdo Schimmel 2083dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 2093dd91570SIdo Schimmel -t ip -q 2103dd91570SIdo Schimmel 2113dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 103 1 2123dd91570SIdo Schimmel check_err $? "Single filter - did not match" 2133dd91570SIdo Schimmel 2143dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 2153dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.0/24 action drop 2163dd91570SIdo Schimmel 2173dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 2183dd91570SIdo Schimmel -t ip -q 2193dd91570SIdo Schimmel 2203dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 102 1 2213dd91570SIdo Schimmel check_err $? "Two filters - did not match highest priority after add" 2223dd91570SIdo Schimmel 2233dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower 2243dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 2253dd91570SIdo Schimmel 2263dd91570SIdo Schimmel log_test "two masks test ($tcflags)" 2273dd91570SIdo Schimmel} 2283dd91570SIdo Schimmel 2293dd91570SIdo Schimmelmultiple_masks_test() 2303dd91570SIdo Schimmel{ 2313dd91570SIdo Schimmel # The number of masks in a region is limited. Once the maximum 2323dd91570SIdo Schimmel # number of masks has been reached filters that require new 2333dd91570SIdo Schimmel # masks are spilled to the C-TCAM. This test verifies that 2343dd91570SIdo Schimmel # spillage is performed correctly and that the right filter is 2353dd91570SIdo Schimmel # matched 2363dd91570SIdo Schimmel 2370d0f20fbSJiri Pirko if [[ "$tcflags" != "skip_sw" ]]; then 2380d0f20fbSJiri Pirko return 0; 2390d0f20fbSJiri Pirko fi 2400d0f20fbSJiri Pirko 2413dd91570SIdo Schimmel local index 2423dd91570SIdo Schimmel 2433dd91570SIdo Schimmel RET=0 2443dd91570SIdo Schimmel 2453dd91570SIdo Schimmel NUM_MASKS=32 2460d0f20fbSJiri Pirko NUM_ERPS=16 2473dd91570SIdo Schimmel BASE_INDEX=100 2483dd91570SIdo Schimmel 2493dd91570SIdo Schimmel for i in $(eval echo {1..$NUM_MASKS}); do 2503dd91570SIdo Schimmel index=$((BASE_INDEX - i)) 2513dd91570SIdo Schimmel 2520d0f20fbSJiri Pirko if ((i > NUM_ERPS)); then 2530d0f20fbSJiri Pirko exp_hits=1 2540d0f20fbSJiri Pirko err_msg="$i filters - C-TCAM spill did not happen when it was expected" 2550d0f20fbSJiri Pirko else 2560d0f20fbSJiri Pirko exp_hits=0 2570d0f20fbSJiri Pirko err_msg="$i filters - C-TCAM spill happened when it should not" 2580d0f20fbSJiri Pirko fi 2590d0f20fbSJiri Pirko 2600d0f20fbSJiri Pirko tp_record "mlxsw:mlxsw_sp_acl_atcam_entry_add_ctcam_spill" \ 2610d0f20fbSJiri Pirko "tc filter add dev $h2 ingress protocol ip pref $index \ 2623dd91570SIdo Schimmel handle $index \ 2630d0f20fbSJiri Pirko flower $tcflags \ 2640d0f20fbSJiri Pirko dst_ip 192.0.2.2/${i} src_ip 192.0.2.1/${i} \ 2650d0f20fbSJiri Pirko action drop" 2660d0f20fbSJiri Pirko tp_check_hits "mlxsw:mlxsw_sp_acl_atcam_entry_add_ctcam_spill" \ 2670d0f20fbSJiri Pirko $exp_hits 2680d0f20fbSJiri Pirko check_err $? "$err_msg" 2693dd91570SIdo Schimmel 2703dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 \ 2713dd91570SIdo Schimmel -B 192.0.2.2 -t ip -q 2723dd91570SIdo Schimmel 2733dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" $index 1 2743dd91570SIdo Schimmel check_err $? "$i filters - did not match highest priority (add)" 2753dd91570SIdo Schimmel done 2763dd91570SIdo Schimmel 2773dd91570SIdo Schimmel for i in $(eval echo {$NUM_MASKS..1}); do 2783dd91570SIdo Schimmel index=$((BASE_INDEX - i)) 2793dd91570SIdo Schimmel 2803dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 \ 2813dd91570SIdo Schimmel -B 192.0.2.2 -t ip -q 2823dd91570SIdo Schimmel 2833dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" $index 2 2843dd91570SIdo Schimmel check_err $? "$i filters - did not match highest priority (del)" 2853dd91570SIdo Schimmel 2863dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref $index \ 2873dd91570SIdo Schimmel handle $index flower 2883dd91570SIdo Schimmel done 2893dd91570SIdo Schimmel 2903dd91570SIdo Schimmel log_test "multiple masks test ($tcflags)" 2913dd91570SIdo Schimmel} 2923dd91570SIdo Schimmel 2933dd91570SIdo Schimmelctcam_two_atcam_masks_test() 2943dd91570SIdo Schimmel{ 2953dd91570SIdo Schimmel RET=0 2963dd91570SIdo Schimmel 2973dd91570SIdo Schimmel # First case: C-TCAM is disabled when there are two A-TCAM masks. 2983dd91570SIdo Schimmel # We push a filter into the C-TCAM by using two identical filters 2993dd91570SIdo Schimmel # as in identical_filters_test() 3003dd91570SIdo Schimmel 3013dd91570SIdo Schimmel # Filter goes into A-TCAM 3023dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 3033dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 3043dd91570SIdo Schimmel # Filter goes into C-TCAM 3053dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 3063dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 3073dd91570SIdo Schimmel # Filter goes into A-TCAM 3083dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ 3097dc5a0eeSJiri Pirko $tcflags dst_ip 192.0.0.0/16 action drop 3103dd91570SIdo Schimmel 3113dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 3123dd91570SIdo Schimmel -t ip -q 3133dd91570SIdo Schimmel 3143dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 101 1 3153dd91570SIdo Schimmel check_err $? "Did not match A-TCAM filter" 3163dd91570SIdo Schimmel 3173dd91570SIdo Schimmel # Delete both A-TCAM and C-TCAM filters and make sure the remaining 3183dd91570SIdo Schimmel # A-TCAM filter still works 3193dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 3203dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 3213dd91570SIdo Schimmel 3223dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 3233dd91570SIdo Schimmel -t ip -q 3243dd91570SIdo Schimmel 3253dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 103 1 3263dd91570SIdo Schimmel check_err $? "Did not match A-TCAM filter" 3273dd91570SIdo Schimmel 3283dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower 3293dd91570SIdo Schimmel 3303dd91570SIdo Schimmel log_test "ctcam with two atcam masks test ($tcflags)" 3313dd91570SIdo Schimmel} 3323dd91570SIdo Schimmel 3333dd91570SIdo Schimmelctcam_one_atcam_mask_test() 3343dd91570SIdo Schimmel{ 3353dd91570SIdo Schimmel RET=0 3363dd91570SIdo Schimmel 3373dd91570SIdo Schimmel # Second case: C-TCAM is disabled when there is one A-TCAM mask. 3383dd91570SIdo Schimmel # The test is similar to identical_filters_test() 3393dd91570SIdo Schimmel 3403dd91570SIdo Schimmel # Filter goes into A-TCAM 3413dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 3423dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 3433dd91570SIdo Schimmel # Filter goes into C-TCAM 3443dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 3453dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 3463dd91570SIdo Schimmel 3473dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 3483dd91570SIdo Schimmel -t ip -q 3493dd91570SIdo Schimmel 3503dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 101 1 3513dd91570SIdo Schimmel check_err $? "Did not match C-TCAM filter" 3523dd91570SIdo Schimmel 3533dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 3543dd91570SIdo Schimmel 3553dd91570SIdo Schimmel $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 3563dd91570SIdo Schimmel -t ip -q 3573dd91570SIdo Schimmel 3583dd91570SIdo Schimmel tc_check_packets "dev $h2 ingress" 102 1 3593dd91570SIdo Schimmel check_err $? "Did not match A-TCAM filter" 3603dd91570SIdo Schimmel 3613dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 3623dd91570SIdo Schimmel 3633dd91570SIdo Schimmel log_test "ctcam with one atcam mask test ($tcflags)" 3643dd91570SIdo Schimmel} 3653dd91570SIdo Schimmel 3663dd91570SIdo Schimmelctcam_no_atcam_masks_test() 3673dd91570SIdo Schimmel{ 3683dd91570SIdo Schimmel RET=0 3693dd91570SIdo Schimmel 3703dd91570SIdo Schimmel # Third case: C-TCAM is disabled when there are no A-TCAM masks 3713dd91570SIdo Schimmel # This test exercises the code path that transitions the eRP table 3723dd91570SIdo Schimmel # to its initial state after deleting the last C-TCAM mask 3733dd91570SIdo Schimmel 3743dd91570SIdo Schimmel # Filter goes into A-TCAM 3753dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 3763dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 3773dd91570SIdo Schimmel # Filter goes into C-TCAM 3783dd91570SIdo Schimmel tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 3793dd91570SIdo Schimmel $tcflags dst_ip 192.0.2.2 action drop 3803dd91570SIdo Schimmel 3813dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 3823dd91570SIdo Schimmel tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 3833dd91570SIdo Schimmel 3843dd91570SIdo Schimmel log_test "ctcam with no atcam masks test ($tcflags)" 3853dd91570SIdo Schimmel} 3863dd91570SIdo Schimmel 3873dd91570SIdo Schimmelctcam_edge_cases_test() 3883dd91570SIdo Schimmel{ 3893dd91570SIdo Schimmel # When the C-TCAM is disabled after deleting the last C-TCAM 3903dd91570SIdo Schimmel # mask, we want to make sure the eRP state machine is put in 3913dd91570SIdo Schimmel # the correct state 3923dd91570SIdo Schimmel 3933dd91570SIdo Schimmel ctcam_two_atcam_masks_test 3943dd91570SIdo Schimmel ctcam_one_atcam_mask_test 3953dd91570SIdo Schimmel ctcam_no_atcam_masks_test 3963dd91570SIdo Schimmel} 3973dd91570SIdo Schimmel 3983b423271SJiri Pirkodelta_simple_test() 3993b423271SJiri Pirko{ 4003b423271SJiri Pirko # The first filter will create eRP, the second filter will fit into 4013b423271SJiri Pirko # the first eRP with delta. Remove the first rule then and check that 4023b423271SJiri Pirko # the eRP stays (referenced by the second filter). 4033b423271SJiri Pirko 4043b423271SJiri Pirko RET=0 4053b423271SJiri Pirko 4063b423271SJiri Pirko if [[ "$tcflags" != "skip_sw" ]]; then 4073b423271SJiri Pirko return 0; 4083b423271SJiri Pirko fi 4093b423271SJiri Pirko 4103b423271SJiri Pirko tp_record "objagg:*" "tc filter add dev $h2 ingress protocol ip \ 4113b423271SJiri Pirko pref 1 handle 101 flower $tcflags dst_ip 192.0.0.0/24 \ 4123b423271SJiri Pirko action drop" 4133b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_root_create" 1 4143b423271SJiri Pirko check_err $? "eRP was not created" 4153b423271SJiri Pirko 4163b423271SJiri Pirko tp_record "objagg:*" "tc filter add dev $h2 ingress protocol ip \ 4173b423271SJiri Pirko pref 2 handle 102 flower $tcflags dst_ip 192.0.2.2 \ 4183b423271SJiri Pirko action drop" 4193b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_root_create" 0 4203b423271SJiri Pirko check_err $? "eRP was incorrectly created" 4213b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_parent_assign" 1 4223b423271SJiri Pirko check_err $? "delta was not created" 4233b423271SJiri Pirko 4243b423271SJiri Pirko $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 4253b423271SJiri Pirko -t ip -q 4263b423271SJiri Pirko 4273b423271SJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 4283b423271SJiri Pirko check_fail $? "Matched a wrong filter" 4293b423271SJiri Pirko 4303b423271SJiri Pirko tc_check_packets "dev $h2 ingress" 102 1 4313b423271SJiri Pirko check_err $? "Did not match on correct filter" 4323b423271SJiri Pirko 4333b423271SJiri Pirko tp_record "objagg:*" "tc filter del dev $h2 ingress protocol ip \ 4343b423271SJiri Pirko pref 1 handle 101 flower" 4353b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_root_destroy" 0 4363b423271SJiri Pirko check_err $? "eRP was incorrectly destroyed" 4373b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_parent_unassign" 0 4383b423271SJiri Pirko check_err $? "delta was incorrectly destroyed" 4393b423271SJiri Pirko 4403b423271SJiri Pirko $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 4413b423271SJiri Pirko -t ip -q 4423b423271SJiri Pirko 4433b423271SJiri Pirko tc_check_packets "dev $h2 ingress" 102 2 4443b423271SJiri Pirko check_err $? "Did not match on correct filter after the first was removed" 4453b423271SJiri Pirko 4463b423271SJiri Pirko tp_record "objagg:*" "tc filter del dev $h2 ingress protocol ip \ 4473b423271SJiri Pirko pref 2 handle 102 flower" 4483b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_parent_unassign" 1 4493b423271SJiri Pirko check_err $? "delta was not destroyed" 4503b423271SJiri Pirko tp_check_hits "objagg:objagg_obj_root_destroy" 1 4513b423271SJiri Pirko check_err $? "eRP was not destroyed" 4523b423271SJiri Pirko 4533b423271SJiri Pirko log_test "delta simple test ($tcflags)" 4543b423271SJiri Pirko} 4553b423271SJiri Pirko 4561f0ac761SJiri Pirkodelta_two_masks_one_key_test() 4571f0ac761SJiri Pirko{ 4581f0ac761SJiri Pirko # If 2 keys are the same and only differ in mask in a way that 4591f0ac761SJiri Pirko # they belong under the same ERP (second is delta of the first), 46075d8d7a6SIdo Schimmel # there should be C-TCAM spill. 4611f0ac761SJiri Pirko 4621f0ac761SJiri Pirko RET=0 4631f0ac761SJiri Pirko 4641f0ac761SJiri Pirko if [[ "$tcflags" != "skip_sw" ]]; then 4651f0ac761SJiri Pirko return 0; 4661f0ac761SJiri Pirko fi 4671f0ac761SJiri Pirko 4681f0ac761SJiri Pirko tp_record "mlxsw:*" "tc filter add dev $h2 ingress protocol ip \ 4691f0ac761SJiri Pirko pref 1 handle 101 flower $tcflags dst_ip 192.0.2.0/24 \ 4701f0ac761SJiri Pirko action drop" 4711f0ac761SJiri Pirko tp_check_hits "mlxsw:mlxsw_sp_acl_atcam_entry_add_ctcam_spill" 0 4721f0ac761SJiri Pirko check_err $? "incorrect C-TCAM spill while inserting the first rule" 4731f0ac761SJiri Pirko 4741f0ac761SJiri Pirko tp_record "mlxsw:*" "tc filter add dev $h2 ingress protocol ip \ 4751f0ac761SJiri Pirko pref 2 handle 102 flower $tcflags dst_ip 192.0.2.2 \ 4761f0ac761SJiri Pirko action drop" 47775d8d7a6SIdo Schimmel tp_check_hits "mlxsw:mlxsw_sp_acl_atcam_entry_add_ctcam_spill" 1 47875d8d7a6SIdo Schimmel check_err $? "C-TCAM spill did not happen while inserting the second rule" 4791f0ac761SJiri Pirko 4801f0ac761SJiri Pirko $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 4811f0ac761SJiri Pirko -t ip -q 4821f0ac761SJiri Pirko 4831f0ac761SJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 4841f0ac761SJiri Pirko check_err $? "Did not match on correct filter" 4851f0ac761SJiri Pirko 4861f0ac761SJiri Pirko tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 4871f0ac761SJiri Pirko 4881f0ac761SJiri Pirko $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 4891f0ac761SJiri Pirko -t ip -q 4901f0ac761SJiri Pirko 4911f0ac761SJiri Pirko tc_check_packets "dev $h2 ingress" 102 1 4921f0ac761SJiri Pirko check_err $? "Did not match on correct filter" 4931f0ac761SJiri Pirko 4941f0ac761SJiri Pirko tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 4951f0ac761SJiri Pirko 4961f0ac761SJiri Pirko log_test "delta two masks one key test ($tcflags)" 4971f0ac761SJiri Pirko} 4981f0ac761SJiri Pirko 499c478d3c3SJiri Pirkodelta_simple_rehash_test() 500c478d3c3SJiri Pirko{ 501c478d3c3SJiri Pirko RET=0 502c478d3c3SJiri Pirko 503c478d3c3SJiri Pirko if [[ "$tcflags" != "skip_sw" ]]; then 504c478d3c3SJiri Pirko return 0; 505c478d3c3SJiri Pirko fi 506c478d3c3SJiri Pirko 507c478d3c3SJiri Pirko devlink dev param set $DEVLINK_DEV \ 508c478d3c3SJiri Pirko name acl_region_rehash_interval cmode runtime value 0 509c478d3c3SJiri Pirko check_err $? "Failed to set ACL region rehash interval" 510c478d3c3SJiri Pirko 511c478d3c3SJiri Pirko tp_record_all mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 7 512c478d3c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 513c478d3c3SJiri Pirko check_fail $? "Rehash trace was hit even when rehash should be disabled" 514c478d3c3SJiri Pirko 515c478d3c3SJiri Pirko devlink dev param set $DEVLINK_DEV \ 516c478d3c3SJiri Pirko name acl_region_rehash_interval cmode runtime value 3000 517c478d3c3SJiri Pirko check_err $? "Failed to set ACL region rehash interval" 518c478d3c3SJiri Pirko 519c478d3c3SJiri Pirko sleep 1 520c478d3c3SJiri Pirko 521c478d3c3SJiri Pirko tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 522c478d3c3SJiri Pirko $tcflags dst_ip 192.0.1.0/25 action drop 523c478d3c3SJiri Pirko tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 524c478d3c3SJiri Pirko $tcflags dst_ip 192.0.2.2 action drop 525c478d3c3SJiri Pirko tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ 526c478d3c3SJiri Pirko $tcflags dst_ip 192.0.3.0/24 action drop 527c478d3c3SJiri Pirko 528c478d3c3SJiri Pirko $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 529c478d3c3SJiri Pirko -t ip -q 530c478d3c3SJiri Pirko 531c478d3c3SJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 532c478d3c3SJiri Pirko check_fail $? "Matched a wrong filter" 533c478d3c3SJiri Pirko 534c478d3c3SJiri Pirko tc_check_packets "dev $h2 ingress" 103 1 535c478d3c3SJiri Pirko check_fail $? "Matched a wrong filter" 536c478d3c3SJiri Pirko 537c478d3c3SJiri Pirko tc_check_packets "dev $h2 ingress" 102 1 538c478d3c3SJiri Pirko check_err $? "Did not match on correct filter" 539c478d3c3SJiri Pirko 540c478d3c3SJiri Pirko tp_record_all mlxsw:* 3 541c478d3c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 542c478d3c3SJiri Pirko check_err $? "Rehash trace was not hit" 543c478d3c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate 544c478d3c3SJiri Pirko check_err $? "Migrate trace was not hit" 545f6eaf1c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate_end 546f6eaf1c3SJiri Pirko check_err $? "Migrate end trace was not hit" 547c478d3c3SJiri Pirko tp_record_all mlxsw:* 3 548c478d3c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 549c478d3c3SJiri Pirko check_err $? "Rehash trace was not hit" 550c478d3c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate 551c478d3c3SJiri Pirko check_fail $? "Migrate trace was hit when no migration should happen" 552f6eaf1c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate_end 553f6eaf1c3SJiri Pirko check_fail $? "Migrate end trace was hit when no migration should happen" 554c478d3c3SJiri Pirko 555c478d3c3SJiri Pirko $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 556c478d3c3SJiri Pirko -t ip -q 557c478d3c3SJiri Pirko 558c478d3c3SJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 559c478d3c3SJiri Pirko check_fail $? "Matched a wrong filter after rehash" 560c478d3c3SJiri Pirko 561c478d3c3SJiri Pirko tc_check_packets "dev $h2 ingress" 103 1 562c478d3c3SJiri Pirko check_fail $? "Matched a wrong filter after rehash" 563c478d3c3SJiri Pirko 564c478d3c3SJiri Pirko tc_check_packets "dev $h2 ingress" 102 2 565c478d3c3SJiri Pirko check_err $? "Did not match on correct filter after rehash" 566c478d3c3SJiri Pirko 567c478d3c3SJiri Pirko tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower 568c478d3c3SJiri Pirko tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 569c478d3c3SJiri Pirko tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 570c478d3c3SJiri Pirko 571c478d3c3SJiri Pirko log_test "delta simple rehash test ($tcflags)" 572c478d3c3SJiri Pirko} 573c478d3c3SJiri Pirko 574d39ca90fSJiri Pirkodelta_simple_ipv6_rehash_test() 575d39ca90fSJiri Pirko{ 576d39ca90fSJiri Pirko RET=0 577d39ca90fSJiri Pirko 578d39ca90fSJiri Pirko if [[ "$tcflags" != "skip_sw" ]]; then 579d39ca90fSJiri Pirko return 0; 580d39ca90fSJiri Pirko fi 581d39ca90fSJiri Pirko 582d39ca90fSJiri Pirko devlink dev param set $DEVLINK_DEV \ 583d39ca90fSJiri Pirko name acl_region_rehash_interval cmode runtime value 0 584d39ca90fSJiri Pirko check_err $? "Failed to set ACL region rehash interval" 585d39ca90fSJiri Pirko 586d39ca90fSJiri Pirko tp_record_all mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 7 587d39ca90fSJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 588d39ca90fSJiri Pirko check_fail $? "Rehash trace was hit even when rehash should be disabled" 589d39ca90fSJiri Pirko 590d39ca90fSJiri Pirko devlink dev param set $DEVLINK_DEV \ 591d39ca90fSJiri Pirko name acl_region_rehash_interval cmode runtime value 3000 592d39ca90fSJiri Pirko check_err $? "Failed to set ACL region rehash interval" 593d39ca90fSJiri Pirko 594d39ca90fSJiri Pirko sleep 1 595d39ca90fSJiri Pirko 596d39ca90fSJiri Pirko tc filter add dev $h2 ingress protocol ipv6 pref 1 handle 101 flower \ 597d39ca90fSJiri Pirko $tcflags dst_ip 2001:db8:1::0/121 action drop 598d39ca90fSJiri Pirko tc filter add dev $h2 ingress protocol ipv6 pref 2 handle 102 flower \ 599d39ca90fSJiri Pirko $tcflags dst_ip 2001:db8:2::2 action drop 600d39ca90fSJiri Pirko tc filter add dev $h2 ingress protocol ipv6 pref 3 handle 103 flower \ 601d39ca90fSJiri Pirko $tcflags dst_ip 2001:db8:3::0/120 action drop 602d39ca90fSJiri Pirko 603d39ca90fSJiri Pirko $MZ $h1 -6 -c 1 -p 64 -a $h1mac -b $h2mac \ 604d39ca90fSJiri Pirko -A 2001:db8:2::1 -B 2001:db8:2::2 -t udp -q 605d39ca90fSJiri Pirko 606d39ca90fSJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 607d39ca90fSJiri Pirko check_fail $? "Matched a wrong filter" 608d39ca90fSJiri Pirko 609d39ca90fSJiri Pirko tc_check_packets "dev $h2 ingress" 103 1 610d39ca90fSJiri Pirko check_fail $? "Matched a wrong filter" 611d39ca90fSJiri Pirko 612d39ca90fSJiri Pirko tc_check_packets "dev $h2 ingress" 102 1 613d39ca90fSJiri Pirko check_err $? "Did not match on correct filter" 614d39ca90fSJiri Pirko 615d39ca90fSJiri Pirko tp_record_all mlxsw:* 3 616d39ca90fSJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 617d39ca90fSJiri Pirko check_err $? "Rehash trace was not hit" 618d39ca90fSJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate 619d39ca90fSJiri Pirko check_err $? "Migrate trace was not hit" 620f6eaf1c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate_end 621f6eaf1c3SJiri Pirko check_err $? "Migrate end trace was not hit" 622d39ca90fSJiri Pirko tp_record_all mlxsw:* 3 623d39ca90fSJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 624d39ca90fSJiri Pirko check_err $? "Rehash trace was not hit" 625d39ca90fSJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate 626d39ca90fSJiri Pirko check_fail $? "Migrate trace was hit when no migration should happen" 627f6eaf1c3SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate_end 628f6eaf1c3SJiri Pirko check_fail $? "Migrate end trace was hit when no migration should happen" 629d39ca90fSJiri Pirko 630d39ca90fSJiri Pirko $MZ $h1 -6 -c 1 -p 64 -a $h1mac -b $h2mac \ 631d39ca90fSJiri Pirko -A 2001:db8:2::1 -B 2001:db8:2::2 -t udp -q 632d39ca90fSJiri Pirko 633d39ca90fSJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 634d39ca90fSJiri Pirko check_fail $? "Matched a wrong filter after rehash" 635d39ca90fSJiri Pirko 636d39ca90fSJiri Pirko tc_check_packets "dev $h2 ingress" 103 1 637d39ca90fSJiri Pirko check_fail $? "Matched a wrong filter after rehash" 638d39ca90fSJiri Pirko 639d39ca90fSJiri Pirko tc_check_packets "dev $h2 ingress" 102 2 640d39ca90fSJiri Pirko check_err $? "Did not match on correct filter after rehash" 641d39ca90fSJiri Pirko 642d39ca90fSJiri Pirko tc filter del dev $h2 ingress protocol ipv6 pref 3 handle 103 flower 643d39ca90fSJiri Pirko tc filter del dev $h2 ingress protocol ipv6 pref 2 handle 102 flower 644d39ca90fSJiri Pirko tc filter del dev $h2 ingress protocol ipv6 pref 1 handle 101 flower 645d39ca90fSJiri Pirko 646d39ca90fSJiri Pirko log_test "delta simple IPv6 rehash test ($tcflags)" 647d39ca90fSJiri Pirko} 648d39ca90fSJiri Pirko 64981d56d82SJiri PirkoTEST_RULE_BASE=256 65081d56d82SJiri Pirkodeclare -a test_rules_inserted 65181d56d82SJiri Pirko 65281d56d82SJiri Pirkotest_rule_add() 65381d56d82SJiri Pirko{ 65481d56d82SJiri Pirko local iface=$1 65581d56d82SJiri Pirko local tcflags=$2 65681d56d82SJiri Pirko local index=$3 65781d56d82SJiri Pirko 65881d56d82SJiri Pirko if ! [ ${test_rules_inserted[$index]} ] ; then 65981d56d82SJiri Pirko test_rules_inserted[$index]=false 66081d56d82SJiri Pirko fi 66181d56d82SJiri Pirko if ${test_rules_inserted[$index]} ; then 66281d56d82SJiri Pirko return 66381d56d82SJiri Pirko fi 66481d56d82SJiri Pirko 66581d56d82SJiri Pirko local number=$(( $index + $TEST_RULE_BASE )) 66681d56d82SJiri Pirko printf -v hexnumber '%x' $number 66781d56d82SJiri Pirko 66881d56d82SJiri Pirko batch="${batch}filter add dev $iface ingress protocol ipv6 pref 1 \ 66981d56d82SJiri Pirko handle $number flower $tcflags \ 67081d56d82SJiri Pirko src_ip 2001:db8:1::$hexnumber action drop\n" 67181d56d82SJiri Pirko test_rules_inserted[$index]=true 67281d56d82SJiri Pirko} 67381d56d82SJiri Pirko 67481d56d82SJiri Pirkotest_rule_del() 67581d56d82SJiri Pirko{ 67681d56d82SJiri Pirko local iface=$1 67781d56d82SJiri Pirko local index=$2 67881d56d82SJiri Pirko 67981d56d82SJiri Pirko if ! [ ${test_rules_inserted[$index]} ] ; then 68081d56d82SJiri Pirko test_rules_inserted[$index]=false 68181d56d82SJiri Pirko fi 68281d56d82SJiri Pirko if ! ${test_rules_inserted[$index]} ; then 68381d56d82SJiri Pirko return 68481d56d82SJiri Pirko fi 68581d56d82SJiri Pirko 68681d56d82SJiri Pirko local number=$(( $index + $TEST_RULE_BASE )) 68781d56d82SJiri Pirko printf -v hexnumber '%x' $number 68881d56d82SJiri Pirko 68981d56d82SJiri Pirko batch="${batch}filter del dev $iface ingress protocol ipv6 pref 1 \ 69081d56d82SJiri Pirko handle $number flower\n" 69181d56d82SJiri Pirko test_rules_inserted[$index]=false 69281d56d82SJiri Pirko} 69381d56d82SJiri Pirko 69481d56d82SJiri Pirkotest_rule_add_or_remove() 69581d56d82SJiri Pirko{ 69681d56d82SJiri Pirko local iface=$1 69781d56d82SJiri Pirko local tcflags=$2 69881d56d82SJiri Pirko local index=$3 69981d56d82SJiri Pirko 70081d56d82SJiri Pirko if ! [ ${test_rules_inserted[$index]} ] ; then 70181d56d82SJiri Pirko test_rules_inserted[$index]=false 70281d56d82SJiri Pirko fi 70381d56d82SJiri Pirko if ${test_rules_inserted[$index]} ; then 70481d56d82SJiri Pirko test_rule_del $iface $index 70581d56d82SJiri Pirko else 70681d56d82SJiri Pirko test_rule_add $iface $tcflags $index 70781d56d82SJiri Pirko fi 70881d56d82SJiri Pirko} 70981d56d82SJiri Pirko 71081d56d82SJiri Pirkotest_rule_add_or_remove_random_batch() 71181d56d82SJiri Pirko{ 71281d56d82SJiri Pirko local iface=$1 71381d56d82SJiri Pirko local tcflags=$2 71481d56d82SJiri Pirko local total_count=$3 71581d56d82SJiri Pirko local skip=0 71681d56d82SJiri Pirko local count=0 71781d56d82SJiri Pirko local MAXSKIP=20 71881d56d82SJiri Pirko local MAXCOUNT=20 71981d56d82SJiri Pirko 72081d56d82SJiri Pirko for ((i=1;i<=total_count;i++)); do 72181d56d82SJiri Pirko if (( $skip == 0 )) && (($count == 0)); then 72281d56d82SJiri Pirko ((skip=$RANDOM % $MAXSKIP + 1)) 72381d56d82SJiri Pirko ((count=$RANDOM % $MAXCOUNT + 1)) 72481d56d82SJiri Pirko fi 72581d56d82SJiri Pirko if (( $skip != 0 )); then 72681d56d82SJiri Pirko ((skip-=1)) 72781d56d82SJiri Pirko else 72881d56d82SJiri Pirko ((count-=1)) 72981d56d82SJiri Pirko test_rule_add_or_remove $iface $tcflags $i 73081d56d82SJiri Pirko fi 73181d56d82SJiri Pirko done 73281d56d82SJiri Pirko} 73381d56d82SJiri Pirko 73481d56d82SJiri Pirkodelta_massive_ipv6_rehash_test() 73581d56d82SJiri Pirko{ 73681d56d82SJiri Pirko RET=0 73781d56d82SJiri Pirko 73881d56d82SJiri Pirko if [[ "$tcflags" != "skip_sw" ]]; then 73981d56d82SJiri Pirko return 0; 74081d56d82SJiri Pirko fi 74181d56d82SJiri Pirko 74281d56d82SJiri Pirko devlink dev param set $DEVLINK_DEV \ 74381d56d82SJiri Pirko name acl_region_rehash_interval cmode runtime value 0 74481d56d82SJiri Pirko check_err $? "Failed to set ACL region rehash interval" 74581d56d82SJiri Pirko 74681d56d82SJiri Pirko tp_record_all mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 7 74781d56d82SJiri Pirko tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 74881d56d82SJiri Pirko check_fail $? "Rehash trace was hit even when rehash should be disabled" 74981d56d82SJiri Pirko 75081d56d82SJiri Pirko RANDOM=4432897 75181d56d82SJiri Pirko declare batch="" 75281d56d82SJiri Pirko test_rule_add_or_remove_random_batch $h2 $tcflags 5000 75381d56d82SJiri Pirko 75481d56d82SJiri Pirko echo -n -e $batch | tc -b - 75581d56d82SJiri Pirko 75681d56d82SJiri Pirko declare batch="" 75781d56d82SJiri Pirko test_rule_add_or_remove_random_batch $h2 $tcflags 5000 75881d56d82SJiri Pirko 75981d56d82SJiri Pirko devlink dev param set $DEVLINK_DEV \ 76081d56d82SJiri Pirko name acl_region_rehash_interval cmode runtime value 3000 76181d56d82SJiri Pirko check_err $? "Failed to set ACL region rehash interval" 76281d56d82SJiri Pirko 76381d56d82SJiri Pirko sleep 1 76481d56d82SJiri Pirko 76581d56d82SJiri Pirko tc filter add dev $h2 ingress protocol ipv6 pref 1 handle 101 flower \ 76681d56d82SJiri Pirko $tcflags dst_ip 2001:db8:1::0/121 action drop 76781d56d82SJiri Pirko tc filter add dev $h2 ingress protocol ipv6 pref 2 handle 102 flower \ 76881d56d82SJiri Pirko $tcflags dst_ip 2001:db8:2::2 action drop 76981d56d82SJiri Pirko tc filter add dev $h2 ingress protocol ipv6 pref 3 handle 103 flower \ 77081d56d82SJiri Pirko $tcflags dst_ip 2001:db8:3::0/120 action drop 77181d56d82SJiri Pirko 77281d56d82SJiri Pirko $MZ $h1 -6 -c 1 -p 64 -a $h1mac -b $h2mac \ 77381d56d82SJiri Pirko -A 2001:db8:2::1 -B 2001:db8:2::2 -t udp -q 77481d56d82SJiri Pirko 77581d56d82SJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 77681d56d82SJiri Pirko check_fail $? "Matched a wrong filter" 77781d56d82SJiri Pirko 77881d56d82SJiri Pirko tc_check_packets "dev $h2 ingress" 103 1 77981d56d82SJiri Pirko check_fail $? "Matched a wrong filter" 78081d56d82SJiri Pirko 78181d56d82SJiri Pirko tc_check_packets "dev $h2 ingress" 102 1 78281d56d82SJiri Pirko check_err $? "Did not match on correct filter" 78381d56d82SJiri Pirko 78481d56d82SJiri Pirko echo -n -e $batch | tc -b - 78581d56d82SJiri Pirko 78681d56d82SJiri Pirko devlink dev param set $DEVLINK_DEV \ 78781d56d82SJiri Pirko name acl_region_rehash_interval cmode runtime value 0 78881d56d82SJiri Pirko check_err $? "Failed to set ACL region rehash interval" 78981d56d82SJiri Pirko 79081d56d82SJiri Pirko $MZ $h1 -6 -c 1 -p 64 -a $h1mac -b $h2mac \ 79181d56d82SJiri Pirko -A 2001:db8:2::1 -B 2001:db8:2::2 -t udp -q 79281d56d82SJiri Pirko 79381d56d82SJiri Pirko tc_check_packets "dev $h2 ingress" 101 1 79481d56d82SJiri Pirko check_fail $? "Matched a wrong filter after rehash" 79581d56d82SJiri Pirko 79681d56d82SJiri Pirko tc_check_packets "dev $h2 ingress" 103 1 79781d56d82SJiri Pirko check_fail $? "Matched a wrong filter after rehash" 79881d56d82SJiri Pirko 79981d56d82SJiri Pirko tc_check_packets "dev $h2 ingress" 102 2 80081d56d82SJiri Pirko check_err $? "Did not match on correct filter after rehash" 80181d56d82SJiri Pirko 80281d56d82SJiri Pirko tc filter del dev $h2 ingress protocol ipv6 pref 3 handle 103 flower 80381d56d82SJiri Pirko tc filter del dev $h2 ingress protocol ipv6 pref 2 handle 102 flower 80481d56d82SJiri Pirko tc filter del dev $h2 ingress protocol ipv6 pref 1 handle 101 flower 80581d56d82SJiri Pirko 80681d56d82SJiri Pirko declare batch="" 80781d56d82SJiri Pirko for i in {1..5000}; do 80881d56d82SJiri Pirko test_rule_del $h2 $tcflags $i 80981d56d82SJiri Pirko done 81081d56d82SJiri Pirko echo -e $batch | tc -b - 81181d56d82SJiri Pirko 81281d56d82SJiri Pirko log_test "delta massive IPv6 rehash test ($tcflags)" 81381d56d82SJiri Pirko} 81481d56d82SJiri Pirko 815095c7208SNir Dotanbloom_simple_test() 816095c7208SNir Dotan{ 817095c7208SNir Dotan # Bloom filter requires that the eRP table is used. This test 818095c7208SNir Dotan # verifies that Bloom filter is not harming correctness of ACLs. 819095c7208SNir Dotan # First, make sure that eRP table is used and then set rule patterns 820095c7208SNir Dotan # which are distant enough and will result skipping a lookup after 821095c7208SNir Dotan # consulting the Bloom filter. Although some eRP lookups are skipped, 822095c7208SNir Dotan # the correct filter should be hit. 823095c7208SNir Dotan 824095c7208SNir Dotan RET=0 825095c7208SNir Dotan 826095c7208SNir Dotan tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ 827095c7208SNir Dotan $tcflags dst_ip 192.0.2.2 action drop 828095c7208SNir Dotan tc filter add dev $h2 ingress protocol ip pref 5 handle 104 flower \ 829095c7208SNir Dotan $tcflags dst_ip 198.51.100.2 action drop 830095c7208SNir Dotan tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ 831095c7208SNir Dotan $tcflags dst_ip 192.0.0.0/8 action drop 832095c7208SNir Dotan 833095c7208SNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 834095c7208SNir Dotan -t ip -q 835095c7208SNir Dotan 836095c7208SNir Dotan tc_check_packets "dev $h2 ingress" 101 1 837095c7208SNir Dotan check_err $? "Two filters - did not match highest priority" 838095c7208SNir Dotan 839095c7208SNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 198.51.100.1 -B 198.51.100.2 \ 840095c7208SNir Dotan -t ip -q 841095c7208SNir Dotan 842095c7208SNir Dotan tc_check_packets "dev $h2 ingress" 104 1 843095c7208SNir Dotan check_err $? "Single filter - did not match" 844095c7208SNir Dotan 845095c7208SNir Dotan tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower 846095c7208SNir Dotan 847095c7208SNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 848095c7208SNir Dotan -t ip -q 849095c7208SNir Dotan 850095c7208SNir Dotan tc_check_packets "dev $h2 ingress" 103 1 851095c7208SNir Dotan check_err $? "Low prio filter - did not match" 852095c7208SNir Dotan 853095c7208SNir Dotan tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 854095c7208SNir Dotan $tcflags dst_ip 198.0.0.0/8 action drop 855095c7208SNir Dotan 856095c7208SNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 198.51.100.1 -B 198.51.100.2 \ 857095c7208SNir Dotan -t ip -q 858095c7208SNir Dotan 859095c7208SNir Dotan tc_check_packets "dev $h2 ingress" 102 1 860095c7208SNir Dotan check_err $? "Two filters - did not match highest priority after add" 861095c7208SNir Dotan 862095c7208SNir Dotan tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower 863095c7208SNir Dotan tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 864095c7208SNir Dotan tc filter del dev $h2 ingress protocol ip pref 5 handle 104 flower 865095c7208SNir Dotan 866095c7208SNir Dotan log_test "bloom simple test ($tcflags)" 867095c7208SNir Dotan} 868095c7208SNir Dotan 8695118ca4eSNir Dotanbloom_complex_test() 8705118ca4eSNir Dotan{ 8715118ca4eSNir Dotan # Bloom filter index computation is affected from region ID, eRP 872fb0f0230SPrabhav Kumar Vaish # ID and from the region key size. In order to exercise those parts 8735118ca4eSNir Dotan # of the Bloom filter code, use a series of regions, each with a 8745118ca4eSNir Dotan # different key size and send packet that should hit all of them. 8755118ca4eSNir Dotan local index 8765118ca4eSNir Dotan 8775118ca4eSNir Dotan RET=0 8785118ca4eSNir Dotan NUM_CHAINS=4 8795118ca4eSNir Dotan BASE_INDEX=100 8805118ca4eSNir Dotan 8815118ca4eSNir Dotan # Create chain with up to 2 key blocks (ip_proto only) 8825118ca4eSNir Dotan tc chain add dev $h2 ingress chain 1 protocol ip flower \ 8835118ca4eSNir Dotan ip_proto tcp &> /dev/null 8845118ca4eSNir Dotan # Create chain with 2-4 key blocks (ip_proto, src MAC) 8855118ca4eSNir Dotan tc chain add dev $h2 ingress chain 2 protocol ip flower \ 8865118ca4eSNir Dotan ip_proto tcp \ 8875118ca4eSNir Dotan src_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null 8885118ca4eSNir Dotan # Create chain with 4-8 key blocks (ip_proto, src & dst MAC, IPv4 dest) 8895118ca4eSNir Dotan tc chain add dev $h2 ingress chain 3 protocol ip flower \ 8905118ca4eSNir Dotan ip_proto tcp \ 8915118ca4eSNir Dotan dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF \ 8925118ca4eSNir Dotan src_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF \ 8935118ca4eSNir Dotan dst_ip 0.0.0.0/32 &> /dev/null 8945118ca4eSNir Dotan # Default chain contains all fields and therefore is 8-12 key blocks 8955118ca4eSNir Dotan tc chain add dev $h2 ingress chain 4 8965118ca4eSNir Dotan 8975118ca4eSNir Dotan # We need at least 2 rules in every region to have eRP table active 8985118ca4eSNir Dotan # so create a dummy rule per chain using a different pattern 8995118ca4eSNir Dotan for i in $(eval echo {0..$NUM_CHAINS}); do 9005118ca4eSNir Dotan index=$((BASE_INDEX - 1 - i)) 9015118ca4eSNir Dotan tc filter add dev $h2 ingress chain $i protocol ip \ 9025118ca4eSNir Dotan pref 2 handle $index flower \ 9035118ca4eSNir Dotan $tcflags ip_proto tcp action drop 9045118ca4eSNir Dotan done 9055118ca4eSNir Dotan 9065118ca4eSNir Dotan # Add rules to test Bloom filter, each in a different chain 9075118ca4eSNir Dotan index=$BASE_INDEX 9085118ca4eSNir Dotan tc filter add dev $h2 ingress protocol ip \ 9095118ca4eSNir Dotan pref 1 handle $((++index)) flower \ 9105118ca4eSNir Dotan $tcflags dst_ip 192.0.0.0/16 action goto chain 1 9115118ca4eSNir Dotan tc filter add dev $h2 ingress chain 1 protocol ip \ 9125118ca4eSNir Dotan pref 1 handle $((++index)) flower \ 9135118ca4eSNir Dotan $tcflags action goto chain 2 9145118ca4eSNir Dotan tc filter add dev $h2 ingress chain 2 protocol ip \ 9155118ca4eSNir Dotan pref 1 handle $((++index)) flower \ 9165118ca4eSNir Dotan $tcflags src_mac $h1mac action goto chain 3 9175118ca4eSNir Dotan tc filter add dev $h2 ingress chain 3 protocol ip \ 9185118ca4eSNir Dotan pref 1 handle $((++index)) flower \ 9195118ca4eSNir Dotan $tcflags dst_ip 192.0.0.0/8 action goto chain 4 9205118ca4eSNir Dotan tc filter add dev $h2 ingress chain 4 protocol ip \ 9215118ca4eSNir Dotan pref 1 handle $((++index)) flower \ 9225118ca4eSNir Dotan $tcflags src_ip 192.0.2.0/24 action drop 9235118ca4eSNir Dotan 9245118ca4eSNir Dotan # Send a packet that is supposed to hit all chains 9255118ca4eSNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ 9265118ca4eSNir Dotan -t ip -q 9275118ca4eSNir Dotan 9285118ca4eSNir Dotan for i in $(eval echo {0..$NUM_CHAINS}); do 9295118ca4eSNir Dotan index=$((BASE_INDEX + i + 1)) 9305118ca4eSNir Dotan tc_check_packets "dev $h2 ingress" $index 1 9315118ca4eSNir Dotan check_err $? "Did not match chain $i" 9325118ca4eSNir Dotan done 9335118ca4eSNir Dotan 9345118ca4eSNir Dotan # Rules cleanup 9355118ca4eSNir Dotan for i in $(eval echo {$NUM_CHAINS..0}); do 9365118ca4eSNir Dotan index=$((BASE_INDEX - i - 1)) 9375118ca4eSNir Dotan tc filter del dev $h2 ingress chain $i \ 9385118ca4eSNir Dotan pref 2 handle $index flower 9395118ca4eSNir Dotan index=$((BASE_INDEX + i + 1)) 9405118ca4eSNir Dotan tc filter del dev $h2 ingress chain $i \ 9415118ca4eSNir Dotan pref 1 handle $index flower 9425118ca4eSNir Dotan done 9435118ca4eSNir Dotan 9445118ca4eSNir Dotan # Chains cleanup 9455118ca4eSNir Dotan for i in $(eval echo {$NUM_CHAINS..1}); do 9465118ca4eSNir Dotan tc chain del dev $h2 ingress chain $i 9475118ca4eSNir Dotan done 9485118ca4eSNir Dotan 9495118ca4eSNir Dotan log_test "bloom complex test ($tcflags)" 9505118ca4eSNir Dotan} 9515118ca4eSNir Dotan 9525d06a76dSNir Dotan 9535d06a76dSNir Dotanbloom_delta_test() 9545d06a76dSNir Dotan{ 9555d06a76dSNir Dotan # When multiple masks are used, the eRP table is activated. When 9565d06a76dSNir Dotan # masks are close enough (delta) the masks reside on the same 9575d06a76dSNir Dotan # eRP table. This test verifies that the eRP table is correctly 9585d06a76dSNir Dotan # allocated and used in delta condition and that Bloom filter is 9595d06a76dSNir Dotan # still functional with delta. 9605d06a76dSNir Dotan 9615d06a76dSNir Dotan RET=0 9625d06a76dSNir Dotan 9635d06a76dSNir Dotan tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ 9645d06a76dSNir Dotan $tcflags dst_ip 192.1.0.0/16 action drop 9655d06a76dSNir Dotan 9665d06a76dSNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.1.2.1 -B 192.1.2.2 \ 9675d06a76dSNir Dotan -t ip -q 9685d06a76dSNir Dotan 9695d06a76dSNir Dotan tc_check_packets "dev $h2 ingress" 103 1 9705d06a76dSNir Dotan check_err $? "Single filter - did not match" 9715d06a76dSNir Dotan 9725d06a76dSNir Dotan tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ 9735d06a76dSNir Dotan $tcflags dst_ip 192.2.1.0/24 action drop 9745d06a76dSNir Dotan 9755d06a76dSNir Dotan $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.2.1.1 -B 192.2.1.2 \ 9765d06a76dSNir Dotan -t ip -q 9775d06a76dSNir Dotan 9785d06a76dSNir Dotan tc_check_packets "dev $h2 ingress" 102 1 9795d06a76dSNir Dotan check_err $? "Delta filters - did not match second filter" 9805d06a76dSNir Dotan 9815d06a76dSNir Dotan tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower 9825d06a76dSNir Dotan tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower 9835d06a76dSNir Dotan 9845d06a76dSNir Dotan log_test "bloom delta test ($tcflags)" 9855d06a76dSNir Dotan} 9865d06a76dSNir Dotan 9876d6eeabcSAmit Cohenmax_erp_entries_test() 9886d6eeabcSAmit Cohen{ 9896d6eeabcSAmit Cohen # The number of eRP entries is limited. Once the maximum number of eRPs 9906d6eeabcSAmit Cohen # has been reached, filters cannot be added. This test verifies that 9916d6eeabcSAmit Cohen # when this limit is reached, inserstion fails without crashing. 9926d6eeabcSAmit Cohen 9936d6eeabcSAmit Cohen RET=0 9946d6eeabcSAmit Cohen 9956d6eeabcSAmit Cohen local num_masks=32 9966d6eeabcSAmit Cohen local num_regions=15 9976d6eeabcSAmit Cohen local chain_failed 9986d6eeabcSAmit Cohen local mask_failed 9996d6eeabcSAmit Cohen local ret 10006d6eeabcSAmit Cohen 10016d6eeabcSAmit Cohen if [[ "$tcflags" != "skip_sw" ]]; then 10026d6eeabcSAmit Cohen return 0; 10036d6eeabcSAmit Cohen fi 10046d6eeabcSAmit Cohen 10056d6eeabcSAmit Cohen for ((i=1; i < $num_regions; i++)); do 10066d6eeabcSAmit Cohen for ((j=$num_masks; j >= 0; j--)); do 10076d6eeabcSAmit Cohen tc filter add dev $h2 ingress chain $i protocol ip \ 10086d6eeabcSAmit Cohen pref $i handle $j flower $tcflags \ 10096d6eeabcSAmit Cohen dst_ip 192.1.0.0/$j &> /dev/null 10106d6eeabcSAmit Cohen ret=$? 10116d6eeabcSAmit Cohen 10126d6eeabcSAmit Cohen if [ $ret -ne 0 ]; then 10136d6eeabcSAmit Cohen chain_failed=$i 10146d6eeabcSAmit Cohen mask_failed=$j 10156d6eeabcSAmit Cohen break 2 10166d6eeabcSAmit Cohen fi 10176d6eeabcSAmit Cohen done 10186d6eeabcSAmit Cohen done 10196d6eeabcSAmit Cohen 10206d6eeabcSAmit Cohen # We expect to exceed the maximum number of eRP entries, so that 10216d6eeabcSAmit Cohen # insertion eventually fails. Otherwise, the test should be adjusted to 10226d6eeabcSAmit Cohen # add more filters. 10236d6eeabcSAmit Cohen check_fail $ret "expected to exceed number of eRP entries" 10246d6eeabcSAmit Cohen 10256d6eeabcSAmit Cohen for ((; i >= 1; i--)); do 10266d6eeabcSAmit Cohen for ((j=0; j <= $num_masks; j++)); do 10276d6eeabcSAmit Cohen tc filter del dev $h2 ingress chain $i protocol ip \ 10286d6eeabcSAmit Cohen pref $i handle $j flower &> /dev/null 10296d6eeabcSAmit Cohen done 10306d6eeabcSAmit Cohen done 10316d6eeabcSAmit Cohen 10326d6eeabcSAmit Cohen log_test "max eRP entries test ($tcflags). " \ 10336d6eeabcSAmit Cohen "max chain $chain_failed, mask $mask_failed" 10346d6eeabcSAmit Cohen} 10356d6eeabcSAmit Cohen 1036483ae90dSIdo Schimmelmax_group_size_test() 1037483ae90dSIdo Schimmel{ 1038483ae90dSIdo Schimmel # The number of ACLs in an ACL group is limited. Once the maximum 1039483ae90dSIdo Schimmel # number of ACLs has been reached, filters cannot be added. This test 1040483ae90dSIdo Schimmel # verifies that when this limit is reached, insertion fails without 1041483ae90dSIdo Schimmel # crashing. 1042483ae90dSIdo Schimmel 1043483ae90dSIdo Schimmel RET=0 1044483ae90dSIdo Schimmel 1045483ae90dSIdo Schimmel local num_acls=32 1046483ae90dSIdo Schimmel local max_size 1047483ae90dSIdo Schimmel local ret 1048483ae90dSIdo Schimmel 1049483ae90dSIdo Schimmel if [[ "$tcflags" != "skip_sw" ]]; then 1050483ae90dSIdo Schimmel return 0; 1051483ae90dSIdo Schimmel fi 1052483ae90dSIdo Schimmel 1053483ae90dSIdo Schimmel for ((i=1; i < $num_acls; i++)); do 1054483ae90dSIdo Schimmel if [[ $(( i % 2 )) == 1 ]]; then 1055483ae90dSIdo Schimmel tc filter add dev $h2 ingress pref $i proto ipv4 \ 1056483ae90dSIdo Schimmel flower $tcflags dst_ip 198.51.100.1/32 \ 1057483ae90dSIdo Schimmel ip_proto tcp tcp_flags 0x01/0x01 \ 1058483ae90dSIdo Schimmel action drop &> /dev/null 1059483ae90dSIdo Schimmel else 1060483ae90dSIdo Schimmel tc filter add dev $h2 ingress pref $i proto ipv6 \ 1061483ae90dSIdo Schimmel flower $tcflags dst_ip 2001:db8:1::1/128 \ 1062483ae90dSIdo Schimmel action drop &> /dev/null 1063483ae90dSIdo Schimmel fi 1064483ae90dSIdo Schimmel 1065483ae90dSIdo Schimmel ret=$? 1066483ae90dSIdo Schimmel [[ $ret -ne 0 ]] && max_size=$((i - 1)) && break 1067483ae90dSIdo Schimmel done 1068483ae90dSIdo Schimmel 1069483ae90dSIdo Schimmel # We expect to exceed the maximum number of ACLs in a group, so that 1070483ae90dSIdo Schimmel # insertion eventually fails. Otherwise, the test should be adjusted to 1071483ae90dSIdo Schimmel # add more filters. 1072483ae90dSIdo Schimmel check_fail $ret "expected to exceed number of ACLs in a group" 1073483ae90dSIdo Schimmel 1074483ae90dSIdo Schimmel for ((; i >= 1; i--)); do 1075483ae90dSIdo Schimmel if [[ $(( i % 2 )) == 1 ]]; then 1076483ae90dSIdo Schimmel tc filter del dev $h2 ingress pref $i proto ipv4 \ 1077483ae90dSIdo Schimmel flower $tcflags dst_ip 198.51.100.1/32 \ 1078483ae90dSIdo Schimmel ip_proto tcp tcp_flags 0x01/0x01 \ 1079483ae90dSIdo Schimmel action drop &> /dev/null 1080483ae90dSIdo Schimmel else 1081483ae90dSIdo Schimmel tc filter del dev $h2 ingress pref $i proto ipv6 \ 1082483ae90dSIdo Schimmel flower $tcflags dst_ip 2001:db8:1::1/128 \ 1083483ae90dSIdo Schimmel action drop &> /dev/null 1084483ae90dSIdo Schimmel fi 1085483ae90dSIdo Schimmel done 1086483ae90dSIdo Schimmel 1087483ae90dSIdo Schimmel log_test "max ACL group size test ($tcflags). max size $max_size" 1088483ae90dSIdo Schimmel} 1089483ae90dSIdo Schimmel 109075d8d7a6SIdo Schimmelcollision_test() 109175d8d7a6SIdo Schimmel{ 109275d8d7a6SIdo Schimmel # Filters cannot share an eRP if in the common unmasked part (i.e., 109375d8d7a6SIdo Schimmel # without the delta bits) they have the same values. If the driver does 109475d8d7a6SIdo Schimmel # not prevent such configuration (by spilling into the C-TCAM), then 109575d8d7a6SIdo Schimmel # multiple entries will be present in the device with the same key, 109675d8d7a6SIdo Schimmel # leading to collisions and a reduced scale. 109775d8d7a6SIdo Schimmel # 109875d8d7a6SIdo Schimmel # Create such a scenario and make sure all the filters are successfully 109975d8d7a6SIdo Schimmel # added. 110075d8d7a6SIdo Schimmel 110175d8d7a6SIdo Schimmel RET=0 110275d8d7a6SIdo Schimmel 110375d8d7a6SIdo Schimmel local ret 110475d8d7a6SIdo Schimmel 110575d8d7a6SIdo Schimmel if [[ "$tcflags" != "skip_sw" ]]; then 110675d8d7a6SIdo Schimmel return 0; 110775d8d7a6SIdo Schimmel fi 110875d8d7a6SIdo Schimmel 110975d8d7a6SIdo Schimmel # Add a single dst_ip/24 filter and multiple dst_ip/32 filters that all 111075d8d7a6SIdo Schimmel # have the same values in the common unmasked part (dst_ip/24). 111175d8d7a6SIdo Schimmel 111275d8d7a6SIdo Schimmel tc filter add dev $h2 ingress pref 1 proto ipv4 handle 101 \ 111375d8d7a6SIdo Schimmel flower $tcflags dst_ip 198.51.100.0/24 \ 111475d8d7a6SIdo Schimmel action drop 111575d8d7a6SIdo Schimmel 111675d8d7a6SIdo Schimmel for i in {0..255}; do 111775d8d7a6SIdo Schimmel tc filter add dev $h2 ingress pref 2 proto ipv4 \ 111875d8d7a6SIdo Schimmel handle $((102 + i)) \ 111975d8d7a6SIdo Schimmel flower $tcflags dst_ip 198.51.100.${i}/32 \ 112075d8d7a6SIdo Schimmel action drop 112175d8d7a6SIdo Schimmel ret=$? 112275d8d7a6SIdo Schimmel [[ $ret -ne 0 ]] && break 112375d8d7a6SIdo Schimmel done 112475d8d7a6SIdo Schimmel 112575d8d7a6SIdo Schimmel check_err $ret "failed to add all the filters" 112675d8d7a6SIdo Schimmel 112775d8d7a6SIdo Schimmel for i in {255..0}; do 112875d8d7a6SIdo Schimmel tc filter del dev $h2 ingress pref 2 proto ipv4 \ 112975d8d7a6SIdo Schimmel handle $((102 + i)) flower 113075d8d7a6SIdo Schimmel done 113175d8d7a6SIdo Schimmel 113275d8d7a6SIdo Schimmel tc filter del dev $h2 ingress pref 1 proto ipv4 handle 101 flower 113375d8d7a6SIdo Schimmel 113475d8d7a6SIdo Schimmel log_test "collision test ($tcflags)" 113575d8d7a6SIdo Schimmel} 113675d8d7a6SIdo Schimmel 11373dd91570SIdo Schimmelsetup_prepare() 11383dd91570SIdo Schimmel{ 11393dd91570SIdo Schimmel h1=${NETIFS[p1]} 11403dd91570SIdo Schimmel h2=${NETIFS[p2]} 11413dd91570SIdo Schimmel h1mac=$(mac_get $h1) 11423dd91570SIdo Schimmel h2mac=$(mac_get $h2) 11433dd91570SIdo Schimmel 11443dd91570SIdo Schimmel vrf_prepare 11453dd91570SIdo Schimmel 11463dd91570SIdo Schimmel h1_create 11473dd91570SIdo Schimmel h2_create 11483dd91570SIdo Schimmel} 11493dd91570SIdo Schimmel 11503dd91570SIdo Schimmelcleanup() 11513dd91570SIdo Schimmel{ 11523dd91570SIdo Schimmel pre_cleanup 11533dd91570SIdo Schimmel 11543dd91570SIdo Schimmel h2_destroy 11553dd91570SIdo Schimmel h1_destroy 11563dd91570SIdo Schimmel 11573dd91570SIdo Schimmel vrf_cleanup 11583dd91570SIdo Schimmel} 11593dd91570SIdo Schimmel 11603dd91570SIdo Schimmeltrap cleanup EXIT 11613dd91570SIdo Schimmel 11623dd91570SIdo Schimmelsetup_prepare 11633dd91570SIdo Schimmelsetup_wait 11643dd91570SIdo Schimmel 11653dd91570SIdo Schimmeltests_run 11663dd91570SIdo Schimmel 11673dd91570SIdo Schimmelif ! tc_offload_check; then 11683dd91570SIdo Schimmel check_err 1 "Could not test offloaded functionality" 11693dd91570SIdo Schimmel log_test "mlxsw-specific tests for tc flower" 11703dd91570SIdo Schimmel exit 11713dd91570SIdo Schimmelelse 11723dd91570SIdo Schimmel tcflags="skip_sw" 11733dd91570SIdo Schimmel tests_run 11743dd91570SIdo Schimmelfi 11753dd91570SIdo Schimmel 11763dd91570SIdo Schimmelexit $EXIT_STATUS 1177