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
|
@ -71,7 +71,6 @@ typedef struct uip_ds6_nbr {
|
||||||
uip_ipaddr_t ipaddr;
|
uip_ipaddr_t ipaddr;
|
||||||
uint8_t isrouter;
|
uint8_t isrouter;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint16_t link_metric;
|
|
||||||
#if UIP_ND6_SEND_NA || UIP_ND6_SEND_RA
|
#if UIP_ND6_SEND_NA || UIP_ND6_SEND_RA
|
||||||
struct stimer reachable;
|
struct stimer reachable;
|
||||||
struct stimer sendns;
|
struct stimer sendns;
|
||||||
|
|
|
@ -52,6 +52,13 @@
|
||||||
* When MRHOF (RFC6719) is used with ETX, no metric container must
|
* When MRHOF (RFC6719) is used with ETX, no metric container must
|
||||||
* be used; instead the rank carries ETX directly.
|
* be used; instead the rank carries ETX directly.
|
||||||
*/
|
*/
|
||||||
|
#ifdef RPL_CONF_WITH_MC
|
||||||
|
#define RPL_WITH_MC RPL_CONF_WITH_MC
|
||||||
|
#else /* RPL_CONF_WITH_MC */
|
||||||
|
#define RPL_WITH_MC 0
|
||||||
|
#endif /* RPL_CONF_WITH_MC */
|
||||||
|
|
||||||
|
/* The MC advertised in DIOs and propagating from the root */
|
||||||
#ifdef RPL_CONF_DAG_MC
|
#ifdef RPL_CONF_DAG_MC
|
||||||
#define RPL_DAG_MC RPL_CONF_DAG_MC
|
#define RPL_DAG_MC RPL_CONF_DAG_MC
|
||||||
#else
|
#else
|
||||||
|
@ -186,15 +193,6 @@
|
||||||
#define RPL_DIO_REDUNDANCY 10
|
#define RPL_DIO_REDUNDANCY 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Initial metric attributed to a link when the ETX is unknown
|
|
||||||
*/
|
|
||||||
#ifndef RPL_CONF_INIT_LINK_METRIC
|
|
||||||
#define RPL_INIT_LINK_METRIC 2
|
|
||||||
#else
|
|
||||||
#define RPL_INIT_LINK_METRIC RPL_CONF_INIT_LINK_METRIC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default route lifetime unit. This is the granularity of time
|
* Default route lifetime unit. This is the granularity of time
|
||||||
* used in RPL lifetime values, in seconds.
|
* used in RPL lifetime values, in seconds.
|
||||||
|
@ -287,15 +285,6 @@
|
||||||
#define RPL_PROBING_INTERVAL (120 * CLOCK_SECOND)
|
#define RPL_PROBING_INTERVAL (120 * CLOCK_SECOND)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* RPL probing expiration time.
|
|
||||||
*/
|
|
||||||
#ifdef RPL_CONF_PROBING_EXPIRATION_TIME
|
|
||||||
#define RPL_PROBING_EXPIRATION_TIME RPL_CONF_PROBING_EXPIRATION_TIME
|
|
||||||
#else
|
|
||||||
#define RPL_PROBING_EXPIRATION_TIME (10 * 60 * CLOCK_SECOND)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function used to select the next parent to be probed.
|
* Function used to select the next parent to be probed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
|
#include "net/link-stats.h"
|
||||||
#include "net/rpl/rpl-private.h"
|
#include "net/rpl/rpl-private.h"
|
||||||
#include "net/ip/uip.h"
|
#include "net/ip/uip.h"
|
||||||
#include "net/ipv6/uip-nd6.h"
|
#include "net/ipv6/uip-nd6.h"
|
||||||
|
@ -91,22 +92,25 @@ void
|
||||||
rpl_print_neighbor_list(void)
|
rpl_print_neighbor_list(void)
|
||||||
{
|
{
|
||||||
if(default_instance != NULL && default_instance->current_dag != NULL &&
|
if(default_instance != NULL && default_instance->current_dag != NULL &&
|
||||||
default_instance->of != NULL && default_instance->of->calculate_rank != NULL) {
|
default_instance->of != NULL) {
|
||||||
int curr_dio_interval = default_instance->dio_intcurrent;
|
int curr_dio_interval = default_instance->dio_intcurrent;
|
||||||
int curr_rank = default_instance->current_dag->rank;
|
int curr_rank = default_instance->current_dag->rank;
|
||||||
rpl_parent_t *p = nbr_table_head(rpl_parents);
|
rpl_parent_t *p = nbr_table_head(rpl_parents);
|
||||||
clock_time_t now = clock_time();
|
const struct link_stats *stats = rpl_get_parent_link_stats(p);
|
||||||
|
|
||||||
printf("RPL: rank %u dioint %u, %u nbr(s)\n", curr_rank, curr_dio_interval, uip_ds6_nbr_num());
|
printf("RPL: OCP %u rank %u dioint %u, nbr count %u\n",
|
||||||
|
default_instance->of->ocp, curr_rank, curr_dio_interval, uip_ds6_nbr_num());
|
||||||
while(p != NULL) {
|
while(p != NULL) {
|
||||||
uip_ds6_nbr_t *nbr = rpl_get_nbr(p);
|
printf("RPL: nbr %3u %5u, %5u => %5u -- %5u %c%c (last tx %u min ago)\n",
|
||||||
printf("RPL: nbr %3u %5u, %5u => %5u %c%c (last tx %u min ago)\n",
|
rpl_get_parent_ipaddr(p)->u8[15],
|
||||||
nbr_table_get_lladdr(rpl_parents, p)->u8[7],
|
p->rank,
|
||||||
p->rank, nbr ? nbr->link_metric : 0,
|
rpl_get_parent_link_metric(p),
|
||||||
default_instance->of->calculate_rank(p, 0),
|
rpl_rank_via_parent(p),
|
||||||
default_instance->current_dag == p->dag ? 'd' : ' ',
|
stats != NULL ? stats->freshness : 0,
|
||||||
p == default_instance->current_dag->preferred_parent ? '*' : ' ',
|
link_stats_is_fresh(stats) ? 'f' : ' ',
|
||||||
(unsigned)((now - p->last_tx_time) / (60 * CLOCK_SECOND)));
|
p == default_instance->current_dag->preferred_parent ? 'p' : ' ',
|
||||||
|
(unsigned)((now - p->last_tx_time) / (60 * CLOCK_SECOND))
|
||||||
|
);
|
||||||
p = nbr_table_next(rpl_parents, p);
|
p = nbr_table_next(rpl_parents, p);
|
||||||
}
|
}
|
||||||
printf("RPL: end of list\n");
|
printf("RPL: end of list\n");
|
||||||
|
@ -151,30 +155,61 @@ rpl_get_parent_rank(uip_lladdr_t *addr)
|
||||||
if(p != NULL) {
|
if(p != NULL) {
|
||||||
return p->rank;
|
return p->rank;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return INFINITE_RANK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uint16_t
|
uint16_t
|
||||||
rpl_get_parent_link_metric(const uip_lladdr_t *addr)
|
rpl_get_parent_link_metric(rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
uip_ds6_nbr_t *nbr;
|
if(p != NULL && p->dag != NULL) {
|
||||||
nbr = nbr_table_get_from_lladdr(ds6_neighbors, (const linkaddr_t *)addr);
|
rpl_instance_t *instance = p->dag->instance;
|
||||||
|
if(instance != NULL && instance->of != NULL && instance->of->parent_link_metric != NULL) {
|
||||||
if(nbr != NULL) {
|
return instance->of->parent_link_metric(p);
|
||||||
return nbr->link_metric;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0xffff;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
rpl_rank_t
|
||||||
|
rpl_rank_via_parent(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
if(p != NULL && p->dag != NULL) {
|
||||||
|
rpl_instance_t *instance = p->dag->instance;
|
||||||
|
if(instance != NULL && instance->of != NULL && instance->of->rank_via_parent != NULL) {
|
||||||
|
return instance->of->rank_via_parent(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INFINITE_RANK;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
const linkaddr_t *
|
||||||
|
rpl_get_parent_lladdr(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
return nbr_table_get_lladdr(rpl_parents, p);
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ipaddr_t *
|
uip_ipaddr_t *
|
||||||
rpl_get_parent_ipaddr(rpl_parent_t *p)
|
rpl_get_parent_ipaddr(rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
linkaddr_t *lladdr = nbr_table_get_lladdr(rpl_parents, p);
|
const linkaddr_t *lladdr = rpl_get_parent_lladdr(p);
|
||||||
return uip_ds6_nbr_ipaddr_from_lladdr((uip_lladdr_t *)lladdr);
|
return uip_ds6_nbr_ipaddr_from_lladdr((uip_lladdr_t *)lladdr);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
const struct link_stats *
|
||||||
|
rpl_get_parent_link_stats(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
const linkaddr_t *lladdr = rpl_get_parent_lladdr(p);
|
||||||
|
return link_stats_from_lladdr(lladdr);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rpl_parent_is_fresh(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
const struct link_stats *stats = rpl_get_parent_link_stats(p);
|
||||||
|
return link_stats_is_fresh(stats);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
rpl_set_preferred_parent(rpl_dag_t *dag, rpl_parent_t *p)
|
rpl_set_preferred_parent(rpl_dag_t *dag, rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
|
@ -640,20 +675,12 @@ rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
PRINTF("RPL: rpl_add_parent p NULL\n");
|
PRINTF("RPL: rpl_add_parent p NULL\n");
|
||||||
} else {
|
} else {
|
||||||
uip_ds6_nbr_t *nbr;
|
|
||||||
nbr = rpl_get_nbr(p);
|
|
||||||
|
|
||||||
p->dag = dag;
|
p->dag = dag;
|
||||||
p->rank = dio->rank;
|
p->rank = dio->rank;
|
||||||
p->dtsn = dio->dtsn;
|
p->dtsn = dio->dtsn;
|
||||||
|
#if RPL_WITH_MC
|
||||||
/* Check whether we have a neighbor that has not gotten a link metric yet */
|
|
||||||
if(nbr != NULL && nbr->link_metric == 0) {
|
|
||||||
nbr->link_metric = RPL_INIT_LINK_METRIC * RPL_DAG_MC_ETX_DIVISOR;
|
|
||||||
}
|
|
||||||
#if RPL_DAG_MC != RPL_DAG_MC_NONE
|
|
||||||
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
||||||
#endif /* RPL_DAG_MC != RPL_DAG_MC_NONE */
|
#endif /* RPL_WITH_MC */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -757,7 +784,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
|
||||||
|
|
||||||
instance->of->update_metric_container(instance);
|
instance->of->update_metric_container(instance);
|
||||||
/* Update the DAG rank. */
|
/* Update the DAG rank. */
|
||||||
best_dag->rank = instance->of->calculate_rank(best_dag->preferred_parent, 0);
|
best_dag->rank = rpl_rank_via_parent(best_dag->preferred_parent);
|
||||||
if(last_parent == NULL || best_dag->rank < best_dag->min_rank) {
|
if(last_parent == NULL || best_dag->rank < best_dag->min_rank) {
|
||||||
best_dag->min_rank = best_dag->rank;
|
best_dag->min_rank = best_dag->rank;
|
||||||
} else if(!acceptable_rank(best_dag, best_dag->rank)) {
|
} else if(!acceptable_rank(best_dag, best_dag->rank)) {
|
||||||
|
@ -798,20 +825,35 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
|
||||||
static rpl_parent_t *
|
static rpl_parent_t *
|
||||||
best_parent(rpl_dag_t *dag)
|
best_parent(rpl_dag_t *dag)
|
||||||
{
|
{
|
||||||
rpl_parent_t *p, *best;
|
rpl_parent_t *p;
|
||||||
|
rpl_of_t *of;
|
||||||
|
rpl_parent_t *best = NULL;
|
||||||
|
|
||||||
best = NULL;
|
if(dag == NULL || dag->instance == NULL || dag->instance->of == NULL) {
|
||||||
|
return NULL;
|
||||||
p = nbr_table_head(rpl_parents);
|
|
||||||
while(p != NULL) {
|
|
||||||
if(p->dag != dag || p->rank == INFINITE_RANK) {
|
|
||||||
/* ignore this neighbor */
|
|
||||||
} else if(best == NULL) {
|
|
||||||
best = p;
|
|
||||||
} else {
|
|
||||||
best = dag->instance->of->best_parent(best, p);
|
|
||||||
}
|
}
|
||||||
p = nbr_table_next(rpl_parents, p);
|
|
||||||
|
of = dag->instance->of;
|
||||||
|
/* Search for the best parent according to the OF */
|
||||||
|
for(p = nbr_table_head(rpl_parents); p != NULL; p = nbr_table_next(rpl_parents, p)) {
|
||||||
|
|
||||||
|
/* Exclude parents from other DAGs or announcing an infinite rank */
|
||||||
|
if(p->dag != dag || p->rank == INFINITE_RANK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef UIP_CONF_ND6_SEND_NA
|
||||||
|
{
|
||||||
|
uip_ds6_nbr_t *nbr = rpl_get_nbr(p);
|
||||||
|
/* Exclude links to a neighbor that is not reachable at a NUD level */
|
||||||
|
if(nbr == NULL || nbr->state != NBR_REACHABLE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* UIP_CONF_ND6_SEND_NA */
|
||||||
|
|
||||||
|
/* Now we have an acceptable parent, check if it is the new best */
|
||||||
|
best = of->best_parent(best, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return best;
|
return best;
|
||||||
|
@ -823,9 +865,12 @@ rpl_select_parent(rpl_dag_t *dag)
|
||||||
rpl_parent_t *best = best_parent(dag);
|
rpl_parent_t *best = best_parent(dag);
|
||||||
|
|
||||||
if(best != NULL) {
|
if(best != NULL) {
|
||||||
|
if(rpl_parent_is_fresh(best)) {
|
||||||
rpl_set_preferred_parent(dag, best);
|
rpl_set_preferred_parent(dag, best);
|
||||||
dag->rank = dag->instance->of->calculate_rank(dag->preferred_parent, 0);
|
dag->rank = rpl_rank_via_parent(dag->preferred_parent);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
rpl_set_preferred_parent(dag, best);
|
||||||
dag->rank = INFINITE_RANK;
|
dag->rank = INFINITE_RANK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1003,6 +1048,10 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
|
|
||||||
instance->of = of;
|
instance->of = of;
|
||||||
instance->mop = dio->mop;
|
instance->mop = dio->mop;
|
||||||
|
instance->mc.type = dio->mc.type;
|
||||||
|
instance->mc.flags = dio->mc.flags;
|
||||||
|
instance->mc.aggr = dio->mc.aggr;
|
||||||
|
instance->mc.prec = dio->mc.prec;
|
||||||
instance->current_dag = dag;
|
instance->current_dag = dag;
|
||||||
instance->dtsn_out = RPL_LOLLIPOP_INIT;
|
instance->dtsn_out = RPL_LOLLIPOP_INIT;
|
||||||
|
|
||||||
|
@ -1022,7 +1071,7 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
|
|
||||||
rpl_set_preferred_parent(dag, p);
|
rpl_set_preferred_parent(dag, p);
|
||||||
instance->of->update_metric_container(instance);
|
instance->of->update_metric_container(instance);
|
||||||
dag->rank = instance->of->calculate_rank(p, 0);
|
dag->rank = rpl_rank_via_parent(p);
|
||||||
/* So far this is the lowest rank we are aware of. */
|
/* So far this is the lowest rank we are aware of. */
|
||||||
dag->min_rank = dag->rank;
|
dag->min_rank = dag->rank;
|
||||||
|
|
||||||
|
@ -1045,6 +1094,8 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
} else {
|
} else {
|
||||||
PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
|
PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance->of->reset(dag);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RPL_MAX_DAG_PER_INSTANCE > 1
|
#if RPL_MAX_DAG_PER_INSTANCE > 1
|
||||||
|
@ -1115,7 +1166,7 @@ rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
|
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
|
||||||
|
|
||||||
rpl_set_preferred_parent(dag, p);
|
rpl_set_preferred_parent(dag, p);
|
||||||
dag->rank = instance->of->calculate_rank(p, 0);
|
dag->rank = rpl_rank_via_parent(p);
|
||||||
dag->min_rank = dag->rank; /* So far this is the lowest rank we know of. */
|
dag->min_rank = dag->rank; /* So far this is the lowest rank we know of. */
|
||||||
|
|
||||||
PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
|
PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
|
||||||
|
@ -1157,7 +1208,7 @@ global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
|
||||||
PRINTF("RPL: Failed to add a parent during the global repair\n");
|
PRINTF("RPL: Failed to add a parent during the global repair\n");
|
||||||
dag->rank = INFINITE_RANK;
|
dag->rank = INFINITE_RANK;
|
||||||
} else {
|
} else {
|
||||||
dag->rank = dag->instance->of->calculate_rank(p, 0);
|
dag->rank = rpl_rank_via_parent(p);
|
||||||
dag->min_rank = dag->rank;
|
dag->min_rank = dag->rank;
|
||||||
PRINTF("RPL: rpl_process_parent_event global repair\n");
|
PRINTF("RPL: rpl_process_parent_event global repair\n");
|
||||||
rpl_process_parent_event(dag->instance, p);
|
rpl_process_parent_event(dag->instance, p);
|
||||||
|
@ -1446,14 +1497,14 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
PRINT6ADDR(&instance->current_dag->dag_id);
|
PRINT6ADDR(&instance->current_dag->dag_id);
|
||||||
PRINTF(", rank %u, min_rank %u, ",
|
PRINTF(", rank %u, min_rank %u, ",
|
||||||
instance->current_dag->rank, instance->current_dag->min_rank);
|
instance->current_dag->rank, instance->current_dag->min_rank);
|
||||||
PRINTF("parent rank %u, parent etx %u, link metric %u, instance etx %u\n",
|
PRINTF("parent rank %u, link metric %u\n",
|
||||||
p->rank, -1/*p->mc.obj.etx*/, rpl_get_nbr(p)->link_metric, instance->mc.obj.etx);
|
p->rank, rpl_get_parent_link_metric(p));
|
||||||
|
|
||||||
/* We have allocated a candidate parent; process the DIO further. */
|
/* We have allocated a candidate parent; process the DIO further. */
|
||||||
|
|
||||||
#if RPL_DAG_MC != RPL_DAG_MC_NONE
|
#if RPL_WITH_MC
|
||||||
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
||||||
#endif /* RPL_DAG_MC != RPL_DAG_MC_NONE */
|
#endif /* RPL_WITH_MC */
|
||||||
if(rpl_process_parent_event(instance, p) == 0) {
|
if(rpl_process_parent_event(instance, p) == 0) {
|
||||||
PRINTF("RPL: The candidate parent is rejected\n");
|
PRINTF("RPL: The candidate parent is rejected\n");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* The Minimum Rank with Hysteresis Objective Function (MRHOF)
|
* The Minimum Rank with Hysteresis Objective Function (MRHOF), RFC6719
|
||||||
*
|
*
|
||||||
* This implementation uses the estimated number of
|
* This implementation uses the estimated number of
|
||||||
* transmissions (ETX) as the additive routing metric,
|
* transmissions (ETX) as the additive routing metric,
|
||||||
|
@ -46,83 +46,48 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "net/rpl/rpl.h"
|
||||||
#include "net/rpl/rpl-private.h"
|
#include "net/rpl/rpl-private.h"
|
||||||
#include "net/nbr-table.h"
|
#include "net/nbr-table.h"
|
||||||
|
#include "net/link-stats.h"
|
||||||
|
|
||||||
#define DEBUG DEBUG_NONE
|
#define DEBUG DEBUG_NONE
|
||||||
#include "net/ip/uip-debug.h"
|
#include "net/ip/uip-debug.h"
|
||||||
|
|
||||||
static void reset(rpl_dag_t *);
|
/* RFC6551 and RFC6719 do not mandate the use of a specific formula to
|
||||||
static void neighbor_link_callback(rpl_parent_t *, int, int);
|
* compute the ETX value. This MRHOF implementation relies on the value
|
||||||
#if RPL_WITH_DAO_ACK
|
* computed by the link-stats module. It has an optional feature,
|
||||||
static void dao_ack_callback(rpl_parent_t *, int);
|
* RPL_MRHOF_CONF_SQUARED_ETX, that consists in squaring this value.
|
||||||
#endif
|
* This basically penalizes bad links while preserving the semantics of ETX
|
||||||
static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
|
* (1 = perfect link, more = worse link). As a result, MRHOF will favor
|
||||||
static rpl_dag_t *best_dag(rpl_dag_t *, rpl_dag_t *);
|
* good links over short paths. Recommended when reliability is a priority.
|
||||||
static rpl_rank_t calculate_rank(rpl_parent_t *, rpl_rank_t);
|
* Without this feature, a hop with 50% PRR (ETX=2) is equivalent to two
|
||||||
static void update_metric_container(rpl_instance_t *);
|
* perfect hops with 100% PRR (ETX=1+1=2). With this feature, the former
|
||||||
|
* path obtains ETX=2*2=4 and the former ETX=1*1+1*1=2. */
|
||||||
rpl_of_t rpl_mrhof = {
|
#ifdef RPL_MRHOF_CONF_SQUARED_ETX
|
||||||
reset,
|
#define RPL_MRHOF_SQUARED_ETX RPL_MRHOF_CONF_SQUARED_ETX
|
||||||
neighbor_link_callback,
|
#else /* RPL_MRHOF_CONF_SQUARED_ETX */
|
||||||
#if RPL_WITH_DAO_ACK
|
#define RPL_MRHOF_SQUARED_ETX 0
|
||||||
dao_ack_callback,
|
#endif /* RPL_MRHOF_CONF_SQUARED_ETX */
|
||||||
#endif
|
|
||||||
best_parent,
|
|
||||||
best_dag,
|
|
||||||
calculate_rank,
|
|
||||||
update_metric_container,
|
|
||||||
1
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Constants for the ETX moving average */
|
|
||||||
#define ETX_SCALE 100
|
|
||||||
#define ETX_ALPHA 90
|
|
||||||
|
|
||||||
/* Reject parents that have a higher link metric than the following. */
|
|
||||||
#define MAX_LINK_METRIC 10
|
|
||||||
|
|
||||||
|
/* Configuration parameters of RFC6719. Reject parents that have a higher
|
||||||
|
* link metric than the following. We use the default values from the RFC. */
|
||||||
|
#define MAX_LINK_METRIC 512 /* Eq ETX of 4 */
|
||||||
/* Reject parents that have a higher path cost than the following. */
|
/* Reject parents that have a higher path cost than the following. */
|
||||||
#define MAX_PATH_COST 100
|
#define MAX_PATH_COST 32768 /* Eq path ETX of 256 */
|
||||||
|
/* Hysteresis of MRHOF: the rank must differ more than PARENT_SWITCH_THRESHOLD_DIV
|
||||||
/*
|
* in order to switch preferred parent. Default in RFC6719: 192, eq ETX of 1.5.
|
||||||
* The rank must differ more than 1/PARENT_SWITCH_THRESHOLD_DIV in order
|
* We use a more aggressive setting: 96, eq ETX of 0.75.
|
||||||
* to switch preferred parent.
|
|
||||||
*/
|
*/
|
||||||
#define PARENT_SWITCH_THRESHOLD_DIV 2
|
#define PARENT_SWITCH_THRESHOLD 96
|
||||||
|
|
||||||
typedef uint16_t rpl_path_metric_t;
|
|
||||||
|
|
||||||
static rpl_path_metric_t
|
|
||||||
calculate_path_metric(rpl_parent_t *p)
|
|
||||||
{
|
|
||||||
uip_ds6_nbr_t *nbr;
|
|
||||||
if(p == NULL) {
|
|
||||||
return MAX_PATH_COST * RPL_DAG_MC_ETX_DIVISOR;
|
|
||||||
}
|
|
||||||
nbr = rpl_get_nbr(p);
|
|
||||||
if(nbr == NULL) {
|
|
||||||
return MAX_PATH_COST * RPL_DAG_MC_ETX_DIVISOR;
|
|
||||||
}
|
|
||||||
#if RPL_DAG_MC == RPL_DAG_MC_NONE
|
|
||||||
{
|
|
||||||
return p->rank + (uint16_t)nbr->link_metric;
|
|
||||||
}
|
|
||||||
#elif RPL_DAG_MC == RPL_DAG_MC_ETX
|
|
||||||
return p->mc.obj.etx + (uint16_t)nbr->link_metric;
|
|
||||||
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
|
|
||||||
return p->mc.obj.energy.energy_est + (uint16_t)nbr->link_metric;
|
|
||||||
#else
|
|
||||||
#error "Unsupported RPL_DAG_MC configured. See rpl.h."
|
|
||||||
#endif /* RPL_DAG_MC */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
reset(rpl_dag_t *dag)
|
reset(rpl_dag_t *dag)
|
||||||
{
|
{
|
||||||
PRINTF("RPL: Reset MRHOF\n");
|
PRINTF("RPL: Reset MRHOF\n");
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#if RPL_WITH_DAO_ACK
|
#if RPL_WITH_DAO_ACK
|
||||||
static void
|
static void
|
||||||
dao_ack_callback(rpl_parent_t *p, int status)
|
dao_ack_callback(rpl_parent_t *p, int status)
|
||||||
|
@ -141,80 +106,117 @@ dao_ack_callback(rpl_parent_t *p, int status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* RPL_WITH_DAO_ACK */
|
#endif /* RPL_WITH_DAO_ACK */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static uint16_t
|
||||||
neighbor_link_callback(rpl_parent_t *p, int status, int numtx)
|
parent_link_metric(rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
uint16_t recorded_etx = 0;
|
const struct link_stats *stats = rpl_get_parent_link_stats(p);
|
||||||
uint16_t packet_etx = numtx * RPL_DAG_MC_ETX_DIVISOR;
|
if(stats != NULL) {
|
||||||
uint16_t new_etx;
|
#if RPL_MRHOF_SQUARED_ETX
|
||||||
uip_ds6_nbr_t *nbr = NULL;
|
uint32_t squared_etx = ((uint32_t)stats->etx * stats->etx) / LINK_STATS_ETX_DIVISOR;
|
||||||
|
return (uint16_t)MIN(squared_etx, 0xffff);
|
||||||
|
#else /* RPL_MRHOF_SQUARED_ETX */
|
||||||
|
return stats->etx;
|
||||||
|
#endif /* RPL_MRHOF_SQUARED_ETX */
|
||||||
|
}
|
||||||
|
return 0xffff;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static uint16_t
|
||||||
|
parent_path_cost(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
uint16_t base;
|
||||||
|
|
||||||
nbr = rpl_get_nbr(p);
|
if(p == NULL || p->dag == NULL || p->dag->instance == NULL) {
|
||||||
if(nbr == NULL) {
|
return 0xffff;
|
||||||
/* No neighbor for this parent - something bad has occurred */
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recorded_etx = nbr->link_metric;
|
#if RPL_WITH_MC
|
||||||
|
/* Handle the different MC types */
|
||||||
/* Do not penalize the ETX when collisions or transmission errors occur. */
|
switch(p->dag->instance->mc.type) {
|
||||||
if(status == MAC_TX_OK || status == MAC_TX_NOACK) {
|
case RPL_DAG_MC_ETX:
|
||||||
if(status == MAC_TX_NOACK) {
|
base = p->mc.obj.etx;
|
||||||
packet_etx = MAX_LINK_METRIC * RPL_DAG_MC_ETX_DIVISOR;
|
break;
|
||||||
|
case RPL_DAG_MC_ENERGY:
|
||||||
|
base = p->mc.obj.energy.energy_est << 8;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
base = p->rank;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
#else /* RPL_WITH_MC */
|
||||||
|
base = p->rank;
|
||||||
|
#endif /* RPL_WITH_MC */
|
||||||
|
|
||||||
if(p->flags & RPL_PARENT_FLAG_LINK_METRIC_VALID) {
|
/* path cost upper bound: 0xffff */
|
||||||
/* We already have a valid link metric, use weighted moving average to update it */
|
return MIN((uint32_t)base + parent_link_metric(p), 0xffff);
|
||||||
new_etx = ((uint32_t)recorded_etx * ETX_ALPHA +
|
|
||||||
(uint32_t)packet_etx * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
|
|
||||||
} else {
|
|
||||||
/* We don't have a valid link metric, set it to the current packet's ETX */
|
|
||||||
new_etx = packet_etx;
|
|
||||||
/* Set link metric as valid */
|
|
||||||
p->flags |= RPL_PARENT_FLAG_LINK_METRIC_VALID;
|
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
PRINTF("RPL: ETX changed from %u to %u (packet ETX = %u)\n",
|
|
||||||
(unsigned)(recorded_etx / RPL_DAG_MC_ETX_DIVISOR),
|
|
||||||
(unsigned)(new_etx / RPL_DAG_MC_ETX_DIVISOR),
|
|
||||||
(unsigned)(packet_etx / RPL_DAG_MC_ETX_DIVISOR));
|
|
||||||
/* update the link metric for this nbr */
|
|
||||||
nbr->link_metric = new_etx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static rpl_rank_t
|
static rpl_rank_t
|
||||||
calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
|
rank_via_parent(rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
rpl_rank_t new_rank;
|
uint16_t min_hoprankinc;
|
||||||
rpl_rank_t rank_increase;
|
uint16_t path_cost;
|
||||||
uip_ds6_nbr_t *nbr;
|
|
||||||
|
|
||||||
if(p == NULL || (nbr = rpl_get_nbr(p)) == NULL) {
|
if(p == NULL || p->dag == NULL || p->dag->instance == NULL) {
|
||||||
if(base_rank == 0) {
|
|
||||||
return INFINITE_RANK;
|
return INFINITE_RANK;
|
||||||
}
|
}
|
||||||
rank_increase = RPL_INIT_LINK_METRIC * RPL_DAG_MC_ETX_DIVISOR;
|
|
||||||
} else {
|
min_hoprankinc = p->dag->instance->min_hoprankinc;
|
||||||
rank_increase = nbr->link_metric;
|
path_cost = parent_path_cost(p);
|
||||||
if(base_rank == 0) {
|
|
||||||
base_rank = p->rank;
|
/* Rank lower-bound: parent rank + min_hoprankinc */
|
||||||
|
return MAX(MIN((uint32_t)p->rank + min_hoprankinc, 0xffff), path_cost);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
parent_is_acceptable(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
uint16_t link_metric = parent_link_metric(p);
|
||||||
|
uint16_t path_cost = parent_path_cost(p);
|
||||||
|
/* Exclude links with too high link metrics or path cost (RFC6719, 3.2.2) */
|
||||||
|
return link_metric <= MAX_LINK_METRIC && path_cost <= MAX_PATH_COST;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static rpl_parent_t *
|
||||||
|
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
||||||
|
{
|
||||||
|
rpl_dag_t *dag;
|
||||||
|
uint16_t p1_cost;
|
||||||
|
uint16_t p2_cost;
|
||||||
|
int p1_is_acceptable;
|
||||||
|
int p2_is_acceptable;
|
||||||
|
|
||||||
|
if(p1 == NULL || p2 == NULL) {
|
||||||
|
/* Return non-null parent if any */
|
||||||
|
return p1 == NULL ? p2 : p1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Maintain stability of the preferred parent in case of similar ranks. */
|
||||||
|
if(p1 == dag->preferred_parent || p2 == dag->preferred_parent) {
|
||||||
|
if(p1_cost < p2_cost + PARENT_SWITCH_THRESHOLD &&
|
||||||
|
p1_cost > p2_cost - PARENT_SWITCH_THRESHOLD) {
|
||||||
|
return dag->preferred_parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(INFINITE_RANK - base_rank < rank_increase) {
|
return p1_cost < p2_cost ? p1 : p2;
|
||||||
/* Reached the maximum rank. */
|
|
||||||
new_rank = INFINITE_RANK;
|
|
||||||
} else {
|
|
||||||
/* Calculate the rank based on the new rank information from DIO or
|
|
||||||
stored otherwise. */
|
|
||||||
new_rank = base_rank + rank_increase;
|
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
return new_rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
static rpl_dag_t *
|
static rpl_dag_t *
|
||||||
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
|
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
|
||||||
{
|
{
|
||||||
|
@ -228,93 +230,76 @@ best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
|
||||||
|
|
||||||
return d1->rank < d2->rank ? d1 : d2;
|
return d1->rank < d2->rank ? d1 : d2;
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static rpl_parent_t *
|
#if !RPL_WITH_MC
|
||||||
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
|
||||||
{
|
|
||||||
rpl_dag_t *dag;
|
|
||||||
rpl_path_metric_t min_diff;
|
|
||||||
rpl_path_metric_t p1_metric;
|
|
||||||
rpl_path_metric_t p2_metric;
|
|
||||||
|
|
||||||
dag = p1->dag; /* Both parents are in the same DAG. */
|
|
||||||
|
|
||||||
min_diff = RPL_DAG_MC_ETX_DIVISOR /
|
|
||||||
PARENT_SWITCH_THRESHOLD_DIV;
|
|
||||||
|
|
||||||
p1_metric = calculate_path_metric(p1);
|
|
||||||
p2_metric = calculate_path_metric(p2);
|
|
||||||
|
|
||||||
/* Maintain stability of the preferred parent in case of similar ranks. */
|
|
||||||
if(p1 == dag->preferred_parent || p2 == dag->preferred_parent) {
|
|
||||||
if(p1_metric < p2_metric + min_diff &&
|
|
||||||
p1_metric > p2_metric - min_diff) {
|
|
||||||
PRINTF("RPL: MRHOF hysteresis: %u <= %u <= %u\n",
|
|
||||||
p2_metric - min_diff,
|
|
||||||
p1_metric,
|
|
||||||
p2_metric + min_diff);
|
|
||||||
return dag->preferred_parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return p1_metric < p2_metric ? p1 : p2;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if RPL_DAG_MC == RPL_DAG_MC_NONE
|
|
||||||
static void
|
static void
|
||||||
update_metric_container(rpl_instance_t *instance)
|
update_metric_container(rpl_instance_t *instance)
|
||||||
{
|
{
|
||||||
instance->mc.type = RPL_DAG_MC;
|
instance->mc.type = RPL_DAG_MC_NONE;
|
||||||
}
|
}
|
||||||
#else
|
#else /* RPL_WITH_MC */
|
||||||
static void
|
static void
|
||||||
update_metric_container(rpl_instance_t *instance)
|
update_metric_container(rpl_instance_t *instance)
|
||||||
{
|
{
|
||||||
rpl_path_metric_t path_metric;
|
|
||||||
rpl_dag_t *dag;
|
rpl_dag_t *dag;
|
||||||
#if RPL_DAG_MC == RPL_DAG_MC_ENERGY
|
uint16_t path_cost;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
#endif
|
|
||||||
|
|
||||||
instance->mc.type = RPL_DAG_MC;
|
|
||||||
instance->mc.flags = RPL_DAG_MC_FLAG_P;
|
|
||||||
instance->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
|
|
||||||
instance->mc.prec = 0;
|
|
||||||
|
|
||||||
dag = instance->current_dag;
|
dag = instance->current_dag;
|
||||||
|
if(dag == NULL || !dag->joined) {
|
||||||
if (!dag->joined) {
|
|
||||||
PRINTF("RPL: Cannot update the metric container when not joined\n");
|
PRINTF("RPL: Cannot update the metric container when not joined\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dag->rank == ROOT_RANK(instance)) {
|
if(dag->rank == ROOT_RANK(instance)) {
|
||||||
path_metric = 0;
|
/* Configure MC at root only, other nodes are auto-configured when joining */
|
||||||
|
instance->mc.type = RPL_DAG_MC;
|
||||||
|
instance->mc.flags = 0;
|
||||||
|
instance->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
|
||||||
|
instance->mc.prec = 0;
|
||||||
|
path_cost = dag->rank;
|
||||||
} else {
|
} else {
|
||||||
path_metric = calculate_path_metric(dag->preferred_parent);
|
path_cost = parent_path_cost(dag->preferred_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RPL_DAG_MC == RPL_DAG_MC_ETX
|
/* Handle the different MC types */
|
||||||
|
switch(instance->mc.type) {
|
||||||
|
case RPL_DAG_MC_NONE:
|
||||||
|
break;
|
||||||
|
case RPL_DAG_MC_ETX:
|
||||||
instance->mc.length = sizeof(instance->mc.obj.etx);
|
instance->mc.length = sizeof(instance->mc.obj.etx);
|
||||||
instance->mc.obj.etx = path_metric;
|
instance->mc.obj.etx = path_cost;
|
||||||
|
break;
|
||||||
PRINTF("RPL: My path ETX to the root is %u.%u\n",
|
case RPL_DAG_MC_ENERGY:
|
||||||
instance->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
|
|
||||||
(instance->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) /
|
|
||||||
RPL_DAG_MC_ETX_DIVISOR);
|
|
||||||
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
|
|
||||||
instance->mc.length = sizeof(instance->mc.obj.energy);
|
instance->mc.length = sizeof(instance->mc.obj.energy);
|
||||||
|
|
||||||
if(dag->rank == ROOT_RANK(instance)) {
|
if(dag->rank == ROOT_RANK(instance)) {
|
||||||
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
|
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
|
||||||
} else {
|
} else {
|
||||||
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
|
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
instance->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
|
instance->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
|
||||||
instance->mc.obj.energy.energy_est = path_metric;
|
/* Energy_est is only one byte, use the least significant byte of the path metric. */
|
||||||
#endif /* RPL_DAG_MC == RPL_DAG_MC_ETX */
|
instance->mc.obj.energy.energy_est = path_cost >> 8;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PRINTF("RPL: MRHOF, non-supported MC %u\n", instance->mc.type);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#endif /* RPL_DAG_MC == RPL_DAG_MC_NONE */
|
}
|
||||||
|
#endif /* RPL_WITH_MC */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
rpl_of_t rpl_mrhof = {
|
||||||
|
reset,
|
||||||
|
#if RPL_WITH_DAO_ACK
|
||||||
|
dao_ack_callback,
|
||||||
|
#endif
|
||||||
|
parent_link_metric,
|
||||||
|
parent_path_cost,
|
||||||
|
rank_via_parent,
|
||||||
|
best_parent,
|
||||||
|
best_dag,
|
||||||
|
update_metric_container,
|
||||||
|
RPL_OCP_MRHOF
|
||||||
|
};
|
||||||
|
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
|
|
@ -27,11 +27,12 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \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>
|
* \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/rpl/rpl-private.h"
|
||||||
|
#include "net/nbr-table.h"
|
||||||
|
#include "net/link-stats.h"
|
||||||
|
|
||||||
#define DEBUG DEBUG_NONE
|
#define DEBUG DEBUG_NONE
|
||||||
#include "net/ip/uip-debug.h"
|
#include "net/ip/uip-debug.h"
|
||||||
|
|
||||||
static void reset(rpl_dag_t *);
|
/* Constants from RFC6552. We use the default values. */
|
||||||
static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
|
#define RANK_STRETCH 0 /* Must be in the range [0;5] */
|
||||||
static rpl_dag_t *best_dag(rpl_dag_t *, rpl_dag_t *);
|
#define RANK_FACTOR 1 /* Must be in the range [1;4] */
|
||||||
static rpl_rank_t calculate_rank(rpl_parent_t *, rpl_rank_t);
|
|
||||||
static void update_metric_container(rpl_instance_t *);
|
|
||||||
|
|
||||||
rpl_of_t rpl_of0 = {
|
#define MIN_STEP_OF_RANK 1
|
||||||
reset,
|
#define MAX_STEP_OF_RANK 9
|
||||||
NULL,
|
|
||||||
#if RPL_WITH_DAO_ACK
|
|
||||||
NULL,
|
|
||||||
#endif
|
|
||||||
best_parent,
|
|
||||||
best_dag,
|
|
||||||
calculate_rank,
|
|
||||||
update_metric_container,
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
#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
|
static void
|
||||||
reset(rpl_dag_t *dag)
|
reset(rpl_dag_t *dag)
|
||||||
{
|
{
|
||||||
PRINTF("RPL: Resetting OF0\n");
|
PRINTF("RPL: Reset OF0\n");
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static rpl_rank_t
|
static uint16_t
|
||||||
calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
|
parent_link_metric(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
min_hoprankinc = p->dag->instance->min_hoprankinc;
|
||||||
|
return (RANK_FACTOR * STEP_OF_RANK(p) + RANK_STRETCH) * min_hoprankinc;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static uint16_t
|
||||||
|
parent_path_cost(rpl_parent_t *p)
|
||||||
|
{
|
||||||
|
if(p == NULL) {
|
||||||
|
return 0xffff;
|
||||||
|
}
|
||||||
|
/* 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)
|
||||||
{
|
{
|
||||||
rpl_rank_t increment;
|
|
||||||
if(base_rank == 0) {
|
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
return INFINITE_RANK;
|
return INFINITE_RANK;
|
||||||
|
} else {
|
||||||
|
return MIN((uint32_t)p->rank + parent_rank_increase(p), INFINITE_RANK);
|
||||||
}
|
}
|
||||||
base_rank = p->rank;
|
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
increment = p != NULL ?
|
static int
|
||||||
p->dag->instance->min_hoprankinc :
|
parent_is_acceptable(rpl_parent_t *p)
|
||||||
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);
|
|
||||||
return INFINITE_RANK;
|
|
||||||
}
|
|
||||||
return base_rank + increment;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static rpl_dag_t *
|
|
||||||
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
|
|
||||||
{
|
{
|
||||||
if(d1->grounded) {
|
return STEP_OF_RANK(p) >= MIN_STEP_OF_RANK
|
||||||
if (!d2->grounded) {
|
&& STEP_OF_RANK(p) <= MAX_STEP_OF_RANK;
|
||||||
return d1;
|
|
||||||
}
|
}
|
||||||
} else if(d2->grounded) {
|
/*---------------------------------------------------------------------------*/
|
||||||
return d2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(d1->preference < d2->preference) {
|
|
||||||
return d2;
|
|
||||||
} else {
|
|
||||||
if(d1->preference > d2->preference) {
|
|
||||||
return d1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(d2->rank < d1->rank) {
|
|
||||||
return d2;
|
|
||||||
} else {
|
|
||||||
return d1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static rpl_parent_t *
|
static rpl_parent_t *
|
||||||
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
||||||
{
|
{
|
||||||
rpl_rank_t r1, r2;
|
|
||||||
rpl_dag_t *dag;
|
rpl_dag_t *dag;
|
||||||
uip_ds6_nbr_t *nbr1, *nbr2;
|
uint16_t p1_cost;
|
||||||
nbr1 = rpl_get_nbr(p1);
|
uint16_t p2_cost;
|
||||||
nbr2 = rpl_get_nbr(p2);
|
int p1_is_acceptable;
|
||||||
|
int p2_is_acceptable;
|
||||||
|
|
||||||
dag = (rpl_dag_t *)p1->dag; /* Both parents must be in the same DAG. */
|
if(p1 == NULL || p2 == NULL) {
|
||||||
|
/* Return non-null parent if any */
|
||||||
if(nbr1 == NULL || nbr2 == NULL) {
|
return p1 == NULL ? p2 : p1;
|
||||||
return dag->preferred_parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("RPL: Comparing parent ");
|
p1_is_acceptable = parent_is_acceptable(p1);
|
||||||
PRINT6ADDR(rpl_get_parent_ipaddr(p1));
|
p2_is_acceptable = parent_is_acceptable(p2);
|
||||||
PRINTF(" (confidence %d, rank %d) with parent ",
|
/* Is only one parent is acceptable, select it. If both are acceptable, or
|
||||||
nbr1->link_metric, p1->rank);
|
* both non-acceptable, proceed to traditional parent comparison. This is a
|
||||||
PRINT6ADDR(rpl_get_parent_ipaddr(p2));
|
* slight departure from the standard but allows to keep connectivity even
|
||||||
PRINTF(" (confidence %d, rank %d)\n",
|
* all neighbors appear to have a bad link. */
|
||||||
nbr2->link_metric, p2->rank);
|
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 +
|
/* Paths costs coarse-grained (multiple of min_hoprankinc), we operate without hysteresis */
|
||||||
nbr1->link_metric;
|
if(p1_cost != p2_cost) {
|
||||||
r2 = DAG_RANK(p2->rank, p1->dag->instance) * RPL_MIN_HOPRANKINC +
|
/* Pick parent with lowest path cost */
|
||||||
nbr2->link_metric;
|
return p1_cost < p2_cost ? p1 : p2;
|
||||||
/* 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;
|
|
||||||
} else {
|
} 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
|
static void
|
||||||
update_metric_container(rpl_instance_t *instance)
|
update_metric_container(rpl_instance_t *instance)
|
||||||
{
|
{
|
||||||
instance->mc.type = RPL_DAG_MC_NONE;
|
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
|
||||||
|
};
|
||||||
|
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
|
|
@ -199,13 +199,6 @@
|
||||||
#define RPL_MCAST_LIFETIME 3
|
#define RPL_MCAST_LIFETIME 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* The ETX in the metric container is expressed as a fixed-point value
|
|
||||||
* whose integer part can be obtained by dividing the value by
|
|
||||||
* RPL_DAG_MC_ETX_DIVISOR.
|
|
||||||
*/
|
|
||||||
#define RPL_DAG_MC_ETX_DIVISOR 256
|
|
||||||
|
|
||||||
/* DIS related */
|
/* DIS related */
|
||||||
#define RPL_DIS_SEND 1
|
#define RPL_DIS_SEND 1
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
|
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
#include "net/rpl/rpl-private.h"
|
#include "net/rpl/rpl-private.h"
|
||||||
|
#include "net/link-stats.h"
|
||||||
#include "net/ipv6/multicast/uip-mcast6.h"
|
#include "net/ipv6/multicast/uip-mcast6.h"
|
||||||
#include "lib/random.h"
|
#include "lib/random.h"
|
||||||
#include "sys/ctimer.h"
|
#include "sys/ctimer.h"
|
||||||
|
|
|
@ -268,10 +268,6 @@ rpl_link_neighbor_callback(const linkaddr_t *addr, int status, int numtx)
|
||||||
/* Trigger DAG rank recalculation. */
|
/* Trigger DAG rank recalculation. */
|
||||||
PRINTF("RPL: rpl_link_neighbor_callback triggering update\n");
|
PRINTF("RPL: rpl_link_neighbor_callback triggering update\n");
|
||||||
parent->flags |= RPL_PARENT_FLAG_UPDATED;
|
parent->flags |= RPL_PARENT_FLAG_UPDATED;
|
||||||
if(instance->of->neighbor_link_callback != NULL) {
|
|
||||||
instance->of->neighbor_link_callback(parent, status, numtx);
|
|
||||||
parent->last_tx_time = clock_time();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,8 +346,6 @@ rpl_init(void)
|
||||||
#if RPL_CONF_STATS
|
#if RPL_CONF_STATS
|
||||||
memset(&rpl_stats, 0, sizeof(rpl_stats));
|
memset(&rpl_stats, 0, sizeof(rpl_stats));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RPL_OF.reset(NULL);
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -113,11 +113,10 @@ struct rpl_dag;
|
||||||
|
|
||||||
struct rpl_parent {
|
struct rpl_parent {
|
||||||
struct rpl_dag *dag;
|
struct rpl_dag *dag;
|
||||||
#if RPL_DAG_MC != RPL_DAG_MC_NONE
|
#if RPL_WITH_MC
|
||||||
rpl_metric_container_t mc;
|
rpl_metric_container_t mc;
|
||||||
#endif /* RPL_DAG_MC != RPL_DAG_MC_NONE */
|
#endif /* RPL_WITH_MC */
|
||||||
rpl_rank_t rank;
|
rpl_rank_t rank;
|
||||||
clock_time_t last_tx_time;
|
|
||||||
uint8_t dtsn;
|
uint8_t dtsn;
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
};
|
};
|
||||||
|
@ -159,11 +158,21 @@ typedef struct rpl_instance rpl_instance_t;
|
||||||
* Resets the objective function state for a specific DAG. This function is
|
* Resets the objective function state for a specific DAG. This function is
|
||||||
* called when doing a global repair on the DAG.
|
* called when doing a global repair on the DAG.
|
||||||
*
|
*
|
||||||
* neighbor_link_callback(parent, known, etx)
|
* parent_link_metric(parent)
|
||||||
*
|
*
|
||||||
* Receives link-layer neighbor information. The parameter "known" is set
|
* Returns the link metric of a parent
|
||||||
* either to 0 or 1. The "etx" parameter specifies the current
|
*
|
||||||
* ETX(estimated transmissions) for the neighbor.
|
* parent_path_cost(parent)
|
||||||
|
*
|
||||||
|
* Returns the path cost of a parent
|
||||||
|
*
|
||||||
|
* rank_via_parent(parent)
|
||||||
|
*
|
||||||
|
* Returns our rank if we select a given parent as preferred parent
|
||||||
|
*
|
||||||
|
* parent_is_acceptable
|
||||||
|
*
|
||||||
|
* Returns 1 if a parent is usable as preferred parent, 0 otherwise
|
||||||
*
|
*
|
||||||
* best_parent(parent1, parent2)
|
* best_parent(parent1, parent2)
|
||||||
*
|
*
|
||||||
|
@ -173,13 +182,6 @@ typedef struct rpl_instance rpl_instance_t;
|
||||||
*
|
*
|
||||||
* Compares two DAGs and returns the best one, according to the OF.
|
* Compares two DAGs and returns the best one, according to the OF.
|
||||||
*
|
*
|
||||||
* calculate_rank(parent, base_rank)
|
|
||||||
*
|
|
||||||
* Calculates a rank value using the parent rank and a base rank.
|
|
||||||
* If "parent" is NULL, the objective function selects a default increment
|
|
||||||
* that is adds to the "base_rank". Otherwise, the OF uses information known
|
|
||||||
* about "parent" to select an increment to the "base_rank".
|
|
||||||
*
|
|
||||||
* update_metric_container(dag)
|
* update_metric_container(dag)
|
||||||
*
|
*
|
||||||
* Updates the metric container for outgoing DIOs in a certain DAG.
|
* Updates the metric container for outgoing DIOs in a certain DAG.
|
||||||
|
@ -194,20 +196,19 @@ typedef struct rpl_instance rpl_instance_t;
|
||||||
*/
|
*/
|
||||||
struct rpl_of {
|
struct rpl_of {
|
||||||
void (*reset)(struct rpl_dag *);
|
void (*reset)(struct rpl_dag *);
|
||||||
void (*neighbor_link_callback)(rpl_parent_t *, int, int);
|
|
||||||
#if RPL_WITH_DAO_ACK
|
#if RPL_WITH_DAO_ACK
|
||||||
void (*dao_ack_callback)(rpl_parent_t *, int status);
|
void (*dao_ack_callback)(rpl_parent_t *, int status);
|
||||||
#endif
|
#endif
|
||||||
|
uint16_t (*parent_link_metric)(rpl_parent_t *);
|
||||||
|
uint16_t (*parent_path_cost)(rpl_parent_t *);
|
||||||
|
rpl_rank_t (*rank_via_parent)(rpl_parent_t *);
|
||||||
rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *);
|
rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *);
|
||||||
rpl_dag_t *(*best_dag)(rpl_dag_t *, rpl_dag_t *);
|
rpl_dag_t *(*best_dag)(rpl_dag_t *, rpl_dag_t *);
|
||||||
rpl_rank_t (*calculate_rank)(rpl_parent_t *, rpl_rank_t);
|
|
||||||
void (*update_metric_container)( rpl_instance_t *);
|
void (*update_metric_container)( rpl_instance_t *);
|
||||||
rpl_ocp_t ocp;
|
rpl_ocp_t ocp;
|
||||||
};
|
};
|
||||||
typedef struct rpl_of rpl_of_t;
|
typedef struct rpl_of rpl_of_t;
|
||||||
|
|
||||||
/* Declare the selected objective function. */
|
|
||||||
extern rpl_of_t RPL_OF;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Instance */
|
/* Instance */
|
||||||
struct rpl_instance {
|
struct rpl_instance {
|
||||||
|
@ -272,10 +273,14 @@ int rpl_verify_header(int);
|
||||||
void rpl_insert_header(void);
|
void rpl_insert_header(void);
|
||||||
void rpl_remove_header(void);
|
void rpl_remove_header(void);
|
||||||
uint8_t rpl_invert_header(void);
|
uint8_t rpl_invert_header(void);
|
||||||
|
const struct link_stats *rpl_get_parent_link_stats(rpl_parent_t *p);
|
||||||
|
int rpl_parent_is_fresh(rpl_parent_t *p);
|
||||||
|
uint16_t rpl_get_parent_link_metric(rpl_parent_t *p);
|
||||||
|
rpl_rank_t rpl_rank_via_parent(rpl_parent_t *p);
|
||||||
|
const linkaddr_t *rpl_get_parent_lladdr(rpl_parent_t *p);
|
||||||
uip_ipaddr_t *rpl_get_parent_ipaddr(rpl_parent_t *nbr);
|
uip_ipaddr_t *rpl_get_parent_ipaddr(rpl_parent_t *nbr);
|
||||||
rpl_parent_t *rpl_get_parent(uip_lladdr_t *addr);
|
rpl_parent_t *rpl_get_parent(uip_lladdr_t *addr);
|
||||||
rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr);
|
rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr);
|
||||||
uint16_t rpl_get_parent_link_metric(const uip_lladdr_t *addr);
|
|
||||||
void rpl_dag_init(void);
|
void rpl_dag_init(void);
|
||||||
uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent);
|
uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent);
|
||||||
void rpl_print_neighbor_list(void);
|
void rpl_print_neighbor_list(void);
|
||||||
|
|
Loading…
Reference in a new issue