Skip to content

Commit

Permalink
Dua req changes (ARMmbed#1494)
Browse files Browse the repository at this point in the history
DUA.req handling refactored.
  • Loading branch information
deepakvenugopal authored Nov 30, 2017
1 parent 1979df8 commit bade70e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 37 deletions.
43 changes: 43 additions & 0 deletions source/6LoWPAN/Thread/thread_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "thread_management_server.h"
#include "socket_api.h"
#include "coap_service_api.h"
#include "Common_Protocols/icmpv6.h"

#define TRACE_GROUP "tBBR"

Expand Down Expand Up @@ -942,6 +943,48 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
#endif // HAVE_THREAD_ROUTER

#ifdef HAVE_THREAD_BORDER_ROUTER
static int thread_bbr_na_send(int8_t interface_id, uint32_t lifetime, const uint8_t target[static 16])
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur) {
return -1;
}

buffer_t *buffer = icmpv6_build_na(cur, false, true, true, target, NULL, ADDR_UNSPECIFIED);
protocol_push(buffer);
return 0;

}
int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr) {
(void) mleid_ptr;
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
if (!this || this->backbone_interface_id < 0) {
tr_err("bbr not ready");
return -1;
}
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_HOST, info, 0, lifetime, 0);
// We are using route info field to store sequence number
if (!route) {
// Direct route to host allows ND proxying to work
tr_err("out of resources");
return -2;
}
// send NA
thread_bbr_na_send(this->backbone_interface_id, lifetime, addr_data_ptr);

return 0;
}

int thread_bbr_nd_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_HOST ) {
//Not found
return -1;
}
//TODO get information to route to parameters eq mleid, timeout
return 0;
}

int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(handler_interface_id);
Expand Down
17 changes: 17 additions & 0 deletions source/6LoWPAN/Thread/thread_bbr_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t tics);
*/
int thread_bbr_commissioner_proxy_service_update(int8_t interface_id);


#else
#define thread_bbr_init(interface_id, external_commisssioner_port)
#define thread_bbr_delete(interface_id)
Expand Down Expand Up @@ -94,10 +95,26 @@ bool thread_bbr_routing_enabled(protocol_interface_info_entry_t *cur);
*/
void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur);

/**
* \brief Add new nd entry to bbr
*
* \param interface_id addr_data_ptr lifetime info mleid_ptr
*/
int thread_bbr_nd_entry_add(int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr);

/**
* \brief Find if bbr has nd entry
*
* \param interface_id addr_data_ptr
*/
int thread_bbr_nd_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)
#define thread_bbr_routing_enabled(cur) false
#define thread_bbr_network_data_update_notify(cur)
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info, mleid_ptr) (0)
#define thread_bbr_nd_entry_find(interface_id, addr_data_ptr) (0)
#endif //HAVE_THREAD_BORDER_ROUTER


Expand Down
49 changes: 17 additions & 32 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "6LoWPAN/Thread/thread_discovery.h"
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
#include "6LoWPAN/Thread/thread_extension_constants.h"
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "Common_Protocols/ipv6.h"

Expand Down Expand Up @@ -151,21 +152,6 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
return this;
}

static duplicate_dua_tr_t *thread_border_router_dup_tr_create(int8_t interface_id, uint8_t *target_eid_ptr, sn_coap_hdr_s *request_ptr)
{
duplicate_dua_tr_t *this = ns_dyn_mem_alloc(sizeof(duplicate_dua_tr_t));

if (!this) {
return NULL;
}
ns_list_add_to_start(&duplicate_dua_tr_list, this);
memcpy(this->target_eid, target_eid_ptr,16);
this->interface_id = interface_id;
this->request_msg_id = request_ptr->msg_id;
this->ttl = 2;
return this;
}

static void thread_border_router_dup_tr_delete(duplicate_dua_tr_t *this)
{

Expand Down Expand Up @@ -422,7 +408,6 @@ static int thread_pbbr_nmkp_req_recv_cb(int8_t service_id, uint8_t source_addres
static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16], uint16_t source_port, sn_coap_hdr_s *request_ptr)
{
(void)source_port;
(void)source_address;
uint16_t addr_len;
uint8_t *addr_data_ptr;
tr_info("Thread BBR BB_QRY.ntf Received");
Expand Down Expand Up @@ -633,6 +618,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
uint8_t *ml_eid_ptr;
uint8_t payload[2 + 16 + 2 + 2 + 1 + 8];
uint8_t domain_prefix[8];
uint8_t bbr_rloc_addr[16];
uint8_t *ptr;
bool entry_keep_alive = false;
uint8_t bbr_status = THREAD_BBR_STATUS_SUCCESS;
Expand Down Expand Up @@ -663,6 +649,14 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
goto send_response;
}
*/
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(this->interface_id);
if (0 != thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) ||
!addr_get_entry(cur,bbr_rloc_addr)) {
// Primary BBR not present or I am not BBR
bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR;
goto send_response;
}

addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
ml_eid_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_ML_EID, &ml_eid_ptr);

Expand All @@ -683,11 +677,13 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address

entry_keep_alive = true;
// TODO add ml_eid to structure saved in info pointer to detect duplicates
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 ) {
//This is new registration
if (thread_bbr_nd_entry_find(this->interface_id, addr_data_ptr) == 0) {
entry_keep_alive = false;
route = NULL;
}

if (thread_bbr_nd_entry_add(this->interface_id, addr_data_ptr, this->dua_timeout + this->delay_timer/500, NULL, ml_eid_ptr) == -1) {
bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE;
goto send_response;
}
/*if (route && memcmp(route->info.next_hop_addr, ml_addr,16) != 0) {
// MLEID not matching duplicate detected
Expand All @@ -696,14 +692,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
goto send_response;
}
*/
route = ipv6_route_add_with_info(addr_data_ptr, 128, this->interface_id, NULL, ROUTE_THREAD_PROXIED_HOST, NULL, 0, this->dua_timeout + this->delay_timer/500, 0);
// We are using route info field to store sequence number
if (!route) {
// Direct route to host allows ND proxying to work
tr_err("out of resources");
bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE;
goto send_response;
}

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

if (entry_keep_alive) {
Expand All @@ -713,10 +702,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
// send BB.qry
// TODO Delay and replay this meessage and answer the response after 2 seconds passed
thread_border_router_bb_qry_send(this,addr_data_ptr,NULL);
if (thread_border_router_dup_tr_create(this->interface_id, addr_data_ptr, request_ptr) ) {
// Waiting for duplicate timeout
return 0;
}
}
// TODO
// Save RLOC to destination cache with Last transaction time. Should these be made as sticky or should I have own table for these?
Expand Down
14 changes: 9 additions & 5 deletions source/DHCPv6_Server/DHCPv6_Server_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "common_functions.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
#include "Common_Protocols/icmpv6.h"
#include "dhcp_service_api.h"

Expand Down Expand Up @@ -105,13 +106,16 @@ int DHCPv6_server_respond_client(dhcpv6_gua_server_entry_s *serverBase, dhcpv6_r
// coverity[returned_null] for ignoring protocol_stack_interface_info_get_by_id NULL return
DHCPV6_server_service_remove_GUA_from_neighcache(protocol_stack_interface_info_get_by_id(serverBase->interfaceId), nonTemporalAddress.requestedAddress);
}
if (thread_bbr_nd_entry_add(serverBase->interfaceId,dhcp_allocated_address->nonTemporalAddress, nonTemporalAddress.validLifeTime, serverBase->guaPrefix, NULL) == -1) {
// No nanostack BBR present we will put entry for application implemented BBR
ipv6_route_t *route = ipv6_route_add_with_info(dhcp_allocated_address->nonTemporalAddress, 128, serverBase->interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST,serverBase->guaPrefix,0, nonTemporalAddress.validLifeTime, 0);
if (!route) {
address_allocated = false;
libdhcpv6_address_rm_from_allocated_list(serverBase,dhcp_allocated_address->nonTemporalAddress);
}

ipv6_route_t *route = ipv6_route_add_with_info(dhcp_allocated_address->nonTemporalAddress, 128, serverBase->interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST,serverBase->guaPrefix,0, nonTemporalAddress.validLifeTime, 0);
if (!route) {
address_allocated = false;
libdhcpv6_address_rm_from_allocated_list(serverBase,dhcp_allocated_address->nonTemporalAddress);
}

}
}

response->responseLength = libdhcpv6_address_reply_message_len(replyPacket->clientDUID.linkType, replyPacket->serverDUID.linkType, 0, replyPacket->rapidCommit, address_allocated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TEST_SRC_FILES = \
../../stub/protocol_6lowpan_stub.c \
../../stub/system_timer_stub.c \
../../stub/dhcp_service_api_stub.c \
../../stub/thread_bbr_api_stub.c \

include ../../MakefileWorker.mk

Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/thread_bbr_api_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_in
{
return -1;
}

int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr)
{
return -1;
}

0 comments on commit bade70e

Please sign in to comment.