]>
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_
40 * Example Counter group with sub-groups and counters
53 * counters_group_events {
61 * To create the above structure of groups, sub-groups, and counters, do the
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);
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");
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");
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");
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);
89 #define MAX_COUNTER_STR_LENGTH 128
90 #define MAX_COUNTER_GROUPS 500
91 #define MAX_COUNTERS 500
95 char counter_name
[MAX_COUNTER_STR_LENGTH
];
96 uint32_t counter_value
;
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
;
109 struct counters_group
{
110 char counters_group_name
[MAX_COUNTER_STR_LENGTH
];
111 uint16_t num_subgroups
;
112 uint16_t max_subgroups
;
114 /* Array of (struct counters_subgroup *) allocated when the group is
115 * created. The subgroup is indexed by the (struct counters_subgroup
117 struct counters_subgroup
**subgroups
;
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.
126 struct counters_group
*create_counters_group(const char *group_name
,
127 uint16_t max_subgroups
);
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.
136 struct counters_subgroup
*create_counters_subgroup(const char *subgroup_name
,
137 uint16_t subgroup_id
,
138 uint16_t max_counters
);
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.
144 bool add_counters_subgroup(struct counters_group
*group
,
145 struct counters_subgroup
*subgroup
);
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.
152 struct counters_subgroup
*
153 clone_counters_subgroup(struct counters_subgroup
*subgroup
,
154 const char *subgroup_name
, uint16_t subgroup_id
);
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.
162 bool create_subgroup_counter(struct counters_subgroup
*subgroup
,
163 uint32_t counter_id
, const char *counter_name
);
166 * Delete the counters_group and recursively delete all subgroups and their
167 * counters. Return true on success or false if group is NULL.
169 bool delete_counters_group(struct counters_group
*group
);
172 * Delete the counters_subgroup and all its counters counters.
173 * Return true on success or false if subgroup is NULL.
175 bool delete_counters_subgroup(struct counters_subgroup
*subgroup
);
178 * Reset all the counters in all sub-groups contained in this group.
179 * Return true on success or false if group is NULL.
181 bool reset_group_counters(struct counters_group
*group
);
184 * Reset all the counters in this subgroup.
185 * Return true on success or false if subgroup is NULL.
187 bool reset_subgroup_counters(struct counters_subgroup
*subgroup
);
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.
194 bool increment_counter(struct counters_group
*group
, uint16_t subgroup_id
,
195 uint16_t counter_id
);
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 >=
202 bool increment_subgroup_counter(struct counters_subgroup
*subgroup
,
203 uint16_t counter_id
);
206 * Dump the counter_group info and all its counter_subgroups.
207 * Return true on success or false if group is NULL.
209 bool dump_counters_group_to_log(struct counters_group
*group
);
212 * Dump all the counters in a counter_subgroup.
213 * Return true on success or false if subgroup is NULL.
215 bool dump_counters_subgroup_to_log(struct counters_subgroup
*subgroup
);
218 * Search for a counters_subgroup by subgroup_id in a counters_group
219 * and return it, if found, else return NULL.
221 struct counters_subgroup
*find_subgroup(const struct counters_group
*group
,
222 uint16_t subgroup_id
);
225 * Given a counters_subgroup, return the sum of all the counters.
227 uint32_t subgroup_counters_total(struct counters_subgroup
*subgroup
);
233 #endif /* PCEP_UTILS_INCLUDE_PCEP_UTILS_COUNTERS_H_ */