Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:479ce5546098 1 /*
sherckuith 0:479ce5546098 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
sherckuith 0:479ce5546098 3 * All rights reserved.
sherckuith 0:479ce5546098 4 *
sherckuith 0:479ce5546098 5 * Redistribution and use in source and binary forms, with or without modification,
sherckuith 0:479ce5546098 6 * are permitted provided that the following conditions are met:
sherckuith 0:479ce5546098 7 *
sherckuith 0:479ce5546098 8 * 1. Redistributions of source code must retain the above copyright notice,
sherckuith 0:479ce5546098 9 * this list of conditions and the following disclaimer.
sherckuith 0:479ce5546098 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
sherckuith 0:479ce5546098 11 * this list of conditions and the following disclaimer in the documentation
sherckuith 0:479ce5546098 12 * and/or other materials provided with the distribution.
sherckuith 0:479ce5546098 13 * 3. The name of the author may not be used to endorse or promote products
sherckuith 0:479ce5546098 14 * derived from this software without specific prior written permission.
sherckuith 0:479ce5546098 15 *
sherckuith 0:479ce5546098 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sherckuith 0:479ce5546098 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sherckuith 0:479ce5546098 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sherckuith 0:479ce5546098 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sherckuith 0:479ce5546098 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sherckuith 0:479ce5546098 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sherckuith 0:479ce5546098 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sherckuith 0:479ce5546098 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sherckuith 0:479ce5546098 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sherckuith 0:479ce5546098 25 * OF SUCH DAMAGE.
sherckuith 0:479ce5546098 26 *
sherckuith 0:479ce5546098 27 * This file is part of the lwIP TCP/IP stack.
sherckuith 0:479ce5546098 28 *
sherckuith 0:479ce5546098 29 * Author: Adam Dunkels <adam@sics.se>
sherckuith 0:479ce5546098 30 *
sherckuith 0:479ce5546098 31 */
sherckuith 0:479ce5546098 32 #ifndef __LWIP_STATS_H__
sherckuith 0:479ce5546098 33 #define __LWIP_STATS_H__
sherckuith 0:479ce5546098 34
sherckuith 0:479ce5546098 35 #include "lwip/opt.h"
sherckuith 0:479ce5546098 36
sherckuith 0:479ce5546098 37 #include "lwip/mem.h"
sherckuith 0:479ce5546098 38 #include "lwip/memp.h"
sherckuith 0:479ce5546098 39
sherckuith 0:479ce5546098 40 #ifdef __cplusplus
sherckuith 0:479ce5546098 41 extern "C" {
sherckuith 0:479ce5546098 42 #endif
sherckuith 0:479ce5546098 43
sherckuith 0:479ce5546098 44 #if LWIP_STATS
sherckuith 0:479ce5546098 45
sherckuith 0:479ce5546098 46 #ifndef LWIP_STATS_LARGE
sherckuith 0:479ce5546098 47 #define LWIP_STATS_LARGE 0
sherckuith 0:479ce5546098 48 #endif
sherckuith 0:479ce5546098 49
sherckuith 0:479ce5546098 50 #if LWIP_STATS_LARGE
sherckuith 0:479ce5546098 51 #define STAT_COUNTER u32_t
sherckuith 0:479ce5546098 52 #define STAT_COUNTER_F U32_F
sherckuith 0:479ce5546098 53 #else
sherckuith 0:479ce5546098 54 #define STAT_COUNTER u16_t
sherckuith 0:479ce5546098 55 #define STAT_COUNTER_F U16_F
sherckuith 0:479ce5546098 56 #endif
sherckuith 0:479ce5546098 57
sherckuith 0:479ce5546098 58 struct stats_proto {
sherckuith 0:479ce5546098 59 STAT_COUNTER xmit; /* Transmitted packets. */
sherckuith 0:479ce5546098 60 STAT_COUNTER recv; /* Received packets. */
sherckuith 0:479ce5546098 61 STAT_COUNTER fw; /* Forwarded packets. */
sherckuith 0:479ce5546098 62 STAT_COUNTER drop; /* Dropped packets. */
sherckuith 0:479ce5546098 63 STAT_COUNTER chkerr; /* Checksum error. */
sherckuith 0:479ce5546098 64 STAT_COUNTER lenerr; /* Invalid length error. */
sherckuith 0:479ce5546098 65 STAT_COUNTER memerr; /* Out of memory error. */
sherckuith 0:479ce5546098 66 STAT_COUNTER rterr; /* Routing error. */
sherckuith 0:479ce5546098 67 STAT_COUNTER proterr; /* Protocol error. */
sherckuith 0:479ce5546098 68 STAT_COUNTER opterr; /* Error in options. */
sherckuith 0:479ce5546098 69 STAT_COUNTER err; /* Misc error. */
sherckuith 0:479ce5546098 70 STAT_COUNTER cachehit;
sherckuith 0:479ce5546098 71 };
sherckuith 0:479ce5546098 72
sherckuith 0:479ce5546098 73 struct stats_igmp {
sherckuith 0:479ce5546098 74 STAT_COUNTER xmit; /* Transmitted packets. */
sherckuith 0:479ce5546098 75 STAT_COUNTER recv; /* Received packets. */
sherckuith 0:479ce5546098 76 STAT_COUNTER drop; /* Dropped packets. */
sherckuith 0:479ce5546098 77 STAT_COUNTER chkerr; /* Checksum error. */
sherckuith 0:479ce5546098 78 STAT_COUNTER lenerr; /* Invalid length error. */
sherckuith 0:479ce5546098 79 STAT_COUNTER memerr; /* Out of memory error. */
sherckuith 0:479ce5546098 80 STAT_COUNTER proterr; /* Protocol error. */
sherckuith 0:479ce5546098 81 STAT_COUNTER rx_v1; /* Received v1 frames. */
sherckuith 0:479ce5546098 82 STAT_COUNTER rx_group; /* Received group-specific queries. */
sherckuith 0:479ce5546098 83 STAT_COUNTER rx_general; /* Received general queries. */
sherckuith 0:479ce5546098 84 STAT_COUNTER rx_report; /* Received reports. */
sherckuith 0:479ce5546098 85 STAT_COUNTER tx_join; /* Sent joins. */
sherckuith 0:479ce5546098 86 STAT_COUNTER tx_leave; /* Sent leaves. */
sherckuith 0:479ce5546098 87 STAT_COUNTER tx_report; /* Sent reports. */
sherckuith 0:479ce5546098 88 };
sherckuith 0:479ce5546098 89
sherckuith 0:479ce5546098 90 struct stats_mem {
sherckuith 0:479ce5546098 91 #ifdef LWIP_DEBUG
sherckuith 0:479ce5546098 92 const char *name;
sherckuith 0:479ce5546098 93 #endif /* LWIP_DEBUG */
sherckuith 0:479ce5546098 94 mem_size_t avail;
sherckuith 0:479ce5546098 95 mem_size_t used;
sherckuith 0:479ce5546098 96 mem_size_t max;
sherckuith 0:479ce5546098 97 STAT_COUNTER err;
sherckuith 0:479ce5546098 98 STAT_COUNTER illegal;
sherckuith 0:479ce5546098 99 };
sherckuith 0:479ce5546098 100
sherckuith 0:479ce5546098 101 struct stats_syselem {
sherckuith 0:479ce5546098 102 STAT_COUNTER used;
sherckuith 0:479ce5546098 103 STAT_COUNTER max;
sherckuith 0:479ce5546098 104 STAT_COUNTER err;
sherckuith 0:479ce5546098 105 };
sherckuith 0:479ce5546098 106
sherckuith 0:479ce5546098 107 struct stats_sys {
sherckuith 0:479ce5546098 108 struct stats_syselem sem;
sherckuith 0:479ce5546098 109 struct stats_syselem mutex;
sherckuith 0:479ce5546098 110 struct stats_syselem mbox;
sherckuith 0:479ce5546098 111 };
sherckuith 0:479ce5546098 112
sherckuith 0:479ce5546098 113 struct stats_ {
sherckuith 0:479ce5546098 114 #if LINK_STATS
sherckuith 0:479ce5546098 115 struct stats_proto link;
sherckuith 0:479ce5546098 116 #endif
sherckuith 0:479ce5546098 117 #if ETHARP_STATS
sherckuith 0:479ce5546098 118 struct stats_proto etharp;
sherckuith 0:479ce5546098 119 #endif
sherckuith 0:479ce5546098 120 #if IPFRAG_STATS
sherckuith 0:479ce5546098 121 struct stats_proto ip_frag;
sherckuith 0:479ce5546098 122 #endif
sherckuith 0:479ce5546098 123 #if IP_STATS
sherckuith 0:479ce5546098 124 struct stats_proto ip;
sherckuith 0:479ce5546098 125 #endif
sherckuith 0:479ce5546098 126 #if ICMP_STATS
sherckuith 0:479ce5546098 127 struct stats_proto icmp;
sherckuith 0:479ce5546098 128 #endif
sherckuith 0:479ce5546098 129 #if IGMP_STATS
sherckuith 0:479ce5546098 130 struct stats_igmp igmp;
sherckuith 0:479ce5546098 131 #endif
sherckuith 0:479ce5546098 132 #if UDP_STATS
sherckuith 0:479ce5546098 133 struct stats_proto udp;
sherckuith 0:479ce5546098 134 #endif
sherckuith 0:479ce5546098 135 #if TCP_STATS
sherckuith 0:479ce5546098 136 struct stats_proto tcp;
sherckuith 0:479ce5546098 137 #endif
sherckuith 0:479ce5546098 138 #if MEM_STATS
sherckuith 0:479ce5546098 139 struct stats_mem mem;
sherckuith 0:479ce5546098 140 #endif
sherckuith 0:479ce5546098 141 #if MEMP_STATS
sherckuith 0:479ce5546098 142 struct stats_mem memp[MEMP_MAX];
sherckuith 0:479ce5546098 143 #endif
sherckuith 0:479ce5546098 144 #if SYS_STATS
sherckuith 0:479ce5546098 145 struct stats_sys sys;
sherckuith 0:479ce5546098 146 #endif
sherckuith 0:479ce5546098 147 };
sherckuith 0:479ce5546098 148
sherckuith 0:479ce5546098 149 extern struct stats_ lwip_stats;
sherckuith 0:479ce5546098 150
sherckuith 0:479ce5546098 151 void stats_init(void);
sherckuith 0:479ce5546098 152
sherckuith 0:479ce5546098 153 #define STATS_INC(x) ++lwip_stats.x
sherckuith 0:479ce5546098 154 #define STATS_DEC(x) --lwip_stats.x
sherckuith 0:479ce5546098 155 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
sherckuith 0:479ce5546098 156 if (lwip_stats.x.max < lwip_stats.x.used) { \
sherckuith 0:479ce5546098 157 lwip_stats.x.max = lwip_stats.x.used; \
sherckuith 0:479ce5546098 158 } \
sherckuith 0:479ce5546098 159 } while(0)
sherckuith 0:479ce5546098 160 #else /* LWIP_STATS */
sherckuith 0:479ce5546098 161 #define stats_init()
sherckuith 0:479ce5546098 162 #define STATS_INC(x)
sherckuith 0:479ce5546098 163 #define STATS_DEC(x)
sherckuith 0:479ce5546098 164 #define STATS_INC_USED(x)
sherckuith 0:479ce5546098 165 #endif /* LWIP_STATS */
sherckuith 0:479ce5546098 166
sherckuith 0:479ce5546098 167 #if TCP_STATS
sherckuith 0:479ce5546098 168 #define TCP_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 169 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
sherckuith 0:479ce5546098 170 #else
sherckuith 0:479ce5546098 171 #define TCP_STATS_INC(x)
sherckuith 0:479ce5546098 172 #define TCP_STATS_DISPLAY()
sherckuith 0:479ce5546098 173 #endif
sherckuith 0:479ce5546098 174
sherckuith 0:479ce5546098 175 #if UDP_STATS
sherckuith 0:479ce5546098 176 #define UDP_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 177 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
sherckuith 0:479ce5546098 178 #else
sherckuith 0:479ce5546098 179 #define UDP_STATS_INC(x)
sherckuith 0:479ce5546098 180 #define UDP_STATS_DISPLAY()
sherckuith 0:479ce5546098 181 #endif
sherckuith 0:479ce5546098 182
sherckuith 0:479ce5546098 183 #if ICMP_STATS
sherckuith 0:479ce5546098 184 #define ICMP_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 185 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
sherckuith 0:479ce5546098 186 #else
sherckuith 0:479ce5546098 187 #define ICMP_STATS_INC(x)
sherckuith 0:479ce5546098 188 #define ICMP_STATS_DISPLAY()
sherckuith 0:479ce5546098 189 #endif
sherckuith 0:479ce5546098 190
sherckuith 0:479ce5546098 191 #if IGMP_STATS
sherckuith 0:479ce5546098 192 #define IGMP_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 193 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
sherckuith 0:479ce5546098 194 #else
sherckuith 0:479ce5546098 195 #define IGMP_STATS_INC(x)
sherckuith 0:479ce5546098 196 #define IGMP_STATS_DISPLAY()
sherckuith 0:479ce5546098 197 #endif
sherckuith 0:479ce5546098 198
sherckuith 0:479ce5546098 199 #if IP_STATS
sherckuith 0:479ce5546098 200 #define IP_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 201 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
sherckuith 0:479ce5546098 202 #else
sherckuith 0:479ce5546098 203 #define IP_STATS_INC(x)
sherckuith 0:479ce5546098 204 #define IP_STATS_DISPLAY()
sherckuith 0:479ce5546098 205 #endif
sherckuith 0:479ce5546098 206
sherckuith 0:479ce5546098 207 #if IPFRAG_STATS
sherckuith 0:479ce5546098 208 #define IPFRAG_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 209 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
sherckuith 0:479ce5546098 210 #else
sherckuith 0:479ce5546098 211 #define IPFRAG_STATS_INC(x)
sherckuith 0:479ce5546098 212 #define IPFRAG_STATS_DISPLAY()
sherckuith 0:479ce5546098 213 #endif
sherckuith 0:479ce5546098 214
sherckuith 0:479ce5546098 215 #if ETHARP_STATS
sherckuith 0:479ce5546098 216 #define ETHARP_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 217 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
sherckuith 0:479ce5546098 218 #else
sherckuith 0:479ce5546098 219 #define ETHARP_STATS_INC(x)
sherckuith 0:479ce5546098 220 #define ETHARP_STATS_DISPLAY()
sherckuith 0:479ce5546098 221 #endif
sherckuith 0:479ce5546098 222
sherckuith 0:479ce5546098 223 #if LINK_STATS
sherckuith 0:479ce5546098 224 #define LINK_STATS_INC(x) STATS_INC(x)
sherckuith 0:479ce5546098 225 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
sherckuith 0:479ce5546098 226 #else
sherckuith 0:479ce5546098 227 #define LINK_STATS_INC(x)
sherckuith 0:479ce5546098 228 #define LINK_STATS_DISPLAY()
sherckuith 0:479ce5546098 229 #endif
sherckuith 0:479ce5546098 230
sherckuith 0:479ce5546098 231 #if MEM_STATS
sherckuith 0:479ce5546098 232 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
sherckuith 0:479ce5546098 233 #define MEM_STATS_INC(x) STATS_INC(mem.x)
sherckuith 0:479ce5546098 234 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
sherckuith 0:479ce5546098 235 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
sherckuith 0:479ce5546098 236 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
sherckuith 0:479ce5546098 237 #else
sherckuith 0:479ce5546098 238 #define MEM_STATS_AVAIL(x, y)
sherckuith 0:479ce5546098 239 #define MEM_STATS_INC(x)
sherckuith 0:479ce5546098 240 #define MEM_STATS_INC_USED(x, y)
sherckuith 0:479ce5546098 241 #define MEM_STATS_DEC_USED(x, y)
sherckuith 0:479ce5546098 242 #define MEM_STATS_DISPLAY()
sherckuith 0:479ce5546098 243 #endif
sherckuith 0:479ce5546098 244
sherckuith 0:479ce5546098 245 #if MEMP_STATS
sherckuith 0:479ce5546098 246 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
sherckuith 0:479ce5546098 247 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
sherckuith 0:479ce5546098 248 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
sherckuith 0:479ce5546098 249 #define MEMP_STATS_INC_USED(x, i) STATS_INC_USED(memp[i], 1)
sherckuith 0:479ce5546098 250 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
sherckuith 0:479ce5546098 251 #else
sherckuith 0:479ce5546098 252 #define MEMP_STATS_AVAIL(x, i, y)
sherckuith 0:479ce5546098 253 #define MEMP_STATS_INC(x, i)
sherckuith 0:479ce5546098 254 #define MEMP_STATS_DEC(x, i)
sherckuith 0:479ce5546098 255 #define MEMP_STATS_INC_USED(x, i)
sherckuith 0:479ce5546098 256 #define MEMP_STATS_DISPLAY(i)
sherckuith 0:479ce5546098 257 #endif
sherckuith 0:479ce5546098 258
sherckuith 0:479ce5546098 259 #if SYS_STATS
sherckuith 0:479ce5546098 260 #define SYS_STATS_INC(x) STATS_INC(sys.x)
sherckuith 0:479ce5546098 261 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
sherckuith 0:479ce5546098 262 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
sherckuith 0:479ce5546098 263 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
sherckuith 0:479ce5546098 264 #else
sherckuith 0:479ce5546098 265 #define SYS_STATS_INC(x)
sherckuith 0:479ce5546098 266 #define SYS_STATS_DEC(x)
sherckuith 0:479ce5546098 267 #define SYS_STATS_INC_USED(x)
sherckuith 0:479ce5546098 268 #define SYS_STATS_DISPLAY()
sherckuith 0:479ce5546098 269 #endif
sherckuith 0:479ce5546098 270
sherckuith 0:479ce5546098 271 /* Display of statistics */
sherckuith 0:479ce5546098 272 #if LWIP_STATS_DISPLAY
sherckuith 0:479ce5546098 273 void stats_display(void);
sherckuith 0:479ce5546098 274 void stats_display_proto(struct stats_proto *proto, char *name);
sherckuith 0:479ce5546098 275 void stats_display_igmp(struct stats_igmp *igmp);
sherckuith 0:479ce5546098 276 void stats_display_mem(struct stats_mem *mem, char *name);
sherckuith 0:479ce5546098 277 void stats_display_memp(struct stats_mem *mem, int index);
sherckuith 0:479ce5546098 278 void stats_display_sys(struct stats_sys *sys);
sherckuith 0:479ce5546098 279 #else /* LWIP_STATS_DISPLAY */
sherckuith 0:479ce5546098 280 #define stats_display()
sherckuith 0:479ce5546098 281 #define stats_display_proto(proto, name)
sherckuith 0:479ce5546098 282 #define stats_display_igmp(igmp)
sherckuith 0:479ce5546098 283 #define stats_display_mem(mem, name)
sherckuith 0:479ce5546098 284 #define stats_display_memp(mem, index)
sherckuith 0:479ce5546098 285 #define stats_display_sys(sys)
sherckuith 0:479ce5546098 286 #endif /* LWIP_STATS_DISPLAY */
sherckuith 0:479ce5546098 287
sherckuith 0:479ce5546098 288 #ifdef __cplusplus
sherckuith 0:479ce5546098 289 }
sherckuith 0:479ce5546098 290 #endif
sherckuith 0:479ce5546098 291
sherckuith 0:479ce5546098 292 #endif /* __LWIP_STATS_H__ */