Skip to content

Commit

Permalink
FHSS: Created statistics for WS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed May 30, 2019
1 parent 3608153 commit 8dc200b
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 19 deletions.
6 changes: 6 additions & 0 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ typedef struct fhss_statistics {

/** FHSS synchronization lost counter. */
uint32_t fhss_synch_lost;

/** FHSS TX to unknown neighbour counter. */
uint32_t fhss_unknown_neighbor;

/** FHSS channel retry counter. */
uint32_t fhss_channel_retry;
} fhss_statistics_t;

/**
Expand Down
8 changes: 8 additions & 0 deletions nanostack/net_fhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ extern int ns_fhss_ws_configuration_set(const fhss_api_t *fhss_api, const fhss_w
*/
extern int ns_fhss_delete(fhss_api_t *fhss_api);

/**
* @brief Starts collecting FHSS statistics.
* @param fhss_api FHSS instance.
* @param fhss_statistics Pointer to stored statistics.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_statistics_start(const fhss_api_t *fhss_api, fhss_statistics_t *fhss_statistics);


#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
return 0;
} else {
// Do not update CCA count when Ack is received, it was already updated with PHY_LINK_TX_SUCCESS event
if ((status != PHY_LINK_TX_DONE) && (status != PHY_LINK_TX_DONE_PENDING)) {
// Do not update CCA count when CCA_OK is received, PHY_LINK_TX_SUCCESS will update it
if ((status != PHY_LINK_TX_DONE) && (status != PHY_LINK_TX_DONE_PENDING) && (status != PHY_LINK_CCA_OK)) {
/* For PHY_LINK_TX_SUCCESS and PHY_LINK_CCA_FAIL cca_retry must always be > 0.
* PHY_LINK_TX_FAIL either happened during transmission or when waiting Ack -> we must use the CCA count given by PHY.
*/
Expand Down
2 changes: 1 addition & 1 deletion source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *

fhss_struct->fhss_event_timer = eventOS_callback_timer_register(fhss_event_timer_cb);
fhss_struct->bs->fhss_configuration = *fhss_configuration;
fhss_struct->bs->fhss_stats_ptr = fhss_statistics;
fhss_struct->fhss_stats_ptr = fhss_statistics;
fhss_struct->number_of_channels = channel_count;

// set a invalid id to tasklet_id, so we know that one is not started yet
Expand Down
1 change: 0 additions & 1 deletion source/Service_Libs/fhss/fhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ struct fhss_bs {
uint16_t channel_list_counter;
uint16_t synch_panid;
uint32_t synch_interval;
struct fhss_statistics *fhss_stats_ptr;
struct fhss_beacon_info *fhss_beacon_info_store;
struct fhss_configuration fhss_configuration;
struct fhss_synch_configuration synch_configuration;
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct fhss_structure {
struct fhss_ws *ws;
struct fhss_timer platform_functions;
struct fhss_callback callbacks;
struct fhss_statistics *fhss_stats_ptr;
fhss_failed_tx_list_t fhss_failed_tx_list;
uint8_t synch_parent[8];
};
Expand Down
10 changes: 10 additions & 0 deletions source/Service_Libs/fhss/fhss_configuration_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Service_Libs/fhss/fhss.h"
#include "Service_Libs/fhss/fhss_common.h"
#include "Service_Libs/fhss/fhss_ws.h"
#include "Service_Libs/fhss/fhss_statistics.h"
#include "ns_trace.h"

#define TRACE_GROUP "fhss"
Expand Down Expand Up @@ -138,3 +139,12 @@ int ns_fhss_ws_set_hop_count(const fhss_api_t *fhss_api, const uint8_t hop_count
}
return fhss_ws_set_hop_count(fhss_structure, hop_count);
}

int ns_fhss_statistics_start(const fhss_api_t *fhss_api, fhss_statistics_t *fhss_statistics)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
if (!fhss_structure) {
return -1;
}
return fhss_statistics_start(fhss_structure, fhss_statistics);
}
24 changes: 18 additions & 6 deletions source/Service_Libs/fhss/fhss_statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,35 @@

void fhss_stats_update(fhss_structure_t *fhss_structure, fhss_stats_type_t type, uint32_t update_val)
{
if (fhss_structure->bs->fhss_stats_ptr) {
if (fhss_structure->fhss_stats_ptr) {
switch (type) {
case STATS_FHSS_DRIFT_COMP:
fhss_structure->bs->fhss_stats_ptr->fhss_drift_compensation = update_val;
fhss_structure->fhss_stats_ptr->fhss_drift_compensation = update_val;
break;
case STATS_FHSS_HOP_COUNT:
fhss_structure->bs->fhss_stats_ptr->fhss_hop_count = update_val;
fhss_structure->fhss_stats_ptr->fhss_hop_count = update_val;
break;
case STATS_FHSS_SYNCH_INTERVAL:
fhss_structure->bs->fhss_stats_ptr->fhss_synch_interval = update_val;
fhss_structure->fhss_stats_ptr->fhss_synch_interval = update_val;
break;
case STATS_FHSS_AVG_SYNCH_FIX:
fhss_structure->bs->fhss_stats_ptr->fhss_prev_avg_synch_fix = update_val;
fhss_structure->fhss_stats_ptr->fhss_prev_avg_synch_fix = update_val;
break;
case STATS_FHSS_SYNCH_LOST:
fhss_structure->bs->fhss_stats_ptr->fhss_synch_lost += update_val;
fhss_structure->fhss_stats_ptr->fhss_synch_lost += update_val;
break;
case STATS_FHSS_UNKNOWN_NEIGHBOR:
fhss_structure->fhss_stats_ptr->fhss_unknown_neighbor += update_val;
break;
case STATS_FHSS_CHANNEL_RETRY:
fhss_structure->fhss_stats_ptr->fhss_channel_retry += update_val;
break;
}
}
}

int fhss_statistics_start(fhss_structure_t *fhss_structure, fhss_statistics_t *fhss_statistics)
{
fhss_structure->fhss_stats_ptr = fhss_statistics;
return 0;
}
3 changes: 3 additions & 0 deletions source/Service_Libs/fhss/fhss_statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ typedef enum {
STATS_FHSS_SYNCH_INTERVAL,
STATS_FHSS_AVG_SYNCH_FIX,
STATS_FHSS_SYNCH_LOST,
STATS_FHSS_UNKNOWN_NEIGHBOR,
STATS_FHSS_CHANNEL_RETRY
} fhss_stats_type_t;

void fhss_stats_update(fhss_structure_t *fhss_structure, fhss_stats_type_t type, uint32_t update_val);
int fhss_statistics_start(fhss_structure_t *fhss_structure, fhss_statistics_t *fhss_statistics);

#endif /* FHSS_STATISTICS_H_ */
9 changes: 8 additions & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "fhss_config.h"
#include "fhss.h"
#include "fhss_common.h"
#include "fhss_statistics.h"
#include "channel_list.h"
#include "channel_functions.h"
#include "fhss_ws.h"
Expand Down Expand Up @@ -143,7 +144,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
fhss_struct->fhss_event_timer = eventOS_callback_timer_register(fhss_event_timer_cb);
fhss_struct->ws->fhss_configuration = *fhss_configuration;
fhss_struct->number_of_channels = channel_count;
fhss_struct->own_hop = 0xff;
fhss_ws_set_hop_count(fhss_struct, 0xff);
fhss_struct->rx_channel = fhss_configuration->unicast_fixed_channel;
fhss_struct->ws->min_synch_interval = DEFAULT_MIN_SYNCH_INTERVAL;
fhss_set_txrx_slot_length(fhss_struct);
Expand Down Expand Up @@ -472,6 +473,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->get_neighbor_info(api, destination_address);
if (!neighbor_timing_info) {
fhss_stats_update(fhss_structure, STATS_FHSS_UNKNOWN_NEIGHBOR, 1);
return -2;
}
// TODO: WS bootstrap has to store neighbors number of channels
Expand Down Expand Up @@ -687,6 +689,7 @@ static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle,
// Create new failure handle and return true to retransmit
fhss_failed_handle_add(fhss_structure, handle, fhss_structure->rx_channel);
}
fhss_stats_update(fhss_structure, STATS_FHSS_CHANNEL_RETRY, 1);
return true;
}

Expand Down Expand Up @@ -858,9 +861,11 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
drift_per_ms_tmp = -MAX_DRIFT_COMPENSATION_STEP;
}
fhss_structure->ws->drift_per_millisecond_ns += drift_per_ms_tmp;
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->ws->drift_per_millisecond_ns * bc_timing_info->broadcast_dwell_interval);
}
tr_debug("synch to parent: %s, drift: %"PRIi32"ms in %"PRIu32" seconds, compensation: %"PRIi32"ns per ms", trace_array(eui64, 8), true_bc_interval_offset - own_bc_interval_offset + ((int32_t)(fhss_structure->ws->bc_slot - own_bc_slot) * bc_timing_info->broadcast_interval), US_TO_S(time_since_last_synch_us), fhss_structure->ws->drift_per_millisecond_ns);
}
fhss_stats_update(fhss_structure, STATS_FHSS_SYNCH_INTERVAL, US_TO_S(time_since_last_synch_us));
return 0;
}

Expand Down Expand Up @@ -915,6 +920,8 @@ int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_co
int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_count)
{
fhss_structure->own_hop = hop_count;
fhss_stats_update(fhss_structure, STATS_FHSS_HOP_COUNT, fhss_structure->own_hop);
return 0;
}

#endif // HAVE_WS
1 change: 1 addition & 0 deletions test/nanostack/unittest/service_libs/fhss_config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TEST_SRC_FILES = \
../../stub/fhss_stub.c \
../../stub/fhss_common_stub.c \
../../stub/fhss_ws_stub.c \
../../stub/fhss_statistics_stub.c \

include ../../MakefileWorker.mk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,41 @@
#include "Service_Libs/fhss/fhss_statistics.h"

static fhss_structure_t fhss_struct;
static fhss_bs_t bs;
static fhss_statistics_t fhss_stats_ptr;

static init_fhss_struct(void)
{
memset(&fhss_stats_ptr, 0, sizeof(fhss_statistics_t));
bs.fhss_stats_ptr = &fhss_stats_ptr;
fhss_struct.bs = &bs;
fhss_struct.fhss_stats_ptr = &fhss_stats_ptr;
}

bool test_fhss_stats_update()
{
init_fhss_struct();
// Test drift compensation
fhss_stats_update(&fhss_struct, STATS_FHSS_DRIFT_COMP, 10);
if (fhss_struct.bs->fhss_stats_ptr->fhss_drift_compensation != 10) {
if (fhss_struct.fhss_stats_ptr->fhss_drift_compensation != 10) {
return false;
}
// Test hop count
fhss_stats_update(&fhss_struct, STATS_FHSS_HOP_COUNT, 1);
if (fhss_struct.bs->fhss_stats_ptr->fhss_hop_count != 1) {
if (fhss_struct.fhss_stats_ptr->fhss_hop_count != 1) {
return false;
}
// Test synch interval
fhss_stats_update(&fhss_struct, STATS_FHSS_SYNCH_INTERVAL, 960);
if (fhss_struct.bs->fhss_stats_ptr->fhss_synch_interval != 960) {
if (fhss_struct.fhss_stats_ptr->fhss_synch_interval != 960) {
return false;
}
// Test average synch fix
fhss_stats_update(&fhss_struct, STATS_FHSS_AVG_SYNCH_FIX, 1000);
if (fhss_struct.bs->fhss_stats_ptr->fhss_prev_avg_synch_fix != 1000) {
if (fhss_struct.fhss_stats_ptr->fhss_prev_avg_synch_fix != 1000) {
return false;
}
// Test synch lost count
fhss_struct.bs->fhss_stats_ptr->fhss_synch_lost = 1;
fhss_struct.fhss_stats_ptr->fhss_synch_lost = 1;
fhss_stats_update(&fhss_struct, STATS_FHSS_SYNCH_LOST, 1);
if (fhss_struct.bs->fhss_stats_ptr->fhss_synch_lost != 2) {
if (fhss_struct.fhss_stats_ptr->fhss_synch_lost != 2) {
return false;
}
return true;
Expand Down
1 change: 1 addition & 0 deletions test/nanostack/unittest/service_libs/fhss_ws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEST_SRC_FILES = \
../../stub/fhss_common_stub.c \
../../stub/fhss_callbacks_stub.c \
../../stub/fhss_platform_stub.c \
../../stub/fhss_statistics_stub.c \
../../stub/platform_stub.c \

include ../../MakefileWorker.mk
Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/fhss_statistics_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ void fhss_stats_update(fhss_structure_t *fhss_structure, fhss_stats_type_t type,
{

}

int fhss_statistics_start(fhss_structure_t *fhss_structure, fhss_statistics_t *fhss_statistics)
{
return 0;
}

0 comments on commit 8dc200b

Please sign in to comment.