1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2021 Vmware, Inc.
6 * Pushpasis Sarkar <spushpasis@vmware.com>
9 #ifndef _FRR_MGMTD_TXN_H_
10 #define _FRR_MGMTD_TXN_H_
12 #include "mgmtd/mgmt_be_adapter.h"
13 #include "mgmtd/mgmt.h"
14 #include "mgmtd/mgmt_ds.h"
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
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 */
26 #define MGMTD_TXN_CLEANUP_DELAY_MSEC 100
27 #define MGMTD_TXN_CLEANUP_DELAY_USEC 10
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.
36 * #define MGMTD_LOCAL_VALIDATIONS_ENABLED
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
43 PREDECL_LIST(mgmt_txns
);
48 MGMTD_TXN_TYPE_NONE
= 0,
49 MGMTD_TXN_TYPE_CONFIG
,
53 static inline const char *mgmt_txn_type2str(enum mgmt_txn_type type
)
56 case MGMTD_TXN_TYPE_NONE
:
58 case MGMTD_TXN_TYPE_CONFIG
:
60 case MGMTD_TXN_TYPE_SHOW
:
67 /* Initialise transaction module. */
68 extern int mgmt_txn_init(struct mgmt_master
*cm
, struct event_loop
*tm
);
70 /* Destroy the transaction module. */
71 extern void mgmt_txn_destroy(void);
74 * Check if transaction is in progress.
77 * session ID if in-progress, MGMTD_SESSION_ID_NONE otherwise.
79 extern uint64_t mgmt_config_txn_in_progress(void);
88 * Transaction type (CONFIG/SHOW/NONE)
93 extern uint64_t mgmt_create_txn(uint64_t session_id
, enum mgmt_txn_type type
);
96 * Destroy transaction.
99 * Unique transaction identifier.
101 extern void mgmt_destroy_txn(uint64_t *txn_id
);
104 * Check if transaction is valid given an ID.
106 extern bool mgmt_txn_id_is_valid(uint64_t txn_id
);
109 * Returns the type of transaction given an ID.
111 extern enum mgmt_txn_type
mgmt_get_txn_type(uint64_t txn_id
);
114 * Send set-config request to be processed later in transaction.
117 * Unique transaction identifier.
120 * Unique transaction request identifier.
132 * Number of config requests.
135 * TRUE if the commit is implicit, FALSE otherwise.
138 * Destination datastore ID.
141 * Destination datastore handle.
144 * 0 on success, -1 on failures.
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
);
155 * Send commit-config request to be processed later in transaction.
158 * Unique transaction identifier.
161 * Unique transaction request identifier.
164 * Source datastore ID.
167 * Source Datastore handle.
170 * TRUE if commit request needs to be validated only, FALSE otherwise.
173 * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
176 * TRUE if the commit is implicit, FALSE otherwise.
179 * 0 on success, -1 on failures.
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
,
189 extern int mgmt_txn_send_commit_config_reply(uint64_t txn_id
,
190 enum mgmt_result result
,
191 const char *error_if_any
);
194 * Send get-config request to be processed later in transaction.
196 * Similar to set-config request.
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
,
205 * Send get-data request to be processed later in transaction.
207 * Similar to get-config request, but here data is fetched from backedn client.
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
,
216 * Notifiy backend adapter on connection.
219 mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter
*adapter
,
223 * Reply to backend adapter about transaction create/delete.
226 mgmt_txn_notify_be_txn_reply(uint64_t txn_id
, bool create
, bool success
,
227 struct mgmt_be_client_adapter
*adapter
);
230 * Reply to backend adapater with config data create request.
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
);
238 * Reply to backend adapater with config data validate request.
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
);
246 * Reply to backend adapater with config data apply request.
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
);
255 * Dump transaction status to vty.
257 extern void mgmt_txn_status_write(struct vty
*vty
);
260 * Trigger rollback config apply.
262 * Creates a new transaction and commit request for rollback.
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_ */