Boot Linux faster!

Check our new training course

Boot Linux faster!

Check our new training course
and Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef __NET_STATS_H__
#define __NET_STATS_H__

#if defined(CONFIG_NET_STATISTICS)

#include <stdlib.h>

#include <net/net_ip.h>
#include <net/net_stats.h>
#include <net/net_if.h>

extern struct net_stats net_stats;

#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
#define SET_STAT(cmd) (cmd)
#define GET_STAT(iface, s) (iface ? iface->stats.s : net_stats.s)
#define GET_STAT_ADDR(iface, s) (iface ? &iface->stats.s : &net_stats.s)
#else
#define SET_STAT(cmd)
#define GET_STAT(iface, s) (net_stats.s)
#define GET_STAT_ADDR(iface, s) (&GET_STAT(iface, s))
#endif

#define UPDATE_STAT_GLOBAL(cmd) (net_##cmd)
#define UPDATE_STAT(_iface, _cmd) \
	{ NET_ASSERT(_iface); (UPDATE_STAT_GLOBAL(_cmd)); \
	  SET_STAT(_iface->_cmd); }
/* Core stats */

static inline void net_stats_update_processing_error(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.processing_error++);
}

static inline void net_stats_update_ip_errors_protoerr(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ip_errors.protoerr++);
}

static inline void net_stats_update_ip_errors_vhlerr(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ip_errors.vhlerr++);
}

static inline void net_stats_update_bytes_recv(struct net_if *iface,
					       u32_t bytes)
{
	UPDATE_STAT(iface, stats.bytes.received += bytes);
}

static inline void net_stats_update_bytes_sent(struct net_if *iface,
					       u32_t bytes)
{
	UPDATE_STAT(iface, stats.bytes.sent += bytes);
}
#else
#define net_stats_update_processing_error(iface)
#define net_stats_update_ip_errors_protoerr(iface)
#define net_stats_update_ip_errors_vhlerr(iface)
#define net_stats_update_bytes_recv(iface, bytes)
#define net_stats_update_bytes_sent(iface, bytes)
#endif /* CONFIG_NET_STATISTICS */

#if defined(CONFIG_NET_STATISTICS_IPV6)
/* IPv6 stats */

static inline void net_stats_update_ipv6_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6.sent++);
}

static inline void net_stats_update_ipv6_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6.recv++);
}

static inline void net_stats_update_ipv6_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6.drop++);
}
#else
#define net_stats_update_ipv6_drop(iface)
#define net_stats_update_ipv6_sent(iface)
#define net_stats_update_ipv6_recv(iface)
#endif /* CONFIG_NET_STATISTICS_IPV6 */

#if defined(CONFIG_NET_STATISTICS_IPV6_ND)
/* IPv6 Neighbor Discovery stats*/

static inline void net_stats_update_ipv6_nd_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6_nd.sent++);
}

static inline void net_stats_update_ipv6_nd_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6_nd.recv++);
}

static inline void net_stats_update_ipv6_nd_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6_nd.drop++);
}
#else
#define net_stats_update_ipv6_nd_sent(iface)
#define net_stats_update_ipv6_nd_recv(iface)
#define net_stats_update_ipv6_nd_drop(iface)
#endif /* CONFIG_NET_STATISTICS_IPV6_ND */

#if defined(CONFIG_NET_STATISTICS_IPV4)
/* IPv4 stats */

static inline void net_stats_update_ipv4_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv4.drop++);
}

static inline void net_stats_update_ipv4_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv4.sent++);
}

static inline void net_stats_update_ipv4_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv4.recv++);
}
#else
#define net_stats_update_ipv4_drop(iface)
#define net_stats_update_ipv4_sent(iface)
#define net_stats_update_ipv4_recv(iface)
#endif /* CONFIG_NET_STATISTICS_IPV4 */

#if defined(CONFIG_NET_STATISTICS_ICMP)
/* Common ICMPv4/ICMPv6 stats */
static inline void net_stats_update_icmp_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.icmp.sent++);
}

static inline void net_stats_update_icmp_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.icmp.recv++);
}

static inline void net_stats_update_icmp_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.icmp.drop++);
}
#else
#define net_stats_update_icmp_sent(iface)
#define net_stats_update_icmp_recv(iface)
#define net_stats_update_icmp_drop(iface)
#endif /* CONFIG_NET_STATISTICS_ICMP */

#if defined(CONFIG_NET_STATISTICS_UDP)
/* UDP stats */
static inline void net_stats_update_udp_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.udp.sent++);
}

static inline void net_stats_update_udp_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.udp.recv++);
}

static inline void net_stats_update_udp_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.udp.drop++);
}

static inline void net_stats_update_udp_chkerr(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.udp.chkerr++);
}
#else
#define net_stats_update_udp_sent(iface)
#define net_stats_update_udp_recv(iface)
#define net_stats_update_udp_drop(iface)
#define net_stats_update_udp_chkerr(iface)
#endif /* CONFIG_NET_STATISTICS_UDP */

#if defined(CONFIG_NET_STATISTICS_TCP)
/* TCP stats */
static inline void net_stats_update_tcp_sent(struct net_if *iface, u32_t bytes)
{
	UPDATE_STAT(iface, stats.tcp.bytes.sent += bytes);
}

static inline void net_stats_update_tcp_recv(struct net_if *iface, u32_t bytes)
{
	UPDATE_STAT(iface, stats.tcp.bytes.received += bytes);
}

static inline void net_stats_update_tcp_resent(struct net_if *iface,
					       u32_t bytes)
{
	UPDATE_STAT(iface, stats.tcp.resent += bytes);
}

static inline void net_stats_update_tcp_seg_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.sent++);
}

static inline void net_stats_update_tcp_seg_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.recv++);
}

static inline void net_stats_update_tcp_seg_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.drop++);
}

static inline void net_stats_update_tcp_seg_rst(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.rst++);
}

static inline void net_stats_update_tcp_seg_conndrop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.conndrop++);
}

static inline void net_stats_update_tcp_seg_connrst(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.connrst++);
}

static inline void net_stats_update_tcp_seg_chkerr(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.chkerr++);
}

static inline void net_stats_update_tcp_seg_ackerr(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.ackerr++);
}

static inline void net_stats_update_tcp_seg_rsterr(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.rsterr++);
}

static inline void net_stats_update_tcp_seg_rexmit(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.tcp.rexmit++);
}
#else
#define net_stats_update_tcp_sent(iface, bytes)
#define net_stats_update_tcp_resent(iface, bytes)
#define net_stats_update_tcp_recv(iface, bytes)
#define net_stats_update_tcp_seg_sent(iface)
#define net_stats_update_tcp_seg_recv(iface)
#define net_stats_update_tcp_seg_drop(iface)
#define net_stats_update_tcp_seg_rst(iface)
#define net_stats_update_tcp_seg_conndrop(iface)
#define net_stats_update_tcp_seg_connrst(iface)
#define net_stats_update_tcp_seg_chkerr(iface)
#define net_stats_update_tcp_seg_ackerr(iface)
#define net_stats_update_tcp_seg_rsterr(iface)
#define net_stats_update_tcp_seg_rexmit(iface)
#endif /* CONFIG_NET_STATISTICS_TCP */

static inline void net_stats_update_per_proto_recv(struct net_if *iface,
						   enum net_ip_protocol proto)
{
	if (IS_ENABLED(CONFIG_NET_UDP) && proto == IPPROTO_UDP) {
		net_stats_update_udp_recv(iface);
	} else if (IS_ENABLED(CONFIG_NET_TCP) && proto == IPPROTO_TCP) {
		net_stats_update_tcp_seg_recv(iface);
	}
}

static inline void net_stats_update_per_proto_drop(struct net_if *iface,
						   enum net_ip_protocol proto)
{
	if (IS_ENABLED(CONFIG_NET_UDP) && proto == IPPROTO_UDP) {
		net_stats_update_udp_drop(iface);
	} else if (IS_ENABLED(CONFIG_NET_TCP) && proto == IPPROTO_TCP) {
		net_stats_update_tcp_seg_drop(iface);
	}
}

#if defined(CONFIG_NET_STATISTICS_MLD)
static inline void net_stats_update_ipv6_mld_recv(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6_mld.recv++);
}

static inline void net_stats_update_ipv6_mld_sent(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6_mld.sent++);
}

static inline void net_stats_update_ipv6_mld_drop(struct net_if *iface)
{
	UPDATE_STAT(iface, stats.ipv6_mld.drop++);
}
#else
#define net_stats_update_ipv6_mld_recv(iface)
#define net_stats_update_ipv6_mld_sent(iface)
#define net_stats_update_ipv6_mld_drop(iface)
#endif /* CONFIG_NET_STATISTICS_MLD */

#if defined(CONFIG_NET_CONTEXT_TIMESTAMP) && defined(CONFIG_NET_STATISTICS)
static inline void net_stats_update_tx_time(struct net_if *iface,
					    u32_t start_time,
					    u32_t end_time)
{
	u32_t diff = abs(end_time - start_time);

	UPDATE_STAT(iface, stats.tx_time.time_sum +=
		    SYS_CLOCK_HW_CYCLES_TO_NS64(diff) / 1000);
	UPDATE_STAT(iface, stats.tx_time.time_count += 1);
}
#else
static inline void net_stats_update_tx_time(struct net_if *iface,
					    u32_t start_time,
					    u32_t end_time)
{
	ARG_UNUSED(iface);
	ARG_UNUSED(start_time);
	ARG_UNUSED(end_time);
}
#endif /* CONFIG_NET_CONTEXT_TIMESTAMP && STATISTICS */

#if (NET_TC_COUNT > 1) && defined(CONFIG_NET_STATISTICS)
static inline void net_stats_update_tc_sent_pkt(struct net_if *iface, u8_t tc)
{
	UPDATE_STAT(iface, stats.tc.sent[tc].pkts++);
}

static inline void net_stats_update_tc_sent_bytes(struct net_if *iface,
						  u8_t tc, size_t bytes)
{
	UPDATE_STAT(iface, stats.tc.sent[tc].bytes += bytes);
}

static inline void net_stats_update_tc_sent_priority(struct net_if *iface,
						     u8_t tc, u8_t priority)
{
	UPDATE_STAT(iface, stats.tc.sent[tc].priority = priority);
}

#if defined(CONFIG_NET_CONTEXT_TIMESTAMP) && defined(CONFIG_NET_STATISTICS)
static inline void net_stats_update_tc_tx_time(struct net_if *iface,
					       u8_t tc,
					       u32_t start_time,
					       u32_t end_time)
{
	u32_t diff = abs(end_time - start_time);

	UPDATE_STAT(iface, stats.tc.sent[tc].tx_time.time_sum +=
		    SYS_CLOCK_HW_CYCLES_TO_NS64(diff) / 1000);
	UPDATE_STAT(iface, stats.tc.sent[tc].tx_time.time_count += 1);

	net_stats_update_tx_time(iface, start_time, end_time);
}
#else
static inline void net_stats_update_tc_tx_time(struct net_if *iface,
					       u8_t tc,
					       u32_t start_time,
					       u32_t end_time)
{
	ARG_UNUSED(iface);
	ARG_UNUSED(tc);
	ARG_UNUSED(start_time);
	ARG_UNUSED(end_time);
}
#endif /* CONFIG_NET_CONTEXT_TIMESTAMP && CONFIG_NET_STATISTICS */

static inline void net_stats_update_tc_recv_pkt(struct net_if *iface, u8_t tc)
{
	UPDATE_STAT(iface, stats.tc.recv[tc].pkts++);
}

static inline void net_stats_update_tc_recv_bytes(struct net_if *iface,
						  u8_t tc, size_t bytes)
{
	UPDATE_STAT(iface, stats.tc.recv[tc].bytes += bytes);
}

static inline void net_stats_update_tc_recv_priority(struct net_if *iface,
						     u8_t tc, u8_t priority)
{
	UPDATE_STAT(iface, stats.tc.recv[tc].priority = priority);
}
#else
#define net_stats_update_tc_sent_pkt(iface, tc)
#define net_stats_update_tc_sent_bytes(iface, tc, bytes)
#define net_stats_update_tc_sent_priority(iface, tc, priority)
#define net_stats_update_tc_recv_pkt(iface, tc)
#define net_stats_update_tc_recv_bytes(iface, tc, bytes)
#define net_stats_update_tc_recv_priority(iface, tc, priority)

#if defined(CONFIG_NET_CONTEXT_TIMESTAMP) && defined(CONFIG_NET_STATISTICS)
static inline void net_stats_update_tc_tx_time(struct net_if *iface,
					       u8_t pkt_priority,
					       u32_t start_time,
					       u32_t end_time)
{
	ARG_UNUSED(pkt_priority);

	net_stats_update_tx_time(iface, start_time, end_time);
}
#else
static inline void net_stats_update_tc_tx_time(struct net_if *iface,
					       u8_t pkt_priority,
					       u32_t start_time,
					       u32_t end_time)
{
	ARG_UNUSED(iface);
	ARG_UNUSED(pkt_priority);
	ARG_UNUSED(start_time);
	ARG_UNUSED(end_time);
}
#endif /* CONFIG_NET_CONTEXT_TIMESTAMP && CONFIG_NET_STATISTICS */
#endif /* NET_TC_COUNT > 1 */

#if defined(CONFIG_NET_STATISTICS_PERIODIC_OUTPUT)
/* A simple periodic statistic printer, used only in net core */
void net_print_statistics_all(void);
void net_print_statistics_iface(struct net_if *iface);
void net_print_statistics(void);
#else
#define net_print_statistics_all()
#define net_print_statistics_iface(iface)
#define net_print_statistics()
#endif

#endif /* __NET_STATS_H__ */