Skip to content

Commit 0870cf5

Browse files
authored
[mirrororch]: Implement HW resources availability validation for SPAN/ERSPAN (sonic-net#2187)
- What I did Added a validation to prevent mirror session configuration if there is no available HW resources - Why I did it To prevent system from unexpected reboots To add some debuggability information to the system journal - How I verified it Configure mirror sessions Signed-off-by: Nazarii Hnydyn <[email protected]>
1 parent f4ec565 commit 0870cf5

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

orchagent/mirrororch.cpp

+30-5
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,35 @@ bool MirrorOrch::validateSrcPortList(const string& srcPortList)
352352
return true;
353353
}
354354

355+
bool MirrorOrch::isHwResourcesAvailable()
356+
{
357+
uint64_t availCount = 0;
358+
359+
sai_status_t status = sai_object_type_get_availability(
360+
gSwitchId, SAI_OBJECT_TYPE_MIRROR_SESSION, 0, nullptr, &availCount
361+
);
362+
if (status != SAI_STATUS_SUCCESS)
363+
{
364+
if (status == SAI_STATUS_NOT_SUPPORTED)
365+
{
366+
SWSS_LOG_WARN("Mirror session resource availability monitoring is not supported. Skipping ...");
367+
return true;
368+
}
369+
370+
return parseHandleSaiStatusFailure(handleSaiGetStatus(SAI_API_MIRROR, status));
371+
}
372+
373+
return availCount > 0;
374+
}
375+
355376
task_process_status MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& data)
356377
{
357378
SWSS_LOG_ENTER();
358379

359380
auto session = m_syncdMirrors.find(key);
360381
if (session != m_syncdMirrors.end())
361382
{
362-
SWSS_LOG_NOTICE("Failed to create session, session %s already exists",
363-
key.c_str());
383+
SWSS_LOG_NOTICE("Failed to create session %s: object already exists", key.c_str());
364384
return task_process_status::task_duplicated;
365385
}
366386

@@ -471,10 +491,13 @@ task_process_status MirrorOrch::createEntry(const string& key, const vector<Fiel
471491
}
472492
}
473493

474-
m_syncdMirrors.emplace(key, entry);
475-
476-
SWSS_LOG_NOTICE("Created mirror session %s", key.c_str());
494+
if (!isHwResourcesAvailable())
495+
{
496+
SWSS_LOG_ERROR("Failed to create session %s: HW resources are not available", key.c_str());
497+
return task_process_status::task_failed;
498+
}
477499

500+
m_syncdMirrors.emplace(key, entry);
478501
setSessionState(key, entry);
479502

480503
if (entry.type == MIRROR_SESSION_SPAN && !entry.dst_port.empty())
@@ -488,6 +511,8 @@ task_process_status MirrorOrch::createEntry(const string& key, const vector<Fiel
488511
m_routeOrch->attach(this, entry.dstIp);
489512
}
490513

514+
SWSS_LOG_NOTICE("Created mirror session %s", key.c_str());
515+
491516
return task_process_status::task_success;
492517
}
493518

orchagent/mirrororch.h

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class MirrorOrch : public Orch, public Observer, public Subject
104104
// session_name -> VLAN | monitor_port_alias | next_hop_ip
105105
map<string, string> m_recoverySessionMap;
106106

107+
bool isHwResourcesAvailable();
108+
107109
task_process_status createEntry(const string&, const vector<FieldValueTuple>&);
108110
task_process_status deleteEntry(const string&);
109111

0 commit comments

Comments
 (0)