From 54c7c6ab9aed6c467854e8fed9756a286de547f5 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 10 Oct 2024 16:18:58 +0200 Subject: [PATCH 1/5] [submodule] Update SAI to latest master Add changes to handle new data types --- SAI | 2 +- lib/Recorder.h | 79 ++++---------------------- meta/Meta.cpp | 38 +++++++++++++ meta/Meta.h | 10 ++++ meta/SaiInterface.cpp | 39 +++++++++++++ meta/SaiInterface.h | 51 ++++++++--------- meta/SaiSerialize.cpp | 60 ++++++++++++++++++++ meta/sai_serialize.h | 17 ++++++ syncd/VendorSai.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 325 insertions(+), 99 deletions(-) diff --git a/SAI b/SAI index 684a8ee78..9fee2f610 160000 --- a/SAI +++ b/SAI @@ -1 +1 @@ -Subproject commit 684a8ee78d4f7393e355ddc4bf1181f8aa57708e +Subproject commit 9fee2f610cf63e0bf8c880108add94f8fbca6a4e diff --git a/lib/Recorder.h b/lib/Recorder.h index 920ee0c7f..da1f8fe7e 100644 --- a/lib/Recorder.h +++ b/lib/Recorder.h @@ -7,27 +7,28 @@ extern "C" { #include "swss/table.h" #include "sairedis.h" +#include "meta/SaiInterface.h" #include #include #include -#define SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(ot) \ - void recordRemove( \ +#define SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(X,ot) \ + void recordRemove( \ _In_ const sai_ ## ot ## _t* ot); -#define SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(ot) \ +#define SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(X,ot) \ void recordCreate( \ _In_ const sai_ ## ot ## _t* ot, \ _In_ uint32_t attr_count, \ _In_ const sai_attribute_t *attr_list); -#define SAI_REDIS_RECORDER_DECLARE_RECORD_SET(ot) \ +#define SAI_REDIS_RECORDER_DECLARE_RECORD_SET(X,ot) \ void recordSet( \ _In_ const sai_ ## ot ## _t* ot, \ _In_ const sai_attribute_t *attr); -#define SAI_REDIS_RECORDER_DECLARE_RECORD_GET(ot) \ +#define SAI_REDIS_RECORDER_DECLARE_RECORD_GET(X,ot) \ void recordGet( \ _In_ const sai_ ## ot ## _t* ot, \ _In_ uint32_t attr_count, \ @@ -162,79 +163,19 @@ namespace sairedis public: // create ENTRY - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(inseg_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(ipmc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(l2mc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(mcast_fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(neighbor_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(route_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(nat_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(my_sid_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(direction_lookup_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(eni_ether_address_map_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(vip_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(inbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(pa_validation_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(outbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(outbound_ca_to_pa_entry); + SAIREDIS_DECLARE_EVERY_ENTRY(SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE); public: // remove ENTRY - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(inseg_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(ipmc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(l2mc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(mcast_fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(neighbor_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(route_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(nat_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(my_sid_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(direction_lookup_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(eni_ether_address_map_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(vip_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(inbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(pa_validation_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(outbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(outbound_ca_to_pa_entry); + SAIREDIS_DECLARE_EVERY_ENTRY(SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE); public: // set ENTRY - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(inseg_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(ipmc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(l2mc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(mcast_fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(neighbor_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(route_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(nat_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(my_sid_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(direction_lookup_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(eni_ether_address_map_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(vip_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(inbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(pa_validation_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(outbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_SET(outbound_ca_to_pa_entry); + SAIREDIS_DECLARE_EVERY_ENTRY(SAI_REDIS_RECORDER_DECLARE_RECORD_SET); public: // get ENTRY - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(inseg_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(ipmc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(l2mc_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(mcast_fdb_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(neighbor_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(route_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(nat_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(my_sid_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(direction_lookup_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(eni_ether_address_map_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(vip_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(inbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(pa_validation_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(outbound_routing_entry); - SAI_REDIS_RECORDER_DECLARE_RECORD_GET(outbound_ca_to_pa_entry); + SAIREDIS_DECLARE_EVERY_ENTRY(SAI_REDIS_RECORDER_DECLARE_RECORD_GET); public: // SAI stats API diff --git a/meta/Meta.cpp b/meta/Meta.cpp index bd3f1b010..a9851d201 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -3116,6 +3116,44 @@ sai_status_t Meta::meta_sai_validate_outbound_ca_to_pa_entry( return SAI_STATUS_SUCCESS; } +sai_status_t Meta::meta_sai_validate_flow_entry( + _In_ const sai_flow_entry_t* flow_entry, + _In_ bool create, + _In_ bool get) +{ + SWSS_LOG_ENTER(); + + if (flow_entry == NULL) + { + SWSS_LOG_ERROR("flow_entry pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + // TODO FIX ME + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +sai_status_t Meta::meta_sai_validate_meter_bucket_entry( + _In_ const sai_meter_bucket_entry_t* meter_bucket_entry, + _In_ bool create, + _In_ bool get) +{ + SWSS_LOG_ENTER(); + + if (meter_bucket_entry == NULL) + { + SWSS_LOG_ERROR("meter_bucket_entry pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + // TODO FIX ME + + return SAI_STATUS_NOT_IMPLEMENTED; +} + sai_status_t Meta::meta_generic_validation_create( _In_ const sai_object_meta_key_t& meta_key, _In_ sai_object_id_t switch_id, diff --git a/meta/Meta.h b/meta/Meta.h index 12dbf3aa7..ce8a0a2dd 100644 --- a/meta/Meta.h +++ b/meta/Meta.h @@ -553,6 +553,16 @@ namespace saimeta _In_ bool create, _In_ bool get = false); + sai_status_t meta_sai_validate_flow_entry( + _In_ const sai_flow_entry_t* flow_entry, + _In_ bool create, + _In_ bool get = false); + + sai_status_t meta_sai_validate_meter_bucket_entry( + _In_ const sai_meter_bucket_entry_t* meter_bucket_entry, + _In_ bool create, + _In_ bool get = false); + public: /* diff --git a/meta/SaiInterface.cpp b/meta/SaiInterface.cpp index a07e97d4f..3a95bc017 100644 --- a/meta/SaiInterface.cpp +++ b/meta/SaiInterface.cpp @@ -339,3 +339,42 @@ sai_log_level_t SaiInterface::logGet( return SAI_LOG_LEVEL_NOTICE; } + +sai_status_t SaiInterface::getStats( + _In_ const sai_meter_bucket_entry_t* entry, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids, + _Out_ uint64_t *counters) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_ERROR("not implemented"); + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +sai_status_t SaiInterface::getStatsExt( + _In_ const sai_meter_bucket_entry_t* entry, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids, + _In_ sai_stats_mode_t mode, + _Out_ uint64_t *counters) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_ERROR("not implemented"); + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +sai_status_t SaiInterface::clearStats( + _In_ const sai_meter_bucket_entry_t* entry, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids) +{ + SWSS_LOG_ENTER(); + + SWSS_LOG_ERROR("not implemented"); + + return SAI_STATUS_NOT_IMPLEMENTED; +} diff --git a/meta/SaiInterface.h b/meta/SaiInterface.h index d45e0b974..fb78e1569 100644 --- a/meta/SaiInterface.h +++ b/meta/SaiInterface.h @@ -6,37 +6,10 @@ extern "C" { } #define SAIREDIS_DECLARE_EVERY_ENTRY(_X) \ - _X(FDB_ENTRY,fdb_entry); \ - _X(INSEG_ENTRY,inseg_entry); \ - _X(IPMC_ENTRY,ipmc_entry); \ - _X(L2MC_ENTRY,l2mc_entry); \ - _X(MCAST_FDB_ENTRY,mcast_fdb_entry); \ - _X(NEIGHBOR_ENTRY,neighbor_entry); \ - _X(ROUTE_ENTRY,route_entry); \ - _X(NAT_ENTRY,nat_entry); \ - _X(MY_SID_ENTRY,my_sid_entry); \ - _X(DIRECTION_LOOKUP_ENTRY,direction_lookup_entry); \ - _X(ENI_ETHER_ADDRESS_MAP_ENTRY,eni_ether_address_map_entry); \ - _X(VIP_ENTRY,vip_entry); \ - _X(INBOUND_ROUTING_ENTRY,inbound_routing_entry); \ - _X(PA_VALIDATION_ENTRY,pa_validation_entry); \ - _X(OUTBOUND_ROUTING_ENTRY,outbound_routing_entry); \ - _X(OUTBOUND_CA_TO_PA_ENTRY,outbound_ca_to_pa_entry); \ + SAI_METADATA_DECLARE_EVERY_ENTRY(_X) #define SAIREDIS_DECLARE_EVERY_BULK_ENTRY(_X) \ - _X(FDB_ENTRY,fdb_entry); \ - _X(INSEG_ENTRY,inseg_entry); \ - _X(NAT_ENTRY,nat_entry); \ - _X(ROUTE_ENTRY,route_entry); \ - _X(MY_SID_ENTRY,my_sid_entry); \ - _X(NEIGHBOR_ENTRY,neighbor_entry); \ - _X(DIRECTION_LOOKUP_ENTRY,direction_lookup_entry); \ - _X(ENI_ETHER_ADDRESS_MAP_ENTRY,eni_ether_address_map_entry); \ - _X(VIP_ENTRY,vip_entry); \ - _X(INBOUND_ROUTING_ENTRY,inbound_routing_entry); \ - _X(PA_VALIDATION_ENTRY,pa_validation_entry); \ - _X(OUTBOUND_ROUTING_ENTRY,outbound_routing_entry); \ - _X(OUTBOUND_CA_TO_PA_ENTRY,outbound_ca_to_pa_entry); \ + SAI_METADATA_DECLARE_EVERY_BULK_ENTRY(_X) #define SAIREDIS_SAIINTERFACE_DECLARE_QUAD_ENTRY_VIRTUAL(OT,ot) \ virtual sai_status_t create( \ @@ -274,6 +247,26 @@ namespace sairedis _In_ sai_stats_mode_t mode, _Inout_ sai_status_t *object_statuses) = 0; + public: // entry stats + + virtual sai_status_t getStats( + _In_ const sai_meter_bucket_entry_t* entry, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids, + _Out_ uint64_t *counters); + + virtual sai_status_t getStatsExt( + _In_ const sai_meter_bucket_entry_t* entry, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids, + _In_ sai_stats_mode_t mode, + _Out_ uint64_t *counters); + + virtual sai_status_t clearStats( + _In_ const sai_meter_bucket_entry_t* entry, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids); + public: // non QUAD API virtual sai_status_t flushFdbEntries( diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index dd268f26a..146b8b84e 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -961,6 +961,26 @@ std::string sai_serialize_fdb_entry( return j.dump(); } +__attribute__((__noreturn__)) std::string sai_serialize_meter_bucket_entry( + _In_ const sai_meter_bucket_entry_t &meter_bucket_entry) +{ + SWSS_LOG_ENTER(); + + json j; + + SWSS_LOG_THROW("not implemented, FIXME"); +} + +__attribute__((__noreturn__)) std::string sai_serialize_flow_entry( + _In_ const sai_flow_entry_t &flow_entry) +{ + SWSS_LOG_ENTER(); + + json j; + + SWSS_LOG_THROW("not implemented, FIXME"); +} + std::string sai_serialize_l2mc_entry_type( _In_ const sai_l2mc_entry_type_t type) { @@ -2180,6 +2200,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_error_status( + _In_ sai_port_error_status_t status) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(status, &sai_metadata_enum_sai_port_error_status_t); +} + std::string sai_serialize_port_host_tx_ready( _In_ sai_port_host_tx_ready_status_t host_tx_ready_status) { @@ -4152,6 +4180,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_error_status( + _In_ const std::string& s, + _Out_ sai_port_error_status_t& status) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_enum(s, &sai_metadata_enum_sai_port_error_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) @@ -4379,6 +4416,28 @@ void sai_deserialize_neighbor_entry( sai_deserialize_ip_address(j["ip"], ne.ip_address); } +__attribute__((__noreturn__)) void sai_deserialize_meter_bucket_entry( + _In_ const std::string& s, + _Out_ sai_meter_bucket_entry_t& meter_bucket_entry) +{ + SWSS_LOG_ENTER(); + + json j = json::parse(s); + + SWSS_LOG_THROW("not implemented, FIXME"); +} + +__attribute__((__noreturn__)) void sai_deserialize_flow_entry( + _In_ const std::string& s, + _Out_ sai_flow_entry_t &flow_entry) +{ + SWSS_LOG_ENTER(); + + json j = json::parse(s); + + SWSS_LOG_THROW("not implemented, FIXME"); +} + void sai_deserialize_twamp_session_stats_data( _In_ const std::string& s, _Out_ sai_twamp_session_stats_data_t &twamp_session_stats_data) @@ -4990,6 +5049,7 @@ void sai_deserialize_port_oper_status_ntf( { sai_deserialize_object_id(j[i]["port_id"], data[i].port_id); sai_deserialize_port_oper_status(j[i]["port_state"], data[i].port_state); + sai_deserialize_port_error_status(j[i]["port_error_status"], data[i].port_error_status); } *port_oper_status = data; diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index d74d753e7..ed7eb91dc 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -69,6 +69,12 @@ std::string sai_serialize_mcast_fdb_entry( std::string sai_serialize_fdb_entry( _In_ const sai_fdb_entry_t &fdb_entry); +std::string sai_serialize_meter_bucket_entry( + _In_ const sai_meter_bucket_entry_t &meter_bucket_entry); + +std::string sai_serialize_flow_entry( + _In_ const sai_flow_entry_t &flow_entry); + std::string sai_serialize_vlan_id( _In_ const sai_vlan_id_t vlan_id); @@ -252,6 +258,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_error_status( + _In_ sai_port_error_status_t status); + std::string sai_serialize_port_host_tx_ready( _In_ sai_port_host_tx_ready_status_t host_tx_ready_status); @@ -427,6 +436,14 @@ void sai_deserialize_mcast_fdb_entry( _In_ const std::string& s, _In_ sai_mcast_fdb_entry_t &mcast_fdb_entry); +void sai_deserialize_meter_bucket_entry( + _In_ const std::string& s, + _Out_ sai_meter_bucket_entry_t& meter_bucket_entry); + +void sai_deserialize_flow_entry( + _In_ const std::string& s, + _Out_ sai_flow_entry_t &flow_entry); + void sai_deserialize_vlan_id( _In_ const std::string& s, _In_ sai_vlan_id_t& vlan_id); diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index db8aba66b..ed4580df2 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -998,6 +998,60 @@ sai_status_t VendorSai::bulkCreate( object_statuses); } +sai_status_t VendorSai::bulkCreate( + _In_ uint32_t object_count, + _In_ const sai_flow_entry_t* entries, + _In_ const uint32_t *attr_count, + _In_ const sai_attribute_t **attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + if (!m_apis.dash_flow_api->create_flow_entries) + { + SWSS_LOG_INFO("create_flow_entries is not supported"); + return SAI_STATUS_NOT_SUPPORTED; + } + + return m_apis.dash_flow_api->create_flow_entries( + object_count, + entries, + attr_count, + attr_list, + mode, + object_statuses); +} + +sai_status_t VendorSai::bulkCreate( + _In_ uint32_t object_count, + _In_ const sai_meter_bucket_entry_t* entries, + _In_ const uint32_t *attr_count, + _In_ const sai_attribute_t **attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + if (!m_apis.dash_meter_api->create_meter_bucket_entries) + { + SWSS_LOG_INFO("create_meter_bucket_entries is not supported"); + return SAI_STATUS_NOT_SUPPORTED; + } + + return m_apis.dash_meter_api->create_meter_bucket_entries( + object_count, + entries, + attr_count, + attr_list, + mode, + object_statuses); +} + // BULK REMOVE sai_status_t VendorSai::bulkRemove( @@ -1300,6 +1354,52 @@ sai_status_t VendorSai::bulkRemove( object_statuses); } +sai_status_t VendorSai::bulkRemove( + _In_ uint32_t object_count, + _In_ const sai_flow_entry_t *entries, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + if (!m_apis.dash_flow_api->remove_flow_entries) + { + SWSS_LOG_INFO("remove_flow_entries is not supported"); + return SAI_STATUS_NOT_SUPPORTED; + } + + return m_apis.dash_flow_api->remove_flow_entries( + object_count, + entries, + mode, + object_statuses); +} + +sai_status_t VendorSai::bulkRemove( + _In_ uint32_t object_count, + _In_ const sai_meter_bucket_entry_t *entries, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + if (!m_apis.dash_meter_api->remove_meter_bucket_entries) + { + SWSS_LOG_INFO("remove_meter_bucket_entries is not supported"); + return SAI_STATUS_NOT_SUPPORTED; + } + + return m_apis.dash_meter_api->remove_meter_bucket_entries( + object_count, + entries, + mode, + object_statuses); +} + // BULK SET sai_status_t VendorSai::bulkSet( @@ -1550,6 +1650,34 @@ sai_status_t VendorSai::bulkSet( return SAI_STATUS_NOT_SUPPORTED; } +sai_status_t VendorSai::bulkSet( + _In_ uint32_t object_count, + _In_ const sai_flow_entry_t *entries, + _In_ const sai_attribute_t *attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + return SAI_STATUS_NOT_SUPPORTED; +} + +sai_status_t VendorSai::bulkSet( + _In_ uint32_t object_count, + _In_ const sai_meter_bucket_entry_t *entries, + _In_ const sai_attribute_t *attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + return SAI_STATUS_NOT_SUPPORTED; +} + // NON QUAD API sai_status_t VendorSai::flushFdbEntries( From 98d7875cd24b46a53c853d69e52431f311c509e2 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 10 Oct 2024 17:03:05 +0200 Subject: [PATCH 2/5] Update swig bindings --- pyext/pysairedis.i | 1 + 1 file changed, 1 insertion(+) diff --git a/pyext/pysairedis.i b/pyext/pysairedis.i index 92ced0421..32e76518a 100644 --- a/pyext/pysairedis.i +++ b/pyext/pysairedis.i @@ -10,6 +10,7 @@ extern "C"{ #include "sai.h" #include "saiextensions.h" +#include "saimetadata.h" } #include "sairedis.h" From 1327b05196442d3517ebc96763268f970d0272c4 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 10 Oct 2024 18:30:11 +0200 Subject: [PATCH 3/5] Add missing serialize methods and fix tests --- meta/SaiSerialize.cpp | 54 ++++++++++++++++--- unittest/meta/TestNotificationFactory.cpp | 2 +- .../meta/TestNotificationPortStateChange.cpp | 4 +- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 146b8b84e..de9c28a66 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -961,24 +961,37 @@ std::string sai_serialize_fdb_entry( return j.dump(); } -__attribute__((__noreturn__)) std::string sai_serialize_meter_bucket_entry( +std::string sai_serialize_meter_bucket_entry( _In_ const sai_meter_bucket_entry_t &meter_bucket_entry) { SWSS_LOG_ENTER(); json j; - SWSS_LOG_THROW("not implemented, FIXME"); + j["switch_id"] = sai_serialize_object_id(meter_bucket_entry.switch_id); + j["eni_id"] = sai_serialize_object_id(meter_bucket_entry.eni_id); + j["meter_class"] = sai_serialize_number(meter_bucket_entry.meter_class); + + return j.dump(); } -__attribute__((__noreturn__)) std::string sai_serialize_flow_entry( +std::string sai_serialize_flow_entry( _In_ const sai_flow_entry_t &flow_entry) { SWSS_LOG_ENTER(); json j; - SWSS_LOG_THROW("not implemented, FIXME"); + j["switch_id"] = sai_serialize_object_id(flow_entry.switch_id); + j["eni_mac"] = sai_serialize_mac(flow_entry.eni_mac); + j["vnet_id"] = sai_serialize_number(flow_entry.vnet_id); + j["ip_proto"] = sai_serialize_number(flow_entry.ip_proto); + j["src_ip"] = sai_serialize_ip_address(flow_entry.src_ip); + j["dst_ip"] = sai_serialize_ip_address(flow_entry.dst_ip); + j["src_port"] = sai_serialize_number(flow_entry.src_port); + j["dst_port"] = sai_serialize_number(flow_entry.dst_port); + + return j.dump(); } std::string sai_serialize_l2mc_entry_type( @@ -2690,6 +2703,14 @@ static bool sai_serialize_object_extension_entry( key = sai_serialize_outbound_ca_to_pa_entry(key_entry.outbound_ca_to_pa_entry); return true; + case SAI_OBJECT_TYPE_FLOW_ENTRY: + key = sai_serialize_flow_entry(key_entry.flow_entry); + return true; + + case SAI_OBJECT_TYPE_METER_BUCKET_ENTRY: + key = sai_serialize_meter_bucket_entry(key_entry.meter_bucket_entry); + return true; + default: return false; } @@ -4416,7 +4437,7 @@ void sai_deserialize_neighbor_entry( sai_deserialize_ip_address(j["ip"], ne.ip_address); } -__attribute__((__noreturn__)) void sai_deserialize_meter_bucket_entry( +void sai_deserialize_meter_bucket_entry( _In_ const std::string& s, _Out_ sai_meter_bucket_entry_t& meter_bucket_entry) { @@ -4424,10 +4445,12 @@ __attribute__((__noreturn__)) void sai_deserialize_meter_bucket_entry( json j = json::parse(s); - SWSS_LOG_THROW("not implemented, FIXME"); + sai_deserialize_object_id(j["switch_id"], meter_bucket_entry.switch_id); + sai_deserialize_object_id(j["eni_id"], meter_bucket_entry.eni_id); + sai_deserialize_number(j["meter_class"], meter_bucket_entry.meter_class); } -__attribute__((__noreturn__)) void sai_deserialize_flow_entry( +void sai_deserialize_flow_entry( _In_ const std::string& s, _Out_ sai_flow_entry_t &flow_entry) { @@ -4435,7 +4458,14 @@ __attribute__((__noreturn__)) void sai_deserialize_flow_entry( json j = json::parse(s); - SWSS_LOG_THROW("not implemented, FIXME"); + sai_deserialize_object_id(j["switch_id"], flow_entry.switch_id); + sai_deserialize_mac(j["eni_mac"], flow_entry.eni_mac); + sai_deserialize_number(j["vnet_id"], flow_entry.vnet_id); + sai_deserialize_number(j["ip_proto"], flow_entry.ip_proto); + sai_deserialize_ip_address(j["src_ip"], flow_entry.src_ip); + sai_deserialize_ip_address(j["dst_ip"], flow_entry.dst_ip); + sai_deserialize_number(j["src_port"], flow_entry.src_port); + sai_deserialize_number(j["dst_port"], flow_entry.dst_port); } void sai_deserialize_twamp_session_stats_data( @@ -4912,6 +4942,14 @@ bool sai_deserialize_object_extension_entry( sai_deserialize_outbound_ca_to_pa_entry(object_id, meta_key.objectkey.key.outbound_ca_to_pa_entry); return true; + case SAI_OBJECT_TYPE_FLOW_ENTRY: + sai_deserialize_flow_entry(object_id, meta_key.objectkey.key.flow_entry); + return true; + + case SAI_OBJECT_TYPE_METER_BUCKET_ENTRY: + sai_deserialize_meter_bucket_entry(object_id, meta_key.objectkey.key.meter_bucket_entry); + return true; + default: return false; } diff --git a/unittest/meta/TestNotificationFactory.cpp b/unittest/meta/TestNotificationFactory.cpp index f8f9541e8..2b8b7de6a 100644 --- a/unittest/meta/TestNotificationFactory.cpp +++ b/unittest/meta/TestNotificationFactory.cpp @@ -41,7 +41,7 @@ TEST(NotificationFactory, deserialize_port_state_change) { auto ntf = NotificationFactory::deserialize( SAI_SWITCH_NOTIFICATION_NAME_PORT_STATE_CHANGE, - "[{\"port_id\":\"oid:0x100000000001a\",\"port_state\":\"SAI_PORT_OPER_STATUS_UP\"}]"); + "[{\"port_id\":\"oid:0x100000000001a\",\"port_state\":\"SAI_PORT_OPER_STATUS_UP\",\"port_error_status\":\"0\"}]"); EXPECT_EQ(ntf->getNotificationType(), SAI_SWITCH_NOTIFICATION_TYPE_PORT_STATE_CHANGE); } diff --git a/unittest/meta/TestNotificationPortStateChange.cpp b/unittest/meta/TestNotificationPortStateChange.cpp index 7f0102784..0f0c336fe 100644 --- a/unittest/meta/TestNotificationPortStateChange.cpp +++ b/unittest/meta/TestNotificationPortStateChange.cpp @@ -12,8 +12,8 @@ using namespace sairedis; using namespace saimeta; -static std::string s = "[{\"port_id\":\"oid:0x100000000001a\",\"port_state\":\"SAI_PORT_OPER_STATUS_UP\"}]"; -static std::string null = "[{\"port_id\":\"oid:0x0\",\"port_state\":\"SAI_PORT_OPER_STATUS_UP\"}]"; +static std::string s = "[{\"port_id\":\"oid:0x100000000001a\",\"port_state\":\"SAI_PORT_OPER_STATUS_UP\",\"port_error_status\":\"0\"}]"; +static std::string null = "[{\"port_id\":\"oid:0x0\",\"port_state\":\"SAI_PORT_OPER_STATUS_UP\",\"port_error_status\":\"0\"}]"; static std::string fullnull = "[]"; TEST(NotificationPortStateChange, ctr) From 11c55a7c98b904e1bf3428062967e3a8ebca0bc2 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 10 Oct 2024 19:05:49 +0200 Subject: [PATCH 4/5] Fix serialize notification --- meta/SaiSerialize.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index de9c28a66..72596c96e 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -2425,6 +2425,7 @@ std::string sai_serialize_port_oper_status_ntf( item["port_id"] = sai_serialize_object_id(port_oper_status[i].port_id); item["port_state"] = sai_serialize_port_oper_status(port_oper_status[i].port_state); + item["port_error_status"] = sai_serialize_port_error_status(port_oper_status[i].port_error_status); j.push_back(item); } From a5251d0360cebdbf559d9f46886890f827fa23dd Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 10 Oct 2024 20:35:41 +0200 Subject: [PATCH 5/5] Add unittests for code coverage --- unittest/meta/TestMeta.cpp | 18 +++++++++++++++++ unittest/meta/TestSaiInterface.cpp | 13 ++++++++++++ unittest/syncd/TestVendorSai.cpp | 32 +++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index 2aae01635..0b0d35b25 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -1823,3 +1823,21 @@ TEST(Meta, bulkGet) SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses)); } + +TEST(Meta, remove_flow_entry) +{ + Meta sai(std::make_shared()); + + sai_flow_entry_t* e = nullptr; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, sai.remove(e)); +} + +TEST(Meta, remove_meter_bucket_entry) +{ + Meta sai(std::make_shared()); + + sai_meter_bucket_entry_t* e = nullptr; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, sai.remove(e)); +} diff --git a/unittest/meta/TestSaiInterface.cpp b/unittest/meta/TestSaiInterface.cpp index 06b1255ef..19a095ab8 100644 --- a/unittest/meta/TestSaiInterface.cpp +++ b/unittest/meta/TestSaiInterface.cpp @@ -104,3 +104,16 @@ TEST(SaiInterface, get) mk.objecttype = SAI_OBJECT_TYPE_L2MC_ENTRY; EXPECT_EQ(SAI_STATUS_FAILURE, sai->get(mk, 0, nullptr)); } + +TEST(SaiInterface, stats_meter_bucket_entry) +{ + DummySaiInterface ds; + + SaiInterface *s = &ds; + + const sai_meter_bucket_entry_t *m = nullptr; + + EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, s->getStats(m, 0, 0, 0)); + EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, s->getStatsExt(m, 0, nullptr, SAI_STATS_MODE_READ, nullptr)); + EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, s->clearStats(m, 0, nullptr)); +} diff --git a/unittest/syncd/TestVendorSai.cpp b/unittest/syncd/TestVendorSai.cpp index d369d40e9..9f6245677 100644 --- a/unittest/syncd/TestVendorSai.cpp +++ b/unittest/syncd/TestVendorSai.cpp @@ -1428,7 +1428,7 @@ TEST(VendorSai, bulk_dash_outbound_ca_to_pa_entry) remove_counter(sai, counter1); } -TEST(VendorSie, bulkGet) +TEST(VendorSai, bulkGet) { VendorSai sai; @@ -1448,3 +1448,33 @@ TEST(VendorSie, bulkGet) statuses)); } +TEST_F(VendorSaiTest, bulk_flow_entry) +{ + sai_flow_entry_t *e = nullptr; + + // metadata will fail + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, + m_vsai->bulkCreate(0, e, nullptr, nullptr, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr)); + + // metadata will fail + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, + m_vsai->bulkRemove(0, e, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr)); + + EXPECT_EQ(SAI_STATUS_NOT_SUPPORTED, + m_vsai->bulkSet(0, e, nullptr, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr)); +} + +TEST_F(VendorSaiTest, bulk_meter_bucket_entry) +{ + sai_meter_bucket_entry_t *e = nullptr; + + // metadata will fail + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, + m_vsai->bulkCreate(0, e, nullptr, nullptr, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr)); + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, + m_vsai->bulkRemove(0, e, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr)); + + EXPECT_EQ(SAI_STATUS_NOT_SUPPORTED, + m_vsai->bulkSet(0, e, nullptr, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr)); +}