33 #include "contiki-net.h"
35 #include "net/rpl/rpl.h"
36 #include "net/rpl/rpl-private.h"
37 #include "net/rpl/rpl-dag-root.h"
41 #define DEBUG DEBUG_NONE
44 #define RPL_DAG_GRACE_PERIOD (CLOCK_SECOND * 20 * 1)
46 #if (UIP_CONF_MAX_ROUTES != 0)
47 static struct uip_ds6_notification n;
49 static uint8_t to_become_root;
50 static struct ctimer c;
52 static const uip_ipaddr_t *
57 dag = rpl_get_any_dag();
65 static const uip_ipaddr_t *
66 get_global_address(
void)
72 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
75 state == ADDR_PREFERRED &&
84 create_dag_callback(
void *ptr)
86 const uip_ipaddr_t *root, *
ipaddr;
89 ipaddr = get_global_address();
91 if(root ==
NULL || uip_ipaddr_cmp(root, ipaddr)) {
95 rpl_dag_root_init_dag_immediately();
101 dag = rpl_get_any_dag();
103 printf(
"Found a network we did not create\n");
104 printf(
"version %d grounded %d preference %d used %d joined %d rank %d\n",
105 dag->version, dag->grounded,
106 dag->preference, dag->used,
107 dag->joined, dag->rank);
115 if(dag->rank == INFINITE_RANK) {
117 rpl_dag_root_init_dag_immediately();
126 #if (UIP_CONF_MAX_ROUTES != 0)
129 route_callback(
int event, uip_ipaddr_t *
route, uip_ipaddr_t *ipaddr,
132 if(event == UIP_DS6_NOTIFICATION_DEFRT_ADD) {
133 if(route !=
NULL && ipaddr !=
NULL &&
144 static uip_ipaddr_t *
145 set_global_address(
void)
147 static uip_ipaddr_t
ipaddr;
153 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
157 printf(
"IPv6 addresses: ");
158 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
162 uip_debug_ipaddr_print(&
uip_ds6_if.addr_list[i].ipaddr);
171 rpl_dag_root_init(
void)
173 static uint8_t initialized = 0;
177 set_global_address();
178 #if (UIP_CONF_MAX_ROUTES != 0)
179 uip_ds6_notification_add(&n, route_callback);
186 rpl_dag_root_init_dag_immediately(
void)
191 uip_ipaddr_t *ipaddr =
NULL;
195 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
198 state == ADDR_PREFERRED &&
205 root_if = uip_ds6_addr_lookup(ipaddr);
206 if(root_if !=
NULL) {
210 rpl_set_root(RPL_DEFAULT_INSTANCE, ipaddr);
211 dag = rpl_get_any_dag();
215 if(RPL_IS_STORING(dag->instance)) {
216 rpl_remove_routes(dag);
218 if(dag->instance !=
NULL &&
219 dag->instance->def_route !=
NULL) {
220 uip_ds6_defrt_rm(dag->instance->def_route);
221 dag->instance->def_route =
NULL;
224 uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
225 rpl_set_prefix(dag, &prefix, 64);
226 PRINTF(
"rpl_dag_root_init_dag: created a new RPL dag\n");
229 PRINTF(
"rpl_dag_root_init_dag: failed to create a new RPL DAG\n");
233 PRINTF(
"rpl_dag_root_init_dag: failed to create a new RPL DAG, no preferred IP address found\n");
239 rpl_dag_root_init_dag(
void)
251 rpl_dag_root_is_root(
void)
253 rpl_instance_t *instance;
255 instance = rpl_get_default_instance();
257 if(instance ==
NULL) {
261 if(instance->current_dag &&
262 instance->current_dag->rank == ROOT_RANK(instance)) {
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
#define uip_is_addr_unspecified(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
static uip_ds6_route_t * route
The next route to use.
Unicast address structure.
#define NULL
The null pointer.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
A set of debugging macros for the IP stack
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC3513 i.e.
uip_ds6_netif_t uip_ds6_if
The single interface.
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