我正在尝试测试文件 rpl-icmp6.c 中的 DIO 消息是否来自接收 DIO 的节点的子节点。谁能帮我?
我发现 Contiki 不保留 child 的列表,只保留 parent 的列表。因此,我不知道该怎么做?
伪代码:
if(senderOfDIO is child) {
check the rank of the packet
}
有人可以帮助我吗?
最佳答案
如果您在存储模式下运行 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;
}
关于c - RPL child 列表 Contiki,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43745521/