Skip to content

Commit 9e6c3a1

Browse files
author
Arto Kinnunen
authored
Update Thread MLE neighbor list cleanup, attempt #2 (#1640)
Update Thread MLE neighbor list cleanup (#1637) -Device needs to clean MLE neighbors (routers and their children) when moving to new partition. Own children can be moved to new partition. -Device is not allowed to update MLE cache based on advertisements from other partition. MLE entries belonging to other partition can be removed from MLE table. -Update traces
1 parent 1060c34 commit 9e6c3a1

File tree

8 files changed

+41
-30
lines changed

8 files changed

+41
-30
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,14 +1159,14 @@ void thread_bootstrap_ready(protocol_interface_info_entry_t *cur)
11591159
mac_data_poll_protocol_poll_mode_decrement(cur);
11601160
}
11611161

1162-
void thread_clean_all_routers_from_neighbor_list(int8_t interface_id)
1163-
{
1164-
mle_neigh_table_list_t *neig_list = mle_class_active_list_get(interface_id);
1165-
/* Init Double linked Routing Table */
1166-
ns_list_foreach_safe(mle_neigh_table_entry_t, cur, neig_list) {
1167-
if (thread_is_router_addr(cur->short_adr)) {
1168-
tr_debug("Free Router %x", cur->short_adr);
1169-
mle_class_remove_entry(interface_id, cur);
1162+
void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur)
1163+
{
1164+
mle_neigh_table_list_t *neig_list = mle_class_active_list_get(cur->id);
1165+
1166+
ns_list_foreach_safe(mle_neigh_table_entry_t, cur_entry, neig_list) {
1167+
if (!thread_addr_is_equal_or_child(cur->thread_info->routerShortAddress, cur_entry->short_adr)) {
1168+
tr_debug("Free ID %x", cur_entry->short_adr);
1169+
mle_class_remove_entry(cur->id, cur_entry);
11701170
}
11711171
}
11721172
}

source/6LoWPAN/Thread/thread_bootstrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void thread_general_mle_receive_cb(int8_t interface_id, mle_message_t *mle_msg,
106106
int thread_bootstrap_reset_child_info(protocol_interface_info_entry_t *cur, struct mle_neigh_table_entry_t *child);
107107
void thread_bootstrap_ready(struct protocol_interface_info_entry *cur);
108108
int thread_bootstrap_reset(struct protocol_interface_info_entry *cur);
109-
void thread_clean_all_routers_from_neighbor_list(int8_t interface_id);
109+
void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur);
110110
bool thread_bootstrap_request_network_data(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, uint16_t short_address);
111111
bool thread_check_is_this_my_parent(struct protocol_interface_info_entry *cur, struct mle_neigh_table_entry_t *entry_temp);
112112
void thread_clean_old_16_bit_address_based_addresses(struct protocol_interface_info_entry *cur);

source/6LoWPAN/Thread/thread_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ int8_t thread_bootstrap_down(protocol_interface_info_entry_t *cur)
233233
tr_debug("SET thread Idle");
234234
//stop polling
235235
mac_data_poll_disable(cur);
236-
//Clean routers from mle table
237-
thread_clean_all_routers_from_neighbor_list(cur->id);
236+
//Clean mle table
237+
thread_neighbor_list_clean(cur);
238238
// store frame counters
239239
if (cur->thread_info) {
240240
thread_nvm_fast_data_t fast_data;
@@ -1849,8 +1849,8 @@ void thread_reset_neighbour_info(protocol_interface_info_entry_t *cur, mle_neigh
18491849
thread_parent_info_t *thread_endnode_parent = thread_info(cur)->thread_endnode_parent;
18501850

18511851
if (!thread_i_am_router(cur) && thread_endnode_parent && thread_endnode_parent->shortAddress == neighbour->short_adr) {
1852-
tr_warn("End device lost Parent!\n");
18531852
if(cur->nwk_bootstrap_state != ER_CHILD_ID_REQ) {
1853+
tr_warn("End device lost parent, reset!\n");
18541854
thread_bootstrap_connection_error(cur->id, CON_PARENT_CONNECT_DOWN, NULL);
18551855
}
18561856
}

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void thread_child_synch_receive_cb(int8_t interface_id, mle_message_t *ml
393393
messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
394394

395395
if (messageId == 0) {
396-
tr_debug("Not for me");
396+
tr_debug("No matching challenge");
397397
return;
398398
}
399399

@@ -471,7 +471,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
471471
return;
472472
}
473473

474-
tr_debug("Thread MLE Parent request response Handler");
474+
tr_debug("MLE Parent response handler");
475475
//State machine What packet should accept in this case
476476
switch (mle_msg->message_type) {
477477
case MLE_COMMAND_PARENT_RESPONSE: {
@@ -496,7 +496,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
496496
messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
497497

498498
if (messageId == 0) {
499-
tr_debug("Not for me");
499+
tr_debug("No matching challenge");
500500
return;
501501
}
502502

@@ -747,7 +747,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
747747
return;
748748
}
749749

750-
tr_debug("Thread MLE Child request response Handler");
750+
tr_debug("Thread MLE Child ID response handler");
751751

752752
switch (mle_msg->message_type) {
753753

@@ -762,7 +762,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
762762
thread_scanned_parent_t *scan_result = thread_info(cur)->thread_attach_scanned_parent;
763763
bool new_entry_created;
764764

765-
tr_info("Received Child ID Response");
765+
tr_info("Recv Child ID Response");
766766

767767
// Validate that response is coming from the scanned parent candidate
768768
memcpy(src_mac64, (mle_msg->packet_src_address + 8), 8);
@@ -779,7 +779,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
779779

780780
cur->thread_info->localServerDataBase.release_old_address = true;
781781

782-
thread_clean_all_routers_from_neighbor_list(cur->id);
782+
thread_neighbor_list_clean(cur);
783783
thread_leader_service_stop(interface_id);
784784
thread_leader_service_leader_data_free(cur->thread_info);
785785
thread_merge_prepare(cur);

source/6LoWPAN/Thread/thread_leader_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ static int thread_leader_service_leader_init(protocol_interface_info_entry_t *cu
12951295
thread_nd_service_delete(cur->id);
12961296
mpl_clear_realm_scope_seeds(cur);
12971297
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
1298-
thread_clean_all_routers_from_neighbor_list(cur->id);
1298+
thread_neighbor_list_clean(cur);
12991299
cur->mesh_callbacks = NULL;
13001300
cur->lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE;
13011301

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
327327
{
328328
mle_tlv_info_t routeTlv;
329329
thread_leader_data_t leaderData;
330-
uint16_t shortAddress;
331330
mle_neigh_table_entry_t *entry_temp;
331+
uint16_t shortAddress;
332+
bool my_parent;
333+
bool adv_from_my_partition;
332334

333335
// Check device mode & bootstrap state
334336
if ((thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE) ||
@@ -346,15 +348,23 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
346348
// Get MLE entry
347349
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
348350

349-
if ((security_headers->KeyIdMode == MAC_KEY_ID_MODE_SRC4_IDX)
350-
&& (thread_instance_id_matches(cur, &leaderData))) {
351+
my_parent = thread_check_is_this_my_parent(cur, entry_temp);
352+
adv_from_my_partition = thread_instance_id_matches(cur, &leaderData);
353+
354+
if ((security_headers->KeyIdMode == MAC_KEY_ID_MODE_SRC4_IDX) && adv_from_my_partition) {
351355
thread_management_key_synch_req(cur->id, common_read_32_bit(security_headers->Keysource));
352356
}
353357

358+
if (entry_temp && !adv_from_my_partition && !my_parent ) {
359+
// Remove MLE entry that are located in other partition and is not my parent
360+
mle_class_remove_entry(cur->id, entry_temp);
361+
entry_temp = NULL;
362+
}
363+
354364
// Check parent status
355365
if (!thread_attach_active_router(cur)) {
356366
//processing for non routers
357-
if (thread_check_is_this_my_parent(cur, entry_temp)) {
367+
if (my_parent) {
358368
//advertisement from parent
359369
if ((thread_info(cur)->thread_leader_data->partitionId != leaderData.partitionId) ||
360370
(thread_info(cur)->thread_leader_data->weighting != leaderData.weighting)) {
@@ -428,7 +438,7 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
428438
messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
429439

430440
if (messageId == 0) {
431-
tr_debug("Not for me");
441+
tr_debug("No matching challenge");
432442
return;
433443
}
434444

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static void thread_router_synch_receive_cb(int8_t interface_id, mle_message_t *m
340340
uint16_t messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
341341

342342
if (messageId == 0) {
343-
tr_debug("Not for me");
343+
tr_debug("No matching challenge");
344344
return;
345345
}
346346
/*Link accept command has an optional MLE Frame counter TLV, if this is not present use link layer frame counter TLV
@@ -896,7 +896,7 @@ static int thread_attach_parent_response_build(protocol_interface_info_entry_t *
896896
if (bufId == 0) {
897897
return -1;
898898
}
899-
tr_debug("MLE ATTACHED 2. Packet");
899+
tr_debug("Build MLE Parent response");
900900

901901
uint32_t keySequence;
902902
uint8_t *ptr = mle_service_get_data_pointer(bufId);
@@ -1359,7 +1359,6 @@ void thread_router_bootstrap_child_id_handler(protocol_interface_info_entry_t *c
13591359
thread_nd_address_registration(cur, tempIPv6Address, entry_temp->short_adr, cur->mac_parameters->pan_id, entry_temp->mac64);
13601360
}
13611361

1362-
tr_debug("Response Child Id Request");
13631362
mle_attach_child_id_response_build(cur,ll64,req, entry_temp);
13641363

13651364
free_request:
@@ -1593,7 +1592,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
15931592
uint16_t messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
15941593

15951594
if (messageId == 0) {
1596-
tr_debug("Not for me");
1595+
tr_debug("No matching challenge");
15971596
return;
15981597
}
15991598

@@ -1608,6 +1607,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
16081607
mle_msg->packet_src_address[8] ^= 2;
16091608

16101609
if (!id_req) {
1610+
tr_debug("No room for child id req");
16111611
return;
16121612
}
16131613

@@ -1629,6 +1629,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
16291629
(!mle_tlv_read_32_bit_tlv(MLE_TYPE_LL_FRAME_COUNTER, mle_msg->data_ptr, mle_msg->data_length, &id_req->frameCounter)) ||
16301630
(!mle_tlv_read_tlv(MLE_TYPE_TLV_REQUEST, mle_msg->data_ptr, mle_msg->data_length, &tlvRequest))) {
16311631
thread_child_id_request_entry_remove(cur, id_req);
1632+
tr_debug("Illegal child id req");
16321633
return;
16331634
}
16341635
//If MLE MLE_TYPE_MLE_FRAME_COUNTER TLV is present then use it for validating further messages else use link layer frame counter
@@ -1829,7 +1830,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
18291830
uint16_t messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
18301831

18311832
if (messageId == 0) {
1832-
tr_debug("Not for me");
1833+
tr_debug("No matching challenge");
18331834
return;
18341835
}
18351836

test/nanostack/unittest/stub/thread_bootstrap_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int8_t thread_mle_class_init(int8_t interface_id)
257257
return 0;
258258
}
259259

260-
void thread_clean_all_routers_from_neighbor_list(int8_t interface_id)
260+
void thread_neighbor_list_clean(protocol_interface_info_entry_t *cur)
261261
{
262262

263263
}

0 commit comments

Comments
 (0)