47 #include "net/rpl/rpl.h"
51 #include "sys/clock.h"
57 #define uip_is_addr_linklocal_rplnodes_mcast(a) \
58 ((((a)->u8[0]) == 0xff) && \
59 (((a)->u8[1]) == 0x02) && \
60 (((a)->u16[1]) == 0) && \
61 (((a)->u16[2]) == 0) && \
62 (((a)->u16[3]) == 0) && \
63 (((a)->u16[4]) == 0) && \
64 (((a)->u16[5]) == 0) && \
65 (((a)->u16[6]) == 0) && \
66 (((a)->u8[14]) == 0) && \
67 (((a)->u8[15]) == 0x1a))
70 #define uip_create_linklocal_rplnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x001a)
73 #define RPL_CODE_DIS 0x00
74 #define RPL_CODE_DIO 0x01
75 #define RPL_CODE_DAO 0x02
76 #define RPL_CODE_DAO_ACK 0x03
77 #define RPL_CODE_SEC_DIS 0x80
78 #define RPL_CODE_SEC_DIO 0x81
79 #define RPL_CODE_SEC_DAO 0x82
80 #define RPL_CODE_SEC_DAO_ACK 0x83
83 #define RPL_OPTION_PAD1 0
84 #define RPL_OPTION_PADN 1
85 #define RPL_OPTION_DAG_METRIC_CONTAINER 2
86 #define RPL_OPTION_ROUTE_INFO 3
87 #define RPL_OPTION_DAG_CONF 4
88 #define RPL_OPTION_TARGET 5
89 #define RPL_OPTION_TRANSIT 6
90 #define RPL_OPTION_SOLICITED_INFO 7
91 #define RPL_OPTION_PREFIX_INFO 8
92 #define RPL_OPTION_TARGET_DESC 9
94 #define RPL_DAO_K_FLAG 0x80
95 #define RPL_DAO_D_FLAG 0x40
100 #define DEFAULT_DAO_LATENCY (CLOCK_SECOND * 8)
103 #define ZERO_LIFETIME 0
106 #define RPL_DEFAULT_LIFETIME_UNIT 0xffff
109 #define RPL_DEFAULT_LIFETIME 0xff
111 #define RPL_LIFETIME(dag, lifetime) \
112 ((unsigned long)(dag)->lifetime_unit * lifetime)
114 #ifndef RPL_CONF_MIN_HOPRANKINC
115 #define DEFAULT_MIN_HOPRANKINC 256
117 #define DEFAULT_MIN_HOPRANKINC RPL_CONF_MIN_HOPRANKINC
119 #define DEFAULT_MAX_RANKINC (3 * DEFAULT_MIN_HOPRANKINC)
121 #define DAG_RANK(fixpt_rank, dag) ((fixpt_rank) / (dag)->min_hoprankinc)
127 #define ROOT_RANK(dag) (dag)->min_hoprankinc
129 #define INFINITE_RANK 0xffff
131 #define INITIAL_LINK_METRIC NEIGHBOR_INFO_ETX2FIX(5)
137 #ifdef RPL_CONF_DIO_INTERVAL_MIN
138 #define DEFAULT_DIO_INTERVAL_MIN RPL_CONF_DIO_INTERVAL_MIN
140 #define DEFAULT_DIO_INTERVAL_MIN 12
144 #ifdef RPL_CONF_DIO_INTERVAL_DOUBLINGS
145 #define DEFAULT_DIO_INTERVAL_DOUBLINGS RPL_CONF_DIO_INTERVAL_DOUBLINGS
147 #define DEFAULT_DIO_INTERVAL_DOUBLINGS 8
151 #ifdef RPL_CONF_DIO_REDUNDANCY
152 #define DEFAULT_DIO_REDUNDANCY RPL_CONF_DIO_REDUNDANCY
154 #define DEFAULT_DIO_REDUNDANCY 10
158 #define DAO_EXPIRATION_TIMEOUT 60
160 #define RPL_INSTANCE_LOCAL_FLAG 0x80
161 #define RPL_INSTANCE_D_FLAG 0x40
164 #define RPL_ROUTE_FROM_INTERNAL 0
165 #define RPL_ROUTE_FROM_UNICAST_DAO 1
166 #define RPL_ROUTE_FROM_MULTICAST_DAO 2
167 #define RPL_ROUTE_FROM_DIO 3
170 #define RPL_MOP_NO_DOWNWARD_ROUTES 0
171 #define RPL_MOP_NON_STORING 1
172 #define RPL_MOP_STORING_NO_MULTICAST 2
173 #define RPL_MOP_STORING_MULTICAST 3
176 #define RPL_MOP_DEFAULT RPL_CONF_MOP
178 #define RPL_MOP_DEFAULT RPL_MOP_STORING_NO_MULTICAST
186 #define RPL_DAG_MC_ETX_DIVISOR 128
189 #define RPL_DIS_SEND 1
190 #ifdef RPL_DIS_INTERVAL_CONF
191 #define RPL_DIS_INTERVAL RPL_DIS_INTERVAL_CONF
193 #define RPL_DIS_INTERVAL 60
195 #define RPL_DIS_START_DELAY 5
208 uint8_t dag_intdoubl;
211 rpl_lifetime_t default_lifetime;
212 uint16_t lifetime_unit;
213 rpl_rank_t dag_max_rankinc;
214 rpl_rank_t dag_min_hoprankinc;
215 rpl_prefix_t destination_prefix;
216 rpl_prefix_t prefix_info;
217 struct rpl_metric_container mc;
219 typedef struct rpl_dio rpl_dio_t;
224 uint16_t mem_overflows;
225 uint16_t local_repairs;
226 uint16_t global_repairs;
227 uint16_t malformed_msgs;
229 uint16_t parent_switch;
231 typedef struct rpl_stats rpl_stats_t;
233 extern rpl_stats_t rpl_stats;
239 #define RPL_STAT(code) (code)
241 #define RPL_STAT(code)
247 void dao_output(rpl_parent_t *, rpl_lifetime_t lifetime);
248 void dao_ack_output(rpl_dag_t *,
uip_ipaddr_t *, uint8_t);
249 void uip_rpl_input(
void);
252 void rpl_join_dag(rpl_dag_t *);
253 void rpl_local_repair(rpl_dag_t *dag);
254 int rpl_set_default_route(rpl_dag_t *dag,
uip_ipaddr_t *from);
256 int rpl_process_parent_event(rpl_dag_t *, rpl_parent_t *);
259 rpl_dag_t *rpl_alloc_dag(uint8_t);
260 void rpl_free_dag(rpl_dag_t *);
263 rpl_parent_t *rpl_add_parent(rpl_dag_t *, rpl_dio_t *dio,
uip_ipaddr_t *);
264 rpl_parent_t *rpl_find_parent(rpl_dag_t *,
uip_ipaddr_t *);
265 int rpl_remove_parent(rpl_dag_t *, rpl_parent_t *);
266 rpl_parent_t *rpl_select_parent(rpl_dag_t *dag);
267 void rpl_recalculate_ranks(
void);
270 void rpl_remove_routes(rpl_dag_t *dag);
273 void rpl_purge_routes(
void);
276 rpl_of_t *rpl_find_of(rpl_ocp_t);
279 void rpl_schedule_dao(rpl_dag_t *);
280 void rpl_reset_dio_timer(rpl_dag_t *, uint8_t);
281 void rpl_reset_periodic_timer(
void);
284 void rpl_poison_routes(rpl_dag_t *, rpl_parent_t *);