Skip to content
Merged
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
19 changes: 19 additions & 0 deletions meta/DummySaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,25 @@ void DummySaiInterface::sendNotification(
}
break;

case SAI_SWITCH_ATTR_ICMP_ECHO_SESSION_STATE_CHANGE_NOTIFY:

if (sn.on_icmp_echo_session_state_change)
{
SWSS_LOG_NOTICE("sending sn.on_icmp_echo_session_state_change");

sai_icmp_echo_session_state_notification_t data;

data.icmp_echo_session_id = 0x2;
data.session_state = SAI_ICMP_ECHO_SESSION_STATE_DOWN;

sn.on_icmp_echo_session_state_change(1, &data);
}
else
{
SWSS_LOG_WARN("pointer sn.on_icmp_echo_session_state_change");
}
break;

case SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY:

if (sn.on_twamp_session_event)
Expand Down
1 change: 1 addition & 0 deletions meta/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ libsaimeta_la_SOURCES = \
NotificationSwitchShutdownRequest.cpp \
NotificationSwitchStateChange.cpp \
NotificationBfdSessionStateChange.cpp \
NotificationIcmpEchoSessionStateChange.cpp \
NotificationHaSetEvent.cpp \
NotificationHaScopeEvent.cpp \
NotificationTwampSessionEvent.cpp \
Expand Down
93 changes: 93 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7055,6 +7055,56 @@ void Meta::meta_sai_on_ha_scope_event(
}
}

void Meta::meta_sai_on_icmp_echo_session_state_change_single(
_In_ const sai_icmp_echo_session_state_notification_t& data)
{
SWSS_LOG_ENTER();

auto ot = objectTypeQuery(data.icmp_echo_session_id);

bool valid = isIcmpEchoSessionObjectIdValid(ot);

if(!valid){
SWSS_LOG_ERROR("data.icmp_echo_session_id %s has unexpected type: %s, expected %s",
sai_serialize_object_id(data.icmp_echo_session_id).c_str(),
sai_serialize_object_type(ot).c_str(),
boost::algorithm::join(getValidIcmpEchoSessionObjectTypes(), ",").c_str());
}

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

sai_object_meta_key_t key = { .objecttype = ot, .objectkey = { .key = { .object_id = data.icmp_echo_session_id } } };

m_oids.objectReferenceInsert(data.icmp_echo_session_id);

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

void Meta::meta_sai_on_icmp_echo_session_state_change(
_In_ uint32_t count,
_In_ const sai_icmp_echo_session_state_notification_t *data)
{
SWSS_LOG_ENTER();

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

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

void Meta::meta_sai_on_twamp_session_event_single(
_In_ const sai_twamp_session_event_notification_data_t& data)
{
Expand Down Expand Up @@ -7389,3 +7439,46 @@ std::vector<std::string> Meta::getValidPortObjectTypes()

return v;
}

bool Meta::isIcmpEchoSessionObjectIdValid(
_In_ sai_object_type_t object_type)
{
SWSS_LOG_ENTER();

auto members = sai_metadata_struct_members_sai_icmp_echo_session_state_notification_t;

for (size_t i = 0; members[i]; i++)
{
auto* mb = members[i];

if (mb->membername != std::string("icmp_echo_session_id"))
continue;

for (size_t idx = 0; idx < mb->allowedobjecttypeslength; idx++)
{
if (mb->allowedobjecttypes[idx] == object_type)
return true;
}

return false;
}

SWSS_LOG_THROW("member not found for sai_icmp_echo_session_state_notification_t");
}

std::vector<std::string> Meta::getValidIcmpEchoSessionObjectTypes()
{
SWSS_LOG_ENTER();

auto md = sai_metadata_enum_sai_object_type_t;

std::vector<std::string> v;

for (size_t i = 0; i < md.valuescount; i++)
{
if (isIcmpEchoSessionObjectIdValid((sai_object_type_t)md.values[i]))
v.push_back(md.valuesshortnames[i]);
}

return v;
}
11 changes: 11 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ namespace saimeta
_In_ uint32_t count,
_In_ const sai_bfd_session_state_notification_t *data);

void meta_sai_on_icmp_echo_session_state_change(
_In_ uint32_t count,
_In_ const sai_icmp_echo_session_state_notification_t *data);

void meta_sai_on_ha_set_event(
_In_ uint32_t count,
_In_ const sai_ha_set_event_data_t *data);
Expand Down Expand Up @@ -287,6 +291,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_icmp_echo_session_state_change_single(
_In_ const sai_icmp_echo_session_state_notification_t& data);

void meta_sai_on_ha_set_event_single(
_In_ const sai_ha_set_event_data_t& data);

Expand Down Expand Up @@ -339,7 +346,11 @@ namespace saimeta
static bool isPortObjectIdValid(
_In_ sai_object_type_t object_type);

static bool isIcmpEchoSessionObjectIdValid(
_In_ sai_object_type_t object_type);

static std::vector<std::string> getValidPortObjectTypes();
static std::vector<std::string> getValidIcmpEchoSessionObjectTypes();

private: // unit tests helpers

Expand Down
4 changes: 4 additions & 0 deletions meta/NotificationFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "NotificationSwitchStateChange.h"
#include "NotificationSwitchAsicSdkHealthEvent.h"
#include "NotificationBfdSessionStateChange.h"
#include "NotificationIcmpEchoSessionStateChange.h"
#include "NotificationTwampSessionEvent.h"
#include "NotificationPortHostTxReadyEvent.h"
#include "NotificationTamTelTypeConfigChange.h"
Expand Down Expand Up @@ -51,6 +52,9 @@ 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_ICMP_ECHO_SESSION_STATE_CHANGE)
return std::make_shared<NotificationIcmpEchoSessionStateChange>(serializedNotification);

if (name == SAI_SWITCH_NOTIFICATION_NAME_HA_SET_EVENT)
return std::make_shared<NotificationHaSetEvent>(serializedNotification);

Expand Down
77 changes: 77 additions & 0 deletions meta/NotificationIcmpEchoSessionStateChange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "NotificationIcmpEchoSessionStateChange.h"

#include "swss/logger.h"

#include "meta/sai_serialize.h"

using namespace sairedis;

NotificationIcmpEchoSessionStateChange::NotificationIcmpEchoSessionStateChange(
_In_ const std::string& serializedNotification):
Notification(
SAI_SWITCH_NOTIFICATION_TYPE_ICMP_ECHO_SESSION_STATE_CHANGE,
serializedNotification),
m_icmpEchoSessionStateNotificationData(nullptr)
{
SWSS_LOG_ENTER();

sai_deserialize_icmp_echo_session_state_ntf(
serializedNotification,
m_count,
&m_icmpEchoSessionStateNotificationData);
}

NotificationIcmpEchoSessionStateChange::~NotificationIcmpEchoSessionStateChange()
{
SWSS_LOG_ENTER();

sai_deserialize_free_icmp_echo_session_state_ntf(m_count, m_icmpEchoSessionStateNotificationData);
}

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

// this notification don't contain switch id field

return SAI_NULL_OBJECT_ID;
}

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

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

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

return SAI_NULL_OBJECT_ID;
}

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

meta->meta_sai_on_icmp_echo_session_state_change(m_count, m_icmpEchoSessionStateNotificationData);
}

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

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

#include "Notification.h"

namespace sairedis
{
class NotificationIcmpEchoSessionStateChange:
public Notification
{
public:

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

virtual ~NotificationIcmpEchoSessionStateChange();

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_icmp_echo_session_state_notification_t *m_icmpEchoSessionStateNotificationData;
};
}
Loading
Loading