From 0870cf5f699aa79e42800c8a8900a3dc3977b934 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Mon, 4 Apr 2022 16:22:35 +0300 Subject: [PATCH] [mirrororch]: Implement HW resources availability validation for SPAN/ERSPAN (#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 --- orchagent/mirrororch.cpp | 35 ++++++++++++++++++++++++++++++----- orchagent/mirrororch.h | 2 ++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/orchagent/mirrororch.cpp b/orchagent/mirrororch.cpp index 6568c63d37c7..fca324e5fb49 100644 --- a/orchagent/mirrororch.cpp +++ b/orchagent/mirrororch.cpp @@ -352,6 +352,27 @@ 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& data) { SWSS_LOG_ENTER(); @@ -359,8 +380,7 @@ task_process_status MirrorOrch::createEntry(const string& key, const vectorattach(this, entry.dstIp); } + SWSS_LOG_NOTICE("Created mirror session %s", key.c_str()); + return task_process_status::task_success; } diff --git a/orchagent/mirrororch.h b/orchagent/mirrororch.h index b31d58bff3d6..d498a7ef6c92 100644 --- a/orchagent/mirrororch.h +++ b/orchagent/mirrororch.h @@ -104,6 +104,8 @@ class MirrorOrch : public Orch, public Observer, public Subject // session_name -> VLAN | monitor_port_alias | next_hop_ip map m_recoverySessionMap; + bool isHwResourcesAvailable(); + task_process_status createEntry(const string&, const vector&); task_process_status deleteEntry(const string&);