如何解决将IPv6地址从路由表存储到链接列表Contiki / Cooja
我想将路由表中直接节点的IPv6地址存储在链接列表中。因此,链接列表可用于仅将消息发送到选定的节点。
-
我通过明确声明在MAKE文件中使用RPL-Classic,将路由固定为“存储模式”。
-
我更改了代码,每60秒访问一次路由表,并且从该表中,我仅将立即节点的地址(uip_ds6_route_nexthop(route))存储在由contiki定义的链接列表(list_route)中。
-
根据专家的建议,在代码中,我使用了Contiki自己定义的“ memb_alloc / free”。
-
但是当我尝试打印此链接列表时,它没有打印任何IP地址。它仅打印文本“ Route IPV6”,但不打印IP地址。
#include "contiki.h"
#include "sys/node-id.h"
#include "sys/log.h"
#include "net/ipv6/uip-ds6-route.h"
#include "net/ipv6/uip-sr.h"
#include "net/mac/tsch/tsch.h"
#include "net/routing/routing.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_DBG
#define DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h"
#include "lib/list.h"
#include "lib/memb.h"
/* List Structure to store IPv6 address from the routing table */
struct list_route {
struct list_route *next;
const uip_ipaddr_t ipaddr;
};
LIST(neighb_table); // Contiki defined list
MEMB(route_mem,struct list_route,5); //memory block for the list MEMB(name,structure,num);
/*---------------------------------------------------------------------------*/
PROCESS(node_process,"RPL Node-Storing Mode");
AUTOSTART_PROCESSES(&node_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process,ev,data)
{
int is_coordinator;
PROCESS_BEGIN();
/* Initialize the memory for the neighbor table entries. */
memb_init(&route_mem);
/* Initialize the list used for the neighbor table. */
list_init(neighb_table);
is_coordinator = 0;
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_Z1
is_coordinator = (node_id == 1);
#endif
if(is_coordinator) {
NETSTACK_ROUTING.root_start();
}
NETSTACK_MAC.on();
static struct etimer et;
/* Print out routing tables every minute */
etimer_set(&et,CLOCK_SECOND * 60);
while(1) {
LOG_INFO("Routing entries: %u\n",uip_ds6_route_num_routes());
if(uip_ds6_route_num_routes()){
uip_ds6_route_t *route = uip_ds6_route_head();
struct list_route *e;
while(route) {
LOG_INFO("Route ");
LOG_INFO_6ADDR(&route->ipaddr);
LOG_INFO_("/128 via ");
LOG_INFO_6ADDR(uip_ds6_route_nexthop(route));
LOG_INFO_("\n");
/* Removing any prevIoUs same entry from the list (to avoid buffer overflow)*/
for(e = list_head(neighb_table); e != NULL; e = e->next) {
if(uip_ip6addr_cmp(&e->ipaddr,uip_ds6_route_nexthop(route))) {
list_remove(neighb_table,e);
memb_free(&route_mem,e);
}
}
e = memb_alloc(&route_mem); // Allocate memory from the route_mem pool
e->next=NULL;
uip_ip6addr_copy(&e->ipaddr,uip_ds6_route_nexthop(route)); //copy IPv6 address
list_add(neighb_table,e); //Append the structure in the list
route = uip_ds6_route_next(route);
}
/* Print out the list */
e = list_head(neighb_table);
while (e != NULL)
{
LOG_INFO_("Route IPV6 ");
LOG_INFO_6ADDR(&e->ipaddr);
LOG_INFO_("\n");
e=e->next;
}
}
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
PROCESS_END();
}
00:07.948 ID:1 [WARN: IPv6 Route] No route found
00:07.948 ID:1 [WARN: IPv6 Route] No route found
00:09.838 ID:2 [WARN: IPv6 Route] No route found
00:09.928 ID:4 [WARN: IPv6 Route] No route found
00:11.068 ID:1 [WARN: IPv6 Route] No route found
00:11.068 ID:1 [WARN: IPv6 Route] No route found
00:11.908 ID:1 [WARN: IPv6 Route] No route found
00:11.908 ID:1 [WARN: IPv6 Route] No route found
00:15.298 ID:3 [WARN: IPv6 Route] No route found
00:15.298 ID:3 [WARN: IPv6 Route] No route found
00:15.328 ID:1 [WARN: IPv6 Route] No route found
00:15.328 ID:1 [WARN: IPv6 Route] No route found
01:00.382 ID:1 [INFO: App ] Route fd00::205:5:5:5/128 via fe80::203:3:3:3
01:00.382 ID:1 [INFO: App ] Route fd00::203:3:3:3/128 via fe80::203:3:3:3
01:00.382 ID:1 [INFO: App ] Route fd00::204:4:4:4/128 via fe80::204:4:4:4
01:00.382 ID:1 [INFO: App ] Route fd00::202:2:2:2/128 via fe80::202:2:2:2
01:00.382 ID:1 Route IPV6
01:00.382 ID:1 Route IPV6
01:00.382 ID:1 Route IPV6
01:00.899 ID:3 [INFO: App ] Route fd00::205:5:5:5/128 via fe80::205:5:5:5
01:00.899 ID:3 Route IPV6
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。