Skip to content

Commit

Permalink
Merge branch 'master' into ledamping_sairedis
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Jan 3, 2024
2 parents 84655fc + c774f13 commit 629934b
Show file tree
Hide file tree
Showing 20 changed files with 558 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ void Switch::updateNotifications(
(sai_port_host_tx_ready_notification_fn)attr.value.ptr;
break;

case SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY:
m_switchNotifications.on_twamp_session_event =
(sai_twamp_session_event_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 \
NotificationTwampSessionEvent.cpp \
NotificationPortHostTxReadyEvent.cpp \
NumberOidIndexGenerator.cpp \
OidRefCounter.cpp \
Expand Down
78 changes: 78 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6729,6 +6729,84 @@ void Meta::meta_sai_on_bfd_session_state_change(
}
}

void Meta::meta_sai_on_twamp_session_event_single(
_In_ const sai_twamp_session_event_notification_data_t& data)
{
SWSS_LOG_ENTER();

auto ot = objectTypeQuery(data.twamp_session_id);

bool valid = false;

switch (ot)
{
// TODO hardcoded types, must advance SAI repository commit to get metadata for this
case SAI_OBJECT_TYPE_TWAMP_SESSION:

valid = true;
break;

default:

SWSS_LOG_ERROR("data.twamp_session_id %s has unexpected type: %s, expected TWAMP_SESSION",
sai_serialize_object_id(data.twamp_session_id).c_str(),
sai_serialize_object_type(ot).c_str());
break;
}

// check if all counter ids are in enum range
for (uint32_t idx = 0; idx < data.session_stats.number_of_counters; idx++)
{
if (!sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_twamp_session_stat_t, data.session_stats.counters_ids[idx]))
{
SWSS_LOG_ERROR("value %d is not in range on sai_twamp_session_stat_t ", data.session_stats.counters_ids[idx]);

return;
}
}

if (valid && !m_oids.objectReferenceExists(data.twamp_session_id))
{
SWSS_LOG_NOTICE("data.twamp_session_id new object spotted %s not present in local DB (snoop!)",
sai_serialize_object_id(data.twamp_session_id).c_str());

sai_object_meta_key_t key = { .objecttype = (sai_object_type_t)ot, .objectkey = { .key = { .object_id = data.twamp_session_id } } };

m_oids.objectReferenceInsert(data.twamp_session_id);

if (!m_saiObjectCollection.objectExists(key))
{
m_saiObjectCollection.createObject(key);
}
}

if (!sai_metadata_get_enum_value_name(
&sai_metadata_enum_sai_twamp_session_state_t,
data.session_state))
{
SWSS_LOG_WARN("session_state value (%d) not found sai_twamp_session_state_t",
data.session_state);
}
}

void Meta::meta_sai_on_twamp_session_event(
_In_ uint32_t count,
_In_ const sai_twamp_session_event_notification_data_t *data)
{
SWSS_LOG_ENTER();

if (count && data == NULL)
{
SWSS_LOG_ERROR("sai_twamp_session_event_notification_data_t pointer is NULL but count is %u", count);
return;
}

for (uint32_t i = 0; i < count; ++i)
{
meta_sai_on_twamp_session_event_single(data[i]);
}
}

int32_t Meta::getObjectReferenceCount(
_In_ sai_object_id_t oid) const
{
Expand Down
7 changes: 7 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ namespace saimeta
_In_ sai_object_id_t switch_id,
_In_ sai_port_host_tx_ready_status_t host_tx_ready_status);

void meta_sai_on_twamp_session_event(
_In_ uint32_t count,
_In_ const sai_twamp_session_event_notification_data_t *data);

private: // notifications helpers

void meta_sai_on_fdb_flush_event_consolidated(
Expand All @@ -248,6 +252,9 @@ namespace saimeta
void meta_sai_on_bfd_session_state_change_single(
_In_ const sai_bfd_session_state_notification_t& data);

void meta_sai_on_twamp_session_event_single(
_In_ const sai_twamp_session_event_notification_data_t& data);

private: // validation helpers

sai_status_t meta_generic_validation_objlist(
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 "NotificationTwampSessionEvent.h"
#include "NotificationPortHostTxReadyEvent.h"
#include "sairediscommon.h"

Expand Down Expand Up @@ -43,5 +44,8 @@ std::shared_ptr<Notification> NotificationFactory::deserialize(
if (name == SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE)
return std::make_shared<NotificationBfdSessionStateChange>(serializedNotification);

if (name == SAI_SWITCH_NOTIFICATION_NAME_TWAMP_SESSION_EVENT)
return std::make_shared<NotificationTwampSessionEvent>(serializedNotification);

SWSS_LOG_THROW("unknown notification: '%s', FIXME", name.c_str());
}
77 changes: 77 additions & 0 deletions meta/NotificationTwampSessionEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "NotificationTwampSessionEvent.h"

#include "swss/logger.h"

#include "meta/sai_serialize.h"

using namespace sairedis;

NotificationTwampSessionEvent::NotificationTwampSessionEvent(
_In_ const std::string& serializedNotification):
Notification(
SAI_SWITCH_NOTIFICATION_TYPE_TWAMP_SESSION_EVENT,
serializedNotification),
m_twampSessionEventNotificationData(nullptr)
{
SWSS_LOG_ENTER();

sai_deserialize_twamp_session_event_ntf(
serializedNotification,
m_count,
&m_twampSessionEventNotificationData);
}

NotificationTwampSessionEvent::~NotificationTwampSessionEvent()
{
SWSS_LOG_ENTER();

sai_deserialize_free_twamp_session_event_ntf(m_count, m_twampSessionEventNotificationData);
}

sai_object_id_t NotificationTwampSessionEvent::getSwitchId() const
{
SWSS_LOG_ENTER();

// this notification don't contain switch id field

return SAI_NULL_OBJECT_ID;
}

sai_object_id_t NotificationTwampSessionEvent::getAnyObjectId() const
{
SWSS_LOG_ENTER();

if (m_twampSessionEventNotificationData == nullptr)
{
return SAI_NULL_OBJECT_ID;
}

for (uint32_t idx = 0; idx < m_count; idx++)
{
if (m_twampSessionEventNotificationData[idx].twamp_session_id != SAI_NULL_OBJECT_ID)
{
return m_twampSessionEventNotificationData[idx].twamp_session_id;
}
}

return SAI_NULL_OBJECT_ID;
}

void NotificationTwampSessionEvent::processMetadata(
_In_ std::shared_ptr<saimeta::Meta> meta) const
{
SWSS_LOG_ENTER();

meta->meta_sai_on_twamp_session_event(m_count, m_twampSessionEventNotificationData);
}

void NotificationTwampSessionEvent::executeCallback(
_In_ const sai_switch_notifications_t& switchNotifications) const
{
SWSS_LOG_ENTER();

if (switchNotifications.on_twamp_session_event)
{
switchNotifications.on_twamp_session_event(m_count, m_twampSessionEventNotificationData);
}
}
35 changes: 35 additions & 0 deletions meta/NotificationTwampSessionEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "Notification.h"

namespace sairedis
{
class NotificationTwampSessionEvent:
public Notification
{
public:

NotificationTwampSessionEvent(
_In_ const std::string& serializedNotification);

virtual ~NotificationTwampSessionEvent();

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:

uint32_t m_count;

sai_twamp_session_event_notification_data_t *m_twampSessionEventNotificationData;
};
}
Loading

0 comments on commit 629934b

Please sign in to comment.