]> git.proxmox.com Git - mirror_frr.git/blame - lib/mgmt_be_client.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / mgmt_be_client.h
CommitLineData
7d65b7b7
CH
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * MGMTD Backend Client Library api interfaces
4 * Copyright (C) 2021 Vmware, Inc.
5 * Pushpasis Sarkar <spushpasis@vmware.com>
6 */
7
8#ifndef _FRR_MGMTD_BE_CLIENT_H_
9#define _FRR_MGMTD_BE_CLIENT_H_
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
f82370b4
CH
15#include "northbound.h"
16#include "mgmt_pb.h"
7d65b7b7
CH
17#include "mgmtd/mgmt_defines.h"
18
19/***************************************************************
20 * Client IDs
21 ***************************************************************/
22
23/*
24 * Add enum value for each supported component, wrap with
25 * #ifdef HAVE_COMPONENT
26 */
27enum mgmt_be_client_id {
28 MGMTD_BE_CLIENT_ID_MIN = 0,
29 MGMTD_BE_CLIENT_ID_INIT = -1,
7d65b7b7
CH
30#ifdef HAVE_STATICD
31 MGMTD_BE_CLIENT_ID_STATICD,
7d65b7b7
CH
32#endif
33 MGMTD_BE_CLIENT_ID_MAX
34};
35
36#define FOREACH_MGMTD_BE_CLIENT_ID(id) \
37 for ((id) = MGMTD_BE_CLIENT_ID_MIN; \
38 (id) < MGMTD_BE_CLIENT_ID_MAX; (id)++)
39
40/***************************************************************
41 * Constants
42 ***************************************************************/
43
44#define MGMTD_BE_CLIENT_ERROR_STRING_MAX_LEN 32
45
46#define MGMTD_BE_DEFAULT_CONN_RETRY_INTVL_SEC 5
47
48#define MGMTD_BE_MSG_PROC_DELAY_USEC 10
49#define MGMTD_BE_MAX_NUM_MSG_PROC 500
50
51#define MGMTD_BE_MSG_WRITE_DELAY_MSEC 1
52#define MGMTD_BE_MAX_NUM_MSG_WRITE 1000
53
54#define GMGD_BE_MAX_NUM_REQ_ITEMS 64
55
56#define MGMTD_BE_MSG_MAX_LEN 16384
57
58#define MGMTD_SOCKET_BE_SEND_BUF_SIZE 65535
59#define MGMTD_SOCKET_BE_RECV_BUF_SIZE MGMTD_SOCKET_BE_SEND_BUF_SIZE
60
61#define MGMTD_MAX_CFG_CHANGES_IN_BATCH \
62 ((10 * MGMTD_BE_MSG_MAX_LEN) / \
63 (MGMTD_MAX_XPATH_LEN + MGMTD_MAX_YANG_VALUE_LEN))
64
65/*
66 * MGMTD_BE_MSG_MAX_LEN must be used 80%
67 * since there is overhead of google protobuf
68 * that gets added to sent message
69 */
70#define MGMTD_BE_CFGDATA_PACKING_EFFICIENCY 0.8
71#define MGMTD_BE_CFGDATA_MAX_MSG_LEN \
72 (MGMTD_BE_MSG_MAX_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY)
73
74#define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \
75 (MGMTD_BE_MSG_MAX_LEN - 128) / sizeof(uint64_t)
76
77#define MGMTD_BE_CONTAINER_NODE_VAL "<<container>>"
78
79/***************************************************************
80 * Data-structures
81 ***************************************************************/
82
83#define MGMTD_BE_MAX_CLIENTS_PER_XPATH_REG 32
84
7aecb863
CH
85struct mgmt_be_client;
86
7d65b7b7
CH
87struct mgmt_be_client_txn_ctx {
88 uintptr_t *user_ctx;
89};
90
7aecb863
CH
91/**
92 * Backend client callbacks.
7d65b7b7 93 *
7aecb863
CH
94 * Callbacks:
95 * client_connect_notify: called when connection is made/lost to mgmtd.
96 * txn_notify: called when a txn has been created
7d65b7b7 97 */
7aecb863
CH
98struct mgmt_be_client_cbs {
99 void (*client_connect_notify)(struct mgmt_be_client *client,
100 uintptr_t usr_data, bool connected);
101
102 void (*txn_notify)(struct mgmt_be_client *client, uintptr_t usr_data,
103 struct mgmt_be_client_txn_ctx *txn_ctx,
104 bool destroyed);
7d65b7b7
CH
105};
106
107/***************************************************************
108 * Global data exported
109 ***************************************************************/
110
111extern const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1];
112
113static inline const char *mgmt_be_client_id2name(enum mgmt_be_client_id id)
114{
115 if (id > MGMTD_BE_CLIENT_ID_MAX)
116 id = MGMTD_BE_CLIENT_ID_MAX;
117 return mgmt_be_client_names[id];
118}
119
120static inline enum mgmt_be_client_id
121mgmt_be_client_name2id(const char *name)
122{
123 enum mgmt_be_client_id id;
124
125 FOREACH_MGMTD_BE_CLIENT_ID (id) {
126 if (!strncmp(mgmt_be_client_names[id], name,
127 MGMTD_CLIENT_NAME_MAX_LEN))
128 return id;
129 }
130
131 return MGMTD_BE_CLIENT_ID_MAX;
132}
133
134/***************************************************************
135 * API prototypes
136 ***************************************************************/
137
7aecb863
CH
138/**
139 * Create backend client and connect to MGMTD.
7d65b7b7 140 *
7aecb863
CH
141 * Args:
142 * client_name: the name of the client
143 * cbs: callbacks for various events.
144 * event_loop: the main event loop.
7d65b7b7
CH
145 *
146 * Returns:
7aecb863 147 * Backend client object.
7d65b7b7 148 */
7aecb863
CH
149extern struct mgmt_be_client *
150mgmt_be_client_create(const char *name, struct mgmt_be_client_cbs *cbs,
151 uintptr_t user_data, struct event_loop *event_loop);
7d65b7b7 152
cfa0facb
CH
153/*
154 * Initialize library vty (adds debug support).
155 *
156 * This call should be added to your component when enabling other vty code to
157 * enable mgmtd client debugs. When adding, one needs to also add a their
158 * component in `xref2vtysh.py` as well.
159 */
160extern void mgmt_be_client_lib_vty_init(void);
161
162/*
163 * Print enabled debugging commands.
164 */
165extern void mgmt_debug_be_client_show_debug(struct vty *vty);
166
7d65b7b7 167/*
7aecb863 168 * [Un]-subscribe with MGMTD for one or more YANG subtree(s).
7d65b7b7 169 *
7aecb863
CH
170 * client
171 * The client object.
7d65b7b7
CH
172 *
173 * reg_yang_xpaths
7aecb863 174 * Yang xpath(s) that needs to be [un]-subscribed from/to
7d65b7b7
CH
175 *
176 * num_xpaths
177 * Number of xpaths
178 *
179 * Returns:
180 * MGMTD_SUCCESS on success, MGMTD_* otherwise.
181 */
7aecb863
CH
182extern int mgmt_be_send_subscr_req(struct mgmt_be_client *client,
183 bool subscr_xpaths, int num_xpaths,
184 char **reg_xpaths);
7d65b7b7
CH
185
186/*
7aecb863 187 * Destroy backend client and cleanup everything.
7d65b7b7 188 */
7aecb863 189extern void mgmt_be_client_destroy(struct mgmt_be_client *client);
7d65b7b7
CH
190
191#ifdef __cplusplus
192}
193#endif
194
195#endif /* _FRR_MGMTD_BE_CLIENT_H_ */