Commit 26d51c15 authored by Simon Duquennoy's avatar Simon Duquennoy
Browse files

Routing API: added more missing functions, homogenize configuration

parent 15b81c0f
......@@ -151,17 +151,15 @@ MAKE_ROUTING ?= MAKE_ROUTING_NONE
endif
ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_CLASSIC)
CFLAGS += -DUIP_CONF_IPV6_RPL=1
CFLAGS += -DUIP_CONF_IPV6_RPL_CLASSIC=1
CFLAGS += -DNETSTACK_ROUTING=rpl_classic_driver
MODULES += os/net/routing/rpl-classic
else ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_LITE)
CFLAGS += -DUIP_CONF_IPV6_RPL=1
CFLAGS += -DUIP_CONF_IPV6_RPL_LITE=1
CFLAGS += -DNETSTACK_ROUTING=rpl_lite_driver
MODULES += os/net/routing/rpl-lite
else
CFLAGS += -DUIP_CONF_IPV6_RPL=0
CFLAGS += -DUIP_CONF_IPV6_NULLROUTING=1
CFLAGS += -DNETSTACK_ROUTING=nullrouting_driver
MODULES += os/net/routing/nullrouting
endif
......
......@@ -76,10 +76,10 @@ PROCESS_THREAD(node_process, ev, data)
etimer_set(&et, CLOCK_SECOND * 60);
while(1) {
/* Used for non-regression testing */
#if RPL_WITH_STORING
#if (UIP_MAX_ROUTES != 0)
PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes());
#endif
#if RPL_WITH_NON_STORING
#if UIP_CONF_IPV6_RPL
PRINTF("Routing links: %u\n", rpl_ns_num_nodes());
#endif
PROCESS_YIELD_UNTIL(etimer_expired(&et));
......
......@@ -32,11 +32,11 @@
#include "contiki.h"
#include "net/routing/routing.h"
#if RPL_WITH_NON_STORING
/* For RPL non-storing specific link printout.
* Note that traditional DS6 routes are printed in addition,
* whenever UIP_MAX_ROUTES != 0 */
#include "rpl-ns.h"
/* For RPL-specific data inclusion, in particular non-storing routing link */
#if UIP_CONF_IPV6_RPL_LITE
#include "net/routing/rpl-lite/rpl.h"
#elif UIP_CONF_IPV6_RPL_CLASSIC
#include "net/routing/rpl-classic/rpl.h"
#endif
#include <stdio.h>
......
......@@ -81,6 +81,10 @@
#define UIP_CONF_ROUTER 1
#endif /* UIP_CONF_ROUTER */
/* UIP_CONF_IPV6_RPL tells whether the RPL routing protocol is running,
whether implemented as RPL Lite or RPL Classic */
#define UIP_CONF_IPV6_RPL (UIP_CONF_IPV6_RPL_LITE || UIP_CONF_IPV6_RPL_CLASSIC)
/* If RPL is enabled also enable the RPL NBR Policy */
#if UIP_CONF_IPV6_RPL
#ifndef NBR_TABLE_FIND_REMOVABLE
......
......@@ -253,7 +253,7 @@ uip_ds6_neighbor_periodic(void)
switch(nbr->state) {
case NBR_REACHABLE:
if(stimer_expired(&nbr->reachable)) {
#if UIP_CONF_IPV6_RPL
#if UIP_CONF_ROUTER
/* when a neighbor leave its REACHABLE state and is a default router,
instead of going to STALE state it enters DELAY state in order to
force a NUD on it. Otherwise, if there is no upward traffic, the
......@@ -273,12 +273,12 @@ uip_ds6_neighbor_periodic(void)
LOG_INFO_(")\n");
nbr->state = NBR_STALE;
}
#else /* UIP_CONF_IPV6_RPL */
#else /* UIP_CONF_ROUTER */
LOG_INFO("REACHABLE: moving to STALE (");
LOG_INFO_6ADDR(&nbr->ipaddr);
LOG_INFO_(")\n");
nbr->state = NBR_STALE;
#endif /* UIP_CONF_IPV6_RPL */
#endif /* UIP_CONF_ROUTER */
}
break;
case NBR_INCOMPLETE:
......
......@@ -62,7 +62,7 @@
#include "net/mac/tsch/tsch-security.h"
#if UIP_CONF_IPV6_RPL
#include "net/mac/tsch/tsch-rpl.h"
#endif /* #if UIP_CONF_IPV6_RPL */
#endif /* UIP_CONF_IPV6_RPL */
#include "net/mac/mac-sequence.h"
#include "lib/random.h"
#include "net/routing/routing.h"
......
......@@ -58,6 +58,29 @@ root_start(void)
return 0;
}
/*---------------------------------------------------------------------------*/
static int
node_is_root(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
get_root_ipaddr(uip_ipaddr_t *ipaddr)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static void
leave_network(void)
{
}
/*---------------------------------------------------------------------------*/
static int
node_is_reachable(void)
{
return 1;
}
/*---------------------------------------------------------------------------*/
static void
global_repair(const char *str)
{
......@@ -118,6 +141,10 @@ const struct routing_driver nullrouting_driver = {
init,
root_set_prefix,
root_start,
node_is_root,
get_root_ipaddr,
leave_network,
node_is_reachable,
global_repair,
local_repair,
ext_header_remove,
......
......@@ -66,6 +66,30 @@ struct routing_driver {
* \return 0 in case of success, -1 otherwise
*/
int (* root_start)(void);
/**
* Tells whether the node is a network root or not
*
* \return 1 if we are root, 0 otherwise
*/
int (* node_is_root)(void);
/**
* Returns the IPv6 address of the network root, if any
*
* \param ipaddr A pointer where to copy the IP address of the root
* \return 1 if the root address was copied, 0 otherwise
*/
int (* get_root_ipaddr)(uip_ipaddr_t *ipaddr);
/**
* Leave the network the node is part of
*
*/
void (* leave_network)(void);
/**
* Tells whether the node is currently reachable as part of the network
*
* \return 1 if we are reachable, 0 otherwise.
*/
int (* node_is_reachable)(void);
/**
* Triggers a global topology repair
*
......
......@@ -383,11 +383,34 @@ drop_route(uip_ds6_route_t *route)
}
}
/*---------------------------------------------------------------------------*/
static void
leave_network(void)
{
PRINTF("RPL: leave_network not supported in RPL Classic\n");
}
/*---------------------------------------------------------------------------*/
static int
get_root_ipaddr(uip_ipaddr_t *ipaddr)
{
rpl_dag_t *dag;
/* Use the DAG id as server address if no other has been specified */
dag = rpl_get_any_dag();
if(dag != NULL && ipaddr != NULL) {
uip_ipaddr_copy(ipaddr, &dag->dag_id);
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
const struct routing_driver rpl_classic_driver = {
"RPL Classic",
init,
rpl_dag_root_set_prefix,
rpl_dag_root_start,
rpl_dag_root_is_root,
get_root_ipaddr,
leave_network,
rpl_has_downward_route,
global_repair,
local_repair,
rpl_ext_header_remove,
......
......@@ -78,6 +78,16 @@ rpl_dag_state_to_str(enum rpl_dag_state state)
}
}
/*---------------------------------------------------------------------------*/
int
rpl_dag_get_root_ipaddr(uip_ipaddr_t *ipaddr)
{
if(curr_instance.used && ipaddr != NULL) {
uip_ipaddr_copy(ipaddr, &curr_instance.dag.dag_id);
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
void
rpl_dag_leave(void)
{
......
......@@ -58,6 +58,13 @@
* \return The description string
*/
const char *rpl_dag_state_to_str(enum rpl_dag_state state);
/**
* Returns the IPv6 address of the RPL DAG root, if any
*
* \param ipaddr A pointer where to copy the IP address of the DAG root
* \return 1 if the root address was copied, 0 otherwise
*/
int rpl_dag_get_root_ipaddr(uip_ipaddr_t *ipaddr);
/**
* Start poisoning and leave the DAG after a delay
*
......
......@@ -210,6 +210,10 @@ const struct routing_driver rpl_lite_driver = {
init,
rpl_dag_root_set_prefix,
rpl_dag_root_start,
rpl_dag_root_is_root,
rpl_dag_get_root_ipaddr,
rpl_dag_poison_and_leave,
rpl_is_reachable,
rpl_global_repair,
rpl_local_repair,
rpl_ext_header_remove,
......
......@@ -59,11 +59,6 @@
#include <string.h>
#include <inttypes.h>
#if UIP_CONF_IPV6_RPL
#include "rpl.h"
#include "net/ipv6/uip-ds6.h"
#endif /* UIP_CONF_IPV6_RPL */
/* Log configuration */
#include "coap-log.h"
#define LOG_MODULE "lwm2m-engine"
......
......@@ -66,7 +66,6 @@
#include "net/routing/rpl-lite/rpl.h"
#elif UIP_CONF_IPV6_RPL_CLASSIC
#include "net/routing/rpl-classic/rpl.h"
#include "net/routing/rpl-classic/rpl-private.h"
#endif
#include <stdlib.h>
......@@ -149,6 +148,50 @@ rpl_ocp_to_str(int ocp)
return "Unknown";
}
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args))
{
PT_BEGIN(pt);
SHELL_OUTPUT(output, "RPL status:\n");
if(!curr_instance.used) {
SHELL_OUTPUT(output, "-- Instance: None\n");
} else {
SHELL_OUTPUT(output, "-- Instance: %u\n", curr_instance.instance_id);
if(NETSTACK_ROUTING.node_is_root()) {
SHELL_OUTPUT(output, "-- DAG root\n");
} else {
SHELL_OUTPUT(output, "-- DAG node\n");
}
SHELL_OUTPUT(output, "-- DAG: ");
shell_output_6addr(output, &curr_instance.dag.dag_id);
SHELL_OUTPUT(output, ", version %u\n", curr_instance.dag.version);
SHELL_OUTPUT(output, "-- Prefix: ");
shell_output_6addr(output, &curr_instance.dag.prefix_info.prefix);
SHELL_OUTPUT(output, "/%u\n", curr_instance.dag.prefix_info.length);
SHELL_OUTPUT(output, "-- MOP: %s\n", rpl_mop_to_str(curr_instance.mop));
SHELL_OUTPUT(output, "-- OF: %s\n", rpl_ocp_to_str(curr_instance.of->ocp));
SHELL_OUTPUT(output, "-- Hop rank increment: %u\n", curr_instance.min_hoprankinc);
SHELL_OUTPUT(output, "-- Default lifetime: %lu seconds\n", RPL_LIFETIME(curr_instance.default_lifetime));
SHELL_OUTPUT(output, "-- State: %s\n", rpl_state_to_str(curr_instance.dag.state));
SHELL_OUTPUT(output, "-- Preferred parent: ");
shell_output_6addr(output, rpl_neighbor_get_ipaddr(curr_instance.dag.preferred_parent));
SHELL_OUTPUT(output, "\n");
SHELL_OUTPUT(output, "-- Rank: %u\n", curr_instance.dag.rank);
SHELL_OUTPUT(output, "-- Lowest rank: %u (%u)\n", curr_instance.dag.lowest_rank, curr_instance.max_rankinc);
SHELL_OUTPUT(output, "-- DTSN out: %u\n", curr_instance.dtsn_out);
SHELL_OUTPUT(output, "-- DAO sequence: last sent %u, last acked %u\n",
curr_instance.dag.dao_last_seqno, curr_instance.dag.dao_last_acked_seqno);
SHELL_OUTPUT(output, "-- Trickle timer: current %u, min %u, max %u, redundancy %u\n",
curr_instance.dag.dio_intcurrent, curr_instance.dio_intmin,
curr_instance.dio_intmin + curr_instance.dio_intdoubl, curr_instance.dio_redundancy);
}
PT_END(pt);
}
#endif /* UIP_CONF_IPV6_RPL_LITE */
/*---------------------------------------------------------------------------*/
static void
......@@ -291,7 +334,6 @@ PT_THREAD(cmd_help(struct pt *pt, shell_output_func output, char *args))
PT_END(pt);
}
#if UIP_CONF_IPV6_RPL_LITE
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_rpl_set_root(struct pt *pt, shell_output_func output, char *args))
......@@ -328,7 +370,7 @@ PT_THREAD(cmd_rpl_set_root(struct pt *pt, shell_output_func output, char *args))
}
if(is_on) {
if(!rpl_dag_root_is_root()) {
if(!NETSTACK_ROUTING.node_is_root()) {
SHELL_OUTPUT(output, "Setting as DAG root with prefix ");
shell_output_6addr(output, &prefix);
SHELL_OUTPUT(output, "/64\n");
......@@ -338,9 +380,9 @@ PT_THREAD(cmd_rpl_set_root(struct pt *pt, shell_output_func output, char *args))
SHELL_OUTPUT(output, "Node is already a DAG root\n");
}
} else {
if(rpl_dag_root_is_root()) {
if(NETSTACK_ROUTING.node_is_root()) {
SHELL_OUTPUT(output, "Setting as non-root node: leaving DAG\n");
rpl_dag_poison_and_leave();
NETSTACK_ROUTING.leave_network();
} else {
SHELL_OUTPUT(output, "Node is not a DAG root\n");
}
......@@ -350,50 +392,6 @@ PT_THREAD(cmd_rpl_set_root(struct pt *pt, shell_output_func output, char *args))
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args))
{
PT_BEGIN(pt);
SHELL_OUTPUT(output, "RPL status:\n");
if(!curr_instance.used) {
SHELL_OUTPUT(output, "-- Instance: None\n");
} else {
SHELL_OUTPUT(output, "-- Instance: %u\n", curr_instance.instance_id);
if(rpl_dag_root_is_root()) {
SHELL_OUTPUT(output, "-- DAG root\n");
} else {
SHELL_OUTPUT(output, "-- DAG node\n");
}
SHELL_OUTPUT(output, "-- DAG: ");
shell_output_6addr(output, &curr_instance.dag.dag_id);
SHELL_OUTPUT(output, ", version %u\n", curr_instance.dag.version);
SHELL_OUTPUT(output, "-- Prefix: ");
shell_output_6addr(output, &curr_instance.dag.prefix_info.prefix);
SHELL_OUTPUT(output, "/%u\n", curr_instance.dag.prefix_info.length);
SHELL_OUTPUT(output, "-- MOP: %s\n", rpl_mop_to_str(curr_instance.mop));
SHELL_OUTPUT(output, "-- OF: %s\n", rpl_ocp_to_str(curr_instance.of->ocp));
SHELL_OUTPUT(output, "-- Hop rank increment: %u\n", curr_instance.min_hoprankinc);
SHELL_OUTPUT(output, "-- Default lifetime: %lu seconds\n", RPL_LIFETIME(curr_instance.default_lifetime));
SHELL_OUTPUT(output, "-- State: %s\n", rpl_state_to_str(curr_instance.dag.state));
SHELL_OUTPUT(output, "-- Preferred parent: ");
shell_output_6addr(output, rpl_neighbor_get_ipaddr(curr_instance.dag.preferred_parent));
SHELL_OUTPUT(output, "\n");
SHELL_OUTPUT(output, "-- Rank: %u\n", curr_instance.dag.rank);
SHELL_OUTPUT(output, "-- Lowest rank: %u (%u)\n", curr_instance.dag.lowest_rank, curr_instance.max_rankinc);
SHELL_OUTPUT(output, "-- DTSN out: %u\n", curr_instance.dtsn_out);
SHELL_OUTPUT(output, "-- DAO sequence: last sent %u, last acked %u\n",
curr_instance.dag.dao_last_seqno, curr_instance.dag.dao_last_acked_seqno);
SHELL_OUTPUT(output, "-- Trickle timer: current %u, min %u, max %u, redundancy %u\n",
curr_instance.dag.dio_intcurrent, curr_instance.dio_intmin,
curr_instance.dio_intmin + curr_instance.dio_intdoubl, curr_instance.dio_redundancy);
}
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_rpl_global_repair(struct pt *pt, shell_output_func output, char *args))
{
PT_BEGIN(pt);
......@@ -414,7 +412,6 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar
PT_END(pt);
}
#endif /* UIP_CONF_IPV6_RPL_LITE */
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args))
......@@ -557,9 +554,9 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
#if RPL_WITH_NON_STORING
rpl_ns_node_t *link;
#endif /* RPL_WITH_NON_STORING */
#if RPL_WITH_STORING
#if (UIP_MAX_ROUTES != 0)
uip_ds6_route_t *route;
#endif /* RPL_WITH_STORING */
#endif /* (UIP_MAX_ROUTES != 0) */
PT_BEGIN(pt);
......@@ -597,7 +594,7 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
SHELL_OUTPUT(output, " to ");
shell_output_6addr(output, &parent_ipaddr);
}
if(link->lifetime != RPL_ROUTE_INFINITE_LIFETIME) {
if(link->lifetime != 0xFFFFFFFF) {
SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)link->lifetime);
} else {
SHELL_OUTPUT(output, " (lifetime: infinite)\n");
......@@ -609,7 +606,7 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
}
#endif /* RPL_WITH_NON_STORING */
#if RPL_WITH_STORING
#if (UIP_MAX_ROUTES != 0)
if(uip_ds6_route_num_routes() > 0) {
/* Our routing entries */
SHELL_OUTPUT(output, "Routing entries (%u in total):\n", uip_ds6_route_num_routes());
......@@ -619,7 +616,7 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
shell_output_6addr(output, &route->ipaddr);
SHELL_OUTPUT(output, " via ");
shell_output_6addr(output, uip_ds6_route_nexthop(route));
if((unsigned long)route->state.lifetime != RPL_ROUTE_INFINITE_LIFETIME) {
if((unsigned long)route->state.lifetime != 0xFFFFFFFF) {
SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime);
} else {
SHELL_OUTPUT(output, " (lifetime: infinite)\n");
......@@ -629,7 +626,7 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
} else {
SHELL_OUTPUT(output, "No routing entries\n");
}
#endif /* RPL_WITH_STORING */
#endif /* (UIP_MAX_ROUTES != 0) */
PT_END(pt);
}
......@@ -724,11 +721,13 @@ struct shell_command_t shell_commands[] = {
{ "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" },
{ "log", cmd_log, "'> log module level': Sets log level (0--4) for a given module (or \"all\"). For module \"mac\", level 4 also enables per-slot logging." },
{ "ping", cmd_ping, "'> ping addr': Pings the IPv6 address 'addr'" },
#if UIP_CONF_IPV6_RPL_LITE
#if UIP_CONF_IPV6_RPL
{ "rpl-set-root", cmd_rpl_set_root, "'> rpl-set-root 0/1 [prefix]': Sets node as root (1) or not (0). A /64 prefix can be optionally specified." },
{ "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" },
{ "rpl-local-repair", cmd_rpl_local_repair, "'> rpl-local-repair': Triggers a RPL local repair" },
{ "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" },
#endif /* UIP_CONF_IPV6_RPL */
#if UIP_CONF_IPV6_RPL_LITE
{ "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" },
#endif /* UIP_CONF_IPV6_RPL_LITE */
{ "routes", cmd_routes, "'> routes': Shows the route entries" },
#if MAC_CONF_WITH_TSCH
......
......@@ -1953,10 +1953,7 @@ INCLUDE_FILE_PATTERNS =
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = CC_FUNCTION_POINTER_ARGS:=1 \
NETSTACK_CONF_WITH_RIME:=1 \
NETSTACK_CONF_WITH_IPV4:=1 \
NETSTACK_CONF_WITH_IPV6:=1 \
UIP_CONF_IPV6_RPL:=1 \
UIP_TCP:=1 \
UIP_UDP:=1 \
UIP_CONF_ICMP6:=1 \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment