nes-proj/examples/6tisch/tsch-stats/node.c

94 lines
3.1 KiB
C
Raw Normal View History

2018-08-31 14:11:25 +00:00
/*
* Copyright (c) 2015, SICS Swedish ICT.
2017-11-27 17:34:43 +00:00
* Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk
2018-08-31 14:11:25 +00:00
* 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
* A RPL+TSCH node.
*
* \author Simon Duquennoy <simonduq@sics.se>
* Atis Elsts <atis.elsts@bristol.ac.uk>
*/
#include "contiki.h"
2017-11-27 17:34:43 +00:00
#include "sys/node-id.h"
2018-08-31 14:11:25 +00:00
#include "sys/log.h"
#include "net/ipv6/uip-ds6-route.h"
2017-11-27 17:34:43 +00:00
#include "net/ipv6/uip-sr.h"
2018-08-31 14:11:25 +00:00
#include "net/mac/tsch/tsch.h"
2017-11-27 17:34:43 +00:00
#include "net/routing/routing.h"
2018-08-31 14:11:25 +00:00
#define DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h"
/*---------------------------------------------------------------------------*/
PROCESS(node_process, "RPL Node");
AUTOSTART_PROCESSES(&node_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process, ev, data)
{
int is_coordinator;
PROCESS_BEGIN();
2017-11-27 17:34:43 +00:00
is_coordinator = 0;
#if CONTIKI_TARGET_COOJA
2018-08-31 14:11:25 +00:00
is_coordinator = (node_id == 1);
2017-11-27 17:34:43 +00:00
#endif
2018-08-31 14:11:25 +00:00
if(is_coordinator) {
2017-11-27 17:34:43 +00:00
NETSTACK_ROUTING.root_start();
2018-08-31 14:11:25 +00:00
}
NETSTACK_MAC.on();
#if WITH_PERIODIC_ROUTES_PRINT
{
static struct etimer et;
/* Print out routing tables every minute */
etimer_set(&et, CLOCK_SECOND * 60);
while(1) {
/* Used for non-regression testing */
2017-11-27 17:34:43 +00:00
#if (UIP_MAX_ROUTES != 0)
2018-08-31 14:11:25 +00:00
PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes());
#endif
2017-11-27 17:34:43 +00:00
#if (UIP_SR_LINK_NUM != 0)
PRINTF("Routing links: %u\n", uip_sr_num_nodes());
2018-08-31 14:11:25 +00:00
#endif
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
}
#endif /* WITH_PERIODIC_ROUTES_PRINT */
PROCESS_END();
}
/*---------------------------------------------------------------------------*/