From 7cc035f93d028ea95488ce54e833d1699e3fd08a Mon Sep 17 00:00:00 2001 From: Renuka Manavalan <47282725+renukamanavalan@users.noreply.github.com> Date: Thu, 15 Sep 2022 10:11:55 -0700 Subject: [PATCH] [orchagent]: Publish identified events via structured-events channel (#2446) * Add events publish * Added header file * signature fix * syntax * syntax * syntax * syntax * syntax * syntax * Updated fake code * Remove if and log messages for event_publish * Remove if and log messages for event_publish (#1) * Remove event_handle_t from signature and add globally * Remove extern orchdaemon.cpp * Revert unneeded changes Co-authored-by: zbud-msft Co-authored-by: Zain Budhwani <99770260+zbud-msft@users.noreply.github.com> --- orchagent/crmorch.cpp | 7 +++++++ orchagent/crmorch.h | 1 + orchagent/orchdaemon.cpp | 5 +++++ orchagent/pfcwdorch.cpp | 43 +++++++++++++++++++++++----------------- orchagent/pfcwdorch.h | 4 +++- orchagent/portsorch.cpp | 3 +++ orchagent/portsorch.h | 1 + 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index f5e864a35764..54e2df78c7e6 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -18,6 +18,7 @@ extern sai_object_id_t gSwitchId; extern sai_switch_api_t *sai_switch_api; extern sai_acl_api_t *sai_acl_api; +extern event_handle_t g_events_handle; using namespace std; using namespace swss; @@ -763,9 +764,15 @@ void CrmOrch::checkCrmThresholds() if ((utilization >= res.highThreshold) && (res.exceededLogCounter < CRM_EXCEEDED_MSG_MAX)) { + event_params_t params = { + { "percent", to_string(percentageUtil) }, + { "used_cnt", to_string(cnt.usedCounter) }, + { "free_cnt", to_string(cnt.availableCounter) }}; + SWSS_LOG_WARN("%s THRESHOLD_EXCEEDED for %s %u%% Used count %u free count %u", res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter); + event_publish(g_events_handle, "chk_crm_threshold", ¶ms); res.exceededLogCounter++; } else if ((utilization <= res.lowThreshold) && (res.exceededLogCounter > 0) && (res.highThreshold != res.lowThreshold)) diff --git a/orchagent/crmorch.h b/orchagent/crmorch.h index f63e2a31c26d..a9c32a83bde7 100644 --- a/orchagent/crmorch.h +++ b/orchagent/crmorch.h @@ -5,6 +5,7 @@ #include #include "orch.h" #include "port.h" +#include "events.h" extern "C" { #include "sai.h" diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 1cc3127c31fd..68032d16893c 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -57,6 +57,7 @@ FlowCounterRouteOrch *gFlowCounterRouteOrch; DebugCounterOrch *gDebugCounterOrch; bool gIsNatSupported = false; +event_handle_t g_events_handle; #define DEFAULT_MAX_BULK_SIZE 1000 size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE; @@ -89,6 +90,8 @@ OrchDaemon::~OrchDaemon() delete(*it); } delete m_select; + + events_deinit_publisher(g_events_handle); } bool OrchDaemon::init() @@ -97,6 +100,8 @@ bool OrchDaemon::init() string platform = getenv("platform") ? getenv("platform") : ""; + g_events_handle = events_init_publisher("sonic-events-swss"); + gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME); TableConnector stateDbSwitchTable(m_stateDb, "SWITCH_CAPABILITY"); diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index da092387afbe..92425580287f 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -32,6 +32,8 @@ extern sai_switch_api_t* sai_switch_api; extern sai_port_api_t *sai_port_api; extern sai_queue_api_t *sai_queue_api; +extern event_handle_t g_events_handle; + extern SwitchOrch *gSwitchOrch; extern PortsOrch *gPortsOrch; @@ -933,6 +935,26 @@ void PfcWdSwOrch::doTask(SelectableTimer &timer) } +template +void PfcWdSwOrch::report_pfc_storm( + sai_object_id_t id, const PfcWdQueueEntry *entry) +{ + event_params_t params = { + { "ifname", entry->portAlias }, + { "queue_index", to_string(entry->index) }, + { "queue_id", to_string(id) }, + { "port_id", to_string(entry->portId) }}; + + SWSS_LOG_NOTICE( + "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", + entry->portAlias.c_str(), + entry->index, + id, + entry->portId); + + event_publish(g_events_handle, "pfc-storm", ¶ms); +} + template bool PfcWdSwOrch::startWdActionOnQueue(const string &event, sai_object_id_t queueId) { @@ -955,12 +977,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string { if (entry->second.handler == nullptr) { - SWSS_LOG_NOTICE( - "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", - entry->second.portAlias.c_str(), - entry->second.index, - entry->first, - entry->second.portId); + report_pfc_storm(entry->first, &entry->second); entry->second.handler = make_shared( entry->second.portId, @@ -977,12 +994,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string { if (entry->second.handler == nullptr) { - SWSS_LOG_NOTICE( - "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", - entry->second.portAlias.c_str(), - entry->second.index, - entry->first, - entry->second.portId); + report_pfc_storm(entry->first, &entry->second); entry->second.handler = make_shared( entry->second.portId, @@ -999,12 +1011,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string { if (entry->second.handler == nullptr) { - SWSS_LOG_NOTICE( - "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", - entry->second.portAlias.c_str(), - entry->second.index, - entry->first, - entry->second.portId); + report_pfc_storm(entry->first, &entry->second); entry->second.handler = make_shared( entry->second.portId, diff --git a/orchagent/pfcwdorch.h b/orchagent/pfcwdorch.h index 63be1be03629..ff493405b9df 100644 --- a/orchagent/pfcwdorch.h +++ b/orchagent/pfcwdorch.h @@ -7,6 +7,7 @@ #include "producertable.h" #include "notificationconsumer.h" #include "timer.h" +#include "events.h" extern "C" { #include "sai.h" @@ -55,7 +56,6 @@ class PfcWdOrch: public Orch protected: virtual bool startWdActionOnQueue(const string &event, sai_object_id_t queueId) = 0; string m_platform = ""; - private: shared_ptr m_countersDb = nullptr; @@ -121,6 +121,8 @@ class PfcWdSwOrch: public PfcWdOrch void enableBigRedSwitchMode(); void setBigRedSwitchMode(string value); + void report_pfc_storm(sai_object_id_t id, const PfcWdQueueEntry *); + map m_entryMap; map m_brsEntryMap; diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 126c33dcc7ec..4a96762a8c08 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -55,6 +55,7 @@ extern string gMySwitchType; extern int32_t gVoqMySwitchId; extern string gMyHostName; extern string gMyAsicName; +extern event_handle_t g_events_handle; #define DEFAULT_SYSTEM_PORT_MTU 9100 #define VLAN_PREFIX "Vlan" @@ -2537,6 +2538,8 @@ bool PortsOrch::setHostIntfsOperStatus(const Port& port, bool isUp) const SWSS_LOG_NOTICE("Set operation status %s to host interface %s", isUp ? "UP" : "DOWN", port.m_alias.c_str()); + event_params_t params = {{"ifname",port.m_alias},{"status",isUp ? "up" : "down"}}; + event_publish(g_events_handle, "if-state", ¶ms); return true; } diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index f481c95d4350..d28a347e088c 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -14,6 +14,7 @@ #include "saihelper.h" #include "lagid.h" #include "flexcounterorch.h" +#include "events.h" #define FCS_LEN 4