Skip to content

Commit 7cc035f

Browse files
[orchagent]: Publish identified events via structured-events channel (sonic-net#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 <zainbudhwani@microsoft.com> Co-authored-by: Zain Budhwani <99770260+zbud-msft@users.noreply.github.com>
1 parent efa0f01 commit 7cc035f

7 files changed

+45
-19
lines changed

orchagent/crmorch.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
extern sai_object_id_t gSwitchId;
1919
extern sai_switch_api_t *sai_switch_api;
2020
extern sai_acl_api_t *sai_acl_api;
21+
extern event_handle_t g_events_handle;
2122

2223
using namespace std;
2324
using namespace swss;
@@ -763,9 +764,15 @@ void CrmOrch::checkCrmThresholds()
763764

764765
if ((utilization >= res.highThreshold) && (res.exceededLogCounter < CRM_EXCEEDED_MSG_MAX))
765766
{
767+
event_params_t params = {
768+
{ "percent", to_string(percentageUtil) },
769+
{ "used_cnt", to_string(cnt.usedCounter) },
770+
{ "free_cnt", to_string(cnt.availableCounter) }};
771+
766772
SWSS_LOG_WARN("%s THRESHOLD_EXCEEDED for %s %u%% Used count %u free count %u",
767773
res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter);
768774

775+
event_publish(g_events_handle, "chk_crm_threshold", &params);
769776
res.exceededLogCounter++;
770777
}
771778
else if ((utilization <= res.lowThreshold) && (res.exceededLogCounter > 0) && (res.highThreshold != res.lowThreshold))

orchagent/crmorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <map>
66
#include "orch.h"
77
#include "port.h"
8+
#include "events.h"
89

910
extern "C" {
1011
#include "sai.h"

orchagent/orchdaemon.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ FlowCounterRouteOrch *gFlowCounterRouteOrch;
5757
DebugCounterOrch *gDebugCounterOrch;
5858

5959
bool gIsNatSupported = false;
60+
event_handle_t g_events_handle;
6061

6162
#define DEFAULT_MAX_BULK_SIZE 1000
6263
size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE;
@@ -89,6 +90,8 @@ OrchDaemon::~OrchDaemon()
8990
delete(*it);
9091
}
9192
delete m_select;
93+
94+
events_deinit_publisher(g_events_handle);
9295
}
9396

9497
bool OrchDaemon::init()
@@ -97,6 +100,8 @@ bool OrchDaemon::init()
97100

98101
string platform = getenv("platform") ? getenv("platform") : "";
99102

103+
g_events_handle = events_init_publisher("sonic-events-swss");
104+
100105
gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME);
101106

102107
TableConnector stateDbSwitchTable(m_stateDb, "SWITCH_CAPABILITY");

orchagent/pfcwdorch.cpp

+25-18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern sai_switch_api_t* sai_switch_api;
3232
extern sai_port_api_t *sai_port_api;
3333
extern sai_queue_api_t *sai_queue_api;
3434

35+
extern event_handle_t g_events_handle;
36+
3537
extern SwitchOrch *gSwitchOrch;
3638
extern PortsOrch *gPortsOrch;
3739

@@ -933,6 +935,26 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::doTask(SelectableTimer &timer)
933935

934936
}
935937

938+
template <typename DropHandler, typename ForwardHandler>
939+
void PfcWdSwOrch<DropHandler, ForwardHandler>::report_pfc_storm(
940+
sai_object_id_t id, const PfcWdQueueEntry *entry)
941+
{
942+
event_params_t params = {
943+
{ "ifname", entry->portAlias },
944+
{ "queue_index", to_string(entry->index) },
945+
{ "queue_id", to_string(id) },
946+
{ "port_id", to_string(entry->portId) }};
947+
948+
SWSS_LOG_NOTICE(
949+
"PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".",
950+
entry->portAlias.c_str(),
951+
entry->index,
952+
id,
953+
entry->portId);
954+
955+
event_publish(g_events_handle, "pfc-storm", &params);
956+
}
957+
936958
template <typename DropHandler, typename ForwardHandler>
937959
bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string &event, sai_object_id_t queueId)
938960
{
@@ -955,12 +977,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
955977
{
956978
if (entry->second.handler == nullptr)
957979
{
958-
SWSS_LOG_NOTICE(
959-
"PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".",
960-
entry->second.portAlias.c_str(),
961-
entry->second.index,
962-
entry->first,
963-
entry->second.portId);
980+
report_pfc_storm(entry->first, &entry->second);
964981

965982
entry->second.handler = make_shared<PfcWdActionHandler>(
966983
entry->second.portId,
@@ -977,12 +994,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
977994
{
978995
if (entry->second.handler == nullptr)
979996
{
980-
SWSS_LOG_NOTICE(
981-
"PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".",
982-
entry->second.portAlias.c_str(),
983-
entry->second.index,
984-
entry->first,
985-
entry->second.portId);
997+
report_pfc_storm(entry->first, &entry->second);
986998

987999
entry->second.handler = make_shared<DropHandler>(
9881000
entry->second.portId,
@@ -999,12 +1011,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
9991011
{
10001012
if (entry->second.handler == nullptr)
10011013
{
1002-
SWSS_LOG_NOTICE(
1003-
"PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".",
1004-
entry->second.portAlias.c_str(),
1005-
entry->second.index,
1006-
entry->first,
1007-
entry->second.portId);
1014+
report_pfc_storm(entry->first, &entry->second);
10081015

10091016
entry->second.handler = make_shared<ForwardHandler>(
10101017
entry->second.portId,

orchagent/pfcwdorch.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "producertable.h"
88
#include "notificationconsumer.h"
99
#include "timer.h"
10+
#include "events.h"
1011

1112
extern "C" {
1213
#include "sai.h"
@@ -55,7 +56,6 @@ class PfcWdOrch: public Orch
5556
protected:
5657
virtual bool startWdActionOnQueue(const string &event, sai_object_id_t queueId) = 0;
5758
string m_platform = "";
58-
5959
private:
6060

6161
shared_ptr<DBConnector> m_countersDb = nullptr;
@@ -121,6 +121,8 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
121121
void enableBigRedSwitchMode();
122122
void setBigRedSwitchMode(string value);
123123

124+
void report_pfc_storm(sai_object_id_t id, const PfcWdQueueEntry *);
125+
124126
map<sai_object_id_t, PfcWdQueueEntry> m_entryMap;
125127
map<sai_object_id_t, PfcWdQueueEntry> m_brsEntryMap;
126128

orchagent/portsorch.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern string gMySwitchType;
5555
extern int32_t gVoqMySwitchId;
5656
extern string gMyHostName;
5757
extern string gMyAsicName;
58+
extern event_handle_t g_events_handle;
5859

5960
#define DEFAULT_SYSTEM_PORT_MTU 9100
6061
#define VLAN_PREFIX "Vlan"
@@ -2537,6 +2538,8 @@ bool PortsOrch::setHostIntfsOperStatus(const Port& port, bool isUp) const
25372538
SWSS_LOG_NOTICE("Set operation status %s to host interface %s",
25382539
isUp ? "UP" : "DOWN", port.m_alias.c_str());
25392540

2541+
event_params_t params = {{"ifname",port.m_alias},{"status",isUp ? "up" : "down"}};
2542+
event_publish(g_events_handle, "if-state", &params);
25402543
return true;
25412544
}
25422545

orchagent/portsorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "saihelper.h"
1515
#include "lagid.h"
1616
#include "flexcounterorch.h"
17+
#include "events.h"
1718

1819

1920
#define FCS_LEN 4

0 commit comments

Comments
 (0)