1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MGMTD Frontend Client Library api interfaces
4 * Copyright (C) 2021 Vmware, Inc.
5 * Pushpasis Sarkar <spushpasis@vmware.com>
8 #ifndef _FRR_MGMTD_FE_CLIENT_H_
9 #define _FRR_MGMTD_FE_CLIENT_H_
17 #include "mgmtd/mgmt_defines.h"
19 /***************************************************************
21 ***************************************************************/
24 * The server port MGMTD daemon is listening for Backend Client
28 #define MGMTD_FE_CLIENT_ERROR_STRING_MAX_LEN 32
30 #define MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC 5
32 #define MGMTD_FE_MSG_PROC_DELAY_USEC 10
33 #define MGMTD_FE_MAX_NUM_MSG_PROC 500
35 #define MGMTD_FE_MSG_WRITE_DELAY_MSEC 1
36 #define MGMTD_FE_MAX_NUM_MSG_WRITE 100
38 #define GMGD_FE_MAX_NUM_REQ_ITEMS 64
40 #define MGMTD_FE_MSG_MAX_LEN 9000
42 #define MGMTD_SOCKET_FE_SEND_BUF_SIZE 65535
43 #define MGMTD_SOCKET_FE_RECV_BUF_SIZE MGMTD_SOCKET_FE_SEND_BUF_SIZE
45 /***************************************************************
47 ***************************************************************/
49 #define MGMTD_SESSION_ID_NONE 0
51 #define MGMTD_CLIENT_ID_NONE 0
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
59 struct mgmt_fe_client
;
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.
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
72 struct mgmt_fe_client_cbs
{
73 void (*client_connect_notify
)(struct mgmt_fe_client
*client
,
74 uintptr_t user_data
, bool connected
);
76 void (*client_session_notify
)(struct mgmt_fe_client
*client
,
77 uintptr_t user_data
, uint64_t client_id
,
78 bool create
, bool success
,
80 uintptr_t user_session_client
);
82 void (*lock_ds_notify
)(struct mgmt_fe_client
*client
,
83 uintptr_t user_data
, uint64_t client_id
,
85 uintptr_t user_session_client
, uint64_t req_id
,
86 bool lock_ds
, bool success
,
87 Mgmtd__DatastoreId ds_id
, char *errmsg_if_any
);
89 void (*set_config_notify
)(struct mgmt_fe_client
*client
,
90 uintptr_t user_data
, uint64_t client_id
,
92 uintptr_t user_session_client
,
93 uint64_t req_id
, bool success
,
94 Mgmtd__DatastoreId ds_id
,
97 void (*commit_config_notify
)(struct mgmt_fe_client
*client
,
98 uintptr_t user_data
, uint64_t client_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
);
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
);
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
);
120 extern struct debug mgmt_dbg_fe_client
;
122 #define MGMTD_FE_CLIENT_DBG(fmt, ...) \
123 DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s:" fmt, __func__, \
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)
131 /***************************************************************
133 ***************************************************************/
136 * Initialize library and try connecting with MGMTD FrontEnd interface.
139 * Frontend client parameters.
145 * Frontend client lib handler (nothing but address of mgmt_fe_client)
147 extern struct mgmt_fe_client
*
148 mgmt_fe_client_create(const char *client_name
, struct mgmt_fe_client_cbs
*cbs
,
149 uintptr_t user_data
, struct event_loop
*event_loop
);
152 * Initialize library vty (adds debug support).
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.
158 extern void mgmt_fe_client_lib_vty_init(void);
161 * Print enabled debugging commands.
163 extern void mgmt_debug_fe_client_show_debug(struct vty
*vty
);
166 * Create a new Session for a Frontend Client connection.
169 * Client library handler.
172 * Unique identifier of client.
178 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
180 extern enum mgmt_result
181 mgmt_fe_create_client_session(struct mgmt_fe_client
*client
, uint64_t client_id
,
182 uintptr_t user_client
);
185 * Delete an existing Session for a Frontend Client connection.
188 * Client library handler.
191 * Unique identifier of client.
194 * 0 on success, otherwise msg_conn_send_msg() return values.
196 extern enum mgmt_result
197 mgmt_fe_destroy_client_session(struct mgmt_fe_client
*client
,
201 * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS.
204 * Client library handler.
213 * Datastore ID (Running/Candidate/Oper/Startup)
216 * TRUE for lock request, FALSE for unlock request.
219 * 0 on success, otherwise msg_conn_send_msg() return values.
221 extern 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
);
226 * Send SET_CONFIG_REQ to MGMTD for one or more config data(s).
229 * Client library handler.
238 * Datastore ID (Running/Candidate/Oper/Startup)
241 * Details regarding the SET_CONFIG_REQ.
244 * Number of config requests.
247 * TRUE for implicit commit, FALSE otherwise.
250 * Destination Datastore ID where data needs to be set.
253 * 0 on success, otherwise msg_conn_send_msg() return values.
256 extern 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
);
264 * Send SET_COMMMIT_REQ to MGMTD for one or more config data(s).
267 * Client library handler.
276 * Source datastore ID from where data needs to be committed from.
279 * Destination datastore ID where data needs to be committed to.
282 * TRUE if data needs to be validated only, FALSE otherwise.
285 * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
288 * 0 on success, otherwise msg_conn_send_msg() return values.
290 extern 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
);
297 * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s).
300 * Client library handler.
309 * Datastore ID (Running/Candidate)
312 * Get config requested.
315 * Number of get config requests.
318 * 0 on success, otherwise msg_conn_send_msg() return values.
320 extern 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
,
327 * Send GET_DATA_REQ to MGMTD for one or more data item(s).
329 * Similar to get config request but supports getting data
330 * from operational ds aka backend clients directly.
332 extern 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
,
339 * Send NOTIFY_REGISTER_REQ to MGMTD daemon.
342 * Client library handler.
354 * TRUE if registering, FALSE otherwise.
357 * Details of the YANG notification data.
360 * Number of data requests.
363 * 0 on success, otherwise msg_conn_send_msg() return values.
365 extern 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
,
369 Mgmtd__YangDataXPath
**data_req
,
373 * Destroy library and cleanup everything.
375 extern void mgmt_fe_client_destroy(struct mgmt_fe_client
*client
);
378 * Get count of open sessions.
380 extern uint
mgmt_fe_client_session_count(struct mgmt_fe_client
*client
);
386 #endif /* _FRR_MGMTD_FE_CLIENT_H_ */