Skip to content

Commit

Permalink
multicast handling updated(ARMmbed#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakvenugopal authored May 11, 2018
1 parent 44110a1 commit d1cf42d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
14 changes: 3 additions & 11 deletions source/6LoWPAN/Thread/thread_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ typedef struct {
ns_list_link_t link;
} thread_bbr_t;

/*
* Thread PBBR ML-EID map structure
*/
typedef struct {
uint8_t mleid_ptr[8];
uint32_t last_contact_time;
} thread_bbr_mleid_map_t;

/* Neighbor discovery options according to RFC6106 (rfc4861) */
#define RFC6106_RECURSIVE_DNS_SERVER_OPTION 25
#define RFC6106_DNS_SEARCH_LIST_OPTION 31
Expand Down Expand Up @@ -989,7 +981,7 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
if (!this || this->backbone_interface_id < 0) {
return -1;
}
thread_bbr_mleid_map_t *map = ns_dyn_mem_alloc(sizeof(thread_bbr_mleid_map_t));
thread_pbbr_dua_info_t *map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
if (!map) {
goto error;
}
Expand All @@ -1014,13 +1006,13 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
return -2;
}

ipv6_route_info_t *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
//Not found
return NULL;
}
return route->info.info;
return route;
}

int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)
Expand Down
3 changes: 2 additions & 1 deletion source/6LoWPAN/Thread/thread_bbr_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "net_interface.h"
#ifdef HAVE_THREAD_ROUTER
struct ipv6_route;

/**
* \brief Initialize Thread Commissioner relay for BBR and Routers
Expand Down Expand Up @@ -115,7 +116,7 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
*
* \param interface_id addr_data_ptr
*/
ipv6_route_info_t *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);

#else
#define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL)
Expand Down
59 changes: 45 additions & 14 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,15 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
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_DUA_HOST ) {
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST || !route->info.info) {
//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 = 30;
uint32_t last_transaction_time = protocol_core_monotonic_time - ((thread_pbbr_dua_info_t *)route->info.info)->last_contact_time;
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
Expand All @@ -477,6 +477,44 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
return 0;
}

static void thread_pbbr_pro_bb_ntf_process(protocol_interface_info_entry_t *cur, uint8_t* network_name_ptr, uint8_t network_name_len, uint8_t *ml_eid_ptr, uint8_t *addr_data_ptr, uint32_t last_transaction_time)
{
(void) network_name_ptr;
(void) network_name_len;
thread_pbbr_dua_info_t *mleid_dua_map;
thread_pbbr_t *this = thread_border_router_find_by_service(cur->id);
if (!this) {
return;
}
ipv6_route_t *route = thread_bbr_dua_entry_find(cur->id, addr_data_ptr);
if (!route || !route->info.info) {
return;
}
mleid_dua_map = route->info.info;
if (memcmp(mleid_dua_map->mleid_ptr, ml_eid_ptr, 8) == 0) {
// matching ml-eid present in our dua map, device has roamed
if (last_transaction_time <= protocol_core_monotonic_time - mleid_dua_map->last_contact_time) {
// remove entry
goto remove_entry;
} else {
thread_border_router_bb_ans_send(this, this->pbbr_multicast_address, addr_data_ptr, ml_eid_ptr, protocol_core_monotonic_time - mleid_dua_map->last_contact_time, thread_joiner_application_network_name_get(cur->id), NULL);
return;
}
}

// duplicate dua address detected
// Address should be ML-prefix + MLeid TODO create spec issue
uint8_t destination_address[16];
thread_management_get_ml_prefix(cur->id, destination_address);
memcpy(&destination_address[8], mleid_dua_map->mleid_ptr, 8);
thread_resolution_client_address_error(cur->id, destination_address, addr_data_ptr, mleid_dua_map->mleid_ptr);

remove_entry:
tr_info("Remove dua registration for %s", trace_ipv6(addr_data_ptr));
ipv6_route_delete(route->prefix, route->prefix_len, cur->id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_DUA_HOST);
return;
}

static int thread_pbbr_dua_duplicate_address_detection(int8_t service_id, uint8_t *addr_data_ptr, uint8_t *ml_eid_ptr)
{
thread_pbbr_t *this = thread_border_router_find_by_service(service_id);
Expand Down Expand Up @@ -512,9 +550,6 @@ static int thread_pbbr_dua_duplicate_address_detection(int8_t service_id, uint8_
ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_DUA_HOST);
}
return 0;

// TODO check last transaction time for migrated device if this answer is newer delete entry
// ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_HOST);
}

static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16], uint16_t source_port, sn_coap_hdr_s *request_ptr)
Expand Down Expand Up @@ -562,11 +597,7 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],

// If rloc16 is present then a/an is sent to the thread device with the rloc
if (thread_tmfcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_RLOC16, &rloc16) != 2) {
// this is Pro active ANS to inform that device has moved in new network
// This message was sent to multicast address
// in spec there is checks for Last transaction time, but we always know that this message has zero and we have lower
// TODO create function to process
// Delete route to DUA as it is moved
thread_pbbr_pro_bb_ntf_process(cur,network_name_ptr,network_name_len,ml_eid_ptr,addr_data_ptr,last_transaction_time);
return 0;
}

Expand Down Expand Up @@ -787,8 +818,10 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
tr_debug("DUA.req addr:%s ml_eid:%s", trace_array(addr_data_ptr, addr_len), trace_array(ml_eid_ptr, ml_eid_len));

entry_keep_alive = false;
// TODO add ml_eid to structure saved in info pointer to detect duplicates
if (thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr) != NULL) {
ipv6_route_t *route = thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr);

if ( route != NULL && route->info.info != NULL) {
((thread_pbbr_dua_info_t *)route->info.info)->last_contact_time = protocol_core_monotonic_time;
entry_keep_alive = true;
}
if (thread_bbr_dua_entry_add(this->interface_id, addr_data_ptr, 0xFFFFFFFF, ml_eid_ptr) != 0) {
Expand All @@ -803,8 +836,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
}
*/

// Update entry timeout value and sequence number needs to be stored

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, NULL);
Expand Down
8 changes: 8 additions & 0 deletions source/6LoWPAN/Thread/thread_extension_bbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
extern "C" {
#endif

/*
* Thread PBBR ML-EID map structure
*/
typedef struct thread_pbbr_dua_info {
uint8_t mleid_ptr[8];
uint32_t last_contact_time;
} thread_pbbr_dua_info_t;

#if defined(HAVE_THREAD_V2) && defined(HAVE_THREAD_BORDER_ROUTER)

int8_t thread_extension_bbr_init(int8_t interface_id, int8_t backbone_interface_id);
Expand Down

0 comments on commit d1cf42d

Please sign in to comment.