]> granicus.if.org Git - esp-idf/blob - components/lwip/include/lwip/lwip/stats.h
Initial public version
[esp-idf] / components / lwip / include / lwip / lwip / stats.h
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
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.
15  *
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
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef LWIP_HDR_STATS_H
33 #define LWIP_HDR_STATS_H
34
35 #include "lwip/opt.h"
36
37 #include "lwip/mem.h"
38 #include "lwip/memp.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #if LWIP_STATS
45
46 #ifndef LWIP_STATS_LARGE
47 #define LWIP_STATS_LARGE 0
48 #endif
49
50 #if LWIP_STATS_LARGE
51 #define STAT_COUNTER     u32_t
52 #define STAT_COUNTER_F   U32_F
53 #else
54 #define STAT_COUNTER     u16_t
55 #define STAT_COUNTER_F   U16_F
56 #endif
57
58 struct stats_proto {
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;
71 };
72
73 struct stats_igmp {
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. */
88 };
89
90 struct stats_mem {
91 #ifdef LWIP_DEBUG
92   const char *name;
93 #endif /* LWIP_DEBUG */
94   STAT_COUNTER err;
95   mem_size_t avail;
96   mem_size_t used;
97   mem_size_t max;
98   STAT_COUNTER illegal;
99 };
100
101 struct stats_syselem {
102   STAT_COUNTER used;
103   STAT_COUNTER max;
104   STAT_COUNTER err;
105 };
106
107 struct stats_sys {
108   struct stats_syselem sem;
109   struct stats_syselem mutex;
110   struct stats_syselem mbox;
111 };
112
113 struct stats_mib2 {
114   /* IP */
115   u32_t ipinhdrerrors;
116   u32_t ipinaddrerrors;
117   u32_t ipinunknownprotos;
118   u32_t ipindiscards;
119   u32_t ipindelivers;
120   u32_t ipoutrequests;
121   u32_t ipoutdiscards;
122   u32_t ipoutnoroutes;
123   u32_t ipreasmoks;
124   u32_t ipreasmfails;
125   u32_t ipfragoks;
126   u32_t ipfragfails;
127   u32_t ipfragcreates;
128   u32_t ipreasmreqds;
129   u32_t ipforwdatagrams;
130   u32_t ipinreceives;
131
132   /* TCP */
133   u32_t tcpactiveopens;
134   u32_t tcppassiveopens;
135   u32_t tcpattemptfails;
136   u32_t tcpestabresets;
137   u32_t tcpoutsegs;
138   u32_t tcpretranssegs;
139   u32_t tcpinsegs;
140   u32_t tcpinerrs;
141   u32_t tcpoutrsts;
142
143   /* UDP */
144   u32_t udpindatagrams;
145   u32_t udpnoports;
146   u32_t udpinerrors;
147   u32_t udpoutdatagrams;
148
149   /* ICMP */
150   u32_t icmpinmsgs;
151   u32_t icmpinerrors;
152   u32_t icmpindestunreachs;
153   u32_t icmpintimeexcds;
154   u32_t icmpinparmprobs;
155   u32_t icmpinsrcquenchs;
156   u32_t icmpinredirects;
157   u32_t icmpinechos;
158   u32_t icmpinechoreps;
159   u32_t icmpintimestamps;
160   u32_t icmpintimestampreps;
161   u32_t icmpinaddrmasks;
162   u32_t icmpinaddrmaskreps;
163   u32_t icmpoutmsgs;
164   u32_t icmpouterrors;
165   u32_t icmpoutdestunreachs;
166   u32_t icmpouttimeexcds;
167   u32_t icmpoutechos; /* can be incremented by user application ('ping') */
168   u32_t icmpoutechoreps;
169 };
170
171 struct stats_mib2_netif_ctrs {
172   /* The total number of octets received on the interface, including framing characters */
173   u32_t ifinoctets;
174   /* The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were
175    * not addressed to a multicast or broadcast address at this sub-layer */
176   u32_t ifinucastpkts;
177   /* The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were 
178    * addressed to a multicast or broadcast address at this sub-layer */
179   u32_t ifinnucastpkts;
180   /* The number of inbound packets which were chosen to be discarded even though no errors had 
181    * been detected to prevent their being deliverable to a higher-layer protocol. One possible 
182    * reason for discarding such a packet could be to free up buffer space */
183   u32_t ifindiscards;
184   /* For packet-oriented interfaces, the number of inbound packets that contained errors 
185    * preventing them from being deliverable to a higher-layer protocol.  For character-
186    * oriented or fixed-length interfaces, the number of inbound transmission units that 
187    * contained errors preventing them from being deliverable to a higher-layer protocol. */
188   u32_t ifinerrors;
189   /* For packet-oriented interfaces, the number of packets received via the interface which
190    * were discarded because of an unknown or unsupported protocol.  For character-oriented
191    * or fixed-length interfaces that support protocol multiplexing the number of transmission
192    * units received via the interface which were discarded because of an unknown or unsupported
193    * protocol. For any interface that does not support protocol multiplexing, this counter will
194    * always be 0 */
195   u32_t ifinunknownprotos;
196   /* The total number of octets transmitted out of the interface, including framing characters. */
197   u32_t ifoutoctets;
198   /* The total number of packets that higher-level protocols requested be transmitted, and
199    * which were not addressed to a multicast or broadcast address at this sub-layer, including
200    * those that were discarded or not sent. */
201   u32_t ifoutucastpkts;
202   /* The total number of packets that higher-level protocols requested be transmitted, and which
203    * were addressed to a multicast or broadcast address at this sub-layer, including
204    * those that were discarded or not sent. */
205   u32_t ifoutnucastpkts;
206   /* The number of outbound packets which were chosen to be discarded even though no errors had
207    * been detected to prevent their being transmitted.  One possible reason for discarding
208    * such a packet could be to free up buffer space. */
209   u32_t ifoutdiscards;
210   /* For packet-oriented interfaces, the number of outbound packets that could not be transmitted
211    * because of errors. For character-oriented or fixed-length interfaces, the number of outbound
212    * transmission units that could not be transmitted because of errors. */
213   u32_t ifouterrors;
214 };
215
216 struct stats_ {
217 #if LINK_STATS
218   struct stats_proto link;
219 #endif
220 #if ETHARP_STATS
221   struct stats_proto etharp;
222 #endif
223 #if IPFRAG_STATS
224   struct stats_proto ip_frag;
225 #endif
226 #if IP_STATS
227   struct stats_proto ip;
228 #endif
229 #if ICMP_STATS
230   struct stats_proto icmp;
231 #endif
232 #if IGMP_STATS
233   struct stats_igmp igmp;
234 #endif
235 #if UDP_STATS
236   struct stats_proto udp;
237 #endif
238 #if TCP_STATS
239   struct stats_proto tcp;
240 #endif
241 #if MEM_STATS
242   struct stats_mem mem;
243 #endif
244 #if MEMP_STATS
245   struct stats_mem memp[MEMP_MAX];
246 #endif
247 #if SYS_STATS
248   struct stats_sys sys;
249 #endif
250 #if IP6_STATS
251   struct stats_proto ip6;
252 #endif
253 #if ICMP6_STATS
254   struct stats_proto icmp6;
255 #endif
256 #if IP6_FRAG_STATS
257   struct stats_proto ip6_frag;
258 #endif
259 #if MLD6_STATS
260   struct stats_igmp mld6;
261 #endif
262 #if ND6_STATS
263   struct stats_proto nd6;
264 #endif
265 #if MIB2_STATS
266   struct stats_mib2 mib2;
267 #endif
268 };
269
270 extern struct stats_ lwip_stats;
271
272 void stats_init(void);
273
274 #define STATS_INC(x) ++lwip_stats.x
275 #define STATS_DEC(x) --lwip_stats.x
276 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
277                                 if (lwip_stats.x.max < lwip_stats.x.used) { \
278                                     lwip_stats.x.max = lwip_stats.x.used; \
279                                 } \
280                              } while(0)
281 #define STATS_GET(x) lwip_stats.x
282 #else /* LWIP_STATS */
283 #define stats_init()
284 #define STATS_INC(x)
285 #define STATS_DEC(x)
286 #define STATS_INC_USED(x)
287 #endif /* LWIP_STATS */
288
289 #if TCP_STATS
290 #define TCP_STATS_INC(x) STATS_INC(x)
291 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
292 #else
293 #define TCP_STATS_INC(x)
294 #define TCP_STATS_DISPLAY()
295 #endif
296
297 #if UDP_STATS
298 #define UDP_STATS_INC(x) STATS_INC(x)
299 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
300 #else
301 #define UDP_STATS_INC(x)
302 #define UDP_STATS_DISPLAY()
303 #endif
304
305 #if ICMP_STATS
306 #define ICMP_STATS_INC(x) STATS_INC(x)
307 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
308 #else
309 #define ICMP_STATS_INC(x)
310 #define ICMP_STATS_DISPLAY()
311 #endif
312
313 #if IGMP_STATS
314 #define IGMP_STATS_INC(x) STATS_INC(x)
315 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP")
316 #else
317 #define IGMP_STATS_INC(x)
318 #define IGMP_STATS_DISPLAY()
319 #endif
320
321 #if IP_STATS
322 #define IP_STATS_INC(x) STATS_INC(x)
323 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
324 #else
325 #define IP_STATS_INC(x)
326 #define IP_STATS_DISPLAY()
327 #endif
328
329 #if IPFRAG_STATS
330 #define IPFRAG_STATS_INC(x) STATS_INC(x)
331 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
332 #else
333 #define IPFRAG_STATS_INC(x)
334 #define IPFRAG_STATS_DISPLAY()
335 #endif
336
337 #if ETHARP_STATS
338 #define ETHARP_STATS_INC(x) STATS_INC(x)
339 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
340 #else
341 #define ETHARP_STATS_INC(x)
342 #define ETHARP_STATS_DISPLAY()
343 #endif
344
345 #if LINK_STATS
346 #define LINK_STATS_INC(x) STATS_INC(x)
347 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
348 #else
349 #define LINK_STATS_INC(x)
350 #define LINK_STATS_DISPLAY()
351 #endif
352
353 #if MEM_STATS
354 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
355 #define MEM_STATS_INC(x) STATS_INC(mem.x)
356 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
357 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
358 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
359 #else
360 #define MEM_STATS_AVAIL(x, y)
361 #define MEM_STATS_INC(x)
362 #define MEM_STATS_INC_USED(x, y)
363 #define MEM_STATS_DEC_USED(x, y)
364 #define MEM_STATS_DISPLAY()
365 #endif
366
367 #if MEMP_STATS
368 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
369 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
370 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
371 #define MEMP_STATS_INC_USED(x, i) STATS_INC_USED(memp[i], 1)
372 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
373 #define MEMP_STATS_GET(x, i) STATS_GET(memp[i].x)
374 #else
375 #define MEMP_STATS_AVAIL(x, i, y)
376 #define MEMP_STATS_INC(x, i)
377 #define MEMP_STATS_DEC(x, i)
378 #define MEMP_STATS_INC_USED(x, i)
379 #define MEMP_STATS_DISPLAY(i)
380 #define MEMP_STATS_GET(x, i) 0
381 #endif
382
383 #if SYS_STATS
384 #define SYS_STATS_INC(x) STATS_INC(sys.x)
385 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
386 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
387 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
388 #else
389 #define SYS_STATS_INC(x)
390 #define SYS_STATS_DEC(x)
391 #define SYS_STATS_INC_USED(x)
392 #define SYS_STATS_DISPLAY()
393 #endif
394
395 #if IP6_STATS
396 #define IP6_STATS_INC(x) STATS_INC(x)
397 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6")
398 #else
399 #define IP6_STATS_INC(x)
400 #define IP6_STATS_DISPLAY()
401 #endif
402
403 #if ICMP6_STATS
404 #define ICMP6_STATS_INC(x) STATS_INC(x)
405 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6")
406 #else
407 #define ICMP6_STATS_INC(x)
408 #define ICMP6_STATS_DISPLAY()
409 #endif
410
411 #if IP6_FRAG_STATS
412 #define IP6_FRAG_STATS_INC(x) STATS_INC(x)
413 #define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG")
414 #else
415 #define IP6_FRAG_STATS_INC(x)
416 #define IP6_FRAG_STATS_DISPLAY()
417 #endif
418
419 #if MLD6_STATS
420 #define MLD6_STATS_INC(x) STATS_INC(x)
421 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1")
422 #else
423 #define MLD6_STATS_INC(x)
424 #define MLD6_STATS_DISPLAY()
425 #endif
426
427 #if ND6_STATS
428 #define ND6_STATS_INC(x) STATS_INC(x)
429 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND")
430 #else
431 #define ND6_STATS_INC(x)
432 #define ND6_STATS_DISPLAY()
433 #endif
434
435 #if MIB2_STATS
436 #define MIB2_STATS_INC(x) STATS_INC(x)
437 #else
438 #define MIB2_STATS_INC(x)
439 #endif
440
441 /* Display of statistics */
442 #if LWIP_STATS_DISPLAY
443 void stats_display(void);
444 void stats_display_proto(struct stats_proto *proto, const char *name);
445 void stats_display_igmp(struct stats_igmp *igmp, const char *name);
446 void stats_display_mem(struct stats_mem *mem, const char *name);
447 void stats_display_memp(struct stats_mem *mem, int index);
448 void stats_display_sys(struct stats_sys *sys);
449 #else /* LWIP_STATS_DISPLAY */
450 #define stats_display()
451 #define stats_display_proto(proto, name)
452 #define stats_display_igmp(igmp, name)
453 #define stats_display_mem(mem, name)
454 #define stats_display_memp(mem, index)
455 #define stats_display_sys(sys)
456 #endif /* LWIP_STATS_DISPLAY */
457
458 #ifdef __cplusplus
459 }
460 #endif
461
462 #endif /* LWIP_HDR_STATS_H */