1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MGMTD Frontend Client Connection Adapter
5 * Copyright (C) 2021 Vmware, Inc.
6 * Pushpasis Sarkar <spushpasis@vmware.com>
9 #ifndef _FRR_MGMTD_FE_ADAPTER_H_
10 #define _FRR_MGMTD_FE_ADAPTER_H_
12 #include "mgmt_fe_client.h"
14 #include "mgmtd/mgmt_defines.h"
16 struct mgmt_fe_client_adapter
;
19 struct mgmt_commit_stats
{
20 struct timeval last_start
;
21 #ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
22 struct timeval validate_start
;
24 struct timeval prep_cfg_start
;
25 struct timeval txn_create_start
;
26 struct timeval send_cfg_start
;
27 struct timeval apply_cfg_start
;
28 struct timeval apply_cfg_end
;
29 struct timeval txn_del_start
;
30 struct timeval last_end
;
31 unsigned long last_exec_tm
;
34 unsigned long last_batch_cnt
;
35 unsigned long last_num_cfgdata_reqs
;
36 unsigned long last_num_apply_reqs
;
37 unsigned long max_batch_cnt
;
38 unsigned long min_batch_cnt
;
39 unsigned long commit_cnt
;
42 struct mgmt_setcfg_stats
{
43 struct timeval last_start
;
44 struct timeval last_end
;
45 unsigned long last_exec_tm
;
49 unsigned long set_cfg_count
;
52 PREDECL_LIST(mgmt_fe_sessions
);
54 PREDECL_LIST(mgmt_fe_adapters
);
56 struct mgmt_fe_client_adapter
{
58 union sockunion conn_su
;
59 struct event
*conn_read_ev
;
60 struct event
*conn_write_ev
;
61 struct event
*conn_writes_on
;
62 struct event
*proc_msg_ev
;
65 char name
[MGMTD_CLIENT_NAME_MAX_LEN
];
67 /* List of sessions created and being maintained for this client. */
68 struct mgmt_fe_sessions_head fe_sessions
;
70 /* IO streams for read and write */
71 struct mgmt_msg_state mstate
;
74 struct mgmt_commit_stats cmt_stats
;
75 struct mgmt_setcfg_stats setcfg_stats
;
77 struct mgmt_fe_adapters_item list_linkage
;
80 #define MGMTD_FE_ADAPTER_FLAGS_WRITES_OFF (1U << 0)
82 DECLARE_LIST(mgmt_fe_adapters
, struct mgmt_fe_client_adapter
, list_linkage
);
84 /* Initialise frontend adapter module */
85 extern int mgmt_fe_adapter_init(struct event_loop
*tm
, struct mgmt_master
*cm
);
87 /* Destroy frontend adapter module */
88 extern void mgmt_fe_adapter_destroy(void);
90 /* Acquire lock for frontend adapter */
91 extern void mgmt_fe_adapter_lock(struct mgmt_fe_client_adapter
*adapter
);
93 /* Remove lock from frontend adapter */
95 mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter
**adapter
);
97 /* Create frontend adapter */
98 extern struct mgmt_fe_client_adapter
*
99 mgmt_fe_create_adapter(int conn_fd
, union sockunion
*su
);
101 /* Fetch frontend adapter given a name */
102 extern struct mgmt_fe_client_adapter
*
103 mgmt_fe_get_adapter(const char *name
);
106 * Send set-config reply to the frontend client.
109 * Unique session identifier.
112 * Unique transaction identifier.
121 * Config request result (MGMT_*).
124 * Buffer to store human-readable error message in case of error.
127 * TRUE if the commit is implicit, FALSE otherwise.
130 * 0 on success, -1 on failures.
132 extern int mgmt_fe_send_set_cfg_reply(uint64_t session_id
, uint64_t txn_id
,
133 Mgmtd__DatastoreId ds_id
,
135 enum mgmt_result result
,
136 const char *error_if_any
,
137 bool implcit_commit
);
140 * Send commit-config reply to the frontend client.
142 extern int mgmt_fe_send_commit_cfg_reply(
143 uint64_t session_id
, uint64_t txn_id
, Mgmtd__DatastoreId src_ds_id
,
144 Mgmtd__DatastoreId dst_ds_id
, uint64_t req_id
, bool validate_only
,
145 enum mgmt_result result
, const char *error_if_any
);
148 * Send get-config reply to the frontend client.
150 extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id
, uint64_t txn_id
,
151 Mgmtd__DatastoreId ds_id
,
153 enum mgmt_result result
,
154 Mgmtd__YangDataReply
*data_resp
,
155 const char *error_if_any
);
158 * Send get-data reply to the frontend client.
160 extern int mgmt_fe_send_get_data_reply(
161 uint64_t session_id
, uint64_t txn_id
, Mgmtd__DatastoreId ds_id
,
162 uint64_t req_id
, enum mgmt_result result
,
163 Mgmtd__YangDataReply
*data_resp
, const char *error_if_any
);
166 * Send data notify to the frontend client.
168 extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id
,
169 Mgmtd__YangData
* data_resp
[],
172 /* Fetch frontend client session set-config stats */
173 extern struct mgmt_setcfg_stats
*
174 mgmt_fe_get_session_setcfg_stats(uint64_t session_id
);
176 /* Fetch frontend client session commit stats */
177 extern struct mgmt_commit_stats
*
178 mgmt_fe_get_session_commit_stats(uint64_t session_id
);
180 extern void mgmt_fe_adapter_status_write(struct vty
*vty
, bool detail
);
181 extern void mgmt_fe_adapter_perf_measurement(struct vty
*vty
, bool config
);
182 extern void mgmt_fe_adapter_reset_perf_stats(struct vty
*vty
);
183 #endif /* _FRR_MGMTD_FE_ADAPTER_H_ */