Skip to content

Commit 1b99fe1

Browse files
author
Juha Heiskanen
committed
Added ETX to rpl_possible_better_candidate
ETX may be 0 when it is new neighbour and then etx is optimistic 128. Change-Id: Ic5ed0d453d04a16ead9d040217cd132b5d35e366
1 parent 3441594 commit 1b99fe1

File tree

10 files changed

+54
-30
lines changed

10 files changed

+54
-30
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,10 +2147,17 @@ static bool ws_rpl_new_parent_callback(uint8_t *ll_parent_address, void *handle,
21472147
}
21482148

21492149
uint8_t replacing[16];
2150-
uint8_t mac64[8];
2150+
uint8_t mac64[10];
21512151
bool replace_ok = false;
21522152
bool create_ok = false;
21532153
llc_neighbour_req_t neigh_buffer;
2154+
2155+
//Discover neigh ready here for possible ETX validate
2156+
memcpy(mac64, ll_parent_address + 8, 8);
2157+
mac64[0] ^= 2;
2158+
2159+
ws_bootstrap_neighbor_info_request(cur, mac64, &neigh_buffer, false);
2160+
21542161
if (rpl_control_candidate_list_size(cur, instance) < cur->ws_info->rpl_parent_candidate_max) {
21552162
//Not reach max value yet accept then all go to create neigh table
21562163
goto neigh_create;
@@ -2161,20 +2168,22 @@ static bool ws_rpl_new_parent_callback(uint8_t *ll_parent_address, void *handle,
21612168
return false;
21622169
}
21632170

2164-
// if not yet probed, return false
2165-
memcpy(mac64, replacing + 8, 8);
2166-
mac64[0] ^= 2;
2171+
// +2 Is for PAN ID space
2172+
memcpy(mac64 + 2, replacing + 8, 8);
2173+
mac64[2] ^= 2;
21672174

2168-
if (ws_bootstrap_neighbor_info_request(cur, mac64, &neigh_buffer, false)) {
2169-
//Verify that we have proped min 1 time
2170-
etx_storage_t *etx_entry = etx_storage_entry_get(cur->id, neigh_buffer.neighbor->index);
2171-
if (etx_entry && etx_entry->etx_samples == 0) {
2172-
return false;
2173-
}
2175+
if (ws_etx_read(cur, ADDR_802_15_4_LONG, mac64) == 0xffff) {
2176+
//Not proped yet because ETX is 0xffff
2177+
return false;
2178+
}
2179+
2180+
uint16_t etx = 0;
2181+
if (neigh_buffer.neighbor) {
2182+
etx = etx_local_etx_read(cur->id, neigh_buffer.neighbor->index);
21742183
}
21752184

21762185
// Accept now only better one's when max candidates slected and max candidate list size is reached
2177-
if (!rpl_possible_better_candidate(cur, instance, replacing, candidate_rank)) {
2186+
if (!rpl_possible_better_candidate(cur, instance, replacing, candidate_rank, etx)) {
21782187
return false;
21792188
}
21802189
//TODO if replacing has poor ETX, put it in blacklist as "poor ETX" to prevent reselection
@@ -2183,14 +2192,16 @@ static bool ws_rpl_new_parent_callback(uint8_t *ll_parent_address, void *handle,
21832192

21842193
neigh_create:
21852194

2186-
memcpy(mac64, ll_parent_address + 8, 8);
2187-
mac64[0] ^= 2;
2188-
if (ws_bootstrap_neighbor_info_request(cur, mac64, &neigh_buffer, false)) {
2195+
2196+
if (neigh_buffer.neighbor) {
2197+
//Use Already discovered entry
21892198
create_ok = true;
21902199
goto neigh_create_ok;
21912200
}
21922201

2193-
//Discover Multicast temporary entry
2202+
//Discover Multicast temporary entry for create neighbour table entry for new candidate
2203+
memcpy(mac64, ll_parent_address + 8, 8);
2204+
mac64[0] ^= 2;
21942205
ws_neighbor_temp_class_t *entry = ws_llc_get_multicast_temp_entry(cur, mac64);
21952206
if (!entry) {
21962207
return false;

source/RPL/rpl_control.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ bool rpl_control_probe_parent_candidate(protocol_interface_info_entry_t *interfa
272272
return false;
273273
}
274274

275-
bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interface, rpl_instance_t *rpl_instance, const uint8_t ll_addr[16], uint16_t candidate_rank)
275+
bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interface, rpl_instance_t *rpl_instance, const uint8_t ll_addr[16], uint16_t candidate_rank, uint16_t etx)
276276
{
277277
if (!interface->rpl_domain) {
278278
return false;
@@ -283,7 +283,7 @@ bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interfa
283283
return false;
284284
}
285285

286-
return rpl_instance_possible_better_candidate(rpl_instance, neighbour, candidate_rank);
286+
return rpl_instance_possible_better_candidate(rpl_instance, neighbour, candidate_rank, etx);
287287

288288
}
289289

@@ -1847,9 +1847,8 @@ void rpl_control_print(route_print_fn_t *print_fn)
18471847
unsigned s = s_full % 60;
18481848
unsigned h = m / 60;
18491849
m %= 60;
1850-
print_fn("Time %02u:%02u:%02u.%u (%u.%u)", h, m, s, t, s_full, t);
18511850
// %zu doesn't work on some Mbed toolchains
1852-
print_fn("RPL memory usage %" PRIu32, (uint32_t) rpl_alloc_total);
1851+
print_fn("Time %02u:%02u:%02u.%u (%u.%u) RPL memory usage %" PRIu32, h, m, s, t, s_full, t, (uint32_t) rpl_alloc_total);
18531852
ns_list_foreach(rpl_domain_t, domain, &rpl_domains) {
18541853
rpl_domain_print(domain, print_fn);
18551854
}

source/RPL/rpl_control.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void rpl_control_unpublish_address(rpl_domain_t *domain, const uint8_t addr[16])
155155
bool rpl_control_is_dodag_parent(struct protocol_interface_info_entry *interface, const uint8_t ll_addr[16]);
156156
bool rpl_control_is_dodag_parent_candidate(struct protocol_interface_info_entry *interface, const uint8_t ll_addr[16], uint16_t candidate_cmp_limiter);
157157
bool rpl_control_probe_parent_candidate(struct protocol_interface_info_entry *interface, const uint8_t ll_addr[16]);
158-
bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interface, struct rpl_instance *rpl_instance, const uint8_t ll_addr[16], uint16_t candidate_rank);
158+
bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interface, struct rpl_instance *rpl_instance, const uint8_t ll_addr[16], uint16_t candidate_rank, uint16_t etx);
159159
uint16_t rpl_control_parent_candidate_list_size(struct protocol_interface_info_entry *interface, bool parent_list);
160160
uint16_t rpl_control_candidate_list_size(struct protocol_interface_info_entry *interface, struct rpl_instance *rpl_instance);
161161
void rpl_control_neighbor_delete(struct protocol_interface_info_entry *interface, const uint8_t ll_addr[16]);

source/RPL/rpl_mrhof.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
static void rpl_mrhof_parent_selection(rpl_instance_t *instance);
4646
static uint16_t rpl_mrhof_path_cost_through_neighbour(const rpl_neighbour_t *neighbour);
4747
static bool rpl_mrhof_neighbour_acceptable(const rpl_instance_t *instance, const rpl_neighbour_t *neighbour);
48-
static bool rpl_mrhof_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank);
48+
static bool rpl_mrhof_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank, uint16_t etx);
4949

5050
static rpl_objective_t rpl_mrhof = {
5151
.ocp = RPL_OCP_MRHOF,
@@ -96,7 +96,7 @@ static bool rpl_mrhof_neighbour_acceptable(const rpl_instance_t *instance, const
9696
return rpl_mrhof_link_metric_to_neighbour(neighbour) <= rpl_policy_mrhof_max_link_metric(instance->domain);
9797
}
9898

99-
static bool rpl_mrhof_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank)
99+
static bool rpl_mrhof_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank, uint16_t etx)
100100
{
101101
uint16_t existing_path = rpl_mrhof_path_cost_through_neighbour(existing);
102102
// Optimistically assume we could get a perfect link to this new person
@@ -105,7 +105,15 @@ static bool rpl_mrhof_possible_better_candidate(const rpl_instance_t *instance,
105105
// Think: could actually use rpl_mrhof_etx here to get an existing ETX estimate
106106
// (except that gives infinite if no current link, would want a variant that checks
107107
// blacklist records for remembered poor ETX)
108-
uint16_t potential_path_with_hysteresis = rpl_rank_add(rank, 128 + rpl_policy_mrhof_parent_switch_threshold(instance->domain));
108+
uint16_t threshold = rpl_policy_mrhof_parent_switch_threshold(instance->domain);
109+
if (etx == 0) {
110+
etx = 128;
111+
} else if (etx >= (0xffff - threshold)) {
112+
return false;
113+
}
114+
115+
etx += threshold;
116+
uint16_t potential_path_with_hysteresis = rpl_rank_add(rank, etx);
109117
return potential_path_with_hysteresis <= existing_path;
110118
}
111119

source/RPL/rpl_objective.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct rpl_objective {
3333
bool (*neighbour_acceptable)(const struct rpl_instance *, const struct rpl_neighbour *);
3434
/* Could someone with specified rank be a significantly better candidate than the existing one? */
3535
/* (In future, this API could be extended to pass a metric pointer as well as rank) */
36-
bool (*possible_better_candidate)(const struct rpl_instance *, const struct rpl_neighbour *existing, uint16_t rank);
36+
bool (*possible_better_candidate)(const struct rpl_instance *, const struct rpl_neighbour *existing, uint16_t rank, uint16_t etx);
3737
ns_list_link_t link;
3838
} rpl_objective_t;
3939

source/RPL/rpl_of0.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
static void rpl_of0_parent_selection(rpl_instance_t *instance);
4343
static uint16_t rpl_of0_rank_through_neighbour(const rpl_neighbour_t *neighbour);
4444
static bool rpl_of0_neighbour_acceptable(const rpl_instance_t *instance, const rpl_neighbour_t *neighbour);
45-
static bool rpl_of0_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank);
45+
static bool rpl_of0_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank, uint16_t etx);
4646

4747
static rpl_objective_t rpl_of0 = {
4848
.ocp = RPL_OCP_OF0,
@@ -117,8 +117,9 @@ static uint16_t rpl_of0_rank_through_neighbour(const rpl_neighbour_t *neighbour)
117117
return rpl_rank_add(neighbour->rank, rpl_of0_rank_increase(neighbour));
118118
}
119119

120-
static bool rpl_of0_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank)
120+
static bool rpl_of0_possible_better_candidate(const rpl_instance_t *instance, const rpl_neighbour_t *existing, uint16_t rank, uint16_t etx)
121121
{
122+
(void)etx;
122123
uint16_t existing_path = rpl_of0_rank_through_neighbour(existing);
123124
uint16_t potential_path_with_hysteresis = rpl_rank_add(rank, 2 * rpl_policy_of0_rank_factor(instance->domain) * existing->dodag_version->dodag->config.min_hop_rank_increase);
124125
return potential_path_with_hysteresis <= existing_path;

source/RPL/rpl_upward.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ uint16_t rpl_instance_candidate_rank(const rpl_neighbour_t *candidate)
290290
return candidate->rank;
291291
}
292292

293-
bool rpl_instance_possible_better_candidate(const rpl_instance_t *instance, rpl_neighbour_t *replacing, uint16_t candidate_rank)
293+
bool rpl_instance_possible_better_candidate(const rpl_instance_t *instance, rpl_neighbour_t *replacing, uint16_t candidate_rank, uint16_t etx)
294294
{
295-
return instance->of->possible_better_candidate(instance, replacing, candidate_rank);
295+
return instance->of->possible_better_candidate(instance, replacing, candidate_rank, etx);
296296
}
297297

298298
/* If we're a member of a DODAG Version matching the predicate in this instance,

source/RPL/rpl_upward.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool rpl_instance_am_root(const rpl_instance_t *instance);
7070
uint8_t rpl_instance_mop(const rpl_instance_t *instance);
7171
rpl_dodag_version_t *rpl_instance_current_dodag_version(const rpl_instance_t *instance);
7272
rpl_neighbour_t *rpl_instance_preferred_parent(const rpl_instance_t *instance);
73-
bool rpl_instance_possible_better_candidate(const rpl_instance_t *instance, rpl_neighbour_t *replacing, uint16_t candidate_rank);
73+
bool rpl_instance_possible_better_candidate(const rpl_instance_t *instance, rpl_neighbour_t *replacing, uint16_t candidate_rank, uint16_t etx);
7474
rpl_dodag_version_t *rpl_instance_predicate_match(rpl_instance_t *instance, uint8_t pred, uint8_t instance_id, const uint8_t *dodagid, uint8_t version_num);
7575
void rpl_instance_inconsistency(rpl_instance_t *instance);
7676
void rpl_instance_consistent_rx(rpl_instance_t *instance);

test/nanostack/unittest/stub/rpl_control_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ bool rpl_control_probe_parent_candidate(protocol_interface_info_entry_t *interfa
269269
return false;
270270
}
271271

272-
bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interface, struct rpl_instance *rpl_instance, const uint8_t ll_addr[16], uint16_t candidate_rank)
272+
bool rpl_possible_better_candidate(struct protocol_interface_info_entry *interface, struct rpl_instance *rpl_instance, const uint8_t ll_addr[16], uint16_t candidate_rank, uint16_t etx)
273273
{
274274
return true;
275275
}

test/nanostack/unittest/stub/rpl_upward_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,9 @@ uint16_t rpl_instance_candidate_rank(const rpl_neighbour_t *candidate)
503503
return 0xffff;
504504
}
505505

506+
bool rpl_instance_possible_better_candidate(const rpl_instance_t *instance, rpl_neighbour_t *replacing, uint16_t candidate_rank, uint16_t etx)
507+
{
508+
return false;
509+
}
510+
506511
#endif /* HAVE_RPL */

0 commit comments

Comments
 (0)