Merge pull request #224 from simonduq/contrib/routing-api

RPL as just a module: generic routing API
This commit is contained in:
Simon Duquennoy 2018-02-14 18:10:02 +01:00 committed by GitHub
commit 9e15ace32c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
119 changed files with 1562 additions and 1733 deletions

View File

@ -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)}}

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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: ");

View File

@ -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"

View File

@ -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();

View File

@ -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;

View File

@ -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"

View File

@ -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 <string.h>
#include <stdio.h>

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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 <stdio.h>
@ -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");

View File

@ -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

View File

@ -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");

View File

@ -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

View File

@ -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");

View File

@ -6,6 +6,6 @@ TARGET ?= jn516x
CONTIKI=../../../../..
MAKE_MAC = MAKE_MAC_TSCH
MODULES_REL += .. ../tools
MODULES_REL += ..
include $(CONTIKI)/Makefile.include

View File

@ -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();
}

View File

@ -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 <simonduq@sics.se>
*/
#include "contiki.h"
#include "contiki-net.h"
#include "net/ipv6/uip.h"
#include "rpl.h"
#include "rpl-dag-root.h"
#include <string.h>
#include <stdio.h>
#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();
}

View File

@ -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 <simonduq@sics.se>
*/
void rpl_tools_init(uip_ipaddr_t *br_prefix);
void print_network_status(void);

View File

@ -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

View File

@ -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();

View File

@ -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 <simonduq@sics.se>
*/
#include "contiki.h"
#include "contiki-net.h"
#include "net/ipv6/uip.h"
#include "rpl.h"
#include "rpl-dag-root.h"
#include <string.h>
#include <stdio.h>
#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();
}

View File

@ -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 <simonduq@sics.se>
*/
void rpl_tools_init(uip_ipaddr_t *br_prefix);
void print_network_status(void);

View File

@ -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

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <AppHardwareApi.h>
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");

View File

@ -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

View File

@ -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 <stdio.h>
#include <stdlib.h>
@ -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");

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
all: mqtt-demo
MAKE_ROUTING = MAKE_ROUTING_NONE
MAKE_ROUTING = MAKE_ROUTING_NULLROUTING
MODULES += os/net/app-layer/mqtt

View File

@ -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

View File

@ -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 <stdio.h>
/*---------------------------------------------------------------------------*/
static struct http_socket s;

View File

@ -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 <stdio.h>
/*---------------------------------------------------------------------------*/

View File

@ -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(" <i>(%u.%02u sec)</i>", numticks / CLOCK_SECOND,
ADD(" <i>(%u.%02u sec)</i>", 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) {

View File

@ -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 <stdio.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
static const char *TOP = "<html><head><title>Contiki-NG</title></head><body>\n";
static const char *BOTTOM = "</body></html>\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 = "<html>\n <head>\n <title>Contiki-NG</title>\n </head>\n<body>\n";
static const char *BOTTOM = "\n</body>\n</html>\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<pre>");
ADD(" Neighbors\n <ul>\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(" <li>");
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("</li>\n");
SEND(&s->sout);
}
ADD("</pre>Routes<pre>\n");
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
ADD(" </ul>\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("<a href=http://[");
ipaddr_add(&r->ipaddr);
ADD("]/status.shtml>");
ipaddr_add(&r->ipaddr);
ADD("</a>");
#else
ipaddr_add(&r->ipaddr);
#endif
#else
#if WEBSERVER_CONF_ROUTE_LINKS
ADD("<a href=http://[");
ipaddr_add(&r->ipaddr);
ADD("]/status.shtml>");
SEND_STRING(&s->sout, buf);
blen = 0;
ipaddr_add(&r->ipaddr);
ADD("</a>");
#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 <ul>\n");
SEND(&s->sout);
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
ADD(" <li>");
ipaddr_add(&r->ipaddr);
ADD("/%u (via ", r->length);
ipaddr_add(uip_ds6_route_nexthop(r));
ADD(") %lus", (unsigned long)r->state.lifetime);
ADD("</li>\n");
SEND(&s->sout);
}
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
ADD(" </ul>\n");
SEND(&s->sout);
}
ADD("</pre>");
#endif /* UIP_MAX_ROUTES != 0 */
#if RPL_WITH_NON_STORING
ADD("Links<pre>\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 <ul>\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("<a href=http://[");
ipaddr_add(&child_ipaddr);
ADD("]/status.shtml>");
ipaddr_add(&child_ipaddr);
ADD("</a>");
#else
ipaddr_add(&child_ipaddr);
#endif
#else
#if WEBSERVER_CONF_ROUTE_LINKS
ADD("<a href=http://[");
ipaddr_add(&child_ipaddr);
ADD("]/status.shtml>");
SEND_STRING(&s->sout, buf);
blen = 0;
ipaddr_add(&child_ipaddr);
ADD("</a>");
#else
ipaddr_add(&child_ipaddr);
#endif
#endif
ADD(" <li>");
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("</li>\n");
SEND(&s->sout);
}
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
}
ADD(" </ul>");
SEND(&s->sout);
}
ADD("</pre>");
#endif /* RPL_WITH_NON_STORING */
#endif /* UIP_SR_LINK_NUM != 0 */
#if WEBSERVER_CONF_FILESTATS
static uint16_t numtimes;
ADD("<br><i>This page sent %u times</i>", ++numtimes);
#endif
#if WEBSERVER_CONF_LOADTIME
numticks = clock_time() - numticks + 1;
ADD(" <i>(%u.%02u sec)</i>", numticks / CLOCK_SECOND, (100 * (numticks % CLOCK_SECOND)) / CLOCK_SECOND));
#endif
SEND_STRING(&s->sout, buf);
SEND_STRING(&s->sout, BOTTOM);
PSOCK_END(&s->sout);

View File

@ -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 */

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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 <string.h>
extern uint16_t uip_slen;

View File

@ -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 <string.h>
#define DEBUG DEBUG_NONE

View File

@ -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);

View File

@ -38,21 +38,15 @@
* \author Julien Abeille <jabeille@cisco.com> (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 <string.h>
@ -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();

View File

@ -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:

View File

@ -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 */

View File

@ -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);

View File

@ -47,6 +47,7 @@
#include <stddef.h>
#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"

View File

@ -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;

View File

@ -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);

View File

@ -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 <simon.duquennoy@inria.fr>
*/
#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);

View File

@ -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 <simon.duquennoy@inria.fr>
*/
#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 */

View File

@ -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");

View File

@ -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);

View File

@ -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 *********/

View File

@ -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"

View File

@ -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;

View File

@ -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 <simon.duquennoy@ri.se>
*/
#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,
};
/*---------------------------------------------------------------------------*/
/** @}*/

177
os/net/routing/routing.h Normal file
View File

@ -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 <simon.duquennoy@ri.se>
*/
#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_ */

View File

@ -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 <string.h>
@ -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)
{

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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;
}

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"
/*---------------------------------------------------------------------------*/

View File

@ -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();

View File

@ -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,
};
/*---------------------------------------------------------------------------*/
/** @}*/

View File

@ -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.

View File

@ -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

View File

@ -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)
{

View File

@ -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

View File

@ -42,7 +42,8 @@
* Contributors: George Oikonomou <oikonomou@users.sourceforge.net> (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;
}

View File

@ -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

View File

@ -42,8 +42,10 @@
* Nicolas Tsiftes <nvt@sics.se>,
* Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#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 */

View File

@ -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
*/

View File

@ -44,7 +44,7 @@
* George Oikonomou <oikonomou@users.sourceforge.net> (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"

View File

@ -44,6 +44,7 @@
#include "uip.h"
#include "uip-ds6.h"
#include "uip-ds6-nbr.h"
/********** Data structures **********/

View File

@ -45,7 +45,7 @@
* Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#include "net/rpl-lite/rpl.h"
#include "net/routing/rpl-lite/rpl.h"
#include "net/nbr-table.h"
#include "net/link-stats.h"

View File

@ -42,7 +42,7 @@
*
*/
#include "net/rpl-lite/rpl.h"
#include "net/routing/rpl-lite/rpl.h"
#include "net/nbr-table.h"
/* Log configuration */

View File

@ -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"

View File

@ -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"

View File

@ -41,7 +41,7 @@
* Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#include "net/rpl-lite/rpl.h"
#include "net/routing/rpl-lite/rpl.h"
#include "net/nbr-table.h"
#include "net/link-stats.h"

View File

@ -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 ||

View File

@ -47,7 +47,7 @@
/********** Includes **********/
#include "net/rpl-lite/rpl.h"
#include "net/routing/rpl-lite/rpl.h"
/********** Public functions **********/

View File

@ -41,7 +41,8 @@
* Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#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,
};
/*---------------------------------------------------------------------------*/
/** @}*/

View File

@ -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 */

View File

@ -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 <simon.duquennoy@inria.fr>
*/
#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 <limits.h>
#include <string.h>
/* 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 */

Some files were not shown because too many files have changed in this diff Show More