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

262 lines
7.2 KiB
C
Raw Normal View History

2012-01-19 17:35:50 +01:00
#include "sys/net/sixlowpan/sixlowip.h"
#ifndef RPL_STRUCTS_H_INCLUDED
#define RPL_STRUCTS_H_INCLUDED
2012-01-19 17:35:50 +01:00
// Modes of Operation
#define NO_DOWNWARD_ROUTES 0x00
#define NON_STORING_MODE 0x01
#define STORING_MODE_NO_MC 0x02
#define STORING_MODE_MC 0x03
//ICMP type
#define ICMP_RPL_CONTROL 155
#define RPL_SEQUENCE_WINDOW 16
#define ICMP_CODE_DIS 0x00
#define ICMP_CODE_DIO 0x01
#define ICMP_CODE_DAO 0x02
#define ICMP_CODE_DAO_ACK 0x03
//packet base lengths
#define DIO_BASE_LEN 24
#define DIS_BASE_LEN 2
#define DAO_BASE_LEN 4
#define DAO_D_LEN 24
#define DAO_ACK_LEN 4
#define DAO_ACK_D_LEN 24
#define RPL_OPT_LEN 2
#define RPL_OPT_DODAG_CONF_LEN 14
#define RPL_OPT_PREFIX_INFO_LEN 30
2012-02-16 23:23:15 +01:00
#define RPL_OPT_SOLICITED_INFO_LEN 19
#define RPL_OPT_TARGET_LEN 18
2012-02-26 19:30:48 +01:00
#define RPL_OPT_TRANSIT_LEN 4
2012-01-19 17:35:50 +01:00
//message options
#define RPL_OPT_PAD1 0
#define RPL_OPT_PADN 1
#define RPL_OPT_DAG_METRIC_CONTAINER 2
#define RPL_OPT_ROUTE_INFO 3
#define RPL_OPT_DODAG_CONF 4
#define RPL_OPT_TARGET 5
#define RPL_OPT_TRANSIT 6
#define RPL_OPT_SOLICITED_INFO 7
#define RPL_OPT_PREFIX_INFO 8
#define RPL_OPT_TARGET_DESC 9
//Counters
#define RPL_COUNTER_MAX 255
#define RPL_COUNTER_LOWER_REGION 127
#define RPL_COUNTER_SEQ_WINDOW 16
#define RPL_COUNTER_INIT RPL_COUNTER_MAX - RPL_COUNTER_SEQ_WINDOW + 1
#define RPL_COUNTER_INCREMENT(counter) (counter > RPL_COUNTER_LOWER_REGION ? (counter == RPL_COUNTER_MAX ? counter=0 : ++counter) : (counter == RPL_COUNTER_LOWER_REGION ? counter=0 : ++counter))
#define RPL_COUNTER_IS_INIT(counter) (counter > RPL_COUNTER_LOWER_REGION)
#define RPL_COUNTER_GREATER_THAN_LOCAL(A,B) (((A<B) && (RPL_COUNTER_LOWER_REGION + 1 - B + A < RPL_COUNTER_SEQ_WINDOW)) || ((A > B) && (A-B < RPL_COUNTER_SEQ_WINDOW)))
#define RPL_COUNTER_GREATER_THAN(A,B) ((A>RPL_COUNTER_LOWER_REGION) ? ((B > RPL_COUNTER_LOWER_REGION ) ? RPL_COUNTER_GREATER_THAN_LOCAL(A,B) : 0): (( B>RPL_COUNTER_LOWER_REGION ) ? 1: RPL_COUNTER_GREATER_THAN_LOCAL(A,B)))
// Default values
#define RPL_DEFAULT_MOP STORING_MODE_NO_MC
// RPL Constants and Variables
#define BASE_RANK 0
#define INFINITE_RANK 0xFFFF
#define RPL_DEFAULT_INSTANCE 0
#define DEFAULT_PATH_CONTROL_SIZE 0
#define DEFAULT_DIO_INTERVAL_MIN 11
//standard value:
2012-03-02 20:22:22 +01:00
//#define DEFAULT_DIO_INTERVAL_MIN 3
#define DEFAULT_DIO_INTERVAL_DOUBLINGS 7
//standard value:
//#define DEFAULT_DIO_INTERVAL_DOUBLINGS 20
2012-01-19 17:35:50 +01:00
#define DEFAULT_DIO_REDUNDANCY_CONSTANT 10
#define DEFAULT_MIN_HOP_RANK_INCREASE 256
#define ROOT_RANK DEFAULT_MIN_HOP_RANK_INCREASE
2012-02-16 23:23:15 +01:00
//DAO_DELAY is in seconds
#define DEFAULT_DAO_DELAY 3
#define REGULAR_DAO_INTERVAL 300
#define DAO_SEND_RETRIES 4
#define DEFAULT_WAIT_FOR_DAO_ACK 15
#define RPL_DODAG_ID_LEN 16
2012-01-19 17:35:50 +01:00
//others
#define NUMBER_IMPLEMENTED_OFS 2
2012-01-19 17:35:50 +01:00
#define RPL_MAX_DODAGS 3
#define RPL_MAX_INSTANCES 1
#define RPL_MAX_CANDIDATE_NEIGHBORS 15
2012-01-19 17:35:50 +01:00
#define RPL_MAX_PARENTS 5
#define RPL_MAX_ROUTING_ENTRIES 128
2012-01-19 17:35:50 +01:00
#define RPL_ROOT_RANK 1
#define RPL_DEFAULT_LIFETIME 0xff
#define RPL_LIFETIME_UNIT 2
2012-01-19 17:35:50 +01:00
#define RPL_GROUNDED 1
#define RPL_PRF_MASK 0x7
2012-01-19 17:35:50 +01:00
#define RPL_MOP_SHIFT 3
#define RPL_SHIFTED_MOP_MASK 0x7
2012-02-16 23:23:15 +01:00
#define RPL_DIS_V_MASK 0x80
#define RPL_DIS_I_MASK 0x40
#define RPL_DIS_D_MASK 0x20
#define RPL_GROUNDED_SHIFT 7
#define RPL_DEFAULT_OCP 0
2012-01-19 17:35:50 +01:00
//DIO Base Object (RFC 6550 Fig. 14)
2012-01-19 17:35:50 +01:00
struct __attribute__((packed)) rpl_dio_t{
uint8_t rpl_instanceid;
uint8_t version_number;
uint16_t rank;
uint8_t g_mop_prf;
uint8_t dtsn;
uint8_t flags;
2012-01-19 17:35:50 +01:00
uint8_t reserved;
ipv6_addr_t dodagid;
};
struct __attribute__((packed)) rpl_dis_t{
uint8_t flags;
uint8_t reserved;
};
//DAO Base Object (RFC 6550 Fig. 16)
2012-01-19 17:35:50 +01:00
struct __attribute__((packed)) rpl_dao_t{
uint8_t rpl_instanceid;
uint8_t k_d_flags;
uint8_t reserved;
uint8_t dao_sequence;
};
//DAO ACK Base Object (RFC 6550 Fig. 17.)
2012-01-19 17:35:50 +01:00
struct __attribute__((packed)) rpl_dao_ack_t{
uint8_t rpl_instanceid;
uint8_t d_reserved;
uint8_t dao_sequence;
uint8_t status;
};
//DODAG ID Struckt
2012-01-19 17:35:50 +01:00
//may be present in dao or dao_ack packets
struct __attribute__((packed)) dodag_id_t{
ipv6_addr_t dodagid;
};
//RPL-Option Generic Format (RFC 6550 Fig. 19)
2012-01-19 17:35:50 +01:00
typedef struct __attribute__((packed)) rpl_opt_t {
uint8_t type;
uint8_t length;
} rpl_opt_t;
//DODAG Configuration-Option (RFC 6550 Fig. 24)
2012-01-19 17:35:50 +01:00
typedef struct __attribute__((packed)) rpl_opt_dodag_conf_t {
uint8_t type;
uint8_t length;
uint8_t flags_a_pcs;
uint8_t DIOIntDoubl;
uint8_t DIOIntMin;
uint8_t DIORedun;
uint16_t MaxRankIncrease;
uint16_t MinHopRankIncrease;
uint16_t ocp;
uint8_t reserved;
uint8_t default_lifetime;
uint16_t lifetime_unit;
} rpl_opt_dodag_conf_t;
//RPL Solicited Information Option (RFC 6550 Fig. 28)
2012-02-16 23:23:15 +01:00
typedef struct __attribute__((packed)) rpl_opt_solicited_t {
uint8_t type;
uint8_t length;
uint8_t rplinstanceid;
uint8_t VID_Flags;
ipv6_addr_t dodagid;
uint8_t version;
} rpl_opt_solicited_t;
//RPL Target-Option (RFC 6550 Fig. 25)
2012-02-16 23:23:15 +01:00
//ipv6_addr_t target may be replaced by a target prefix of variable length
typedef struct __attribute__((packed)) rpl_opt_target_t {
uint8_t type;
uint8_t length;
uint8_t flags;
uint8_t prefix_length;
ipv6_addr_t target;
} rpl_opt_target_t;
//RPL Transit-Option (RFC 6550 Fig. 26)
2012-02-26 19:30:48 +01:00
typedef struct __attribute__((packed)) rpl_opt_transit_t {
uint8_t type;
uint8_t length;
uint8_t e_flags;
uint8_t path_control;
uint8_t path_sequence;
uint8_t path_lifetime;
} rpl_opt_transit_t;
2012-01-19 17:35:50 +01:00
struct rpl_dodag_t;
typedef struct rpl_candidate_neighbor_t {
ipv6_addr_t addr;
struct rpl_dodag_t *dodag;
uint8_t used;
} rpl_candidate_neighbor_t;
2012-01-19 17:35:50 +01:00
typedef struct rpl_parent_t {
ipv6_addr_t addr;
uint16_t rank;
2012-02-26 19:30:48 +01:00
uint8_t dtsn;
2012-01-19 17:35:50 +01:00
struct rpl_dodag_t *dodag;
uint16_t lifetime;
uint8_t used;
2012-01-19 17:35:50 +01:00
} rpl_parent_t;
typedef struct rpl_instance_t {
//struct rpl_dodag_t *current_dodoag;
2012-01-19 17:35:50 +01:00
uint8_t id;
uint8_t used;
uint8_t joined;
} rpl_instance_t;
typedef struct rpl_dodag_t {
rpl_instance_t *instance;
ipv6_addr_t dodag_id;
uint8_t used;
uint8_t mop;
uint8_t dtsn;
uint8_t prf;
2012-01-19 17:35:50 +01:00
uint8_t dio_interval_doubling;
uint8_t dio_min;
uint8_t dio_redundancy;
uint16_t maxrankincrease;
uint16_t minhoprankincrease;
2012-01-19 17:35:50 +01:00
uint8_t default_lifetime;
uint16_t lifetime_unit;
2012-01-19 17:35:50 +01:00
uint8_t version;
uint8_t grounded;
uint16_t my_rank;
uint8_t dao_seq;
uint16_t min_rank;
2012-01-19 17:35:50 +01:00
uint8_t joined;
rpl_parent_t *my_preferred_parent;
struct rpl_of_t *of;
} rpl_dodag_t;
typedef struct rpl_of_t {
uint16_t ocp;
uint16_t (*calc_rank)();
2012-01-19 17:35:50 +01:00
rpl_parent_t *(*which_parent)(rpl_parent_t *, rpl_parent_t *);
rpl_dodag_t *(*which_dodag)(rpl_dodag_t *, rpl_dodag_t *);
void (*reset)(struct rpl_dodag_t *);
void (*parent_state_callback)(rpl_parent_t *, int, int);
void (*init) (void); //OF specific init function
void (*process_dio) (); //DIO processing callback (acc. to OF0 spec, chpt 5)
2012-01-19 17:35:50 +01:00
} rpl_of_t;
typedef struct rpl_routing_entry_t {
uint8_t used;
ipv6_addr_t address;
ipv6_addr_t next_hop;
uint16_t lifetime;
} rpl_routing_entry_t;
#endif