0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 lib_dir=$(dirname $0)/../../../net/forwarding
0011
0012 ALL_TESTS="
0013 unprovision_test
0014 provision_test
0015 activation_16x100G_test
0016 "
0017
0018 NUM_NETIFS=0
0019
0020 source $lib_dir/lib.sh
0021 source $lib_dir/devlink_lib.sh
0022
0023 until_lc_state_is()
0024 {
0025 local state=$1; shift
0026 local current=$("$@")
0027
0028 echo "$current"
0029 [ "$current" == "$state" ]
0030 }
0031
0032 until_lc_state_is_not()
0033 {
0034 ! until_lc_state_is "$@"
0035 }
0036
0037 lc_state_get()
0038 {
0039 local lc=$1
0040
0041 devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].state"
0042 }
0043
0044 lc_wait_until_state_changes()
0045 {
0046 local lc=$1
0047 local state=$2
0048 local timeout=$3
0049
0050 busywait "$timeout" until_lc_state_is_not "$state" lc_state_get "$lc"
0051 }
0052
0053 lc_wait_until_state_becomes()
0054 {
0055 local lc=$1
0056 local state=$2
0057 local timeout=$3
0058
0059 busywait "$timeout" until_lc_state_is "$state" lc_state_get "$lc"
0060 }
0061
0062 until_lc_port_count_is()
0063 {
0064 local port_count=$1; shift
0065 local current=$("$@")
0066
0067 echo "$current"
0068 [ $current == $port_count ]
0069 }
0070
0071 lc_port_count_get()
0072 {
0073 local lc=$1
0074
0075 devlink port -j | jq -e -r ".[][] | select(.lc==$lc) | .port" | wc -l
0076 }
0077
0078 lc_wait_until_port_count_is()
0079 {
0080 local lc=$1
0081 local port_count=$2
0082 local timeout=$3
0083
0084 busywait "$timeout" until_lc_port_count_is "$port_count" lc_port_count_get "$lc"
0085 }
0086
0087 lc_nested_devlink_dev_get()
0088 {
0089 local lc=$1
0090
0091 devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].nested_devlink"
0092 }
0093
0094 PROV_UNPROV_TIMEOUT=8000
0095 POST_PROV_ACT_TIMEOUT=2000
0096 PROV_PORTS_INSTANTIATION_TIMEOUT=15000
0097
0098 unprovision_one()
0099 {
0100 local lc=$1
0101 local state
0102
0103 state=$(lc_state_get $lc)
0104 check_err $? "Failed to get state of linecard $lc"
0105 if [[ "$state" == "unprovisioned" ]]; then
0106 return
0107 fi
0108
0109 log_info "Unprovisioning linecard $lc"
0110
0111 devlink lc set $DEVLINK_DEV lc $lc notype
0112 check_err $? "Failed to trigger linecard $lc unprovisioning"
0113
0114 state=$(lc_wait_until_state_changes $lc "unprovisioning" \
0115 $PROV_UNPROV_TIMEOUT)
0116 check_err $? "Failed to unprovision linecard $lc (timeout)"
0117
0118 [ "$state" == "unprovisioned" ]
0119 check_err $? "Failed to unprovision linecard $lc (state=$state)"
0120 }
0121
0122 provision_one()
0123 {
0124 local lc=$1
0125 local type=$2
0126 local state
0127
0128 log_info "Provisioning linecard $lc"
0129
0130 devlink lc set $DEVLINK_DEV lc $lc type $type
0131 check_err $? "Failed trigger linecard $lc provisioning"
0132
0133 state=$(lc_wait_until_state_changes $lc "provisioning" \
0134 $PROV_UNPROV_TIMEOUT)
0135 check_err $? "Failed to provision linecard $lc (timeout)"
0136
0137 [ "$state" == "provisioned" ] || [ "$state" == "active" ]
0138 check_err $? "Failed to provision linecard $lc (state=$state)"
0139
0140 provisioned_type=$(devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].type")
0141 [ "$provisioned_type" == "$type" ]
0142 check_err $? "Wrong provision type returned for linecard $lc (got \"$provisioned_type\", expected \"$type\")"
0143
0144
0145
0146 state=$(lc_wait_until_state_becomes $lc "active" \
0147 $POST_PROV_ACT_TIMEOUT)
0148 }
0149
0150 unprovision_test()
0151 {
0152 RET=0
0153 local lc
0154
0155 lc=$LC_SLOT
0156 unprovision_one $lc
0157 log_test "Unprovision"
0158 }
0159
0160 LC_16X100G_TYPE="16x100G"
0161 LC_16X100G_PORT_COUNT=16
0162
0163 supported_types_check()
0164 {
0165 local lc=$1
0166 local supported_types_count
0167 local type_index
0168 local lc_16x100_found=false
0169
0170 supported_types_count=$(devlink lc show $DEVLINK_DEV lc $lc -j | \
0171 jq -e -r ".[][][].supported_types | length")
0172 [ $supported_types_count != 0 ]
0173 check_err $? "No supported types found for linecard $lc"
0174 for (( type_index=0; type_index<$supported_types_count; type_index++ ))
0175 do
0176 type=$(devlink lc show $DEVLINK_DEV lc $lc -j | \
0177 jq -e -r ".[][][].supported_types[$type_index]")
0178 if [[ "$type" == "$LC_16X100G_TYPE" ]]; then
0179 lc_16x100_found=true
0180 break
0181 fi
0182 done
0183 [ $lc_16x100_found = true ]
0184 check_err $? "16X100G not found between supported types of linecard $lc"
0185 }
0186
0187 ports_check()
0188 {
0189 local lc=$1
0190 local expected_port_count=$2
0191 local port_count
0192
0193 port_count=$(lc_wait_until_port_count_is $lc $expected_port_count \
0194 $PROV_PORTS_INSTANTIATION_TIMEOUT)
0195 [ $port_count != 0 ]
0196 check_err $? "No port associated with linecard $lc"
0197 [ $port_count == $expected_port_count ]
0198 check_err $? "Unexpected port count linecard $lc (got $port_count, expected $expected_port_count)"
0199 }
0200
0201 lc_dev_info_provisioned_check()
0202 {
0203 local lc=$1
0204 local nested_devlink_dev=$2
0205 local fixed_hw_revision
0206 local running_ini_version
0207
0208 fixed_hw_revision=$(devlink dev info $nested_devlink_dev -j | \
0209 jq -e -r '.[][].versions.fixed."hw.revision"')
0210 check_err $? "Failed to get linecard $lc fixed.hw.revision"
0211 log_info "Linecard $lc fixed.hw.revision: \"$fixed_hw_revision\""
0212 running_ini_version=$(devlink dev info $nested_devlink_dev -j | \
0213 jq -e -r '.[][].versions.running."ini.version"')
0214 check_err $? "Failed to get linecard $lc running.ini.version"
0215 log_info "Linecard $lc running.ini.version: \"$running_ini_version\""
0216 }
0217
0218 provision_test()
0219 {
0220 RET=0
0221 local lc
0222 local type
0223 local state
0224 local nested_devlink_dev
0225
0226 lc=$LC_SLOT
0227 supported_types_check $lc
0228 state=$(lc_state_get $lc)
0229 check_err $? "Failed to get state of linecard $lc"
0230 if [[ "$state" != "unprovisioned" ]]; then
0231 unprovision_one $lc
0232 fi
0233 provision_one $lc $LC_16X100G_TYPE
0234 ports_check $lc $LC_16X100G_PORT_COUNT
0235
0236 nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)
0237 check_err $? "Failed to get nested devlink handle of linecard $lc"
0238 lc_dev_info_provisioned_check $lc $nested_devlink_dev
0239
0240 log_test "Provision"
0241 }
0242
0243 ACTIVATION_TIMEOUT=20000
0244
0245 interface_check()
0246 {
0247 ip link set $h1 up
0248 ip link set $h2 up
0249 ifaces_upped=true
0250 setup_wait
0251 }
0252
0253 lc_dev_info_active_check()
0254 {
0255 local lc=$1
0256 local nested_devlink_dev=$2
0257 local fixed_device_fw_psid
0258 local running_device_fw
0259
0260 fixed_device_fw_psid=$(devlink dev info $nested_devlink_dev -j | \
0261 jq -e -r ".[][].versions.fixed" | \
0262 jq -e -r '."fw.psid"')
0263 check_err $? "Failed to get linecard $lc fixed fw PSID"
0264 log_info "Linecard $lc fixed.fw.psid: \"$fixed_device_fw_psid\""
0265
0266 running_device_fw=$(devlink dev info $nested_devlink_dev -j | \
0267 jq -e -r ".[][].versions.running.fw")
0268 check_err $? "Failed to get linecard $lc running.fw.version"
0269 log_info "Linecard $lc running.fw: \"$running_device_fw\""
0270 }
0271
0272 activation_16x100G_test()
0273 {
0274 RET=0
0275 local lc
0276 local type
0277 local state
0278 local nested_devlink_dev
0279
0280 lc=$LC_SLOT
0281 type=$LC_16X100G_TYPE
0282
0283 unprovision_one $lc
0284 provision_one $lc $type
0285 state=$(lc_wait_until_state_becomes $lc "active" \
0286 $ACTIVATION_TIMEOUT)
0287 check_err $? "Failed to get linecard $lc activated (timeout)"
0288
0289 interface_check
0290
0291 nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)
0292 check_err $? "Failed to get nested devlink handle of linecard $lc"
0293 lc_dev_info_active_check $lc $nested_devlink_dev
0294
0295 log_test "Activation 16x100G"
0296 }
0297
0298 setup_prepare()
0299 {
0300 local lc_num=$(devlink lc show -j | jq -e -r ".[][\"$DEVLINK_DEV\"] |length")
0301 if [[ $? -ne 0 ]] || [[ $lc_num -eq 0 ]]; then
0302 echo "SKIP: No linecard support found"
0303 exit $ksft_skip
0304 fi
0305
0306 if [ -z "$LC_SLOT" ]; then
0307 echo "SKIP: \"LC_SLOT\" variable not provided"
0308 exit $ksft_skip
0309 fi
0310
0311
0312
0313
0314 NUM_NETIFS=2
0315 h1=${NETIFS[p1]}
0316 h2=${NETIFS[p2]}
0317 ifaces_upped=false
0318 }
0319
0320 cleanup()
0321 {
0322 if [ "$ifaces_upped" = true ] ; then
0323 ip link set $h1 down
0324 ip link set $h2 down
0325 fi
0326 }
0327
0328 trap cleanup EXIT
0329
0330 setup_prepare
0331
0332 tests_run
0333
0334 exit $EXIT_STATUS