51 #define LOG_MODULE "IPv6 SR" 52 #define LOG_LEVEL LOG_LEVEL_IPV6 69 node_matches_address(
void *graph,
const uip_sr_node_t *node,
const uip_ipaddr_t *
addr)
71 if(node == NULL || addr == NULL || graph != node->graph) {
74 uip_ipaddr_t node_ipaddr;
76 return uip_ipaddr_cmp(&node_ipaddr, addr);
86 if(node_matches_address(graph, l, addr)) {
96 int max_depth = UIP_SR_LINK_NUM;
97 uip_ipaddr_t root_ipaddr;
105 while(node != NULL && node != root_node && max_depth > 0) {
109 return node != NULL && node == root_node;
117 if(l != NULL && node_matches_address(graph, l->parent, parent)) {
118 l->lifetime = UIP_SR_REMOVAL_DELAY;
123 uip_sr_update_node(
void *graph,
const uip_ipaddr_t *child,
const uip_ipaddr_t *parent, uint32_t lifetime)
131 if(parent_node == NULL) {
133 if(parent_node == NULL) {
134 LOG_ERR(
"NS: no space left for root node!\n");
141 if(child_node == NULL) {
144 if(child_node == NULL) {
145 LOG_ERR(
"NS: no space left for child ");
146 LOG_ERR_6ADDR(child);
150 child_node->parent = NULL;
156 child_node->graph = graph;
157 child_node->lifetime = lifetime;
158 memcpy(child_node->link_identifier, ((
const unsigned char *)child) + 8, 8);
162 old_parent_node = child_node->parent;
164 child_node->parent = parent_node;
170 child_node->parent = old_parent_node;
173 child_node->parent = parent_node;
176 LOG_INFO(
"NS: updating link, child ");
177 LOG_INFO_6ADDR(child);
178 LOG_INFO_(
", parent ");
179 LOG_INFO_6ADDR(parent);
180 LOG_INFO_(
", lifetime %u, num_nodes %u\n", (
unsigned)lifetime, num_nodes);
212 for(l =
list_head(nodelist); l != NULL; l = next) {
214 if(l->lifetime == 0) {
217 if(l2->parent == l) {
221 if(LOG_INFO_ENABLED) {
222 uip_ipaddr_t node_addr;
224 LOG_INFO(
"NS: removing expired node ");
225 LOG_INFO_6ADDR(&node_addr);
232 }
else if(l->lifetime != UIP_SR_INFINITE_LIFETIME) {
233 l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0;
243 for(l =
list_head(nodelist); l != NULL; l = next) {
255 uip_ipaddr_t child_ipaddr;
256 uip_ipaddr_t parent_ipaddr;
261 if(LOG_WITH_COMPACT_ADDR) {
266 if(index >= buflen) {
270 if(link->parent == NULL) {
271 index += snprintf(buf+index, buflen-index,
" (DODAG root)");
272 if(index >= buflen) {
276 index += snprintf(buf+index, buflen-index,
" to ");
277 if(index >= buflen) {
280 if(LOG_WITH_COMPACT_ADDR) {
285 if(index >= buflen) {
289 if(link->lifetime != UIP_SR_INFINITE_LIFETIME) {
290 index += snprintf(buf+index, buflen-index,
291 " (lifetime: %lu seconds)", (
unsigned long)link->lifetime);
292 if(index >= buflen) {
296 index += snprintf(buf+index, buflen-index,
" (lifetime: infinite)");
297 if(index >= buflen) {
int uip_sr_num_nodes(void)
Tells how many nodes are currently stored in the graph.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
void uip_sr_free_all(void)
Deallocate all neighbors.
void uip_sr_init(void)
Initialize this module.
void uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
Expires a given child-parent link.
uip_sr_node_t * uip_sr_node_next(uip_sr_node_t *item)
Returns the next element of the non-storing node list.
Header file for the IP address manipulation library.
void uip_sr_periodic(unsigned seconds)
A function called periodically.
Linked list manipulation routines.
void * list_head(list_t list)
Get a pointer to the first element of a list.
uip_sr_node_t * uip_sr_node_head(void)
Returns the head of the non-storing node list.
Routing driver header file
uip_sr_node_t * uip_sr_get_node(void *graph, const uip_ipaddr_t *addr)
Looks up for a source routing node from its IPv6 global address.
Memory block allocation routines.
void list_add(list_t list, void *item)
Add an item at the end of a list.
void list_init(list_t list)
Initialize a list.
int uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link)
Print a textual description of a source routing link.
#define LIST(name)
Declare a linked list.
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
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.
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(* get_sr_node_ipaddr)(uip_ipaddr_t *addr, const uip_sr_node_t *node)
Returns the global IPv6 address of a source routing node.
int(* get_root_ipaddr)(uip_ipaddr_t *ipaddr)
Returns the IPv6 address of the network root, if any.
void memb_init(struct memb *m)
Initialize a memory block that was declared with MEMB().
char memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
Header file for the logging system
int uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr)
Telle whether an address is reachable, i.e.
void list_remove(list_t list, void *item)
Remove a specific element from a list.
void * list_item_next(void *item)
Get the next item following this item.
A node in a source routing graph, stored at the root and representing all child-parent relationship...
#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.