Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
stats_tree.h
Go to the documentation of this file.
1
11#pragma once
12#include <epan/epan.h>
13#include <epan/packet_info.h>
14#include <epan/tap.h>
15#include <epan/stat_groups.h>
16#include "ws_symbol_export.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif /* __cplusplus */
21
22#define STAT_TREE_ROOT "root"
23#define STATS_TREE_MENU_SEPARATOR "//"
24
25/* stats_tree specific flags. When registering, these are used together
26 * with the TL_ flags defined in tap.h, so make sure they don't overlap!
27 * (Yes, that applies even to the flags that apply to nodes instead of
28 * the entire tree, and should not be passed in stats_tree_register.
29 * XXX - Why? These flags should be reworked at some point.)
30 */
31
32/* Flags on child nodes for internal use only */
33#define ST_FLG_AVERAGE 0x10000000 /* Calculate averages for nodes, rather than totals */
34#define ST_FLG_ROOTCHILD 0x20000000 /* This node is a direct child of the root node */
35
36/* Flags set on child nodes via stat_node_set_flags */
37#define ST_FLG_DEF_NOEXPAND 0x01000000 /* This node should not be expanded by default */
38#define ST_FLG_SORT_TOP 0x00400000 /* When sorting always keep these lines on of list */
39
40/* Flags for the entire stat_tree, set via stats_tree_register[_plugin] */
41#define ST_FLG_SORT_DESC 0x00800000 /* When sorting, sort descending instead of ascending */
42#define ST_FLG_SRTCOL_MASK 0x000F0000 /* Mask for sort column ID */
43#define ST_FLG_SRTCOL_SHIFT 16 /* Number of bits to shift masked result */
44
45#define ST_FLG_MASK (ST_FLG_AVERAGE|ST_FLG_ROOTCHILD|ST_FLG_DEF_NOEXPAND| \
46 ST_FLG_SORT_TOP|ST_FLG_SORT_DESC|ST_FLG_SRTCOL_MASK)
47
48#define ST_SORT_COL_NAME 1 /* Sort nodes by node names */
49#define ST_SORT_COL_COUNT 2 /* Sort nodes by node count */
50#define ST_SORT_COL_AVG 3 /* Sort nodes by node average */
51#define ST_SORT_COL_MIN 4 /* Sort nodes by minimum node value */
52#define ST_SORT_COL_MAX 5 /* Sort nodes by maximum node value */
53#define ST_SORT_COL_BURSTRATE 6 /* Sort nodes by burst rate */
54
55/* obscure information regarding the stats_tree */
56typedef struct _stats_tree stats_tree;
57
58/* tap packet callback for stats_tree */
59typedef tap_packet_status (*stat_tree_packet_cb)(stats_tree*,
62 const void *,
63 tap_flags_t flags);
64
65/* stats_tree initialization callback */
66typedef void (*stat_tree_init_cb)(stats_tree *);
67
68/* stats_tree cleanup callback */
69typedef void (*stat_tree_cleanup_cb)(stats_tree *);
70
71typedef enum _stat_node_datatype {
72 STAT_DT_INT,
73 STAT_DT_FLOAT
74} stat_node_datatype;
75
76typedef struct _stats_tree_cfg stats_tree_cfg;
77
80extern void stats_tree_init(void);
81
92WS_DLL_PUBLIC stats_tree_cfg *stats_tree_register(const char *tapname,
93 const char *abbr,
94 const char *path,
95 unsigned flags,
96 stat_tree_packet_cb packet,
97 stat_tree_init_cb init,
98 stat_tree_cleanup_cb cleanup);
99
110WS_DLL_PUBLIC stats_tree_cfg *stats_tree_register_plugin(const char *tapname,
111 const char *abbr,
112 const char *path,
113 unsigned flags,
114 stat_tree_packet_cb packet,
115 stat_tree_init_cb init,
116 stat_tree_cleanup_cb cleanup);
117
122WS_DLL_PUBLIC void stats_tree_set_group(stats_tree_cfg *st_config, register_stat_group_t stat_group);
123
129WS_DLL_PUBLIC void stats_tree_set_first_column_name(stats_tree_cfg *st_config, const char *column_name);
130
131
139WS_DLL_PUBLIC int stats_tree_parent_id_by_name(stats_tree *st, const char *parent_name);
140
141/* Creates a node in the tree (to be used in the in init_cb)
142 * st: the stats_tree in which to create it
143 * name: the name of the new node
144 * parent_name: the name of the parent_node (NULL for root)
145 * datatype: datatype used for the value of the node
146 * with_children: true if this node will have "dynamically created" children
147 */
148WS_DLL_PUBLIC int stats_tree_create_node(stats_tree *st,
149 const char *name,
150 int parent_id,
151 stat_node_datatype datatype,
152 bool with_children);
153
154/* creates a node using its parent's tree name */
162WS_DLL_PUBLIC int stats_tree_create_node_by_pname(stats_tree *st,
163 const char *name,
164 const char *parent_name,
165 stat_node_datatype datatype,
166 bool with_children);
167
181WS_DLL_PUBLIC int stats_tree_create_range_node(stats_tree *st,
182 const char *name,
183 int parent_id,
184 ...);
185
197 const char *name,
198 int parent_id,
199 int num_str_ranges,
200 char** str_ranges);
201
210WS_DLL_PUBLIC int stats_tree_range_node_with_pname(stats_tree *st,
211 const char *name,
212 const char *parent_name,
213 ...);
214
215/* increases by one the ranged node and the sub node to whose range the value belongs */
225WS_DLL_PUBLIC int stats_tree_tick_range(stats_tree *st,
226 const char *name,
227 int parent_id,
228 int value_in_range);
229
230#define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
231 stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range)))
232
241WS_DLL_PUBLIC int stats_tree_create_pivot(stats_tree *st,
242 const char *name,
243 int parent_id);
244
253WS_DLL_PUBLIC int stats_tree_create_pivot_by_pname(stats_tree *st,
254 const char *name,
255 const char *parent_name);
256
267WS_DLL_PUBLIC int stats_tree_tick_pivot(stats_tree *st,
268 int pivot_id,
269 const char *pivot_value);
270
276extern void stats_tree_cleanup(void);
277
278
279/*
280 * manipulates the value of the node whose name is given
281 * if the node does not exist yet it's created (with counter=1)
282 * using parent_name as parent node (NULL for root).
283 * with_children=true to indicate that the created node will be a parent
284 */
285typedef enum _manip_node_mode {
286 MN_INCREASE,
287 MN_SET,
288 MN_AVERAGE,
289 MN_AVERAGE_NOTICK,
290 MN_SET_FLAGS,
291 MN_CLEAR_FLAGS
292} manip_node_mode;
293
305WS_DLL_PUBLIC int stats_tree_manip_node_int(manip_node_mode mode,
306 stats_tree *st,
307 const char *name,
308 int parent_id,
309 bool with_children,
310 int value);
311
323WS_DLL_PUBLIC int stats_tree_manip_node_float(manip_node_mode mode,
324 stats_tree *st,
325 const char *name,
326 int parent_id,
327 bool with_children,
328 float value);
329
330#define increase_stat_node(st,name,parent_id,with_children,value) \
331 (stats_tree_manip_node_int(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))
332
333#define tick_stat_node(st,name,parent_id,with_children) \
334 (stats_tree_manip_node_int(MN_INCREASE,(st),(name),(parent_id),(with_children),1))
335
336#define set_stat_node(st,name,parent_id,with_children,value) \
337 (stats_tree_manip_node_int(MN_SET,(st),(name),(parent_id),(with_children),value))
338
339#define zero_stat_node(st,name,parent_id,with_children) \
340 (stats_tree_manip_node_int(MN_SET,(st),(name),(parent_id),(with_children),0))
341
342/*
343 * Add value to average calculation WITHOUT ticking node. Node MUST be ticked separately!
344 *
345 * Intention is to allow code to separately tick node (backward compatibility for plugin)
346 * and set value to use for averages. Older versions without average support will then at
347 * least show a count instead of 0.
348 */
349#define avg_stat_node_add_value_notick(st,name,parent_id,with_children,value) \
350 (stats_tree_manip_node_int(MN_AVERAGE_NOTICK,(st),(name),(parent_id),(with_children),value))
351
352/* Tick node and add a new value to the average calculation for this stats node. */
353#define avg_stat_node_add_value_int(st,name,parent_id,with_children,value) \
354 (stats_tree_manip_node_int(MN_AVERAGE,(st),(name),(parent_id),(with_children),value))
355
356#define avg_stat_node_add_value_float(st,name,parent_id,with_children,value) \
357 (stats_tree_manip_node_float(MN_AVERAGE,(st),(name),(parent_id),(with_children),value))
358
359/* Set flags for this node. Node created if it does not yet exist. */
360#define stat_node_set_flags(st,name,parent_id,with_children,flags) \
361 (stats_tree_manip_node_int(MN_SET_FLAGS,(st),(name),(parent_id),(with_children),flags))
362
363/* Clear flags for this node. Node created if it does not yet exist. */
364#define stat_node_clear_flags(st,name,parent_id,with_children,flags) \
365 (stats_tree_manip_node_int(MN_CLEAR_FLAGS,(st),(name),(parent_id),(with_children),flags))
366
367#ifdef __cplusplus
368}
369#endif /* __cplusplus */
370
371/*
372 * Editor modelines - https://www.wireshark.org/tools/modelines.html
373 *
374 * Local variables:
375 * c-basic-offset: 4
376 * tab-width: 8
377 * indent-tabs-mode: nil
378 * End:
379 *
380 * vi: set shiftwidth=4 tabstop=8 expandtab:
381 * :indentSize=4:tabSize=8:noTabs=true:
382 */
enum register_stat_group_e register_stat_group_t
WS_DLL_PUBLIC void stats_tree_set_first_column_name(stats_tree_cfg *st_config, const char *column_name)
Definition stats_tree.c:352
WS_DLL_PUBLIC int stats_tree_range_node_with_pname(stats_tree *st, const char *name, const char *parent_name,...)
Increases by one the ranged node and the sub node to whose range the value belongs.
Definition stats_tree.c:925
void stats_tree_init(void)
Definition stats_tree.c:284
WS_DLL_PUBLIC int stats_tree_create_pivot_by_pname(stats_tree *st, const char *name, const char *parent_name)
Creates a pivot node in the statistics tree by name.
Definition stats_tree.c:1014
WS_DLL_PUBLIC int stats_tree_parent_id_by_name(stats_tree *st, const char *parent_name)
Retrieves the parent ID of a node in the stats tree by its name.
Definition stats_tree.c:913
WS_DLL_PUBLIC void stats_tree_set_group(stats_tree_cfg *st_config, register_stat_group_t stat_group)
Definition stats_tree.c:345
WS_DLL_PUBLIC int stats_tree_create_node_by_pname(stats_tree *st, const char *name, const char *parent_name, stat_node_datatype datatype, bool with_children)
Creates a node in the statistics tree.
Definition stats_tree.c:583
WS_DLL_PUBLIC int stats_tree_create_range_node(stats_tree *st, const char *name, int parent_id,...)
Creates a node in the stats tree that will contain a ranges list.
Definition stats_tree.c:872
void stats_tree_cleanup(void)
Cleans up the statistics tree registry.
Definition stats_tree.c:1523
WS_DLL_PUBLIC int stats_tree_manip_node_float(manip_node_mode mode, stats_tree *st, const char *name, int parent_id, bool with_children, float value)
Manipulates a node in the statistics tree with a float value.
Definition stats_tree.c:745
WS_DLL_PUBLIC int stats_tree_tick_pivot(stats_tree *st, int pivot_id, const char *pivot_value)
Ticks a pivot node in the statistics tree.
Definition stats_tree.c:1029
WS_DLL_PUBLIC stats_tree_cfg * stats_tree_register(const char *tapname, const char *abbr, const char *path, unsigned flags, stat_tree_packet_cb packet, stat_tree_init_cb init, stat_tree_cleanup_cb cleanup)
Definition stats_tree.c:291
WS_DLL_PUBLIC int stats_tree_create_range_node_string(stats_tree *st, const char *name, int parent_id, int num_str_ranges, char **str_ranges)
Creates a range node in the statistics tree with string ranges.
Definition stats_tree.c:890
WS_DLL_PUBLIC int stats_tree_tick_range(stats_tree *st, const char *name, int parent_id, int value_in_range)
Increment a statistic in a stats tree within a specified range.
Definition stats_tree.c:946
WS_DLL_PUBLIC int stats_tree_manip_node_int(manip_node_mode mode, stats_tree *st, const char *name, int parent_id, bool with_children, int value)
Manipulates a node in a statistics tree by increasing its integer value.
Definition stats_tree.c:683
WS_DLL_PUBLIC int stats_tree_create_pivot(stats_tree *st, const char *name, int parent_id)
Creates a new pivot node in the statistics tree.
Definition stats_tree.c:1003
WS_DLL_PUBLIC stats_tree_cfg * stats_tree_register_plugin(const char *tapname, const char *abbr, const char *path, unsigned flags, stat_tree_packet_cb packet, stat_tree_init_cb init, stat_tree_cleanup_cb cleanup)
Definition stats_tree.c:332
Definition packet_info.h:40
Definition stats_tree_priv.h:142
unsigned flags
Definition stats_tree_priv.h:158
stat_tree_packet_cb packet
Definition stats_tree_priv.h:153
Definition stats_tree_priv.h:108
Definition packet-epl-profile-parser.c:79
Definition epan_dissect.h:25
tap_packet_status
Definition tap.h:22