Skip to content

Commit

Permalink
Add POC code for storing multicast address
Browse files Browse the repository at this point in the history
This code is only usable in interop and testing. Full NVM is needed later

Add validity check when active that if network data is lost pbbr is reset
  • Loading branch information
Mika Tervonen committed Jul 20, 2018
1 parent 684efef commit 1444c2f
Showing 1 changed file with 63 additions and 4 deletions.
67 changes: 63 additions & 4 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ static NS_LIST_DEFINE(duplicate_dua_tr_list, duplicate_dua_tr_t, link);
#define THREAD_BBR_STATUS_NOT_SPECIFIED 6
#define THREAD_BBR_STATUS_BB_LINK_NOT_OPERATIONAL 7


static void thread_border_router_multicast_store_add(thread_pbbr_t *this, uint8_t *destination_addr_ptr);
static void thread_border_router_multicast_store_del(thread_pbbr_t *this, uint8_t *destination_addr_ptr);
static void thread_border_router_multicast_store_activate(thread_pbbr_t *this);

static int stringlen(const char *s, int n)
{
char *end = memchr(s, 0, n);
Expand Down Expand Up @@ -195,7 +200,6 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_find(int8_t interface_id,
return this;
}


/*
* Target EID TLV
* ML-EID TLV
Expand Down Expand Up @@ -652,7 +656,7 @@ static int thread_extension_bbr_bmlr_req_send(int8_t service_id, const uint8_t b
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_IPV6_ADDRESS, addr_len, address_ptr);
ptr = thread_meshcop_tlv_data_write_uint32(ptr, TMFCOP_TLV_TIMEOUT, timeout);

tr_debug("thread BMLR.ntf send; timeout: %"PRIu32, timeout);
tr_debug("thread BMLR.ntf send %s; timeout: %"PRIu32, trace_ipv6(address_ptr), timeout);

coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_NONE, br_addr, THREAD_MANAGEMENT_PORT,
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_BBR_BMLR_NTF, COAP_CT_OCTET_STREAM, payload, ptr - payload, NULL);
Expand Down Expand Up @@ -732,6 +736,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
while (remaining > 0) {
//Go through all addresses
if (!addr_is_ipv6_multicast(addr_ptr)) {
tr_err("Invalid /n/mr not multicast address");
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
if (!invalid_addr_ptr) {
invalid_addr_ptr = addr_ptr;
Expand All @@ -741,12 +746,12 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
//tr_debug("Multicast address: %s delete", trace_ipv6(addr_ptr));
addr_multicast_fwd_remove(cur, addr_ptr);
// TODO remove address from NVM
tr_info("delete multicast address from NVM");
thread_border_router_multicast_store_del(this, addr_ptr);
} else {
//tr_debug("Multicast address: %s Timeout value: %"PRIu32, trace_ipv6(addr_ptr),timeout_value);
multicast_fwd_add(this->interface_id, addr_ptr, timeout_value);
if (timeout_value == 0xffffffff) {
tr_info("Store multicast address to NVM");
thread_border_router_multicast_store_add(this, addr_ptr);
}
// send BMLR.ntf message to backend
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, addr_data_ptr, 16, timeout_value);
Expand Down Expand Up @@ -892,6 +897,51 @@ 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;
}


/*POC for multicast NVM*/
#define MULTICAST_ADDRESS_STORE_AMOUNT 3

typedef struct {
uint8_t addr[16];
} multicast_addr_t;
static multicast_addr_t multicast_store[MULTICAST_ADDRESS_STORE_AMOUNT] = {0};

static void thread_border_router_multicast_store_add(thread_pbbr_t *this, uint8_t *destination_addr_ptr)
{
(void)this;
tr_info("Store multicast address to NVM");
for(int n = 0; n < MULTICAST_ADDRESS_STORE_AMOUNT;n++) {
if (memcmp(multicast_store[n].addr, ADDR_UNSPECIFIED,16) == 0) {
memcpy(multicast_store[n].addr,destination_addr_ptr,16);
break;
}
}
}

static void thread_border_router_multicast_store_del(thread_pbbr_t *this, uint8_t *destination_addr_ptr)
{
(void)this;
tr_info("delete multicast address from NVM");
for(int n = 0; n < MULTICAST_ADDRESS_STORE_AMOUNT;n++) {
if (memcmp(multicast_store[n].addr, destination_addr_ptr,16) == 0) {
memcpy(multicast_store[n].addr,ADDR_UNSPECIFIED,16);
}
}
}

static void thread_border_router_multicast_store_activate(thread_pbbr_t *this)
{
(void)this;
for(int n = 0; n < MULTICAST_ADDRESS_STORE_AMOUNT;n++) {
if (memcmp(multicast_store[n].addr, ADDR_UNSPECIFIED,16) != 0) {
multicast_fwd_add(this->interface_id, multicast_store[n].addr, 0xffffffff);
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, multicast_store[n].addr, 16, 0xffffffff);
}
}
}


static bool thread_extension_bbr_downgrade_to_secondary(struct protocol_interface_info_entry *cur)
{
uint16_t rloc16 = mac_helper_mac16_address_get(cur);
Expand Down Expand Up @@ -1021,6 +1071,7 @@ static int thread_extension_bbr_pbbr_start(thread_pbbr_t *this)
// Register Primary BBR backbone multicast address
multicast_add_address(this->pbbr_multicast_address, false);
this->pbbr_started = true;
thread_border_router_multicast_store_activate(this);

// Register Backbone commercial features
coap_service_register_uri(this->br_bb_service_id, THREAD_URI_BBR_BB_QRY_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_bb_qry_cb);
Expand Down Expand Up @@ -1237,6 +1288,14 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
tr_info("pbbr downgraded");
thread_extension_bbr_pbbr_stop(this);
}
uint8_t bbr_rloc_addr[16];
// If there is no pBBR or I am not pBBR reset
if (0 != thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) ||
!addr_get_entry(cur,bbr_rloc_addr)) {
tr_info("pbbr stop network data not correct");
thread_extension_bbr_pbbr_stop(this);
}


}
// Check secondary state if we need to drop
Expand Down

0 comments on commit 1444c2f

Please sign in to comment.