Skip to content

Commit

Permalink
Refactor sairedis (#375)
Browse files Browse the repository at this point in the history
* add missing object types
* refactor stats to be generic
  • Loading branch information
kcudnik authored Nov 11, 2018
1 parent 38deb1e commit 333c5ff
Show file tree
Hide file tree
Showing 39 changed files with 1,017 additions and 1,101 deletions.
175 changes: 97 additions & 78 deletions lib/inc/sai_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ extern std::shared_ptr<swss::RedisClient> 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;
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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<std::string> &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,
Expand All @@ -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<std::string> &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<std::string> &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

Expand All @@ -249,4 +242,30 @@ void handle_notification(
_In_ const std::string &data,
_In_ const std::vector<swss::FieldValueTuple> &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__
82 changes: 65 additions & 17 deletions lib/inc/sai_redis_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ## _stat_t>( \
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,
4 changes: 2 additions & 2 deletions lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 333c5ff

Please sign in to comment.