Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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