2014-07-08 16:54:54 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Oliver Hahm <oliver.hahm@inria.fr>
|
2013-06-22 05:11:53 +02:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-07-08 16:54:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup rpl
|
2013-06-22 05:11:53 +02:00
|
|
|
* @{
|
2014-07-08 16:54:54 +02:00
|
|
|
* @file of0.c
|
|
|
|
* @brief Objective Function Zero.
|
|
|
|
*
|
|
|
|
* Implementation of Objective Function Zero.
|
|
|
|
*
|
|
|
|
* @author Eric Engel <eric.engel@fu-berlin.de>
|
2013-06-22 05:11:53 +02:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2012-01-19 17:35:50 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include "of0.h"
|
|
|
|
|
2013-03-15 17:48:13 +01:00
|
|
|
//Function Prototypes
|
|
|
|
static uint16_t calc_rank(rpl_parent_t *, uint16_t);
|
|
|
|
static rpl_parent_t *which_parent(rpl_parent_t *, rpl_parent_t *);
|
|
|
|
static rpl_dodag_t *which_dodag(rpl_dodag_t *, rpl_dodag_t *);
|
|
|
|
static void reset(rpl_dodag_t *);
|
|
|
|
|
2015-02-01 16:01:56 +01:00
|
|
|
static rpl_of_t rpl_of0 = {
|
2013-06-22 05:11:53 +02:00
|
|
|
0x0,
|
|
|
|
calc_rank,
|
|
|
|
which_parent,
|
|
|
|
which_dodag,
|
|
|
|
reset,
|
2013-11-21 14:18:54 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2013-06-22 05:11:53 +02:00
|
|
|
NULL
|
2012-01-19 17:35:50 +01:00
|
|
|
};
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
rpl_of_t *rpl_get_of0(void)
|
|
|
|
{
|
|
|
|
return &rpl_of0;
|
2012-01-26 20:26:55 +01:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
void reset(rpl_dodag_t *dodag)
|
|
|
|
{
|
|
|
|
/* Nothing to do in OF0 */
|
2013-11-21 14:18:54 +01:00
|
|
|
(void) dodag;
|
2012-01-19 17:35:50 +01:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank)
|
|
|
|
{
|
2013-06-24 22:37:35 +02:00
|
|
|
if (base_rank == 0) {
|
|
|
|
if (parent == NULL) {
|
2013-06-22 05:11:53 +02:00
|
|
|
return INFINITE_RANK;
|
|
|
|
}
|
|
|
|
|
|
|
|
base_rank = parent->rank;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t add;
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (parent != NULL) {
|
2013-06-22 05:11:53 +02:00
|
|
|
add = parent->dodag->minhoprankincrease;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
add = DEFAULT_MIN_HOP_RANK_INCREASE;
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (base_rank + add < base_rank) {
|
2013-06-22 05:11:53 +02:00
|
|
|
return INFINITE_RANK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base_rank + add;
|
2012-01-19 17:35:50 +01:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
/* We simply return the Parent with lower rank */
|
|
|
|
rpl_parent_t *which_parent(rpl_parent_t *p1, rpl_parent_t *p2)
|
|
|
|
{
|
2013-06-24 22:37:35 +02:00
|
|
|
if (p1->rank < p2->rank) {
|
2013-06-22 05:11:53 +02:00
|
|
|
return p1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p2;
|
2012-01-19 17:35:50 +01:00
|
|
|
}
|
|
|
|
|
2013-06-28 17:53:21 +02:00
|
|
|
/* Not used yet, as the implementation only makes use of one dodag for now. */
|
2013-06-22 05:11:53 +02:00
|
|
|
rpl_dodag_t *which_dodag(rpl_dodag_t *d1, rpl_dodag_t *d2)
|
|
|
|
{
|
2013-11-21 14:18:54 +01:00
|
|
|
(void) d2;
|
2013-06-22 05:11:53 +02:00
|
|
|
return d1;
|
2012-01-19 17:35:50 +01:00
|
|
|
}
|