Skip to content

Commit

Permalink
Clear COAP retransmissions in partition change (ARMmbed#1872)
Browse files Browse the repository at this point in the history
-Delete old COAP transactions when partition is changed to prevent
 possible COAP retransmissions.

- Combine coap_service_ids to share service id from thread_management_server.

- Thread BR does not update RLOC if publish has failed
  • Loading branch information
Arto Kinnunen authored Oct 26, 2018
1 parent bf36b91 commit d4c95f2
Show file tree
Hide file tree
Showing 28 changed files with 206 additions and 85 deletions.
2 changes: 1 addition & 1 deletion source/6LoWPAN/Thread/thread_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
return true;
}

if (cur->thread_info->routerIdReqCoapID) {
if (cur->thread_info->routerIdRequested) {
// Router id reguest pending we need to wait for response
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/Thread/thread_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ void thread_bootstrap_attached_finish(protocol_interface_info_entry_t *cur)
cur->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ADDRESS_REGISTER_READY;
cur->lowpan_info &= ~INTERFACE_NWK_ROUTER_DEVICE;
cur->bootsrap_state_machine_cnt = 10;
cur->thread_info->routerIdReqCoapID = 0;
cur->thread_info->routerIdRequested = false;
cur->thread_info->networkDataRequested = false;
clear_power_state(ICMP_ACTIVE);

Expand Down Expand Up @@ -2044,7 +2044,7 @@ void thread_discover_native_commissioner_response(protocol_interface_info_entry_
interface->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ADDRESS_REGISTER_READY;
interface->lowpan_info &= ~INTERFACE_NWK_ROUTER_DEVICE;

interface->thread_info->routerIdReqCoapID = 0;
interface->thread_info->routerIdRequested = false;
interface->thread_info->networkDataRequested = false;

interface->bootsrap_state_machine_cnt = 10;
Expand Down
38 changes: 25 additions & 13 deletions source/6LoWPAN/Thread/thread_border_router_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "NWK_INTERFACE/Include/protocol.h"
#include "6LoWPAN/Thread/thread_config.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
#include "6LoWPAN/Thread/thread_network_data_lib.h"
#include "6LoWPAN/Thread/thread_network_data_storage.h"
#include "6LoWPAN/Thread/thread_management_client.h"
Expand Down Expand Up @@ -591,6 +592,15 @@ void thread_border_router_network_data_update_notify(protocol_interface_info_ent

thread_border_router_network_data_appl_callback(cur);
}

void thread_border_router_old_partition_data_clean(int8_t interface_id)
{
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
if (this) {
coap_service_request_delete_by_service_id(this->coap_service_id);
}
thread_extension_bbr_old_partition_data_clean(interface_id);
}
#endif // HAVE_THREAD_ROUTER

/*External APIs*/
Expand Down Expand Up @@ -837,7 +847,6 @@ int thread_border_router_dns_search_list_option_set(int8_t interface_id, uint8_t
static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t status, uint8_t *data_ptr, uint16_t data_len)
{
protocol_interface_info_entry_t *cur;
(void) status;
(void) data_len;
(void) data_ptr;

Expand All @@ -846,7 +855,7 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
return;
}

cur->thread_info->localServerDataBase.publish_active = false;
cur->thread_info->localServerDataBase.publish_coap_req_id = 0;

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

Expand All @@ -855,9 +864,11 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
thread_border_router_publish(cur->id);
}

// always update RLOC to new one. If COAP response fails then resubmit timer will trigger new a/sd
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
cur->thread_info->localServerDataBase.release_old_address = false;
if (status == 0) {
// If request was successful, then update RLOC to new one.
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
cur->thread_info->localServerDataBase.release_old_address = false;
}
}
#endif

Expand All @@ -884,21 +895,20 @@ int thread_border_router_publish(int8_t interface_id)
rloc16 = mac_helper_mac16_address_get(cur);
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);

if (cur->thread_info->localServerDataBase.publish_active) {
if (cur->thread_info->localServerDataBase.publish_coap_req_id) {
if (rloc16 != cur->thread_info->localServerDataBase.registered_rloc16) {
/*
* Device short address has changed, cancel previous a/sd and a/as requests
* Device short address has changed, cancel previous a/sd requests
* and start resubmit timer
* */
tr_debug("address changed, kill pending reuqests");
thread_management_client_pending_coap_request_kill(cur->id);
tr_debug("RLOC changed, kill pending a/sd request");
thread_management_client_coap_message_delete(cur->id, cur->thread_info->localServerDataBase.publish_coap_req_id);
thread_border_router_resubmit_timer_set(interface_id, 5);
return 0;
} else {
cur->thread_info->localServerDataBase.publish_pending = true;
tr_debug("Activate pending status for publish");
return 0;
}
return 0;
}

//Allocate Memory for Data
Expand Down Expand Up @@ -926,8 +936,10 @@ int thread_border_router_publish(int8_t interface_id)
if (payload_ptr) {
ns_dyn_mem_free(payload_ptr);
}
if (ret_val == 0) {
cur->thread_info->localServerDataBase.publish_active = true;
if (ret_val > 0) {
// a/sd request successful, save coap request id
cur->thread_info->localServerDataBase.publish_coap_req_id = (uint16_t)ret_val;
ret_val = 0 ;
}

thread_border_router_resubmit_timer_set(interface_id, -1);
Expand Down
9 changes: 9 additions & 0 deletions source/6LoWPAN/Thread/thread_border_router_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,22 @@ void thread_border_router_network_data_appl_callback(protocol_interface_info_ent
*
*/
void thread_border_router_network_data_update_notify(protocol_interface_info_entry_t *cur);

/**
* \brief Clear data related to old partition.
*
* \param interface_id Network interface ID.
*/
void thread_border_router_old_partition_data_clean(int8_t interface_id);

#else
#define thread_border_router_init(interface_id)
#define thread_border_router_delete(interface_id)
#define thread_border_router_seconds_timer(interface_id, tics)
#define thread_border_router_resubmit_timer_set(interface_id, seconds)
#define thread_border_router_network_data_appl_callback(cur)
#define thread_border_router_network_data_update_notify(cur)
#define thread_border_router_old_partition_data_clean(interface_id)

#endif
#endif /* THREAD_BORDER_ROUTER_API_INTERNAL_H_ */
17 changes: 14 additions & 3 deletions source/6LoWPAN/Thread/thread_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/Thread/thread_beacon.h"
#include "6LoWPAN/Thread/thread_diagnostic.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
#include "6LoWPAN/Thread/thread_leader_service.h"
#include "6LoWPAN/Thread/thread_routing.h"
#include "DHCPv6_client/dhcpv6_client_api.h"
Expand All @@ -60,6 +62,7 @@
#include "6LoWPAN/Thread/thread_management_internal.h"
#include "6LoWPAN/Thread/thread_management_client.h"
#include "6LoWPAN/Thread/thread_management_server.h"
#include "6LoWPAN/Thread/thread_resolution_server.h"
#include "6LoWPAN/Thread/thread_resolution_client.h"
#include "6LoWPAN/Thread/thread_address_registration_client.h"
#include "6LoWPAN/Thread/thread_resolution_client.h"
Expand Down Expand Up @@ -259,9 +262,11 @@ int8_t thread_bootstrap_down(protocol_interface_info_entry_t *cur)
thread_leader_mleid_rloc_map_to_nvm_write(cur);
thread_bootstrap_stop(cur);
mle_service_interface_unregister(cur->id);
thread_diagnostic_delete(cur->id); // delete before thread_management_server_delete as they share same coap_service id
thread_management_client_delete(cur->id); // delete before thread_management_server_delete as they share same coap_service id
thread_nd_service_disable(cur->id); // delete before thread_management_server_delete as they share same coap_service id
thread_management_server_delete(cur->id);
thread_joiner_application_deinit(cur->id);
thread_management_client_delete(cur->id);
//free network Data
thread_network_data_free_and_clean(&cur->thread_info->networkDataStorage);
//free local also here
Expand Down Expand Up @@ -452,7 +457,7 @@ void thread_data_base_init(thread_info_t *thread_info, int8_t interfaceId)
thread_leader_commissioner_create(thread_info);
thread_info->rfc6775 = false;
thread_info->threadPrivatePrefixInfo.ulaValid = false;
thread_info->routerIdReqCoapID = 0;
thread_info->routerIdRequested = false;
thread_info->networkDataRequested = false;
thread_info->proactive_an_timer = 0;

Expand Down Expand Up @@ -2063,10 +2068,16 @@ void thread_mcast_group_change(struct protocol_interface_info_entry *interface,
}
}

static void thread_old_partition_data_clean(int8_t interface_id)
{
thread_management_client_old_partition_data_clean(interface_id);
thread_border_router_old_partition_data_clean(interface_id);
}

void thread_partition_data_purge(protocol_interface_info_entry_t *cur)
{
/* Partition has been changed. Wipe out data related to old partition */
thread_management_client_pending_coap_request_kill(cur->id);
thread_old_partition_data_clean(cur->id);

/* Reset previous routing information */
thread_routing_reset(&cur->thread_info->routing);
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/Thread/thread_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ typedef struct thread_info_s {
uint16_t routerShortAddress;
uint16_t reedJitterTimer;
uint16_t reedMergeAdvTimer;
uint16_t routerIdReqCoapID; // COAP msg id of RouterID request
int16_t childUpdateReqTimer;
uint16_t childUpdateReqMsgId;
uint16_t proactive_an_timer;
Expand All @@ -323,6 +322,7 @@ typedef struct thread_info_s {
bool rfc6775: 1;
bool requestFullNetworkData: 1;
bool leaderCab: 1;
bool routerIdRequested: 1;
bool releaseRouterId: 1;
bool networkSynch: 1;
bool networkDataRequested: 1;
Expand Down
8 changes: 5 additions & 3 deletions source/6LoWPAN/Thread/thread_diagnostic.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "nsdynmemLIB.h"
#include "net_interface.h"
#include "thread_management_if.h"
#include "thread_management_server.h"
#include "thread_common.h"
#include "thread_joiner_application.h"
#include "thread_leader_service.h"
Expand Down Expand Up @@ -543,7 +544,7 @@ int thread_diagnostic_init(int8_t interface_id)

this->interface_id = interface_id;

this->coap_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_NONE, NULL, NULL);
this->coap_service_id = thread_management_server_service_id_get(interface_id);
if (this->coap_service_id < 0) {
tr_error("Thread diagnostic init failed");
ns_dyn_mem_free(this);
Expand All @@ -567,8 +568,9 @@ int thread_diagnostic_delete(int8_t interface_id)
if (!this) {
return -1;
}

coap_service_delete(this->coap_service_id);
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_DIAGNOSTIC_REQUEST);
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_DIAGNOSTIC_RESET);
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_DIAGNOSTIC_QUERY);
ns_list_remove(&instance_list, this);
ns_dyn_mem_free(this);
return 0;
Expand Down
8 changes: 4 additions & 4 deletions source/6LoWPAN/Thread/thread_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void thread_extension_addr_ntf_send(struct protocol_interface_info_entry *cur, u
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, addr_data_ptr);
ptr = thread_tmfcop_tlv_data_write_uint8(ptr, TMFCOP_TLV_STATUS, bbr_status);

coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_ADDRESS_SHORT,
coap_service_request_send(thread_management_server_service_id_get(cur->id), COAP_REQUEST_OPTIONS_ADDRESS_SHORT,
destination_address, THREAD_MANAGEMENT_PORT,
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST,
THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_CT_OCTET_STREAM,
Expand Down Expand Up @@ -475,7 +475,7 @@ static void thread_extension_dua_registration_send(protocol_interface_info_entry
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, address);
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_ML_EID, 8, ml_eid);

coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE,
coap_service_request_send(thread_management_server_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE,
dst_addr, THREAD_MANAGEMENT_PORT,
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST,
THREAD_URI_BBR_DOMAIN_ADDRESS_REGISTRATION, COAP_CT_OCTET_STREAM,
Expand Down Expand Up @@ -516,7 +516,7 @@ void thread_extension_init(int8_t interface_id, int8_t coap_service_id)

void thread_extension_mtd_service_register(protocol_interface_info_entry_t *cur)
{
coap_service_register_uri(thread_management_client_service_id_get(cur->id), THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_mtd_dua_ntf_cb);
coap_service_register_uri(thread_management_server_service_id_get(cur->id), THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_mtd_dua_ntf_cb);
}

static int thread_extension_mlr_req_send(protocol_interface_info_entry_t *cur, const uint8_t br_addr[16], const uint8_t *address, uint8_t address_len)
Expand All @@ -527,7 +527,7 @@ static int thread_extension_mlr_req_send(protocol_interface_info_entry_t *cur, c
}
tr_debug("thread MLR.req send");

coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE, br_addr, THREAD_MANAGEMENT_PORT,
coap_service_request_send(thread_management_server_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE, br_addr, THREAD_MANAGEMENT_PORT,
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_BBR_MCAST_LISTENER_REPORT, COAP_CT_OCTET_STREAM, address, address_len, thread_comercial_mlr_cb);
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,5 +1455,12 @@ int thread_extension_bbr_sequence_number_set(int8_t interface_id, uint8_t seq_nu
return 0;
}

void thread_extension_bbr_old_partition_data_clean(int8_t interface_id)
{
thread_pbbr_t *this = thread_bbr_find_by_interface(interface_id);
if (this) {
coap_service_request_delete_by_service_id(this->coap_service_id);
}
}

#endif //HAVE_THREAD_BORDER_ROUTER && HAVE_THREAD_V2
2 changes: 2 additions & 0 deletions source/6LoWPAN/Thread/thread_extension_bbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int thread_extension_bbr_timeout_set(int8_t interface_id, uint32_t timeout_a, ui
int thread_extension_bbr_address_set(int8_t interface_id, const uint8_t *addr_ptr, uint16_t port);
void thread_extension_bbr_route_update(protocol_interface_info_entry_t *cur);
int thread_extension_bbr_prefix_set(int8_t interface_id, uint8_t *prefix);
void thread_extension_bbr_old_partition_data_clean(int8_t interface_id);


#else
Expand All @@ -70,6 +71,7 @@ int thread_extension_bbr_prefix_set(int8_t interface_id, uint8_t *prefix);
#define thread_extension_bbr_route_update(cur)
#define thread_extension_bbr_sequence_number_set(interface_id, seq_number) (-1)
#define thread_extension_bbr_prefix_set(interface_id, prefix) 0
#define thread_extension_bbr_old_partition_data_clean(interface_id)
#endif

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit d4c95f2

Please sign in to comment.