Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 1653b06

Browse files
author
Mika Tervonen
committed
replace ETX calculation for Wi-SUN
Create new function to calculate ETX for Wi-SUN Calculate parent candidate set using signal strength
1 parent 745c1dd commit 1653b06

File tree

7 files changed

+110
-4
lines changed

7 files changed

+110
-4
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,47 @@ static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
219219
cur->ws_info->fhss_api = fhss_api;
220220
return 0;
221221
}
222+
/* \return 0x0100 to 0xFFFF ETX value (8 bit fraction)
223+
* \return 0xFFFF address not associated
224+
* \return 0x0000 address unknown or other error
225+
* \return 0x0001 no ETX statistics on this interface
226+
*/
227+
uint16_t ws_etx_read(protocol_interface_info_entry_t *interface, addrtype_t addr_type, const uint8_t *addr_ptr)
228+
{
229+
230+
uint16_t etx;
231+
if (!addr_ptr || !interface) {
232+
return 0;
233+
}
234+
235+
uint8_t attribute_index;
236+
237+
mac_neighbor_table_entry_t *mac_neighbor = mac_neighbor_table_address_discover(mac_neighbor_info(interface), addr_ptr + PAN_ID_LEN, addr_type);
238+
if (!mac_neighbor) {
239+
return 0xffff;
240+
}
241+
attribute_index = mac_neighbor->index;
242+
ws_neighbor_class_entry_t *ws_neighbour = ws_neighbor_class_entry_get(&interface->ws_info->neighbor_storage, attribute_index);
243+
244+
if (!ws_neighbour ||
245+
!ws_neighbour->candidate_parent) {
246+
// if RSL value is not good enough candidate parent flag is removed and device not accepted as parent
247+
//tr_debug("ws_etx_read not valid parent");
248+
return 0xffff;
249+
}
250+
251+
etx = etx_local_etx_read(interface->id,attribute_index);
252+
if (etx == 0) {
253+
return 0xffff;
254+
}
255+
if (etx > 0x800) {
256+
// Wi-SUN section 6.2.3.1.6.1 says ETX can only be maximum of 1024 (8*128) in RPL units, ie 8.0.
257+
etx = 0x800;
258+
}
259+
260+
//tr_debug("ws_etx_read etx:%d", etx);
261+
return etx;
262+
}
222263

223264
static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
224265
{
@@ -891,6 +932,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
891932
cur->if_up = ws_bootstrap_up;
892933
cur->if_down = ws_bootstrap_down;
893934
cur->ws_info->neighbor_storage = neigh_info;
935+
cur->etx_read_override = ws_etx_read;
894936

895937
ws_bootstrap_configuration_reset(cur);
896938
addr_notification_register(ws_bootstrap_address_notification_cb);

source/6LoWPAN/ws/ws_common_defines.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ typedef struct ws_bs_ie {
185185
#define WS_NEIGHBOR_LINK_TIMEOUT 240
186186
#define WS_NEIGHBOR_NUD_TIMEOUT WS_NEIGHBOR_LINK_TIMEOUT / 2
187187

188+
/*
189+
* Threshold (referenced to DEVICE_MIN_SENS) above which a neighbor node may be considered for inclusion into candidate parent set
190+
*/
191+
#define CAND_PARENT_THRESHOLD 10
192+
/*
193+
* Hysteresis factor to be applied to CAND_PARENT_THRESHOLD when admitting or dropping nodes from the candidate parent set.
194+
*/
195+
#define CAND_PARENT_HYSTERISIS 3
196+
188197
/*
189198
* value when send the first RPL DIS in 100ms ticks. Value is randomized between timeout/2 - timeout
190199
*/
@@ -194,5 +203,4 @@ typedef struct ws_bs_ie {
194203
*/
195204
#define WS_RPL_DIS_TIMEOUT 1800
196205

197-
198206
#endif /* WS_COMMON_DEFINES_H_ */

source/6LoWPAN/ws/ws_neighbor_class.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,43 @@ uint8_t ws_neighbor_class_rssi_from_dbm_calculate( int8_t dbm_heard)
123123
return dbm_heard - DEVICE_MIN_SENS;
124124
}
125125

126+
static void ws_neighbor_class_parent_set_analyze(ws_neighbor_class_entry_t *ws_neighbor)
127+
{
128+
if (ws_neighbor->rsl_in == RSL_UNITITIALIZED ||
129+
ws_neighbor->rsl_out == RSL_UNITITIALIZED) {
130+
ws_neighbor->candidate_parent = false;
131+
return;
132+
}
133+
134+
if (ws_neighbor_class_rsl_in_get(ws_neighbor) < (CAND_PARENT_THRESHOLD - CAND_PARENT_HYSTERISIS) &&
135+
ws_neighbor_class_rsl_out_get(ws_neighbor) < (CAND_PARENT_THRESHOLD - CAND_PARENT_HYSTERISIS)) {
136+
ws_neighbor->candidate_parent = false;
137+
}
138+
139+
if (ws_neighbor_class_rsl_in_get(ws_neighbor) > (CAND_PARENT_THRESHOLD + CAND_PARENT_HYSTERISIS) &&
140+
ws_neighbor_class_rsl_out_get(ws_neighbor) > (CAND_PARENT_THRESHOLD + CAND_PARENT_HYSTERISIS)) {
141+
ws_neighbor->candidate_parent = true;
142+
}
143+
}
144+
126145
void ws_neighbor_class_rsl_in_calculate(ws_neighbor_class_entry_t *ws_neighbor, int8_t dbm_heard)
127146
{
128147
uint8_t rssi = ws_neighbor_class_rssi_from_dbm_calculate(dbm_heard);
129148
if (ws_neighbor->rsl_in == RSL_UNITITIALIZED) {
130149
ws_neighbor->rsl_in = rssi << WS_RSL_SCALING;
131-
return;
132150
}
133151
ws_neighbor->rsl_in = ws_neighbor->rsl_in + rssi - (ws_neighbor->rsl_in >> WS_RSL_SCALING);
152+
ws_neighbor_class_parent_set_analyze(ws_neighbor);
134153
return;
135154
}
136155

137156
void ws_neighbor_class_rsl_out_calculate(ws_neighbor_class_entry_t *ws_neighbor, uint8_t rsl_reported)
138157
{
139158
if (ws_neighbor->rsl_out == RSL_UNITITIALIZED) {
140159
ws_neighbor->rsl_out = rsl_reported << WS_RSL_SCALING;
141-
return;
142160
}
143161
ws_neighbor->rsl_out = ws_neighbor->rsl_out + rsl_reported - (ws_neighbor->rsl_out >> WS_RSL_SCALING);
162+
ws_neighbor_class_parent_set_analyze(ws_neighbor);
144163
return;
145164
}
146165

source/6LoWPAN/ws/ws_neighbor_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct ws_neighbor_class_entry {
2525
fhss_ws_neighbor_timing_info_t fhss_data;
2626
uint16_t rsl_in; /*!< RSL EWMA heard from neighbour*/
2727
uint16_t rsl_out; /*!< RSL EWMA heard by neighbour*/
28+
bool candidate_parent:1;
2829
} ws_neighbor_class_entry_t;
2930

3031
/**

source/NWK_INTERFACE/Include/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ typedef void beacon_indication_cb(int8_t if_id, const mlme_beacon_ind_t* conf);
342342
typedef void comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* status);
343343

344344

345-
346345
struct protocol_interface_info_entry {
347346
beacon_indication_cb *beacon_cb;
348347
scan_confirm_cb *scan_cb;
@@ -476,6 +475,7 @@ struct protocol_interface_info_entry {
476475
uint8_t (*if_llao_parse)(struct protocol_interface_info_entry *cur, const uint8_t *opt_in, sockaddr_t *ll_addr_out);
477476
uint8_t (*if_llao_write)(struct protocol_interface_info_entry *cur, uint8_t *opt_out, uint8_t opt_type, bool must, const uint8_t *ip_addr);
478477
void (*mac_security_key_usage_update_cb)(struct protocol_interface_info_entry *cur, const struct mlme_security_s *security_params);
478+
uint16_t (*etx_read_override)(struct protocol_interface_info_entry *cur, addrtype_t addr_type, const uint8_t *addr_ptr);
479479
};
480480

481481
typedef NS_LIST_HEAD(protocol_interface_info_entry_t, link) protocol_interface_list_t;

source/Service_Libs/etx/etx.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ uint16_t etx_read(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr
188188
return 0;
189189
}
190190

191+
if (interface->etx_read_override) {
192+
// Interface has modified ETX calculation
193+
return interface->etx_read_override(interface, addr_type, addr_ptr);
194+
}
195+
191196
uint8_t attribute_index;
192197
if (interface->nwk_id == IF_IPV6) {
193198
return 1;
@@ -242,6 +247,25 @@ uint16_t etx_local_incoming_idr_read(int8_t interface_id, uint8_t attribute_inde
242247
return local_incoming_idr;
243248
}
244249

250+
/**
251+
* \brief A function to read local incoming IDR value
252+
*
253+
* Returns local incoming IDR value for an address
254+
*
255+
* \param mac64_addr_ptr long MAC address
256+
*
257+
* \return 0x0100 to 0xFFFF incoming IDR value (8 bit fraction)
258+
* \return 0x0000 address unknown
259+
*/
260+
uint16_t etx_local_etx_read(int8_t interface_id, uint8_t attribute_index)
261+
{
262+
etx_storage_t * entry = etx_storage_entry_get(interface_id, attribute_index);
263+
if (!entry) {
264+
return 0;
265+
}
266+
return etx_current_calc(entry->etx, entry->accumulated_failures) >> 4;
267+
}
268+
245269
/**
246270
* \brief A function to calculate current ETX
247271
*

source/Service_Libs/etx/etx.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ uint16_t etx_read(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr
9393
*/
9494
uint16_t etx_local_incoming_idr_read(int8_t interface_id, uint8_t attribute_index);
9595

96+
/**
97+
* \brief A function to read local ETXvalue
98+
*
99+
* Returns local ETX value for an address
100+
*
101+
* \param mac64_addr_ptr long MAC address
102+
*
103+
* \return 0x0100 to 0xFFFF ETX value (8 bit fraction)
104+
* \return 0x0000 address unknown
105+
*/
106+
uint16_t etx_local_etx_read(int8_t interface_id, uint8_t attribute_index);
107+
96108
/**
97109
* \brief A function to update ETX value based on LQI and dBm
98110
*

0 commit comments

Comments
 (0)