2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
32 #ifndef LWIP_HDR_STATS_H
33 #define LWIP_HDR_STATS_H
38 #include "lwip/memp.h"
46 #ifndef LWIP_STATS_LARGE
47 #define LWIP_STATS_LARGE 0
51 #define STAT_COUNTER u32_t
52 #define STAT_COUNTER_F U32_F
54 #define STAT_COUNTER u16_t
55 #define STAT_COUNTER_F U16_F
59 STAT_COUNTER xmit; /* Transmitted packets. */
60 STAT_COUNTER recv; /* Received packets. */
61 STAT_COUNTER fw; /* Forwarded packets. */
62 STAT_COUNTER drop; /* Dropped packets. */
63 STAT_COUNTER chkerr; /* Checksum error. */
64 STAT_COUNTER lenerr; /* Invalid length error. */
65 STAT_COUNTER memerr; /* Out of memory error. */
66 STAT_COUNTER rterr; /* Routing error. */
67 STAT_COUNTER proterr; /* Protocol error. */
68 STAT_COUNTER opterr; /* Error in options. */
69 STAT_COUNTER err; /* Misc error. */
70 STAT_COUNTER cachehit;
74 STAT_COUNTER xmit; /* Transmitted packets. */
75 STAT_COUNTER recv; /* Received packets. */
76 STAT_COUNTER drop; /* Dropped packets. */
77 STAT_COUNTER chkerr; /* Checksum error. */
78 STAT_COUNTER lenerr; /* Invalid length error. */
79 STAT_COUNTER memerr; /* Out of memory error. */
80 STAT_COUNTER proterr; /* Protocol error. */
81 STAT_COUNTER rx_v1; /* Received v1 frames. */
82 STAT_COUNTER rx_group; /* Received group-specific queries. */
83 STAT_COUNTER rx_general; /* Received general queries. */
84 STAT_COUNTER rx_report; /* Received reports. */
85 STAT_COUNTER tx_join; /* Sent joins. */
86 STAT_COUNTER tx_leave; /* Sent leaves. */
87 STAT_COUNTER tx_report; /* Sent reports. */
93 #endif /* LWIP_DEBUG */
101 struct stats_syselem {
108 struct stats_syselem sem;
109 struct stats_syselem mutex;
110 struct stats_syselem mbox;
116 u32_t ipinaddrerrors;
117 u32_t ipinunknownprotos;
129 u32_t ipforwdatagrams;
133 u32_t tcpactiveopens;
134 u32_t tcppassiveopens;
135 u32_t tcpattemptfails;
136 u32_t tcpestabresets;
138 u32_t tcpretranssegs;
144 u32_t udpindatagrams;
147 u32_t udpoutdatagrams;
152 u32_t icmpindestunreachs;
153 u32_t icmpintimeexcds;
154 u32_t icmpinparmprobs;
155 u32_t icmpinsrcquenchs;
156 u32_t icmpinredirects;
158 u32_t icmpinechoreps;
159 u32_t icmpintimestamps;
160 u32_t icmpintimestampreps;
161 u32_t icmpinaddrmasks;
162 u32_t icmpinaddrmaskreps;
165 u32_t icmpoutdestunreachs;
166 u32_t icmpouttimeexcds;
167 u32_t icmpoutechos; /* can be incremented by user application ('ping') */
168 u32_t icmpoutechoreps;
171 struct stats_mib2_netif_ctrs {
174 u32_t ifinnucastpkts;
177 u32_t ifinunknownprotos;
179 u32_t ifoutucastpkts;
180 u32_t ifoutnucastpkts;
187 struct stats_proto link;
190 struct stats_proto etharp;
193 struct stats_proto ip_frag;
196 struct stats_proto ip;
199 struct stats_proto icmp;
202 struct stats_igmp igmp;
205 struct stats_proto udp;
208 struct stats_proto tcp;
211 struct stats_mem mem;
214 struct stats_mem memp[MEMP_MAX];
217 struct stats_sys sys;
220 struct stats_proto ip6;
223 struct stats_proto icmp6;
226 struct stats_proto ip6_frag;
229 struct stats_igmp mld6;
232 struct stats_proto nd6;
235 struct stats_mib2 mib2;
239 extern struct stats_ lwip_stats;
241 void stats_init(void);
243 #define STATS_INC(x) ++lwip_stats.x
244 #define STATS_DEC(x) --lwip_stats.x
245 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
246 if (lwip_stats.x.max < lwip_stats.x.used) { \
247 lwip_stats.x.max = lwip_stats.x.used; \
250 #define STATS_GET(x) lwip_stats.x
251 #else /* LWIP_STATS */
255 #define STATS_INC_USED(x)
256 #endif /* LWIP_STATS */
259 #define TCP_STATS_INC(x) STATS_INC(x)
260 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
262 #define TCP_STATS_INC(x)
263 #define TCP_STATS_DISPLAY()
267 #define UDP_STATS_INC(x) STATS_INC(x)
268 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
270 #define UDP_STATS_INC(x)
271 #define UDP_STATS_DISPLAY()
275 #define ICMP_STATS_INC(x) STATS_INC(x)
276 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
278 #define ICMP_STATS_INC(x)
279 #define ICMP_STATS_DISPLAY()
283 #define IGMP_STATS_INC(x) STATS_INC(x)
284 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP")
286 #define IGMP_STATS_INC(x)
287 #define IGMP_STATS_DISPLAY()
291 #define IP_STATS_INC(x) STATS_INC(x)
292 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
294 #define IP_STATS_INC(x)
295 #define IP_STATS_DISPLAY()
299 #define IPFRAG_STATS_INC(x) STATS_INC(x)
300 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
302 #define IPFRAG_STATS_INC(x)
303 #define IPFRAG_STATS_DISPLAY()
307 #define ETHARP_STATS_INC(x) STATS_INC(x)
308 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
310 #define ETHARP_STATS_INC(x)
311 #define ETHARP_STATS_DISPLAY()
315 #define LINK_STATS_INC(x) STATS_INC(x)
316 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
318 #define LINK_STATS_INC(x)
319 #define LINK_STATS_DISPLAY()
323 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
324 #define MEM_STATS_INC(x) STATS_INC(mem.x)
325 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
326 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
327 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
329 #define MEM_STATS_AVAIL(x, y)
330 #define MEM_STATS_INC(x)
331 #define MEM_STATS_INC_USED(x, y)
332 #define MEM_STATS_DEC_USED(x, y)
333 #define MEM_STATS_DISPLAY()
337 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
338 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
339 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
340 #define MEMP_STATS_INC_USED(x, i) STATS_INC_USED(memp[i], 1)
341 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
343 #define MEMP_STATS_AVAIL(x, i, y)
344 #define MEMP_STATS_INC(x, i)
345 #define MEMP_STATS_DEC(x, i)
346 #define MEMP_STATS_INC_USED(x, i)
347 #define MEMP_STATS_DISPLAY(i)
351 #define SYS_STATS_INC(x) STATS_INC(sys.x)
352 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
353 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
354 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
356 #define SYS_STATS_INC(x)
357 #define SYS_STATS_DEC(x)
358 #define SYS_STATS_INC_USED(x)
359 #define SYS_STATS_DISPLAY()
363 #define IP6_STATS_INC(x) STATS_INC(x)
364 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6")
366 #define IP6_STATS_INC(x)
367 #define IP6_STATS_DISPLAY()
371 #define ICMP6_STATS_INC(x) STATS_INC(x)
372 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6")
374 #define ICMP6_STATS_INC(x)
375 #define ICMP6_STATS_DISPLAY()
379 #define IP6_FRAG_STATS_INC(x) STATS_INC(x)
380 #define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG")
382 #define IP6_FRAG_STATS_INC(x)
383 #define IP6_FRAG_STATS_DISPLAY()
387 #define MLD6_STATS_INC(x) STATS_INC(x)
388 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1")
390 #define MLD6_STATS_INC(x)
391 #define MLD6_STATS_DISPLAY()
395 #define ND6_STATS_INC(x) STATS_INC(x)
396 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND")
398 #define ND6_STATS_INC(x)
399 #define ND6_STATS_DISPLAY()
403 #define MIB2_STATS_INC(x) STATS_INC(x)
405 #define MIB2_STATS_INC(x)
408 /* Display of statistics */
409 #if LWIP_STATS_DISPLAY
410 void stats_display(void);
411 void stats_display_proto(struct stats_proto *proto, const char *name);
412 void stats_display_igmp(struct stats_igmp *igmp, const char *name);
413 void stats_display_mem(struct stats_mem *mem, const char *name);
414 void stats_display_memp(struct stats_mem *mem, int index);
415 void stats_display_sys(struct stats_sys *sys);
416 #else /* LWIP_STATS_DISPLAY */
417 #define stats_display()
418 #define stats_display_proto(proto, name)
419 #define stats_display_igmp(igmp, name)
420 #define stats_display_mem(mem, name)
421 #define stats_display_memp(mem, index)
422 #define stats_display_sys(sys)
423 #endif /* LWIP_STATS_DISPLAY */
429 #endif /* LWIP_HDR_STATS_H */