Skip to content

Commit

Permalink
[port_rates][rif_rates] Fix port_rates.lua (sonic-net#1520)
Browse files Browse the repository at this point in the history
Previously, loop sets DONE state on processing the first port, leaving the rest of the ports' states uninitialized. 
Now, the fix set rate collect logic init state per port.

Signed-off-by: Volodymyr Boyko <[email protected]>
  • Loading branch information
vboykox authored and daall committed Dec 7, 2020
1 parent 77cbb3c commit 58e27fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions orchagent/port_rates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ logit(alpha)
logit(one_minus_alpha)
logit(delta)

local initialized = redis.call('HGET', rates_table_name .. ':' .. 'PORT', 'INIT_DONE')

logit(initialized)

local n = table.getn(KEYS)
for i = 1, n do
local state_table = rates_table_name .. ':' .. KEYS[i] .. ':' .. 'PORT'
local initialized = redis.call('HGET', state_table, 'INIT_DONE')
logit(initialized)

-- Get new COUNTERS values
local in_ucast_pkts = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_PORT_STAT_IF_IN_UCAST_PKTS')
local in_non_ucast_pkts = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS')
Expand Down Expand Up @@ -76,7 +76,7 @@ for i = 1, n do
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'RX_PPS', rx_pps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_BPS', tx_bps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_PPS', tx_pps_new)
redis.call('HSET', rates_table_name .. ':' .. 'PORT', 'INIT_DONE', 'DONE')
redis.call('HSET', state_table, 'INIT_DONE', 'DONE')
end
else
-- Set old COUNTERS values
Expand All @@ -86,7 +86,7 @@ for i = 1, n do
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS_last', out_non_ucast_pkts)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_PORT_STAT_IF_IN_OCTETS_last', in_octets)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_PORT_STAT_IF_OUT_OCTETS_last', out_octets)
redis.call('HSET', rates_table_name .. ':' .. 'PORT', 'INIT_DONE', 'COUNTERS_LAST')
redis.call('HSET', state_table, 'INIT_DONE', 'COUNTERS_LAST')
end
end

Expand Down
11 changes: 6 additions & 5 deletions orchagent/rif_rates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ end
local one_minus_alpha = 1.0 - alpha
local delta = tonumber(ARGV[3])

local initialized = redis.call('HGET', rates_table_name .. ':' .. 'RIF', 'INIT_DONE')
logit(initialized)

local n = table.getn(KEYS)
for i = 1, n do
local state_table = rates_table_name .. ':' .. KEYS[i] .. ':' .. 'RIF'
local initialized = redis.call('HGET', state_table, 'INIT_DONE')
logit(initialized)

-- Get new COUNTERS values
local in_octets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_IN_OCTETS')
local in_pkts = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_IN_PACKETS')
Expand Down Expand Up @@ -67,15 +68,15 @@ for i = 1, n do
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'RX_PPS', rx_pps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_BPS', tx_bps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_PPS', tx_pps_new)
redis.call('HSET', rates_table_name .. ':' .. 'RIF', 'INIT_DONE', 'DONE')
redis.call('HSET', state_table, 'INIT_DONE', 'DONE')
end
else
-- Set old COUNTERS values
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_IN_OCTETS_last', in_octets)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_IN_PACKETS_last', in_pkts)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS_last', out_octets)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS_last', out_pkts)
redis.call('HSET', rates_table_name .. ':' .. 'RIF', 'INIT_DONE', 'COUNTERS_LAST')
redis.call('HSET', state_table, 'INIT_DONE', 'COUNTERS_LAST')
end
end

Expand Down

0 comments on commit 58e27fa

Please sign in to comment.