Skip to content

Commit

Permalink
Optimize stagger based on uptime and startup type
Browse files Browse the repository at this point in the history
Give faster stagger values on following situations
if Network has been stable for more than 4 hours
If we joined network without Authentication

Otherwise allow the 75% of bandwidth to be given to Application
  • Loading branch information
Mika Tervonen authored and Mika Tervonen committed Mar 26, 2021
1 parent ed5209e commit 45504fd
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
13 changes: 12 additions & 1 deletion source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
/* Data rate for application used in Stagger calculation */
#define STAGGER_DATARATE_FOR_APPL(n) ((n)*75/100)

/* Time after network is considered stable and smaller stagger values can be given*/
#define STAGGER_STABLE_NETWORK_TIME 3600*4

#ifdef HAVE_RPL
rpl_domain_t *protocol_6lowpan_rpl_domain;
/* Having to sidestep old rpl_dodag_t type for the moment */
Expand Down Expand Up @@ -858,7 +861,15 @@ bool protocol_6lowpan_stagger_estimate_get(int8_t interface_id, uint32_t data_am
/*
* Do not occupy whole bandwidth, leave space for network formation etc...
*/
datarate = STAGGER_DATARATE_FOR_APPL(datarate);
if (ws_info(cur_interface) &&
(ws_common_connected_time_get(cur_interface) > STAGGER_STABLE_NETWORK_TIME || ws_common_authentication_time_get(cur_interface) == 0)) {
// After four hours of network connected full bandwidth is given to application
// Authentication has not been required during bootstrap so network load is much smaller
} else {
// Smaller data rate allowed as we have just joined to the network and Authentication was made
datarate = STAGGER_DATARATE_FOR_APPL(datarate);
}

stagger_value = 1 + ((data_amount * 1024 * 8 * network_size) / datarate);
/**
* Example:
Expand Down
16 changes: 13 additions & 3 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
ws_nud_table_reset(cur);

ws_bootstrap_candidate_table_reset(cur);
// Zero uptime counters
cur->ws_info->uptime = 0;
cur->ws_info->authentication_time = 0;
cur->ws_info->connected_time = 0;

blacklist_params_set(
WS_BLACKLIST_ENTRY_LIFETIME,
Expand All @@ -1154,6 +1158,8 @@ void ws_bootstrap_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_e
//Already moved to leaving state.
return;
}
// We are no longer connected
cur->ws_info->connected_time = 0;

if (cur->rpl_domain && cur->nwk_bootstrap_state == ER_BOOTSRAP_DONE) {
//Stop Asych Timer
Expand Down Expand Up @@ -3225,10 +3231,12 @@ static void ws_bootstrap_nw_info_updated(protocol_interface_info_entry_t *cur, u

static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, auth_result_e result, uint8_t *target_eui_64)
{
(void) target_eui_64;

if (result == AUTH_RESULT_OK) {
tr_debug("authentication success");
tr_debug("authentication success eui64:%s", trace_array(target_eui_64, 8));
if (target_eui_64) {
// Authentication was made contacting the authenticator
cur->ws_info->authentication_time = cur->ws_info->uptime;
}
ws_bootstrap_event_configuration_start(cur);
} else if (result == AUTH_RESULT_ERR_TX_ERR) {
// eapol parent selected is not working
Expand Down Expand Up @@ -3888,6 +3896,7 @@ void ws_bootstrap_rpl_wait_process(protocol_interface_info_entry_t *cur)

if (cur->ws_info->rpl_state == RPL_EVENT_DAO_DONE) {
// RPL routing is ready
cur->ws_info->connected_time = cur->ws_info->uptime;
ws_bootstrap_event_routing_ready(cur);
} else if (!rpl_control_have_dodag(cur->rpl_domain)) {
// RPL not ready send DIS message if possible
Expand Down Expand Up @@ -4113,6 +4122,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
} else if (ws_bootstrap_state_active(cur)) {
ws_stats_update(cur, STATS_WS_STATE_5, 1);
}
cur->ws_info->uptime++;

ws_llc_timer_seconds(cur, seconds);

Expand Down
24 changes: 24 additions & 0 deletions source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,30 @@ uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cu
return network_size_estimate;
}

uint32_t ws_common_connected_time_get(protocol_interface_info_entry_t *cur)
{
if (!ws_info(cur)) {
return 0;
}
if (cur->ws_info->connected_time == 0) {
// We are not connected
return 0;
}
return cur->ws_info->uptime - cur->ws_info->connected_time;
}

uint32_t ws_common_authentication_time_get(protocol_interface_info_entry_t *cur)
{
if (!ws_info(cur)) {
return 0;
}
if (cur->ws_info->authentication_time == 0) {
// Authentication was not done when joined to network so time is not known
return 0;
}
return cur->ws_info->uptime - cur->ws_info->authentication_time;
}

void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
{
ws_bootstrap_primary_parent_update(interface, neighbor);
Expand Down
11 changes: 10 additions & 1 deletion source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ typedef struct ws_info_s {
ws_bsi_block_t ws_bsi_block;
uint16_t aro_registration_timer; /**< Aro registration timer */
uint16_t rpl_version_timer; /**< RPL version update timeout */
uint32_t pan_timeout_timer; /**< routers will fallback to previous state after this */
uint32_t pan_timeout_timer; /**< routers will fallback to previous state after this */
uint32_t uptime; /**< Seconds after interface has been started */
uint32_t authentication_time; /**< When the last authentication was performed */
uint32_t connected_time; /**< Time we have been connected to network */
uint32_t pan_config_sol_max_timeout;
uint8_t gtkhash[32];
uint16_t network_pan_id;
Expand Down Expand Up @@ -172,6 +175,10 @@ uint32_t ws_common_usable_application_datarate_get(protocol_interface_info_entry

uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cur);

uint32_t ws_common_connected_time_get(protocol_interface_info_entry_t *cur);

uint32_t ws_common_authentication_time_get(protocol_interface_info_entry_t *cur);

void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor);

void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interface);
Expand All @@ -195,6 +202,8 @@ void ws_common_border_router_alive_update(protocol_interface_info_entry_t *inter
#define ws_common_datarate_get(cur) 0
#define ws_common_usable_application_datarate_get(cur) 0
#define ws_common_network_size_estimate_get(cur) 0
#define ws_common_connected_time_get(cur) 0
#define ws_common_authentication_time_get(cur) 0
#define ws_common_primary_parent_update(interface, neighbor)
#define ws_common_secondary_parent_update(interface)
#define ws_common_border_router_alive_update(interface) ((void) 0)
Expand Down
6 changes: 1 addition & 5 deletions source/6LoWPAN/ws/ws_pae_supp.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,7 @@ static void ws_pae_supp_authenticate_response(pae_supp_t *pae_supp, auth_result_
pae_supp->auth_trickle_running = false;
if (pae_supp->auth_requested && pae_supp->auth_completed) {
pae_supp->auth_requested = false;
uint8_t *target_eui_64 = NULL;
if (result != AUTH_RESULT_OK) {
target_eui_64 = pae_supp->target_addr.eui_64;
}
pae_supp->auth_completed(pae_supp->interface_ptr, result, target_eui_64);
pae_supp->auth_completed(pae_supp->interface_ptr, result, pae_supp->target_addr.eui_64);
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/nanostack/unittest/stub/ws_common_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ uint16_t ws_active_channel_count(uint32_t *channel_mask, uint16_t number_of_chan
return 35;
}

uint32_t ws_common_connected_time_get(protocol_interface_info_entry_t *cur)
{
return 0;
}

uint32_t ws_common_authentication_time_get(protocol_interface_info_entry_t *cur)
{
return 0;
}

void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
{
}
Expand Down

0 comments on commit 45504fd

Please sign in to comment.