Skip to content

Commit

Permalink
Support ASIC/SDK health event (sonic-net#1340)
Browse files Browse the repository at this point in the history
* ASIC/SDK health event

Signed-off-by: Stephen Sun <[email protected]>

* Fix check error

Signed-off-by: Stephen Sun <[email protected]>

* Fix UT error

Signed-off-by: Stephen Sun <[email protected]>

* Improve coverage

Signed-off-by: Stephen Sun <[email protected]>

* Fix review comments

Signed-off-by: Stephen Sun <[email protected]>

---------

Signed-off-by: Stephen Sun <[email protected]>
  • Loading branch information
stephenxs authored May 2, 2024
1 parent c3395e5 commit 8a0cc25
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void Switch::updateNotifications(
(sai_switch_state_change_notification_fn)attr.value.ptr;
break;

case SAI_SWITCH_ATTR_SWITCH_ASIC_SDK_HEALTH_EVENT_NOTIFY:
m_switchNotifications.on_switch_asic_sdk_health_event =
(sai_switch_asic_sdk_health_event_notification_fn)attr.value.ptr;
break;

case SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY:
m_switchNotifications.on_switch_shutdown_request =
(sai_switch_shutdown_request_notification_fn)attr.value.ptr;
Expand Down
1 change: 1 addition & 0 deletions meta/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ libsaimeta_la_SOURCES = \
NotificationNatEvent.cpp \
NotificationPortStateChange.cpp \
NotificationQueuePfcDeadlock.cpp \
NotificationSwitchAsicSdkHealthEvent.cpp \
NotificationSwitchShutdownRequest.cpp \
NotificationSwitchStateChange.cpp \
NotificationBfdSessionStateChange.cpp \
Expand Down
48 changes: 48 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6513,6 +6513,54 @@ void Meta::meta_sai_on_switch_state_change(
// we should not snoop switch_id, since switch id should be created directly by user
}

void Meta::meta_sai_on_switch_asic_sdk_health_event(
_In_ sai_object_id_t switch_id,
_In_ sai_switch_asic_sdk_health_severity_t severity,
_In_ sai_timespec_t timestamp,
_In_ sai_switch_asic_sdk_health_category_t category,
_In_ sai_switch_health_data_t data,
_In_ const sai_u8_list_t description)
{
SWSS_LOG_ENTER();

if (!sai_metadata_get_enum_value_name(
&sai_metadata_enum_sai_switch_asic_sdk_health_severity_t,
severity))
{
SWSS_LOG_WARN("Switch ASIC/SDK health event severity value (%d) not found in sai_switch_asic_sdk_health_severity_t",
severity);
}

if (!sai_metadata_get_enum_value_name(
&sai_metadata_enum_sai_switch_asic_sdk_health_category_t,
category))
{
SWSS_LOG_WARN("Switch ASIC/SDK health event category value (%d) not found in sai_switch_asic_sdk_health_severity_t",
category);
}

auto ot = objectTypeQuery(switch_id);

if (ot != SAI_OBJECT_TYPE_SWITCH)
{
SWSS_LOG_WARN("switch_id %s is of type %s, but expected SAI_OBJECT_TYPE_SWITCH",
sai_serialize_object_id(switch_id).c_str(),
sai_serialize_object_type(ot).c_str());

return;
}

sai_object_meta_key_t switch_meta_key = { .objecttype = ot , .objectkey = { .key = { .object_id = switch_id } } };

if (!m_saiObjectCollection.objectExists(switch_meta_key))
{
SWSS_LOG_ERROR("switch_id %s don't exists in local database",
sai_serialize_object_id(switch_id).c_str());
}

// we should not snoop switch_id, since switch id should be created directly by user
}

void Meta::meta_sai_on_switch_shutdown_request(
_In_ sai_object_id_t switch_id)
{
Expand Down
8 changes: 8 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ namespace saimeta
_In_ sai_object_id_t switch_id,
_In_ sai_switch_oper_status_t switch_oper_status);

void meta_sai_on_switch_asic_sdk_health_event(
_In_ sai_object_id_t switch_id,
_In_ sai_switch_asic_sdk_health_severity_t severity,
_In_ sai_timespec_t timestamp,
_In_ sai_switch_asic_sdk_health_category_t category,
_In_ sai_switch_health_data_t data,
_In_ const sai_u8_list_t description);

void meta_sai_on_switch_shutdown_request(
_In_ sai_object_id_t switch_id);

Expand Down
4 changes: 4 additions & 0 deletions meta/NotificationFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "NotificationQueuePfcDeadlock.h"
#include "NotificationSwitchShutdownRequest.h"
#include "NotificationSwitchStateChange.h"
#include "NotificationSwitchAsicSdkHealthEvent.h"
#include "NotificationBfdSessionStateChange.h"
#include "NotificationTwampSessionEvent.h"
#include "NotificationPortHostTxReadyEvent.h"
Expand Down Expand Up @@ -38,6 +39,9 @@ std::shared_ptr<Notification> NotificationFactory::deserialize(
if (name == SAI_SWITCH_NOTIFICATION_NAME_SWITCH_SHUTDOWN_REQUEST)
return std::make_shared<NotificationSwitchShutdownRequest>(serializedNotification);

if (name == SAI_SWITCH_NOTIFICATION_NAME_SWITCH_ASIC_SDK_HEALTH_EVENT)
return std::make_shared<NotificationSwitchAsicSdkHealthEvent>(serializedNotification);

if (name == SAI_SWITCH_NOTIFICATION_NAME_SWITCH_STATE_CHANGE)
return std::make_shared<NotificationSwitchStateChange>(serializedNotification);

Expand Down
74 changes: 74 additions & 0 deletions meta/NotificationSwitchAsicSdkHealthEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "NotificationSwitchAsicSdkHealthEvent.h"

#include "swss/logger.h"

#include "sai_serialize.h"

using namespace sairedis;

NotificationSwitchAsicSdkHealthEvent::NotificationSwitchAsicSdkHealthEvent(
_In_ const std::string& serializedNotification):
Notification(
SAI_SWITCH_NOTIFICATION_TYPE_SWITCH_ASIC_SDK_HEALTH_EVENT,
serializedNotification)
{
SWSS_LOG_ENTER();

sai_deserialize_switch_asic_sdk_health_event(serializedNotification,
m_switchId,
m_severity,
m_timestamp,
m_category,
m_healthData,
m_description);
}

NotificationSwitchAsicSdkHealthEvent::~NotificationSwitchAsicSdkHealthEvent()
{
SWSS_LOG_ENTER();

sai_deserialize_free_switch_asic_sdk_health_event(m_description);
}

sai_object_id_t NotificationSwitchAsicSdkHealthEvent::getSwitchId() const
{
SWSS_LOG_ENTER();

return m_switchId;
}

sai_object_id_t NotificationSwitchAsicSdkHealthEvent::getAnyObjectId() const
{
SWSS_LOG_ENTER();

return m_switchId;
}

void NotificationSwitchAsicSdkHealthEvent::processMetadata(
_In_ std::shared_ptr<saimeta::Meta> meta) const
{
SWSS_LOG_ENTER();

meta->meta_sai_on_switch_asic_sdk_health_event(m_switchId,
m_severity,
m_timestamp,
m_category,
m_healthData,
m_description);
}

void NotificationSwitchAsicSdkHealthEvent::executeCallback(
_In_ const sai_switch_notifications_t& switchNotifications) const
{
SWSS_LOG_ENTER();

if (switchNotifications.on_switch_asic_sdk_health_event)
{
switchNotifications.on_switch_asic_sdk_health_event(m_switchId,
m_severity,
m_timestamp,
m_category,
m_healthData,
m_description);
}
}
38 changes: 38 additions & 0 deletions meta/NotificationSwitchAsicSdkHealthEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "Notification.h"

namespace sairedis
{
class NotificationSwitchAsicSdkHealthEvent:
public Notification
{
public:

NotificationSwitchAsicSdkHealthEvent(
_In_ const std::string& serializedNotification);

virtual ~NotificationSwitchAsicSdkHealthEvent();

public:

virtual sai_object_id_t getSwitchId() const override;

virtual sai_object_id_t getAnyObjectId() const override;

virtual void processMetadata(
_In_ std::shared_ptr<saimeta::Meta> meta) const override;

virtual void executeCallback(
_In_ const sai_switch_notifications_t& switchNotifications) const override;

private:

sai_object_id_t m_switchId;
sai_switch_asic_sdk_health_severity_t m_severity;
sai_switch_asic_sdk_health_category_t m_category;
sai_timespec_t m_timestamp;
sai_switch_health_data_t m_healthData;
sai_u8_list_t m_description;
};
}
97 changes: 96 additions & 1 deletion meta/SaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,41 @@ std::string sai_serialize_egress_drop_reason(
return sai_serialize_enum(reason, &sai_metadata_enum_sai_out_drop_reason_t);
}

std::string sai_serialize_timespec(
_In_ const sai_timespec_t &timespec)
{
SWSS_LOG_ENTER();

json j;

j["tv_sec"] = sai_serialize_number<uint64_t>(timespec.tv_sec);
j["tv_nsec"] = sai_serialize_number<uint32_t>(timespec.tv_nsec);

return j.dump();
}

std::string sai_serialize_switch_asic_sdk_health_event(
_In_ sai_object_id_t switch_id,
_In_ sai_switch_asic_sdk_health_severity_t severity,
_In_ const sai_timespec_t &timestamp,
_In_ sai_switch_asic_sdk_health_category_t category,
_In_ const sai_switch_health_data_t &data,
_In_ const sai_u8_list_t &description)
{
SWSS_LOG_ENTER();

json j;

j["switch_id"] = sai_serialize_object_id(switch_id);
j["severity"] = sai_serialize_enum(severity, &sai_metadata_enum_sai_switch_asic_sdk_health_severity_t);
j["timestamp"] = sai_serialize_timespec(timestamp);
j["category"] = sai_serialize_enum(category, &sai_metadata_enum_sai_switch_asic_sdk_health_category_t);
j["data.data_type"] = sai_serialize_enum(data.data_type, &sai_metadata_enum_sai_health_data_type_t);
j["description"] = sai_serialize_number_list(description, false);

return j.dump();
}

std::string sai_serialize_switch_shutdown_request(
_In_ sai_object_id_t switch_id)
{
Expand Down Expand Up @@ -1299,7 +1334,7 @@ template <typename T>
std::string sai_serialize_number_list(
_In_ const T& list,
_In_ bool countOnly,
_In_ bool hex = false)
_In_ bool hex)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -4147,6 +4182,66 @@ void sai_deserialize_switch_oper_status(
sai_deserialize_enum(j["status"], &sai_metadata_enum_sai_switch_oper_status_t, (int32_t&)status);
}

void sai_deserialize_timespec(
_In_ const std::string& s,
_Out_ sai_timespec_t &timestamp)
{
SWSS_LOG_ENTER();

json j;
try
{
j = json::parse(s);
}
catch (const std::exception&)
{
SWSS_LOG_THROW("Received an exception after trying to parse timespec_t from %s", s.c_str());
}

sai_deserialize_number<uint64_t>(j["tv_sec"], timestamp.tv_sec);
sai_deserialize_number<uint32_t>(j["tv_nsec"], timestamp.tv_nsec);
}

void sai_deserialize_switch_asic_sdk_health_event(
_In_ const std::string& s,
_Out_ sai_object_id_t &switch_id,
_Out_ sai_switch_asic_sdk_health_severity_t &severity,
_Out_ sai_timespec_t &timestamp,
_Out_ sai_switch_asic_sdk_health_category_t &category,
_Out_ sai_switch_health_data_t &data,
_Out_ sai_u8_list_t &description)
{
SWSS_LOG_ENTER();

json j;
try
{
j = json::parse(s);
}
catch (const std::exception&)
{
SWSS_LOG_THROW("Received an exception after trying to parse switch_asic_sdk_health_event from %s", s.c_str());
}

sai_deserialize_object_id(j["switch_id"], switch_id);
sai_deserialize_enum(j["severity"], &sai_metadata_enum_sai_switch_asic_sdk_health_severity_t, (int32_t&)severity);
sai_deserialize_timespec(j["timestamp"], timestamp);
sai_deserialize_enum(j["category"], &sai_metadata_enum_sai_switch_asic_sdk_health_category_t, (int32_t&)category);
int32_t data_type;
sai_deserialize_enum(j["data.data_type"], &sai_metadata_enum_sai_health_data_type_t, data_type);
data.data_type = (sai_health_data_type_t)data_type;
data.data_type = SAI_HEALTH_DATA_TYPE_GENERAL;
sai_deserialize_number_list(j["description"], description, false, false);
}

void sai_deserialize_free_switch_asic_sdk_health_event(
_In_ sai_u8_list_t &description)
{
SWSS_LOG_ENTER();

sai_free_list(description);
}

void sai_deserialize_switch_shutdown_request(
_In_ const std::string& s,
_Out_ sai_object_id_t &switch_id)
Expand Down
Loading

0 comments on commit 8a0cc25

Please sign in to comment.