diff --git a/SAI b/SAI index f981a1f61..b4331a048 160000 --- a/SAI +++ b/SAI @@ -1 +1 @@ -Subproject commit f981a1f618ff84c28f75f8185ccad6dd73bf2bb4 +Subproject commit b4331a048ec7f80cdf20304b80894fb011dc7b6e diff --git a/lib/Switch.cpp b/lib/Switch.cpp index c7af4a297..4968a0289 100644 --- a/lib/Switch.cpp +++ b/lib/Switch.cpp @@ -118,6 +118,11 @@ 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/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 db1c6cc71..b9d03a3a2 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -6434,6 +6434,49 @@ 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. Dropping the notification", + host_tx_ready_status); + + return; + } + + auto ot = objectTypeQuery(port_id); + + 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()); + return; + } + + 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()); + + 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..456af8891 100644 --- a/meta/NotificationFactory.cpp +++ b/meta/NotificationFactory.cpp @@ -6,6 +6,7 @@ #include "NotificationSwitchShutdownRequest.h" #include "NotificationSwitchStateChange.h" #include "NotificationBfdSessionStateChange.h" +#include "NotificationPortHostTxReadyEvent.h" #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..d1a2ecc52 --- /dev/null +++ b/meta/NotificationPortHostTxReadyEvent.cpp @@ -0,0 +1,60 @@ +#include "NotificationPortHostTxReadyEvent.h" + +#include "swss/logger.h" + +#include "sai_serialize.h" + +using namespace sairedis; + +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_object_id_t NotificationPortHostTxReady::getSwitchId() const +{ + SWSS_LOG_ENTER(); + + return m_switchId; +} + +sai_object_id_t NotificationPortHostTxReady::getAnyObjectId() const +{ + SWSS_LOG_ENTER(); + + return m_portId; +} + +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..9f46c33f9 --- /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; + + }; +} diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index af039526f..158789153 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,25 @@ 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 +3926,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 +4637,21 @@ 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 = json::parse(s); + + 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, diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index ea6a52404..7d53c11cc 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( diff --git a/saiplayer/SaiPlayer.cpp b/saiplayer/SaiPlayer.cpp index 6e22de110..7649008f0 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..10efad7f9 100644 --- a/saiplayer/SaiPlayer.h +++ b/saiplayer/SaiPlayer.h @@ -240,6 +240,11 @@ namespace saiplayer _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: std::shared_ptr m_sai; 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..ccdfdb02d 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 %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 %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()); + + 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,20 @@ 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); +} + void NotificationProcessor::handle_bfd_session_state_change( _In_ const std::string &data) { @@ -685,6 +721,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..f289936ed 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, @@ -95,7 +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 = nullptr, + .on_port_host_tx_ready = &Slot::onPortHostTxReady, .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/unittest/lib/TestSwitch.cpp b/unittest/lib/TestSwitch.cpp index 0969095e1..69e04d6a7 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,9 +46,10 @@ 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); + s->updateNotifications(9, attrs); auto sn = s->getSwitchNotifications(); @@ -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..66d5938b5 100644 --- a/unittest/meta/TestNotificationFactory.cpp +++ b/unittest/meta/TestNotificationFactory.cpp @@ -46,6 +46,15 @@ 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\",\"port_id\":\"oid:0x100000000001a\",\"switch_id\":\"oid:0x2100000000\"}]"); + + 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..15c93aa12 --- /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_notifications_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), diff --git a/vslib/Switch.cpp b/vslib/Switch.cpp index 874f7767a..4c24bc015 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;