Skip to content

Commit

Permalink
pbbr changes (ARMmbed#1499)
Browse files Browse the repository at this point in the history
Change logic for bbr downgrade to speed up multiple bbr situation

add support for pbbr downgrade

Add RLOC for BB_ANS if present in QRY
  • Loading branch information
Mika Tervonen authored Dec 1, 2017
1 parent 1ece307 commit e058c2a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
6 changes: 3 additions & 3 deletions source/6LoWPAN/Thread/thread_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ static void thread_bbr_status_check(thread_bbr_t *this, uint32_t seconds)
// Check states when we need to remove our BR from network
if (this->br_hosted && this->br_count > 1) {
// Race condition More border routers than there should trigger random delay to remove BR
// our implementation prefers lowest RLOC to drop out to reduce problem time
// our implementation prefers lowest RLOC to to stay to reduce problem time
if (br_lowest_host) {
this->br_delete_timer = randLIB_get_random_in_range(5,10);
} else {
this->br_delete_timer = randLIB_get_random_in_range(20,60);
} else {
this->br_delete_timer = randLIB_get_random_in_range(5,10);
}
tr_info("br: too many BRs start remove jitter: %d", this->br_delete_timer);
return;
Expand Down
80 changes: 67 additions & 13 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "6LoWPAN/Thread/thread_extension_constants.h"
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
#include "6LoWPAN/Thread/thread_resolution_client.h"
#include "6LoWPAN/MAC/mac_helper.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "Common_Protocols/ipv6.h"

Expand Down Expand Up @@ -201,7 +202,7 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_find(int8_t interface_id,
* DUA Registration Sequence Number TLV
* Network Name TLV
*/
static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *destination_addr_ptr, uint8_t *target_eid_ptr, uint8_t *ml_eid_ptr, uint32_t last_transaction_time, uint8_t *network_name_ptr)
static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *destination_addr_ptr, uint8_t *target_eid_ptr, uint8_t *ml_eid_ptr, uint32_t last_transaction_time, uint8_t *network_name_ptr, uint16_t *rloc_ptr)
{
uint8_t *payload_ptr, *ptr;

Expand All @@ -217,6 +218,9 @@ static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *desti
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_ML_EID, 8, ml_eid_ptr);
ptr = thread_meshcop_tlv_data_write_uint32(ptr, TMFCOP_TLV_LAST_TRANSACTION_TIME, last_transaction_time);
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_NETWORK_NAME, stringlen((char *)network_name_ptr, 16), network_name_ptr);
if (rloc_ptr) {
ptr = thread_meshcop_tlv_data_write_uint16(ptr, TMFCOP_TLV_RLOC16, *rloc_ptr);
}

/* UDP Encapsulation TLV */
coap_service_request_send(this->br_bb_service_id, COAP_REQUEST_OPTIONS_NONE, destination_addr_ptr, this->pbbr_port,
Expand Down Expand Up @@ -428,6 +432,8 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
(void)source_port;
uint16_t addr_len;
uint8_t *addr_data_ptr;
uint16_t rloc;
uint16_t *rloc_ptr = NULL;
tr_info("Thread BBR BB_QRY.ntf Received");

thread_pbbr_t *this = thread_border_router_find_by_service(service_id);
Expand All @@ -449,19 +455,23 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],

addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
if (addr_len < 16) {
tr_err("Invalid BB_QRY.ntf message");
tr_warn("Invalid BB_QRY.ntf message");
return 0;
}
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, this->interface_id, NULL);
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_HOST ) {
//address not in mesh
return 0;
}
if (thread_meshcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_RLOC16, &rloc) > 1) {
rloc_ptr = &rloc;
}

uint32_t last_transaction_time = this->mlr_timeout > route->lifetime? this->mlr_timeout - route->lifetime : 0;
uint8_t *ml_eid_ptr = &route->prefix[8];// TODO MLEID needs to be stored in own structure route->info.info and support for dealloc made

// This address is valid in our MESH
thread_border_router_bb_ans_send(this, source_address, addr_data_ptr, ml_eid_ptr, last_transaction_time, link_configuration_ptr->name);
thread_border_router_bb_ans_send(this, source_address, addr_data_ptr, ml_eid_ptr, last_transaction_time, link_configuration_ptr->name, rloc_ptr);

return 0;
}
Expand Down Expand Up @@ -528,7 +538,7 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_HOST);
} else {
// Roaming case lets inform other pbbr that we have newest
thread_border_router_bb_ans_send(this, source_address, tr_ptr->target_eid, tr_ptr->ml_eid, 0, link_configuration_ptr->name);
thread_border_router_bb_ans_send(this, source_address, tr_ptr->target_eid, tr_ptr->ml_eid, 0, link_configuration_ptr->name, NULL);
}
} else {
ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_HOST);
Expand Down Expand Up @@ -720,7 +730,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address

if (entry_keep_alive) {
// send proactive BB_ans.ntf
thread_border_router_bb_ans_send(this, this->pbbr_multicast_address, addr_data_ptr, ml_eid_ptr, 0, link_configuration_ptr->name);
thread_border_router_bb_ans_send(this, this->pbbr_multicast_address, addr_data_ptr, ml_eid_ptr, 0, link_configuration_ptr->name, NULL);
} else {
// send BB.qry
// TODO Create duplicate Transaction to wait answers from Backbone
Expand Down Expand Up @@ -748,6 +758,45 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
coap_service_response_send(this->coap_service_id, COAP_REQUEST_OPTIONS_NONE, request_ptr, response_code, COAP_CT_OCTET_STREAM, payload, ptr - payload);
return 0;
}
static bool thread_extension_bbr_downgrade_to_secondary(struct protocol_interface_info_entry *cur)
{
uint16_t rloc16 = mac_helper_mac16_address_get(cur);
uint16_t highest_rloc16 = rloc16;
uint8_t highest_seq = 0;


ns_list_foreach(thread_network_data_service_cache_entry_t, service, &cur->thread_info->networkDataStorage.service_list) {

if (service->S_enterprise_number != THREAD_ENTERPRISE_NUMBER) {
// Not Thread service
continue;
}
if (service->S_service_data_length < 1 &&
service->S_service_data[0] != THREAD_SERVICE_DATA_BBR) {
//Not pBBR service
continue;
}

ns_list_foreach(thread_network_data_service_server_entry_t, service_instance, &service->server_list) {
if (service_instance->router_id > 0xfffe) {
continue;
}
if (service_instance->server_data_length < 1) {
continue;
}
if (service_instance->server_data[0] > highest_seq) {
highest_seq = service_instance->server_data[0];
highest_rloc16 = service_instance->router_id;
}
}
}
if (highest_rloc16 != rloc16) {
// We are not highest serquence number we
return true;
}
return false;
}


static int thread_border_router_pbbr_nw_data_register(thread_pbbr_t *this)
{
Expand All @@ -770,7 +819,7 @@ static int thread_border_router_pbbr_nw_data_register(thread_pbbr_t *this)
return 0;
}

static int thread_border_router_pbbr_stop(thread_pbbr_t *this)
static int thread_extension_bbr_pbbr_stop(thread_pbbr_t *this)
{
// Create Primary BBR network data and send to leader
uint8_t service_data[1];
Expand Down Expand Up @@ -825,7 +874,7 @@ static int thread_extension_bbr_pbbr_start(thread_pbbr_t *this)
this->br_bb_service_id = coap_service_initialize(this->backbone_interface_id, this->pbbr_port, COAP_SERVICE_OPTIONS_SELECT_SOCKET_IF, NULL, NULL);
if(this->br_bb_service_id < 0) {
tr_error("pBBR service start failed");
thread_border_router_pbbr_stop(this);
thread_extension_bbr_pbbr_stop(this);
return -1;
}
multicast_add_address(this->pbbr_multicast_address, false);
Expand Down Expand Up @@ -910,7 +959,7 @@ void thread_extension_bbr_delete(int8_t interface_id)
if (!this) {
return;
}
thread_border_router_pbbr_stop(this);
thread_extension_bbr_pbbr_stop(this);
coap_service_delete(this->coap_service_id);

ns_list_remove(&pbbr_instance_list, this);
Expand Down Expand Up @@ -947,13 +996,13 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
// Not in commercial network
return;
}
protocol_interface_info_entry_t *cur;
cur = protocol_stack_interface_info_get_by_id(this->interface_id);
if (!cur) {
return;
}
if(!this->pbbr_started) {
// Check if I am valid to start as pBBR
protocol_interface_info_entry_t *cur;
cur = protocol_stack_interface_info_get_by_id(this->interface_id);
if (!cur) {
return;
}
if (thread_attach_ready(cur) != 0) {
//not yet attached
return;
Expand All @@ -974,6 +1023,11 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
// }

thread_extension_bbr_pbbr_start(this);
} else {
if (thread_extension_bbr_downgrade_to_secondary(cur)) {
tr_info("pbbr downgraded");
thread_extension_bbr_pbbr_stop(this);
}
}
// Check secondary state if we need to drop

Expand Down

0 comments on commit e058c2a

Please sign in to comment.