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.
|
|
|
|
*
|
2011-02-11 15:21:17 +00:00
|
|
|
* \file
|
2012-04-21 22:17:10 +00:00
|
|
|
* Public API declarations for ContikiRPL.
|
2011-02-11 15:21:17 +00:00
|
|
|
* \author
|
|
|
|
* Joakim Eriksson <joakime@sics.se> & Nicolas Tsiftes <nvt@sics.se>
|
2010-04-30 13:43:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RPL_H
|
|
|
|
#define RPL_H
|
|
|
|
|
2012-04-21 22:17:10 +00:00
|
|
|
#include "rpl-conf.h"
|
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
#include "lib/list.h"
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ip/uip.h"
|
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2011-02-11 15:21:17 +00:00
|
|
|
#include "sys/ctimer.h"
|
2011-01-25 09:54:03 +00:00
|
|
|
|
2011-02-11 15:21:17 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 13:43:53 +00:00
|
|
|
typedef uint16_t rpl_rank_t;
|
|
|
|
typedef uint16_t rpl_ocp_t;
|
2011-02-15 00:13:30 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* DAG Metric Container Object Types, to be confirmed by IANA. */
|
|
|
|
#define RPL_DAG_MC_NONE 0 /* Local identifier for empty MC */
|
|
|
|
#define RPL_DAG_MC_NSA 1 /* Node State and Attributes */
|
2011-03-15 00:16:20 +00:00
|
|
|
#define RPL_DAG_MC_ENERGY 2 /* Node Energy */
|
|
|
|
#define RPL_DAG_MC_HOPCOUNT 3 /* Hop Count */
|
2011-02-15 00:13:30 +00:00
|
|
|
#define RPL_DAG_MC_THROUGHPUT 4 /* Throughput */
|
|
|
|
#define RPL_DAG_MC_LATENCY 5 /* Latency */
|
|
|
|
#define RPL_DAG_MC_LQL 6 /* Link Quality Level */
|
2011-06-28 15:49:32 +00:00
|
|
|
#define RPL_DAG_MC_ETX 7 /* Expected Transmission Count */
|
2011-02-15 00:13:30 +00:00
|
|
|
#define RPL_DAG_MC_LC 8 /* Link Color */
|
|
|
|
|
|
|
|
/* DAG Metric Container flags. */
|
|
|
|
#define RPL_DAG_MC_FLAG_P 0x8
|
|
|
|
#define RPL_DAG_MC_FLAG_C 0x4
|
|
|
|
#define RPL_DAG_MC_FLAG_O 0x2
|
|
|
|
#define RPL_DAG_MC_FLAG_R 0x1
|
|
|
|
|
|
|
|
/* DAG Metric Container aggregation mode. */
|
|
|
|
#define RPL_DAG_MC_AGGR_ADDITIVE 0
|
|
|
|
#define RPL_DAG_MC_AGGR_MAXIMUM 1
|
|
|
|
#define RPL_DAG_MC_AGGR_MINIMUM 2
|
|
|
|
#define RPL_DAG_MC_AGGR_MULTIPLICATIVE 3
|
|
|
|
|
2011-03-15 00:16:20 +00:00
|
|
|
/* The bit index within the flags field of
|
|
|
|
the rpl_metric_object_energy structure. */
|
|
|
|
#define RPL_DAG_MC_ENERGY_INCLUDED 3
|
|
|
|
#define RPL_DAG_MC_ENERGY_TYPE 1
|
|
|
|
#define RPL_DAG_MC_ENERGY_ESTIMATION 0
|
|
|
|
|
|
|
|
#define RPL_DAG_MC_ENERGY_TYPE_MAINS 0
|
|
|
|
#define RPL_DAG_MC_ENERGY_TYPE_BATTERY 1
|
|
|
|
#define RPL_DAG_MC_ENERGY_TYPE_SCAVENGING 2
|
|
|
|
|
|
|
|
struct rpl_metric_object_energy {
|
|
|
|
uint8_t flags;
|
|
|
|
uint8_t energy_est;
|
2011-02-15 00:13:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Logical representation of a DAG Metric Container. */
|
|
|
|
struct rpl_metric_container {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t flags;
|
|
|
|
uint8_t aggr;
|
|
|
|
uint8_t prec;
|
|
|
|
uint8_t length;
|
2011-03-15 00:16:20 +00:00
|
|
|
union metric_object {
|
|
|
|
struct rpl_metric_object_energy energy;
|
|
|
|
uint16_t etx;
|
|
|
|
} obj;
|
2011-02-15 00:13:30 +00:00
|
|
|
};
|
|
|
|
typedef struct rpl_metric_container rpl_metric_container_t;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
struct rpl_instance;
|
2011-02-11 15:21:17 +00:00
|
|
|
struct rpl_dag;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-04-29 14:25:16 +00:00
|
|
|
#define RPL_PARENT_FLAG_UPDATED 0x1
|
|
|
|
#define RPL_PARENT_FLAG_LINK_METRIC_VALID 0x2
|
|
|
|
|
2010-05-25 21:58:54 +00:00
|
|
|
struct rpl_parent {
|
2011-02-11 15:21:17 +00:00
|
|
|
struct rpl_dag *dag;
|
2013-07-01 16:00:21 +00:00
|
|
|
#if RPL_DAG_MC != RPL_DAG_MC_NONE
|
2011-02-15 00:13:30 +00:00
|
|
|
rpl_metric_container_t mc;
|
2013-07-01 16:00:21 +00:00
|
|
|
#endif /* RPL_DAG_MC != RPL_DAG_MC_NONE */
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_rank_t rank;
|
2015-05-06 09:35:42 +00:00
|
|
|
clock_time_t last_tx_time;
|
2010-06-06 21:42:50 +00:00
|
|
|
uint8_t dtsn;
|
2014-04-29 14:25:16 +00:00
|
|
|
uint8_t flags;
|
2010-04-30 13:43:53 +00:00
|
|
|
};
|
2010-05-25 21:58:54 +00:00
|
|
|
typedef struct rpl_parent rpl_parent_t;
|
2010-06-14 12:44:37 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
/* RPL DIO prefix suboption */
|
|
|
|
struct rpl_prefix {
|
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
uint32_t lifetime;
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t flags;
|
|
|
|
};
|
|
|
|
typedef struct rpl_prefix rpl_prefix_t;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Directed Acyclic Graph */
|
|
|
|
struct rpl_dag {
|
|
|
|
uip_ipaddr_t dag_id;
|
2012-02-29 20:59:50 +00:00
|
|
|
rpl_rank_t min_rank; /* should be reset per DAG iteration! */
|
2011-07-11 13:50:51 +00:00
|
|
|
uint8_t version;
|
|
|
|
uint8_t grounded;
|
|
|
|
uint8_t preference;
|
|
|
|
uint8_t used;
|
|
|
|
/* live data for the DAG */
|
|
|
|
uint8_t joined;
|
|
|
|
rpl_parent_t *preferred_parent;
|
|
|
|
rpl_rank_t rank;
|
|
|
|
struct rpl_instance *instance;
|
|
|
|
rpl_prefix_t prefix_info;
|
2015-09-30 07:39:44 +00:00
|
|
|
uint32_t lifetime;
|
2011-07-11 13:50:51 +00:00
|
|
|
};
|
|
|
|
typedef struct rpl_dag rpl_dag_t;
|
|
|
|
typedef struct rpl_instance rpl_instance_t;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-14 12:44:37 +00:00
|
|
|
/*
|
|
|
|
* API for RPL objective functions (OF)
|
|
|
|
*
|
|
|
|
* reset(dag)
|
|
|
|
*
|
|
|
|
* Resets the objective function state for a specific DAG. This function is
|
|
|
|
* called when doing a global repair on the DAG.
|
|
|
|
*
|
2013-07-29 19:50:33 +00:00
|
|
|
* neighbor_link_callback(parent, known, etx)
|
2010-06-14 12:44:37 +00:00
|
|
|
*
|
|
|
|
* Receives link-layer neighbor information. The parameter "known" is set
|
|
|
|
* either to 0 or 1. The "etx" parameter specifies the current
|
|
|
|
* ETX(estimated transmissions) for the neighbor.
|
|
|
|
*
|
|
|
|
* best_parent(parent1, parent2)
|
|
|
|
*
|
|
|
|
* Compares two parents and returns the best one, according to the OF.
|
|
|
|
*
|
2012-04-24 12:08:40 +00:00
|
|
|
* best_dag(dag1, dag2)
|
2011-07-11 13:50:51 +00:00
|
|
|
*
|
2012-04-24 12:08:40 +00:00
|
|
|
* Compares two DAGs and returns the best one, according to the OF.
|
2011-07-11 13:50:51 +00:00
|
|
|
*
|
2010-06-14 12:44:37 +00:00
|
|
|
* calculate_rank(parent, base_rank)
|
|
|
|
*
|
|
|
|
* Calculates a rank value using the parent rank and a base rank.
|
|
|
|
* If "parent" is NULL, the objective function selects a default increment
|
|
|
|
* that is adds to the "base_rank". Otherwise, the OF uses information known
|
|
|
|
* about "parent" to select an increment to the "base_rank".
|
2011-02-15 00:13:30 +00:00
|
|
|
*
|
|
|
|
* update_metric_container(dag)
|
|
|
|
*
|
|
|
|
* Updates the metric container for outgoing DIOs in a certain DAG.
|
|
|
|
* If the objective function of the DAG does not use metric containers,
|
2011-02-15 17:10:15 +00:00
|
|
|
* the function should set the object type to RPL_DAG_MC_NONE.
|
2010-06-14 12:44:37 +00:00
|
|
|
*/
|
2010-04-30 13:43:53 +00:00
|
|
|
struct rpl_of {
|
2011-02-11 15:21:17 +00:00
|
|
|
void (*reset)(struct rpl_dag *);
|
2013-07-29 19:50:33 +00:00
|
|
|
void (*neighbor_link_callback)(rpl_parent_t *, int, int);
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *);
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_dag_t *(*best_dag)(rpl_dag_t *, rpl_dag_t *);
|
2010-06-14 12:44:37 +00:00
|
|
|
rpl_rank_t (*calculate_rank)(rpl_parent_t *, rpl_rank_t);
|
2011-07-11 13:50:51 +00:00
|
|
|
void (*update_metric_container)( rpl_instance_t *);
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_ocp_t ocp;
|
|
|
|
};
|
|
|
|
typedef struct rpl_of rpl_of_t;
|
2014-03-27 15:00:32 +00:00
|
|
|
|
|
|
|
/* Declare the selected objective function. */
|
|
|
|
extern rpl_of_t RPL_OF;
|
2010-06-14 12:44:37 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 13:50:51 +00:00
|
|
|
/* Instance */
|
|
|
|
struct rpl_instance {
|
2010-04-30 13:43:53 +00:00
|
|
|
/* DAG configuration */
|
2011-02-15 00:13:30 +00:00
|
|
|
rpl_metric_container_t mc;
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_of_t *of;
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_dag_t *current_dag;
|
2012-02-29 20:59:50 +00:00
|
|
|
rpl_dag_t dag_table[RPL_MAX_DAG_PER_INSTANCE];
|
2010-06-14 12:44:37 +00:00
|
|
|
/* The current default router - used for routing "upwards" */
|
2010-04-30 13:43:53 +00:00
|
|
|
uip_ds6_defrt_t *def_route;
|
2011-07-13 08:28:56 +00:00
|
|
|
uint8_t instance_id;
|
|
|
|
uint8_t used;
|
2010-06-08 16:21:54 +00:00
|
|
|
uint8_t dtsn_out;
|
2010-12-13 10:54:25 +00:00
|
|
|
uint8_t mop;
|
2010-04-30 13:43:53 +00:00
|
|
|
uint8_t dio_intdoubl;
|
|
|
|
uint8_t dio_intmin;
|
|
|
|
uint8_t dio_redundancy;
|
2010-12-13 10:59:37 +00:00
|
|
|
uint8_t default_lifetime;
|
2010-04-30 13:43:53 +00:00
|
|
|
uint8_t dio_intcurrent;
|
2011-07-13 08:28:56 +00:00
|
|
|
uint8_t dio_send; /* for keeping track of which mode the timer is in */
|
2010-04-30 13:43:53 +00:00
|
|
|
uint8_t dio_counter;
|
2011-07-13 08:28:56 +00:00
|
|
|
rpl_rank_t max_rankinc;
|
|
|
|
rpl_rank_t min_hoprankinc;
|
|
|
|
uint16_t lifetime_unit; /* lifetime in seconds = l_u * d_l */
|
2010-04-30 13:43:53 +00:00
|
|
|
#if RPL_CONF_STATS
|
|
|
|
uint16_t dio_totint;
|
|
|
|
uint16_t dio_totsend;
|
|
|
|
uint16_t dio_totrecv;
|
|
|
|
#endif /* RPL_CONF_STATS */
|
2012-11-26 18:35:39 +00:00
|
|
|
clock_time_t dio_next_delay; /* delay for completion of dio interval */
|
2015-05-06 09:35:42 +00:00
|
|
|
#if RPL_WITH_PROBING
|
|
|
|
struct ctimer probing_timer;
|
|
|
|
#endif /* RPL_WITH_PROBING */
|
2010-04-30 13:43:53 +00:00
|
|
|
struct ctimer dio_timer;
|
|
|
|
struct ctimer dao_timer;
|
2013-11-20 13:02:38 +00:00
|
|
|
struct ctimer dao_lifetime_timer;
|
2010-04-30 13:43:53 +00:00
|
|
|
};
|
2011-07-11 13:50:51 +00:00
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-02-11 15:21:17 +00:00
|
|
|
/* Public RPL functions. */
|
|
|
|
void rpl_init(void);
|
2011-12-02 14:55:07 +00:00
|
|
|
void uip_rpl_input(void);
|
2014-06-11 22:59:17 +00:00
|
|
|
rpl_dag_t *rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id);
|
2011-11-21 14:09:19 +00:00
|
|
|
int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len);
|
2011-07-11 13:50:51 +00:00
|
|
|
int rpl_repair_root(uint8_t instance_id);
|
|
|
|
int rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from);
|
|
|
|
rpl_dag_t *rpl_get_any_dag(void);
|
|
|
|
rpl_instance_t *rpl_get_instance(uint8_t instance_id);
|
2014-01-31 08:38:42 +00:00
|
|
|
int rpl_update_header_empty(void);
|
2011-12-02 14:55:07 +00:00
|
|
|
int rpl_update_header_final(uip_ipaddr_t *addr);
|
|
|
|
int rpl_verify_header(int);
|
2013-07-31 20:39:00 +00:00
|
|
|
void rpl_insert_header(void);
|
2011-07-11 13:50:51 +00:00
|
|
|
void rpl_remove_header(void);
|
2011-12-02 14:55:07 +00:00
|
|
|
uint8_t rpl_invert_header(void);
|
2013-07-03 17:53:51 +00:00
|
|
|
uip_ipaddr_t *rpl_get_parent_ipaddr(rpl_parent_t *nbr);
|
2014-01-31 08:38:42 +00:00
|
|
|
rpl_parent_t *rpl_get_parent(uip_lladdr_t *addr);
|
2013-07-03 17:53:51 +00:00
|
|
|
rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr);
|
2013-11-16 13:42:57 +00:00
|
|
|
uint16_t rpl_get_parent_link_metric(const uip_lladdr_t *addr);
|
2013-08-11 21:50:37 +00:00
|
|
|
void rpl_dag_init(void);
|
2014-10-20 14:15:20 +00:00
|
|
|
uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent);
|
2015-05-06 09:34:52 +00:00
|
|
|
void rpl_print_neighbor_list();
|
2013-11-20 13:10:39 +00:00
|
|
|
|
2015-05-06 09:35:42 +00:00
|
|
|
/* Per-parent RPL information */
|
|
|
|
NBR_TABLE_DECLARE(rpl_parents);
|
|
|
|
|
2013-11-20 13:10:39 +00:00
|
|
|
/**
|
|
|
|
* RPL modes
|
|
|
|
*
|
|
|
|
* The RPL module can be in either of three modes: mesh mode
|
|
|
|
* (RPL_MODE_MESH), feater mode (RPL_MODE_FEATHER), and leaf mode
|
|
|
|
* (RPL_MODE_LEAF). In mesh mode, nodes forward data for other nodes,
|
|
|
|
* and are reachable by others. In feather mode, nodes can forward
|
|
|
|
* data for other nodes, but are not reachable themselves. In leaf
|
|
|
|
* mode, nodes do not forward data for others, but are reachable by
|
|
|
|
* others. */
|
|
|
|
enum rpl_mode {
|
|
|
|
RPL_MODE_MESH = 0,
|
|
|
|
RPL_MODE_FEATHER = 1,
|
|
|
|
RPL_MODE_LEAF = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the RPL mode
|
|
|
|
*
|
|
|
|
* \param mode The new RPL mode
|
|
|
|
* \retval The previous RPL mode
|
|
|
|
*/
|
|
|
|
enum rpl_mode rpl_set_mode(enum rpl_mode mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the RPL mode
|
|
|
|
*
|
|
|
|
* \retval The RPL mode
|
|
|
|
*/
|
|
|
|
enum rpl_mode rpl_get_mode(void);
|
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#endif /* RPL_H */
|