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.
|
|
|
|
*
|
|
|
|
* Author: Joakim Eriksson, Nicolas Tsiftes
|
|
|
|
*
|
2010-06-12 10:55:46 +00:00
|
|
|
* $Id: rpl.h,v 1.17 2010/06/12 10:55:46 joxe Exp $
|
2010-04-30 13:43:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RPL_H
|
|
|
|
#define RPL_H
|
|
|
|
|
2010-06-01 22:30:02 +00:00
|
|
|
/*
|
|
|
|
* ContikiRPL - an implementation of the routing protocol for low power and
|
2010-06-12 10:55:46 +00:00
|
|
|
* lossy networks. See: draft-ietf-roll-rpl-09.
|
2010-06-01 22:30:02 +00:00
|
|
|
*
|
|
|
|
* --
|
|
|
|
* The DIOs handle prefix information option for setting global IP addresses
|
|
|
|
* on the nodes, but the current handling is not awaiting the join of the DAG
|
|
|
|
* so it does not currently support multiple DAGs.
|
|
|
|
*/
|
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
#include "lib/list.h"
|
|
|
|
#include "net/uip.h"
|
|
|
|
#include "sys/clock.h"
|
|
|
|
#include "net/rime/ctimer.h"
|
|
|
|
#include "net/uip-ds6.h"
|
|
|
|
|
|
|
|
/* set to 1 for some statistics on trickle / DIO */
|
|
|
|
#ifndef RPL_CONF_STATS
|
|
|
|
#define RPL_CONF_STATS 1
|
|
|
|
#endif /* RPL_CONF_STATS */
|
|
|
|
|
|
|
|
/* The RPL Codes for the message types */
|
2010-06-01 22:30:02 +00:00
|
|
|
#define RPL_CODE_DIS 0 /* DIS message */
|
|
|
|
#define RPL_CODE_DIO 1 /* DIO message */
|
|
|
|
#define RPL_CODE_DAO 2 /* DAO message */
|
|
|
|
#define RPL_CODE_DAO_ACK 3 /* DAO ACK message */
|
|
|
|
|
|
|
|
#define RPL_CODE_SEC_DIS 0x80 /* DIS message */
|
|
|
|
#define RPL_CODE_SEC_DIO 0x81 /* DIO message */
|
|
|
|
#define RPL_CODE_SEC_DAO 0x82 /* DAO message */
|
|
|
|
#define RPL_CODE_SEC_DAO_ACK 0x83 /* DAO ACK message */
|
2010-04-30 13:43:53 +00:00
|
|
|
|
2010-06-03 14:49:15 +00:00
|
|
|
/* RPL DIO/DAO suboption types */
|
2010-04-30 13:43:53 +00:00
|
|
|
#define RPL_DIO_SUBOPT_PAD1 0 /* Pad1 */
|
|
|
|
#define RPL_DIO_SUBOPT_PADN 1 /* PadN */
|
|
|
|
#define RPL_DIO_SUBOPT_DAG_MC 2 /* DAG metric container */
|
2010-06-01 22:30:02 +00:00
|
|
|
#define RPL_DIO_SUBOPT_ROUTE_INFO 3 /* Route information */
|
2010-04-30 13:43:53 +00:00
|
|
|
#define RPL_DIO_SUBOPT_DAG_CONF 4 /* DAG configuration */
|
2010-06-01 22:30:02 +00:00
|
|
|
#define RPL_DIO_SUBOPT_TARGET 5 /* Target */
|
|
|
|
#define RPL_DIO_SUBOPT_TRANSIT 6 /* Transit information */
|
|
|
|
#define RPL_DIO_SUBOPT_SOLICITED_INFO 7 /* Solicited information */
|
|
|
|
#define RPL_DIO_SUBOPT_PREFIX_INFO 8 /* Prefix information option */
|
|
|
|
|
2010-06-03 14:49:15 +00:00
|
|
|
#define RPL_DAO_K_FLAG 0x80 /* DAO ACK requested */
|
|
|
|
#define RPL_DAO_D_FLAG 0x40 /* DODAG ID Present */
|
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Default values for RPL constants and variables. */
|
|
|
|
|
2010-06-06 21:48:15 +00:00
|
|
|
#define DEFAULT_DAO_LATENCY (CLOCK_SECOND * (1 + (random_rand() & 0xf)))
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
/* Special value indicating immediate removal. */
|
|
|
|
#define ZERO_LIFETIME 0
|
|
|
|
|
|
|
|
/* Special value indicating that a DAO should not expire. */
|
|
|
|
#define INFINITE_LIFETIME 0xffffffff
|
|
|
|
|
|
|
|
/* Default route lifetime in seconds. */
|
|
|
|
#define DEFAULT_ROUTE_LIFETIME INFINITE_LIFETIME
|
|
|
|
|
|
|
|
/* Rank of a node outside the LLN. */
|
|
|
|
#define BASE_RANK 0
|
|
|
|
|
|
|
|
/* Rank of a root node. */
|
|
|
|
#define ROOT_RANK 1
|
|
|
|
|
|
|
|
#define INFINITE_RANK 0xffff
|
|
|
|
|
|
|
|
#define RPL_DEFAULT_INSTANCE 0
|
|
|
|
#define RPL_ANY_INSTANCE -1
|
|
|
|
|
2010-05-29 22:23:21 +00:00
|
|
|
#define RPL_DEFAULT_OCP 1
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
/* TODO: pick these from OCP later? */
|
|
|
|
#define DEFAULT_MAX_RANKINC 16
|
|
|
|
#define DEFAULT_MIN_HOPRANKINC 4
|
|
|
|
|
|
|
|
/* Represents 2^n ms. */
|
2010-04-30 15:03:55 +00:00
|
|
|
#define DEFAULT_DIO_INTERVAL_MIN 12
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
/* Maximum amount of timer doublings. */
|
|
|
|
#define DEFAULT_DIO_INTERVAL_DOUBLINGS 8
|
|
|
|
|
|
|
|
/* Desired DIO redundancy. */
|
|
|
|
#define DEFAULT_DIO_REDUNDANCY 1
|
|
|
|
|
|
|
|
/* Expire DAOs from neighbors that do not respond in this time. (seconds) */
|
|
|
|
#define DAO_EXPIRATION_TIMEOUT 60
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-03 14:49:15 +00:00
|
|
|
#define RPL_INSTANCE_LOCAL_FLAG 0x80
|
|
|
|
#define RPL_INSTANCE_D_FLAG 0x40
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
#define RPL_ROUTE_FROM_INTERNAL 0
|
|
|
|
#define RPL_ROUTE_FROM_UNICAST_DAO 1
|
|
|
|
#define RPL_ROUTE_FROM_MULTICAST_DAO 2
|
|
|
|
#define RPL_ROUTE_FROM_DIO 3
|
|
|
|
|
|
|
|
/* DAG Metric Container Object Types, to be confirmed by IANA. */
|
|
|
|
#define RPL_DAG_MC_NSA 1
|
|
|
|
#define RPL_DAG_MC_NE 2
|
|
|
|
#define RPL_DAG_MC_HC 3
|
|
|
|
#define RPL_DAG_MC_THROUGHPUT 4
|
|
|
|
#define RPL_DAG_MC_LATENCY 5
|
|
|
|
#define RPL_DAG_MC_LQL 6
|
|
|
|
#define RPL_DAG_MC_ETX 7
|
|
|
|
#define RPL_DAG_MC_LC 8
|
|
|
|
|
|
|
|
/* DIS related */
|
|
|
|
#define RPL_DIS_SEND 1
|
|
|
|
#define RPL_DIS_INTERVAL 60
|
|
|
|
#define RPL_DIS_START_DELAY 5
|
|
|
|
|
|
|
|
typedef uint16_t rpl_rank_t;
|
|
|
|
typedef uint16_t rpl_ocp_t;
|
|
|
|
|
2010-05-25 21:58:54 +00:00
|
|
|
struct rpl_parent {
|
|
|
|
struct rpl_parent *next;
|
2010-04-30 13:43:53 +00:00
|
|
|
void *dag;
|
|
|
|
uip_ipaddr_t addr;
|
|
|
|
rpl_rank_t rank;
|
|
|
|
uint8_t local_confidence;
|
2010-06-06 21:42:50 +00:00
|
|
|
uint8_t dtsn;
|
2010-04-30 13:43:53 +00:00
|
|
|
};
|
|
|
|
|
2010-05-25 21:58:54 +00:00
|
|
|
typedef struct rpl_parent rpl_parent_t;
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
struct rpl_of {
|
2010-05-31 14:22:00 +00:00
|
|
|
void (*reset)(void *);
|
2010-05-29 22:23:21 +00:00
|
|
|
void (*parent_state_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 *);
|
2010-06-02 16:23:08 +00:00
|
|
|
|
|
|
|
/* Increment the rank - the rank that just have been received in a DIO
|
|
|
|
(or if picked from a parent) is the first argument. This is considered
|
|
|
|
the valid rank to calculate based on. The second argument is the parent
|
|
|
|
that is related to this calculation - if any (can be NULL) */
|
|
|
|
rpl_rank_t (*increment_rank)(rpl_rank_t rank, rpl_parent_t *parent);
|
2010-04-30 13:43:53 +00:00
|
|
|
rpl_ocp_t ocp;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct rpl_of rpl_of_t;
|
|
|
|
|
2010-05-25 19:19:43 +00:00
|
|
|
/* RPL DIO prefix suboption */
|
|
|
|
struct rpl_prefix {
|
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
uint32_t lifetime;
|
|
|
|
uint8_t length;
|
2010-06-01 22:30:02 +00:00
|
|
|
uint8_t flags;
|
2010-05-25 19:19:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct rpl_prefix rpl_prefix_t;
|
|
|
|
|
2010-04-30 13:43:53 +00:00
|
|
|
/* Logical representation of a DAG Information Object (DIO.) */
|
|
|
|
struct rpl_dio {
|
|
|
|
uip_ipaddr_t dag_id;
|
|
|
|
rpl_ocp_t ocp;
|
|
|
|
rpl_rank_t dag_rank;
|
|
|
|
uint8_t grounded;
|
|
|
|
uint8_t dst_adv_trigger;
|
|
|
|
uint8_t dst_adv_supported;
|
|
|
|
uint8_t preference;
|
2010-06-01 22:30:02 +00:00
|
|
|
uint8_t version;
|
2010-04-30 13:43:53 +00:00
|
|
|
uint8_t instance_id;
|
|
|
|
uint8_t dtsn;
|
|
|
|
uint8_t dag_intdoubl;
|
|
|
|
uint8_t dag_intmin;
|
|
|
|
uint8_t dag_redund;
|
|
|
|
uint8_t dag_max_rankinc;
|
|
|
|
uint8_t dag_min_hoprankinc;
|
2010-05-25 19:19:43 +00:00
|
|
|
rpl_prefix_t destination_prefix;
|
2010-06-01 22:30:02 +00:00
|
|
|
rpl_prefix_t prefix_info;
|
2010-04-30 13:43:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct rpl_dio rpl_dio_t;
|
|
|
|
|
|
|
|
/* Directed Acyclic Graph */
|
|
|
|
struct rpl_dag {
|
|
|
|
/* DAG configuration */
|
|
|
|
rpl_of_t *of;
|
|
|
|
uip_ipaddr_t dag_id;
|
|
|
|
/* this is the current def-router that is set - used for routing "upwards" */
|
|
|
|
uip_ds6_defrt_t *def_route;
|
|
|
|
rpl_rank_t rank;
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_rank_t min_rank; /* should be reset per DODAG iteration! */
|
2010-06-08 16:21:54 +00:00
|
|
|
uint8_t dtsn_out;
|
2010-04-30 13:43:53 +00:00
|
|
|
uint8_t instance_id;
|
2010-06-02 11:59:51 +00:00
|
|
|
uint8_t version;
|
2010-04-30 13:43:53 +00:00
|
|
|
uint8_t preference;
|
|
|
|
uint8_t grounded;
|
|
|
|
uint8_t dio_intdoubl;
|
|
|
|
uint8_t dio_intmin;
|
|
|
|
uint8_t dio_redundancy;
|
|
|
|
uint8_t max_rankinc;
|
|
|
|
uint8_t min_hoprankinc;
|
|
|
|
uint8_t used;
|
|
|
|
|
|
|
|
/* live data for the DAG */
|
|
|
|
uint8_t joined;
|
|
|
|
uint8_t dio_intcurrent;
|
|
|
|
uint8_t dio_send; /* for keeping track of which mode the timer is in */
|
|
|
|
uint8_t dio_counter;
|
|
|
|
#if RPL_CONF_STATS
|
|
|
|
uint16_t dio_totint;
|
|
|
|
uint16_t dio_totsend;
|
|
|
|
uint16_t dio_totrecv;
|
|
|
|
#endif /* RPL_CONF_STATS */
|
|
|
|
uint16_t dio_next_delay; /* delay for completion of dio interval */
|
|
|
|
struct ctimer dio_timer;
|
|
|
|
struct ctimer dao_timer;
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *best_parent;
|
|
|
|
void *parent_list;
|
|
|
|
list_t parents;
|
2010-06-01 22:30:02 +00:00
|
|
|
rpl_prefix_t prefix_info;
|
2010-04-30 13:43:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct rpl_dag rpl_dag_t;
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* RPL macro functions. */
|
2010-05-25 21:58:54 +00:00
|
|
|
#define RPL_PARENT_COUNT(dag) list_length((dag)->parents)
|
2010-04-30 13:43:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* ICMPv6 functions for RPL. */
|
|
|
|
void dis_output(uip_ipaddr_t *addr);
|
|
|
|
void dio_output(rpl_dag_t *, uip_ipaddr_t *uc_addr);
|
2010-05-25 21:58:54 +00:00
|
|
|
void dao_output(rpl_parent_t *, uint32_t lifetime);
|
2010-06-06 21:42:50 +00:00
|
|
|
void dao_ack_output(rpl_dag_t *, uip_ipaddr_t *, uint8_t);
|
2010-04-30 13:43:53 +00:00
|
|
|
void uip_rpl_input(void);
|
|
|
|
|
|
|
|
/* RPL logic functions. */
|
2010-05-29 22:23:21 +00:00
|
|
|
rpl_dag_t *rpl_set_root(uip_ipaddr_t *);
|
2010-05-25 19:19:43 +00:00
|
|
|
int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, int len);
|
2010-04-30 13:43:53 +00:00
|
|
|
int rpl_repair_dag(rpl_dag_t *dag);
|
|
|
|
int rpl_set_default_route(rpl_dag_t *dag, uip_ipaddr_t *from);
|
|
|
|
void rpl_process_dio(uip_ipaddr_t *, rpl_dio_t *);
|
|
|
|
|
|
|
|
/* DAG allocation and deallocation. */
|
2010-06-08 21:41:02 +00:00
|
|
|
rpl_dag_t *rpl_alloc_dag(uint8_t);
|
2010-04-30 13:43:53 +00:00
|
|
|
void rpl_free_dag(rpl_dag_t *);
|
|
|
|
|
|
|
|
/* DAG parent management function. */
|
2010-06-02 16:54:59 +00:00
|
|
|
rpl_parent_t *rpl_add_parent(rpl_dag_t *, rpl_dio_t *dio, uip_ipaddr_t *);
|
2010-05-25 21:58:54 +00:00
|
|
|
rpl_parent_t *rpl_find_parent(rpl_dag_t *, uip_ipaddr_t *);
|
|
|
|
int rpl_remove_parent(rpl_dag_t *, rpl_parent_t *);
|
|
|
|
rpl_parent_t *rpl_preferred_parent(rpl_dag_t *dag);
|
2010-04-30 13:43:53 +00:00
|
|
|
|
|
|
|
void rpl_join_dag(rpl_dag_t *);
|
|
|
|
rpl_dag_t *rpl_get_dag(int instance_id);
|
|
|
|
rpl_dag_t *rpl_find_dag(unsigned char aucIndex);
|
|
|
|
|
|
|
|
/* RPL routing table functions. */
|
2010-06-03 15:20:56 +00:00
|
|
|
void rpl_remove_routes(rpl_dag_t *dag);
|
2010-04-30 13:43:53 +00:00
|
|
|
uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix,
|
|
|
|
int prefix_len, uip_ipaddr_t *next_hop);
|
|
|
|
void rpl_purge_routes(void);
|
|
|
|
|
|
|
|
/* Objective function. */
|
|
|
|
rpl_of_t *rpl_find_of(rpl_ocp_t);
|
|
|
|
|
|
|
|
/* Timer functions. */
|
|
|
|
void rpl_schedule_dao(rpl_dag_t *);
|
|
|
|
void rpl_reset_dio_timer(rpl_dag_t *, uint8_t);
|
|
|
|
void rpl_reset_periodic_timer(void);
|
|
|
|
|
|
|
|
/* Route poisoning. */
|
2010-05-25 21:58:54 +00:00
|
|
|
void rpl_poison_routes(rpl_dag_t *, rpl_parent_t *);
|
2010-04-30 13:43:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void rpl_init(void);
|
|
|
|
|
|
|
|
#endif /* RPL_H */
|