1a865ad99SShalom Toledo#!/bin/bash 2a865ad99SShalom Toledo# SPDX-License-Identifier: GPL-2.0 3a865ad99SShalom Toledo 4a865ad99SShalom ToledoALL_TESTS=" 5a865ad99SShalom Toledo port_pool_test 6a865ad99SShalom Toledo port_tc_ip_test 7a865ad99SShalom Toledo port_tc_arp_test 8a865ad99SShalom Toledo" 9a865ad99SShalom Toledo 10a865ad99SShalom ToledoNUM_NETIFS=2 11a865ad99SShalom Toledosource ../../../net/forwarding/lib.sh 12a865ad99SShalom Toledosource ../../../net/forwarding/devlink_lib.sh 13a865ad99SShalom Toledosource mlxsw_lib.sh 14a865ad99SShalom Toledo 15a865ad99SShalom ToledoSB_POOL_ING=0 16a865ad99SShalom ToledoSB_POOL_EGR_CPU=10 17a865ad99SShalom Toledo 18025b7de7SIdo SchimmelSB_ITC_CPU_IP=2 19a865ad99SShalom ToledoSB_ITC_CPU_ARP=2 20a865ad99SShalom ToledoSB_ITC=0 21a865ad99SShalom Toledo 22a865ad99SShalom Toledoh1_create() 23a865ad99SShalom Toledo{ 24a865ad99SShalom Toledo simple_if_init $h1 192.0.1.1/24 25*03528ff8SDanielle Ratson tc qdisc add dev $h1 clsact 26*03528ff8SDanielle Ratson 27*03528ff8SDanielle Ratson # Add egress filter on $h1 that will guarantee that the packet sent, 28*03528ff8SDanielle Ratson # will be the only packet being passed to the device. 29*03528ff8SDanielle Ratson tc filter add dev $h1 egress pref 2 handle 102 matchall action drop 30a865ad99SShalom Toledo} 31a865ad99SShalom Toledo 32a865ad99SShalom Toledoh1_destroy() 33a865ad99SShalom Toledo{ 34*03528ff8SDanielle Ratson tc filter del dev $h1 egress pref 2 handle 102 matchall action drop 35*03528ff8SDanielle Ratson tc qdisc del dev $h1 clsact 36a865ad99SShalom Toledo simple_if_fini $h1 192.0.1.1/24 37a865ad99SShalom Toledo} 38a865ad99SShalom Toledo 39a865ad99SShalom Toledoh2_create() 40a865ad99SShalom Toledo{ 41a865ad99SShalom Toledo simple_if_init $h2 192.0.1.2/24 42*03528ff8SDanielle Ratson tc qdisc add dev $h2 clsact 43*03528ff8SDanielle Ratson 44*03528ff8SDanielle Ratson # Add egress filter on $h2 that will guarantee that the packet sent, 45*03528ff8SDanielle Ratson # will be the only packet being passed to the device. 46*03528ff8SDanielle Ratson tc filter add dev $h2 egress pref 1 handle 101 matchall action drop 47a865ad99SShalom Toledo} 48a865ad99SShalom Toledo 49a865ad99SShalom Toledoh2_destroy() 50a865ad99SShalom Toledo{ 51*03528ff8SDanielle Ratson tc filter del dev $h2 egress pref 1 handle 101 matchall action drop 52*03528ff8SDanielle Ratson tc qdisc del dev $h2 clsact 53a865ad99SShalom Toledo simple_if_fini $h2 192.0.1.2/24 54a865ad99SShalom Toledo} 55a865ad99SShalom Toledo 56a865ad99SShalom Toledosb_occ_pool_check() 57a865ad99SShalom Toledo{ 58a865ad99SShalom Toledo local dl_port=$1; shift 59a865ad99SShalom Toledo local pool=$1; shift 60a865ad99SShalom Toledo local exp_max_occ=$1 61a865ad99SShalom Toledo local max_occ 62a865ad99SShalom Toledo local err=0 63a865ad99SShalom Toledo 64a865ad99SShalom Toledo max_occ=$(devlink sb -j occupancy show $dl_port \ 65a865ad99SShalom Toledo | jq -e ".[][][\"pool\"][\"$pool\"][\"max\"]") 66a865ad99SShalom Toledo 67a865ad99SShalom Toledo if [[ "$max_occ" -ne "$exp_max_occ" ]]; then 68a865ad99SShalom Toledo err=1 69a865ad99SShalom Toledo fi 70a865ad99SShalom Toledo 71a865ad99SShalom Toledo echo $max_occ 72a865ad99SShalom Toledo return $err 73a865ad99SShalom Toledo} 74a865ad99SShalom Toledo 75a865ad99SShalom Toledosb_occ_itc_check() 76a865ad99SShalom Toledo{ 77a865ad99SShalom Toledo local dl_port=$1; shift 78a865ad99SShalom Toledo local itc=$1; shift 79a865ad99SShalom Toledo local exp_max_occ=$1 80a865ad99SShalom Toledo local max_occ 81a865ad99SShalom Toledo local err=0 82a865ad99SShalom Toledo 83a865ad99SShalom Toledo max_occ=$(devlink sb -j occupancy show $dl_port \ 84a865ad99SShalom Toledo | jq -e ".[][][\"itc\"][\"$itc\"][\"max\"]") 85a865ad99SShalom Toledo 86a865ad99SShalom Toledo if [[ "$max_occ" -ne "$exp_max_occ" ]]; then 87a865ad99SShalom Toledo err=1 88a865ad99SShalom Toledo fi 89a865ad99SShalom Toledo 90a865ad99SShalom Toledo echo $max_occ 91a865ad99SShalom Toledo return $err 92a865ad99SShalom Toledo} 93a865ad99SShalom Toledo 94a865ad99SShalom Toledosb_occ_etc_check() 95a865ad99SShalom Toledo{ 96a865ad99SShalom Toledo local dl_port=$1; shift 97a865ad99SShalom Toledo local etc=$1; shift 98a865ad99SShalom Toledo local exp_max_occ=$1; shift 99a865ad99SShalom Toledo local max_occ 100a865ad99SShalom Toledo local err=0 101a865ad99SShalom Toledo 102a865ad99SShalom Toledo max_occ=$(devlink sb -j occupancy show $dl_port \ 103a865ad99SShalom Toledo | jq -e ".[][][\"etc\"][\"$etc\"][\"max\"]") 104a865ad99SShalom Toledo 105a865ad99SShalom Toledo if [[ "$max_occ" -ne "$exp_max_occ" ]]; then 106a865ad99SShalom Toledo err=1 107a865ad99SShalom Toledo fi 108a865ad99SShalom Toledo 109a865ad99SShalom Toledo echo $max_occ 110a865ad99SShalom Toledo return $err 111a865ad99SShalom Toledo} 112a865ad99SShalom Toledo 113a865ad99SShalom Toledoport_pool_test() 114a865ad99SShalom Toledo{ 115f520489eSIdo Schimmel local exp_max_occ=$(devlink_cell_size_get) 116a865ad99SShalom Toledo local max_occ 117a865ad99SShalom Toledo 118*03528ff8SDanielle Ratson tc filter add dev $h1 egress protocol ip pref 1 handle 101 flower \ 119*03528ff8SDanielle Ratson src_mac $h1mac dst_mac $h2mac \ 120*03528ff8SDanielle Ratson src_ip 192.0.1.1 dst_ip 192.0.1.2 \ 121*03528ff8SDanielle Ratson action pass 122*03528ff8SDanielle Ratson 123a865ad99SShalom Toledo devlink sb occupancy clearmax $DEVLINK_DEV 124a865ad99SShalom Toledo 125f520489eSIdo Schimmel $MZ $h1 -c 1 -p 10 -a $h1mac -b $h2mac -A 192.0.1.1 -B 192.0.1.2 \ 126a865ad99SShalom Toledo -t ip -q 127a865ad99SShalom Toledo 128a865ad99SShalom Toledo devlink sb occupancy snapshot $DEVLINK_DEV 129a865ad99SShalom Toledo 130a865ad99SShalom Toledo RET=0 131a865ad99SShalom Toledo max_occ=$(sb_occ_pool_check $dl_port2 $SB_POOL_ING $exp_max_occ) 132a865ad99SShalom Toledo check_err $? "Expected iPool($SB_POOL_ING) max occupancy to be $exp_max_occ, but got $max_occ" 133a865ad99SShalom Toledo log_test "physical port's($h2) ingress pool" 134a865ad99SShalom Toledo 135a865ad99SShalom Toledo RET=0 136a865ad99SShalom Toledo max_occ=$(sb_occ_pool_check $cpu_dl_port $SB_POOL_EGR_CPU $exp_max_occ) 137a865ad99SShalom Toledo check_err $? "Expected ePool($SB_POOL_EGR_CPU) max occupancy to be $exp_max_occ, but got $max_occ" 138a865ad99SShalom Toledo log_test "CPU port's egress pool" 139*03528ff8SDanielle Ratson 140*03528ff8SDanielle Ratson tc filter del dev $h1 egress protocol ip pref 1 handle 101 flower \ 141*03528ff8SDanielle Ratson src_mac $h1mac dst_mac $h2mac \ 142*03528ff8SDanielle Ratson src_ip 192.0.1.1 dst_ip 192.0.1.2 \ 143*03528ff8SDanielle Ratson action pass 144a865ad99SShalom Toledo} 145a865ad99SShalom Toledo 146a865ad99SShalom Toledoport_tc_ip_test() 147a865ad99SShalom Toledo{ 148f520489eSIdo Schimmel local exp_max_occ=$(devlink_cell_size_get) 149a865ad99SShalom Toledo local max_occ 150a865ad99SShalom Toledo 151*03528ff8SDanielle Ratson tc filter add dev $h1 egress protocol ip pref 1 handle 101 flower \ 152*03528ff8SDanielle Ratson src_mac $h1mac dst_mac $h2mac \ 153*03528ff8SDanielle Ratson src_ip 192.0.1.1 dst_ip 192.0.1.2 \ 154*03528ff8SDanielle Ratson action pass 155*03528ff8SDanielle Ratson 156a865ad99SShalom Toledo devlink sb occupancy clearmax $DEVLINK_DEV 157a865ad99SShalom Toledo 158f520489eSIdo Schimmel $MZ $h1 -c 1 -p 10 -a $h1mac -b $h2mac -A 192.0.1.1 -B 192.0.1.2 \ 159a865ad99SShalom Toledo -t ip -q 160a865ad99SShalom Toledo 161a865ad99SShalom Toledo devlink sb occupancy snapshot $DEVLINK_DEV 162a865ad99SShalom Toledo 163a865ad99SShalom Toledo RET=0 164a865ad99SShalom Toledo max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ) 165a865ad99SShalom Toledo check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ" 166a865ad99SShalom Toledo log_test "physical port's($h2) ingress TC - IP packet" 167a865ad99SShalom Toledo 168a865ad99SShalom Toledo RET=0 169a865ad99SShalom Toledo max_occ=$(sb_occ_etc_check $cpu_dl_port $SB_ITC_CPU_IP $exp_max_occ) 170a865ad99SShalom Toledo check_err $? "Expected egress TC($SB_ITC_CPU_IP) max occupancy to be $exp_max_occ, but got $max_occ" 171a865ad99SShalom Toledo log_test "CPU port's egress TC - IP packet" 172*03528ff8SDanielle Ratson 173*03528ff8SDanielle Ratson tc filter del dev $h1 egress protocol ip pref 1 handle 101 flower \ 174*03528ff8SDanielle Ratson src_mac $h1mac dst_mac $h2mac \ 175*03528ff8SDanielle Ratson src_ip 192.0.1.1 dst_ip 192.0.1.2 \ 176*03528ff8SDanielle Ratson action pass 177a865ad99SShalom Toledo} 178a865ad99SShalom Toledo 179a865ad99SShalom Toledoport_tc_arp_test() 180a865ad99SShalom Toledo{ 181f520489eSIdo Schimmel local exp_max_occ=$(devlink_cell_size_get) 182a865ad99SShalom Toledo local max_occ 183a865ad99SShalom Toledo 184*03528ff8SDanielle Ratson tc filter add dev $h1 egress protocol arp pref 1 handle 101 flower \ 185*03528ff8SDanielle Ratson src_mac $h1mac action pass 186*03528ff8SDanielle Ratson 187a865ad99SShalom Toledo devlink sb occupancy clearmax $DEVLINK_DEV 188a865ad99SShalom Toledo 189f520489eSIdo Schimmel $MZ $h1 -c 1 -p 10 -a $h1mac -A 192.0.1.1 -t arp -q 190a865ad99SShalom Toledo 191a865ad99SShalom Toledo devlink sb occupancy snapshot $DEVLINK_DEV 192a865ad99SShalom Toledo 193a865ad99SShalom Toledo RET=0 194a865ad99SShalom Toledo max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ) 195a865ad99SShalom Toledo check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ" 196a865ad99SShalom Toledo log_test "physical port's($h2) ingress TC - ARP packet" 197a865ad99SShalom Toledo 198a865ad99SShalom Toledo RET=0 199a865ad99SShalom Toledo max_occ=$(sb_occ_etc_check $cpu_dl_port $SB_ITC_CPU_ARP $exp_max_occ) 200a865ad99SShalom Toledo check_err $? "Expected egress TC($SB_ITC_IP2ME) max occupancy to be $exp_max_occ, but got $max_occ" 201a865ad99SShalom Toledo log_test "CPU port's egress TC - ARP packet" 202*03528ff8SDanielle Ratson 203*03528ff8SDanielle Ratson tc filter del dev $h1 egress protocol arp pref 1 handle 101 flower \ 204*03528ff8SDanielle Ratson src_mac $h1mac action pass 205a865ad99SShalom Toledo} 206a865ad99SShalom Toledo 207a865ad99SShalom Toledosetup_prepare() 208a865ad99SShalom Toledo{ 209a865ad99SShalom Toledo h1=${NETIFS[p1]} 210a865ad99SShalom Toledo h2=${NETIFS[p2]} 211a865ad99SShalom Toledo 212a865ad99SShalom Toledo h1mac=$(mac_get $h1) 213a865ad99SShalom Toledo h2mac=$(mac_get $h2) 214a865ad99SShalom Toledo 215a865ad99SShalom Toledo dl_port1=$(devlink_port_by_netdev $h1) 216a865ad99SShalom Toledo dl_port2=$(devlink_port_by_netdev $h2) 217a865ad99SShalom Toledo 218a865ad99SShalom Toledo cpu_dl_port=$(devlink_cpu_port_get) 219a865ad99SShalom Toledo 220a865ad99SShalom Toledo vrf_prepare 221a865ad99SShalom Toledo 222a865ad99SShalom Toledo h1_create 223a865ad99SShalom Toledo h2_create 224a865ad99SShalom Toledo} 225a865ad99SShalom Toledo 226a865ad99SShalom Toledocleanup() 227a865ad99SShalom Toledo{ 228a865ad99SShalom Toledo pre_cleanup 229a865ad99SShalom Toledo 230a865ad99SShalom Toledo h2_destroy 231a865ad99SShalom Toledo h1_destroy 232a865ad99SShalom Toledo 233a865ad99SShalom Toledo vrf_cleanup 234a865ad99SShalom Toledo} 235a865ad99SShalom Toledo 236a865ad99SShalom Toledotrap cleanup EXIT 237a865ad99SShalom Toledo 238a865ad99SShalom Toledosetup_prepare 239a865ad99SShalom Toledosetup_wait 240a865ad99SShalom Toledo 241a865ad99SShalom Toledotests_run 242a865ad99SShalom Toledo 243a865ad99SShalom Toledoexit $EXIT_STATUS 244