From 06e2b421af496b92ca29046fd513d2f506b175e6 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Tue, 13 Dec 2016 14:50:31 +0100 Subject: [PATCH] net: statistics: Make statistics calculation fully private Let's change from macros to inlined function to make things nicer. Change-Id: Ie98e0667613961b03c84ca60bc551d0f473765f6 Signed-off-by: Tomasz Bursztyka --- include/net/net_context.h | 21 ---- include/net/net_stats.h | 27 ----- subsys/net/ip/connection.c | 6 +- subsys/net/ip/icmpv4.c | 14 +-- subsys/net/ip/icmpv6.c | 16 +-- subsys/net/ip/ipv6.c | 34 ++++-- subsys/net/ip/net_core.c | 26 ++-- subsys/net/ip/net_if.c | 16 +++ subsys/net/ip/net_shell.c | 7 +- subsys/net/ip/net_stats.c | 4 +- subsys/net/ip/net_stats.h | 241 +++++++++++++++++++++++++++++++++++++ subsys/net/ip/rpl.c | 61 +++++----- 12 files changed, 345 insertions(+), 128 deletions(-) diff --git a/include/net/net_context.h b/include/net/net_context.h index cb745f4c269..dc8796defbe 100644 --- a/include/net/net_context.h +++ b/include/net/net_context.h @@ -631,27 +631,6 @@ int net_context_recv(struct net_context *context, int32_t timeout, void *user_data); -/** - * @brief Internal function that is called when network packet is sent - * successfully. - * - * @param context The network context to use. - * @param token User supplied token tied to the net_buf that was sent. - * @param err_code Error code - */ -static inline void net_context_send_cb(struct net_context *context, - void *token, - int err_code) -{ - if (context->send_cb) { - context->send_cb(context, err_code, token, context->user_data); - } - - if (net_context_get_ip_proto(context) == IPPROTO_UDP) { - NET_STATS_UDP(++net_stats.udp.sent); - } -} - typedef void (*net_context_cb_t)(struct net_context *context, void *user_data); /** diff --git a/include/net/net_stats.h b/include/net/net_stats.h index 2fce67d1fc3..5cdea2790a1 100644 --- a/include/net/net_stats.h +++ b/include/net/net_stats.h @@ -30,13 +30,6 @@ extern "C" { #endif -#if defined(CONFIG_NET_STATISTICS) -#define NET_STATS(s) s -extern struct net_stats net_stats; -#else -#define NET_STATS(s) -#endif - typedef uint32_t net_stats_t; struct net_stats_ip { @@ -202,39 +195,24 @@ struct net_stats { #if defined(CONFIG_NET_IPV6) struct net_stats_ip ipv6; -#define NET_STATS_IPV6(s) NET_STATS(s) -#else -#define NET_STATS_IPV6(s) #endif #if defined(CONFIG_NET_IPV4) struct net_stats_ip ipv4; -#define NET_STATS_IPV4(s) NET_STATS(s) -#else -#define NET_STATS_IPV4(s) #endif struct net_stats_icmp icmp; #if defined(CONFIG_NET_TCP) struct net_stats_tcp tcp; -#define NET_STATS_TCP(s) NET_STATS(s) -#else -#define NET_STATS_TCP(s) #endif #if defined (CONFIG_NET_UDP) struct net_stats_udp udp; -#define NET_STATS_UDP(s) NET_STATS(s) -#else -#define NET_STATS_UDP(s) #endif #if defined(CONFIG_NET_IPV6_ND) struct net_stats_ipv6_nd ipv6_nd; -#define NET_STATS_IPV6_ND(s) NET_STATS(s) -#else -#define NET_STATS_IPV6_ND(s) #endif #if defined(CONFIG_NET_RPL_STATS) @@ -255,11 +233,6 @@ struct net_stats { struct net_stats_rpl_dao dao; struct net_stats_rpl_dao_ack dao_ack; } rpl; -#define NET_STATS_RPL(s) NET_STATS(s) -#define NET_STATS_RPL_DIS(s) NET_STATS(s) -#else -#define NET_STATS_RPL(s) -#define NET_STATS_RPL_DIS(s) #endif /* CONFIG_NET_RPL_STATS */ }; diff --git a/subsys/net/ip/connection.c b/subsys/net/ip/connection.c index 276e42a83f7..febfa39fa42 100644 --- a/subsys/net/ip/connection.c +++ b/subsys/net/ip/connection.c @@ -28,12 +28,12 @@ #include #include -#include #include "net_private.h" #include "icmpv6.h" #include "icmpv4.h" #include "connection.h" +#include "net_stats.h" /** Is this connection used or not */ #define NET_CONN_IN_USE BIT(0) @@ -754,7 +754,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf) } if (proto == IPPROTO_UDP) { - NET_STATS_UDP(++net_stats.udp.recv); + net_stats_update_udp_recv(); } return NET_OK; @@ -785,7 +785,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf) drop: if (proto == IPPROTO_UDP) { - NET_STATS_UDP(++net_stats.udp.drop); + net_stats_update_udp_drop(); } return NET_DROP; diff --git a/subsys/net/ip/icmpv4.c b/subsys/net/ip/icmpv4.c index f0d53c04aa2..74e48841b5f 100644 --- a/subsys/net/ip/icmpv4.c +++ b/subsys/net/ip/icmpv4.c @@ -28,9 +28,9 @@ #include #include #include -#include #include "net_private.h" #include "icmpv4.h" +#include "net_stats.h" static inline enum net_verdict handle_echo_request(struct net_buf *buf) { @@ -66,11 +66,11 @@ static inline enum net_verdict handle_echo_request(struct net_buf *buf) #endif /* NET_DEBUG > 0 */ if (net_send_data(buf) < 0) { - NET_STATS(++net_stats.icmp.drop); + net_stats_update_icmp_drop(); return NET_DROP; } - NET_STATS(++net_stats.icmp.sent); + net_stats_update_icmp_sent(); return NET_OK; } @@ -159,12 +159,12 @@ int net_icmpv4_send_echo_request(struct net_if *iface, sizeof(struct net_icmpv4_echo_req)); if (net_send_data(buf) >= 0) { - NET_STATS(++net_stats.icmp.sent); + net_stats_update_icmp_sent(); return 0; } net_nbuf_unref(buf); - NET_STATS(++net_stats.icmp.drop); + net_stats_update_icmp_drop(); return -EIO; } @@ -268,13 +268,13 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) #endif /* NET_DEBUG > 0 */ if (net_send_data(buf) >= 0) { - NET_STATS(++net_stats.icmp.sent); + net_stats_update_icmp_sent(); return -EIO; } drop: net_nbuf_unref(buf); - NET_STATS(++net_stats.icmp.drop); + net_stats_update_icmp_drop(); /* Note that we always return < 0 so that the caller knows to * discard the original buffer. diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index 27d53b0f003..97e1781b921 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -29,10 +29,10 @@ #include #include #include -#include #include "net_private.h" #include "icmpv6.h" #include "ipv6.h" +#include "net_stats.h" static sys_slist_t handlers; @@ -163,14 +163,14 @@ static enum net_verdict handle_echo_request(struct net_buf *orig) goto drop; } - NET_STATS(++net_stats.icmp.sent); + net_stats_update_icmp_sent(); return NET_DROP; drop: net_nbuf_unref(buf); + net_stats_update_icmp_drop(); - NET_STATS(++net_stats.icmp.drop); return NET_DROP; } @@ -279,13 +279,13 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, #endif /* NET_DEBUG > 0 */ if (net_send_data(buf) >= 0) { - NET_STATS(++net_stats.icmp.sent); + net_stats_update_icmp_sent(); return -EIO; } drop: net_nbuf_unref(buf); - NET_STATS(++net_stats.icmp.drop); + net_stats_update_icmp_drop(); /* Note that we always return < 0 so that the caller knows to * discard the original buffer. @@ -342,12 +342,12 @@ int net_icmpv6_send_echo_request(struct net_if *iface, #endif /* NET_DEBUG > 0 */ if (net_send_data(buf) >= 0) { - NET_STATS(++net_stats.icmp.sent); + net_stats_update_icmp_sent(); return 0; } net_nbuf_unref(buf); - NET_STATS(++net_stats.icmp.drop); + net_stats_update_icmp_drop(); return -EIO; } @@ -368,7 +368,7 @@ enum net_verdict net_icmpv6_input(struct net_buf *buf, uint16_t len, } if (cb->type == type && (cb->code == code || cb->code == 0)) { - NET_STATS(++net_stats.icmp.recv); + net_stats_update_icmp_recv(); return cb->handler(buf); } } diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index 3981b5186e4..d2b376a721f 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -40,6 +40,7 @@ #include "6lo.h" #include "route.h" #include "rpl.h" +#include "net_stats.h" #if defined(CONFIG_NET_IPV6_ND) @@ -833,12 +834,14 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src, goto drop; } - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent); + net_stats_update_ipv6_nd_sent(); + return 0; drop: net_nbuf_unref(buf); - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop); + net_stats_update_ipv6_nd_drop(); + return -EINVAL; } @@ -856,7 +859,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) &NET_IPV6_BUF(buf)->dst, &NET_ICMPV6_NS_BUF(buf)->tgt); - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.recv); + net_stats_update_ipv6_nd_recv(); if ((total_len < (sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr) + @@ -1011,7 +1014,8 @@ send_na: return NET_DROP; drop: - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop); + net_stats_update_ipv6_nd_drop(); + return NET_DROP; } @@ -1278,7 +1282,7 @@ static enum net_verdict handle_na_input(struct net_buf *buf) &NET_IPV6_BUF(buf)->dst, &NET_ICMPV6_NS_BUF(buf)->tgt); - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.recv); + net_stats_update_ipv6_nd_recv(); if ((total_len < (sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr) + @@ -1357,11 +1361,13 @@ static enum net_verdict handle_na_input(struct net_buf *buf) goto drop; } - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent); + net_stats_update_ipv6_nd_sent(); + return NET_OK; drop: - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop); + net_stats_update_ipv6_nd_drop(); + return NET_DROP; } @@ -1494,13 +1500,14 @@ int net_ipv6_send_ns(struct net_if *iface, goto drop; } - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent); + net_stats_update_ipv6_nd_sent(); return 0; drop: net_nbuf_unref(buf); - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop); + net_stats_update_ipv6_nd_drop(); + return -EINVAL; } @@ -1566,13 +1573,14 @@ int net_ipv6_send_rs(struct net_if *iface) goto drop; } - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent); + net_stats_update_ipv6_nd_sent(); return 0; drop: net_nbuf_unref(buf); - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop); + net_stats_update_ipv6_nd_drop(); + return -EINVAL; } @@ -1899,7 +1907,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) &NET_IPV6_BUF(buf)->src, &NET_IPV6_BUF(buf)->dst); - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.recv); + net_stats_update_ipv6_nd_recv(); if ((total_len < (sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr) + @@ -2074,7 +2082,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) return NET_OK; drop: - NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop); + net_stats_update_ipv6_nd_drop(); return NET_DROP; } diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 616006ae74c..7334f6d68a0 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -207,7 +207,7 @@ static inline enum net_verdict process_ipv6_pkt(struct net_buf *buf) if (real_len != pkt_len) { NET_DBG("IPv6 packet size %d buf len %d", pkt_len, real_len); - NET_STATS_IPV6(++net_stats.ipv6.drop); + net_stats_update_ipv6_drop(); goto drop; } @@ -221,8 +221,8 @@ static inline enum net_verdict process_ipv6_pkt(struct net_buf *buf) #endif /* NET_DEBUG > 0 */ if (net_is_ipv6_addr_mcast(&hdr->src)) { - NET_STATS_IPV6(++net_stats.ipv6.drop); NET_DBG("Dropping src multicast packet"); + net_stats_update_ipv6_drop(); goto drop; } @@ -231,7 +231,7 @@ static inline enum net_verdict process_ipv6_pkt(struct net_buf *buf) !net_is_ipv6_addr_mcast(&hdr->dst) && !net_is_ipv6_addr_loopback(&hdr->dst)) { NET_DBG("IPv6 packet in buf %p not for me", buf); - NET_STATS_IPV6(++net_stats.ipv6.drop); + net_stats_update_ipv6_drop(); goto drop; } @@ -380,7 +380,7 @@ bad_hdr: offset - 1); NET_DBG("Unknown next header type"); - NET_STATS(++net_stats.ip_errors.protoerr); + net_stats_update_ip_errors_protoerr(); return NET_DROP; } @@ -457,7 +457,7 @@ static inline enum net_verdict process_ipv4_pkt(struct net_buf *buf) } drop: - NET_STATS(++net_stats.ipv4.drop); + net_stats_update_ipv4_drop(); return NET_DROP; } #endif /* CONFIG_NET_IPV4 */ @@ -476,7 +476,7 @@ static inline enum net_verdict process_data(struct net_buf *buf, if (!buf->frags || !buf->pool->user_data_size) { NET_DBG("Corrupted buffer (frags %p, data size %u)", buf->frags, buf->pool->user_data_size); - NET_STATS(++net_stats.processing_error); + net_stats_update_processing_error(); return NET_DROP; } @@ -486,7 +486,7 @@ static inline enum net_verdict process_data(struct net_buf *buf, if (ret != NET_CONTINUE) { if (ret == NET_DROP) { NET_DBG("Buffer %p discarded by L2", buf); - NET_STATS(++net_stats.processing_error); + net_stats_update_processing_error(); } return ret; @@ -497,13 +497,13 @@ static inline enum net_verdict process_data(struct net_buf *buf, switch (NET_IPV6_BUF(buf)->vtc & 0xf0) { #if defined(CONFIG_NET_IPV6) case 0x60: - NET_STATS_IPV6(++net_stats.ipv6.recv); + net_stats_update_ipv6_recv(); net_nbuf_set_family(buf, PF_INET6); return process_ipv6_pkt(buf); #endif #if defined(CONFIG_NET_IPV4) case 0x40: - NET_STATS_IPV4(++net_stats.ipv4.recv); + net_stats_update_ipv4_recv(); net_nbuf_set_family(buf, PF_INET); return process_ipv4_pkt(buf); #endif @@ -511,8 +511,8 @@ static inline enum net_verdict process_data(struct net_buf *buf, NET_DBG("Unknown IP family packet (0x%x)", NET_IPV6_BUF(buf)->vtc & 0xf0); - NET_STATS(++net_stats.ip_errors.protoerr); - NET_STATS(++net_stats.ip_errors.vhlerr); + net_stats_update_ip_errors_protoerr(); + net_stats_update_ip_errors_vhlerr(); return NET_DROP; } @@ -664,10 +664,10 @@ int net_send_data(struct net_buf *buf) #if defined(CONFIG_NET_STATISTICS) switch (net_nbuf_family(buf)) { case AF_INET: - NET_STATS_IPV4(++net_stats.ipv4.sent); + net_stats_update_ipv4_sent(); break; case AF_INET6: - NET_STATS_IPV6(++net_stats.ipv6.sent); + net_stats_update_ipv6_sent(); break; } #endif diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index f8561ce101a..9a452a68d8a 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -33,6 +33,8 @@ #include "ipv6.h" #include "rpl.h" +#include "net_stats.h" + #define REACHABLE_TIME (30 * MSEC_PER_SEC) /* in ms */ #define MIN_RANDOM_FACTOR (1/2) #define MAX_RANDOM_FACTOR (3/2) @@ -61,6 +63,20 @@ static sys_slist_t link_callbacks; #define debug_check_packet(...) #endif +static inline void net_context_send_cb(struct net_context *context, + void *token, int status) +{ + if (context->send_cb) { + context->send_cb(context, status, token, context->user_data); + } + +#if defined(CONFIG_NET_UDP) + if (net_context_get_ip_proto(context) == IPPROTO_UDP) { + net_stats_update_udp_sent(); + } +#endif +} + static void net_if_tx_thread(struct net_if *iface) { const struct net_if_api *api = iface->dev->driver_api; diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 314a34353f8..2fef97a4078 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -24,7 +24,6 @@ #include #include -#include #include #include "route.h" @@ -36,6 +35,7 @@ #endif #include "net_shell.h" +#include "net_stats.h" /* * Set NET_DEBUG in order to activate address printing functions @@ -376,9 +376,8 @@ static void iface_per_mcast_route_cb(struct net_if *iface, void *user_data) #endif /* CONFIG_NET_ROUTE_MCAST */ #if defined(CONFIG_NET_STATISTICS) -#define GET_STAT(s) net_stats.s -static inline void net_print_statistics(void) +static inline void net_shell_print_statistics(void) { #if defined(CONFIG_NET_IPV6) printf("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d\n", @@ -757,7 +756,7 @@ static int shell_cmd_stats(int argc, char *argv[]) ARG_UNUSED(argv); #if defined(CONFIG_NET_STATISTICS) - net_print_statistics(); + net_shell_print_statistics(); #else printf("Network statistics not compiled in.\n"); #endif diff --git a/subsys/net/ip/net_stats.c b/subsys/net/ip/net_stats.c index 3d6ffa54078..ef8d2bf4073 100644 --- a/subsys/net/ip/net_stats.c +++ b/subsys/net/ip/net_stats.c @@ -21,11 +21,11 @@ #include #include #include -#include + +#include "net_stats.h" struct net_stats net_stats; -#define GET_STAT(s) net_stats.s #define PRINT_STATISTICS_INTERVAL (30 * MSEC_PER_SEC) void net_print_statistics(void) diff --git a/subsys/net/ip/net_stats.h b/subsys/net/ip/net_stats.h index f4d2c73a552..bb18080e8df 100644 --- a/subsys/net/ip/net_stats.h +++ b/subsys/net/ip/net_stats.h @@ -19,8 +19,249 @@ #if defined(CONFIG_NET_STATISTICS) +#include + extern struct net_stats net_stats; +#define GET_STAT(s) net_stats.s + +/* Core stats */ + +static inline void net_stats_update_processing_error(void) +{ + net_stats.processing_error++; +} + +static inline void net_stats_update_ip_errors_protoerr(void) +{ + net_stats.ip_errors.protoerr++; +} + +static inline void net_stats_update_ip_errors_vhlerr(void) +{ + net_stats.ip_errors.vhlerr++; +} +#else +#define net_stats_update_processing_error() +#define net_stats_update_ip_errors_protoerr() +#define net_stats_update_ip_errors_vhlerr() +#endif /* CONFIG_NET_STATISTICS */ + +#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_STATISTICS) +/* IPv6 stats */ + +static inline void net_stats_update_ipv6_sent(void) +{ + net_stats.ipv6.sent++; +} + +static inline void net_stats_update_ipv6_recv(void) +{ + net_stats.ipv6.recv++; +} + +static inline void net_stats_update_ipv6_drop(void) +{ + net_stats.ipv6.drop++; +} +#else +#define net_stats_update_ipv6_drop() +#define net_stats_update_ipv6_sent() +#define net_stats_update_ipv6_recv() +#endif /* CONFIG_NET_IPV6 */ + +#if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_STATISTICS) +/* IPv6 Neighbor Discovery stats*/ + +static inline void net_stats_update_ipv6_nd_sent(void) +{ + net_stats.ipv6_nd.sent++; +} + +static inline void net_stats_update_ipv6_nd_recv(void) +{ + net_stats.ipv6_nd.recv++; +} + +static inline void net_stats_update_ipv6_nd_drop(void) +{ + net_stats.ipv6_nd.drop++; +} +#else +#define net_stats_update_ipv6_nd_sent() +#define net_stats_update_ipv6_nd_recv() +#define net_stats_update_ipv6_nd_drop() +#endif /* CONFIG_NET_IPV6_ND */ + +#if defined(CONFIG_NET_IPV4) && defined(CONFIG_NET_STATISTICS) +/* IPv4 stats */ + +static inline void net_stats_update_ipv4_drop(void) +{ + net_stats.ipv4.drop++; +} + +static inline void net_stats_update_ipv4_sent(void) +{ + net_stats.ipv4.sent++; +} + +static inline void net_stats_update_ipv4_recv(void) +{ + net_stats.ipv4.recv++; +} +#else +#define net_stats_update_ipv4_drop() +#define net_stats_update_ipv4_sent() +#define net_stats_update_ipv4_recv() +#endif /* CONFIG_NET_IPV4 */ + +#if defined(CONFIG_NET_STATISTICS) +/* Common ICMPv4/ICMPv6 stats */ +static inline void net_stats_update_icmp_sent(void) +{ + net_stats.icmp.sent++; +} + +static inline void net_stats_update_icmp_recv(void) +{ + net_stats.icmp.recv++; +} + +static inline void net_stats_update_icmp_drop(void) +{ + net_stats.icmp.drop++; +} +#else +#define net_stats_update_icmp_sent() +#define net_stats_update_icmp_recv() +#define net_stats_update_icmp_drop() +#endif + +#if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_STATISTICS) +/* UDP stats */ +static inline void net_stats_update_udp_sent(void) +{ + net_stats.udp.sent++; +} + +static inline void net_stats_update_udp_recv(void) +{ + net_stats.udp.recv++; +} + +static inline void net_stats_update_udp_drop(void) +{ + net_stats.udp.drop++; +} +#else +#define net_stats_update_udp_sent() +#define net_stats_update_udp_recv() +#define net_stats_update_udp_drop() +#endif /* CONFIG_NET_UDP */ + +#if defined(CONFIG_NET_RPL_STATS) +/* RPL stats */ +static inline void net_stats_update_rpl_resets(void) +{ + net_stats.rpl.resets++; +} + +static inline void net_stats_update_rpl_mem_overflows(void) +{ + net_stats.rpl.mem_overflows++; +} + +static inline void net_stats_update_rpl_parent_switch(void) +{ + net_stats.rpl.parent_switch++; +} + +static inline void net_stats_update_rpl_local_repairs(void) +{ + net_stats.rpl.local_repairs++; +} + +static inline void net_stats_update_rpl_global_repairs(void) +{ + net_stats.rpl.global_repairs++; +} + +static inline void net_stats_update_rpl_root_repairs(void) +{ + net_stats.rpl.root_repairs++; +} + +static inline void net_stats_update_rpl_malformed_msgs(void) +{ + net_stats.rpl.malformed_msgs++; +} + +static inline void net_stats_update_rpl_forward_errors(void) +{ + net_stats.rpl.forward_errors++; +} + +static inline void net_stats_update_rpl_loop_errors(void) +{ + net_stats.rpl.loop_errors++; +} + +static inline void net_stats_update_rpl_loop_warnings(void) +{ + net_stats.rpl.loop_warnings++; +} + +static inline void net_stats_update_rpl_dis_sent(void) +{ + net_stats.rpl.dis.sent++; +} + +static inline void net_stats_update_rpl_dio_sent(void) +{ + net_stats.rpl.dio.sent++; +} + +static inline void net_stats_update_rpl_dao_sent(void) +{ + net_stats.rpl.dao.sent++; +} + +static inline void net_stats_update_rpl_dao_forwarded(void) +{ + net_stats.rpl.dao.forwarded++; +} + +static inline void net_stats_update_rpl_dao_ack_sent(void) +{ + net_stats.rpl.dao_ack.sent++; +} + +static inline void net_stats_update_rpl_dao_ack_recv(void) +{ + net_stats.rpl.dao_ack.recv++; +} +#else +#define net_stats_update_rpl_resets() +#define net_stats_update_rpl_mem_overflows() +#define net_stats_update_rpl_parent_switch() +#define net_stats_update_rpl_local_repairs() +#define net_stats_update_rpl_global_repairs() +#define net_stats_update_rpl_root_repairs() +#define net_stats_update_rpl_malformed_msgs() +#define net_stats_update_rpl_forward_errors() +#define net_stats_update_rpl_loop_errors() +#define net_stats_update_rpl_loop_warnings() +#define net_stats_update_rpl_dis_sent() +#define net_stats_update_rpl_dio_sent() +#define net_stats_update_rpl_dao_sent() +#define net_stats_update_rpl_dao_forwarded() +#define net_stats_update_rpl_dao_ack_sent() +#define net_stats_update_rpl_dao_ack_recv() +#endif + +#if defined(CONFIG_NET_STATISTICS) + /* A simple periodic statistic printer, used only in net core */ void net_print_statistics(void); diff --git a/subsys/net/ip/rpl.c b/subsys/net/ip/rpl.c index a2a7ffdd067..22faab449b9 100644 --- a/subsys/net/ip/rpl.c +++ b/subsys/net/ip/rpl.c @@ -59,7 +59,6 @@ #include #include -#include #include "net_private.h" #include "ipv6.h" @@ -67,6 +66,7 @@ #include "nbr.h" #include "route.h" #include "rpl.h" +#include "net_stats.h" #define NET_RPL_DIO_GROUNDED 0x80 #define NET_RPL_DIO_MOP_SHIFT 3 @@ -574,8 +574,8 @@ int net_rpl_dio_send(struct net_if *iface, net_sprint_ipv6_addr(dst)); } - NET_STATS_RPL(++net_stats.icmp.sent); - NET_STATS_RPL(++net_stats.rpl.dio.sent); + net_stats_update_icmp_sent(); + net_stats_update_rpl_dio_sent(); return 0; } @@ -705,7 +705,7 @@ static void net_rpl_dio_reset_timer(struct net_rpl_instance *instance) new_dio_interval(instance); } - NET_STATS_RPL(net_stats.rpl.resets++); + net_stats_update_rpl_resets(); } static inline void send_dis_all_interfaces(struct net_if *iface, @@ -765,8 +765,8 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface) NET_DBG("Sent a %s DIS to %s", dst ? "unicast" : "multicast", net_sprint_ipv6_addr(dst_addr)); - NET_STATS_RPL(++net_stats.icmp.sent); - NET_STATS_RPL_DIS(++net_stats.rpl.dis.sent); + net_stats_update_icmp_sent(); + net_stats_update_rpl_dis_sent(); } else { net_nbuf_unref(buf); } @@ -994,7 +994,8 @@ static struct net_rpl_dag *alloc_dag(uint8_t instance_id, instance = net_rpl_alloc_instance(instance_id); if (!instance) { NET_DBG("Cannot allocate instance id %d", instance_id); - NET_STATS_RPL(net_stats.rpl.mem_overflows++); + net_stats_update_rpl_mem_overflows(); + return NULL; } } @@ -1186,7 +1187,7 @@ static void net_rpl_reset_dio_timer(struct net_rpl_instance *instance) new_dio_interval(instance); } - NET_STATS_RPL(net_stats.rpl.resets++); + net_stats_update_rpl_resets(); } static @@ -1840,7 +1841,7 @@ struct net_rpl_dag *net_rpl_select_dag(struct net_if *iface, NET_DBG("Changed preferred parent, rank changed from %u to %u", old_rank, best_dag->rank); - NET_STATS_RPL(net_stats.rpl.parent_switch++); + net_stats_update_rpl_parent_switch(); if (instance->mop != NET_RPL_MOP_NO_DOWNWARD_ROUTES) { if (last_parent) { @@ -1914,7 +1915,7 @@ static void net_rpl_local_repair(struct net_if *iface, net_rpl_reset_dio_timer(instance); - NET_STATS_RPL(net_stats.rpl.local_repairs++); + net_stats_update_rpl_local_repairs(); } /* Return true if parent is kept, false if it is dropped */ @@ -1991,7 +1992,7 @@ static bool net_rpl_repair_root(uint8_t instance_id) return false; } - NET_STATS_RPL(net_stats.rpl.root_repairs++); + net_stats_update_rpl_root_repairs(); net_rpl_lollipop_increment(&instance->current_dag->version); net_rpl_lollipop_increment(&instance->dtsn); @@ -2067,7 +2068,7 @@ static void global_repair(struct net_if *iface, NET_DBG("Participating in a global repair version %d rank %d", dag->version, dag->rank); - NET_STATS_RPL(net_stats.rpl.global_repairs++); + net_stats_update_rpl_global_repairs(); } #define net_rpl_print_parent_info(parent, instance) \ @@ -2757,7 +2758,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) if (!frag && pos) { NET_DBG("Invalid DIO packet"); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -2767,7 +2768,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) case NET_RPL_OPTION_DAG_METRIC_CONTAINER: if (len < 6) { NET_DBG("Invalid DAG MC len %d", len); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -2808,7 +2809,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) if (len < 9) { NET_DBG("Invalid destination prefix " "option len %d", len); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -2832,7 +2833,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) } else { NET_DBG("Invalid route info option len %d", len); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -2841,7 +2842,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) if (len != 16) { NET_DBG("Invalid DAG configuration option " "len %d", len); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -2882,7 +2883,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) if (len != 32) { NET_DBG("Invalid DAG prefix info len %d != 32", len); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -3027,8 +3028,8 @@ int net_rpl_dao_send(struct net_if *iface, if (ret >= 0) { net_rpl_dao_info(buf, src, dst, prefix); - NET_STATS_RPL(++net_stats.icmp.sent); - NET_STATS_RPL(++net_stats.rpl.dao.sent); + net_stats_update_icmp_sent(); + net_stats_update_rpl_dao_sent(); } else { net_nbuf_unref(buf); } @@ -3076,8 +3077,8 @@ static inline int dao_forward(struct net_if *iface, ret = net_send_data(buf); if (ret >= 0) { - NET_STATS_RPL(++net_stats.icmp.sent); - NET_STATS_RPL(++net_stats.rpl.dao.forwarded); + net_stats_update_icmp_sent(); + net_stats_update_rpl_dao_forwarded(); } else { net_nbuf_unref(buf); } @@ -3123,8 +3124,8 @@ static int dao_ack_send(struct net_buf *orig, net_rpl_dao_ack_info(buf, src, dst, instance->instance_id, sequence); - NET_STATS_RPL(++net_stats.icmp.sent); - NET_STATS_RPL(++net_stats.rpl.dao_ack.sent); + net_stats_update_icmp_sent(); + net_stats_update_rpl_dao_ack_sent(); } else { net_nbuf_unref(buf); } @@ -3274,7 +3275,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) if (!frag && pos) { NET_DBG("Invalid DAO packet"); - NET_STATS_RPL(net_stats.rpl.malformed_msgs++); + net_stats_update_rpl_malformed_msgs(); goto out; } @@ -3387,7 +3388,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) route = net_rpl_add_route(dag, net_nbuf_iface(buf), &addr, target_len, dao_sender); if (!route) { - NET_STATS_RPL(net_stats.rpl.mem_overflows++); + net_stats_update_rpl_mem_overflows(); NET_DBG("Could not add a route after receiving a DAO"); return NET_DROP; @@ -3425,7 +3426,7 @@ static enum net_verdict handle_dao_ack(struct net_buf *buf) { net_rpl_info(buf, "Destination Advertisement Object Ack"); - NET_STATS_RPL(++net_stats.rpl.dao_ack.recv); + net_stats_update_rpl_dao_ack_recv(); return NET_DROP; } @@ -3584,7 +3585,7 @@ bool net_rpl_verify_header(struct net_buf *buf, net_route_del(route); } - NET_STATS_RPL(net_stats.rpl.forward_errors++); + net_stats_update_rpl_forward_errors(); /* Trigger DAO retransmission */ net_rpl_reset_dio_timer(instance); @@ -3618,7 +3619,7 @@ bool net_rpl_verify_header(struct net_buf *buf, sender_closer); if (flags & NET_RPL_HDR_OPT_RANK_ERR) { - NET_STATS_RPL(net_stats.rpl.loop_errors++); + net_stats_update_rpl_loop_errors(); NET_DBG("Rank error signalled in RPL option!"); @@ -3631,7 +3632,7 @@ bool net_rpl_verify_header(struct net_buf *buf, } NET_DBG("Single error tolerated."); - NET_STATS_RPL(net_stats.rpl.loop_warnings++); + net_stats_update_rpl_loop_warnings(); net_nbuf_write_u8(buf, buf->frags, offset, pos, flags | NET_RPL_HDR_OPT_RANK_ERR);