Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SAI Notification support for host_tx_ready #1304

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.cpp"
#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
73 changes: 73 additions & 0 deletions meta/NotificationPortHostTxReadyEvent.cpp
Original file line number Diff line number Diff line change
@@ -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<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;

};
}
77 changes: 77 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,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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 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 Expand Up @@ -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);
Expand Down
Loading
Loading