1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MGMTD Backend Client Library api interfaces
4 * Copyright (C) 2021 Vmware, Inc.
5 * Pushpasis Sarkar <spushpasis@vmware.com>
8 #ifndef _FRR_MGMTD_BE_CLIENT_H_
9 #define _FRR_MGMTD_BE_CLIENT_H_
15 #include "northbound.h"
17 #include "mgmtd/mgmt_defines.h"
19 /***************************************************************
21 ***************************************************************/
24 * Add enum value for each supported component, wrap with
25 * #ifdef HAVE_COMPONENT
27 enum mgmt_be_client_id
{
28 MGMTD_BE_CLIENT_ID_MIN
= 0,
29 MGMTD_BE_CLIENT_ID_INIT
= -1,
31 MGMTD_BE_CLIENT_ID_STATICD
,
33 MGMTD_BE_CLIENT_ID_MAX
36 #define FOREACH_MGMTD_BE_CLIENT_ID(id) \
37 for ((id) = MGMTD_BE_CLIENT_ID_MIN; \
38 (id) < MGMTD_BE_CLIENT_ID_MAX; (id)++)
40 /***************************************************************
42 ***************************************************************/
44 #define MGMTD_BE_CLIENT_ERROR_STRING_MAX_LEN 32
46 #define MGMTD_BE_DEFAULT_CONN_RETRY_INTVL_SEC 5
48 #define MGMTD_BE_MSG_PROC_DELAY_USEC 10
49 #define MGMTD_BE_MAX_NUM_MSG_PROC 500
51 #define MGMTD_BE_MSG_WRITE_DELAY_MSEC 1
52 #define MGMTD_BE_MAX_NUM_MSG_WRITE 1000
54 #define GMGD_BE_MAX_NUM_REQ_ITEMS 64
56 #define MGMTD_BE_MSG_MAX_LEN 16384
58 #define MGMTD_SOCKET_BE_SEND_BUF_SIZE 65535
59 #define MGMTD_SOCKET_BE_RECV_BUF_SIZE MGMTD_SOCKET_BE_SEND_BUF_SIZE
61 #define MGMTD_MAX_CFG_CHANGES_IN_BATCH \
62 ((10 * MGMTD_BE_MSG_MAX_LEN) / \
63 (MGMTD_MAX_XPATH_LEN + MGMTD_MAX_YANG_VALUE_LEN))
66 * MGMTD_BE_MSG_MAX_LEN must be used 80%
67 * since there is overhead of google protobuf
68 * that gets added to sent message
70 #define MGMTD_BE_CFGDATA_PACKING_EFFICIENCY 0.8
71 #define MGMTD_BE_CFGDATA_MAX_MSG_LEN \
72 (MGMTD_BE_MSG_MAX_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY)
74 #define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \
75 (MGMTD_BE_MSG_MAX_LEN - 128) / sizeof(uint64_t)
77 #define MGMTD_BE_CONTAINER_NODE_VAL "<<container>>"
79 /***************************************************************
81 ***************************************************************/
83 #define MGMTD_BE_MAX_CLIENTS_PER_XPATH_REG 32
85 struct mgmt_be_client_txn_ctx
{
90 * All the client-specific information this library needs to
91 * initialize itself, setup connection with MGMTD BackEnd interface
92 * and carry on all required procedures appropriately.
94 * BackEnd clients need to initialise a instance of this structure
95 * with appropriate data and pass it while calling the API
96 * to initialize the library (See mgmt_be_client_lib_init for
99 struct mgmt_be_client_params
{
100 char name
[MGMTD_CLIENT_NAME_MAX_LEN
];
102 unsigned long conn_retry_intvl_sec
;
104 void (*client_connect_notify
)(uintptr_t lib_hndl
,
108 void (*client_subscribe_notify
)(
109 uintptr_t lib_hndl
, uintptr_t usr_data
,
110 struct nb_yang_xpath
**xpath
,
111 enum mgmt_result subscribe_result
[], int num_paths
);
114 uintptr_t lib_hndl
, uintptr_t usr_data
,
115 struct mgmt_be_client_txn_ctx
*txn_ctx
, bool destroyed
);
117 enum mgmt_result (*data_validate
)(
118 uintptr_t lib_hndl
, uintptr_t usr_data
,
119 struct mgmt_be_client_txn_ctx
*txn_ctx
,
120 struct nb_yang_xpath
*xpath
, struct nb_yang_value
*data
,
121 bool delete, char *error_if_any
);
123 enum mgmt_result (*data_apply
)(
124 uintptr_t lib_hndl
, uintptr_t usr_data
,
125 struct mgmt_be_client_txn_ctx
*txn_ctx
,
126 struct nb_yang_xpath
*xpath
, struct nb_yang_value
*data
,
129 enum mgmt_result (*get_data_elem
)(
130 uintptr_t lib_hndl
, uintptr_t usr_data
,
131 struct mgmt_be_client_txn_ctx
*txn_ctx
,
132 struct nb_yang_xpath
*xpath
, struct nb_yang_xpath_elem
*elem
);
134 enum mgmt_result (*get_data
)(
135 uintptr_t lib_hndl
, uintptr_t usr_data
,
136 struct mgmt_be_client_txn_ctx
*txn_ctx
,
137 struct nb_yang_xpath
*xpath
, bool keys_only
,
138 struct nb_yang_xpath_elem
**elems
, int *num_elems
,
141 enum mgmt_result (*get_next_data
)(
142 uintptr_t lib_hndl
, uintptr_t usr_data
,
143 struct mgmt_be_client_txn_ctx
*txn_ctx
,
144 struct nb_yang_xpath
*xpath
, bool keys_only
,
145 struct nb_yang_xpath_elem
**elems
, int *num_elems
);
148 /***************************************************************
149 * Global data exported
150 ***************************************************************/
152 extern const char *mgmt_be_client_names
[MGMTD_BE_CLIENT_ID_MAX
+ 1];
154 static inline const char *mgmt_be_client_id2name(enum mgmt_be_client_id id
)
156 if (id
> MGMTD_BE_CLIENT_ID_MAX
)
157 id
= MGMTD_BE_CLIENT_ID_MAX
;
158 return mgmt_be_client_names
[id
];
161 static inline enum mgmt_be_client_id
162 mgmt_be_client_name2id(const char *name
)
164 enum mgmt_be_client_id id
;
166 FOREACH_MGMTD_BE_CLIENT_ID (id
) {
167 if (!strncmp(mgmt_be_client_names
[id
], name
,
168 MGMTD_CLIENT_NAME_MAX_LEN
))
172 return MGMTD_BE_CLIENT_ID_MAX
;
175 /***************************************************************
177 ***************************************************************/
180 * Initialize library and try connecting with MGMTD.
183 * Backend client parameters.
189 * Backend client lib handler (nothing but address of mgmt_be_client_ctx)
191 extern uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params
*params
,
192 struct event_loop
*master_thread
);
195 * Subscribe with MGMTD for one or more YANG subtree(s).
198 * Client library handler.
201 * Yang xpath(s) that needs to be subscribed to.
207 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
209 extern enum mgmt_result
mgmt_be_subscribe_yang_data(uintptr_t lib_hndl
,
210 char **reg_yang_xpaths
,
214 * Send one or more YANG notifications to MGMTD daemon.
217 * Client library handler.
220 * Yang data elements from data tree.
223 * Number of data elements.
226 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
228 extern enum mgmt_result
229 mgmt_be_send_yang_notify(uintptr_t lib_hndl
, Mgmtd__YangData
**data_elems
,
233 * Un-subscribe with MGMTD for one or more YANG subtree(s).
236 * Client library handler.
239 * Yang xpath(s) that needs to be un-subscribed from.
242 * Number of subscribed xpaths
245 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
247 enum mgmt_result
mgmt_be_unsubscribe_yang_data(uintptr_t lib_hndl
,
248 char **reg_yang_xpaths
,
252 * Destroy library and cleanup everything.
254 extern void mgmt_be_client_lib_destroy(uintptr_t lib_hndl
);
260 #endif /* _FRR_MGMTD_BE_CLIENT_H_ */