mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/net/gnrc/rpl: refactor netstats_rpl_t
There is a repeating pattern in the struct that is split out into a subtype in this commit. This makes handling the data easier, as now done in the print routine.
This commit is contained in:
parent
a1ee44e114
commit
93d8bade8e
@ -27,46 +27,29 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief One block of RPL statistics
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t rx_ucast_count; /**< unicast packets received */
|
||||
uint32_t rx_ucast_bytes; /**< unicast bytes received */
|
||||
uint32_t rx_mcast_count; /**< multicast packets received */
|
||||
uint32_t rx_mcast_bytes; /**< multicast bytes received */
|
||||
uint32_t tx_ucast_count; /**< unicast packets sent */
|
||||
uint32_t tx_ucast_bytes; /**< unicast bytes sent */
|
||||
uint32_t tx_mcast_count; /**< multicast packets sent */
|
||||
uint32_t tx_mcast_bytes; /**< multicast bytes sent*/
|
||||
|
||||
} netstats_rpl_block_t;
|
||||
|
||||
/**
|
||||
* @brief RPL statistics struct
|
||||
*/
|
||||
typedef struct {
|
||||
/* DIO */
|
||||
uint32_t dio_rx_ucast_count; /**< unicast dio received in packets */
|
||||
uint32_t dio_rx_ucast_bytes; /**< unicast dio received in bytes */
|
||||
uint32_t dio_rx_mcast_count; /**< multicast dio received in packets */
|
||||
uint32_t dio_rx_mcast_bytes; /**< multicast dio received in bytes */
|
||||
uint32_t dio_tx_ucast_count; /**< unicast dio sent in packets */
|
||||
uint32_t dio_tx_ucast_bytes; /**< unicast dio sent in bytes */
|
||||
uint32_t dio_tx_mcast_count; /**< multicast dio sent in packets */
|
||||
uint32_t dio_tx_mcast_bytes; /**< multicast dio sent in bytes*/
|
||||
/* DIS */
|
||||
uint32_t dis_rx_ucast_count; /**< unicast dis received in packets */
|
||||
uint32_t dis_rx_ucast_bytes; /**< unicast dis received in bytes */
|
||||
uint32_t dis_rx_mcast_count; /**< multicast dis received in packets */
|
||||
uint32_t dis_rx_mcast_bytes; /**< multicast dis received in bytes */
|
||||
uint32_t dis_tx_ucast_count; /**< unicast dis sent in packets */
|
||||
uint32_t dis_tx_ucast_bytes; /**< unicast dis sent in bytes */
|
||||
uint32_t dis_tx_mcast_count; /**< multicast dis sent in packets */
|
||||
uint32_t dis_tx_mcast_bytes; /**< multicast dis sent in bytes*/
|
||||
/* DAO */
|
||||
uint32_t dao_rx_ucast_count; /**< unicast dao received in packets */
|
||||
uint32_t dao_rx_ucast_bytes; /**< unicast dao received in bytes */
|
||||
uint32_t dao_rx_mcast_count; /**< multicast dao received in packets */
|
||||
uint32_t dao_rx_mcast_bytes; /**< multicast dao received in bytes */
|
||||
uint32_t dao_tx_ucast_count; /**< unicast dao sent in packets */
|
||||
uint32_t dao_tx_ucast_bytes; /**< unicast dao sent in bytes */
|
||||
uint32_t dao_tx_mcast_count; /**< multicast dao sent in packets */
|
||||
uint32_t dao_tx_mcast_bytes; /**< multicast dao sent in bytes*/
|
||||
/* DAO-ACK */
|
||||
uint32_t dao_ack_rx_ucast_count; /**< unicast dao_ack received in packets */
|
||||
uint32_t dao_ack_rx_ucast_bytes; /**< unicast dao_ack received in bytes */
|
||||
uint32_t dao_ack_rx_mcast_count; /**< multicast dao_ack received in packets */
|
||||
uint32_t dao_ack_rx_mcast_bytes; /**< multicast dao_ack received in bytes */
|
||||
uint32_t dao_ack_tx_ucast_count; /**< unicast dao_ack sent in packets */
|
||||
uint32_t dao_ack_tx_ucast_bytes; /**< unicast dao_ack sent in bytes */
|
||||
uint32_t dao_ack_tx_mcast_count; /**< multicast dao_ack sent in packets */
|
||||
uint32_t dao_ack_tx_mcast_bytes; /**< multicast dao_ack sent in bytes*/
|
||||
netstats_rpl_block_t dio; /**< DIO statistics */
|
||||
netstats_rpl_block_t dis; /**< DIS statistics */
|
||||
netstats_rpl_block_t dao; /**< DAO statistics */
|
||||
netstats_rpl_block_t dao_ack; /**< DAO-ACK statistics */
|
||||
} netstats_rpl_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -23,6 +23,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "irq.h"
|
||||
#include "net/rpl/rpl_netstats.h"
|
||||
|
||||
#define GNRC_RPL_NETSTATS_MULTICAST (0)
|
||||
@ -38,12 +39,12 @@ extern "C" {
|
||||
static inline void gnrc_rpl_netstats_rx_DIO(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dio_rx_mcast_count++;
|
||||
netstats->dio_rx_mcast_bytes += len;
|
||||
netstats->dio.rx_mcast_count++;
|
||||
netstats->dio.rx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dio_rx_ucast_count++;
|
||||
netstats->dio_rx_ucast_bytes += len;
|
||||
netstats->dio.rx_ucast_count++;
|
||||
netstats->dio.rx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,12 +58,12 @@ static inline void gnrc_rpl_netstats_rx_DIO(netstats_rpl_t *netstats, size_t len
|
||||
static inline void gnrc_rpl_netstats_tx_DIO(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dio_tx_mcast_count++;
|
||||
netstats->dio_tx_mcast_bytes += len;
|
||||
netstats->dio.tx_mcast_count++;
|
||||
netstats->dio.tx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dio_tx_ucast_count++;
|
||||
netstats->dio_tx_ucast_bytes += len;
|
||||
netstats->dio.tx_ucast_count++;
|
||||
netstats->dio.tx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,12 +77,12 @@ static inline void gnrc_rpl_netstats_tx_DIO(netstats_rpl_t *netstats, size_t len
|
||||
static inline void gnrc_rpl_netstats_rx_DIS(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dis_rx_mcast_count++;
|
||||
netstats->dis_rx_mcast_bytes += len;
|
||||
netstats->dis.rx_mcast_count++;
|
||||
netstats->dis.rx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dis_rx_ucast_count++;
|
||||
netstats->dis_rx_ucast_bytes += len;
|
||||
netstats->dis.rx_ucast_count++;
|
||||
netstats->dis.rx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,12 +96,12 @@ static inline void gnrc_rpl_netstats_rx_DIS(netstats_rpl_t *netstats, size_t len
|
||||
static inline void gnrc_rpl_netstats_tx_DIS(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dis_tx_mcast_count++;
|
||||
netstats->dis_tx_mcast_bytes += len;
|
||||
netstats->dis.tx_mcast_count++;
|
||||
netstats->dis.tx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dis_tx_ucast_count++;
|
||||
netstats->dis_tx_ucast_bytes += len;
|
||||
netstats->dis.tx_ucast_count++;
|
||||
netstats->dis.tx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,12 +115,12 @@ static inline void gnrc_rpl_netstats_tx_DIS(netstats_rpl_t *netstats, size_t len
|
||||
static inline void gnrc_rpl_netstats_rx_DAO(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dao_rx_mcast_count++;
|
||||
netstats->dao_rx_mcast_bytes += len;
|
||||
netstats->dao.rx_mcast_count++;
|
||||
netstats->dao.rx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dao_rx_ucast_count++;
|
||||
netstats->dao_rx_ucast_bytes += len;
|
||||
netstats->dao.rx_ucast_count++;
|
||||
netstats->dao.rx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,12 +134,12 @@ static inline void gnrc_rpl_netstats_rx_DAO(netstats_rpl_t *netstats, size_t len
|
||||
static inline void gnrc_rpl_netstats_tx_DAO(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dao_tx_mcast_count++;
|
||||
netstats->dao_tx_mcast_bytes += len;
|
||||
netstats->dao.tx_mcast_count++;
|
||||
netstats->dao.tx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dao_tx_ucast_count++;
|
||||
netstats->dao_tx_ucast_bytes += len;
|
||||
netstats->dao.tx_ucast_count++;
|
||||
netstats->dao.tx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,12 +153,12 @@ static inline void gnrc_rpl_netstats_tx_DAO(netstats_rpl_t *netstats, size_t len
|
||||
static inline void gnrc_rpl_netstats_rx_DAO_ACK(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dao_ack_rx_mcast_count++;
|
||||
netstats->dao_ack_rx_mcast_bytes += len;
|
||||
netstats->dao_ack.rx_mcast_count++;
|
||||
netstats->dao_ack.rx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dao_ack_rx_ucast_count++;
|
||||
netstats->dao_ack_rx_ucast_bytes += len;
|
||||
netstats->dao_ack.rx_ucast_count++;
|
||||
netstats->dao_ack.rx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,12 +172,12 @@ static inline void gnrc_rpl_netstats_rx_DAO_ACK(netstats_rpl_t *netstats, size_t
|
||||
static inline void gnrc_rpl_netstats_tx_DAO_ACK(netstats_rpl_t *netstats, size_t len, int cast)
|
||||
{
|
||||
if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
|
||||
netstats->dao_ack_tx_mcast_count++;
|
||||
netstats->dao_ack_tx_mcast_bytes += len;
|
||||
netstats->dao_ack.tx_mcast_count++;
|
||||
netstats->dao_ack.tx_mcast_bytes += len;
|
||||
}
|
||||
else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
|
||||
netstats->dao_ack_tx_ucast_count++;
|
||||
netstats->dao_ack_tx_ucast_bytes += len;
|
||||
netstats->dao_ack.tx_ucast_count++;
|
||||
netstats->dao_ack.tx_ucast_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,33 +204,23 @@ int _gnrc_rpl_send_dis(void)
|
||||
}
|
||||
|
||||
#ifdef MODULE_NETSTATS_RPL
|
||||
static void _print_stats_block(netstats_rpl_block_t *block, const char *name)
|
||||
{
|
||||
printf("%7s #packets: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
name, block->rx_ucast_count, block->tx_ucast_count,
|
||||
block->rx_mcast_count, block->tx_mcast_count);
|
||||
printf("%7s #bytes: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
name, block->rx_ucast_bytes, block->tx_ucast_bytes,
|
||||
block->rx_mcast_bytes, block->tx_mcast_bytes);
|
||||
}
|
||||
|
||||
int _stats(void)
|
||||
{
|
||||
puts( "Statistics (ucast) RX / TX RX / TX (mcast)");
|
||||
printf("DIO #packets: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dio_rx_ucast_count, gnrc_rpl_netstats.dio_tx_ucast_count,
|
||||
gnrc_rpl_netstats.dio_rx_mcast_count, gnrc_rpl_netstats.dio_tx_mcast_count);
|
||||
printf("DIO #bytes: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dio_rx_ucast_bytes, gnrc_rpl_netstats.dio_tx_ucast_bytes,
|
||||
gnrc_rpl_netstats.dio_rx_mcast_bytes, gnrc_rpl_netstats.dio_tx_mcast_bytes);
|
||||
printf("DIS #packets: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dis_rx_ucast_count, gnrc_rpl_netstats.dis_tx_ucast_count,
|
||||
gnrc_rpl_netstats.dis_rx_mcast_count, gnrc_rpl_netstats.dis_tx_mcast_count);
|
||||
printf("DIS #bytes: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dis_rx_ucast_bytes, gnrc_rpl_netstats.dis_tx_ucast_bytes,
|
||||
gnrc_rpl_netstats.dis_rx_mcast_bytes, gnrc_rpl_netstats.dis_tx_mcast_bytes);
|
||||
printf("DAO #packets: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dao_rx_ucast_count, gnrc_rpl_netstats.dao_tx_ucast_count,
|
||||
gnrc_rpl_netstats.dao_rx_mcast_count, gnrc_rpl_netstats.dao_tx_mcast_count);
|
||||
printf("DAO #bytes: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dao_rx_ucast_bytes, gnrc_rpl_netstats.dao_tx_ucast_bytes,
|
||||
gnrc_rpl_netstats.dao_rx_mcast_bytes, gnrc_rpl_netstats.dao_tx_mcast_bytes);
|
||||
printf("DAO-ACK #packets: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dao_ack_rx_ucast_count, gnrc_rpl_netstats.dao_ack_tx_ucast_count,
|
||||
gnrc_rpl_netstats.dao_ack_rx_mcast_count, gnrc_rpl_netstats.dao_ack_tx_mcast_count);
|
||||
printf("DAO-ACK #bytes: %10" PRIu32 " / %-10" PRIu32 " %10" PRIu32 " / %-10" PRIu32 "\n",
|
||||
gnrc_rpl_netstats.dao_ack_rx_ucast_bytes, gnrc_rpl_netstats.dao_ack_tx_ucast_bytes,
|
||||
gnrc_rpl_netstats.dao_ack_rx_mcast_bytes, gnrc_rpl_netstats.dao_ack_tx_mcast_bytes);
|
||||
_print_stats_block(&gnrc_rpl_netstats.dio, "DIO");
|
||||
_print_stats_block(&gnrc_rpl_netstats.dis, "DIS");
|
||||
_print_stats_block(&gnrc_rpl_netstats.dao, "DAO");
|
||||
_print_stats_block(&gnrc_rpl_netstats.dao_ack, "DAO-ACK");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user