forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountercheckorch.cpp
More file actions
237 lines (194 loc) · 6.42 KB
/
Copy pathcountercheckorch.cpp
File metadata and controls
237 lines (194 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "countercheckorch.h"
#include "portsorch.h"
#include "select.h"
#include "notifier.h"
#include "redisclient.h"
#include "sai_serialize.h"
#include <inttypes.h>
#define COUNTER_CHECK_POLL_TIMEOUT_SEC (5 * 60)
extern sai_port_api_t *sai_port_api;
extern PortsOrch *gPortsOrch;
CounterCheckOrch& CounterCheckOrch::getInstance(DBConnector *db)
{
SWSS_LOG_ENTER();
static vector<string> tableNames = {};
static CounterCheckOrch *wd = new CounterCheckOrch(db, tableNames);
return *wd;
}
CounterCheckOrch::CounterCheckOrch(DBConnector *db, vector<string> &tableNames):
Orch(db, tableNames),
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
m_countersTable(new Table(m_countersDb.get(), COUNTERS_TABLE))
{
SWSS_LOG_ENTER();
auto interv = timespec { .tv_sec = COUNTER_CHECK_POLL_TIMEOUT_SEC, .tv_nsec = 0 };
auto timer = new SelectableTimer(interv);
auto executor = new ExecutableTimer(timer, this, "MC_COUNTERS_POLL");
Orch::addExecutor(executor);
timer->start();
}
CounterCheckOrch::~CounterCheckOrch(void)
{
SWSS_LOG_ENTER();
}
void CounterCheckOrch::doTask(SelectableTimer &timer)
{
SWSS_LOG_ENTER();
mcCounterCheck();
pfcFrameCounterCheck();
}
void CounterCheckOrch::mcCounterCheck()
{
SWSS_LOG_ENTER();
for (auto& i : m_mcCountersMap)
{
auto oid = i.first;
auto mcCounters = i.second;
uint8_t pfcMask = 0;
Port port;
if (!gPortsOrch->getPort(oid, port))
{
SWSS_LOG_ERROR("Invalid port oid 0x%" PRIx64, oid);
continue;
}
auto newMcCounters = getQueueMcCounters(port);
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
continue;
}
for (size_t prio = 0; prio != mcCounters.size(); prio++)
{
bool isLossy = ((1 << prio) & pfcMask) == 0;
if (newMcCounters[prio] == numeric_limits<uint64_t>::max())
{
SWSS_LOG_WARN("Could not retreive MC counters on queue %zu port %s",
prio,
port.m_alias.c_str());
}
else if (!isLossy && mcCounters[prio] < newMcCounters[prio])
{
SWSS_LOG_WARN("Got Multicast %" PRIu64 " frame(s) on lossless queue %zu port %s",
newMcCounters[prio] - mcCounters[prio],
prio,
port.m_alias.c_str());
}
}
i.second= newMcCounters;
}
}
void CounterCheckOrch::pfcFrameCounterCheck()
{
SWSS_LOG_ENTER();
for (auto& i : m_pfcFrameCountersMap)
{
auto oid = i.first;
auto counters = i.second;
auto newCounters = getPfcFrameCounters(oid);
uint8_t pfcMask = 0;
Port port;
if (!gPortsOrch->getPort(oid, port))
{
SWSS_LOG_ERROR("Invalid port oid 0x%" PRIx64, oid);
continue;
}
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
continue;
}
for (size_t prio = 0; prio != counters.size(); prio++)
{
bool isLossy = ((1 << prio) & pfcMask) == 0;
if (newCounters[prio] == numeric_limits<uint64_t>::max())
{
SWSS_LOG_WARN("Could not retreive PFC frame count on queue %zu port %s",
prio,
port.m_alias.c_str());
}
else if (isLossy && counters[prio] < newCounters[prio])
{
SWSS_LOG_WARN("Got PFC %" PRIu64 " frame(s) on lossy queue %zu port %s",
newCounters[prio] - counters[prio],
prio,
port.m_alias.c_str());
}
}
i.second = newCounters;
}
}
PfcFrameCounters CounterCheckOrch::getPfcFrameCounters(sai_object_id_t portId)
{
SWSS_LOG_ENTER();
vector<FieldValueTuple> fieldValues;
PfcFrameCounters counters;
counters.fill(numeric_limits<uint64_t>::max());
static const array<string, PFC_WD_TC_MAX> counterNames =
{
"SAI_PORT_STAT_PFC_0_RX_PKTS",
"SAI_PORT_STAT_PFC_1_RX_PKTS",
"SAI_PORT_STAT_PFC_2_RX_PKTS",
"SAI_PORT_STAT_PFC_3_RX_PKTS",
"SAI_PORT_STAT_PFC_4_RX_PKTS",
"SAI_PORT_STAT_PFC_5_RX_PKTS",
"SAI_PORT_STAT_PFC_6_RX_PKTS",
"SAI_PORT_STAT_PFC_7_RX_PKTS"
};
if (!m_countersTable->get(sai_serialize_object_id(portId), fieldValues))
{
return move(counters);
}
for (const auto& fv : fieldValues)
{
const auto field = fvField(fv);
const auto value = fvValue(fv);
for (size_t prio = 0; prio != counterNames.size(); prio++)
{
if (field == counterNames[prio])
{
counters[prio] = stoul(value);
}
}
}
return move(counters);
}
QueueMcCounters CounterCheckOrch::getQueueMcCounters(
const Port& port)
{
SWSS_LOG_ENTER();
vector<FieldValueTuple> fieldValues;
QueueMcCounters counters;
RedisClient redisClient(m_countersDb.get());
for (uint8_t prio = 0; prio < port.m_queue_ids.size(); prio++)
{
sai_object_id_t queueId = port.m_queue_ids[prio];
auto queueIdStr = sai_serialize_object_id(queueId);
auto queueType = redisClient.hget(COUNTERS_QUEUE_TYPE_MAP, queueIdStr);
if (queueType.get() == nullptr || *queueType != "SAI_QUEUE_TYPE_MULTICAST" || !m_countersTable->get(queueIdStr, fieldValues))
{
continue;
}
uint64_t pkts = numeric_limits<uint64_t>::max();
for (const auto& fv : fieldValues)
{
const auto field = fvField(fv);
const auto value = fvValue(fv);
if (field == "SAI_QUEUE_STAT_PACKETS")
{
pkts = stoul(value);
}
}
counters.push_back(pkts);
}
return move(counters);
}
void CounterCheckOrch::addPort(const Port& port)
{
m_mcCountersMap.emplace(port.m_port_id, getQueueMcCounters(port));
m_pfcFrameCountersMap.emplace(port.m_port_id, getPfcFrameCounters(port.m_port_id));
}
void CounterCheckOrch::removePort(const Port& port)
{
m_mcCountersMap.erase(port.m_port_id);
m_pfcFrameCountersMap.erase(port.m_port_id);
}