]>
Commit | Line | Data |
---|---|---|
1c84efe4 CH |
1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | /* | |
3 | * MGMTD message definition header. | |
4 | * | |
5 | * Copyright (C) 2021 Vmware, Inc. | |
6 | * Pushpasis Sarkar <spushpasis@vmware.com> | |
7 | */ | |
8 | ||
9 | #ifndef _FRR_MGMTD_H | |
10 | #define _FRR_MGMTD_H | |
11 | ||
12 | #include "vrf.h" | |
1c84efe4 | 13 | #include "defaults.h" |
ef43a632 | 14 | #include "stream.h" |
1c84efe4 CH |
15 | |
16 | #include "mgmtd/mgmt_memory.h" | |
74335ceb YR |
17 | #include "mgmtd/mgmt_defines.h" |
18 | #include "mgmtd/mgmt_history.h" | |
19 | #include "mgmtd/mgmt_txn.h" | |
1c84efe4 CH |
20 | #include "mgmtd/mgmt_ds.h" |
21 | ||
22 | #define MGMTD_VTY_PORT 2622 | |
23 | #define MGMTD_SOCKET_BUF_SIZE 65535 | |
74335ceb | 24 | #define MGMTD_MAX_COMMIT_LIST 10 |
1c84efe4 CH |
25 | |
26 | extern bool mgmt_debug_be; | |
27 | extern bool mgmt_debug_fe; | |
28 | extern bool mgmt_debug_ds; | |
29 | extern bool mgmt_debug_txn; | |
30 | ||
74335ceb YR |
31 | struct mgmt_txn_ctx; |
32 | ||
1c84efe4 CH |
33 | /* |
34 | * MGMTD master for system wide configurations and variables. | |
35 | */ | |
36 | struct mgmt_master { | |
cd9d0537 | 37 | struct event_loop *master; |
1c84efe4 CH |
38 | |
39 | /* How big should we set the socket buffer size */ | |
40 | uint32_t socket_buffer; | |
41 | ||
74335ceb YR |
42 | /* The single instance of config transaction allowed at any time */ |
43 | struct mgmt_txns_head txn_list; | |
44 | ||
45 | /* Map of Transactions and its ID */ | |
46 | struct hash *txn_hash; | |
47 | uint64_t next_txn_id; | |
48 | ||
49 | /* The single instance of config transaction allowed at any time */ | |
50 | struct mgmt_txn_ctx *cfg_txn; | |
51 | ||
1c84efe4 CH |
52 | /* Datastores */ |
53 | struct mgmt_ds_ctx *running_ds; | |
54 | struct mgmt_ds_ctx *candidate_ds; | |
55 | struct mgmt_ds_ctx *oper_ds; | |
56 | ||
57 | bool terminating; /* global flag that sigint terminate seen */ | |
58 | bool perf_stats_en; /* to enable performance stats measurement */ | |
74335ceb YR |
59 | |
60 | /* List of commit infos */ | |
61 | struct mgmt_cmt_infos_head cmts; /* List of last 10 commits executed. */ | |
1c84efe4 CH |
62 | }; |
63 | ||
64 | extern struct mgmt_master *mm; | |
8033bf39 CH |
65 | extern char const *const mgmt_daemons[]; |
66 | extern uint mgmt_daemons_count; | |
1c84efe4 | 67 | |
ef43a632 CH |
68 | /* Inline functions */ |
69 | static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b) | |
70 | { | |
71 | return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO) | |
72 | + (a.tv_usec - b.tv_usec)); | |
73 | } | |
74 | ||
1c84efe4 CH |
75 | /* |
76 | * Remove trailing separator from a string. | |
77 | * | |
78 | * str | |
79 | * A null terminated string. | |
80 | * | |
81 | * sep | |
82 | * Trailing character that needs to be removed. | |
83 | */ | |
84 | static inline void mgmt_remove_trailing_separator(char *str, char sep) | |
85 | { | |
86 | size_t len; | |
87 | ||
88 | len = strlen(str); | |
89 | if (len && str[len - 1] == sep) | |
90 | str[len - 1] = '\0'; | |
91 | } | |
92 | ||
93 | /* Prototypes. */ | |
94 | extern void mgmt_terminate(void); | |
95 | extern void mgmt_reset(void); | |
96 | extern time_t mgmt_clock(void); | |
97 | ||
98 | extern int mgmt_config_write(struct vty *vty); | |
99 | ||
cd9d0537 | 100 | extern void mgmt_master_init(struct event_loop *master, const int buffer_size); |
1c84efe4 CH |
101 | |
102 | extern void mgmt_init(void); | |
103 | extern void mgmt_vty_init(void); | |
104 | ||
105 | static inline char *mgmt_realtime_to_string(struct timeval *tv, char *buf, | |
106 | size_t sz) | |
107 | { | |
74335ceb YR |
108 | struct tm tm; |
109 | size_t n; | |
1c84efe4 | 110 | |
74335ceb YR |
111 | localtime_r((const time_t *)&tv->tv_sec, &tm); |
112 | n = strftime(buf, sz, "%Y-%m-%dT%H:%M:%S", &tm); | |
113 | snprintf(&buf[n], sz - n, ",%06u000", (unsigned int)tv->tv_usec); | |
1c84efe4 CH |
114 | return buf; |
115 | } | |
116 | ||
117 | #endif /* _FRR_MGMTD_H */ |