]> git.proxmox.com Git - mirror_frr.git/blame - mgmtd/mgmt_fe_adapter.h
*: Rename thread.[ch] to event.[ch]
[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;
59 struct thread *conn_read_ev;
60 struct thread *conn_write_ev;
61 struct thread *conn_writes_on;
62 struct thread *proc_msg_ev;
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 */
85extern int mgmt_fe_adapter_init(struct thread_master *tm,
86 struct mgmt_master *cm);
87
88/* Destroy frontend adapter module */
89extern void mgmt_fe_adapter_destroy(void);
90
91/* Acquire lock for frontend adapter */
92extern void mgmt_fe_adapter_lock(struct mgmt_fe_client_adapter *adapter);
93
94/* Remove lock from frontend adapter */
95extern void
96mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter **adapter);
97
98/* Create frontend adapter */
99extern struct mgmt_fe_client_adapter *
100mgmt_fe_create_adapter(int conn_fd, union sockunion *su);
101
102/* Fetch frontend adapter given a name */
103extern struct mgmt_fe_client_adapter *
104mgmt_fe_get_adapter(const char *name);
105
106/*
107 * Send set-config reply to the frontend client.
108 *
109 * session
110 * Unique session identifier.
111 *
112 * txn_id
113 * Unique transaction identifier.
114 *
115 * ds_id
116 * Datastore ID.
117 *
118 * req_id
119 * Config request ID.
120 *
121 * result
122 * Config request result (MGMT_*).
123 *
124 * error_if_any
125 * Buffer to store human-readable error message in case of error.
126 *
127 * implicit_commit
128 * TRUE if the commit is implicit, FALSE otherwise.
129 *
130 * Returns:
131 * 0 on success, -1 on failures.
132 */
133extern int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
134 Mgmtd__DatastoreId ds_id,
135 uint64_t req_id,
136 enum mgmt_result result,
137 const char *error_if_any,
138 bool implcit_commit);
139
140/*
141 * Send commit-config reply to the frontend client.
142 */
143extern 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);
147
148/*
149 * Send get-config reply to the frontend client.
150 */
151extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
152 Mgmtd__DatastoreId ds_id,
153 uint64_t req_id,
154 enum mgmt_result result,
155 Mgmtd__YangDataReply *data_resp,
156 const char *error_if_any);
157
158/*
159 * Send get-data reply to the frontend client.
160 */
161extern 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);
165
166/*
167 * Send data notify to the frontend client.
168 */
169extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id,
170 Mgmtd__YangData * data_resp[],
171 int num_data);
172
173/* Fetch frontend client session set-config stats */
174extern struct mgmt_setcfg_stats *
175mgmt_fe_get_session_setcfg_stats(uint64_t session_id);
176
177/* Fetch frontend client session commit stats */
178extern struct mgmt_commit_stats *
179mgmt_fe_get_session_commit_stats(uint64_t session_id);
180
181extern void mgmt_fe_adapter_status_write(struct vty *vty, bool detail);
182extern void mgmt_fe_adapter_perf_measurement(struct vty *vty, bool config);
183extern void mgmt_fe_adapter_reset_perf_stats(struct vty *vty);
184#endif /* _FRR_MGMTD_FE_ADAPTER_H_ */