Skip to content

Commit

Permalink
refactored trickkle running checks
Browse files Browse the repository at this point in the history
Added boolean to check when trickle is running

trickle_running and trickle_stop are not meant to be checkking
the high level status of trickle

No need to check status anymore for running when analysing
inconsistent/consistent state

Fixed trickle timer function name
  • Loading branch information
Mika Tervonen committed Sep 11, 2018
1 parent 61ff793 commit b5d276d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
71 changes: 44 additions & 27 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ void ws_bootstrap_configuration_reset(protocol_interface_info_entry_t *cur)

cur->nwk_bootstrap_state = ER_ACTIVE_SCAN;
cur->ws_info->network_pan_id = 0xffff;
trickle_stop(&cur->ws_info->trickle_pan_advertisement_solicit);
trickle_stop(&cur->ws_info->trickle_pan_advertisement);
trickle_stop(&cur->ws_info->trickle_pan_config_solicit);
trickle_stop(&cur->ws_info->trickle_pan_config);
cur->ws_info->trickle_pas_running = false;
cur->ws_info->trickle_pa_running = false;
cur->ws_info->trickle_pcs_running = false;
cur->ws_info->trickle_pc_running = false;

//cur->mac_security_key_usage_update_cb = ws_management_mac_security_key_update_cb;
return;
Expand Down Expand Up @@ -524,9 +524,7 @@ static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interf
if (pan_information->routing_cost <= cur->ws_info->pan_information.routing_cost) {
trickle_consistent_heard(&cur->ws_info->trickle_pan_advertisement);
} else {
if (trickle_running(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_discovery)) {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_discovery);
}
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_discovery);
}

}
Expand Down Expand Up @@ -655,9 +653,7 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
* An inconsistent transmission is defined as:
* A PAN Advertisement Solicit with NETNAME-IE matching that of the receiving node.
*/
if (trickle_running(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_discovery)) {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_discovery);
}
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_discovery);
/*
* A consistent transmission is defined as
* a PAN Advertisement Solicit with NETNAME-IE / Network Name matching that configured on the receiving node.
Expand Down Expand Up @@ -734,9 +730,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
trickle_consistent_heard(&cur->ws_info->trickle_pan_config);
} else {
tr_info("different pan version heard");
if (trickle_running(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery)) {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery);
}
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery);
if (common_serial_number_greater_16(cur->ws_info->pan_information.pan_version, pan_version)) {
// older version heard ignoring the message
return;
Expand Down Expand Up @@ -813,9 +807,7 @@ static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_in
* A PAN Configuration Solicit with a PAN-ID matching that of the receiving node and
* a NETNAME-IE / Network Name matching the network name configured on the receiving
*/
if (trickle_running(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery)) {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery);
}
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery);
}
static bool ws_bootstrap_network_found(protocol_interface_info_entry_t *cur)
{
Expand Down Expand Up @@ -1336,8 +1328,10 @@ static void ws_bootstrap_network_discovery_configure(protocol_interface_info_ent

static void ws_bootstrap_advertise_start(protocol_interface_info_entry_t *cur)
{
cur->ws_info->trickle_pa_running = true;
trickle_start(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_discovery);
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_discovery);
cur->ws_info->trickle_pc_running = true;
trickle_start(&cur->ws_info->trickle_pan_config, &trickle_params_pan_discovery);
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config, &trickle_params_pan_discovery);
}
Expand Down Expand Up @@ -1365,6 +1359,7 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
ws_bootstrap_ip_stack_addr_clear(cur);

// Reset advertisement solicit trickle to start discovering network
cur->ws_info->trickle_pas_running = true;
trickle_start(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_discovery);
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_discovery);

Expand All @@ -1386,6 +1381,7 @@ static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry

cur->ws_info->pas_requests = 0;
// Reset advertisement solicit trickle to start discovering network
cur->ws_info->trickle_pcs_running = true;
trickle_start(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery);
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery);
}
Expand Down Expand Up @@ -1592,8 +1588,11 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
break;
case WS_DISCOVERY_START:
tr_info("Discovery start");
trickle_stop(&cur->ws_info->trickle_pan_advertisement);
trickle_stop(&cur->ws_info->trickle_pan_config);
// All trikkles stopped so here can be entered anytime
cur->ws_info->trickle_pa_running = false;
cur->ws_info->trickle_pc_running = false;
cur->ws_info->trickle_pas_running = false;
cur->ws_info->trickle_pcs_running = false;

if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
tr_debug("Border router start network");
Expand Down Expand Up @@ -1625,25 +1624,33 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
break;
case WS_AUTHENTICATION_START:
tr_info("authentication start");
trickle_stop(&cur->ws_info->trickle_pan_advertisement_solicit);
// only advert sol stopped as we might be doing re authentication
cur->ws_info->trickle_pas_running = false;
//Add Test ecurity key and security level's
ws_bootstrap_set_test_key(cur);
ws_bootstrap_event_configuration_start(cur);
break;
case WS_CONFIGURATION_START:
tr_info("Configuration start");
trickle_stop(&cur->ws_info->trickle_pan_advertisement);
trickle_stop(&cur->ws_info->trickle_pan_config);
// Old configuration is considered invalid stopping all
cur->ws_info->trickle_pa_running = false;
cur->ws_info->trickle_pc_running = false;
cur->ws_info->trickle_pas_running = false;
cur->ws_info->trickle_pcs_running = false;

// Build list of possible neighbours and learn first broadcast schedule

ws_bootstrap_start_configuration_learn(cur);
break;
case WS_OPERATION_START:
tr_info("operation start");
// Advertisements stopped during the RPL scan
cur->ws_info->trickle_pa_running = false;
cur->ws_info->trickle_pc_running = false;
cur->ws_info->trickle_pas_running = false;
cur->ws_info->trickle_pcs_running = false;
// Activate RPL
// Activate IPv6 stack
trickle_stop(&cur->ws_info->trickle_pan_config_solicit);
ws_bootstrap_ip_stack_activate(cur);
ws_bootstrap_rpl_activate(cur);
ws_bootstrap_network_start(cur);
Expand All @@ -1656,6 +1663,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
break;
case WS_ROUTING_READY:
tr_info("Routing ready");
// stopped all to make sure we can enter here from any state
cur->ws_info->trickle_pa_running = false;
cur->ws_info->trickle_pc_running = false;
cur->ws_info->trickle_pas_running = false;
cur->ws_info->trickle_pcs_running = false;

ws_bootstrap_advertise_start(cur);
ws_bootstrap_state_change(cur, ER_BOOTSRAP_DONE);
break;
Expand Down Expand Up @@ -1795,14 +1808,16 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
}
}

void ws_bootstrap_trigle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks)
void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks)
{
if(trickle_timer(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_discovery, ticks)) {
if(cur->ws_info->trickle_pas_running &&
trickle_timer(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_discovery, ticks)) {
// send PAN advertisement solicit
tr_info("Send PAN advertisement Solicit");
ws_bootstrap_pan_advert_solicit(cur);
}
if(trickle_timer(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery, ticks)) {
if(cur->ws_info->trickle_pcs_running &&
trickle_timer(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery, ticks)) {
// send PAN Configuration solicit
if (cur->ws_info->pas_requests > PCS_MAX) {
// if MAX PCS sent restart discovery
Expand All @@ -1814,12 +1829,14 @@ void ws_bootstrap_trigle_timer(protocol_interface_info_entry_t *cur, uint16_t ti
cur->ws_info->pas_requests++;
ws_bootstrap_pan_config_solicit(cur);
}
if(trickle_timer(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_discovery, ticks)) {
if(cur->ws_info->trickle_pa_running &&
trickle_timer(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_discovery, ticks)) {
// send PAN advertisement
tr_info("Send PAN advertisement");
ws_bootstrap_pan_advert(cur);
}
if(trickle_timer(&cur->ws_info->trickle_pan_config, &trickle_params_pan_discovery, ticks)) {
if(cur->ws_info->trickle_pc_running &&
trickle_timer(&cur->ws_info->trickle_pan_config, &trickle_params_pan_discovery, ticks)) {
// send PAN Configuration
tr_info("Send PAN configuration");
ws_bootstrap_pan_config(cur);
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/ws/ws_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ws_bootstrap_configuration_trickle_reset(protocol_interface_info_entry_t *c

void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);

void ws_bootstrap_trigle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);
void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);

#else

Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void ws_common_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seco

void ws_common_fast_timer(protocol_interface_info_entry_t *cur, uint16_t ticks)
{
ws_bootstrap_trigle_timer(cur, ticks);
ws_bootstrap_trickle_timer(cur, ticks);
}


Expand Down
4 changes: 4 additions & 0 deletions source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ typedef struct ws_info_s {
uint32_t pan_version_timeout_timer; /**< routers will fallback to previous state after this */
uint8_t gtkhash[32];
bool configuration_learned:1;
bool trickle_pas_running:1;
bool trickle_pa_running:1;
bool trickle_pcs_running:1;
bool trickle_pc_running:1;
// default fhss parameters for this device
uint8_t fhss_uc_dwell_interval;
uint8_t fhss_bc_dwell_interval;
Expand Down

0 comments on commit b5d276d

Please sign in to comment.