2010-04-30 13:43:53 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2014-11-08 00:15:42 +00:00
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Logic for Directed Acyclic Graphs in RPL.
|
|
|
|
*
|
|
|
|
* \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se>
|
2011-12-09 12:15:04 +00:00
|
|
|
* Contributors: George Oikonomou <oikonomou@users.sourceforge.net> (multicast)
|
2010-04-30 13:43:53 +00:00
|
|
|
*/
|
|
|
|
|
2014-11-08 00:15:42 +00:00
|
|
|
/**
|
2017-09-29 20:18:48 +00:00
|
|
|
* \addtogroup uip
|
2014-11-08 00:15:42 +00:00
|
|
|
* @{
|
|
|
|
*/
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-01-04 20:43:28 +00:00
|
|
|
#include "contiki.h"
|
2015-11-29 20:44:39 +00:00
|
|
|
#include "net/link-stats.h"
|
2017-12-10 20:59:17 +00:00
|
|
|
#include "net/routing/rpl-classic/rpl.h"
|
|
|
|
#include "net/routing/rpl-classic/rpl-private.h"
|
2017-12-13 20:00:33 +00:00
|
|
|
#include "net/routing/rpl-classic/rpl-dag-root.h"
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip.h"
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ipv6/uip-nd6.h"
|
2014-10-20 14:15:20 +00:00
|
|
|
#include "net/ipv6/uip-ds6-nbr.h"
|
2013-07-29 16:49:21 +00:00
|
|
|
#include "net/nbr-table.h"
|
2011-12-09 12:15:04 +00:00
|
|
|
#include "net/ipv6/multicast/uip-mcast6.h"
|
2010-04-30 13:43:53 +00:00
|
|
|
#include "lib/list.h"
|
|
|
|
#include "lib/memb.h"
|
2010-06-14 12:44:37 +00:00
|
|
|
#include "sys/ctimer.h"
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
#include <limits.h>
|
2010-05-04 14:41:55 +00:00
|
|
|
#include <string.h>
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-02-13 20:36:07 +00:00
|
|
|
#define DEBUG DEBUG_NONE
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip-debug.h"
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2015-09-21 16:23:14 +00:00
|
|
|
/* A configurable function called after every RPL parent switch */
|
|
|
|
#ifdef RPL_CALLBACK_PARENT_SWITCH
|
|
|
|
void RPL_CALLBACK_PARENT_SWITCH(rpl_parent_t *old, rpl_parent_t *new);
|
|
|
|
#endif /* RPL_CALLBACK_PARENT_SWITCH */
|
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-29 20:48:06 +00:00
|
|
|
extern rpl_of_t rpl_of0, rpl_mrhof;
|
|
|
|
static rpl_of_t * const objective_functions[] = RPL_SUPPORTED_OFS;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
/* RPL definitions. */
|
|
|
|
|
|
|
|
#ifndef RPL_CONF_GROUNDED
|
|
|
|
#define RPL_GROUNDED 0
|
|
|
|
#else
|
|
|
|
#define RPL_GROUNDED RPL_CONF_GROUNDED
|
|
|
|
#endif /* !RPL_CONF_GROUNDED */
|
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-07-03 17:53:51 +00:00
|
|
|
/* Per-parent RPL information */
|
2015-05-06 09:35:42 +00:00
|
|
|
NBR_TABLE_GLOBAL(rpl_parent_t, rpl_parents);
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
/* Allocate instance table. */
|
|
|
|
rpl_instance_t instance_table[RPL_MAX_INSTANCES];
|
2011-12-09 13:36:23 +00:00
|
|
|
rpl_instance_t *default_instance;
|
2014-10-20 14:15:20 +00:00
|
|
|
|
2015-05-06 09:34:52 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2016-03-02 06:00:57 +00:00
|
|
|
rpl_print_neighbor_list(void)
|
2015-05-06 09:34:52 +00:00
|
|
|
{
|
|
|
|
if(default_instance != NULL && default_instance->current_dag != NULL &&
|
2015-11-29 20:44:39 +00:00
|
|
|
default_instance->of != NULL) {
|
2015-05-06 09:34:52 +00:00
|
|
|
int curr_dio_interval = default_instance->dio_intcurrent;
|
|
|
|
int curr_rank = default_instance->current_dag->rank;
|
|
|
|
rpl_parent_t *p = nbr_table_head(rpl_parents);
|
2015-11-29 20:46:41 +00:00
|
|
|
clock_time_t clock_now = clock_time();
|
2015-05-06 09:34:52 +00:00
|
|
|
|
2016-02-01 17:02:33 +00:00
|
|
|
printf("RPL: MOP %u OCP %u rank %u dioint %u, nbr count %u\n",
|
|
|
|
default_instance->mop, default_instance->of->ocp, curr_rank, curr_dio_interval, uip_ds6_nbr_num());
|
2015-05-06 09:34:52 +00:00
|
|
|
while(p != NULL) {
|
2015-11-29 20:46:41 +00:00
|
|
|
const struct link_stats *stats = rpl_get_parent_link_stats(p);
|
|
|
|
printf("RPL: nbr %3u %5u, %5u => %5u -- %2u %c%c (last tx %u min ago)\n",
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_parent_get_ipaddr(p)->u8[15],
|
2015-11-29 20:44:39 +00:00
|
|
|
p->rank,
|
|
|
|
rpl_get_parent_link_metric(p),
|
|
|
|
rpl_rank_via_parent(p),
|
|
|
|
stats != NULL ? stats->freshness : 0,
|
|
|
|
link_stats_is_fresh(stats) ? 'f' : ' ',
|
|
|
|
p == default_instance->current_dag->preferred_parent ? 'p' : ' ',
|
2015-11-29 20:46:41 +00:00
|
|
|
(unsigned)((clock_now - stats->last_tx_time) / (60 * CLOCK_SECOND))
|
2015-11-29 20:44:39 +00:00
|
|
|
);
|
2015-05-06 09:34:52 +00:00
|
|
|
p = nbr_table_next(rpl_parents, p);
|
|
|
|
}
|
|
|
|
printf("RPL: end of list\n");
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-10-20 14:15:20 +00:00
|
|
|
uip_ds6_nbr_t *
|
2014-12-10 08:07:20 +00:00
|
|
|
rpl_get_nbr(rpl_parent_t *parent)
|
|
|
|
{
|
2015-11-29 20:48:53 +00:00
|
|
|
const linkaddr_t *lladdr = rpl_get_parent_lladdr(parent);
|
2014-10-20 14:15:20 +00:00
|
|
|
if(lladdr != NULL) {
|
|
|
|
return nbr_table_get_from_lladdr(ds6_neighbors, lladdr);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-11-20 13:06:46 +00:00
|
|
|
static void
|
|
|
|
nbr_callback(void *ptr)
|
|
|
|
{
|
|
|
|
rpl_remove_parent(ptr);
|
|
|
|
}
|
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
void
|
2013-08-11 21:46:26 +00:00
|
|
|
rpl_dag_init(void)
|
2013-07-03 17:53:51 +00:00
|
|
|
{
|
2013-11-20 13:06:46 +00:00
|
|
|
nbr_table_register(rpl_parents, (nbr_table_callback *)nbr_callback);
|
2013-07-03 17:53:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-01-31 08:38:42 +00:00
|
|
|
rpl_parent_t *
|
|
|
|
rpl_get_parent(uip_lladdr_t *addr)
|
|
|
|
{
|
|
|
|
rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (linkaddr_t *)addr);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_rank_t
|
|
|
|
rpl_get_parent_rank(uip_lladdr_t *addr)
|
|
|
|
{
|
2013-12-12 22:58:52 +00:00
|
|
|
rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (linkaddr_t *)addr);
|
2013-07-03 17:53:51 +00:00
|
|
|
if(p != NULL) {
|
|
|
|
return p->rank;
|
|
|
|
} else {
|
2017-06-10 12:35:39 +00:00
|
|
|
return RPL_INFINITE_RANK;
|
2013-07-03 17:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-08-11 21:50:37 +00:00
|
|
|
uint16_t
|
2015-11-29 20:44:39 +00:00
|
|
|
rpl_get_parent_link_metric(rpl_parent_t *p)
|
2013-08-11 21:50:37 +00:00
|
|
|
{
|
2015-11-29 20:44:39 +00:00
|
|
|
if(p != NULL && p->dag != NULL) {
|
|
|
|
rpl_instance_t *instance = p->dag->instance;
|
|
|
|
if(instance != NULL && instance->of != NULL && instance->of->parent_link_metric != NULL) {
|
|
|
|
return instance->of->parent_link_metric(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2013-08-11 21:50:37 +00:00
|
|
|
}
|
2017-06-10 12:35:39 +00:00
|
|
|
return RPL_INFINITE_RANK;
|
2015-11-29 20:44:39 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
const linkaddr_t *
|
|
|
|
rpl_get_parent_lladdr(rpl_parent_t *p)
|
|
|
|
{
|
|
|
|
return nbr_table_get_lladdr(rpl_parents, p);
|
2013-08-11 21:50:37 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-07-03 17:53:51 +00:00
|
|
|
uip_ipaddr_t *
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_parent_get_ipaddr(rpl_parent_t *p)
|
2013-07-03 17:53:51 +00:00
|
|
|
{
|
2015-11-29 20:44:39 +00:00
|
|
|
const linkaddr_t *lladdr = rpl_get_parent_lladdr(p);
|
2013-07-03 17:53:51 +00:00
|
|
|
return uip_ds6_nbr_ipaddr_from_lladdr((uip_lladdr_t *)lladdr);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-29 20:44:39 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-30 18:17:17 +00:00
|
|
|
int
|
|
|
|
rpl_parent_is_reachable(rpl_parent_t *p) {
|
|
|
|
if(p == NULL || p->dag == NULL || p->dag->instance == NULL || p->dag->instance->of == NULL) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
2017-01-16 12:44:15 +00:00
|
|
|
#if UIP_ND6_SEND_NS
|
2015-11-30 18:17:17 +00:00
|
|
|
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) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-16 12:44:15 +00:00
|
|
|
#endif /* UIP_ND6_SEND_NS */
|
2015-11-30 18:17:17 +00:00
|
|
|
/* If we don't have fresh link information, assume the parent is reachable. */
|
|
|
|
return !rpl_parent_is_fresh(p) || p->dag->instance->of->parent_has_usable_link(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-07-03 17:53:51 +00:00
|
|
|
static void
|
|
|
|
rpl_set_preferred_parent(rpl_dag_t *dag, rpl_parent_t *p)
|
|
|
|
{
|
|
|
|
if(dag != NULL && dag->preferred_parent != p) {
|
2013-08-11 21:42:51 +00:00
|
|
|
PRINTF("RPL: rpl_set_preferred_parent ");
|
|
|
|
if(p != NULL) {
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(p));
|
2013-08-11 21:42:51 +00:00
|
|
|
} else {
|
|
|
|
PRINTF("NULL");
|
|
|
|
}
|
|
|
|
PRINTF(" used to be ");
|
|
|
|
if(dag->preferred_parent != NULL) {
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
|
2013-08-11 21:42:51 +00:00
|
|
|
} else {
|
|
|
|
PRINTF("NULL");
|
|
|
|
}
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2015-09-21 16:23:14 +00:00
|
|
|
#ifdef RPL_CALLBACK_PARENT_SWITCH
|
|
|
|
RPL_CALLBACK_PARENT_SWITCH(dag->preferred_parent, p);
|
|
|
|
#endif /* RPL_CALLBACK_PARENT_SWITCH */
|
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
/* Always keep the preferred parent locked, so it remains in the
|
|
|
|
* neighbor table. */
|
|
|
|
nbr_table_unlock(rpl_parents, dag->preferred_parent);
|
|
|
|
nbr_table_lock(rpl_parents, p);
|
2013-08-11 22:01:07 +00:00
|
|
|
dag->preferred_parent = p;
|
2013-07-03 17:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-02-29 20:59:50 +00:00
|
|
|
/* Greater-than function for the lollipop counter. */
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-04-21 22:18:07 +00:00
|
|
|
static int
|
|
|
|
lollipop_greater_than(int a, int b)
|
|
|
|
{
|
2012-02-21 12:20:20 +00:00
|
|
|
/* Check if we are comparing an initial value with an old value */
|
|
|
|
if(a > RPL_LOLLIPOP_CIRCULAR_REGION && b <= RPL_LOLLIPOP_CIRCULAR_REGION) {
|
|
|
|
return (RPL_LOLLIPOP_MAX_VALUE + 1 + b - a) > RPL_LOLLIPOP_SEQUENCE_WINDOWS;
|
|
|
|
}
|
|
|
|
/* Otherwise check if a > b and comparable => ok, or
|
|
|
|
if they have wrapped and are still comparable */
|
|
|
|
return (a > b && (a - b) < RPL_LOLLIPOP_SEQUENCE_WINDOWS) ||
|
|
|
|
(a < b && (b - a) > (RPL_LOLLIPOP_CIRCULAR_REGION + 1-
|
|
|
|
RPL_LOLLIPOP_SEQUENCE_WINDOWS));
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-28 14:51:23 +00:00
|
|
|
/* Remove DAG parents with a rank that is at least the same as minimum_rank. */
|
2010-04-30 13:43:53 +00:00
|
|
|
static void
|
2010-06-28 14:51:23 +00:00
|
|
|
remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-09-15 13:22:22 +00:00
|
|
|
PRINTF("RPL: Removing parents (minimum rank %u)\n",
|
|
|
|
minimum_rank);
|
2010-06-14 12:44:37 +00:00
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
p = nbr_table_head(rpl_parents);
|
|
|
|
while(p != NULL) {
|
|
|
|
if(dag == p->dag && p->rank >= minimum_rank) {
|
|
|
|
rpl_remove_parent(p);
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
2013-07-03 17:53:51 +00:00
|
|
|
p = nbr_table_next(rpl_parents, p);
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-02-13 20:33:47 +00:00
|
|
|
static void
|
2011-07-11 13:50:51 +00:00
|
|
|
nullify_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
|
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_parent_t *p;
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2013-11-20 13:07:29 +00:00
|
|
|
PRINTF("RPL: Nullifying parents (minimum rank %u)\n",
|
2011-07-11 13:50:51 +00:00
|
|
|
minimum_rank);
|
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
p = nbr_table_head(rpl_parents);
|
|
|
|
while(p != NULL) {
|
|
|
|
if(dag == p->dag && p->rank >= minimum_rank) {
|
|
|
|
rpl_nullify_parent(p);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2013-07-03 17:53:51 +00:00
|
|
|
p = nbr_table_next(rpl_parents, p);
|
2011-02-14 22:01:11 +00:00
|
|
|
}
|
2011-02-13 20:33:47 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-06 21:42:50 +00:00
|
|
|
static int
|
2016-11-25 15:30:08 +00:00
|
|
|
should_refresh_routes(rpl_instance_t *instance, rpl_dio_t *dio, rpl_parent_t *p)
|
2010-06-06 21:42:50 +00:00
|
|
|
{
|
2011-04-06 18:14:30 +00:00
|
|
|
/* if MOP is set to no downward routes no DAO should be sent */
|
2011-11-21 13:59:31 +00:00
|
|
|
if(instance->mop == RPL_MOP_NO_DOWNWARD_ROUTES) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-21 12:20:20 +00:00
|
|
|
/* check if the new DTSN is more recent */
|
2011-11-21 13:59:31 +00:00
|
|
|
return p == instance->current_dag->preferred_parent &&
|
2012-04-21 22:18:07 +00:00
|
|
|
(lollipop_greater_than(dio->dtsn, p->dtsn));
|
2010-06-06 21:42:50 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-07 14:01:22 +00:00
|
|
|
static int
|
2010-06-14 12:44:37 +00:00
|
|
|
acceptable_rank(rpl_dag_t *dag, rpl_rank_t rank)
|
2010-06-07 14:01:22 +00:00
|
|
|
{
|
2017-06-10 12:35:39 +00:00
|
|
|
return rank != RPL_INFINITE_RANK &&
|
2011-07-11 13:50:51 +00:00
|
|
|
((dag->instance->max_rankinc == 0) ||
|
|
|
|
DAG_RANK(rank, dag->instance) <= DAG_RANK(dag->min_rank + dag->instance->max_rankinc, dag->instance));
|
2010-06-07 14:01:22 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-04-17 21:35:19 +00:00
|
|
|
static rpl_dag_t *
|
|
|
|
get_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
|
|
|
|
{
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
rpl_dag_t *dag;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
instance = rpl_get_instance(instance_id);
|
|
|
|
if(instance == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < RPL_MAX_DAG_PER_INSTANCE; ++i) {
|
|
|
|
dag = &instance->dag_table[i];
|
|
|
|
if(dag->used && uip_ipaddr_cmp(&dag->dag_id, dag_id)) {
|
|
|
|
return dag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-29 22:23:21 +00:00
|
|
|
rpl_dag_t *
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *instance;
|
|
|
|
uint8_t version;
|
2015-01-16 15:43:14 +00:00
|
|
|
int i;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
version = RPL_LOLLIPOP_INIT;
|
2015-01-16 15:43:14 +00:00
|
|
|
instance = rpl_get_instance(instance_id);
|
|
|
|
if(instance != NULL) {
|
|
|
|
for(i = 0; i < RPL_MAX_DAG_PER_INSTANCE; ++i) {
|
|
|
|
dag = &instance->dag_table[i];
|
|
|
|
if(dag->used) {
|
|
|
|
if(uip_ipaddr_cmp(&dag->dag_id, dag_id)) {
|
|
|
|
version = dag->version;
|
|
|
|
RPL_LOLLIPOP_INCREMENT(version);
|
|
|
|
}
|
|
|
|
if(dag == dag->instance->current_dag) {
|
|
|
|
PRINTF("RPL: Dropping a joined DAG when setting this node as root");
|
2017-12-07 13:52:37 +00:00
|
|
|
rpl_set_default_route(instance, NULL);
|
2015-01-16 15:43:14 +00:00
|
|
|
dag->instance->current_dag = NULL;
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Dropping a DAG when setting this node as root");
|
|
|
|
}
|
|
|
|
rpl_free_dag(dag);
|
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 21:12:47 +00:00
|
|
|
dag = rpl_alloc_dag(instance_id, dag_id);
|
2010-04-30 13:43:53 +00:00
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL: Failed to allocate a DAG\n");
|
2010-05-29 22:23:21 +00:00
|
|
|
return NULL;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
instance = dag->instance;
|
|
|
|
|
|
|
|
dag->version = version;
|
2010-04-30 13:43:53 +00:00
|
|
|
dag->joined = 1;
|
|
|
|
dag->grounded = RPL_GROUNDED;
|
2013-07-02 11:41:19 +00:00
|
|
|
dag->preference = RPL_PREFERENCE;
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->mop = RPL_MOP_DEFAULT;
|
2015-11-29 20:48:06 +00:00
|
|
|
instance->of = rpl_find_of(RPL_OF_OCP);
|
|
|
|
if(instance->of == NULL) {
|
|
|
|
PRINTF("RPL: OF with OCP %u not supported\n", RPL_OF_OCP);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_set_preferred_parent(dag, NULL);
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
memcpy(&dag->dag_id, dag_id, sizeof(dag->dag_id));
|
|
|
|
|
2012-02-29 20:59:50 +00:00
|
|
|
instance->dio_intdoubl = RPL_DIO_INTERVAL_DOUBLINGS;
|
|
|
|
instance->dio_intmin = RPL_DIO_INTERVAL_MIN;
|
2012-01-04 10:22:11 +00:00
|
|
|
/* The current interval must differ from the minimum interval in order to
|
|
|
|
trigger a DIO timer reset. */
|
2012-02-29 20:59:50 +00:00
|
|
|
instance->dio_intcurrent = RPL_DIO_INTERVAL_MIN +
|
|
|
|
RPL_DIO_INTERVAL_DOUBLINGS;
|
|
|
|
instance->dio_redundancy = RPL_DIO_REDUNDANCY;
|
|
|
|
instance->max_rankinc = RPL_MAX_RANKINC;
|
|
|
|
instance->min_hoprankinc = RPL_MIN_HOPRANKINC;
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->default_lifetime = RPL_DEFAULT_LIFETIME;
|
|
|
|
instance->lifetime_unit = RPL_DEFAULT_LIFETIME_UNIT;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->rank = ROOT_RANK(instance);
|
2010-12-13 10:59:37 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->current_dag != dag && instance->current_dag != NULL) {
|
|
|
|
/* Remove routes installed by DAOs. */
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(instance)) {
|
|
|
|
rpl_remove_routes(instance->current_dag);
|
|
|
|
}
|
2011-02-20 19:15:40 +00:00
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
instance->current_dag->joined = 0;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
instance->current_dag = dag;
|
|
|
|
instance->dtsn_out = RPL_LOLLIPOP_INIT;
|
|
|
|
instance->of->update_metric_container(instance);
|
|
|
|
default_instance = instance;
|
2011-02-15 00:13:30 +00:00
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("RPL: Node set to be a DAG root with DAG ID ");
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
ANNOTATE("#A root=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
|
2011-02-22 15:15:16 +00:00
|
|
|
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_reset_dio_timer(instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-05-29 22:23:21 +00:00
|
|
|
return dag;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
int
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_repair_root(uint8_t instance_id)
|
|
|
|
{
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_instance_t *instance;
|
2011-07-11 13:50:51 +00:00
|
|
|
|
|
|
|
instance = rpl_get_instance(instance_id);
|
2012-01-04 10:22:11 +00:00
|
|
|
if(instance == NULL ||
|
|
|
|
instance->current_dag->rank != ROOT_RANK(instance)) {
|
2013-08-11 21:42:51 +00:00
|
|
|
PRINTF("RPL: rpl_repair_root triggered but not root\n");
|
2011-07-11 13:50:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-16 08:24:55 +00:00
|
|
|
RPL_STAT(rpl_stats.root_repairs++);
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2012-01-04 10:22:11 +00:00
|
|
|
RPL_LOLLIPOP_INCREMENT(instance->current_dag->version);
|
|
|
|
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
|
2013-08-11 21:42:51 +00:00
|
|
|
PRINTF("RPL: rpl_repair_root initiating global repair with version %d\n", instance->current_dag->version);
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_reset_dio_timer(instance);
|
|
|
|
return 1;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-11-21 13:59:31 +00:00
|
|
|
static void
|
|
|
|
set_ip_from_prefix(uip_ipaddr_t *ipaddr, rpl_prefix_t *prefix)
|
2011-07-13 08:42:59 +00:00
|
|
|
{
|
|
|
|
memset(ipaddr, 0, sizeof(uip_ipaddr_t));
|
2011-09-22 15:22:59 +00:00
|
|
|
memcpy(ipaddr, &prefix->prefix, (prefix->length + 7) / 8);
|
2011-07-13 08:42:59 +00:00
|
|
|
uip_ds6_set_addr_iid(ipaddr, &uip_lladdr);
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-11-21 13:59:31 +00:00
|
|
|
static void
|
|
|
|
check_prefix(rpl_prefix_t *last_prefix, rpl_prefix_t *new_prefix)
|
2011-07-13 08:42:59 +00:00
|
|
|
{
|
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
uip_ds6_addr_t *rep;
|
2011-11-21 13:59:31 +00:00
|
|
|
|
|
|
|
if(last_prefix != NULL && new_prefix != NULL &&
|
|
|
|
last_prefix->length == new_prefix->length &&
|
|
|
|
uip_ipaddr_prefixcmp(&last_prefix->prefix, &new_prefix->prefix, new_prefix->length) &&
|
|
|
|
last_prefix->flags == new_prefix->flags) {
|
|
|
|
/* Nothing has changed. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(last_prefix != NULL) {
|
|
|
|
set_ip_from_prefix(&ipaddr, last_prefix);
|
|
|
|
rep = uip_ds6_addr_lookup(&ipaddr);
|
|
|
|
if(rep != NULL) {
|
2011-07-13 08:42:59 +00:00
|
|
|
PRINTF("RPL: removing global IP address ");
|
|
|
|
PRINT6ADDR(&ipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_ds6_addr_rm(rep);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 09:01:20 +00:00
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
if(new_prefix != NULL) {
|
|
|
|
set_ip_from_prefix(&ipaddr, new_prefix);
|
2011-07-13 08:42:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
int
|
2011-11-21 13:59:31 +00:00
|
|
|
rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len)
|
2010-06-03 12:55:09 +00:00
|
|
|
{
|
2013-02-05 10:19:41 +00:00
|
|
|
rpl_prefix_t last_prefix;
|
|
|
|
uint8_t last_len = dag->prefix_info.length;
|
2014-05-30 09:01:20 +00:00
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
if(len > 128) {
|
|
|
|
return 0;
|
2010-05-25 19:19:43 +00:00
|
|
|
}
|
2013-02-05 10:19:41 +00:00
|
|
|
if(dag->prefix_info.length != 0) {
|
|
|
|
memcpy(&last_prefix, &dag->prefix_info, sizeof(rpl_prefix_t));
|
|
|
|
}
|
2011-11-21 13:59:31 +00:00
|
|
|
memset(&dag->prefix_info.prefix, 0, sizeof(dag->prefix_info.prefix));
|
|
|
|
memcpy(&dag->prefix_info.prefix, prefix, (len + 7) / 8);
|
|
|
|
dag->prefix_info.length = len;
|
|
|
|
dag->prefix_info.flags = UIP_ND6_RA_FLAG_AUTONOMOUS;
|
|
|
|
PRINTF("RPL: Prefix set - will announce this in DIOs\n");
|
2017-12-11 16:19:02 +00:00
|
|
|
if(dag->rank != ROOT_RANK(dag->instance)) {
|
|
|
|
/* Autoconfigure an address if this node does not already have an address
|
|
|
|
with this prefix. Otherwise, update the prefix */
|
|
|
|
if(last_len == 0) {
|
|
|
|
PRINTF("rpl_set_prefix - prefix NULL\n");
|
|
|
|
check_prefix(NULL, &dag->prefix_info);
|
|
|
|
} else {
|
|
|
|
PRINTF("rpl_set_prefix - prefix NON-NULL\n");
|
|
|
|
check_prefix(&last_prefix, &dag->prefix_info);
|
|
|
|
}
|
2013-02-05 10:19:41 +00:00
|
|
|
}
|
2011-11-21 13:59:31 +00:00
|
|
|
return 1;
|
2010-05-25 19:19:43 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-25 19:19:43 +00:00
|
|
|
int
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->def_route != NULL) {
|
2012-11-26 18:53:38 +00:00
|
|
|
PRINTF("RPL: Removing default route through ");
|
|
|
|
PRINT6ADDR(&instance->def_route->ipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_ds6_defrt_rm(instance->def_route);
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->def_route = NULL;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(from != NULL) {
|
|
|
|
PRINTF("RPL: Adding default route through ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF("\n");
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->def_route = uip_ds6_defrt_add(from,
|
2014-09-10 14:56:53 +00:00
|
|
|
RPL_DEFAULT_ROUTE_INFINITE_LIFETIME ? 0 : RPL_LIFETIME(instance, instance->default_lifetime));
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->def_route == NULL) {
|
2010-04-30 13:43:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *
|
|
|
|
rpl_alloc_instance(uint8_t instance_id)
|
|
|
|
{
|
|
|
|
rpl_instance_t *instance, *end;
|
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
|
|
|
|
instance < end; ++instance) {
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->used == 0) {
|
|
|
|
memset(instance, 0, sizeof(*instance));
|
|
|
|
instance->instance_id = instance_id;
|
|
|
|
instance->def_route = NULL;
|
|
|
|
instance->used = 1;
|
2015-05-06 09:35:42 +00:00
|
|
|
#if RPL_WITH_PROBING
|
|
|
|
rpl_schedule_probing(instance);
|
|
|
|
#endif /* RPL_WITH_PROBING */
|
2011-07-11 13:50:51 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_dag_t *
|
2012-04-17 21:12:47 +00:00
|
|
|
rpl_alloc_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_dag_t *dag, *end;
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
|
|
|
|
instance = rpl_get_instance(instance_id);
|
2012-04-17 21:12:47 +00:00
|
|
|
if(instance == NULL) {
|
2011-07-11 13:50:51 +00:00
|
|
|
instance = rpl_alloc_instance(instance_id);
|
2012-04-17 21:12:47 +00:00
|
|
|
if(instance == NULL) {
|
2011-07-11 13:50:51 +00:00
|
|
|
RPL_STAT(rpl_stats.mem_overflows++);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-06-14 12:44:37 +00:00
|
|
|
|
2012-02-29 20:59:50 +00:00
|
|
|
for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) {
|
2011-07-11 13:50:51 +00:00
|
|
|
if(!dag->used) {
|
2010-06-14 12:44:37 +00:00
|
|
|
memset(dag, 0, sizeof(*dag));
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->used = 1;
|
2017-06-10 12:35:39 +00:00
|
|
|
dag->rank = RPL_INFINITE_RANK;
|
|
|
|
dag->min_rank = RPL_INFINITE_RANK;
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->instance = instance;
|
2010-06-14 12:44:37 +00:00
|
|
|
return dag;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-21 22:18:07 +00:00
|
|
|
|
|
|
|
RPL_STAT(rpl_stats.mem_overflows++);
|
2010-04-30 13:43:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
void
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_set_default_instance(rpl_instance_t *instance)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
default_instance = instance;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-03-24 13:41:19 +00:00
|
|
|
rpl_instance_t *
|
|
|
|
rpl_get_default_instance(void)
|
|
|
|
{
|
|
|
|
return default_instance;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
void
|
|
|
|
rpl_free_instance(rpl_instance_t *instance)
|
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
|
|
|
rpl_dag_t *end;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("RPL: Leaving the instance %u\n", instance->instance_id);
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2012-02-29 20:59:50 +00:00
|
|
|
/* Remove any DAG inside this instance */
|
|
|
|
for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) {
|
2011-07-11 13:50:51 +00:00
|
|
|
if(dag->used) {
|
2012-04-17 21:12:47 +00:00
|
|
|
rpl_free_dag(dag);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl_set_default_route(instance, NULL);
|
|
|
|
|
2015-05-06 09:35:42 +00:00
|
|
|
#if RPL_WITH_PROBING
|
|
|
|
ctimer_stop(&instance->probing_timer);
|
|
|
|
#endif /* RPL_WITH_PROBING */
|
2011-07-11 13:50:51 +00:00
|
|
|
ctimer_stop(&instance->dio_timer);
|
|
|
|
ctimer_stop(&instance->dao_timer);
|
2014-11-28 22:17:16 +00:00
|
|
|
ctimer_stop(&instance->dao_lifetime_timer);
|
2011-07-11 13:50:51 +00:00
|
|
|
|
|
|
|
if(default_instance == instance) {
|
|
|
|
default_instance = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance->used = 0;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
void
|
2012-04-17 21:12:47 +00:00
|
|
|
rpl_free_dag(rpl_dag_t *dag)
|
2011-07-11 13:50:51 +00:00
|
|
|
{
|
|
|
|
if(dag->joined) {
|
|
|
|
PRINTF("RPL: Leaving the DAG ");
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
dag->joined = 0;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
/* Remove routes installed by DAOs. */
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(dag->instance)) {
|
|
|
|
rpl_remove_routes(dag);
|
|
|
|
}
|
2017-12-07 13:52:37 +00:00
|
|
|
/* Stop the DAO retransmit timer */
|
|
|
|
#if RPL_WITH_DAO_ACK
|
|
|
|
ctimer_stop(&dag->instance->dao_retransmit_timer);
|
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
2010-06-03 15:20:56 +00:00
|
|
|
|
2011-07-13 08:42:59 +00:00
|
|
|
/* Remove autoconfigured address */
|
|
|
|
if((dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) {
|
2011-11-21 13:59:31 +00:00
|
|
|
check_prefix(&dag->prefix_info, NULL);
|
2011-07-13 08:42:59 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
remove_parents(dag, 0);
|
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
dag->used = 0;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *
|
2010-06-02 16:54:59 +00:00
|
|
|
rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_parent_t *p = NULL;
|
|
|
|
/* Is the parent known by ds6? Drop this request if not.
|
|
|
|
* Typically, the parent is added upon receiving a DIO. */
|
2013-11-16 13:42:57 +00:00
|
|
|
const uip_lladdr_t *lladdr = uip_ds6_nbr_lladdr_from_ipaddr(addr);
|
2013-07-03 17:53:51 +00:00
|
|
|
|
2013-11-20 13:07:29 +00:00
|
|
|
PRINTF("RPL: rpl_add_parent lladdr %p ", lladdr);
|
|
|
|
PRINT6ADDR(addr);
|
|
|
|
PRINTF("\n");
|
2013-07-03 17:53:51 +00:00
|
|
|
if(lladdr != NULL) {
|
2015-09-20 19:02:30 +00:00
|
|
|
/* Add parent in rpl_parents - again this is due to DIO */
|
|
|
|
p = nbr_table_add_lladdr(rpl_parents, (linkaddr_t *)lladdr,
|
|
|
|
NBR_TABLE_REASON_RPL_DIO, dio);
|
2013-11-20 13:08:20 +00:00
|
|
|
if(p == NULL) {
|
|
|
|
PRINTF("RPL: rpl_add_parent p NULL\n");
|
|
|
|
} else {
|
|
|
|
p->dag = dag;
|
|
|
|
p->rank = dio->rank;
|
|
|
|
p->dtsn = dio->dtsn;
|
2015-11-29 20:44:39 +00:00
|
|
|
#if RPL_WITH_MC
|
2013-11-20 13:08:20 +00:00
|
|
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
2015-11-29 20:44:39 +00:00
|
|
|
#endif /* RPL_WITH_MC */
|
2013-11-20 13:08:20 +00:00
|
|
|
}
|
2013-07-03 17:53:51 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 21:58:54 +00:00
|
|
|
return p;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-07-03 17:53:51 +00:00
|
|
|
static rpl_parent_t *
|
|
|
|
find_parent_any_dag_any_instance(uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
uip_ds6_nbr_t *ds6_nbr = uip_ds6_nbr_lookup(addr);
|
2013-11-16 13:42:57 +00:00
|
|
|
const uip_lladdr_t *lladdr = uip_ds6_nbr_get_ll(ds6_nbr);
|
2013-12-12 22:58:52 +00:00
|
|
|
return nbr_table_get_from_lladdr(rpl_parents, (linkaddr_t *)lladdr);
|
2013-07-03 17:53:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *
|
|
|
|
rpl_find_parent(rpl_dag_t *dag, uip_ipaddr_t *addr)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_parent_t *p = find_parent_any_dag_any_instance(addr);
|
|
|
|
if(p != NULL && p->dag == dag) {
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-01-04 10:22:11 +00:00
|
|
|
static rpl_dag_t *
|
|
|
|
find_parent_dag(rpl_instance_t *instance, uip_ipaddr_t *addr)
|
2011-07-11 13:50:51 +00:00
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_parent_t *p = find_parent_any_dag_any_instance(addr);
|
|
|
|
if(p != NULL) {
|
|
|
|
return p->dag;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_find_parent_any_dag(rpl_instance_t *instance, uip_ipaddr_t *addr)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_parent_t *p = find_parent_any_dag_any_instance(addr);
|
|
|
|
if(p && p->dag && p->dag->instance == instance) {
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_dag_t *
|
2012-04-17 21:12:47 +00:00
|
|
|
rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
|
2011-07-11 13:50:51 +00:00
|
|
|
{
|
|
|
|
rpl_parent_t *last_parent;
|
|
|
|
rpl_dag_t *dag, *end, *best_dag;
|
|
|
|
rpl_rank_t old_rank;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
old_rank = instance->current_dag->rank;
|
|
|
|
last_parent = instance->current_dag->preferred_parent;
|
|
|
|
|
2017-12-11 16:19:26 +00:00
|
|
|
if(instance->current_dag->rank != ROOT_RANK(instance)) {
|
|
|
|
rpl_select_parent(p->dag);
|
|
|
|
}
|
|
|
|
|
|
|
|
best_dag = NULL;
|
|
|
|
for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) {
|
|
|
|
if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != RPL_INFINITE_RANK) {
|
|
|
|
if(best_dag == NULL) {
|
|
|
|
best_dag = dag;
|
|
|
|
} else {
|
|
|
|
best_dag = instance->of->best_dag(best_dag, dag);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 12:44:37 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(best_dag == NULL) {
|
2011-11-16 08:49:22 +00:00
|
|
|
/* No parent found: the calling function handle this problem. */
|
2011-04-07 15:44:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->current_dag != best_dag) {
|
|
|
|
/* Remove routes installed by DAOs. */
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(instance)) {
|
|
|
|
rpl_remove_routes(instance->current_dag);
|
|
|
|
}
|
2011-05-03 15:50:24 +00:00
|
|
|
|
2012-02-29 20:59:50 +00:00
|
|
|
PRINTF("RPL: New preferred DAG: ");
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINT6ADDR(&best_dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2011-07-13 08:42:59 +00:00
|
|
|
if(best_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
|
2011-11-21 13:59:31 +00:00
|
|
|
check_prefix(&instance->current_dag->prefix_info, &best_dag->prefix_info);
|
2011-07-13 08:42:59 +00:00
|
|
|
} else if(instance->current_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
|
2011-11-21 13:59:31 +00:00
|
|
|
check_prefix(&instance->current_dag->prefix_info, NULL);
|
2011-07-13 08:42:59 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
best_dag->joined = 1;
|
|
|
|
instance->current_dag->joined = 0;
|
|
|
|
instance->current_dag = best_dag;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance->of->update_metric_container(instance);
|
|
|
|
/* Update the DAG rank. */
|
2015-11-29 20:44:39 +00:00
|
|
|
best_dag->rank = rpl_rank_via_parent(best_dag->preferred_parent);
|
2013-07-26 10:38:25 +00:00
|
|
|
if(last_parent == NULL || best_dag->rank < best_dag->min_rank) {
|
2015-11-29 20:50:16 +00:00
|
|
|
/* This is a slight departure from RFC6550: if we had no preferred parent before,
|
|
|
|
* reset min_rank. This helps recovering from temporary bad link conditions. */
|
2011-07-11 13:50:51 +00:00
|
|
|
best_dag->min_rank = best_dag->rank;
|
2015-11-29 20:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!acceptable_rank(best_dag, best_dag->rank)) {
|
2011-11-21 14:50:19 +00:00
|
|
|
PRINTF("RPL: New rank unacceptable!\n");
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_set_preferred_parent(instance->current_dag, NULL);
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(instance) && last_parent != NULL) {
|
2011-07-11 13:50:51 +00:00
|
|
|
/* Send a No-Path DAO to the removed preferred parent. */
|
2012-02-29 20:59:50 +00:00
|
|
|
dao_output(last_parent, RPL_ZERO_LIFETIME);
|
2011-04-06 18:14:30 +00:00
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
return NULL;
|
2010-06-03 15:20:56 +00:00
|
|
|
}
|
2010-06-14 12:44:37 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(best_dag->preferred_parent != last_parent) {
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_set_default_route(instance, rpl_parent_get_ipaddr(best_dag->preferred_parent));
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("RPL: Changed preferred parent, rank changed from %u to %u\n",
|
2018-04-07 13:19:58 +00:00
|
|
|
(unsigned)old_rank, best_dag->rank);
|
2011-07-11 13:50:51 +00:00
|
|
|
RPL_STAT(rpl_stats.parent_switch++);
|
2016-11-25 15:30:08 +00:00
|
|
|
if(RPL_IS_STORING(instance)) {
|
|
|
|
if(last_parent != NULL) {
|
|
|
|
/* Send a No-Path DAO to the removed preferred parent. */
|
|
|
|
dao_output(last_parent, RPL_ZERO_LIFETIME);
|
|
|
|
}
|
|
|
|
/* Trigger DAO transmission from immediate children.
|
|
|
|
* Only for storing mode, see RFC6550 section 9.6. */
|
|
|
|
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2016-02-01 17:02:33 +00:00
|
|
|
/* The DAO parent set changed - schedule a DAO transmission. */
|
|
|
|
rpl_schedule_dao(instance);
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_reset_dio_timer(instance);
|
2015-05-06 09:34:52 +00:00
|
|
|
#if DEBUG
|
|
|
|
rpl_print_neighbor_list();
|
|
|
|
#endif
|
2011-07-11 13:50:51 +00:00
|
|
|
} else if(best_dag->rank != old_rank) {
|
|
|
|
PRINTF("RPL: Preferred parent update, rank changed from %u to %u\n",
|
2018-04-07 13:19:58 +00:00
|
|
|
(unsigned)old_rank, best_dag->rank);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
return best_dag;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-11-20 13:09:11 +00:00
|
|
|
static rpl_parent_t *
|
2016-04-22 22:13:59 +00:00
|
|
|
best_parent(rpl_dag_t *dag, int fresh_only)
|
2011-07-11 13:50:51 +00:00
|
|
|
{
|
2015-11-29 20:44:39 +00:00
|
|
|
rpl_parent_t *p;
|
|
|
|
rpl_of_t *of;
|
|
|
|
rpl_parent_t *best = NULL;
|
2010-06-28 14:51:23 +00:00
|
|
|
|
2015-11-29 20:44:39 +00:00
|
|
|
if(dag == NULL || dag->instance == NULL || dag->instance->of == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-03 17:53:51 +00:00
|
|
|
|
2015-11-29 20:44:39 +00:00
|
|
|
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 */
|
2017-06-10 12:35:39 +00:00
|
|
|
if(p->dag != dag || p->rank == RPL_INFINITE_RANK || p->rank < ROOT_RANK(dag->instance)) {
|
2016-03-16 12:12:20 +00:00
|
|
|
if(p->rank < ROOT_RANK(dag->instance)) {
|
|
|
|
PRINTF("RPL: Parent has invalid rank\n");
|
|
|
|
}
|
2015-11-29 20:44:39 +00:00
|
|
|
continue;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2015-11-29 20:44:39 +00:00
|
|
|
|
2016-04-22 22:13:59 +00:00
|
|
|
if(fresh_only && !rpl_parent_is_fresh(p)) {
|
|
|
|
/* Filter out non-fresh parents if fresh_only is set */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-16 12:44:15 +00:00
|
|
|
#if UIP_ND6_SEND_NS
|
2015-11-29 20:44:39 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 12:44:15 +00:00
|
|
|
#endif /* UIP_ND6_SEND_NS */
|
2015-11-29 20:44:39 +00:00
|
|
|
|
|
|
|
/* Now we have an acceptable parent, check if it is the new best */
|
|
|
|
best = of->best_parent(best, p);
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 13:09:11 +00:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
rpl_parent_t *
|
|
|
|
rpl_select_parent(rpl_dag_t *dag)
|
|
|
|
{
|
2016-04-22 22:13:59 +00:00
|
|
|
/* Look for best parent (regardless of freshness) */
|
|
|
|
rpl_parent_t *best = best_parent(dag, 0);
|
2013-11-20 13:09:11 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(best != NULL) {
|
2016-06-03 10:23:56 +00:00
|
|
|
#if RPL_WITH_PROBING
|
2015-11-29 20:44:39 +00:00
|
|
|
if(rpl_parent_is_fresh(best)) {
|
|
|
|
rpl_set_preferred_parent(dag, best);
|
2018-05-09 21:39:14 +00:00
|
|
|
/* Unschedule any already scheduled urgent probing */
|
|
|
|
dag->instance->urgent_probing_target = NULL;
|
2015-11-29 20:46:41 +00:00
|
|
|
} else {
|
2016-04-22 22:13:59 +00:00
|
|
|
/* The best is not fresh. Look for the best fresh now. */
|
|
|
|
rpl_parent_t *best_fresh = best_parent(dag, 1);
|
|
|
|
if(best_fresh == NULL) {
|
|
|
|
/* No fresh parent around, use best (non-fresh) */
|
|
|
|
rpl_set_preferred_parent(dag, best);
|
|
|
|
} else {
|
|
|
|
/* Use best fresh */
|
|
|
|
rpl_set_preferred_parent(dag, best_fresh);
|
|
|
|
}
|
2016-06-03 10:23:56 +00:00
|
|
|
/* Probe the best parent shortly in order to get a fresh estimate */
|
2015-11-29 20:46:41 +00:00
|
|
|
dag->instance->urgent_probing_target = best;
|
2018-05-09 21:39:14 +00:00
|
|
|
rpl_schedule_probing_now(dag->instance);
|
2016-09-05 13:49:41 +00:00
|
|
|
}
|
2016-06-03 10:23:56 +00:00
|
|
|
#else /* RPL_WITH_PROBING */
|
2016-09-05 15:24:55 +00:00
|
|
|
rpl_set_preferred_parent(dag, best);
|
|
|
|
dag->rank = rpl_rank_via_parent(dag->preferred_parent);
|
2016-02-04 21:44:24 +00:00
|
|
|
#endif /* RPL_WITH_PROBING */
|
2014-01-11 08:00:20 +00:00
|
|
|
} else {
|
2016-06-03 10:23:56 +00:00
|
|
|
rpl_set_preferred_parent(dag, NULL);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2011-11-22 13:18:32 +00:00
|
|
|
|
2016-06-03 10:23:56 +00:00
|
|
|
dag->rank = rpl_rank_via_parent(dag->preferred_parent);
|
|
|
|
return dag->preferred_parent;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
void
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_remove_parent(rpl_parent_t *parent)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2010-05-25 21:58:54 +00:00
|
|
|
PRINTF("RPL: Removing parent ");
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(parent));
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("\n");
|
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_nullify_parent(parent);
|
|
|
|
|
|
|
|
nbr_table_remove(rpl_parents, parent);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
void
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_nullify_parent(rpl_parent_t *parent)
|
2011-07-11 13:50:51 +00:00
|
|
|
{
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_dag_t *dag = parent->dag;
|
2013-07-23 18:01:10 +00:00
|
|
|
/* This function can be called when the preferred parent is NULL, so we
|
|
|
|
need to handle this condition in order to trigger uip_ds6_defrt_rm. */
|
2013-07-23 13:35:47 +00:00
|
|
|
if(parent == dag->preferred_parent || dag->preferred_parent == NULL) {
|
2017-06-10 12:35:39 +00:00
|
|
|
dag->rank = RPL_INFINITE_RANK;
|
2011-07-11 13:50:51 +00:00
|
|
|
if(dag->joined) {
|
|
|
|
if(dag->instance->def_route != NULL) {
|
2013-07-03 17:53:51 +00:00
|
|
|
PRINTF("RPL: Removing default route ");
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(parent));
|
2013-07-03 17:53:51 +00:00
|
|
|
PRINTF("\n");
|
|
|
|
uip_ds6_defrt_rm(dag->instance->def_route);
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->instance->def_route = NULL;
|
|
|
|
}
|
2016-02-01 17:02:33 +00:00
|
|
|
/* Send No-Path DAO only when nullifying preferred parent */
|
2014-01-15 15:22:39 +00:00
|
|
|
if(parent == dag->preferred_parent) {
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(dag->instance)) {
|
|
|
|
dao_output(parent, RPL_ZERO_LIFETIME);
|
|
|
|
}
|
2014-01-15 15:22:39 +00:00
|
|
|
rpl_set_preferred_parent(dag, NULL);
|
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2010-10-27 12:20:35 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("RPL: Nullifying parent ");
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(parent));
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("\n");
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
void
|
|
|
|
rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent)
|
|
|
|
{
|
|
|
|
if(parent == dag_src->preferred_parent) {
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_set_preferred_parent(dag_src, NULL);
|
2017-06-10 12:35:39 +00:00
|
|
|
dag_src->rank = RPL_INFINITE_RANK;
|
2011-11-22 13:18:32 +00:00
|
|
|
if(dag_src->joined && dag_src->instance->def_route != NULL) {
|
2012-11-26 18:53:38 +00:00
|
|
|
PRINTF("RPL: Removing default route ");
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(parent));
|
2012-11-26 18:53:38 +00:00
|
|
|
PRINTF("\n");
|
2012-11-27 22:01:10 +00:00
|
|
|
PRINTF("rpl_move_parent\n");
|
2012-11-26 18:53:38 +00:00
|
|
|
uip_ds6_defrt_rm(dag_src->instance->def_route);
|
2011-07-11 13:50:51 +00:00
|
|
|
dag_src->instance->def_route = NULL;
|
|
|
|
}
|
|
|
|
} else if(dag_src->joined) {
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(dag_src->instance)) {
|
|
|
|
/* Remove uIPv6 routes that have this parent as the next hop. */
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_remove_routes_by_nexthop(rpl_parent_get_ipaddr(parent), dag_src);
|
2016-02-01 17:02:33 +00:00
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRINTF("RPL: Moving parent ");
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(parent));
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("\n");
|
|
|
|
|
|
|
|
parent->dag = dag_dst;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-03-26 19:12:52 +00:00
|
|
|
int
|
2017-12-13 20:55:22 +00:00
|
|
|
rpl_has_joined(void)
|
|
|
|
{
|
|
|
|
return rpl_get_any_dag() != NULL;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
2016-03-26 19:12:52 +00:00
|
|
|
rpl_has_downward_route(void)
|
|
|
|
{
|
|
|
|
int i;
|
2017-12-13 20:00:33 +00:00
|
|
|
if(rpl_dag_root_is_root()) {
|
|
|
|
return 1; /* We are the root, and know the route to ourself */
|
|
|
|
}
|
2016-03-26 19:12:52 +00:00
|
|
|
for(i = 0; i < RPL_MAX_INSTANCES; ++i) {
|
|
|
|
if(instance_table[i].used && instance_table[i].has_downward_route) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_dag_t *
|
2016-02-01 17:02:33 +00:00
|
|
|
rpl_get_dag(const uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for(i = 0; i < RPL_MAX_INSTANCES; ++i) {
|
|
|
|
if(instance_table[i].used) {
|
|
|
|
for(j = 0; j < RPL_MAX_DAG_PER_INSTANCE; ++j) {
|
|
|
|
if(instance_table[i].dag_table[j].joined
|
|
|
|
&& uip_ipaddr_prefixcmp(&instance_table[i].dag_table[j].dag_id, addr,
|
|
|
|
instance_table[i].dag_table[j].prefix_info.length)) {
|
|
|
|
return &instance_table[i].dag_table[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
rpl_dag_t *
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_get_any_dag(void)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
|
|
|
int i;
|
2010-12-17 15:24:25 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
for(i = 0; i < RPL_MAX_INSTANCES; ++i) {
|
|
|
|
if(instance_table[i].used && instance_table[i].current_dag->joined) {
|
|
|
|
return instance_table[i].current_dag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *
|
|
|
|
rpl_get_instance(uint8_t instance_id)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < RPL_MAX_INSTANCES; ++i) {
|
|
|
|
if(instance_table[i].used && instance_table[i].instance_id == instance_id) {
|
|
|
|
return &instance_table[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_of_t *
|
|
|
|
rpl_find_of(rpl_ocp_t ocp)
|
|
|
|
{
|
2011-02-19 08:25:29 +00:00
|
|
|
unsigned int i;
|
2010-05-29 22:23:21 +00:00
|
|
|
|
2011-01-04 20:43:28 +00:00
|
|
|
for(i = 0;
|
2011-07-11 13:50:51 +00:00
|
|
|
i < sizeof(objective_functions) / sizeof(objective_functions[0]);
|
2011-01-04 20:43:28 +00:00
|
|
|
i++) {
|
|
|
|
if(objective_functions[i]->ocp == ocp) {
|
|
|
|
return objective_functions[i];
|
2010-05-29 22:23:21 +00:00
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2010-05-29 22:23:21 +00:00
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
void
|
|
|
|
rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *instance;
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_dag_t *dag;
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_of_t *of;
|
|
|
|
|
2016-02-01 17:02:33 +00:00
|
|
|
if((!RPL_WITH_NON_STORING && dio->mop == RPL_MOP_NON_STORING)
|
|
|
|
|| (!RPL_WITH_STORING && (dio->mop == RPL_MOP_STORING_NO_MULTICAST
|
|
|
|
|| dio->mop == RPL_MOP_STORING_MULTICAST))) {
|
|
|
|
PRINTF("RPL: DIO advertising a non-supported MOP %u\n", dio->mop);
|
2016-07-05 10:13:46 +00:00
|
|
|
return;
|
2016-02-01 17:02:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 16:24:03 +00:00
|
|
|
/* Determine the objective function by using the
|
|
|
|
objective code point of the DIO. */
|
|
|
|
of = rpl_find_of(dio->ocp);
|
|
|
|
if(of == NULL) {
|
|
|
|
PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF: %u\n",
|
|
|
|
dio->instance_id, dio->ocp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-17 21:12:47 +00:00
|
|
|
dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id);
|
2010-04-30 13:43:53 +00:00
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL: Failed to allocate a DAG object!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
instance = dag->instance;
|
|
|
|
|
2010-06-02 16:54:59 +00:00
|
|
|
p = rpl_add_parent(dag, dio, from);
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("RPL: Adding ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF(" as a parent: ");
|
2010-05-25 21:58:54 +00:00
|
|
|
if(p == NULL) {
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("failed\n");
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->used = 0;
|
2010-04-30 13:43:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
p->dtsn = dio->dtsn;
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("succeeded\n");
|
|
|
|
|
2010-06-03 18:37:47 +00:00
|
|
|
/* Autoconfigure an address if this node does not already have an address
|
|
|
|
with this prefix. */
|
2012-04-21 22:18:07 +00:00
|
|
|
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
|
2011-11-21 13:59:31 +00:00
|
|
|
check_prefix(NULL, &dio->prefix_info);
|
2010-06-03 18:37:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 15:20:56 +00:00
|
|
|
dag->joined = 1;
|
2010-12-13 10:54:25 +00:00
|
|
|
dag->preference = dio->preference;
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->grounded = dio->grounded;
|
2010-06-02 11:59:51 +00:00
|
|
|
dag->version = dio->version;
|
2010-06-06 21:42:50 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->of = of;
|
|
|
|
instance->mop = dio->mop;
|
2015-11-29 20:44:39 +00:00
|
|
|
instance->mc.type = dio->mc.type;
|
|
|
|
instance->mc.flags = dio->mc.flags;
|
|
|
|
instance->mc.aggr = dio->mc.aggr;
|
|
|
|
instance->mc.prec = dio->mc.prec;
|
2012-04-21 22:18:07 +00:00
|
|
|
instance->current_dag = dag;
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dtsn_out = RPL_LOLLIPOP_INIT;
|
|
|
|
|
|
|
|
instance->max_rankinc = dio->dag_max_rankinc;
|
|
|
|
instance->min_hoprankinc = dio->dag_min_hoprankinc;
|
|
|
|
instance->dio_intdoubl = dio->dag_intdoubl;
|
|
|
|
instance->dio_intmin = dio->dag_intmin;
|
2012-01-04 10:22:11 +00:00
|
|
|
instance->dio_intcurrent = instance->dio_intmin + instance->dio_intdoubl;
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_redundancy = dio->dag_redund;
|
|
|
|
instance->default_lifetime = dio->default_lifetime;
|
|
|
|
instance->lifetime_unit = dio->lifetime_unit;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));
|
|
|
|
|
2012-04-21 22:18:07 +00:00
|
|
|
/* Copy prefix information from the DIO into the DAG object. */
|
2010-06-01 22:30:02 +00:00
|
|
|
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
|
2010-05-25 19:19:43 +00:00
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_set_preferred_parent(dag, p);
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->of->update_metric_container(instance);
|
2015-11-29 20:44:39 +00:00
|
|
|
dag->rank = rpl_rank_via_parent(p);
|
2012-04-21 22:18:07 +00:00
|
|
|
/* So far this is the lowest rank we are aware of. */
|
|
|
|
dag->min_rank = dag->rank;
|
2011-02-22 01:01:15 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(default_instance == NULL) {
|
|
|
|
default_instance = instance;
|
|
|
|
}
|
|
|
|
|
2010-05-04 22:55:32 +00:00
|
|
|
PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
|
2010-04-30 13:43:53 +00:00
|
|
|
dio->instance_id, dag->rank);
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
|
2011-02-22 15:15:16 +00:00
|
|
|
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_reset_dio_timer(instance);
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_set_default_route(instance, from);
|
|
|
|
|
|
|
|
if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES) {
|
2015-09-20 19:02:30 +00:00
|
|
|
rpl_schedule_dao(instance);
|
2011-07-11 13:50:51 +00:00
|
|
|
} else {
|
|
|
|
PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
|
|
|
|
}
|
2015-11-29 20:44:39 +00:00
|
|
|
|
|
|
|
instance->of->reset(dag);
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 15:46:17 +00:00
|
|
|
#if RPL_MAX_DAG_PER_INSTANCE > 1
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-30 18:21:18 +00:00
|
|
|
rpl_dag_t *
|
2012-04-17 21:12:47 +00:00
|
|
|
rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
|
2011-07-11 13:50:51 +00:00
|
|
|
{
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
rpl_dag_t *dag, *previous_dag;
|
|
|
|
rpl_parent_t *p;
|
|
|
|
rpl_of_t *of;
|
2011-02-22 15:15:16 +00:00
|
|
|
|
2012-04-17 21:12:47 +00:00
|
|
|
dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id);
|
2011-07-11 13:50:51 +00:00
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL: Failed to allocate a DAG object!\n");
|
2015-11-30 18:21:18 +00:00
|
|
|
return NULL;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
2010-12-13 10:59:37 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
instance = dag->instance;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2012-01-04 10:22:11 +00:00
|
|
|
previous_dag = find_parent_dag(instance, from);
|
2011-07-11 13:50:51 +00:00
|
|
|
if(previous_dag == NULL) {
|
|
|
|
PRINTF("RPL: Adding ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF(" as a parent: ");
|
2011-11-21 13:59:31 +00:00
|
|
|
p = rpl_add_parent(dag, dio, from);
|
2011-07-11 13:50:51 +00:00
|
|
|
if(p == NULL) {
|
|
|
|
PRINTF("failed\n");
|
|
|
|
dag->used = 0;
|
2015-11-30 18:21:18 +00:00
|
|
|
return NULL;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
PRINTF("succeeded\n");
|
2010-04-30 13:43:53 +00:00
|
|
|
} else {
|
2011-07-11 13:50:51 +00:00
|
|
|
p = rpl_find_parent(previous_dag, from);
|
2011-11-21 13:59:31 +00:00
|
|
|
if(p != NULL) {
|
|
|
|
rpl_move_parent(previous_dag, dag, p);
|
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2015-09-30 13:23:34 +00:00
|
|
|
p->rank = dio->rank;
|
2011-07-11 13:50:51 +00:00
|
|
|
|
|
|
|
/* Determine the objective function by using the
|
|
|
|
objective code point of the DIO. */
|
|
|
|
of = rpl_find_of(dio->ocp);
|
2011-11-21 13:59:31 +00:00
|
|
|
if(of != instance->of ||
|
|
|
|
instance->mop != dio->mop ||
|
|
|
|
instance->max_rankinc != dio->dag_max_rankinc ||
|
|
|
|
instance->min_hoprankinc != dio->dag_min_hoprankinc ||
|
|
|
|
instance->dio_intdoubl != dio->dag_intdoubl ||
|
|
|
|
instance->dio_intmin != dio->dag_intmin ||
|
|
|
|
instance->dio_redundancy != dio->dag_redund ||
|
|
|
|
instance->default_lifetime != dio->default_lifetime ||
|
|
|
|
instance->lifetime_unit != dio->lifetime_unit) {
|
2014-03-27 15:17:47 +00:00
|
|
|
PRINTF("RPL: DIO for DAG instance %u incompatible with previous DIO\n",
|
2011-11-21 13:59:31 +00:00
|
|
|
dio->instance_id);
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_remove_parent(p);
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->used = 0;
|
2015-11-30 18:21:18 +00:00
|
|
|
return NULL;
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dag->used = 1;
|
|
|
|
dag->grounded = dio->grounded;
|
|
|
|
dag->preference = dio->preference;
|
|
|
|
dag->version = dio->version;
|
|
|
|
|
|
|
|
memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));
|
|
|
|
|
|
|
|
/* copy prefix information into the dag */
|
|
|
|
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
|
|
|
|
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_set_preferred_parent(dag, p);
|
2015-11-29 20:44:39 +00:00
|
|
|
dag->rank = rpl_rank_via_parent(p);
|
2011-07-11 13:50:51 +00:00
|
|
|
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 ",
|
|
|
|
dio->instance_id, dag->rank);
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
rpl_process_parent_event(instance, p);
|
2011-07-11 13:50:51 +00:00
|
|
|
p->dtsn = dio->dtsn;
|
2015-11-30 18:21:18 +00:00
|
|
|
|
|
|
|
return dag;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2014-12-03 15:46:17 +00:00
|
|
|
#endif /* RPL_MAX_DAG_PER_INSTANCE > 1 */
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
static void
|
|
|
|
global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
|
|
|
|
{
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-06-28 14:51:23 +00:00
|
|
|
remove_parents(dag, 0);
|
2010-06-02 11:59:51 +00:00
|
|
|
dag->version = dio->version;
|
2014-10-24 13:13:27 +00:00
|
|
|
|
|
|
|
/* copy parts of the configuration so that it propagates in the network */
|
|
|
|
dag->instance->dio_intdoubl = dio->dag_intdoubl;
|
|
|
|
dag->instance->dio_intmin = dio->dag_intmin;
|
|
|
|
dag->instance->dio_redundancy = dio->dag_redund;
|
|
|
|
dag->instance->default_lifetime = dio->default_lifetime;
|
|
|
|
dag->instance->lifetime_unit = dio->lifetime_unit;
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
dag->instance->of->reset(dag);
|
2017-06-10 12:35:39 +00:00
|
|
|
dag->min_rank = RPL_INFINITE_RANK;
|
2011-07-11 13:50:51 +00:00
|
|
|
RPL_LOLLIPOP_INCREMENT(dag->instance->dtsn_out);
|
2011-11-22 13:18:32 +00:00
|
|
|
|
2011-11-21 13:59:31 +00:00
|
|
|
p = rpl_add_parent(dag, dio, from);
|
|
|
|
if(p == NULL) {
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("RPL: Failed to add a parent during the global repair\n");
|
2017-06-10 12:35:39 +00:00
|
|
|
dag->rank = RPL_INFINITE_RANK;
|
2010-04-30 13:43:53 +00:00
|
|
|
} else {
|
2015-11-29 20:44:39 +00:00
|
|
|
dag->rank = rpl_rank_via_parent(p);
|
2012-04-21 22:18:07 +00:00
|
|
|
dag->min_rank = dag->rank;
|
2013-08-11 21:42:51 +00:00
|
|
|
PRINTF("RPL: rpl_process_parent_event global repair\n");
|
2011-11-21 13:59:31 +00:00
|
|
|
rpl_process_parent_event(dag->instance, p);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2011-11-22 13:18:32 +00:00
|
|
|
|
2010-06-03 12:55:09 +00:00
|
|
|
PRINTF("RPL: Participating in a global repair (version=%u, rank=%hu)\n",
|
2010-06-02 11:59:51 +00:00
|
|
|
dag->version, dag->rank);
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-10-27 00:46:40 +00:00
|
|
|
RPL_STAT(rpl_stats.global_repairs++);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2015-09-22 19:01:55 +00:00
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
void
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_local_repair(rpl_instance_t *instance)
|
2010-10-27 00:46:40 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
int i;
|
2010-10-27 00:46:40 +00:00
|
|
|
|
2013-08-11 22:19:12 +00:00
|
|
|
if(instance == NULL) {
|
|
|
|
PRINTF("RPL: local repair requested for instance NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("RPL: Starting a local instance repair\n");
|
2012-02-29 20:59:50 +00:00
|
|
|
for(i = 0; i < RPL_MAX_DAG_PER_INSTANCE; i++) {
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->dag_table[i].used) {
|
2017-06-10 12:35:39 +00:00
|
|
|
instance->dag_table[i].rank = RPL_INFINITE_RANK;
|
2011-07-11 13:50:51 +00:00
|
|
|
nullify_parents(&instance->dag_table[i], 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 19:12:52 +00:00
|
|
|
/* no downward route anymore */
|
|
|
|
instance->has_downward_route = 0;
|
2017-12-07 13:52:37 +00:00
|
|
|
#if RPL_WITH_DAO_ACK
|
|
|
|
ctimer_stop(&instance->dao_retransmit_timer);
|
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
2015-09-22 19:01:55 +00:00
|
|
|
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_reset_dio_timer(instance);
|
2016-11-25 15:30:08 +00:00
|
|
|
if(RPL_IS_STORING(instance)) {
|
|
|
|
/* Request refresh of DAO registrations next DIO. Only for storing mode. In
|
|
|
|
* non-storing mode, non-root nodes increment DTSN only on when their parent do,
|
|
|
|
* or on global repair (see RFC6550 section 9.6.) */
|
|
|
|
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
|
|
|
|
}
|
2010-10-27 00:46:40 +00:00
|
|
|
|
|
|
|
RPL_STAT(rpl_stats.local_repairs++);
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-10-27 00:46:40 +00:00
|
|
|
void
|
2010-06-14 12:44:37 +00:00
|
|
|
rpl_recalculate_ranks(void)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
2013-07-03 17:53:51 +00:00
|
|
|
p = nbr_table_head(rpl_parents);
|
|
|
|
while(p != NULL) {
|
2014-04-29 14:25:16 +00:00
|
|
|
if(p->dag != NULL && p->dag->instance && (p->flags & RPL_PARENT_FLAG_UPDATED)) {
|
|
|
|
p->flags &= ~RPL_PARENT_FLAG_UPDATED;
|
2013-08-11 21:42:51 +00:00
|
|
|
PRINTF("RPL: rpl_process_parent_event recalculate_ranks\n");
|
2013-07-03 17:53:51 +00:00
|
|
|
if(!rpl_process_parent_event(p->dag->instance, p)) {
|
|
|
|
PRINTF("RPL: A parent was dropped\n");
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-03 17:53:51 +00:00
|
|
|
p = nbr_table_next(rpl_parents, p);
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-14 12:44:37 +00:00
|
|
|
int
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p)
|
2010-06-14 12:44:37 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
int return_value;
|
2016-02-04 21:45:25 +00:00
|
|
|
rpl_parent_t *last_parent = instance->current_dag->preferred_parent;
|
2010-06-14 12:44:37 +00:00
|
|
|
|
2013-08-11 21:53:36 +00:00
|
|
|
#if DEBUG
|
|
|
|
rpl_rank_t old_rank;
|
2011-07-11 13:50:51 +00:00
|
|
|
old_rank = instance->current_dag->rank;
|
2013-08-11 21:53:36 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
return_value = 1;
|
2010-06-14 12:44:37 +00:00
|
|
|
|
2016-02-01 17:02:33 +00:00
|
|
|
if(RPL_IS_STORING(instance)
|
2017-06-10 12:35:39 +00:00
|
|
|
&& uip_ds6_route_is_nexthop(rpl_parent_get_ipaddr(p))
|
2016-02-01 17:02:33 +00:00
|
|
|
&& !rpl_parent_is_reachable(p) && instance->mop > RPL_MOP_NON_STORING) {
|
2015-11-30 18:17:17 +00:00
|
|
|
PRINTF("RPL: Unacceptable link %u, removing routes via: ", rpl_get_parent_link_metric(p));
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(p));
|
2015-11-30 18:17:17 +00:00
|
|
|
PRINTF("\n");
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_remove_routes_by_nexthop(rpl_parent_get_ipaddr(p), p->dag);
|
2015-11-30 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
2012-04-21 22:18:07 +00:00
|
|
|
if(!acceptable_rank(p->dag, p->rank)) {
|
2010-06-14 12:44:37 +00:00
|
|
|
/* The candidate parent is no longer valid: the rank increase resulting
|
|
|
|
from the choice of it as a parent would be too high. */
|
2015-11-29 20:48:53 +00:00
|
|
|
PRINTF("RPL: Unacceptable rank %u (Current min %u, MaxRankInc %u)\n", (unsigned)p->rank,
|
|
|
|
p->dag->min_rank, p->dag->instance->max_rankinc);
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_nullify_parent(p);
|
2011-07-11 13:50:51 +00:00
|
|
|
if(p != instance->current_dag->preferred_parent) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return_value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 21:12:47 +00:00
|
|
|
if(rpl_select_dag(instance, p) == NULL) {
|
2016-02-04 21:45:25 +00:00
|
|
|
if(last_parent != NULL) {
|
|
|
|
/* No suitable parent anymore; trigger a local repair. */
|
|
|
|
PRINTF("RPL: No parents found in any DAG\n");
|
|
|
|
rpl_local_repair(instance);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
#if DEBUG
|
|
|
|
if(DAG_RANK(old_rank, instance) != DAG_RANK(instance->current_dag->rank, instance)) {
|
2011-11-21 13:59:31 +00:00
|
|
|
PRINTF("RPL: Moving in the instance from rank %hu to %hu\n",
|
2011-07-11 13:50:51 +00:00
|
|
|
DAG_RANK(old_rank, instance), DAG_RANK(instance->current_dag->rank, instance));
|
2017-06-10 12:35:39 +00:00
|
|
|
if(instance->current_dag->rank != RPL_INFINITE_RANK) {
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("RPL: The preferred parent is ");
|
2017-06-10 12:35:39 +00:00
|
|
|
PRINT6ADDR(rpl_parent_get_ipaddr(instance->current_dag->preferred_parent));
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF(" (rank %u)\n",
|
|
|
|
(unsigned)DAG_RANK(instance->current_dag->preferred_parent->rank, instance));
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: We don't have any parent");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
return return_value;
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-08-20 15:09:32 +00:00
|
|
|
static int
|
|
|
|
add_nbr_from_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|
|
|
{
|
2015-09-20 19:02:30 +00:00
|
|
|
/* add this to the neighbor cache if not already there */
|
|
|
|
if(rpl_icmp6_update_nbr_table(from, NBR_TABLE_REASON_RPL_DIO, dio) == NULL) {
|
|
|
|
PRINTF("RPL: Out of memory, dropping DIO from ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF("\n");
|
|
|
|
return 0;
|
2015-08-20 15:09:32 +00:00
|
|
|
}
|
2015-09-20 19:02:30 +00:00
|
|
|
return 1;
|
2015-08-20 15:09:32 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-14 12:44:37 +00:00
|
|
|
void
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *instance;
|
|
|
|
rpl_dag_t *dag, *previous_dag;
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *p;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2016-06-20 14:35:09 +00:00
|
|
|
#if RPL_WITH_MULTICAST
|
2011-12-09 12:15:04 +00:00
|
|
|
/* If the root is advertising MOP 2 but we support MOP 3 we can still join
|
|
|
|
* In that scenario, we suppress DAOs for multicast targets */
|
|
|
|
if(dio->mop < RPL_MOP_STORING_NO_MULTICAST) {
|
|
|
|
#else
|
2010-12-13 10:54:25 +00:00
|
|
|
if(dio->mop != RPL_MOP_DEFAULT) {
|
2011-12-09 12:15:04 +00:00
|
|
|
#endif
|
2010-12-13 10:54:25 +00:00
|
|
|
PRINTF("RPL: Ignoring a DIO with an unsupported MOP: %d\n", dio->mop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:31:44 +00:00
|
|
|
dag = get_dag(dio->instance_id, &dio->dag_id);
|
|
|
|
instance = rpl_get_instance(dio->instance_id);
|
|
|
|
|
|
|
|
if(dag != NULL && instance != NULL) {
|
|
|
|
if(lollipop_greater_than(dio->version, dag->version)) {
|
|
|
|
if(dag->rank == ROOT_RANK(instance)) {
|
2016-02-03 16:10:24 +00:00
|
|
|
PRINTF("RPL: Root received inconsistent DIO version number (current: %u, received: %u)\n", dag->version, dio->version);
|
|
|
|
dag->version = dio->version;
|
|
|
|
RPL_LOLLIPOP_INCREMENT(dag->version);
|
|
|
|
rpl_reset_dio_timer(instance);
|
2012-11-26 18:31:44 +00:00
|
|
|
} else {
|
2014-03-27 15:17:47 +00:00
|
|
|
PRINTF("RPL: Global repair\n");
|
2013-02-05 10:19:41 +00:00
|
|
|
if(dio->prefix_info.length != 0) {
|
|
|
|
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
|
2016-03-09 10:32:02 +00:00
|
|
|
PRINTF("RPL: Prefix announced in DIO\n");
|
2013-02-05 10:19:41 +00:00
|
|
|
rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length);
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 16:10:24 +00:00
|
|
|
global_repair(from, dag, dio);
|
2012-11-26 18:31:44 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lollipop_greater_than(dag->version, dio->version)) {
|
|
|
|
/* The DIO sender is on an older version of the DAG. */
|
|
|
|
PRINTF("RPL: old version received => inconsistency detected\n");
|
|
|
|
if(dag->joined) {
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_reset_dio_timer(instance);
|
|
|
|
return;
|
2012-11-26 18:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance == NULL) {
|
2016-02-03 16:10:24 +00:00
|
|
|
PRINTF("RPL: New instance detected (ID=%u): Joining...\n", dio->instance_id);
|
2015-08-20 15:09:32 +00:00
|
|
|
if(add_nbr_from_dio(from, dio)) {
|
|
|
|
rpl_join_instance(from, dio);
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Not joining since could not add parent\n");
|
|
|
|
}
|
2010-05-31 14:22:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-08 14:41:24 +00:00
|
|
|
if(instance->current_dag->rank == ROOT_RANK(instance) && instance->current_dag != dag) {
|
|
|
|
PRINTF("RPL: Root ignored DIO for different DAG\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(dag == NULL) {
|
2014-12-03 15:46:17 +00:00
|
|
|
#if RPL_MAX_DAG_PER_INSTANCE > 1
|
2012-04-17 21:12:47 +00:00
|
|
|
PRINTF("RPL: Adding new DAG to known instance.\n");
|
2015-08-20 15:09:32 +00:00
|
|
|
if(!add_nbr_from_dio(from, dio)) {
|
|
|
|
PRINTF("RPL: Could not add new DAG, could not add parent\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-11-30 18:21:18 +00:00
|
|
|
dag = rpl_add_dag(from, dio);
|
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL: Failed to add DAG.\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-12-03 15:46:17 +00:00
|
|
|
#else /* RPL_MAX_DAG_PER_INSTANCE > 1 */
|
|
|
|
PRINTF("RPL: Only one instance supported.\n");
|
|
|
|
return;
|
|
|
|
#endif /* RPL_MAX_DAG_PER_INSTANCE > 1 */
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2012-04-21 22:18:07 +00:00
|
|
|
|
|
|
|
if(dio->rank < ROOT_RANK(instance)) {
|
2011-02-20 19:15:40 +00:00
|
|
|
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
|
|
|
|
(unsigned)dio->rank);
|
|
|
|
return;
|
2010-06-28 14:51:23 +00:00
|
|
|
}
|
2013-11-20 13:09:42 +00:00
|
|
|
|
2013-02-05 10:19:41 +00:00
|
|
|
/* Prefix Information Option treated to add new prefix */
|
|
|
|
if(dio->prefix_info.length != 0) {
|
|
|
|
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
|
2016-03-09 10:32:02 +00:00
|
|
|
PRINTF("RPL: Prefix announced in DIO\n");
|
2013-02-05 10:19:41 +00:00
|
|
|
rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length);
|
|
|
|
}
|
|
|
|
}
|
2010-06-28 14:51:23 +00:00
|
|
|
|
2016-04-25 15:13:10 +00:00
|
|
|
if(!add_nbr_from_dio(from, dio)) {
|
|
|
|
PRINTF("RPL: Could not add parent based on DIO\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(dag->rank == ROOT_RANK(instance)) {
|
2017-06-10 12:35:39 +00:00
|
|
|
if(dio->rank != RPL_INFINITE_RANK) {
|
2011-11-16 08:49:22 +00:00
|
|
|
instance->dio_counter++;
|
2010-06-28 14:51:23 +00:00
|
|
|
}
|
2010-06-14 12:44:37 +00:00
|
|
|
return;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 07:39:44 +00:00
|
|
|
/* The DIO comes from a valid DAG, we can refresh its lifetime */
|
2016-06-13 09:36:17 +00:00
|
|
|
dag->lifetime = (1UL << (instance->dio_intmin + instance->dio_intdoubl)) * RPL_DAG_LIFETIME / 1000;
|
2015-09-30 07:39:44 +00:00
|
|
|
PRINTF("Set dag ");
|
|
|
|
PRINT6ADDR(&dag->dag_id);
|
|
|
|
PRINTF(" lifetime to %ld\n", dag->lifetime);
|
|
|
|
|
2010-06-28 14:51:23 +00: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 12:44:37 +00:00
|
|
|
|
|
|
|
p = rpl_find_parent(dag, from);
|
2011-02-13 20:33:47 +00:00
|
|
|
if(p == NULL) {
|
2012-01-04 10:22:11 +00:00
|
|
|
previous_dag = find_parent_dag(instance, from);
|
2011-07-11 13:50:51 +00:00
|
|
|
if(previous_dag == NULL) {
|
|
|
|
/* 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 (");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF(")\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINT6ADDR(from);
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINTF("\n");
|
|
|
|
} else {
|
|
|
|
p = rpl_find_parent(previous_dag, from);
|
2012-01-30 22:51:07 +00:00
|
|
|
if(p != NULL) {
|
|
|
|
rpl_move_parent(previous_dag, dag, p);
|
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(p->rank == dio->rank) {
|
|
|
|
PRINTF("RPL: Received consistent DIO\n");
|
|
|
|
if(dag->joined) {
|
|
|
|
instance->dio_counter++;
|
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
2015-09-30 13:23:34 +00:00
|
|
|
p->rank = dio->rank;
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2017-06-10 12:35:39 +00:00
|
|
|
if(dio->rank == RPL_INFINITE_RANK && p == dag->preferred_parent) {
|
2016-02-04 21:46:16 +00:00
|
|
|
/* Our preferred parent advertised an infinite rank, reset DIO timer */
|
|
|
|
rpl_reset_dio_timer(instance);
|
|
|
|
}
|
|
|
|
|
2014-12-16 10:30:16 +00:00
|
|
|
/* Parent info has been updated, trigger rank recalculation */
|
|
|
|
p->flags |= RPL_PARENT_FLAG_UPDATED;
|
|
|
|
|
2012-02-29 20:59:50 +00:00
|
|
|
PRINTF("RPL: preferred DAG ");
|
2011-07-11 13:50:51 +00:00
|
|
|
PRINT6ADDR(&instance->current_dag->dag_id);
|
2012-01-04 10:22:11 +00:00
|
|
|
PRINTF(", rank %u, min_rank %u, ",
|
2011-11-21 13:59:31 +00:00
|
|
|
instance->current_dag->rank, instance->current_dag->min_rank);
|
2015-11-29 20:44:39 +00:00
|
|
|
PRINTF("parent rank %u, link metric %u\n",
|
|
|
|
p->rank, rpl_get_parent_link_metric(p));
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2010-09-15 13:22:22 +00:00
|
|
|
/* We have allocated a candidate parent; process the DIO further. */
|
2011-03-16 12:29:01 +00:00
|
|
|
|
2015-11-29 20:44:39 +00:00
|
|
|
#if RPL_WITH_MC
|
2011-07-11 13:50:51 +00:00
|
|
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
2015-11-29 20:44:39 +00:00
|
|
|
#endif /* RPL_WITH_MC */
|
2011-07-11 13:50:51 +00:00
|
|
|
if(rpl_process_parent_event(instance, p) == 0) {
|
|
|
|
PRINTF("RPL: The candidate parent is rejected\n");
|
2010-06-28 14:51:23 +00:00
|
|
|
return;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2011-11-22 13:18:32 +00:00
|
|
|
/* We don't use route control, so we can have only one official parent. */
|
|
|
|
if(dag->joined && p == dag->preferred_parent) {
|
2016-11-25 15:30:08 +00:00
|
|
|
if(should_refresh_routes(instance, dio, p)) {
|
|
|
|
/* Our parent is requesting a new DAO. Increment DTSN in turn,
|
|
|
|
* in both storing and non-storing mode (see RFC6550 section 9.6.) */
|
2011-07-11 13:50:51 +00:00
|
|
|
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
|
|
|
|
rpl_schedule_dao(instance);
|
|
|
|
}
|
2013-02-05 14:43:13 +00:00
|
|
|
/* We received a new DIO from our preferred parent.
|
|
|
|
* Call uip_ds6_defrt_add to set a fresh value for the lifetime counter */
|
2014-09-10 14:56:53 +00:00
|
|
|
uip_ds6_defrt_add(from, RPL_DEFAULT_ROUTE_INFINITE_LIFETIME ? 0 : RPL_LIFETIME(instance, instance->default_lifetime));
|
2010-06-14 12:44:37 +00:00
|
|
|
}
|
|
|
|
p->dtsn = dio->dtsn;
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-30 09:01:20 +00:00
|
|
|
/** @} */
|