Replaced ROOT_RANK with a macro that allows for other min_hoprankinc parameters than the default. Also made some minor style improvements.
This commit is contained in:
parent
263f7e6ebd
commit
01b7a4f7f2
|
@ -179,7 +179,6 @@ rpl_set_root(uip_ipaddr_t *dag_id)
|
||||||
dag->version = version + 1;
|
dag->version = version + 1;
|
||||||
dag->grounded = RPL_GROUNDED;
|
dag->grounded = RPL_GROUNDED;
|
||||||
dag->mop = RPL_MOP_DEFAULT;
|
dag->mop = RPL_MOP_DEFAULT;
|
||||||
dag->rank = ROOT_RANK;
|
|
||||||
dag->of = &RPL_OF;
|
dag->of = &RPL_OF;
|
||||||
dag->preferred_parent = NULL;
|
dag->preferred_parent = NULL;
|
||||||
dag->dtsn_out = 1; /* Trigger DAOs from the beginning. */
|
dag->dtsn_out = 1; /* Trigger DAOs from the beginning. */
|
||||||
|
@ -195,6 +194,8 @@ rpl_set_root(uip_ipaddr_t *dag_id)
|
||||||
dag->default_lifetime = DEFAULT_RPL_DEF_LIFETIME;
|
dag->default_lifetime = DEFAULT_RPL_DEF_LIFETIME;
|
||||||
dag->lifetime_unit = DEFAULT_RPL_LIFETIME_UNIT;
|
dag->lifetime_unit = DEFAULT_RPL_LIFETIME_UNIT;
|
||||||
|
|
||||||
|
dag->rank = ROOT_RANK(dag);
|
||||||
|
|
||||||
dag->of->update_metric_container(dag);
|
dag->of->update_metric_container(dag);
|
||||||
|
|
||||||
PRINTF("RPL: Node set to be a DAG root with DAG ID ");
|
PRINTF("RPL: Node set to be a DAG root with DAG ID ");
|
||||||
|
@ -555,7 +556,7 @@ global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
|
||||||
int
|
int
|
||||||
rpl_repair_dag(rpl_dag_t *dag)
|
rpl_repair_dag(rpl_dag_t *dag)
|
||||||
{
|
{
|
||||||
if(dag->rank == ROOT_RANK) {
|
if(dag->rank == ROOT_RANK(dag)) {
|
||||||
dag->version++;
|
dag->version++;
|
||||||
dag->dtsn_out = 1;
|
dag->dtsn_out = 1;
|
||||||
rpl_reset_dio_timer(dag, 1);
|
rpl_reset_dio_timer(dag, 1);
|
||||||
|
@ -673,7 +674,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dio->version > dag->version) {
|
if(dio->version > dag->version) {
|
||||||
if(dag->rank == ROOT_RANK) {
|
if(dag->rank == ROOT_RANK(dag)) {
|
||||||
PRINTF("RPL: Root received inconsistent DIO version number\n");
|
PRINTF("RPL: Root received inconsistent DIO version number\n");
|
||||||
dag->version = dio->version + 1;
|
dag->version = dio->version + 1;
|
||||||
rpl_reset_dio_timer(dag, 1);
|
rpl_reset_dio_timer(dag, 1);
|
||||||
|
@ -690,9 +691,13 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
|
|
||||||
if(dio->rank == INFINITE_RANK) {
|
if(dio->rank == INFINITE_RANK) {
|
||||||
rpl_reset_dio_timer(dag, 1);
|
rpl_reset_dio_timer(dag, 1);
|
||||||
|
} else if(dio->rank < ROOT_RANK(dag)) {
|
||||||
|
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
|
||||||
|
(unsigned)dio->rank);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dag->rank == ROOT_RANK) {
|
if(dag->rank == ROOT_RANK(dag)) {
|
||||||
if(dio->rank != INFINITE_RANK) {
|
if(dio->rank != INFINITE_RANK) {
|
||||||
dag->dio_counter++;
|
dag->dio_counter++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,6 @@ rpl_of_t rpl_of_etx = {
|
||||||
typedef uint16_t rpl_etx_t;
|
typedef uint16_t rpl_etx_t;
|
||||||
#define MAX_ETX 65535
|
#define MAX_ETX 65535
|
||||||
|
|
||||||
static rpl_etx_t min_path_cost = MAX_ETX;
|
|
||||||
|
|
||||||
static uint16_t
|
static uint16_t
|
||||||
calculate_etx(rpl_parent_t *p)
|
calculate_etx(rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
|
@ -98,18 +96,11 @@ calculate_etx(rpl_parent_t *p)
|
||||||
static void
|
static void
|
||||||
reset(rpl_dag_t *dag)
|
reset(rpl_dag_t *dag)
|
||||||
{
|
{
|
||||||
min_path_cost = MAX_ETX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parent_state_callback(rpl_parent_t *parent, int known, int etx)
|
parent_state_callback(rpl_parent_t *parent, int known, int etx)
|
||||||
{
|
{
|
||||||
if(!known) {
|
|
||||||
if(RPL_PARENT_COUNT(parent->dag) == 1) {
|
|
||||||
/* Our last parent has disappeared, set the path ETX to INFINITE_RANK. */
|
|
||||||
min_path_cost = INFINITE_RANK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static rpl_rank_t
|
static rpl_rank_t
|
||||||
|
@ -156,7 +147,7 @@ best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
||||||
dag = p1->dag; /* Both parents must be in the same DAG. */
|
dag = p1->dag; /* Both parents must be in the same DAG. */
|
||||||
|
|
||||||
min_diff = RPL_DAG_MC_ETX_DIVISOR /
|
min_diff = RPL_DAG_MC_ETX_DIVISOR /
|
||||||
PARENT_SWITCH_THRESHOLD_DIV;
|
PARENT_SWITCH_THRESHOLD_DIV;
|
||||||
|
|
||||||
p1_etx = calculate_etx(p1);
|
p1_etx = calculate_etx(p1);
|
||||||
p2_etx = calculate_etx(p2);
|
p2_etx = calculate_etx(p2);
|
||||||
|
@ -171,11 +162,7 @@ best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
||||||
return dag->preferred_parent;
|
return dag->preferred_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p1_etx < p2_etx) {
|
return p1_etx < p2_etx ? p1 : p2;
|
||||||
return p1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return p2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -186,7 +173,7 @@ update_metric_container(rpl_dag_t *dag)
|
||||||
dag->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
|
dag->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
|
||||||
dag->mc.prec = 0;
|
dag->mc.prec = 0;
|
||||||
dag->mc.length = sizeof(dag->mc.etx.etx);
|
dag->mc.length = sizeof(dag->mc.etx.etx);
|
||||||
if(dag->rank == ROOT_RANK) {
|
if(dag->rank == ROOT_RANK(dag)) {
|
||||||
dag->mc.etx.etx = 0;
|
dag->mc.etx.etx = 0;
|
||||||
} else {
|
} else {
|
||||||
dag->mc.etx.etx = calculate_etx(dag->preferred_parent);
|
dag->mc.etx.etx = calculate_etx(dag->preferred_parent);
|
||||||
|
|
|
@ -119,17 +119,17 @@
|
||||||
|
|
||||||
#define DAG_RANK(fixpt_rank, dag) ((fixpt_rank) / (dag)->min_hoprankinc)
|
#define DAG_RANK(fixpt_rank, dag) ((fixpt_rank) / (dag)->min_hoprankinc)
|
||||||
|
|
||||||
/* Rank of a node outside the LLN. */
|
/* Rank of a virtual root node that coordinates DAG root nodes. */
|
||||||
#define BASE_RANK 0
|
#define BASE_RANK 0
|
||||||
|
|
||||||
/* Rank of a root node. */
|
/* Rank of a root node. */
|
||||||
#define ROOT_RANK DEFAULT_MIN_HOPRANKINC
|
#define ROOT_RANK(dag) (dag)->min_hoprankinc
|
||||||
|
|
||||||
#define INFINITE_RANK 0xffff
|
#define INFINITE_RANK 0xffff
|
||||||
|
|
||||||
/* Represents 2^n ms. */
|
/* Represents 2^n ms. */
|
||||||
/* Default alue according to the specification is 3 which
|
/* Default value according to the specification is 3 which
|
||||||
means 8 milliseconds - this is not a reasonable value if
|
means 8 milliseconds, but that is an unreasonable value if
|
||||||
using power-saving / duty-cycling */
|
using power-saving / duty-cycling */
|
||||||
#define DEFAULT_DIO_INTERVAL_MIN 12
|
#define DEFAULT_DIO_INTERVAL_MIN 12
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue