2 * A counter tree API for Wireshark dissectors
3 * 2005, Luis E. G. Ontanon
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __STATS_TREE_H
24 #define __STATS_TREE_H
27 #include <epan/epan.h>
28 #include <epan/packet_info.h>
30 #include <epan/stat_groups.h>
31 #include "../register.h"
32 #include "ws_symbol_export.h"
34 #define STAT_TREE_ROOT "root"
36 #define ST_FLG_AVERAGE 0x10000000 /* Calculate overages for nodes, rather than totals */
37 #define ST_FLG_ROOTCHILD 0x20000000 /* This node is a direct child of the root node */
38 #define ST_FLG_DEF_NOEXPAND 0x01000000 /* This node should not be expanded by default */
39 #define ST_FLG_SORT_DESC 0x00800000 /* When sorting, sort ascending instead of decending */
40 #define ST_FLG_SORT_TOP 0x00400000 /* When sorting always keep these lines on of list */
41 #define ST_FLG_SRTCOL_MASK 0x000F0000 /* Mask for sort column ID */
42 #define ST_FLG_SRTCOL_SHIFT 16 /* Number of bits to shift masked result */
44 #define ST_FLG_MASK (ST_FLG_AVERAGE|ST_FLG_ROOTCHILD|ST_FLG_DEF_NOEXPAND| \
45 ST_FLG_SORT_TOP|ST_FLG_SORT_DESC|ST_FLG_SRTCOL_MASK)
47 #define ST_SORT_COL_NAME 1 /* Sort nodes by node names */
48 #define ST_SORT_COL_COUNT 2 /* Sort nodes by node count */
49 #define ST_SORT_COL_AVG 3 /* Sort nodes by node average */
50 #define ST_SORT_COL_MIN 4 /* Sort nodes by minimum node value */
51 #define ST_SORT_COL_MAX 5 /* Sort nodes by maximum node value */
52 #define ST_SORT_COL_BURSTRATE 6 /* Sort nodes by burst rate */
54 /* obscure information regarding the stats_tree */
55 typedef struct _stats_tree stats_tree;
57 /* tap packet callback for stats_tree */
58 typedef int (*stat_tree_packet_cb)(stats_tree*,
63 /* stats_tree initialization callback */
64 typedef void (*stat_tree_init_cb)(stats_tree *);
66 /* stats_tree cleanup callback */
67 typedef void (*stat_tree_cleanup_cb)(stats_tree *);
69 /* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED
71 * name: protocol display name
72 * flags: tap listener flags for per-packet callback
73 * packet: per packet callback
74 * init: tree initialization callback
75 * cleanup: cleanup callback
77 WS_DLL_PUBLIC void stats_tree_register(const gchar *tapname,
81 stat_tree_packet_cb packet,
82 stat_tree_init_cb init,
83 stat_tree_cleanup_cb cleanup);
85 /* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED from a plugin
87 * name: protocol display name
88 * flags: tap listener flags for per-packet callback
89 * packet: per packet callback
90 * init: tree initialization callback
91 * cleanup: cleanup callback
93 WS_DLL_PUBLIC void stats_tree_register_plugin(const gchar *tapname,
97 stat_tree_packet_cb packet,
98 stat_tree_init_cb init,
99 stat_tree_cleanup_cb cleanup);
101 /* registers a new stats tree
102 * abbr: protocol abbr
103 * name: protocol display name
104 * flags: tap listener flags for per-packet callback
105 * packet: per packet callback
106 * init: tree initialization callback
107 * cleanup: cleanup callback
108 * stat_group: the group this stat belongs to
110 WS_DLL_PUBLIC void stats_tree_register_with_group(const gchar *tapname,
114 stat_tree_packet_cb packet,
115 stat_tree_init_cb init,
116 stat_tree_cleanup_cb cleanup,
117 register_stat_group_t stat_group);
119 WS_DLL_PUBLIC int stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name);
121 /* Creates a node in the tree (to be used in the in init_cb)
122 * st: the stats_tree in which to create it
123 * name: the name of the new node
124 * parent_name: the name of the parent_node (NULL for root)
125 * with_children: TRUE if this node will have "dynamically created" children
127 WS_DLL_PUBLIC int stats_tree_create_node(stats_tree *st,
130 gboolean with_children);
132 /* creates a node using its parent's tree name */
133 WS_DLL_PUBLIC int stats_tree_create_node_by_pname(stats_tree *st,
135 const gchar *parent_name,
136 gboolean with_children);
138 /* creates a node in the tree, that will contain a ranges list.
140 stats_tree_create_range_node(st,name,parent,
141 "-99","100-199","200-299","300-399","400-", NULL);
143 WS_DLL_PUBLIC int stats_tree_create_range_node(stats_tree *st,
148 WS_DLL_PUBLIC int stats_tree_create_range_node_string(stats_tree *st,
154 WS_DLL_PUBLIC int stats_tree_range_node_with_pname(stats_tree *st,
156 const gchar *parent_name,
159 /* increases by one the ranged node and the sub node to whose range the value belongs */
160 WS_DLL_PUBLIC int stats_tree_tick_range(stats_tree *st,
165 #define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
166 stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range))
169 WS_DLL_PUBLIC int stats_tree_create_pivot(stats_tree *st,
173 WS_DLL_PUBLIC int stats_tree_create_pivot_by_pname(stats_tree *st,
175 const gchar *parent_name);
177 WS_DLL_PUBLIC int stats_tree_tick_pivot(stats_tree *st,
179 const gchar *pivot_value);
182 * manipulates the value of the node whose name is given
183 * if the node does not exist yet it's created (with counter=1)
184 * using parent_name as parent node (NULL for root).
185 * with_children=TRUE to indicate that the created node will be a parent
187 typedef enum _manip_node_mode {
195 WS_DLL_PUBLIC int stats_tree_manip_node(manip_node_mode mode,
199 gboolean with_children,
202 #define increase_stat_node(st,name,parent_id,with_children,value) \
203 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))
205 #define tick_stat_node(st,name,parent_id,with_children) \
206 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),1))
208 #define set_stat_node(st,name,parent_id,with_children,value) \
209 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),value))
211 #define zero_stat_node(st,name,parent_id,with_children) \
212 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),0))
215 * Add value to average calculation WITHOUT ticking node. Node MUST be ticked separately!
217 * Intention is to allow code to separately tick node (backward compatibility for plugin)
218 * and set value to use for averages. Older versions without average support will then at
219 * least show a count instead of 0.
221 #define avg_stat_node_add_value_notick(st,name,parent_id,with_children,value) \
222 (stats_tree_manip_node(MN_AVERAGE_NOTICK,(st),(name),(parent_id),(with_children),value))
224 /* Tick node and add a new value to the average calculation for this stats node. */
225 #define avg_stat_node_add_value(st,name,parent_id,with_children,value) \
226 (stats_tree_manip_node(MN_AVERAGE,(st),(name),(parent_id),(with_children),value))
228 /* Set flags for this node. Node created if it does not yet exist. */
229 #define stat_node_set_flags(st,name,parent_id,with_children,flags) \
230 (stats_tree_manip_node(MN_SET_FLAGS,(st),(name),(parent_id),(with_children),flags))
232 /* Clear flags for this node. Node created if it does not yet exist. */
233 #define stat_node_clear_flags(st,name,parent_id,with_children,flags) \
234 (stats_tree_manip_node(MN_CLEAR_FLAGS,(st),(name),(parent_id),(with_children),flags))
237 * Editor modelines - http://www.wireshark.org/tools/modelines.html
242 * indent-tabs-mode: nil
245 * vi: set shiftwidth=4 tabstop=8 expandtab:
246 * :indentSize=4:tabSize=8:noTabs=true:
249 #endif /* __STATS_TREE_H */