Skip to content

Commit

Permalink
ETX service update
Browse files Browse the repository at this point in the history
Removed MLE dependency from ETX module API by unique attribute_index.
Attribute index is same what is used for SW MAC and it works like a
pointer to define pointer to storage list.

Defined etx storage structure which include neighbour etx information
and removed same parameters from mle_table_entry_t.

Added ETX storage allocate function for allocate requirement etx info
entries.

Adaptation interface have separate etx update enable function for
6lowpan and thread

Fixed Unit test's.

Change-Id: I2cf73d204dd6cdbe0e44dd8a155cd4200bdb4237
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Mar 12, 2018
1 parent e5aba03 commit 0efc062
Show file tree
Hide file tree
Showing 20 changed files with 612 additions and 326 deletions.
12 changes: 9 additions & 3 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c
Expand Up @@ -72,6 +72,7 @@
#include "6LoWPAN/MAC/mpx_api.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
#include "Service_Libs/etx/etx.h"


#define TRACE_GROUP_LOWPAN "6lo"
Expand Down Expand Up @@ -487,6 +488,7 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
neigh_table_ptr = mle_class_get_by_link_address(interface_id, addr_ptr + PAN_ID_LEN, addr_type);

if (neigh_table_ptr) {
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, neigh_table_ptr->attribute_index);
// If primary parent has changed clears priority from previous parent
if (!neigh_table_ptr->priorityFlag) {
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST);
Expand All @@ -500,8 +502,9 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_SHORT, temp);
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_LONG, neigh_table_ptr->mac64);
}

protocol_stats_update(STATS_ETX_1ST_PARENT, neigh_table_ptr->etx >> 4);
if (etx_entry) {
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
}
return 1;
} else {
return 0;
Expand All @@ -519,12 +522,15 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
neigh_table_ptr = mle_class_get_by_link_address(interface_id, addr_ptr + PAN_ID_LEN, addr_type);

if (neigh_table_ptr) {
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, neigh_table_ptr->attribute_index);
// If secondary parent has changed clears priority from previous parent
if (neigh_table_ptr->second_priority_flag == 0) {
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_2ND);
}
neigh_table_ptr->second_priority_flag = 1;
protocol_stats_update(STATS_ETX_2ND_PARENT, neigh_table_ptr->etx >> 4);
if (etx_entry) {
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
}
return 1;
} else {
return 0;
Expand Down
33 changes: 24 additions & 9 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_bootstrap.c
Expand Up @@ -69,6 +69,7 @@
#include "mac_api.h"
#include "6LoWPAN/MAC/mac_data_poll.h"
#include "libNET/src/net_load_balance_internal.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "6LoWPAN/NVM/nwk_nvm.h"


Expand All @@ -90,7 +91,7 @@ static void protocol_6lowpan_bootstrap_rpl_callback(rpl_event_t event, void *han
#endif

static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_entry *cur_interface, uint8_t entry_count, uint8_t force_priority);
static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *mle_neigh_table, uint8_t entry_count);
static uint8_t protocol_6lowpan_mle_order_last_entries(int8_t interface_id,mle_neigh_table_list_t *mle_neigh_table, uint8_t entry_count);
static uint8_t protocol_6lowpan_mle_data_allocate(void);
static bool mle_accept_request_cb(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* status);
Expand Down Expand Up @@ -469,7 +470,7 @@ static uint8_t *mle_table_set_neighbours(int8_t interface_id, uint8_t *ptr)
*ptr++ = MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK;
}

*ptr++ = etx_local_incoming_idr_read(interface_id, cur) >> 3;
*ptr++ = etx_local_incoming_idr_read(interface_id, cur->attribute_index) >> 3;

if ((*link_flags_ptr & 0x07) == 1) {
ptr = common_write_16_bit(cur->short_adr, ptr);
Expand Down Expand Up @@ -610,7 +611,7 @@ static void mle_neigh_entry_update_by_mle_tlv_list(int8_t interface_id, mle_neig
uint8_t link_idr;
uint8_t iop_flags;
if (mle_link_quality_tlv_parse(mac64, short_address, mle_tlv_info.dataPtr, mle_tlv_info.tlvLen, &iop_flags, &link_idr)) {
etx_remote_incoming_idr_update(interface_id, link_idr, entry_temp);
etx_remote_incoming_idr_update(interface_id, link_idr, entry_temp->attribute_index);

if ((iop_flags & MLE_NEIGHBOR_PRIORITY_LINK) == MLE_NEIGHBOR_PRIORITY_LINK) {
entry_temp->priority_child_flag = true;
Expand Down Expand Up @@ -986,8 +987,10 @@ int protocol_6lowpan_router_synch_to_new_router(protocol_interface_info_entry_t

static uint8_t mle_calculate_idr(int8_t interface_id, mle_message_t *mle_msg, mle_neigh_table_entry_t *entry_temp)
{

return etx_lqi_dbm_update(interface_id, mle_msg->lqi, mle_msg->dbm, entry_temp) >> 3;
if (!entry_temp) {
return etx_lqi_dbm_update(-2, mle_msg->lqi, mle_msg->dbm, 0) >> 3;
}
return etx_lqi_dbm_update(interface_id, mle_msg->lqi, mle_msg->dbm, entry_temp->attribute_index) >> 3;

}

Expand Down Expand Up @@ -1315,7 +1318,7 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_
return;
}

entry_count = protocol_6lowpan_mle_order_last_entries(mle_neigh_table, entry_count);
entry_count = protocol_6lowpan_mle_order_last_entries(cur_interface->id, mle_neigh_table, entry_count);

ns_list_foreach_reverse_safe(mle_neigh_table_entry_t, entry, mle_neigh_table) {
if (++count > entry_count) {
Expand Down Expand Up @@ -1343,12 +1346,12 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_
}
}

static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *mle_neigh_table, uint8_t entry_count)
static uint8_t protocol_6lowpan_mle_order_last_entries(int8_t interface_id, mle_neigh_table_list_t *mle_neigh_table, uint8_t entry_count)
{
mle_neigh_table_entry_t *last;
mle_neigh_table_entry_t *first_ordered = NULL;
etx_storage_t * etx_last, *etx_cur;
uint8_t count = 0;

do {
last = NULL;

Expand All @@ -1363,6 +1366,8 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *m
continue;
}



// Primary parent (parent selected for bootstrap or RPL primary parent)
if (entry->priorityFlag && !last->priorityFlag) {
continue;
Expand All @@ -1379,7 +1384,10 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *m
}

// Better ETX
if (entry->etx <= last->etx) {
etx_cur = etx_storage_entry_get(interface_id, entry->attribute_index);
etx_last = etx_storage_entry_get(interface_id, last->attribute_index);

if (etx_cur && etx_last && etx_cur->etx <= etx_last->etx) {
continue;
}

Expand Down Expand Up @@ -1678,6 +1686,13 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
if (mle_class_init(interface_id, buffer.device_decription_table_size, &protocol_6lowpan_neighbor_information_remove, &protocol_6lowpan_host_challenge, &lowpan_interface_is_active) != 0) {
return -1;
}

if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
return -1;
}

lowpan_adaptation_interface_etx_update_enable(cur->id);

mle_class_router_challenge(interface_id, protocol_6lowpan_router_challenge);
}

Expand Down
8 changes: 8 additions & 0 deletions source/6LoWPAN/Thread/thread_bootstrap.c
Expand Up @@ -89,9 +89,11 @@
#include "thread_meshcop_lib.h"
#include "multicast_api.h"
#include "mlme.h"
#include "Service_Libs/etx/etx.h"
#include "Service_Libs/nd_proxy/nd_proxy.h"
#include "Service_Libs/blacklist/blacklist.h"
#include "6LoWPAN/MAC/mac_data_poll.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"

#define TRACE_GROUP "thbs"

Expand Down Expand Up @@ -154,6 +156,12 @@ int8_t thread_mle_class_init(int8_t interface_id)
return -1;
}

if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
return -1;
}

lowpan_adaptation_interface_etx_update_enable(cur->id);

mle_class_router_challenge(interface_id, NULL);

//Defined well know neighbour for discovery
Expand Down
9 changes: 7 additions & 2 deletions source/6LoWPAN/Thread/thread_common.c
Expand Up @@ -104,7 +104,7 @@ thread_leader_data_t *thread_leader_data_generate(void);
thread_parent_info_t *thread_parent_data_allocate(thread_info_t *info);
static uint8_t * thread_joining_port_tlv_write(uint16_t port, uint8_t *ptr);
static uint8_t * thread_commissioner_port_tlv_write(uint16_t port, uint8_t *ptr);
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, mle_neigh_table_entry_t *neighbor);
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, uint8_t attribute_index);
static void thread_address_notification_cb(struct protocol_interface_info_entry *interface, const struct if_address_entry *addr, if_address_callback_t reason);

/* Helper functions*/
Expand Down Expand Up @@ -1827,7 +1827,7 @@ static uint8_t * thread_commissioner_port_tlv_write(uint16_t port, uint8_t *ptr)
return common_write_16_bit(port, ptr);
}

static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, mle_neigh_table_entry_t *neighbor)
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, uint8_t attribute_index)
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(nwk_id);

Expand All @@ -1837,6 +1837,11 @@ static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failure
return;
}

mle_neigh_table_entry_t *neighbor = mle_class_get_by_device_attribute_id(cur->id, attribute_index);
if (!neighbor) {
return;
}

if (accumulated_failures >= THREAD_MAC_TRANSMISSIONS*THREAD_FAILED_CHILD_TRANSMISSIONS) {
thread_reset_neighbour_info(cur, neighbor);
}
Expand Down
67 changes: 51 additions & 16 deletions source/6LoWPAN/adaptation_interface.c
Expand Up @@ -46,6 +46,8 @@

#define TRACE_GROUP "6lAd"

typedef void (adaptation_etx_update_cb)(protocol_interface_info_entry_t *cur, buffer_t *buf, const mcps_data_conf_t *confirm);

// #define EXTRA_DEBUG_EXTRA
#ifdef EXTRA_DEBUG_EXTRA
#define tr_debug_extra(...) tr_debug(__VA_ARGS__)
Expand Down Expand Up @@ -89,6 +91,7 @@ typedef struct {
uint16_t max_indirect_big_packets_total;
uint16_t max_indirect_small_packets_per_child;
bool fragmenter_active; /*!< Fragmenter state */
adaptation_etx_update_cb *etx_update_cb;
mpx_api_t *mpx_api;
uint16_t mpx_user_id;
ns_list_link_t link; /*!< List link entry */
Expand Down Expand Up @@ -129,6 +132,43 @@ static void lowpan_adaptation_indirect_queue_free_message(struct protocol_interf

static fragmenter_tx_entry_t* lowpan_adaptation_indirect_mac_data_request_active(fragmenter_interface_t *interface_ptr, fragmenter_tx_entry_t *tx_ptr);

static void lowpan_adaptation_etx_update_cb(protocol_interface_info_entry_t *cur, buffer_t *buf, const mcps_data_conf_t *confirm)
{
switch (confirm->status) {
case MLME_TX_NO_ACK:
case MLME_NO_DATA:
case MLME_SUCCESS:
if (buf->link_specific.ieee802_15_4.requestAck) {
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) {
bool success = false;
if (confirm->status == MLME_SUCCESS) {
success = true;
}
// Gets table entry
mle_neigh_table_entry_t *neigh_table_ptr = mle_class_get_by_link_address(cur->id, buf->dst_sa.address + PAN_ID_LEN, buf->dst_sa.addr_type);
if (neigh_table_ptr) {
etx_transm_attempts_update(cur->id, 1 + confirm->tx_retries , success, neigh_table_ptr->attribute_index);
// Updates ETX statistics
etx_storage_t * etx_entry = etx_storage_entry_get(cur->id, neigh_table_ptr->attribute_index);
if (etx_entry) {
if (neigh_table_ptr->priorityFlag) {
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
} else if (neigh_table_ptr->second_priority_flag) {
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
}
}
}
}
}
break;
default:

break;

}
}


//Discover
static fragmenter_interface_t *lowpan_adaptation_interface_discover(int8_t interfaceId)
{
Expand Down Expand Up @@ -321,6 +361,14 @@ int8_t lowpan_adaptation_interface_init(int8_t interface_id, uint16_t mac_mtu_si
return 0;
}

void lowpan_adaptation_interface_etx_update_enable(int8_t interface_id)
{
fragmenter_interface_t *interface_ptr = lowpan_adaptation_interface_discover(interface_id);
if (interface_ptr) {
interface_ptr->etx_update_cb = lowpan_adaptation_etx_update_cb;
}
}

int8_t lowpan_adaptation_interface_free(int8_t interface_id)
{
//Discover
Expand Down Expand Up @@ -1022,23 +1070,10 @@ int8_t lowpan_adaptation_interface_tx_confirm(protocol_interface_info_entry_t *c
}
}

switch (confirm->status) {
case MLME_TX_NO_ACK:
case MLME_NO_DATA:
case MLME_SUCCESS:
if (buf->link_specific.ieee802_15_4.requestAck) {
bool success = false;
if (confirm->status == MLME_SUCCESS) {
success = true;
}
etx_transm_attempts_update(cur->id, 1 + confirm->tx_retries , success, buf->dst_sa.addr_type, buf->dst_sa.address);
}
break;
default:

break;

if (interface_ptr->etx_update_cb) {
interface_ptr->etx_update_cb(cur, buf, confirm);
}

//Switch original channel back
if (buf->link_specific.ieee802_15_4.rf_channel_switch) {
mac_helper_mac_channel_set(cur, buf->link_specific.ieee802_15_4.selected_channel);
Expand Down
2 changes: 2 additions & 0 deletions source/6LoWPAN/lowpan_adaptation_interface.h
Expand Up @@ -27,6 +27,8 @@ struct mpx_api_s;

int8_t lowpan_adaptation_interface_init(int8_t interface_id, uint16_t mac_mtu_size);

void lowpan_adaptation_interface_etx_update_enable(int8_t interface_id);

int8_t lowpan_adaptation_interface_free(int8_t interface_id);

int8_t lowpan_adaptation_interface_reset(int8_t interface_id);
Expand Down
6 changes: 6 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.c
Expand Up @@ -47,6 +47,7 @@
#include "6LoWPAN/ws/ws_neighbor_class.h"
#include "6LoWPAN/ws/ws_ie_lib.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "Service_Libs/etx/etx.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "platform/topo_trace.h"

Expand Down Expand Up @@ -680,6 +681,10 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
return -2;
}

if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
return -1;
}

switch (bootstrap_mode) {
// case NET_6LOWPAN_SLEEPY_HOST:
case NET_6LOWPAN_HOST:
Expand Down Expand Up @@ -749,6 +754,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
init_fail:
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
mac_neighbor_table_delete(cur->mac_parameters->mac_neighbor_table);
etx_storage_list_allocate(cur->id, 0);
ws_neighbor_class_dealloc(&neigh_info);
ws_llc_delete(cur);
return ret_val;
Expand Down
8 changes: 4 additions & 4 deletions source/MLE/mle.c
Expand Up @@ -138,7 +138,7 @@ static void mle_table_class_list_free(mle_table_class_t *mle_table_class) {
//Call Remove callback
mle_table_class->remove_cb(mle_table_class->interfaceId, cur);
//Removes ETX neighbor
etx_neighbor_remove(mle_table_class->interfaceId, cur);
etx_neighbor_remove(mle_table_class->interfaceId, cur->attribute_index);
ns_list_add_to_start(&mle_table_class->free_enty_list, cur);
}
topo_trace(TOPOLOGY_MLE, NULL, TOPO_CLEAR);
Expand Down Expand Up @@ -586,7 +586,7 @@ int8_t mle_class_remove_entry(int8_t interface_id, mle_neigh_table_entry_t *entr
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);

//Removes ETX neighbor
etx_neighbor_remove(interface_id, entry);
etx_neighbor_remove(interface_id, entry->attribute_index);
//Add to free list
ns_list_add_to_start(&mle_class_ptr->free_enty_list, entry);
return 0;
Expand Down Expand Up @@ -614,7 +614,7 @@ int8_t mle_class_remove_neighbour(int8_t interface_id, const uint8_t *address, a
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);

//Removes ETX neighbor
etx_neighbor_remove(interface_id, entry);
etx_neighbor_remove(interface_id, entry->attribute_index);
//Add to free list
ns_list_add_to_start(&mle_class_ptr->free_enty_list, entry);

Expand Down Expand Up @@ -689,7 +689,7 @@ static void mle_class_table_ttl(uint16_t ticks, mle_table_class_t *mle_class_ptr
mle_class_ptr->remove_cb(mle_class_ptr->interfaceId, cur);
topo_trace(TOPOLOGY_MLE, cur->ext64, TOPO_REMOVE);
//Removes ETX neighbor
etx_neighbor_remove(mle_class_ptr->interfaceId, cur);
etx_neighbor_remove(mle_class_ptr->interfaceId, cur->attribute_index);
//Add to free list
ns_list_add_to_start(&mle_class_ptr->free_enty_list, cur);

Expand Down

0 comments on commit 0efc062

Please sign in to comment.