From 3d3e75457e1dd77b0224496c24c919a4ec47fe92 Mon Sep 17 00:00:00 2001 From: Harjot Singh Date: Thu, 1 May 2025 14:52:08 -0700 Subject: [PATCH] ICMP_ECHO_SESSION meta and notification layer changes --- meta/DummySaiInterface.cpp | 19 +++ meta/Makefile.am | 1 + meta/Meta.cpp | 93 +++++++++++++++ meta/Meta.h | 11 ++ meta/NotificationFactory.cpp | 4 + ...NotificationIcmpEchoSessionStateChange.cpp | 77 ++++++++++++ meta/NotificationIcmpEchoSessionStateChange.h | 35 ++++++ meta/SaiSerialize.cpp | 73 ++++++++++++ meta/sai_serialize.h | 14 +++ proxylib/Proxy.cpp | 11 ++ proxylib/Proxy.h | 4 + pyext/pysairedis.cpp | 21 ++++ pyext/pysairedis.i | 5 + saiplayer/SaiPlayer.cpp | 11 +- saiplayer/SaiPlayer.h | 4 + syncd/NotificationHandler.cpp | 11 ++ syncd/NotificationHandler.h | 4 + syncd/NotificationProcessor.cpp | 48 ++++++++ syncd/NotificationProcessor.h | 7 ++ syncd/SwitchNotifications.cpp | 10 ++ syncd/SwitchNotifications.h | 16 ++- syncd/Syncd.cpp | 1 + unittest/meta/Makefile.am | 1 + unittest/meta/TestDummySaiInterface.cpp | 18 ++- ...NotificationIcmpEchoSessionStateChange.cpp | 111 ++++++++++++++++++ unittest/proxylib/TestProxy.cpp | 18 ++- unittest/proxylib/TestSai.cpp | 20 +++- unittest/syncd/TestNotificationHandler.cpp | 13 ++ unittest/syncd/TestNotificationProcessor.cpp | 11 ++ vslib/SwitchStateBase.cpp | 4 + 30 files changed, 670 insertions(+), 6 deletions(-) create mode 100644 meta/NotificationIcmpEchoSessionStateChange.cpp create mode 100644 meta/NotificationIcmpEchoSessionStateChange.h create mode 100644 unittest/meta/TestNotificationIcmpEchoSessionStateChange.cpp diff --git a/meta/DummySaiInterface.cpp b/meta/DummySaiInterface.cpp index 59f87e8d92..422e5332ea 100644 --- a/meta/DummySaiInterface.cpp +++ b/meta/DummySaiInterface.cpp @@ -854,6 +854,25 @@ void DummySaiInterface::sendNotification( } break; + case SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY: + + if (sn.on_icmp_echo_session_state_change) + { + SWSS_LOG_NOTICE("sending sn.on_icmp_echo_session_state_change"); + + sai_icmp_echo_session_state_notification_t data; + + data.icmp_echo_session_id = 0x2; + data.session_state = SAI_ICMP_ECHO_SESSION_STATE_DOWN; + + sn.on_icmp_echo_session_state_change(1, &data); + } + else + { + SWSS_LOG_WARN("pointer sn.on_icmp_echo_session_state_change"); + } + break; + case SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY: if (sn.on_twamp_session_event) diff --git a/meta/Makefile.am b/meta/Makefile.am index 5835c6e274..73723bc3cc 100644 --- a/meta/Makefile.am +++ b/meta/Makefile.am @@ -36,6 +36,7 @@ libsaimeta_la_SOURCES = \ NotificationSwitchShutdownRequest.cpp \ NotificationSwitchStateChange.cpp \ NotificationBfdSessionStateChange.cpp \ + NotificationIcmpEchoSessionStateChange.cpp \ NotificationHaSetEvent.cpp \ NotificationHaScopeEvent.cpp \ NotificationTwampSessionEvent.cpp \ diff --git a/meta/Meta.cpp b/meta/Meta.cpp index d95e4e5a61..2889a62953 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -7055,6 +7055,56 @@ void Meta::meta_sai_on_ha_scope_event( } } +void Meta::meta_sai_on_icmp_echo_session_state_change_single( + _In_ const sai_icmp_echo_session_state_notification_t& data) +{ + SWSS_LOG_ENTER(); + + auto ot = objectTypeQuery(data.icmp_echo_session_id); + + bool valid = isIcmpEchoSessionObjectIdValid(ot); + + if(!valid){ + SWSS_LOG_ERROR("data.icmp_echo_session_id %s has unexpected type: %s, expected %s", + sai_serialize_object_id(data.icmp_echo_session_id).c_str(), + sai_serialize_object_type(ot).c_str(), + boost::algorithm::join(getValidIcmpEchoSessionObjectTypes(), ",").c_str()); + } + + if (valid && !m_oids.objectReferenceExists(data.icmp_echo_session_id)) + { + SWSS_LOG_NOTICE("data.icmp_echo_session_id new object spotted %s not present in local DB (snoop!)", + sai_serialize_object_id(data.icmp_echo_session_id).c_str()); + + sai_object_meta_key_t key = { .objecttype = ot, .objectkey = { .key = { .object_id = data.icmp_echo_session_id } } }; + + m_oids.objectReferenceInsert(data.icmp_echo_session_id); + + if (!m_saiObjectCollection.objectExists(key)) + { + m_saiObjectCollection.createObject(key); + } + } +} + +void Meta::meta_sai_on_icmp_echo_session_state_change( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + if (count && data == NULL) + { + SWSS_LOG_ERROR("sai_icmp_echo_session_state_notification_t pointer is NULL but count is %u", count); + return; + } + + for (uint32_t i = 0; i < count; ++i) + { + meta_sai_on_icmp_echo_session_state_change_single(data[i]); + } +} + void Meta::meta_sai_on_twamp_session_event_single( _In_ const sai_twamp_session_event_notification_data_t& data) { @@ -7389,3 +7439,46 @@ std::vector Meta::getValidPortObjectTypes() return v; } + +bool Meta::isIcmpEchoSessionObjectIdValid( + _In_ sai_object_type_t object_type) +{ + SWSS_LOG_ENTER(); + + auto members = sai_metadata_struct_members_sai_icmp_echo_session_state_notification_t; + + for (size_t i = 0; members[i]; i++) + { + auto* mb = members[i]; + + if (mb->membername != std::string("icmp_echo_session_id")) + continue; + + for (size_t idx = 0; idx < mb->allowedobjecttypeslength; idx++) + { + if (mb->allowedobjecttypes[idx] == object_type) + return true; + } + + return false; + } + + SWSS_LOG_THROW("member not found for sai_icmp_echo_session_state_notification_t"); +} + +std::vector Meta::getValidIcmpEchoSessionObjectTypes() +{ + SWSS_LOG_ENTER(); + + auto md = sai_metadata_enum_sai_object_type_t; + + std::vector v; + + for (size_t i = 0; i < md.valuescount; i++) + { + if (isIcmpEchoSessionObjectIdValid((sai_object_type_t)md.values[i])) + v.push_back(md.valuesshortnames[i]); + } + + return v; +} diff --git a/meta/Meta.h b/meta/Meta.h index f30aaddfcb..f18315a534 100644 --- a/meta/Meta.h +++ b/meta/Meta.h @@ -245,6 +245,10 @@ namespace saimeta _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + void meta_sai_on_icmp_echo_session_state_change( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data); + void meta_sai_on_ha_set_event( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data); @@ -287,6 +291,9 @@ namespace saimeta void meta_sai_on_bfd_session_state_change_single( _In_ const sai_bfd_session_state_notification_t& data); + void meta_sai_on_icmp_echo_session_state_change_single( + _In_ const sai_icmp_echo_session_state_notification_t& data); + void meta_sai_on_ha_set_event_single( _In_ const sai_ha_set_event_data_t& data); @@ -339,7 +346,11 @@ namespace saimeta static bool isPortObjectIdValid( _In_ sai_object_type_t object_type); + static bool isIcmpEchoSessionObjectIdValid( + _In_ sai_object_type_t object_type); + static std::vector getValidPortObjectTypes(); + static std::vector getValidIcmpEchoSessionObjectTypes(); private: // unit tests helpers diff --git a/meta/NotificationFactory.cpp b/meta/NotificationFactory.cpp index fce0912c5b..df11a91e63 100644 --- a/meta/NotificationFactory.cpp +++ b/meta/NotificationFactory.cpp @@ -7,6 +7,7 @@ #include "NotificationSwitchStateChange.h" #include "NotificationSwitchAsicSdkHealthEvent.h" #include "NotificationBfdSessionStateChange.h" +#include "NotificationIcmpEchoSessionStateChange.h" #include "NotificationTwampSessionEvent.h" #include "NotificationPortHostTxReadyEvent.h" #include "NotificationTamTelTypeConfigChange.h" @@ -51,6 +52,9 @@ std::shared_ptr NotificationFactory::deserialize( if (name == SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE) return std::make_shared(serializedNotification); + if (name == SAI_SWITCH_NOTIFICATION_NAME_ICMP_ECHO_SESSION_STATE_CHANGE) + return std::make_shared(serializedNotification); + if (name == SAI_SWITCH_NOTIFICATION_NAME_HA_SET_EVENT) return std::make_shared(serializedNotification); diff --git a/meta/NotificationIcmpEchoSessionStateChange.cpp b/meta/NotificationIcmpEchoSessionStateChange.cpp new file mode 100644 index 0000000000..6486b5bcc0 --- /dev/null +++ b/meta/NotificationIcmpEchoSessionStateChange.cpp @@ -0,0 +1,77 @@ +#include "NotificationIcmpEchoSessionStateChange.h" + +#include "swss/logger.h" + +#include "meta/sai_serialize.h" + +using namespace sairedis; + +NotificationIcmpEchoSessionStateChange::NotificationIcmpEchoSessionStateChange( + _In_ const std::string& serializedNotification): + Notification( + SAI_SWITCH_NOTIFICATION_TYPE_ICMP_ECHO_SESSION_STATE_CHANGE, + serializedNotification), + m_icmpEchoSessionStateNotificationData(nullptr) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_icmp_echo_session_state_ntf( + serializedNotification, + m_count, + &m_icmpEchoSessionStateNotificationData); +} + +NotificationIcmpEchoSessionStateChange::~NotificationIcmpEchoSessionStateChange() +{ + SWSS_LOG_ENTER(); + + sai_deserialize_free_icmp_echo_session_state_ntf(m_count, m_icmpEchoSessionStateNotificationData); +} + +sai_object_id_t NotificationIcmpEchoSessionStateChange::getSwitchId() const +{ + SWSS_LOG_ENTER(); + + // this notification don't contain switch id field + + return SAI_NULL_OBJECT_ID; +} + +sai_object_id_t NotificationIcmpEchoSessionStateChange::getAnyObjectId() const +{ + SWSS_LOG_ENTER(); + + if (m_icmpEchoSessionStateNotificationData == nullptr) + { + return SAI_NULL_OBJECT_ID; + } + + for (uint32_t idx = 0; idx < m_count; idx++) + { + if (m_icmpEchoSessionStateNotificationData[idx].icmp_echo_session_id != SAI_NULL_OBJECT_ID) + { + return m_icmpEchoSessionStateNotificationData[idx].icmp_echo_session_id; + } + } + + return SAI_NULL_OBJECT_ID; +} + +void NotificationIcmpEchoSessionStateChange::processMetadata( + _In_ std::shared_ptr meta) const +{ + SWSS_LOG_ENTER(); + + meta->meta_sai_on_icmp_echo_session_state_change(m_count, m_icmpEchoSessionStateNotificationData); +} + +void NotificationIcmpEchoSessionStateChange::executeCallback( + _In_ const sai_switch_notifications_t& switchNotifications) const +{ + SWSS_LOG_ENTER(); + + if (switchNotifications.on_icmp_echo_session_state_change) + { + switchNotifications.on_icmp_echo_session_state_change(m_count, m_icmpEchoSessionStateNotificationData); + } +} diff --git a/meta/NotificationIcmpEchoSessionStateChange.h b/meta/NotificationIcmpEchoSessionStateChange.h new file mode 100644 index 0000000000..5583aa47e6 --- /dev/null +++ b/meta/NotificationIcmpEchoSessionStateChange.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Notification.h" + +namespace sairedis +{ + class NotificationIcmpEchoSessionStateChange: + public Notification + { + public: + + NotificationIcmpEchoSessionStateChange( + _In_ const std::string& serializedNotification); + + virtual ~NotificationIcmpEchoSessionStateChange(); + + 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_icmp_echo_session_state_notification_t *m_icmpEchoSessionStateNotificationData; + }; +} diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index b4ccd8c9e5..af66b9b84d 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -2342,6 +2342,14 @@ std::string sai_serialize_bfd_session_state( return sai_serialize_enum(status, &sai_metadata_enum_sai_bfd_session_state_t); } +std::string sai_serialize_icmp_echo_session_state( + _In_ sai_icmp_echo_session_state_t status) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(status, &sai_metadata_enum_sai_icmp_echo_session_state_t); +} + std::string sai_serialize_ha_set_event( _In_ sai_ha_set_event_t event) { @@ -2569,6 +2577,31 @@ std::string sai_serialize_bfd_session_state_ntf( return j.dump(); } +std::string sai_serialize_icmp_echo_session_state_ntf( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t* icmp_echo_session_state) +{ + SWSS_LOG_ENTER(); + + if (icmp_echo_session_state == NULL) + { + SWSS_LOG_THROW("icmp_echo_session _state pointer is null"); + } + + json j = json::array(); + + for (uint32_t i = 0; i < count; ++i) + { + json item; + item["icmp_echo_session_id"] = sai_serialize_object_id(icmp_echo_session_state[i].icmp_echo_session_id); + item["session_state"] = sai_serialize_icmp_echo_session_state(icmp_echo_session_state[i].session_state); + + j.push_back(item); + } + + return j.dump(); +} + std::string sai_serialize_ha_set_event_ntf( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t* ha_set_event) @@ -4499,6 +4532,15 @@ void sai_deserialize_bfd_session_state( sai_deserialize_enum(s, &sai_metadata_enum_sai_bfd_session_state_t, (int32_t&)state); } +void sai_deserialize_icmp_echo_session_state( + _In_ const std::string& s, + _Out_ sai_icmp_echo_session_state_t& state) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_enum(s, &sai_metadata_enum_sai_icmp_echo_session_state_t, (int32_t&)state); +} + void sai_deserialize_ha_set_event( _In_ const std::string& s, _Out_ sai_ha_set_event_t& event) @@ -5431,6 +5473,28 @@ void sai_deserialize_bfd_session_state_ntf( *bfd_session_state = data; } +void sai_deserialize_icmp_echo_session_state_ntf( + _In_ const std::string& s, + _Out_ uint32_t &count, + _Out_ sai_icmp_echo_session_state_notification_t** icmp_echo_session_state) +{ + SWSS_LOG_ENTER(); + + json j = json::parse(s); + + count = (uint32_t)j.size(); + + auto data = new sai_icmp_echo_session_state_notification_t[count]; + + for (uint32_t i = 0; i < count; ++i) + { + sai_deserialize_object_id(j[i]["icmp_echo_session_id"], data[i].icmp_echo_session_id); + sai_deserialize_icmp_echo_session_state(j[i]["session_state"], data[i].session_state); + } + + *icmp_echo_session_state = data; +} + void sai_deserialize_ha_set_event_ntf( _In_ const std::string& s, _Out_ uint32_t &count, @@ -5811,6 +5875,15 @@ void sai_deserialize_free_bfd_session_state_ntf( delete[] bfd_session_state; } +void sai_deserialize_free_icmp_echo_session_state_ntf( + _In_ uint32_t count, + _In_ sai_icmp_echo_session_state_notification_t* icmp_echo_session_state) +{ + SWSS_LOG_ENTER(); + + delete[] icmp_echo_session_state; +} + void sai_deserialize_free_ha_set_event_ntf( _In_ uint32_t count, _In_ sai_ha_set_event_data_t* ha_set_event) diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index f961f56d6d..7f259d7e12 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -329,6 +329,10 @@ std::string sai_serialize_bfd_session_state_ntf( _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t* bfd_session_state); +std::string sai_serialize_icmp_echo_session_state_ntf( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t* icmp_echo_session_state); + std::string sai_serialize_ha_set_event_ntf( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t* ha_set_event); @@ -584,6 +588,12 @@ void sai_deserialize_bfd_session_state_ntf( _Out_ uint32_t &count, _Out_ sai_bfd_session_state_notification_t** bfdsession); + +void sai_deserialize_icmp_echo_session_state_ntf( + _In_ const std::string& s, + _Out_ uint32_t &count, + _Out_ sai_icmp_echo_session_state_notification_t** icmp_echo_session); + void sai_deserialize_ha_set_event_ntf( _In_ const std::string& s, _Out_ uint32_t &count, @@ -634,6 +644,10 @@ void sai_deserialize_free_bfd_session_state_ntf( _In_ uint32_t count, _In_ sai_bfd_session_state_notification_t* bfdsessionstate); +void sai_deserialize_free_icmp_echo_session_state_ntf( + _In_ uint32_t count, + _In_ sai_icmp_echo_session_state_notification_t* icmp_echo_session_state); + void sai_deserialize_free_ha_set_event_ntf( _In_ uint32_t count, _In_ sai_ha_set_event_data_t* ha_set_event); diff --git a/proxylib/Proxy.cpp b/proxylib/Proxy.cpp index 32052d84c8..d800c738f9 100644 --- a/proxylib/Proxy.cpp +++ b/proxylib/Proxy.cpp @@ -63,6 +63,7 @@ Proxy::Proxy( m_swNtf.onSwitchShutdownRequest = std::bind(&Proxy::onSwitchShutdownRequest, this, _1); m_swNtf.onSwitchStateChange = std::bind(&Proxy::onSwitchStateChange, this, _1, _2); m_swNtf.onBfdSessionStateChange = std::bind(&Proxy::onBfdSessionStateChange, this, _1, _2); + m_swNtf.onIcmpEchoSessionStateChange = std::bind(&Proxy::onIcmpEchoSessionStateChange, this, _1, _2); m_swNtf.onHaSetEvent = std::bind(&Proxy::onHaSetEvent, this, _1, _2); m_swNtf.onHaScopeEvent = std::bind(&Proxy::onHaScopeEvent, this, _1, _2); m_swNtf.onPortHostTxReady = std::bind(&Proxy::onPortHostTxReady, this, _1, _2, _3); @@ -1206,6 +1207,16 @@ void Proxy::onBfdSessionStateChange( sendNotification(SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE, s); } +void Proxy::onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + std::string s = sai_serialize_icmp_echo_session_state_ntf(count, data); + + sendNotification(SAI_SWITCH_NOTIFICATION_NAME_ICMP_ECHO_SESSION_STATE_CHANGE, s); +} void Proxy::onHaSetEvent( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data) diff --git a/proxylib/Proxy.h b/proxylib/Proxy.h index 86c7e4c72c..b3b9cbd613 100644 --- a/proxylib/Proxy.h +++ b/proxylib/Proxy.h @@ -148,6 +148,10 @@ namespace saiproxy _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data); + void onHaSetEvent( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data); diff --git a/pyext/pysairedis.cpp b/pyext/pysairedis.cpp index 2a0f805961..d09354b5e0 100644 --- a/pyext/pysairedis.cpp +++ b/pyext/pysairedis.cpp @@ -95,6 +95,7 @@ sai_ip_prefix_t* sai_ip_prefix_t_from_string(const std::string& s) PyObject *py_convert_sai_fdb_event_notification_data_t_to_PyObject(const sai_fdb_event_notification_data_t*ntf); PyObject *py_convert_sai_bfd_session_state_notification_t_to_PyObject(const sai_bfd_session_state_notification_t*ntf); +PyObject *py_convert_sai_icmp_echo_session_state_notification_t_to_PyObject(const sai_icmp_echo_session_state_notification_t*ntf); PyObject *py_convert_sai_ha_set_event_data_t_to_PyObject(const sai_ha_set_event_data_t*ntf); PyObject *py_convert_sai_ha_scope_event_data_t_to_PyObject(const sai_ha_scope_event_data_t*ntf); PyObject *py_convert_sai_port_oper_status_notification_t_to_PyObject(const sai_port_oper_status_notification_t*ntf); @@ -106,6 +107,7 @@ 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; +static PyObject * py_icmp_echo_session_state_change_notification = NULL; static PyObject * py_ha_set_event_notification = NULL; static PyObject * py_ha_scope_event_notification = NULL; static PyObject * py_tam_tel_type_config_change_notification = NULL; @@ -211,6 +213,20 @@ static void sai_bfd_session_state_change_notification( Py_DECREF(arglist); } +static void sai_icmp_echo_session_state_change_notification( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + PyObject* obj = py_convert_sai_icmp_echo_session_state_notification_t_to_PyObject(data); + + PyObject* arglist = Py_BuildValue("(iO)", count, obj); + + call_python(py_icmp_echo_session_state_change_notification, arglist); + + Py_DECREF(obj); +} + + static void sai_ha_set_event_notification( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data) @@ -294,6 +310,11 @@ sai_pointer_t sai_get_notification_pointer( py_bfd_session_state_change_notification = callback; return (void*)&sai_bfd_session_state_change_notification; + case SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY: + Py_XDECREF(py_icmp_echo_session_state_change_notification); + py_icmp_echo_session_state_change_notification = callback; + return (void*)&sai_icmp_echo_session_state_change_notification; + case SAI_SWITCH_ATTR_HA_SET_EVENT_NOTIFY: Py_XDECREF(py_ha_set_event_notification); py_ha_set_event_notification = callback; diff --git a/pyext/pysairedis.i b/pyext/pysairedis.i index 694b491d6e..0efa722341 100644 --- a/pyext/pysairedis.i +++ b/pyext/pysairedis.i @@ -69,6 +69,9 @@ sai_ip_prefix_t* sai_ip_prefix_t_from_string(const std::string& s); %array_functions(sai_bfd_session_state_notification_t, sai_bfd_session_state_notification_t_arr); %pointer_functions(sai_bfd_session_state_notification_t, sai_bfd_session_state_notification_t_p); +%array_functions(sai_icmp_echo_session_state_notification_t, sai_icmp_echo_session_state_notification_t_arr); +%pointer_functions(sai_icmp_echo_session_state_notification_t, sai_icmp_echo_session_state_notification_t_p); + %array_functions(sai_ha_set_event_data_t, sai_ha_set_event_data_t_arr); %pointer_functions(sai_ha_set_event_data_t, sai_ha_set_event_data_t_p); %array_functions(sai_ha_scope_event_data_t, sai_ha_scope_event_data_t_arr); @@ -85,6 +88,8 @@ PyObject *py_convert_sai_fdb_event_notification_data_t_to_PyObject(const sai_fdb { return SWIG_NewPointerObj((void*)ntf, SWIGTYPE_p__sai_fdb_event_notification_data_t, 0 | 0); } PyObject *py_convert_sai_bfd_session_state_notification_t_to_PyObject(const sai_bfd_session_state_notification_t*ntf) { return SWIG_NewPointerObj((void*)ntf, SWIGTYPE_p__sai_bfd_session_state_notification_t, 0 | 0); } +PyObject *py_convert_sai_icmp_echo_session_state_notification_t_to_PyObject(const sai_icmp_echo_session_state_notification_t*ntf) +{ return SWIG_NewPointerObj((void*)ntf, SWIGTYPE_p__sai_icmp_echo_session_state_notification_t, 0 | 0); } PyObject *py_convert_sai_ha_set_event_data_t_to_PyObject(const sai_ha_set_event_data_t*ntf) { return SWIG_NewPointerObj((void*)ntf, SWIGTYPE_p__sai_ha_set_event_data_t, 0 | 0); } PyObject *py_convert_sai_ha_scope_event_data_t_to_PyObject(const sai_ha_scope_event_data_t*ntf) diff --git a/saiplayer/SaiPlayer.cpp b/saiplayer/SaiPlayer.cpp index 3e80a27ef2..24b8f2568f 100644 --- a/saiplayer/SaiPlayer.cpp +++ b/saiplayer/SaiPlayer.cpp @@ -94,7 +94,7 @@ SaiPlayer::SaiPlayer( m_sn.onHaSetEvent = std::bind(&SaiPlayer::onHaSetEvent, this, _1, _2); m_sn.onHaScopeEvent = std::bind(&SaiPlayer::onHaScopeEvent, this, _1, _2); m_sn.onPortHostTxReady = std::bind(&SaiPlayer::onPortHostTxReady, this, _1, _2, _3); - + m_sn.onIcmpEchoSessionStateChange = std::bind(&SaiPlayer::onIcmpEchoSessionStateChange, this, _1, _2); m_switchNotifications= m_sn.getSwitchNotifications(); } @@ -179,6 +179,15 @@ void SaiPlayer::onBfdSessionStateChange( // empty } +void SaiPlayer::onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + // empty +} + void SaiPlayer::onHaSetEvent( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data) diff --git a/saiplayer/SaiPlayer.h b/saiplayer/SaiPlayer.h index 45b897a4f3..25790026fc 100644 --- a/saiplayer/SaiPlayer.h +++ b/saiplayer/SaiPlayer.h @@ -249,6 +249,10 @@ namespace saiplayer _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data); + void onHaSetEvent( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data); diff --git a/syncd/NotificationHandler.cpp b/syncd/NotificationHandler.cpp index ab7caddebb..6d138af8e3 100644 --- a/syncd/NotificationHandler.cpp +++ b/syncd/NotificationHandler.cpp @@ -188,6 +188,17 @@ void NotificationHandler::onBfdSessionStateChange( enqueueNotification(SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE, s); } +void NotificationHandler::onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + std::string s = sai_serialize_icmp_echo_session_state_ntf(count, data); + + enqueueNotification(SAI_SWITCH_NOTIFICATION_NAME_ICMP_ECHO_SESSION_STATE_CHANGE, s); +} + void NotificationHandler::onHaSetEvent( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data) diff --git a/syncd/NotificationHandler.h b/syncd/NotificationHandler.h index 3a0d31009f..e251314c73 100644 --- a/syncd/NotificationHandler.h +++ b/syncd/NotificationHandler.h @@ -83,6 +83,10 @@ namespace syncd _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data); + void onTwampSessionEvent( _In_ uint32_t count, _In_ const sai_twamp_session_event_notification_data_t *data); diff --git a/syncd/NotificationProcessor.cpp b/syncd/NotificationProcessor.cpp index 0500bfab01..68d7664a5d 100644 --- a/syncd/NotificationProcessor.cpp +++ b/syncd/NotificationProcessor.cpp @@ -558,6 +558,35 @@ void NotificationProcessor::process_on_bfd_session_state_change( sendNotification(SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE, s); } +void NotificationProcessor::process_on_icmp_echo_session_state_change( + _In_ uint32_t count, + _In_ sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_DEBUG("icmp echo session state notification count: %u", count); + + for (uint32_t i = 0; i < count; i++) + { + sai_icmp_echo_session_state_notification_t *icmp_echo_session_state = &data[i]; + + /* + * We are using switch_rid as null, since ICMP_ECHO should be already + * defined inside local db after creation. + * + * If this will be faster than return from create ICMP_ECHO then we can use + * query switch id and extract rid of switch id and then convert it to + * switch vid. + */ + + icmp_echo_session_state->icmp_echo_session_id = m_translator->translateRidToVid(icmp_echo_session_state->icmp_echo_session_id, SAI_NULL_OBJECT_ID, true); + } + + std::string s = sai_serialize_icmp_echo_session_state_ntf(count, data); + + sendNotification(SAI_SWITCH_NOTIFICATION_NAME_ICMP_ECHO_SESSION_STATE_CHANGE, s); +} + void NotificationProcessor::process_on_ha_set_event( _In_ uint32_t count, _In_ sai_ha_set_event_data_t *data) @@ -746,6 +775,21 @@ void NotificationProcessor::handle_bfd_session_state_change( sai_deserialize_free_bfd_session_state_ntf(count, bfdsessionstate); } +void NotificationProcessor::handle_icmp_echo_session_state_change( + _In_ const std::string &data) +{ + SWSS_LOG_ENTER(); + + uint32_t count; + sai_icmp_echo_session_state_notification_t *icmp_echo_session_state = NULL; + + sai_deserialize_icmp_echo_session_state_ntf(data, count, &icmp_echo_session_state); + + process_on_icmp_echo_session_state_change(count, icmp_echo_session_state); + + sai_deserialize_free_icmp_echo_session_state_ntf(count, icmp_echo_session_state); +} + void NotificationProcessor::handle_ha_set_event( _In_ const std::string &data) { @@ -894,6 +938,10 @@ void NotificationProcessor::syncProcessNotification( { handle_bfd_session_state_change(data); } + else if (notification == SAI_SWITCH_NOTIFICATION_NAME_ICMP_ECHO_SESSION_STATE_CHANGE) + { + handle_icmp_echo_session_state_change(data); + } else if (notification == SAI_SWITCH_NOTIFICATION_NAME_TWAMP_SESSION_EVENT) { handle_twamp_session_event(data); diff --git a/syncd/NotificationProcessor.h b/syncd/NotificationProcessor.h index f48c728298..751442ce57 100644 --- a/syncd/NotificationProcessor.h +++ b/syncd/NotificationProcessor.h @@ -92,6 +92,10 @@ namespace syncd _In_ uint32_t count, _In_ sai_bfd_session_state_notification_t *data); + void process_on_icmp_echo_session_state_change( + _In_ uint32_t count, + _In_ sai_icmp_echo_session_state_notification_t *data); + void process_on_ha_set_event( _In_ uint32_t count, _In_ sai_ha_set_event_data_t *data); @@ -140,6 +144,9 @@ namespace syncd void handle_bfd_session_state_change( _In_ const std::string &data); + void handle_icmp_echo_session_state_change( + _In_ const std::string &data); + void handle_ha_set_event( _In_ const std::string &data); diff --git a/syncd/SwitchNotifications.cpp b/syncd/SwitchNotifications.cpp index bc8d70d96d..99bbdc481f 100644 --- a/syncd/SwitchNotifications.cpp +++ b/syncd/SwitchNotifications.cpp @@ -89,6 +89,16 @@ void SwitchNotifications::SlotBase::onBfdSessionStateChange( return m_slots.at(context)->m_handler->onBfdSessionStateChange(count, data); } +void SwitchNotifications::SlotBase::onIcmpEchoSessionStateChange( + _In_ int context, + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + return m_slots.at(context)->m_handler->onIcmpEchoSessionStateChange(count, data); +} + void SwitchNotifications::SlotBase::onHaSetEvent( _In_ int context, _In_ uint32_t count, diff --git a/syncd/SwitchNotifications.h b/syncd/SwitchNotifications.h index f60d471101..8b9c45e6ca 100644 --- a/syncd/SwitchNotifications.h +++ b/syncd/SwitchNotifications.h @@ -85,6 +85,11 @@ namespace syncd _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + static void onIcmpEchoSessionStateChange( + _In_ int context, + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data); + static void onTwampSessionEvent( _In_ int context, _In_ uint32_t count, @@ -132,7 +137,7 @@ namespace syncd .on_switch_asic_sdk_health_event = &Slot::onSwitchAsicSdkHealthEvent, .on_port_host_tx_ready = &Slot::onPortHostTxReady, .on_twamp_session_event = &Slot::onTwampSessionEvent, - .on_icmp_echo_session_state_change = nullptr, + .on_icmp_echo_session_state_change = &Slot::onIcmpEchoSessionStateChange, .on_extended_port_state_change = nullptr, .on_tam_tel_type_config_change = &Slot::onTamTelTypeConfigChange, .on_ha_set_event = &Slot::onHaSetEvent, @@ -189,6 +194,14 @@ namespace syncd return SlotBase::onBfdSessionStateChange(context, count, data); } + static void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) + { + SWSS_LOG_ENTER(); + + return SlotBase::onIcmpEchoSessionStateChange(context, count, data); + } static void onHaSetEvent( _In_ uint32_t count, _In_ const sai_ha_set_event_data_t *data) @@ -298,6 +311,7 @@ namespace syncd std::function onSwitchShutdownRequest; std::function onSwitchStateChange; std::function onBfdSessionStateChange; + std::function onIcmpEchoSessionStateChange; std::function onTwampSessionEvent; std::function onTamTelTypeConfigChange; std::function onHaSetEvent; diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index bc49ec9d6a..43f7847cbc 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -165,6 +165,7 @@ Syncd::Syncd( 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_sn.onIcmpEchoSessionStateChange = std::bind(&NotificationHandler::onIcmpEchoSessionStateChange, m_handler.get(), _1, _2); m_sn.onPortHostTxReady = std::bind(&NotificationHandler::onPortHostTxReady, m_handler.get(), _1, _2, _3); m_sn.onTwampSessionEvent = std::bind(&NotificationHandler::onTwampSessionEvent, m_handler.get(), _1, _2); m_sn.onTamTelTypeConfigChange = std::bind(&NotificationHandler::onTamTelTypeConfigChange, m_handler.get(), _1); diff --git a/unittest/meta/Makefile.am b/unittest/meta/Makefile.am index cd51bd08ce..f6019e9022 100644 --- a/unittest/meta/Makefile.am +++ b/unittest/meta/Makefile.am @@ -26,6 +26,7 @@ tests_SOURCES = \ TestNotificationSwitchAsicSdkHealthEvent.cpp \ TestNotificationSwitchStateChange.cpp \ TestNotificationBfdSessionStateChange.cpp \ + TestNotificationIcmpEchoSessionStateChange.cpp \ TestNotificationHaScopeEvent.cpp \ TestNotificationHaSetEvent.cpp \ TestNotificationTam.cpp \ diff --git a/unittest/meta/TestDummySaiInterface.cpp b/unittest/meta/TestDummySaiInterface.cpp index 04fbd5b9d3..e5b98d9ac2 100644 --- a/unittest/meta/TestDummySaiInterface.cpp +++ b/unittest/meta/TestDummySaiInterface.cpp @@ -219,6 +219,17 @@ static void onBfdSessionStateChange( ntfCounter++; } +static void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_NOTICE("received: onIcmpEchoSessionStateChange"); + + ntfCounter++; +} + void onTwampSessionEvent( _In_ uint32_t count, _In_ const sai_twamp_session_event_notification_data_t *data) @@ -258,6 +269,7 @@ TEST(DummySaiInterface, sendNotification) EXPECT_EQ(sai.enqueueNotificationToSend(SAI_SWITCH_ATTR_HA_SET_EVENT_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(sai.enqueueNotificationToSend(SAI_SWITCH_ATTR_HA_SCOPE_EVENT_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(sai.enqueueNotificationToSend(SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); + EXPECT_EQ(sai.enqueueNotificationToSend(SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(sai.enqueueNotificationToSend(SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(sai.enqueueNotificationToSend(SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); @@ -316,6 +328,10 @@ TEST(DummySaiInterface, sendNotification) attr.value.ptr = (void*)&onBfdSessionStateChange; sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); + attr.id = SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY; + attr.value.ptr = (void*)&onIcmpEchoSessionStateChange; + sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); + attr.id = SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY; attr.value.ptr = (void*)&onTwampSessionEvent; sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); @@ -330,5 +346,5 @@ TEST(DummySaiInterface, sendNotification) EXPECT_EQ(sai.stop(), SAI_STATUS_SUCCESS); - EXPECT_EQ(ntfCounter, 4 + 6 + 1); + EXPECT_EQ(ntfCounter, 4 + 7 + 1); } diff --git a/unittest/meta/TestNotificationIcmpEchoSessionStateChange.cpp b/unittest/meta/TestNotificationIcmpEchoSessionStateChange.cpp new file mode 100644 index 0000000000..1b22de644a --- /dev/null +++ b/unittest/meta/TestNotificationIcmpEchoSessionStateChange.cpp @@ -0,0 +1,111 @@ +#include "NotificationIcmpEchoSessionStateChange.h" +#include "Meta.h" +#include "MetaTestSaiInterface.h" + +#include "sairediscommon.h" +#include "sai_serialize.h" +#include "VirtualObjectIdManager.h" +#include "NumberOidIndexGenerator.h" +#include + +#include + +using namespace sairedis; +using namespace saimeta; + +std::string s = "[{\"icmp_echo_session_id\":\"oid:0x100000000001a\",\"session_state\":\"SAI_ICMP_ECHO_SESSION_STATE_DOWN\"}]"; +static std::string invalid_id_str = "[{\"icmp_echo_session_id\":\"oid:0x100000000004a\",\"session_state\":\"SAI_ICMP_ECHO_SESSION_STATE_DOWN\"}]"; +static std::string null = "[{\"icmp_echo_session_id\":\"oid:0x0\",\"session_state\":\"SAI_ICMP_ECHO_SESSION_STATE_DOWN\"}]"; +static std::string fullnull = "[]"; +static sai_object_id_t icmp_echo_session_oid; + +sai_object_id_t generateOid() +{ + SWSS_LOG_ENTER(); + auto hw_info = "asic0"; + auto scc = std::make_shared(); + scc->insert(std::make_shared(0, hw_info)); + auto vidManager = VirtualObjectIdManager(0, scc, std::make_shared()); + auto sid = vidManager.allocateNewSwitchObjectId("asic0"); + return vidManager.allocateNewObjectId(SAI_OBJECT_TYPE_ICMP_ECHO_SESSION, sid); +} + +void setUp() +{ + SWSS_LOG_ENTER(); + icmp_echo_session_oid = generateOid(); + auto oidStr = sai_serialize_object_id(icmp_echo_session_oid); + s = "[{\"icmp_echo_session_id\":\"" + oidStr + "\",\"session_state\":\"SAI_ICMP_ECHO_SESSION_STATE_DOWN\"}]"; +} + +TEST(NotificationIcmpEchoSessionStateChange, ctr) +{ + setUp(); + NotificationIcmpEchoSessionStateChange n(s); +} + +TEST(NotificationIcmpEchoSessionStateChange, getSwitchId) +{ + NotificationIcmpEchoSessionStateChange n(s); + + EXPECT_EQ(n.getSwitchId(), 0); + + NotificationIcmpEchoSessionStateChange n2(null); + + EXPECT_EQ(n2.getSwitchId(), 0); +} + +TEST(NotificationIcmpEchoSessionStateChange, getAnyObjectId) +{ + NotificationIcmpEchoSessionStateChange n(s); + + EXPECT_EQ(n.getAnyObjectId(), icmp_echo_session_oid); + + NotificationIcmpEchoSessionStateChange n2(null); + + EXPECT_EQ(n2.getAnyObjectId(), 0); + + NotificationIcmpEchoSessionStateChange n3(fullnull); + + EXPECT_EQ(n3.getSwitchId(), 0); + + EXPECT_EQ(n3.getAnyObjectId(), 0); +} + +TEST(NotificationIcmpEchoSessionStateChange, processMetadata) +{ + NotificationIcmpEchoSessionStateChange n(s); + + auto sai = std::make_shared(); + auto meta = std::make_shared(sai); + + n.processMetadata(meta); +} + +TEST(NotificationIcmpEchoSessionStateChange, processInvlaidMetadata) +{ + NotificationIcmpEchoSessionStateChange n(invalid_id_str); + + auto sai = std::make_shared(); + auto meta = std::make_shared(sai); + + n.processMetadata(meta); +} + +static void on_icmp_echo_session_state_change( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); +} + +TEST(NotificationIcmpEchoSessionStateChange, executeCallback) +{ + NotificationIcmpEchoSessionStateChange n(s); + + sai_switch_notifications_t ntfs; + + ntfs.on_icmp_echo_session_state_change = &on_icmp_echo_session_state_change; + + n.executeCallback(ntfs); +} diff --git a/unittest/proxylib/TestProxy.cpp b/unittest/proxylib/TestProxy.cpp index 3da5310364..97f662a17f 100644 --- a/unittest/proxylib/TestProxy.cpp +++ b/unittest/proxylib/TestProxy.cpp @@ -185,6 +185,17 @@ static void onBfdSessionStateChange( ntfCounter++; } +static void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_NOTICE("received: onIcmpEchoSessionStateChange"); + + ntfCounter++; +} + static void onTwampSessionEvent( _In_ uint32_t count, _In_ const sai_twamp_session_event_notification_data_t *data) @@ -225,6 +236,7 @@ TEST(Proxy, notifications) EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); + EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_TAM_TEL_TYPE_CONFIG_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); @@ -294,6 +306,10 @@ TEST(Proxy, notifications) attr.value.ptr = (void*)&onBfdSessionStateChange; sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); + attr.id = SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY; + attr.value.ptr = (void*)&onIcmpEchoSessionStateChange; + sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); + attr.id = SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY; attr.value.ptr = (void*)&onTwampSessionEvent; sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); @@ -310,7 +326,7 @@ TEST(Proxy, notifications) // dummy stop sending notifications EXPECT_EQ(dummy->stop(), SAI_STATUS_SUCCESS); - EXPECT_EQ(proxy->getNotificationsSentCount(), 4+6+1); + EXPECT_EQ(proxy->getNotificationsSentCount(), 4+7+1); proxy->stop(); diff --git a/unittest/proxylib/TestSai.cpp b/unittest/proxylib/TestSai.cpp index 1d2c93b254..eb1647249e 100644 --- a/unittest/proxylib/TestSai.cpp +++ b/unittest/proxylib/TestSai.cpp @@ -727,6 +727,17 @@ static void onBfdSessionStateChange( ntfCounter++; } +static void onIcmpEchoSessionStateChange( + _In_ uint32_t count, + _In_ const sai_icmp_echo_session_state_notification_t *data) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_NOTICE("received: onIcmpEchoSessionStateChange"); + + ntfCounter++; +} + static void onTwampSessionEvent( _In_ uint32_t count, _In_ const sai_twamp_session_event_notification_data_t *data) @@ -767,6 +778,7 @@ TEST(Sai, handleNotification) EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); + EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY), SAI_STATUS_SUCCESS); EXPECT_EQ(dummy->enqueueNotificationToSend(SAI_SWITCH_ATTR_TAM_TEL_TYPE_CONFIG_CHANGE_NOTIFY), SAI_STATUS_SUCCESS); @@ -836,6 +848,10 @@ TEST(Sai, handleNotification) attr.value.ptr = (void*)&onBfdSessionStateChange; sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); + attr.id = SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY; + attr.value.ptr = (void*)&onIcmpEchoSessionStateChange; + sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); + attr.id = SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY; attr.value.ptr = (void*)&onTwampSessionEvent; sai.set(SAI_OBJECT_TYPE_SWITCH, switch_id, &attr); @@ -852,10 +868,10 @@ TEST(Sai, handleNotification) // dummy stop sending notifications EXPECT_EQ(dummy->stop(), SAI_STATUS_SUCCESS); - EXPECT_EQ(proxy->getNotificationsSentCount(), 11); + EXPECT_EQ(proxy->getNotificationsSentCount(), 12); // important check, whether Sai class processed notifications correctly - EXPECT_EQ(ntfCounter, 11); + EXPECT_EQ(ntfCounter, 12); proxy->stop(); diff --git a/unittest/syncd/TestNotificationHandler.cpp b/unittest/syncd/TestNotificationHandler.cpp index 9e3f25d8d4..deaf978219 100644 --- a/unittest/syncd/TestNotificationHandler.cpp +++ b/unittest/syncd/TestNotificationHandler.cpp @@ -8,6 +8,7 @@ using namespace syncd; static std::string natData = "[{\"nat_entry\":\"{\\\"nat_data\\\":{\\\"key\\\":{\\\"dst_ip\\\":\\\"10.10.10.10\\\",\\\"l4_dst_port\\\":\\\"20006\\\",\\\"l4_src_port\\\":\\\"0\\\",\\\"proto\\\":\\\"6\\\",\\\"src_ip\\\":\\\"0.0.0.0\\\"},\\\"mask\\\":{\\\"dst_ip\\\":\\\"255.255.255.255\\\",\\\"l4_dst_port\\\":\\\"65535\\\",\\\"l4_src_port\\\":\\\"0\\\",\\\"proto\\\":\\\"255\\\",\\\"src_ip\\\":\\\"0.0.0.0\\\"}},\\\"nat_type\\\":\\\"SAI_NAT_TYPE_DESTINATION_NAT\\\",\\\"switch_id\\\":\\\"oid:0x21000000000000\\\",\\\"vr\\\":\\\"oid:0x3000000000048\\\"}\",\"nat_event\":\"SAI_NAT_EVENT_AGED\"}]"; +static std::string icmp_echo_sesion_state_str = "[{\"icmp_echo_session_id\":\"oid:0x100000000003a\",\"session_state\":\"SAI_ICMP_ECHO_SESSION_STATE_DOWN\"}]"; // Test ASIC/SDK health event std::string asheData = "{" @@ -44,6 +45,18 @@ TEST(NotificationHandler, NotificationHandlerTest) sai_deserialize_nat_event_ntf(natData, count, &natevent); notificationHandler->onNatEvent(count, natevent); + attrs.clear(); + sai_attribute_t icmp_echo_attr; + icmp_echo_attr.id = SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY; + icmp_echo_attr.value.ptr = (void *) 1; + + attrs.push_back(icmp_echo_attr); + notificationHandler->updateNotificationsPointers(1, attrs.data()); + + sai_icmp_echo_session_state_notification_t *icmp_echo_session_state_ntf = NULL; + sai_deserialize_icmp_echo_session_state_ntf(icmp_echo_sesion_state_str, count, &icmp_echo_session_state_ntf); + notificationHandler->onIcmpEchoSessionStateChange(count, icmp_echo_session_state_ntf); + sai_object_id_t switch_id; sai_switch_asic_sdk_health_severity_t severity; sai_timespec_t timestamp; diff --git a/unittest/syncd/TestNotificationProcessor.cpp b/unittest/syncd/TestNotificationProcessor.cpp index d683f105d8..9ac0bbb4ba 100644 --- a/unittest/syncd/TestNotificationProcessor.cpp +++ b/unittest/syncd/TestNotificationProcessor.cpp @@ -12,6 +12,8 @@ using namespace syncd; static std::string natData = "[{\"nat_entry\":\"{\\\"nat_data\\\":{\\\"key\\\":{\\\"dst_ip\\\":\\\"10.10.10.10\\\",\\\"l4_dst_port\\\":\\\"20006\\\",\\\"l4_src_port\\\":\\\"0\\\",\\\"proto\\\":\\\"6\\\",\\\"src_ip\\\":\\\"0.0.0.0\\\"},\\\"mask\\\":{\\\"dst_ip\\\":\\\"255.255.255.255\\\",\\\"l4_dst_port\\\":\\\"65535\\\",\\\"l4_src_port\\\":\\\"0\\\",\\\"proto\\\":\\\"255\\\",\\\"src_ip\\\":\\\"0.0.0.0\\\"}},\\\"nat_type\\\":\\\"SAI_NAT_TYPE_DESTINATION_NAT\\\",\\\"switch_id\\\":\\\"oid:0x21000000000000\\\",\\\"vr\\\":\\\"oid:0x3000000000048\\\"}\",\"nat_event\":\"SAI_NAT_EVENT_AGED\"}]"; +static std::string icmp_echo_session_ntf_str = "[{\"icmp_echo_session_id\":\"oid:0x100000000003a\",\"session_state\":\"SAI_ICMP_ECHO_SESSION_STATE_DOWN\"}]"; + TEST(NotificationProcessor, NotificationProcessorTest) { auto sai = std::make_shared(); @@ -74,6 +76,15 @@ TEST(NotificationProcessor, NotificationProcessorTest) EXPECT_EQ(*bridgeport, "oid:0x3a000000000a99"); EXPECT_EQ(ip, nullptr); + //Test ICMP_ECHO_SESSION_STATE_CHANGE Notification + translator->insertRidAndVid(0x21000000000000,0x210000000000); + translator->insertRidAndVid(0x100000000003a,0x100000000003a); + std::vector icmp_echo_session_ntf_entry; + swss::KeyOpFieldsValuesTuple icmp_obj(SAI_SWITCH_NOTIFICATION_NAME_ICMP_ECHO_SESSION_STATE_CHANGE, icmp_echo_session_ntf_str, icmp_echo_session_ntf_entry); + notificationProcessor->syncProcessNotification(icmp_obj); + translator->eraseRidAndVid(0x21000000000000,0x210000000000); + translator->insertRidAndVid(0x100000000003a,0x100000000003a); + // Test ASIC/SDK health event std::string asheString = "{" "\"category\":\"SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_FW\"," diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 20df43b2e2..36a4375086 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -1060,6 +1060,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_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY; + + CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); + attr.id = SAI_SWITCH_ATTR_HA_SET_EVENT_NOTIFY; CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr));