Skip to content

Commit

Permalink
[mirrororch]: Implement HW resources availability validation for SPAN…
Browse files Browse the repository at this point in the history
…/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]>
  • Loading branch information
nazariig authored Apr 4, 2022
1 parent f4ec565 commit 0870cf5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
35 changes: 30 additions & 5 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,35 @@ bool MirrorOrch::validateSrcPortList(const string& srcPortList)
return true;
}

bool MirrorOrch::isHwResourcesAvailable()
{
uint64_t availCount = 0;

sai_status_t status = sai_object_type_get_availability(
gSwitchId, SAI_OBJECT_TYPE_MIRROR_SESSION, 0, nullptr, &availCount
);
if (status != SAI_STATUS_SUCCESS)
{
if (status == SAI_STATUS_NOT_SUPPORTED)
{
SWSS_LOG_WARN("Mirror session resource availability monitoring is not supported. Skipping ...");
return true;
}

return parseHandleSaiStatusFailure(handleSaiGetStatus(SAI_API_MIRROR, status));
}

return availCount > 0;
}

task_process_status MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& data)
{
SWSS_LOG_ENTER();

auto session = m_syncdMirrors.find(key);
if (session != m_syncdMirrors.end())
{
SWSS_LOG_NOTICE("Failed to create session, session %s already exists",
key.c_str());
SWSS_LOG_NOTICE("Failed to create session %s: object already exists", key.c_str());
return task_process_status::task_duplicated;
}

Expand Down Expand Up @@ -471,10 +491,13 @@ task_process_status MirrorOrch::createEntry(const string& key, const vector<Fiel
}
}

m_syncdMirrors.emplace(key, entry);

SWSS_LOG_NOTICE("Created mirror session %s", key.c_str());
if (!isHwResourcesAvailable())
{
SWSS_LOG_ERROR("Failed to create session %s: HW resources are not available", key.c_str());
return task_process_status::task_failed;
}

m_syncdMirrors.emplace(key, entry);
setSessionState(key, entry);

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

SWSS_LOG_NOTICE("Created mirror session %s", key.c_str());

return task_process_status::task_success;
}

Expand Down
2 changes: 2 additions & 0 deletions orchagent/mirrororch.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class MirrorOrch : public Orch, public Observer, public Subject
// session_name -> VLAN | monitor_port_alias | next_hop_ip
map<string, string> m_recoverySessionMap;

bool isHwResourcesAvailable();

task_process_status createEntry(const string&, const vector<FieldValueTuple>&);
task_process_status deleteEntry(const string&);

Expand Down

0 comments on commit 0870cf5

Please sign in to comment.