From f28b8cbdf0ca3d1e0d49a0b0b247f39afae83f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=20Lepp=C3=A4nen?= Date: Mon, 6 Apr 2020 14:07:38 +0300 Subject: [PATCH] Added Wi-SUN statistics interface Added network and MAC statistics to Wi-SUN interface. --- .../mbed-mesh-api/WisunInterface.h | 34 ++++++++ .../mbed-mesh-api/mesh_interface_types.h | 27 +++++++ .../mbed-mesh-api/source/WisunInterface.cpp | 30 +++++++ .../source/include/wisun_tasklet.h | 26 +++++- .../mbed-mesh-api/source/wisun_tasklet.c | 79 ++++++++++++++++++- 5 files changed, 194 insertions(+), 2 deletions(-) diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h index e80657c3e3..eee67d5fad 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h @@ -131,6 +131,40 @@ public: * \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(); diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h index e6a5a7334a..c3f5ad7c0d 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h @@ -64,6 +64,33 @@ typedef enum { MESH_DEVICE_TYPE_WISUN_BORDER_ROUTER /*operating_mode = NET_6LOWPAN_ROUTER; } - wisun_tasklet_data_ptr->operating_mode_extension = NET_6LOWPAN_WS; 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); #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; @@ -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; +} + +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; +}