Skip to content

Add Wi-SUN statistics interface #12766

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

Merged
merged 1 commit into from
Apr 15, 2020
Merged
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
34 changes: 34 additions & 0 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,40 @@ class WisunInterface : public MeshInterfaceNanostack {
* \param len
* */
bool getRouterIpAddress(char *address, int8_t len);

/**
* \brief Enable Wi-SUN statistics
*
* After enabling statistics those can be read using the network, physical layer,
* MAC and FHSS and Wi-SUN statistics read functions.
*
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN on error
* */
mesh_error_t enable_statistics(void);

/**
* \brief Reads Wi-SUN network statistics
*
* Reads network statistics.
*
* \param statistics Network statistics.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN on error
* */
mesh_error_t read_nw_statistics(mesh_nw_statistics_t *statistics);

/**
* \brief Reads Wi-SUN MAC statistics
*
* Reads MAC statistics.
*
* \param statistics MAC statistics.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN on error
* */
mesh_error_t read_mac_statistics(mesh_mac_statistics_t *statistics);

protected:
Nanostack::WisunInterface *get_interface() const;
virtual nsapi_error_t do_initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ typedef enum {
MESH_DEVICE_TYPE_WISUN_BORDER_ROUTER /*<! Wi-SUN border router */
} mesh_device_type_t;

/**
* Mesh network statistics
*/
typedef struct {
uint32_t rpl_total_memory; /*<! RPL current memory usage total. */
uint16_t etx_1st_parent; /*<! Primary parent ETX. */
uint16_t etx_2nd_parent; /*<! Secondary parent ETX. */
uint32_t asynch_tx_count; /*<! Asynch TX counter */
uint32_t asynch_rx_count; /*<! Asynch RX counter */
} mesh_nw_statistics_t;

/**
* Mesh physical layer statistics
*/
typedef struct {
uint32_t mac_rx_count; /*<! MAC RX packet count. */
uint32_t mac_tx_count; /*<! MAC TX packet count. */
uint32_t mac_bc_rx_count; /*<! MAC broadcast RX packet count. */
uint32_t mac_bc_tx_count; /*<! MAC broadcast TX packet count. */
uint32_t mac_tx_bytes; /*<! MAC TX bytes count. */
uint32_t mac_rx_bytes; /*<! MAC RX bytes count. */
Copy link

Choose a reason for hiding this comment

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

We have multiple levels of RX counts and byte counts I think one is enough
Mac_tx/rx_count
Mac_bx_tx/rx_count and
Mac_tx/rx/bytes
seems the best on that area

Copy link
Author

Choose a reason for hiding this comment

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

corrected

uint32_t mac_tx_failed_count; /*<! MAC TX failed count. */
uint32_t mac_retry_count; /*<! MAC TX retry count. */

Choose a reason for hiding this comment

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

mac_bc_tx_count, mac_tx_count and mac_retry_count are important.

Copy link
Author

Choose a reason for hiding this comment

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

ok

uint32_t mac_cca_attempts_count; /*<! MAC CCA attempts count. */
uint32_t mac_failed_cca_count; /*<! MAC failed CCA count. */
Copy link

Choose a reason for hiding this comment

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

Mac_failed_cca and tx failed are usable

Copy link
Author

Choose a reason for hiding this comment

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

ok

} mesh_mac_statistics_t;

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 30 additions & 0 deletions features/nanostack/mbed-mesh-api/source/WisunInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,36 @@ mesh_error_t WisunInterface::remove_trusted_certificates(void)
return ret_val;
}

mesh_error_t WisunInterface::enable_statistics(void)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_statistics_start();
if (status < 0) {
ret_val = MESH_ERROR_UNKNOWN;
}
return ret_val;
}

mesh_error_t WisunInterface::read_nw_statistics(mesh_nw_statistics_t *statistics)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_statistics_nw_read(statistics);
if (status < 0) {
ret_val = MESH_ERROR_UNKNOWN;
}
return ret_val;
}

mesh_error_t WisunInterface::read_mac_statistics(mesh_mac_statistics_t *statistics)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_statistics_mac_read(statistics);
if (status < 0) {
ret_val = MESH_ERROR_UNKNOWN;
}
return ret_val;
}

#define WISUN 0x2345
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
Expand Down
26 changes: 25 additions & 1 deletion features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,35 @@ int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len);
/*
* \brief Remove trusted certificate from Wi-SUN network
*
* \return 0 if certificates removed successfully
* \return 0 if certificates removed successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_remove_trusted_certificates(void);

/*
* \brief Start Wi-SUN statistics
*
* \return 0 Statistics start successful
* \return < 0 in case of errors
*/
int wisun_tasklet_statistics_start(void);

/*
* \brief Reads Wi-SUN network statistics
*
* \return 0 Statistics read successful
* \return < 0 in case of errors
*/
int wisun_tasklet_statistics_nw_read(mesh_nw_statistics_t *stats);

/*
* \brief Reads Wi-SUN MAC statistics
*
* \return 0 Statistics read successful
* \return < 0 in case of errors
*/
int wisun_tasklet_statistics_mac_read(mesh_mac_statistics_t *stats);

#ifdef __cplusplus
}
#endif
Expand Down
79 changes: 78 additions & 1 deletion features/nanostack/mbed-mesh-api/source/wisun_tasklet.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "sw_mac.h"
#include "ns_list.h"
#include "net_interface.h"
#include "nwk_stats_api.h"
#include "ws_management_api.h" //ws_management_node_init
#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
#if !defined(MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) || !defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) || \
Expand Down Expand Up @@ -118,6 +119,15 @@ static wisun_network_settings_t wisun_settings_str = {
};
static mac_api_t *mac_api = NULL;

typedef struct {
nwk_stats_t nwk_stats;
mac_statistics_t mac_statistics;
ws_statistics_t ws_statistics;
} wisun_statistics_t;

static bool statistics_started = false;
static wisun_statistics_t *statistics = NULL;

extern fhss_timer_t fhss_functions;

/* private function prototypes */
Expand All @@ -128,6 +138,7 @@ static void wisun_tasklet_configure_and_connect_to_network(void);
static void wisun_tasklet_clear_stored_certificates(void) ;
static int wisun_tasklet_store_certificate_data(const uint8_t *cert, uint16_t cert_len, const uint8_t *cert_key, uint16_t cert_key_len, bool remove_own, bool remove_trusted, bool trusted_cert);
static int wisun_tasklet_add_stored_certificates(void) ;
static void wisun_tasklet_statistics_do_start(void);

/*
* \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
Expand Down Expand Up @@ -257,7 +268,6 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
} else {
wisun_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
}

wisun_tasklet_data_ptr->operating_mode_extension = NET_6LOWPAN_WS;

arm_nwk_interface_configure_6lowpan_bootstrap_set(
Expand Down Expand Up @@ -367,6 +377,10 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
arm_network_own_certificate_add((const arm_certificate_entry_s *)&own_cert);
#endif

if (statistics_started) {
wisun_tasklet_statistics_do_start();
}

status = arm_nwk_interface_up(wisun_tasklet_data_ptr->network_interface_id);
if (status >= 0) {
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED;
Expand Down Expand Up @@ -681,3 +695,66 @@ int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
}
return wisun_tasklet_store_certificate_data(cert, cert_len, NULL, 0, false, false, true);
}

int wisun_tasklet_statistics_start(void)
{
statistics_started = true;

if (statistics == NULL) {
statistics = ns_dyn_mem_alloc(sizeof(wisun_statistics_t));
}
if (statistics == NULL) {
return -1;
}
memset(statistics, 0, sizeof(wisun_statistics_t));

wisun_tasklet_statistics_do_start();

return 0;
}

static void wisun_tasklet_statistics_do_start(void)
{
if (!wisun_tasklet_data_ptr || wisun_tasklet_data_ptr->network_interface_id < 0 || !mac_api) {
return;
}

protocol_stats_start(&statistics->nwk_stats);
ns_sw_mac_statistics_start(mac_api, &statistics->mac_statistics);
ws_statistics_start(wisun_tasklet_data_ptr->network_interface_id, &statistics->ws_statistics);
}

int wisun_tasklet_statistics_nw_read(mesh_nw_statistics_t *stats)
{
if (!statistics || !stats) {
return -1;
}

stats->rpl_total_memory = statistics->nwk_stats.rpl_total_memory;
stats->etx_1st_parent = statistics->nwk_stats.etx_1st_parent;
stats->etx_2nd_parent = statistics->nwk_stats.etx_2nd_parent;
stats->asynch_tx_count = statistics->ws_statistics.asynch_tx_count;
stats->asynch_rx_count = statistics->ws_statistics.asynch_rx_count;

return 0;
Copy link

Choose a reason for hiding this comment

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

This binds the nanostack API to mbedOS API and we can't make changes to any independently

I think we need to select the wanted statistics to Mbed OS API and just copy those not take everything at bulk

Copy link
Author

Choose a reason for hiding this comment

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

corrected

}

int wisun_tasklet_statistics_mac_read(mesh_mac_statistics_t *stats)
{
if (!statistics || !stats) {
return -1;
}

stats->mac_rx_count = statistics->mac_statistics.mac_rx_count;
stats->mac_tx_count = statistics->mac_statistics.mac_tx_count;
stats->mac_bc_rx_count = statistics->mac_statistics.mac_bc_rx_count;
stats->mac_bc_tx_count = statistics->mac_statistics.mac_bc_tx_count;
stats->mac_tx_bytes = statistics->mac_statistics.mac_tx_bytes;
stats->mac_rx_bytes = statistics->mac_statistics.mac_rx_bytes;
stats->mac_tx_failed_count = statistics->mac_statistics.mac_tx_failed_count;
stats->mac_retry_count = statistics->mac_statistics.mac_retry_count;
stats->mac_cca_attempts_count = statistics->mac_statistics.mac_cca_attempts_count;
stats->mac_failed_cca_count = statistics->mac_statistics.mac_failed_cca_count;

return 0;
}