Search code examples
ccontiki

RPL children-list Contiki


I am trying to test whether or not the DIO messages in the file rpl-icmp6.c are coming from a child of the node that receives the DIO. Can anyone help me?

I have seen that contiki do not keep a list of the children, only the parents. Therefore, I am not sure how to do it?

Pseudocode:

if(senderOfDIO is child) {

   check the rank of the packet

}

Can anyone help me?


Solution

  • If you're running RPL in storing mode, you can tell which nodes are directly connected by looking at the routes towards them and checking whether the nexthop of the route is the same as the endpoint addess.

    This is an example of code that loops over direct children:

    #include "ipv6/uip-ds6-route.h"
    
    static void
    iterate_children(void)
    {
      uip_ds6_route_t *route;
    
      /* Loop over routing entries */
      route = uip_ds6_route_head();
      while(route != NULL) {
        const uip_ipaddr_t *address = &route->ipaddr;
        const uip_ipaddr_t *nexthop = uip_ds6_route_nexthop(route);
        if(uip_ipaddr_cmp(&address, &nexthop)) {
           /* direct child: do somehting */
        }
    
        route = uip_ds6_route_next(route);
      }
    }
    

    To solve your question specifically, use something like this:

    static uint8_t
    is_direct_child(uip_ipaddr_t *address)
    {
      uip_ds6_route_t *route;
    
      route = uip_ds6_route_lookup(address);
      if(route != NULL) {
        const uip_ipaddr_t *nexthop = uip_ds6_route_nexthop(route);
        if(uip_ipaddr_cmp(&address, &nexthop)) {
           /* nexthop and the address are the same */
           return 1;
        }
      }
      return 0;
    }