Skip to content

Commit 80af9cb

Browse files
author
Arto Kinnunen
authored
Thread BR network data clearing (ARMmbed#1518)
When Thread BR upgrades from REED to Router is must include REED RLOC to a/sd coap message so that network leader is able to delete REED network data. The REED RLOC was missing when publish attempt was made when previous publish was still active.
1 parent 5a6f6b5 commit 80af9cb

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ void thread_tasklet(arm_event_s *event)
11591159
thread_router_bootstrap_active_router_attach(cur);
11601160
thread_bootstrap_child_id_request(cur);
11611161
if (thread_nd_own_service_list_data_size(&cur->thread_info->localServerDataBase)) {
1162-
// We publish our services if we have some BUG leader cannot remove old ones
1162+
// publish our services to allow leader to remove old ones
11631163
thread_border_router_publish(cur->id);
11641164
}
11651165
thread_router_bootstrap_address_change_notify_send(cur);
@@ -1177,7 +1177,7 @@ void thread_tasklet(arm_event_s *event)
11771177
case THREAD_ATTACH_ROUTER_ID_RELEASED:
11781178
tr_debug_extra("Thread SM THREAD_ATTACH_ROUTER_ID_RELEASED");
11791179
if (thread_nd_own_service_list_data_size(&cur->thread_info->localServerDataBase)) {
1180-
// We publish our services if we have some BUG leader cannot remove old ones
1180+
// publish our services to allow leader to remove old ones
11811181
thread_border_router_publish(cur->id);
11821182
}
11831183
break;

source/6LoWPAN/Thread/thread_border_router_api.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef struct {
8282
/* Neighbor discovery options according to RFC6106 (rfc4861) */
8383
#define RFC6106_RECURSIVE_DNS_SERVER_OPTION 25
8484
#define RFC6106_DNS_SEARCH_LIST_OPTION 31
85+
8586
static NS_LIST_DEFINE(border_router_instance_list, thread_border_router_t, link);
8687

8788

@@ -457,6 +458,7 @@ void thread_border_router_delete(int8_t interface_id)
457458
ns_dyn_mem_free(this->recursive_dns_server_option);
458459
ns_dyn_mem_free(this);
459460
}
461+
460462
void thread_border_router_seconds_timer(int8_t interface_id, uint32_t seconds)
461463
{
462464
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
@@ -783,17 +785,19 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
783785
if (!cur) {
784786
return;
785787
}
786-
// Save the old address
787-
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
788-
cur->thread_info->localServerDataBase.release_old_address = false;
788+
789789
cur->thread_info->localServerDataBase.publish_active = false;
790790

791-
tr_debug("border router status %s, addr: %x",status?"Fail":"Ok", cur->thread_info->localServerDataBase.registered_rloc16);
791+
tr_debug("BR a/sd response status: %s, addr: %x",status?"Fail":"OK", cur->thread_info->localServerDataBase.registered_rloc16);
792792

793793
if (cur->thread_info->localServerDataBase.publish_pending) {
794794
cur->thread_info->localServerDataBase.publish_pending = false;
795795
thread_border_router_publish(cur->id);
796796
}
797+
798+
// always update RLOC to new one. If COAP response fails then resubmit timer will trigger new a/sd
799+
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
800+
cur->thread_info->localServerDataBase.release_old_address = false;
797801
}
798802
#endif
799803

@@ -817,6 +821,9 @@ int thread_border_router_publish(int8_t interface_id)
817821
return -2;
818822
}
819823

824+
rloc16 = mac_helper_mac16_address_get(cur);
825+
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);
826+
820827
if (cur->thread_info->localServerDataBase.publish_active) {
821828
cur->thread_info->localServerDataBase.publish_pending = true;
822829
tr_debug("Activate pending status for publish");
@@ -831,20 +838,18 @@ int thread_border_router_publish(int8_t interface_id)
831838
if (!ptr) {
832839
return -3;
833840
}
834-
rloc16 = mac_helper_mac16_address_get(cur);
835841

836842
ptr = thread_tmfcop_tlv_data_write_header(ptr, TMFCOP_TLV_NETWORK_DATA, network_data_len);
837843
ptr = thread_nd_own_service_list_data_write(&cur->thread_info->localServerDataBase, ptr, rloc16);
838844

839-
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);
840-
841845
if (cur->thread_info->localServerDataBase.registered_rloc16 != 0xffff &&
842846
cur->thread_info->localServerDataBase.release_old_address &&
843847
cur->thread_info->localServerDataBase.registered_rloc16 != rloc16) {
844848
// Our address has changed so we must register our network with new address and remove the old address
845-
tr_debug("Border router Address changed remove old");
849+
tr_debug("BR address changed - remove old %x", cur->thread_info->localServerDataBase.registered_rloc16);
846850
ptr = thread_tmfcop_tlv_data_write_uint16(ptr,TMFCOP_TLV_RLOC16,cur->thread_info->localServerDataBase.registered_rloc16);
847851
}
852+
848853
cur->thread_info->localServerDataBase.registered_rloc16 = rloc16;
849854
ret_val = thread_management_client_network_data_register(cur->id, payload_ptr, ptr - payload_ptr, thread_tmf_client_network_data_set_cb);
850855
if (payload_ptr) {

source/6LoWPAN/Thread/thread_leader_service.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ static int thread_leader_service_petition_ka_cb(int8_t service_id, uint8_t sourc
11221122

11231123
static int thread_leader_service_network_data_register(protocol_interface_info_entry_t *cur, uint8_t *network_data_ptr, uint16_t network_data_length, uint16_t routerId)
11241124
{
1125-
tr_debug("thread leader Register request");
1125+
tr_debug("Register network data for %x", routerId);
11261126
// Mark all data to be cleared
11271127
thread_network_data_router_id_mark_delete(&cur->thread_info->networkDataStorage, routerId, true);
11281128

@@ -1176,8 +1176,8 @@ static int thread_leader_service_register_cb(int8_t service_id, uint8_t source_a
11761176

11771177
if (2 <= thread_tmfcop_tlv_data_get_uint16(payload_ptr, payload_len, TMFCOP_TLV_RLOC16, &old_rloc)) {
11781178
// This will delete everything from old rloc
1179+
tr_warn("Remove network data from: %x", old_rloc);
11791180
ret = thread_leader_service_network_data_register(cur, NULL, 0, old_rloc);
1180-
tr_warn("Removed network data from: %x", old_rloc);
11811181
}
11821182

11831183
if (!thread_tmfcop_tlv_exist(payload_ptr, payload_len, TMFCOP_TLV_NETWORK_DATA)) {

source/6LoWPAN/Thread/thread_management_client.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,9 @@ void thread_management_client_pending_coap_request_kill(int8_t interface_id)
614614
return;
615615
}
616616

617+
cur->thread_info->localServerDataBase.publish_active = false;
618+
617619
if (this->coap_asd_msg_id != 0) {
618-
cur->thread_info->localServerDataBase.publish_active = false;
619620
coap_service_request_delete(this->coap_service_id, this->coap_asd_msg_id);
620621
this->coap_asd_msg_id = 0;
621622
}

source/6LoWPAN/Thread/thread_network_data_storage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ typedef struct thread_network_local_data_cache_entry_s {
185185
thread_network_data_service_list_t service_list;
186186
uint16_t registered_rloc16;/*!< Address used for latest registration */
187187
bool release_old_address:1;/*!< true if release of old address is needed */
188-
bool publish_active:1;
189-
bool publish_pending:1;
188+
bool publish_active:1;/*!< true when publish is active */
189+
bool publish_pending:1;/*!< true when publish attempt made during active publish */
190190
} thread_network_local_data_cache_entry_t;
191191

192192
/**

0 commit comments

Comments
 (0)