38#include "contiki-net.h"
40#include "net/routing/rpl-classic/rpl.h"
41#include "net/routing/rpl-classic/rpl-private.h"
48#define LOG_MODULE "RPL"
49#define LOG_LEVEL LOG_LEVEL_RPL
53set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid)
56 static uip_ipaddr_t root_ipaddr;
61 uip_ip6addr_copy(&root_ipaddr, default_prefix);
63 memcpy(&root_ipaddr, prefix, 8);
69 memcpy((uint8_t *)&root_ipaddr + 8, (uint8_t *)iid + 8, 8);
75 LOG_DBG(
"IPv6 addresses: \n");
76 for(
size_t i = 0; i < UIP_DS6_ADDR_NB; i++) {
81 LOG_DBG_6ADDR(&
uip_ds6_if.addr_list[i].ipaddr);
89rpl_dag_root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid)
91 static uint8_t initialized = 0;
94 set_global_address(prefix, iid);
100rpl_dag_root_start(
void)
102 uip_ipaddr_t *
ipaddr = NULL;
104 rpl_dag_root_set_prefix(NULL, NULL);
106 for(
size_t i = 0; i < UIP_DS6_ADDR_NB; i++) {
107 uint8_t state =
uip_ds6_if.addr_list[i].state;
109 state == ADDR_PREFERRED &&
116 LOG_ERR(
"failed to create a DAG: no preferred IP address found\n");
121 if(root_if == NULL) {
122 LOG_ERR(
"failed to create a DAG: no root interface found\n");
126 rpl_set_root(RPL_DEFAULT_INSTANCE,
ipaddr);
129 LOG_ERR(
"failed to create a DAG: cannot get any DAG\n");
135 if(RPL_IS_STORING(dag->instance)) {
136 rpl_remove_routes(dag);
138 if(dag->instance != NULL && dag->instance->def_route != NULL) {
139 uip_ds6_defrt_rm(dag->instance->def_route);
140 dag->instance->def_route = NULL;
144 uip_ip6addr_copy(&prefix,
ipaddr);
145 rpl_set_prefix(dag, &prefix, 64);
147 LOG_INFO(
"created a new RPL dag\n");
152rpl_dag_root_is_root(
void)
156 return instance && instance->current_dag &&
157 instance->current_dag->rank == ROOT_RANK(instance);
const uip_ip6addr_t * uip_ds6_default_prefix()
Retrieve the Default IPv6 prefix.
uip_lladdr_t uip_lladdr
Host L2 address.
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.
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC 4291 i.e.
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
uip_ds6_netif_t uip_ds6_if
The single interface.
Header file for the logging system.
Unicast address structure.
Header file for routing table manipulation.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.