1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4ALL_TESTS=" 5 port_pool_test 6 port_tc_ip_test 7 port_tc_arp_test 8" 9 10NUM_NETIFS=2 11source ../../../net/forwarding/lib.sh 12source ../../../net/forwarding/devlink_lib.sh 13source mlxsw_lib.sh 14 15SB_POOL_ING=0 16SB_POOL_EGR_CPU=10 17 18SB_ITC_CPU_IP=2 19SB_ITC_CPU_ARP=2 20SB_ITC=0 21 22h1_create() 23{ 24 simple_if_init $h1 192.0.1.1/24 25} 26 27h1_destroy() 28{ 29 simple_if_fini $h1 192.0.1.1/24 30} 31 32h2_create() 33{ 34 simple_if_init $h2 192.0.1.2/24 35} 36 37h2_destroy() 38{ 39 simple_if_fini $h2 192.0.1.2/24 40} 41 42sb_occ_pool_check() 43{ 44 local dl_port=$1; shift 45 local pool=$1; shift 46 local exp_max_occ=$1 47 local max_occ 48 local err=0 49 50 max_occ=$(devlink sb -j occupancy show $dl_port \ 51 | jq -e ".[][][\"pool\"][\"$pool\"][\"max\"]") 52 53 if [[ "$max_occ" -ne "$exp_max_occ" ]]; then 54 err=1 55 fi 56 57 echo $max_occ 58 return $err 59} 60 61sb_occ_itc_check() 62{ 63 local dl_port=$1; shift 64 local itc=$1; shift 65 local exp_max_occ=$1 66 local max_occ 67 local err=0 68 69 max_occ=$(devlink sb -j occupancy show $dl_port \ 70 | jq -e ".[][][\"itc\"][\"$itc\"][\"max\"]") 71 72 if [[ "$max_occ" -ne "$exp_max_occ" ]]; then 73 err=1 74 fi 75 76 echo $max_occ 77 return $err 78} 79 80sb_occ_etc_check() 81{ 82 local dl_port=$1; shift 83 local etc=$1; shift 84 local exp_max_occ=$1; shift 85 local max_occ 86 local err=0 87 88 max_occ=$(devlink sb -j occupancy show $dl_port \ 89 | jq -e ".[][][\"etc\"][\"$etc\"][\"max\"]") 90 91 if [[ "$max_occ" -ne "$exp_max_occ" ]]; then 92 err=1 93 fi 94 95 echo $max_occ 96 return $err 97} 98 99port_pool_test() 100{ 101 local exp_max_occ=$(devlink_cell_size_get) 102 local max_occ 103 104 devlink sb occupancy clearmax $DEVLINK_DEV 105 106 $MZ $h1 -c 1 -p 10 -a $h1mac -b $h2mac -A 192.0.1.1 -B 192.0.1.2 \ 107 -t ip -q 108 109 devlink sb occupancy snapshot $DEVLINK_DEV 110 111 RET=0 112 max_occ=$(sb_occ_pool_check $dl_port1 $SB_POOL_ING $exp_max_occ) 113 check_err $? "Expected iPool($SB_POOL_ING) max occupancy to be $exp_max_occ, but got $max_occ" 114 log_test "physical port's($h1) ingress pool" 115 116 RET=0 117 max_occ=$(sb_occ_pool_check $dl_port2 $SB_POOL_ING $exp_max_occ) 118 check_err $? "Expected iPool($SB_POOL_ING) max occupancy to be $exp_max_occ, but got $max_occ" 119 log_test "physical port's($h2) ingress pool" 120 121 RET=0 122 max_occ=$(sb_occ_pool_check $cpu_dl_port $SB_POOL_EGR_CPU $exp_max_occ) 123 check_err $? "Expected ePool($SB_POOL_EGR_CPU) max occupancy to be $exp_max_occ, but got $max_occ" 124 log_test "CPU port's egress pool" 125} 126 127port_tc_ip_test() 128{ 129 local exp_max_occ=$(devlink_cell_size_get) 130 local max_occ 131 132 devlink sb occupancy clearmax $DEVLINK_DEV 133 134 $MZ $h1 -c 1 -p 10 -a $h1mac -b $h2mac -A 192.0.1.1 -B 192.0.1.2 \ 135 -t ip -q 136 137 devlink sb occupancy snapshot $DEVLINK_DEV 138 139 RET=0 140 max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ) 141 check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ" 142 log_test "physical port's($h1) ingress TC - IP packet" 143 144 RET=0 145 max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ) 146 check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ" 147 log_test "physical port's($h2) ingress TC - IP packet" 148 149 RET=0 150 max_occ=$(sb_occ_etc_check $cpu_dl_port $SB_ITC_CPU_IP $exp_max_occ) 151 check_err $? "Expected egress TC($SB_ITC_CPU_IP) max occupancy to be $exp_max_occ, but got $max_occ" 152 log_test "CPU port's egress TC - IP packet" 153} 154 155port_tc_arp_test() 156{ 157 local exp_max_occ=$(devlink_cell_size_get) 158 local max_occ 159 160 devlink sb occupancy clearmax $DEVLINK_DEV 161 162 $MZ $h1 -c 1 -p 10 -a $h1mac -A 192.0.1.1 -t arp -q 163 164 devlink sb occupancy snapshot $DEVLINK_DEV 165 166 RET=0 167 max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ) 168 check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ" 169 log_test "physical port's($h1) ingress TC - ARP packet" 170 171 RET=0 172 max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ) 173 check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ" 174 log_test "physical port's($h2) ingress TC - ARP packet" 175 176 RET=0 177 max_occ=$(sb_occ_etc_check $cpu_dl_port $SB_ITC_CPU_ARP $exp_max_occ) 178 check_err $? "Expected egress TC($SB_ITC_IP2ME) max occupancy to be $exp_max_occ, but got $max_occ" 179 log_test "CPU port's egress TC - ARP packet" 180} 181 182setup_prepare() 183{ 184 h1=${NETIFS[p1]} 185 h2=${NETIFS[p2]} 186 187 h1mac=$(mac_get $h1) 188 h2mac=$(mac_get $h2) 189 190 dl_port1=$(devlink_port_by_netdev $h1) 191 dl_port2=$(devlink_port_by_netdev $h2) 192 193 cpu_dl_port=$(devlink_cpu_port_get) 194 195 vrf_prepare 196 197 h1_create 198 h2_create 199} 200 201cleanup() 202{ 203 pre_cleanup 204 205 h2_destroy 206 h1_destroy 207 208 vrf_cleanup 209} 210 211trap cleanup EXIT 212 213setup_prepare 214setup_wait 215 216tests_run 217 218exit $EXIT_STATUS 219