2017-05-02 46 views
0

我想测试文件rpl-icmp6.c中的DIO消息是否来自接收DIO的节点的子节点。谁能帮我?RPL children-list Contiki

我已经看到,contiki不保留儿童名单,只有父母。所以,我不知道该怎么做?

伪代码:

if(senderOfDIO is child) { 

    check the rank of the packet 

} 

谁能帮助我?

回答

0

如果您在存储模式下运行RPL,您可以通过查看到它们的路由并检查路由下一跳是否与端点地址相同来判断哪些节点是直接连接的。

这是遍历直接孩子的代码示例:

#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); 
    } 
} 

要专门解决你的问题,使用这样的:

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; 
} 
+0

非常感谢你的回答。非常好的答案!一个快速后续问题:在is_direct_child中,我应该发送孩子的IP地址还是主机IP地址? – Freddyny

+0

地址'参数'意味着孩子的IP地址。 – kfx

+0

我明白了!所以我像这样调用'is_direct_child':'is_direct_child(&from)',其中from是这样接收的:'uip_ipaddr_copy(&from,&UIP_IP_BUF-> srcipaddr);'。但是,在'uip_ds6_route_lookup(地址)'中根本找不到任何路由。它输出:'uip-ds6-route:查找fe80 :: c40c:0:0:3的路径',那么下一个输出是'No route found'。你能想到为什么@kfx的原因? – Freddyny

0

无论是在RPL登记模式或者非存储模式从父节点到子节点的DIO将以两个senarios发送。 1形成DODAG之前 2形成DODAG后定期发送DIO。

每次DIO都将被多播,除非响应子节点发出DIS。

要测试孩子是否正在接收DIO消息,可以在COOJA中看到这是一个虚拟模拟。

在非存储模式下,路由器以外的所有节点都不会存储子地址。这里的数据包转发将由承载所有地址的源路由头(SRH)完成。