Skip to content

Commit d92b2f9

Browse files
author
Arto Kinnunen
authored
Thread advertisement adjustment (ARMmbed#1703)
Thread will not send advertisement when it is attaching. - trickle time advanced if it has less than 6 seconds remaining when starting parent scan - Bootstrap needs to be in completed state before sending MLE advertisement
1 parent 1adb52b commit d92b2f9

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

source/6LoWPAN/Thread/thread_common.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,14 +1019,15 @@ void thread_timer(protocol_interface_info_entry_t *cur, uint8_t ticks)
10191019
return;
10201020
}
10211021

1022-
if (thread_i_am_router(cur)) {
1022+
if (cur->nwk_bootstrap_state != ER_BOOTSRAP_DONE && cur->nwk_bootstrap_state != ER_MLE_ATTACH_READY) {
1023+
/* Own attach is ongoing, do not send advertisements */
1024+
return;
1025+
}
10231026

1027+
if (thread_i_am_router(cur)) {
10241028
if (thread_routing_timer(thread_info, ticks)) {
10251029
thread_router_bootstrap_mle_advertise(cur);
10261030
}
1027-
1028-
} else {
1029-
10301031
}
10311032
}
10321033

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ void thread_network_attach_start(protocol_interface_info_entry_t *cur)
285285
tr_debug("MLE Parent request");
286286
cur->nwk_bootstrap_state = ER_MLE_SCAN;
287287
cur->bootsrap_state_machine_cnt = 0;
288+
/* advance trickle timer by 6 (in 100ms ticks) seconds if needed */
289+
thread_routing_trickle_advance(&cur->thread_info->routing, 6*10);
288290
} else {
289291
cur->bootsrap_state_machine_cnt = 5;
290292
}

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,13 @@ static void thread_reed_advertisements_cb(void* arg)
23422342
protocol_interface_info_entry_t *cur = arg;
23432343

23442344
cur->thread_info->routerSelectParameters.reedAdvertisementTimeout = NULL;
2345+
2346+
if (cur->nwk_bootstrap_state != ER_BOOTSRAP_DONE && cur->nwk_bootstrap_state != ER_MLE_ATTACH_READY) {
2347+
/* Own attach is ongoing, try to send advertisement after few seconds */
2348+
cur->thread_info->routerSelectParameters.reedAdvertisementTimeout = eventOS_timeout_ms(thread_reed_advertisements_cb, 2 * 1000, cur);
2349+
return;
2350+
}
2351+
23452352
if (cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED &&
23462353
cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_ROUTER){
23472354
thread_reed_advertise(cur);

source/6LoWPAN/Thread/thread_routing.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,21 @@ static void thread_trickle_accelerate(trickle_t *t, const trickle_params_t *para
975975
}
976976
}
977977

978+
void thread_routing_trickle_advance(thread_routing_info_t *routing, uint16_t ticks)
979+
{
980+
trickle_t *t =&routing->mle_advert_timer;
981+
982+
if (!trickle_running(t, &thread_mle_advert_trickle_params)) {
983+
return;
984+
}
985+
986+
if ((t->t > t->now) && (t->t - t->now < ticks)) {
987+
/* advance trickle elapsing time by number of ticks */
988+
t->t = t->t + ticks - (t->t - t->now);
989+
tr_debug("trickle advanced to %d, now %d ", t->t, t->now);
990+
}
991+
}
992+
978993
// This functions speeds up next advertisement depending on the disconnect period to leader
979994
void thread_routing_leader_connection_validate(thread_info_t *thread, uint16_t disconnect_period)
980995
{

source/6LoWPAN/Thread/thread_routing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ void thread_routing_free(thread_routing_info_t *routing);
187187
void thread_routing_activate(thread_routing_info_t *routing);
188188
void thread_routing_deactivate(thread_routing_info_t *routing);
189189
bool thread_routing_timer(struct thread_info_s *thread, uint8_t ticks);
190+
void thread_routing_trickle_advance(thread_routing_info_t *routing, uint16_t ticks);
190191
void thread_routing_leader_connection_validate(struct thread_info_s *thread, uint16_t disconnect_period);
191192
void thread_routing_set_mesh_callbacks(protocol_interface_info_entry_t *cur);
192193

@@ -233,6 +234,7 @@ int_fast8_t thread_routing_get_route_data(protocol_interface_info_entry_t *cur,
233234
#define thread_routing_activate(routing)
234235
#define thread_routing_deactivate(routing)
235236
#define thread_routing_timer(thread, ticks) false
237+
#define thread_routing_trickle_advance(routing, ticks)
236238
#define thread_routing_leader_connection_validate(thread, disconnect_period)
237239
#define thread_routing_set_mesh_callbacks(cur)
238240
#define thread_routing_cost_get_by_router_id(routing, routerId) (0)

test/nanostack/unittest/stub/thread_routing_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ bool thread_routing_timer(thread_info_t *thread, uint8_t ticks)
146146
return false;
147147
}
148148

149+
void thread_routing_trickle_advance(thread_routing_info_t *routing, uint16_t ticks)
150+
{
151+
}
152+
149153
void thread_routing_leader_connection_validate(struct thread_info_s *thread, uint16_t disconnect_period)
150154
{
151155
}

0 commit comments

Comments
 (0)