diff --git a/Makefile.include b/Makefile.include index 5ca9cd5da..0a013f84a 100644 --- a/Makefile.include +++ b/Makefile.include @@ -52,7 +52,7 @@ ifneq ("$(wildcard project-conf.h)","") CFLAGS += -DPROJECT_CONF_PATH=\"project-conf.h\" endif -MODULES += os os/net os/net/mac os/storage +MODULES += os os/net os/net/mac os/net/routing os/storage oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}} @@ -139,7 +139,7 @@ ifeq ($(WITH_IP64),1) endif # Configure Routing protocol -MAKE_ROUTING_NONE = 0 +MAKE_ROUTING_NULLROUTING = 0 MAKE_ROUTING_RPL_CLASSIC = 1 MAKE_ROUTING_RPL_LITE = 2 @@ -147,19 +147,18 @@ MAKE_ROUTING_RPL_LITE = 2 ifeq ($(MAKE_NET),MAKE_NET_IPV6) MAKE_ROUTING ?= MAKE_ROUTING_RPL_LITE else -MAKE_ROUTING ?= MAKE_ROUTING_NONE +MAKE_ROUTING ?= MAKE_ROUTING_NULLROUTING endif ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_CLASSIC) - CFLAGS += -DUIP_CONF_IPV6_RPL=1 - CFLAGS += -DUIP_CONF_IPV6_RPL_CLASSIC=1 - MODULES += os/net/rpl-classic + CFLAGS += -DROUTING_CONF_RPL_CLASSIC=1 + 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 - MODULES += os/net/rpl-lite -else - CFLAGS += -DUIP_CONF_IPV6_RPL=0 + CFLAGS += -DROUTING_CONF_RPL_LITE=1 + MODULES += os/net/routing/rpl-lite +else ifeq ($(MAKE_ROUTING),MAKE_ROUTING_NULLROUTING) + CFLAGS += -DROUTING_CONF_NULLROUTING=1 + MODULES += os/net/routing/nullrouting endif MODULEDIRS = $(MODULES_REL) ${wildcard ${addprefix $(CONTIKI)/, $(MODULES)}} diff --git a/examples/6tisch/6p-packet/Makefile b/examples/6tisch/6p-packet/Makefile index 1ae6e34b5..7e154f9d3 100644 --- a/examples/6tisch/6p-packet/Makefile +++ b/examples/6tisch/6p-packet/Makefile @@ -4,7 +4,7 @@ PROJECT_SOURCEFILES += test-sf.c CONTIKI = ../../../ MAKE_MAC = MAKE_MAC_TSCH -MAKE_ROUTING = MAKE_ROUTING_NONE +MAKE_ROUTING = MAKE_ROUTING_NULLROUTING MODULES += os/net/mac/tsch/sixtop include $(CONTIKI)/Makefile.include diff --git a/examples/6tisch/etsi-plugtest-2017/node.c b/examples/6tisch/etsi-plugtest-2017/node.c index 578727d1f..3e16666dd 100644 --- a/examples/6tisch/etsi-plugtest-2017/node.c +++ b/examples/6tisch/etsi-plugtest-2017/node.c @@ -38,15 +38,11 @@ #include "contiki.h" #include "node-id.h" -#include "rpl.h" -#include "rpl-dag-root.h" #include "sys/log.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch-log.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #include "serial-shell.h" #include "sf-plugtest.h" #if CONTIKI_TARGET_SRF06_CC26XX @@ -81,7 +77,7 @@ PROCESS_THREAD(node_process, ev, data) #endif if(is_coordinator) { - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); } NETSTACK_MAC.on(); diff --git a/examples/6tisch/simple-node/node.c b/examples/6tisch/simple-node/node.c index 9884b4e0e..4fa416290 100644 --- a/examples/6tisch/simple-node/node.c +++ b/examples/6tisch/simple-node/node.c @@ -38,15 +38,12 @@ #include "contiki.h" #include "node-id.h" -#include "rpl.h" -#include "rpl-dag-root.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/mac/tsch/tsch-log.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #define DEBUG DEBUG_PRINT #include "net/ipv6/uip-debug.h" @@ -69,7 +66,7 @@ PROCESS_THREAD(node_process, ev, data) #endif if(is_coordinator) { - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); } NETSTACK_MAC.on(); @@ -80,11 +77,11 @@ 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 - PRINTF("Routing links: %u\n", rpl_ns_num_nodes()); + #if (UIP_SR_LINK_NUM != 0) + PRINTF("Routing links: %u\n", uip_sr_num_nodes()); #endif PROCESS_YIELD_UNTIL(etimer_expired(&et)); etimer_reset(&et); diff --git a/examples/6tisch/sixtop/node-sixtop.c b/examples/6tisch/sixtop/node-sixtop.c index 4c60db3a7..73e9fab2e 100755 --- a/examples/6tisch/sixtop/node-sixtop.c +++ b/examples/6tisch/sixtop/node-sixtop.c @@ -39,17 +39,13 @@ #include "contiki.h" #include "node-id.h" -#include "rpl.h" -#include "rpl-dag-root.h" #include "sys/log.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch-log.h" #include "net/mac/tsch/tsch-schedule.h" #include "net/mac/tsch/sixtop/sixtop.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #include "sf-simple.h" @@ -77,7 +73,7 @@ PROCESS_THREAD(node_process, ev, data) #endif if(is_coordinator) { - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); } NETSTACK_MAC.on(); diff --git a/examples/ip64-router/ip64-router.c b/examples/ip64-router/ip64-router.c index a6a5af450..632b9ba2e 100644 --- a/examples/ip64-router/ip64-router.c +++ b/examples/ip64-router/ip64-router.c @@ -2,7 +2,7 @@ #include "contiki-net.h" #include "ip64/ip64.h" #include "net/netstack.h" -#include "rpl-dag-root.h" +#include "net/routing/routing.h" #include "sys/autostart.h" /*---------------------------------------------------------------------------*/ @@ -14,7 +14,7 @@ PROCESS_THREAD(router_node_process, ev, data) PROCESS_BEGIN(); /* Set us up as a RPL root node. */ - rpl_dag_root_init_dag_delay(); + NETSTACK_ROUTING.root_start(); /* Initialize the IP64 module so we'll start translating packets */ ip64_init(); diff --git a/examples/ipso-objects/example-server.c b/examples/ipso-objects/example-server.c index a62ba4ffd..4eac38f69 100644 --- a/examples/ipso-objects/example-server.c +++ b/examples/ipso-objects/example-server.c @@ -38,9 +38,8 @@ #include "contiki.h" #include "net/ipv6/uip.h" -#include "rpl.h" -#include "rpl-dag-root.h" #include "net/netstack.h" +#include "net/routing/routing.h" #include "coap-constants.h" #include "coap-engine.h" #include "lwm2m-engine.h" @@ -237,8 +236,8 @@ setup_network(void) uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); #endif - rpl_dag_root_init(&ipaddr, &ipaddr); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_set_prefix(&ipaddr, &ipaddr); + NETSTACK_ROUTING.root_start(); #endif /* UIP_CONF_ROUTER */ PRINTF("IPv6 addresses: "); diff --git a/examples/ipv6-hooks/ipv6-hooks.c b/examples/ipv6-hooks/ipv6-hooks.c index 30269b030..eafc45654 100644 --- a/examples/ipv6-hooks/ipv6-hooks.c +++ b/examples/ipv6-hooks/ipv6-hooks.c @@ -1,5 +1,5 @@ #include "contiki.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "random.h" #include "net/netstack.h" #include "net/ipv6/simple-udp.h" diff --git a/examples/multicast/root.c b/examples/multicast/root.c index b4bf9dcdb..d536211c1 100644 --- a/examples/multicast/root.c +++ b/examples/multicast/root.c @@ -48,8 +48,7 @@ #define DEBUG DEBUG_PRINT #include "net/ipv6/uip-debug.h" -#include "rpl.h" -#include "rpl-dag-root.h" +#include "net/routing/routing.h" #define MAX_PAYLOAD_LEN 120 #define MCAST_SINK_UDP_PORT 3001 /* Host byte order */ @@ -112,7 +111,7 @@ PROCESS_THREAD(rpl_root_process, ev, data) PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); prepare_mcast(); diff --git a/examples/multicast/sink.c b/examples/multicast/sink.c index e15d0f695..34ad6009d 100644 --- a/examples/multicast/sink.c +++ b/examples/multicast/sink.c @@ -71,7 +71,7 @@ tcpip_handler(void) if(uip_newdata()) { count++; PRINTF("In: [0x%08lx], TTL %u, total %u\n", - uip_ntohl((unsigned long) *((uint32_t *)(uip_appdata))), + (unsigned long)uip_ntohl((unsigned long) *((uint32_t *)(uip_appdata))), UIP_IP_BUF->ttl, count); } return; diff --git a/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c b/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c index 18b806ac9..c28b5c741 100644 --- a/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c +++ b/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c @@ -42,11 +42,8 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #include "mqtt.h" -#include "rpl.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-icmp6.h" #include "net/ipv6/sicslowpan.h" diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c b/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c index e12f2cd16..d3042bf81 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c @@ -35,8 +35,13 @@ #include "contiki.h" #include "contiki-lib.h" #include "contiki-net.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "net/ipv6/uip.h" +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#elif ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#endif #include #include diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c b/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c index 59ecee1ce..7eb4ab5ee 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c @@ -36,11 +36,8 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #include "mqtt.h" -#include "rpl.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-icmp6.h" #include "sys/etimer.h" diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c b/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c index 5c6690f34..e24aac689 100644 --- a/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c +++ b/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c @@ -40,10 +40,7 @@ #include "net/netstack.h" #include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6-route.h" -#include "rpl.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #include "coap-engine.h" #include "coap.h" diff --git a/examples/platform-specific/jn516x/rpl/coap-dongle-node/Makefile b/examples/platform-specific/jn516x/rpl/coap-dongle-node/Makefile index 1b39fbae3..538bacf91 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dongle-node/Makefile +++ b/examples/platform-specific/jn516x/rpl/coap-dongle-node/Makefile @@ -8,7 +8,7 @@ CONTIKI=../../../../.. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/lib/json -MODULES_REL += .. ../tools +MODULES_REL += .. MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c b/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c index a41c64b1c..2fb2d7761 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c +++ b/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c @@ -34,7 +34,7 @@ #include "contiki.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" -#include "tools/rpl-tools.h" +#include "net/routing/routing.h" #include "coap-engine.h" #include "sys/ctimer.h" #include @@ -130,12 +130,10 @@ PROCESS_THREAD(start_app, ev, data) /* Start net stack */ if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); - } printf("Starting RPL node\n"); + NETSTACK_ROUTING.root_start(); + } + NETSTACK_MAC.on(); + printf("Starting RPL node\n"); coap_engine_init(); coap_activate_resource(&resource_led_toggle, "Dongle/LED-toggle"); diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/Makefile b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/Makefile index 79a7e7f13..6fb119351 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/Makefile +++ b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/Makefile @@ -8,7 +8,7 @@ CONTIKI=../../../../.. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/lib/json -MODULES_REL += .. ../tools +MODULES_REL += .. MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c index 4c59f3d7b..443cf4fbe 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c +++ b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c @@ -35,7 +35,7 @@ #include "contiki.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" -#include "tools/rpl-tools.h" +#include "net/routing/routing.h" #include "coap-engine.h" #include "light-sensor.h" #include "ht-sensor.h" @@ -350,12 +350,10 @@ PROCESS_THREAD(start_app, ev, data) /* Start net stack */ if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); - } printf("Starting RPL node\n"); + NETSTACK_ROUTING.root_start(); + } + NETSTACK_MAC.on(); + printf("Starting RPL node\n"); coap_engine_init(); coap_activate_resource(&resource_light_sensor_value, "DR1175/LightSensor/Value"); diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/Makefile b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/Makefile index a5887a8ef..bdef1a42a 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/Makefile +++ b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/Makefile @@ -8,7 +8,7 @@ CONTIKI=../../../../.. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/lib/json -MODULES_REL += .. ../tools +MODULES_REL += .. MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c index e03e76747..d341170ad 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c +++ b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c @@ -34,7 +34,7 @@ #include "contiki.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" -#include "tools/rpl-tools.h" +#include "net/routing/routing.h" #include "coap-engine.h" #include "dev/leds.h" #include "button-sensor.h" @@ -351,12 +351,10 @@ PROCESS_THREAD(start_app, ev, data) /* Start net stack */ if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); - } printf("Starting RPL node\n"); + NETSTACK_ROUTING.root_start(); + } + NETSTACK_MAC.on(); + printf("Starting RPL node\n"); coap_engine_init(); coap_activate_resource(&resource_switch_sw1, "DR1199/Switch/SW1"); diff --git a/examples/platform-specific/jn516x/rpl/node/Makefile b/examples/platform-specific/jn516x/rpl/node/Makefile index 83cd48869..228287cf8 100644 --- a/examples/platform-specific/jn516x/rpl/node/Makefile +++ b/examples/platform-specific/jn516x/rpl/node/Makefile @@ -6,6 +6,6 @@ TARGET ?= jn516x CONTIKI=../../../../.. MAKE_MAC = MAKE_MAC_TSCH -MODULES_REL += .. ../tools +MODULES_REL += .. include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/jn516x/rpl/node/node.c b/examples/platform-specific/jn516x/rpl/node/node.c index 3c24f36c1..71e015e6d 100644 --- a/examples/platform-specific/jn516x/rpl/node/node.c +++ b/examples/platform-specific/jn516x/rpl/node/node.c @@ -37,8 +37,7 @@ #include "contiki.h" #include "net/ipv6/uip-ds6.h" -#include "rpl.h" -#include "tools/rpl-tools.h" +#include "net/routing/routing.h" #define DEBUG DEBUG_PRINT #include "net/ipv6/uip-debug.h" @@ -59,7 +58,6 @@ AUTOSTART_PROCESSES(&node_process); /*---------------------------------------------------------------------------*/ PROCESS_THREAD(node_process, ev, data) { - static struct etimer et; PROCESS_BEGIN(); /* 3 possible roles: @@ -73,6 +71,7 @@ PROCESS_THREAD(node_process, ev, data) #if CONFIG_VIA_BUTTON { #define CONFIG_WAIT_TIME 5 + static struct etimer et; SENSORS_ACTIVATE(button_sensor); etimer_set(&et, CLOCK_SECOND * CONFIG_WAIT_TIME); @@ -96,22 +95,10 @@ PROCESS_THREAD(node_process, ev, data) node_role == role_6ln ? "6ln" : "6dr"); is_coordinator = node_role > role_6ln; - if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); - } - - /* Print out routing tables every minute */ - etimer_set(&et, CLOCK_SECOND * 60); - while(1) { - print_network_status(); - PROCESS_YIELD_UNTIL(etimer_expired(&et)); - etimer_reset(&et); + NETSTACK_ROUTING.root_start(); } + NETSTACK_MAC.on(); PROCESS_END(); } diff --git a/examples/platform-specific/jn516x/rpl/tools/rpl-tools.c b/examples/platform-specific/jn516x/rpl/tools/rpl-tools.c deleted file mode 100644 index 570be8566..000000000 --- a/examples/platform-specific/jn516x/rpl/tools/rpl-tools.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2015, SICS Swedish ICT. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -/** - * \file - * - * \author Simon Duquennoy - */ - -#include "contiki.h" -#include "contiki-net.h" -#include "net/ipv6/uip.h" -#include "rpl.h" -#include "rpl-dag-root.h" -#include -#include - -#define DEBUG DEBUG_PRINT -#include "net/ipv6/uip-debug.h" - -/*---------------------------------------------------------------------------*/ -void -print_network_status(void) -{ - int i; - uint8_t state; - uip_ds6_defrt_t *default_route; - uip_ds6_route_t *route; - - PRINTA("--- Network status ---\n"); - - /* Our IPv6 addresses */ - PRINTA("- Server IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { - PRINTA("-- "); - uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); - PRINTA("\n"); - } - } - - /* Our default route */ - PRINTA("- Default route:\n"); - default_route = uip_ds6_defrt_lookup(uip_ds6_defrt_choose()); - if(default_route != NULL) { - PRINTA("-- "); - uip_debug_ipaddr_print(&default_route->ipaddr);; - PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)default_route->lifetime.interval); - } else { - PRINTA("-- None\n"); - } - - /* Our routing entries */ - PRINTA("- Routing entries (%u in total):\n", uip_ds6_route_num_routes()); - route = uip_ds6_route_head(); - while(route != NULL) { - PRINTA("-- "); - uip_debug_ipaddr_print(&route->ipaddr); - PRINTA(" via "); - uip_debug_ipaddr_print(uip_ds6_route_nexthop(route)); - PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime); - route = uip_ds6_route_next(route); - } - - PRINTA("----------------------\n"); -} -/*---------------------------------------------------------------------------*/ -static void -print_local_addresses(void) -{ - int i; - uint8_t state; - - PRINTA("Server IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { - PRINTA(" "); - uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); - PRINTA("\n"); - } - } -} -/*---------------------------------------------------------------------------*/ -void -rpl_tools_init(uip_ipaddr_t *br_prefix) -{ - if(br_prefix) { /* We are root */ - rpl_dag_root_init(br_prefix, NULL); - rpl_dag_root_init_dag_immediately(); - } else { - rpl_dag_root_init(NULL, NULL); - } - - - NETSTACK_MAC.on(); - - print_local_addresses(); -} diff --git a/examples/platform-specific/jn516x/rpl/tools/rpl-tools.h b/examples/platform-specific/jn516x/rpl/tools/rpl-tools.h deleted file mode 100644 index f14ec1d86..000000000 --- a/examples/platform-specific/jn516x/rpl/tools/rpl-tools.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015, SICS Swedish ICT. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -/** - - * \author Simon Duquennoy - */ - -void rpl_tools_init(uip_ipaddr_t *br_prefix); -void print_network_status(void); diff --git a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/Makefile b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/Makefile index 2e7e32585..82685c610 100644 --- a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/Makefile +++ b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/Makefile @@ -5,7 +5,7 @@ JN516x_WITH_DONGLE = 1 CONTIKI=../../../../../.. -MODULES_REL += .. ../../tools +MODULES_REL += .. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/net/app-layer/coap MODULES += os/services/orchestra os/lib/json diff --git a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c index 0b1bc3414..12350a5f4 100644 --- a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c +++ b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c @@ -37,14 +37,10 @@ #include "net/mac/tsch/tsch-schedule.h" #include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch-private.h" -#include "rpl.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" #include "net/mac/tsch/tsch-schedule.h" #include "net/ipv6/uip-debug.h" #include "lib/random.h" -#include "rpl-tools.h" #include "node-id.h" #include "waveform.h" #include "leds.h" @@ -173,12 +169,9 @@ PROCESS_THREAD(node_process, ev, data) is_coordinator = node_role > role_6ln; if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, 0xbbbb, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); + NETSTACK_ROUTING.root_start(); } + NETSTACK_MAC.on(); /* Selected waveform depends on LS byte of MAC */ selected_waveform = node_mac[7] % NUMBER_OF_WAVEFORMS; @@ -214,10 +207,6 @@ PROCESS_THREAD(node_process, ev, data) printf("No host\n"); } etimer_restart(&et); - if (total_time%60 == 0) { - /* Print network status once per minute */ - print_network_status(); - } } } PROCESS_END(); diff --git a/examples/platform-specific/jn516x/tsch/tools/rpl-tools.c b/examples/platform-specific/jn516x/tsch/tools/rpl-tools.c deleted file mode 100644 index e71a19bc9..000000000 --- a/examples/platform-specific/jn516x/tsch/tools/rpl-tools.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2014, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -/** - * \file - * - * \author Simon Duquennoy - */ - -#include "contiki.h" -#include "contiki-net.h" -#include "net/ipv6/uip.h" -#include "rpl.h" -#include "rpl-dag-root.h" -#include -#include - -#define DEBUG DEBUG_PRINT -#include "net/ipv6/uip-debug.h" - -void -print_network_status(void) -{ - int i; - uint8_t state; - uip_ds6_defrt_t *default_route; - uip_ds6_route_t *route; - PRINTA("--- Network status ---\n"); - /* Our IPv6 addresses */ - PRINTA("- Server IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { - PRINTA("-- "); - uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); - PRINTA("\n"); - } - } - /* Our default route */ - PRINTA("- Default route:\n"); - default_route = uip_ds6_defrt_lookup(uip_ds6_defrt_choose()); - if(default_route != NULL) { - PRINTA("-- "); - uip_debug_ipaddr_print(&default_route->ipaddr);; - PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)default_route->lifetime.interval); - } else { - PRINTA("-- None\n"); - } - /* Our routing entries */ - PRINTA("- Routing entries (%u in total):\n", uip_ds6_route_num_routes()); - route = uip_ds6_route_head(); - while(route != NULL) { - PRINTA("-- "); - uip_debug_ipaddr_print(&route->ipaddr); - PRINTA(" via "); - uip_debug_ipaddr_print(uip_ds6_route_nexthop(route)); - PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime); - route = uip_ds6_route_next(route); - } - PRINTA("----------------------\n"); -} -/*---------------------------------------------------------------------------*/ -static void -print_local_addresses(void) -{ - int i; - uint8_t state; - - PRINTA("Server IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { - PRINTA(" "); - uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); - PRINTA("\n"); - } - } -} -/*---------------------------------------------------------------------------*/ -void -rpl_tools_init(uip_ipaddr_t *br_prefix) -{ - if(br_prefix) { /* We are root */ - rpl_dag_root_init(br_prefix, NULL); - rpl_dag_root_init_dag_immediately(); - } else { - rpl_dag_root_init(NULL, NULL); - } - - /* Start TSCH */ - NETSTACK_MAC.on(); - print_local_addresses(); -} diff --git a/examples/platform-specific/jn516x/tsch/tools/rpl-tools.h b/examples/platform-specific/jn516x/tsch/tools/rpl-tools.h deleted file mode 100644 index b04cdb712..000000000 --- a/examples/platform-specific/jn516x/tsch/tools/rpl-tools.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2014, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -/** - - * \author Simon Duquennoy - */ - -void rpl_tools_init(uip_ipaddr_t *br_prefix); -void print_network_status(void); diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/Makefile b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/Makefile index 3884b9d30..43a0490ce 100644 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/Makefile +++ b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/Makefile @@ -5,7 +5,7 @@ JN516x_WITH_DONGLE = 1 CONTIKI=../../../../../.. -MODULES_REL += .. ../../tools +MODULES_REL += .. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c index b8ad8bc7b..995dc3304 100644 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c +++ b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c @@ -33,13 +33,13 @@ */ #include "contiki.h" #include "net/ipv6/uip-ds6.h" +#include "net/routing/routing.h" #include "net/netstack.h" #include "net/ipv6/uip.h" #include "net/linkaddr.h" -#include "rpl-tools.h" #include "coap-engine.h" -#include -#include +#include +#include #include static void set_tx_power_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -56,7 +56,7 @@ AUTOSTART_PROCESSES(&start_app); /*---------------------------------------------------------------------------*/ /*********** sensor/ resource ************************************************/ -RESOURCE(resource_set_tx_power, +RESOURCE(resource_set_tx_power, "title=\"Set TX Power\"", NULL, set_tx_power_handler, @@ -77,7 +77,7 @@ set_tx_power_handler(coap_message_t *request, coap_message_t *response, uint8_t } } -RESOURCE(resource_get_tx_power, +RESOURCE(resource_get_tx_power, "title=\"Get TX Power\"", get_tx_power_handler, NULL, @@ -102,17 +102,14 @@ PROCESS_THREAD(start_app, ev, data) { PROCESS_BEGIN(); static int is_coordinator = 0; - + /* Start network stack */ if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); + NETSTACK_ROUTING.root_start(); } + NETSTACK_MAC.on(); printf("Starting RPL node\n"); - + coap_engine_init(); coap_activate_resource(&resource_set_tx_power, "Set-TX-Power"); coap_activate_resource(&resource_get_tx_power, "Get-TX-Power"); diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile index 3773e04a5..edbc2fe19 100644 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile +++ b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile @@ -7,7 +7,7 @@ CONTIKI=../../../../../.. PROJECT_SOURCEFILES += slip-bridge.c slip.c -MODULES_REL += .. ../../tools +MODULES_REL += .. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c index 5d9f83df1..642e370d1 100644 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c +++ b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c @@ -36,14 +36,13 @@ #include "contiki-net.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "simple-udp.h" #include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch-schedule.h" #include "net/netstack.h" #include "dev/slip.h" #include "coap-engine.h" -#include "rpl-tools.h" #include #include @@ -67,7 +66,7 @@ static int content_len = 0; PROCESS(border_router_process, "Border router process"); AUTOSTART_PROCESSES(&border_router_process); -RESOURCE(resource_get_rssi, +RESOURCE(resource_get_rssi, "title=\"Get RSSI\"", get_rssi_handler, NULL, @@ -88,7 +87,7 @@ get_rssi_handler(coap_message_t *request, coap_message_t *response, uint8_t *buf } } -RESOURCE(resource_get_last_rssi, +RESOURCE(resource_get_last_rssi, "title=\"Get last RSSI\"", get_last_rssi_handler, NULL, @@ -157,7 +156,8 @@ PROCESS_THREAD(border_router_process, ev, data) uip_debug_ipaddr_print(&prefix); PRINTF("\n"); - rpl_tools_init(&prefix); + NETSTACK_ROUTING.root_set_prefix(&prefix, NULL); + NETSTACK_ROUTING.root_start(); coap_engine_init(); coap_activate_resource(&resource_get_rssi, "Get-RSSI"); diff --git a/examples/platform-specific/jn516x/tsch/uart1-test-node/Makefile b/examples/platform-specific/jn516x/tsch/uart1-test-node/Makefile index 640495432..1dd86cc3d 100644 --- a/examples/platform-specific/jn516x/tsch/uart1-test-node/Makefile +++ b/examples/platform-specific/jn516x/tsch/uart1-test-node/Makefile @@ -6,7 +6,7 @@ TARGET_WITH_UART1 = 1 CONTIKI=../../../../.. -MODULES_REL += .. ../tools +MODULES_REL += .. MAKE_MAC = MAKE_MAC_TSCH MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c b/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c index affb6e6ca..dd647fa21 100644 --- a/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c +++ b/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c @@ -34,8 +34,8 @@ #include "contiki.h" #include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip.h" +#include "net/routing/routing.h" #include "net/linkaddr.h" -#include "rpl-tools.h" #include "coap-engine.h" #include "sys/ctimer.h" #include "dev/uart-driver.h" @@ -64,7 +64,7 @@ static int tail_index = 0; /* index where last read took place */ /* String aligned buffer */ #define RX_BUFFER_SIZE RINGBUF_SIZE -static uint8_t rx_buf[RX_BUFFER_SIZE+1]; +static uint8_t rx_buf[RX_BUFFER_SIZE+1]; static uint8_t rx_buf_index = 0; /* index for rx_buf */ /*---------------------------------------------------------------------------*/ @@ -75,7 +75,7 @@ AUTOSTART_PROCESSES(&start_app, &rx_data_process); /*********** COAP resources *************************************************/ /*****************************************************************************/ -/* Observable resource and event handler to obtain terminal input from UART1 */ +/* Observable resource and event handler to obtain terminal input from UART1 */ /*****************************************************************************/ EVENT_RESOURCE(resource_coap_rx_uart1, /* name */ "obs;title=\"rx_uart1\"", /* attributes */ @@ -95,7 +95,7 @@ get_coap_rx_uart1_handler(coap_message_t *request, coap_message_t *response, uin coap_set_header_content_format(response, TEXT_PLAIN); coap_set_payload(response, (uint8_t *)content, content_len); } -} +} static void event_coap_rx_uart1_handler(void) @@ -105,7 +105,7 @@ event_coap_rx_uart1_handler(void) } /*****************************************************************************/ -/* GET/PUT resource to send data to terminal on UART1 */ +/* GET/PUT resource to send data to terminal on UART1 */ /*****************************************************************************/ RESOURCE(resource_coap_tx_uart1, /* name */ "obs;title=\"tx_uart1\"", /* attributes */ @@ -140,20 +140,17 @@ PROCESS_THREAD(start_app, ev, data) /* Define process that handles data */ process_start(&rx_data_process ,NULL); /* Initialise UART1 */ - uart1_init(UART1_BAUD_RATE); + uart1_init(UART1_BAUD_RATE); /* Callback received byte */ uart1_set_input(handleRxChar); /* Start network stack */ if(is_coordinator) { - uip_ipaddr_t prefix; - uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); - rpl_tools_init(&prefix); - } else { - rpl_tools_init(NULL); + NETSTACK_ROUTING.root_start(); } + NETSTACK_MAC.on(); printf("Starting RPL node\n"); - + coap_engine_init(); coap_activate_resource(&resource_coap_rx_uart1, "UART1-RX"); coap_activate_resource(&resource_coap_tx_uart1, "UART1-TX"); @@ -166,29 +163,29 @@ PROCESS_THREAD(start_app, ev, data) PROCESS_THREAD(rx_data_process, ev, data) { PROCESS_BEGIN(); - + /* Process is polled whenever data is available from uart isr */ uint8_t c; while(1) { PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); - /* Read RX ringbuffer. ASCII chars Output when LF is seen. - If overflowed, strings are skipped */ + /* Read RX ringbuffer. ASCII chars Output when LF is seen. + If overflowed, strings are skipped */ do { if (get_ringbuf(&c) == -1) { break; /* No more rx char's in ringbuffer */ } else { if (rx_buf_index == RX_BUFFER_SIZE) { /* Skip current content if buffer full */ rx_buf_index = 0; - } + } rx_buf[rx_buf_index++] = c; if ((c == '\n')||(c == '\r')) { rx_buf[rx_buf_index] = '\0'; - printf("RX on UART1: %s", rx_buf); + printf("RX on UART1: %s", rx_buf); /* Signal event to coap clients. Demo assumes data is consumed before new data comes in */ - event_coap_rx_uart1_handler(); - rx_buf_index = 0; + event_coap_rx_uart1_handler(); + rx_buf_index = 0; } } } while (1); @@ -200,7 +197,7 @@ PROCESS_THREAD(rx_data_process, ev, data) /* Local test functions */ /*************************************************************************/ /* TX function for UART1 */ -static void +static void string2uart1(uint8_t *c) { while (*c!= '\0') { @@ -210,7 +207,7 @@ string2uart1(uint8_t *c) } /* handleRxChar runs on uart isr */ -static int +static int handleRxChar(uint8_t c) { if (put_ringbuf(c) == -1) { @@ -225,7 +222,7 @@ handleRxChar(uint8_t c) /* Simple ringbuffer if tail==head, no data has been written yet on that position. So, empty buffer is also initial state */ -static int +static int get_ringbuf(uint8_t *c) { int return_val = 0; @@ -241,7 +238,7 @@ get_ringbuf(uint8_t *c) return return_val; } -static int +static int put_ringbuf(uint8_t c) { int return_val = 0; @@ -249,10 +246,10 @@ put_ringbuf(uint8_t c) uart1_disable_interrupts(); if (head_index != tail_index) { ringbuf[head_index] = c; - head_index = ((head_index+1)&RINGBUF_MAX_INDEX); + head_index = ((head_index+1)&RINGBUF_MAX_INDEX); } else { return_val = -1; } uart1_enable_interrupts(); - return return_val; + return return_val; } diff --git a/examples/platform-specific/nrf52dk/blink-hello/Makefile b/examples/platform-specific/nrf52dk/blink-hello/Makefile index d5d2de18d..9bc1ee34f 100644 --- a/examples/platform-specific/nrf52dk/blink-hello/Makefile +++ b/examples/platform-specific/nrf52dk/blink-hello/Makefile @@ -1,6 +1,6 @@ CONTIKI_PROJECT = blink-hello -MAKE_ROUTING = MAKE_ROUTING_NONE +MAKE_ROUTING = MAKE_ROUTING_NULLROUTING MAKE_MAC=MAKE_MAC_NULLMAC NRF52_WITHOUT_SOFTDEVICE=1 diff --git a/examples/platform-specific/nrf52dk/coap-demo/Makefile b/examples/platform-specific/nrf52dk/coap-demo/Makefile index 0ad01fc57..39692524d 100644 --- a/examples/platform-specific/nrf52dk/coap-demo/Makefile +++ b/examples/platform-specific/nrf52dk/coap-demo/Makefile @@ -21,6 +21,6 @@ MODULES_REL += ./resources # REST Engine shall use Erbium CoAP implementation MODULES += os/net/app-layer/coap -MAKE_ROUTING = MAKE_ROUTING_NONE +MAKE_ROUTING = MAKE_ROUTING_NULLROUTING include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/nrf52dk/mqtt-demo/Makefile b/examples/platform-specific/nrf52dk/mqtt-demo/Makefile index bf1b35fff..d32903531 100644 --- a/examples/platform-specific/nrf52dk/mqtt-demo/Makefile +++ b/examples/platform-specific/nrf52dk/mqtt-demo/Makefile @@ -1,6 +1,6 @@ all: mqtt-demo -MAKE_ROUTING = MAKE_ROUTING_NONE +MAKE_ROUTING = MAKE_ROUTING_NULLROUTING MODULES += os/net/app-layer/mqtt diff --git a/examples/platform-specific/nrf52dk/timer-test/Makefile b/examples/platform-specific/nrf52dk/timer-test/Makefile index de851dcf1..c5ddcfbd2 100644 --- a/examples/platform-specific/nrf52dk/timer-test/Makefile +++ b/examples/platform-specific/nrf52dk/timer-test/Makefile @@ -1,6 +1,6 @@ CONTIKI_PROJECT = timer-test -MAKE_ROUTING = MAKE_ROUTING_NONE +MAKE_ROUTING = MAKE_ROUTING_NULLROUTING MAKE_MAC=MAKE_MAC_NULLMAC NRF52_WITHOUT_SOFTDEVICE=1 diff --git a/examples/platform-specific/zoul/orion/client/client.c b/examples/platform-specific/zoul/orion/client/client.c index 18f1a5e91..ebbd34fb0 100644 --- a/examples/platform-specific/zoul/orion/client/client.c +++ b/examples/platform-specific/zoul/orion/client/client.c @@ -33,7 +33,7 @@ #include "http-socket.h" #include "ipv6/ip64-addr.h" #include "dev/leds.h" -#include "rpl.h" +#include "net/routing/routing.h" #include /*---------------------------------------------------------------------------*/ static struct http_socket s; diff --git a/examples/platform-specific/zoul/orion/client/ifttt-client.c b/examples/platform-specific/zoul/orion/client/ifttt-client.c index ec1288753..7cc962c18 100644 --- a/examples/platform-specific/zoul/orion/client/ifttt-client.c +++ b/examples/platform-specific/zoul/orion/client/ifttt-client.c @@ -33,7 +33,7 @@ #include "http-socket.h" #include "ipv6/ip64-addr.h" #include "dev/leds.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "dev/button-sensor.h" #include /*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c b/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c index 433f58426..5f2a98e24 100644 --- a/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c +++ b/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c @@ -45,8 +45,7 @@ #include "contiki-net.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" -#include "rpl.h" -#include "rpl-dag-root.h" +#include "net/routing/routing.h" #include "dev/leds.h" #include "ip64/ip64.h" #include "net/netstack.h" @@ -248,7 +247,7 @@ PT_THREAD(generate_routes(struct httpd_state *s)) #if WEBSERVER_CONF_LOADTIME numticks = clock_time() - numticks + 1; - ADD(" (%u.%02u sec)", numticks / CLOCK_SECOND, + ADD(" (%u.%02u sec)", numticks / CLOCK_SECOND, (100 * (numticks % CLOCK_SECOND)) / CLOCK_SECOND)); #endif @@ -308,7 +307,7 @@ PROCESS_THREAD(router_node_process, ev, data) leds_off(LEDS_DHCP); /* Set us up as a RPL root node. */ - rpl_dag_root_init_dag_delay(); + NETSTACK_ROUTING.root_start(); /* ... and do nothing more. */ while(1) { diff --git a/examples/rpl-border-router/webserver/webserver.c b/examples/rpl-border-router/webserver/webserver.c index 61be96086..3658381bf 100644 --- a/examples/rpl-border-router/webserver/webserver.c +++ b/examples/rpl-border-router/webserver/webserver.c @@ -31,50 +31,31 @@ */ #include "contiki.h" -#include "rpl.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" +#include "net/ipv6/uip-ds6-route.h" +#include "net/ipv6/uip-sr.h" #include #include /*---------------------------------------------------------------------------*/ -static const char *TOP = "Contiki-NG\n"; -static const char *BOTTOM = "\n"; -#if BUF_USES_STACK -static char *bufptr, *bufend; -#define ADD(...) do { \ - bufptr += snprintf(bufptr, bufend - bufptr, __VA_ARGS__); \ - } while(0) -#else +static const char *TOP = "\n \n Contiki-NG\n \n\n"; +static const char *BOTTOM = "\n\n\n"; static char buf[256]; static int blen; #define ADD(...) do { \ blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \ } while(0) -#endif +#define SEND(s) do { \ + SEND_STRING(s, buf); \ + blen = 0; \ +} while(0); /* Use simple webserver with only one page for minimum footprint. * Multiple connections can result in interleaved tcp segments since * a single static buffer is used for all segments. */ #include "httpd-simple.h" -/* The internal webserver can provide additional information if - * enough program flash is available. - */ -#define WEBSERVER_CONF_LOADTIME 0 -#define WEBSERVER_CONF_FILESTATS 0 -#define WEBSERVER_CONF_NEIGHBOR_STATUS 0 -/* Adding links requires a larger RAM buffer. To avoid static allocation - * the stack can be used for formatting; however tcp retransmissions - * and multiple connections can result in garbled segments. - * TODO:use PSOCk_GENERATOR_SEND and tcp state storage to fix this. - */ -#define WEBSERVER_CONF_ROUTE_LINKS 0 -#if WEBSERVER_CONF_ROUTE_LINKS -#define BUF_USES_STACK 1 -#endif /*---------------------------------------------------------------------------*/ static void @@ -102,210 +83,72 @@ ipaddr_add(const uip_ipaddr_t *addr) static PT_THREAD(generate_routes(struct httpd_state *s)) { - static uip_ds6_route_t *r; -#if RPL_WITH_NON_STORING - static rpl_ns_node_t *link; -#endif /* RPL_WITH_NON_STORING */ static uip_ds6_nbr_t *nbr; -#if BUF_USES_STACK - char buf[256]; -#endif -#if WEBSERVER_CONF_LOADTIME - static clock_time_t numticks; - numticks = clock_time(); -#endif PSOCK_BEGIN(&s->sout); - SEND_STRING(&s->sout, TOP); -#if BUF_USES_STACK - bufptr = buf; - bufend = bufptr + sizeof(buf); -#else - blen = 0; -#endif - ADD("Neighbors
");
 
+  ADD("  Neighbors\n  
    \n"); + SEND(&s->sout); for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) { - -#if WEBSERVER_CONF_NEIGHBOR_STATUS -#if BUF_USES_STACK - { char *j = bufptr + 25; - ipaddr_add(&nbr->ipaddr); - while(bufptr < j) ADD(" "); - switch(nbr->state) { - case NBR_INCOMPLETE: ADD(" INCOMPLETE"); - break; - case NBR_REACHABLE: ADD(" REACHABLE"); - break; - case NBR_STALE: ADD(" STALE"); - break; - case NBR_DELAY: ADD(" DELAY"); - break; - case NBR_PROBE: ADD(" NBR_PROBE"); - break; - } - } -#else - { uint8_t j = blen + 25; - ipaddr_add(&nbr->ipaddr); - while(blen < j) ADD(" "); - switch(nbr->state) { - case NBR_INCOMPLETE: ADD(" INCOMPLETE"); - break; - case NBR_REACHABLE: ADD(" REACHABLE"); - break; - case NBR_STALE: ADD(" STALE"); - break; - case NBR_DELAY: ADD(" DELAY"); - break; - case NBR_PROBE: ADD(" NBR_PROBE"); - break; - } - } -#endif -#else + ADD("
  • "); ipaddr_add(&nbr->ipaddr); -#endif - - ADD("\n"); -#if BUF_USES_STACK - if(bufptr > bufend - 45) { - SEND_STRING(&s->sout, buf); - bufptr = buf; - bufend = bufptr + sizeof(buf); - } -#else - if(blen > sizeof(buf) - 45) { - SEND_STRING(&s->sout, buf); - blen = 0; - } -#endif + ADD("
  • \n"); + SEND(&s->sout); } - ADD("
Routes
\n");
-  SEND_STRING(&s->sout, buf);
-#if BUF_USES_STACK
-  bufptr = buf;
-  bufend = bufptr + sizeof(buf);
-#else
-  blen = 0;
-#endif
+  ADD("  \n");
+  SEND(&s->sout);
 
-  for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
-
-#if BUF_USES_STACK
-#if WEBSERVER_CONF_ROUTE_LINKS
-    ADD("ipaddr);
-    ADD("]/status.shtml>");
-    ipaddr_add(&r->ipaddr);
-    ADD("");
-#else
-    ipaddr_add(&r->ipaddr);
-#endif
-#else
-#if WEBSERVER_CONF_ROUTE_LINKS
-    ADD("ipaddr);
-    ADD("]/status.shtml>");
-    SEND_STRING(&s->sout, buf);
-    blen = 0;
-    ipaddr_add(&r->ipaddr);
-    ADD("");
-#else
-    ipaddr_add(&r->ipaddr);
-#endif
-#endif
-    ADD("/%u (via ", r->length);
-    ipaddr_add(uip_ds6_route_nexthop(r));
-    if(1 || (r->state.lifetime < 600)) {
-      ADD(") %lus\n", (unsigned long)r->state.lifetime);
-    } else {
-      ADD(")\n");
+#if (UIP_MAX_ROUTES != 0)
+  {
+    static uip_ds6_route_t *r;
+    ADD("  Routes\n  
    \n"); + SEND(&s->sout); + for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) { + ADD("
  • "); + ipaddr_add(&r->ipaddr); + ADD("/%u (via ", r->length); + ipaddr_add(uip_ds6_route_nexthop(r)); + ADD(") %lus", (unsigned long)r->state.lifetime); + ADD("
  • \n"); + SEND(&s->sout); } - SEND_STRING(&s->sout, buf); -#if BUF_USES_STACK - bufptr = buf; - bufend = bufptr + sizeof(buf); -#else - blen = 0; -#endif + ADD("
\n"); + SEND(&s->sout); } - ADD("
"); +#endif /* UIP_MAX_ROUTES != 0 */ -#if RPL_WITH_NON_STORING - ADD("Links
\n");
-  SEND_STRING(&s->sout, buf);
-#if BUF_USES_STACK
-  bufptr = buf;
-  bufend = bufptr + sizeof(buf);
-#else
-  blen = 0;
-#endif
-  for(link = rpl_ns_node_head(); link != NULL; link = rpl_ns_node_next(link)) {
-    if(link->parent != NULL) {
-      uip_ipaddr_t child_ipaddr;
-      uip_ipaddr_t parent_ipaddr;
+#if (UIP_SR_LINK_NUM != 0)
+  if(uip_sr_num_nodes() > 0) {
+    static uip_sr_node_t *link;
+    ADD("  Routing links\n  
    \n"); + SEND(&s->sout); + for(link = uip_sr_node_head(); link != NULL; link = uip_sr_node_next(link)) { + if(link->parent != NULL) { + uip_ipaddr_t child_ipaddr; + uip_ipaddr_t parent_ipaddr; - rpl_ns_get_node_global_addr(&child_ipaddr, link); - rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent); + NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link); + NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent); -#if BUF_USES_STACK -#if WEBSERVER_CONF_ROUTE_LINKS - ADD(""); - ipaddr_add(&child_ipaddr); - ADD(""); -#else - ipaddr_add(&child_ipaddr); -#endif -#else -#if WEBSERVER_CONF_ROUTE_LINKS - ADD(""); - SEND_STRING(&s->sout, buf); - blen = 0; - ipaddr_add(&child_ipaddr); - ADD(""); -#else - ipaddr_add(&child_ipaddr); -#endif -#endif + ADD("
  • "); + ipaddr_add(&child_ipaddr); - ADD(" (parent: "); - ipaddr_add(&parent_ipaddr); - if(1 || (link->lifetime < 600)) { - ADD(") %us\n", (unsigned int)link->lifetime); - } else { - ADD(")\n"); + ADD(" (parent: "); + ipaddr_add(&parent_ipaddr); + ADD(") %us", (unsigned int)link->lifetime); + + ADD("
  • \n"); + SEND(&s->sout); } - SEND_STRING(&s->sout, buf); -#if BUF_USES_STACK - bufptr = buf; - bufend = bufptr + sizeof(buf); -#else - blen = 0; -#endif } + ADD("
"); + SEND(&s->sout); } - ADD("
"); -#endif /* RPL_WITH_NON_STORING */ +#endif /* UIP_SR_LINK_NUM != 0 */ -#if WEBSERVER_CONF_FILESTATS - static uint16_t numtimes; - ADD("
This page sent %u times", ++numtimes); -#endif - -#if WEBSERVER_CONF_LOADTIME - numticks = clock_time() - numticks + 1; - ADD(" (%u.%02u sec)", numticks / CLOCK_SECOND, (100 * (numticks % CLOCK_SECOND)) / CLOCK_SECOND)); -#endif - - SEND_STRING(&s->sout, buf); SEND_STRING(&s->sout, BOTTOM); PSOCK_END(&s->sout); diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index 10e336dac..a10d188ac 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -1,5 +1,5 @@ #include "contiki.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "random.h" #include "net/netstack.h" #include "net/ipv6/simple-udp.h" @@ -45,6 +45,7 @@ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic_timer; static unsigned count; + uip_ipaddr_t dest_ipaddr; PROCESS_BEGIN(); @@ -56,25 +57,21 @@ PROCESS_THREAD(udp_client_process, ev, data) while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); - if(rpl_is_reachable()) { + if(NETSTACK_ROUTING.node_is_reachable() && NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) { /* Send to DAG root */ - rpl_dag_t *dag = rpl_get_any_dag(); - if(dag != NULL) { /* Only a sanity check. Should never be NULL - as rpl_is_reachable() is true */ - LOG_INFO("Sending request %u to ", count); - LOG_INFO_6ADDR(&dag->dag_id); - LOG_INFO_("\n"); - /* Set the number of transmissions to use for this packet - - this can be used to create more reliable transmissions or - less reliable than the default. Works end-to-end if - UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1. - */ - uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5); - simple_udp_sendto(&udp_conn, &count, sizeof(count), &dag->dag_id); - count++; - } + LOG_INFO("Sending request %u to ", count); + LOG_INFO_6ADDR(&dest_ipaddr); + LOG_INFO_("\n"); + /* Set the number of transmissions to use for this packet - + this can be used to create more reliable transmissions or + less reliable than the default. Works end-to-end if + UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1. + */ + uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5); + simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); + count++; } else { - LOG_INFO("Not reachable yet %p\n", rpl_get_any_dag()); + LOG_INFO("Not reachable yet\n"); } /* Add some jitter */ diff --git a/examples/rpl-udp/udp-server.c b/examples/rpl-udp/udp-server.c index 222556d59..399cabfc4 100644 --- a/examples/rpl-udp/udp-server.c +++ b/examples/rpl-udp/udp-server.c @@ -28,8 +28,7 @@ */ #include "contiki.h" -#include "rpl.h" -#include "rpl-dag-root.h" +#include "net/routing/routing.h" #include "net/netstack.h" #include "net/ipv6/simple-udp.h" @@ -72,7 +71,7 @@ PROCESS_THREAD(udp_server_process, ev, data) PROCESS_BEGIN(); /* Initialize DAG root */ - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); /* Initialize UDP connection */ simple_udp_register(&udp_conn, UDP_SERVER_PORT, NULL, diff --git a/examples/slip-radio/Makefile b/examples/slip-radio/Makefile index 3ab7bffa3..6b30b2d13 100644 --- a/examples/slip-radio/Makefile +++ b/examples/slip-radio/Makefile @@ -10,5 +10,5 @@ PROJECT_SOURCEFILES += slip-net.c # custom net layer, but with IPv6 enabled MAKE_NET = MAKE_NET_IPV6 -MAKE_ROUTING = MAKE_ROUTING_NONE +MAKE_ROUTING = MAKE_ROUTING_NULLROUTING include $(CONTIKI)/Makefile.include diff --git a/os/contiki-default-conf.h b/os/contiki-default-conf.h index 0395f6ca4..8ec1a41f7 100644 --- a/os/contiki-default-conf.h +++ b/os/contiki-default-conf.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 (ROUTING_CONF_RPL_LITE || ROUTING_CONF_RPL_CLASSIC) + /* If RPL is enabled also enable the RPL NBR Policy */ #if UIP_CONF_IPV6_RPL #ifndef NBR_TABLE_FIND_REMOVABLE diff --git a/os/contiki-net.h b/os/contiki-net.h index 9b467363f..1eb50dd8d 100644 --- a/os/contiki-net.h +++ b/os/contiki-net.h @@ -42,6 +42,7 @@ #include "net/ipv6/uip-udp-packet.h" #include "net/ipv6/simple-udp.h" #include "net/ipv6/uip-nameserver.h" +#include "net/routing/routing.h" #if NETSTACK_CONF_WITH_IPV6 #include "net/ipv6/uip-icmp6.h" diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index adbea25e0..00619c354 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -46,15 +46,16 @@ #include "net/ipv6/multicast/uip-mcast6-route.h" #include "net/ipv6/multicast/uip-mcast6-stats.h" #include "net/ipv6/multicast/esmrf.h" -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ +#include "net/routing/routing.h" #include "net/ipv6/uip.h" #include "net/netstack.h" #include "net/packetbuf.h" +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#endif /* ROUTING_CONF_RPL_LITE */ +#if ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#endif /* ROUTING_CONF_RPL_CLASSIC */ #include extern uint16_t uip_slen; diff --git a/os/net/ipv6/multicast/smrf.c b/os/net/ipv6/multicast/smrf.c index 00043d60b..86a053648 100644 --- a/os/net/ipv6/multicast/smrf.c +++ b/os/net/ipv6/multicast/smrf.c @@ -47,13 +47,15 @@ #include "net/ipv6/multicast/uip-mcast6-route.h" #include "net/ipv6/multicast/uip-mcast6-stats.h" #include "net/ipv6/multicast/smrf.h" -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ +#include "net/routing/routing.h" #include "net/netstack.h" #include "net/packetbuf.h" +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#endif /* ROUTING_CONF_RPL_LITE */ +#if ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#endif /* ROUTING_CONF_RPL_CLASSIC */ #include #define DEBUG DEBUG_NONE diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 060699e93..9bb906f6d 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -74,12 +74,7 @@ #include "net/packetbuf.h" #include "net/queuebuf.h" -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ +#include "net/routing/routing.h" /* Log configuration */ #include "sys/log.h" @@ -1436,10 +1431,8 @@ packet_sent(void *ptr, int status, int transmissions) /* Update neighbor link statistics */ link_stats_packet_sent(dest, status, transmissions); -#if UIP_CONF_IPV6_RPL - /* Call RPL link callback */ - rpl_link_callback(dest, status, transmissions); -#endif /* UIP_CONF_IPV6_RPL */ + /* Call routing protocol link callback */ + NETSTACK_ROUTING.link_callback(dest, status, transmissions); /* DS6 callback, used for UIP_DS6_LL_NUD */ uip_ds6_link_callback(status, transmissions); diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index e096ce44b..41d317d17 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -38,21 +38,15 @@ * \author Julien Abeille (IPv6 related code) */ +#include "contiki.h" #include "contiki-net.h" #include "net/ipv6/uip-packetqueue.h" #include "net/ipv6/uip-nd6.h" #include "net/ipv6/uip-ds6.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/linkaddr.h" - -#if UIP_CONF_IPV6_RPL -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#endif +#include "net/routing/routing.h" #include @@ -103,11 +97,6 @@ enum { PACKET_INPUT }; -#if UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING -#define NEXTHOP_NON_STORING(addr) rpl_ext_header_srh_get_next_hop(addr) -#else -#define NEXTHOP_NON_STORING(addr) 0 -#endif /*---------------------------------------------------------------------------*/ static void init_appstate(uip_tcp_appstate_t *as, void *state) @@ -489,23 +478,6 @@ output_fallback(void) } /*---------------------------------------------------------------------------*/ static void -drop_route(uip_ds6_route_t *route) -{ -#if UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) - - /* If we are running RPL, and if we are the root of the - network, we'll trigger a global repair before we remove - the route. */ - rpl_dag_t *dag; - dag = (rpl_dag_t *)route->state.dag; - if(dag != NULL && dag->instance != NULL) { - rpl_repair_root(dag->instance->instance_id); - } -#endif /* UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) */ - uip_ds6_route_rm(route); -} -/*---------------------------------------------------------------------------*/ -static void annotate_transmission(uip_ipaddr_t *nexthop) { #if TCPIP_CONF_ANNOTATE_TRANSMISSIONS @@ -533,7 +505,7 @@ get_nexthop(uip_ipaddr_t *addr) LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); LOG_INFO_("\n"); - if(NEXTHOP_NON_STORING(addr)) { + if(NETSTACK_ROUTING.ext_header_srh_get_next_hop(addr)) { LOG_INFO("output: selected next hop from SRH: "); LOG_INFO_6ADDR(addr); LOG_INFO_("\n"); @@ -571,9 +543,11 @@ get_nexthop(uip_ipaddr_t *addr) never responded to link-layer acks, we drop its route. */ if(nexthop == NULL) { LOG_ERR("output: found dead route\n"); - drop_route(route); - /* We don't have a nexthop to send the packet to, so we drop - it. */ + /* Notifiy the routing protocol that we are about to remove the route */ + NETSTACK_ROUTING.drop_route(route); + /* Remove the route */ + uip_ds6_route_rm(route); + /* We don't have a nexthop to send the packet to, so we drop it. */ } else { LOG_INFO("output: found next hop from routing table: "); LOG_INFO_6ADDR(nexthop); @@ -678,14 +652,13 @@ tcpip_ipv6_output(void) goto exit; } -#if UIP_CONF_IPV6_RPL - if(!rpl_ext_header_update()) { + + if(!NETSTACK_ROUTING.ext_header_update()) { /* Packet can not be forwarded */ - LOG_ERR("output: RPL header update error\n"); + LOG_ERR("output: routing protocol extension header update error\n"); uip_clear_buf(); return; } -#endif /* UIP_CONF_IPV6_RPL */ if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) { linkaddr = NULL; @@ -855,10 +828,8 @@ PROCESS_THREAD(tcpip_process, ev, data) #ifdef UIP_FALLBACK_INTERFACE UIP_FALLBACK_INTERFACE.init(); #endif - /* initialize RPL if configured for using RPL */ -#if UIP_CONF_IPV6_RPL - rpl_init(); -#endif /* UIP_CONF_IPV6_RPL */ + /* Initialize routing protocol */ + NETSTACK_ROUTING.init(); while(1) { PROCESS_YIELD(); diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index d07f85d78..e49125548 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -50,20 +50,16 @@ #include "net/link-stats.h" #include "net/linkaddr.h" #include "net/packetbuf.h" +#include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip-ds6-nbr.h" +#include "net/ipv6/uip-nd6.h" +#include "net/routing/routing.h" /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "IPv6 Nbr" #define LOG_LEVEL LOG_LEVEL_IPV6 -#ifdef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED -#define NEIGHBOR_STATE_CHANGED(n) UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED(n) -void NEIGHBOR_STATE_CHANGED(uip_ds6_nbr_t *n); -#else -#define NEIGHBOR_STATE_CHANGED(n) -#endif /* UIP_DS6_CONF_NEIGHBOR_STATE_CHANGED */ - NBR_TABLE_GLOBAL(uip_ds6_nbr_t, ds6_neighbors); /*---------------------------------------------------------------------------*/ @@ -105,7 +101,7 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, LOG_INFO_(" link addr "); LOG_INFO_LLADDR((linkaddr_t*)lladdr); LOG_INFO_(" state %u\n", state); - NEIGHBOR_STATE_CHANGED(nbr); + NETSTACK_ROUTING.neighbor_state_changed(nbr); return nbr; } else { LOG_INFO("Add drop ip addr "); @@ -125,7 +121,7 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) #if UIP_CONF_IPV6_QUEUE_PKT uip_packetqueue_free(&nbr->packethandle); #endif /* UIP_CONF_IPV6_QUEUE_PKT */ - NEIGHBOR_STATE_CHANGED(nbr); + NETSTACK_ROUTING.neighbor_state_changed(nbr); return nbr_table_remove(ds6_neighbors, nbr); } return 0; @@ -257,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 @@ -277,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: diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index ebb7de2d8..9aec47b4a 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -46,10 +46,11 @@ #ifndef UIP_DS6_NEIGHBOR_H_ #define UIP_DS6_NEIGHBOR_H_ +#include "contiki.h" #include "net/ipv6/uip.h" +#include "net/ipv6/uip-nd6.h" #include "net/nbr-table.h" #include "sys/stimer.h" -#include "net/ipv6/uip-ds6.h" #if UIP_CONF_IPV6_QUEUE_PKT #include "net/ipv6/uip-packetqueue.h" #endif /*UIP_CONF_QUEUE_PKT */ diff --git a/os/net/ipv6/uip-ds6-route.h b/os/net/ipv6/uip-ds6-route.h index acc417670..9f435824c 100644 --- a/os/net/ipv6/uip-ds6-route.h +++ b/os/net/ipv6/uip-ds6-route.h @@ -44,22 +44,28 @@ #include "net/nbr-table.h" #include "sys/stimer.h" #include "lib/list.h" -#if UIP_CONF_IPV6_RPL -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl-conf.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl-conf.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#endif #ifdef UIP_CONF_MAX_ROUTES + #define UIP_MAX_ROUTES UIP_CONF_MAX_ROUTES + #else /* UIP_CONF_MAX_ROUTES */ + +#if ROUTING_CONF_RPL_LITE +#define UIP_MAX_ROUTES 0 /* RPL Lite only supports non-storing, no routes */ +#elif ROUTING_CONF_RPL_CLASSIC + +#include "net/routing/rpl-classic/rpl-conf.h" #if RPL_WITH_STORING #define UIP_MAX_ROUTES NETSTACK_MAX_ROUTE_ENTRIES -#else -#define UIP_MAX_ROUTES 0 +#else /* RPL_WITH_STORING */ +#define UIP_MAX_ROUTES 0 /* No storing mode, no need for routes */ +#endif /* RPL_WITH_STORING */ + +#else /* Not RPL Lite nor RPL Classic */ +#define UIP_MAX_ROUTES NETSTACK_MAX_ROUTE_ENTRIES #endif + #endif /* UIP_CONF_MAX_ROUTES */ NBR_TABLE_DECLARE(nbr_routes); diff --git a/os/net/ipv6/uip-ds6.c b/os/net/ipv6/uip-ds6.c index 18e9d33e9..6dd178dc8 100644 --- a/os/net/ipv6/uip-ds6.c +++ b/os/net/ipv6/uip-ds6.c @@ -47,6 +47,7 @@ #include #include "lib/random.h" #include "net/ipv6/uip-nd6.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6.h" #include "net/ipv6/multicast/uip-mcast6.h" #include "net/ipv6/uip-packetqueue.h" diff --git a/os/net/ipv6/uip-ds6.h b/os/net/ipv6/uip-ds6.h index 736f9bfeb..45394fec3 100644 --- a/os/net/ipv6/uip-ds6.h +++ b/os/net/ipv6/uip-ds6.h @@ -46,8 +46,8 @@ #include "sys/stimer.h" /* The size of uip_ds6_addr_t depends on UIP_ND6_DEF_MAXDADNS. Include uip-nd6.h to define it. */ #include "net/ipv6/uip-nd6.h" -#include "net/ipv6/uip-ds6-route.h" #include "net/ipv6/uip-ds6-nbr.h" +#include "net/ipv6/uip-ds6-route.h" /*--------------------------------------------------*/ /** Configuration. For all tables (Neighbor cache, Prefix List, Routing Table, @@ -226,13 +226,6 @@ typedef struct uip_ds6_maddr { uip_ipaddr_t ipaddr; } uip_ds6_maddr_t; -/* only define the callback if RPL is active */ -#if UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) -#ifndef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED -#define UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED rpl_ipv6_neighbor_callback -#endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */ -#endif /* UIP_CONF_IPV6_RPL */ - /** \brief Interface structure (contains all the interface variables) */ typedef struct uip_ds6_netif { uint32_t link_mtu; diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index d46a9cd68..be33a1101 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -46,6 +46,7 @@ #include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip-icmp6.h" #include "contiki-default-conf.h" +#include "net/routing/routing.h" /* Log configuration */ #include "sys/log.h" @@ -58,15 +59,6 @@ #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN]) -#if UIP_CONF_IPV6_RPL -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#endif /* UIP_CONF_IPV6_RPL */ - /** \brief temporary IP address */ static uip_ipaddr_t tmp_ipaddr; @@ -193,11 +185,8 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { } } -#if UIP_CONF_IPV6_RPL - rpl_ext_header_remove(); -#else - uip_ext_len = 0; -#endif /* UIP_CONF_IPV6_RPL */ + /* Remove all extension headers related to the routing protocol in place */ + NETSTACK_ROUTING.ext_header_remove(); /* remember data of original packet before shifting */ uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr); diff --git a/os/net/rpl-lite/rpl-ns.c b/os/net/ipv6/uip-sr.c similarity index 72% rename from os/net/rpl-lite/rpl-ns.c rename to os/net/ipv6/uip-sr.c index 0b31484b8..9b859fb3a 100644 --- a/os/net/rpl-lite/rpl-ns.c +++ b/os/net/ipv6/uip-sr.c @@ -30,55 +30,59 @@ */ /** - * \addtogroup rpl-lite + * \addtogroup uip * @{ * * \file - * RPL non-storing mode specific functions. Includes support for - * source routing. + * Source routing support * * \author Simon Duquennoy */ -#include "net/rpl-lite/rpl.h" +#include "contiki.h" +#include "net/ipv6/uip-sr.h" +#include "net/routing/routing.h" #include "lib/list.h" #include "lib/memb.h" /* Log configuration */ #include "sys/log.h" -#define LOG_MODULE "RPL" -#define LOG_LEVEL LOG_LEVEL_RPL +#define LOG_MODULE "IPv6 SR" +#define LOG_LEVEL LOG_LEVEL_IPV6 /* Total number of nodes */ static int num_nodes; /* Every known node in the network */ LIST(nodelist); -MEMB(nodememb, rpl_ns_node_t, RPL_NS_LINK_NUM); +MEMB(nodememb, uip_sr_node_t, UIP_SR_LINK_NUM); /*---------------------------------------------------------------------------*/ int -rpl_ns_num_nodes(void) +uip_sr_num_nodes(void) { return num_nodes; } /*---------------------------------------------------------------------------*/ static int -node_matches_address(const rpl_ns_node_t *node, const uip_ipaddr_t *addr) +node_matches_address(void *graph, const uip_sr_node_t *node, const uip_ipaddr_t *addr) { - return addr != NULL - && node != NULL - && !memcmp(addr, &curr_instance.dag.dag_id, 8) - && !memcmp(((const unsigned char *)addr) + 8, node->link_identifier, 8); + if(node == NULL || addr == NULL || graph != node->graph) { + return 0; + } else { + uip_ipaddr_t node_ipaddr; + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_ipaddr, node); + return uip_ipaddr_cmp(&node_ipaddr, addr); + } } /*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_get_node(const uip_ipaddr_t *addr) +uip_sr_node_t * +uip_sr_get_node(void *graph, const uip_ipaddr_t *addr) { - rpl_ns_node_t *l; + uip_sr_node_t *l; for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) { /* Compare prefix and node identifier */ - if(node_matches_address(l, addr)) { + if(node_matches_address(graph, l, addr)) { return l; } } @@ -86,11 +90,17 @@ rpl_ns_get_node(const uip_ipaddr_t *addr) } /*---------------------------------------------------------------------------*/ int -rpl_ns_is_addr_reachable(const uip_ipaddr_t *addr) +uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr) { - int max_depth = RPL_NS_LINK_NUM; - rpl_ns_node_t *node = rpl_ns_get_node(addr); - rpl_ns_node_t *root_node = rpl_ns_get_node(&curr_instance.dag.dag_id); + int max_depth = UIP_SR_LINK_NUM; + uip_ipaddr_t root_ipaddr; + uip_sr_node_t *node; + uip_sr_node_t *root_node; + + NETSTACK_ROUTING.get_root_ipaddr(&root_ipaddr); + node = uip_sr_get_node(graph, addr); + root_node = uip_sr_get_node(graph, &root_ipaddr); + while(node != NULL && node != root_node && max_depth > 0) { node = node->parent; max_depth--; @@ -99,26 +109,26 @@ rpl_ns_is_addr_reachable(const uip_ipaddr_t *addr) } /*---------------------------------------------------------------------------*/ void -rpl_ns_expire_parent(const uip_ipaddr_t *child, const uip_ipaddr_t *parent) +uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent) { - rpl_ns_node_t *l = rpl_ns_get_node(child); + uip_sr_node_t *l = uip_sr_get_node(graph, child); /* Check if parent matches */ - if(l != NULL && node_matches_address(l->parent, parent)) { - l->lifetime = RPL_NOPATH_REMOVAL_DELAY; + if(l != NULL && node_matches_address(graph, l->parent, parent)) { + l->lifetime = UIP_SR_REMOVAL_DELAY; } } /*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime) +uip_sr_node_t * +uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime) { - rpl_ns_node_t *child_node = rpl_ns_get_node(child); - rpl_ns_node_t *parent_node = rpl_ns_get_node(parent); - rpl_ns_node_t *old_parent_node; + uip_sr_node_t *child_node = uip_sr_get_node(graph, child); + uip_sr_node_t *parent_node = uip_sr_get_node(graph, parent); + uip_sr_node_t *old_parent_node; if(parent != NULL) { /* No node for the parent, add one with infinite lifetime */ if(parent_node == NULL) { - parent_node = rpl_ns_update_node(parent, NULL, RPL_ROUTE_INFINITE_LIFETIME); + parent_node = uip_sr_update_node(graph, parent, NULL, UIP_SR_INFINITE_LIFETIME); if(parent_node == NULL) { LOG_ERR("NS: no space left for root node!\n"); return NULL; @@ -142,16 +152,17 @@ rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32 } /* Initialize node */ + child_node->graph = graph; child_node->lifetime = lifetime; memcpy(child_node->link_identifier, ((const unsigned char *)child) + 8, 8); /* Is the node reachable before the update? */ - if(rpl_ns_is_addr_reachable(child)) { + if(uip_sr_is_addr_reachable(graph, child)) { old_parent_node = child_node->parent; /* Update node */ child_node->parent = parent_node; /* Has the node become unreachable? May happen if we create a loop. */ - if(!rpl_ns_is_addr_reachable(child)) { + if(!uip_sr_is_addr_reachable(graph, child)) { /* The new parent makes the node unreachable, restore old parent. * We will take the update next time, with chances we know more of * the topology and the loop is gone. */ @@ -171,48 +182,36 @@ rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32 } /*---------------------------------------------------------------------------*/ void -rpl_ns_init(void) +uip_sr_init(void) { num_nodes = 0; memb_init(&nodememb); list_init(nodelist); } /*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_node_head(void) +uip_sr_node_t * +uip_sr_node_head(void) { return list_head(nodelist); } /*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_node_next(rpl_ns_node_t *item) +uip_sr_node_t * +uip_sr_node_next(uip_sr_node_t *item) { return list_item_next(item); } /*---------------------------------------------------------------------------*/ -int -rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node) -{ - if(addr != NULL && node != NULL) { - memcpy(addr, &curr_instance.dag.dag_id, 8); - memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8); - return 1; - } else { - return 0; - } -} -/*---------------------------------------------------------------------------*/ void -rpl_ns_periodic(unsigned seconds) +uip_sr_periodic(unsigned seconds) { - rpl_ns_node_t *l; - rpl_ns_node_t *next; + uip_sr_node_t *l; + uip_sr_node_t *next; /* First pass, for all expired nodes, deallocate them iff no child points to them */ for(l = list_head(nodelist); l != NULL; l = next) { next = list_item_next(l); if(l->lifetime == 0) { - rpl_ns_node_t *l2; + uip_sr_node_t *l2; for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) { if(l2->parent == l) { break; @@ -220,7 +219,7 @@ rpl_ns_periodic(unsigned seconds) } #if LOG_INFO_ENABLED uip_ipaddr_t node_addr; - rpl_ns_get_node_global_addr(&node_addr, l); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, l); LOG_INFO("NS: removing expired node "); LOG_INFO_6ADDR(&node_addr); LOG_INFO_("\n"); @@ -229,17 +228,17 @@ rpl_ns_periodic(unsigned seconds) list_remove(nodelist, l); memb_free(&nodememb, l); num_nodes--; - } else if(l->lifetime != RPL_ROUTE_INFINITE_LIFETIME) { + } else if(l->lifetime != UIP_SR_INFINITE_LIFETIME) { l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0; } } } /*---------------------------------------------------------------------------*/ void -rpl_ns_free_all(void) +uip_sr_free_all(void) { - rpl_ns_node_t *l; - rpl_ns_node_t *next; + uip_sr_node_t *l; + uip_sr_node_t *next; for(l = list_head(nodelist); l != NULL; l = next) { next = list_item_next(l); list_remove(nodelist, l); diff --git a/os/net/rpl-lite/rpl-ns.h b/os/net/ipv6/uip-sr.h similarity index 57% rename from os/net/rpl-lite/rpl-ns.h rename to os/net/ipv6/uip-sr.h index 5f6e3d86d..7224cea14 100644 --- a/os/net/rpl-lite/rpl-ns.h +++ b/os/net/ipv6/uip-sr.h @@ -30,37 +30,75 @@ */ /** - * \addtogroup rpl-lite + * \addtogroup uip * @{ * * \file - * RPL non-storing mode specific functions. Includes support for - * source routing. + * Source routing support * * \author Simon Duquennoy */ -#ifndef RPL_NS_H -#define RPL_NS_H +#ifndef UIP_SR_H +#define UIP_SR_H /********** Includes **********/ +#include "contiki.h" #include "net/ipv6/uip.h" -#include "net/rpl-lite/rpl.h" + +/********** Configuration **********/ + +/* The number of source routing nodes, i.e. the maximum netwrok size at the root */ +#ifdef UIP_SR_CONF_LINK_NUM + +#define UIP_SR_LINK_NUM UIP_SR_CONF_LINK_NUM + +#else /* UIP_SR_CONF_LINK_NUM */ + +#if ROUTING_CONF_RPL_LITE +#define UIP_SR_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES +#elif ROUTING_CONF_RPL_CLASSIC + +#include "net/routing/rpl-classic/rpl-conf.h" +#if RPL_WITH_NON_STORING +#define UIP_SR_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES +#else /* RPL_WITH_NON_STORING */ +#define UIP_SR_LINK_NUM 0 +#endif /* RPL_WITH_NON_STORING */ + +#else + +#define UIP_SR_LINK_NUM 0 + +#endif + +#endif /* UIP_SR_CONF_LINK_NUM */ + +/* Delay between between expiration order and actual node removal */ +#ifdef UIP_SR_CONF_REMOVAL_DELAY +#define UIP_SR_REMOVAL_DELAY UIP_SR_CONF_REMOVAL_DELAY +#else /* UIP_SR_CONF_REMOVAL_DELAY */ +#define UIP_SR_REMOVAL_DELAY 60 +#endif /* UIP_SR_CONF_REMOVAL_DELAY */ + +#define UIP_SR_INFINITE_LIFETIME 0xFFFFFFFF /********** Data Structures **********/ -/* A node in a RPL Non-storing graph, stored at the root and representing +/** \brief A node in a source routing graph, stored at the root and representing * all child-parent relationship. Used to build source routes */ -typedef struct rpl_ns_node { - struct rpl_ns_node *next; +typedef struct uip_sr_node { + struct uip_sr_node *next; uint32_t lifetime; - rpl_dag_t *dag; - /* Store only IPv6 link identifiers as all nodes in the DAG share the same prefix */ + /* Protocol-specific graph structure */ + void *graph; + /* Store only IPv6 link identifiers, the routing protocol will provide + us with the prefix */ unsigned char link_identifier[8]; - struct rpl_ns_node *parent; -} rpl_ns_node_t; + struct uip_sr_node *parent; +} uip_sr_node_t; /********** Public functions **********/ @@ -69,31 +107,33 @@ typedef struct rpl_ns_node { * * \return The number of nodes */ -int rpl_ns_num_nodes(void); +int uip_sr_num_nodes(void); /** * Expires a given child-parent link * + * \param graph The graph the link belongs to * \param child The IPv6 address of the child * \param parent The IPv6 address of the parent */ -void rpl_ns_expire_parent(const uip_ipaddr_t *child, const uip_ipaddr_t *parent); +void uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent); /** * Updates a child-parent link * + * \param graph The graph the link belongs to * \param child The IPv6 address of the child * \param parent The IPv6 address of the parent * \param lifetime The link lifetime in seconds */ -rpl_ns_node_t *rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime); +uip_sr_node_t *uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime); /** * Returns the head of the non-storing node list * * \return The head of the list */ -rpl_ns_node_t *rpl_ns_node_head(void); +uip_sr_node_t *uip_sr_node_head(void); /** * Returns the next element of the non-storing node list @@ -101,33 +141,26 @@ rpl_ns_node_t *rpl_ns_node_head(void); * \param item The current element in the list * \return The next element of the list */ -rpl_ns_node_t *rpl_ns_node_next(rpl_ns_node_t *item); +uip_sr_node_t *uip_sr_node_next(uip_sr_node_t *item); /** - * Looks up for a RPL NS node from its IPv6 global address + * Looks up for a source routing node from its IPv6 global address * + * \param graph The graph where to look up for the node * \param addr The target address * \return A pointer to the node */ -rpl_ns_node_t *rpl_ns_get_node(const uip_ipaddr_t *addr); +uip_sr_node_t *uip_sr_get_node(void *graph, const uip_ipaddr_t *addr); /** * Telle whether an address is reachable, i.e. if there exists a path from - * the root to the node in the current RPL NS graph + * the root to the node in the current source routing graph * + * \param graph The graph where to look up for the node * \param addr The target IPv6 global address * \return 1 if the node is reachable, 0 otherwise */ -int rpl_ns_is_addr_reachable(const uip_ipaddr_t *addr); - -/** - * Finds the global address of a given node - * - * \param addr A pointer to the address to be written - * \param node The target node - * \return 1 if success, 0 otherwise -*/ -int rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node); +int uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr); /** * A function called periodically. Used to age the links (decrease lifetime @@ -135,18 +168,18 @@ int rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node); * * \param seconds The number of seconds elapsted since last call */ -void rpl_ns_periodic(unsigned seconds); +void uip_sr_periodic(unsigned seconds); /** - * Initialize rpl-ns module + * Initialize this module */ -void rpl_ns_init(void); +void uip_sr_init(void); /** * Deallocate all neighbors */ -void rpl_ns_free_all(void); +void uip_sr_free_all(void); /** @} */ -#endif /* RPL_NS_H */ +#endif /* UIP_SR_H */ diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 72384414a..de14486b9 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -79,15 +79,7 @@ #include "net/ipv6/uip-nd6.h" #include "net/ipv6/uip-ds6.h" #include "net/ipv6/multicast/uip-mcast6.h" - -#if UIP_CONF_IPV6_RPL -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#endif +#include "net/routing/routing.h" #if UIP_ND6_SEND_NS #include "net/ipv6/uip-ds6-nbr.h" @@ -161,9 +153,6 @@ uint8_t uip_ext_opt_offset = 0; #define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) #define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#if UIP_CONF_IPV6_RPL -#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#endif /* UIP_CONF_IPV6_RPL */ #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len]) /** @} */ /** @@ -883,13 +872,10 @@ ext_hdr_options_process(void) * Using this fix, the header is ignored, and the next header (if * present) is processed. */ -#if UIP_CONF_IPV6_RPL - LOG_DBG("Processing RPL option\n"); - if(!rpl_ext_header_hbh_update(uip_ext_opt_offset)) { + if(!NETSTACK_ROUTING.ext_header_hbh_update(uip_ext_opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } -#endif /* UIP_CONF_IPV6_RPL */ uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF->len) + 2; return 0; default: @@ -1363,8 +1349,7 @@ uip_process(uint8_t flag) LOG_DBG("Processing Routing header\n"); if(UIP_ROUTING_BUF->seg_left > 0) { -#if UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING - if(rpl_ext_header_srh_update()) { + if(NETSTACK_ROUTING.ext_header_srh_update()) { /* With routing header, the detination address is us and will * be swapped later to the next hop. Because of this, the MTU @@ -1392,7 +1377,6 @@ uip_process(uint8_t flag) goto send; /* Proceed to forwarding */ } -#endif /* UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING */ uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, UIP_IPH_LEN + uip_ext_len + 2); UIP_STAT(++uip_stat.ip.drop); LOG_ERR("unrecognized routing type"); diff --git a/os/net/mac/tsch/tsch-rpl.c b/os/net/mac/tsch/tsch-rpl.c index ec3f24d8b..bc54de99c 100644 --- a/os/net/mac/tsch/tsch-rpl.c +++ b/os/net/mac/tsch/tsch-rpl.c @@ -40,21 +40,23 @@ * @{ */ +#include "contiki.h" + #if UIP_CONF_IPV6_RPL -#include "contiki.h" -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ +#include "net/routing/routing.h" #include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch-private.h" #include "net/mac/tsch/tsch-schedule.h" #include "net/mac/tsch/tsch-log.h" #include "net/mac/tsch/tsch-rpl.h" -#include "tsch-rpl.h" + +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#elif ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl-private.h" +#endif /* Log configuration */ #include "sys/log.h" @@ -66,7 +68,7 @@ void tsch_rpl_callback_ka_sent(int status, int transmissions) { - rpl_link_callback(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions); + NETSTACK_ROUTING.link_callback(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions); } /*---------------------------------------------------------------------------*/ /* To use, set #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network */ @@ -81,14 +83,7 @@ tsch_rpl_callback_joining_network(void) void tsch_rpl_callback_leaving_network(void) { - rpl_dag_t *dag = rpl_get_any_dag(); - if(dag != NULL) { -#if UIP_CONF_IPV6_RPL_LITE - rpl_local_repair("TSCH leaving"); -#else - rpl_local_repair(dag->instance); -#endif - } + NETSTACK_ROUTING.local_repair("TSCH leaving"); } /*---------------------------------------------------------------------------*/ /* Set TSCH EB period based on current RPL DIO period. @@ -100,7 +95,7 @@ tsch_rpl_callback_new_dio_interval(clock_time_t dio_interval) rpl_dag_t *dag; rpl_rank_t root_rank; rpl_rank_t dag_rank; -#if UIP_CONF_IPV6_RPL_LITE +#if ROUTING_CONF_RPL_LITE dag = &curr_instance.dag; root_rank = ROOT_RANK; dag_rank = DAG_RANK(dag->rank); diff --git a/os/net/mac/tsch/tsch-rpl.h b/os/net/mac/tsch/tsch-rpl.h index 15be760f5..41fa17e91 100644 --- a/os/net/mac/tsch/tsch-rpl.h +++ b/os/net/mac/tsch/tsch-rpl.h @@ -38,12 +38,13 @@ /********** Includes **********/ -#if UIP_CONF_IPV6_RPL_LITE == 1 -#include "net/rpl-lite/rpl.h" -#else /* UIP_CONF_IPV6_RPL_LITE == 1 */ -#include "net/rpl-classic/rpl.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */ +#include "net/routing/routing.h" #include "net/mac/tsch/tsch-queue.h" +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#elif ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#endif /********** Functions *********/ diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index 6d60f097a..9d0affb8a 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -60,12 +60,12 @@ #include "net/mac/tsch/tsch-log.h" #include "net/mac/tsch/tsch-packet.h" #include "net/mac/tsch/tsch-security.h" -#include "net/mac/mac-sequence.h" -#include "lib/random.h" - #if UIP_CONF_IPV6_RPL #include "net/mac/tsch/tsch-rpl.h" #endif /* UIP_CONF_IPV6_RPL */ +#include "net/mac/mac-sequence.h" +#include "lib/random.h" +#include "net/routing/routing.h" #if TSCH_WITH_SIXTOP #include "net/mac/tsch/sixtop/sixtop.h" diff --git a/os/net/netstack.h b/os/net/netstack.h index 4251ef5e9..b55319356 100644 --- a/os/net/netstack.h +++ b/os/net/netstack.h @@ -43,6 +43,22 @@ #include "contiki.h" +/* Routing protocol configuration. The Routing protocol is configured through the Makefile, + via the flag MAC_ROUTING */ +#ifdef NETSTACK_CONF_ROUTING +#define NETSTACK_ROUTING NETSTACK_CONF_ROUTING +#else /* NETSTACK_CONF_ROUTING */ +#if ROUTING_CONF_RPL_LITE +#define NETSTACK_ROUTING rpl_lite_driver +#elif ROUTING_CONF_RPL_CLASSIC +#define NETSTACK_ROUTING rpl_classic_driver +#elif ROUTING_CONF_NULLROUTING +#define NETSTACK_ROUTING nullrouting_driver +#else +#error Unknown ROUTING configuration +#endif +#endif /* NETSTACK_CONF_ROUTING */ + /* Network layer configuration. The NET layer is configured through the Makefile, via the flag MAC_NET */ #ifdef NETSTACK_CONF_NETWORK @@ -110,6 +126,7 @@ struct network_driver { }; +extern const struct routing_driver NETSTACK_ROUTING; extern const struct network_driver NETSTACK_NETWORK; extern const struct mac_driver NETSTACK_MAC; extern const struct radio_driver NETSTACK_RADIO; diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c new file mode 100644 index 000000000..14c328b0c --- /dev/null +++ b/os/net/routing/nullrouting/nullrouting.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2017, RISE SICS. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +/** + * \addtogroup null-routing + * @{ + * + * \file + * A routing protocol that does nothing + * + * \author Simon Duquennoy + */ + +#include "net/routing/routing.h" + +/*---------------------------------------------------------------------------*/ +static void +init(void) +{ +} +/*---------------------------------------------------------------------------*/ +static void +root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) +{ +} +/*---------------------------------------------------------------------------*/ +static int +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 int +get_sr_node_ipaddr(uip_ipaddr_t *addr, const uip_sr_node_t *node) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static void +leave_network(void) +{ +} +/*---------------------------------------------------------------------------*/ +static int +node_has_joined(void) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +node_is_reachable(void) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +static void +global_repair(const char *str) +{ +} +/*---------------------------------------------------------------------------*/ +static void +local_repair(const char *str) +{ +} +/*---------------------------------------------------------------------------*/ +static void +ext_header_remove(void) +{ + uip_ext_len = 0; +} +/*---------------------------------------------------------------------------*/ +static int +ext_header_update(void) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +ext_header_hbh_update(int uip_ext_opt_offset) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +ext_header_srh_update(void) +{ + return 0; /* Means SRH not found */ +} +/*---------------------------------------------------------------------------*/ +static int +ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static void +link_callback(const linkaddr_t *addr, int status, int numtx) +{ +} +/*---------------------------------------------------------------------------*/ +static void +neighbor_state_changed(uip_ds6_nbr_t *nbr) +{ +} +/*---------------------------------------------------------------------------*/ +static void +drop_route(uip_ds6_route_t *route) +{ +} +/*---------------------------------------------------------------------------*/ +const struct routing_driver nullrouting_driver = { + "Null Routing", + init, + root_set_prefix, + root_start, + node_is_root, + get_root_ipaddr, + get_sr_node_ipaddr, + leave_network, + node_has_joined, + node_is_reachable, + global_repair, + local_repair, + ext_header_remove, + ext_header_update, + ext_header_hbh_update, + ext_header_srh_update, + ext_header_srh_get_next_hop, + link_callback, + neighbor_state_changed, + drop_route, +}; +/*---------------------------------------------------------------------------*/ + +/** @}*/ diff --git a/os/net/routing/routing.h b/os/net/routing/routing.h new file mode 100644 index 000000000..7fe6e7ca8 --- /dev/null +++ b/os/net/routing/routing.h @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2017, RISE SICS. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * Routing driver header file + * \author + * Simon Duquennoy + */ + +#ifndef ROUTING_H_ +#define ROUTING_H_ + +#include "contiki.h" +#include "net/ipv6/uip.h" +#include "net/ipv6/uip-ds6-nbr.h" +#include "net/ipv6/uip-ds6-route.h" +#include "net/ipv6/uip-sr.h" +#include "net/linkaddr.h" + +/** + * The structure of a routing protocol driver. + */ +struct routing_driver { + char *name; + /** Initialize the routing protocol */ + void (* init)(void); + /** + * Set the prefix, for nodes that will operate as root + * + * \param prefix The prefix. If NULL, UIP_DS6_DEFAULT_PREFIX is used instead + * \param iid The IID. If NULL, it will be built from uip_ds6_set_addr_iid. + */ + void (* root_set_prefix)(uip_ipaddr_t *prefix, uip_ipaddr_t *iid); + /** + * Set the node as root and start a network + * + * \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); + /** + * Returns the global IPv6 address of a source routing node + * + * \param ipaddr A pointer where to copy the IP address of the node + * \param node The source routing node + * \return 1 if the global node address was copied, 0 otherwise + */ + int (* get_sr_node_ipaddr)(uip_ipaddr_t *addr, const uip_sr_node_t *node); + /** + * Leave the network the node is part of + * + */ + void (* leave_network)(void); + /** + * Tells whether the node is currently part of a network + * + * \return 1 if we have joined a network, 0 otherwise. + */ + int (* node_has_joined)(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 + * + * \param str A textual description of the cause for triggering a repair + */ + void (* global_repair)(const char *str); + /** + * Triggers a RPL local topology repair + * + * \param str A textual description of the cause for triggering a repair + */ + void (* local_repair)(const char *str); + /** + * Removes all extension headers that pertain to the routing protocol. + */ + void (* ext_header_remove)(void); + /** + * Adds/updates routing protocol extension headers to current uIP packet. + * + * \return 1 in case of success, 0 otherwise + */ + int (* ext_header_update)(void); + /** + * Process and update the routing protocol hob-by-hop + * extention headers of the current uIP packet. + * + * \param uip_ext_opt_offset The offset within the uIP packet where + * extension headers start + * \return 1 in case the packet is valid and to be processed further, + * 0 in case the packet must be dropped. + */ + int (* ext_header_hbh_update)(int uip_ext_opt_offset); + /** + * Process and update SRH in-place, + * i.e. internal address swapping as per RFC6554 + * \return 1 if SRH found, 0 otherwise + */ + int (* ext_header_srh_update)(void); + /** + * Look for next hop from SRH of current uIP packet. + * + * \param ipaddr A pointer to the address where to store the next hop. + * \return 1 if a next hop was found, 0 otherwise + */ + int (* ext_header_srh_get_next_hop)(uip_ipaddr_t *ipaddr); + /** + * Called by lower layers after every packet transmission + * + * \param addr The link-layer addrress of the packet destination + * \param status The transmission status (see os/net/mac/mac.h) + * \param numtx The total number of transmission attempts + */ + void (* link_callback)(const linkaddr_t *addr, int status, int numtx); + /** + * Called by uIP to notify addition/removal of IPv6 neighbor entries + * + * \param addr The link-layer addrress of the packet destination + * \param status The transmission status (see os/net/mac/mac.h) + * \param numtx The total number of transmission attempts + */ + void (* neighbor_state_changed)(uip_ds6_nbr_t *nbr); + /** + * Called by uIP if it has decided to drop a route because + * + * \param route The route that will be dropped after this function returns + */ + void (* drop_route)(uip_ds6_route_t *route); +}; + +#endif /* ROUTING_H_ */ diff --git a/os/net/rpl-classic/rpl-conf.h b/os/net/routing/rpl-classic/rpl-conf.h similarity index 100% rename from os/net/rpl-classic/rpl-conf.h rename to os/net/routing/rpl-classic/rpl-conf.h diff --git a/os/net/rpl-classic/rpl-dag-root.c b/os/net/routing/rpl-classic/rpl-dag-root.c similarity index 54% rename from os/net/rpl-classic/rpl-dag-root.c rename to os/net/routing/rpl-classic/rpl-dag-root.c index 96d00f6e1..05adff4de 100644 --- a/os/net/rpl-classic/rpl-dag-root.c +++ b/os/net/routing/rpl-classic/rpl-dag-root.c @@ -32,9 +32,8 @@ #include "contiki.h" #include "contiki-net.h" -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#include "net/rpl-classic/rpl-dag-root.h" +#include "net/routing/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/ipv6/uip-ds6-route.h" #include @@ -42,105 +41,6 @@ #define DEBUG DEBUG_NONE #include "net/ipv6/uip-debug.h" -#define RPL_DAG_GRACE_PERIOD (CLOCK_SECOND * 20 * 1) - -#if (UIP_MAX_ROUTES != 0) -static struct uip_ds6_notification n; -#endif /* (UIP_MAX_ROUTES != 0) */ -static uint8_t to_become_root; -static struct ctimer c; -/*---------------------------------------------------------------------------*/ -static const uip_ipaddr_t * -dag_root(void) -{ - rpl_dag_t *dag; - - dag = rpl_get_any_dag(); - if(dag != NULL) { - return &dag->dag_id; - } - - return NULL; -} -/*---------------------------------------------------------------------------*/ -static const uip_ipaddr_t * -get_global_address(void) -{ - int i; - uint8_t state; - uip_ipaddr_t *ipaddr = NULL; - - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - state == ADDR_PREFERRED && - !uip_is_addr_linklocal(&uip_ds6_if.addr_list[i].ipaddr)) { - ipaddr = &uip_ds6_if.addr_list[i].ipaddr; - } - } - return ipaddr; -} -/*---------------------------------------------------------------------------*/ -static void -create_dag_callback(void *ptr) -{ - const uip_ipaddr_t *root, *ipaddr; - - root = dag_root(); - ipaddr = get_global_address(); - - if(root == NULL || uip_ipaddr_cmp(root, ipaddr)) { - /* The RPL network we are joining is one that we created, so we - become root. */ - if(to_become_root) { - rpl_dag_root_init_dag_immediately(); - to_become_root = 0; - } - } else { - rpl_dag_t *dag; - - dag = rpl_get_any_dag(); -#if DEBUG - printf("Found a network we did not create\n"); - printf("version %d grounded %d preference %d used %d joined %d rank %d\n", - dag->version, dag->grounded, - dag->preference, dag->used, - dag->joined, dag->rank); -#endif /* DEBUG */ - - /* We found a RPL network that we did not create so we just join - it without becoming root. But if the network has an infinite - rank, we assume the network has broken, and we become the new - root of the network. */ - - if(dag->rank == RPL_INFINITE_RANK) { - if(to_become_root) { - rpl_dag_root_init_dag_immediately(); - to_become_root = 0; - } - } - - /* Try again after the grace period */ - ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL); - } -} -#if (UIP_MAX_ROUTES != 0) -/*---------------------------------------------------------------------------*/ -static void -route_callback(int event, uip_ipaddr_t *route, uip_ipaddr_t *ipaddr, - int numroutes) -{ - if(event == UIP_DS6_NOTIFICATION_DEFRT_ADD) { - if(route != NULL && ipaddr != NULL && - !uip_is_addr_unspecified(route) && - !uip_is_addr_unspecified(ipaddr)) { - if(to_become_root) { - ctimer_set(&c, 0, create_dag_callback, NULL); - } - } - } -} -#endif /* (UIP_MAX_ROUTES != 0) */ /*---------------------------------------------------------------------------*/ static void set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) @@ -176,29 +76,25 @@ set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) } /*---------------------------------------------------------------------------*/ void -rpl_dag_root_init(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) +rpl_dag_root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) { static uint8_t initialized = 0; if(!initialized) { - to_become_root = 0; set_global_address(prefix, iid); -#if (UIP_MAX_ROUTES != 0) - uip_ds6_notification_add(&n, route_callback); -#endif /* (UIP_MAX_ROUTES != 0) */ initialized = 1; } } /*---------------------------------------------------------------------------*/ int -rpl_dag_root_init_dag_immediately(void) +rpl_dag_root_start(void) { struct uip_ds6_addr *root_if; int i; uint8_t state; uip_ipaddr_t *ipaddr = NULL; - rpl_dag_root_init(NULL, NULL); + rpl_dag_root_set_prefix(NULL, NULL); for(i = 0; i < UIP_DS6_ADDR_NB; i++) { state = uip_ds6_if.addr_list[i].state; @@ -223,38 +119,25 @@ rpl_dag_root_init_dag_immediately(void) if(RPL_IS_STORING(dag->instance)) { rpl_remove_routes(dag); } - if(dag->instance != NULL && - dag->instance->def_route != NULL) { - uip_ds6_defrt_rm(dag->instance->def_route); + if(dag->instance != NULL && dag->instance->def_route != NULL) { + uip_ds6_defrt_rm(dag->instance->def_route); dag->instance->def_route = NULL; } uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); rpl_set_prefix(dag, &prefix, 64); - PRINTF("rpl_dag_root_init_dag: created a new RPL dag\n"); + PRINTF("rpl_dag_root_set_prefix_dag: created a new RPL dag\n"); return 0; } else { - PRINTF("rpl_dag_root_init_dag: failed to create a new RPL DAG\n"); + PRINTF("rpl_dag_root_set_prefix_dag: failed to create a new RPL DAG\n"); return -1; } } else { - PRINTF("rpl_dag_root_init_dag: failed to create a new RPL DAG, no preferred IP address found\n"); + PRINTF("rpl_dag_root_set_prefix_dag: failed to create a new RPL DAG, no preferred IP address found\n"); return -2; } } /*---------------------------------------------------------------------------*/ -void -rpl_dag_root_init_dag_delay(void) -{ - rpl_dag_root_init(NULL, NULL); - - ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL); - to_become_root = 1; - - /* Send a DIS packet to request RPL info from neighbors. */ - dis_output(NULL); -} -/*---------------------------------------------------------------------------*/ int rpl_dag_root_is_root(void) { diff --git a/os/net/rpl-classic/rpl-dag-root.h b/os/net/routing/rpl-classic/rpl-dag-root.h similarity index 92% rename from os/net/rpl-classic/rpl-dag-root.h rename to os/net/routing/rpl-classic/rpl-dag-root.h index 05daec15b..9d2d09b02 100644 --- a/os/net/rpl-classic/rpl-dag-root.h +++ b/os/net/routing/rpl-classic/rpl-dag-root.h @@ -32,9 +32,8 @@ #ifndef RPL_DAG_ROOT_H_ #define RPL_DAG_ROOT_H_ -void rpl_dag_root_init(uip_ipaddr_t *prefix, uip_ipaddr_t *iid); -void rpl_dag_root_init_dag_delay(void); -int rpl_dag_root_init_dag_immediately(void); +void rpl_dag_root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid); +int rpl_dag_root_start(void); int rpl_dag_root_is_root(void); diff --git a/os/net/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c similarity index 99% rename from os/net/rpl-classic/rpl-dag.c rename to os/net/routing/rpl-classic/rpl-dag.c index aeed6194e..899322264 100644 --- a/os/net/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -45,7 +45,9 @@ #include "contiki.h" #include "net/link-stats.h" -#include "net/rpl-classic/rpl-private.h" +#include "net/routing/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl-private.h" +#include "net/routing/rpl-classic/rpl-dag-root.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-nd6.h" #include "net/ipv6/uip-ds6-nbr.h" @@ -1004,9 +1006,18 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent) } /*---------------------------------------------------------------------------*/ int +rpl_has_joined(void) +{ + return rpl_get_any_dag() != NULL; +} +/*---------------------------------------------------------------------------*/ +int rpl_has_downward_route(void) { int i; + if(rpl_dag_root_is_root()) { + return 1; /* We are the root, and know the route to ourself */ + } for(i = 0; i < RPL_MAX_INSTANCES; ++i) { if(instance_table[i].used && instance_table[i].has_downward_route) { return 1; diff --git a/os/net/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c similarity index 96% rename from os/net/rpl-classic/rpl-ext-header.c rename to os/net/routing/rpl-classic/rpl-ext-header.c index 083d26741..e6498b993 100644 --- a/os/net/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -44,11 +44,12 @@ * @{ */ +#include "net/routing/routing.h" #include "net/ipv6/uip.h" #include "net/ipv6/tcpip.h" #include "net/ipv6/uip-ds6.h" -#include "net/rpl-classic/rpl-private.h" -#include "net/rpl-classic/rpl-ns.h" +#include "net/ipv6/uip-sr.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/packetbuf.h" #define DEBUG DEBUG_NONE @@ -174,15 +175,15 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) return 1; } /*---------------------------------------------------------------------------*/ -#if RPL_WITH_NON_STORING int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) { +#if RPL_WITH_NON_STORING uint8_t *uip_next_hdr; int last_uip_ext_len = uip_ext_len; rpl_dag_t *dag; - rpl_ns_node_t *dest_node; - rpl_ns_node_t *root_node; + uip_sr_node_t *dest_node; + uip_sr_node_t *root_node; uip_ext_len = 0; uip_next_hdr = &UIP_IP_BUF->proto; @@ -208,8 +209,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) } dag = rpl_get_dag(&UIP_IP_BUF->destipaddr); - root_node = rpl_ns_get_node(dag, &dag->dag_id); - dest_node = rpl_ns_get_node(dag, &UIP_IP_BUF->destipaddr); + root_node = uip_sr_get_node(dag, &dag->dag_id); + dest_node = uip_sr_get_node(dag, &UIP_IP_BUF->destipaddr); if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING && UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) || @@ -227,11 +228,15 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) uip_ext_len = last_uip_ext_len; return 0; +#else /* RPL_WITH_NON_STORING */ + return 0; /* SRH not found */ +#endif /* RPL_WITH_NON_STORING */ } /*---------------------------------------------------------------------------*/ int rpl_ext_header_srh_update(void) { +#if RPL_WITH_NON_STORING uint8_t *uip_next_hdr; int last_uip_ext_len = uip_ext_len; @@ -308,6 +313,9 @@ rpl_ext_header_srh_update(void) uip_ext_len = last_uip_ext_len; return 0; +#else /* RPL_WITH_NON_STORING */ + return 0; /* SRH not found */ +#endif /* RPL_WITH_NON_STORING */ } /*---------------------------------------------------------------------------*/ static int @@ -332,9 +340,9 @@ insert_srh_header(void) uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */ uint8_t *hop_ptr; uint8_t padding; - rpl_ns_node_t *dest_node; - rpl_ns_node_t *root_node; - rpl_ns_node_t *node; + uip_sr_node_t *dest_node; + uip_sr_node_t *root_node; + uip_sr_node_t *node; rpl_dag_t *dag; uip_ipaddr_t node_addr; @@ -352,19 +360,19 @@ insert_srh_header(void) return 0; } - dest_node = rpl_ns_get_node(dag, &UIP_IP_BUF->destipaddr); + dest_node = uip_sr_get_node(dag, &UIP_IP_BUF->destipaddr); if(dest_node == NULL) { /* The destination is not found, skip SRH insertion */ return 1; } - root_node = rpl_ns_get_node(dag, &dag->dag_id); + root_node = uip_sr_get_node(dag, &dag->dag_id); if(root_node == NULL) { PRINTF("RPL: SRH root node not found\n"); return 0; } - if(!rpl_ns_is_node_reachable(dag, &UIP_IP_BUF->destipaddr)) { + if(!uip_sr_is_addr_reachable(dag, &UIP_IP_BUF->destipaddr)) { PRINTF("RPL: SRH no path found to destination\n"); return 0; } @@ -383,7 +391,7 @@ insert_srh_header(void) while(node != NULL && node != root_node) { - rpl_ns_get_node_global_addr(&node_addr, node); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); /* How many bytes in common between all nodes in the path? */ cmpri = MIN(cmpri, count_matching_bytes(&node_addr, &UIP_IP_BUF->destipaddr, 16)); @@ -437,7 +445,7 @@ insert_srh_header(void) hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */ while(node != NULL && node->parent != root_node) { - rpl_ns_get_node_global_addr(&node_addr, node); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); hop_ptr -= (16 - cmpri); memcpy(hop_ptr, ((uint8_t*)&node_addr) + cmpri, 16 - cmpri); @@ -446,7 +454,7 @@ insert_srh_header(void) } /* The next hop (i.e. node whose parent is the root) is placed as the current IPv6 destination */ - rpl_ns_get_node_global_addr(&node_addr, node); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &node_addr); /* In-place update of IPv6 length field */ @@ -461,9 +469,6 @@ insert_srh_header(void) return 1; } -#else /* RPL_WITH_NON_STORING */ -int insert_srh_header(void); -#endif /* RPL_WITH_NON_STORING */ /*---------------------------------------------------------------------------*/ static int update_hbh_header(void) diff --git a/os/net/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c similarity index 99% rename from os/net/rpl-classic/rpl-icmp6.c rename to os/net/routing/rpl-classic/rpl-icmp6.c index 6d9a2bca3..914575dbf 100644 --- a/os/net/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -49,9 +49,9 @@ #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip-nd6.h" +#include "net/ipv6/uip-sr.h" #include "net/ipv6/uip-icmp6.h" -#include "net/rpl-classic/rpl-private.h" -#include "net/rpl-classic/rpl-ns.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/packetbuf.h" #include "net/ipv6/multicast/uip-mcast6.h" #include "random.h" @@ -993,9 +993,9 @@ dao_input_nonstoring(void) if(lifetime == RPL_ZERO_LIFETIME) { PRINTF("RPL: No-Path DAO received\n"); - rpl_ns_expire_parent(dag, &prefix, &dao_parent_addr); + uip_sr_expire_parent(dag, &prefix, &dao_parent_addr); } else { - if(rpl_ns_update_node(dag, &prefix, &dao_parent_addr, RPL_LIFETIME(instance, lifetime)) == NULL) { + if(uip_sr_update_node(dag, &prefix, &dao_parent_addr, RPL_LIFETIME(instance, lifetime)) == NULL) { PRINTF("RPL: failed to add link\n"); return; } diff --git a/os/net/rpl-classic/rpl-mrhof.c b/os/net/routing/rpl-classic/rpl-mrhof.c similarity index 99% rename from os/net/rpl-classic/rpl-mrhof.c rename to os/net/routing/rpl-classic/rpl-mrhof.c index 21db377e7..4f5189384 100644 --- a/os/net/rpl-classic/rpl-mrhof.c +++ b/os/net/routing/rpl-classic/rpl-mrhof.c @@ -46,8 +46,8 @@ * @{ */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" +#include "net/routing/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/nbr-table.h" #include "net/link-stats.h" diff --git a/os/net/rpl-classic/rpl-nbr-policy.c b/os/net/routing/rpl-classic/rpl-nbr-policy.c similarity index 99% rename from os/net/rpl-classic/rpl-nbr-policy.c rename to os/net/routing/rpl-classic/rpl-nbr-policy.c index 1804fd4b7..077977a10 100644 --- a/os/net/rpl-classic/rpl-nbr-policy.c +++ b/os/net/routing/rpl-classic/rpl-nbr-policy.c @@ -44,7 +44,7 @@ * */ -#include "net/rpl-classic/rpl-private.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/nbr-table.h" #include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6-route.h" diff --git a/os/net/rpl-classic/rpl-of0.c b/os/net/routing/rpl-classic/rpl-of0.c similarity index 98% rename from os/net/rpl-classic/rpl-of0.c rename to os/net/routing/rpl-classic/rpl-of0.c index aa18823cb..1a679d23b 100644 --- a/os/net/rpl-classic/rpl-of0.c +++ b/os/net/routing/rpl-classic/rpl-of0.c @@ -42,8 +42,8 @@ * @{ */ -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" +#include "net/routing/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/nbr-table.h" #include "net/link-stats.h" diff --git a/os/net/rpl-classic/rpl-private.h b/os/net/routing/rpl-classic/rpl-private.h similarity index 99% rename from os/net/rpl-classic/rpl-private.h rename to os/net/routing/rpl-classic/rpl-private.h index 723154cdd..1259fffeb 100644 --- a/os/net/rpl-classic/rpl-private.h +++ b/os/net/routing/rpl-classic/rpl-private.h @@ -37,7 +37,7 @@ #ifndef RPL_PRIVATE_H #define RPL_PRIVATE_H -#include "net/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl.h" #include "lib/list.h" #include "net/ipv6/uip.h" @@ -45,7 +45,6 @@ #include "sys/ctimer.h" #include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip-ds6-route.h" -#include "net/rpl-classic/rpl-ns.h" #include "net/ipv6/multicast/uip-mcast6.h" /*---------------------------------------------------------------------------*/ diff --git a/os/net/rpl-classic/rpl-timers.c b/os/net/routing/rpl-classic/rpl-timers.c similarity index 99% rename from os/net/rpl-classic/rpl-timers.c rename to os/net/routing/rpl-classic/rpl-timers.c index 7742a5fcc..c812a8897 100644 --- a/os/net/rpl-classic/rpl-timers.c +++ b/os/net/routing/rpl-classic/rpl-timers.c @@ -42,10 +42,10 @@ */ #include "contiki.h" -#include "net/rpl-classic/rpl-private.h" -#include "net/rpl-classic/rpl-ns.h" +#include "net/routing/rpl-classic/rpl-private.h" #include "net/link-stats.h" #include "net/ipv6/multicast/uip-mcast6.h" +#include "net/ipv6/uip-sr.h" #include "lib/random.h" #include "sys/ctimer.h" @@ -89,7 +89,7 @@ handle_periodic_timer(void *ptr) rpl_purge_routes(); } if(RPL_IS_NON_STORING(dag->instance)) { - rpl_ns_periodic(); + uip_sr_periodic(1); } } rpl_recalculate_ranks(); diff --git a/os/net/rpl-classic/rpl.c b/os/net/routing/rpl-classic/rpl.c similarity index 80% rename from os/net/rpl-classic/rpl.c rename to os/net/routing/rpl-classic/rpl.c index dfa7c99cf..b1905d611 100644 --- a/os/net/rpl-classic/rpl.c +++ b/os/net/routing/rpl-classic/rpl.c @@ -45,9 +45,11 @@ #include "net/ipv6/uip.h" #include "net/ipv6/tcpip.h" #include "net/ipv6/uip-ds6.h" +#include "net/ipv6/uip-sr.h" #include "net/ipv6/uip-icmp6.h" -#include "net/rpl-classic/rpl-private.h" -#include "net/rpl-classic/rpl-ns.h" +#include "net/routing/routing.h" +#include "net/routing/rpl-classic/rpl-private.h" +#include "net/routing/rpl-classic/rpl-dag-root.h" #include "net/ipv6/multicast/uip-mcast6.h" #define DEBUG DEBUG_NONE @@ -327,8 +329,8 @@ rpl_purge_dags(void) } } /*---------------------------------------------------------------------------*/ -void -rpl_init(void) +static void +init(void) { uip_ipaddr_t rplmaddr; PRINTF("RPL started\n"); @@ -347,9 +349,93 @@ rpl_init(void) #endif #if RPL_WITH_NON_STORING - rpl_ns_init(); + uip_sr_init(); #endif /* RPL_WITH_NON_STORING */ } /*---------------------------------------------------------------------------*/ +static int +get_sr_node_ipaddr(uip_ipaddr_t *addr, const uip_sr_node_t *node) +{ + if(addr != NULL && node != NULL) { + memcpy(addr, &((rpl_dag_t *)node->graph)->dag_id, 8); + memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8); + return 1; + } else { + return 0; + } +} +/*---------------------------------------------------------------------------*/ +static void +global_repair(const char *str) +{ + rpl_dag_t *dag = rpl_get_any_dag(); + if(dag != NULL && dag->instance != NULL) { + rpl_repair_root(dag->instance->instance_id); + } +} +/*---------------------------------------------------------------------------*/ +static void +local_repair(const char *str) +{ + rpl_dag_t *dag = rpl_get_any_dag(); + if(dag != NULL) { + rpl_local_repair(dag->instance); + } +} +/*---------------------------------------------------------------------------*/ +static void +drop_route(uip_ds6_route_t *route) +{ + /* If we are the root of the network, trigger a global repair before + the route gets removed */ + rpl_dag_t *dag; + dag = (rpl_dag_t *)route->state.dag; + if(dag != NULL && dag->instance != NULL) { + rpl_repair_root(dag->instance->instance_id); + } +} +/*---------------------------------------------------------------------------*/ +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, + get_sr_node_ipaddr, + leave_network, + rpl_has_joined, + rpl_has_downward_route, + global_repair, + local_repair, + rpl_ext_header_remove, + rpl_ext_header_update, + rpl_ext_header_hbh_update, + rpl_ext_header_srh_update, + rpl_ext_header_srh_get_next_hop, + rpl_link_callback, + rpl_ipv6_neighbor_callback, + drop_route, +}; +/*---------------------------------------------------------------------------*/ /** @}*/ diff --git a/os/net/rpl-classic/rpl.h b/os/net/routing/rpl-classic/rpl.h similarity index 98% rename from os/net/rpl-classic/rpl.h rename to os/net/routing/rpl-classic/rpl.h index 2fe9f1dbf..db87cc824 100644 --- a/os/net/rpl-classic/rpl.h +++ b/os/net/routing/rpl-classic/rpl.h @@ -38,7 +38,7 @@ #ifndef RPL_H #define RPL_H -#include "net/rpl-classic/rpl-conf.h" +#include "net/routing/rpl-classic/rpl-conf.h" #include "lib/list.h" #include "net/ipv6/uip.h" @@ -266,7 +266,6 @@ struct rpl_instance { /*---------------------------------------------------------------------------*/ /* Public RPL functions. */ -void rpl_init(void); void uip_rpl_input(void); rpl_dag_t *rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id); int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len); @@ -328,6 +327,12 @@ enum rpl_mode rpl_set_mode(enum rpl_mode mode); */ enum rpl_mode rpl_get_mode(void); +/** + * Tells whether the node has joined a network or not + * + * \retval 1 if we have joined a network, 0 if not. + */ +int rpl_has_joined(void); /** * Get the RPL's best guess on if we have downward route or not. diff --git a/os/net/rpl-lite/rpl-conf.h b/os/net/routing/rpl-lite/rpl-conf.h similarity index 97% rename from os/net/rpl-lite/rpl-conf.h rename to os/net/routing/rpl-lite/rpl-conf.h index 410cce988..aa08a1db8 100644 --- a/os/net/rpl-lite/rpl-conf.h +++ b/os/net/routing/rpl-lite/rpl-conf.h @@ -62,7 +62,16 @@ * We only support non-storing mode */ #define RPL_WITH_STORING 0 + +/* + * Embed support for non-storing mode + */ +#ifdef RPL_CONF_WITH_NON_STORING +#define RPL_WITH_NON_STORING RPL_CONF_WITH_NON_STORING +#else /* RPL_CONF_WITH_NON_STORING */ +/* By default: embed support for non-storing if and only if the configured MOP is non-storing */ #define RPL_WITH_NON_STORING (RPL_MOP_DEFAULT == RPL_MOP_NON_STORING) +#endif /* RPL_CONF_WITH_NON_STORING */ /* The number of non-storing nodes, i.e. the maximum netwrok size at the root */ #ifdef RPL_NS_CONF_LINK_NUM @@ -309,13 +318,6 @@ #define RPL_DAO_DELAY (CLOCK_SECOND * 4) #endif /* RPL_CONF_DAO_DELAY */ -/* Delay between reception of a no-path DAO and actual route removal */ -#ifdef RPL_CONF_NOPATH_REMOVAL_DELAY -#define RPL_NOPATH_REMOVAL_DELAY RPL_CONF_NOPATH_REMOVAL_DELAY -#else /* RPL_CONF_NOPATH_REMOVAL_DELAY */ -#define RPL_NOPATH_REMOVAL_DELAY 60 -#endif /* RPL_CONF_NOPATH_REMOVAL_DELAY */ - #ifdef RPL_CONF_DAO_MAX_RETRANSMISSIONS #define RPL_DAO_MAX_RETRANSMISSIONS RPL_CONF_DAO_MAX_RETRANSMISSIONS #else diff --git a/os/net/rpl-lite/rpl-const.h b/os/net/routing/rpl-lite/rpl-const.h similarity index 100% rename from os/net/rpl-lite/rpl-const.h rename to os/net/routing/rpl-lite/rpl-const.h diff --git a/os/net/rpl-lite/rpl-dag-root.c b/os/net/routing/rpl-lite/rpl-dag-root.c similarity index 68% rename from os/net/rpl-lite/rpl-dag-root.c rename to os/net/routing/rpl-lite/rpl-dag-root.c index cfe227d4c..0d5cebe92 100644 --- a/os/net/rpl-lite/rpl-dag-root.c +++ b/os/net/routing/rpl-lite/rpl-dag-root.c @@ -40,7 +40,7 @@ #include "contiki.h" #include "contiki-net.h" -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "net/ipv6/uip-ds6-route.h" /* Log configuration */ @@ -48,48 +48,6 @@ #define LOG_MODULE "RPL" #define LOG_LEVEL LOG_LEVEL_RPL -#define RPL_DAG_GRACE_PERIOD (CLOCK_SECOND * 20 * 1) - -static uint8_t to_become_root; -static struct ctimer c; - -/*---------------------------------------------------------------------------*/ -static void -create_dag_callback(void *ptr) -{ - const uip_ipaddr_t *root, *ipaddr; - - root = curr_instance.used ? &curr_instance.dag.dag_id : NULL; - ipaddr = rpl_get_global_address(); - - if(root == NULL || uip_ipaddr_cmp(root, ipaddr)) { - /* The RPL network we are joining is one that we created, so we - become root. */ - if(to_become_root) { - rpl_dag_root_init_dag_immediately(); - to_become_root = 0; - } - } else { - LOG_WARN("found a network we did not create: version %d grounded %d preference %d rank %d\n", - curr_instance.dag.version, curr_instance.dag.grounded, - curr_instance.dag.preference, curr_instance.dag.rank); - - /* We found a RPL network that we did not create so we just join - it without becoming root. But if the network has an infinite - rank, we assume the network has broken, and we become the new - root of the network. */ - - if(curr_instance.dag.rank == RPL_INFINITE_RANK) { - if(to_become_root) { - rpl_dag_root_init_dag_immediately(); - to_become_root = 0; - } - } - - /* Try again after the grace period */ - ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL); - } -} /*---------------------------------------------------------------------------*/ static void set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) @@ -125,26 +83,25 @@ set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) } /*---------------------------------------------------------------------------*/ void -rpl_dag_root_init(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) +rpl_dag_root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) { static uint8_t initialized = 0; if(!initialized) { - to_become_root = 0; set_global_address(prefix, iid); initialized = 1; } } /*---------------------------------------------------------------------------*/ int -rpl_dag_root_init_dag_immediately(void) +rpl_dag_root_start(void) { struct uip_ds6_addr *root_if; int i; uint8_t state; uip_ipaddr_t *ipaddr = NULL; - rpl_dag_root_init(NULL, NULL); + rpl_dag_root_set_prefix(NULL, NULL); for(i = 0; i < UIP_DS6_ADDR_NB; i++) { state = uip_ds6_if.addr_list[i].state; @@ -170,18 +127,6 @@ rpl_dag_root_init_dag_immediately(void) } } /*---------------------------------------------------------------------------*/ -void -rpl_dag_root_init_dag_delay(void) -{ - rpl_dag_root_init(NULL, NULL); - - ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL); - to_become_root = 1; - - /* Send a DIS packet to request RPL info from neighbors. */ - rpl_icmp6_dis_output(NULL); -} -/*---------------------------------------------------------------------------*/ int rpl_dag_root_is_root(void) { diff --git a/os/net/rpl-lite/rpl-dag-root.h b/os/net/routing/rpl-lite/rpl-dag-root.h similarity index 83% rename from os/net/rpl-lite/rpl-dag-root.h rename to os/net/routing/rpl-lite/rpl-dag-root.h index d6260ff21..af0048c4d 100644 --- a/os/net/rpl-lite/rpl-dag-root.h +++ b/os/net/routing/rpl-lite/rpl-dag-root.h @@ -43,26 +43,19 @@ /********** Public functions **********/ /** - * Initialize dag-root module and sets a prefix in case the node is later - * set as dag root. + * Set a prefix in case the node is later set as dag root. * * \param prefix The prefix. If NULL, UIP_DS6_DEFAULT_PREFIX is used instead * \param iid The IID. If NULL, it will be built from uip_ds6_set_addr_iid. */ -void rpl_dag_root_init(uip_ipaddr_t *prefix, uip_ipaddr_t *iid); +void rpl_dag_root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid); /** - * Initializes the node as DAG root after a delay. Until the delay, the node - * gets a chance to hear another DAG and join it instead. -*/ -void rpl_dag_root_init_dag_delay(void); - -/** - * Initializes the node as DAG root immediatly. + * Set the node as root and start a DAG * * \return 0 in case of success, -1 otherwise */ -int rpl_dag_root_init_dag_immediately(void); +int rpl_dag_root_start(void); /** * Tells whether we are DAG root or not diff --git a/os/net/rpl-lite/rpl-dag.c b/os/net/routing/rpl-lite/rpl-dag.c similarity index 97% rename from os/net/rpl-lite/rpl-dag.c rename to os/net/routing/rpl-lite/rpl-dag.c index 36373dfb1..fed488013 100644 --- a/os/net/rpl-lite/rpl-dag.c +++ b/os/net/routing/rpl-lite/rpl-dag.c @@ -42,7 +42,8 @@ * Contributors: George Oikonomou (multicast) */ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" +#include "net/ipv6/uip-sr.h" #include "net/nbr-table.h" #include "net/link-stats.h" @@ -78,6 +79,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) { @@ -96,7 +107,7 @@ rpl_dag_leave(void) /* Remove all neighbors and lnks */ rpl_neighbor_remove_all(); - rpl_ns_free_all(); + uip_sr_free_all(); /* Stop all timers */ rpl_timers_stop_dag_timers(); @@ -169,11 +180,11 @@ find_objective_function(rpl_ocp_t ocp) } /*---------------------------------------------------------------------------*/ void -rpl_global_repair(void) +rpl_global_repair(const char *str) { if(rpl_dag_root_is_root()) { - LOG_WARN("initiating global repair, version %u, rank %u)\n", - curr_instance.dag.version, curr_instance.dag.rank); + LOG_WARN("initiating global repair (%s), version %u, rank %u)\n", + str, curr_instance.dag.version, curr_instance.dag.rank); #if LOG_INFO_ENABLED rpl_neighbor_print_list("Global repair (before)"); #endif /* LOG_INFO_ENABLED */ @@ -391,7 +402,7 @@ process_dio_from_current_dag(uip_ipaddr_t *from, rpl_dio_t *dio) LOG_ERR("inconsistent DIO version (current: %u, received: %u), initiate global repair\n", curr_instance.dag.version, dio->version); curr_instance.dag.version = dio->version; /* Update version and trigger global repair */ - rpl_global_repair(); + rpl_global_repair("Inconsistent DIO version"); } else { LOG_WARN("new DIO version (current: %u, received: %u), apply global repair\n", curr_instance.dag.version, dio->version); @@ -579,9 +590,9 @@ void rpl_process_dao(uip_ipaddr_t *from, rpl_dao_t *dao) { if(dao->lifetime == 0) { - rpl_ns_expire_parent(from, &dao->parent_addr); + uip_sr_expire_parent(NULL, from, &dao->parent_addr); } else { - if(!rpl_ns_update_node(from, &dao->parent_addr, RPL_LIFETIME(dao->lifetime))) { + if(!uip_sr_update_node(NULL, from, &dao->parent_addr, RPL_LIFETIME(dao->lifetime))) { LOG_ERR("failed to add link on incoming DAO\n"); return; } diff --git a/os/net/rpl-lite/rpl-dag.h b/os/net/routing/rpl-lite/rpl-dag.h similarity index 93% rename from os/net/rpl-lite/rpl-dag.h rename to os/net/routing/rpl-lite/rpl-dag.h index bc59ac4bb..f9ae66f5f 100644 --- a/os/net/rpl-lite/rpl-dag.h +++ b/os/net/routing/rpl-lite/rpl-dag.h @@ -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 * @@ -78,8 +85,10 @@ void rpl_dag_periodic(unsigned seconds); /** * Triggers a RPL global repair + * + * \param str A textual description of the cause for triggering a repair */ -void rpl_global_repair(void); +void rpl_global_repair(const char *str); /** * Triggers a RPL local repair diff --git a/os/net/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c similarity index 96% rename from os/net/rpl-lite/rpl-ext-header.c rename to os/net/routing/rpl-lite/rpl-ext-header.c index 6031d7eef..af67cdaff 100644 --- a/os/net/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -42,8 +42,10 @@ * Nicolas Tsiftes , * Simon Duquennoy */ - -#include "net/rpl-lite/rpl.h" + +#include "net/routing/routing.h" +#include "net/routing/rpl-lite/rpl.h" +#include "net/ipv6/uip-sr.h" #include "net/packetbuf.h" /* Log configuration */ @@ -68,8 +70,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) { uint8_t *uip_next_hdr; int last_uip_ext_len = uip_ext_len; - rpl_ns_node_t *dest_node; - rpl_ns_node_t *root_node; + uip_sr_node_t *dest_node; + uip_sr_node_t *root_node; uip_ext_len = 0; uip_next_hdr = &UIP_IP_BUF->proto; @@ -96,8 +98,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) return 0; } - root_node = rpl_ns_get_node(&curr_instance.dag.dag_id); - dest_node = rpl_ns_get_node(&UIP_IP_BUF->destipaddr); + root_node = uip_sr_get_node(NULL, &curr_instance.dag.dag_id); + dest_node = uip_sr_get_node(NULL, &UIP_IP_BUF->destipaddr); if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING && UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) || @@ -227,9 +229,9 @@ insert_srh_header(void) uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */ uint8_t *hop_ptr; uint8_t padding; - rpl_ns_node_t *dest_node; - rpl_ns_node_t *root_node; - rpl_ns_node_t *node; + uip_sr_node_t *dest_node; + uip_sr_node_t *root_node; + uip_sr_node_t *node; uip_ipaddr_t node_addr; LOG_INFO("SRH creating source routing header with destination "); @@ -246,20 +248,20 @@ insert_srh_header(void) return 1; } - dest_node = rpl_ns_get_node(&UIP_IP_BUF->destipaddr); + dest_node = uip_sr_get_node(NULL, &UIP_IP_BUF->destipaddr); if(dest_node == NULL) { /* The destination is not found, skip SRH insertion */ LOG_INFO("SRH node not found, skip SRH insertion\n"); return 1; } - root_node = rpl_ns_get_node(&curr_instance.dag.dag_id); + root_node = uip_sr_get_node(NULL, &curr_instance.dag.dag_id); if(root_node == NULL) { LOG_ERR("SRH root node not found\n"); return 0; } - if(!rpl_ns_is_addr_reachable(&UIP_IP_BUF->destipaddr)) { + if(!uip_sr_is_addr_reachable(NULL, &UIP_IP_BUF->destipaddr)) { LOG_ERR("SRH no path found to destination\n"); return 0; } @@ -277,7 +279,7 @@ insert_srh_header(void) while(node != NULL && node != root_node) { - rpl_ns_get_node_global_addr(&node_addr, node); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); /* How many bytes in common between all nodes in the path? */ cmpri = MIN(cmpri, count_matching_bytes(&node_addr, &UIP_IP_BUF->destipaddr, 16)); @@ -331,7 +333,7 @@ insert_srh_header(void) hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */ while(node != NULL && node->parent != root_node) { - rpl_ns_get_node_global_addr(&node_addr, node); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); hop_ptr -= (16 - cmpri); memcpy(hop_ptr, ((uint8_t*)&node_addr) + cmpri, 16 - cmpri); @@ -340,7 +342,7 @@ insert_srh_header(void) } /* The next hop (i.e. node whose parent is the root) is placed as the current IPv6 destination */ - rpl_ns_get_node_global_addr(&node_addr, node); + NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &node_addr); /* In-place update of IPv6 length field */ diff --git a/os/net/rpl-lite/rpl-ext-header.h b/os/net/routing/rpl-lite/rpl-ext-header.h similarity index 71% rename from os/net/rpl-lite/rpl-ext-header.h rename to os/net/routing/rpl-lite/rpl-ext-header.h index 3e339e6e2..df61bc325 100644 --- a/os/net/rpl-lite/rpl-ext-header.h +++ b/os/net/routing/rpl-lite/rpl-ext-header.h @@ -44,33 +44,34 @@ /********** Public functions **********/ - /** - * Look for next hop from SRH of current uIP packet. - * - * \param ipaddr A pointer to the address where to store the next hop. - * \return 1 if a next hop was found, 0 otherwise - */ - int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr); - - /** - * Process and update SRH in-place, - * i.e. internal address swapping as per RFC6554 - * \return 1 if SRH found, 0 otherwise - */ - int rpl_ext_header_srh_update(void); - - /** - * Process and update the RPL extension headers of the current uIP packet. - * - * \param uip_ext_opt_offset The offset within the uIP packet where - * extension headers start - * \return 1 in case the packet is valid and to be processed further, - * 0 in case the packet must be dropped. - */ - int rpl_ext_header_hbh_update(int uip_ext_opt_offset); +/** +* Look for next hop from SRH of current uIP packet. +* +* \param ipaddr A pointer to the address where to store the next hop. +* \return 1 if a next hop was found, 0 otherwise +*/ +int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr); /** - * Adds/updates RPL extension headers to current uIP packet. +* Process and update SRH in-place, +* i.e. internal address swapping as per RFC6554 +* \return 1 if SRH found, 0 otherwise +*/ +int rpl_ext_header_srh_update(void); + +/** +* Process and update the RPL hop-by-hop extension headers of +* the current uIP packet. +* +* \param uip_ext_opt_offset The offset within the uIP packet where +* extension headers start +* \return 1 in case the packet is valid and to be processed further, +* 0 in case the packet must be dropped. +*/ +int rpl_ext_header_hbh_update(int uip_ext_opt_offset); + +/** + * Adds/updates all RPL extension headers to current uIP packet. * * \return 1 in case of success, 0 otherwise */ diff --git a/os/net/rpl-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c similarity index 99% rename from os/net/rpl-lite/rpl-icmp6.c rename to os/net/routing/rpl-lite/rpl-icmp6.c index 65c486be5..1e4a50423 100644 --- a/os/net/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -44,7 +44,7 @@ * George Oikonomou (multicast) */ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "net/ipv6/uip-icmp6.h" #include "net/packetbuf.h" #include "lib/random.h" diff --git a/os/net/rpl-lite/rpl-icmp6.h b/os/net/routing/rpl-lite/rpl-icmp6.h similarity index 99% rename from os/net/rpl-lite/rpl-icmp6.h rename to os/net/routing/rpl-lite/rpl-icmp6.h index 443d28ef6..fc877b948 100644 --- a/os/net/rpl-lite/rpl-icmp6.h +++ b/os/net/routing/rpl-lite/rpl-icmp6.h @@ -44,6 +44,7 @@ #include "uip.h" #include "uip-ds6.h" +#include "uip-ds6-nbr.h" /********** Data structures **********/ diff --git a/os/net/rpl-lite/rpl-mrhof.c b/os/net/routing/rpl-lite/rpl-mrhof.c similarity index 99% rename from os/net/rpl-lite/rpl-mrhof.c rename to os/net/routing/rpl-lite/rpl-mrhof.c index 9f9ba2889..a0b2546eb 100644 --- a/os/net/rpl-lite/rpl-mrhof.c +++ b/os/net/routing/rpl-lite/rpl-mrhof.c @@ -45,7 +45,7 @@ * Simon Duquennoy */ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "net/nbr-table.h" #include "net/link-stats.h" diff --git a/os/net/rpl-lite/rpl-nbr-policy.c b/os/net/routing/rpl-lite/rpl-nbr-policy.c similarity index 99% rename from os/net/rpl-lite/rpl-nbr-policy.c rename to os/net/routing/rpl-lite/rpl-nbr-policy.c index 0a8da44d4..f848ddb39 100644 --- a/os/net/rpl-lite/rpl-nbr-policy.c +++ b/os/net/routing/rpl-lite/rpl-nbr-policy.c @@ -42,7 +42,7 @@ * */ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "net/nbr-table.h" /* Log configuration */ diff --git a/os/net/rpl-lite/rpl-neighbor.c b/os/net/routing/rpl-lite/rpl-neighbor.c similarity index 99% rename from os/net/rpl-lite/rpl-neighbor.c rename to os/net/routing/rpl-lite/rpl-neighbor.c index 96c85a886..d6a545e13 100644 --- a/os/net/rpl-lite/rpl-neighbor.c +++ b/os/net/routing/rpl-lite/rpl-neighbor.c @@ -43,7 +43,7 @@ */ #include "contiki.h" -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "net/link-stats.h" #include "net/nbr-table.h" diff --git a/os/net/rpl-lite/rpl-neighbor.h b/os/net/routing/rpl-lite/rpl-neighbor.h similarity index 99% rename from os/net/rpl-lite/rpl-neighbor.h rename to os/net/routing/rpl-lite/rpl-neighbor.h index 319ab2414..028d089c7 100644 --- a/os/net/rpl-lite/rpl-neighbor.h +++ b/os/net/routing/rpl-lite/rpl-neighbor.h @@ -47,7 +47,7 @@ /********** Includes **********/ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "lib/list.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" diff --git a/os/net/rpl-lite/rpl-of0.c b/os/net/routing/rpl-lite/rpl-of0.c similarity index 99% rename from os/net/rpl-lite/rpl-of0.c rename to os/net/routing/rpl-lite/rpl-of0.c index 0e94f73f9..c6f820157 100644 --- a/os/net/rpl-lite/rpl-of0.c +++ b/os/net/routing/rpl-lite/rpl-of0.c @@ -41,7 +41,7 @@ * Simon Duquennoy */ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" #include "net/nbr-table.h" #include "net/link-stats.h" diff --git a/os/net/rpl-lite/rpl-timers.c b/os/net/routing/rpl-lite/rpl-timers.c similarity index 99% rename from os/net/rpl-lite/rpl-timers.c rename to os/net/routing/rpl-lite/rpl-timers.c index 486ccd5b4..5da6edc67 100644 --- a/os/net/rpl-lite/rpl-timers.c +++ b/os/net/routing/rpl-lite/rpl-timers.c @@ -41,7 +41,8 @@ */ #include "contiki.h" -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" +#include "net/ipv6/uip-sr.h" #include "net/link-stats.h" #include "lib/random.h" #include "sys/ctimer.h" @@ -500,7 +501,7 @@ handle_periodic_timer(void *ptr) { if(curr_instance.used) { rpl_dag_periodic(PERIODIC_DELAY_SECONDS); - rpl_ns_periodic(PERIODIC_DELAY_SECONDS); + uip_sr_periodic(PERIODIC_DELAY_SECONDS); } if(!curr_instance.used || diff --git a/os/net/rpl-lite/rpl-timers.h b/os/net/routing/rpl-lite/rpl-timers.h similarity index 98% rename from os/net/rpl-lite/rpl-timers.h rename to os/net/routing/rpl-lite/rpl-timers.h index c32f3775c..884a55696 100644 --- a/os/net/rpl-lite/rpl-timers.h +++ b/os/net/routing/rpl-lite/rpl-timers.h @@ -47,7 +47,7 @@ /********** Includes **********/ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" /********** Public functions **********/ diff --git a/os/net/rpl-lite/rpl-types.h b/os/net/routing/rpl-lite/rpl-types.h similarity index 100% rename from os/net/rpl-lite/rpl-types.h rename to os/net/routing/rpl-lite/rpl-types.h diff --git a/os/net/rpl-lite/rpl.c b/os/net/routing/rpl-lite/rpl.c similarity index 80% rename from os/net/rpl-lite/rpl.c rename to os/net/routing/rpl-lite/rpl.c index 29eca52b0..acfe94c37 100644 --- a/os/net/rpl-lite/rpl.c +++ b/os/net/routing/rpl-lite/rpl.c @@ -41,7 +41,8 @@ * Simon Duquennoy */ -#include "net/rpl-lite/rpl.h" +#include "net/routing/rpl-lite/rpl.h" +#include "net/routing/routing.h" /* Log configuration */ #include "sys/log.h" @@ -108,6 +109,12 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx) } /*---------------------------------------------------------------------------*/ int +rpl_has_joined(void) +{ + return curr_instance.used && curr_instance.dag.state >= DAG_JOINED; +} +/*---------------------------------------------------------------------------*/ +int rpl_is_reachable(void) { return curr_instance.used && curr_instance.dag.state == DAG_REACHABLE; @@ -175,8 +182,8 @@ rpl_set_prefix(rpl_prefix_t *prefix) return 0; } /*---------------------------------------------------------------------------*/ -void -rpl_init(void) +static void +init(void) { LOG_INFO("initializing\n"); @@ -189,8 +196,55 @@ rpl_init(void) rpl_timers_init(); rpl_icmp6_init(); - rpl_ns_init(); + uip_sr_init(); } /*---------------------------------------------------------------------------*/ +static int +get_sr_node_ipaddr(uip_ipaddr_t *addr, const uip_sr_node_t *node) +{ + if(addr != NULL && node != NULL) { + memcpy(addr, &curr_instance.dag.dag_id, 8); + memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8); + return 1; + } else { + return 0; + } +} +/*---------------------------------------------------------------------------*/ +static void +neighbor_state_changed(uip_ds6_nbr_t *nbr) +{ + /* Nothing needs be done in non-storing mode */ +} +/*---------------------------------------------------------------------------*/ +static void +drop_route(uip_ds6_route_t *route) +{ + /* Do nothing. RPL-lite only supports non-storing mode, i.e. no routes */ +} +/*---------------------------------------------------------------------------*/ +const struct routing_driver rpl_lite_driver = { + "RPL Lite", + init, + rpl_dag_root_set_prefix, + rpl_dag_root_start, + rpl_dag_root_is_root, + rpl_dag_get_root_ipaddr, + get_sr_node_ipaddr, + rpl_dag_poison_and_leave, + rpl_has_joined, + rpl_is_reachable, + rpl_global_repair, + rpl_local_repair, + rpl_ext_header_remove, + rpl_ext_header_update, + rpl_ext_header_hbh_update, + rpl_ext_header_srh_update, + rpl_ext_header_srh_get_next_hop, + rpl_link_callback, + neighbor_state_changed, + drop_route, +}; +/*---------------------------------------------------------------------------*/ /** @}*/ diff --git a/os/net/rpl-lite/rpl.h b/os/net/routing/rpl-lite/rpl.h similarity index 90% rename from os/net/rpl-lite/rpl.h rename to os/net/routing/rpl-lite/rpl.h index 9557f41c3..7fb4c8718 100644 --- a/os/net/rpl-lite/rpl.h +++ b/os/net/routing/rpl-lite/rpl.h @@ -48,16 +48,15 @@ /********** Includes **********/ #include "net/ipv6/uip.h" -#include "net/rpl-lite/rpl-const.h" -#include "net/rpl-lite/rpl-conf.h" -#include "net/rpl-lite/rpl-types.h" -#include "net/rpl-lite/rpl-icmp6.h" -#include "net/rpl-lite/rpl-dag.h" -#include "net/rpl-lite/rpl-ns.h" -#include "net/rpl-lite/rpl-dag-root.h" -#include "net/rpl-lite/rpl-neighbor.h" -#include "net/rpl-lite/rpl-ext-header.h" -#include "net/rpl-lite/rpl-timers.h" +#include "net/routing/rpl-lite/rpl-const.h" +#include "net/routing/rpl-lite/rpl-conf.h" +#include "net/routing/rpl-lite/rpl-types.h" +#include "net/routing/rpl-lite/rpl-icmp6.h" +#include "net/routing/rpl-lite/rpl-dag.h" +#include "net/routing/rpl-lite/rpl-dag-root.h" +#include "net/routing/rpl-lite/rpl-neighbor.h" +#include "net/routing/rpl-lite/rpl-ext-header.h" +#include "net/routing/rpl-lite/rpl-timers.h" /********** Public symbols **********/ @@ -127,11 +126,6 @@ int rpl_is_reachable(void); */ int rpl_lollipop_greater_than(int a, int b); -/** - * Initialize RPL main module - */ -void rpl_init(void); - /** @} */ #endif /* RPL_H */ diff --git a/os/net/rpl-classic/rpl-ns.c b/os/net/rpl-classic/rpl-ns.c deleted file mode 100644 index dc2eb23e4..000000000 --- a/os/net/rpl-classic/rpl-ns.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2016, Inria. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - */ - -/** - * \file - * RPL non-storing mode specific functions. Includes support for - * source routing. - * - * \author Simon Duquennoy - */ - -#include "net/rpl-classic/rpl-conf.h" - -#include "net/ipv6/uip.h" -#include "net/ipv6/tcpip.h" -#include "net/ipv6/uip-ds6.h" -#include "net/ipv6/uip-icmp6.h" -#include "net/rpl-classic/rpl-private.h" -#include "net/rpl-classic/rpl-ns.h" -#include "lib/list.h" -#include "lib/memb.h" - -#if RPL_WITH_NON_STORING - -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" - -#include -#include - -/* Total number of nodes */ -static int num_nodes; - -/* Every known node in the network */ -LIST(nodelist); -MEMB(nodememb, rpl_ns_node_t, RPL_NS_LINK_NUM); - -/*---------------------------------------------------------------------------*/ -int -rpl_ns_num_nodes(void) -{ - return num_nodes; -} -/*---------------------------------------------------------------------------*/ -static int -node_matches_address(const rpl_dag_t *dag, const rpl_ns_node_t *node, const uip_ipaddr_t *addr) -{ - return addr != NULL - && node != NULL - && dag != NULL - && dag == node->dag - && !memcmp(addr, &node->dag->dag_id, 8) - && !memcmp(((const unsigned char *)addr) + 8, node->link_identifier, 8); -} -/*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_get_node(const rpl_dag_t *dag, const uip_ipaddr_t *addr) -{ - rpl_ns_node_t *l; - for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) { - /* Compare prefix and node identifier */ - if(node_matches_address(dag, l, addr)) { - return l; - } - } - return NULL; -} -/*---------------------------------------------------------------------------*/ -int -rpl_ns_is_node_reachable(const rpl_dag_t *dag, const uip_ipaddr_t *addr) -{ - int max_depth = RPL_NS_LINK_NUM; - rpl_ns_node_t *node = rpl_ns_get_node(dag, addr); - rpl_ns_node_t *root_node = rpl_ns_get_node(dag, dag != NULL ? &dag->dag_id : NULL); - while(node != NULL && node != root_node && max_depth > 0) { - node = node->parent; - max_depth--; - } - return node != NULL && node == root_node; -} -/*---------------------------------------------------------------------------*/ -void -rpl_ns_expire_parent(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent) -{ - rpl_ns_node_t *l = rpl_ns_get_node(dag, child); - /* Check if parent matches */ - if(l != NULL && node_matches_address(dag, l->parent, parent)) { - l->lifetime = RPL_NOPATH_REMOVAL_DELAY; - } -} -/*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_update_node(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime) -{ - rpl_ns_node_t *child_node = rpl_ns_get_node(dag, child); - rpl_ns_node_t *parent_node = rpl_ns_get_node(dag, parent); - rpl_ns_node_t *old_parent_node; - - if(parent != NULL) { - /* No node for the parent, add one with infinite lifetime */ - if(parent_node == NULL) { - parent_node = rpl_ns_update_node(dag, parent, NULL, 0xffffffff); - if(parent_node == NULL) { - return NULL; - } - } - } - - /* No node for this child, add one */ - if(child_node == NULL) { - child_node = memb_alloc(&nodememb); - /* No space left, abort */ - if(child_node == NULL) { - return NULL; - } - child_node->parent = NULL; - list_add(nodelist, child_node); - num_nodes++; - } - - /* Initialize node */ - child_node->dag = dag; - child_node->lifetime = lifetime; - memcpy(child_node->link_identifier, ((const unsigned char *)child) + 8, 8); - - /* Is the node reachable before the update? */ - if(rpl_ns_is_node_reachable(dag, child)) { - old_parent_node = child_node->parent; - /* Update node */ - child_node->parent = parent_node; - /* Has the node become unreachable? May happen if we create a loop. */ - if(!rpl_ns_is_node_reachable(dag, child)) { - /* The new parent makes the node unreachable, restore old parent. - * We will take the update next time, with chances we know more of - * the topology and the loop is gone. */ - child_node->parent = old_parent_node; - } - } else { - child_node->parent = parent_node; - } - - return child_node; -} -/*---------------------------------------------------------------------------*/ -void -rpl_ns_init(void) -{ - num_nodes = 0; - memb_init(&nodememb); - list_init(nodelist); -} -/*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_node_head(void) -{ - return list_head(nodelist); -} -/*---------------------------------------------------------------------------*/ -rpl_ns_node_t * -rpl_ns_node_next(rpl_ns_node_t *item) -{ - return list_item_next(item); -} -/*---------------------------------------------------------------------------*/ -void -rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node) -{ - if(addr != NULL && node != NULL && node->dag != NULL) { - memcpy(addr, &node->dag->dag_id, 8); - memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8); - } -} -/*---------------------------------------------------------------------------*/ -void -rpl_ns_periodic(void) -{ - rpl_ns_node_t *l; - rpl_ns_node_t *next; - - /* First pass, for all expired nodes, deallocate them iff no child points to them */ - for(l = list_head(nodelist); l != NULL; l = next) { - next = list_item_next(l); - if(l->lifetime == 0) { - rpl_ns_node_t *l2; - for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) { - if(l2->parent == l) { - break; - } - } - /* No child found, deallocate node */ - list_remove(nodelist, l); - memb_free(&nodememb, l); - num_nodes--; - } else if(l->lifetime != 0xffffffff) { - /* Decrement lifetime for all nodes with non-infinite lifetime */ - l->lifetime--; - } - } -} - -#endif /* RPL_WITH_NON_STORING */ diff --git a/os/net/rpl-classic/rpl-ns.h b/os/net/rpl-classic/rpl-ns.h deleted file mode 100644 index dcc7e584a..000000000 --- a/os/net/rpl-classic/rpl-ns.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2016, Inria. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - */ - -/** - * \file - * RPL non-storing mode specific functions. Includes support for - * source routing. - * - * \author Simon Duquennoy - */ - - -#ifndef RPL_NS_H -#define RPL_NS_H - -#include "net/rpl-classic/rpl-conf.h" - -#ifdef RPL_NS_CONF_LINK_NUM -#define RPL_NS_LINK_NUM RPL_NS_CONF_LINK_NUM -#else /* RPL_NS_CONF_LINK_NUM */ -#if RPL_WITH_NON_STORING -#define RPL_NS_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES -#else -#define RPL_NS_LINK_NUM 0 -#endif -#endif /* RPL_NS_CONF_LINK_NUM */ - -typedef struct rpl_ns_node { - struct rpl_ns_node *next; - uint32_t lifetime; - rpl_dag_t *dag; - /* Store only IPv6 link identifiers as all nodes in the DAG share the same prefix */ - unsigned char link_identifier[8]; - struct rpl_ns_node *parent; -} rpl_ns_node_t; - -int rpl_ns_num_nodes(void); -void rpl_ns_expire_parent(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent); -rpl_ns_node_t *rpl_ns_update_node(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime); -void rpl_ns_init(void); -rpl_ns_node_t *rpl_ns_node_head(void); -rpl_ns_node_t *rpl_ns_node_next(rpl_ns_node_t *item); -rpl_ns_node_t *rpl_ns_get_node(const rpl_dag_t *dag, const uip_ipaddr_t *addr); -int rpl_ns_is_node_reachable(const rpl_dag_t *dag, const uip_ipaddr_t *addr); -void rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node); -void rpl_ns_periodic(void); - -#endif /* RPL_NS_H */ diff --git a/os/services/lwm2m/lwm2m-engine.c b/os/services/lwm2m/lwm2m-engine.c index a36b4f7b1..cdd82af89 100644 --- a/os/services/lwm2m/lwm2m-engine.c +++ b/os/services/lwm2m/lwm2m-engine.c @@ -57,10 +57,9 @@ #include #include -#if UIP_CONF_IPV6_RPL -#include "rpl.h" +#ifndef LWM2M_ENGINE_CLIENT_ENDPOINT_NAME #include "net/ipv6/uip-ds6.h" -#endif /* UIP_CONF_IPV6_RPL */ +#endif /* LWM2M_ENGINE_CLIENT_ENDPOINT_NAME */ /* Log configuration */ #include "coap-log.h" diff --git a/os/services/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c b/os/services/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c index fbafa4654..723b9e847 100644 --- a/os/services/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c +++ b/os/services/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c @@ -44,10 +44,7 @@ #include "orchestra.h" #include "net/ipv6/uip-ds6-route.h" #include "net/packetbuf.h" -#include "rpl.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" /* * The body of this rule should be compiled only when "nbr_routes" is available, diff --git a/os/services/orchestra/orchestra.c b/os/services/orchestra/orchestra.c index 3ea78ca96..8b9929c03 100644 --- a/os/services/orchestra/orchestra.c +++ b/os/services/orchestra/orchestra.c @@ -40,10 +40,12 @@ #include "orchestra.h" #include "net/packetbuf.h" #include "net/ipv6/uip-icmp6.h" -#include "rpl.h" -#if UIP_CONF_IPV6_RPL_LITE == 0 -#include "rpl-private.h" -#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ +#include "net/routing/routing.h" +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#elif ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#endif #define DEBUG DEBUG_PRINT #include "net/ipv6/uip-debug.h" diff --git a/os/services/rpl-border-router/embedded/border-router-embedded.c b/os/services/rpl-border-router/embedded/border-router-embedded.c index 8ec4bd49c..884f60a97 100644 --- a/os/services/rpl-border-router/embedded/border-router-embedded.c +++ b/os/services/rpl-border-router/embedded/border-router-embedded.c @@ -36,7 +36,7 @@ */ #include "contiki.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "dev/button-sensor.h" #include "dev/slip.h" #include "rpl-border-router.h" @@ -88,11 +88,7 @@ PROCESS_THREAD(border_router_process, ev, data) PROCESS_YIELD(); if(ev == sensors_event && data == &button_sensor) { LOG_INFO("Initiating global repair\n"); -#if UIP_CONF_IPV6_RPL_LITE - rpl_global_repair(); -#else - rpl_repair_root(RPL_DEFAULT_INSTANCE); -#endif + NETSTACK_ROUTING.global_repair("Button press"); } } diff --git a/os/services/rpl-border-router/native/border-router-cmds.c b/os/services/rpl-border-router/native/border-router-cmds.c index 4a044f96e..9d0e2eb9f 100644 --- a/os/services/rpl-border-router/native/border-router-cmds.c +++ b/os/services/rpl-border-router/native/border-router-cmds.c @@ -40,7 +40,7 @@ #include "border-router.h" #include "border-router-cmds.h" #include "dev/serial-line.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "net/ipv6/uiplib.h" #include #include "shell.h" @@ -121,11 +121,7 @@ border_router_cmd_handler(const uint8_t *data, int len) case 'G': /* This is supposed to be from stdin */ printf("Performing Global Repair...\n"); -#if UIP_CONF_IPV6_RPL_LITE - rpl_global_repair(); -#else - rpl_repair_root(RPL_DEFAULT_INSTANCE); -#endif + NETSTACK_ROUTING.global_repair("Command"); return 1; case 'C': { /* send on a set-param thing! */ diff --git a/os/services/rpl-border-router/native/border-router-native.c b/os/services/rpl-border-router/native/border-router-native.c index 36516429d..3da0ef000 100644 --- a/os/services/rpl-border-router/native/border-router-native.c +++ b/os/services/rpl-border-router/native/border-router-native.c @@ -40,7 +40,8 @@ #include "contiki.h" #include "contiki-net.h" -#include "rpl.h" + +#include "net/routing/routing.h" #include "rpl-border-router.h" #include "cmd.h" #include "border-router.h" @@ -81,7 +82,7 @@ border_router_set_mac(const uint8_t *data) add them back again - a bit messy... ?*/ PROCESS_CONTEXT_BEGIN(&tcpip_process); uip_ds6_init(); - rpl_init(); + NETSTACK_ROUTING.init(); PROCESS_CONTEXT_END(&tcpip_process); mac_set = 1; diff --git a/os/services/rpl-border-router/rpl-border-router.c b/os/services/rpl-border-router/rpl-border-router.c index 59426d7f9..f07a41fdd 100644 --- a/os/services/rpl-border-router/rpl-border-router.c +++ b/os/services/rpl-border-router/rpl-border-router.c @@ -31,8 +31,8 @@ */ #include "contiki.h" +#include "net/routing/routing.h" #include "rpl-border-router.h" -#include "rpl-dag-root.h" /* Log configuration */ #include "sys/log.h" @@ -64,8 +64,8 @@ void set_prefix_64(uip_ipaddr_t *prefix_64) { prefix_set = 1; - rpl_dag_root_init(prefix_64, NULL); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_set_prefix(prefix_64, NULL); + NETSTACK_ROUTING.root_start(); } /*---------------------------------------------------------------------------*/ void diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 09edda827..5e19a0dc8 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -58,14 +58,16 @@ #include "net/mac/tsch/tsch-log.h" #include "net/mac/tsch/tsch-private.h" #endif /* MAC_CONF_WITH_TSCH */ -#if UIP_CONF_IPV6_RPL_LITE -#include "net/rpl-lite/rpl.h" -#elif UIP_CONF_IPV6_RPL_CLASSIC -#include "net/rpl-classic/rpl.h" -#include "net/rpl-classic/rpl-private.h" -#endif +#include "net/routing/routing.h" #include "net/mac/llsec802154.h" +/* For RPL-specific commands */ +#if ROUTING_CONF_RPL_LITE +#include "net/routing/rpl-lite/rpl.h" +#elif ROUTING_CONF_RPL_CLASSIC +#include "net/routing/rpl-classic/rpl.h" +#endif + #include #define PING_TIMEOUT (5 * CLOCK_SECOND) @@ -98,7 +100,7 @@ ds6_nbr_state_to_str(uint8_t state) return "Unknown"; } } -#if UIP_CONF_IPV6_RPL_LITE +#if ROUTING_CONF_RPL_LITE /*---------------------------------------------------------------------------*/ static const char * rpl_state_to_str(enum rpl_dag_state state) @@ -146,7 +148,51 @@ rpl_ocp_to_str(int ocp) return "Unknown"; } } -#endif /* UIP_CONF_IPV6_RPL_LITE */ +/*---------------------------------------------------------------------------*/ +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 /* ROUTING_CONF_RPL_LITE */ /*---------------------------------------------------------------------------*/ static void echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen) @@ -288,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)) @@ -325,19 +370,19 @@ 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"); - rpl_dag_root_init(&prefix, NULL); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_set_prefix(&prefix, NULL); + NETSTACK_ROUTING.root_start(); } else { 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"); } @@ -347,56 +392,12 @@ 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); - SHELL_OUTPUT(output, "Triggering RPL global repair\n") - rpl_global_repair(); + SHELL_OUTPUT(output, "Triggering routing global repair\n") + NETSTACK_ROUTING.global_repair("Shell"); PT_END(pt); } @@ -406,12 +407,11 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar { PT_BEGIN(pt); - SHELL_OUTPUT(output, "Triggering RPL local repair\n"); - rpl_local_repair("Shell"); + SHELL_OUTPUT(output, "Triggering routing local repair\n"); + NETSTACK_ROUTING.local_repair("Shell"); PT_END(pt); } -#endif /* UIP_CONF_IPV6_RPL_LITE */ /*---------------------------------------------------------------------------*/ static PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args)) @@ -551,12 +551,6 @@ static PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args)) { uip_ds6_defrt_t *default_route; -#if RPL_WITH_NON_STORING - rpl_ns_node_t *link; -#endif /* RPL_WITH_NON_STORING */ -#if RPL_WITH_STORING - uip_ds6_route_t *route; -#endif /* RPL_WITH_STORING */ PT_BEGIN(pt); @@ -575,16 +569,17 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args)) SHELL_OUTPUT(output, "-- None\n"); } -#if RPL_WITH_NON_STORING - if(rpl_ns_num_nodes() > 0) { +#if UIP_CONF_IPV6_RPL + if(uip_sr_num_nodes() > 0) { + uip_sr_node_t *link; /* Our routing links */ - SHELL_OUTPUT(output, "Routing links (%u in total):\n", rpl_ns_num_nodes()); - link = rpl_ns_node_head(); + SHELL_OUTPUT(output, "Routing links (%u in total):\n", uip_sr_num_nodes()); + link = uip_sr_node_head(); while(link != NULL) { uip_ipaddr_t child_ipaddr; uip_ipaddr_t parent_ipaddr; - rpl_ns_get_node_global_addr(&child_ipaddr, link); - rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent); + NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link); + NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent); SHELL_OUTPUT(output, "-- "); shell_output_6addr(output, &child_ipaddr); if(link->parent == NULL) { @@ -594,20 +589,21 @@ 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 != UIP_SR_INFINITE_LIFETIME) { SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)link->lifetime); } else { SHELL_OUTPUT(output, " (lifetime: infinite)\n"); } - link = rpl_ns_node_next(link); + link = uip_sr_node_next(link); } } else { SHELL_OUTPUT(output, "No routing links\n"); } -#endif /* RPL_WITH_NON_STORING */ +#endif /* UIP_CONF_IPV6_RPL */ -#if RPL_WITH_STORING +#if (UIP_MAX_ROUTES != 0) if(uip_ds6_route_num_routes() > 0) { + uip_ds6_route_t *route; /* Our routing entries */ SHELL_OUTPUT(output, "Routing entries (%u in total):\n", uip_ds6_route_num_routes()); route = uip_ds6_route_head(); @@ -616,7 +612,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"); @@ -626,7 +622,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); } @@ -721,12 +717,14 @@ 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_LITE */ +#endif /* UIP_CONF_IPV6_RPL */ +#if ROUTING_CONF_RPL_LITE + { "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" }, +#endif /* ROUTING_CONF_RPL_LITE */ { "routes", cmd_routes, "'> routes': Shows the route entries" }, #if MAC_CONF_WITH_TSCH { "tsch-set-coordinator", cmd_tsch_set_coordinator, "'> tsch-set-coordinator 0/1 [0/1]': Sets node as coordinator (1) or not (0). Second, optional parameter: enable (1) or disable (0) security." }, diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index 748837c50..d043c9d6e 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -4,6 +4,7 @@ TOOLSDIR=../../tools EXAMPLES = \ hello-world/native \ hello-world/native:MAKE_NET=MAKE_NET_NULLNET \ +hello-world/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ hello-world/sky \ storage/eeprom-test/native \ multicast/sky \ diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index 854d138b1..4d20fe5d8 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -28,6 +28,7 @@ platform-specific/cc2538-common/crypto/cc2538dk \ platform-specific/cc2538-common/pka/cc2538dk \ hello-world/cc2538dk \ rpl-border-router/cc2538dk \ +rpl-border-router/cc2538dk:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ hello-world/nrf52dk \ platform-specific/nrf52dk/coap-demo/nrf52dk:coap-server \ platform-specific/nrf52dk/coap-demo/nrf52dk:coap-client:SERVER_IPV6_EP=ffff \ diff --git a/tests/07-simulation-base/code-ipv6/sender/unicast-sender.c b/tests/07-simulation-base/code-ipv6/sender/unicast-sender.c index 929e0d584..4e2e664b3 100644 --- a/tests/07-simulation-base/code-ipv6/sender/unicast-sender.c +++ b/tests/07-simulation-base/code-ipv6/sender/unicast-sender.c @@ -1,8 +1,7 @@ #include "contiki.h" #include "contiki-lib.h" #include "contiki-net.h" -#include "rpl.h" -#include "rpl-dag-root.h" +#include "net/routing/routing.h" #include @@ -41,7 +40,7 @@ PROCESS_THREAD(udp_process, ev, data) PROCESS_BEGIN(); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); simple_udp_register(&broadcast_connection, UDP_PORT, NULL, UDP_PORT, diff --git a/tests/07-simulation-base/code-slip-radio/wait-dag.c b/tests/07-simulation-base/code-slip-radio/wait-dag.c index 83e3d28f7..a059661b4 100644 --- a/tests/07-simulation-base/code-slip-radio/wait-dag.c +++ b/tests/07-simulation-base/code-slip-radio/wait-dag.c @@ -33,7 +33,7 @@ #include "contiki.h" #include "contiki-lib.h" #include "contiki-net.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "net/ipv6/uip.h" #include @@ -49,8 +49,7 @@ AUTOSTART_PROCESSES(&wait_for_dag); static void timeout_handler(void) { - rpl_dag_t *dag = rpl_get_any_dag(); - if (dag != NULL) { + if(NETSTACK_ROUTING.node_has_joined()) { PRINTF("DAG Found\n"); } } @@ -67,7 +66,7 @@ PROCESS_THREAD(wait_for_dag, ev, data) if(etimer_expired(&et)) { timeout_handler(); etimer_restart(&et); - } + } } PROCESS_END(); } diff --git a/tests/14-rpl-lite/code/receiver-node.c b/tests/14-rpl-lite/code/receiver-node.c index 352f23cb5..b5265d3f7 100644 --- a/tests/14-rpl-lite/code/receiver-node.c +++ b/tests/14-rpl-lite/code/receiver-node.c @@ -38,7 +38,7 @@ #include "simple-udp.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "dev/leds.h" #include diff --git a/tests/14-rpl-lite/code/root-node.c b/tests/14-rpl-lite/code/root-node.c index ef3c982ee..7c9fc8c99 100644 --- a/tests/14-rpl-lite/code/root-node.c +++ b/tests/14-rpl-lite/code/root-node.c @@ -38,8 +38,7 @@ #include "simple-udp.h" -#include "rpl.h" -#include "rpl-dag-root.h" +#include "net/routing/routing.h" #include #include @@ -75,7 +74,7 @@ PROCESS_THREAD(unicast_receiver_process, ev, data) { PROCESS_BEGIN(); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); diff --git a/tests/15-rpl-classic/05-rpl-up-and-down-routes-non-storing.csc b/tests/15-rpl-classic/05-rpl-up-and-down-routes-non-storing.csc new file mode 100644 index 000000000..aa412586b --- /dev/null +++ b/tests/15-rpl-classic/05-rpl-up-and-down-routes-non-storing.csc @@ -0,0 +1,341 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/collect-view + [APPS_DIR]/powertracker + + My simulation + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 50.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype743 + Sender + [CONFIG_DIR]/code/sender-node.c + make clean TARGET=cooja +make -j sender-node.cooja TARGET=cooja DEFINES=RPL_CONF_MOP=RPL_MOP_NON_STORING + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype452 + RPL root + [CONFIG_DIR]/code/root-node.c + make clean TARGET=cooja +make -j root-node.cooja TARGET=cooja DEFINES=RPL_CONF_MOP=RPL_MOP_NON_STORING + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype782 + Receiver + [CONFIG_DIR]/code/receiver-node.c + make clean TARGET=cooja +make -j receiver-node.cooja TARGET=cooja DEFINES=RPL_CONF_MOP=RPL_MOP_NON_STORING + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + -22.5728586847096 + 123.9358664968653 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype782 + + + + org.contikios.cooja.interfaces.Position + 116.13379149678028 + 88.36698920455684 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype743 + + + + org.contikios.cooja.interfaces.Position + -1.39303771455413 + 100.21446701029119 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 4 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype782 + + + + org.contikios.cooja.interfaces.Position + 95.25095618820441 + 63.14998053005015 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 5 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype782 + + + + org.contikios.cooja.interfaces.Position + 66.09378990830604 + 38.32698761608261 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 6 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype782 + + + + org.contikios.cooja.interfaces.Position + 29.05630841762433 + 30.840688165838436 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 7 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype782 + + + + org.contikios.cooja.interfaces.Position + 10.931583432822638 + 69.848248459216 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 8 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype782 + + + + org.contikios.cooja.interfaces.Position + 0.0 + 0.0 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + mtype452 + + + + org.contikios.cooja.plugins.SimControl + 280 + 1 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.GridVisualizerSkin + org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin + 2.5379695437350276 0.0 0.0 2.5379695437350276 75.2726010197627 15.727272727272757 + + 400 + 2 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + + + 1184 + 3 + 240 + 402 + 162 + + + org.contikios.cooja.plugins.Notes + + Enter notes here + true + + 904 + 4 + 160 + 680 + 0 + + + org.contikios.cooja.plugins.ScriptRunner + + + true + + 962 + 0 + 596 + 603 + 43 + + diff --git a/tests/15-rpl-classic/code/receiver-node.c b/tests/15-rpl-classic/code/receiver-node.c index 770f50f77..20bf165f8 100644 --- a/tests/15-rpl-classic/code/receiver-node.c +++ b/tests/15-rpl-classic/code/receiver-node.c @@ -38,7 +38,7 @@ #include "simple-udp.h" -#include "rpl.h" +#include "net/routing/routing.h" #include "dev/leds.h" #include @@ -91,6 +91,7 @@ set_global_address(void) return &ipaddr; } /*---------------------------------------------------------------------------*/ +#if RPL_WITH_STORING uint8_t should_blink = 1; static void route_callback(int event, uip_ipaddr_t *route, uip_ipaddr_t *ipaddr, int num_routes) @@ -101,17 +102,22 @@ route_callback(int event, uip_ipaddr_t *route, uip_ipaddr_t *ipaddr, int num_rou should_blink = 1; } } +#endif /* #if RPL_WITH_STORING */ /*---------------------------------------------------------------------------*/ PROCESS_THREAD(receiver_node_process, ev, data) { static struct etimer et; +#if RPL_WITH_STORING static struct uip_ds6_notification n; +#endif /* #if RPL_WITH_STORING */ PROCESS_BEGIN(); set_global_address(); +#if RPL_WITH_STORING uip_ds6_notification_add(&n, route_callback); +#endif /* #if RPL_WITH_STORING */ simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); @@ -120,12 +126,14 @@ PROCESS_THREAD(receiver_node_process, ev, data) while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); +#if RPL_WITH_STORING if(should_blink) { leds_on(LEDS_ALL); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); leds_off(LEDS_ALL); } +#endif /* #if RPL_WITH_STORING */ } PROCESS_END(); } diff --git a/tests/15-rpl-classic/code/root-node.c b/tests/15-rpl-classic/code/root-node.c index ef3c982ee..e25b2872f 100644 --- a/tests/15-rpl-classic/code/root-node.c +++ b/tests/15-rpl-classic/code/root-node.c @@ -35,12 +35,9 @@ #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip-debug.h" - +#include "net/routing/routing.h" #include "simple-udp.h" -#include "rpl.h" -#include "rpl-dag-root.h" - #include #include @@ -75,7 +72,7 @@ PROCESS_THREAD(unicast_receiver_process, ev, data) { PROCESS_BEGIN(); - rpl_dag_root_init_dag_immediately(); + NETSTACK_ROUTING.root_start(); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); diff --git a/tools/doxygen/Doxyfile b/tools/doxygen/Doxyfile index 2c2bf5e4a..a7dc79fab 100644 --- a/tools/doxygen/Doxyfile +++ b/tools/doxygen/Doxyfile @@ -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 \