@@ -29,28 +29,33 @@ logit(alpha)
29
29
logit (one_minus_alpha )
30
30
logit (delta )
31
31
32
- local n = table .getn (KEYS )
33
- for i = 1 , n do
34
- local state_table = rates_table_name .. ' :' .. KEYS [i ] .. ' :' .. ' PORT'
32
+ local function compute_rate (port )
33
+ local state_table = rates_table_name .. ' :' .. port .. ' :' .. ' PORT'
35
34
local initialized = redis .call (' HGET' , state_table , ' INIT_DONE' )
36
35
logit (initialized )
37
36
38
37
-- Get new COUNTERS values
39
- local in_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_IN_UCAST_PKTS' )
40
- local in_non_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS' )
41
- local out_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_OUT_UCAST_PKTS' )
42
- local out_non_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS' )
43
- local in_octets = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_IN_OCTETS' )
44
- local out_octets = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_OUT_OCTETS' )
38
+ local in_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_UCAST_PKTS' )
39
+ local in_non_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS' )
40
+ local out_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_UCAST_PKTS' )
41
+ local out_non_ucast_pkts = redis .call (' HGET' , counters_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS' )
42
+ local in_octets = redis .call (' HGET' , counters_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_OCTETS' )
43
+ local out_octets = redis .call (' HGET' , counters_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_OCTETS' )
44
+
45
+ if not in_ucast_pkts or not in_non_ucast_pkts or not out_ucast_pkts or
46
+ not out_non_ucast_pkts or not in_octets or not out_octets then
47
+ logit (" Not found some counters on " .. port )
48
+ return
49
+ end
45
50
46
51
if initialized == ' DONE' or initialized == ' COUNTERS_LAST' then
47
52
-- Get old COUNTERS values
48
- local in_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' SAI_PORT_STAT_IF_IN_UCAST_PKTS_last' )
49
- local in_non_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS_last' )
50
- local out_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' SAI_PORT_STAT_IF_OUT_UCAST_PKTS_last' )
51
- local out_non_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS_last' )
52
- local in_octets_last = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' SAI_PORT_STAT_IF_IN_OCTETS_last' )
53
- local out_octets_last = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' SAI_PORT_STAT_IF_OUT_OCTETS_last' )
53
+ local in_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_UCAST_PKTS_last' )
54
+ local in_non_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS_last' )
55
+ local out_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_UCAST_PKTS_last' )
56
+ local out_non_ucast_pkts_last = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS_last' )
57
+ local in_octets_last = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_OCTETS_last' )
58
+ local out_octets_last = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_OCTETS_last' )
54
59
55
60
-- Calculate new rates values
56
61
local rx_bps_new = (in_octets - in_octets_last ) / delta * 1000
@@ -60,35 +65,40 @@ for i = 1, n do
60
65
61
66
if initialized == " DONE" then
62
67
-- Get old rates values
63
- local rx_bps_old = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' RX_BPS' )
64
- local rx_pps_old = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' RX_PPS' )
65
- local tx_bps_old = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' TX_BPS' )
66
- local tx_pps_old = redis .call (' HGET' , rates_table_name .. ' :' .. KEYS [ i ] , ' TX_PPS' )
68
+ local rx_bps_old = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' RX_BPS' )
69
+ local rx_pps_old = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' RX_PPS' )
70
+ local tx_bps_old = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' TX_BPS' )
71
+ local tx_pps_old = redis .call (' HGET' , rates_table_name .. ' :' .. port , ' TX_PPS' )
67
72
68
73
-- Smooth the rates values and store them in DB
69
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' RX_BPS' , alpha * rx_bps_new + one_minus_alpha * rx_bps_old )
70
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' RX_PPS' , alpha * rx_pps_new + one_minus_alpha * rx_pps_old )
71
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' TX_BPS' , alpha * tx_bps_new + one_minus_alpha * tx_bps_old )
72
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' TX_PPS' , alpha * tx_pps_new + one_minus_alpha * tx_pps_old )
74
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' RX_BPS' , alpha * rx_bps_new + one_minus_alpha * rx_bps_old )
75
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' RX_PPS' , alpha * rx_pps_new + one_minus_alpha * rx_pps_old )
76
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' TX_BPS' , alpha * tx_bps_new + one_minus_alpha * tx_bps_old )
77
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' TX_PPS' , alpha * tx_pps_new + one_minus_alpha * tx_pps_old )
73
78
else
74
79
-- Store unsmoothed initial rates values in DB
75
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' RX_BPS' , rx_bps_new )
76
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' RX_PPS' , rx_pps_new )
77
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' TX_BPS' , tx_bps_new )
78
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [ i ] , ' TX_PPS' , tx_pps_new )
80
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' RX_BPS' , rx_bps_new )
81
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' RX_PPS' , rx_pps_new )
82
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' TX_BPS' , tx_bps_new )
83
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' TX_PPS' , tx_pps_new )
79
84
redis .call (' HSET' , state_table , ' INIT_DONE' , ' DONE' )
80
85
end
81
86
else
82
87
redis .call (' HSET' , state_table , ' INIT_DONE' , ' COUNTERS_LAST' )
83
88
end
84
89
85
90
-- Set old COUNTERS values
86
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_IN_UCAST_PKTS_last' , in_ucast_pkts )
87
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS_last' , in_non_ucast_pkts )
88
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_OUT_UCAST_PKTS_last' , out_ucast_pkts )
89
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS_last' , out_non_ucast_pkts )
90
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_IN_OCTETS_last' , in_octets )
91
- redis .call (' HSET' , rates_table_name .. ' :' .. KEYS [i ], ' SAI_PORT_STAT_IF_OUT_OCTETS_last' , out_octets )
91
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_UCAST_PKTS_last' , in_ucast_pkts )
92
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS_last' , in_non_ucast_pkts )
93
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_UCAST_PKTS_last' , out_ucast_pkts )
94
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS_last' , out_non_ucast_pkts )
95
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_IN_OCTETS_last' , in_octets )
96
+ redis .call (' HSET' , rates_table_name .. ' :' .. port , ' SAI_PORT_STAT_IF_OUT_OCTETS_last' , out_octets )
97
+ end
98
+
99
+ local n = table .getn (KEYS )
100
+ for i = 1 , n do
101
+ compute_rate (KEYS [i ])
92
102
end
93
103
94
104
return logtable
0 commit comments