]>
git.proxmox.com Git - mirror_frr.git/blob - pceplib/pcep_utils_counters.h
2 * This file is part of the PCEPlib, a PCEP protocol library.
4 * Copyright (C) 2020 Volta Networks https://voltanet.io/
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.
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.
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/>.
19 * Author : Brady Johnson <brady@voltanet.io>
25 * Definitions of PCEP Counters.
28 #ifndef PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_
29 #define PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_
39 * Example Counter group with sub-groups and counters
52 * counters_group_events {
60 * To create the above structure of groups, sub-groups, and counters, do the
63 * struct counters_subgroup *rx_subgroup = create_counters_subgroup("rx
64 * counters", 3); struct counters_subgroup *tx_subgroup =
65 * create_counters_subgroup("tx counters", 3); struct counters_subgroup
66 * *events_subgroup = create_counters_subgroup("events counters", 4);
68 * Use message_id: PCEP_TYPE_OPEN=1
69 * create_subgroup_counter(rx_subgroup, 1, "Message Open");
70 * create_subgroup_counter(rx_subgroup, 2, "Message KeepAlive");
71 * create_subgroup_counter(rx_subgroup, 3, "Message PcReq");
73 * create_subgroup_counter(tx_subgroup, 1, "Message Open");
74 * create_subgroup_counter(tx_subgroup, 2, "Message KeepAlive");
75 * create_subgroup_counter(tx_subgroup, 3, "Message PcReq");
77 * create_subgroup_counter(events_subgroup, 1, "PCC Connect");
78 * create_subgroup_counter(events_subgroup, 2, "PCE Connect");
79 * create_subgroup_counter(events_subgroup, 3, "PCC Disconnect");
80 * create_subgroup_counter(events_subgroup, 4, "PCE Disconnect");
82 * struct counters_group *cntrs_group = create_counters_group("PCEP Counters",
83 * 3); add_counters_subgroup(cntrs_group, rx_subgroup);
84 * add_counters_subgroup(cntrs_group, tx_subgroup);
85 * add_counters_subgroup(cntrs_group, events_subgroup);
88 #define MAX_COUNTER_STR_LENGTH 128
89 #define MAX_COUNTER_GROUPS 500
90 #define MAX_COUNTERS 500
94 char counter_name
[MAX_COUNTER_STR_LENGTH
];
95 uint32_t counter_value
;
98 struct counters_subgroup
{
99 char counters_subgroup_name
[MAX_COUNTER_STR_LENGTH
];
100 uint16_t subgroup_id
;
101 uint16_t num_counters
;
102 uint16_t max_counters
;
103 /* Array of (struct counter *) allocated when the subgroup is created.
104 * The array is indexed by the struct counter->counter_id */
105 struct counter
**counters
;
108 struct counters_group
{
109 char counters_group_name
[MAX_COUNTER_STR_LENGTH
];
110 uint16_t num_subgroups
;
111 uint16_t max_subgroups
;
113 /* Array of (struct counters_subgroup *) allocated when the group is
114 * created. The subgroup is indexed by the (struct counters_subgroup
116 struct counters_subgroup
**subgroups
;
120 * Create a counters group with the given group_name and number of subgroups.
121 * Subgroup_ids are 0-based, so take that into account when setting
122 * max_subgroups. Return true on success or false if group_name is NULL or
123 * max_subgroups >= MAX_COUNTER_GROUPS.
125 struct counters_group
*create_counters_group(const char *group_name
,
126 uint16_t max_subgroups
);
129 * Create a counters subgroup with the given subgroup_name, subgroup_id and
130 * number of counters. The subgroup_id is 0-based. counter_ids are 0-based, so
131 * take that into account when setting max_counters. Return true on success or
132 * false if subgroup_name is NULL, subgroup_id >= MAX_COUNTER_GROUPS, or
133 * max_counters >= MAX_COUNTERS.
135 struct counters_subgroup
*create_counters_subgroup(const char *subgroup_name
,
136 uint16_t subgroup_id
,
137 uint16_t max_counters
);
140 * Add a counter_subgroup to a counter_group.
141 * Return true on success or false if group is NULL or if subgroup is NULL.
143 bool add_counters_subgroup(struct counters_group
*group
,
144 struct counters_subgroup
*subgroup
);
147 * Clone a subgroup and set a new name and subgroup_id for the new subgroup.
148 * This is useful for RX and TX counters: just create the RX counters and clone
149 * it for the TX counters.
151 struct counters_subgroup
*
152 clone_counters_subgroup(struct counters_subgroup
*subgroup
,
153 const char *subgroup_name
, uint16_t subgroup_id
);
156 * Create a counter in a subgroup with the given counter_id and counter_name.
157 * The counter_id is 0-based.
158 * Return true on success or false if subgroup is NULL, counter_id >=
159 * MAX_COUNTERS, or if counter_name is NULL.
161 bool create_subgroup_counter(struct counters_subgroup
*subgroup
,
162 uint32_t counter_id
, const char *counter_name
);
165 * Delete the counters_group and recursively delete all subgroups and their
166 * counters. Return true on success or false if group is NULL.
168 bool delete_counters_group(struct counters_group
*group
);
171 * Delete the counters_subgroup and all its counters counters.
172 * Return true on success or false if subgroup is NULL.
174 bool delete_counters_subgroup(struct counters_subgroup
*subgroup
);
177 * Reset all the counters in all sub-groups contained in this group.
178 * Return true on success or false if group is NULL.
180 bool reset_group_counters(struct counters_group
*group
);
183 * Reset all the counters in this subgroup.
184 * Return true on success or false if subgroup is NULL.
186 bool reset_subgroup_counters(struct counters_subgroup
*subgroup
);
189 * Increment a counter given a counter_group, subgroup_id, and counter_id.
190 * Return true on success or false if group is NULL, subgroup_id >=
191 * MAX_COUNTER_GROUPS, or counter_id >= MAX_COUNTERS.
193 bool increment_counter(struct counters_group
*group
, uint16_t subgroup_id
,
194 uint16_t counter_id
);
197 * Increment a counter given the counter_subgroup and counter_id.
198 * Return true on success or false if subgroup is NULL or counter_id >=
201 bool increment_subgroup_counter(struct counters_subgroup
*subgroup
,
202 uint16_t counter_id
);
205 * Dump the counter_group info and all its counter_subgroups.
206 * Return true on success or false if group is NULL.
208 bool dump_counters_group_to_log(struct counters_group
*group
);
211 * Dump all the counters in a counter_subgroup.
212 * Return true on success or false if subgroup is NULL.
214 bool dump_counters_subgroup_to_log(struct counters_subgroup
*subgroup
);
217 * Search for a counters_subgroup by subgroup_id in a counters_group
218 * and return it, if found, else return NULL.
220 struct counters_subgroup
*find_subgroup(const struct counters_group
*group
,
221 uint16_t subgroup_id
);
224 * Given a counters_subgroup, return the sum of all the counters.
226 uint32_t subgroup_counters_total(struct counters_subgroup
*subgroup
);
232 #endif /* PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_ */