diff --git a/lib/Switch.cpp b/lib/Switch.cpp index f16d6934d710..0f909f13e952 100644 --- a/lib/Switch.cpp +++ b/lib/Switch.cpp @@ -108,6 +108,11 @@ void Switch::updateNotifications( (sai_queue_pfc_deadlock_notification_fn)attr.value.ptr; break; + case SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY: + m_switchNotifications.on_bfd_session_state_change = + (sai_bfd_session_state_change_notification_fn)attr.value.ptr; + break; + default: SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); break; diff --git a/meta/Makefile.am b/meta/Makefile.am index 58039c758ad5..fa3e2a86c2bc 100644 --- a/meta/Makefile.am +++ b/meta/Makefile.am @@ -33,6 +33,7 @@ libsaimeta_la_SOURCES = \ NotificationQueuePfcDeadlock.cpp \ NotificationSwitchShutdownRequest.cpp \ NotificationSwitchStateChange.cpp \ + NotificationBfdSessionStateChange.cpp \ OidRefCounter.cpp \ PerformanceIntervalTimer.cpp \ PortRelatedSet.cpp \ diff --git a/meta/Meta.cpp b/meta/Meta.cpp index 79509a34c690..5e9d3263c0d4 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -7745,6 +7745,65 @@ void Meta::meta_sai_on_queue_pfc_deadlock_notification( } } +void Meta::meta_sai_on_bfd_session_state_change_single( + _In_ const sai_bfd_session_state_notification_t& data) +{ + SWSS_LOG_ENTER(); + + auto ot = objectTypeQuery(data.bfd_session_id); + + bool valid = false; + + switch (ot) + { + // TODO hardcoded types, must advance SAI repository commit to get metadata for this + case SAI_OBJECT_TYPE_BFD_SESSION: + + valid = true; + break; + + default: + + SWSS_LOG_ERROR("data.bfd_session_id %s has unexpected type: %s, expected BFD_SESSION", + sai_serialize_object_id(data.bfd_session_id).c_str(), + sai_serialize_object_type(ot).c_str()); + break; + } + + if (valid && !m_oids.objectReferenceExists(data.bfd_session_id)) + { + SWSS_LOG_NOTICE("data.bfd_session_id new object spotted %s not present in local DB (snoop!)", + sai_serialize_object_id(data.bfd_session_id).c_str()); + + sai_object_meta_key_t key = { .objecttype = ot, .objectkey = { .key = { .object_id = data.bfd_session_id } } }; + + m_oids.objectReferenceInsert(data.bfd_session_id); + + if (!m_saiObjectCollection.objectExists(key)) + { + m_saiObjectCollection.createObject(key); + } + } +} + +void Meta::meta_sai_on_bfd_session_state_change( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + if (count && data == NULL) + { + SWSS_LOG_ERROR("sai_bfd_session_state_notification_t pointer is NULL but count is %u", count); + return; + } + + for (uint32_t i = 0; i < count; ++i) + { + meta_sai_on_bfd_session_state_change_single(data[i]); + } +} + int32_t Meta::getObjectReferenceCount( _In_ sai_object_id_t oid) const { diff --git a/meta/Meta.h b/meta/Meta.h index 521c73575958..e498d2a5d360 100644 --- a/meta/Meta.h +++ b/meta/Meta.h @@ -184,6 +184,10 @@ namespace saimeta _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t *data); + void meta_sai_on_bfd_session_state_change( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data); + private: // notifications helpers void meta_sai_on_fdb_flush_event_consolidated( @@ -201,6 +205,9 @@ namespace saimeta void meta_sai_on_queue_pfc_deadlock_notification_single( _In_ const sai_queue_deadlock_notification_data_t& data); + void meta_sai_on_bfd_session_state_change_single( + _In_ const sai_bfd_session_state_notification_t& data); + private: // validation helpers sai_status_t meta_generic_validation_objlist( diff --git a/meta/NotificationBfdSessionStateChange.cpp b/meta/NotificationBfdSessionStateChange.cpp new file mode 100644 index 000000000000..d332c3a9f4ed --- /dev/null +++ b/meta/NotificationBfdSessionStateChange.cpp @@ -0,0 +1,77 @@ +#include "NotificationBfdSessionStateChange.h" + +#include "swss/logger.h" + +#include "meta/sai_serialize.h" + +using namespace sairedis; + +NotificationBfdSessionStateChange::NotificationBfdSessionStateChange( + _In_ const std::string& serializedNotification): + Notification( + SAI_SWITCH_NOTIFICATION_TYPE_BFD_SESSION_STATE_CHANGE, + serializedNotification), + m_bfdSessionStateNotificationData(nullptr) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_bfd_session_state_ntf( + serializedNotification, + m_count, + &m_bfdSessionStateNotificationData); +} + +NotificationBfdSessionStateChange::~NotificationBfdSessionStateChange() +{ + SWSS_LOG_ENTER(); + + sai_deserialize_free_bfd_session_state_ntf(m_count, m_bfdSessionStateNotificationData); +} + +sai_object_id_t NotificationBfdSessionStateChange::getSwitchId() const +{ + SWSS_LOG_ENTER(); + + // this notification don't contain switch id field + + return SAI_NULL_OBJECT_ID; +} + +sai_object_id_t NotificationBfdSessionStateChange::getAnyObjectId() const +{ + SWSS_LOG_ENTER(); + + if (m_bfdSessionStateNotificationData == nullptr) + { + return SAI_NULL_OBJECT_ID; + } + + for (uint32_t idx = 0; idx < m_count; idx++) + { + if (m_bfdSessionStateNotificationData[idx].bfd_session_id != SAI_NULL_OBJECT_ID) + { + return m_bfdSessionStateNotificationData[idx].bfd_session_id; + } + } + + return SAI_NULL_OBJECT_ID; +} + +void NotificationBfdSessionStateChange::processMetadata( + _In_ std::shared_ptr meta) const +{ + SWSS_LOG_ENTER(); + + meta->meta_sai_on_bfd_session_state_change(m_count, m_bfdSessionStateNotificationData); +} + +void NotificationBfdSessionStateChange::executeCallback( + _In_ const sai_switch_notifications_t& switchNotifications) const +{ + SWSS_LOG_ENTER(); + + if (switchNotifications.on_bfd_session_state_change) + { + switchNotifications.on_bfd_session_state_change(m_count, m_bfdSessionStateNotificationData); + } +} diff --git a/meta/NotificationBfdSessionStateChange.h b/meta/NotificationBfdSessionStateChange.h new file mode 100644 index 000000000000..9ebd0551e02e --- /dev/null +++ b/meta/NotificationBfdSessionStateChange.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Notification.h" + +namespace sairedis +{ + class NotificationBfdSessionStateChange: + public Notification + { + public: + + NotificationBfdSessionStateChange( + _In_ const std::string& serializedNotification); + + virtual ~NotificationBfdSessionStateChange(); + + public: + + virtual sai_object_id_t getSwitchId() const override; + + virtual sai_object_id_t getAnyObjectId() const override; + + virtual void processMetadata( + _In_ std::shared_ptr meta) const override; + + virtual void executeCallback( + _In_ const sai_switch_notifications_t& switchNotifications) const override; + + private: + + uint32_t m_count; + + sai_bfd_session_state_notification_t *m_bfdSessionStateNotificationData; + }; +} diff --git a/meta/NotificationFactory.cpp b/meta/NotificationFactory.cpp index 4ed49300e644..d5a0b81abb66 100644 --- a/meta/NotificationFactory.cpp +++ b/meta/NotificationFactory.cpp @@ -4,6 +4,7 @@ #include "NotificationQueuePfcDeadlock.h" #include "NotificationSwitchShutdownRequest.h" #include "NotificationSwitchStateChange.h" +#include "NotificationBfdSessionStateChange.h" #include "sairediscommon.h" #include "swss/logger.h" @@ -31,6 +32,9 @@ std::shared_ptr NotificationFactory::deserialize( if (name == SAI_SWITCH_NOTIFICATION_NAME_SWITCH_STATE_CHANGE) return std::make_shared(serializedNotification); + if (name == SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE) + return std::make_shared(serializedNotification); + SWSS_LOG_ERROR("unknown notification: '%s', FIXME", name.c_str()); return nullptr; diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 6f67a92bc16b..aab641c78be6 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -1756,6 +1756,14 @@ static json sai_serialize_json_fdb_event_notification_data( return j; } +std::string sai_serialize_bfd_session_state( + _In_ sai_bfd_session_state_t status) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(status, &sai_metadata_enum_sai_bfd_session_state_t); +} + std::string sai_serialize_fdb_event_ntf( _In_ uint32_t count, _In_ const sai_fdb_event_notification_data_t* fdb_event) @@ -1834,6 +1842,33 @@ std::string sai_serialize_queue_deadlock_ntf( return j.dump(); } +std::string sai_serialize_bfd_session_state_ntf( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t* bfd_session_state) +{ + SWSS_LOG_ENTER(); + + if (bfd_session_state == NULL) + { + SWSS_LOG_THROW("bfd_session_state pointer is null"); + } + + json j = json::array(); + + for (uint32_t i = 0; i < count; ++i) + { + json item; + + item["bfd_session_id"] = sai_serialize_object_id(bfd_session_state[i].bfd_session_id); + item["session_state"] = sai_serialize_bfd_session_state(bfd_session_state[i].session_state); + + j.push_back(item); + } + + // we don't need count since it can be deduced + return j.dump(); +} + json sai_serialize_nat_entry_key( _In_ const sai_nat_entry_key_t& nat_entry_key) { @@ -3062,6 +3097,15 @@ void sai_deserialize_fdb_event( sai_deserialize_enum(s, &sai_metadata_enum_sai_fdb_event_t, (int32_t&)event); } +void sai_deserialize_bfd_session_state( + _In_ const std::string& s, + _Out_ sai_bfd_session_state_t& state) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_enum(s, &sai_metadata_enum_sai_bfd_session_state_t, (int32_t&)state); +} + void sai_deserialize_switch_oper_status( _In_ const std::string& s, _Out_ sai_object_id_t &switch_id, @@ -3483,6 +3527,28 @@ void sai_deserialize_queue_deadlock_ntf( *deadlock_data = data; } +void sai_deserialize_bfd_session_state_ntf( + _In_ const std::string& s, + _Out_ uint32_t &count, + _Out_ sai_bfd_session_state_notification_t** bfd_session_state) +{ + SWSS_LOG_ENTER(); + + json j = json::parse(s); + + count = (uint32_t)j.size(); + + auto data = new sai_bfd_session_state_notification_t[count]; + + for (uint32_t i = 0; i < count; ++i) + { + sai_deserialize_object_id(j[i]["bfd_session_id"], data[i].bfd_session_id); + sai_deserialize_bfd_session_state(j[i]["session_state"], data[i].session_state); + } + + *bfd_session_state = data; +} + // deserialize free void sai_deserialize_free_attribute_value( @@ -3684,6 +3750,15 @@ void sai_deserialize_free_queue_deadlock_ntf( delete[] queue_deadlock; } +void sai_deserialize_free_bfd_session_state_ntf( + _In_ uint32_t count, + _In_ sai_bfd_session_state_notification_t* bfd_session_state) +{ + SWSS_LOG_ENTER(); + + delete[] bfd_session_state; +} + void sai_deserialize_ingress_priority_group_attr( _In_ const std::string& s, _Out_ sai_ingress_priority_group_attr_t& attr) diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index 1ba81ef92769..969b85843d5a 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -205,6 +205,10 @@ std::string sai_serialize_queue_deadlock_ntf( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t* deadlock_data); +std::string sai_serialize_bfd_session_state_ntf( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t* bfd_session_state); + // sairedis std::string sai_serialize( @@ -341,6 +345,11 @@ void sai_deserialize_queue_deadlock_ntf( _Out_ uint32_t &count, _Out_ sai_queue_deadlock_notification_data_t** deadlock_data); +void sai_deserialize_bfd_session_state_ntf( + _In_ const std::string& s, + _Out_ uint32_t &count, + _Out_ sai_bfd_session_state_notification_t** bfdsession); + // free methods void sai_deserialize_free_attribute_value( @@ -361,6 +370,10 @@ void sai_deserialize_free_queue_deadlock_ntf( _In_ uint32_t count, _In_ sai_queue_deadlock_notification_data_t* deadlock_data); +void sai_deserialize_free_bfd_session_state_ntf( + _In_ uint32_t count, + _In_ sai_bfd_session_state_notification_t* bfdsessionstate); + void sai_deserialize_ingress_priority_group_attr( _In_ const std::string& s, _Out_ sai_ingress_priority_group_attr_t& attr); diff --git a/pyext/pysairedis.cpp b/pyext/pysairedis.cpp index 98a1894fb405..582ed19e3e45 100644 --- a/pyext/pysairedis.cpp +++ b/pyext/pysairedis.cpp @@ -103,6 +103,7 @@ static PyObject * py_port_state_change_notification = NULL; static PyObject * py_queue_pfc_deadlock_notification = NULL; static PyObject * py_switch_shutdown_request_notification = NULL; static PyObject * py_switch_state_change_notification = NULL; +static PyObject * py_bfd_session_state_change_notification = NULL; void call_python(PyObject* callObject, PyObject* arglist) { @@ -190,6 +191,21 @@ static void sai_switch_state_change_notification( Py_DECREF(arglist); } +static void sai_bfd_session_state_change_notification( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data) +{ + PyObject* obj = py_convert_sai_bfd_session_state_notification_t_to_PyObject(data); + + PyObject* arglist = Py_BuildValue("(iO)", count, obj); + + call_python(py_bfd_session_state_change_notification, arglist); + + Py_DECREF(obj); + + Py_DECREF(arglist); +} + sai_pointer_t sai_get_notification_pointer( sai_attr_id_t id, PyObject*callback) @@ -228,6 +244,11 @@ sai_pointer_t sai_get_notification_pointer( py_queue_pfc_deadlock_notification = callback; return (void*)&sai_queue_pfc_deadlock_notification; + case SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY: + Py_XDECREF(py_bfd_session_state_change_notification); + py_bfd_session_state_change_notification = callback; + return (void*)&sai_bfd_session_state_change_notification; + default: Py_XDECREF(callback); break; diff --git a/saiplayer/SaiPlayer.cpp b/saiplayer/SaiPlayer.cpp index d469b9b71d06..f9cb6dc0f92d 100644 --- a/saiplayer/SaiPlayer.cpp +++ b/saiplayer/SaiPlayer.cpp @@ -89,6 +89,7 @@ SaiPlayer::SaiPlayer( m_sn.onQueuePfcDeadlock = std::bind(&SaiPlayer::onQueuePfcDeadlock, this, _1, _2); m_sn.onSwitchShutdownRequest = std::bind(&SaiPlayer::onSwitchShutdownRequest, this, _1); m_sn.onSwitchStateChange = std::bind(&SaiPlayer::onSwitchStateChange, this, _1, _2); + m_sn.onBfdSessionStateChange = std::bind(&SaiPlayer::onBfdSessionStateChange, this, _1, _2); m_switchNotifications= m_sn.getSwitchNotifications(); } @@ -165,6 +166,15 @@ void SaiPlayer::onPortStateChange( // empty } +void SaiPlayer::onBfdSessionStateChange( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + // empty +} + void SaiPlayer::onQueuePfcDeadlock( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t *data) @@ -721,6 +731,10 @@ void SaiPlayer::update_notifications_pointers( attr.value.ptr = (void*)m_switchNotifications.on_queue_pfc_deadlock; break; + case SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY: + attr.value.ptr = (void*)m_switchNotifications.on_bfd_session_state_change; + break; + default: SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); break; diff --git a/saiplayer/SaiPlayer.h b/saiplayer/SaiPlayer.h index 2c77d655806e..efd1f03ba690 100644 --- a/saiplayer/SaiPlayer.h +++ b/saiplayer/SaiPlayer.h @@ -194,6 +194,10 @@ namespace saiplayer _In_ sai_object_id_t switch_id, _In_ sai_switch_oper_status_t switch_oper_status); + void onBfdSessionStateChange( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data); + private: std::shared_ptr m_sai; diff --git a/syncd/NotificationHandler.cpp b/syncd/NotificationHandler.cpp index 388606607924..2e897a1fbde4 100644 --- a/syncd/NotificationHandler.cpp +++ b/syncd/NotificationHandler.cpp @@ -108,6 +108,10 @@ void NotificationHandler::updateNotificationsPointers( attr.value.ptr = (void*)m_switchNotifications.on_queue_pfc_deadlock; break; + case SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY: + attr.value.ptr = (void*)m_switchNotifications.on_bfd_session_state_change; + break; + default: SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); @@ -177,6 +181,17 @@ void NotificationHandler::onSwitchStateChange( enqueueNotification(SAI_SWITCH_NOTIFICATION_NAME_SWITCH_STATE_CHANGE, s); } +void NotificationHandler::onBfdSessionStateChange( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + std::string s = sai_serialize_bfd_session_state_ntf(count, data); + + enqueueNotification(SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE, s); +} + void NotificationHandler::enqueueNotification( _In_ const std::string& op, _In_ const std::string& data, diff --git a/syncd/NotificationHandler.h b/syncd/NotificationHandler.h index f5288a113115..4c3e7a934b95 100644 --- a/syncd/NotificationHandler.h +++ b/syncd/NotificationHandler.h @@ -56,6 +56,10 @@ namespace syncd _In_ sai_object_id_t switch_id, _In_ sai_switch_oper_status_t switch_oper_status); + void onBfdSessionStateChange( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data); + private: void enqueueNotification( diff --git a/syncd/NotificationProcessor.cpp b/syncd/NotificationProcessor.cpp index 1ee3e9e937e9..3392d3ddc409 100644 --- a/syncd/NotificationProcessor.cpp +++ b/syncd/NotificationProcessor.cpp @@ -420,6 +420,35 @@ void NotificationProcessor::process_on_port_state_change( sendNotification(SAI_SWITCH_NOTIFICATION_NAME_PORT_STATE_CHANGE, s); } +void NotificationProcessor::process_on_bfd_session_state_change( + _In_ uint32_t count, + _In_ sai_bfd_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_DEBUG("bfd sessuin state notification count: %u", count); + + for (uint32_t i = 0; i < count; i++) + { + sai_bfd_session_state_notification_t *bfd_session_state = &data[i]; + + /* + * We are using switch_rid as null, since BFD should be already + * defined inside local db after creation. + * + * If this will be faster than return from create BFD then we can use + * query switch id and extract rid of switch id and then convert it to + * switch vid. + */ + + bfd_session_state->bfd_session_id = m_translator->translateRidToVid(bfd_session_state->bfd_session_id, SAI_NULL_OBJECT_ID); + } + + std::string s = sai_serialize_bfd_session_state_ntf(count, data); + + sendNotification(SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE, s); +} + void NotificationProcessor::process_on_switch_shutdown_request( _In_ sai_object_id_t switch_rid) { @@ -495,6 +524,21 @@ void NotificationProcessor::handle_port_state_change( sai_deserialize_free_port_oper_status_ntf(count, portoperstatus); } +void NotificationProcessor::handle_bfd_session_state_change( + _In_ const std::string &data) +{ + SWSS_LOG_ENTER(); + + uint32_t count; + sai_bfd_session_state_notification_t *bfdsessionstate = NULL; + + sai_deserialize_bfd_session_state_ntf(data, count, &bfdsessionstate); + + process_on_bfd_session_state_change(count, bfdsessionstate); + + sai_deserialize_free_bfd_session_state_ntf(count, bfdsessionstate); +} + void NotificationProcessor::handle_switch_shutdown_request( _In_ const std::string &data) { @@ -543,6 +587,10 @@ void NotificationProcessor::syncProcessNotification( { handle_queue_deadlock(data); } + else if (notification == SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE) + { + handle_bfd_session_state_change(data); + } else { SWSS_LOG_ERROR("unknown notification: %s", notification.c_str()); diff --git a/syncd/NotificationProcessor.h b/syncd/NotificationProcessor.h index 13f2eda01cfc..d378fe612324 100644 --- a/syncd/NotificationProcessor.h +++ b/syncd/NotificationProcessor.h @@ -81,6 +81,10 @@ namespace syncd _In_ uint32_t count, _In_ sai_port_oper_status_notification_t *data); + void process_on_bfd_session_state_change( + _In_ uint32_t count, + _In_ sai_bfd_session_state_notification_t *data); + void process_on_switch_shutdown_request( _In_ sai_object_id_t switch_rid); @@ -98,6 +102,9 @@ namespace syncd void handle_port_state_change( _In_ const std::string &data); + void handle_bfd_session_state_change( + _In_ const std::string &data); + void handle_switch_shutdown_request( _In_ const std::string &data); diff --git a/syncd/SwitchNotifications.cpp b/syncd/SwitchNotifications.cpp index 5ba3bea35d98..423265ab2f5d 100644 --- a/syncd/SwitchNotifications.cpp +++ b/syncd/SwitchNotifications.cpp @@ -57,6 +57,16 @@ void SwitchNotifications::SlotBase::onPortStateChange( return m_slots.at(context)->m_handler->onPortStateChange(count, data); } +void SwitchNotifications::SlotBase::onBfdSessionStateChange( + _In_ int context, + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + return m_slots.at(context)->m_handler->onBfdSessionStateChange(count, data); +} + void SwitchNotifications::SlotBase::onQueuePfcDeadlock( _In_ int context, _In_ uint32_t count, diff --git a/syncd/SwitchNotifications.h b/syncd/SwitchNotifications.h index 82cf8e4dfafb..898719aadf69 100644 --- a/syncd/SwitchNotifications.h +++ b/syncd/SwitchNotifications.h @@ -59,6 +59,11 @@ namespace syncd _In_ sai_object_id_t switch_id, _In_ sai_switch_oper_status_t switch_oper_status); + static void onBfdSessionStateChange( + _In_ int context, + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data); + protected: SwitchNotifications* m_handler; @@ -74,7 +79,7 @@ namespace syncd Slot(): SlotBase({ - .on_bfd_session_state_change = nullptr, + .on_bfd_session_state_change = &Slot::onBfdSessionStateChange, .on_fdb_event = &Slot::onFdbEvent, .on_packet_event = nullptr, .on_port_state_change = &Slot::onPortStateChange, @@ -106,6 +111,15 @@ namespace syncd return SlotBase::onPortStateChange(context, count, data); } + static void onBfdSessionStateChange( + _In_ uint32_t count, + _In_ const sai_bfd_session_state_notification_t *data) + { + SWSS_LOG_ENTER(); + + return SlotBase::onBfdSessionStateChange(context, count, data); + } + static void onQueuePfcDeadlock( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t *data) @@ -152,6 +166,7 @@ namespace syncd std::function onQueuePfcDeadlock; std::function onSwitchShutdownRequest; std::function onSwitchStateChange; + std::function onBfdSessionStateChange; private: diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index 3eebdc8d5231..32ce857bdb6a 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -143,6 +143,7 @@ Syncd::Syncd( m_sn.onQueuePfcDeadlock = std::bind(&NotificationHandler::onQueuePfcDeadlock, m_handler.get(), _1, _2); m_sn.onSwitchShutdownRequest = std::bind(&NotificationHandler::onSwitchShutdownRequest, m_handler.get(), _1); m_sn.onSwitchStateChange = std::bind(&NotificationHandler::onSwitchStateChange, m_handler.get(), _1, _2); + m_sn.onBfdSessionStateChange = std::bind(&NotificationHandler::onBfdSessionStateChange, m_handler.get(), _1, _2); m_handler->setSwitchNotifications(m_sn.getSwitchNotifications()); @@ -3892,7 +3893,8 @@ void Syncd::performWarmRestartSingleSwitch( SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY, SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY, SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY, - SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY + SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY, + SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY }; std::vector attrs; diff --git a/tests/aspell.en.pws b/tests/aspell.en.pws index 7b444acecbf3..e99b9a373117 100644 --- a/tests/aspell.en.pws +++ b/tests/aspell.en.pws @@ -12,6 +12,7 @@ ApplyView AsicView AttrHash BCM +BFD Bool CHARDATA COLDVIDS diff --git a/vslib/Switch.cpp b/vslib/Switch.cpp index ea166f8bbd9a..1729083f4c05 100644 --- a/vslib/Switch.cpp +++ b/vslib/Switch.cpp @@ -105,6 +105,11 @@ void Switch::updateNotifications( (sai_queue_pfc_deadlock_notification_fn)attr.value.ptr; break; + case SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY: + m_switchNotifications.on_bfd_session_state_change = + (sai_bfd_session_state_change_notification_fn)attr.value.ptr; + break; + default: SWSS_LOG_THROW("pointer for %s is not handled, FIXME!", meta->attridname); } diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 1493bdaf9928..7ca4bff259a6 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -941,6 +941,10 @@ sai_status_t SwitchStateBase::set_switch_default_attributes() CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); + attr.id = SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY; + + CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); + attr.id = SAI_SWITCH_ATTR_FDB_AGING_TIME; attr.value.u32 = 0;