]> git.proxmox.com Git - mirror_frr.git/blame - lib/mgmt_fe_client.h
lib: mgmtd: remove obfuscating abstraction layer and other cleanup
[mirror_frr.git] / lib / mgmt_fe_client.h
CommitLineData
ef43a632
CH
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * MGMTD Frontend Client Library api interfaces
4 * Copyright (C) 2021 Vmware, Inc.
5 * Pushpasis Sarkar <spushpasis@vmware.com>
6 */
7
8#ifndef _FRR_MGMTD_FE_CLIENT_H_
9#define _FRR_MGMTD_FE_CLIENT_H_
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
ef43a632 15#include "mgmt_pb.h"
24a58196 16#include "frrevent.h"
f82370b4 17#include "mgmtd/mgmt_defines.h"
ef43a632
CH
18
19/***************************************************************
20 * Macros
21 ***************************************************************/
22
23/*
24 * The server port MGMTD daemon is listening for Backend Client
25 * connections.
26 */
27
28#define MGMTD_FE_CLIENT_ERROR_STRING_MAX_LEN 32
29
30#define MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC 5
31
32#define MGMTD_FE_MSG_PROC_DELAY_USEC 10
33#define MGMTD_FE_MAX_NUM_MSG_PROC 500
34
35#define MGMTD_FE_MSG_WRITE_DELAY_MSEC 1
36#define MGMTD_FE_MAX_NUM_MSG_WRITE 100
37
38#define GMGD_FE_MAX_NUM_REQ_ITEMS 64
39
40#define MGMTD_FE_MSG_MAX_LEN 9000
41
42#define MGMTD_SOCKET_FE_SEND_BUF_SIZE 65535
43#define MGMTD_SOCKET_FE_RECV_BUF_SIZE MGMTD_SOCKET_FE_SEND_BUF_SIZE
44
45/***************************************************************
46 * Data-structures
47 ***************************************************************/
48
49#define MGMTD_SESSION_ID_NONE 0
50
51#define MGMTD_CLIENT_ID_NONE 0
52
53#define MGMTD_DS_NONE MGMTD__DATASTORE_ID__DS_NONE
54#define MGMTD_DS_RUNNING MGMTD__DATASTORE_ID__RUNNING_DS
55#define MGMTD_DS_CANDIDATE MGMTD__DATASTORE_ID__CANDIDATE_DS
56#define MGMTD_DS_OPERATIONAL MGMTD__DATASTORE_ID__OPERATIONAL_DS
57#define MGMTD_DS_MAX_ID MGMTD_DS_OPERATIONAL + 1
58
65256cd8
CH
59struct mgmt_fe_client;
60
61
ef43a632
CH
62/*
63 * All the client specific information this library needs to
64 * initialize itself, setup connection with MGMTD FrontEnd interface
65 * and carry on all required procedures appropriately.
66 *
67 * FrontEnd clients need to initialise a instance of this structure
68 * with appropriate data and pass it while calling the API
69 * to initialize the library (See mgmt_fe_client_lib_init for
70 * more details).
71 */
65256cd8
CH
72struct mgmt_fe_client_cbs {
73 void (*client_connect_notify)(struct mgmt_fe_client *client,
74 uintptr_t user_data, bool connected);
75
76 void (*client_session_notify)(struct mgmt_fe_client *client,
77 uintptr_t user_data, uint64_t client_id,
ef43a632
CH
78 bool create, bool success,
79 uintptr_t session_id,
65256cd8 80 uintptr_t user_session_client);
ef43a632 81
65256cd8
CH
82 void (*lock_ds_notify)(struct mgmt_fe_client *client,
83 uintptr_t user_data, uint64_t client_id,
84 uintptr_t session_id,
85 uintptr_t user_session_client, uint64_t req_id,
ef43a632
CH
86 bool lock_ds, bool success,
87 Mgmtd__DatastoreId ds_id, char *errmsg_if_any);
88
65256cd8
CH
89 void (*set_config_notify)(struct mgmt_fe_client *client,
90 uintptr_t user_data, uint64_t client_id,
91 uintptr_t session_id,
92 uintptr_t user_session_client,
93 uint64_t req_id, bool success,
94 Mgmtd__DatastoreId ds_id,
ef43a632
CH
95 char *errmsg_if_any);
96
65256cd8
CH
97 void (*commit_config_notify)(struct mgmt_fe_client *client,
98 uintptr_t user_data, uint64_t client_id,
99 uintptr_t session_id,
100 uintptr_t user_session_client,
101 uint64_t req_id, bool success,
102 Mgmtd__DatastoreId src_ds_id,
103 Mgmtd__DatastoreId dst_ds_id,
104 bool validate_only, char *errmsg_if_any);
105
106 int (*get_data_notify)(struct mgmt_fe_client *client,
107 uintptr_t user_data, uint64_t client_id,
108 uintptr_t session_id,
109 uintptr_t user_session_client, uint64_t req_id,
110 bool success, Mgmtd__DatastoreId ds_id,
111 Mgmtd__YangData **yang_data, size_t num_data,
112 int next_key, char *errmsg_if_any);
113
114 int (*data_notify)(uint64_t client_id, uint64_t session_id,
115 uintptr_t user_data, uint64_t req_id,
116 Mgmtd__DatastoreId ds_id,
117 Mgmtd__YangData **yang_data, size_t num_data);
ef43a632
CH
118};
119
a1d8c7a3
CH
120extern struct debug mgmt_dbg_fe_client;
121
122#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
123 DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s:" fmt, __func__, \
124 ##__VA_ARGS__)
125#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
126 zlog_err("FE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__)
127#define MGMTD_DBG_FE_CLIENT_CHECK() \
128 DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_ALL)
129
130
ef43a632
CH
131/***************************************************************
132 * API prototypes
133 ***************************************************************/
134
135/*
136 * Initialize library and try connecting with MGMTD FrontEnd interface.
137 *
138 * params
139 * Frontend client parameters.
140 *
141 * master_thread
142 * Thread master.
143 *
144 * Returns:
65256cd8 145 * Frontend client lib handler (nothing but address of mgmt_fe_client)
ef43a632 146 */
65256cd8
CH
147extern struct mgmt_fe_client *
148mgmt_fe_client_create(const char *client_name, struct mgmt_fe_client_cbs *cbs,
149 uintptr_t user_data, struct event_loop *event_loop);
ef43a632 150
cfa0facb
CH
151/*
152 * Initialize library vty (adds debug support).
153 *
65256cd8
CH
154 * This call should be added to your component when enabling other vty
155 * code to enable mgmtd client debugs. When adding, one needs to also
156 * add a their component in `xref2vtysh.py` as well.
cfa0facb
CH
157 */
158extern void mgmt_fe_client_lib_vty_init(void);
159
160/*
161 * Print enabled debugging commands.
162 */
163extern void mgmt_debug_fe_client_show_debug(struct vty *vty);
164
ef43a632
CH
165/*
166 * Create a new Session for a Frontend Client connection.
167 *
168 * lib_hndl
169 * Client library handler.
170 *
171 * client_id
172 * Unique identifier of client.
173 *
65256cd8 174 * user_client
ef43a632
CH
175 * Client context.
176 *
177 * Returns:
178 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
179 */
65256cd8
CH
180extern enum mgmt_result
181mgmt_fe_create_client_session(struct mgmt_fe_client *client, uint64_t client_id,
182 uintptr_t user_client);
ef43a632
CH
183
184/*
185 * Delete an existing Session for a Frontend Client connection.
186 *
187 * lib_hndl
188 * Client library handler.
189 *
190 * client_id
191 * Unique identifier of client.
192 *
193 * Returns:
65256cd8 194 * 0 on success, otherwise msg_conn_send_msg() return values.
ef43a632 195 */
65256cd8
CH
196extern enum mgmt_result
197mgmt_fe_destroy_client_session(struct mgmt_fe_client *client,
198 uint64_t client_id);
ef43a632
CH
199
200/*
201 * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS.
202 *
203 * lib_hndl
204 * Client library handler.
205 *
206 * session_id
207 * Client session ID.
208 *
209 * req_id
210 * Client request ID.
211 *
212 * ds_id
213 * Datastore ID (Running/Candidate/Oper/Startup)
214 *
215 * lock_ds
216 * TRUE for lock request, FALSE for unlock request.
217 *
218 * Returns:
65256cd8 219 * 0 on success, otherwise msg_conn_send_msg() return values.
ef43a632 220 */
65256cd8
CH
221extern int mgmt_fe_send_lockds_req(struct mgmt_fe_client *client,
222 uint64_t session_id, uint64_t req_id,
223 Mgmtd__DatastoreId ds_id, bool lock_ds);
ef43a632
CH
224
225/*
226 * Send SET_CONFIG_REQ to MGMTD for one or more config data(s).
227 *
228 * lib_hndl
229 * Client library handler.
230 *
231 * session_id
232 * Client session ID.
233 *
234 * req_id
235 * Client request ID.
236 *
237 * ds_id
238 * Datastore ID (Running/Candidate/Oper/Startup)
239 *
240 * conf_req
241 * Details regarding the SET_CONFIG_REQ.
242 *
243 * num_req
244 * Number of config requests.
245 *
246 * implcit commit
247 * TRUE for implicit commit, FALSE otherwise.
248 *
249 * dst_ds_id
250 * Destination Datastore ID where data needs to be set.
251 *
252 * Returns:
65256cd8 253 * 0 on success, otherwise msg_conn_send_msg() return values.
ef43a632 254 */
65256cd8
CH
255
256extern int mgmt_fe_send_setcfg_req(struct mgmt_fe_client *client,
257 uint64_t session_id, uint64_t req_id,
258 Mgmtd__DatastoreId ds_id,
259 Mgmtd__YangCfgDataReq **config_req,
260 int num_req, bool implicit_commit,
261 Mgmtd__DatastoreId dst_ds_id);
ef43a632
CH
262
263/*
264 * Send SET_COMMMIT_REQ to MGMTD for one or more config data(s).
265 *
266 * lib_hndl
267 * Client library handler.
268 *
269 * session_id
270 * Client session ID.
271 *
272 * req_id
273 * Client request ID.
274 *
275 * src_ds_id
276 * Source datastore ID from where data needs to be committed from.
277 *
278 * dst_ds_id
279 * Destination datastore ID where data needs to be committed to.
280 *
281 * validate_only
282 * TRUE if data needs to be validated only, FALSE otherwise.
283 *
284 * abort
285 * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
286 *
287 * Returns:
65256cd8 288 * 0 on success, otherwise msg_conn_send_msg() return values.
ef43a632 289 */
65256cd8
CH
290extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
291 uint64_t session_id, uint64_t req_id,
292 Mgmtd__DatastoreId src_ds_id,
293 Mgmtd__DatastoreId dst_ds_id,
294 bool validate_only, bool abort);
ef43a632
CH
295
296/*
297 * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s).
298 *
299 * lib_hndl
300 * Client library handler.
301 *
302 * session_id
303 * Client session ID.
304 *
305 * req_id
306 * Client request ID.
307 *
308 * ds_id
309 * Datastore ID (Running/Candidate)
310 *
311 * data_req
312 * Get config requested.
313 *
314 * num_req
315 * Number of get config requests.
316 *
317 * Returns:
65256cd8 318 * 0 on success, otherwise msg_conn_send_msg() return values.
ef43a632 319 */
65256cd8
CH
320extern int mgmt_fe_send_getcfg_req(struct mgmt_fe_client *client,
321 uint64_t session_id, uint64_t req_id,
322 Mgmtd__DatastoreId ds_id,
323 Mgmtd__YangGetDataReq **data_req,
324 int num_reqs);
ef43a632
CH
325
326/*
327 * Send GET_DATA_REQ to MGMTD for one or more data item(s).
328 *
329 * Similar to get config request but supports getting data
330 * from operational ds aka backend clients directly.
331 */
65256cd8
CH
332extern int mgmt_fe_send_getdata_req(struct mgmt_fe_client *client,
333 uint64_t session_id, uint64_t req_id,
334 Mgmtd__DatastoreId ds_id,
335 Mgmtd__YangGetDataReq **data_req,
336 int num_reqs);
ef43a632
CH
337
338/*
339 * Send NOTIFY_REGISTER_REQ to MGMTD daemon.
340 *
341 * lib_hndl
342 * Client library handler.
343 *
344 * session_id
345 * Client session ID.
346 *
347 * req_id
348 * Client request ID.
349 *
350 * ds_id
351 * Datastore ID.
352 *
353 * register_req
354 * TRUE if registering, FALSE otherwise.
355 *
356 * data_req
357 * Details of the YANG notification data.
358 *
359 * num_reqs
360 * Number of data requests.
361 *
362 * Returns:
65256cd8 363 * 0 on success, otherwise msg_conn_send_msg() return values.
ef43a632 364 */
65256cd8
CH
365extern int mgmt_fe_send_regnotify_req(struct mgmt_fe_client *client,
366 uint64_t session_id, uint64_t req_id,
367 Mgmtd__DatastoreId ds_id,
368 bool register_req,
369 Mgmtd__YangDataXPath **data_req,
370 int num_reqs);
ef43a632
CH
371
372/*
373 * Destroy library and cleanup everything.
374 */
65256cd8 375extern void mgmt_fe_client_destroy(struct mgmt_fe_client *client);
ef43a632 376
e13a5c41
CH
377/*
378 * Get count of open sessions.
379 */
65256cd8 380extern uint mgmt_fe_client_session_count(struct mgmt_fe_client *client);
e13a5c41 381
ef43a632
CH
382#ifdef __cplusplus
383}
384#endif
385
386#endif /* _FRR_MGMTD_FE_CLIENT_H_ */