]> git.proxmox.com Git - mirror_frr.git/blob - pceplib/pcep_utils_counters.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / pceplib / pcep_utils_counters.h
1 /*
2 * This file is part of the PCEPlib, a PCEP protocol library.
3 *
4 * Copyright (C) 2020 Volta Networks https://voltanet.io/
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Author : Brady Johnson <brady@voltanet.io>
20 *
21 */
22
23
24 /*
25 * Definitions of PCEP Counters.
26 */
27
28 #ifndef PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_
29 #define PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_
30
31 #include <stdbool.h>
32 #include <stdint.h>
33 #include <time.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /*
40 * Example Counter group with sub-groups and counters
41 *
42 * pcep_counters {
43 * counters_group_rx {
44 * message_open;
45 * message_keepalive;
46 * message_pcreq;
47 * }
48 * counters_group_tx {
49 * message_open;
50 * message_keepalive;
51 * message_pcreq;
52 * }
53 * counters_group_events {
54 * pcc_connect;
55 * pce_connect;
56 * pcc_disconnect;
57 * pce_disconnect;
58 * }
59 * }
60 *
61 * To create the above structure of groups, sub-groups, and counters, do the
62 * following:
63 *
64 * struct counters_subgroup *rx_subgroup = create_counters_subgroup("rx
65 * counters", 3); struct counters_subgroup *tx_subgroup =
66 * create_counters_subgroup("tx counters", 3); struct counters_subgroup
67 * *events_subgroup = create_counters_subgroup("events counters", 4);
68 *
69 * Use message_id: PCEP_TYPE_OPEN=1
70 * create_subgroup_counter(rx_subgroup, 1, "Message Open");
71 * create_subgroup_counter(rx_subgroup, 2, "Message KeepAlive");
72 * create_subgroup_counter(rx_subgroup, 3, "Message PcReq");
73 *
74 * create_subgroup_counter(tx_subgroup, 1, "Message Open");
75 * create_subgroup_counter(tx_subgroup, 2, "Message KeepAlive");
76 * create_subgroup_counter(tx_subgroup, 3, "Message PcReq");
77 *
78 * create_subgroup_counter(events_subgroup, 1, "PCC Connect");
79 * create_subgroup_counter(events_subgroup, 2, "PCE Connect");
80 * create_subgroup_counter(events_subgroup, 3, "PCC Disconnect");
81 * create_subgroup_counter(events_subgroup, 4, "PCE Disconnect");
82 *
83 * struct counters_group *cntrs_group = create_counters_group("PCEP Counters",
84 * 3); add_counters_subgroup(cntrs_group, rx_subgroup);
85 * add_counters_subgroup(cntrs_group, tx_subgroup);
86 * add_counters_subgroup(cntrs_group, events_subgroup);
87 */
88
89 #define MAX_COUNTER_STR_LENGTH 128
90 #define MAX_COUNTER_GROUPS 500
91 #define MAX_COUNTERS 500
92
93 struct counter {
94 uint16_t counter_id;
95 char counter_name[MAX_COUNTER_STR_LENGTH];
96 uint32_t counter_value;
97 };
98
99 struct counters_subgroup {
100 char counters_subgroup_name[MAX_COUNTER_STR_LENGTH];
101 uint16_t subgroup_id;
102 uint16_t num_counters;
103 uint16_t max_counters;
104 /* Array of (struct counter *) allocated when the subgroup is created.
105 * The array is indexed by the struct counter->counter_id */
106 struct counter **counters;
107 };
108
109 struct counters_group {
110 char counters_group_name[MAX_COUNTER_STR_LENGTH];
111 uint16_t num_subgroups;
112 uint16_t max_subgroups;
113 time_t start_time;
114 /* Array of (struct counters_subgroup *) allocated when the group is
115 * created. The subgroup is indexed by the (struct counters_subgroup
116 * *)->subgroup_id */
117 struct counters_subgroup **subgroups;
118 };
119
120 /*
121 * Create a counters group with the given group_name and number of subgroups.
122 * Subgroup_ids are 0-based, so take that into account when setting
123 * max_subgroups. Return true on success or false if group_name is NULL or
124 * max_subgroups >= MAX_COUNTER_GROUPS.
125 */
126 struct counters_group *create_counters_group(const char *group_name,
127 uint16_t max_subgroups);
128
129 /*
130 * Create a counters subgroup with the given subgroup_name, subgroup_id and
131 * number of counters. The subgroup_id is 0-based. counter_ids are 0-based, so
132 * take that into account when setting max_counters. Return true on success or
133 * false if subgroup_name is NULL, subgroup_id >= MAX_COUNTER_GROUPS, or
134 * max_counters >= MAX_COUNTERS.
135 */
136 struct counters_subgroup *create_counters_subgroup(const char *subgroup_name,
137 uint16_t subgroup_id,
138 uint16_t max_counters);
139
140 /*
141 * Add a counter_subgroup to a counter_group.
142 * Return true on success or false if group is NULL or if subgroup is NULL.
143 */
144 bool add_counters_subgroup(struct counters_group *group,
145 struct counters_subgroup *subgroup);
146
147 /*
148 * Clone a subgroup and set a new name and subgroup_id for the new subgroup.
149 * This is useful for RX and TX counters: just create the RX counters and clone
150 * it for the TX counters.
151 */
152 struct counters_subgroup *
153 clone_counters_subgroup(struct counters_subgroup *subgroup,
154 const char *subgroup_name, uint16_t subgroup_id);
155
156 /*
157 * Create a counter in a subgroup with the given counter_id and counter_name.
158 * The counter_id is 0-based.
159 * Return true on success or false if subgroup is NULL, counter_id >=
160 * MAX_COUNTERS, or if counter_name is NULL.
161 */
162 bool create_subgroup_counter(struct counters_subgroup *subgroup,
163 uint32_t counter_id, const char *counter_name);
164
165 /*
166 * Delete the counters_group and recursively delete all subgroups and their
167 * counters. Return true on success or false if group is NULL.
168 */
169 bool delete_counters_group(struct counters_group *group);
170
171 /*
172 * Delete the counters_subgroup and all its counters counters.
173 * Return true on success or false if subgroup is NULL.
174 */
175 bool delete_counters_subgroup(struct counters_subgroup *subgroup);
176
177 /*
178 * Reset all the counters in all sub-groups contained in this group.
179 * Return true on success or false if group is NULL.
180 */
181 bool reset_group_counters(struct counters_group *group);
182
183 /*
184 * Reset all the counters in this subgroup.
185 * Return true on success or false if subgroup is NULL.
186 */
187 bool reset_subgroup_counters(struct counters_subgroup *subgroup);
188
189 /*
190 * Increment a counter given a counter_group, subgroup_id, and counter_id.
191 * Return true on success or false if group is NULL, subgroup_id >=
192 * MAX_COUNTER_GROUPS, or counter_id >= MAX_COUNTERS.
193 */
194 bool increment_counter(struct counters_group *group, uint16_t subgroup_id,
195 uint16_t counter_id);
196
197 /*
198 * Increment a counter given the counter_subgroup and counter_id.
199 * Return true on success or false if subgroup is NULL or counter_id >=
200 * MAX_COUNTERS.
201 */
202 bool increment_subgroup_counter(struct counters_subgroup *subgroup,
203 uint16_t counter_id);
204
205 /*
206 * Dump the counter_group info and all its counter_subgroups.
207 * Return true on success or false if group is NULL.
208 */
209 bool dump_counters_group_to_log(struct counters_group *group);
210
211 /*
212 * Dump all the counters in a counter_subgroup.
213 * Return true on success or false if subgroup is NULL.
214 */
215 bool dump_counters_subgroup_to_log(struct counters_subgroup *subgroup);
216
217 /*
218 * Search for a counters_subgroup by subgroup_id in a counters_group
219 * and return it, if found, else return NULL.
220 */
221 struct counters_subgroup *find_subgroup(const struct counters_group *group,
222 uint16_t subgroup_id);
223
224 /*
225 * Given a counters_subgroup, return the sum of all the counters.
226 */
227 uint32_t subgroup_counters_total(struct counters_subgroup *subgroup);
228
229 #ifdef __cplusplus
230 }
231 #endif
232
233 #endif /* PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_ */