Skip to content

Commit

Permalink
Add SAI Notification support for host_tx_ready (sonic-net#1307)
Browse files Browse the repository at this point in the history
New PORT_HOST_TX_READY notification logic was added to sonic-sairedis and syncd in order to support host_tx_ready synchronization enhancements.

HLD: sonic-net/SONiC#1453
  • Loading branch information
noaOrMlnx authored Nov 27, 2023
1 parent 9804bd7 commit 4cbbeed
Show file tree
Hide file tree
Showing 24 changed files with 457 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions meta/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ libsaimeta_la_SOURCES = \
NotificationSwitchShutdownRequest.cpp \
NotificationSwitchStateChange.cpp \
NotificationBfdSessionStateChange.cpp \
NotificationPortHostTxReadyEvent.cpp \
NumberOidIndexGenerator.cpp \
OidRefCounter.cpp \
PerformanceIntervalTimer.cpp \
Expand Down
43 changes: 43 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions meta/NotificationFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "NotificationSwitchShutdownRequest.h"
#include "NotificationSwitchStateChange.h"
#include "NotificationBfdSessionStateChange.h"
#include "NotificationPortHostTxReadyEvent.h"
#include "sairediscommon.h"

#include "swss/logger.h"
Expand All @@ -24,6 +25,9 @@ std::shared_ptr<Notification> NotificationFactory::deserialize(
if (name == SAI_SWITCH_NOTIFICATION_NAME_NAT_EVENT)
return std::make_shared<NotificationNatEvent>(serializedNotification);

if (name == SAI_SWITCH_NOTIFICATION_NAME_PORT_HOST_TX_READY)
return std::make_shared<NotificationPortHostTxReady>(serializedNotification);

if (name == SAI_SWITCH_NOTIFICATION_NAME_PORT_STATE_CHANGE)
return std::make_shared<NotificationPortStateChange>(serializedNotification);

Expand Down
60 changes: 60 additions & 0 deletions meta/NotificationPortHostTxReadyEvent.cpp
Original file line number Diff line number Diff line change
@@ -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<saimeta::Meta> 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);
}
}
38 changes: 38 additions & 0 deletions meta/NotificationPortHostTxReadyEvent.h
Original file line number Diff line number Diff line change
@@ -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<saimeta::Meta> 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;

};
}
59 changes: 59 additions & 0 deletions meta/SaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions meta/sai_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions saiplayer/SaiPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions saiplayer/SaiPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<sairedis::SaiInterface> m_sai;
Expand Down
16 changes: 16 additions & 0 deletions syncd/NotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 4cbbeed

Please sign in to comment.