Skip to content

Commit dbf8408

Browse files
committed
Support TWAMP Light notification in syncd (#1306)
Signed-off-by: yoush <[email protected]>
1 parent 7acd028 commit dbf8408

17 files changed

+508
-10
lines changed

lib/Switch.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ void Switch::updateNotifications(
118118
(sai_bfd_session_state_change_notification_fn)attr.value.ptr;
119119
break;
120120

121+
case SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY:
122+
m_switchNotifications.on_twamp_session_event =
123+
(sai_twamp_session_event_notification_fn)attr.value.ptr;
124+
break;
125+
121126
default:
122127
SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname);
123128
break;

meta/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ libsaimeta_la_SOURCES = \
3535
NotificationSwitchShutdownRequest.cpp \
3636
NotificationSwitchStateChange.cpp \
3737
NotificationBfdSessionStateChange.cpp \
38+
NotificationTwampSessionEvent.cpp \
3839
NumberOidIndexGenerator.cpp \
3940
OidRefCounter.cpp \
4041
PerformanceIntervalTimer.cpp \

meta/Meta.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -6686,6 +6686,84 @@ void Meta::meta_sai_on_bfd_session_state_change(
66866686
}
66876687
}
66886688

6689+
void Meta::meta_sai_on_twamp_session_event_single(
6690+
_In_ const sai_twamp_session_event_notification_data_t& data)
6691+
{
6692+
SWSS_LOG_ENTER();
6693+
6694+
auto ot = objectTypeQuery(data.twamp_session_id);
6695+
6696+
bool valid = false;
6697+
6698+
switch (ot)
6699+
{
6700+
// TODO hardcoded types, must advance SAI repository commit to get metadata for this
6701+
case SAI_OBJECT_TYPE_TWAMP_SESSION:
6702+
6703+
valid = true;
6704+
break;
6705+
6706+
default:
6707+
6708+
SWSS_LOG_ERROR("data.twamp_session_id %s has unexpected type: %s, expected TWAMP_SESSION",
6709+
sai_serialize_object_id(data.twamp_session_id).c_str(),
6710+
sai_serialize_object_type(ot).c_str());
6711+
break;
6712+
}
6713+
6714+
// check if all counter ids are in enum range
6715+
for (uint32_t idx = 0; idx < data.session_stats.number_of_counters; idx++)
6716+
{
6717+
if (!sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_twamp_session_stat_t, data.session_stats.counters_ids[idx]))
6718+
{
6719+
SWSS_LOG_ERROR("value %d is not in range on sai_twamp_session_stat_t ", data.session_stats.counters_ids[idx]);
6720+
6721+
return;
6722+
}
6723+
}
6724+
6725+
if (valid && !m_oids.objectReferenceExists(data.twamp_session_id))
6726+
{
6727+
SWSS_LOG_NOTICE("data.twamp_session_id new object spotted %s not present in local DB (snoop!)",
6728+
sai_serialize_object_id(data.twamp_session_id).c_str());
6729+
6730+
sai_object_meta_key_t key = { .objecttype = (sai_object_type_t)ot, .objectkey = { .key = { .object_id = data.twamp_session_id } } };
6731+
6732+
m_oids.objectReferenceInsert(data.twamp_session_id);
6733+
6734+
if (!m_saiObjectCollection.objectExists(key))
6735+
{
6736+
m_saiObjectCollection.createObject(key);
6737+
}
6738+
}
6739+
6740+
if (!sai_metadata_get_enum_value_name(
6741+
&sai_metadata_enum_sai_twamp_session_state_t,
6742+
data.session_state))
6743+
{
6744+
SWSS_LOG_WARN("session_state value (%d) not found sai_twamp_session_state_t",
6745+
data.session_state);
6746+
}
6747+
}
6748+
6749+
void Meta::meta_sai_on_twamp_session_event(
6750+
_In_ uint32_t count,
6751+
_In_ const sai_twamp_session_event_notification_data_t *data)
6752+
{
6753+
SWSS_LOG_ENTER();
6754+
6755+
if (count && data == NULL)
6756+
{
6757+
SWSS_LOG_ERROR("sai_twamp_session_event_notification_data_t pointer is NULL but count is %u", count);
6758+
return;
6759+
}
6760+
6761+
for (uint32_t i = 0; i < count; ++i)
6762+
{
6763+
meta_sai_on_twamp_session_event_single(data[i]);
6764+
}
6765+
}
6766+
66896767
int32_t Meta::getObjectReferenceCount(
66906768
_In_ sai_object_id_t oid) const
66916769
{

meta/Meta.h

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ namespace saimeta
220220
_In_ uint32_t count,
221221
_In_ const sai_bfd_session_state_notification_t *data);
222222

223+
void meta_sai_on_twamp_session_event(
224+
_In_ uint32_t count,
225+
_In_ const sai_twamp_session_event_notification_data_t *data);
226+
223227
private: // notifications helpers
224228

225229
void meta_sai_on_fdb_flush_event_consolidated(
@@ -243,6 +247,9 @@ namespace saimeta
243247
void meta_sai_on_bfd_session_state_change_single(
244248
_In_ const sai_bfd_session_state_notification_t& data);
245249

250+
void meta_sai_on_twamp_session_event_single(
251+
_In_ const sai_twamp_session_event_notification_data_t& data);
252+
246253
private: // validation helpers
247254

248255
sai_status_t meta_generic_validation_objlist(

meta/NotificationFactory.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "NotificationSwitchShutdownRequest.h"
77
#include "NotificationSwitchStateChange.h"
88
#include "NotificationBfdSessionStateChange.h"
9+
#include "NotificationTwampSessionEvent.h"
910
#include "sairediscommon.h"
1011

1112
#include "swss/logger.h"
@@ -39,5 +40,8 @@ std::shared_ptr<Notification> NotificationFactory::deserialize(
3940
if (name == SAI_SWITCH_NOTIFICATION_NAME_BFD_SESSION_STATE_CHANGE)
4041
return std::make_shared<NotificationBfdSessionStateChange>(serializedNotification);
4142

43+
if (name == SAI_SWITCH_NOTIFICATION_NAME_TWAMP_SESSION_EVENT)
44+
return std::make_shared<NotificationTwampSessionEvent>(serializedNotification);
45+
4246
SWSS_LOG_THROW("unknown notification: '%s', FIXME", name.c_str());
4347
}
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "NotificationTwampSessionEvent.h"
2+
3+
#include "swss/logger.h"
4+
5+
#include "meta/sai_serialize.h"
6+
7+
using namespace sairedis;
8+
9+
NotificationTwampSessionEvent::NotificationTwampSessionEvent(
10+
_In_ const std::string& serializedNotification):
11+
Notification(
12+
SAI_SWITCH_NOTIFICATION_TYPE_TWAMP_SESSION_EVENT,
13+
serializedNotification),
14+
m_twampSessionEventNotificationData(nullptr)
15+
{
16+
SWSS_LOG_ENTER();
17+
18+
sai_deserialize_twamp_session_event_ntf(
19+
serializedNotification,
20+
m_count,
21+
&m_twampSessionEventNotificationData);
22+
}
23+
24+
NotificationTwampSessionEvent::~NotificationTwampSessionEvent()
25+
{
26+
SWSS_LOG_ENTER();
27+
28+
sai_deserialize_free_twamp_session_event_ntf(m_count, m_twampSessionEventNotificationData);
29+
}
30+
31+
sai_object_id_t NotificationTwampSessionEvent::getSwitchId() const
32+
{
33+
SWSS_LOG_ENTER();
34+
35+
// this notification don't contain switch id field
36+
37+
return SAI_NULL_OBJECT_ID;
38+
}
39+
40+
sai_object_id_t NotificationTwampSessionEvent::getAnyObjectId() const
41+
{
42+
SWSS_LOG_ENTER();
43+
44+
if (m_twampSessionEventNotificationData == nullptr)
45+
{
46+
return SAI_NULL_OBJECT_ID;
47+
}
48+
49+
for (uint32_t idx = 0; idx < m_count; idx++)
50+
{
51+
if (m_twampSessionEventNotificationData[idx].twamp_session_id != SAI_NULL_OBJECT_ID)
52+
{
53+
return m_twampSessionEventNotificationData[idx].twamp_session_id;
54+
}
55+
}
56+
57+
return SAI_NULL_OBJECT_ID;
58+
}
59+
60+
void NotificationTwampSessionEvent::processMetadata(
61+
_In_ std::shared_ptr<saimeta::Meta> meta) const
62+
{
63+
SWSS_LOG_ENTER();
64+
65+
meta->meta_sai_on_twamp_session_event(m_count, m_twampSessionEventNotificationData);
66+
}
67+
68+
void NotificationTwampSessionEvent::executeCallback(
69+
_In_ const sai_switch_notifications_t& switchNotifications) const
70+
{
71+
SWSS_LOG_ENTER();
72+
73+
if (switchNotifications.on_twamp_session_event)
74+
{
75+
switchNotifications.on_twamp_session_event(m_count, m_twampSessionEventNotificationData);
76+
}
77+
}

meta/NotificationTwampSessionEvent.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include "Notification.h"
4+
5+
namespace sairedis
6+
{
7+
class NotificationTwampSessionEvent:
8+
public Notification
9+
{
10+
public:
11+
12+
NotificationTwampSessionEvent(
13+
_In_ const std::string& serializedNotification);
14+
15+
virtual ~NotificationTwampSessionEvent();
16+
17+
public:
18+
19+
virtual sai_object_id_t getSwitchId() const override;
20+
21+
virtual sai_object_id_t getAnyObjectId() const override;
22+
23+
virtual void processMetadata(
24+
_In_ std::shared_ptr<saimeta::Meta> meta) const override;
25+
26+
virtual void executeCallback(
27+
_In_ const sai_switch_notifications_t& switchNotifications) const override;
28+
29+
private:
30+
31+
uint32_t m_count;
32+
33+
sai_twamp_session_event_notification_data_t *m_twampSessionEventNotificationData;
34+
};
35+
}

0 commit comments

Comments
 (0)