@@ -22,69 +22,78 @@ for i = n, 1, -1 do
22
22
local pfc_wd_status = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_STATUS' )
23
23
local pfc_wd_action = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_ACTION' )
24
24
if pfc_wd_status == ' operational' or pfc_wd_action == ' alert' then
25
- local detection_time = tonumber (redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_DETECTION_TIME' ))
26
- local time_left = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_DETECTION_TIME_LEFT' )
27
- if not time_left then
28
- time_left = detection_time
29
- else
30
- time_left = tonumber (time_left )
31
- end
25
+ local detection_time = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_DETECTION_TIME' )
26
+ if detection_time then
27
+ detection_time = tonumber (detection_time )
28
+ local time_left = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_DETECTION_TIME_LEFT' )
29
+ if not time_left then
30
+ time_left = detection_time
31
+ else
32
+ time_left = tonumber (time_left )
33
+ end
32
34
33
- local queue_index = redis .call (' HGET' , ' COUNTERS_QUEUE_INDEX_MAP' , KEYS [i ])
34
- local port_id = redis .call (' HGET' , ' COUNTERS_QUEUE_PORT_MAP' , KEYS [i ])
35
- local pfc_rx_pkt_key = ' SAI_PORT_STAT_PFC_' .. queue_index .. ' _RX_PKTS'
36
- local pfc_on2off_key = ' SAI_PORT_STAT_PFC_' .. queue_index .. ' _ON2OFF_RX_PKTS'
37
-
35
+ local queue_index = redis .call (' HGET' , ' COUNTERS_QUEUE_INDEX_MAP' , KEYS [i ])
36
+ local port_id = redis .call (' HGET' , ' COUNTERS_QUEUE_PORT_MAP' , KEYS [i ])
37
+ local pfc_rx_pkt_key = ' SAI_PORT_STAT_PFC_' .. queue_index .. ' _RX_PKTS'
38
+ local pfc_on2off_key = ' SAI_PORT_STAT_PFC_' .. queue_index .. ' _ON2OFF_RX_PKTS'
38
39
39
- -- Get all counters
40
- local occupancy_bytes = tonumber (redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES' ))
41
- local packets = tonumber (redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_PACKETS' ))
42
- local pfc_rx_packets = tonumber (redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_rx_pkt_key ))
43
- local pfc_on2off = tonumber (redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_on2off_key ))
44
- local queue_pause_status = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_ATTR_PAUSE_STATUS' )
45
-
46
- local packets_last = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_PACKETS_last' )
47
- local pfc_rx_packets_last = redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_rx_pkt_key .. ' _last' )
48
- local pfc_on2off_last = redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_on2off_key .. ' _last' )
49
- local queue_pause_status_last = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_ATTR_PAUSE_STATUS_last' )
40
+ -- Get all counters
41
+ local occupancy_bytes = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES' )
42
+ local packets = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_PACKETS' )
43
+ local pfc_rx_packets = redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_rx_pkt_key )
44
+ local pfc_on2off = redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_on2off_key )
45
+ local queue_pause_status = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_ATTR_PAUSE_STATUS' )
50
46
51
- -- DEBUG CODE START. Uncomment to enable
52
- local debug_storm = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' DEBUG_STORM' )
53
- -- DEBUG CODE END.
47
+ if occupancy_bytes and packets and pfc_rx_packets and pfc_on2off and queue_pause_status then
48
+ occupancy_bytes = tonumber (occupancy_bytes )
49
+ packets = tonumber (packets )
50
+ pfc_rx_packets = tonumber (pfc_rx_packets )
51
+ pfc_on2off = tonumber (pfc_on2off )
54
52
55
- -- If this is not a first run, then we have last values available
56
- if packets_last and pfc_rx_packets_last and pfc_on2off_last and queue_pause_status_last then
57
- packets_last = tonumber (packets_last )
58
- pfc_rx_packets_last = tonumber (pfc_rx_packets_last )
59
- pfc_on2off_last = tonumber (pfc_on2off_last )
53
+ local packets_last = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_PACKETS_last' )
54
+ local pfc_rx_packets_last = redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_rx_pkt_key .. ' _last' )
55
+ local pfc_on2off_last = redis .call (' HGET' , counters_table_name .. ' :' .. port_id , pfc_on2off_key .. ' _last' )
56
+ local queue_pause_status_last = redis .call (' HGET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_ATTR_PAUSE_STATUS_last' )
60
57
61
- -- Check actual condition of queue being in PFC storm
62
- if (occupancy_bytes > 0 and packets - packets_last == 0 and pfc_rx_packets - pfc_rx_packets_last > 0 ) or
63
58
-- DEBUG CODE START. Uncomment to enable
64
- ( debug_storm == " enabled " ) or
59
+ local debug_storm = redis . call ( ' HGET ' , counters_table_name .. ' : ' .. KEYS [ i ], ' DEBUG_STORM ' )
65
60
-- DEBUG CODE END.
66
- (occupancy_bytes == 0 and pfc_rx_packets - pfc_rx_packets_last > 0 and pfc_on2off - pfc_on2off_last == 0 and queue_pause_status_last == ' true' and queue_pause_status == ' true' ) then
67
- if time_left <= poll_time then
68
- redis .call (' PUBLISH' , ' PFC_WD' , ' ["' .. KEYS [i ] .. ' ","storm"]' )
69
- is_deadlock = true
70
- time_left = detection_time
71
- else
72
- time_left = time_left - poll_time
73
- end
74
- else
75
- if pfc_wd_action == ' alert' and pfc_wd_status ~= ' operational' then
76
- redis .call (' PUBLISH' , ' PFC_WD' , ' ["' .. KEYS [i ] .. ' ","restore"]' )
61
+
62
+ -- If this is not a first run, then we have last values available
63
+ if packets_last and pfc_rx_packets_last and pfc_on2off_last and queue_pause_status_last then
64
+ packets_last = tonumber (packets_last )
65
+ pfc_rx_packets_last = tonumber (pfc_rx_packets_last )
66
+ pfc_on2off_last = tonumber (pfc_on2off_last )
67
+
68
+ -- Check actual condition of queue being in PFC storm
69
+ if (occupancy_bytes > 0 and packets - packets_last == 0 and pfc_rx_packets - pfc_rx_packets_last > 0 ) or
70
+ -- DEBUG CODE START. Uncomment to enable
71
+ (debug_storm == " enabled" ) or
72
+ -- DEBUG CODE END.
73
+ (occupancy_bytes == 0 and pfc_rx_packets - pfc_rx_packets_last > 0 and pfc_on2off - pfc_on2off_last == 0 and queue_pause_status_last == ' true' and queue_pause_status == ' true' ) then
74
+ if time_left <= poll_time then
75
+ redis .call (' PUBLISH' , ' PFC_WD' , ' ["' .. KEYS [i ] .. ' ","storm"]' )
76
+ is_deadlock = true
77
+ time_left = detection_time
78
+ else
79
+ time_left = time_left - poll_time
80
+ end
81
+ else
82
+ if pfc_wd_action == ' alert' and pfc_wd_status ~= ' operational' then
83
+ redis .call (' PUBLISH' , ' PFC_WD' , ' ["' .. KEYS [i ] .. ' ","restore"]' )
84
+ end
85
+ time_left = detection_time
86
+ end
77
87
end
78
- time_left = detection_time
88
+
89
+ -- Save values for next run
90
+ redis .call (' HSET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_ATTR_PAUSE_STATUS_last' , queue_pause_status )
91
+ redis .call (' HSET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_PACKETS_last' , packets )
92
+ redis .call (' HSET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_DETECTION_TIME_LEFT' , time_left )
93
+ redis .call (' HSET' , counters_table_name .. ' :' .. port_id , pfc_rx_pkt_key .. ' _last' , pfc_rx_packets )
94
+ redis .call (' HSET' , counters_table_name .. ' :' .. port_id , pfc_on2off_key .. ' _last' , pfc_on2off )
79
95
end
80
96
end
81
-
82
- -- Save values for next run
83
- redis .call (' HSET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_ATTR_PAUSE_STATUS_last' , queue_pause_status )
84
- redis .call (' HSET' , counters_table_name .. ' :' .. KEYS [i ], ' SAI_QUEUE_STAT_PACKETS_last' , packets )
85
- redis .call (' HSET' , counters_table_name .. ' :' .. KEYS [i ], ' PFC_WD_DETECTION_TIME_LEFT' , time_left )
86
- redis .call (' HSET' , counters_table_name .. ' :' .. port_id , pfc_rx_pkt_key .. ' _last' , pfc_rx_packets )
87
- redis .call (' HSET' , counters_table_name .. ' :' .. port_id , pfc_on2off_key .. ' _last' , pfc_on2off )
88
97
end
89
98
end
90
99
0 commit comments