Rehauling of RPL OFs, both MRHOF and OF0. Fixed compliance with RFC6551, 6552, 6719. Now using the link-stats module.
This commit is contained in:
parent
752fef9e42
commit
426e10c3ed
9 changed files with 445 additions and 387 deletions
|
@ -27,11 +27,12 @@
|
|||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* An implementation of RPL's objective function 0.
|
||||
* An implementation of RPL's objective function 0, RFC6552
|
||||
*
|
||||
* \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se>
|
||||
*/
|
||||
|
@ -41,136 +42,176 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#include "net/rpl/rpl.h"
|
||||
#include "net/rpl/rpl-private.h"
|
||||
#include "net/nbr-table.h"
|
||||
#include "net/link-stats.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/ip/uip-debug.h"
|
||||
|
||||
static void reset(rpl_dag_t *);
|
||||
static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
|
||||
static rpl_dag_t *best_dag(rpl_dag_t *, rpl_dag_t *);
|
||||
static rpl_rank_t calculate_rank(rpl_parent_t *, rpl_rank_t);
|
||||
static void update_metric_container(rpl_instance_t *);
|
||||
/* Constants from RFC6552. We use the default values. */
|
||||
#define RANK_STRETCH 0 /* Must be in the range [0;5] */
|
||||
#define RANK_FACTOR 1 /* Must be in the range [1;4] */
|
||||
|
||||
rpl_of_t rpl_of0 = {
|
||||
reset,
|
||||
NULL,
|
||||
#if RPL_WITH_DAO_ACK
|
||||
NULL,
|
||||
#endif
|
||||
best_parent,
|
||||
best_dag,
|
||||
calculate_rank,
|
||||
update_metric_container,
|
||||
0
|
||||
};
|
||||
#define MIN_STEP_OF_RANK 1
|
||||
#define MAX_STEP_OF_RANK 9
|
||||
|
||||
#define DEFAULT_RANK_INCREMENT RPL_MIN_HOPRANKINC
|
||||
/* OF0 computes rank increase as follows:
|
||||
* rank_increase = (RANK_FACTOR * STEP_OF_RANK + RANK_STRETCH) * min_hop_rank_increase
|
||||
* STEP_OF_RANK is an implementation-specific scalar value in the range [1;9].
|
||||
* RFC6552 provides a default value of 3 but recommends to use a dynamic link metric
|
||||
* such as ETX.
|
||||
* */
|
||||
|
||||
#define MIN_DIFFERENCE (RPL_MIN_HOPRANKINC + RPL_MIN_HOPRANKINC / 2)
|
||||
#define RPL_OF0_FIXED_SR 0
|
||||
#define RPL_OF0_ETX_BASED_SR 1
|
||||
/* Select RPL_OF0_FIXED_SR or RPL_OF0_ETX_BASED_SR */
|
||||
#ifdef RPL_OF0_CONF_SR
|
||||
#define RPL_OF0_SR RPL_OF0_CONF_SR
|
||||
#else /* RPL_OF0_CONF_SR */
|
||||
#define RPL_OF0_SR RPL_OF0_ETX_BASED_SR
|
||||
#endif /* RPL_OF0_CONF_SR */
|
||||
|
||||
#if RPL_OF0_FIXED_SR
|
||||
#define STEP_OF_RANK(p) (3)
|
||||
#endif /* RPL_OF0_FIXED_SR */
|
||||
|
||||
#if RPL_OF0_ETX_BASED_SR
|
||||
/* Numbers suggested by P. Thubert for in the 6TiSCH WG. Anything that maps ETX to
|
||||
* a step between 1 and 9 works. */
|
||||
#define STEP_OF_RANK(p) (((3 * parent_link_metric(p)) / LINK_STATS_ETX_DIVISOR) - 2)
|
||||
#endif /* RPL_OF0_ETX_BASED_SR */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
reset(rpl_dag_t *dag)
|
||||
{
|
||||
PRINTF("RPL: Resetting OF0\n");
|
||||
PRINTF("RPL: Reset OF0\n");
|
||||
}
|
||||
|
||||
static rpl_rank_t
|
||||
calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
parent_link_metric(rpl_parent_t *p)
|
||||
{
|
||||
rpl_rank_t increment;
|
||||
if(base_rank == 0) {
|
||||
if(p == NULL) {
|
||||
return INFINITE_RANK;
|
||||
}
|
||||
base_rank = p->rank;
|
||||
}
|
||||
|
||||
increment = p != NULL ?
|
||||
p->dag->instance->min_hoprankinc :
|
||||
DEFAULT_RANK_INCREMENT;
|
||||
|
||||
if((rpl_rank_t)(base_rank + increment) < base_rank) {
|
||||
PRINTF("RPL: OF0 rank %d incremented to infinite rank due to wrapping\n",
|
||||
base_rank);
|
||||
/* OF0 operates without metric container; the only metric we have is ETX */
|
||||
const struct link_stats *stats = rpl_get_parent_link_stats(p);
|
||||
return stats != NULL ? stats->etx : 0xffff;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
parent_rank_increase(rpl_parent_t *p)
|
||||
{
|
||||
uint16_t min_hoprankinc;
|
||||
if(p == NULL || p->dag == NULL || p->dag->instance == NULL) {
|
||||
return INFINITE_RANK;
|
||||
}
|
||||
return base_rank + increment;
|
||||
|
||||
min_hoprankinc = p->dag->instance->min_hoprankinc;
|
||||
return (RANK_FACTOR * STEP_OF_RANK(p) + RANK_STRETCH) * min_hoprankinc;
|
||||
}
|
||||
|
||||
static rpl_dag_t *
|
||||
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
parent_path_cost(rpl_parent_t *p)
|
||||
{
|
||||
if(d1->grounded) {
|
||||
if (!d2->grounded) {
|
||||
return d1;
|
||||
}
|
||||
} else if(d2->grounded) {
|
||||
return d2;
|
||||
if(p == NULL) {
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
if(d1->preference < d2->preference) {
|
||||
return d2;
|
||||
/* path cost upper bound: 0xffff */
|
||||
return MIN((uint32_t)p->rank + parent_link_metric(p), 0xffff);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static rpl_rank_t
|
||||
rank_via_parent(rpl_parent_t *p)
|
||||
{
|
||||
if(p == NULL) {
|
||||
return INFINITE_RANK;
|
||||
} else {
|
||||
if(d1->preference > d2->preference) {
|
||||
return d1;
|
||||
}
|
||||
}
|
||||
|
||||
if(d2->rank < d1->rank) {
|
||||
return d2;
|
||||
} else {
|
||||
return d1;
|
||||
return MIN((uint32_t)p->rank + parent_rank_increase(p), INFINITE_RANK);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
parent_is_acceptable(rpl_parent_t *p)
|
||||
{
|
||||
return STEP_OF_RANK(p) >= MIN_STEP_OF_RANK
|
||||
&& STEP_OF_RANK(p) <= MAX_STEP_OF_RANK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static rpl_parent_t *
|
||||
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
||||
{
|
||||
rpl_rank_t r1, r2;
|
||||
rpl_dag_t *dag;
|
||||
uip_ds6_nbr_t *nbr1, *nbr2;
|
||||
nbr1 = rpl_get_nbr(p1);
|
||||
nbr2 = rpl_get_nbr(p2);
|
||||
rpl_dag_t *dag;
|
||||
uint16_t p1_cost;
|
||||
uint16_t p2_cost;
|
||||
int p1_is_acceptable;
|
||||
int p2_is_acceptable;
|
||||
|
||||
dag = (rpl_dag_t *)p1->dag; /* Both parents must be in the same DAG. */
|
||||
|
||||
if(nbr1 == NULL || nbr2 == NULL) {
|
||||
return dag->preferred_parent;
|
||||
if(p1 == NULL || p2 == NULL) {
|
||||
/* Return non-null parent if any */
|
||||
return p1 == NULL ? p2 : p1;
|
||||
}
|
||||
|
||||
PRINTF("RPL: Comparing parent ");
|
||||
PRINT6ADDR(rpl_get_parent_ipaddr(p1));
|
||||
PRINTF(" (confidence %d, rank %d) with parent ",
|
||||
nbr1->link_metric, p1->rank);
|
||||
PRINT6ADDR(rpl_get_parent_ipaddr(p2));
|
||||
PRINTF(" (confidence %d, rank %d)\n",
|
||||
nbr2->link_metric, p2->rank);
|
||||
p1_is_acceptable = parent_is_acceptable(p1);
|
||||
p2_is_acceptable = parent_is_acceptable(p2);
|
||||
/* Is only one parent is acceptable, select it. If both are acceptable, or
|
||||
* both non-acceptable, proceed to traditional parent comparison. This is a
|
||||
* slight departure from the standard but allows to keep connectivity even
|
||||
* all neighbors appear to have a bad link. */
|
||||
if(p1_is_acceptable != p2_is_acceptable) {
|
||||
return p1_is_acceptable ? p1 : p2;
|
||||
}
|
||||
|
||||
dag = p1->dag; /* Both parents are in the same DAG. */
|
||||
p1_cost = parent_path_cost(p1);
|
||||
p2_cost = parent_path_cost(p2);
|
||||
|
||||
r1 = DAG_RANK(p1->rank, p1->dag->instance) * RPL_MIN_HOPRANKINC +
|
||||
nbr1->link_metric;
|
||||
r2 = DAG_RANK(p2->rank, p1->dag->instance) * RPL_MIN_HOPRANKINC +
|
||||
nbr2->link_metric;
|
||||
/* Compare two parents by looking both and their rank and at the ETX
|
||||
for that parent. We choose the parent that has the most
|
||||
favourable combination. */
|
||||
|
||||
if(r1 < r2 + MIN_DIFFERENCE &&
|
||||
r1 > r2 - MIN_DIFFERENCE) {
|
||||
return dag->preferred_parent;
|
||||
} else if(r1 < r2) {
|
||||
return p1;
|
||||
/* Paths costs coarse-grained (multiple of min_hoprankinc), we operate without hysteresis */
|
||||
if(p1_cost != p2_cost) {
|
||||
/* Pick parent with lowest path cost */
|
||||
return p1_cost < p2_cost ? p1 : p2;
|
||||
} else {
|
||||
return p2;
|
||||
/* We have a tie! */
|
||||
/* Stik to current preferred parent if possible */
|
||||
if(p1 == dag->preferred_parent || p2 == dag->preferred_parent) {
|
||||
return dag->preferred_parent;
|
||||
}
|
||||
/* None of the nodes is the current preferred parent,
|
||||
* choose parent with best link metric */
|
||||
return parent_link_metric(p1) < parent_link_metric(p2) ? p1 : p2;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static rpl_dag_t *
|
||||
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
|
||||
{
|
||||
if(d1->grounded != d2->grounded) {
|
||||
return d1->grounded ? d1 : d2;
|
||||
}
|
||||
|
||||
if(d1->preference != d2->preference) {
|
||||
return d1->preference > d2->preference ? d1 : d2;
|
||||
}
|
||||
|
||||
return d1->rank < d2->rank ? d1 : d2;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
update_metric_container(rpl_instance_t *instance)
|
||||
{
|
||||
instance->mc.type = RPL_DAG_MC_NONE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
rpl_of_t rpl_of0 = {
|
||||
reset,
|
||||
#if RPL_WITH_DAO_ACK
|
||||
NULL,
|
||||
#endif
|
||||
parent_link_metric,
|
||||
parent_path_cost,
|
||||
rank_via_parent,
|
||||
best_parent,
|
||||
best_dag,
|
||||
update_metric_container,
|
||||
RPL_OCP_OF0
|
||||
};
|
||||
|
||||
/** @}*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue