Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc_netif: fix neighbor statistics with netdev_new_api #21002

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sys/include/net/netstats/neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
* @{
*/
typedef enum {
NETSTATS_NB_BUSY, /**< Failed due to medium busy */
NETSTATS_NB_SUCCESS = 0,/**< Successful transmission */

Check warning on line 35 in sys/include/net/netstats/neighbor.h

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace
NETSTATS_NB_NOACK, /**< Failed due to no ack received */
NETSTATS_NB_SUCCESS, /**< Successful transmission */
NETSTATS_NB_BUSY, /**< Failed due to medium busy */
} netstats_nb_result_t;
Comment on lines 34 to 38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef enum {
NETSTATS_NB_BUSY, /**< Failed due to medium busy */
NETSTATS_NB_SUCCESS = 0,/**< Successful transmission */
NETSTATS_NB_NOACK, /**< Failed due to no ack received */
NETSTATS_NB_SUCCESS, /**< Successful transmission */
NETSTATS_NB_BUSY, /**< Failed due to medium busy */
} netstats_nb_result_t;
typedef enum {
NETSTATS_NB_SUCCESS = 0, /**< Successful transmission */
NETSTATS_NB_NOACK, /**< Failed due to no ack received */
NETSTATS_NB_BUSY, /**< Failed due to medium busy */
} netstats_nb_result_t;

The static tests don't like the missing space between , and /**...*/

/** @} */

Expand Down
24 changes: 23 additions & 1 deletion sys/net/gnrc/netif/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,17 @@
#endif /* IS_USED(MODULE_GNRC_NETIF_PKTQ) */
}

static netstats_nb_result_t _res_to_nb_result(int res)
{
if (res >= 0) {
return NETSTATS_NB_SUCCESS;
}
if (res == -EHOSTUNREACH) {
return NETSTATS_NB_NOACK;
}
return NETSTATS_NB_BUSY;
}

static void _tx_done(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt,
gnrc_pktsnip_t *tx_sync, int res, bool push_back)
{
Expand All @@ -1771,12 +1782,23 @@
gnrc_pktbuf_release_error(tx_sync, err);
}

if (IS_USED(MODULE_NETSTATS_NEIGHBOR) && gnrc_netif_netdev_new_api(netif)) {
int8_t retries = -1;
netstats_nb_result_t result = _res_to_nb_result(res);
if (result != NETSTATS_NB_BUSY) {
netdev_t *dev = netif->dev;
retries = dev->driver->get(dev, NETOPT_TX_RETRIES_NEEDED, &retries, sizeof(retries));
}

netstats_nb_update_tx(&netif->netif, result, retries + 1);
}

/* no frame was transmitted */
if (res < 0) {
DEBUG("gnrc_netif: error sending packet %p (code: %i)\n",
(void *)pkt, res);

if (IS_USED(MODULE_NETSTATS_NEIGHBOR)) {
if (IS_USED(MODULE_NETSTATS_NEIGHBOR) && gnrc_netif_netdev_legacy_api(netif)) {
netstats_nb_update_tx(&netif->netif, NETSTATS_NB_BUSY, 0);
}
}
Expand Down Expand Up @@ -2156,4 +2178,4 @@
}
}
}
/** @} */

Check warning on line 2181 in sys/net/gnrc/netif/gnrc_netif.c

View workflow job for this annotation

GitHub Actions / static-tests

source file is too long
Loading