From e0d2bcf0a47b3639ef3ffec4e40f50c04b2715b5 Mon Sep 17 00:00:00 2001 From: Sonic Build Admin Date: Tue, 22 Apr 2025 07:33:19 +0000 Subject: [PATCH] Initialize the last fec ber computed values if not found **What I did** `SAI_PORT_STAT_IF_FEC_CORRECTED_BITS_last` and `SAI_PORT_STAT_IF_FEC_NOT_CORRECTABLE_FARMES_last` counter values could be NOT present in redis, so initialize these values to ZERO **Why I did it** To prevent following error seen during warm boot ``` root@sonic:/# redis-cli --eval ./usr/share/swss/port_rates.lua oid:0x100000000000a , 2 COUNTERS 10 (error) ERR user_script:204: attempt to concatenate local 'fec_corr_bits_last' (a boolean value) script: b46cd0b446729aab6bbd20e0d4aa977e3da8f5f1, on @user_script:204. root@sonic:/# redis-cli --eval ./usr/share/swss/port_rates.lua oid:0x100000000000a , 2 COUNTERS 10 (error) ERR user_script:204: attempt to concatenate local 'fec_corr_bits_last' (a boolean value) script: b46cd0b446729aab6bbd20e0d4aa977e3da8f5f1, on @user_script:204. root@sonic:/# redis-cli --eval ./usr/share/swss/port_rates.lua oid:0x100000000000a , 2 COUNTERS 10 (error) ERR user_script:206: attempt to perform arithmetic on local 'fec_corr_bits_last' (a boolean value) script: cb98161ae9433f9bf8265cffd7d2eaaf6ac9282f, on @user_script:206. root@sonic:/# ``` **How I verified it** After fix the last computer FEC ber values are stored in redis DB ``` root@sonic:/# redis-cli --eval ./usr/share/swss/port_rates.lua oid:0x100000000000a , 2 COUNTERS 10 1) "0.18" 2) "0.82" 3) "10" 4) "DONE" root@str2-7050cx3-acs-14:/# redis-cli -n 2 hgetall "RATES:oid:0x100000000000a" 1) "SAI_PORT_STAT_IF_IN_UCAST_PKTS_last" 2) "0" 3) "SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS_last" 4) "0" 5) "SAI_PORT_STAT_IF_OUT_UCAST_PKTS_last" 6) "0" 7) "SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS_last" 8) "0" 9) "SAI_PORT_STAT_IF_IN_OCTETS_last" 10) "0" 11) "SAI_PORT_STAT_IF_OUT_OCTETS_last" 12) "0" 13) "RX_BPS" 14) "0" 15) "RX_PPS" 16) "0" 17) "TX_BPS" 18) "0" 19) "TX_PPS" 20) "0" 21) "SAI_PORT_STAT_IF_FEC_CORRECTED_BITS_last" 22) "0" 23) "SAI_PORT_STAT_IF_FEC_NOT_CORRECTABLE_FARMES_last" 24) "0" 25) "FEC_PRE_BER" 26) "0" 27) "FEC_POST_BER" 28) "0" root@str2-7050cx3-acs-14:/# ``` **Details if related** --- orchagent/port_rates.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/orchagent/port_rates.lua b/orchagent/port_rates.lua index d7b8b8e4b14..917e7458e19 100644 --- a/orchagent/port_rates.lua +++ b/orchagent/port_rates.lua @@ -200,6 +200,10 @@ local function compute_rate(port) local fec_corr_bits_last = redis.call('HGET', rates_table_name .. ':' .. port, 'SAI_PORT_STAT_IF_FEC_CORRECTED_BITS_last') local fec_uncorr_frames_last = redis.call('HGET', rates_table_name .. ':' .. port, 'SAI_PORT_STAT_IF_FEC_NOT_CORRECTABLE_FARMES_last') + -- Initialize to 0 if last counter values does not exist (during first boot for eg) + fec_corr_bits_last = tonumber(fec_corr_bits_last) or 0 + fec_uncorr_frames_last = tonumber(fec_uncorr_frames_last) or 0 + local serdes_rate_total = lanes_count * serdes_speed * delta / 1000 fec_corr_bits_ber_new = (fec_corr_bits - fec_corr_bits_last) / serdes_rate_total @@ -207,7 +211,6 @@ local function compute_rate(port) else logit("FEC counters or lane info not found on " .. port) end - else redis.call('HSET', state_table, 'INIT_DONE', 'COUNTERS_LAST') end