diff --git a/lib/inc/sai_redis.h b/lib/inc/sai_redis.h index d6021dc45052..5318eb9a8f28 100644 --- a/lib/inc/sai_redis.h +++ b/lib/inc/sai_redis.h @@ -70,13 +70,21 @@ extern std::shared_ptr g_redisClient; extern std::mutex g_apimutex; extern const sai_acl_api_t redis_acl_api; -extern const sai_buffer_api_t redis_buffer_api; +extern const sai_bfd_api_t redis_bfd_api; extern const sai_bridge_api_t redis_bridge_api; +extern const sai_buffer_api_t redis_buffer_api; +extern const sai_dtel_api_t redis_dtel_api; extern const sai_fdb_api_t redis_fdb_api; extern const sai_hash_api_t redis_hash_api; extern const sai_hostif_api_t redis_hostif_api; +extern const sai_ipmc_api_t redis_ipmc_api; +extern const sai_ipmc_group_api_t redis_ipmc_group_api; +extern const sai_l2mc_api_t redis_l2mc_api; +extern const sai_l2mc_group_api_t redis_l2mc_group_api; extern const sai_lag_api_t redis_lag_api; +extern const sai_mcast_fdb_api_t redis_mcast_fdb_api; extern const sai_mirror_api_t redis_mirror_api; +extern const sai_mpls_api_t redis_mpls_api; extern const sai_neighbor_api_t redis_neighbor_api; extern const sai_next_hop_api_t redis_next_hop_api; extern const sai_next_hop_group_api_t redis_next_hop_group_api; @@ -86,17 +94,20 @@ extern const sai_qos_map_api_t redis_qos_map_api; extern const sai_queue_api_t redis_queue_api; extern const sai_route_api_t redis_route_api; extern const sai_router_interface_api_t redis_router_interface_api; +extern const sai_rpf_group_api_t redis_rpf_group_api; extern const sai_samplepacket_api_t redis_samplepacket_api; extern const sai_scheduler_api_t redis_scheduler_api; extern const sai_scheduler_group_api_t redis_scheduler_group_api; +extern const sai_segmentroute_api_t redis_segmentroute_api; extern const sai_stp_api_t redis_stp_api; extern const sai_switch_api_t redis_switch_api; +extern const sai_tam_api_t redis_tam_api; extern const sai_tunnel_api_t redis_tunnel_api; +extern const sai_uburst_api_t redis_uburst_api; extern const sai_udf_api_t redis_udf_api; extern const sai_virtual_router_api_t redis_virtual_router_api; extern const sai_vlan_api_t redis_vlan_api; extern const sai_wred_api_t redis_wred_api; -extern const sai_dtel_api_t redis_dtel_api; #define UNREFERENCED_PARAMETER(X) @@ -118,29 +129,68 @@ void translate_rid_to_vid( _In_ uint32_t attr_count, _In_ sai_attribute_t *attr_list); -// CREATE +// OID QUAD sai_status_t redis_generic_create( _In_ sai_object_type_t object_type, - _Out_ sai_object_id_t* object_id, + _Out_ sai_object_id_t *object_id, _In_ sai_object_id_t switch_id, _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list); -sai_status_t redis_generic_create_fdb_entry( - _In_ const sai_fdb_entry_t *fdb_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list); +sai_status_t redis_generic_remove( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id); -sai_status_t redis_generic_create_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list); +sai_status_t redis_generic_set( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_attribute_t *attr); -sai_status_t redis_generic_create_route_entry( - _In_ const sai_route_entry_t* route_entry, +sai_status_t redis_generic_get( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list); + _Out_ sai_attribute_t *attr_list); + +// ENTRY QUAD + +#define REDIS_CREATE_ENTRY_DEF(ot) \ + sai_status_t redis_generic_create_ ## ot( \ + _In_ const sai_ ## ot ## _t * ot, \ + _In_ uint32_t attr_count, \ + _In_ const sai_attribute_t *attr_list); + +#define REDIS_REMOVE_ENTRY_DEF(ot) \ + sai_status_t redis_generic_remove_ ## ot( \ + _In_ const sai_ ## ot ## _t * ot); + +#define REDIS_SET_ENTRY_DEF(ot) \ + sai_status_t redis_generic_set_ ## ot( \ + _In_ const sai_ ## ot ## _t * ot, \ + _In_ const sai_attribute_t *attr); + +#define REDIS_GET_ENTRY_DEF(ot) \ + sai_status_t redis_generic_get_ ## ot( \ + _In_ const sai_ ## ot ## _t * ot, \ + _In_ uint32_t attr_count, \ + _Out_ sai_attribute_t *attr_list); + +#define REDIS_ENTRY_QUAD(ot) \ + REDIS_CREATE_ENTRY_DEF(ot) \ + REDIS_REMOVE_ENTRY_DEF(ot) \ + REDIS_SET_ENTRY_DEF(ot) \ + REDIS_GET_ENTRY_DEF(ot) + +REDIS_ENTRY_QUAD(fdb_entry); +REDIS_ENTRY_QUAD(inseg_entry); +REDIS_ENTRY_QUAD(ipmc_entry); +REDIS_ENTRY_QUAD(l2mc_entry); +REDIS_ENTRY_QUAD(mcast_fdb_entry); +REDIS_ENTRY_QUAD(neighbor_entry); +REDIS_ENTRY_QUAD(route_entry); + +// BULK sai_status_t redis_bulk_generic_create( _In_ sai_object_type_t object_type, @@ -149,29 +199,14 @@ sai_status_t redis_bulk_generic_create( _In_ sai_object_id_t switch_id, _In_ const uint32_t *attr_count, /* array */ _In_ const sai_attribute_t *const *attr_list, /* array */ - _Inout_ sai_status_t *object_statuses) /* array */; + _Inout_ sai_status_t *object_statuses); /* array */ sai_status_t internal_redis_bulk_generic_create( _In_ sai_object_type_t object_type, _In_ const std::vector &serialized_object_ids, _In_ const uint32_t *attr_count, - _In_ const sai_attribute_t *const *attr_list, - _Inout_ sai_status_t *object_statuses); - -// REMOVE - -sai_status_t redis_generic_remove( - _In_ sai_object_type_t object_type, - _In_ sai_object_id_t object_id); - -sai_status_t redis_generic_remove_fdb_entry( - _In_ const sai_fdb_entry_t* fdb_entry); - -sai_status_t redis_generic_remove_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry); - -sai_status_t redis_generic_remove_route_entry( - _In_ const sai_route_entry_t* route_entry); + _In_ const sai_attribute_t *const *attr_list, /* array */ + _Inout_ sai_status_t *object_statuses) /* array */; sai_status_t redis_bulk_generic_remove( _In_ sai_object_type_t object_type, @@ -182,55 +217,13 @@ sai_status_t redis_bulk_generic_remove( sai_status_t internal_redis_bulk_generic_remove( _In_ sai_object_type_t object_type, _In_ const std::vector &serialized_object_ids, - _Out_ sai_status_t *object_statuses) /* array */; - -// SET - -sai_status_t redis_generic_set( - _In_ sai_object_type_t object_type, - _In_ sai_object_id_t object_id, - _In_ const sai_attribute_t *attr); - -sai_status_t redis_generic_set_fdb_entry( - _In_ const sai_fdb_entry_t *fdb_entry, - _In_ const sai_attribute_t *attr); - -sai_status_t redis_generic_set_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ const sai_attribute_t *attr); - -sai_status_t redis_generic_set_route_entry( - _In_ const sai_route_entry_t* route_entry, - _In_ const sai_attribute_t *attr); + _Out_ sai_status_t *object_statuses); /* array */ sai_status_t internal_redis_bulk_generic_set( _In_ sai_object_type_t object_type, _In_ const std::vector &serialized_object_ids, - _In_ const sai_attribute_t *attr_list, - _In_ const sai_status_t *object_statuses); - -// GET - -sai_status_t redis_generic_get( - _In_ sai_object_type_t object_type, - _In_ sai_object_id_t object_id, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list); - -sai_status_t redis_generic_get_fdb_entry( - _In_ const sai_fdb_entry_t *fdb_entry, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list); - -sai_status_t redis_generic_get_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list); - -sai_status_t redis_generic_get_route_entry( - _In_ const sai_route_entry_t* route_entry, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list); + _In_ const sai_attribute_t *attr_list, /* array */ + _In_ const sai_status_t *object_statuses); /* array */ // get_stats @@ -249,4 +242,30 @@ void handle_notification( _In_ const std::string &data, _In_ const std::vector &values); +// STATS + +sai_status_t redis_generic_get_stats( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids, + _Out_ uint64_t *counters); + +sai_status_t redis_generic_get_stats_ext( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids, + _In_ sai_stats_mode_t mode, + _Out_ uint64_t *counters); + +sai_status_t redis_generic_clear_stats( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids); + #endif // __SAI_REDIS__ diff --git a/lib/inc/sai_redis_internal.h b/lib/inc/sai_redis_internal.h index 1606b448e3a6..47aae5a35b4f 100644 --- a/lib/inc/sai_redis_internal.h +++ b/lib/inc/sai_redis_internal.h @@ -141,21 +141,69 @@ // stats -#define REDIS_GENERIC_GET_STATS(OBJECT_TYPE,object_type) \ - sai_status_t redis_get_ ## object_type ## _stats( \ - _In_ sai_object_id_t object_type ##_id, \ - _In_ uint32_t count, \ - _In_ const sai_ ## object_type ## _stat_t *counter_id_list, \ - _Out_ uint64_t *counter_list) \ - { \ - MUTEX(); \ - SWSS_LOG_ENTER(); \ - \ - return meta_sai_get_stats_oid( \ - SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \ - object_type ## _id, \ - count, \ - counter_id_list, \ - counter_list, \ - &redis_generic_get_stats); \ +#define REDIS_GET_STATS(OBJECT_TYPE,object_type) \ + sai_status_t redis_get_ ## object_type ## _stats( \ + _In_ sai_object_id_t object_type ## _id, \ + _In_ uint32_t number_of_counters, \ + _In_ const sai_ ## object_type ## _stat_t *counter_ids, \ + _Out_ uint64_t *counters) \ + { \ + MUTEX(); \ + SWSS_LOG_ENTER(); \ + return meta_sai_get_stats_oid( \ + SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \ + object_type ## _id, \ + &sai_metadata_enum_sai_ ## object_type ## _stat_t, \ + number_of_counters, \ + (const int32_t*)counter_ids, \ + counters, \ + &redis_generic_get_stats); \ } + +#define REDIS_GET_STATS_EXT(OBJECT_TYPE,object_type) \ + sai_status_t redis_get_ ## object_type ## _stats_ext( \ + _In_ sai_object_id_t object_type ## _id, \ + _In_ uint32_t number_of_counters, \ + _In_ const sai_ ## object_type ## _stat_t *counter_ids, \ + _In_ sai_stats_mode_t mode, \ + _Out_ uint64_t *counters) \ + { \ + MUTEX(); \ + SWSS_LOG_ENTER(); \ + return redis_generic_get_stats_ext( \ + SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \ + object_type ## _id, \ + &sai_metadata_enum_sai_ ## object_type ## _stat_t, \ + number_of_counters, \ + (const int32_t*)counter_ids, \ + mode, \ + counters); \ + } + +#define REDIS_CLEAR_STATS(OBJECT_TYPE,object_type) \ + sai_status_t redis_clear_ ## object_type ## _stats( \ + _In_ sai_object_id_t object_type ## _id, \ + _In_ uint32_t number_of_counters, \ + _In_ const sai_ ## object_type ## _stat_t *counter_ids) \ + { \ + MUTEX(); \ + SWSS_LOG_ENTER(); \ + return redis_generic_clear_stats( \ + SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \ + object_type ## _id, \ + &sai_metadata_enum_sai_ ## object_type ## _stat_t, \ + number_of_counters, \ + (const int32_t*)counter_ids); \ + } + +#define REDIS_GENERIC_STATS(OT, ot) \ + REDIS_GET_STATS(OT,ot); \ + REDIS_GET_STATS_EXT(OT,ot); \ + REDIS_CLEAR_STATS(OT,ot); + +// common stats api + +#define REDIS_GENERIC_STATS_API(ot) \ + redis_get_ ## ot ## _stats, \ + redis_get_ ## ot ## _stats_ext, \ + redis_clear_ ## ot ## _stats, diff --git a/lib/inc/sairedis.h b/lib/inc/sairedis.h index 0c0efe7f1269..514c930374f9 100644 --- a/lib/inc/sairedis.h +++ b/lib/inc/sairedis.h @@ -149,7 +149,7 @@ sai_status_t sai_bulk_create_route_entry( _In_ uint32_t object_count, _In_ const sai_route_entry_t *route_entry, _In_ const uint32_t *attr_count, - _In_ const sai_attribute_t *const *attr_list, + _In_ const sai_attribute_t **attr_list, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_status_t *object_statuses); @@ -224,7 +224,7 @@ sai_status_t sai_bulk_create_next_hop_group_members( _In_ sai_object_id_t switch_id, _In_ uint32_t object_count, _In_ const uint32_t *attr_count, - _In_ const sai_attribute_t *const *attrs, + _In_ const sai_attribute_t **attrs, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_object_id_t *object_id, _Out_ sai_status_t *object_statuses); diff --git a/lib/src/Makefile.am b/lib/src/Makefile.am index 6dc26deae21f..706bdc23becd 100644 --- a/lib/src/Makefile.am +++ b/lib/src/Makefile.am @@ -9,42 +9,53 @@ endif lib_LTLIBRARIES = libsairedis.la libsairedis_la_SOURCES = \ - sai_redis_acl.cpp \ - sai_redis_buffer.cpp \ - sai_redis_bridge.cpp \ - sai_redis_fdb.cpp \ - sai_redis_hash.cpp \ - sai_redis_hostintf.cpp \ - sai_redis_dtel.cpp \ - sai_redis_interfacequery.cpp \ - sai_redis_lag.cpp \ - sai_redis_mirror.cpp \ - sai_redis_neighbor.cpp \ - sai_redis_nexthop.cpp \ - sai_redis_nexthopgroup.cpp \ - sai_redis_policer.cpp \ - sai_redis_port.cpp \ - sai_redis_qosmaps.cpp \ - sai_redis_queue.cpp \ - sai_redis_route.cpp \ - sai_redis_router.cpp \ - sai_redis_routerintf.cpp \ - sai_redis_samplepacket.cpp \ - sai_redis_scheduler.cpp \ - sai_redis_schedulergroup.cpp \ - sai_redis_stp.cpp \ - sai_redis_switch.cpp \ - sai_redis_tunnel.cpp \ - sai_redis_udf.cpp \ - sai_redis_vlan.cpp \ - sai_redis_wred.cpp \ - sai_redis_generic_create.cpp \ - sai_redis_generic_remove.cpp \ - sai_redis_generic_set.cpp \ - sai_redis_generic_get.cpp \ - sai_redis_notifications.cpp \ - sai_redis_record.cpp \ - sai_redis_generic_get_stats.cpp + sai_redis_acl.cpp \ + sai_redis_bfd.cpp \ + sai_redis_bridge.cpp \ + sai_redis_buffer.cpp \ + sai_redis_dtel.cpp \ + sai_redis_fdb.cpp \ + sai_redis_hash.cpp \ + sai_redis_hostintf.cpp \ + sai_redis_interfacequery.cpp \ + sai_redis_ipmc.cpp \ + sai_redis_ipmc_group.cpp \ + sai_redis_l2mc.cpp \ + sai_redis_l2mcgroup.cpp \ + sai_redis_lag.cpp \ + sai_redis_mcastfdb.cpp \ + sai_redis_mirror.cpp \ + sai_redis_mpls.cpp \ + sai_redis_neighbor.cpp \ + sai_redis_nexthop.cpp \ + sai_redis_nexthopgroup.cpp \ + sai_redis_policer.cpp \ + sai_redis_port.cpp \ + sai_redis_qosmaps.cpp \ + sai_redis_queue.cpp \ + sai_redis_route.cpp \ + sai_redis_router_interface.cpp \ + sai_redis_rpfgroup.cpp \ + sai_redis_samplepacket.cpp \ + sai_redis_scheduler.cpp \ + sai_redis_schedulergroup.cpp \ + sai_redis_segmentroute.cpp \ + sai_redis_stp.cpp \ + sai_redis_switch.cpp \ + sai_redis_tam.cpp \ + sai_redis_tunnel.cpp \ + sai_redis_uburst.cpp \ + sai_redis_udf.cpp \ + sai_redis_virtual_router.cpp \ + sai_redis_vlan.cpp \ + sai_redis_wred.cpp \ + sai_redis_generic_create.cpp \ + sai_redis_generic_remove.cpp \ + sai_redis_generic_set.cpp \ + sai_redis_generic_get.cpp \ + sai_redis_generic_stats.cpp \ + sai_redis_notifications.cpp \ + sai_redis_record.cpp libsairedis_la_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) libsairedis_la_LIBADD = -lhiredis -lswsscommon diff --git a/lib/src/sai_redis_bfd.cpp b/lib/src/sai_redis_bfd.cpp new file mode 100644 index 000000000000..08dac5ff9fc9 --- /dev/null +++ b/lib/src/sai_redis_bfd.cpp @@ -0,0 +1,11 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD(BFD_SESSION,bfd_session); +REDIS_GENERIC_STATS(BFD_SESSION,bfd_session); + +const sai_bfd_api_t redis_bfd_api = { + + REDIS_GENERIC_QUAD_API(bfd_session) + REDIS_GENERIC_STATS_API(bfd_session) +}; diff --git a/lib/src/sai_redis_bridge.cpp b/lib/src/sai_redis_bridge.cpp index 4e4f5a4f1b9d..c3491830e7b8 100644 --- a/lib/src/sai_redis_bridge.cpp +++ b/lib/src/sai_redis_bridge.cpp @@ -1,97 +1,14 @@ #include "sai_redis.h" -sai_status_t redis_get_bridge_stats( - _In_ sai_object_id_t bridge_id, - _In_ uint32_t number_of_counters, - _In_ const sai_bridge_stat_t *counter_ids, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_bridge_stats( - _In_ sai_object_id_t bridge_id, - _In_ uint32_t number_of_counters, - _In_ const sai_bridge_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_bridge_port_stats( - _In_ sai_object_id_t bridge_port_id, - _In_ uint32_t number_of_counters, - _In_ const sai_bridge_port_stat_t *counter_ids, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_bridge_port_stats_ext( - _In_ sai_object_id_t bridge_port_id, - _In_ uint32_t number_of_counters, - _In_ const sai_bridge_port_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_bridge_stats_ext( - _In_ sai_object_id_t bridge_id, - _In_ uint32_t number_of_counters, - _In_ const sai_bridge_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_bridge_port_stats( - _In_ sai_object_id_t bridge_port_id, - _In_ uint32_t number_of_counters, - _In_ const sai_bridge_port_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(BRIDGE,bridge); REDIS_GENERIC_QUAD(BRIDGE_PORT,bridge_port); +REDIS_GENERIC_STATS(BRIDGE,bridge); +REDIS_GENERIC_STATS(BRIDGE_PORT,bridge_port); -const sai_bridge_api_t redis_bridge_api = -{ - REDIS_GENERIC_QUAD_API(bridge) - - redis_get_bridge_stats, - redis_get_bridge_stats_ext, - redis_clear_bridge_stats, +const sai_bridge_api_t redis_bridge_api = { + REDIS_GENERIC_QUAD_API(bridge) + REDIS_GENERIC_STATS_API(bridge) REDIS_GENERIC_QUAD_API(bridge_port) - - redis_get_bridge_port_stats, - redis_get_bridge_port_stats_ext, - redis_clear_bridge_port_stats, + REDIS_GENERIC_STATS_API(bridge_port) }; diff --git a/lib/src/sai_redis_buffer.cpp b/lib/src/sai_redis_buffer.cpp index 73679f2d0204..833ef3e13f67 100644 --- a/lib/src/sai_redis_buffer.cpp +++ b/lib/src/sai_redis_buffer.cpp @@ -1,89 +1,16 @@ #include "sai_redis.h" -sai_status_t redis_clear_ingress_priority_group_stats( - _In_ sai_object_id_t ingress_pg_id, - _In_ uint32_t number_of_counters, - _In_ const sai_ingress_priority_group_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_ingress_priority_group_stats_ext( - _In_ sai_object_id_t ingress_priority_group_id, - _In_ uint32_t number_of_counters, - _In_ const sai_ingress_priority_group_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_buffer_pool_stats( - _In_ sai_object_id_t pool_id, - _In_ uint32_t number_of_counters, - _In_ const sai_buffer_pool_stat_t *counter_ids, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_buffer_pool_stats_ext( - _In_ sai_object_id_t buffer_pool_id, - _In_ uint32_t number_of_counters, - _In_ const sai_buffer_pool_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_buffer_pool_stats( - _In_ sai_object_id_t pool_id, - _In_ uint32_t number_of_counters, - _In_ const sai_buffer_pool_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(BUFFER_POOL,buffer_pool); REDIS_GENERIC_QUAD(INGRESS_PRIORITY_GROUP,ingress_priority_group); REDIS_GENERIC_QUAD(BUFFER_PROFILE,buffer_profile); - -REDIS_GENERIC_GET_STATS(INGRESS_PRIORITY_GROUP,ingress_priority_group); +REDIS_GENERIC_STATS(BUFFER_POOL,buffer_pool); +REDIS_GENERIC_STATS(INGRESS_PRIORITY_GROUP,ingress_priority_group); const sai_buffer_api_t redis_buffer_api = { REDIS_GENERIC_QUAD_API(buffer_pool) - - redis_get_buffer_pool_stats, - redis_get_buffer_pool_stats_ext, - redis_clear_buffer_pool_stats, - + REDIS_GENERIC_STATS_API(buffer_pool) REDIS_GENERIC_QUAD_API(ingress_priority_group) - - redis_get_ingress_priority_group_stats, - redis_get_ingress_priority_group_stats_ext, - redis_clear_ingress_priority_group_stats, - + REDIS_GENERIC_STATS_API(ingress_priority_group) REDIS_GENERIC_QUAD_API(buffer_profile) }; diff --git a/lib/src/sai_redis_generic_create.cpp b/lib/src/sai_redis_generic_create.cpp index 30e34cc75c38..5cba3362d44b 100644 --- a/lib/src/sai_redis_generic_create.cpp +++ b/lib/src/sai_redis_generic_create.cpp @@ -391,50 +391,25 @@ sai_status_t internal_redis_bulk_generic_create( return SAI_STATUS_SUCCESS; } -sai_status_t redis_generic_create_fdb_entry( - _In_ const sai_fdb_entry_t *fdb_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - SWSS_LOG_ENTER(); - - std::string str_fdb_entry = sai_serialize_fdb_entry(*fdb_entry); - - return internal_redis_generic_create( - SAI_OBJECT_TYPE_FDB_ENTRY, - str_fdb_entry, - attr_count, - attr_list); -} - -sai_status_t redis_generic_create_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - SWSS_LOG_ENTER(); - - std::string str_neighbor_entry = sai_serialize_neighbor_entry(*neighbor_entry); - - return internal_redis_generic_create( - SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, - str_neighbor_entry, - attr_count, - attr_list); -} - -sai_status_t redis_generic_create_route_entry( - _In_ const sai_route_entry_t* route_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - SWSS_LOG_ENTER(); - - std::string str_route_entry = sai_serialize_route_entry(*route_entry); +#define REDIS_ENTRY_CREATE(OT,ot) \ + sai_status_t redis_generic_create_ ## ot( \ + _In_ const sai_ ## ot ## _t * entry, \ + _In_ uint32_t attr_count, \ + _In_ const sai_attribute_t *attr_list) \ + { \ + SWSS_LOG_ENTER(); \ + std::string str = sai_serialize_ ## ot(*entry); \ + return internal_redis_generic_create( \ + SAI_OBJECT_TYPE_ ## OT, \ + str, \ + attr_count, \ + attr_list); \ + } - return internal_redis_generic_create( - SAI_OBJECT_TYPE_ROUTE_ENTRY, - str_route_entry, - attr_count, - attr_list); -} +REDIS_ENTRY_CREATE(FDB_ENTRY,fdb_entry); +REDIS_ENTRY_CREATE(INSEG_ENTRY,inseg_entry); +REDIS_ENTRY_CREATE(IPMC_ENTRY,ipmc_entry); +REDIS_ENTRY_CREATE(L2MC_ENTRY,l2mc_entry); +REDIS_ENTRY_CREATE(MCAST_FDB_ENTRY,mcast_fdb_entry); +REDIS_ENTRY_CREATE(NEIGHBOR_ENTRY,neighbor_entry); +REDIS_ENTRY_CREATE(ROUTE_ENTRY,route_entry); diff --git a/lib/src/sai_redis_generic_get.cpp b/lib/src/sai_redis_generic_get.cpp index cd3984356ea6..e794848927b9 100644 --- a/lib/src/sai_redis_generic_get.cpp +++ b/lib/src/sai_redis_generic_get.cpp @@ -263,50 +263,25 @@ sai_status_t redis_generic_get( attr_list); } -sai_status_t redis_generic_get_fdb_entry( - _In_ const sai_fdb_entry_t *fdb_entry, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list) -{ - SWSS_LOG_ENTER(); - - std::string str_fdb_entry = sai_serialize_fdb_entry(*fdb_entry); - - return internal_redis_generic_get( - SAI_OBJECT_TYPE_FDB_ENTRY, - str_fdb_entry, - attr_count, - attr_list); -} - -sai_status_t redis_generic_get_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list) -{ - SWSS_LOG_ENTER(); - - std::string str_neighbor_entry = sai_serialize_neighbor_entry(*neighbor_entry); - - return internal_redis_generic_get( - SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, - str_neighbor_entry, - attr_count, - attr_list); +#define REDIS_ENTRY_GET(OT,ot) \ +sai_status_t redis_generic_get_ ## ot( \ + _In_ const sai_ ## ot ## _t *entry, \ + _In_ uint32_t attr_count, \ + _Out_ sai_attribute_t *attr_list) \ +{ \ + SWSS_LOG_ENTER(); \ + std::string str = sai_serialize_ ## ot(*entry); \ + return internal_redis_generic_get( \ + SAI_OBJECT_TYPE_ ## OT, \ + str, \ + attr_count, \ + attr_list); \ } -sai_status_t redis_generic_get_route_entry( - _In_ const sai_route_entry_t* route_entry, - _In_ uint32_t attr_count, - _Out_ sai_attribute_t *attr_list) -{ - SWSS_LOG_ENTER(); - - std::string str_route_entry = sai_serialize_route_entry(*route_entry); - - return internal_redis_generic_get( - SAI_OBJECT_TYPE_ROUTE_ENTRY, - str_route_entry, - attr_count, - attr_list); -} +REDIS_ENTRY_GET(FDB_ENTRY,fdb_entry); +REDIS_ENTRY_GET(INSEG_ENTRY,inseg_entry); +REDIS_ENTRY_GET(IPMC_ENTRY,ipmc_entry); +REDIS_ENTRY_GET(L2MC_ENTRY,l2mc_entry); +REDIS_ENTRY_GET(MCAST_FDB_ENTRY,mcast_fdb_entry); +REDIS_ENTRY_GET(NEIGHBOR_ENTRY,neighbor_entry); +REDIS_ENTRY_GET(ROUTE_ENTRY,route_entry); diff --git a/lib/src/sai_redis_generic_get_stats.cpp b/lib/src/sai_redis_generic_get_stats.cpp deleted file mode 100644 index 6e3f2092fa28..000000000000 --- a/lib/src/sai_redis_generic_get_stats.cpp +++ /dev/null @@ -1,231 +0,0 @@ -#include "sai_redis.h" -#include "meta/sai_serialize.h" - -sai_status_t internal_redis_get_stats_process( - _In_ sai_object_type_t object_type, - _In_ uint32_t count, - _Out_ uint64_t *counter_list, - _In_ swss::KeyOpFieldsValuesTuple &kco) -{ - SWSS_LOG_ENTER(); - - // key: sai_status - // field: stat_id - // value: stat_value - - const auto &key = kfvKey(kco); - const auto &values = kfvFieldsValues(kco); - - auto str_sai_status = key; - - sai_status_t status; - - sai_deserialize_status(str_sai_status, status); - - if (status == SAI_STATUS_SUCCESS) - { - uint32_t i = 0; - for (const auto &v : values) - { - if (i >= count) - { - SWSS_LOG_ERROR("Received more values than expected"); - status = SAI_STATUS_FAILURE; - break; - } - - uint64_t value = 0; - - value = stoull(fvValue(v)); - counter_list[i] = value; - i++; - } - } - - return status; -} - -template struct stat_traits {}; - -template <> -struct stat_traits -{ - typedef std::string (*serialize_stat)(sai_port_stat_t); - static constexpr serialize_stat serialize_stat_fn = sai_serialize_port_stat; -}; - -template <> -struct stat_traits -{ - typedef std::string (*serialize_stat)(sai_port_pool_stat_t); - static constexpr serialize_stat serialize_stat_fn = sai_serialize_port_pool_stat; -}; - -template <> -struct stat_traits -{ - typedef std::string (*serialize_stat)(sai_queue_stat_t); - static constexpr serialize_stat serialize_stat_fn = sai_serialize_queue_stat; -}; - -template <> -struct stat_traits -{ - typedef std::string (*serialize_stat)(sai_ingress_priority_group_stat_t); - static constexpr serialize_stat serialize_stat_fn = sai_serialize_ingress_priority_group_stat; -}; - -template <> -struct stat_traits -{ - typedef std::string (*serialize_stat)(sai_tunnel_stat_t); - static constexpr serialize_stat serialize_stat_fn = sai_serialize_tunnel_stat; -}; - - -template -std::vector serialize_counter_id_list( - _In_ uint32_t count, - _In_ const T *counter_id_list) -{ - SWSS_LOG_ENTER(); - - std::vector values; - - for (uint32_t i = 0; i < count; i++) - { - std::string field = stat_traits::serialize_stat_fn(counter_id_list[i]); - values.emplace_back(field, ""); - } - - return std::move(values); -} - -template -sai_status_t internal_redis_generic_get_stats( - _In_ sai_object_type_t object_type, - _In_ const std::string &serialized_object_id, - _In_ uint32_t count, - _In_ const T *counter_id_list, - _Out_ uint64_t *counter_list) -{ - SWSS_LOG_ENTER(); - - std::vector entry = serialize_counter_id_list( - count, - counter_id_list); - - std::string str_object_type = sai_serialize_object_type(object_type); - - std::string key = str_object_type + ":" + serialized_object_id; - - SWSS_LOG_DEBUG("generic get stats key: %s, fields: %lu", key.c_str(), entry.size()); - - if (g_record) - { - // XXX don't know which character to use for get stats. For now its 'm' - recordLine("m|" + key + "|" + joinFieldValues(entry)); - } - - // get is special, it will not put data - // into asic view, only to message queue - g_asicState->set(key, entry, "get_stats"); - - // wait for response - - swss::Select s; - - s.addSelectable(g_redisGetConsumer.get()); - - while (true) - { - SWSS_LOG_DEBUG("wait for get_stats response"); - - swss::Selectable *sel; - - int result = s.select(&sel, GET_RESPONSE_TIMEOUT); - - if (result == swss::Select::OBJECT) - { - swss::KeyOpFieldsValuesTuple kco; - - g_redisGetConsumer->pop(kco); - - const std::string &op = kfvOp(kco); - const std::string &opkey = kfvKey(kco); - - SWSS_LOG_DEBUG("response: op = %s, key = %s", opkey.c_str(), op.c_str()); - - if (op != "getresponse") // ignore non response messages - { - continue; - } - - sai_status_t status = internal_redis_get_stats_process( - object_type, - count, - counter_list, - kco); - - if (g_record) - { - const auto &str_status = kfvKey(kco); - const auto &values = kfvFieldsValues(kco); - - // first serialized is status - recordLine("M|" + str_status + "|" + joinFieldValues(values)); - } - - SWSS_LOG_DEBUG("generic get status: %d", status); - - return status; - } - - SWSS_LOG_ERROR("generic get failed due to SELECT operation result"); - break; - } - - if (g_record) - { - recordLine("M|SAI_STATUS_FAILURE"); - } - - SWSS_LOG_ERROR("generic get stats failed to get response"); - - return SAI_STATUS_FAILURE; -} - -template -sai_status_t redis_generic_get_stats( - _In_ sai_object_type_t object_type, - _In_ sai_object_id_t object_id, - _In_ uint32_t count, - _In_ const T* counter_id_list, - _Out_ uint64_t *counter_list) -{ - SWSS_LOG_ENTER(); - - std::string str_object_id = sai_serialize_object_id(object_id); - - return internal_redis_generic_get_stats( - object_type, - str_object_id, - count, - counter_id_list, - counter_list); -} - -#define DECLARE_REDIS_GENERIC_GET_STATS(type) \ - template \ - sai_status_t redis_generic_get_stats( \ - _In_ sai_object_type_t object_type, \ - _In_ sai_object_id_t object_id, \ - _In_ uint32_t count, \ - _In_ const sai_ ## type ## _stat_t *counter_id_list, \ - _Out_ uint64_t *counter_list); \ - -DECLARE_REDIS_GENERIC_GET_STATS(port); -DECLARE_REDIS_GENERIC_GET_STATS(port_pool); -DECLARE_REDIS_GENERIC_GET_STATS(queue); -DECLARE_REDIS_GENERIC_GET_STATS(ingress_priority_group); -DECLARE_REDIS_GENERIC_GET_STATS(tunnel); diff --git a/lib/src/sai_redis_generic_remove.cpp b/lib/src/sai_redis_generic_remove.cpp index ec047490933e..631438524bbd 100644 --- a/lib/src/sai_redis_generic_remove.cpp +++ b/lib/src/sai_redis_generic_remove.cpp @@ -137,38 +137,22 @@ sai_status_t internal_redis_bulk_generic_remove( return SAI_STATUS_SUCCESS; } -sai_status_t redis_generic_remove_fdb_entry( - _In_ const sai_fdb_entry_t* fdb_entry) -{ - SWSS_LOG_ENTER(); - - std::string str_fdb_entry = sai_serialize_fdb_entry(*fdb_entry); - - return internal_redis_generic_remove( - SAI_OBJECT_TYPE_FDB_ENTRY, - str_fdb_entry); -} - -sai_status_t redis_generic_remove_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry) -{ - SWSS_LOG_ENTER(); - std::string str_neighbor_entry = sai_serialize_neighbor_entry(*neighbor_entry); - - return internal_redis_generic_remove( - SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, - str_neighbor_entry); -} - -sai_status_t redis_generic_remove_route_entry( - _In_ const sai_route_entry_t* route_entry) -{ - SWSS_LOG_ENTER(); - - std::string str_route_entry = sai_serialize_route_entry(*route_entry); +#define REDIS_ENTRY_REMOVE(OT,ot) \ + sai_status_t redis_generic_remove_ ## ot( \ + _In_ const sai_ ## ot ## _t *entry) \ + { \ + SWSS_LOG_ENTER(); \ + std::string str = sai_serialize_ ## ot(*entry); \ + return internal_redis_generic_remove( \ + SAI_OBJECT_TYPE_ ## OT, \ + str); \ + } - return internal_redis_generic_remove( - SAI_OBJECT_TYPE_ROUTE_ENTRY, - str_route_entry); -} +REDIS_ENTRY_REMOVE(FDB_ENTRY,fdb_entry); +REDIS_ENTRY_REMOVE(INSEG_ENTRY,inseg_entry); +REDIS_ENTRY_REMOVE(IPMC_ENTRY,ipmc_entry); +REDIS_ENTRY_REMOVE(L2MC_ENTRY,l2mc_entry); +REDIS_ENTRY_REMOVE(MCAST_FDB_ENTRY,mcast_fdb_entry); +REDIS_ENTRY_REMOVE(NEIGHBOR_ENTRY,neighbor_entry); +REDIS_ENTRY_REMOVE(ROUTE_ENTRY,route_entry); diff --git a/lib/src/sai_redis_generic_set.cpp b/lib/src/sai_redis_generic_set.cpp index 33fb35b8f81a..14904d4218f8 100644 --- a/lib/src/sai_redis_generic_set.cpp +++ b/lib/src/sai_redis_generic_set.cpp @@ -129,44 +129,23 @@ sai_status_t redis_generic_set( attr); } -sai_status_t redis_generic_set_fdb_entry( - _In_ const sai_fdb_entry_t *fdb_entry, - _In_ const sai_attribute_t *attr) -{ - SWSS_LOG_ENTER(); - - std::string str_fdb_entry = sai_serialize_fdb_entry(*fdb_entry); - - return internal_redis_generic_set( - SAI_OBJECT_TYPE_FDB_ENTRY, - str_fdb_entry, - attr); -} - -sai_status_t redis_generic_set_neighbor_entry( - _In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ const sai_attribute_t *attr) -{ - SWSS_LOG_ENTER(); - - std::string str_neighbor_entry = sai_serialize_neighbor_entry(*neighbor_entry); - - return internal_redis_generic_set( - SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, - str_neighbor_entry, - attr); +#define REDIS_ENTRY_SET(OT,ot) \ +sai_status_t redis_generic_set_ ## ot( \ + _In_ const sai_ ## ot ## _t *entry, \ + _In_ const sai_attribute_t *attr) \ +{ \ + SWSS_LOG_ENTER(); \ + std::string str = sai_serialize_ ## ot(*entry); \ + return internal_redis_generic_set( \ + SAI_OBJECT_TYPE_ ## OT, \ + str, \ + attr); \ } -sai_status_t redis_generic_set_route_entry( - _In_ const sai_route_entry_t* route_entry, - _In_ const sai_attribute_t *attr) -{ - SWSS_LOG_ENTER(); - - std::string str_route_entry = sai_serialize_route_entry(*route_entry); - - return internal_redis_generic_set( - SAI_OBJECT_TYPE_ROUTE_ENTRY, - str_route_entry, - attr); -} +REDIS_ENTRY_SET(FDB_ENTRY,fdb_entry); +REDIS_ENTRY_SET(INSEG_ENTRY,inseg_entry); +REDIS_ENTRY_SET(IPMC_ENTRY,ipmc_entry); +REDIS_ENTRY_SET(L2MC_ENTRY,l2mc_entry); +REDIS_ENTRY_SET(MCAST_FDB_ENTRY,mcast_fdb_entry); +REDIS_ENTRY_SET(NEIGHBOR_ENTRY,neighbor_entry); +REDIS_ENTRY_SET(ROUTE_ENTRY,route_entry); diff --git a/lib/src/sai_redis_generic_stats.cpp b/lib/src/sai_redis_generic_stats.cpp new file mode 100644 index 000000000000..84e2d4c022b0 --- /dev/null +++ b/lib/src/sai_redis_generic_stats.cpp @@ -0,0 +1,367 @@ +#include "sai_redis.h" +#include "meta/sai_serialize.h" + +/* + * Max number of counters used in 1 api call + */ +#define REDIS_MAX_COUNTERS 128 + +#define REDIS_COUNTERS_COUNT_MSB (0x80000000) + +sai_status_t internal_redis_generic_stats_function( + _In_ sai_object_type_t obejct_type, + _In_ sai_object_id_t object_id, + _In_ sai_object_id_t switch_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_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 redis_generic_stats_function( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids, + _In_ sai_stats_mode_t mode, + _Out_ uint64_t *counters) +{ + SWSS_LOG_ENTER(); + + /* + * Do all parameter validation. + */ + + if (object_id == SAI_NULL_OBJECT_ID) + { + SWSS_LOG_ERROR("object id is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + sai_object_type_t ot = sai_object_type_query(object_id); + + if (ot != object_type) + { + SWSS_LOG_ERROR("object %s is %s but expected %s", + sai_serialize_object_id(object_id).c_str(), + sai_serialize_object_type(ot).c_str(), + sai_serialize_object_type(object_type).c_str()); + + return SAI_STATUS_INVALID_PARAMETER; + } + + sai_object_id_t switch_id = sai_switch_id_query(object_id); + + if (switch_id == SAI_NULL_OBJECT_ID) + { + SWSS_LOG_ERROR("object %s does not correspond to any switch object", + sai_serialize_object_id(object_id).c_str()); + + return SAI_STATUS_INVALID_PARAMETER; + } + + uint32_t count = number_of_counters & ~REDIS_COUNTERS_COUNT_MSB; + + if (count > REDIS_MAX_COUNTERS) + { + SWSS_LOG_ERROR("max supported counters to get/clear is %u, but %u given", + REDIS_MAX_COUNTERS, + count); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (counter_ids == NULL) + { + SWSS_LOG_ERROR("counter ids pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (counters == NULL) + { + SWSS_LOG_ERROR("counters output pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (enum_metadata == NULL) + { + SWSS_LOG_ERROR("enum metadata pointer is NULL, bug?"); + + return SAI_STATUS_FAILURE; + } + + for (uint32_t i = 0; i < count; i++) + { + if (sai_metadata_get_enum_value_name(enum_metadata, counter_ids[i]) == NULL) + { + SWSS_LOG_ERROR("counter id %u is not allowed on %s", counter_ids[i], enum_metadata->name); + + return SAI_STATUS_INVALID_PARAMETER; + } + } + + switch (mode) + { + case SAI_STATS_MODE_READ: + case SAI_STATS_MODE_READ_AND_CLEAR: + break; + + default: + + SWSS_LOG_ERROR("counters mode is invalid %d", mode); + + return SAI_STATUS_INVALID_PARAMETER; + } + + return internal_redis_generic_stats_function( + object_type, + object_id, + switch_id, + enum_metadata, + number_of_counters, + counter_ids, + mode, + counters); +} + +sai_status_t internal_redis_get_stats_process( + _In_ sai_object_type_t object_type, + _In_ uint32_t count, + _Out_ uint64_t *counter_list, + _In_ swss::KeyOpFieldsValuesTuple &kco) +{ + SWSS_LOG_ENTER(); + + // key: sai_status + // field: stat_id + // value: stat_value + + const auto &key = kfvKey(kco); + const auto &values = kfvFieldsValues(kco); + + auto str_sai_status = key; + + sai_status_t status; + + sai_deserialize_status(str_sai_status, status); + + if (status == SAI_STATUS_SUCCESS) + { + uint32_t i = 0; + for (const auto &v : values) + { + if (i >= count) + { + SWSS_LOG_ERROR("Received more values than expected"); + status = SAI_STATUS_FAILURE; + break; + } + + uint64_t value = 0; + + value = stoull(fvValue(v)); + counter_list[i] = value; + i++; + } + } + + return status; +} + +std::vector serialize_counter_id_list( + _In_ const sai_enum_metadata_t *stats_enum, + _In_ uint32_t count, + _In_ const int32_t *counter_id_list) +{ + SWSS_LOG_ENTER(); + + std::vector values; + + for (uint32_t i = 0; i < count; i++) + { + const char *name = sai_metadata_get_enum_value_name(stats_enum, counter_id_list[i]); + + if (name == NULL) + { + SWSS_LOG_THROW("failed to find enum %d in %s", counter_id_list[i], stats_enum->name); + } + + values.emplace_back(name, ""); + } + + return std::move(values); +} + +sai_status_t internal_redis_generic_get_stats( + _In_ sai_object_type_t object_type, + _In_ const std::string &serialized_object_id, + _In_ const sai_enum_metadata_t *stats_enum, + _In_ uint32_t count, + _In_ const int32_t *counter_id_list, + _Out_ uint64_t *counter_list) +{ + SWSS_LOG_ENTER(); + + std::vector entry = serialize_counter_id_list( + stats_enum, + count, + counter_id_list); + + std::string str_object_type = sai_serialize_object_type(object_type); + + std::string key = str_object_type + ":" + serialized_object_id; + + SWSS_LOG_DEBUG("generic get stats key: %s, fields: %lu", key.c_str(), entry.size()); + + if (g_record) + { + recordLine("m|" + key + "|" + joinFieldValues(entry)); + } + + // get is special, it will not put data + // into asic view, only to message queue + g_asicState->set(key, entry, "get_stats"); + + // wait for response + + swss::Select s; + + s.addSelectable(g_redisGetConsumer.get()); + + while (true) + { + SWSS_LOG_DEBUG("wait for get_stats response"); + + swss::Selectable *sel; + + int result = s.select(&sel, GET_RESPONSE_TIMEOUT); + + if (result == swss::Select::OBJECT) + { + swss::KeyOpFieldsValuesTuple kco; + + g_redisGetConsumer->pop(kco); + + const std::string &op = kfvOp(kco); + const std::string &opkey = kfvKey(kco); + + SWSS_LOG_DEBUG("response: op = %s, key = %s", opkey.c_str(), op.c_str()); + + if (op != "getresponse") // ignore non response messages + { + continue; + } + + sai_status_t status = internal_redis_get_stats_process( + object_type, + count, + counter_list, + kco); + + if (g_record) + { + const auto &str_status = kfvKey(kco); + const auto &values = kfvFieldsValues(kco); + + // first serialized is status + recordLine("M|" + str_status + "|" + joinFieldValues(values)); + } + + SWSS_LOG_DEBUG("generic get status: %d", status); + + return status; + } + + SWSS_LOG_ERROR("generic get failed due to SELECT operation result"); + break; + } + + if (g_record) + { + recordLine("M|SAI_STATUS_FAILURE"); + } + + SWSS_LOG_ERROR("generic get stats failed to get response"); + + return SAI_STATUS_FAILURE; +} + +sai_status_t redis_generic_get_stats( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *stats_enum, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids, + _Out_ uint64_t *counters) +{ + SWSS_LOG_ENTER(); + + std::string str_object_id = sai_serialize_object_id(object_id); + + return internal_redis_generic_get_stats( + object_type, + str_object_id, + stats_enum, + number_of_counters, + counter_ids, + counters); +} + +sai_status_t redis_generic_get_stats_ext( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids, + _In_ sai_stats_mode_t mode, + _Out_ uint64_t *counters) +{ + SWSS_LOG_ENTER(); + + return redis_generic_stats_function( + object_type, + object_id, + enum_metadata, + number_of_counters, + counter_ids, + mode, + counters); +} + +sai_status_t redis_generic_clear_stats( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids) +{ + SWSS_LOG_ENTER(); + + /* + * Clear stats is the same as get stats ext with mode == + * SAI_STATS_MODE_READ_AND_CLEAR and we just read counters locally and + * discard them, in that way. + */ + + uint64_t counters[REDIS_MAX_COUNTERS]; + + return redis_generic_stats_function( + object_type, + object_id, + enum_metadata, + number_of_counters, + counter_ids, + SAI_STATS_MODE_READ_AND_CLEAR, + counters); +} diff --git a/lib/src/sai_redis_interfacequery.cpp b/lib/src/sai_redis_interfacequery.cpp index b1c356485547..b39cde4bce38 100644 --- a/lib/src/sai_redis_interfacequery.cpp +++ b/lib/src/sai_redis_interfacequery.cpp @@ -212,39 +212,45 @@ sai_status_t sai_api_query( switch (sai_api_id) { API_CASE(ACL,acl); + API_CASE(BFD,bfd); API_CASE(BRIDGE,bridge); API_CASE(BUFFER,buffer); + API_CASE(DTEL,dtel); API_CASE(FDB,fdb); API_CASE(HASH,hash); API_CASE(HOSTIF,hostif); - //API_CASE(IPMC,ipmc); - //API_CASE(IPMC_GROUP,ipmc_group); - //API_CASE(L2MC,l2mc); - //API_CASE(L2MC_GROUP,l2mc_group); + API_CASE(IPMC_GROUP,ipmc_group); + API_CASE(IPMC,ipmc); + //API_CASE(ISOLATION_GROUP,isolation_group); + API_CASE(L2MC_GROUP,l2mc_group); + API_CASE(L2MC,l2mc); API_CASE(LAG,lag); - //API_CASE(MCAST_FDB,mcast_fdb); + API_CASE(MCAST_FDB,mcast_fdb); API_CASE(MIRROR,mirror); + API_CASE(MPLS,mpls); API_CASE(NEIGHBOR,neighbor); - API_CASE(NEXT_HOP,next_hop); API_CASE(NEXT_HOP_GROUP,next_hop_group); + API_CASE(NEXT_HOP,next_hop); API_CASE(POLICER,policer); API_CASE(PORT,port); API_CASE(QOS_MAP,qos_map); API_CASE(QUEUE,queue); - API_CASE(ROUTE,route); API_CASE(ROUTER_INTERFACE,router_interface); - //API_CASE(RPF_GROUP,rpf_group); + API_CASE(ROUTE,route); + API_CASE(RPF_GROUP,rpf_group); API_CASE(SAMPLEPACKET,samplepacket); - API_CASE(SCHEDULER,scheduler); API_CASE(SCHEDULER_GROUP,scheduler_group); + API_CASE(SCHEDULER,scheduler); + API_CASE(SEGMENTROUTE,segmentroute); API_CASE(STP,stp); API_CASE(SWITCH,switch); + API_CASE(TAM,tam); API_CASE(TUNNEL,tunnel); + API_CASE(UBURST,uburst); API_CASE(UDF,udf); API_CASE(VIRTUAL_ROUTER,virtual_router); API_CASE(VLAN,vlan); API_CASE(WRED,wred); - API_CASE(DTEL,dtel); default: SWSS_LOG_ERROR("Invalid API type %d", sai_api_id); diff --git a/lib/src/sai_redis_ipmc.cpp b/lib/src/sai_redis_ipmc.cpp new file mode 100644 index 000000000000..ddc90bd27bf2 --- /dev/null +++ b/lib/src/sai_redis_ipmc.cpp @@ -0,0 +1,9 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD_ENTRY(IPMC_ENTRY,ipmc_entry); + +const sai_ipmc_api_t redis_ipmc_api = { + + REDIS_GENERIC_QUAD_API(ipmc_entry) +}; diff --git a/lib/src/sai_redis_ipmc_group.cpp b/lib/src/sai_redis_ipmc_group.cpp new file mode 100644 index 000000000000..acfa53e0f068 --- /dev/null +++ b/lib/src/sai_redis_ipmc_group.cpp @@ -0,0 +1,11 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD(IPMC_GROUP,ipmc_group); +REDIS_GENERIC_QUAD(IPMC_GROUP_MEMBER,ipmc_group_member); + +const sai_ipmc_group_api_t redis_ipmc_group_api = { + + REDIS_GENERIC_QUAD_API(ipmc_group) + REDIS_GENERIC_QUAD_API(ipmc_group_member) +}; diff --git a/lib/src/sai_redis_l2mc.cpp b/lib/src/sai_redis_l2mc.cpp new file mode 100644 index 000000000000..3b381eb0b9ee --- /dev/null +++ b/lib/src/sai_redis_l2mc.cpp @@ -0,0 +1,9 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD_ENTRY(L2MC_ENTRY,l2mc_entry); + +const sai_l2mc_api_t redis_l2mc_api = { + + REDIS_GENERIC_QUAD_API(l2mc_entry) +}; diff --git a/lib/src/sai_redis_l2mcgroup.cpp b/lib/src/sai_redis_l2mcgroup.cpp new file mode 100644 index 000000000000..dabcf9841058 --- /dev/null +++ b/lib/src/sai_redis_l2mcgroup.cpp @@ -0,0 +1,11 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD(L2MC_GROUP,l2mc_group); +REDIS_GENERIC_QUAD(L2MC_GROUP_MEMBER,l2mc_group_member); + +const sai_l2mc_group_api_t redis_l2mc_group_api = { + + REDIS_GENERIC_QUAD_API(l2mc_group) + REDIS_GENERIC_QUAD_API(l2mc_group_member) +}; diff --git a/lib/src/sai_redis_mcastfdb.cpp b/lib/src/sai_redis_mcastfdb.cpp new file mode 100644 index 000000000000..86ca62e43350 --- /dev/null +++ b/lib/src/sai_redis_mcastfdb.cpp @@ -0,0 +1,9 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD_ENTRY(MCAST_FDB_ENTRY,mcast_fdb_entry); + +const sai_mcast_fdb_api_t redis_mcast_fdb_api = { + + REDIS_GENERIC_QUAD_API(mcast_fdb_entry) +}; diff --git a/lib/src/sai_redis_mpls.cpp b/lib/src/sai_redis_mpls.cpp new file mode 100644 index 000000000000..3e227aee1bf8 --- /dev/null +++ b/lib/src/sai_redis_mpls.cpp @@ -0,0 +1,9 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD_ENTRY(INSEG_ENTRY,inseg_entry); + +const sai_mpls_api_t redis_mpls_api = { + + REDIS_GENERIC_QUAD_API(inseg_entry) +}; diff --git a/lib/src/sai_redis_nexthopgroup.cpp b/lib/src/sai_redis_nexthopgroup.cpp index 1c266d70bcfd..44907cecca06 100644 --- a/lib/src/sai_redis_nexthopgroup.cpp +++ b/lib/src/sai_redis_nexthopgroup.cpp @@ -4,7 +4,7 @@ sai_status_t sai_bulk_create_next_hop_group_members( _In_ sai_object_id_t switch_id, _In_ uint32_t object_count, _In_ const uint32_t *attr_count, - _In_ const sai_attribute_t *const *attrs, + _In_ const sai_attribute_t **attrs, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_object_id_t *object_id, _Out_ sai_status_t *object_statuses) @@ -13,8 +13,14 @@ sai_status_t sai_bulk_create_next_hop_group_members( SWSS_LOG_ENTER(); - return redis_bulk_generic_create(SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER, object_count, object_id - , switch_id, attr_count, attrs, object_statuses); + return redis_bulk_generic_create( + SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER, + object_count, + object_id, + switch_id, + attr_count, + attrs, + object_statuses); } sai_status_t sai_bulk_remove_next_hop_group_members( @@ -27,7 +33,11 @@ sai_status_t sai_bulk_remove_next_hop_group_members( SWSS_LOG_ENTER(); - return redis_bulk_generic_remove(SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER, object_count, object_id, object_statuses); + return redis_bulk_generic_remove( + SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER, + object_count, + object_id, + object_statuses); } REDIS_GENERIC_QUAD(NEXT_HOP_GROUP,next_hop_group); @@ -38,7 +48,6 @@ const sai_next_hop_group_api_t redis_next_hop_group_api = { REDIS_GENERIC_QUAD_API(next_hop_group) REDIS_GENERIC_QUAD_API(next_hop_group_member) - // TODO: upstream signiture fix to SAI repo - (sai_bulk_object_create_fn)sai_bulk_create_next_hop_group_members, + sai_bulk_create_next_hop_group_members, sai_bulk_remove_next_hop_group_members, }; diff --git a/lib/src/sai_redis_notifications.cpp b/lib/src/sai_redis_notifications.cpp index 3273205ab463..22d2b20bd9fd 100644 --- a/lib/src/sai_redis_notifications.cpp +++ b/lib/src/sai_redis_notifications.cpp @@ -7,23 +7,13 @@ * this will need to be corrected later. */ -sai_switch_state_change_notification_fn on_switch_state_change = NULL; -sai_switch_shutdown_request_notification_fn on_switch_shutdown_request_notification = NULL; -sai_fdb_event_notification_fn on_fdb_event = NULL; -sai_port_state_change_notification_fn on_port_state_change = NULL; -sai_packet_event_notification_fn on_packet_event = NULL; -sai_queue_pfc_deadlock_notification_fn on_queue_deadlock = NULL; +sai_switch_notifications_t sn; void clear_notifications() { SWSS_LOG_ENTER(); - on_switch_state_change = NULL; - on_switch_shutdown_request_notification = NULL; - on_fdb_event = NULL; - on_port_state_change = NULL; - on_packet_event = NULL; - on_queue_deadlock = NULL; + memset(&sn, 0, sizeof(sn)); } void check_notifications_pointers( @@ -57,27 +47,27 @@ void check_notifications_pointers( switch (attr.id) { case SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY: - on_switch_state_change = (sai_switch_state_change_notification_fn)attr.value.ptr; + sn.on_switch_state_change = (sai_switch_state_change_notification_fn)attr.value.ptr; break; case SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY: - on_switch_shutdown_request_notification = (sai_switch_shutdown_request_notification_fn)attr.value.ptr; + sn.on_switch_shutdown_request = (sai_switch_shutdown_request_notification_fn)attr.value.ptr; break; case SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY: - on_fdb_event = (sai_fdb_event_notification_fn)attr.value.ptr; + sn.on_fdb_event = (sai_fdb_event_notification_fn)attr.value.ptr; break; case SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY: - on_port_state_change = (sai_port_state_change_notification_fn)attr.value.ptr; + sn.on_port_state_change = (sai_port_state_change_notification_fn)attr.value.ptr; break; case SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY: - on_packet_event = (sai_packet_event_notification_fn)attr.value.ptr; + sn.on_packet_event = (sai_packet_event_notification_fn)attr.value.ptr; break; case SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY: - on_queue_deadlock = (sai_queue_pfc_deadlock_notification_fn)attr.value.ptr; + sn.on_queue_pfc_deadlock = (sai_queue_pfc_deadlock_notification_fn)attr.value.ptr; break; default: @@ -99,9 +89,9 @@ void handle_switch_state_change( sai_deserialize_switch_oper_status(data, switch_id, switch_oper_status); - if (on_switch_state_change != NULL) + if (sn.on_switch_state_change != NULL) { - on_switch_state_change(switch_id, switch_oper_status); + sn.on_switch_state_change(switch_id, switch_oper_status); } } @@ -127,9 +117,9 @@ void handle_fdb_event( meta_sai_on_fdb_event(count, fdbevent); } - if (on_fdb_event != NULL) + if (sn.on_fdb_event != NULL) { - on_fdb_event(count, fdbevent); + sn.on_fdb_event(count, fdbevent); } sai_deserialize_free_fdb_event_ntf(count, fdbevent); @@ -147,9 +137,9 @@ void handle_port_state_change( sai_deserialize_port_oper_status_ntf(data, count, &portoperstatus); - if (on_port_state_change != NULL) + if (sn.on_port_state_change != NULL) { - on_port_state_change(count, portoperstatus); + sn.on_port_state_change(count, portoperstatus); } sai_deserialize_free_port_oper_status_ntf(count, portoperstatus); @@ -166,9 +156,9 @@ void handle_switch_shutdown_request( sai_deserialize_switch_shutdown_request(data, switch_id); - if (on_switch_shutdown_request_notification != NULL) + if (sn.on_switch_shutdown_request != NULL) { - on_switch_shutdown_request_notification(switch_id); + sn.on_switch_shutdown_request(switch_id); } } @@ -182,7 +172,7 @@ void handle_packet_event( SWSS_LOG_ERROR("not implemented"); - if (on_packet_event != NULL) + if (sn.on_packet_event != NULL) { //on_packet_event(switch_id, buffer.data(), buffer_size, list.get_attr_count(), list.get_attr_list()); } @@ -200,9 +190,9 @@ void handle_queue_deadlock_event( sai_deserialize_queue_deadlock_ntf(data, count, &ntfData); - if (on_queue_deadlock != NULL) + if (sn.on_queue_pfc_deadlock != NULL) { - on_queue_deadlock(count, ntfData); + sn.on_queue_pfc_deadlock(count, ntfData); } sai_deserialize_free_queue_deadlock_ntf(count, ntfData); diff --git a/lib/src/sai_redis_policer.cpp b/lib/src/sai_redis_policer.cpp index 3101f1b0b8cf..4129c9cd4945 100644 --- a/lib/src/sai_redis_policer.cpp +++ b/lib/src/sai_redis_policer.cpp @@ -1,51 +1,10 @@ #include "sai_redis.h" -sai_status_t redis_get_policer_stats( - _In_ sai_object_id_t policer_id, - _In_ uint32_t number_of_counters, - _In_ const sai_policer_stat_t *counter_ids, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_sai_get_policer_stats_ext( - _In_ sai_object_id_t policer_id, - _In_ uint32_t number_of_counters, - _In_ const sai_policer_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_policer_stats( - _In_ sai_object_id_t policer_id, - _In_ uint32_t number_of_counters, - _In_ const sai_policer_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(POLICER,policer); +REDIS_GENERIC_STATS(POLICER,policer); const sai_policer_api_t redis_policer_api = { REDIS_GENERIC_QUAD_API(policer) - - redis_get_policer_stats, - redis_sai_get_policer_stats_ext, - redis_clear_policer_stats, + REDIS_GENERIC_STATS_API(policer) }; diff --git a/lib/src/sai_redis_port.cpp b/lib/src/sai_redis_port.cpp index 5f05bbfd840c..83c39149fb1d 100644 --- a/lib/src/sai_redis_port.cpp +++ b/lib/src/sai_redis_port.cpp @@ -1,31 +1,5 @@ #include "sai_redis.h" -sai_status_t redis_clear_port_stats( - _In_ sai_object_id_t port_id, - _In_ uint32_t number_of_counters, - _In_ const sai_port_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_port_stats_ext( - _In_ sai_object_id_t port_id, - _In_ uint32_t number_of_counters, - _In_ const sai_port_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - sai_status_t redis_clear_port_all_stats( _In_ sai_object_id_t port_id) { @@ -36,50 +10,18 @@ sai_status_t redis_clear_port_all_stats( return SAI_STATUS_NOT_IMPLEMENTED; } -sai_status_t redis_get_port_pool_stats_ext( - _In_ sai_object_id_t port_pool_id, - _In_ uint32_t number_of_counters, - _In_ const sai_port_pool_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_port_pool_stats( - _In_ sai_object_id_t port_pool_id, - _In_ uint32_t number_of_counters, - _In_ const sai_port_pool_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(PORT,port); REDIS_GENERIC_QUAD(PORT_POOL,port_pool); - -REDIS_GENERIC_GET_STATS(PORT, port); -REDIS_GENERIC_GET_STATS(PORT_POOL, port_pool); +REDIS_GENERIC_STATS(PORT,port); +REDIS_GENERIC_STATS(PORT_POOL,port_pool); const sai_port_api_t redis_port_api = { REDIS_GENERIC_QUAD_API(port) + REDIS_GENERIC_STATS_API(port) - redis_get_port_stats, - redis_get_port_stats_ext, - redis_clear_port_stats, redis_clear_port_all_stats, REDIS_GENERIC_QUAD_API(port_pool) - - redis_get_port_pool_stats, - redis_get_port_pool_stats_ext, - redis_clear_port_pool_stats + REDIS_GENERIC_STATS_API(port_pool) }; diff --git a/lib/src/sai_redis_queue.cpp b/lib/src/sai_redis_queue.cpp index 3d0a51f5d22f..1954ed1c37f6 100644 --- a/lib/src/sai_redis_queue.cpp +++ b/lib/src/sai_redis_queue.cpp @@ -1,41 +1,11 @@ #include "sai_redis.h" #include "sai_redis_internal.h" -sai_status_t redis_clear_queue_stats( - _In_ sai_object_id_t queue_id, - _In_ uint32_t number_of_counters, - _In_ const sai_queue_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_queue_stats_ext( - _In_ sai_object_id_t queue_id, - _In_ uint32_t number_of_counters, - _In_ const sai_queue_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(QUEUE,queue); - -REDIS_GENERIC_GET_STATS(QUEUE, queue); +REDIS_GENERIC_STATS(QUEUE,queue); const sai_queue_api_t redis_queue_api = { REDIS_GENERIC_QUAD_API(queue) - - redis_get_queue_stats, - redis_get_queue_stats_ext, - redis_clear_queue_stats, + REDIS_GENERIC_STATS_API(queue) }; diff --git a/lib/src/sai_redis_route.cpp b/lib/src/sai_redis_route.cpp index 348e1a4a64e5..982116e0dab6 100644 --- a/lib/src/sai_redis_route.cpp +++ b/lib/src/sai_redis_route.cpp @@ -24,7 +24,7 @@ sai_status_t sai_bulk_create_route_entry( _In_ uint32_t object_count, _In_ const sai_route_entry_t *route_entry, _In_ const uint32_t *attr_count, - _In_ const sai_attribute_t *const *attr_list, + _In_ const sai_attribute_t **attr_list, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_status_t *object_statuses) { @@ -301,8 +301,7 @@ const sai_route_api_t redis_route_api = { REDIS_GENERIC_QUAD_API(route_entry) - // TODO: upstream signiture fix to SAI repo - (sai_bulk_create_route_entry_fn)sai_bulk_create_route_entry, + sai_bulk_create_route_entry, sai_bulk_remove_route_entry, sai_bulk_set_route_entry_attribute, sai_bulk_get_route_entry_attribute, diff --git a/lib/src/sai_redis_router_interface.cpp b/lib/src/sai_redis_router_interface.cpp new file mode 100644 index 000000000000..feab7584e9c5 --- /dev/null +++ b/lib/src/sai_redis_router_interface.cpp @@ -0,0 +1,10 @@ +#include "sai_redis.h" + +REDIS_GENERIC_QUAD(ROUTER_INTERFACE,router_interface); +REDIS_GENERIC_STATS(ROUTER_INTERFACE,router_interface); + +const sai_router_interface_api_t redis_router_interface_api = { + + REDIS_GENERIC_QUAD_API(router_interface) + REDIS_GENERIC_STATS_API(router_interface) +}; diff --git a/lib/src/sai_redis_routerintf.cpp b/lib/src/sai_redis_routerintf.cpp deleted file mode 100644 index 2536faefd27e..000000000000 --- a/lib/src/sai_redis_routerintf.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "sai_redis.h" - -REDIS_GENERIC_QUAD(ROUTER_INTERFACE,router_interface); - -sai_status_t redis_get_router_interface_stats( - _In_ sai_object_id_t router_interface_id, - _In_ uint32_t number_of_counters, - _In_ const sai_router_interface_stat_t *counter_ids, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_router_interface_stats_ext( - _In_ sai_object_id_t router_interface_id, - _In_ uint32_t number_of_counters, - _In_ const sai_router_interface_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_router_interface_stats( - _In_ sai_object_id_t router_interface_id, - _In_ uint32_t number_of_counters, - _In_ const sai_router_interface_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -const sai_router_interface_api_t redis_router_interface_api = { - - REDIS_GENERIC_QUAD_API(router_interface) - - redis_get_router_interface_stats, - redis_get_router_interface_stats_ext, - redis_clear_router_interface_stats, -}; diff --git a/lib/src/sai_redis_rpfgroup.cpp b/lib/src/sai_redis_rpfgroup.cpp new file mode 100644 index 000000000000..723760b84d3a --- /dev/null +++ b/lib/src/sai_redis_rpfgroup.cpp @@ -0,0 +1,11 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD(RPF_GROUP,rpf_group); +REDIS_GENERIC_QUAD(RPF_GROUP_MEMBER,rpf_group_member); + +const sai_rpf_group_api_t redis_rpf_group_api = { + + REDIS_GENERIC_QUAD_API(rpf_group) + REDIS_GENERIC_QUAD_API(rpf_group_member) +}; diff --git a/lib/src/sai_redis_segmentroute.cpp b/lib/src/sai_redis_segmentroute.cpp new file mode 100644 index 000000000000..c16996dd6cf3 --- /dev/null +++ b/lib/src/sai_redis_segmentroute.cpp @@ -0,0 +1,41 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +sai_status_t redis_create_segmentroute_sidlists( + _In_ sai_object_id_t switch_id, + _In_ uint32_t object_count, + _In_ const uint32_t *attr_count, + _In_ const sai_attribute_t **attrs, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_object_id_t *object_id, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + + SWSS_LOG_ENTER(); + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +sai_status_t redis_remove_segmentroute_sidlists( + _In_ uint32_t object_count, + _In_ const sai_object_id_t *object_id, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + + SWSS_LOG_ENTER(); + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +REDIS_GENERIC_QUAD(SEGMENTROUTE_SIDLIST,segmentroute_sidlist); + +const sai_segmentroute_api_t redis_segmentroute_api = { + + REDIS_GENERIC_QUAD_API(segmentroute_sidlist) + + redis_create_segmentroute_sidlists, + redis_remove_segmentroute_sidlists, +}; diff --git a/lib/src/sai_redis_tam.cpp b/lib/src/sai_redis_tam.cpp new file mode 100644 index 000000000000..685e6b3224aa --- /dev/null +++ b/lib/src/sai_redis_tam.cpp @@ -0,0 +1,31 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +sai_status_t redis_get_tam_snapshot_stats( + _In_ sai_object_id_t tam_snapshot_id, + _Inout_ uint32_t *number_of_counters, + _Inout_ sai_tam_statistic_t *statistics) +{ + MUTEX(); + SWSS_LOG_ENTER(); + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +REDIS_GENERIC_QUAD(TAM,tam); +REDIS_GENERIC_QUAD(TAM_STAT,tam_stat); +REDIS_GENERIC_QUAD(TAM_THRESHOLD,tam_threshold); +REDIS_GENERIC_QUAD(TAM_SNAPSHOT,tam_snapshot); +REDIS_GENERIC_QUAD(TAM_TRANSPORTER,tam_transporter); + +const sai_tam_api_t redis_tam_api = { + + REDIS_GENERIC_QUAD_API(tam) + REDIS_GENERIC_QUAD_API(tam_stat) + REDIS_GENERIC_QUAD_API(tam_threshold) + REDIS_GENERIC_QUAD_API(tam_snapshot) + + redis_get_tam_snapshot_stats, + + REDIS_GENERIC_QUAD_API(tam_transporter) +}; diff --git a/lib/src/sai_redis_tunnel.cpp b/lib/src/sai_redis_tunnel.cpp index 4126a238dcd9..5c7ea6462cb8 100644 --- a/lib/src/sai_redis_tunnel.cpp +++ b/lib/src/sai_redis_tunnel.cpp @@ -1,46 +1,16 @@ #include "sai_redis.h" -sai_status_t redis_clear_tunnel_stats( - _In_ sai_object_id_t tunnel_id, - _In_ uint32_t number_of_counters, - _In_ const sai_tunnel_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_tunnel_stats_ext( - _In_ sai_object_id_t tunnel_id, - _In_ uint32_t number_of_counters, - _In_ const sai_tunnel_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(TUNNEL_MAP,tunnel_map); REDIS_GENERIC_QUAD(TUNNEL,tunnel); REDIS_GENERIC_QUAD(TUNNEL_TERM_TABLE_ENTRY,tunnel_term_table_entry); REDIS_GENERIC_QUAD(TUNNEL_MAP_ENTRY,tunnel_map_entry); - -REDIS_GENERIC_GET_STATS(TUNNEL, tunnel); +REDIS_GENERIC_STATS(TUNNEL,tunnel); const sai_tunnel_api_t redis_tunnel_api = { + REDIS_GENERIC_QUAD_API(tunnel_map) REDIS_GENERIC_QUAD_API(tunnel) - - redis_get_tunnel_stats, - redis_get_tunnel_stats_ext, - redis_clear_tunnel_stats, - + REDIS_GENERIC_STATS_API(tunnel) REDIS_GENERIC_QUAD_API(tunnel_term_table_entry) REDIS_GENERIC_QUAD_API(tunnel_map_entry) }; diff --git a/lib/src/sai_redis_uburst.cpp b/lib/src/sai_redis_uburst.cpp new file mode 100644 index 000000000000..46e9bbe5dba5 --- /dev/null +++ b/lib/src/sai_redis_uburst.cpp @@ -0,0 +1,25 @@ +#include "sai_redis.h" +#include "sai_redis_internal.h" + +REDIS_GENERIC_QUAD(TAM_MICROBURST,tam_microburst); +REDIS_GENERIC_QUAD(TAM_HISTOGRAM,tam_histogram); + +sai_status_t redis_get_tam_histogram_stats( + _In_ sai_object_id_t tam_histogram_id, + _Inout_ uint32_t *number_of_counters, + _Out_ uint64_t *counters) +{ + MUTEX(); + + SWSS_LOG_ENTER(); + + return SAI_STATUS_NOT_IMPLEMENTED; +} + +const sai_uburst_api_t redis_uburst_api = { + + REDIS_GENERIC_QUAD_API(tam_microburst) + REDIS_GENERIC_QUAD_API(tam_histogram) + + redis_get_tam_histogram_stats +}; diff --git a/lib/src/sai_redis_router.cpp b/lib/src/sai_redis_virtual_router.cpp similarity index 100% rename from lib/src/sai_redis_router.cpp rename to lib/src/sai_redis_virtual_router.cpp diff --git a/lib/src/sai_redis_vlan.cpp b/lib/src/sai_redis_vlan.cpp index 3eaffcc8cb9b..4fc96c14711e 100644 --- a/lib/src/sai_redis_vlan.cpp +++ b/lib/src/sai_redis_vlan.cpp @@ -29,47 +29,9 @@ sai_status_t redis_remove_vlan_members( return SAI_STATUS_NOT_IMPLEMENTED; } -sai_status_t redis_get_vlan_stats( - _In_ sai_object_id_t vlan_id, - _In_ uint32_t number_of_counters, - _In_ const sai_vlan_stat_t *counter_ids, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_get_vlan_stats_ext( - _In_ sai_object_id_t vlan_id, - _In_ uint32_t number_of_counters, - _In_ const sai_vlan_stat_t *counter_ids, - _In_ sai_stats_mode_t mode, - _Out_ uint64_t *counters) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - -sai_status_t redis_clear_vlan_stats( - _In_ sai_object_id_t vlan_id, - _In_ uint32_t number_of_counters, - _In_ const sai_vlan_stat_t *counter_ids) -{ - MUTEX(); - - SWSS_LOG_ENTER(); - - return SAI_STATUS_NOT_IMPLEMENTED; -} - REDIS_GENERIC_QUAD(VLAN,vlan); REDIS_GENERIC_QUAD(VLAN_MEMBER,vlan_member); +REDIS_GENERIC_STATS(VLAN,vlan); const sai_vlan_api_t redis_vlan_api = { @@ -78,7 +40,6 @@ const sai_vlan_api_t redis_vlan_api = { redis_create_vlan_members, redis_remove_vlan_members, - redis_get_vlan_stats, - redis_get_vlan_stats_ext, - redis_clear_vlan_stats, + + REDIS_GENERIC_STATS_API(vlan) }; diff --git a/meta/sai_meta.cpp b/meta/sai_meta.cpp index ba34ba446102..d6254b225d7c 100644 --- a/meta/sai_meta.cpp +++ b/meta/sai_meta.cpp @@ -2470,55 +2470,6 @@ sai_status_t meta_generic_validation_get( return SAI_STATUS_SUCCESS; } -template -sai_status_t meta_generic_validation_get_stats( - _In_ const sai_object_meta_key_t& meta_key, - _In_ uint32_t count, - _In_ const T *counter_id_list, - _In_ const uint64_t *counter_list) -{ - SWSS_LOG_ENTER(); - - if (meta_unittests_enabled() && (count & 0x80000000)) - { - /* - * If last bit of counters count is set to high, and unittests are enabled, - * then this api can be used to SET counter values by user for debugging purposes. - */ - count = count & ~0x80000000; - } - - if (count < 1) - { - SWSS_LOG_ERROR("expected at least 1 stat when calling get_stats, zero given"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - if (count > MAX_LIST_COUNT) - { - SWSS_LOG_ERROR("get stats count %u > max list count %u", count, MAX_LIST_COUNT); - - return SAI_STATUS_INVALID_PARAMETER; - } - - if (counter_id_list == NULL) - { - SWSS_LOG_ERROR("counter id list pointer is NULL"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - if (counter_list == NULL) - { - SWSS_LOG_ERROR("counter list pointer is NULL"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - return SAI_STATUS_SUCCESS; -} - void meta_generic_validation_post_create( _In_ const sai_object_meta_key_t& meta_key, _In_ sai_object_id_t switch_id, @@ -5759,18 +5710,88 @@ sai_status_t meta_sai_get_oid( return status; } -template +// STATS + +sai_status_t meta_generic_validation_get_stats( + _In_ const sai_object_meta_key_t& meta_key, + _In_ const sai_enum_metadata_t* stats_enum, + _In_ uint32_t count, + _In_ const int32_t *counter_id_list, + _In_ const uint64_t *counter_list) +{ + SWSS_LOG_ENTER(); + + if (meta_unittests_enabled() && (count & 0x80000000)) + { + /* + * If last bit of counters count is set to high, and unittests are enabled, + * then this api can be used to SET counter values by user for debugging purposes. + */ + count = count & ~0x80000000; + } + + if (count < 1) + { + SWSS_LOG_ERROR("expected at least 1 stat when calling get_stats, zero given"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (count > MAX_LIST_COUNT) + { + SWSS_LOG_ERROR("get stats count %u > max list count %u", count, MAX_LIST_COUNT); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (counter_id_list == NULL) + { + SWSS_LOG_ERROR("counter id list pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (counter_list == NULL) + { + SWSS_LOG_ERROR("counter list pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (stats_enum == NULL) + { + SWSS_LOG_ERROR("enum metadata pointer is NULL, bug?"); + + return SAI_STATUS_FAILURE; + } + + for (uint32_t i = 0; i < count; i++) + { + if (sai_metadata_get_enum_value_name(stats_enum, counter_id_list[i]) == NULL) + { + SWSS_LOG_ERROR("counter id %u is not allowed on %s", counter_id_list[i], stats_enum->name); + + return SAI_STATUS_INVALID_PARAMETER; + } + } + + return SAI_STATUS_SUCCESS; +} + sai_status_t meta_sai_get_stats_oid( _In_ sai_object_type_t object_type, _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t* stats_enum, _In_ uint32_t count, - _In_ const T* counter_id_list, + _In_ const int32_t *counter_id_list, _Out_ uint64_t *counter_list, - _In_ sai_get_generic_stats_fn get) + _In_ sai_get_generic_stats_fn get_stats) { SWSS_LOG_ENTER(); - sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false); + sai_object_id_t switch_id = sai_switch_id_query(object_id); + + sai_status_t status = meta_sai_validate_oid(object_type, &object_id, switch_id, false); if (status != SAI_STATUS_SUCCESS) { @@ -5779,43 +5800,27 @@ sai_status_t meta_sai_get_stats_oid( sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } }; - status = meta_generic_validation_get_stats(meta_key, count, counter_id_list, counter_list); + status = meta_generic_validation_get_stats(meta_key, stats_enum, count, counter_id_list, counter_list); if (status != SAI_STATUS_SUCCESS) { return status; } - if (get == NULL) + if (get_stats == NULL) { SWSS_LOG_ERROR("get function pointer is NULL"); return SAI_STATUS_INVALID_PARAMETER; } - status = get(object_type, object_id, count, counter_id_list, counter_list); + status = get_stats(object_type, object_id, stats_enum, count, counter_id_list, counter_list); META_LOG_STATUS(status); return status; } -#define DECLARE_META_GET_STATS_OID(type) \ - template \ - sai_status_t meta_sai_get_stats_oid( \ - _In_ sai_object_type_t object_type, \ - _In_ sai_object_id_t object_id, \ - _In_ uint32_t count, \ - _In_ const sai_ ## type ## _stat_t* counter_id_list, \ - _Out_ uint64_t *counter_list, \ - _In_ sai_get_generic_stats_fn get); - -DECLARE_META_GET_STATS_OID(port); -DECLARE_META_GET_STATS_OID(port_pool); -DECLARE_META_GET_STATS_OID(queue); -DECLARE_META_GET_STATS_OID(ingress_priority_group); -DECLARE_META_GET_STATS_OID(tunnel); - // NOTIFICATIONS static sai_mac_t zero_mac = { 0, 0, 0, 0, 0, 0 }; diff --git a/meta/sai_meta.h b/meta/sai_meta.h index 29edd8edab6f..39b939fc35fc 100644 --- a/meta/sai_meta.h +++ b/meta/sai_meta.h @@ -39,14 +39,6 @@ typedef sai_status_t (*sai_get_generic_attribute_fn)( _In_ uint32_t attr_count, _Inout_ sai_attribute_t *attr_list); -template -using sai_get_generic_stats_fn = sai_status_t (*)( - _In_ sai_object_type_t object_type, - _In_ sai_object_id_t object_id, - _In_ uint32_t count, - _In_ const T* counter_id_list, - _Out_ uint64_t *counter_list); - // META GENERIC extern sai_status_t meta_sai_create_oid( @@ -75,15 +67,6 @@ extern sai_status_t meta_sai_get_oid( _Inout_ sai_attribute_t *attr_list, _In_ sai_get_generic_attribute_fn get); -template -extern sai_status_t meta_sai_get_stats_oid( - _In_ sai_object_type_t object_type, - _In_ sai_object_id_t object_id, - _In_ uint32_t count, - _In_ const T* counter_id_list, - _Inout_ uint64_t *counter_list, - _In_ sai_get_generic_stats_fn get); - // META ENTRY QUAD #define META_CREATE_ENTRY(ot) \ @@ -125,6 +108,25 @@ META_QUAD_ENTRY(mcast_fdb_entry); META_QUAD_ENTRY(neighbor_entry); META_QUAD_ENTRY(route_entry); +// STATS + +typedef sai_status_t (*sai_get_generic_stats_fn)( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t *enum_metadata, + _In_ uint32_t number_of_counters, + _In_ const int32_t *counter_ids, + _Out_ uint64_t *counters); + +sai_status_t meta_sai_get_stats_oid( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ const sai_enum_metadata_t* stats_enum, + _In_ uint32_t count, + _In_ const int32_t *counter_id_list, + _Out_ uint64_t *counter_list, + _In_ sai_get_generic_stats_fn get_stats); + // NOTIFICATIONS extern void meta_sai_on_fdb_event( diff --git a/syncd/tests.cpp b/syncd/tests.cpp index fadf85f812ed..95887696cdd0 100644 --- a/syncd/tests.cpp +++ b/syncd/tests.cpp @@ -217,7 +217,7 @@ void test_bulk_next_hop_group_member_create() ASSERT_SUCCESS("Failed to create switch"); std::vector> nhgm_attrs; - std::vector nhgm_attrs_array; + std::vector nhgm_attrs_array; std::vector nhgm_attrs_count; // next hop group @@ -257,8 +257,7 @@ void test_bulk_next_hop_group_member_create() std::vector statuses(count); std::vector object_id(count); - sai_bulk_create_next_hop_group_members(switch_id, count, nhgm_attrs_count.data(), nhgm_attrs_array.data() - , SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, object_id.data(), statuses.data()); + sai_bulk_create_next_hop_group_members(switch_id, count, nhgm_attrs_count.data(), nhgm_attrs_array.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, object_id.data(), statuses.data()); ASSERT_SUCCESS("Failed to bulk create nhgm"); for (size_t j = 0; j < statuses.size(); j++) { @@ -430,7 +429,7 @@ void test_bulk_route_set() ASSERT_SUCCESS("Failed to create switch"); std::vector> route_attrs; - std::vector route_attrs_array; + std::vector route_attrs_array; std::vector route_attrs_count; for (uint32_t i = index; i < index + count; ++i) @@ -477,8 +476,7 @@ void test_bulk_route_set() } std::vector statuses(count); - status = sai_bulk_create_route_entry(count, routes.data(), route_attrs_count.data(), route_attrs_array.data() - , SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data()); + status = sai_bulk_create_route_entry(count, routes.data(), route_attrs_count.data(), route_attrs_array.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data()); ASSERT_SUCCESS("Failed to create route"); for (size_t j = 0; j < statuses.size(); j++) { diff --git a/vslib/src/sai_vs_route.cpp b/vslib/src/sai_vs_route.cpp index 9a01a2a54533..14db9d1bf156 100644 --- a/vslib/src/sai_vs_route.cpp +++ b/vslib/src/sai_vs_route.cpp @@ -65,8 +65,6 @@ const sai_route_api_t vs_route_api = { VS_GENERIC_QUAD_API(route_entry) - // TODO: upstream signiture fix to SAI repo - // (sai_bulk_create_route_entry_fn)vs_bulk_create_route_entry, vs_bulk_create_route_entry, vs_bulk_remove_route_entry, vs_bulk_set_route_entry_attribute,