2010-04-30 15:43:53 +02:00
|
|
|
/**
|
|
|
|
* \addtogroup uip6
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Logic for Directed Acyclic Graphs in RPL.
|
|
|
|
*
|
|
|
|
* \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-01-04 21:43:28 +01:00
|
|
|
#include "contiki.h"
|
2011-02-11 16:21:17 +01:00
|
|
|
#include "net/rpl/rpl-private.h"
|
2010-04-30 15:43:53 +02:00
|
|
|
#include "net/uip.h"
|
2010-05-25 21:19:43 +02:00
|
|
|
#include "net/uip-nd6.h"
|
2010-04-30 15:43:53 +02:00
|
|
|
#include "lib/list.h"
|
|
|
|
#include "lib/memb.h"
|
2010-06-14 14:44:37 +02:00
|
|
|
#include "sys/ctimer.h"
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
#include <limits.h>
|
2010-05-04 16:41:55 +02:00
|
|
|
#include <string.h>
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2011-02-13 21:36:07 +01:00
|
|
|
#define DEBUG DEBUG_NONE
|
2010-04-30 15:43:53 +02:00
|
|
|
#include "net/uip-debug.h"
|
|
|
|
|
2011-02-11 14:18:57 +01:00
|
|
|
#include "net/neighbor-info.h"
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
/************************************************************************/
|
2011-01-04 21:43:28 +01:00
|
|
|
extern rpl_of_t RPL_OF;
|
|
|
|
static rpl_of_t * const objective_functions[] = {&RPL_OF};
|
2010-05-30 00:23:21 +02:00
|
|
|
/************************************************************************/
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
#ifndef RPL_CONF_MAX_DAG_ENTRIES
|
|
|
|
#define RPL_MAX_DAG_ENTRIES 2
|
|
|
|
#else
|
|
|
|
#define RPL_MAX_DAG_ENTRIES RPL_CONF_MAX_DAG_ENTRIES
|
|
|
|
#endif /* !RPL_CONF_MAX_DAG_ENTRIES */
|
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
#ifndef RPL_CONF_MAX_PARENTS
|
2010-06-14 14:44:37 +02:00
|
|
|
#define RPL_MAX_PARENTS 8
|
2010-04-30 15:43:53 +02:00
|
|
|
#else
|
2010-05-25 23:58:54 +02:00
|
|
|
#define RPL_MAX_PARENTS RPL_CONF_MAX_PARENTS
|
|
|
|
#endif /* !RPL_CONF_MAX_PARENTS */
|
2010-04-30 15:43:53 +02:00
|
|
|
/************************************************************************/
|
|
|
|
/* RPL definitions. */
|
|
|
|
|
|
|
|
#ifndef RPL_CONF_GROUNDED
|
|
|
|
#define RPL_GROUNDED 0
|
|
|
|
#else
|
|
|
|
#define RPL_GROUNDED RPL_CONF_GROUNDED
|
|
|
|
#endif /* !RPL_CONF_GROUNDED */
|
|
|
|
|
|
|
|
#ifndef RPL_CONF_DIO_INTERVAL_MIN
|
|
|
|
#define RPL_DIO_INTERVAL_MIN DEFAULT_DIO_INTERVAL_MIN
|
|
|
|
#else
|
|
|
|
#define RPL_DIO_INTERVAL_MIN RPL_CONF_DIO_INTERVAL_MIN
|
|
|
|
#endif /* !RPL_CONF_DIO_INTERVAL_MIN */
|
|
|
|
|
|
|
|
#ifndef RPL_CONF_DIO_INTERVAL_DOUBLINGS
|
|
|
|
#define RPL_DIO_INTERVAL_DOUBLINGS DEFAULT_DIO_INTERVAL_DOUBLINGS
|
|
|
|
#else
|
|
|
|
#define RPL_DIO_INTERVAL_DOUBLINGS RPL_CONF_DIO_INTERVAL_DOUBLINGS
|
|
|
|
#endif /* !RPL_CONF_DIO_INTERVAL_DOUBLINGS */
|
2011-02-11 14:18:57 +01:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
/************************************************************************/
|
2010-05-25 23:58:54 +02:00
|
|
|
/* Allocate parents from the same static MEMB chunk to reduce memory waste. */
|
|
|
|
MEMB(parent_memb, struct rpl_parent, RPL_MAX_PARENTS);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
static rpl_dag_t dag_table[RPL_MAX_DAG_ENTRIES];
|
|
|
|
/************************************************************************/
|
2010-06-28 16:51:23 +02:00
|
|
|
/* Remove DAG parents with a rank that is at least the same as minimum_rank. */
|
2010-04-30 15:43:53 +02:00
|
|
|
static void
|
2010-06-28 16:51:23 +02:00
|
|
|
remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p, *p2;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-09-15 15:22:22 +02:00
|
|
|
PRINTF("RPL: Removing parents (minimum rank %u)\n",
|
|
|
|
minimum_rank);
|
2010-06-14 14:44:37 +02:00
|
|
|
|
|
|
|
for(p = list_head(dag->parents); p != NULL; p = p2) {
|
|
|
|
p2 = p->next;
|
2010-10-27 02:46:40 +02:00
|
|
|
if(p->rank >= minimum_rank) {
|
2010-06-14 14:44:37 +02:00
|
|
|
rpl_remove_parent(dag, p);
|
|
|
|
}
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
2011-02-13 21:33:47 +01:00
|
|
|
static void
|
2011-02-14 23:01:11 +01:00
|
|
|
remove_worst_parent(rpl_dag_t *dag, rpl_rank_t min_worst_rank)
|
2011-02-13 21:33:47 +01:00
|
|
|
{
|
|
|
|
rpl_parent_t *p, *worst;
|
|
|
|
|
|
|
|
PRINTF("RPL: Removing the worst parent\n");
|
|
|
|
|
2011-02-14 23:01:11 +01:00
|
|
|
/* Find the parent with the highest rank. */
|
2011-02-13 21:33:47 +01:00
|
|
|
worst = NULL;
|
2011-02-14 23:01:11 +01:00
|
|
|
for(p = list_head(dag->parents); p != NULL; p = list_item_next(p)) {
|
|
|
|
if(p != dag->preferred_parent &&
|
|
|
|
(worst == NULL || p->rank > worst->rank)) {
|
2011-02-13 21:33:47 +01:00
|
|
|
worst = p;
|
|
|
|
}
|
|
|
|
}
|
2011-02-14 23:01:11 +01:00
|
|
|
/* Remove the neighbor if its rank is worse than the minimum worst
|
|
|
|
rank. */
|
|
|
|
if(worst != NULL && worst->rank > min_worst_rank) {
|
|
|
|
rpl_remove_parent(dag, worst);
|
|
|
|
}
|
2011-02-13 21:33:47 +01:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
2010-06-06 23:42:50 +02:00
|
|
|
static int
|
|
|
|
should_send_dao(rpl_dag_t *dag, rpl_dio_t *dio, rpl_parent_t *p)
|
|
|
|
{
|
2011-04-06 20:14:30 +02:00
|
|
|
/* if MOP is set to no downward routes no DAO should be sent */
|
|
|
|
if(dag->mop == RPL_MOP_NO_DOWNWARD_ROUTES) return 0;
|
2010-12-17 16:24:25 +01:00
|
|
|
return dio->dtsn > p->dtsn && p == dag->preferred_parent;
|
2010-06-06 23:42:50 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
2010-06-07 16:01:22 +02:00
|
|
|
static int
|
2010-06-14 14:44:37 +02:00
|
|
|
acceptable_rank(rpl_dag_t *dag, rpl_rank_t rank)
|
2010-06-07 16:01:22 +02:00
|
|
|
{
|
2010-09-15 15:22:22 +02:00
|
|
|
return rank != INFINITE_RANK &&
|
2010-10-25 22:03:37 +02:00
|
|
|
(dag->max_rankinc == 0 ||
|
|
|
|
DAG_RANK(rank, dag) <= DAG_RANK(dag->min_rank + dag->max_rankinc, dag));
|
2010-06-07 16:01:22 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
2010-05-30 00:23:21 +02:00
|
|
|
rpl_dag_t *
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_set_root(uip_ipaddr_t *dag_id)
|
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
2010-06-03 17:20:56 +02:00
|
|
|
int version;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-06-03 17:20:56 +02:00
|
|
|
version = -1;
|
2010-06-08 23:37:22 +02:00
|
|
|
dag = rpl_get_dag(RPL_DEFAULT_INSTANCE);
|
2010-04-30 15:43:53 +02:00
|
|
|
if(dag != NULL) {
|
|
|
|
PRINTF("RPL: Dropping a joined DAG when setting this node as root");
|
2010-06-03 17:20:56 +02:00
|
|
|
version = dag->version;
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_free_dag(dag);
|
|
|
|
}
|
|
|
|
|
2010-06-08 23:37:22 +02:00
|
|
|
dag = rpl_alloc_dag(RPL_DEFAULT_INSTANCE);
|
2010-04-30 15:43:53 +02:00
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL: Failed to allocate a DAG\n");
|
2010-05-30 00:23:21 +02:00
|
|
|
return NULL;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dag->joined = 1;
|
2010-06-03 17:20:56 +02:00
|
|
|
dag->version = version + 1;
|
2010-04-30 15:43:53 +02:00
|
|
|
dag->grounded = RPL_GROUNDED;
|
2010-12-13 11:54:25 +01:00
|
|
|
dag->mop = RPL_MOP_DEFAULT;
|
2011-01-04 21:43:28 +01:00
|
|
|
dag->of = &RPL_OF;
|
2010-06-14 14:44:37 +02:00
|
|
|
dag->preferred_parent = NULL;
|
2010-06-08 18:21:54 +02:00
|
|
|
dag->dtsn_out = 1; /* Trigger DAOs from the beginning. */
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
memcpy(&dag->dag_id, dag_id, sizeof(dag->dag_id));
|
|
|
|
|
|
|
|
dag->dio_intdoubl = DEFAULT_DIO_INTERVAL_DOUBLINGS;
|
|
|
|
dag->dio_intmin = DEFAULT_DIO_INTERVAL_MIN;
|
|
|
|
dag->dio_redundancy = DEFAULT_DIO_REDUNDANCY;
|
2010-06-02 00:30:02 +02:00
|
|
|
dag->max_rankinc = DEFAULT_MAX_RANKINC;
|
|
|
|
dag->min_hoprankinc = DEFAULT_MIN_HOPRANKINC;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-12-13 11:59:37 +01:00
|
|
|
dag->default_lifetime = DEFAULT_RPL_DEF_LIFETIME;
|
|
|
|
dag->lifetime_unit = DEFAULT_RPL_LIFETIME_UNIT;
|
|
|
|
|
2011-02-20 20:15:40 +01:00
|
|
|
dag->rank = ROOT_RANK(dag);
|
|
|
|
|
2011-02-15 01:13:30 +01:00
|
|
|
dag->of->update_metric_container(dag);
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINTF("RPL: Node set to be a DAG root with DAG ID ");
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2011-02-22 16:15:16 +01:00
|
|
|
ANNOTATE("#A root=%u\n",dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
|
|
|
|
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
|
|
|
|
2010-05-30 00:23:21 +02:00
|
|
|
return dag;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
int
|
2010-06-03 14:55:09 +02:00
|
|
|
rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, int len)
|
|
|
|
{
|
2010-05-25 21:19:43 +02:00
|
|
|
if(len <= 128) {
|
2010-06-02 00:30:02 +02:00
|
|
|
memset(&dag->prefix_info.prefix, 0, 16);
|
2010-06-03 14:55:09 +02:00
|
|
|
memcpy(&dag->prefix_info.prefix, prefix, (len + 7) / 8);
|
2010-06-02 00:30:02 +02:00
|
|
|
dag->prefix_info.length = len;
|
|
|
|
dag->prefix_info.flags = UIP_ND6_RA_FLAG_AUTONOMOUS;
|
2010-05-25 21:19:43 +02:00
|
|
|
PRINTF("RPL: Prefix set - will announce this in DIOs\n");
|
2010-06-03 14:55:09 +02:00
|
|
|
return 1;
|
2010-05-25 21:19:43 +02:00
|
|
|
}
|
2010-06-03 14:55:09 +02:00
|
|
|
return 0;
|
2010-05-25 21:19:43 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
int
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_set_default_route(rpl_dag_t *dag, uip_ipaddr_t *from)
|
|
|
|
{
|
|
|
|
if(dag->def_route != NULL) {
|
|
|
|
PRINTF("RPL: Removing default route through ");
|
|
|
|
PRINT6ADDR(&dag->def_route->ipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_ds6_defrt_rm(dag->def_route);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(from != NULL) {
|
|
|
|
PRINTF("RPL: Adding default route through ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF("\n");
|
2010-05-10 15:46:35 +02:00
|
|
|
if(DEFAULT_ROUTE_LIFETIME == INFINITE_LIFETIME) {
|
|
|
|
dag->def_route = uip_ds6_defrt_add(from, 0);
|
|
|
|
} else {
|
|
|
|
dag->def_route = uip_ds6_defrt_add(from, DEFAULT_ROUTE_LIFETIME);
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
if(dag->def_route == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
rpl_dag_t *
|
2010-06-08 23:37:22 +02:00
|
|
|
rpl_alloc_dag(uint8_t instance_id)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2010-06-14 14:44:37 +02:00
|
|
|
rpl_dag_t *dag;
|
|
|
|
rpl_dag_t *end;
|
|
|
|
|
|
|
|
for(dag = &dag_table[0], end = dag + RPL_MAX_DAG_ENTRIES; dag < end; dag++) {
|
|
|
|
if(dag->used == 0) {
|
|
|
|
memset(dag, 0, sizeof(*dag));
|
|
|
|
dag->parents = &dag->parent_list;
|
|
|
|
list_init(dag->parents);
|
|
|
|
dag->instance_id = instance_id;
|
|
|
|
dag->def_route = NULL;
|
|
|
|
dag->rank = INFINITE_RANK;
|
|
|
|
dag->min_rank = INFINITE_RANK;
|
|
|
|
return dag;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
2010-12-17 16:24:25 +01:00
|
|
|
|
|
|
|
RPL_STAT(rpl_stats.mem_overflows++);
|
2010-04-30 15:43:53 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
void
|
|
|
|
rpl_free_dag(rpl_dag_t *dag)
|
|
|
|
{
|
|
|
|
PRINTF("RPL: Leaving the DAG ");
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2010-06-03 17:20:56 +02:00
|
|
|
/* Remove routes installed by DAOs. */
|
|
|
|
rpl_remove_routes(dag);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-06-03 17:20:56 +02:00
|
|
|
/* Remove parents and the default route. */
|
2010-06-28 16:51:23 +02:00
|
|
|
remove_parents(dag, 0);
|
2010-06-03 17:20:56 +02:00
|
|
|
rpl_set_default_route(dag, NULL);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
ctimer_stop(&dag->dio_timer);
|
|
|
|
ctimer_stop(&dag->dao_timer);
|
2010-06-03 17:20:56 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
dag->used = 0;
|
|
|
|
dag->joined = 0;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *
|
2010-06-02 18:54:59 +02:00
|
|
|
rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
p = memb_alloc(&parent_memb);
|
|
|
|
if(p == NULL) {
|
2010-10-27 02:46:40 +02:00
|
|
|
RPL_STAT(rpl_stats.mem_overflows++);
|
2010-04-30 15:43:53 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
memcpy(&p->addr, addr, sizeof(p->addr));
|
|
|
|
p->dag = dag;
|
2010-06-14 14:44:37 +02:00
|
|
|
p->rank = dio->rank;
|
2011-03-16 13:29:01 +01:00
|
|
|
p->link_metric = INITIAL_LINK_METRIC;
|
2010-06-06 23:42:50 +02:00
|
|
|
p->dtsn = 0;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2011-02-15 01:13:30 +01:00
|
|
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
list_add(dag->parents, p);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
return p;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *
|
|
|
|
rpl_find_parent(rpl_dag_t *dag, uip_ipaddr_t *addr)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
for(p = list_head(dag->parents); p != NULL; p = p->next) {
|
|
|
|
if(uip_ipaddr_cmp(&p->addr, addr)) {
|
|
|
|
return p;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *
|
2010-06-14 14:44:37 +02:00
|
|
|
rpl_select_parent(rpl_dag_t *dag)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p;
|
|
|
|
rpl_parent_t *best;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
best = NULL;
|
2010-05-25 23:58:54 +02:00
|
|
|
for(p = list_head(dag->parents); p != NULL; p = p->next) {
|
2011-04-07 17:44:07 +02:00
|
|
|
if(p->rank == INFINITE_RANK) {
|
|
|
|
/* ignore this neighbor */
|
|
|
|
} else if(best == NULL) {
|
2010-05-25 23:58:54 +02:00
|
|
|
best = p;
|
|
|
|
} else {
|
|
|
|
best = dag->of->best_parent(best, p);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 14:44:37 +02:00
|
|
|
|
2011-04-07 17:44:07 +02:00
|
|
|
if(best == NULL) {
|
|
|
|
/* need to handle update of best... */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
if(dag->preferred_parent != best) {
|
2011-05-03 17:50:24 +02:00
|
|
|
PRINTF("RPL: Sending a No-Path DAO to old DAO parent\n");
|
|
|
|
dao_output(dag->preferred_parent, ZERO_LIFETIME);
|
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
dag->preferred_parent = best; /* Cache the value. */
|
2011-02-15 01:13:30 +01:00
|
|
|
dag->of->update_metric_container(dag);
|
2010-06-03 17:20:56 +02:00
|
|
|
rpl_set_default_route(dag, &best->addr);
|
2010-06-08 17:40:50 +02:00
|
|
|
/* The DAO parent set changed - schedule a DAO transmission. */
|
2011-04-06 20:14:30 +02:00
|
|
|
if(dag->mop != RPL_MOP_NO_DOWNWARD_ROUTES) {
|
|
|
|
rpl_schedule_dao(dag);
|
|
|
|
}
|
2010-06-28 16:51:23 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
2010-06-14 14:44:37 +02:00
|
|
|
PRINTF("RPL: New preferred parent, rank changed from %u to %u\n",
|
|
|
|
(unsigned)dag->rank, dag->of->calculate_rank(best, 0));
|
2011-03-15 14:14:41 +01:00
|
|
|
RPL_STAT(rpl_stats.parent_switch++);
|
2010-06-03 17:20:56 +02:00
|
|
|
}
|
2010-06-14 14:44:37 +02:00
|
|
|
|
|
|
|
/* Update the DAG rank, since link-layer information may have changed
|
|
|
|
the local confidence. */
|
|
|
|
dag->rank = dag->of->calculate_rank(best, 0);
|
2010-06-28 16:51:23 +02:00
|
|
|
if(dag->rank < dag->min_rank) {
|
|
|
|
dag->min_rank = dag->rank;
|
2010-06-14 14:44:37 +02:00
|
|
|
} else if(!acceptable_rank(dag, best->rank)) {
|
2010-06-28 16:51:23 +02:00
|
|
|
/* Send a No-Path DAO to the soon-to-be-removed preferred parent. */
|
2011-05-03 17:50:24 +02:00
|
|
|
dao_output(best, ZERO_LIFETIME);
|
2010-06-28 16:51:23 +02:00
|
|
|
|
|
|
|
remove_parents(dag, 0);
|
2010-06-14 14:44:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
int
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_remove_parent(rpl_dag_t *dag, rpl_parent_t *parent)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
|
|
|
uip_ds6_defrt_t *defrt;
|
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
/* Remove uIPv6 routes that have this parent as the next hop. **/
|
2010-04-30 15:43:53 +02:00
|
|
|
uip_ds6_route_rm_by_nexthop(&parent->addr);
|
|
|
|
defrt = uip_ds6_defrt_lookup(&parent->addr);
|
|
|
|
if(defrt != NULL) {
|
|
|
|
PRINTF("RPL: Removing default route ");
|
|
|
|
PRINT6ADDR(&parent->addr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_ds6_defrt_rm(defrt);
|
|
|
|
dag->def_route = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
PRINTF("RPL: Removing parent ");
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINT6ADDR(&parent->addr);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2010-10-27 14:20:35 +02:00
|
|
|
if(parent == dag->preferred_parent) {
|
|
|
|
dag->preferred_parent = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 23:58:54 +02:00
|
|
|
list_remove(dag->parents, parent);
|
|
|
|
memb_free(&parent_memb, parent);
|
2010-04-30 15:43:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
rpl_dag_t *
|
|
|
|
rpl_get_dag(int instance_id)
|
|
|
|
{
|
|
|
|
int i;
|
2010-12-17 16:24:25 +01:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
for(i = 0; i < RPL_MAX_DAG_ENTRIES; i++) {
|
|
|
|
if(dag_table[i].joined && (instance_id == RPL_ANY_INSTANCE ||
|
2011-01-04 21:43:28 +01:00
|
|
|
dag_table[i].instance_id == instance_id)) {
|
2010-04-30 15:43:53 +02:00
|
|
|
return &dag_table[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
rpl_of_t *
|
|
|
|
rpl_find_of(rpl_ocp_t ocp)
|
|
|
|
{
|
2011-02-19 09:25:29 +01:00
|
|
|
unsigned int i;
|
2010-05-30 00:23:21 +02:00
|
|
|
|
2011-01-04 21:43:28 +01:00
|
|
|
for(i = 0;
|
|
|
|
i < sizeof(objective_functions) / sizeof(objective_functions[0]);
|
|
|
|
i++) {
|
|
|
|
if(objective_functions[i]->ocp == ocp) {
|
|
|
|
return objective_functions[i];
|
2010-05-30 00:23:21 +02:00
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2010-05-30 00:23:21 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
static void
|
|
|
|
join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_of_t *of;
|
|
|
|
|
2010-06-08 23:37:22 +02:00
|
|
|
dag = rpl_alloc_dag(dio->instance_id);
|
2010-04-30 15:43:53 +02:00
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL: Failed to allocate a DAG object!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-02 18:54:59 +02:00
|
|
|
p = rpl_add_parent(dag, dio, from);
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINTF("RPL: Adding ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF(" as a parent: ");
|
2010-05-25 23:58:54 +02:00
|
|
|
if(p == NULL) {
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINTF("failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PRINTF("succeeded\n");
|
|
|
|
|
|
|
|
/* Determine the objective function by using the
|
|
|
|
objective code point of the DIO. */
|
|
|
|
of = rpl_find_of(dio->ocp);
|
|
|
|
if(of == NULL) {
|
2010-05-05 00:55:32 +02:00
|
|
|
PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF\n",
|
2010-04-30 15:43:53 +02:00
|
|
|
dio->instance_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-03 20:37:47 +02:00
|
|
|
/* Autoconfigure an address if this node does not already have an address
|
|
|
|
with this prefix. */
|
|
|
|
if((dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) {
|
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
/* assume that the prefix ends with zeros! */
|
|
|
|
memcpy(&ipaddr, &dio->prefix_info.prefix, 16);
|
|
|
|
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
|
|
|
if(uip_ds6_addr_lookup(&ipaddr) == NULL) {
|
|
|
|
PRINTF("RPL: adding global IP address ");
|
|
|
|
PRINT6ADDR(&ipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-03 17:20:56 +02:00
|
|
|
dag->joined = 1;
|
2010-04-30 15:43:53 +02:00
|
|
|
dag->used = 1;
|
|
|
|
dag->of = of;
|
|
|
|
dag->grounded = dio->grounded;
|
2010-12-13 11:54:25 +01:00
|
|
|
dag->mop = dio->mop;
|
|
|
|
dag->preference = dio->preference;
|
2010-04-30 15:43:53 +02:00
|
|
|
dag->instance_id = dio->instance_id;
|
2010-09-15 15:22:22 +02:00
|
|
|
|
|
|
|
dag->max_rankinc = dio->dag_max_rankinc;
|
|
|
|
dag->min_hoprankinc = dio->dag_min_hoprankinc;
|
|
|
|
|
2010-06-02 13:59:51 +02:00
|
|
|
dag->version = dio->version;
|
2010-06-14 14:44:37 +02:00
|
|
|
dag->preferred_parent = p;
|
2011-02-15 01:13:30 +01:00
|
|
|
dag->of->update_metric_container(dag);
|
2010-06-06 23:42:50 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
dag->dio_intdoubl = dio->dag_intdoubl;
|
|
|
|
dag->dio_intmin = dio->dag_intmin;
|
|
|
|
dag->dio_redundancy = dio->dag_redund;
|
|
|
|
|
|
|
|
memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));
|
|
|
|
|
2010-05-25 21:19:43 +02:00
|
|
|
/* copy prefix information into the dag */
|
2010-06-02 00:30:02 +02:00
|
|
|
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
|
2010-05-25 21:19:43 +02:00
|
|
|
|
2011-02-22 02:01:15 +01:00
|
|
|
dag->rank = dag->of->calculate_rank(p, dio->rank);
|
|
|
|
dag->min_rank = dag->rank; /* So far this is the lowest rank we know of. */
|
|
|
|
|
2010-05-05 00:55:32 +02:00
|
|
|
PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
|
2010-04-30 15:43:53 +02:00
|
|
|
dio->instance_id, dag->rank);
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2011-02-22 16:15:16 +01:00
|
|
|
ANNOTATE("#A join=%u\n",dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
|
|
|
|
|
|
|
|
|
2010-12-13 11:59:37 +01:00
|
|
|
dag->default_lifetime = dio->default_lifetime;
|
|
|
|
dag->lifetime_unit = dio->lifetime_unit;
|
|
|
|
|
2010-06-03 17:20:56 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_set_default_route(dag, from);
|
|
|
|
|
2010-06-06 23:42:50 +02:00
|
|
|
if(should_send_dao(dag, dio, p)) {
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_schedule_dao(dag);
|
|
|
|
} else {
|
2010-12-13 11:54:25 +01:00
|
|
|
PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
static void
|
|
|
|
global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
|
|
|
|
{
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-06-28 16:51:23 +02:00
|
|
|
remove_parents(dag, 0);
|
2010-06-02 13:59:51 +02:00
|
|
|
dag->version = dio->version;
|
2010-06-08 18:21:54 +02:00
|
|
|
dag->dtsn_out = 1;
|
2010-06-02 18:54:59 +02:00
|
|
|
dag->of->reset(dag);
|
|
|
|
if((p = rpl_add_parent(dag, dio, from)) == NULL) {
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINTF("RPL: Failed to add a parent during the global repair\n");
|
|
|
|
dag->rank = INFINITE_RANK;
|
|
|
|
} else {
|
|
|
|
rpl_set_default_route(dag, from);
|
2010-06-14 14:44:37 +02:00
|
|
|
dag->rank = dag->of->calculate_rank(NULL, dio->rank);
|
|
|
|
dag->min_rank = dag->rank;
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
2010-06-06 23:42:50 +02:00
|
|
|
if(should_send_dao(dag, dio, p)) {
|
|
|
|
rpl_schedule_dao(dag);
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2010-06-03 14:55:09 +02:00
|
|
|
PRINTF("RPL: Participating in a global repair (version=%u, rank=%hu)\n",
|
2010-06-02 13:59:51 +02:00
|
|
|
dag->version, dag->rank);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-10-27 02:46:40 +02:00
|
|
|
RPL_STAT(rpl_stats.global_repairs++);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
int
|
|
|
|
rpl_repair_dag(rpl_dag_t *dag)
|
|
|
|
{
|
2011-02-20 20:15:40 +01:00
|
|
|
if(dag->rank == ROOT_RANK(dag)) {
|
2010-06-02 13:59:51 +02:00
|
|
|
dag->version++;
|
2010-06-08 18:21:54 +02:00
|
|
|
dag->dtsn_out = 1;
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
void
|
2010-10-27 02:46:40 +02:00
|
|
|
rpl_local_repair(rpl_dag_t *dag)
|
|
|
|
{
|
|
|
|
PRINTF("RPL: Starting a local DAG repair\n");
|
|
|
|
|
|
|
|
dag->rank = INFINITE_RANK;
|
|
|
|
remove_parents(dag, 0);
|
|
|
|
rpl_reset_dio_timer(dag, 1);
|
|
|
|
|
|
|
|
RPL_STAT(rpl_stats.local_repairs++);
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
void
|
2010-06-14 14:44:37 +02:00
|
|
|
rpl_recalculate_ranks(void)
|
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
|
|
|
rpl_parent_t *p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We recalculate ranks when we receive feedback from the system rather
|
|
|
|
* than RPL protocol messages. This periodical recalculation is called
|
|
|
|
* from a timer in order to keep the stack depth reasonably low.
|
|
|
|
*/
|
|
|
|
dag = rpl_get_dag(RPL_ANY_INSTANCE);
|
|
|
|
if(dag != NULL) {
|
|
|
|
for(p = list_head(dag->parents); p != NULL; p = p->next) {
|
|
|
|
if(p->updated) {
|
|
|
|
p->updated = 0;
|
|
|
|
rpl_process_parent_event(dag, p);
|
|
|
|
/*
|
|
|
|
* Stop calculating here because the parent list may have changed.
|
|
|
|
* If more ranks need to be recalculated, it will be taken care of
|
|
|
|
* in subsequent calls to this functions.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
int
|
|
|
|
rpl_process_parent_event(rpl_dag_t *dag, rpl_parent_t *p)
|
|
|
|
{
|
|
|
|
rpl_rank_t parent_rank;
|
|
|
|
rpl_rank_t old_rank;
|
|
|
|
|
|
|
|
/* Update the parent rank. */
|
|
|
|
parent_rank = p->rank;
|
|
|
|
old_rank = dag->rank;
|
|
|
|
|
|
|
|
if(rpl_select_parent(dag) == NULL) {
|
|
|
|
/* No suitable parent; trigger a local repair. */
|
2010-10-27 02:46:40 +02:00
|
|
|
PRINTF("RPL: No parents found in a DAG\n");
|
|
|
|
rpl_local_repair(dag);
|
2010-06-14 14:44:37 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-15 15:22:22 +02:00
|
|
|
if(DAG_RANK(old_rank, dag) != DAG_RANK(dag->rank, dag)) {
|
2010-06-14 14:44:37 +02:00
|
|
|
if(dag->rank < dag->min_rank) {
|
|
|
|
dag->min_rank = dag->rank;
|
|
|
|
}
|
|
|
|
PRINTF("RPL: Moving in the DAG from rank %hu to %hu\n",
|
2010-10-25 22:03:37 +02:00
|
|
|
DAG_RANK(old_rank, dag), DAG_RANK(dag->rank, dag));
|
2010-10-22 17:40:10 +02:00
|
|
|
PRINTF("RPL: The preferred parent is ");
|
2010-06-14 14:44:37 +02:00
|
|
|
PRINT6ADDR(&dag->preferred_parent->addr);
|
2010-10-22 17:40:10 +02:00
|
|
|
PRINTF(" (rank %u)\n",
|
|
|
|
(unsigned)DAG_RANK(dag->preferred_parent->rank, dag));
|
2010-06-14 14:44:37 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
|
|
|
}
|
|
|
|
|
2011-04-07 17:44:07 +02:00
|
|
|
if(parent_rank == INFINITE_RANK ||
|
|
|
|
!acceptable_rank(dag, dag->of->calculate_rank(NULL, parent_rank))) {
|
2010-06-14 14:44:37 +02:00
|
|
|
/* The candidate parent is no longer valid: the rank increase resulting
|
|
|
|
from the choice of it as a parent would be too high. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/************************************************************************/
|
|
|
|
void
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
2010-05-25 23:58:54 +02:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-12-13 11:54:25 +01:00
|
|
|
if(dio->mop != RPL_MOP_DEFAULT) {
|
|
|
|
PRINTF("RPL: Ignoring a DIO with an unsupported MOP: %d\n", dio->mop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
dag = rpl_get_dag(dio->instance_id);
|
|
|
|
if(dag == NULL) {
|
2010-06-14 14:44:37 +02:00
|
|
|
/* Join the first possible DAG of this RPL instance. */
|
|
|
|
if(dio->rank != INFINITE_RANK) {
|
2010-04-30 15:43:53 +02:00
|
|
|
join_dag(from, dio);
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Ignoring DIO from node with infinite rank: ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF("\n");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-31 16:22:00 +02:00
|
|
|
if(memcmp(&dag->dag_id, &dio->dag_id, sizeof(dag->dag_id))) {
|
|
|
|
PRINTF("RPL: Ignoring DIO for another DAG within our instance\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-02 13:59:51 +02:00
|
|
|
if(dio->version > dag->version) {
|
2011-02-20 20:15:40 +01:00
|
|
|
if(dag->rank == ROOT_RANK(dag)) {
|
2010-06-02 13:59:51 +02:00
|
|
|
PRINTF("RPL: Root received inconsistent DIO version number\n");
|
|
|
|
dag->version = dio->version + 1;
|
2010-05-31 16:22:00 +02:00
|
|
|
rpl_reset_dio_timer(dag, 1);
|
|
|
|
} else {
|
|
|
|
global_repair(from, dag, dio);
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
return;
|
2010-06-02 18:54:59 +02:00
|
|
|
} else if(dio->version < dag->version) {
|
|
|
|
/* Inconsistency detected - someone is still on old version */
|
|
|
|
PRINTF("RPL: old version received => inconsistency detected\n");
|
|
|
|
rpl_reset_dio_timer(dag, 1);
|
|
|
|
return;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
if(dio->rank == INFINITE_RANK) {
|
|
|
|
rpl_reset_dio_timer(dag, 1);
|
2011-02-20 20:15:40 +01:00
|
|
|
} else if(dio->rank < ROOT_RANK(dag)) {
|
|
|
|
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
|
|
|
|
(unsigned)dio->rank);
|
|
|
|
return;
|
2010-06-28 16:51:23 +02:00
|
|
|
}
|
|
|
|
|
2011-02-20 20:15:40 +01:00
|
|
|
if(dag->rank == ROOT_RANK(dag)) {
|
2010-06-28 16:51:23 +02:00
|
|
|
if(dio->rank != INFINITE_RANK) {
|
|
|
|
dag->dio_counter++;
|
|
|
|
}
|
2010-06-14 14:44:37 +02:00
|
|
|
return;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
|
2010-06-28 16:51:23 +02:00
|
|
|
/*
|
|
|
|
* At this point, we know that this DIO pertains to a DAG that
|
|
|
|
* we are already part of. We consider the sender of the DIO to be
|
|
|
|
* a candidate parent, and let rpl_process_parent_event decide
|
|
|
|
* whether to keep it in the set.
|
|
|
|
*/
|
2010-06-14 14:44:37 +02:00
|
|
|
|
|
|
|
p = rpl_find_parent(dag, from);
|
2011-02-13 21:33:47 +01:00
|
|
|
if(p == NULL) {
|
2010-07-04 01:52:02 +02:00
|
|
|
if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) {
|
2011-02-13 21:33:47 +01:00
|
|
|
/* Make room for a new parent. */
|
2011-02-14 23:01:11 +01:00
|
|
|
remove_worst_parent(dag, dio->rank);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2011-02-13 18:05:28 +01:00
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
/* Add the DIO sender as a candidate parent. */
|
|
|
|
p = rpl_add_parent(dag, dio, from);
|
|
|
|
if(p == NULL) {
|
|
|
|
PRINTF("RPL: Failed to add a new parent (");
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINT6ADDR(from);
|
2010-06-14 14:44:37 +02:00
|
|
|
PRINTF(")\n");
|
|
|
|
return;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2011-03-16 13:29:01 +01:00
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF("\n");
|
2010-09-15 15:22:22 +02:00
|
|
|
} else if(DAG_RANK(p->rank, dag) == DAG_RANK(dio->rank, dag)) {
|
2010-06-28 16:51:23 +02:00
|
|
|
PRINTF("RPL: Received consistent DIO\n");
|
|
|
|
dag->dio_counter++;
|
2010-06-14 14:44:37 +02:00
|
|
|
}
|
2011-02-13 18:05:28 +01:00
|
|
|
|
2010-09-15 15:22:22 +02:00
|
|
|
/* We have allocated a candidate parent; process the DIO further. */
|
2011-03-16 13:29:01 +01:00
|
|
|
|
|
|
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
2010-06-28 16:51:23 +02:00
|
|
|
p->rank = dio->rank;
|
|
|
|
if(rpl_process_parent_event(dag, p) == 0) {
|
|
|
|
/* The candidate parent no longer exists. */
|
|
|
|
return;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2011-02-13 18:05:28 +01:00
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
if(should_send_dao(dag, dio, p)) {
|
|
|
|
rpl_schedule_dao(dag);
|
|
|
|
}
|
2011-02-13 18:05:28 +01:00
|
|
|
|
2010-06-14 14:44:37 +02:00
|
|
|
p->dtsn = dio->dtsn;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/************************************************************************/
|
2010-06-07 16:01:22 +02:00
|
|
|
|