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 {
172 /* The total number of octets received on the interface, including framing characters */
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 */
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 */
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. */
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
195 u32_t ifinunknownprotos;
196 /* The total number of octets transmitted out of the interface, including framing characters. */
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. */
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. */
218 struct stats_proto link;
221 struct stats_proto etharp;
224 struct stats_proto ip_frag;
227 struct stats_proto ip;
230 struct stats_proto icmp;
233 struct stats_igmp igmp;
236 struct stats_proto udp;
239 struct stats_proto tcp;
242 struct stats_mem mem;
245 struct stats_mem memp[MEMP_MAX];
248 struct stats_sys sys;
251 struct stats_proto ip6;
254 struct stats_proto icmp6;
257 struct stats_proto ip6_frag;
260 struct stats_igmp mld6;
263 struct stats_proto nd6;
266 struct stats_mib2 mib2;
270 extern struct stats_ lwip_stats;
272 void stats_init(void);
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; \
281 #define STATS_GET(x) lwip_stats.x
282 #else /* LWIP_STATS */
286 #define STATS_INC_USED(x)
287 #endif /* LWIP_STATS */
290 #define TCP_STATS_INC(x) STATS_INC(x)
291 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
293 #define TCP_STATS_INC(x)
294 #define TCP_STATS_DISPLAY()
298 #define UDP_STATS_INC(x) STATS_INC(x)
299 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
301 #define UDP_STATS_INC(x)
302 #define UDP_STATS_DISPLAY()
306 #define ICMP_STATS_INC(x) STATS_INC(x)
307 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
309 #define ICMP_STATS_INC(x)
310 #define ICMP_STATS_DISPLAY()
314 #define IGMP_STATS_INC(x) STATS_INC(x)
315 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP")
317 #define IGMP_STATS_INC(x)
318 #define IGMP_STATS_DISPLAY()
322 #define IP_STATS_INC(x) STATS_INC(x)
323 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
325 #define IP_STATS_INC(x)
326 #define IP_STATS_DISPLAY()
330 #define IPFRAG_STATS_INC(x) STATS_INC(x)
331 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
333 #define IPFRAG_STATS_INC(x)
334 #define IPFRAG_STATS_DISPLAY()
338 #define ETHARP_STATS_INC(x) STATS_INC(x)
339 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
341 #define ETHARP_STATS_INC(x)
342 #define ETHARP_STATS_DISPLAY()
346 #define LINK_STATS_INC(x) STATS_INC(x)
347 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
349 #define LINK_STATS_INC(x)
350 #define LINK_STATS_DISPLAY()
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")
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()
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)
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
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)
389 #define SYS_STATS_INC(x)
390 #define SYS_STATS_DEC(x)
391 #define SYS_STATS_INC_USED(x)
392 #define SYS_STATS_DISPLAY()
396 #define IP6_STATS_INC(x) STATS_INC(x)
397 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6")
399 #define IP6_STATS_INC(x)
400 #define IP6_STATS_DISPLAY()
404 #define ICMP6_STATS_INC(x) STATS_INC(x)
405 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6")
407 #define ICMP6_STATS_INC(x)
408 #define ICMP6_STATS_DISPLAY()
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")
415 #define IP6_FRAG_STATS_INC(x)
416 #define IP6_FRAG_STATS_DISPLAY()
420 #define MLD6_STATS_INC(x) STATS_INC(x)
421 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1")
423 #define MLD6_STATS_INC(x)
424 #define MLD6_STATS_DISPLAY()
428 #define ND6_STATS_INC(x) STATS_INC(x)
429 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND")
431 #define ND6_STATS_INC(x)
432 #define ND6_STATS_DISPLAY()
436 #define MIB2_STATS_INC(x) STATS_INC(x)
438 #define MIB2_STATS_INC(x)
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 */
462 #endif /* LWIP_HDR_STATS_H */