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
|
|
|
|
* RPL timer management.
|
|
|
|
*
|
|
|
|
* \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se>
|
|
|
|
*/
|
|
|
|
|
2014-11-08 00:15:42 +00:00
|
|
|
/**
|
|
|
|
* \addtogroup uip6
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
#include "contiki-conf.h"
|
2011-02-11 15:21:17 +00:00
|
|
|
#include "net/rpl/rpl-private.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/random.h"
|
2010-06-14 12:44:37 +00:00
|
|
|
#include "sys/ctimer.h"
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-11-03 15:41:23 +00:00
|
|
|
#define DEBUG DEBUG_NONE
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ip/uip-debug.h"
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
static struct ctimer periodic_timer;
|
|
|
|
|
|
|
|
static void handle_periodic_timer(void *ptr);
|
2011-07-11 13:50:51 +00:00
|
|
|
static void new_dio_interval(rpl_instance_t *instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
static void handle_dio_timer(void *ptr);
|
|
|
|
|
|
|
|
static uint16_t next_dis;
|
2010-05-09 17:52:37 +00:00
|
|
|
|
|
|
|
/* dio_send_ok is true if the node is ready to send DIOs */
|
|
|
|
static uint8_t dio_send_ok;
|
|
|
|
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
static void
|
|
|
|
handle_periodic_timer(void *ptr)
|
|
|
|
{
|
|
|
|
rpl_purge_routes();
|
2010-06-14 12:44:37 +00:00
|
|
|
rpl_recalculate_ranks();
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
/* handle DIS */
|
2014-03-18 07:11:34 +00:00
|
|
|
#if RPL_DIS_SEND
|
2010-04-30 13:43:53 +00:00
|
|
|
next_dis++;
|
2011-07-11 13:50:51 +00:00
|
|
|
if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) {
|
2010-05-04 22:55:32 +00:00
|
|
|
next_dis = 0;
|
|
|
|
dis_output(NULL);
|
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
#endif
|
|
|
|
ctimer_reset(&periodic_timer);
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
static void
|
2011-07-11 13:50:51 +00:00
|
|
|
new_dio_interval(rpl_instance_t *instance)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2010-12-15 12:12:27 +00:00
|
|
|
uint32_t time;
|
2012-11-26 18:35:39 +00:00
|
|
|
clock_time_t ticks;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-05-04 22:55:32 +00:00
|
|
|
/* TODO: too small timer intervals for many cases */
|
2011-07-11 13:50:51 +00:00
|
|
|
time = 1UL << instance->dio_intcurrent;
|
2010-05-04 22:55:32 +00:00
|
|
|
|
2010-12-15 12:12:27 +00:00
|
|
|
/* Convert from milliseconds to CLOCK_TICKS. */
|
2012-11-26 18:35:39 +00:00
|
|
|
ticks = (time * CLOCK_SECOND) / 1000;
|
|
|
|
instance->dio_next_delay = ticks;
|
2010-05-04 22:55:32 +00:00
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
/* random number between I/2 and I */
|
2012-11-26 18:35:39 +00:00
|
|
|
ticks = ticks / 2 + (ticks / 2 * (uint32_t)random_rand()) / RANDOM_RAND_MAX;
|
2010-05-04 22:55:32 +00:00
|
|
|
|
2010-12-15 12:12:27 +00:00
|
|
|
/*
|
|
|
|
* The intervals must be equally long among the nodes for Trickle to
|
|
|
|
* operate efficiently. Therefore we need to calculate the delay between
|
|
|
|
* the randomized time and the start time of the next interval.
|
|
|
|
*/
|
2012-11-26 18:35:39 +00:00
|
|
|
instance->dio_next_delay -= ticks;
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_send = 1;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
#if RPL_CONF_STATS
|
|
|
|
/* keep some stats */
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_totint++;
|
|
|
|
instance->dio_totrecv += instance->dio_counter;
|
2010-10-28 20:39:06 +00:00
|
|
|
ANNOTATE("#A rank=%u.%u(%u),stats=%d %d %d %d,color=%s\n",
|
2011-07-11 13:50:51 +00:00
|
|
|
DAG_RANK(instance->current_dag->rank, instance),
|
|
|
|
(10 * (instance->current_dag->rank % instance->min_hoprankinc)) / instance->min_hoprankinc,
|
|
|
|
instance->current_dag->version,
|
|
|
|
instance->dio_totint, instance->dio_totsend,
|
|
|
|
instance->dio_totrecv,instance->dio_intcurrent,
|
|
|
|
instance->current_dag->rank == ROOT_RANK(instance) ? "BLUE" : "ORANGE");
|
2010-04-30 13:43:53 +00:00
|
|
|
#endif /* RPL_CONF_STATS */
|
|
|
|
|
|
|
|
/* reset the redundancy counter */
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_counter = 0;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
/* schedule the timer */
|
2012-11-26 18:35:39 +00:00
|
|
|
PRINTF("RPL: Scheduling DIO timer %lu ticks in future (Interval)\n", ticks);
|
|
|
|
ctimer_set(&instance->dio_timer, ticks, &handle_dio_timer, instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
static void
|
|
|
|
handle_dio_timer(void *ptr)
|
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *instance;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
instance = (rpl_instance_t *)ptr;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
PRINTF("RPL: DIO Timer triggered\n");
|
2010-05-09 17:52:37 +00:00
|
|
|
if(!dio_send_ok) {
|
|
|
|
if(uip_ds6_get_link_local(ADDR_PREFERRED) != NULL) {
|
|
|
|
dio_send_ok = 1;
|
|
|
|
} else {
|
2010-06-14 12:44:37 +00:00
|
|
|
PRINTF("RPL: Postponing DIO transmission since link local address is not ok\n");
|
2011-07-11 13:50:51 +00:00
|
|
|
ctimer_set(&instance->dio_timer, CLOCK_SECOND, &handle_dio_timer, instance);
|
2010-05-09 17:52:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->dio_send) {
|
2010-04-30 13:43:53 +00:00
|
|
|
/* send DIO if counter is less than desired redundancy */
|
2014-09-10 14:57:27 +00:00
|
|
|
if(instance->dio_redundancy != 0 && instance->dio_counter < instance->dio_redundancy) {
|
2010-04-30 13:43:53 +00:00
|
|
|
#if RPL_CONF_STATS
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_totsend++;
|
2010-04-30 13:43:53 +00:00
|
|
|
#endif /* RPL_CONF_STATS */
|
2011-07-11 13:50:51 +00:00
|
|
|
dio_output(instance, NULL);
|
2010-04-30 13:43:53 +00:00
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Supressing DIO transmission (%d >= %d)\n",
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_counter, instance->dio_redundancy);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_send = 0;
|
2012-01-04 10:22:11 +00:00
|
|
|
PRINTF("RPL: Scheduling DIO timer %lu ticks in future (sent)\n",
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_next_delay);
|
|
|
|
ctimer_set(&instance->dio_timer, instance->dio_next_delay, handle_dio_timer, instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
} else {
|
|
|
|
/* check if we need to double interval */
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->dio_intcurrent < instance->dio_intmin + instance->dio_intdoubl) {
|
|
|
|
instance->dio_intcurrent++;
|
|
|
|
PRINTF("RPL: DIO Timer interval doubled %d\n", instance->dio_intcurrent);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2011-07-11 13:50:51 +00:00
|
|
|
new_dio_interval(instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2015-05-06 09:34:52 +00:00
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
rpl_print_neighbor_list();
|
|
|
|
#endif
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
void
|
|
|
|
rpl_reset_periodic_timer(void)
|
|
|
|
{
|
2012-11-26 18:36:51 +00:00
|
|
|
next_dis = RPL_DIS_INTERVAL / 2 +
|
|
|
|
((uint32_t)RPL_DIS_INTERVAL * (uint32_t)random_rand()) / RANDOM_RAND_MAX -
|
|
|
|
RPL_DIS_START_DELAY;
|
2010-04-30 13:43:53 +00:00
|
|
|
ctimer_set(&periodic_timer, CLOCK_SECOND, handle_periodic_timer, NULL);
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
/* Resets the DIO timer in the instance to its minimal interval. */
|
2010-04-30 13:43:53 +00:00
|
|
|
void
|
2012-01-04 10:22:11 +00:00
|
|
|
rpl_reset_dio_timer(rpl_instance_t *instance)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
#if !RPL_LEAF_ONLY
|
2011-11-16 08:49:22 +00:00
|
|
|
/* Do not reset if we are already on the minimum interval,
|
|
|
|
unless forced to do so. */
|
2012-01-04 10:22:11 +00:00
|
|
|
if(instance->dio_intcurrent > instance->dio_intmin) {
|
2011-07-11 13:50:51 +00:00
|
|
|
instance->dio_counter = 0;
|
|
|
|
instance->dio_intcurrent = instance->dio_intmin;
|
|
|
|
new_dio_interval(instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2010-10-28 20:39:06 +00:00
|
|
|
#if RPL_CONF_STATS
|
|
|
|
rpl_stats.resets++;
|
2011-07-11 13:50:51 +00:00
|
|
|
#endif /* RPL_CONF_STATS */
|
|
|
|
#endif /* RPL_LEAF_ONLY */
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-11-20 13:02:38 +00:00
|
|
|
static void handle_dao_timer(void *ptr);
|
|
|
|
static void
|
|
|
|
set_dao_lifetime_timer(rpl_instance_t *instance)
|
|
|
|
{
|
|
|
|
if(rpl_get_mode() == RPL_MODE_FEATHER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up another DAO within half the expiration time, if such a
|
|
|
|
time has been configured */
|
|
|
|
if(instance->lifetime_unit != 0xffff && instance->default_lifetime != 0xff) {
|
|
|
|
clock_time_t expiration_time;
|
|
|
|
expiration_time = (clock_time_t)instance->default_lifetime *
|
|
|
|
(clock_time_t)instance->lifetime_unit *
|
|
|
|
CLOCK_SECOND / 2;
|
|
|
|
PRINTF("RPL: Scheduling DAO lifetime timer %u ticks in the future\n",
|
|
|
|
(unsigned)expiration_time);
|
|
|
|
ctimer_set(&instance->dao_lifetime_timer, expiration_time,
|
|
|
|
handle_dao_timer, instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
static void
|
|
|
|
handle_dao_timer(void *ptr)
|
|
|
|
{
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_instance_t *instance;
|
2011-12-09 12:15:04 +00:00
|
|
|
#if RPL_CONF_MULTICAST
|
|
|
|
uip_mcast6_route_t *mcast_route;
|
|
|
|
uint8_t i;
|
|
|
|
#endif
|
2010-05-25 21:58:54 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
instance = (rpl_instance_t *)ptr;
|
2010-05-09 19:12:47 +00:00
|
|
|
|
2011-11-16 08:49:22 +00:00
|
|
|
if(!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
|
|
|
|
PRINTF("RPL: Postpone DAO transmission\n");
|
2011-07-11 13:50:51 +00:00
|
|
|
ctimer_set(&instance->dao_timer, CLOCK_SECOND, handle_dao_timer, instance);
|
2010-05-09 19:12:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-28 15:08:44 +00:00
|
|
|
/* Send the DAO to the DAO parent set -- the preferred parent in our case. */
|
2011-07-11 13:50:51 +00:00
|
|
|
if(instance->current_dag->preferred_parent != NULL) {
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("RPL: handle_dao_timer - sending DAO\n");
|
2011-06-28 15:08:44 +00:00
|
|
|
/* Set the route lifetime to the default value. */
|
2011-07-11 13:50:51 +00:00
|
|
|
dao_output(instance->current_dag->preferred_parent, instance->default_lifetime);
|
2011-12-09 12:15:04 +00:00
|
|
|
|
|
|
|
#if RPL_CONF_MULTICAST
|
|
|
|
/* Send DAOs for multicast prefixes only if the instance is in MOP 3 */
|
|
|
|
if(instance->mop == RPL_MOP_STORING_MULTICAST) {
|
|
|
|
/* Send a DAO for own multicast addresses */
|
|
|
|
for(i = 0; i < UIP_DS6_MADDR_NB; i++) {
|
|
|
|
if(uip_ds6_if.maddr_list[i].isused
|
|
|
|
&& uip_is_addr_mcast_global(&uip_ds6_if.maddr_list[i].ipaddr)) {
|
|
|
|
dao_output_target(instance->current_dag->preferred_parent,
|
|
|
|
&uip_ds6_if.maddr_list[i].ipaddr, RPL_MCAST_LIFETIME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Iterate over multicast routes and send DAOs */
|
|
|
|
mcast_route = uip_mcast6_route_list_head();
|
|
|
|
while(mcast_route != NULL) {
|
|
|
|
/* Don't send if it's also our own address, done that already */
|
|
|
|
if(uip_ds6_maddr_lookup(&mcast_route->group) == NULL) {
|
|
|
|
dao_output_target(instance->current_dag->preferred_parent,
|
|
|
|
&mcast_route->group, RPL_MCAST_LIFETIME);
|
|
|
|
}
|
|
|
|
mcast_route = list_item_next(mcast_route);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-09 19:12:47 +00:00
|
|
|
} else {
|
2011-06-28 15:08:44 +00:00
|
|
|
PRINTF("RPL: No suitable DAO parent\n");
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2013-11-20 13:02:38 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
ctimer_stop(&instance->dao_timer);
|
2013-11-20 13:02:38 +00:00
|
|
|
|
|
|
|
if(etimer_expired(&instance->dao_lifetime_timer.etimer)) {
|
|
|
|
set_dao_lifetime_timer(instance);
|
|
|
|
}
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-11-20 13:02:38 +00:00
|
|
|
static void
|
|
|
|
schedule_dao(rpl_instance_t *instance, clock_time_t latency)
|
2010-04-30 13:43:53 +00:00
|
|
|
{
|
|
|
|
clock_time_t expiration_time;
|
2010-05-24 16:38:56 +00:00
|
|
|
|
2013-11-20 13:10:39 +00:00
|
|
|
if(rpl_get_mode() == RPL_MODE_FEATHER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
expiration_time = etimer_expiration_time(&instance->dao_timer.etimer);
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2011-07-11 13:50:51 +00:00
|
|
|
if(!etimer_expired(&instance->dao_timer.etimer)) {
|
2010-04-30 13:43:53 +00:00
|
|
|
PRINTF("RPL: DAO timer already scheduled\n");
|
|
|
|
} else {
|
2013-11-20 13:02:38 +00:00
|
|
|
if(latency != 0) {
|
|
|
|
expiration_time = latency / 2 +
|
|
|
|
(random_rand() % (latency));
|
|
|
|
} else {
|
|
|
|
expiration_time = 0;
|
|
|
|
}
|
2010-12-17 15:24:25 +00:00
|
|
|
PRINTF("RPL: Scheduling DAO timer %u ticks in the future\n",
|
|
|
|
(unsigned)expiration_time);
|
2011-07-11 13:50:51 +00:00
|
|
|
ctimer_set(&instance->dao_timer, expiration_time,
|
|
|
|
handle_dao_timer, instance);
|
2013-11-20 13:02:38 +00:00
|
|
|
|
|
|
|
set_dao_lifetime_timer(instance);
|
2010-04-30 13:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 10:47:02 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-11-20 13:02:38 +00:00
|
|
|
void
|
|
|
|
rpl_schedule_dao(rpl_instance_t *instance)
|
|
|
|
{
|
|
|
|
schedule_dao(instance, RPL_DAO_LATENCY);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
rpl_schedule_dao_immediately(rpl_instance_t *instance)
|
|
|
|
{
|
|
|
|
schedule_dao(instance, 0);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
rpl_cancel_dao(rpl_instance_t *instance)
|
|
|
|
{
|
|
|
|
ctimer_stop(&instance->dao_timer);
|
|
|
|
ctimer_stop(&instance->dao_lifetime_timer);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-05-06 09:35:42 +00:00
|
|
|
#if RPL_WITH_PROBING
|
|
|
|
static rpl_parent_t *
|
|
|
|
get_probing_target(rpl_dag_t *dag)
|
|
|
|
{
|
2015-05-08 08:19:14 +00:00
|
|
|
/* Returns the next probing target. The current implementation probes the current
|
2015-05-10 11:19:56 +00:00
|
|
|
* preferred parent if we have not updated its link for RPL_PROBING_EXPIRATION_TIME.
|
2015-05-08 08:19:14 +00:00
|
|
|
* Otherwise, it picks at random between:
|
2015-05-10 11:19:56 +00:00
|
|
|
* (1) selecting the best parent not updated for RPL_PROBING_EXPIRATION_TIME
|
2015-05-08 08:19:14 +00:00
|
|
|
* (2) selecting the least recently updated parent
|
|
|
|
*/
|
2015-05-06 09:35:42 +00:00
|
|
|
|
|
|
|
rpl_parent_t *p;
|
2015-05-08 08:19:14 +00:00
|
|
|
rpl_parent_t *probing_target = NULL;
|
|
|
|
rpl_rank_t probing_target_rank = INFINITE_RANK;
|
2015-05-10 11:19:56 +00:00
|
|
|
/* min_last_tx is the clock time RPL_PROBING_EXPIRATION_TIME in the past */
|
2015-05-06 09:35:42 +00:00
|
|
|
clock_time_t min_last_tx = clock_time();
|
2015-05-10 11:19:56 +00:00
|
|
|
min_last_tx = min_last_tx > 2 * RPL_PROBING_EXPIRATION_TIME
|
|
|
|
? min_last_tx - RPL_PROBING_EXPIRATION_TIME : 1;
|
2015-05-06 09:35:42 +00:00
|
|
|
|
|
|
|
if(dag == NULL ||
|
|
|
|
dag->instance == NULL ||
|
|
|
|
dag->preferred_parent == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Our preferred parent needs probing */
|
|
|
|
if(dag->preferred_parent->last_tx_time < min_last_tx) {
|
2015-05-10 11:28:00 +00:00
|
|
|
probing_target = dag->preferred_parent;
|
2015-05-06 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-05-10 11:28:00 +00:00
|
|
|
/* With 50% probability: probe best parent not updated for RPL_PROBING_EXPIRATION_TIME */
|
|
|
|
if(probing_target == NULL && (random_rand() % 2) == 0) {
|
2015-05-08 08:19:14 +00:00
|
|
|
p = nbr_table_head(rpl_parents);
|
|
|
|
while(p != NULL) {
|
|
|
|
if(p->dag == dag && p->last_tx_time < min_last_tx) {
|
|
|
|
/* p is in our dag and needs probing */
|
|
|
|
rpl_rank_t p_rank = dag->instance->of->calculate_rank(p, 0);
|
|
|
|
if(probing_target == NULL
|
|
|
|
|| p_rank < probing_target_rank) {
|
2015-05-06 09:35:42 +00:00
|
|
|
probing_target = p;
|
|
|
|
probing_target_rank = p_rank;
|
|
|
|
}
|
|
|
|
}
|
2015-05-08 08:19:14 +00:00
|
|
|
p = nbr_table_next(rpl_parents, p);
|
2015-05-06 09:35:42 +00:00
|
|
|
}
|
2015-05-10 11:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The default probing target is the least recently updated parent */
|
|
|
|
if(probing_target == NULL) {
|
2015-05-08 08:19:14 +00:00
|
|
|
p = nbr_table_head(rpl_parents);
|
|
|
|
while(p != NULL) {
|
|
|
|
if(p->dag == dag) {
|
|
|
|
if(probing_target == NULL
|
|
|
|
|| p->last_tx_time < probing_target->last_tx_time) {
|
|
|
|
probing_target = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = nbr_table_next(rpl_parents, p);
|
|
|
|
}
|
2015-05-06 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return probing_target;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
handle_probing_timer(void *ptr)
|
|
|
|
{
|
|
|
|
rpl_instance_t *instance = (rpl_instance_t *)ptr;
|
|
|
|
rpl_parent_t *probing_target = RPL_PROBING_SELECT_FUNC(instance->current_dag);
|
|
|
|
|
|
|
|
/* Perform probing */
|
|
|
|
if(probing_target != NULL && rpl_get_parent_ipaddr(probing_target) != NULL) {
|
|
|
|
PRINTF("RPL: probing %3u\n",
|
|
|
|
nbr_table_get_lladdr(rpl_parents, probing_target)->u8[7]);
|
|
|
|
/* Send probe, e.g. unicast DIO or DIS */
|
|
|
|
RPL_PROBING_SEND_FUNC(instance, rpl_get_parent_ipaddr(probing_target));
|
|
|
|
}
|
2014-05-30 09:01:20 +00:00
|
|
|
|
2015-05-06 09:35:42 +00:00
|
|
|
/* Schedule next probing */
|
|
|
|
rpl_schedule_probing(instance);
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
rpl_print_neighbor_list();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
rpl_schedule_probing(rpl_instance_t *instance)
|
|
|
|
{
|
2015-05-08 08:23:03 +00:00
|
|
|
ctimer_set(&instance->probing_timer, RPL_PROBING_DELAY_FUNC(),
|
2015-05-06 09:35:42 +00:00
|
|
|
handle_probing_timer, instance);
|
|
|
|
}
|
|
|
|
#endif /* RPL_WITH_PROBING */
|
2014-05-30 09:01:20 +00:00
|
|
|
/** @}*/
|