49 #include "net/rpl/rpl-private.h"
52 #define DEBUG DEBUG_NONE
61 rpl_stats_t rpl_stats;
64 static enum rpl_mode mode = RPL_MODE_MESH;
75 enum rpl_mode oldmode = mode;
79 if(m == RPL_MODE_MESH) {
85 PRINTF(
"RPL: switching to mesh mode\n");
88 if(default_instance !=
NULL) {
89 rpl_schedule_dao_immediately(default_instance);
91 }
else if(m == RPL_MODE_FEATHER) {
93 PRINTF(
"RPL: switching to feather mode\n");
95 if(default_instance !=
NULL) {
96 rpl_cancel_dao(default_instance);
107 rpl_purge_routes(
void)
112 #if RPL_CONF_MULTICAST
117 r = uip_ds6_route_head();
120 if(r->state.lifetime >= 1) {
128 r = uip_ds6_route_next(r);
132 r = uip_ds6_route_head();
135 if(r->state.lifetime < 1) {
140 r = uip_ds6_route_head();
141 PRINTF(
"No more routes to ");
143 dag = default_instance->current_dag;
145 if(dag->rank != ROOT_RANK(default_instance)) {
146 PRINTF(
" -> generate No-Path DAO\n");
147 dao_output_target(dag->preferred_parent, &prefix, RPL_ZERO_LIFETIME);
153 r = uip_ds6_route_next(r);
157 #if RPL_CONF_MULTICAST
158 mcast_route = uip_mcast6_route_list_head();
160 while(mcast_route !=
NULL) {
161 if(mcast_route->lifetime <= 1) {
162 uip_mcast6_route_rm(mcast_route);
163 mcast_route = uip_mcast6_route_list_head();
165 mcast_route->lifetime--;
173 rpl_remove_routes(rpl_dag_t *dag)
176 #if RPL_CONF_MULTICAST
180 r = uip_ds6_route_head();
183 if(r->state.dag == dag) {
185 r = uip_ds6_route_head();
187 r = uip_ds6_route_next(r);
191 #if RPL_CONF_MULTICAST
192 mcast_route = uip_mcast6_route_list_head();
194 while(mcast_route !=
NULL) {
195 if(mcast_route->dag == dag) {
196 uip_mcast6_route_rm(mcast_route);
197 mcast_route = uip_mcast6_route_list_head();
206 rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag)
210 r = uip_ds6_route_head();
213 if(uip_ipaddr_cmp(uip_ds6_route_nexthop(r), nexthop) &&
214 r->state.dag == dag) {
216 r = uip_ds6_route_head();
218 r = uip_ds6_route_next(r);
221 ANNOTATE(
"#L %u 0\n", nexthop->u8[
sizeof(uip_ipaddr_t) - 1]);
225 rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix,
int prefix_len,
226 uip_ipaddr_t *next_hop)
230 if((rep = uip_ds6_route_add(prefix, prefix_len, next_hop)) ==
NULL) {
231 PRINTF(
"RPL: No space for more route entries\n");
235 rep->state.dag = dag;
236 rep->state.lifetime = RPL_LIFETIME(dag->instance, dag->instance->default_lifetime);
237 rep->state.learned_from = RPL_ROUTE_FROM_INTERNAL;
239 PRINTF(
"RPL: Added a route to ");
241 PRINTF(
"/%d via ", prefix_len);
242 PRINT6ADDR(next_hop);
249 rpl_link_neighbor_callback(
const linkaddr_t *addr,
int status,
int numtx)
252 rpl_parent_t *parent;
253 rpl_instance_t *instance;
259 for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
260 if(instance->used == 1 ) {
261 parent = rpl_find_parent_any_dag(instance, &ipaddr);
264 PRINTF(
"RPL: rpl_link_neighbor_callback triggering update\n");
265 parent->flags |= RPL_PARENT_FLAG_UPDATED;
266 if(instance->of->neighbor_link_callback !=
NULL) {
267 instance->of->neighbor_link_callback(parent, status, numtx);
278 rpl_instance_t *instance;
281 PRINTF(
"RPL: Removing neighbor ");
282 PRINT6ADDR(&nbr->ipaddr);
284 for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
285 if(instance->used == 1 ) {
286 p = rpl_find_parent_any_dag(instance, &nbr->ipaddr);
288 p->rank = INFINITE_RANK;
290 PRINTF(
"RPL: rpl_ipv6_neighbor_callback infinite rank\n");
291 p->flags |= RPL_PARENT_FLAG_UPDATED;
300 uip_ipaddr_t rplmaddr;
301 PRINTF(
"RPL started\n");
302 default_instance =
NULL;
305 rpl_reset_periodic_timer();
306 rpl_icmp6_register_handlers();
309 uip_create_linklocal_rplnodes_mcast(&rplmaddr);
310 uip_ds6_maddr_add(&rplmaddr);
313 memset(&rpl_stats, 0,
sizeof(rpl_stats));
An entry in the routing table.
This header file contains configuration directives for uIPv6 multicast support.
Header file for the uIP TCP/IP stack.
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
Header for the Contiki/uIP interface.
Network interface and stateless autoconfiguration (RFC 4862)
void * list_item_next(void *item)
Get the next item following this item.
#define NULL
The null pointer.
An entry in the multicast routing table.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
ICMPv6 echo request and error messages (RFC 4443)
enum rpl_mode rpl_get_mode(void)
Get the RPL mode.
enum rpl_mode rpl_set_mode(enum rpl_mode m)
Set the RPL mode.
A set of debugging macros.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
An entry in the nbr cache.