diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 1d5dd4a22aa4..d1336828be5b 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -29,6 +29,7 @@ PSEUDOMODULES += gnrc_sixloenc PSEUDOMODULES += gnrc_sixlowpan_border_router_default PSEUDOMODULES += gnrc_sixlowpan_default PSEUDOMODULES += gnrc_sixlowpan_frag_hint +PSEUDOMODULES += gnrc_sixlowpan_frag_stats PSEUDOMODULES += gnrc_sixlowpan_iphc_nhc PSEUDOMODULES += gnrc_sixlowpan_nd_border_router PSEUDOMODULES += gnrc_sixlowpan_router diff --git a/sys/include/net/gnrc/sixlowpan/frag.h b/sys/include/net/gnrc/sixlowpan/frag.h index 75279c161d7e..59417ea6a845 100644 --- a/sys/include/net/gnrc/sixlowpan/frag.h +++ b/sys/include/net/gnrc/sixlowpan/frag.h @@ -148,6 +148,29 @@ typedef struct { #endif /* MODULE_GNRC_SIXLOWPAN_FRAG_HINT */ } gnrc_sixlowpan_msg_frag_t; +#if defined(MODULE_GNRC_SIXLOWPAN_FRAG_STATS) || DOXYGEN +/** + * @brief Statistics on fragmentation and reassembly + * + * @note Only available with the `gnrc_sixlowpan_frag_stats` module + */ +typedef struct { + unsigned rbuf_full; /**< counts the number of events were the + * reassembly buffer is full */ +#if defined(MODULE_GNRC_SIXLOWPAN_FRAG_VRB) || DOXYGEN + unsigned vrb_full; /**< counts the number of events were the virtual + * reassembly buffer is full */ +#endif +} gnrc_sixlowpan_frag_stats_t; + +/** + * @brief Get the current statistics on fragmentation and reassembly + * + * @return The current statistics on fragmentation and reassembly + */ +gnrc_sixlowpan_frag_stats_t *gnrc_sixlowpan_frag_stats_get(void); +#endif + /** * @brief Allocates a @ref gnrc_sixlowpan_msg_frag_t object * diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c index f7dad3da60f3..993b73c96d7b 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c @@ -88,6 +88,15 @@ enum { RBUF_ADD_DUPLICATE, }; +#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_STATS +static gnrc_sixlowpan_frag_stats_t _stats; + +gnrc_sixlowpan_frag_stats_t *gnrc_sixlowpan_frag_stats_get(void) +{ + return &_stats; +} +#endif + static int _check_fragments(gnrc_sixlowpan_rbuf_base_t *entry, size_t frag_size, size_t offset) { @@ -190,6 +199,9 @@ static int _rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt, dst, netif_hdr->dst_l2addr_len, datagram_size, tag, page)) == NULL) { DEBUG("6lo rbuf: reassembly buffer full.\n"); +#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_STATS + _stats.rbuf_full++; +#endif gnrc_pktbuf_release(pkt); return RBUF_ADD_ERROR; } diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/vrb/gnrc_sixlowpan_frag_vrb.c b/sys/net/gnrc/network_layer/sixlowpan/frag/vrb/gnrc_sixlowpan_frag_vrb.c index cfd4023e2352..ae27b6e5d006 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/vrb/gnrc_sixlowpan_frag_vrb.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/vrb/gnrc_sixlowpan_frag_vrb.c @@ -73,6 +73,11 @@ gnrc_sixlowpan_frag_vrb_t *gnrc_sixlowpan_frag_vrb_add( break; } } +#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_STATS + if (vrbe == NULL) { + gnrc_sixlowpan_frag_stats_get()->vrb_full++; + } +#endif return vrbe; }