c - RPL child 列表 Contiki

标签 c contiki

我正在尝试测试文件 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/

相关文章:

c - 为什么扩展 grep 不起作用?

ipv6 - 在 Contiki 操作系统中使用 Rime 和 6LoWPAN

c - 如何在Contiki OS中运行hello-world?

process - Contiki编译错误, “ERROR: address 0x820003 out of range at line 1740 of…”

无符号类型与有符号类型的比较

c 从BMP中获取数据

c - 这个程序怎么可能有意义?

有人可以解释一下为什么当我输入的字符串大小超过允许的字符串大小时我的 fgets 会跳行

c - contiki 操作系统中的 sha256 错误散列

c - 如何在 Contiki 中将链接本地地址转换为全局地址