@@ -120,14 +120,32 @@ local function find_lanes_and_serdes(interface_name)
120120 return count , lane_speed , serdes
121121end
122122
123+ -- find the max T - Maximum FEC histogram bin with non-zero count
124+ -- return max T value
125+
126+ local function find_maxT (port )
127+ local maxT = - 1
128+ for i = 0 , 15 do
129+ local fec_cwi = ' SAI_PORT_STAT_IF_IN_FEC_CODEWORD_ERRORS_S' .. i
130+ local fec_cwi_val = redis .call (' HGET' , counters_table_name .. ' :' .. port , fec_cwi )
131+ if fec_cwi_val then
132+ fec_cwi_val = tonumber (fec_cwi_val ) or 0
133+ if fec_cwi_val > 0 then
134+ maxT = i
135+ end
136+ end
137+ end
138+ return maxT
139+ end
140+
123141local function compute_rate (port )
124142
125143 local state_table = rates_table_name .. ' :' .. port .. ' :' .. ' PORT'
126144 local initialized = redis .call (' HGET' , state_table , ' INIT_DONE' )
127145 logit (initialized )
128146
129147 -- FEC BER
130- local fec_corr_bits , fec_uncorr_frames
148+ local fec_corr_bits , fec_uncorr_frames , maxT
131149 local fec_corr_bits_ber_new , fec_uncorr_bits_ber_new = - 1 , - 1
132150 -- HLD review suggest to use the statistical average when calculate the post fec ber
133151 local rs_average_frame_ber = 1e-8
@@ -213,6 +231,8 @@ local function compute_rate(port)
213231 else
214232 logit (" FEC counters or lane info not found on " .. port )
215233 end
234+
235+ maxT = find_maxT (port )
216236 else
217237 redis .call (' HSET' , state_table , ' INIT_DONE' , ' COUNTERS_LAST' )
218238 end
@@ -226,7 +246,7 @@ local function compute_rate(port)
226246 redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_OCTETS_last' , out_octets )
227247
228248 -- do not update FEC related stat if we dont have it
229-
249+
230250 if not fec_corr_bits or not fec_uncorr_frames or not fec_corr_bits_ber_new or
231251 not fec_uncorr_bits_ber_new then
232252 logit (" FEC counters not found on " .. port )
@@ -243,6 +263,7 @@ local function compute_rate(port)
243263 redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_FEC_NOT_CORRECTABLE_FARMES_last' , fec_uncorr_frames )
244264 redis .call (' HSET' , rates_table_name .. ' :' .. port , ' FEC_PRE_BER' , fec_corr_bits_ber_new )
245265 redis .call (' HSET' , rates_table_name .. ' :' .. port , ' FEC_POST_BER' , fec_uncorr_bits_ber_new )
266+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' FEC_MAX_T' , maxT )
246267end
247268
248269local n = table .getn (KEYS )
0 commit comments