Coverage Report

Created: 2026-04-09 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/frr/mgmtd/mgmt_txn.h
Line
Count
Source
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
0
{
55
0
  switch (type) {
56
0
  case MGMTD_TXN_TYPE_NONE:
57
0
    return "None";
58
0
  case MGMTD_TXN_TYPE_CONFIG:
59
0
    return "CONFIG";
60
0
  case MGMTD_TXN_TYPE_SHOW:
61
0
    return "SHOW";
62
0
  }
63
0
64
0
  return "Unknown";
65
0
}
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
 * Send set-config request to be processed later in transaction.
105
 *
106
 * txn_id
107
 *    Unique transaction identifier.
108
 *
109
 * req_id
110
 *    Unique transaction request identifier.
111
 *
112
 * ds_id
113
 *    Datastore ID.
114
 *
115
 * ds_hndl
116
 *    Datastore handle.
117
 *
118
 * cfg_req
119
 *    Config requests.
120
 *
121
 * num_req
122
 *    Number of config requests.
123
 *
124
 * implicit_commit
125
 *    TRUE if the commit is implicit, FALSE otherwise.
126
 *
127
 * dst_ds_id
128
 *    Destination datastore ID.
129
 *
130
 * dst_ds_handle
131
 *    Destination datastore handle.
132
 *
133
 * Returns:
134
 *    0 on success, -1 on failures.
135
 */
136
extern int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
137
           Mgmtd__DatastoreId ds_id,
138
           struct mgmt_ds_ctx *ds_ctx,
139
           Mgmtd__YangCfgDataReq **cfg_req,
140
           size_t num_req, bool implicit_commit,
141
           Mgmtd__DatastoreId dst_ds_id,
142
           struct mgmt_ds_ctx *dst_ds_ctx);
143
144
/*
145
 * Send commit-config request to be processed later in transaction.
146
 *
147
 * txn_id
148
 *    Unique transaction identifier.
149
 *
150
 * req_id
151
 *    Unique transaction request identifier.
152
 *
153
 * src_ds_id
154
 *    Source datastore ID.
155
 *
156
 * src_ds_hndl
157
 *    Source Datastore handle.
158
 *
159
 * validate_only
160
 *    TRUE if commit request needs to be validated only, FALSE otherwise.
161
 *
162
 * abort
163
 *    TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
164
 *
165
 * implicit
166
 *    TRUE if the commit is implicit, FALSE otherwise.
167
 *
168
 * Returns:
169
 *    0 on success, -1 on failures.
170
 */
171
extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id,
172
             Mgmtd__DatastoreId src_ds_id,
173
             struct mgmt_ds_ctx *dst_ds_ctx,
174
             Mgmtd__DatastoreId dst_ds_id,
175
             struct mgmt_ds_ctx *src_ds_ctx,
176
             bool validate_only, bool abort,
177
             bool implicit);
178
179
/*
180
 * Send get-{cfg,data} request to be processed later in transaction.
181
 *
182
 * Is get-config if cfg_root is provided and the config is gathered locally,
183
 * otherwise it's get-data and data is fetched from backedn clients.
184
 */
185
extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
186
         Mgmtd__DatastoreId ds_id,
187
         struct nb_config *cfg_root,
188
         Mgmtd__YangGetDataReq **data_req,
189
         size_t num_reqs);
190
191
/*
192
 * Notifiy backend adapter on connection.
193
 */
194
extern int
195
mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
196
            bool connect);
197
198
/*
199
 * Reply to backend adapter about transaction create/delete.
200
 */
201
extern int
202
mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success,
203
          struct mgmt_be_client_adapter *adapter);
204
205
/*
206
 * Reply to backend adapater with config data create request.
207
 */
208
extern int
209
mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
210
             bool success, char *error_if_any,
211
             struct mgmt_be_client_adapter *adapter);
212
213
/*
214
 * Reply to backend adapater with config data validate request.
215
 */
216
extern int mgmt_txn_notify_be_cfg_validate_reply(
217
  uint64_t txn_id, bool success, uint64_t batch_ids[],
218
  size_t num_batch_ids, char *error_if_any,
219
  struct mgmt_be_client_adapter *adapter);
220
221
/*
222
 * Reply to backend adapater with config data apply request.
223
 */
224
extern int
225
mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
226
               uint64_t batch_ids[],
227
               size_t num_batch_ids, char *error_if_any,
228
               struct mgmt_be_client_adapter *adapter);
229
230
/*
231
 * Dump transaction status to vty.
232
 */
233
extern void mgmt_txn_status_write(struct vty *vty);
234
235
/*
236
 * Trigger rollback config apply.
237
 *
238
 * Creates a new transaction and commit request for rollback.
239
 */
240
extern int
241
mgmt_txn_rollback_trigger_cfg_apply(struct mgmt_ds_ctx *src_ds_ctx,
242
             struct mgmt_ds_ctx *dst_ds_ctx);
243
#endif /* _FRR_MGMTD_TXN_H_ */