1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MGMTD Backend Client Connection Adapter
5 * Copyright (C) 2021 Vmware, Inc.
6 * Pushpasis Sarkar <spushpasis@vmware.com>
9 #ifndef _FRR_MGMTD_BE_ADAPTER_H_
10 #define _FRR_MGMTD_BE_ADAPTER_H_
12 #include "mgmt_be_client.h"
14 #include "mgmtd/mgmt_defines.h"
15 #include "mgmtd/mgmt_ds.h"
17 #define MGMTD_BE_CONN_INIT_DELAY_MSEC 50
19 #define MGMTD_FIND_ADAPTER_BY_INDEX(adapter_index) \
20 mgmt_adaptr_ref[adapter_index]
22 enum mgmt_be_req_type
{
23 MGMTD_BE_REQ_NONE
= 0,
24 MGMTD_BE_REQ_CFG_VALIDATE
,
25 MGMTD_BE_REQ_CFG_APPLY
,
26 MGMTD_BE_REQ_DATA_GET_ELEM
,
27 MGMTD_BE_REQ_DATA_GET_NEXT
30 struct mgmt_be_cfgreq
{
31 Mgmtd__YangCfgDataReq
**cfgdata_reqs
;
35 struct mgmt_be_datareq
{
36 Mgmtd__YangGetDataReq
**getdata_reqs
;
40 PREDECL_LIST(mgmt_be_adapters
);
41 PREDECL_LIST(mgmt_txn_badapters
);
43 struct mgmt_be_client_adapter
{
44 enum mgmt_be_client_id id
;
46 union sockunion conn_su
;
47 struct thread
*conn_init_ev
;
48 struct thread
*conn_read_ev
;
49 struct thread
*conn_write_ev
;
50 struct thread
*conn_writes_on
;
51 struct thread
*proc_msg_ev
;
53 char name
[MGMTD_CLIENT_NAME_MAX_LEN
];
54 uint8_t num_xpath_reg
;
55 char xpath_reg
[MGMTD_MAX_NUM_XPATH_REG
][MGMTD_MAX_XPATH_LEN
];
57 /* IO streams for read and write */
58 struct mgmt_msg_state mstate
;
63 * List of config items that should be sent to the
64 * backend during re/connect. This is temporarily
65 * created and then freed-up as soon as the initial
66 * config items has been applied onto the backend.
68 struct nb_config_cbs cfg_chgs
;
70 struct mgmt_be_adapters_item list_linkage
;
71 struct mgmt_txn_badapters_item txn_list_linkage
;
74 #define MGMTD_BE_ADAPTER_FLAGS_WRITES_OFF (1U << 0)
75 #define MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED (1U << 1)
77 DECLARE_LIST(mgmt_be_adapters
, struct mgmt_be_client_adapter
, list_linkage
);
78 DECLARE_LIST(mgmt_txn_badapters
, struct mgmt_be_client_adapter
,
81 union mgmt_be_xpath_subscr_info
{
84 uint8_t validate_config
: 1;
85 uint8_t notify_config
: 1;
86 uint8_t own_oper_data
: 1;
90 struct mgmt_be_client_subscr_info
{
91 union mgmt_be_xpath_subscr_info xpath_subscr
[MGMTD_BE_CLIENT_ID_MAX
];
94 /* Initialise backend adapter module. */
95 extern int mgmt_be_adapter_init(struct thread_master
*tm
);
97 /* Destroy the backend adapter module. */
98 extern void mgmt_be_adapter_destroy(void);
100 /* Acquire lock for backend adapter. */
101 extern void mgmt_be_adapter_lock(struct mgmt_be_client_adapter
*adapter
);
103 /* Remove lock from backend adapter. */
104 extern void mgmt_be_adapter_unlock(struct mgmt_be_client_adapter
**adapter
);
106 /* Create backend adapter. */
107 extern struct mgmt_be_client_adapter
*
108 mgmt_be_create_adapter(int conn_fd
, union sockunion
*su
);
110 /* Fetch backend adapter given an adapter name. */
111 extern struct mgmt_be_client_adapter
*
112 mgmt_be_get_adapter_by_name(const char *name
);
114 /* Fetch backend adapter given an client ID. */
115 extern struct mgmt_be_client_adapter
*
116 mgmt_be_get_adapter_by_id(enum mgmt_be_client_id id
);
118 /* Fetch backend adapter config. */
120 mgmt_be_get_adapter_config(struct mgmt_be_client_adapter
*adapter
,
121 struct mgmt_ds_ctx
*ds_ctx
,
122 struct nb_config_cbs
**cfg_chgs
);
124 /* Create a transaction. */
125 extern int mgmt_be_create_txn(struct mgmt_be_client_adapter
*adapter
,
128 /* Destroy a transaction. */
129 extern int mgmt_be_destroy_txn(struct mgmt_be_client_adapter
*adapter
,
133 * Send config data create request to backend client.
136 * Backend adapter information.
139 * Unique transaction identifier.
145 * Config data request.
148 * TRUE if the data from last batch, FALSE otherwise.
151 * 0 on success, -1 on failure.
153 extern int mgmt_be_send_cfg_data_create_req(
154 struct mgmt_be_client_adapter
*adapter
, uint64_t txn_id
,
155 uint64_t batch_id
, struct mgmt_be_cfgreq
*cfg_req
, bool end_of_data
);
158 * Send config validate request to backend client.
161 * Backend adapter information.
164 * Unique transaction identifier.
167 * List of request batch IDs.
170 * Number of batch ids.
173 * 0 on success, -1 on failure.
176 mgmt_be_send_cfg_validate_req(struct mgmt_be_client_adapter
*adapter
,
177 uint64_t txn_id
, uint64_t batch_ids
[],
178 size_t num_batch_ids
);
181 * Send config apply request to backend client.
184 * Backend adapter information.
187 * Unique transaction identifier.
190 * 0 on success, -1 on failure.
193 mgmt_be_send_cfg_apply_req(struct mgmt_be_client_adapter
*adapter
,
197 * Dump backend adapter status to vty.
199 extern void mgmt_be_adapter_status_write(struct vty
*vty
);
202 * Dump xpath registry for each backend client to vty.
204 extern void mgmt_be_xpath_register_write(struct vty
*vty
);
207 * Maps a YANG dtata Xpath to one or more
208 * backend clients that should be contacted for various purposes.
210 extern int mgmt_be_get_subscr_info_for_xpath(
211 const char *xpath
, struct mgmt_be_client_subscr_info
*subscr_info
);
214 * Dump backend client information for a given xpath to vty.
216 extern void mgmt_be_xpath_subscr_info_write(struct vty
*vty
,
219 #endif /* _FRR_MGMTD_BE_ADAPTER_H_ */