Contiki-NG
Loading...
Searching...
No Matches
tsch-rpl.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, SICS Swedish ICT.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31/**
32 * \file
33 * Interaction between TSCH and RPL
34 *
35 * \author Simon Duquennoy <simonduq@sics.se>
36 */
37
38/**
39 * \addtogroup tsch
40 * @{
41*/
42
43#include "contiki.h"
44
45#if UIP_CONF_IPV6_RPL
46
47#include "net/routing/routing.h"
48#include "net/mac/tsch/tsch.h"
49#include "net/link-stats.h"
50
51#if ROUTING_CONF_RPL_LITE
52#include "net/routing/rpl-lite/rpl.h"
53#elif ROUTING_CONF_RPL_CLASSIC
54#include "net/routing/rpl-classic/rpl.h"
55#include "net/routing/rpl-classic/rpl-private.h"
56#endif
57
58/* Log configuration */
59#include "sys/log.h"
60#define LOG_MODULE "TSCH RPL"
61#define LOG_LEVEL LOG_LEVEL_MAC
62
63/*---------------------------------------------------------------------------*/
64/* To use, set #define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent */
65void
66tsch_rpl_callback_ka_sent(int status, int transmissions)
67{
68 NETSTACK_ROUTING.link_callback(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions);
69}
70/*---------------------------------------------------------------------------*/
71/* To use, set #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network */
72void
74{
75}
76/*---------------------------------------------------------------------------*/
77/* Upon leaving a TSCH network, perform a local repair
78 * (cleanup neighbor state, reset Trickle timer etc)
79 * To use, set #define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network */
80void
82{
83 /* Forget past link statistics. If we are leaving a TSCH
84 network, there are changes we've been out of sync in the recent past, and
85 as a result have irrelevant link statistices. */
86 link_stats_reset();
87 /* RPL local repair */
88 NETSTACK_ROUTING.local_repair("TSCH leaving");
89}
90/*---------------------------------------------------------------------------*/
91/* Set TSCH EB period based on current RPL DIO period.
92 * To use, set #define RPL_CALLBACK_NEW_DIO_INTERVAL tsch_rpl_callback_new_dio_interval */
93void
94tsch_rpl_callback_new_dio_interval(clock_time_t dio_interval)
95{
96 /* Transmit EBs only if we have a valid rank as per 6TiSCH minimal */
97 rpl_dag_t *dag;
98 rpl_rank_t root_rank;
99 rpl_rank_t dag_rank;
100#if ROUTING_CONF_RPL_LITE
101 dag = &curr_instance.dag;
102 root_rank = ROOT_RANK;
103 dag_rank = DAG_RANK(dag->rank);
104#else
105 rpl_instance_t *instance;
106 dag = rpl_get_any_dag();
107 instance = dag != NULL ? dag->instance : NULL;
108 root_rank = ROOT_RANK(instance);
109 dag_rank = DAG_RANK(dag->rank, instance);
110#endif
111
112 if(dag != NULL && dag->rank != RPL_INFINITE_RANK) {
113 /* If we are root set TSCH as coordinator */
114 if(dag->rank == root_rank) {
116 }
117 /* Set EB period */
118 tsch_set_eb_period(dio_interval);
119 /* Set join priority based on RPL rank */
120 tsch_set_join_priority(dag_rank - 1);
121 } else {
122 tsch_set_eb_period(TSCH_EB_PERIOD);
123 }
124}
125/*---------------------------------------------------------------------------*/
126/* Set TSCH time source based on current RPL preferred parent.
127 * To use, set #define RPL_CALLBACK_PARENT_SWITCH tsch_rpl_callback_parent_switch */
128void
129tsch_rpl_callback_parent_switch(rpl_parent_t *old, rpl_parent_t *new)
130{
131 /* Map the TSCH time source on the RPL preferred parent */
132 if(tsch_is_associated == 1) {
134 (const linkaddr_t *)uip_ds6_nbr_lladdr_from_ipaddr(
135 rpl_parent_get_ipaddr(new)));
136 }
137}
138/*---------------------------------------------------------------------------*/
139/* Check RPL has joined DODAG.
140 * To use, set #define TSCH_RPL_CHECK_DODAG_JOINED tsch_rpl_check_dodag_joined */
141int
143{
144 return NETSTACK_ROUTING.node_has_joined();
145}
146#endif /* UIP_CONF_IPV6_RPL */
147/** @} */
void tsch_rpl_callback_parent_switch(rpl_parent_t *old, rpl_parent_t *new)
Set TSCH time source based on current RPL preferred parent.
void tsch_rpl_callback_joining_network(void)
Let RPL know that TSCH joined a new network.
void tsch_rpl_callback_leaving_network(void)
Let RPL know that TSCH joined a new network.
int tsch_queue_update_time_source(const linkaddr_t *new_addr)
Update TSCH time source.
Definition tsch-queue.c:142
void tsch_rpl_callback_new_dio_interval(clock_time_t dio_interval)
Set TSCH EB period based on current RPL DIO period.
void tsch_rpl_callback_ka_sent(int status, int transmissions)
Report statiscs from KA packet sent in RPL.
void tsch_set_eb_period(uint32_t period)
Set the period at wich TSCH enhanced beacons (EBs) are sent.
Definition tsch.c:197
void tsch_set_coordinator(int enable)
Set the node as PAN coordinator.
Definition tsch.c:167
void tsch_set_join_priority(uint8_t jp)
Set the TSCH join priority (JP)
Definition tsch.c:184
int tsch_rpl_check_dodag_joined(void)
Check RPL has joined DODAG.
const uip_lladdr_t * uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr)
Get the link-layer address associated with a specified IPv6 address.
Header file for the logging system.
Routing driver header file.
void(* link_callback)(const linkaddr_t *addr, int status, int numtx)
Called by lower layers after every packet transmission.
Definition routing.h:170
int(* node_has_joined)(void)
Tells whether the node is currently part of a network.
Definition routing.h:108
void(* local_repair)(const char *str)
Triggers a RPL local topology repair.
Definition routing.h:126
RPL DAG structure.
Definition rpl.h:138
RPL instance structure.
Definition rpl.h:222
Main API declarations for TSCH.