RPL border router: move more shared functionality to common directory

This commit is contained in:
Simon Duquennoy 2017-11-01 16:02:41 +01:00
parent 2d2b60fe5b
commit 50f060477c
6 changed files with 133 additions and 96 deletions

View File

@ -15,7 +15,7 @@ endif
include $(SOURCES_DIR)/Makefile
PROJECTDIRS += $(SOURCES_DIR)
PROJECT_SOURCEFILES += httpd-simple.c webserver.c
PROJECT_SOURCEFILES += httpd-simple.c webserver.c border-router-common.c
CFLAGS += -DPROJECT_CONF_PATH=\"$(SOURCES_DIR)/project-conf.h\"
include $(CONTIKI)/Makefile.include

View File

@ -0,0 +1,71 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "border-router-common.h"
#include "rpl-dag-root.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "BR"
#define LOG_LEVEL LOG_LEVEL_INFO
uip_ipaddr_t prefix;
uint8_t prefix_set;
/*---------------------------------------------------------------------------*/
void
print_local_addresses(void)
{
int i;
uint8_t state;
LOG_INFO("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)) {
LOG_INFO(" ");
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
LOG_INFO_("\n");
}
}
}
/*---------------------------------------------------------------------------*/
void
set_prefix_64(uip_ipaddr_t *prefix_64)
{
memcpy(&prefix, prefix_64, 16);
prefix_set = 1;
rpl_dag_root_init(prefix_64, NULL);
rpl_dag_root_init_dag_immediately();
}

View File

@ -0,0 +1,41 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6.h"
extern uip_ipaddr_t prefix;
extern uint8_t prefix_set;
void print_local_addresses(void);
void set_prefix_64(uip_ipaddr_t *prefix_64);

View File

@ -36,71 +36,21 @@
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "rpl.h"
#if UIP_CONF_IPV6_RPL_LITE == 0
#include "rpl-private.h"
#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */
#include "rpl-dag-root.h"
#if RPL_WITH_NON_STORING
#include "rpl-ns.h"
#endif /* RPL_WITH_NON_STORING */
#include "net/netstack.h"
#include "dev/button-sensor.h"
#include "dev/slip.h"
#include "net/ipv6/uip-debug.h"
#include "border-router-common.h"
/*---------------------------------------------------------------------------*/
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "BR"
#define LOG_LEVEL LOG_LEVEL_INFO
/*---------------------------------------------------------------------------*/
static uip_ipaddr_t prefix;
static uint8_t prefix_set;
void request_prefix(void);
/*---------------------------------------------------------------------------*/
PROCESS(border_router_process, "Border router process");
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
LOG_INFO("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)) {
LOG_INFO(" ");
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
LOG_INFO_("\n");
}
}
}
/*---------------------------------------------------------------------------*/
void
request_prefix(void)
{
/* mess up uip_buf with a dirty request... */
uip_buf[0] = '?';
uip_buf[1] = 'P';
uip_len = 2;
slip_send();
uip_clear_buf();
}
/*---------------------------------------------------------------------------*/
void
set_prefix_64(uip_ipaddr_t *prefix_64)
{
memcpy(&prefix, prefix_64, 16);
prefix_set = 1;
rpl_dag_root_init(prefix_64, NULL);
rpl_dag_root_init_dag_immediately();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
@ -132,9 +82,7 @@ PROCESS_THREAD(border_router_process, ev, data)
NETSTACK_MAC.on();
#if DEBUG || 1
print_local_addresses();
#endif
while(1) {
PROCESS_YIELD();

View File

@ -53,6 +53,18 @@
void set_prefix_64(uip_ipaddr_t *);
static uip_ipaddr_t last_sender;
/*---------------------------------------------------------------------------*/
void
request_prefix(void)
{
/* mess up uip_buf with a dirty request... */
uip_buf[0] = '?';
uip_buf[1] = 'P';
uip_len = 2;
slip_send();
uip_clear_buf();
}
/*---------------------------------------------------------------------------*/
static void
slip_input_callback(void)

View File

@ -39,15 +39,9 @@
*/
#include "contiki.h"
#include "contiki-lib.h"
#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/netstack.h"
#include "dev/slip.h"
#include "border-router-common.h"
#include "cmd.h"
#include "border-router.h"
#include "border-router-cmds.h"
@ -55,13 +49,13 @@
#define DEBUG DEBUG_FULL
#include "net/ipv6/uip-debug.h"
#include <stdlib.h>
#define MAX_SENSORS 4
extern long slip_sent;
extern long slip_received;
static uip_ipaddr_t prefix;
static uint8_t prefix_set;
static uint8_t mac_set;
static uint8_t sensor_count = 0;
@ -77,24 +71,6 @@ CMD_HANDLERS(border_router_cmd_handler);
PROCESS(border_router_process, "Border router process");
/*---------------------------------------------------------------------------*/
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(" %p: =>", &uip_ds6_if.addr_list[i]);
uip_debug_ipaddr_print(&(uip_ds6_if.addr_list[i]).ipaddr);
PRINTA("\n");
}
}
}
/*---------------------------------------------------------------------------*/
static void
request_mac(void)
@ -150,15 +126,6 @@ border_router_set_sensors(const char *data, int len)
sensor_count = sc;
}
/*---------------------------------------------------------------------------*/
static void
set_prefix_64(uip_ipaddr_t *prefix_64)
{
memcpy(&prefix, prefix_64, 16);
prefix_set = 1;
rpl_dag_root_init(prefix_64, NULL);
rpl_dag_root_init_dag_immediately();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
static struct etimer et;
@ -197,9 +164,7 @@ PROCESS_THREAD(border_router_process, ev, data)
}
}
#if DEBUG
print_local_addresses();
#endif
while(1) {
etimer_set(&et, CLOCK_SECOND * 2);