RPL (Contiki / Cooja) 存储模式下的访问路由 table
Access routing table in storing mode of RPL (Contiki / Cooja)
- 我能够成功 运行 示例代码 (../examples/6tisch/simple-node),其中实现了 rpl-lite,并且在每 60 秒根网络打印其路由后 table。由于它使用rpl-lite,只有根节点存储路由table。
- 我正在寻找在这个程序中实现(存储模式)的示例代码,每60秒打印每个节点的路由table。
我在生成文件中添加了“MAKE_ROUTING = MAKE_ROUTING_RPL_CLASSIC”以启用 RPL-Classic
#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 DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h"
/*---------------------------------------------------------------------------*/
PROCESS(node_process, "RPL Node");
AUTOSTART_PROCESSES(&node_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process, ev, data)
{
int is_coordinator;
PROCESS_BEGIN();
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) {
PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes());
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
}
PROCESS_END();
}
这些步骤对我有用:
- 将
MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC
添加到Makefile以确保使用RPL Classic;存储模式默认开启。
- 为方便起见,添加允许使用 Contiki-NG 日志记录模块的包含和定义:
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_DBG
- 将此代码添加到
while(1)
循环中:
LOG_INFO("Routing entries: %u\n", uip_ds6_route_num_routes());
uip_ds6_route_t *route = uip_ds6_route_head();
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");
route = uip_ds6_route_next(route);
}
根节点上的输出:
01:00.382 ID:1 [INFO: App ] Routing entries: 7
01:00.382 ID:1 [INFO: App ] Route fd00::205:5:5:5/128 via fe80::205:5:5:5
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::208:8:8:8/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::207:7:7:7/128 via fe80::203:3:3:3
01:00.382 ID:1 [INFO: App ] Route fd00::206:6:6:6/128 via fe80::203:3:3:3
01:00.382 ID:1 [INFO: App ] Route fd00::202:2:2:2/128 via fe80::203:3:3:3
转发器节点上的输出:
01:00.899 ID:3 [INFO: App ] Routing entries: 4
01:00.899 ID:3 [INFO: App ] Route fd00::208:8:8:8/128 via fe80::206:6:6:6
01:00.899 ID:3 [INFO: App ] Route fd00::207:7:7:7/128 via fe80::206:6:6:6
01:00.899 ID:3 [INFO: App ] Route fd00::206:6:6:6/128 via fe80::206:6:6:6
01:00.899 ID:3 [INFO: App ] Route fd00::202:2:2:2/128 via fe80::202:2:2:2
- 我能够成功 运行 示例代码 (../examples/6tisch/simple-node),其中实现了 rpl-lite,并且在每 60 秒根网络打印其路由后 table。由于它使用rpl-lite,只有根节点存储路由table。
- 我正在寻找在这个程序中实现(存储模式)的示例代码,每60秒打印每个节点的路由table。
我在生成文件中添加了“MAKE_ROUTING = MAKE_ROUTING_RPL_CLASSIC”以启用 RPL-Classic
#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 DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h"
/*---------------------------------------------------------------------------*/
PROCESS(node_process, "RPL Node");
AUTOSTART_PROCESSES(&node_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process, ev, data)
{
int is_coordinator;
PROCESS_BEGIN();
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) {
PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes());
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
}
PROCESS_END();
}
这些步骤对我有用:
- 将
MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC
添加到Makefile以确保使用RPL Classic;存储模式默认开启。 - 为方便起见,添加允许使用 Contiki-NG 日志记录模块的包含和定义:
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_DBG
- 将此代码添加到
while(1)
循环中:
LOG_INFO("Routing entries: %u\n", uip_ds6_route_num_routes());
uip_ds6_route_t *route = uip_ds6_route_head();
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");
route = uip_ds6_route_next(route);
}
根节点上的输出:
01:00.382 ID:1 [INFO: App ] Routing entries: 7
01:00.382 ID:1 [INFO: App ] Route fd00::205:5:5:5/128 via fe80::205:5:5:5
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::208:8:8:8/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::207:7:7:7/128 via fe80::203:3:3:3
01:00.382 ID:1 [INFO: App ] Route fd00::206:6:6:6/128 via fe80::203:3:3:3
01:00.382 ID:1 [INFO: App ] Route fd00::202:2:2:2/128 via fe80::203:3:3:3
转发器节点上的输出:
01:00.899 ID:3 [INFO: App ] Routing entries: 4
01:00.899 ID:3 [INFO: App ] Route fd00::208:8:8:8/128 via fe80::206:6:6:6
01:00.899 ID:3 [INFO: App ] Route fd00::207:7:7:7/128 via fe80::206:6:6:6
01:00.899 ID:3 [INFO: App ] Route fd00::206:6:6:6/128 via fe80::206:6:6:6
01:00.899 ID:3 [INFO: App ] Route fd00::202:2:2:2/128 via fe80::202:2:2:2