Skip to content

Commit ffb47a2

Browse files
additional reed advertisement (#1609)
reed advertisement sent when an advertisement from lower partition is heard.
1 parent cfb1e81 commit ffb47a2

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

source/6LoWPAN/Thread/thread_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ typedef struct thread_info_s {
286286
uint16_t native_commissioner_port;
287287
uint16_t routerShortAddress;
288288
uint16_t reedJitterTimer;
289+
uint16_t reedMergeAdvTimer;
289290
uint16_t routerIdReqCoapID; // COAP msg id of RouterID request
290291
int16_t childUpdateReqTimer;
291292
uint16_t childUpdateReqMsgId;

source/6LoWPAN/Thread/thread_constants.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@
174174
#define MIN_DOWNGRADE_NEIGHBORS 7
175175
#define THREAD_REED_ADVERTISEMENT_DELAY 5000
176176

177+
// Interval after which REED can send an advertisement to help others merge to higher partition.
178+
// This is not related to default REED advertisements.
179+
#define THREAD_REED_MERGE_ADVERTISEMENT_INTERVAL 120
180+
177181
/** Default Threshold for router Selection */
178182
#define ROUTER_DOWNGRADE_THRESHOLD 23 // Define downGrade Threshold when active router is higher than this
179183
#define ROUTER_UPGRADE_THRESHOLD 16 // Define upgrade Threshold fort REED when Active Router Count is smaller than this upgrade is possible

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,30 @@ static bool thread_router_leader_data_process(protocol_interface_info_entry_t *c
239239
return true;
240240
}
241241

242+
static bool thread_heard_lower_partition(protocol_interface_info_entry_t *cur, thread_leader_data_t heard_partition_leader_data)
243+
{
244+
if (heard_partition_leader_data.weighting < thread_info(cur)->thread_leader_data->weighting) {
245+
return true;
246+
}
247+
if (heard_partition_leader_data.weighting == thread_info(cur)->thread_leader_data->weighting &&
248+
heard_partition_leader_data.partitionId < thread_info(cur)->thread_leader_data->partitionId) {
249+
return true;
250+
}
251+
return false;
252+
}
253+
242254
static bool thread_reed_partitions_merge(protocol_interface_info_entry_t *cur, uint16_t shortAddress, thread_leader_data_t heard_partition_leader_data)
243255
{
244256
if (thread_is_router_addr(shortAddress)) {
245257
return false;
246258
}
247-
if (thread_extension_version_check(thread_info(cur)->version)) {
248-
// lower weighting heard
249-
if (thread_info(cur)->thread_leader_data->weighting > heard_partition_leader_data.weighting) {
250-
return false;
251-
}
252-
// lower/same partition id heard
253-
if (thread_info(cur)->thread_leader_data->weighting == heard_partition_leader_data.weighting &&
254-
thread_info(cur)->thread_leader_data->partitionId >= heard_partition_leader_data.partitionId ) {
255-
return false;
256-
}
257-
} else if (thread_info(cur)->thread_leader_data->partitionId >= heard_partition_leader_data.partitionId){
259+
// lower weighting heard
260+
if (thread_info(cur)->thread_leader_data->weighting > heard_partition_leader_data.weighting) {
261+
return false;
262+
}
263+
// lower/same partition id heard
264+
if (thread_info(cur)->thread_leader_data->weighting == heard_partition_leader_data.weighting &&
265+
thread_info(cur)->thread_leader_data->partitionId >= heard_partition_leader_data.partitionId ) {
258266
return false;
259267
}
260268
// can merge to a higher weighting/partition id
@@ -385,6 +393,10 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
385393
if (thread_reed_partitions_merge(cur, shortAddress, leaderData)) {
386394
return;
387395
}
396+
// REED advertisement to lower partition to help merge faster
397+
if (thread_heard_lower_partition(cur,leaderData)) {
398+
thread_router_bootstrap_reed_merge_advertisement(cur);
399+
}
388400
} else {
389401
//Router
390402
if (!thread_router_leader_data_process(cur, mle_msg->packet_src_address, &leaderData, &routeTlv, entry_temp) ) {

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,16 @@ void thread_router_bootstrap_reed_advertisements_start(protocol_interface_info_e
23682368
cur->thread_info->routerSelectParameters.reedAdvertisementTimeout = eventOS_timeout_ms(thread_reed_advertisements_cb,timeout, cur);
23692369
}
23702370

2371+
void thread_router_bootstrap_reed_merge_advertisement(protocol_interface_info_entry_t *cur)
2372+
{
2373+
if (cur->thread_info->reedMergeAdvTimer > 1) {
2374+
return;
2375+
}
2376+
thread_reed_advertise(cur);
2377+
// 120s second timer reinitialised before next merge advertisement
2378+
cur->thread_info->reedMergeAdvTimer = THREAD_REED_MERGE_ADVERTISEMENT_INTERVAL;
2379+
2380+
}
23712381
void thread_router_bootstrap_router_id_release(protocol_interface_info_entry_t *cur)
23722382
{
23732383
tr_debug("Router ID Release");
@@ -2417,6 +2427,12 @@ void thread_router_bootstrap_timer(protocol_interface_info_entry_t *cur, uint32_
24172427
}
24182428
}
24192429

2430+
if (cur->thread_info->reedMergeAdvTimer > ticks) {
2431+
cur->thread_info->reedMergeAdvTimer -= ticks;
2432+
} else {
2433+
cur->thread_info->reedMergeAdvTimer = 0;
2434+
}
2435+
24202436
if (!thread_info->leader_private_data && thread_info->thread_attached_state == THREAD_STATE_CONNECTED_ROUTER) {
24212437
// Non leader router checks
24222438
if (thread_info->routing.activated) {

source/6LoWPAN/Thread/thread_router_bootstrap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct mle_security_header;
4545
struct buffer;
4646

4747
void thread_router_bootstrap_reed_advertisements_start(protocol_interface_info_entry_t *cur);
48+
void thread_router_bootstrap_reed_merge_advertisement(protocol_interface_info_entry_t *cur);
4849
int thread_router_bootstrap_mle_advertise(struct protocol_interface_info_entry *cur);
4950

5051
void thread_router_bootstrap_child_information_clear(protocol_interface_info_entry_t *cur);
@@ -101,6 +102,7 @@ void thread_router_bootstrap_address_change_notify_send(protocol_interface_info_
101102
#define thread_router_bootstrap_network_data_distribute(cur)
102103
#define thread_router_bootstrap_routing_allowed(cur) false
103104
#define thread_router_bootstrap_address_change_notify_send(cur)
105+
#define thread_router_bootstrap_reed_merge_advertisement(cur)
104106

105107
#endif/*HAVE_THREAD_ROUTER*/
106108

0 commit comments

Comments
 (0)