1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

rpl: merge storing/non-storing to reduce the amount of redundant code

This commit is contained in:
Cenk Gündoğan 2015-01-22 12:56:04 +01:00
parent fbf3296ca5
commit d6e8e57d1f
10 changed files with 199 additions and 1360 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013, 2014 INRIA.
* Copyright (C) 2013 - 2014 INRIA.
* Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
@ -19,6 +20,7 @@
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/
#ifndef __RPL_H
@ -45,16 +47,29 @@ extern "C" {
/* global variables */
extern kernel_pid_t rpl_process_pid;
extern uint8_t rpl_max_routing_entries;
extern ipv6_addr_t my_address;
extern msg_t rpl_msg_queue[RPL_PKT_RECV_BUF_SIZE];
extern char rpl_process_buf[RPL_PROCESS_STACKSIZE];
extern uint8_t rpl_buffer[BUFFER_SIZE - LL_HDR_LEN];
/**
* @brief Sends a RPL message to a given destination
*
* This function sends any RPL related messages to a given destination.
*
* @param[in] destination IPv6-address of the destination of the message.
* @param[in] payload Payload of the message.
* @param[in] p_len Length of the message
* @param[in] next_header Index to next header in message.
*
*/
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header);
/**
* @brief Initialization of RPL.
*
* This function initializes all basic RPL resources such as
* corresponding objective functions and sixlowpan (including own address). Calls
* initialization for mode as specified by PL_DEFAULT_MOP in rpl_structs.h.
* corresponding objective functions and sixlowpan (including own address).
*
* @param[in] if_id ID of the interface, which correspond to the network under RPL-control
*
@ -68,8 +83,6 @@ uint8_t rpl_init(int if_id);
* @brief Initialization of RPL-root.
*
* This function initializes all RPL resources to act as a root node.
* Because the root has different features in different modes, the core
* initialization just calls the root-initialization of the chosen mode
*
*/
void rpl_init_root(void);
@ -77,9 +90,7 @@ void rpl_init_root(void);
/**
* @brief Sends a DIO-message to a given destination
*
* This function sends a DIO message to a given destination. Because nodes can act
* differently in different modes, this function calls the DIO
* sending function of the chosen mode.
* This function sends a DIO message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DIO. Should be a direct neighbor.
*
@ -89,9 +100,7 @@ void rpl_send_DIO(ipv6_addr_t *destination);
/**
* @brief Sends a DAO-message to a given destination
*
* This function sends a DAO message to a given destination. Because nodes can act
* differently in different modes, this function calls the DAO
* sending function of the chosen mode.
* This function sends a DAO message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DAO. Should be the preferred parent.
* @param[in] lifetime Lifetime of the node. Reflect the estimated time of presence in the network.
@ -104,32 +113,29 @@ void rpl_send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifet
/**
* @brief Sends a DIS-message to a given destination
*
* This function sends a DIS message to a given destination or multicast-address. Because nodes can act
* differently in different modes, this function calls the DIS
* sending function of the chosen mode.
* This function sends a DIS message to a given destination or multicast-address.
*
* @param[in] destination IPv6-address of the destination of the DIS. Should be a direct neighbor or multicast-address.
*
*/
void rpl_send_DIS(ipv6_addr_t *destination);
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
/**
* @brief Sends a DAO acknowledgment-message to a given destination
*
* This function sends a DAO_ACK message to a given destination. Because nodes can act
* differently in different modes, this function calls the DAO_ACK
* sending function of the chosen mode.
* This function sends a DAO_ACK message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DAO_ACK. Should be a direct neighbor.
*
*/
void rpl_send_DAO_ACK(ipv6_addr_t *destination);
#endif
/**
* @brief Receives a DIO message
*
* This function handles receiving a DIO message. Because nodes can act differently in different modes,
* this function just calls the receiving function of the chosen mode.
* This function handles receiving a DIO message.
*
*/
void rpl_recv_DIO(void);
@ -137,8 +143,7 @@ void rpl_recv_DIO(void);
/**
* @brief Receives a DAO message
*
* This function handles receiving a DAO message. Because nodes can act differently in different modes,
* this function just calls the receiving function of the chosen mode.
* This function handles receiving a DAO message.
*
*/
void rpl_recv_DAO(void);
@ -146,8 +151,7 @@ void rpl_recv_DAO(void);
/**
* @brief Receives a DIS message
*
* This function handles receiving a DIS message. Because nodes can act differently in different modes,
* this function just calls the receiving function of the chosen mode.
* This function handles receiving a DIS message.
*
*/
void rpl_recv_DIS(void);
@ -155,8 +159,7 @@ void rpl_recv_DIS(void);
/**
* @brief Receives a DAO acknowledgment message
*
* This function handles receiving a DAO_ACK message. Because nodes can act differently in different modes,
* this function just calls the receiving function of the chosen mode.
* This function handles receiving a DAO_ACK message.
*
*/
void rpl_recv_DAO_ACK(void);
@ -166,6 +169,7 @@ void rpl_recv_DAO_ACK(void);
*
* This function initializes all RPL resources especially for root purposes.
* corresponding objective functions and sixlowpan (including own address).
*
* @param arg ignored
* @returns nothing
*/

View File

@ -1,161 +0,0 @@
/*
* Copyright (C) 2013, 2014 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup rpl
* @{
*
* @file rpl_nonstoring.h
* @brief RPL non-storing-mode header
*
* Header which includes all mode related RPL-functions. All functions are mandatory for any
* RPL-mode. Describes receiving and sending of all RPL-related messages and special initialization behavior.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
*/
#ifndef RPL_NONSTORING_H_
#define RPL_NONSTORING_H_
#include "rpl_structs.h"
#include "rpl_config.h"
#include "rpl.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialization of RPL-root.
*
* This function initializes all RPL resources especially for root purposes. Initializes a new DODAG and sets
* itself as root. Starts trickle-timer so sending DIOs starts and other can join the DODAG.
*
*/
void rpl_init_root_mode(void);
/**
* @brief Initialization of RPL storing mode.
*
* This function initializes all basic RPL mode resources. For this mode this includes only acquiring the own
* address.
*
* @param[in] my_ipv6_address Own IPv6 address as assigned by RPL core-initialization.
*
*/
void rpl_init_mode(ipv6_addr_t *my_ipv6_address);
/**
* @brief Returns whether a node is root or not
*
* This function initializes all basic RPL mode resources. For this mode this includes only acquiring the own
* address.
*
* @return 1 if node is root
* @return 0 if node is not root
*
*/
uint8_t rpl_is_root_mode(void);
/**
* @brief Sends a DIO-message to a given destination
*
* This function sends a DIO message to a given destination. This is triggered by the trickle-timer.
*
* @param[in] destination IPv6-address of the destination of the DIO. Should be a direct neighbor or multicast address.
*
*/
void rpl_send_DIO_mode(ipv6_addr_t *destination);
/**
* @brief Sends a DAO-message to a given destination
*
* This function sends a DAO message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DAO. Should be the proffered parent.
* @param[in] lifetime Lifetime of the node. Reflect the estimated time of presence in the network.
* @param[in] default_lifetime If true, param lifetime is ignored and lifetime is DODAG default-lifetime
* @param[in] start_index Describes whether a DAO must be split because of too many routing entries.
*
*/
void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index);
/**
* @brief Sends a DIS-message to a given destination
*
* This function sends a DIS message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DIS. Should be a direct neighbor.
*
*/
void rpl_send_DIS_mode(ipv6_addr_t *destination);
/**
* @brief Sends a DAO acknowledgment-message to a given destination
*
* This function sends a DAO_ACK message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DAO_ACK. Should be a direct neighbor.
*
*/
void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination);
/**
* @brief Receives a DIO message
*
* This function handles receiving a DIO message in any mode .
*
*/
void rpl_recv_DIO_mode(void);
/**
* @brief Receives a DAO message
*
* This function handles receiving a DAO message in any mode.
*
*/
void rpl_recv_DAO_mode(void);
/**
* @brief Receives a DIS message
*
* This function handles receiving a DIS message in any mode.
*
*/
void rpl_recv_DIS_mode(void);
/**
* @brief Receives a DAO acknowledgment message
*
* This function handles receiving a DAO_ACK message in any mode.
*
*/
void rpl_recv_dao_ack_mode(void);
/**
* @brief Sends a RPL message to a given destination
*
* This function sends any RPl related messages to a given destination. This implementation should be equal
* for all modes and therefore should not be altered. Every mode related RPL-sending function calls this for
* relaying it in lower layers to sixlowpan.
*
* @param[in] destination IPv6-address of the destination of the message.
* @param[in] payload Payload of the message.
* @param[in] p_len Length of the message
* @param[in] next_header Index to next header in message.
*
*/
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header);
#ifdef __cplusplus
}
#endif
#endif /* RPL_NONSTORING_H_ */
/** @} */

View File

@ -1,162 +0,0 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup rpl
* @brief Routing Protocol for Low power and Lossy Networks
* @{
*
* @file
* @brief RPL storing-mode header
*
* Header which includes all mode related RPL-functions. All functions are mandatory for any
* RPL-mode. Describes receiving and sending of all RPL-related messages and special initialization behavior.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
*/
#ifndef __RPL_SM_H
#define __RPL_SM_H
#include "rpl_structs.h"
#include "rpl_config.h"
#include "rpl.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialization of RPL-root.
*
* This function initializes all RPL resources especially for root purposes. Initializes a new DODAG and sets
* itself as root. Starts trickle-timer so sending DIOs starts and other can join the DODAG.
*
*/
void rpl_init_root_mode(void);
/**
* @brief Initialization of RPL storing mode.
*
* This function initializes all basic RPL mode resources. For this mode this includes only acquiring the own
* address.
*
* @param[in] my_ipv6_address Own IPv6 address as assigned by RPL core-initialization.
*
*/
void rpl_init_mode(ipv6_addr_t *my_ipv6_address);
/**
* @brief Sends a DIO-message to a given destination
*
* This function sends a DIO message to a given destination. This is triggered by the trickle-timer.
*
* @param[in] destination IPv6-address of the destination of the DIO. Should be a direct neighbor or multicast address.
*
*/
void rpl_send_DIO_mode(ipv6_addr_t *destination);
/**
* @brief Returns whether a node is root or not
*
* This function initializes all basic RPL mode resources. For this mode this includes only acquiring the own
* address.
*
* @return 1 if node is root
* @return 0 if node is not root
*
*/
uint8_t rpl_is_root_mode(void);
/**
* @brief Sends a DAO-message to a given destination
*
* This function sends a DAO message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DAO. Should be the proffered parent.
* @param[in] lifetime Lifetime of the node. Reflect the estimated time of presence in the network.
* @param[in] default_lifetime If true, param lifetime is ignored and lifetime is DODAG default-lifetime
* @param[in] start_index Describes whether a DAO must be split because of too many routing entries.
*
*/
void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index);
/**
* @brief Sends a DIS-message to a given destination
*
* This function sends a DIS message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DIS. Should be a direct neighbor.
*
*/
void rpl_send_DIS_mode(ipv6_addr_t *destination);
/**
* @brief Sends a DAO acknowledgment-message to a given destination
*
* This function sends a DAO_ACK message to a given destination.
*
* @param[in] destination IPv6-address of the destination of the DAO_ACK. Should be a direct neighbor.
*
*/
void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination);
/**
* @brief Receives a DIO message
*
* This function handles receiving a DIO message in any mode .
*
*/
void rpl_recv_DIO_mode(void);
/**
* @brief Receives a DAO message
*
* This function handles receiving a DAO message in any mode.
*
*/
void rpl_recv_DAO_mode(void);
/**
* @brief Receives a DIS message
*
* This function handles receiving a DIS message in any mode.
*
*/
void rpl_recv_DIS_mode(void);
/**
* @brief Receives a DAO acknowledgment message
*
* This function handles receiving a DAO_ACK message in any mode.
*
*/
void rpl_recv_dao_ack_mode(void);
/**
* @brief Sends a RPL message to a given destination
*
* This function sends any RPl related messages to a given destination. This implementation should be equal
* for all modes and therefore should not be altered. Every mode related RPL-sending function calls this for
* relaying it in lower layers to sixlowpan.
*
* @param[in] destination IPv6-address of the destination of the message.
* @param[in] payload Payload of the message.
* @param[in] p_len Length of the message
* @param[in] next_header Index to next header in message.
*
*/
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header);
#ifdef __cplusplus
}
#endif
#endif /* __RPL_SM_H */
/** @} */

View File

@ -9,19 +9,15 @@ MODE :=
ifeq (RPL_MOP_NO_DOWNWARD_ROUTES, $(RPL_MOP))
MODE := 0x00
DIRS += rpl_storing
endif
ifeq (RPL_MOP_NON_STORING_MODE, $(RPL_MOP))
MODE := 0x01
DIRS += rpl_nonstoring
endif
ifeq (RPL_MOP_STORING_MODE_NO_MC, $(RPL_MOP))
MODE := 0x02
DIRS += rpl_storing
endif
ifeq (RPL_MOP_STORING_MODE_MC, $(RPL_MOP))
MODE := 0x03
DIRS += rpl_storing
endif
# If a valid RPL_MOP was provided, use it for RPL
@ -30,7 +26,6 @@ ifneq (,$(MODE))
else
# If no (valid) RPL_MOP has been provided, use the following parameters
CFLAGS += -DRPL_DEFAULT_MOP=0x02
DIRS += rpl_storing
endif
# Set the maximum number of routing entries to 128 if no number is provided

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013, 2014 INRIA.
* Copyright (C) 2013 - 2014 INRIA.
* Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
@ -18,6 +19,7 @@
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/
#include <string.h>
@ -34,14 +36,6 @@
#include "sixlowpan.h"
#include "net_help.h"
#if RPL_DEFAULT_MOP == RPL_MOP_STORING_MODE_NO_MC
#include "rpl/rpl_storing.h"
#elif RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE
#include "rpl/rpl_nonstoring.h"
#else
#include "rpl/rpl_storing.h"
#endif
#define ENABLE_DEBUG (0)
#if ENABLE_DEBUG
char addr_str[IPV6_MAX_ADDR_STR_LEN];
@ -73,7 +67,7 @@ static msg_t srh_m_send, srh_m_recv;
static rpl_routing_entry_t rpl_routing_table[RPL_MAX_ROUTING_ENTRIES];
#endif
uint8_t rpl_max_routing_entries;
static ipv6_addr_t my_address;
ipv6_addr_t my_address;
/* IPv6 message buffer */
static ipv6_hdr_t *ipv6_buf;
@ -106,7 +100,6 @@ uint8_t rpl_init(int if_id)
/* initialize objective function manager */
rpl_of_manager_init(&my_address);
rpl_init_mode(&my_address);
rt_time = timex_set(RPL_LIFETIME_STEP, 0);
vtimer_set_msg(&rt_timer, rt_time, rpl_process_pid, RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE, NULL);
@ -114,27 +107,6 @@ uint8_t rpl_init(int if_id)
return SIXLOWERROR_SUCCESS;
}
void rpl_init_root(void)
{
#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE)
#ifndef RPL_NODE_IS_ROOT
puts("\n############################## ERROR ###############################");
puts("This configuration has NO ROUTING TABLE available for the root node!");
puts("The root will NOT be INITIALIZED.");
puts("Please build the binary for root in non-storing MOP with:");
puts("\t\t'make RPL_NODE_IS_ROOT=1'");
puts("############################## ERROR ###############################\n");
return;
#endif
#endif
rpl_init_root_mode();
}
uint8_t rpl_is_root(void)
{
return rpl_is_root_mode();
}
#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE)
void internal_srh_process(ipv6_srh_t *srh_header)
{
@ -154,7 +126,7 @@ void internal_srh_process(ipv6_srh_t *srh_header)
srh_header->segments_left = segs - 1;
DEBUGF("Segments left after reduction: %d\n", srh_header->segments_left);
DEBUGF("Next hop is: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, down_next_hop));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, down_next_hop));
}
}
#endif
@ -176,9 +148,11 @@ void *rpl_process(void *arg)
switch (m_recv.type) {
case RPL_MSG_TYPE_DAO_HANDLE:
dodag = (rpl_dodag_t *) m_recv.content.ptr;
if (dodag->joined) {
_dao_handle_send(dodag);
}
break;
case RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE:
@ -187,16 +161,20 @@ void *rpl_process(void *arg)
case RPL_MSG_TYPE_TRICKLE_INTERVAL:
trickle = (trickle_t *) m_recv.content.ptr;
if (trickle->callback.func != NULL) {
trickle_interval(trickle);
}
break;
case RPL_MSG_TYPE_TRICKLE_CALLBACK:
trickle = (trickle_t *) m_recv.content.ptr;
if (trickle->callback.func != NULL) {
trickle_callback(trickle);
}
break;
default:
@ -214,7 +192,7 @@ void *rpl_process(void *arg)
/* get code for message-interpretation and process message */
DEBUGF("Received RPL information of type %04X and length %u\n",
m_recv.type, NTOHS(ipv6_buf->length));
m_recv.type, NTOHS(ipv6_buf->length));
switch (m_recv.type) {
case (ICMP_CODE_DIS): {
@ -252,21 +230,23 @@ void *rpl_process(void *arg)
/* if there are no segments left, the routing is finished */
if (srh_header->segments_left == 0) {
DEBUGF("Source routing finished with next header: %02X.\n",
srh_header->nextheader);
srh_header->nextheader);
DEBUGF("Size of srh: %d\n", srh_header->hdrextlen);
uint8_t *payload = ((uint8_t *)(m_recv.content.ptr +
IPV6_HDR_LEN + sizeof(ipv6_srh_t)+srh_header->hdrextlen));
IPV6_HDR_LEN + sizeof(ipv6_srh_t) + srh_header->hdrextlen));
rpl_remove_srh_header(ipv6_buf, payload, srh_header->nextheader);
}
else {
internal_srh_process(srh_header);
if (down_next_hop != NULL) {
uint8_t *payload = ((uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN));
rpl_srh_sendto(payload, NTOHS(ipv6_buf->length), &ipv6_buf->srcaddr,
down_next_hop, srh_header, 0);
down_next_hop, srh_header, 0);
}
}
}
#if RPL_MAX_ROUTING_ENTRIES != 0
else {
srh_header = rpl_get_srh_header(ipv6_buf);
@ -274,87 +254,24 @@ void *rpl_process(void *arg)
if (srh_header != NULL) {
uint8_t *payload = ((uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN));
rpl_srh_sendto(payload, NTOHS(ipv6_buf->length),
&ipv6_buf->srcaddr, &ipv6_buf->destaddr, srh_header,
srh_header->hdrextlen + sizeof(ipv6_srh_t));
&ipv6_buf->srcaddr, &ipv6_buf->destaddr, srh_header,
srh_header->hdrextlen + sizeof(ipv6_srh_t));
}
}
#endif
}
#endif
}
}
}
void rpl_send_DIO(ipv6_addr_t *destination)
void _rpl_update_routing_table(void)
{
if (destination) {
DEBUGF("Send DIO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
rpl_send_DIO_mode(destination);
}
void rpl_send_DAO(ipv6_addr_t *destination, uint8_t lifetime,
bool default_lifetime, uint8_t start_index)
{
if (destination) {
DEBUGF("Send DAO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
rpl_send_DAO_mode(destination, lifetime, default_lifetime, start_index);
}
void rpl_send_DIS(ipv6_addr_t *destination)
{
if (destination) {
DEBUGF("Send DIS to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
rpl_send_DIS_mode(destination);
}
void rpl_send_DAO_ACK(ipv6_addr_t *destination)
{
if (destination) {
DEBUGF("Send DAO ACK to %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
rpl_send_DAO_ACK_mode(destination);
}
void rpl_recv_DIO(void)
{
DEBUGF("DIO received\n");
rpl_recv_DIO_mode();
}
void rpl_recv_DAO(void)
{
DEBUGF("DAO received\n");
rpl_recv_DAO_mode();
}
void rpl_recv_DIS(void)
{
DEBUGF("DIS received\n");
rpl_recv_DIS_mode();
}
void rpl_recv_DAO_ACK(void)
{
DEBUGF("DAO ACK received\n");
rpl_recv_dao_ack_mode();
}
void _rpl_update_routing_table(void) {
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
rpl_routing_entry_t *rt;
if (my_dodag != NULL) {
rt = rpl_get_routing_table();
@ -393,7 +310,7 @@ void rpl_delay_dao(rpl_dodag_t *dodag)
dodag->ack_received = false;
vtimer_remove(&dodag->dao_timer);
vtimer_set_msg(&dodag->dao_timer, dodag->dao_time,
rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag);
rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag);
}
/* This function is used for regular update of the routes.
@ -406,7 +323,7 @@ void long_delay_dao(rpl_dodag_t *dodag)
dodag->ack_received = false;
vtimer_remove(&dodag->dao_timer);
vtimer_set_msg(&dodag->dao_timer, dodag->dao_time,
rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag);
rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag);
}
void rpl_dao_ack_received(rpl_dodag_t *dodag)
@ -415,14 +332,15 @@ void rpl_dao_ack_received(rpl_dodag_t *dodag)
long_delay_dao(dodag);
}
void _dao_handle_send(rpl_dodag_t *dodag) {
void _dao_handle_send(rpl_dodag_t *dodag)
{
if ((dodag->ack_received == false) && (dodag->dao_counter < DAO_SEND_RETRIES)) {
dodag->dao_counter++;
rpl_send_DAO(NULL, 0, true, 0);
dodag->dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK, 0);
vtimer_remove(&dodag->dao_timer);
vtimer_set_msg(&dodag->dao_timer, dodag->dao_time,
rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag);
rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag);
}
else if (dodag->ack_received == false) {
long_delay_dao(dodag);
@ -433,32 +351,34 @@ ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t *addr)
{
DEBUGF("Looking up the next hop to %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
#if RPL_MAX_ROUTING_ENTRIES != 0
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (rpl_routing_table[i].used) {
DEBUGF("checking %d: %s\n", i,
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &rpl_routing_table[i].address));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &rpl_routing_table[i].address));
}
if ((RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) && rpl_is_root()) {
if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) {
DEBUGF("found %d: %s\n", i,
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&rpl_routing_table[i].address));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&rpl_routing_table[i].address));
return &rpl_routing_table[i].address;
}
}
else {
if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) {
DEBUGF("found %d: %s\n", i,
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&rpl_routing_table[i].next_hop));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&rpl_routing_table[i].next_hop));
return &rpl_routing_table[i].next_hop;
}
}
}
#else
(void) addr;
#endif
@ -570,9 +490,9 @@ void rpl_add_srh_entry(ipv6_addr_t *child, ipv6_addr_t *parent, uint16_t lifetim
* so that route aggregation can be done properly.
*/
DEBUGF("Adding source-routing entry child: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, child));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, child));
DEBUGF("Adding source-routing entry parent: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, parent));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, parent));
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (!rpl_routing_table[i].used) {
@ -621,12 +541,12 @@ ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr)
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (rpl_routing_table[i].used
&& ipv6_suffix_is_equal(&rpl_routing_table[i].address, actual_node)) {
&& ipv6_suffix_is_equal(&rpl_routing_table[i].address, actual_node)) {
DEBUGF("[INFO] Found parent-child relation with P: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&rpl_routing_table[i].next_hop));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&rpl_routing_table[i].next_hop));
DEBUGF(" and C: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, actual_node));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, actual_node));
memcpy(&rev_route[counter], actual_node, sizeof(ipv6_addr_t));
actual_node = &rpl_routing_table[i].next_hop;
@ -638,6 +558,7 @@ ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr)
DEBUGF("Error with computing source routing header.\n");
return NULL;
}
break;
}
}
@ -652,11 +573,12 @@ ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr)
* After building it starts with the node next to destination
*/
if (counter > 1) {
for (uint8_t i = 0; i < counter-1; i++) {
memcpy(&srh_header->route[i], &rev_route[counter-i-2], sizeof(ipv6_addr_t));
for (uint8_t i = 0; i < counter - 1; i++) {
memcpy(&srh_header->route[i], &rev_route[counter - i - 2], sizeof(ipv6_addr_t));
}
srh_header->hdrextlen = sizeof(ipv6_addr_t)*(counter-1);
memcpy(&(act_ipv6_hdr->destaddr), &rev_route[counter-1], sizeof(ipv6_addr_t));
srh_header->hdrextlen = sizeof(ipv6_addr_t) * (counter - 1);
memcpy(&(act_ipv6_hdr->destaddr), &rev_route[counter - 1], sizeof(ipv6_addr_t));
DEBUGF("Route size: %d\n", srh_header->hdrextlen);
}
else {
@ -689,13 +611,13 @@ void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nex
memcpy(payload, buf, msg_length);
DEBUGF("Source routing header extraction finished.\n");
DEBUGF("Dest is now: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &temp_ipv6_header->destaddr));
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &temp_ipv6_header->destaddr));
srh_m_send.content.ptr = (char *) srh_send_buffer;
msg_send_receive(&srh_m_send, &srh_m_recv, ip_process_pid);
}
int rpl_srh_sendto(const void *buf, uint16_t len,
ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_srh_t *srh_header, uint8_t srh_length)
ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_srh_t *srh_header, uint8_t srh_length)
{
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&srh_send_buffer));
ipv6_srh_t *current_packet = ((ipv6_srh_t *)(&srh_send_buffer[IPV6_HDR_LEN]));
@ -711,6 +633,6 @@ int rpl_srh_sendto(const void *buf, uint16_t len,
DEBUGF("My payload length: %d\n", plength);
return ipv6_sendto(&temp_ipv6_header->destaddr, IPV6_PROTO_NUM_SRH,
(uint8_t *)current_packet, plength, &temp_ipv6_header->destaddr);
(uint8_t *)current_packet, plength, &temp_ipv6_header->destaddr);
}
#endif

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013, 2014 INRIA.
* Copyright (C) 2013 - 2014 INRIA.
* Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
@ -10,16 +11,18 @@
* @ingroup rpl
* @{
*
* @file rpl_storing.c
* @brief RPL storing-mode
* @brief RPL control messages handling
*
* Implementation of the storing mode of RPL.
* Implementation of RPL control messages handling
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/
#include "rpl/rpl_storing.h"
#include "rpl.h"
#include "rpl/rpl_structs.h"
#include "rpl/rpl_config.h"
#include "msg.h"
#include "trickle.h"
@ -28,13 +31,10 @@
#define ENABLE_DEBUG (0)
#if ENABLE_DEBUG
static char addr_str_mode[IPV6_MAX_ADDR_STR_LEN];
static char addr_str[IPV6_MAX_ADDR_STR_LEN];
#endif
#include "debug.h"
/* global variables */
static ipv6_addr_t my_address;
/* Identification variables */
static char i_am_root;
@ -44,7 +44,9 @@ static uint8_t rpl_send_buffer[BUFFER_SIZE];
/* SEND BUFFERS */
static icmpv6_hdr_t *icmp_send_buf;
static rpl_dis_t *rpl_send_dis_buf;
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
static rpl_dao_ack_t *rpl_send_dao_ack_buf;
#endif
static ipv6_hdr_t *ipv6_send_buf;
static rpl_dio_t *rpl_send_dio_buf;
static rpl_dao_t *rpl_send_dao_buf;
@ -70,10 +72,12 @@ static icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len)
return ((icmpv6_hdr_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ext_len]));
}
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
static rpl_dao_ack_t *get_rpl_send_dao_ack_buf(void)
{
return ((rpl_dao_ack_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
#endif
static rpl_dis_t *get_rpl_send_dis_buf(void)
{
@ -167,13 +171,19 @@ static rpl_opt_solicited_t *get_rpl_opt_solicited_buf(uint8_t rpl_msg_len)
return ((rpl_opt_solicited_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
void rpl_init_mode(ipv6_addr_t *init_address)
{
memcpy(&my_address, init_address, sizeof(ipv6_addr_t));
}
void rpl_init_root_mode(void)
void rpl_init_root(void)
{
#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE)
#ifndef RPL_NODE_IS_ROOT
puts("\n############################## ERROR ###############################");
puts("This configuration has NO ROUTING TABLE available for the root node!");
puts("The root will NOT be INITIALIZED.");
puts("Please build the binary for root in non-storing MOP with:");
puts("\t\t'make RPL_NODE_IS_ROOT=1'");
puts("############################## ERROR ###############################\n");
return;
#endif
#endif
rpl_instance_t *inst;
rpl_dodag_t *dodag;
@ -216,19 +226,26 @@ void rpl_init_root_mode(void)
i_am_root = 1;
trickle_start(rpl_process_pid, &dodag->trickle, RPL_MSG_TYPE_TRICKLE_INTERVAL,
RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), dodag->dio_interval_doubling,
dodag->dio_redundancy);
RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), dodag->dio_interval_doubling,
dodag->dio_redundancy);
DEBUGF("ROOT INIT FINISHED\n");
}
uint8_t rpl_is_root_mode(void)
uint8_t rpl_is_root(void)
{
return i_am_root;
}
void rpl_send_DIO_mode(ipv6_addr_t *destination)
void rpl_send_DIO(ipv6_addr_t *destination)
{
#if ENABLE_DEBUG
if (destination) {
DEBUGF("Send DIO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
#endif
rpl_dodag_t *mydodag;
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
@ -252,7 +269,7 @@ void rpl_send_DIO_mode(ipv6_addr_t *destination)
rpl_send_dio_buf->rank = byteorder_htons(mydodag->my_rank);
DEBUG("rank %04X\n", byteorder_ntohs(rpl_send_dio_buf->rank));
rpl_send_dio_buf->g_mop_prf = (mydodag->grounded << RPL_GROUNDED_SHIFT) |
(mydodag->mop << RPL_MOP_SHIFT) | mydodag->prf;
(mydodag->mop << RPL_MOP_SHIFT) | mydodag->prf;
rpl_send_dio_buf->dtsn = mydodag->dtsn;
rpl_send_dio_buf->flags = 0;
rpl_send_dio_buf->reserved = 0;
@ -280,8 +297,21 @@ void rpl_send_DIO_mode(ipv6_addr_t *destination)
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index)
void rpl_send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
uint8_t start_index)
{
#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE
(void) start_index;
#endif
#if ENABLE_DEBUG
if (destination) {
DEBUGF("Send DAO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
#endif
if (i_am_root) {
return;
}
@ -294,12 +324,17 @@ void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_
}
if (destination == NULL) {
#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE
destination = &my_dodag->dodag_id;
#else
if (my_dodag->my_preferred_parent == NULL) {
DEBUGF("send_DAO: my_dodag has no my_preferred_parent\n");
return;
}
destination = &my_dodag->my_preferred_parent->addr;
#endif
}
if (default_lifetime) {
@ -318,6 +353,7 @@ void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_
rpl_send_dao_buf->dao_sequence = my_dodag->dao_seq;
uint16_t opt_len = 0;
rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN);
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
/* add all targets from routing table as targets */
uint8_t entries = 0;
uint8_t continue_index = 0;
@ -329,7 +365,7 @@ void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_
rpl_send_opt_target_buf->flags = 0x00;
rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN;
memcpy(&rpl_send_opt_target_buf->target, &rpl_get_routing_table()[i].address,
sizeof(ipv6_addr_t));
sizeof(ipv6_addr_t));
opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN;
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT;
@ -351,6 +387,7 @@ void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_
}
}
#endif
/* add own address */
rpl_send_opt_target_buf->type = RPL_OPT_TARGET;
rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN;
@ -361,23 +398,42 @@ void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT;
rpl_send_opt_transit_buf->length = (RPL_OPT_TRANSIT_LEN - sizeof(ipv6_addr_t));
rpl_send_opt_transit_buf->e_flags = 0x00;
rpl_send_opt_transit_buf->path_control = 0x00;
rpl_send_opt_transit_buf->path_sequence = 0x00;
rpl_send_opt_transit_buf->path_lifetime = lifetime;
#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE
rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN;
memcpy(&rpl_send_opt_transit_buf->parent, rpl_get_my_preferred_parent(), sizeof(ipv6_addr_t));
opt_len += RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN;
#else
rpl_send_opt_transit_buf->length = (RPL_OPT_TRANSIT_LEN - sizeof(ipv6_addr_t));
opt_len += (RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN - sizeof(ipv6_addr_t));
#endif
uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len;
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
if (continue_index > 1) {
rpl_send_DAO(destination, lifetime, default_lifetime, continue_index);
}
#endif
}
void rpl_send_DIS_mode(ipv6_addr_t *destination)
void rpl_send_DIS(ipv6_addr_t *destination)
{
#if ENABLE_DEBUG
if (destination) {
DEBUGF("Send DIS to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
#endif
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL;
@ -389,8 +445,18 @@ void rpl_send_DIS_mode(ipv6_addr_t *destination)
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination)
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
void rpl_send_DAO_ACK(ipv6_addr_t *destination)
{
#if ENABLE_DEBUG
if (destination) {
DEBUGF("Send DAO ACK to %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
#endif
rpl_dodag_t *my_dodag;
my_dodag = rpl_get_my_dodag();
@ -412,8 +478,9 @@ void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination)
uint16_t plen = ICMPV6_HDR_LEN + DAO_ACK_LEN;
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
#endif
void rpl_recv_DIO_mode(void)
void rpl_recv_DIO(void)
{
ipv6_buf = get_rpl_ipv6_buf();
@ -634,7 +701,7 @@ void rpl_recv_DIO_mode(void)
DEBUGF("My dodag has no preferred_parent yet - seems to be odd since I have a parent...\n");
}
else if (rpl_equal_id(&parent->addr, &my_dodag->my_preferred_parent->addr) &&
(parent->dtsn != rpl_dio_buf->dtsn)) {
(parent->dtsn != rpl_dio_buf->dtsn)) {
rpl_delay_dao(my_dodag);
}
@ -642,7 +709,7 @@ void rpl_recv_DIO_mode(void)
}
void rpl_recv_DAO_mode(void)
void rpl_recv_DAO(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
@ -651,6 +718,14 @@ void rpl_recv_DAO_mode(void)
return;
}
#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE
if (!i_am_root) {
DEBUGF("[Error] something went wrong - got a DAO.\n");
return;
}
#endif
ipv6_buf = get_rpl_ipv6_buf();
rpl_dao_buf = get_rpl_dao_buf();
DEBUG("instance %04X ", rpl_dao_buf->rpl_instanceid);
@ -692,20 +767,23 @@ void rpl_recv_DAO_mode(void)
if (rpl_opt_transit_buf->type != RPL_OPT_TRANSIT) {
DEBUGF("[Error] - no transit information for target option type = %d\n",
rpl_opt_transit_buf->type);
rpl_opt_transit_buf->type);
break;
}
len += (rpl_opt_transit_buf->length + RPL_OPT_LEN);
/* route lifetime seconds = (DAO lifetime) * (Unit Lifetime) */
#if RPL_MAX_ROUTING_ENTRIES != 0
#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) && (RPL_MAX_ROUTING_ENTRIES != 0)
rpl_add_srh_entry(&rpl_opt_target_buf->target, &rpl_opt_transit_buf->parent,
rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit);
#elif (RPL_MAX_ROUTING_ENTRIES != 0)
DEBUG("Adding routing information: Target: %s, Source: %s, Lifetime: %u\n",
ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN, &rpl_opt_target_buf->target),
ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN, &ipv6_buf->srcaddr),
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &rpl_opt_target_buf->target),
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &ipv6_buf->srcaddr),
(rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit));
rpl_add_routing_entry(&rpl_opt_target_buf->target, &ipv6_buf->srcaddr,
rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit);
rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit);
#endif
increment_seq = 1;
break;
@ -726,7 +804,9 @@ void rpl_recv_DAO_mode(void)
}
}
#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE
rpl_send_DAO_ACK(&ipv6_buf->srcaddr);
#endif
if (increment_seq) {
RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
@ -734,7 +814,7 @@ void rpl_recv_DAO_mode(void)
}
}
void rpl_recv_DIS_mode(void)
void rpl_recv_DIS(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
@ -801,7 +881,7 @@ void rpl_recv_DIS_mode(void)
}
void rpl_recv_dao_ack_mode(void)
void rpl_recv_DAO_ACK(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();

View File

@ -35,7 +35,8 @@ static rpl_instance_t instances[RPL_MAX_INSTANCES];
static rpl_dodag_t dodags[RPL_MAX_DODAGS];
static rpl_parent_t parents[RPL_MAX_PARENTS];
void rpl_trickle_send_dio(void *args) {
void rpl_trickle_send_dio(void *args)
{
(void) args;
ipv6_addr_t mcast;
@ -383,8 +384,8 @@ void rpl_join_dodag(rpl_dodag_t *dodag, ipv6_addr_t *parent, uint16_t parent_ran
DEBUG("\tmy_preferred_parent lifetime\t%04X\n", my_dodag->my_preferred_parent->lifetime);
trickle_start(rpl_process_pid, &my_dodag->trickle, RPL_MSG_TYPE_TRICKLE_INTERVAL,
RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << my_dodag->dio_min), my_dodag->dio_interval_doubling,
my_dodag->dio_redundancy);
RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << my_dodag->dio_min), my_dodag->dio_interval_doubling,
my_dodag->dio_redundancy);
rpl_delay_dao(my_dodag);
}

View File

@ -1,3 +0,0 @@
MODULE := rpl
INCLUDES += -I$(RIOTBASE)/sys/net/routing/rpl
include $(RIOTBASE)/Makefile.base

View File

@ -1,834 +0,0 @@
/*
* Copyright (C) 2013, 2014 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup rpl
* @{
*
* @file rpl_nonstoring.c
* @brief RPL non-storing-mode
*
* Implementation of the non-storing mode of RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
*/
#include "rpl/rpl_nonstoring.h"
#include "msg.h"
#include "trickle.h"
#include "sixlowpan.h"
#include "net_help.h"
#define ENABLE_DEBUG (0)
#if ENABLE_DEBUG
static char addr_str_mode[IPV6_MAX_ADDR_STR_LEN];
#endif
#include "debug.h"
/* Identification variables */
static char i_am_root;
static char i_am_leaf;
static ipv6_addr_t my_address;
/* in send buffer we need space for LL_HDR */
static uint8_t rpl_send_buffer[BUFFER_SIZE];
/* SEND BUFFERS */
static icmpv6_hdr_t *icmp_send_buf;
static rpl_dis_t *rpl_send_dis_buf;
static ipv6_hdr_t *ipv6_send_buf;
static rpl_dio_t *rpl_send_dio_buf;
static rpl_dao_t *rpl_send_dao_buf;
static rpl_opt_dodag_conf_t *rpl_send_opt_dodag_conf_buf;
static rpl_opt_target_t *rpl_send_opt_target_buf;
static rpl_opt_transit_t *rpl_send_opt_transit_buf;
/* RECEIVE BUFFERS */
static ipv6_hdr_t *ipv6_buf;
static rpl_dio_t *rpl_dio_buf;
static rpl_dao_t *rpl_dao_buf;
static rpl_dao_ack_t *rpl_dao_ack_buf;
static rpl_opt_dodag_conf_t *rpl_opt_dodag_conf_buf;
static rpl_opt_target_t *rpl_opt_target_buf;
static rpl_opt_transit_t *rpl_opt_transit_buf;
static rpl_dis_t *rpl_dis_buf;
static rpl_opt_t *rpl_opt_buf;
static rpl_opt_solicited_t *rpl_opt_solicited_buf;
/* SEND BUFFERS */
static icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len)
{
return ((icmpv6_hdr_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ext_len]));
}
static rpl_dis_t *get_rpl_send_dis_buf(void)
{
return ((rpl_dis_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static ipv6_hdr_t *get_rpl_send_ipv6_buf(void)
{
return ((ipv6_hdr_t *) & (rpl_send_buffer[0]));
}
static uint8_t *get_rpl_send_payload_buf(uint8_t ext_len)
{
return &(rpl_send_buffer[IPV6_HDR_LEN + ext_len]);
}
static rpl_dio_t *get_rpl_send_dio_buf(void)
{
return ((rpl_dio_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static rpl_dao_t *get_rpl_send_dao_buf(void)
{
return ((rpl_dao_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static rpl_opt_dodag_conf_t *get_rpl_send_opt_dodag_conf_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_dodag_conf_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
static rpl_opt_target_t *get_rpl_send_opt_target_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_target_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
static rpl_opt_transit_t *get_rpl_send_opt_transit_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_transit_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
/* RECEIVE BUFFERS */
static ipv6_hdr_t *get_rpl_ipv6_buf(void)
{
return ((ipv6_hdr_t *) & (rpl_buffer[0]));
}
static rpl_opt_target_t *get_rpl_opt_target_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_target_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
static rpl_opt_transit_t *get_rpl_opt_transit_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_transit_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
static rpl_opt_dodag_conf_t *get_rpl_opt_dodag_conf_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_dodag_conf_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
static rpl_dio_t *get_rpl_dio_buf(void)
{
return ((rpl_dio_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static rpl_dao_t *get_rpl_dao_buf(void)
{
return ((rpl_dao_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static rpl_dao_ack_t *get_rpl_dao_ack_buf(void)
{
return ((rpl_dao_ack_t *) & (buffer[(LL_HDR_LEN + IPV6_HDR_LEN + ICMPV6_HDR_LEN)]));
}
static rpl_dis_t *get_rpl_dis_buf(void)
{
return ((rpl_dis_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static rpl_opt_t *get_rpl_opt_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
static rpl_opt_solicited_t *get_rpl_opt_solicited_buf(uint8_t rpl_msg_len)
{
return ((rpl_opt_solicited_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len]));
}
void rpl_init_mode(ipv6_addr_t *init_address)
{
DEBUGF("My address: %s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN, init_address));
memcpy(&my_address, init_address, sizeof(ipv6_addr_t));
}
void rpl_init_root_mode(void)
{
rpl_instance_t *inst;
rpl_dodag_t *dodag;
inst = rpl_new_instance(RPL_DEFAULT_INSTANCE);
if (inst == NULL) {
DEBUGF("Error - No memory for another RPL instance\n");
return;
}
inst->id = RPL_DEFAULT_INSTANCE;
inst->joined = 1;
dodag = rpl_new_dodag(RPL_DEFAULT_INSTANCE, &my_address);
/* set root values */
i_am_root = 1;
if (dodag != NULL) {
dodag->of = (struct rpl_of_t *) rpl_get_of_for_ocp(RPL_DEFAULT_OCP);
DEBUGF("Dodag init done.\n");
dodag->instance = inst;
dodag->mop = RPL_DEFAULT_MOP;
dodag->dtsn = 1;
dodag->prf = 0;
dodag->dio_interval_doubling = DEFAULT_DIO_INTERVAL_DOUBLINGS;
dodag->dio_min = DEFAULT_DIO_INTERVAL_MIN;
dodag->dio_redundancy = DEFAULT_DIO_REDUNDANCY_CONSTANT;
dodag->maxrankincrease = 0;
dodag->minhoprankincrease = (uint16_t)DEFAULT_MIN_HOP_RANK_INCREASE;
dodag->default_lifetime = (uint8_t)RPL_DEFAULT_LIFETIME;
dodag->lifetime_unit = RPL_LIFETIME_UNIT;
dodag->version = RPL_COUNTER_INIT;
dodag->grounded = RPL_GROUNDED;
dodag->node_status = (uint8_t) ROOT_NODE;
dodag->my_rank = RPL_ROOT_RANK;
dodag->joined = 1;
dodag->my_preferred_parent = NULL;
memcpy(&dodag->dodag_id, &my_address, sizeof(ipv6_addr_t));
}
else {
DEBUGF("Error - could not generate DODAG\n");
return;
}
trickle_start(rpl_process_pid, &dodag->trickle, RPL_MSG_TYPE_TRICKLE_INTERVAL,
RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), dodag->dio_interval_doubling,
dodag->dio_redundancy);
DEBUGF("Root init finished.\n");
}
uint8_t rpl_is_root_mode(void)
{
return i_am_root;
}
void rpl_send_DIO_mode(ipv6_addr_t *destination)
{
if (i_am_leaf) {
return;
}
rpl_dodag_t *mydodag;
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
mydodag = rpl_get_my_dodag();
if (mydodag == NULL) {
DEBUGF("Error - trying to send DIO without being part of a dodag.\n");
return;
}
icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL;
icmp_send_buf->code = ICMP_CODE_DIO;
rpl_send_dio_buf = get_rpl_send_dio_buf();
memset(rpl_send_dio_buf, 0, sizeof(*rpl_send_dio_buf));
DEBUGF("Sending DIO with ");
rpl_send_dio_buf->rpl_instanceid = mydodag->instance->id;
DEBUG("instance %02X ", rpl_send_dio_buf->rpl_instanceid);
rpl_send_dio_buf->version_number = mydodag->version;
rpl_send_dio_buf->rank = byteorder_htons(mydodag->my_rank);
DEBUG("rank %04X\n", byteorder_ntohs(rpl_send_dio_buf->rank));
rpl_send_dio_buf->g_mop_prf = (mydodag->grounded << RPL_GROUNDED_SHIFT) |
(mydodag->mop << RPL_MOP_SHIFT) | mydodag->prf;
rpl_send_dio_buf->dtsn = mydodag->dtsn;
rpl_send_dio_buf->flags = 0;
rpl_send_dio_buf->reserved = 0;
rpl_send_dio_buf->dodagid = mydodag->dodag_id;
int opt_hdr_len = 0;
/* DODAG configuration option */
rpl_send_opt_dodag_conf_buf = get_rpl_send_opt_dodag_conf_buf(DIO_BASE_LEN);
rpl_send_opt_dodag_conf_buf->type = RPL_OPT_DODAG_CONF;
rpl_send_opt_dodag_conf_buf->length = RPL_OPT_DODAG_CONF_LEN;
rpl_send_opt_dodag_conf_buf->flags_a_pcs = 0;
rpl_send_opt_dodag_conf_buf->DIOIntDoubl = mydodag->dio_interval_doubling;
rpl_send_opt_dodag_conf_buf->DIOIntMin = mydodag->dio_min;
rpl_send_opt_dodag_conf_buf->DIORedun = mydodag->dio_redundancy;
rpl_send_opt_dodag_conf_buf->MaxRankIncrease = byteorder_htons(mydodag->maxrankincrease);
rpl_send_opt_dodag_conf_buf->MinHopRankIncrease = byteorder_htons(mydodag->minhoprankincrease);
rpl_send_opt_dodag_conf_buf->ocp = byteorder_htons(mydodag->of->ocp);
DEBUGF("Building done.\n");
rpl_send_opt_dodag_conf_buf->reserved = 0;
rpl_send_opt_dodag_conf_buf->default_lifetime = mydodag->default_lifetime;
rpl_send_opt_dodag_conf_buf->lifetime_unit = byteorder_htons(mydodag->lifetime_unit);
opt_hdr_len += RPL_OPT_DODAG_CONF_LEN_WITH_OPT_LEN;
uint16_t plen = ICMPV6_HDR_LEN + DIO_BASE_LEN + opt_hdr_len;
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index)
{
(void) start_index;
if (i_am_root) {
return;
}
/* TODO: take advantage of start_index, by now not used in non-storing mode
start_index++;
*/
rpl_dodag_t *my_dodag;
if ((my_dodag = rpl_get_my_dodag()) == NULL) {
DEBUGF("send_DAO: Not part of a DODAG\n");
return;
}
if (destination == NULL) {
destination = &my_dodag->dodag_id;
}
if (default_lifetime) {
lifetime = my_dodag->default_lifetime;
}
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL;
icmp_send_buf->code = ICMP_CODE_DAO;
rpl_send_dao_buf = get_rpl_send_dao_buf();
memset(rpl_send_dao_buf, 0, sizeof(*rpl_send_dao_buf));
rpl_send_dao_buf->rpl_instanceid = my_dodag->instance->id;
rpl_send_dao_buf->k_d_flags = 0x00;
rpl_send_dao_buf->dao_sequence = my_dodag->dao_seq;
uint16_t opt_len = 0;
rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN);
/* add own address */
rpl_send_opt_target_buf->type = RPL_OPT_TARGET;
rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN;
rpl_send_opt_target_buf->flags = 0x00;
rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN;
memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t));
/* 18+2=20 bytes for one target-option */
opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN;
/* add parent */
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT;
rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN;
rpl_send_opt_transit_buf->e_flags = 0x00;
rpl_send_opt_transit_buf->path_control = 0x00;
rpl_send_opt_transit_buf->path_sequence = 0x00;
rpl_send_opt_transit_buf->path_lifetime = lifetime;
memcpy(&rpl_send_opt_transit_buf->parent, rpl_get_my_preferred_parent(), sizeof(ipv6_addr_t));
DEBUGF("My pref parent is:%s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN,
rpl_get_my_preferred_parent()));
DEBUGF("Send DAO with instance %04X and sequence %04X to %s\n",
rpl_send_dao_buf->rpl_instanceid, rpl_send_dao_buf->dao_sequence,
ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN, destination));
/* 4+2=6 byte for one transit-option */
opt_len += RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN;
uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len;
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void rpl_send_DIS_mode(ipv6_addr_t *destination)
{
icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL;
icmp_send_buf->code = ICMP_CODE_DIS;
rpl_send_dis_buf = get_rpl_send_dis_buf();
uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN;
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination)
{
/* This is just for suppressing the mandatory unused parameter warning */
(void) destination;
/* A DAO-ACK would require a complete source routing header. Since DAO-ACKS are optional, this one is suppressed in
* non-storing mode.
*/
return;
}
void rpl_recv_DIO_mode(void)
{
/* If i am root, there is no need for managing DIOs. */
if (rpl_is_root()) {
return;
}
ipv6_buf = get_rpl_ipv6_buf();
DEBUGF("DIO received from %s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->srcaddr));
rpl_dio_buf = get_rpl_dio_buf();
DEBUGF("instance %04X rank %04X\n", rpl_dio_buf->rpl_instanceid, byteorder_ntohs(rpl_dio_buf->rank));
int len = DIO_BASE_LEN;
rpl_instance_t *dio_inst = rpl_get_instance(rpl_dio_buf->rpl_instanceid);
rpl_instance_t *my_inst = rpl_get_my_instance();
if (dio_inst == NULL) {
if (my_inst != NULL) {
/* already part of a DODAG -> impossible to join other instance */
DEBUGF("Not joining another DODAG!\n");
return;
}
dio_inst = rpl_new_instance(rpl_dio_buf->rpl_instanceid);
if (dio_inst == NULL) {
DEBUGF("Failed to create a new RPL instance!\n");
return;
}
}
else if (my_inst == NULL) {
DEBUGF("Not joined an instance yet\n");
}
else if (my_inst->id != dio_inst->id) {
/* TODO: Add support support for several instances. */
/* At the moment, nodes can only join one instance, this is
* the instance they join first.
* Instances cannot be switched later on. */
DEBUGF("Ignoring instance - we are %d and got %d\n", my_inst->id, dio_inst->id);
return;
}
rpl_dodag_t dio_dodag;
memset(&dio_dodag, 0, sizeof(dio_dodag));
memcpy(&dio_dodag.dodag_id, &rpl_dio_buf->dodagid, sizeof(dio_dodag.dodag_id));
dio_dodag.dtsn = rpl_dio_buf->dtsn;
dio_dodag.mop = ((rpl_dio_buf->g_mop_prf >> RPL_MOP_SHIFT) & RPL_SHIFTED_MOP_MASK);
dio_dodag.grounded = rpl_dio_buf->g_mop_prf >> RPL_GROUNDED_SHIFT;
dio_dodag.prf = (rpl_dio_buf->g_mop_prf & RPL_PRF_MASK);
dio_dodag.version = rpl_dio_buf->version_number;
dio_dodag.instance = dio_inst;
uint8_t has_dodag_conf_opt = 0;
/* Parse until all options are consumed.
* ipv6_buf->length contains the packet length minus ipv6 and
* icmpv6 header, so only ICMPV6_HDR_LEN remains to be
* subtracted. */
while (len < (NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN)) {
DEBUGF("parsing DIO options\n");
rpl_opt_buf = get_rpl_opt_buf(len);
switch (rpl_opt_buf->type) {
case (RPL_OPT_PAD1): {
len += 1;
break;
}
case (RPL_OPT_PADN): {
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_ROUTE_INFO): {
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_DODAG_CONF): {
has_dodag_conf_opt = 1;
if (rpl_opt_buf->length != RPL_OPT_DODAG_CONF_LEN) {
DEBUGF("DODAG configuration is malformed.\n");
/* error malformed */
return;
}
rpl_opt_dodag_conf_buf = get_rpl_opt_dodag_conf_buf(len);
dio_dodag.dio_interval_doubling = rpl_opt_dodag_conf_buf->DIOIntDoubl;
dio_dodag.dio_min = rpl_opt_dodag_conf_buf->DIOIntMin;
dio_dodag.dio_redundancy = rpl_opt_dodag_conf_buf->DIORedun;
dio_dodag.maxrankincrease = byteorder_ntohs(rpl_opt_dodag_conf_buf->MaxRankIncrease);
dio_dodag.minhoprankincrease = byteorder_ntohs(rpl_opt_dodag_conf_buf->MinHopRankIncrease);
dio_dodag.default_lifetime = rpl_opt_dodag_conf_buf->default_lifetime;
dio_dodag.lifetime_unit = byteorder_ntohs(rpl_opt_dodag_conf_buf->lifetime_unit);
dio_dodag.of = (struct rpl_of_t *) rpl_get_of_for_ocp(byteorder_ntohs(rpl_opt_dodag_conf_buf->ocp));
if (dio_dodag.of == NULL) {
DEBUGF("[Error] OCP from DIO is not supported! ocp: %x\n",
byteorder_ntohs(rpl_opt_dodag_conf_buf->ocp));
return;
}
len += RPL_OPT_DODAG_CONF_LEN_WITH_OPT_LEN;
break;
}
case (RPL_OPT_PREFIX_INFO): {
if (rpl_opt_buf->length != RPL_OPT_PREFIX_INFO_LEN) {
/* error malformed */
return;
}
len += RPL_OPT_PREFIX_INFO_LEN_WITH_OPT_LEN;
break;
}
default:
DEBUGF("[Error] Unsupported DIO option\n");
return;
}
}
DEBUGF("Handle packet content.\n");
/* handle packet content... */
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if (my_dodag == NULL) {
if (!has_dodag_conf_opt) {
DEBUGF("send DIS\n");
rpl_send_DIS(&ipv6_buf->srcaddr);
}
if (byteorder_ntohs(rpl_dio_buf->rank) < ROOT_RANK) {
DEBUGF("DIO with Rank < ROOT_RANK\n");
}
if (dio_dodag.mop != RPL_DEFAULT_MOP) {
i_am_leaf = 1;
DEBUGF("Will join DODAG as LEAF\n");
rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, INFINITE_RANK);
DEBUGF("Joined DODAG\n");
DEBUGF("The DODAG-root is: %s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN,
&dio_dodag.dodag_id));
}
if (dio_dodag.of == NULL) {
DEBUGF("Required objective function not supported\n");
}
if (byteorder_ntohs(rpl_dio_buf->rank) != INFINITE_RANK) {
DEBUGF("Will join DODAG\n");
rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, byteorder_ntohs(rpl_dio_buf->rank));
DEBUGF("Joined DODAG\n");
DEBUGF("The DODAG-root is: %s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN,
&dio_dodag.dodag_id));
}
else {
DEBUGF("Cannot access DODAG because of DIO with infinite rank\n");
}
return;
}
if (rpl_equal_id(&my_dodag->dodag_id, &dio_dodag.dodag_id)) {
/* "our" DODAG */
if (RPL_COUNTER_GREATER_THAN(dio_dodag.version, my_dodag->version)) {
if (my_dodag->my_rank == ROOT_RANK) {
DEBUGF("[Warning] Inconsistent Dodag Version\n");
my_dodag->version = RPL_COUNTER_INCREMENT(dio_dodag.version);
trickle_reset_timer(&my_dodag->trickle);
}
else {
DEBUGF("my dodag has no preferred_parent yet - seems to be odd since I have a parent.\n");
rpl_global_repair(&dio_dodag, &ipv6_buf->srcaddr, byteorder_ntohs(rpl_dio_buf->rank));
}
return;
}
else if (RPL_COUNTER_GREATER_THAN(my_dodag->version, dio_dodag.version)) {
trickle_reset_timer(&my_dodag->trickle);
return;
}
}
/* version matches, DODAG matches */
if (byteorder_ntohs(rpl_dio_buf->rank) == INFINITE_RANK) {
trickle_reset_timer(&my_dodag->trickle);
}
/* We are root, all done!*/
if (my_dodag->my_rank == ROOT_RANK) {
if (byteorder_ntohs(rpl_dio_buf->rank) != INFINITE_RANK) {
trickle_increment_counter(&my_dodag->trickle);
}
return;
}
/********************* Parent Handling *********************/
DEBUGF("Parent handling.\n");
rpl_parent_t *parent;
parent = rpl_find_parent(&ipv6_buf->srcaddr);
if (parent == NULL) {
/* add new parent candidate */
parent = rpl_new_parent(my_dodag, &ipv6_buf->srcaddr, byteorder_ntohs(rpl_dio_buf->rank));
if (parent == NULL) {
return;
}
}
else {
/* DIO OK */
trickle_increment_counter(&my_dodag->trickle);
}
/* update parent rank */
parent->rank = byteorder_ntohs(rpl_dio_buf->rank);
rpl_parent_update(parent);
if (my_dodag->my_preferred_parent == NULL) {
DEBUGF("My dodag has no preferred_parent yet - seems to be odd since I have a parent.\n");
}
else if (rpl_equal_id(&parent->addr, &my_dodag->my_preferred_parent->addr) &&
(parent->dtsn != rpl_dio_buf->dtsn)) {
rpl_delay_dao(my_dodag);
}
parent->dtsn = rpl_dio_buf->dtsn;
DEBUGF("Finished DIO-handling.\n");
}
void rpl_recv_DAO_mode(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if (my_dodag == NULL) {
DEBUGF("[Error] got DAO although not a DODAG.\n");
return;
}
if (!i_am_root) {
DEBUGF("[Error] something went wrong - got a DAO.\n");
return;
}
ipv6_buf = get_rpl_ipv6_buf();
rpl_dao_buf = get_rpl_dao_buf();
int len = DAO_BASE_LEN;
uint8_t increment_seq = 0;
while (len < (NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN)) {
rpl_opt_buf = get_rpl_opt_buf(len);
switch (rpl_opt_buf->type) {
case (RPL_OPT_PAD1): {
len += 1;
break;
}
case (RPL_OPT_PADN): {
len += (rpl_opt_buf->length + RPL_OPT_LEN);
break;
}
case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += (rpl_opt_buf->length + RPL_OPT_LEN);
break;
}
case (RPL_OPT_TARGET): {
rpl_opt_target_buf = get_rpl_opt_target_buf(len);
if (rpl_opt_target_buf->prefix_length != RPL_DODAG_ID_LEN) {
DEBUGF("prefixes are not supported yet\n");
break;
}
len += (rpl_opt_target_buf->length + RPL_OPT_LEN);
rpl_opt_transit_buf = get_rpl_opt_transit_buf(len);
if (rpl_opt_transit_buf->type != RPL_OPT_TRANSIT) {
DEBUGF("[Error] - no transit information for target option type = %d\n",
rpl_opt_transit_buf->type);
break;
}
len += (rpl_opt_transit_buf->length + RPL_OPT_LEN);
/* route lifetime seconds = (DAO lifetime) * (Unit Lifetime) */
DEBUGF("Target: %s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN,
&rpl_opt_target_buf->target));
DEBUGF("Transit: %s\n", ipv6_addr_to_str(addr_str_mode, IPV6_MAX_ADDR_STR_LEN,
&rpl_opt_transit_buf->parent));
#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) && (RPL_MAX_ROUTING_ENTRIES != 0)
rpl_add_srh_entry(&rpl_opt_target_buf->target, &rpl_opt_transit_buf->parent,
rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit);
#endif
increment_seq = 1;
break;
}
case (RPL_OPT_TRANSIT): {
len += (rpl_opt_buf->length + RPL_OPT_LEN);
break;
}
case (RPL_OPT_TARGET_DESC): {
len += (rpl_opt_buf->length + RPL_OPT_LEN);
break;
}
default:
return;
}
}
if (increment_seq) {
RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
rpl_delay_dao(my_dodag);
}
}
void rpl_recv_DIS_mode(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if (my_dodag == NULL) {
return;
}
ipv6_buf = get_rpl_ipv6_buf();
rpl_dis_buf = get_rpl_dis_buf();
int len = DIS_BASE_LEN;
while (len < (NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN)) {
rpl_opt_buf = get_rpl_opt_buf(len);
switch (rpl_opt_buf->type) {
case (RPL_OPT_PAD1): {
len += 1;
break;
}
case (RPL_OPT_PADN): {
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_SOLICITED_INFO): {
len += RPL_OPT_SOLICITED_INFO_LEN;
/* extract and check */
if (rpl_opt_buf->length != RPL_OPT_SOLICITED_INFO_LEN) {
/* error malformed */
return;
}
rpl_opt_solicited_buf = get_rpl_opt_solicited_buf(len);
if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_I_MASK) {
if (my_dodag->instance->id != rpl_opt_solicited_buf->rplinstanceid) {
return;
}
}
if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_D_MASK) {
if (!rpl_equal_id(&my_dodag->dodag_id, &rpl_opt_solicited_buf->dodagid)) {
return;
}
}
if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_V_MASK) {
if (my_dodag->version != rpl_opt_solicited_buf->version) {
return;
}
}
break;
}
default:
return;
}
}
rpl_send_DIO(&ipv6_buf->srcaddr);
}
void rpl_recv_dao_ack_mode(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if (my_dodag == NULL) {
return;
}
rpl_dao_ack_buf = get_rpl_dao_ack_buf();
if (rpl_dao_ack_buf->rpl_instanceid != my_dodag->instance->id) {
return;
}
if (rpl_dao_ack_buf->status != 0) {
return;
}
rpl_dao_ack_received(my_dodag);
}
/* obligatory for each mode. normally not modified */
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header)
{
uint8_t *p_ptr;
ipv6_send_buf = get_rpl_send_ipv6_buf();
p_ptr = get_rpl_send_payload_buf(ipv6_ext_hdr_len);
DEBUGF("Trying to send to destination: %s\n", ipv6_addr_to_str(addr_str_mode,
IPV6_MAX_ADDR_STR_LEN, destination));
ipv6_send_buf->version_trafficclass = IPV6_VER;
ipv6_send_buf->trafficclass_flowlabel = 0;
ipv6_send_buf->flowlabel = 0;
ipv6_send_buf->nextheader = next_header;
ipv6_send_buf->hoplimit = MULTIHOP_HOPLIMIT;
ipv6_send_buf->length = HTONS(p_len);
memcpy(&(ipv6_send_buf->destaddr), destination, 16);
ipv6_net_if_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
icmp_send_buf->checksum = icmpv6_csum(ipv6_send_buf, icmp_send_buf);
/* The packet was "assembled" in rpl_%mode%.c. Therefore rpl_send_buf was used.
* Therefore memcpy is not needed because the payload is at the
* right memory location already. */
if (p_ptr != payload) {
memcpy(p_ptr, payload, p_len);
}
ipv6_send_packet(ipv6_send_buf, NULL);
}

View File

@ -1,3 +0,0 @@
MODULE := rpl
INCLUDES += -I$(RIOTBASE)/sys/net/routing/rpl
include $(RIOTBASE)/Makefile.base