mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 10:12:45 +01:00
netstats: collect layer 2 netstats in gnrc_netif
This the first step in moving the collection of layer 2 netstats from the low level driver to a central location, ie. gnrc_netif, to avoid code duplication.
This commit is contained in:
parent
1d693403b6
commit
6d0384f068
@ -153,10 +153,10 @@ static int xbee_adpt_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
|||||||
|
|
||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
if (hdr->flags & BCAST) {
|
if (hdr->flags & BCAST) {
|
||||||
netif->dev->stats.tx_mcast_count++;
|
netif->stats.tx_mcast_count++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
netif->dev->stats.tx_unicast_count++;
|
netif->stats.tx_unicast_count++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
DEBUG("[xbee-gnrc] send: triggering the drivers send function\n");
|
DEBUG("[xbee-gnrc] send: triggering the drivers send function\n");
|
||||||
|
@ -47,6 +47,9 @@
|
|||||||
#include "net/ndp.h"
|
#include "net/ndp.h"
|
||||||
#include "net/netdev.h"
|
#include "net/netdev.h"
|
||||||
#include "net/netopt.h"
|
#include "net/netopt.h"
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
#include "net/netstats.h"
|
||||||
|
#endif
|
||||||
#include "rmutex.h"
|
#include "rmutex.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -65,6 +68,9 @@ typedef struct {
|
|||||||
const gnrc_netif_ops_t *ops; /**< Operations of the network interface */
|
const gnrc_netif_ops_t *ops; /**< Operations of the network interface */
|
||||||
netdev_t *dev; /**< Network device of the network interface */
|
netdev_t *dev; /**< Network device of the network interface */
|
||||||
rmutex_t mutex; /**< Mutex of the interface */
|
rmutex_t mutex; /**< Mutex of the interface */
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
netstats_t stats; /**< transceiver's statistics */
|
||||||
|
#endif
|
||||||
#if defined(MODULE_GNRC_IPV6) || DOXYGEN
|
#if defined(MODULE_GNRC_IPV6) || DOXYGEN
|
||||||
gnrc_netif_ipv6_t ipv6; /**< IPv6 component */
|
gnrc_netif_ipv6_t ipv6; /**< IPv6 component */
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,10 +103,10 @@ int _gnrc_gomach_transmit(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
|||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
if (netif_hdr->flags &
|
if (netif_hdr->flags &
|
||||||
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
||||||
netif->dev->stats.tx_mcast_count++;
|
netif->stats.tx_mcast_count++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
netif->dev->stats.tx_unicast_count++;
|
netif->stats.tx_unicast_count++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_GNRC_MAC
|
#ifdef MODULE_GNRC_MAC
|
||||||
|
@ -90,10 +90,10 @@ int _gnrc_lwmac_transmit(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
|||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
if (netif_hdr->flags &
|
if (netif_hdr->flags &
|
||||||
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
||||||
netif->dev->stats.tx_mcast_count++;
|
netif->stats.tx_mcast_count++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
netif->dev->stats.tx_unicast_count++;
|
netif->stats.tx_unicast_count++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_GNRC_MAC
|
#ifdef MODULE_GNRC_MAC
|
||||||
|
@ -145,10 +145,10 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
|||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
if ((netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_BROADCAST) ||
|
if ((netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_BROADCAST) ||
|
||||||
(netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
(netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
||||||
dev->stats.tx_mcast_count++;
|
netif->stats.tx_mcast_count++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dev->stats.tx_unicast_count++;
|
netif->stats.tx_unicast_count++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
res = dev->driver->send(dev, &iolist);
|
res = dev->driver->send(dev, &iolist);
|
||||||
@ -183,6 +183,10 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
|
|||||||
DEBUG("gnrc_netif_ethernet: read error.\n");
|
DEBUG("gnrc_netif_ethernet: read error.\n");
|
||||||
goto safe_out;
|
goto safe_out;
|
||||||
}
|
}
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
netif->stats.rx_count++;
|
||||||
|
netif->stats.rx_bytes += nread;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (nread < bytes_expected) {
|
if (nread < bytes_expected) {
|
||||||
/* we've got less than the expected packet size,
|
/* we've got less than the expected packet size,
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "net/gnrc/ipv6/nib.h"
|
#include "net/gnrc/ipv6/nib.h"
|
||||||
#include "net/gnrc/ipv6.h"
|
#include "net/gnrc/ipv6.h"
|
||||||
#endif /* MODULE_GNRC_IPV6_NIB */
|
#endif /* MODULE_GNRC_IPV6_NIB */
|
||||||
#ifdef MODULE_NETSTATS_IPV6
|
#ifdef MODULE_NETSTATS
|
||||||
#include "net/netstats.h"
|
#include "net/netstats.h"
|
||||||
#endif
|
#endif
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
@ -126,6 +126,13 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt)
|
|||||||
*((netstats_t **)opt->data) = &netif->ipv6.stats;
|
*((netstats_t **)opt->data) = &netif->ipv6.stats;
|
||||||
res = sizeof(&netif->ipv6.stats);
|
res = sizeof(&netif->ipv6.stats);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
case NETSTATS_LAYER2:
|
||||||
|
assert(opt->data_len == sizeof(netstats_t *));
|
||||||
|
*((netstats_t **)opt->data) = &netif->stats;
|
||||||
|
res = sizeof(&netif->stats);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
/* take from device */
|
/* take from device */
|
||||||
@ -1196,6 +1203,9 @@ static void *_gnrc_netif_thread(void *args)
|
|||||||
if (netif->ops->init) {
|
if (netif->ops->init) {
|
||||||
netif->ops->init(netif);
|
netif->ops->init(netif);
|
||||||
}
|
}
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
memset(&netif->stats, 0, sizeof(netstats_t));
|
||||||
|
#endif
|
||||||
/* now let rest of GNRC use the interface */
|
/* now let rest of GNRC use the interface */
|
||||||
gnrc_netif_release(netif);
|
gnrc_netif_release(netif);
|
||||||
|
|
||||||
@ -1215,6 +1225,11 @@ static void *_gnrc_netif_thread(void *args)
|
|||||||
DEBUG("gnrc_netif: error sending packet %p (code: %u)\n",
|
DEBUG("gnrc_netif: error sending packet %p (code: %u)\n",
|
||||||
msg.content.ptr, res);
|
msg.content.ptr, res);
|
||||||
}
|
}
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
else {
|
||||||
|
netif->stats.tx_bytes += res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case GNRC_NETAPI_MSG_TYPE_SET:
|
case GNRC_NETAPI_MSG_TYPE_SET:
|
||||||
opt = msg.content.ptr;
|
opt = msg.content.ptr;
|
||||||
@ -1287,25 +1302,24 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG("gnrc_netif: event triggered -> %i\n", event);
|
DEBUG("gnrc_netif: event triggered -> %i\n", event);
|
||||||
|
gnrc_pktsnip_t *pkt = NULL;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case NETDEV_EVENT_RX_COMPLETE: {
|
case NETDEV_EVENT_RX_COMPLETE:
|
||||||
gnrc_pktsnip_t *pkt = netif->ops->recv(netif);
|
pkt = netif->ops->recv(netif);
|
||||||
|
if (pkt) {
|
||||||
if (pkt) {
|
_pass_on_packet(pkt);
|
||||||
_pass_on_packet(pkt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
case NETDEV_EVENT_TX_MEDIUM_BUSY:
|
case NETDEV_EVENT_TX_MEDIUM_BUSY:
|
||||||
/* we are the only ones supposed to touch this variable,
|
/* we are the only ones supposed to touch this variable,
|
||||||
* so no acquire necessary */
|
* so no acquire necessary */
|
||||||
dev->stats.tx_failed++;
|
netif->stats.tx_failed++;
|
||||||
break;
|
break;
|
||||||
case NETDEV_EVENT_TX_COMPLETE:
|
case NETDEV_EVENT_TX_COMPLETE:
|
||||||
/* we are the only ones supposed to touch this variable,
|
/* we are the only ones supposed to touch this variable,
|
||||||
* so no acquire necessary */
|
* so no acquire necessary */
|
||||||
dev->stats.tx_success++;
|
netif->stats.tx_success++;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -70,6 +70,11 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
|
|||||||
gnrc_pktbuf_release(pkt);
|
gnrc_pktbuf_release(pkt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
netif->stats.rx_count++;
|
||||||
|
netif->stats.rx_bytes += nread;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (nread < bytes_expected) {
|
if (nread < bytes_expected) {
|
||||||
/* we've got less then the expected packet size,
|
/* we've got less then the expected packet size,
|
||||||
* so free the unused space.*/
|
* so free the unused space.*/
|
||||||
@ -102,7 +107,7 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
|||||||
netdev_t *dev = netif->dev;
|
netdev_t *dev = netif->dev;
|
||||||
|
|
||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
dev->stats.tx_unicast_count++;
|
netif->stats.tx_unicast_count++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
res = dev->driver->send(dev, (iolist_t *)pkt);
|
res = dev->driver->send(dev, (iolist_t *)pkt);
|
||||||
|
@ -95,6 +95,11 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
|
|||||||
gnrc_pktbuf_release(pkt);
|
gnrc_pktbuf_release(pkt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef MODULE_NETSTATS_L2
|
||||||
|
netif->stats.rx_count++;
|
||||||
|
netif->stats.rx_bytes += nread;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (netif->flags & GNRC_NETIF_FLAGS_RAWMODE) {
|
if (netif->flags & GNRC_NETIF_FLAGS_RAWMODE) {
|
||||||
/* Raw mode, skip packet processing, but provide rx_info via
|
/* Raw mode, skip packet processing, but provide rx_info via
|
||||||
* GNRC_NETTYPE_NETIF */
|
* GNRC_NETTYPE_NETIF */
|
||||||
@ -241,10 +246,10 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
|||||||
#ifdef MODULE_NETSTATS_L2
|
#ifdef MODULE_NETSTATS_L2
|
||||||
if (netif_hdr->flags &
|
if (netif_hdr->flags &
|
||||||
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
||||||
netif->dev->stats.tx_mcast_count++;
|
netif->stats.tx_mcast_count++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
netif->dev->stats.tx_unicast_count++;
|
netif->stats.tx_unicast_count++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_GNRC_MAC
|
#ifdef MODULE_GNRC_MAC
|
||||||
|
Loading…
Reference in New Issue
Block a user