Skip to content

Commit 333c5ff

Browse files
authored
Refactor sairedis (#375)
* add missing object types * refactor stats to be generic
1 parent 38deb1e commit 333c5ff

39 files changed

+1017
-1101
lines changed

lib/inc/sai_redis.h

+97-78
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,21 @@ extern std::shared_ptr<swss::RedisClient> g_redisClient;
7070
extern std::mutex g_apimutex;
7171

7272
extern const sai_acl_api_t redis_acl_api;
73-
extern const sai_buffer_api_t redis_buffer_api;
73+
extern const sai_bfd_api_t redis_bfd_api;
7474
extern const sai_bridge_api_t redis_bridge_api;
75+
extern const sai_buffer_api_t redis_buffer_api;
76+
extern const sai_dtel_api_t redis_dtel_api;
7577
extern const sai_fdb_api_t redis_fdb_api;
7678
extern const sai_hash_api_t redis_hash_api;
7779
extern const sai_hostif_api_t redis_hostif_api;
80+
extern const sai_ipmc_api_t redis_ipmc_api;
81+
extern const sai_ipmc_group_api_t redis_ipmc_group_api;
82+
extern const sai_l2mc_api_t redis_l2mc_api;
83+
extern const sai_l2mc_group_api_t redis_l2mc_group_api;
7884
extern const sai_lag_api_t redis_lag_api;
85+
extern const sai_mcast_fdb_api_t redis_mcast_fdb_api;
7986
extern const sai_mirror_api_t redis_mirror_api;
87+
extern const sai_mpls_api_t redis_mpls_api;
8088
extern const sai_neighbor_api_t redis_neighbor_api;
8189
extern const sai_next_hop_api_t redis_next_hop_api;
8290
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;
8694
extern const sai_queue_api_t redis_queue_api;
8795
extern const sai_route_api_t redis_route_api;
8896
extern const sai_router_interface_api_t redis_router_interface_api;
97+
extern const sai_rpf_group_api_t redis_rpf_group_api;
8998
extern const sai_samplepacket_api_t redis_samplepacket_api;
9099
extern const sai_scheduler_api_t redis_scheduler_api;
91100
extern const sai_scheduler_group_api_t redis_scheduler_group_api;
101+
extern const sai_segmentroute_api_t redis_segmentroute_api;
92102
extern const sai_stp_api_t redis_stp_api;
93103
extern const sai_switch_api_t redis_switch_api;
104+
extern const sai_tam_api_t redis_tam_api;
94105
extern const sai_tunnel_api_t redis_tunnel_api;
106+
extern const sai_uburst_api_t redis_uburst_api;
95107
extern const sai_udf_api_t redis_udf_api;
96108
extern const sai_virtual_router_api_t redis_virtual_router_api;
97109
extern const sai_vlan_api_t redis_vlan_api;
98110
extern const sai_wred_api_t redis_wred_api;
99-
extern const sai_dtel_api_t redis_dtel_api;
100111

101112
#define UNREFERENCED_PARAMETER(X)
102113

@@ -118,29 +129,68 @@ void translate_rid_to_vid(
118129
_In_ uint32_t attr_count,
119130
_In_ sai_attribute_t *attr_list);
120131

121-
// CREATE
132+
// OID QUAD
122133

123134
sai_status_t redis_generic_create(
124135
_In_ sai_object_type_t object_type,
125-
_Out_ sai_object_id_t* object_id,
136+
_Out_ sai_object_id_t *object_id,
126137
_In_ sai_object_id_t switch_id,
127138
_In_ uint32_t attr_count,
128139
_In_ const sai_attribute_t *attr_list);
129140

130-
sai_status_t redis_generic_create_fdb_entry(
131-
_In_ const sai_fdb_entry_t *fdb_entry,
132-
_In_ uint32_t attr_count,
133-
_In_ const sai_attribute_t *attr_list);
141+
sai_status_t redis_generic_remove(
142+
_In_ sai_object_type_t object_type,
143+
_In_ sai_object_id_t object_id);
134144

135-
sai_status_t redis_generic_create_neighbor_entry(
136-
_In_ const sai_neighbor_entry_t* neighbor_entry,
137-
_In_ uint32_t attr_count,
138-
_In_ const sai_attribute_t *attr_list);
145+
sai_status_t redis_generic_set(
146+
_In_ sai_object_type_t object_type,
147+
_In_ sai_object_id_t object_id,
148+
_In_ const sai_attribute_t *attr);
139149

140-
sai_status_t redis_generic_create_route_entry(
141-
_In_ const sai_route_entry_t* route_entry,
150+
sai_status_t redis_generic_get(
151+
_In_ sai_object_type_t object_type,
152+
_In_ sai_object_id_t object_id,
142153
_In_ uint32_t attr_count,
143-
_In_ const sai_attribute_t *attr_list);
154+
_Out_ sai_attribute_t *attr_list);
155+
156+
// ENTRY QUAD
157+
158+
#define REDIS_CREATE_ENTRY_DEF(ot) \
159+
sai_status_t redis_generic_create_ ## ot( \
160+
_In_ const sai_ ## ot ## _t * ot, \
161+
_In_ uint32_t attr_count, \
162+
_In_ const sai_attribute_t *attr_list);
163+
164+
#define REDIS_REMOVE_ENTRY_DEF(ot) \
165+
sai_status_t redis_generic_remove_ ## ot( \
166+
_In_ const sai_ ## ot ## _t * ot);
167+
168+
#define REDIS_SET_ENTRY_DEF(ot) \
169+
sai_status_t redis_generic_set_ ## ot( \
170+
_In_ const sai_ ## ot ## _t * ot, \
171+
_In_ const sai_attribute_t *attr);
172+
173+
#define REDIS_GET_ENTRY_DEF(ot) \
174+
sai_status_t redis_generic_get_ ## ot( \
175+
_In_ const sai_ ## ot ## _t * ot, \
176+
_In_ uint32_t attr_count, \
177+
_Out_ sai_attribute_t *attr_list);
178+
179+
#define REDIS_ENTRY_QUAD(ot) \
180+
REDIS_CREATE_ENTRY_DEF(ot) \
181+
REDIS_REMOVE_ENTRY_DEF(ot) \
182+
REDIS_SET_ENTRY_DEF(ot) \
183+
REDIS_GET_ENTRY_DEF(ot)
184+
185+
REDIS_ENTRY_QUAD(fdb_entry);
186+
REDIS_ENTRY_QUAD(inseg_entry);
187+
REDIS_ENTRY_QUAD(ipmc_entry);
188+
REDIS_ENTRY_QUAD(l2mc_entry);
189+
REDIS_ENTRY_QUAD(mcast_fdb_entry);
190+
REDIS_ENTRY_QUAD(neighbor_entry);
191+
REDIS_ENTRY_QUAD(route_entry);
192+
193+
// BULK
144194

145195
sai_status_t redis_bulk_generic_create(
146196
_In_ sai_object_type_t object_type,
@@ -149,29 +199,14 @@ sai_status_t redis_bulk_generic_create(
149199
_In_ sai_object_id_t switch_id,
150200
_In_ const uint32_t *attr_count, /* array */
151201
_In_ const sai_attribute_t *const *attr_list, /* array */
152-
_Inout_ sai_status_t *object_statuses) /* array */;
202+
_Inout_ sai_status_t *object_statuses); /* array */
153203

154204
sai_status_t internal_redis_bulk_generic_create(
155205
_In_ sai_object_type_t object_type,
156206
_In_ const std::vector<std::string> &serialized_object_ids,
157207
_In_ const uint32_t *attr_count,
158-
_In_ const sai_attribute_t *const *attr_list,
159-
_Inout_ sai_status_t *object_statuses);
160-
161-
// REMOVE
162-
163-
sai_status_t redis_generic_remove(
164-
_In_ sai_object_type_t object_type,
165-
_In_ sai_object_id_t object_id);
166-
167-
sai_status_t redis_generic_remove_fdb_entry(
168-
_In_ const sai_fdb_entry_t* fdb_entry);
169-
170-
sai_status_t redis_generic_remove_neighbor_entry(
171-
_In_ const sai_neighbor_entry_t* neighbor_entry);
172-
173-
sai_status_t redis_generic_remove_route_entry(
174-
_In_ const sai_route_entry_t* route_entry);
208+
_In_ const sai_attribute_t *const *attr_list, /* array */
209+
_Inout_ sai_status_t *object_statuses) /* array */;
175210

176211
sai_status_t redis_bulk_generic_remove(
177212
_In_ sai_object_type_t object_type,
@@ -182,55 +217,13 @@ sai_status_t redis_bulk_generic_remove(
182217
sai_status_t internal_redis_bulk_generic_remove(
183218
_In_ sai_object_type_t object_type,
184219
_In_ const std::vector<std::string> &serialized_object_ids,
185-
_Out_ sai_status_t *object_statuses) /* array */;
186-
187-
// SET
188-
189-
sai_status_t redis_generic_set(
190-
_In_ sai_object_type_t object_type,
191-
_In_ sai_object_id_t object_id,
192-
_In_ const sai_attribute_t *attr);
193-
194-
sai_status_t redis_generic_set_fdb_entry(
195-
_In_ const sai_fdb_entry_t *fdb_entry,
196-
_In_ const sai_attribute_t *attr);
197-
198-
sai_status_t redis_generic_set_neighbor_entry(
199-
_In_ const sai_neighbor_entry_t* neighbor_entry,
200-
_In_ const sai_attribute_t *attr);
201-
202-
sai_status_t redis_generic_set_route_entry(
203-
_In_ const sai_route_entry_t* route_entry,
204-
_In_ const sai_attribute_t *attr);
220+
_Out_ sai_status_t *object_statuses); /* array */
205221

206222
sai_status_t internal_redis_bulk_generic_set(
207223
_In_ sai_object_type_t object_type,
208224
_In_ const std::vector<std::string> &serialized_object_ids,
209-
_In_ const sai_attribute_t *attr_list,
210-
_In_ const sai_status_t *object_statuses);
211-
212-
// GET
213-
214-
sai_status_t redis_generic_get(
215-
_In_ sai_object_type_t object_type,
216-
_In_ sai_object_id_t object_id,
217-
_In_ uint32_t attr_count,
218-
_Out_ sai_attribute_t *attr_list);
219-
220-
sai_status_t redis_generic_get_fdb_entry(
221-
_In_ const sai_fdb_entry_t *fdb_entry,
222-
_In_ uint32_t attr_count,
223-
_Out_ sai_attribute_t *attr_list);
224-
225-
sai_status_t redis_generic_get_neighbor_entry(
226-
_In_ const sai_neighbor_entry_t* neighbor_entry,
227-
_In_ uint32_t attr_count,
228-
_Out_ sai_attribute_t *attr_list);
229-
230-
sai_status_t redis_generic_get_route_entry(
231-
_In_ const sai_route_entry_t* route_entry,
232-
_In_ uint32_t attr_count,
233-
_Out_ sai_attribute_t *attr_list);
225+
_In_ const sai_attribute_t *attr_list, /* array */
226+
_In_ const sai_status_t *object_statuses); /* array */
234227

235228
// get_stats
236229

@@ -249,4 +242,30 @@ void handle_notification(
249242
_In_ const std::string &data,
250243
_In_ const std::vector<swss::FieldValueTuple> &values);
251244

245+
// STATS
246+
247+
sai_status_t redis_generic_get_stats(
248+
_In_ sai_object_type_t object_type,
249+
_In_ sai_object_id_t object_id,
250+
_In_ const sai_enum_metadata_t *enum_metadata,
251+
_In_ uint32_t number_of_counters,
252+
_In_ const int32_t *counter_ids,
253+
_Out_ uint64_t *counters);
254+
255+
sai_status_t redis_generic_get_stats_ext(
256+
_In_ sai_object_type_t object_type,
257+
_In_ sai_object_id_t object_id,
258+
_In_ const sai_enum_metadata_t *enum_metadata,
259+
_In_ uint32_t number_of_counters,
260+
_In_ const int32_t *counter_ids,
261+
_In_ sai_stats_mode_t mode,
262+
_Out_ uint64_t *counters);
263+
264+
sai_status_t redis_generic_clear_stats(
265+
_In_ sai_object_type_t object_type,
266+
_In_ sai_object_id_t object_id,
267+
_In_ const sai_enum_metadata_t *enum_metadata,
268+
_In_ uint32_t number_of_counters,
269+
_In_ const int32_t *counter_ids);
270+
252271
#endif // __SAI_REDIS__

lib/inc/sai_redis_internal.h

+65-17
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,69 @@
141141

142142
// stats
143143

144-
#define REDIS_GENERIC_GET_STATS(OBJECT_TYPE,object_type) \
145-
sai_status_t redis_get_ ## object_type ## _stats( \
146-
_In_ sai_object_id_t object_type ##_id, \
147-
_In_ uint32_t count, \
148-
_In_ const sai_ ## object_type ## _stat_t *counter_id_list, \
149-
_Out_ uint64_t *counter_list) \
150-
{ \
151-
MUTEX(); \
152-
SWSS_LOG_ENTER(); \
153-
\
154-
return meta_sai_get_stats_oid<sai_ ## object_type ## _stat_t>( \
155-
SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \
156-
object_type ## _id, \
157-
count, \
158-
counter_id_list, \
159-
counter_list, \
160-
&redis_generic_get_stats); \
144+
#define REDIS_GET_STATS(OBJECT_TYPE,object_type) \
145+
sai_status_t redis_get_ ## object_type ## _stats( \
146+
_In_ sai_object_id_t object_type ## _id, \
147+
_In_ uint32_t number_of_counters, \
148+
_In_ const sai_ ## object_type ## _stat_t *counter_ids, \
149+
_Out_ uint64_t *counters) \
150+
{ \
151+
MUTEX(); \
152+
SWSS_LOG_ENTER(); \
153+
return meta_sai_get_stats_oid( \
154+
SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \
155+
object_type ## _id, \
156+
&sai_metadata_enum_sai_ ## object_type ## _stat_t, \
157+
number_of_counters, \
158+
(const int32_t*)counter_ids, \
159+
counters, \
160+
&redis_generic_get_stats); \
161161
}
162+
163+
#define REDIS_GET_STATS_EXT(OBJECT_TYPE,object_type) \
164+
sai_status_t redis_get_ ## object_type ## _stats_ext( \
165+
_In_ sai_object_id_t object_type ## _id, \
166+
_In_ uint32_t number_of_counters, \
167+
_In_ const sai_ ## object_type ## _stat_t *counter_ids, \
168+
_In_ sai_stats_mode_t mode, \
169+
_Out_ uint64_t *counters) \
170+
{ \
171+
MUTEX(); \
172+
SWSS_LOG_ENTER(); \
173+
return redis_generic_get_stats_ext( \
174+
SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \
175+
object_type ## _id, \
176+
&sai_metadata_enum_sai_ ## object_type ## _stat_t, \
177+
number_of_counters, \
178+
(const int32_t*)counter_ids, \
179+
mode, \
180+
counters); \
181+
}
182+
183+
#define REDIS_CLEAR_STATS(OBJECT_TYPE,object_type) \
184+
sai_status_t redis_clear_ ## object_type ## _stats( \
185+
_In_ sai_object_id_t object_type ## _id, \
186+
_In_ uint32_t number_of_counters, \
187+
_In_ const sai_ ## object_type ## _stat_t *counter_ids) \
188+
{ \
189+
MUTEX(); \
190+
SWSS_LOG_ENTER(); \
191+
return redis_generic_clear_stats( \
192+
SAI_OBJECT_TYPE_ ## OBJECT_TYPE, \
193+
object_type ## _id, \
194+
&sai_metadata_enum_sai_ ## object_type ## _stat_t, \
195+
number_of_counters, \
196+
(const int32_t*)counter_ids); \
197+
}
198+
199+
#define REDIS_GENERIC_STATS(OT, ot) \
200+
REDIS_GET_STATS(OT,ot); \
201+
REDIS_GET_STATS_EXT(OT,ot); \
202+
REDIS_CLEAR_STATS(OT,ot);
203+
204+
// common stats api
205+
206+
#define REDIS_GENERIC_STATS_API(ot) \
207+
redis_get_ ## ot ## _stats, \
208+
redis_get_ ## ot ## _stats_ext, \
209+
redis_clear_ ## ot ## _stats,

lib/inc/sairedis.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ sai_status_t sai_bulk_create_route_entry(
149149
_In_ uint32_t object_count,
150150
_In_ const sai_route_entry_t *route_entry,
151151
_In_ const uint32_t *attr_count,
152-
_In_ const sai_attribute_t *const *attr_list,
152+
_In_ const sai_attribute_t **attr_list,
153153
_In_ sai_bulk_op_error_mode_t mode,
154154
_Out_ sai_status_t *object_statuses);
155155

@@ -224,7 +224,7 @@ sai_status_t sai_bulk_create_next_hop_group_members(
224224
_In_ sai_object_id_t switch_id,
225225
_In_ uint32_t object_count,
226226
_In_ const uint32_t *attr_count,
227-
_In_ const sai_attribute_t *const *attrs,
227+
_In_ const sai_attribute_t **attrs,
228228
_In_ sai_bulk_op_error_mode_t mode,
229229
_Out_ sai_object_id_t *object_id,
230230
_Out_ sai_status_t *object_statuses);

0 commit comments

Comments
 (0)