Skip to content

Commit 0efc062

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
ETX service update
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
1 parent e5aba03 commit 0efc062

File tree

20 files changed

+612
-326
lines changed

20 files changed

+612
-326
lines changed

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "6LoWPAN/MAC/mpx_api.h"
7373
#include "6LoWPAN/lowpan_adaptation_interface.h"
7474
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
75+
#include "Service_Libs/etx/etx.h"
7576

7677

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

489490
if (neigh_table_ptr) {
491+
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, neigh_table_ptr->attribute_index);
490492
// If primary parent has changed clears priority from previous parent
491493
if (!neigh_table_ptr->priorityFlag) {
492494
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST);
@@ -500,8 +502,9 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
500502
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_SHORT, temp);
501503
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_LONG, neigh_table_ptr->mac64);
502504
}
503-
504-
protocol_stats_update(STATS_ETX_1ST_PARENT, neigh_table_ptr->etx >> 4);
505+
if (etx_entry) {
506+
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
507+
}
505508
return 1;
506509
} else {
507510
return 0;
@@ -519,12 +522,15 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
519522
neigh_table_ptr = mle_class_get_by_link_address(interface_id, addr_ptr + PAN_ID_LEN, addr_type);
520523

521524
if (neigh_table_ptr) {
525+
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, neigh_table_ptr->attribute_index);
522526
// If secondary parent has changed clears priority from previous parent
523527
if (neigh_table_ptr->second_priority_flag == 0) {
524528
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_2ND);
525529
}
526530
neigh_table_ptr->second_priority_flag = 1;
527-
protocol_stats_update(STATS_ETX_2ND_PARENT, neigh_table_ptr->etx >> 4);
531+
if (etx_entry) {
532+
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
533+
}
528534
return 1;
529535
} else {
530536
return 0;

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_bootstrap.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "mac_api.h"
7070
#include "6LoWPAN/MAC/mac_data_poll.h"
7171
#include "libNET/src/net_load_balance_internal.h"
72+
#include "6LoWPAN/lowpan_adaptation_interface.h"
7273
#include "6LoWPAN/NVM/nwk_nvm.h"
7374

7475

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

9293
static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_entry *cur_interface, uint8_t entry_count, uint8_t force_priority);
93-
static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *mle_neigh_table, uint8_t entry_count);
94+
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);
9495
static uint8_t protocol_6lowpan_mle_data_allocate(void);
9596
static bool mle_accept_request_cb(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
9697
static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* status);
@@ -469,7 +470,7 @@ static uint8_t *mle_table_set_neighbours(int8_t interface_id, uint8_t *ptr)
469470
*ptr++ = MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK;
470471
}
471472

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

474475
if ((*link_flags_ptr & 0x07) == 1) {
475476
ptr = common_write_16_bit(cur->short_adr, ptr);
@@ -610,7 +611,7 @@ static void mle_neigh_entry_update_by_mle_tlv_list(int8_t interface_id, mle_neig
610611
uint8_t link_idr;
611612
uint8_t iop_flags;
612613
if (mle_link_quality_tlv_parse(mac64, short_address, mle_tlv_info.dataPtr, mle_tlv_info.tlvLen, &iop_flags, &link_idr)) {
613-
etx_remote_incoming_idr_update(interface_id, link_idr, entry_temp);
614+
etx_remote_incoming_idr_update(interface_id, link_idr, entry_temp->attribute_index);
614615

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

987988
static uint8_t mle_calculate_idr(int8_t interface_id, mle_message_t *mle_msg, mle_neigh_table_entry_t *entry_temp)
988989
{
989-
990-
return etx_lqi_dbm_update(interface_id, mle_msg->lqi, mle_msg->dbm, entry_temp) >> 3;
990+
if (!entry_temp) {
991+
return etx_lqi_dbm_update(-2, mle_msg->lqi, mle_msg->dbm, 0) >> 3;
992+
}
993+
return etx_lqi_dbm_update(interface_id, mle_msg->lqi, mle_msg->dbm, entry_temp->attribute_index) >> 3;
991994

992995
}
993996

@@ -1315,7 +1318,7 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_
13151318
return;
13161319
}
13171320

1318-
entry_count = protocol_6lowpan_mle_order_last_entries(mle_neigh_table, entry_count);
1321+
entry_count = protocol_6lowpan_mle_order_last_entries(cur_interface->id, mle_neigh_table, entry_count);
13191322

13201323
ns_list_foreach_reverse_safe(mle_neigh_table_entry_t, entry, mle_neigh_table) {
13211324
if (++count > entry_count) {
@@ -1343,12 +1346,12 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_
13431346
}
13441347
}
13451348

1346-
static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *mle_neigh_table, uint8_t entry_count)
1349+
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)
13471350
{
13481351
mle_neigh_table_entry_t *last;
13491352
mle_neigh_table_entry_t *first_ordered = NULL;
1353+
etx_storage_t * etx_last, *etx_cur;
13501354
uint8_t count = 0;
1351-
13521355
do {
13531356
last = NULL;
13541357

@@ -1363,6 +1366,8 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *m
13631366
continue;
13641367
}
13651368

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

13811386
// Better ETX
1382-
if (entry->etx <= last->etx) {
1387+
etx_cur = etx_storage_entry_get(interface_id, entry->attribute_index);
1388+
etx_last = etx_storage_entry_get(interface_id, last->attribute_index);
1389+
1390+
if (etx_cur && etx_last && etx_cur->etx <= etx_last->etx) {
13831391
continue;
13841392
}
13851393

@@ -1678,6 +1686,13 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
16781686
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) {
16791687
return -1;
16801688
}
1689+
1690+
if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
1691+
return -1;
1692+
}
1693+
1694+
lowpan_adaptation_interface_etx_update_enable(cur->id);
1695+
16811696
mle_class_router_challenge(interface_id, protocol_6lowpan_router_challenge);
16821697
}
16831698

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@
8989
#include "thread_meshcop_lib.h"
9090
#include "multicast_api.h"
9191
#include "mlme.h"
92+
#include "Service_Libs/etx/etx.h"
9293
#include "Service_Libs/nd_proxy/nd_proxy.h"
9394
#include "Service_Libs/blacklist/blacklist.h"
9495
#include "6LoWPAN/MAC/mac_data_poll.h"
96+
#include "6LoWPAN/lowpan_adaptation_interface.h"
9597

9698
#define TRACE_GROUP "thbs"
9799

@@ -154,6 +156,12 @@ int8_t thread_mle_class_init(int8_t interface_id)
154156
return -1;
155157
}
156158

159+
if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
160+
return -1;
161+
}
162+
163+
lowpan_adaptation_interface_etx_update_enable(cur->id);
164+
157165
mle_class_router_challenge(interface_id, NULL);
158166

159167
//Defined well know neighbour for discovery

source/6LoWPAN/Thread/thread_common.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ thread_leader_data_t *thread_leader_data_generate(void);
104104
thread_parent_info_t *thread_parent_data_allocate(thread_info_t *info);
105105
static uint8_t * thread_joining_port_tlv_write(uint16_t port, uint8_t *ptr);
106106
static uint8_t * thread_commissioner_port_tlv_write(uint16_t port, uint8_t *ptr);
107-
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, mle_neigh_table_entry_t *neighbor);
107+
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, uint8_t attribute_index);
108108
static void thread_address_notification_cb(struct protocol_interface_info_entry *interface, const struct if_address_entry *addr, if_address_callback_t reason);
109109

110110
/* Helper functions*/
@@ -1827,7 +1827,7 @@ static uint8_t * thread_commissioner_port_tlv_write(uint16_t port, uint8_t *ptr)
18271827
return common_write_16_bit(port, ptr);
18281828
}
18291829

1830-
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, mle_neigh_table_entry_t *neighbor)
1830+
static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failures, uint8_t attribute_index)
18311831
{
18321832
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(nwk_id);
18331833

@@ -1837,6 +1837,11 @@ static void thread_tx_failure_handler(int8_t nwk_id, uint8_t accumulated_failure
18371837
return;
18381838
}
18391839

1840+
mle_neigh_table_entry_t *neighbor = mle_class_get_by_device_attribute_id(cur->id, attribute_index);
1841+
if (!neighbor) {
1842+
return;
1843+
}
1844+
18401845
if (accumulated_failures >= THREAD_MAC_TRANSMISSIONS*THREAD_FAILED_CHILD_TRANSMISSIONS) {
18411846
thread_reset_neighbour_info(cur, neighbor);
18421847
}

source/6LoWPAN/adaptation_interface.c

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
#define TRACE_GROUP "6lAd"
4848

49+
typedef void (adaptation_etx_update_cb)(protocol_interface_info_entry_t *cur, buffer_t *buf, const mcps_data_conf_t *confirm);
50+
4951
// #define EXTRA_DEBUG_EXTRA
5052
#ifdef EXTRA_DEBUG_EXTRA
5153
#define tr_debug_extra(...) tr_debug(__VA_ARGS__)
@@ -89,6 +91,7 @@ typedef struct {
8991
uint16_t max_indirect_big_packets_total;
9092
uint16_t max_indirect_small_packets_per_child;
9193
bool fragmenter_active; /*!< Fragmenter state */
94+
adaptation_etx_update_cb *etx_update_cb;
9295
mpx_api_t *mpx_api;
9396
uint16_t mpx_user_id;
9497
ns_list_link_t link; /*!< List link entry */
@@ -129,6 +132,43 @@ static void lowpan_adaptation_indirect_queue_free_message(struct protocol_interf
129132

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

135+
static void lowpan_adaptation_etx_update_cb(protocol_interface_info_entry_t *cur, buffer_t *buf, const mcps_data_conf_t *confirm)
136+
{
137+
switch (confirm->status) {
138+
case MLME_TX_NO_ACK:
139+
case MLME_NO_DATA:
140+
case MLME_SUCCESS:
141+
if (buf->link_specific.ieee802_15_4.requestAck) {
142+
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) {
143+
bool success = false;
144+
if (confirm->status == MLME_SUCCESS) {
145+
success = true;
146+
}
147+
// Gets table entry
148+
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);
149+
if (neigh_table_ptr) {
150+
etx_transm_attempts_update(cur->id, 1 + confirm->tx_retries , success, neigh_table_ptr->attribute_index);
151+
// Updates ETX statistics
152+
etx_storage_t * etx_entry = etx_storage_entry_get(cur->id, neigh_table_ptr->attribute_index);
153+
if (etx_entry) {
154+
if (neigh_table_ptr->priorityFlag) {
155+
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
156+
} else if (neigh_table_ptr->second_priority_flag) {
157+
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
158+
}
159+
}
160+
}
161+
}
162+
}
163+
break;
164+
default:
165+
166+
break;
167+
168+
}
169+
}
170+
171+
132172
//Discover
133173
static fragmenter_interface_t *lowpan_adaptation_interface_discover(int8_t interfaceId)
134174
{
@@ -321,6 +361,14 @@ int8_t lowpan_adaptation_interface_init(int8_t interface_id, uint16_t mac_mtu_si
321361
return 0;
322362
}
323363

364+
void lowpan_adaptation_interface_etx_update_enable(int8_t interface_id)
365+
{
366+
fragmenter_interface_t *interface_ptr = lowpan_adaptation_interface_discover(interface_id);
367+
if (interface_ptr) {
368+
interface_ptr->etx_update_cb = lowpan_adaptation_etx_update_cb;
369+
}
370+
}
371+
324372
int8_t lowpan_adaptation_interface_free(int8_t interface_id)
325373
{
326374
//Discover
@@ -1022,23 +1070,10 @@ int8_t lowpan_adaptation_interface_tx_confirm(protocol_interface_info_entry_t *c
10221070
}
10231071
}
10241072

1025-
switch (confirm->status) {
1026-
case MLME_TX_NO_ACK:
1027-
case MLME_NO_DATA:
1028-
case MLME_SUCCESS:
1029-
if (buf->link_specific.ieee802_15_4.requestAck) {
1030-
bool success = false;
1031-
if (confirm->status == MLME_SUCCESS) {
1032-
success = true;
1033-
}
1034-
etx_transm_attempts_update(cur->id, 1 + confirm->tx_retries , success, buf->dst_sa.addr_type, buf->dst_sa.address);
1035-
}
1036-
break;
1037-
default:
1038-
1039-
break;
1040-
1073+
if (interface_ptr->etx_update_cb) {
1074+
interface_ptr->etx_update_cb(cur, buf, confirm);
10411075
}
1076+
10421077
//Switch original channel back
10431078
if (buf->link_specific.ieee802_15_4.rf_channel_switch) {
10441079
mac_helper_mac_channel_set(cur, buf->link_specific.ieee802_15_4.selected_channel);

source/6LoWPAN/lowpan_adaptation_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct mpx_api_s;
2727

2828
int8_t lowpan_adaptation_interface_init(int8_t interface_id, uint16_t mac_mtu_size);
2929

30+
void lowpan_adaptation_interface_etx_update_enable(int8_t interface_id);
31+
3032
int8_t lowpan_adaptation_interface_free(int8_t interface_id);
3133

3234
int8_t lowpan_adaptation_interface_reset(int8_t interface_id);

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "6LoWPAN/ws/ws_neighbor_class.h"
4848
#include "6LoWPAN/ws/ws_ie_lib.h"
4949
#include "6LoWPAN/lowpan_adaptation_interface.h"
50+
#include "Service_Libs/etx/etx.h"
5051
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
5152
#include "platform/topo_trace.h"
5253

@@ -680,6 +681,10 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
680681
return -2;
681682
}
682683

684+
if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
685+
return -1;
686+
}
687+
683688
switch (bootstrap_mode) {
684689
// case NET_6LOWPAN_SLEEPY_HOST:
685690
case NET_6LOWPAN_HOST:
@@ -749,6 +754,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
749754
init_fail:
750755
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
751756
mac_neighbor_table_delete(cur->mac_parameters->mac_neighbor_table);
757+
etx_storage_list_allocate(cur->id, 0);
752758
ws_neighbor_class_dealloc(&neigh_info);
753759
ws_llc_delete(cur);
754760
return ret_val;

source/MLE/mle.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void mle_table_class_list_free(mle_table_class_t *mle_table_class) {
138138
//Call Remove callback
139139
mle_table_class->remove_cb(mle_table_class->interfaceId, cur);
140140
//Removes ETX neighbor
141-
etx_neighbor_remove(mle_table_class->interfaceId, cur);
141+
etx_neighbor_remove(mle_table_class->interfaceId, cur->attribute_index);
142142
ns_list_add_to_start(&mle_table_class->free_enty_list, cur);
143143
}
144144
topo_trace(TOPOLOGY_MLE, NULL, TOPO_CLEAR);
@@ -586,7 +586,7 @@ int8_t mle_class_remove_entry(int8_t interface_id, mle_neigh_table_entry_t *entr
586586
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);
587587

588588
//Removes ETX neighbor
589-
etx_neighbor_remove(interface_id, entry);
589+
etx_neighbor_remove(interface_id, entry->attribute_index);
590590
//Add to free list
591591
ns_list_add_to_start(&mle_class_ptr->free_enty_list, entry);
592592
return 0;
@@ -614,7 +614,7 @@ int8_t mle_class_remove_neighbour(int8_t interface_id, const uint8_t *address, a
614614
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);
615615

616616
//Removes ETX neighbor
617-
etx_neighbor_remove(interface_id, entry);
617+
etx_neighbor_remove(interface_id, entry->attribute_index);
618618
//Add to free list
619619
ns_list_add_to_start(&mle_class_ptr->free_enty_list, entry);
620620

@@ -689,7 +689,7 @@ static void mle_class_table_ttl(uint16_t ticks, mle_table_class_t *mle_class_ptr
689689
mle_class_ptr->remove_cb(mle_class_ptr->interfaceId, cur);
690690
topo_trace(TOPOLOGY_MLE, cur->ext64, TOPO_REMOVE);
691691
//Removes ETX neighbor
692-
etx_neighbor_remove(mle_class_ptr->interfaceId, cur);
692+
etx_neighbor_remove(mle_class_ptr->interfaceId, cur->attribute_index);
693693
//Add to free list
694694
ns_list_add_to_start(&mle_class_ptr->free_enty_list, cur);
695695

0 commit comments

Comments
 (0)