From ed9f43ab3a337b20dcba331a788342559c0da3e6 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Wed, 5 Feb 2020 16:14:46 +0100 Subject: [PATCH] gnrc_sixlowpan_frag_stats: add average fragments per datagram statistic --- sys/include/net/gnrc/sixlowpan/frag/stats.h | 2 ++ .../sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c | 18 ++++++++++++++++++ sys/shell/commands/sc_gnrc_6lo_frag_stats.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/sys/include/net/gnrc/sixlowpan/frag/stats.h b/sys/include/net/gnrc/sixlowpan/frag/stats.h index 4c7b657e3d..7ca9636c36 100644 --- a/sys/include/net/gnrc/sixlowpan/frag/stats.h +++ b/sys/include/net/gnrc/sixlowpan/frag/stats.h @@ -35,6 +35,8 @@ typedef struct { * reassembly buffer is full */ unsigned frag_full; /**< counts the number of events that there where * no @ref gnrc_sixlowpan_frag_fb_t available */ + unsigned datagrams; /**< reassembled datagrams */ + unsigned fragments; /**< total fragments of reassembled fragments */ #if defined(MODULE_GNRC_SIXLOWPAN_FRAG_VRB) || DOXYGEN unsigned vrb_full; /**< counts the number of events where the virtual * reassembly buffer is full */ diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c index c4cd26d8ee..f29bb07dc4 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c @@ -580,6 +580,20 @@ static void _tmp_rm(gnrc_sixlowpan_frag_rb_t *rbuf) #endif /* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER */ } +#if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_STATS) +static inline unsigned _count_frags(gnrc_sixlowpan_frag_rb_t *rbuf) +{ + unsigned frags = 0; + gnrc_sixlowpan_frag_rb_int_t *frag = rbuf->super.ints; + + while (frag) { + frag = frag->next; + frags++; + } + return frags; +} +#endif + int gnrc_sixlowpan_frag_rb_dispatch_when_complete(gnrc_sixlowpan_frag_rb_t *rbuf, gnrc_netif_hdr_t *netif_hdr) { @@ -610,6 +624,10 @@ int gnrc_sixlowpan_frag_rb_dispatch_when_complete(gnrc_sixlowpan_frag_rb_t *rbuf new_netif_hdr->lqi = netif_hdr->lqi; new_netif_hdr->rssi = netif_hdr->rssi; LL_APPEND(rbuf->pkt, netif); +#if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_STATS) + gnrc_sixlowpan_frag_stats_get()->fragments += _count_frags(rbuf); + gnrc_sixlowpan_frag_stats_get()->datagrams++; +#endif gnrc_sixlowpan_dispatch_recv(rbuf->pkt, NULL, 0); _tmp_rm(rbuf); } diff --git a/sys/shell/commands/sc_gnrc_6lo_frag_stats.c b/sys/shell/commands/sc_gnrc_6lo_frag_stats.c index 175a670f21..53beec1384 100644 --- a/sys/shell/commands/sc_gnrc_6lo_frag_stats.c +++ b/sys/shell/commands/sc_gnrc_6lo_frag_stats.c @@ -28,6 +28,8 @@ int _gnrc_6lo_frag_stats(int argc, char **argv) #ifdef MODULE_GNRC_SIXLOWPAN_FRAG_VRB printf("VRB full: %u\n", stats->vrb_full); #endif + printf("frags complete: %u\n", stats->fragments); + printf("dgs complete: %u\n", stats->datagrams); return 0; }