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 thread
*conn_read_ev
;
60 struct thread
*conn_write_ev
;
61 struct thread
*conn_writes_on
;
62 struct thread
*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 thread_master
*tm
,
86 struct mgmt_master
*cm
);
88 /* Destroy frontend adapter module */
89 extern void mgmt_fe_adapter_destroy(void);
91 /* Acquire lock for frontend adapter */
92 extern void mgmt_fe_adapter_lock(struct mgmt_fe_client_adapter
*adapter
);
94 /* Remove lock from frontend adapter */
96 mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter
**adapter
);
98 /* Create frontend adapter */
99 extern struct mgmt_fe_client_adapter
*
100 mgmt_fe_create_adapter(int conn_fd
, union sockunion
*su
);
102 /* Fetch frontend adapter given a name */
103 extern struct mgmt_fe_client_adapter
*
104 mgmt_fe_get_adapter(const char *name
);
107 * Send set-config reply to the frontend client.
110 * Unique session identifier.
113 * Unique transaction identifier.
122 * Config request result (MGMT_*).
125 * Buffer to store human-readable error message in case of error.
128 * TRUE if the commit is implicit, FALSE otherwise.
131 * 0 on success, -1 on failures.
133 extern int mgmt_fe_send_set_cfg_reply(uint64_t session_id
, uint64_t txn_id
,
134 Mgmtd__DatastoreId ds_id
,
136 enum mgmt_result result
,
137 const char *error_if_any
,
138 bool implcit_commit
);
141 * Send commit-config reply to the frontend client.
143 extern int mgmt_fe_send_commit_cfg_reply(
144 uint64_t session_id
, uint64_t txn_id
, Mgmtd__DatastoreId src_ds_id
,
145 Mgmtd__DatastoreId dst_ds_id
, uint64_t req_id
, bool validate_only
,
146 enum mgmt_result result
, const char *error_if_any
);
149 * Send get-config reply to the frontend client.
151 extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id
, uint64_t txn_id
,
152 Mgmtd__DatastoreId ds_id
,
154 enum mgmt_result result
,
155 Mgmtd__YangDataReply
*data_resp
,
156 const char *error_if_any
);
159 * Send get-data reply to the frontend client.
161 extern int mgmt_fe_send_get_data_reply(
162 uint64_t session_id
, uint64_t txn_id
, Mgmtd__DatastoreId ds_id
,
163 uint64_t req_id
, enum mgmt_result result
,
164 Mgmtd__YangDataReply
*data_resp
, const char *error_if_any
);
167 * Send data notify to the frontend client.
169 extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id
,
170 Mgmtd__YangData
* data_resp
[],
173 /* Fetch frontend client session set-config stats */
174 extern struct mgmt_setcfg_stats
*
175 mgmt_fe_get_session_setcfg_stats(uint64_t session_id
);
177 /* Fetch frontend client session commit stats */
178 extern struct mgmt_commit_stats
*
179 mgmt_fe_get_session_commit_stats(uint64_t session_id
);
181 extern void mgmt_fe_adapter_status_write(struct vty
*vty
, bool detail
);
182 extern void mgmt_fe_adapter_perf_measurement(struct vty
*vty
, bool config
);
183 extern void mgmt_fe_adapter_reset_perf_stats(struct vty
*vty
);
184 #endif /* _FRR_MGMTD_FE_ADAPTER_H_ */