51#define LOG_MODULE "IPv6 SR"
52#define LOG_LEVEL LOG_LEVEL_IPV6
69node_matches_address(
const void *graph,
const uip_sr_node_t *node,
70 const uip_ipaddr_t *
addr)
72 if(node == NULL ||
addr == NULL || graph != node->graph) {
75 uip_ipaddr_t node_ipaddr;
77 return uip_ipaddr_cmp(&node_ipaddr,
addr);
87 if(node_matches_address(graph, l,
addr)) {
97 int max_depth = UIP_SR_LINK_NUM;
98 uip_ipaddr_t root_ipaddr;
106 while(node != NULL && node != root_node && max_depth > 0) {
110 return node != NULL && node == root_node;
115 const uip_ipaddr_t *parent)
119 if(l != NULL && node_matches_address(graph, l->parent, parent)) {
120 if(l->lifetime > UIP_SR_REMOVAL_DELAY) {
121 l->lifetime = UIP_SR_REMOVAL_DELAY;
128 const uip_ipaddr_t *parent, uint32_t lifetime)
136 if(parent_node == NULL) {
138 if(parent_node == NULL) {
139 LOG_ERR(
"NS: no space left for root node!\n");
146 if(child_node == NULL) {
149 if(child_node == NULL) {
150 LOG_ERR(
"NS: no space left for child ");
151 LOG_ERR_6ADDR(child);
155 child_node->parent = NULL;
161 child_node->graph = graph;
162 child_node->lifetime = lifetime;
163 memcpy(child_node->link_identifier, ((
const unsigned char *)child) + 8, 8);
167 old_parent_node = child_node->parent;
169 child_node->parent = parent_node;
175 child_node->parent = old_parent_node;
178 child_node->parent = parent_node;
181 LOG_INFO(
"NS: updating link, child ");
182 LOG_INFO_6ADDR(child);
183 LOG_INFO_(
", parent ");
184 LOG_INFO_6ADDR(parent);
185 LOG_INFO_(
", lifetime %u, num_nodes %u\n", (
unsigned)lifetime, num_nodes);
217 for(l =
list_head(nodelist); l != NULL; l = next) {
219 if(l->lifetime == 0) {
221 int can_be_removed = 1;
223 if(l2->parent == l) {
230 if(LOG_INFO_ENABLED) {
231 uip_ipaddr_t node_addr;
233 LOG_INFO(
"NS: removing expired node ");
234 LOG_INFO_6ADDR(&node_addr);
241 }
else if(l->lifetime != UIP_SR_INFINITE_LIFETIME) {
242 l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0;
252 for(l =
list_head(nodelist); l != NULL; l = next) {
264 uip_ipaddr_t child_ipaddr;
265 uip_ipaddr_t parent_ipaddr;
270 if(LOG_WITH_COMPACT_ADDR) {
275 if(index >= buflen) {
279 if(link->parent == NULL) {
280 index += snprintf(buf+index, buflen-index,
" (DODAG root)");
281 if(index >= buflen) {
285 index += snprintf(buf+index, buflen-index,
" to ");
286 if(index >= buflen) {
289 if(LOG_WITH_COMPACT_ADDR) {
294 if(index >= buflen) {
298 if(link->lifetime != UIP_SR_INFINITE_LIFETIME) {
299 index += snprintf(buf+index, buflen-index,
300 " (lifetime: %lu seconds)", (
unsigned long)link->lifetime);
301 if(index >= buflen) {
305 index += snprintf(buf+index, buflen-index,
" (lifetime: infinite)");
306 if(index >= buflen) {
static void list_init(list_t list)
Initialize a list.
#define LIST(name)
Declare a linked list.
static void * list_item_next(const void *item)
Get the next item following this item.
void list_add(list_t list, void *item)
Add an item at the end of a list.
void list_remove(list_t list, const void *item)
Remove a specific element from a list.
static void * list_head(const_list_t list)
Get a pointer to the first element of a list.
int log_6addr_compact_snprint(char *buf, size_t size, const uip_ipaddr_t *ipaddr)
Write at most size - 1 characters of the IP address to the output string, in a compact representation...
int memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
void memb_init(struct memb *m)
Initialize a memory block that was declared with MEMB().
#define MEMB(name, structure, num)
Declare a memory block.
int uiplib_ipaddr_snprint(char *buf, size_t size, const uip_ipaddr_t *addr)
Write at most size - 1 characters of the IP address to the output string.
uip_sr_node_t * uip_sr_get_node(const void *graph, const uip_ipaddr_t *addr)
Looks up for a source routing node from its IPv6 global address.
void uip_sr_expire_parent(const void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
Expires a given child-parent link.
void uip_sr_init(void)
Initialize this module.
void uip_sr_free_all(void)
Deallocate all neighbors.
int uip_sr_is_addr_reachable(const void *graph, const uip_ipaddr_t *addr)
Telle whether an address is reachable, i.e.
uip_sr_node_t * uip_sr_node_head(void)
Returns the head of the non-storing node list.
int uip_sr_link_snprint(char *buf, int buflen, const uip_sr_node_t *link)
Print a textual description of a source routing link.
void uip_sr_periodic(unsigned seconds)
A function called periodically.
int uip_sr_num_nodes(void)
Tells how many nodes are currently stored in the graph.
uip_sr_node_t * uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
Updates a child-parent link.
uip_sr_node_t * uip_sr_node_next(const uip_sr_node_t *item)
Returns the next element of the non-storing node list.
Linked list manipulation routines.
Header file for the logging system.
Memory block allocation routines.
Routing driver header file.
int(* get_root_ipaddr)(uip_ipaddr_t *ipaddr)
Returns the IPv6 address of the network root, if any.
int(* get_sr_node_ipaddr)(uip_ipaddr_t *ipaddr, const uip_sr_node_t *node)
Returns the global IPv6 address of a source routing node.
A node in a source routing graph, stored at the root and representing all child-parent relationship.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Header file for the IP address manipulation library.