]> git.proxmox.com Git - mirror_frr.git/blob - mgmtd/mgmt_txn.h
Merge pull request #12454 from donaldsharp/bgp_getc
[mirror_frr.git] / mgmtd / mgmt_txn.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * MGMTD Transactions
4 *
5 * Copyright (C) 2021 Vmware, Inc.
6 * Pushpasis Sarkar <spushpasis@vmware.com>
7 */
8
9 #ifndef _FRR_MGMTD_TXN_H_
10 #define _FRR_MGMTD_TXN_H_
11
12 #include "mgmtd/mgmt_be_adapter.h"
13 #include "mgmtd/mgmt.h"
14 #include "mgmtd/mgmt_ds.h"
15
16 #define MGMTD_TXN_PROC_DELAY_MSEC 5
17 #define MGMTD_TXN_PROC_DELAY_USEC 10
18 #define MGMTD_TXN_MAX_NUM_SETCFG_PROC 128
19 #define MGMTD_TXN_MAX_NUM_GETCFG_PROC 128
20 #define MGMTD_TXN_MAX_NUM_GETDATA_PROC 128
21
22 #define MGMTD_TXN_SEND_CFGVALIDATE_DELAY_MSEC 100
23 #define MGMTD_TXN_SEND_CFGAPPLY_DELAY_MSEC 100
24 #define MGMTD_TXN_CFG_COMMIT_MAX_DELAY_MSEC 30000 /* 30 seconds */
25
26 #define MGMTD_TXN_CLEANUP_DELAY_MSEC 100
27 #define MGMTD_TXN_CLEANUP_DELAY_USEC 10
28
29 /*
30 * The following definition enables local validation of config
31 * on the MGMTD process by loading client-defined NB callbacks
32 * and calling them locally before sening CNFG_APPLY_REQ to
33 * backend for actual apply of configuration on internal state
34 * of the backend application.
35 *
36 * #define MGMTD_LOCAL_VALIDATIONS_ENABLED
37 *
38 * Note: Enabled by default in configure.ac, if this needs to be
39 * disabled then pass --enable-mgmtd-local-validations=no to
40 * the list of arguments passed to ./configure
41 */
42
43 PREDECL_LIST(mgmt_txns);
44
45 struct mgmt_master;
46
47 enum mgmt_txn_type {
48 MGMTD_TXN_TYPE_NONE = 0,
49 MGMTD_TXN_TYPE_CONFIG,
50 MGMTD_TXN_TYPE_SHOW
51 };
52
53 static inline const char *mgmt_txn_type2str(enum mgmt_txn_type type)
54 {
55 switch (type) {
56 case MGMTD_TXN_TYPE_NONE:
57 return "None";
58 case MGMTD_TXN_TYPE_CONFIG:
59 return "CONFIG";
60 case MGMTD_TXN_TYPE_SHOW:
61 return "SHOW";
62 }
63
64 return "Unknown";
65 }
66
67 /* Initialise transaction module. */
68 extern int mgmt_txn_init(struct mgmt_master *cm, struct event_loop *tm);
69
70 /* Destroy the transaction module. */
71 extern void mgmt_txn_destroy(void);
72
73 /*
74 * Check if transaction is in progress.
75 *
76 * Returns:
77 * session ID if in-progress, MGMTD_SESSION_ID_NONE otherwise.
78 */
79 extern uint64_t mgmt_config_txn_in_progress(void);
80
81 /*
82 * Create transaction.
83 *
84 * session_id
85 * Session ID.
86 *
87 * type
88 * Transaction type (CONFIG/SHOW/NONE)
89 *
90 * Returns:
91 * transaction ID.
92 */
93 extern uint64_t mgmt_create_txn(uint64_t session_id, enum mgmt_txn_type type);
94
95 /*
96 * Destroy transaction.
97 *
98 * txn_id
99 * Unique transaction identifier.
100 */
101 extern void mgmt_destroy_txn(uint64_t *txn_id);
102
103 /*
104 * Check if transaction is valid given an ID.
105 */
106 extern bool mgmt_txn_id_is_valid(uint64_t txn_id);
107
108 /*
109 * Returns the type of transaction given an ID.
110 */
111 extern enum mgmt_txn_type mgmt_get_txn_type(uint64_t txn_id);
112
113 /*
114 * Send set-config request to be processed later in transaction.
115 *
116 * txn_id
117 * Unique transaction identifier.
118 *
119 * req_id
120 * Unique transaction request identifier.
121 *
122 * ds_id
123 * Datastore ID.
124 *
125 * ds_hndl
126 * Datastore handle.
127 *
128 * cfg_req
129 * Config requests.
130 *
131 * num_req
132 * Number of config requests.
133 *
134 * implicit_commit
135 * TRUE if the commit is implicit, FALSE otherwise.
136 *
137 * dst_ds_id
138 * Destination datastore ID.
139 *
140 * dst_ds_handle
141 * Destination datastore handle.
142 *
143 * Returns:
144 * 0 on success, -1 on failures.
145 */
146 extern int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
147 Mgmtd__DatastoreId ds_id,
148 struct mgmt_ds_ctx *ds_ctx,
149 Mgmtd__YangCfgDataReq **cfg_req,
150 size_t num_req, bool implicit_commit,
151 Mgmtd__DatastoreId dst_ds_id,
152 struct mgmt_ds_ctx *dst_ds_ctx);
153
154 /*
155 * Send commit-config request to be processed later in transaction.
156 *
157 * txn_id
158 * Unique transaction identifier.
159 *
160 * req_id
161 * Unique transaction request identifier.
162 *
163 * src_ds_id
164 * Source datastore ID.
165 *
166 * src_ds_hndl
167 * Source Datastore handle.
168 *
169 * validate_only
170 * TRUE if commit request needs to be validated only, FALSE otherwise.
171 *
172 * abort
173 * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
174 *
175 * implicit
176 * TRUE if the commit is implicit, FALSE otherwise.
177 *
178 * Returns:
179 * 0 on success, -1 on failures.
180 */
181 extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id,
182 Mgmtd__DatastoreId src_ds_id,
183 struct mgmt_ds_ctx *dst_ds_ctx,
184 Mgmtd__DatastoreId dst_ds_id,
185 struct mgmt_ds_ctx *src_ds_ctx,
186 bool validate_only, bool abort,
187 bool implicit);
188
189 extern int mgmt_txn_send_commit_config_reply(uint64_t txn_id,
190 enum mgmt_result result,
191 const char *error_if_any);
192
193 /*
194 * Send get-config request to be processed later in transaction.
195 *
196 * Similar to set-config request.
197 */
198 extern int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
199 Mgmtd__DatastoreId ds_id,
200 struct mgmt_ds_ctx *ds_ctx,
201 Mgmtd__YangGetDataReq **data_req,
202 size_t num_reqs);
203
204 /*
205 * Send get-data request to be processed later in transaction.
206 *
207 * Similar to get-config request, but here data is fetched from backedn client.
208 */
209 extern int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id,
210 Mgmtd__DatastoreId ds_id,
211 struct mgmt_ds_ctx *ds_ctx,
212 Mgmtd__YangGetDataReq **data_req,
213 size_t num_reqs);
214
215 /*
216 * Notifiy backend adapter on connection.
217 */
218 extern int
219 mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
220 bool connect);
221
222 /*
223 * Reply to backend adapter about transaction create/delete.
224 */
225 extern int
226 mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success,
227 struct mgmt_be_client_adapter *adapter);
228
229 /*
230 * Reply to backend adapater with config data create request.
231 */
232 extern int
233 mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
234 bool success, char *error_if_any,
235 struct mgmt_be_client_adapter *adapter);
236
237 /*
238 * Reply to backend adapater with config data validate request.
239 */
240 extern int mgmt_txn_notify_be_cfg_validate_reply(
241 uint64_t txn_id, bool success, uint64_t batch_ids[],
242 size_t num_batch_ids, char *error_if_any,
243 struct mgmt_be_client_adapter *adapter);
244
245 /*
246 * Reply to backend adapater with config data apply request.
247 */
248 extern int
249 mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
250 uint64_t batch_ids[],
251 size_t num_batch_ids, char *error_if_any,
252 struct mgmt_be_client_adapter *adapter);
253
254 /*
255 * Dump transaction status to vty.
256 */
257 extern void mgmt_txn_status_write(struct vty *vty);
258
259 /*
260 * Trigger rollback config apply.
261 *
262 * Creates a new transaction and commit request for rollback.
263 */
264 extern int
265 mgmt_txn_rollback_trigger_cfg_apply(struct mgmt_ds_ctx *src_ds_ctx,
266 struct mgmt_ds_ctx *dst_ds_ctx);
267 #endif /* _FRR_MGMTD_TXN_H_ */