3 * Statistics API (to be used from TCPIP thread)
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * This file is part of the lwIP TCP/IP stack.
34 * Author: Adam Dunkels <adam@sics.se>
37 #ifndef LWIP_HDR_STATS_H
38 #define LWIP_HDR_STATS_H
43 #include "lwip/memp.h"
51 #ifndef LWIP_STATS_LARGE
52 #define LWIP_STATS_LARGE 0
56 #define STAT_COUNTER u32_t
57 #define STAT_COUNTER_F U32_F
59 #define STAT_COUNTER u16_t
60 #define STAT_COUNTER_F U16_F
63 /** Protocol related stats */
65 STAT_COUNTER xmit; /* Transmitted packets. */
66 STAT_COUNTER recv; /* Received packets. */
67 STAT_COUNTER fw; /* Forwarded packets. */
68 STAT_COUNTER drop; /* Dropped packets. */
69 STAT_COUNTER chkerr; /* Checksum error. */
70 STAT_COUNTER lenerr; /* Invalid length error. */
71 STAT_COUNTER memerr; /* Out of memory error. */
72 STAT_COUNTER rterr; /* Routing error. */
73 STAT_COUNTER proterr; /* Protocol error. */
74 STAT_COUNTER opterr; /* Error in options. */
75 STAT_COUNTER err; /* Misc error. */
76 STAT_COUNTER cachehit;
81 STAT_COUNTER xmit; /* Transmitted packets. */
82 STAT_COUNTER recv; /* Received packets. */
83 STAT_COUNTER drop; /* Dropped packets. */
84 STAT_COUNTER chkerr; /* Checksum error. */
85 STAT_COUNTER lenerr; /* Invalid length error. */
86 STAT_COUNTER memerr; /* Out of memory error. */
87 STAT_COUNTER proterr; /* Protocol error. */
88 STAT_COUNTER rx_v1; /* Received v1 frames. */
89 STAT_COUNTER rx_group; /* Received group-specific queries. */
90 STAT_COUNTER rx_general; /* Received general queries. */
91 STAT_COUNTER rx_report; /* Received reports. */
92 STAT_COUNTER tx_join; /* Sent joins. */
93 STAT_COUNTER tx_leave; /* Sent leaves. */
94 STAT_COUNTER tx_report; /* Sent reports. */
99 #if defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY
101 #endif /* defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY */
106 STAT_COUNTER illegal;
109 /** System element stats */
110 struct stats_syselem {
118 struct stats_syselem sem;
119 struct stats_syselem mutex;
120 struct stats_syselem mbox;
123 /** SNMP MIB2 stats */
127 u32_t ipinaddrerrors;
128 u32_t ipinunknownprotos;
140 u32_t ipforwdatagrams;
144 u32_t tcpactiveopens;
145 u32_t tcppassiveopens;
146 u32_t tcpattemptfails;
147 u32_t tcpestabresets;
149 u32_t tcpretranssegs;
155 u32_t udpindatagrams;
158 u32_t udpoutdatagrams;
163 u32_t icmpindestunreachs;
164 u32_t icmpintimeexcds;
165 u32_t icmpinparmprobs;
166 u32_t icmpinsrcquenchs;
167 u32_t icmpinredirects;
169 u32_t icmpinechoreps;
170 u32_t icmpintimestamps;
171 u32_t icmpintimestampreps;
172 u32_t icmpinaddrmasks;
173 u32_t icmpinaddrmaskreps;
176 u32_t icmpoutdestunreachs;
177 u32_t icmpouttimeexcds;
178 u32_t icmpoutechos; /* can be incremented by user application ('ping') */
179 u32_t icmpoutechoreps;
183 * @ingroup netif_mib2
184 * SNMP MIB2 interface stats
186 struct stats_mib2_netif_ctrs {
187 /** The total number of octets received on the interface, including framing characters */
189 /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were
190 * not addressed to a multicast or broadcast address at this sub-layer */
192 /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were
193 * addressed to a multicast or broadcast address at this sub-layer */
194 u32_t ifinnucastpkts;
195 /** The number of inbound packets which were chosen to be discarded even though no errors had
196 * been detected to prevent their being deliverable to a higher-layer protocol. One possible
197 * reason for discarding such a packet could be to free up buffer space */
199 /** For packet-oriented interfaces, the number of inbound packets that contained errors
200 * preventing them from being deliverable to a higher-layer protocol. For character-
201 * oriented or fixed-length interfaces, the number of inbound transmission units that
202 * contained errors preventing them from being deliverable to a higher-layer protocol. */
204 /** For packet-oriented interfaces, the number of packets received via the interface which
205 * were discarded because of an unknown or unsupported protocol. For character-oriented
206 * or fixed-length interfaces that support protocol multiplexing the number of transmission
207 * units received via the interface which were discarded because of an unknown or unsupported
208 * protocol. For any interface that does not support protocol multiplexing, this counter will
210 u32_t ifinunknownprotos;
211 /** The total number of octets transmitted out of the interface, including framing characters. */
213 /** The total number of packets that higher-level protocols requested be transmitted, and
214 * which were not addressed to a multicast or broadcast address at this sub-layer, including
215 * those that were discarded or not sent. */
216 u32_t ifoutucastpkts;
217 /** The total number of packets that higher-level protocols requested be transmitted, and which
218 * were addressed to a multicast or broadcast address at this sub-layer, including
219 * those that were discarded or not sent. */
220 u32_t ifoutnucastpkts;
221 /** The number of outbound packets which were chosen to be discarded even though no errors had
222 * been detected to prevent their being transmitted. One possible reason for discarding
223 * such a packet could be to free up buffer space. */
225 /** For packet-oriented interfaces, the number of outbound packets that could not be transmitted
226 * because of errors. For character-oriented or fixed-length interfaces, the number of outbound
227 * transmission units that could not be transmitted because of errors. */
231 /** lwIP stats container */
235 struct stats_proto link;
239 struct stats_proto etharp;
243 struct stats_proto ip_frag;
247 struct stats_proto ip;
251 struct stats_proto icmp;
255 struct stats_igmp igmp;
259 struct stats_proto udp;
263 struct stats_proto tcp;
267 struct stats_mem mem;
270 /** Internal memory pools */
271 struct stats_mem *memp[MEMP_MAX];
275 struct stats_sys sys;
279 struct stats_proto ip6;
283 struct stats_proto icmp6;
286 /** IPv6 fragmentation */
287 struct stats_proto ip6_frag;
290 /** Multicast listener discovery */
291 struct stats_igmp mld6;
294 /** Neighbor discovery */
295 struct stats_proto nd6;
299 struct stats_mib2 mib2;
303 /** Global variable containing lwIP internal statistics. Add this to your debugger's watchlist. */
304 extern struct stats_ lwip_stats;
306 /** Init statistics */
307 void stats_init(void);
309 #define STATS_INC(x) ++lwip_stats.x
310 #define STATS_DEC(x) --lwip_stats.x
311 #define STATS_INC_USED(x, y, type) do { lwip_stats.x.used = (type)(lwip_stats.x.used + y); \
312 if (lwip_stats.x.max < lwip_stats.x.used) { \
313 lwip_stats.x.max = lwip_stats.x.used; \
316 #define STATS_GET(x) lwip_stats.x
317 #else /* LWIP_STATS */
321 #define STATS_INC_USED(x, y, type)
322 #endif /* LWIP_STATS */
325 #define TCP_STATS_INC(x) STATS_INC(x)
326 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
328 #define TCP_STATS_INC(x)
329 #define TCP_STATS_DISPLAY()
333 #define UDP_STATS_INC(x) STATS_INC(x)
334 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
336 #define UDP_STATS_INC(x)
337 #define UDP_STATS_DISPLAY()
341 #define ICMP_STATS_INC(x) STATS_INC(x)
342 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
344 #define ICMP_STATS_INC(x)
345 #define ICMP_STATS_DISPLAY()
349 #define IGMP_STATS_INC(x) STATS_INC(x)
350 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP")
352 #define IGMP_STATS_INC(x)
353 #define IGMP_STATS_DISPLAY()
357 #define IP_STATS_INC(x) STATS_INC(x)
358 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
360 #define IP_STATS_INC(x)
361 #define IP_STATS_DISPLAY()
365 #define IPFRAG_STATS_INC(x) STATS_INC(x)
366 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
368 #define IPFRAG_STATS_INC(x)
369 #define IPFRAG_STATS_DISPLAY()
373 #define ETHARP_STATS_INC(x) STATS_INC(x)
374 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
376 #define ETHARP_STATS_INC(x)
377 #define ETHARP_STATS_DISPLAY()
381 #define LINK_STATS_INC(x) STATS_INC(x)
382 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
384 #define LINK_STATS_INC(x)
385 #define LINK_STATS_DISPLAY()
389 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
390 #define MEM_STATS_INC(x) STATS_INC(mem.x)
391 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y, mem_size_t)
392 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x = (mem_size_t)((lwip_stats.mem.x) - (y))
393 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
395 #define MEM_STATS_AVAIL(x, y)
396 #define MEM_STATS_INC(x)
397 #define MEM_STATS_INC_USED(x, y)
398 #define MEM_STATS_DEC_USED(x, y)
399 #define MEM_STATS_DISPLAY()
403 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i]->x)
404 #define MEMP_STATS_DISPLAY(i) stats_display_memp(lwip_stats.memp[i], i)
405 #define MEMP_STATS_GET(x, i) STATS_GET(memp[i]->x)
407 #define MEMP_STATS_DEC(x, i)
408 #define MEMP_STATS_DISPLAY(i)
409 #define MEMP_STATS_GET(x, i) 0
413 #define SYS_STATS_INC(x) STATS_INC(sys.x)
414 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
415 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1, STAT_COUNTER)
416 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
418 #define SYS_STATS_INC(x)
419 #define SYS_STATS_DEC(x)
420 #define SYS_STATS_INC_USED(x)
421 #define SYS_STATS_DISPLAY()
425 #define IP6_STATS_INC(x) STATS_INC(x)
426 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6")
428 #define IP6_STATS_INC(x)
429 #define IP6_STATS_DISPLAY()
433 #define ICMP6_STATS_INC(x) STATS_INC(x)
434 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6")
436 #define ICMP6_STATS_INC(x)
437 #define ICMP6_STATS_DISPLAY()
441 #define IP6_FRAG_STATS_INC(x) STATS_INC(x)
442 #define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG")
444 #define IP6_FRAG_STATS_INC(x)
445 #define IP6_FRAG_STATS_DISPLAY()
449 #define MLD6_STATS_INC(x) STATS_INC(x)
450 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1")
452 #define MLD6_STATS_INC(x)
453 #define MLD6_STATS_DISPLAY()
457 #define ND6_STATS_INC(x) STATS_INC(x)
458 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND")
460 #define ND6_STATS_INC(x)
461 #define ND6_STATS_DISPLAY()
465 #define MIB2_STATS_INC(x) STATS_INC(x)
467 #define MIB2_STATS_INC(x)
470 /* Display of statistics */
471 #if LWIP_STATS_DISPLAY
472 void stats_display(void);
473 void stats_display_proto(struct stats_proto *proto, const char *name);
474 void stats_display_igmp(struct stats_igmp *igmp, const char *name);
475 void stats_display_mem(struct stats_mem *mem, const char *name);
476 void stats_display_memp(struct stats_mem *mem, int index);
477 void stats_display_sys(struct stats_sys *sys);
478 #else /* LWIP_STATS_DISPLAY */
479 #define stats_display()
480 #define stats_display_proto(proto, name)
481 #define stats_display_igmp(igmp, name)
482 #define stats_display_mem(mem, name)
483 #define stats_display_memp(mem, index)
484 #define stats_display_sys(sys)
485 #endif /* LWIP_STATS_DISPLAY */
491 #endif /* LWIP_HDR_STATS_H */