Skip to content

Commit 4770917

Browse files
committed
Monitor fabric port flapping.
1 parent 76c53da commit 4770917

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

orchagent/fabricportsorch.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,45 +272,74 @@ void FabricPortsOrch::updateFabricPortState()
272272
{
273273
if (!m_getFabricPortListDone) return;
274274

275+
SWSS_LOG_ENTER();
276+
275277
sai_status_t status;
276278
sai_attribute_t attr;
277279

280+
time_t now;
281+
struct timespec time_now;
282+
if (clock_gettime(CLOCK_MONOTONIC, &time_now) < 0)
283+
{
284+
return;
285+
}
286+
now = time_now.tv_sec;
287+
278288
for (auto p : m_fabricLanePortMap)
279289
{
280290
int lane = p.first;
281291
sai_object_id_t port = p.second;
282292

283293
string key = "PORT" + to_string(lane);
284294
std::vector<FieldValueTuple> values;
295+
uint32_t remote_peer;
296+
uint32_t remote_port;
285297

286298
attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED;
287299
status = sai_port_api->get_port_attribute(port, 1, &attr);
288300
if (status != SAI_STATUS_SUCCESS)
289301
{
290302
throw runtime_error("FabricPortsOrch get port status failure");
291303
}
292-
FieldValueTuple s("STATUS", attr.value.booldata ? "up" : "down");
293-
values.push_back(s);
294304

295-
if (attr.value.booldata)
305+
if (m_portStatus.find(lane) != m_portStatus.end() &&
306+
m_portStatus[lane] != attr.value.booldata)
307+
{
308+
m_portFlappingCount[lane] ++;
309+
m_portFlappingSeenLastTime[lane] = now;
310+
}
311+
m_portStatus[lane] = attr.value.booldata;
312+
313+
if (m_portStatus[lane])
296314
{
297315
attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_ID;
298316
status = sai_port_api->get_port_attribute(port, 1, &attr);
299317
if (status != SAI_STATUS_SUCCESS)
300318
{
301319
throw runtime_error("FabricPortsOrch get remote id failure");
302320
}
303-
FieldValueTuple rm("REMOTE_MOD", to_string(attr.value.u32));
304-
values.push_back(rm);
321+
remote_peer = attr.value.u32;
305322

306323
attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX;
307324
status = sai_port_api->get_port_attribute(port, 1, &attr);
308325
if (status != SAI_STATUS_SUCCESS)
309326
{
310327
throw runtime_error("FabricPortsOrch get remote port index failure");
311328
}
312-
FieldValueTuple rp("REMOTE_PORT", to_string(attr.value.u32));
313-
values.push_back(rp);
329+
remote_port = attr.value.u32;
330+
}
331+
332+
values.emplace_back("STATUS", m_portStatus[lane] ? "up" : "down");
333+
if (m_portStatus[lane])
334+
{
335+
values.emplace_back("REMOTE_MOD", to_string(remote_peer));
336+
values.emplace_back("REMOTE_PORT", to_string(remote_port));
337+
}
338+
if (m_portFlappingCount[lane] > 0)
339+
{
340+
values.emplace_back("PORT_FLAPPING_COUNT", to_string(m_portFlappingCount[lane]));
341+
values.emplace_back("PORT_FLAPPING_SEEN_LAST_TIME",
342+
to_string(m_portFlappingSeenLastTime[lane]));
314343
}
315344
m_stateTable->set(key, values);
316345
}

orchagent/fabricportsorch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class FabricPortsOrch : public Orch, public Subject
3636

3737
sai_uint32_t m_fabricPortCount;
3838
map<int, sai_object_id_t> m_fabricLanePortMap;
39+
unordered_map<int, bool> m_portStatus;
40+
unordered_map<int, size_t> m_portFlappingCount;
41+
unordered_map<int, time_t> m_portFlappingSeenLastTime;
3942

4043
bool m_getFabricPortListDone = false;
4144
bool m_isQueueStatsGenerated = false;

0 commit comments

Comments
 (0)