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_
15 #include "mgmtd/mgmt_defines.h"
18 /***************************************************************
20 ***************************************************************/
23 * The server port MGMTD daemon is listening for Backend Client
27 #define MGMTD_FE_CLIENT_ERROR_STRING_MAX_LEN 32
29 #define MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC 5
31 #define MGMTD_FE_MSG_PROC_DELAY_USEC 10
32 #define MGMTD_FE_MAX_NUM_MSG_PROC 500
34 #define MGMTD_FE_MSG_WRITE_DELAY_MSEC 1
35 #define MGMTD_FE_MAX_NUM_MSG_WRITE 100
37 #define GMGD_FE_MAX_NUM_REQ_ITEMS 64
39 #define MGMTD_FE_MSG_MAX_LEN 9000
41 #define MGMTD_SOCKET_FE_SEND_BUF_SIZE 65535
42 #define MGMTD_SOCKET_FE_RECV_BUF_SIZE MGMTD_SOCKET_FE_SEND_BUF_SIZE
44 /***************************************************************
46 ***************************************************************/
48 #define MGMTD_SESSION_ID_NONE 0
50 #define MGMTD_CLIENT_ID_NONE 0
52 #define MGMTD_DS_NONE MGMTD__DATASTORE_ID__DS_NONE
53 #define MGMTD_DS_RUNNING MGMTD__DATASTORE_ID__RUNNING_DS
54 #define MGMTD_DS_CANDIDATE MGMTD__DATASTORE_ID__CANDIDATE_DS
55 #define MGMTD_DS_OPERATIONAL MGMTD__DATASTORE_ID__OPERATIONAL_DS
56 #define MGMTD_DS_MAX_ID MGMTD_DS_OPERATIONAL + 1
58 struct mgmt_fe_msg_hdr
{
60 uint16_t len
; /* Includes header */
62 #define MGMTD_FE_MSG_HDR_LEN sizeof(struct mgmt_fe_msg_hdr)
63 #define MGMTD_FE_MSG_MARKER 0xdeaf
66 struct mgmt_fe_msg_hdr hdr
;
71 * All the client specific information this library needs to
72 * initialize itself, setup connection with MGMTD FrontEnd interface
73 * and carry on all required procedures appropriately.
75 * FrontEnd clients need to initialise a instance of this structure
76 * with appropriate data and pass it while calling the API
77 * to initialize the library (See mgmt_fe_client_lib_init for
80 struct mgmt_fe_client_params
{
81 char name
[MGMTD_CLIENT_NAME_MAX_LEN
];
83 unsigned long conn_retry_intvl_sec
;
85 void (*client_connect_notify
)(uintptr_t lib_hndl
,
89 void (*client_session_notify
)(uintptr_t lib_hndl
,
92 bool create
, bool success
,
94 uintptr_t user_session_ctx
);
96 void (*lock_ds_notify
)(uintptr_t lib_hndl
, uintptr_t user_data
,
97 uint64_t client_id
, uintptr_t session_id
,
98 uintptr_t user_session_ctx
, uint64_t req_id
,
99 bool lock_ds
, bool success
,
100 Mgmtd__DatastoreId ds_id
, char *errmsg_if_any
);
102 void (*set_config_notify
)(uintptr_t lib_hndl
, uintptr_t user_data
,
103 uint64_t client_id
, uintptr_t session_id
,
104 uintptr_t user_session_ctx
, uint64_t req_id
,
105 bool success
, Mgmtd__DatastoreId ds_id
,
106 char *errmsg_if_any
);
108 void (*commit_config_notify
)(
109 uintptr_t lib_hndl
, uintptr_t user_data
, uint64_t client_id
,
110 uintptr_t session_id
, uintptr_t user_session_ctx
,
111 uint64_t req_id
, bool success
, Mgmtd__DatastoreId src_ds_id
,
112 Mgmtd__DatastoreId dst_ds_id
, bool validate_only
,
113 char *errmsg_if_any
);
115 enum mgmt_result (*get_data_notify
)(
116 uintptr_t lib_hndl
, uintptr_t user_data
, uint64_t client_id
,
117 uintptr_t session_id
, uintptr_t user_session_ctx
,
118 uint64_t req_id
, bool success
, Mgmtd__DatastoreId ds_id
,
119 Mgmtd__YangData
**yang_data
, size_t num_data
, int next_key
,
120 char *errmsg_if_any
);
122 enum mgmt_result (*data_notify
)(
123 uint64_t client_id
, uint64_t session_id
, uintptr_t user_data
,
124 uint64_t req_id
, Mgmtd__DatastoreId ds_id
,
125 Mgmtd__YangData
**yang_data
, size_t num_data
);
128 /***************************************************************
130 ***************************************************************/
133 * Initialize library and try connecting with MGMTD FrontEnd interface.
136 * Frontend client parameters.
142 * Frontend client lib handler (nothing but address of mgmt_fe_client_ctx)
145 mgmt_fe_client_lib_init(struct mgmt_fe_client_params
*params
,
146 struct thread_master
*master_thread
);
149 * Create a new Session for a Frontend Client connection.
152 * Client library handler.
155 * Unique identifier of client.
161 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
163 extern enum mgmt_result
mgmt_fe_create_client_session(uintptr_t lib_hndl
,
168 * Delete an existing Session for a Frontend Client connection.
171 * Client library handler.
174 * Unique identifier of client.
177 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
179 extern enum mgmt_result
mgmt_fe_destroy_client_session(uintptr_t lib_hndl
,
183 * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS.
186 * Client library handler.
195 * Datastore ID (Running/Candidate/Oper/Startup)
198 * TRUE for lock request, FALSE for unlock request.
201 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
203 extern enum mgmt_result
204 mgmt_fe_lock_ds(uintptr_t lib_hndl
, uintptr_t session_id
, uint64_t req_id
,
205 Mgmtd__DatastoreId ds_id
, bool lock_ds
);
208 * Send SET_CONFIG_REQ to MGMTD for one or more config data(s).
211 * Client library handler.
220 * Datastore ID (Running/Candidate/Oper/Startup)
223 * Details regarding the SET_CONFIG_REQ.
226 * Number of config requests.
229 * TRUE for implicit commit, FALSE otherwise.
232 * Destination Datastore ID where data needs to be set.
235 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
237 extern enum mgmt_result
238 mgmt_fe_set_config_data(uintptr_t lib_hndl
, uintptr_t session_id
,
239 uint64_t req_id
, Mgmtd__DatastoreId ds_id
,
240 Mgmtd__YangCfgDataReq
**config_req
, int num_req
,
241 bool implicit_commit
, Mgmtd__DatastoreId dst_ds_id
);
244 * Send SET_COMMMIT_REQ to MGMTD for one or more config data(s).
247 * Client library handler.
256 * Source datastore ID from where data needs to be committed from.
259 * Destination datastore ID where data needs to be committed to.
262 * TRUE if data needs to be validated only, FALSE otherwise.
265 * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
268 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
270 extern enum mgmt_result
271 mgmt_fe_commit_config_data(uintptr_t lib_hndl
, uintptr_t session_id
,
272 uint64_t req_id
, Mgmtd__DatastoreId src_ds_id
,
273 Mgmtd__DatastoreId dst_ds_id
, bool validate_only
,
277 * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s).
280 * Client library handler.
289 * Datastore ID (Running/Candidate)
292 * Get config requested.
295 * Number of get config requests.
298 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
300 extern enum mgmt_result
301 mgmt_fe_get_config_data(uintptr_t lib_hndl
, uintptr_t session_id
,
302 uint64_t req_id
, Mgmtd__DatastoreId ds_id
,
303 Mgmtd__YangGetDataReq
**data_req
, int num_reqs
);
306 * Send GET_DATA_REQ to MGMTD for one or more data item(s).
308 * Similar to get config request but supports getting data
309 * from operational ds aka backend clients directly.
311 extern enum mgmt_result
312 mgmt_fe_get_data(uintptr_t lib_hndl
, uintptr_t session_id
, uint64_t req_id
,
313 Mgmtd__DatastoreId ds_id
, Mgmtd__YangGetDataReq
**data_req
,
317 * Send NOTIFY_REGISTER_REQ to MGMTD daemon.
320 * Client library handler.
332 * TRUE if registering, FALSE otherwise.
335 * Details of the YANG notification data.
338 * Number of data requests.
341 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
343 extern enum mgmt_result
344 mgmt_fe_register_yang_notify(uintptr_t lib_hndl
, uintptr_t session_id
,
345 uint64_t req_id
, Mgmtd__DatastoreId ds_id
,
347 Mgmtd__YangDataXPath
**data_req
, int num_reqs
);
350 * Destroy library and cleanup everything.
352 extern void mgmt_fe_client_lib_destroy(uintptr_t lib_hndl
);
358 #endif /* _FRR_MGMTD_FE_CLIENT_H_ */