Skip to content

Commit 45504fd

Browse files
Mika TervonenMika Tervonen
authored andcommitted
Optimize stagger based on uptime and startup type
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
1 parent ed5209e commit 45504fd

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
/* Data rate for application used in Stagger calculation */
8686
#define STAGGER_DATARATE_FOR_APPL(n) ((n)*75/100)
8787

88+
/* Time after network is considered stable and smaller stagger values can be given*/
89+
#define STAGGER_STABLE_NETWORK_TIME 3600*4
90+
8891
#ifdef HAVE_RPL
8992
rpl_domain_t *protocol_6lowpan_rpl_domain;
9093
/* Having to sidestep old rpl_dodag_t type for the moment */
@@ -858,7 +861,15 @@ bool protocol_6lowpan_stagger_estimate_get(int8_t interface_id, uint32_t data_am
858861
/*
859862
* Do not occupy whole bandwidth, leave space for network formation etc...
860863
*/
861-
datarate = STAGGER_DATARATE_FOR_APPL(datarate);
864+
if (ws_info(cur_interface) &&
865+
(ws_common_connected_time_get(cur_interface) > STAGGER_STABLE_NETWORK_TIME || ws_common_authentication_time_get(cur_interface) == 0)) {
866+
// After four hours of network connected full bandwidth is given to application
867+
// Authentication has not been required during bootstrap so network load is much smaller
868+
} else {
869+
// Smaller data rate allowed as we have just joined to the network and Authentication was made
870+
datarate = STAGGER_DATARATE_FOR_APPL(datarate);
871+
}
872+
862873
stagger_value = 1 + ((data_amount * 1024 * 8 * network_size) / datarate);
863874
/**
864875
* Example:

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,10 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
11321132
ws_nud_table_reset(cur);
11331133

11341134
ws_bootstrap_candidate_table_reset(cur);
1135+
// Zero uptime counters
1136+
cur->ws_info->uptime = 0;
1137+
cur->ws_info->authentication_time = 0;
1138+
cur->ws_info->connected_time = 0;
11351139

11361140
blacklist_params_set(
11371141
WS_BLACKLIST_ENTRY_LIFETIME,
@@ -1154,6 +1158,8 @@ void ws_bootstrap_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_e
11541158
//Already moved to leaving state.
11551159
return;
11561160
}
1161+
// We are no longer connected
1162+
cur->ws_info->connected_time = 0;
11571163

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

32263232
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, auth_result_e result, uint8_t *target_eui_64)
32273233
{
3228-
(void) target_eui_64;
3229-
32303234
if (result == AUTH_RESULT_OK) {
3231-
tr_debug("authentication success");
3235+
tr_debug("authentication success eui64:%s", trace_array(target_eui_64, 8));
3236+
if (target_eui_64) {
3237+
// Authentication was made contacting the authenticator
3238+
cur->ws_info->authentication_time = cur->ws_info->uptime;
3239+
}
32323240
ws_bootstrap_event_configuration_start(cur);
32333241
} else if (result == AUTH_RESULT_ERR_TX_ERR) {
32343242
// eapol parent selected is not working
@@ -3888,6 +3896,7 @@ void ws_bootstrap_rpl_wait_process(protocol_interface_info_entry_t *cur)
38883896

38893897
if (cur->ws_info->rpl_state == RPL_EVENT_DAO_DONE) {
38903898
// RPL routing is ready
3899+
cur->ws_info->connected_time = cur->ws_info->uptime;
38913900
ws_bootstrap_event_routing_ready(cur);
38923901
} else if (!rpl_control_have_dodag(cur->rpl_domain)) {
38933902
// RPL not ready send DIS message if possible
@@ -4113,6 +4122,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
41134122
} else if (ws_bootstrap_state_active(cur)) {
41144123
ws_stats_update(cur, STATS_WS_STATE_5, 1);
41154124
}
4125+
cur->ws_info->uptime++;
41164126

41174127
ws_llc_timer_seconds(cur, seconds);
41184128

source/6LoWPAN/ws/ws_common.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,30 @@ uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cu
706706
return network_size_estimate;
707707
}
708708

709+
uint32_t ws_common_connected_time_get(protocol_interface_info_entry_t *cur)
710+
{
711+
if (!ws_info(cur)) {
712+
return 0;
713+
}
714+
if (cur->ws_info->connected_time == 0) {
715+
// We are not connected
716+
return 0;
717+
}
718+
return cur->ws_info->uptime - cur->ws_info->connected_time;
719+
}
720+
721+
uint32_t ws_common_authentication_time_get(protocol_interface_info_entry_t *cur)
722+
{
723+
if (!ws_info(cur)) {
724+
return 0;
725+
}
726+
if (cur->ws_info->authentication_time == 0) {
727+
// Authentication was not done when joined to network so time is not known
728+
return 0;
729+
}
730+
return cur->ws_info->uptime - cur->ws_info->authentication_time;
731+
}
732+
709733
void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
710734
{
711735
ws_bootstrap_primary_parent_update(interface, neighbor);

source/6LoWPAN/ws/ws_common.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ typedef struct ws_info_s {
9797
ws_bsi_block_t ws_bsi_block;
9898
uint16_t aro_registration_timer; /**< Aro registration timer */
9999
uint16_t rpl_version_timer; /**< RPL version update timeout */
100-
uint32_t pan_timeout_timer; /**< routers will fallback to previous state after this */
100+
uint32_t pan_timeout_timer; /**< routers will fallback to previous state after this */
101+
uint32_t uptime; /**< Seconds after interface has been started */
102+
uint32_t authentication_time; /**< When the last authentication was performed */
103+
uint32_t connected_time; /**< Time we have been connected to network */
101104
uint32_t pan_config_sol_max_timeout;
102105
uint8_t gtkhash[32];
103106
uint16_t network_pan_id;
@@ -172,6 +175,10 @@ uint32_t ws_common_usable_application_datarate_get(protocol_interface_info_entry
172175

173176
uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cur);
174177

178+
uint32_t ws_common_connected_time_get(protocol_interface_info_entry_t *cur);
179+
180+
uint32_t ws_common_authentication_time_get(protocol_interface_info_entry_t *cur);
181+
175182
void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor);
176183

177184
void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interface);
@@ -195,6 +202,8 @@ void ws_common_border_router_alive_update(protocol_interface_info_entry_t *inter
195202
#define ws_common_datarate_get(cur) 0
196203
#define ws_common_usable_application_datarate_get(cur) 0
197204
#define ws_common_network_size_estimate_get(cur) 0
205+
#define ws_common_connected_time_get(cur) 0
206+
#define ws_common_authentication_time_get(cur) 0
198207
#define ws_common_primary_parent_update(interface, neighbor)
199208
#define ws_common_secondary_parent_update(interface)
200209
#define ws_common_border_router_alive_update(interface) ((void) 0)

source/6LoWPAN/ws/ws_pae_supp.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,7 @@ static void ws_pae_supp_authenticate_response(pae_supp_t *pae_supp, auth_result_
429429
pae_supp->auth_trickle_running = false;
430430
if (pae_supp->auth_requested && pae_supp->auth_completed) {
431431
pae_supp->auth_requested = false;
432-
uint8_t *target_eui_64 = NULL;
433-
if (result != AUTH_RESULT_OK) {
434-
target_eui_64 = pae_supp->target_addr.eui_64;
435-
}
436-
pae_supp->auth_completed(pae_supp->interface_ptr, result, target_eui_64);
432+
pae_supp->auth_completed(pae_supp->interface_ptr, result, pae_supp->target_addr.eui_64);
437433
}
438434
}
439435

test/nanostack/unittest/stub/ws_common_stub.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ uint16_t ws_active_channel_count(uint32_t *channel_mask, uint16_t number_of_chan
127127
return 35;
128128
}
129129

130+
uint32_t ws_common_connected_time_get(protocol_interface_info_entry_t *cur)
131+
{
132+
return 0;
133+
}
134+
135+
uint32_t ws_common_authentication_time_get(protocol_interface_info_entry_t *cur)
136+
{
137+
return 0;
138+
}
139+
130140
void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
131141
{
132142
}

0 commit comments

Comments
 (0)