]> git.proxmox.com Git - mirror_frr.git/blame - mgmtd/mgmt_fe_adapter.h
*: Convert `struct event_master` to `struct event_loop`
[mirror_frr.git] / mgmtd / mgmt_fe_adapter.h
CommitLineData
ef43a632
CH
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * MGMTD Frontend Client Connection Adapter
4 *
5 * Copyright (C) 2021 Vmware, Inc.
6 * Pushpasis Sarkar <spushpasis@vmware.com>
7 */
8
9#ifndef _FRR_MGMTD_FE_ADAPTER_H_
10#define _FRR_MGMTD_FE_ADAPTER_H_
11
f82370b4
CH
12#include "mgmt_fe_client.h"
13#include "mgmt_msg.h"
14#include "mgmtd/mgmt_defines.h"
15
ef43a632
CH
16struct mgmt_fe_client_adapter;
17struct mgmt_master;
18
19struct mgmt_commit_stats {
20 struct timeval last_start;
21#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
22 struct timeval validate_start;
23#endif
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;
32 unsigned long max_tm;
33 unsigned long min_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;
40};
41
42struct mgmt_setcfg_stats {
43 struct timeval last_start;
44 struct timeval last_end;
45 unsigned long last_exec_tm;
46 unsigned long max_tm;
47 unsigned long min_tm;
48 unsigned long avg_tm;
49 unsigned long set_cfg_count;
50};
51
52PREDECL_LIST(mgmt_fe_sessions);
53
54PREDECL_LIST(mgmt_fe_adapters);
55
56struct mgmt_fe_client_adapter {
57 int conn_fd;
58 union sockunion conn_su;
e6685141
DS
59 struct event *conn_read_ev;
60 struct event *conn_write_ev;
61 struct event *conn_writes_on;
62 struct event *proc_msg_ev;
ef43a632
CH
63 uint32_t flags;
64
65 char name[MGMTD_CLIENT_NAME_MAX_LEN];
66
67 /* List of sessions created and being maintained for this client. */
68 struct mgmt_fe_sessions_head fe_sessions;
69
70 /* IO streams for read and write */
f82370b4 71 struct mgmt_msg_state mstate;
ef43a632
CH
72
73 int refcount;
ef43a632
CH
74 struct mgmt_commit_stats cmt_stats;
75 struct mgmt_setcfg_stats setcfg_stats;
76
77 struct mgmt_fe_adapters_item list_linkage;
78};
79
80#define MGMTD_FE_ADAPTER_FLAGS_WRITES_OFF (1U << 0)
81
82DECLARE_LIST(mgmt_fe_adapters, struct mgmt_fe_client_adapter, list_linkage);
83
84/* Initialise frontend adapter module */
cd9d0537 85extern int mgmt_fe_adapter_init(struct event_loop *tm, struct mgmt_master *cm);
ef43a632
CH
86
87/* Destroy frontend adapter module */
88extern void mgmt_fe_adapter_destroy(void);
89
90/* Acquire lock for frontend adapter */
91extern void mgmt_fe_adapter_lock(struct mgmt_fe_client_adapter *adapter);
92
93/* Remove lock from frontend adapter */
94extern void
95mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter **adapter);
96
97/* Create frontend adapter */
98extern struct mgmt_fe_client_adapter *
99mgmt_fe_create_adapter(int conn_fd, union sockunion *su);
100
101/* Fetch frontend adapter given a name */
102extern struct mgmt_fe_client_adapter *
103mgmt_fe_get_adapter(const char *name);
104
105/*
106 * Send set-config reply to the frontend client.
107 *
108 * session
109 * Unique session identifier.
110 *
111 * txn_id
112 * Unique transaction identifier.
113 *
114 * ds_id
115 * Datastore ID.
116 *
117 * req_id
118 * Config request ID.
119 *
120 * result
121 * Config request result (MGMT_*).
122 *
123 * error_if_any
124 * Buffer to store human-readable error message in case of error.
125 *
126 * implicit_commit
127 * TRUE if the commit is implicit, FALSE otherwise.
128 *
129 * Returns:
130 * 0 on success, -1 on failures.
131 */
132extern int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
133 Mgmtd__DatastoreId ds_id,
134 uint64_t req_id,
135 enum mgmt_result result,
136 const char *error_if_any,
137 bool implcit_commit);
138
139/*
140 * Send commit-config reply to the frontend client.
141 */
142extern 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);
146
147/*
148 * Send get-config reply to the frontend client.
149 */
150extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
151 Mgmtd__DatastoreId ds_id,
152 uint64_t req_id,
153 enum mgmt_result result,
154 Mgmtd__YangDataReply *data_resp,
155 const char *error_if_any);
156
157/*
158 * Send get-data reply to the frontend client.
159 */
160extern 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);
164
165/*
166 * Send data notify to the frontend client.
167 */
168extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id,
169 Mgmtd__YangData * data_resp[],
170 int num_data);
171
172/* Fetch frontend client session set-config stats */
173extern struct mgmt_setcfg_stats *
174mgmt_fe_get_session_setcfg_stats(uint64_t session_id);
175
176/* Fetch frontend client session commit stats */
177extern struct mgmt_commit_stats *
178mgmt_fe_get_session_commit_stats(uint64_t session_id);
179
180extern void mgmt_fe_adapter_status_write(struct vty *vty, bool detail);
181extern void mgmt_fe_adapter_perf_measurement(struct vty *vty, bool config);
182extern void mgmt_fe_adapter_reset_perf_stats(struct vty *vty);
183#endif /* _FRR_MGMTD_FE_ADAPTER_H_ */