From 12e32f01846b45b6b1ac6d4e419c36fe908bad41 Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Sun, 20 Aug 2023 12:04:07 +0000 Subject: [PATCH 1/7] Add SAI Notification support for host_tx_ready --- lib/Switch.cpp | 6 ++ meta/Meta.cpp | 49 +++++++++++++++ meta/Meta.h | 5 ++ meta/NotificationFactory.cpp | 4 ++ meta/NotificationPortHostTxReadyEvent.cpp | 73 +++++++++++++++++++++ meta/NotificationPortHostTxReadyEvent.h | 38 +++++++++++ meta/SaiSerialize.cpp | 77 +++++++++++++++++++++++ meta/sai_serialize.h | 18 ++++++ saiplayer/SaiPlayer.cpp | 11 ++++ saiplayer/SaiPlayer.h | 5 ++ syncd/NotificationHandler.cpp | 16 +++++ syncd/NotificationHandler.h | 5 ++ syncd/NotificationProcessor.cpp | 42 +++++++++++++ syncd/NotificationProcessor.h | 8 +++ syncd/SwitchNotifications.cpp | 11 ++++ syncd/SwitchNotifications.h | 34 +++++++--- syncd/Syncd.cpp | 1 + syncd/scripts/syncd_init_common.sh | 5 ++ vslib/Switch.cpp | 5 ++ 19 files changed, 405 insertions(+), 8 deletions(-) create mode 100644 meta/NotificationPortHostTxReadyEvent.cpp create mode 100644 meta/NotificationPortHostTxReadyEvent.h diff --git a/lib/Switch.cpp b/lib/Switch.cpp index c7af4a297..f153af4b3 100644 --- a/lib/Switch.cpp +++ b/lib/Switch.cpp @@ -118,6 +118,12 @@ void Switch::updateNotifications( (sai_bfd_session_state_change_notification_fn)attr.value.ptr; break; + case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY: + m_switchNotifications.on_port_host_tx_ready = + (sai_port_host_tx_ready_notification_fn)attr.value.ptr; + break; + + default: SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); break; diff --git a/meta/Meta.cpp b/meta/Meta.cpp index db1c6cc71..921625d1a 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -6434,6 +6434,55 @@ void Meta::meta_sai_on_nat_event( } } +void Meta::meta_sai_on_port_host_tx_ready_change( + _In_ sai_object_id_t port_id, + _In_ sai_object_id_t switch_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + if (!sai_metadata_get_enum_value_name( + &sai_metadata_enum_sai_port_host_tx_ready_status_t, + host_tx_ready_status)) + { + SWSS_LOG_WARN("port host_tx_ready value (%d) not found in sai_port_host_tx_ready_status_t", + host_tx_ready_status); + } + + auto ot = objectTypeQuery(port_id); + auto valid = false; + + switch (ot) + { + case SAI_OBJECT_TYPE_PORT: + // case SAI_OBJECT_TYPE_BRIDGE_PORT: + // case SAI_OBJECT_TYPE_LAG: + valid = true; + break; + + default: + SWSS_LOG_ERROR("port_id %s has unexpected type: %s, expected PORT", //, BRIDGE_PORT or LAG + sai_serialize_object_id(port_id).c_str(), + sai_serialize_object_type(ot).c_str()); + break; + } + + if (valid && !m_oids.objectReferenceExists(port_id)) + { + SWSS_LOG_NOTICE("port_id new object spotted %s not present in local DB (snoop!)", + sai_serialize_object_id(port_id).c_str()); + + sai_object_meta_key_t host_tx_ready_key = { .objecttype = ot, .objectkey = { .key = { .object_id = port_id } } }; + m_oids.objectReferenceInsert(port_id); + + if (!m_saiObjectCollection.objectExists(host_tx_ready_key)) + { + m_saiObjectCollection.createObject(host_tx_ready_key); + } + } +} + + void Meta::meta_sai_on_switch_state_change( _In_ sai_object_id_t switch_id, _In_ sai_switch_oper_status_t switch_oper_status) diff --git a/meta/Meta.h b/meta/Meta.h index 0eae42b51..e018624e6 100644 --- a/meta/Meta.h +++ b/meta/Meta.h @@ -220,6 +220,11 @@ namespace saimeta _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + void meta_sai_on_port_host_tx_ready_change( + _In_ sai_object_id_t port_id, + _In_ sai_object_id_t switch_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); + private: // notifications helpers void meta_sai_on_fdb_flush_event_consolidated( diff --git a/meta/NotificationFactory.cpp b/meta/NotificationFactory.cpp index 9682848d8..894bc8ab7 100644 --- a/meta/NotificationFactory.cpp +++ b/meta/NotificationFactory.cpp @@ -6,6 +6,7 @@ #include "NotificationSwitchShutdownRequest.h" #include "NotificationSwitchStateChange.h" #include "NotificationBfdSessionStateChange.h" +#include "NotificationPortHostTxReadyEvent.cpp" #include "sairediscommon.h" #include "swss/logger.h" @@ -24,6 +25,9 @@ std::shared_ptr NotificationFactory::deserialize( if (name == SAI_SWITCH_NOTIFICATION_NAME_NAT_EVENT) return std::make_shared(serializedNotification); + if (name == SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY) + return std::make_shared(serializedNotification); + if (name == SAI_SWITCH_NOTIFICATION_NAME_PORT_STATE_CHANGE) return std::make_shared(serializedNotification); diff --git a/meta/NotificationPortHostTxReadyEvent.cpp b/meta/NotificationPortHostTxReadyEvent.cpp new file mode 100644 index 000000000..83a25434b --- /dev/null +++ b/meta/NotificationPortHostTxReadyEvent.cpp @@ -0,0 +1,73 @@ +#include "NotificationPortHostTxReadyEvent.h" + +#include "swss/logger.h" + +#include "sai_serialize.h" + +using namespace sairedis; + +// NotificationSwitchStateChange::NotificationSwitchStateChange( +// _In_ const std::string& serializedNotification): +// Notification( +// SAI_SWITCH_NOTIFICATION_TYPE_SWITCH_STATE_CHANGE, +// serializedNotification) + +NotificationPortHostTxReady::NotificationPortHostTxReady( + _In_ const std::string& serializedNotification): + Notification( + SAI_SWITCH_NOTIFICATION_TYPE_PORT_HOST_TX_READY, + serializedNotification) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_port_host_tx_ready_ntf( + serializedNotification, + m_switchId, + m_portId, + m_portHostTxReadyStatus); +} + +NotificationPortHostTxReady::~NotificationPortHostTxReady() +{ + SWSS_LOG_ENTER(); + + sai_deserialize_free_port_host_tx_ready_ntf(m_portHostTxReadyStatus); +} + +sai_object_id_t NotificationPortHostTxReady::getSwitchId() const +{ + SWSS_LOG_ENTER(); + + return m_switchId; +} + +sai_object_id_t NotificationPortHostTxReady::getAnyObjectId() const +{ + SWSS_LOG_ENTER(); + + if (m_portId != SAI_NULL_OBJECT_ID) + { + return m_portId; + } + + return SAI_NULL_OBJECT_ID; +} + +void NotificationPortHostTxReady::processMetadata( + _In_ std::shared_ptr meta) const +{ + SWSS_LOG_ENTER(); + + meta->meta_sai_on_port_host_tx_ready_change(m_portId, m_switchId, m_portHostTxReadyStatus); +} + +void NotificationPortHostTxReady::executeCallback( + _In_ const sai_switch_notifications_t& switchNotifications) const +{ + SWSS_LOG_ENTER(); + + if (switchNotifications.on_port_host_tx_ready) + { + switchNotifications.on_port_host_tx_ready(m_switchId, m_portId, m_portHostTxReadyStatus); + } +} diff --git a/meta/NotificationPortHostTxReadyEvent.h b/meta/NotificationPortHostTxReadyEvent.h new file mode 100644 index 000000000..2de2ba118 --- /dev/null +++ b/meta/NotificationPortHostTxReadyEvent.h @@ -0,0 +1,38 @@ +#pragma once + +#include "Notification.h" + +namespace sairedis +{ + class NotificationPortHostTxReady: + public Notification + { + public: + + NotificationPortHostTxReady( + _In_ const std::string& serializedNotification); + + virtual ~NotificationPortHostTxReady(); + + 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: + + sai_object_id_t m_portId; + + sai_object_id_t m_switchId; + + sai_port_host_tx_ready_status_t m_portHostTxReadyStatus; + + }; +} \ No newline at end of file diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index af039526f..60c3cb1b7 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -1098,6 +1098,14 @@ std::string sai_serialize_switch_oper_status( return j.dump(); } +std::string sai_serialize_port_host_tx_ready_status( + _In_ const sai_port_host_tx_ready_status_t status) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(status, &sai_metadata_enum_sai_port_host_tx_ready_status_t); +} + std::string sai_serialize_ingress_drop_reason( _In_ const sai_in_drop_reason_t reason) { @@ -2113,6 +2121,14 @@ std::string sai_serialize_port_oper_status( return sai_serialize_enum(status, &sai_metadata_enum_sai_port_oper_status_t); } +std::string sai_serialize_port_host_tx_ready( + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(host_tx_ready_status, &sai_metadata_enum_sai_port_host_tx_ready_status_t); +} + std::string sai_serialize_queue_deadlock_event( _In_ sai_queue_pfc_deadlock_event_type_t event) { @@ -2271,6 +2287,27 @@ std::string sai_serialize_port_oper_status_ntf( return j.dump(); } + +std::string sai_serialize_port_host_tx_ready_ntf( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + json j = json::array(); + json item; + + item["port_id"] = sai_serialize_object_id(port_id); + item["switch_id"] = sai_serialize_object_id(switch_id); + item["host_tx_ready_status"] = sai_serialize_port_host_tx_ready_status(host_tx_ready_status); + + j.push_back(item); + + return j.dump(); +} + + std::string sai_serialize_queue_deadlock_ntf( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t* deadlock_data) @@ -3891,6 +3928,15 @@ void sai_deserialize_port_oper_status( sai_deserialize_enum(s, &sai_metadata_enum_sai_port_oper_status_t, (int32_t&)status); } +void sai_deserialize_port_host_tx_ready_status( + _In_ const std::string& s, + _Out_ sai_port_host_tx_ready_status_t& status) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_enum(s, &sai_metadata_enum_sai_port_host_tx_ready_status_t, (int32_t&)status); +} + void sai_deserialize_queue_deadlock( _In_ const std::string& s, _Out_ sai_queue_pfc_deadlock_event_type_t& event) @@ -4593,6 +4639,31 @@ void sai_deserialize_port_oper_status_ntf( *port_oper_status = data; } +void sai_deserialize_port_host_tx_ready_ntf( + _In_ const std::string& s, + _Out_ sai_object_id_t& switch_id, + _Out_ sai_object_id_t& port_id, + _Out_ sai_port_host_tx_ready_status_t& host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + json j; + try + { + j = json::parse(s); + } + catch (const std::exception&) + { + SWSS_LOG_ERROR("Recieved an exception after trying to parse %s", s.c_str()); + return; + } + // auto count = (uint32_t)j.size(); + + sai_deserialize_object_id(j[0]["port_id"], port_id); + sai_deserialize_object_id(j[0]["switch_id"], switch_id); + sai_deserialize_port_host_tx_ready_status(j[0]["host_tx_ready_status"], host_tx_ready_status); +} + void sai_deserialize_queue_deadlock_ntf( _In_ const std::string& s, _Out_ uint32_t &count, @@ -4881,6 +4952,12 @@ void sai_deserialize_free_port_oper_status_ntf( delete[] port_oper_status; } +void sai_deserialize_free_port_host_tx_ready_ntf( + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); +} + void sai_deserialize_free_queue_deadlock_ntf( _In_ uint32_t count, _In_ sai_queue_deadlock_notification_data_t* queue_deadlock) diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index ea6a52404..5922c41ab 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -232,6 +232,9 @@ std::string sai_serialize_mac( std::string sai_serialize_port_oper_status( _In_ sai_port_oper_status_t status); +std::string sai_serialize_port_host_tx_ready( + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); + std::string sai_serialize_ingress_drop_reason( _In_ const sai_in_drop_reason_t reason); @@ -272,6 +275,11 @@ 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_port_host_tx_ready_ntf( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); + // sairedis std::string sai_serialize( @@ -470,6 +478,13 @@ void sai_deserialize_bfd_session_state_ntf( _Out_ uint32_t &count, _Out_ sai_bfd_session_state_notification_t** bfdsession); +void sai_deserialize_port_host_tx_ready_ntf( + _In_ const std::string& s, + _Out_ sai_object_id_t& switch_id, + _Out_ sai_object_id_t& port_id, + _Out_ sai_port_host_tx_ready_status_t& host_tx_ready_status); + + // free methods void sai_deserialize_free_attribute_value( @@ -498,6 +513,9 @@ void sai_deserialize_free_bfd_session_state_ntf( _In_ uint32_t count, _In_ sai_bfd_session_state_notification_t* bfdsessionstate); +void sai_deserialize_free_port_host_tx_ready_ntf( + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); + void sai_deserialize_ingress_priority_group_attr( _In_ const std::string& s, _Out_ sai_ingress_priority_group_attr_t& attr); diff --git a/saiplayer/SaiPlayer.cpp b/saiplayer/SaiPlayer.cpp index 6e22de110..6aefe9893 100644 --- a/saiplayer/SaiPlayer.cpp +++ b/saiplayer/SaiPlayer.cpp @@ -90,6 +90,7 @@ SaiPlayer::SaiPlayer( 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_sn.onPortHostTxReady = std::bind(&SaiPlayer::onPortHostTxReady, this, _1, _2, _3); m_switchNotifications= m_sn.getSwitchNotifications(); } @@ -175,6 +176,16 @@ void SaiPlayer::onBfdSessionStateChange( // empty } +void SaiPlayer::onPortHostTxReady( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + // empty +} + void SaiPlayer::onQueuePfcDeadlock( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t *data) diff --git a/saiplayer/SaiPlayer.h b/saiplayer/SaiPlayer.h index fe7f91119..1aeda13c9 100644 --- a/saiplayer/SaiPlayer.h +++ b/saiplayer/SaiPlayer.h @@ -239,6 +239,11 @@ namespace saiplayer void onBfdSessionStateChange( _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); + + void onPortHostTxReady( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); private: diff --git a/syncd/NotificationHandler.cpp b/syncd/NotificationHandler.cpp index 7e0c29573..ff2aeae59 100644 --- a/syncd/NotificationHandler.cpp +++ b/syncd/NotificationHandler.cpp @@ -108,6 +108,10 @@ void NotificationHandler::updateNotificationsPointers( attr.value.ptr = (void*)m_switchNotifications.on_port_state_change; break; + case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY: + attr.value.ptr = (void*)m_switchNotifications.on_port_host_tx_ready; + break; + case SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY: attr.value.ptr = (void*)m_switchNotifications.on_queue_pfc_deadlock; break; @@ -164,6 +168,18 @@ void NotificationHandler::onPortStateChange( enqueueNotification(SAI_SWITCH_NOTIFICATION_NAME_PORT_STATE_CHANGE, s); } +void NotificationHandler::onPortHostTxReady( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + auto s = sai_serialize_port_host_tx_ready_ntf(switch_id, port_id, host_tx_ready_status); + + enqueueNotification(SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY, s); +} + void NotificationHandler::onQueuePfcDeadlock( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t *data) diff --git a/syncd/NotificationHandler.h b/syncd/NotificationHandler.h index 060009b49..9e093a47e 100644 --- a/syncd/NotificationHandler.h +++ b/syncd/NotificationHandler.h @@ -49,6 +49,11 @@ namespace syncd _In_ uint32_t count, _In_ const sai_port_oper_status_notification_t *data); + void onPortHostTxReady( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); + void onQueuePfcDeadlock( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t *data); diff --git a/syncd/NotificationProcessor.cpp b/syncd/NotificationProcessor.cpp index 68068a65d..a6aefc417 100644 --- a/syncd/NotificationProcessor.cpp +++ b/syncd/NotificationProcessor.cpp @@ -463,6 +463,28 @@ void NotificationProcessor::process_on_queue_deadlock_event( sendNotification(SAI_SWITCH_NOTIFICATION_NAME_QUEUE_PFC_DEADLOCK, s); } + +void NotificationProcessor::process_on_port_host_tx_ready_change( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t *host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_DEBUG("Port ID before translating from RID to VID is 0x%lx", port_id); + sai_object_id_t port_vid = m_translator->translateRidToVid(port_id, SAI_NULL_OBJECT_ID); + SWSS_LOG_DEBUG("Port ID after translating from RID to VID is 0x%lx", port_vid); + + sai_object_id_t switch_vid = m_translator->translateRidToVid(switch_id, SAI_NULL_OBJECT_ID); + + std::string s = sai_serialize_port_host_tx_ready_ntf(switch_vid, port_vid, *host_tx_ready_status); + + SWSS_LOG_DEBUG("Host_tx_ready status after sai_serialize is %s", s.c_str()); + + sendNotification(SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY, s); +} + + void NotificationProcessor::process_on_port_state_change( _In_ uint32_t count, _In_ sai_port_oper_status_notification_t *data) @@ -626,6 +648,22 @@ void NotificationProcessor::handle_port_state_change( sai_deserialize_free_port_oper_status_ntf(count, portoperstatus); } +void NotificationProcessor::handle_port_host_tx_ready_change( + _In_ const std::string &data) +{ + SWSS_LOG_ENTER(); + + sai_object_id_t port_id; + sai_object_id_t switch_id; + sai_port_host_tx_ready_status_t host_tx_ready_status; + + sai_deserialize_port_host_tx_ready_ntf(data, switch_id, port_id, host_tx_ready_status); + + process_on_port_host_tx_ready_change(switch_id, port_id, &host_tx_ready_status); + + sai_deserialize_free_port_host_tx_ready_ntf(host_tx_ready_status); +} + void NotificationProcessor::handle_bfd_session_state_change( _In_ const std::string &data) { @@ -685,6 +723,10 @@ void NotificationProcessor::syncProcessNotification( { handle_port_state_change(data); } + else if (notification == SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY) + { + handle_port_host_tx_ready_change(data); + } else if (notification == SAI_SWITCH_NOTIFICATION_NAME_SWITCH_SHUTDOWN_REQUEST) { handle_switch_shutdown_request(data); diff --git a/syncd/NotificationProcessor.h b/syncd/NotificationProcessor.h index f7ac2c674..1a6d86ef7 100644 --- a/syncd/NotificationProcessor.h +++ b/syncd/NotificationProcessor.h @@ -92,6 +92,11 @@ namespace syncd _In_ uint32_t count, _In_ sai_bfd_session_state_notification_t *data); + void process_on_port_host_tx_ready_change( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t *host_tx_ready_status); + void process_on_switch_shutdown_request( _In_ sai_object_id_t switch_rid); @@ -118,6 +123,9 @@ namespace syncd void handle_switch_shutdown_request( _In_ const std::string &data); + void handle_port_host_tx_ready_change( + _In_ const std::string &data); + void processNotification( _In_ const swss::KeyOpFieldsValuesTuple& item); diff --git a/syncd/SwitchNotifications.cpp b/syncd/SwitchNotifications.cpp index 75d176e74..bf2a9ba40 100644 --- a/syncd/SwitchNotifications.cpp +++ b/syncd/SwitchNotifications.cpp @@ -67,6 +67,17 @@ void SwitchNotifications::SlotBase::onPortStateChange( return m_slots.at(context)->m_handler->onPortStateChange(count, data); } +void SwitchNotifications::SlotBase::onPortHostTxReady( + _In_ int context, + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); + + return m_slots.at(context)->m_handler->onPortHostTxReady(switch_id, port_id, host_tx_ready_status); +} + void SwitchNotifications::SlotBase::onBfdSessionStateChange( _In_ int context, _In_ uint32_t count, diff --git a/syncd/SwitchNotifications.h b/syncd/SwitchNotifications.h index 00d2379b9..013ba60d0 100644 --- a/syncd/SwitchNotifications.h +++ b/syncd/SwitchNotifications.h @@ -50,6 +50,13 @@ namespace syncd _In_ uint32_t count, _In_ const sai_port_oper_status_notification_t *data); + + static void onPortHostTxReady( + _In_ int context, + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); + static void onQueuePfcDeadlock( _In_ int context, _In_ uint32_t count, @@ -87,6 +94,7 @@ namespace syncd .on_switch_state_change = &Slot::onSwitchStateChange, .on_switch_shutdown_request = &Slot::onSwitchShutdownRequest, .on_fdb_event = &Slot::onFdbEvent, + .on_port_host_tx_ready = &Slot::onPortHostTxReady, .on_port_state_change = &Slot::onPortStateChange, .on_packet_event = nullptr, .on_queue_pfc_deadlock = &Slot::onQueuePfcDeadlock, @@ -95,7 +103,6 @@ namespace syncd .on_ipsec_sa_status_change = nullptr, .on_nat_event = &Slot::onNatEvent, .on_switch_asic_sdk_health_event = nullptr, - .on_port_host_tx_ready = nullptr, .on_twamp_session_event = nullptr, }) { } @@ -130,6 +137,16 @@ namespace syncd return SlotBase::onPortStateChange(context, count, data); } + static void onPortHostTxReady( + _In_ sai_object_id_t switch_id, + _In_ sai_object_id_t port_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) + { + SWSS_LOG_ENTER(); + + return SlotBase::onPortHostTxReady(context, switch_id, port_id, host_tx_ready_status); + } + static void onBfdSessionStateChange( _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data) @@ -180,13 +197,14 @@ namespace syncd public: // wrapped methods - std::function onFdbEvent; - std::function onNatEvent; - std::function onPortStateChange; - std::function onQueuePfcDeadlock; - std::function onSwitchShutdownRequest; - std::function onSwitchStateChange; - std::function onBfdSessionStateChange; + std::function onFdbEvent; + std::function onNatEvent; + std::function onPortStateChange; + std::function onPortHostTxReady; + std::function onQueuePfcDeadlock; + std::function onSwitchShutdownRequest; + std::function onSwitchStateChange; + std::function onBfdSessionStateChange; private: diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index 869cfd87a..df442ff42 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -158,6 +158,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.onPortHostTxReady = std::bind(&NotificationHandler::onPortHostTxReady, m_handler.get(), _1, _2, _3); m_handler->setSwitchNotifications(m_sn.getSwitchNotifications()); diff --git a/syncd/scripts/syncd_init_common.sh b/syncd/scripts/syncd_init_common.sh index 214d3b125..dd663b1ed 100644 --- a/syncd/scripts/syncd_init_common.sh +++ b/syncd/scripts/syncd_init_common.sh @@ -233,6 +233,11 @@ config_syncd_mlnx() if [[ -f /tmp/sai_extra.profile ]]; then cat /tmp/sai_extra.profile >> /tmp/sai.profile fi + + if [[ -f /$HWSKU_DIR/independent_mode_support.profile ]]; then + cat /$HWSKU_DIR/independent_mode_support.profile >> /tmp/sai.profile + fi + } config_syncd_centec() diff --git a/vslib/Switch.cpp b/vslib/Switch.cpp index 874f7767a..fa337a1ee 100644 --- a/vslib/Switch.cpp +++ b/vslib/Switch.cpp @@ -95,6 +95,11 @@ void Switch::updateNotifications( (sai_port_state_change_notification_fn)attr.value.ptr; break; + case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY: + m_switchNotifications.on_port_host_tx_ready = + (sai_port_host_tx_ready_notification_fn)attr.value.ptr; + break; + case SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY: m_switchNotifications.on_packet_event = (sai_packet_event_notification_fn)attr.value.ptr; From ef4b449314003fc57c812df907824cb7946e7dc6 Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Sun, 29 Oct 2023 11:50:38 +0000 Subject: [PATCH 2/7] Fix CR comments --- lib/Switch.cpp | 3 +-- meta/Makefile.am | 1 + meta/Meta.cpp | 24 +++++++++-------------- meta/NotificationFactory.cpp | 2 +- meta/NotificationPortHostTxReadyEvent.cpp | 15 +------------- meta/NotificationPortHostTxReadyEvent.h | 2 +- meta/SaiSerialize.cpp | 11 +---------- meta/sai_serialize.h | 3 --- syncd/NotificationProcessor.cpp | 8 +++----- syncd/scripts/syncd_init_common.sh | 5 ----- 10 files changed, 18 insertions(+), 56 deletions(-) diff --git a/lib/Switch.cpp b/lib/Switch.cpp index f153af4b3..7094b0e39 100644 --- a/lib/Switch.cpp +++ b/lib/Switch.cpp @@ -121,8 +121,7 @@ void Switch::updateNotifications( case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY: m_switchNotifications.on_port_host_tx_ready = (sai_port_host_tx_ready_notification_fn)attr.value.ptr; - break; - + break; default: SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); diff --git a/meta/Makefile.am b/meta/Makefile.am index c2de85b3f..d604241b2 100644 --- a/meta/Makefile.am +++ b/meta/Makefile.am @@ -35,6 +35,7 @@ libsaimeta_la_SOURCES = \ NotificationSwitchShutdownRequest.cpp \ NotificationSwitchStateChange.cpp \ NotificationBfdSessionStateChange.cpp \ + NotificationPortHostTxReadyEvent.cpp \ NumberOidIndexGenerator.cpp \ OidRefCounter.cpp \ PerformanceIntervalTimer.cpp \ diff --git a/meta/Meta.cpp b/meta/Meta.cpp index 921625d1a..b9d03a3a2 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -6445,29 +6445,23 @@ void Meta::meta_sai_on_port_host_tx_ready_change( &sai_metadata_enum_sai_port_host_tx_ready_status_t, host_tx_ready_status)) { - SWSS_LOG_WARN("port host_tx_ready value (%d) not found in sai_port_host_tx_ready_status_t", + SWSS_LOG_WARN("port host_tx_ready value (%d) not found in sai_port_host_tx_ready_status_t. Dropping the notification", host_tx_ready_status); + + return; } - + auto ot = objectTypeQuery(port_id); - auto valid = false; - - switch (ot) - { - case SAI_OBJECT_TYPE_PORT: - // case SAI_OBJECT_TYPE_BRIDGE_PORT: - // case SAI_OBJECT_TYPE_LAG: - valid = true; - break; - default: - SWSS_LOG_ERROR("port_id %s has unexpected type: %s, expected PORT", //, BRIDGE_PORT or LAG + if (ot != SAI_OBJECT_TYPE_PORT) + { + SWSS_LOG_ERROR("port_id %s has unexpected type: %s, expected PORT", sai_serialize_object_id(port_id).c_str(), sai_serialize_object_type(ot).c_str()); - break; + return; } - if (valid && !m_oids.objectReferenceExists(port_id)) + if (!m_oids.objectReferenceExists(port_id)) { SWSS_LOG_NOTICE("port_id new object spotted %s not present in local DB (snoop!)", sai_serialize_object_id(port_id).c_str()); diff --git a/meta/NotificationFactory.cpp b/meta/NotificationFactory.cpp index 894bc8ab7..456af8891 100644 --- a/meta/NotificationFactory.cpp +++ b/meta/NotificationFactory.cpp @@ -6,7 +6,7 @@ #include "NotificationSwitchShutdownRequest.h" #include "NotificationSwitchStateChange.h" #include "NotificationBfdSessionStateChange.h" -#include "NotificationPortHostTxReadyEvent.cpp" +#include "NotificationPortHostTxReadyEvent.h" #include "sairediscommon.h" #include "swss/logger.h" diff --git a/meta/NotificationPortHostTxReadyEvent.cpp b/meta/NotificationPortHostTxReadyEvent.cpp index 83a25434b..d1a2ecc52 100644 --- a/meta/NotificationPortHostTxReadyEvent.cpp +++ b/meta/NotificationPortHostTxReadyEvent.cpp @@ -6,12 +6,6 @@ using namespace sairedis; -// NotificationSwitchStateChange::NotificationSwitchStateChange( -// _In_ const std::string& serializedNotification): -// Notification( -// SAI_SWITCH_NOTIFICATION_TYPE_SWITCH_STATE_CHANGE, -// serializedNotification) - NotificationPortHostTxReady::NotificationPortHostTxReady( _In_ const std::string& serializedNotification): Notification( @@ -30,8 +24,6 @@ NotificationPortHostTxReady::NotificationPortHostTxReady( NotificationPortHostTxReady::~NotificationPortHostTxReady() { SWSS_LOG_ENTER(); - - sai_deserialize_free_port_host_tx_ready_ntf(m_portHostTxReadyStatus); } sai_object_id_t NotificationPortHostTxReady::getSwitchId() const @@ -45,12 +37,7 @@ sai_object_id_t NotificationPortHostTxReady::getAnyObjectId() const { SWSS_LOG_ENTER(); - if (m_portId != SAI_NULL_OBJECT_ID) - { - return m_portId; - } - - return SAI_NULL_OBJECT_ID; + return m_portId; } void NotificationPortHostTxReady::processMetadata( diff --git a/meta/NotificationPortHostTxReadyEvent.h b/meta/NotificationPortHostTxReadyEvent.h index 2de2ba118..9f46c33f9 100644 --- a/meta/NotificationPortHostTxReadyEvent.h +++ b/meta/NotificationPortHostTxReadyEvent.h @@ -35,4 +35,4 @@ namespace sairedis sai_port_host_tx_ready_status_t m_portHostTxReadyStatus; }; -} \ No newline at end of file +} diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 60c3cb1b7..583780020 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -2287,7 +2287,6 @@ std::string sai_serialize_port_oper_status_ntf( return j.dump(); } - std::string sai_serialize_port_host_tx_ready_ntf( _In_ sai_object_id_t switch_id, _In_ sai_object_id_t port_id, @@ -2307,7 +2306,6 @@ std::string sai_serialize_port_host_tx_ready_ntf( return j.dump(); } - std::string sai_serialize_queue_deadlock_ntf( _In_ uint32_t count, _In_ const sai_queue_deadlock_notification_data_t* deadlock_data) @@ -4657,10 +4655,9 @@ void sai_deserialize_port_host_tx_ready_ntf( SWSS_LOG_ERROR("Recieved an exception after trying to parse %s", s.c_str()); return; } - // auto count = (uint32_t)j.size(); sai_deserialize_object_id(j[0]["port_id"], port_id); - sai_deserialize_object_id(j[0]["switch_id"], switch_id); + sai_deserialize_object_id(j[0]["switch_id"], switch_id); sai_deserialize_port_host_tx_ready_status(j[0]["host_tx_ready_status"], host_tx_ready_status); } @@ -4952,12 +4949,6 @@ void sai_deserialize_free_port_oper_status_ntf( delete[] port_oper_status; } -void sai_deserialize_free_port_host_tx_ready_ntf( - _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) -{ - SWSS_LOG_ENTER(); -} - void sai_deserialize_free_queue_deadlock_ntf( _In_ uint32_t count, _In_ sai_queue_deadlock_notification_data_t* queue_deadlock) diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index 5922c41ab..7d53c11cc 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -513,9 +513,6 @@ void sai_deserialize_free_bfd_session_state_ntf( _In_ uint32_t count, _In_ sai_bfd_session_state_notification_t* bfdsessionstate); -void sai_deserialize_free_port_host_tx_ready_ntf( - _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); - void sai_deserialize_ingress_priority_group_attr( _In_ const std::string& s, _Out_ sai_ingress_priority_group_attr_t& attr); diff --git a/syncd/NotificationProcessor.cpp b/syncd/NotificationProcessor.cpp index a6aefc417..ccdfdb02d 100644 --- a/syncd/NotificationProcessor.cpp +++ b/syncd/NotificationProcessor.cpp @@ -471,12 +471,12 @@ void NotificationProcessor::process_on_port_host_tx_ready_change( { SWSS_LOG_ENTER(); - SWSS_LOG_DEBUG("Port ID before translating from RID to VID is 0x%lx", port_id); + SWSS_LOG_DEBUG("Port ID before translating from RID to VID is %s", sai_serialize_object_id(port_id).c_str()); sai_object_id_t port_vid = m_translator->translateRidToVid(port_id, SAI_NULL_OBJECT_ID); - SWSS_LOG_DEBUG("Port ID after translating from RID to VID is 0x%lx", port_vid); + SWSS_LOG_DEBUG("Port ID after translating from RID to VID is %s", sai_serialize_object_id(port_id).c_str()); sai_object_id_t switch_vid = m_translator->translateRidToVid(switch_id, SAI_NULL_OBJECT_ID); - + std::string s = sai_serialize_port_host_tx_ready_ntf(switch_vid, port_vid, *host_tx_ready_status); SWSS_LOG_DEBUG("Host_tx_ready status after sai_serialize is %s", s.c_str()); @@ -660,8 +660,6 @@ void NotificationProcessor::handle_port_host_tx_ready_change( sai_deserialize_port_host_tx_ready_ntf(data, switch_id, port_id, host_tx_ready_status); process_on_port_host_tx_ready_change(switch_id, port_id, &host_tx_ready_status); - - sai_deserialize_free_port_host_tx_ready_ntf(host_tx_ready_status); } void NotificationProcessor::handle_bfd_session_state_change( diff --git a/syncd/scripts/syncd_init_common.sh b/syncd/scripts/syncd_init_common.sh index dd663b1ed..214d3b125 100644 --- a/syncd/scripts/syncd_init_common.sh +++ b/syncd/scripts/syncd_init_common.sh @@ -233,11 +233,6 @@ config_syncd_mlnx() if [[ -f /tmp/sai_extra.profile ]]; then cat /tmp/sai_extra.profile >> /tmp/sai.profile fi - - if [[ -f /$HWSKU_DIR/independent_mode_support.profile ]]; then - cat /$HWSKU_DIR/independent_mode_support.profile >> /tmp/sai.profile - fi - } config_syncd_centec() From 8c45fd6b137b00f203dcae5edb7111b28f40540b Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Sun, 5 Nov 2023 13:26:03 +0000 Subject: [PATCH 3/7] Extend coverage for host_tx_ready enhancements --- unittest/lib/TestSwitch.cpp | 5 +- unittest/meta/TestNotificationFactory.cpp | 10 +++ .../TestNotificationPortHostTxReadyEvent.cpp | 79 +++++++++++++++++++ unittest/meta/TestSaiSerialize.cpp | 5 ++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 unittest/meta/TestNotificationPortHostTxReadyEvent.cpp diff --git a/unittest/lib/TestSwitch.cpp b/unittest/lib/TestSwitch.cpp index 0969095e1..8637bc772 100644 --- a/unittest/lib/TestSwitch.cpp +++ b/unittest/lib/TestSwitch.cpp @@ -36,6 +36,7 @@ TEST(Switch, updateNotifications) attrs[5].value.ptr = (void*)1; attrs[6].value.ptr = (void*)1; attrs[7].value.ptr = (void*)1; + attrs[8].value.ptr = (void*)1; attrs[0].id = SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY; attrs[1].id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY; @@ -45,7 +46,8 @@ TEST(Switch, updateNotifications) attrs[5].id = SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY; attrs[6].id = SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY; attrs[7].id = SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY; - attrs[8].id = SAI_SWITCH_ATTR_INIT_SWITCH; + attrs[8].id = SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY; + attrs[9].id = SAI_SWITCH_ATTR_INIT_SWITCH; s->updateNotifications(8, attrs); @@ -59,4 +61,5 @@ TEST(Switch, updateNotifications) EXPECT_EQ((void*)1, sn.on_switch_shutdown_request); EXPECT_EQ((void*)1, sn.on_switch_state_change); EXPECT_EQ((void*)1, sn.on_nat_event); + EXPECT_EQ((void*)1, sn.on_port_host_tx_ready); } diff --git a/unittest/meta/TestNotificationFactory.cpp b/unittest/meta/TestNotificationFactory.cpp index f6f18eec6..8b049d157 100644 --- a/unittest/meta/TestNotificationFactory.cpp +++ b/unittest/meta/TestNotificationFactory.cpp @@ -46,6 +46,16 @@ TEST(NotificationFactory, deserialize_port_state_change) EXPECT_EQ(ntf->getNotificationType(), SAI_SWITCH_NOTIFICATION_TYPE_PORT_STATE_CHANGE); } +TEST(NotificationFactory, deserialize_port_host_tx_ready_status) +{ + auto ntf = NotificationFactory::deserialize( + SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY, + "[{\"host_tx_ready_status\":\"SAI_PORT_HOST_TX_READY_STATUS_READY\"}]" + ); + + EXPECT_EQ(ntf->getNotificationType(), SAI_SWITCH_NOTIFICATION_TYPE_PORT_HOST_TX_READY); +} + TEST(NotificationFactory, deserialize_queue_pfc_deadlock) { auto str = "[{\"event\":\"SAI_QUEUE_PFC_DEADLOCK_EVENT_TYPE_DETECTED\",\"queue_id\":\"oid:0x1500000000020a\"}]"; diff --git a/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp b/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp new file mode 100644 index 000000000..88afb559f --- /dev/null +++ b/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp @@ -0,0 +1,79 @@ +#include "NotificationPortHostTxReadyEvent.h" +#include "Meta.h" +#include "MetaTestSaiInterface.h" + +#include "sairediscommon.h" +#include "sai_serialize.h" + +#include +#include + +using namespace sairedis; +using namespace saimeta; + +static std::string s = "[{\"host_tx_ready_status\":\"SAI_PORT_HOST_TX_READY_STATUS_READY\",\"port_id\":\"oid:0x100000000001a\",\"switch_id\":\"oid:0x2100000000\"}]"; +static std::string null = "[{\"host_tx_ready_status\":\"SAI_PORT_HOST_TX_READY_STATUS_READY\",\"port_id\":\"oid:0x0\",\"switch_id\":\"oid:0x0\"}]"; +static std::string fullnull = "[]"; + +TEST(NotificationPortHostTxReadyEvent, ctr) +{ + NotificationPortHostTxReadyEvent n(s); +} + +TEST(NotificationPortHostTxReadyEvent, getSwitchId) +{ + NotificationPortHostTxReadyEvent n(s); + + EXPECT_EQ(n.getSwitchId(), 0x2100000000); + + NotificationSwitchStateChange n2(null); + + EXPECT_EQ(n2.getSwitchId(), 0); +} + +TEST(NotificationPortHostTxReadyEvent, getAnyObjectId) +{ + NotificationPortHostTxReadyEvent n(s); + + EXPECT_EQ(n.getAnyObjectId(), 0x100000000001a); + + NotificationPortHostTxReadyEvent n2(null); + + EXPECT_EQ(n2.getAnyObjectId(), 0); + + NotificationPortHostTxReadyEvent n3(fullnull); + + EXPECT_EQ(n3.getSwitchId(), 0); + + EXPECT_EQ(n3.getAnyObjectId(), 0); +} + +TEST(NotificationPortHostTxReadyEvent, processMetadata) +{ + NotificationPortHostTxReadyEvent n(s); + + auto sai = std::make_shared(); + auto meta = std::make_shared(sai); + + n.processMetadata(meta); +} + +static void on_port_host_tx_ready_change_notification( + _In_ sai_object_id_t port_id, + _In_ sai_object_id_t switch_id, + _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) +{ + SWSS_LOG_ENTER(); +} + +TEST(NotificationPortHostTxReadyEvent, executeCallback) +{ + NotificationPortHostTxReadyEvent n(s); + + sai_switch_notification_t ntfs; + + ntfs.on_port_host_tx_ready_change = &on_port_host_tx_ready_change_notification; + + n.executeCallback(ntfs); +} + diff --git a/unittest/meta/TestSaiSerialize.cpp b/unittest/meta/TestSaiSerialize.cpp index 5fec3b436..46a2e0761 100644 --- a/unittest/meta/TestSaiSerialize.cpp +++ b/unittest/meta/TestSaiSerialize.cpp @@ -483,6 +483,11 @@ TEST(SaiSerialize, sai_serialize_port_oper_status) EXPECT_EQ(sai_serialize_port_oper_status(SAI_PORT_OPER_STATUS_UP), "SAI_PORT_OPER_STATUS_UP"); } +TEST(SaiSerialize, sai_serialize_port_host_tx_ready) +{ + EXPECT_EQ(sai_serialize_port_host_tx_ready(SAI_PORT_HOST_TX_READY_STATUS_READY), "SAI_PORT_HOST_TX_READY_STATUS_READY"); +} + TEST(SaiSerialize, sai_serialize_queue_deadlock_event) { EXPECT_EQ(sai_serialize_queue_deadlock_event(SAI_QUEUE_PFC_DEADLOCK_EVENT_TYPE_DETECTED), From 5365042e6413f138e83f452324f4bf4006c140c4 Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Mon, 6 Nov 2023 08:18:21 +0000 Subject: [PATCH 4/7] Update SAI community submodule pointer to latest master --- SAI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SAI b/SAI index f981a1f61..b4331a048 160000 --- a/SAI +++ b/SAI @@ -1 +1 @@ -Subproject commit f981a1f618ff84c28f75f8185ccad6dd73bf2bb4 +Subproject commit b4331a048ec7f80cdf20304b80894fb011dc7b6e From 0f00097d5acc6320515e748976eb7e7c682505c2 Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Mon, 6 Nov 2023 13:43:23 +0000 Subject: [PATCH 5/7] Update on_port_host_tx_ready function in the right order and removed whitespaces --- lib/Switch.cpp | 2 +- saiplayer/SaiPlayer.cpp | 2 +- saiplayer/SaiPlayer.h | 2 +- syncd/SwitchNotifications.h | 2 +- vslib/Switch.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Switch.cpp b/lib/Switch.cpp index 7094b0e39..4968a0289 100644 --- a/lib/Switch.cpp +++ b/lib/Switch.cpp @@ -121,7 +121,7 @@ void Switch::updateNotifications( case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY: m_switchNotifications.on_port_host_tx_ready = (sai_port_host_tx_ready_notification_fn)attr.value.ptr; - break; + break; default: SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); diff --git a/saiplayer/SaiPlayer.cpp b/saiplayer/SaiPlayer.cpp index 6aefe9893..7649008f0 100644 --- a/saiplayer/SaiPlayer.cpp +++ b/saiplayer/SaiPlayer.cpp @@ -182,7 +182,7 @@ void SaiPlayer::onPortHostTxReady( _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) { SWSS_LOG_ENTER(); - + // empty } diff --git a/saiplayer/SaiPlayer.h b/saiplayer/SaiPlayer.h index 1aeda13c9..10efad7f9 100644 --- a/saiplayer/SaiPlayer.h +++ b/saiplayer/SaiPlayer.h @@ -239,7 +239,7 @@ namespace saiplayer void onBfdSessionStateChange( _In_ uint32_t count, _In_ const sai_bfd_session_state_notification_t *data); - + void onPortHostTxReady( _In_ sai_object_id_t switch_id, _In_ sai_object_id_t port_id, diff --git a/syncd/SwitchNotifications.h b/syncd/SwitchNotifications.h index 013ba60d0..f289936ed 100644 --- a/syncd/SwitchNotifications.h +++ b/syncd/SwitchNotifications.h @@ -94,7 +94,6 @@ namespace syncd .on_switch_state_change = &Slot::onSwitchStateChange, .on_switch_shutdown_request = &Slot::onSwitchShutdownRequest, .on_fdb_event = &Slot::onFdbEvent, - .on_port_host_tx_ready = &Slot::onPortHostTxReady, .on_port_state_change = &Slot::onPortStateChange, .on_packet_event = nullptr, .on_queue_pfc_deadlock = &Slot::onQueuePfcDeadlock, @@ -103,6 +102,7 @@ namespace syncd .on_ipsec_sa_status_change = nullptr, .on_nat_event = &Slot::onNatEvent, .on_switch_asic_sdk_health_event = nullptr, + .on_port_host_tx_ready = &Slot::onPortHostTxReady, .on_twamp_session_event = nullptr, }) { } diff --git a/vslib/Switch.cpp b/vslib/Switch.cpp index fa337a1ee..4c24bc015 100644 --- a/vslib/Switch.cpp +++ b/vslib/Switch.cpp @@ -96,7 +96,7 @@ void Switch::updateNotifications( break; case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY: - m_switchNotifications.on_port_host_tx_ready = + m_switchNotifications.on_port_host_tx_ready = (sai_port_host_tx_ready_notification_fn)attr.value.ptr; break; From 426d73a0a6320ea9af8677a5a298a67bf0bf5cce Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Sun, 12 Nov 2023 08:21:32 +0000 Subject: [PATCH 6/7] Remove try-catch from json parse --- meta/SaiSerialize.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 583780020..158789153 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -4645,16 +4645,7 @@ void sai_deserialize_port_host_tx_ready_ntf( { SWSS_LOG_ENTER(); - json j; - try - { - j = json::parse(s); - } - catch (const std::exception&) - { - SWSS_LOG_ERROR("Recieved an exception after trying to parse %s", s.c_str()); - return; - } + json j = json::parse(s); sai_deserialize_object_id(j[0]["port_id"], port_id); sai_deserialize_object_id(j[0]["switch_id"], switch_id); From fc717d2bd0602caa5cc7f42aa47839a27b15cec3 Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Wed, 15 Nov 2023 11:34:17 +0000 Subject: [PATCH 7/7] Fix typo in UT --- unittest/lib/TestSwitch.cpp | 2 +- unittest/meta/TestNotificationFactory.cpp | 3 +-- unittest/meta/TestNotificationPortHostTxReadyEvent.cpp | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/unittest/lib/TestSwitch.cpp b/unittest/lib/TestSwitch.cpp index 8637bc772..69e04d6a7 100644 --- a/unittest/lib/TestSwitch.cpp +++ b/unittest/lib/TestSwitch.cpp @@ -49,7 +49,7 @@ TEST(Switch, updateNotifications) attrs[8].id = SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY; attrs[9].id = SAI_SWITCH_ATTR_INIT_SWITCH; - s->updateNotifications(8, attrs); + s->updateNotifications(9, attrs); auto sn = s->getSwitchNotifications(); diff --git a/unittest/meta/TestNotificationFactory.cpp b/unittest/meta/TestNotificationFactory.cpp index 8b049d157..66d5938b5 100644 --- a/unittest/meta/TestNotificationFactory.cpp +++ b/unittest/meta/TestNotificationFactory.cpp @@ -50,8 +50,7 @@ TEST(NotificationFactory, deserialize_port_host_tx_ready_status) { auto ntf = NotificationFactory::deserialize( SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY, - "[{\"host_tx_ready_status\":\"SAI_PORT_HOST_TX_READY_STATUS_READY\"}]" - ); + "[{\"host_tx_ready_status\":\"SAI_PORT_HOST_TX_READY_STATUS_READY\",\"port_id\":\"oid:0x100000000001a\",\"switch_id\":\"oid:0x2100000000\"}]"); EXPECT_EQ(ntf->getNotificationType(), SAI_SWITCH_NOTIFICATION_TYPE_PORT_HOST_TX_READY); } diff --git a/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp b/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp index 88afb559f..15c93aa12 100644 --- a/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp +++ b/unittest/meta/TestNotificationPortHostTxReadyEvent.cpp @@ -5,7 +5,7 @@ #include "sairediscommon.h" #include "sai_serialize.h" -#include +#include #include using namespace sairedis; @@ -70,7 +70,7 @@ TEST(NotificationPortHostTxReadyEvent, executeCallback) { NotificationPortHostTxReadyEvent n(s); - sai_switch_notification_t ntfs; + sai_switch_notifications_t ntfs; ntfs.on_port_host_tx_ready_change = &on_port_host_tx_ready_change_notification;