1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* MGMTD Transactions
*
* Copyright (C) 2021 Vmware, Inc.
* Pushpasis Sarkar <spushpasis@vmware.com>
*/
#ifndef _FRR_MGMTD_TXN_H_
#define _FRR_MGMTD_TXN_H_
#include "lib/mgmt_msg_native.h"
#include "mgmtd/mgmt_be_adapter.h"
#include "mgmtd/mgmt.h"
#include "mgmtd/mgmt_ds.h"
#define MGMTD_TXN_PROC_DELAY_USEC 10
#define MGMTD_TXN_MAX_NUM_SETCFG_PROC 128
#define MGMTD_TXN_MAX_NUM_GETCFG_PROC 128
#define MGMTD_TXN_MAX_NUM_GETDATA_PROC 128
#define MGMTD_TXN_CFG_COMMIT_MAX_DELAY_SEC 600
#define MGMTD_TXN_GET_TREE_MAX_DELAY_SEC 600
#define MGMTD_TXN_RPC_MAX_DELAY_SEC 60
#define MGMTD_TXN_CLEANUP_DELAY_USEC 10
#define MGMTD_TXN_ID_NONE 0
/*
* The following definition enables local validation of config
* on the MGMTD process by loading client-defined NB callbacks
* and calling them locally before sening CNFG_APPLY_REQ to
* backend for actual apply of configuration on internal state
* of the backend application.
*
* #define MGMTD_LOCAL_VALIDATIONS_ENABLED
*
* Note: Enabled by default in configure.ac, if this needs to be
* disabled then pass --enable-mgmtd-local-validations=no to
* the list of arguments passed to ./configure
*/
PREDECL_LIST(mgmt_txns);
struct mgmt_master;
struct mgmt_edit_req;
enum mgmt_txn_type {
MGMTD_TXN_TYPE_NONE = 0,
MGMTD_TXN_TYPE_CONFIG,
MGMTD_TXN_TYPE_SHOW,
MGMTD_TXN_TYPE_RPC,
};
static inline const char *mgmt_txn_type2str(enum mgmt_txn_type type)
{
switch (type) {
case MGMTD_TXN_TYPE_NONE:
return "None";
case MGMTD_TXN_TYPE_CONFIG:
return "CONFIG";
case MGMTD_TXN_TYPE_SHOW:
return "SHOW";
case MGMTD_TXN_TYPE_RPC:
return "RPC";
}
return "Unknown";
}
/* Initialise transaction module. */
extern int mgmt_txn_init(struct mgmt_master *cm, struct event_loop *tm);
/* Destroy the transaction module. */
extern void mgmt_txn_destroy(void);
/*
* Check if configuration transaction is in progress.
*
* Returns:
* true if in-progress, false otherwise.
*/
extern bool mgmt_config_txn_in_progress(void);
/**
* Get the session ID associated with the given ``txn-id``.
*
*/
extern uint64_t mgmt_txn_get_session_id(uint64_t txn_id);
/*
* Create transaction.
*
* session_id
* Session ID.
*
* type
* Transaction type (CONFIG/SHOW/NONE)
*
* Returns:
* transaction ID.
*/
extern uint64_t mgmt_create_txn(uint64_t session_id, enum mgmt_txn_type type);
/*
* Destroy transaction.
*
* txn_id
* Unique transaction identifier.
*/
extern void mgmt_destroy_txn(uint64_t *txn_id);
/*
* Send set-config request to be processed later in transaction.
*
* txn_id
* Unique transaction identifier.
*
* req_id
* Unique transaction request identifier.
*
* ds_id
* Datastore ID.
*
* ds_hndl
* Datastore handle.
*
* cfg_req
* Config requests.
*
* num_req
* Number of config requests.
*
* implicit_commit
* TRUE if the commit is implicit, FALSE otherwise.
*
* dst_ds_id
* Destination datastore ID.
*
* dst_ds_handle
* Destination datastore handle.
*
* Returns:
* 0 on success, -1 on failures.
*/
extern int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
Mgmtd__DatastoreId ds_id,
struct mgmt_ds_ctx *ds_ctx,
Mgmtd__YangCfgDataReq **cfg_req,
size_t num_req, bool implicit_commit,
Mgmtd__DatastoreId dst_ds_id,
struct mgmt_ds_ctx *dst_ds_ctx);
/*
* Send commit-config request to be processed later in transaction.
*
* txn_id
* Unique transaction identifier.
*
* req_id
* Unique transaction request identifier.
*
* src_ds_id
* Source datastore ID.
*
* src_ds_hndl
* Source Datastore handle.
*
* validate_only
* TRUE if commit request needs to be validated only, FALSE otherwise.
*
* abort
* TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
*
* implicit
* TRUE if the commit is implicit, FALSE otherwise.
*
* edit
* Additional info when triggered from native edit request.
*
* Returns:
* 0 on success, -1 on failures.
*/
extern int mgmt_txn_send_commit_config_req(
uint64_t txn_id, uint64_t req_id, Mgmtd__DatastoreId src_ds_id,
struct mgmt_ds_ctx *dst_ds_ctx, Mgmtd__DatastoreId dst_ds_id,
struct mgmt_ds_ctx *src_ds_ctx, bool validate_only, bool abort,
bool implicit, struct mgmt_edit_req *edit);
/*
* Send get-{cfg,data} request to be processed later in transaction.
*
* Is get-config if cfg_root is provided and the config is gathered locally,
* otherwise it's get-data and data is fetched from backedn clients.
*/
extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
Mgmtd__DatastoreId ds_id,
struct nb_config *cfg_root,
Mgmtd__YangGetDataReq **data_req,
size_t num_reqs);
/**
* Send get-tree to the backend `clients`.
*
* Args:
* txn_id: Transaction identifier.
* req_id: FE client request identifier.
* clients: Bitmask of clients to send get-tree to.
* ds_id: datastore ID.
* result_type: LYD_FORMAT result format.
* flags: option flags for the request.
* wd_options: LYD_PRINT_WD_* flags for the result.
* simple_xpath: true if xpath is simple (only key predicates).
* xpath: The xpath to get the tree from.
*
* Return:
* 0 on success.
*/
extern int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id,
uint64_t clients,
Mgmtd__DatastoreId ds_id,
LYD_FORMAT result_type, uint8_t flags,
uint32_t wd_options, bool simple_xpath,
const char *xpath);
/**
* Send edit request.
*
* Args:
* txn_id: Transaction identifier.
* req_id: FE client request identifier.
* ds_id: Datastore ID.
* ds_ctx: Datastore context.
* commit_ds_id: Commit datastore ID.
* commit_ds_ctx: Commit datastore context.
* unlock: Unlock datastores after the edit.
* commit: Commit the candidate datastore after the edit.
* request_type: LYD_FORMAT request type.
* flags: option flags for the request.
* operation: The operation to perform.
* xpath: The xpath of data node to edit.
* data: The data tree.
*/
extern int
mgmt_txn_send_edit(uint64_t txn_id, uint64_t req_id, Mgmtd__DatastoreId ds_id,
struct mgmt_ds_ctx *ds_ctx, Mgmtd__DatastoreId commit_ds_id,
struct mgmt_ds_ctx *commit_ds_ctx, bool unlock, bool commit,
LYD_FORMAT request_type, uint8_t flags, uint8_t operation,
const char *xpath, const char *data);
/**
* Send RPC request.
*
* Args:
* txn_id: Transaction identifier.
* req_id: FE client request identifier.
* clients: Bitmask of clients to send RPC to.
* result_type: LYD_FORMAT result format.
* xpath: The xpath of the RPC.
* data: The input parameters data tree.
* data_len: The length of the input parameters data.
*
* Return:
* 0 on success.
*/
extern int mgmt_txn_send_rpc(uint64_t txn_id, uint64_t req_id, uint64_t clients,
LYD_FORMAT result_type, const char *xpath,
const char *data, size_t data_len);
/*
* Notifiy backend adapter on connection.
*/
extern int
mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
bool connect);
/*
* Reply to backend adapter about transaction create/delete.
*/
extern int
mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success,
struct mgmt_be_client_adapter *adapter);
/*
* Reply to backend adapater with config data create request.
*/
extern int
mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, bool success,
char *error_if_any,
struct mgmt_be_client_adapter *adapter);
/*
* Reply to backend adapater with config data validate request.
*/
extern int mgmt_txn_notify_be_cfg_validate_reply(
uint64_t txn_id, bool success, uint64_t batch_ids[],
size_t num_batch_ids, char *error_if_any,
struct mgmt_be_client_adapter *adapter);
/*
* Reply to backend adapater with config data apply request.
*/
extern int
mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
char *error_if_any,
struct mgmt_be_client_adapter *adapter);
/**
* Process a reply from a backend client to our get-tree request
*
* Args:
* adapter: The adapter that received the result.
* txn_id: The transaction for this get-tree request.
* req_id: The request ID for this transaction.
* error: the integer error value (negative)
* errstr: the string description of the error.
*/
int mgmt_txn_notify_error(struct mgmt_be_client_adapter *adapter,
uint64_t txn_id, uint64_t req_id, int error,
const char *errstr);
/**
* Process a reply from a backend client to our get-tree request
*
* Args:
* adapter: The adapter that received the result.
* data_msg: The message from the backend.
* msg_len: Total length of the message.
*/
extern int mgmt_txn_notify_tree_data_reply(struct mgmt_be_client_adapter *adapter,
struct mgmt_msg_tree_data *data_msg,
size_t msg_len);
/**
* Process a reply from a backend client to our RPC request
*
* Args:
* adapter: The adapter that received the result.
* reply_msg: The message from the backend.
* msg_len: Total length of the message.
*/
extern int mgmt_txn_notify_rpc_reply(struct mgmt_be_client_adapter *adapter,
struct mgmt_msg_rpc_reply *reply_msg,
size_t msg_len);
/*
* Dump transaction status to vty.
*/
extern void mgmt_txn_status_write(struct vty *vty);
/*
* Trigger rollback config apply.
*
* Creates a new transaction and commit request for rollback.
*/
extern int
mgmt_txn_rollback_trigger_cfg_apply(struct mgmt_ds_ctx *src_ds_ctx,
struct mgmt_ds_ctx *dst_ds_ctx);
#endif /* _FRR_MGMTD_TXN_H_ */
|