STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stats.h
Go to the documentation of this file.
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  u32_t ifinoctets;
173  u32_t ifinucastpkts;
174  u32_t ifinnucastpkts;
175  u32_t ifindiscards;
176  u32_t ifinerrors;
177  u32_t ifinunknownprotos;
178  u32_t ifoutoctets;
179  u32_t ifoutucastpkts;
180  u32_t ifoutnucastpkts;
181  u32_t ifoutdiscards;
182  u32_t ifouterrors;
183 };
184 
185 struct stats_ {
186 #if LINK_STATS
187  struct stats_proto link;
188 #endif
189 #if ETHARP_STATS
190  struct stats_proto etharp;
191 #endif
192 #if IPFRAG_STATS
193  struct stats_proto ip_frag;
194 #endif
195 #if IP_STATS
196  struct stats_proto ip;
197 #endif
198 #if ICMP_STATS
199  struct stats_proto icmp;
200 #endif
201 #if IGMP_STATS
202  struct stats_igmp igmp;
203 #endif
204 #if UDP_STATS
205  struct stats_proto udp;
206 #endif
207 #if TCP_STATS
208  struct stats_proto tcp;
209 #endif
210 #if MEM_STATS
211  struct stats_mem mem;
212 #endif
213 #if MEMP_STATS
214  struct stats_mem memp[MEMP_MAX];
215 #endif
216 #if SYS_STATS
217  struct stats_sys sys;
218 #endif
219 #if IP6_STATS
220  struct stats_proto ip6;
221 #endif
222 #if ICMP6_STATS
223  struct stats_proto icmp6;
224 #endif
225 #if IP6_FRAG_STATS
226  struct stats_proto ip6_frag;
227 #endif
228 #if MLD6_STATS
229  struct stats_igmp mld6;
230 #endif
231 #if ND6_STATS
232  struct stats_proto nd6;
233 #endif
234 #if MIB2_STATS
235  struct stats_mib2 mib2;
236 #endif
237 };
238 
239 extern struct stats_ lwip_stats;
240 
241 void stats_init(void);
242 
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; \
248  } \
249  } while(0)
250 #define STATS_GET(x) lwip_stats.x
251 #else /* LWIP_STATS */
252 #define stats_init()
253 #define STATS_INC(x)
254 #define STATS_DEC(x)
255 #define STATS_INC_USED(x)
256 #endif /* LWIP_STATS */
257 
258 #if TCP_STATS
259 #define TCP_STATS_INC(x) STATS_INC(x)
260 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
261 #else
262 #define TCP_STATS_INC(x)
263 #define TCP_STATS_DISPLAY()
264 #endif
265 
266 #if UDP_STATS
267 #define UDP_STATS_INC(x) STATS_INC(x)
268 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
269 #else
270 #define UDP_STATS_INC(x)
271 #define UDP_STATS_DISPLAY()
272 #endif
273 
274 #if ICMP_STATS
275 #define ICMP_STATS_INC(x) STATS_INC(x)
276 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
277 #else
278 #define ICMP_STATS_INC(x)
279 #define ICMP_STATS_DISPLAY()
280 #endif
281 
282 #if IGMP_STATS
283 #define IGMP_STATS_INC(x) STATS_INC(x)
284 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP")
285 #else
286 #define IGMP_STATS_INC(x)
287 #define IGMP_STATS_DISPLAY()
288 #endif
289 
290 #if IP_STATS
291 #define IP_STATS_INC(x) STATS_INC(x)
292 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
293 #else
294 #define IP_STATS_INC(x)
295 #define IP_STATS_DISPLAY()
296 #endif
297 
298 #if IPFRAG_STATS
299 #define IPFRAG_STATS_INC(x) STATS_INC(x)
300 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
301 #else
302 #define IPFRAG_STATS_INC(x)
303 #define IPFRAG_STATS_DISPLAY()
304 #endif
305 
306 #if ETHARP_STATS
307 #define ETHARP_STATS_INC(x) STATS_INC(x)
308 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
309 #else
310 #define ETHARP_STATS_INC(x)
311 #define ETHARP_STATS_DISPLAY()
312 #endif
313 
314 #if LINK_STATS
315 #define LINK_STATS_INC(x) STATS_INC(x)
316 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
317 #else
318 #define LINK_STATS_INC(x)
319 #define LINK_STATS_DISPLAY()
320 #endif
321 
322 #if MEM_STATS
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")
328 #else
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()
334 #endif
335 
336 #if MEMP_STATS
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)
342 #define MEMP_STATS_GET(x, i) STATS_GET(memp[i].x)
343 #else
344 #define MEMP_STATS_AVAIL(x, i, y)
345 #define MEMP_STATS_INC(x, i)
346 #define MEMP_STATS_DEC(x, i)
347 #define MEMP_STATS_INC_USED(x, i)
348 #define MEMP_STATS_DISPLAY(i)
349 #define MEMP_STATS_GET(x, i) 0
350 #endif
351 
352 #if SYS_STATS
353 #define SYS_STATS_INC(x) STATS_INC(sys.x)
354 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
355 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
356 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
357 #else
358 #define SYS_STATS_INC(x)
359 #define SYS_STATS_DEC(x)
360 #define SYS_STATS_INC_USED(x)
361 #define SYS_STATS_DISPLAY()
362 #endif
363 
364 #if IP6_STATS
365 #define IP6_STATS_INC(x) STATS_INC(x)
366 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6")
367 #else
368 #define IP6_STATS_INC(x)
369 #define IP6_STATS_DISPLAY()
370 #endif
371 
372 #if ICMP6_STATS
373 #define ICMP6_STATS_INC(x) STATS_INC(x)
374 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6")
375 #else
376 #define ICMP6_STATS_INC(x)
377 #define ICMP6_STATS_DISPLAY()
378 #endif
379 
380 #if IP6_FRAG_STATS
381 #define IP6_FRAG_STATS_INC(x) STATS_INC(x)
382 #define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG")
383 #else
384 #define IP6_FRAG_STATS_INC(x)
385 #define IP6_FRAG_STATS_DISPLAY()
386 #endif
387 
388 #if MLD6_STATS
389 #define MLD6_STATS_INC(x) STATS_INC(x)
390 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1")
391 #else
392 #define MLD6_STATS_INC(x)
393 #define MLD6_STATS_DISPLAY()
394 #endif
395 
396 #if ND6_STATS
397 #define ND6_STATS_INC(x) STATS_INC(x)
398 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND")
399 #else
400 #define ND6_STATS_INC(x)
401 #define ND6_STATS_DISPLAY()
402 #endif
403 
404 #if MIB2_STATS
405 #define MIB2_STATS_INC(x) STATS_INC(x)
406 #else
407 #define MIB2_STATS_INC(x)
408 #endif
409 
410 /* Display of statistics */
411 #if LWIP_STATS_DISPLAY
412 void stats_display(void);
413 void stats_display_proto(struct stats_proto *proto, const char *name);
414 void stats_display_igmp(struct stats_igmp *igmp, const char *name);
415 void stats_display_mem(struct stats_mem *mem, const char *name);
416 void stats_display_memp(struct stats_mem *mem, int index);
417 void stats_display_sys(struct stats_sys *sys);
418 #else /* LWIP_STATS_DISPLAY */
419 #define stats_display()
420 #define stats_display_proto(proto, name)
421 #define stats_display_igmp(igmp, name)
422 #define stats_display_mem(mem, name)
423 #define stats_display_memp(mem, index)
424 #define stats_display_sys(sys)
425 #endif /* LWIP_STATS_DISPLAY */
426 
427 #ifdef __cplusplus
428 }
429 #endif
430 
431 #endif /* LWIP_HDR_STATS_H */
432 
Definition: memp.h:48
#define stats_display_mem(mem, name)
Definition: stats.h:422
u16_t mem_size_t
Definition: mem.h:76
#define stats_display_proto(proto, name)
Definition: stats.h:420
#define stats_display_igmp(igmp, name)
Definition: stats.h:421
unsigned long u32_t
Definition: cc.h:42
#define stats_display_memp(mem, index)
Definition: stats.h:423
#define stats_display_sys(sys)
Definition: stats.h:424
Definition: memp_priv.h:85
#define stats_display()
Definition: stats.h:419
#define stats_init()
Definition: stats.h:252
Definition: mem.c:179