1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/net/gnrc/rpl/structs.h

300 lines
11 KiB
C
Raw Normal View History

2015-05-22 21:47:37 +02:00
/*
* Copyright (C) 2013 INRIA.
* Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
*
* 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.
*/
/**
* @ingroup net_gnrc_rpl
2015-05-22 21:47:37 +02:00
* @{
*
* @file
* @brief RPL data structs
*
* Header file, which defines all structs used by RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/
#ifndef GNRC_RPL_STRUCTS_H
#define GNRC_RPL_STRUCTS_H
2015-05-22 21:47:37 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2016-03-22 17:35:14 +01:00
#include "net/gnrc/ipv6/netif.h"
#include "net/ipv6/addr.h"
2015-09-04 13:19:19 +02:00
#include "xtimer.h"
2015-05-22 21:47:37 +02:00
#include "trickle.h"
/**
* @name Option lengths
* @{
*/
#define GNRC_RPL_OPT_DODAG_CONF_LEN (14)
#define GNRC_RPL_OPT_PREFIX_INFO_LEN (30)
#define GNRC_RPL_OPT_TARGET_LEN (18)
#define GNRC_RPL_OPT_TRANSIT_INFO_LEN (4)
/** @} */
/**
* @name DAO flag macros
* @{
*/
#define GNRC_RPL_DAO_D_BIT (1 << 6)
#define GNRC_RPL_DAO_K_BIT (1 << 7)
/** @} */
/**
* @name DAO-ACK flag macros
* @{
*/
#define GNRC_RPL_DAO_ACK_D_BIT (1 << 7)
/** @} */
/**
2016-03-15 15:17:46 +01:00
* @anchor GNRC_RPL_REQ_DIO_OPTS
* @name DIO Options for gnrc_rpl_dodag_t::dio_opts
* @{
*/
2016-03-15 15:17:46 +01:00
#define GNRC_RPL_REQ_DIO_OPT_DODAG_CONF_SHIFT (0)
#define GNRC_RPL_REQ_DIO_OPT_DODAG_CONF (1 << GNRC_RPL_REQ_DIO_OPT_DODAG_CONF_SHIFT)
#define GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT (1)
#define GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO (1 << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT)
/** @} */
2015-05-22 21:47:37 +02:00
/**
* @brief RPL-Option Generic Format
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.1">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.7.1, RPL Control Message Option Generic Format
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< Option Type */
uint8_t length; /**< Option Length, does not include the first two byte */
} gnrc_rpl_opt_t;
2015-05-22 21:47:37 +02:00
/**
* @brief DIO Base Object
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.3.1">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.3.1, Format of the DIO Base Object
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t instance_id; /**< id of the instance */
uint8_t version_number; /**< version number of the DODAG */
network_uint16_t rank; /**< rank of the parent emitting the DIO */
uint8_t g_mop_prf; /**< grounded, MOP, preferred flags */
uint8_t dtsn; /**< Destination Advertisement Trigger Sequence Number */
uint8_t flags; /**< unused */
uint8_t reserved; /**< reserved */
ipv6_addr_t dodag_id; /**< id of the dodag */
} gnrc_rpl_dio_t;
2015-05-22 21:47:37 +02:00
/**
* @brief DODAG Configuration Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.6">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.7.6, DODAG Configuration
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< Option Type: 0x04 */
uint8_t length; /**< length of option, not including first two bytes */
uint8_t flags_a_pcs; /**< flags */
uint8_t dio_int_doubl; /**< trickle Imax parameter */
uint8_t dio_int_min; /**< trickle Imin parameter */
uint8_t dio_redun; /**< trickle k parameter */
network_uint16_t max_rank_inc; /**< allowable increase in rank */
network_uint16_t min_hop_rank_inc; /**< DAGRank(rank) = floor(rank/MinHopRankIncrease) */
network_uint16_t ocp; /**< Objective Code Point */
uint8_t reserved; /**< reserved */
uint8_t default_lifetime; /**< lifetime of RPL routes (lifetime * lifetime_unit) */
network_uint16_t lifetime_unit; /**< unit in seconds */
} gnrc_rpl_opt_dodag_conf_t;
2015-05-22 21:47:37 +02:00
/**
* @brief DODAG Information Solicitation
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.2">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.2, DODAG Information Solicitation
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t flags; /**< unused */
uint8_t reserved; /**< reserved */
} gnrc_rpl_dis_t;
2015-05-22 21:47:37 +02:00
/**
* @brief Destination Advertisement Object
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.4">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.4, Destination Advertisement Object
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t instance_id; /**< id of the instance */
uint8_t k_d_flags; /**< K and D flags */
uint8_t reserved; /**< reserved */
uint8_t dao_sequence; /**< sequence of the DAO, needs to be used for DAO-ACK */
} gnrc_rpl_dao_t;
2015-05-22 21:47:37 +02:00
/**
* @brief Destination Advertisement Object Acknowledgement
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.5">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.5, Destination Advertisement Object Acknowledgement
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t instance_id; /**< id of the instance */
uint8_t d_reserved; /**< if set, indicates that the DODAG id should be included */
uint8_t dao_sequence; /**< sequence must be equal to the sequence from the DAO object */
uint8_t status; /**< indicates completion */
} gnrc_rpl_dao_ack_t;
2015-05-22 21:47:37 +02:00
/**
* @brief Target Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.7">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.7.7, RPL Target
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t flags; /**< unused */
uint8_t prefix_length; /**< number of valid leading bits in the IPv6 prefix */
ipv6_addr_t target; /**< IPv6 prefix, address or multicast group */
} gnrc_rpl_opt_target_t;
2015-05-22 21:47:37 +02:00
/**
* @brief Transit Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.8">
2015-08-18 19:07:15 +02:00
* RFC6550, section 6.7.8, Transit Information
2015-05-22 21:47:37 +02:00
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t e_flags; /**< external flag indicates external routes */
uint8_t path_control; /**< limits the number of DAO parents */
uint8_t path_sequence; /**< increased value for route updates */
uint8_t path_lifetime; /**< lifetime of routes */
} gnrc_rpl_opt_transit_t;
2015-05-22 21:47:37 +02:00
2015-07-23 13:23:42 +02:00
/**
* @brief Prefix Information Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.10">
* RFC6550, section 6.7.10, Prefix Information
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t prefix_len; /**< prefix length */
uint8_t LAR_flags; /**< flags and resereved */
uint32_t valid_lifetime; /**< valid lifetime */
uint32_t pref_lifetime; /**< preferred lifetime */
uint32_t reserved; /**< reserved */
ipv6_addr_t prefix; /**< prefix used for Stateless Address Autoconfiguration */
} gnrc_rpl_opt_prefix_info_t;
2015-07-23 13:23:42 +02:00
/**
* @brief DODAG representation
*/
typedef struct gnrc_rpl_dodag gnrc_rpl_dodag_t;
2015-05-22 21:47:37 +02:00
/**
* @brief Parent representation
*/
typedef struct gnrc_rpl_parent gnrc_rpl_parent_t;
/**
* @brief Instance representation
*/
typedef struct gnrc_rpl_instance gnrc_rpl_instance_t;
/**
* @cond INTERNAL */
struct gnrc_rpl_parent {
2015-09-04 13:19:19 +02:00
gnrc_rpl_parent_t *next; /**< pointer to the next parent */
2015-05-22 21:47:37 +02:00
uint8_t state; /**< 0 for unsued, 1 for used */
ipv6_addr_t addr; /**< link-local IPv6 address of this parent */
uint8_t dtsn; /**< last seen dtsn of this parent */
uint16_t rank; /**< rank of the parent */
2015-09-04 13:19:19 +02:00
gnrc_rpl_dodag_t *dodag; /**< DODAG the parent belongs to */
uint32_t lifetime; /**< lifetime of this parent in seconds */
2015-05-22 21:47:37 +02:00
double link_metric; /**< metric of the link */
uint8_t link_metric_type; /**< type of the metric */
};
/**
* @endcond
*/
2015-05-22 21:47:37 +02:00
/**
* @brief Objective function representation
*/
typedef struct {
uint16_t ocp; /**< objective code point */
uint16_t (*calc_rank)(gnrc_rpl_parent_t *parent, uint16_t base_rank); /**< calculate the rank */
gnrc_rpl_parent_t *(*which_parent)(gnrc_rpl_parent_t *, gnrc_rpl_parent_t *); /**< compare for parents */
gnrc_rpl_dodag_t *(*which_dodag)(gnrc_rpl_dodag_t *, gnrc_rpl_dodag_t *); /**< compare for dodags */
void (*reset)(gnrc_rpl_dodag_t *); /**< resets the OF */
void (*parent_state_callback)(gnrc_rpl_parent_t *, int, int); /**< retrieves the state of a parent*/
2015-05-22 21:47:37 +02:00
void (*init)(void); /**< OF specific init function */
void (*process_dio)(void); /**< DIO processing callback (acc. to OF0 spec, chpt 5) */
} gnrc_rpl_of_t;
2015-05-22 21:47:37 +02:00
/**
* @cond INTERNAL
2015-05-22 21:47:37 +02:00
*/
struct gnrc_rpl_dodag {
2015-05-22 21:47:37 +02:00
ipv6_addr_t dodag_id; /**< id of the DODAG */
2016-03-22 17:35:14 +01:00
gnrc_ipv6_netif_addr_t *netif_addr; /**< netif address for this DODAG */
gnrc_rpl_parent_t *parents; /**< pointer to the parents list of this DODAG */
gnrc_rpl_instance_t *instance; /**< pointer to the instance that this dodag is part of */
2015-05-22 21:47:37 +02:00
uint8_t dtsn; /**< DAO Trigger Sequence Number */
uint8_t prf; /**< preferred flag */
uint8_t dio_interval_doubl; /**< trickle Imax parameter */
uint8_t dio_min; /**< trickle Imin parameter */
uint8_t dio_redun; /**< trickle k parameter */
uint8_t default_lifetime; /**< lifetime of routes (lifetime * unit) */
uint16_t lifetime_unit; /**< unit in seconds of the lifetime */
2016-03-22 14:58:23 +01:00
kernel_pid_t iface; /**< interface PID this DODAG operates on */
2015-05-22 21:47:37 +02:00
uint8_t version; /**< version of this DODAG */
uint8_t grounded; /**< grounded flag */
uint16_t my_rank; /**< rank/position in the DODAG */
uint8_t node_status; /**< leaf, normal, or root node */
uint8_t dao_seq; /**< dao sequence number */
uint8_t dao_counter; /**< amount of retried DAOs */
bool dao_ack_received; /**< flag to check for DAO-ACK */
2016-03-15 15:17:46 +01:00
uint8_t dio_opts; /**< options in the next DIO
(see @ref GNRC_RPL_REQ_DIO_OPTS "DIO Options") */
2015-11-17 19:53:26 +01:00
uint8_t dao_time; /**< time to schedule a DAO in seconds */
2015-05-22 21:47:37 +02:00
trickle_t trickle; /**< trickle representation */
};
struct gnrc_rpl_instance {
uint8_t id; /**< id of the instance */
uint8_t state; /**< 0 for unused, 1 for used */
gnrc_rpl_dodag_t dodag; /**< DODAG of this instance */
uint8_t mop; /**< configured Mode of Operation */
gnrc_rpl_of_t *of; /**< configured Objective Function */
uint16_t min_hop_rank_inc; /**< minimum hop rank increase */
uint16_t max_rank_inc; /**< max increase in the rank */
2015-11-17 14:39:32 +01:00
int8_t cleanup; /**< cleanup time in seconds */
};
/**
* @endcond
*/
2015-05-22 21:47:37 +02:00
#ifdef __cplusplus
}
#endif
#endif /* GNRC_RPL_STRUCTS_H */
2015-05-22 21:47:37 +02:00
/**
* @}
*/