mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #12766 from mikaleppanen/wisun_stats
Add Wi-SUN statistics interfacepull/12826/head
commit
04dacfaac3
|
@ -131,6 +131,40 @@ public:
|
||||||
* \param len
|
* \param len
|
||||||
* */
|
* */
|
||||||
bool getRouterIpAddress(char *address, int8_t 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:
|
protected:
|
||||||
Nanostack::WisunInterface *get_interface() const;
|
Nanostack::WisunInterface *get_interface() const;
|
||||||
virtual nsapi_error_t do_initialize();
|
virtual nsapi_error_t do_initialize();
|
||||||
|
|
|
@ -64,6 +64,33 @@ typedef enum {
|
||||||
MESH_DEVICE_TYPE_WISUN_BORDER_ROUTER /*<! Wi-SUN border router */
|
MESH_DEVICE_TYPE_WISUN_BORDER_ROUTER /*<! Wi-SUN border router */
|
||||||
} mesh_device_type_t;
|
} 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. */
|
||||||
|
uint32_t mac_tx_failed_count; /*<! MAC TX failed count. */
|
||||||
|
uint32_t mac_retry_count; /*<! MAC TX retry count. */
|
||||||
|
uint32_t mac_cca_attempts_count; /*<! MAC CCA attempts count. */
|
||||||
|
uint32_t mac_failed_cca_count; /*<! MAC failed CCA count. */
|
||||||
|
} mesh_mac_statistics_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -252,6 +252,36 @@ mesh_error_t WisunInterface::remove_trusted_certificates(void)
|
||||||
return ret_val;
|
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
|
#define WISUN 0x2345
|
||||||
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
|
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
|
||||||
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
|
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
|
||||||
|
|
|
@ -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
|
* \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
|
* \return < 0 in case of errors
|
||||||
*/
|
*/
|
||||||
int wisun_tasklet_remove_trusted_certificates(void);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "sw_mac.h"
|
#include "sw_mac.h"
|
||||||
#include "ns_list.h"
|
#include "ns_list.h"
|
||||||
#include "net_interface.h"
|
#include "net_interface.h"
|
||||||
|
#include "nwk_stats_api.h"
|
||||||
#include "ws_management_api.h" //ws_management_node_init
|
#include "ws_management_api.h" //ws_management_node_init
|
||||||
#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
|
#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) || \
|
#if !defined(MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) || !defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) || \
|
||||||
|
@ -118,6 +119,15 @@ static wisun_network_settings_t wisun_settings_str = {
|
||||||
};
|
};
|
||||||
static mac_api_t *mac_api = NULL;
|
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;
|
extern fhss_timer_t fhss_functions;
|
||||||
|
|
||||||
/* private function prototypes */
|
/* private function prototypes */
|
||||||
|
@ -128,6 +138,7 @@ static void wisun_tasklet_configure_and_connect_to_network(void);
|
||||||
static void wisun_tasklet_clear_stored_certificates(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_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 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.
|
* \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
|
||||||
|
@ -257,7 +268,6 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
|
||||||
} else {
|
} else {
|
||||||
wisun_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
|
wisun_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
wisun_tasklet_data_ptr->operating_mode_extension = NET_6LOWPAN_WS;
|
wisun_tasklet_data_ptr->operating_mode_extension = NET_6LOWPAN_WS;
|
||||||
|
|
||||||
arm_nwk_interface_configure_6lowpan_bootstrap_set(
|
arm_nwk_interface_configure_6lowpan_bootstrap_set(
|
||||||
|
@ -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);
|
arm_network_own_certificate_add((const arm_certificate_entry_s *)&own_cert);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (statistics_started) {
|
||||||
|
wisun_tasklet_statistics_do_start();
|
||||||
|
}
|
||||||
|
|
||||||
status = arm_nwk_interface_up(wisun_tasklet_data_ptr->network_interface_id);
|
status = arm_nwk_interface_up(wisun_tasklet_data_ptr->network_interface_id);
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED;
|
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED;
|
||||||
|
@ -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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue