]> git.proxmox.com Git - mirror_frr.git/blob - mgmtd/mgmt_be_adapter.h
lib: Remove tests for ipv[4|6]_prefix_table
[mirror_frr.git] / mgmtd / mgmt_be_adapter.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * MGMTD Backend Client Connection Adapter
4 *
5 * Copyright (C) 2021 Vmware, Inc.
6 * Pushpasis Sarkar <spushpasis@vmware.com>
7 */
8
9 #ifndef _FRR_MGMTD_BE_ADAPTER_H_
10 #define _FRR_MGMTD_BE_ADAPTER_H_
11
12 #include "mgmt_be_client.h"
13 #include "mgmt_msg.h"
14 #include "mgmtd/mgmt_defines.h"
15 #include "mgmtd/mgmt_ds.h"
16
17 #define MGMTD_BE_CONN_INIT_DELAY_MSEC 50
18
19 #define MGMTD_FIND_ADAPTER_BY_INDEX(adapter_index) \
20 mgmt_adaptr_ref[adapter_index]
21
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
28 };
29
30 struct mgmt_be_cfgreq {
31 Mgmtd__YangCfgDataReq **cfgdata_reqs;
32 size_t num_reqs;
33 };
34
35 struct mgmt_be_datareq {
36 Mgmtd__YangGetDataReq **getdata_reqs;
37 size_t num_reqs;
38 };
39
40 PREDECL_LIST(mgmt_be_adapters);
41 PREDECL_LIST(mgmt_txn_badapters);
42
43 struct mgmt_be_client_adapter {
44 enum mgmt_be_client_id id;
45 int conn_fd;
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;
52 uint32_t flags;
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];
56
57 /* IO streams for read and write */
58 struct mgmt_msg_state mstate;
59
60 int refcount;
61
62 /*
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.
67 */
68 struct nb_config_cbs cfg_chgs;
69
70 struct mgmt_be_adapters_item list_linkage;
71 struct mgmt_txn_badapters_item txn_list_linkage;
72 };
73
74 #define MGMTD_BE_ADAPTER_FLAGS_WRITES_OFF (1U << 0)
75 #define MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED (1U << 1)
76
77 DECLARE_LIST(mgmt_be_adapters, struct mgmt_be_client_adapter, list_linkage);
78 DECLARE_LIST(mgmt_txn_badapters, struct mgmt_be_client_adapter,
79 txn_list_linkage);
80
81 union mgmt_be_xpath_subscr_info {
82 uint8_t subscribed;
83 struct {
84 uint8_t validate_config : 1;
85 uint8_t notify_config : 1;
86 uint8_t own_oper_data : 1;
87 };
88 };
89
90 struct mgmt_be_client_subscr_info {
91 union mgmt_be_xpath_subscr_info xpath_subscr[MGMTD_BE_CLIENT_ID_MAX];
92 };
93
94 /* Initialise backend adapter module. */
95 extern int mgmt_be_adapter_init(struct thread_master *tm);
96
97 /* Destroy the backend adapter module. */
98 extern void mgmt_be_adapter_destroy(void);
99
100 /* Acquire lock for backend adapter. */
101 extern void mgmt_be_adapter_lock(struct mgmt_be_client_adapter *adapter);
102
103 /* Remove lock from backend adapter. */
104 extern void mgmt_be_adapter_unlock(struct mgmt_be_client_adapter **adapter);
105
106 /* Create backend adapter. */
107 extern struct mgmt_be_client_adapter *
108 mgmt_be_create_adapter(int conn_fd, union sockunion *su);
109
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);
113
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);
117
118 /* Fetch backend adapter config. */
119 extern int
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);
123
124 /* Create a transaction. */
125 extern int mgmt_be_create_txn(struct mgmt_be_client_adapter *adapter,
126 uint64_t txn_id);
127
128 /* Destroy a transaction. */
129 extern int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter,
130 uint64_t txn_id);
131
132 /*
133 * Send config data create request to backend client.
134 *
135 * adaptr
136 * Backend adapter information.
137 *
138 * txn_id
139 * Unique transaction identifier.
140 *
141 * batch_id
142 * Request batch ID.
143 *
144 * cfg_req
145 * Config data request.
146 *
147 * end_of_data
148 * TRUE if the data from last batch, FALSE otherwise.
149 *
150 * Returns:
151 * 0 on success, -1 on failure.
152 */
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);
156
157 /*
158 * Send config validate request to backend client.
159 *
160 * adaptr
161 * Backend adapter information.
162 *
163 * txn_id
164 * Unique transaction identifier.
165 *
166 * batch_ids
167 * List of request batch IDs.
168 *
169 * num_batch_ids
170 * Number of batch ids.
171 *
172 * Returns:
173 * 0 on success, -1 on failure.
174 */
175 extern int
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);
179
180 /*
181 * Send config apply request to backend client.
182 *
183 * adaptr
184 * Backend adapter information.
185 *
186 * txn_id
187 * Unique transaction identifier.
188 *
189 * Returns:
190 * 0 on success, -1 on failure.
191 */
192 extern int
193 mgmt_be_send_cfg_apply_req(struct mgmt_be_client_adapter *adapter,
194 uint64_t txn_id);
195
196 /*
197 * Dump backend adapter status to vty.
198 */
199 extern void mgmt_be_adapter_status_write(struct vty *vty);
200
201 /*
202 * Dump xpath registry for each backend client to vty.
203 */
204 extern void mgmt_be_xpath_register_write(struct vty *vty);
205
206 /*
207 * Maps a YANG dtata Xpath to one or more
208 * backend clients that should be contacted for various purposes.
209 */
210 extern int mgmt_be_get_subscr_info_for_xpath(
211 const char *xpath, struct mgmt_be_client_subscr_info *subscr_info);
212
213 /*
214 * Dump backend client information for a given xpath to vty.
215 */
216 extern void mgmt_be_xpath_subscr_info_write(struct vty *vty,
217 const char *xpath);
218
219 #endif /* _FRR_MGMTD_BE_ADAPTER_H_ */