Merge pull request #1404 from fabianbrandt/rpl_nonstoring

Introduction of RPL non-storing mode
This commit is contained in:
Oleg Hahm 2014-11-28 00:29:45 +01:00
commit 7f9fb2bea3
32 changed files with 1967 additions and 398 deletions

View File

@ -6,6 +6,17 @@
* directory for more details.
*/
/**
* @ingroup rpl
* @{
* @file etx_beaconing.h
*
* Header-file, which includes all constants and functions used for ETX-based beaconing.
*
* @author Stephan Arndt <arndtste@zedat.fu-berlin.de>
* @}
*/
#ifndef ETX_BEACONING_H_
#define ETX_BEACONING_H_
#include <stdint.h>

View File

@ -7,21 +7,18 @@
*/
/**
* @defgroup net_rpl RPL
* @ingroup net
* @brief Routing Protocol for Low power and Lossy Networks
*
* Header which includes all core RPL-functions. Normally it shouldn't be necessary to
* modify this file.
*
* @ingroup rpl
* @{
*
* @file rpl.h
* @brief RPL header. Declaration of global variables and functions needed for
* core functionality of RPL.
* core functionality of RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
* Header which includes all core RPL-functions. Normally it shouldn't be necessary to
* modify this file.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
*/
#ifndef __RPL_H
@ -44,11 +41,11 @@ extern "C" {
#define CC1100_RADIO_MODE CC1100_MODE_WOR
#define RPL_PKT_RECV_BUF_SIZE 16
#define RPL_PROCESS_STACKSIZE KERNEL_CONF_STACKSIZE_DEFAULT
#define RPL_PROCESS_STACKSIZE KERNEL_CONF_STACKSIZE_MAIN
/* global variables */
extern rpl_routing_entry_t rpl_routing_table[RPL_MAX_ROUTING_ENTRIES];
extern kernel_pid_t rpl_process_pid;
extern uint8_t rpl_max_routing_entries;
/* needed for receiving messages with ICMP-code 155. Received via IPC from ipv6.c */
extern mutex_t rpl_recv_mutex;
@ -95,7 +92,7 @@ void rpl_init_root(void);
* @param[in] destination IPv6-address of the destination of the DIO. Should be a direct neighbor.
*
*/
void send_DIO(ipv6_addr_t *destination);
void rpl_send_DIO(ipv6_addr_t *destination);
/**
* @brief Sends a DAO-message to a given destination
@ -110,7 +107,7 @@ void send_DIO(ipv6_addr_t *destination);
* @param[in] start_index Describes whether a DAO must be split because of too many routing entries.
*
*/
void send_DAO(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);
/**
* @brief Sends a DIS-message to a given destination
@ -122,7 +119,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
* @param[in] destination IPv6-address of the destination of the DIS. Should be a direct neighbor or multicast-address.
*
*/
void send_DIS(ipv6_addr_t *destination);
void rpl_send_DIS(ipv6_addr_t *destination);
/**
* @brief Sends a DAO acknowledgment-message to a given destination
@ -134,7 +131,7 @@ void send_DIS(ipv6_addr_t *destination);
* @param[in] destination IPv6-address of the destination of the DAO_ACK. Should be a direct neighbor.
*
*/
void send_DAO_ACK(ipv6_addr_t *destination);
void rpl_send_DAO_ACK(ipv6_addr_t *destination);
/**
* @brief Receives a DIO message
@ -143,7 +140,7 @@ void send_DAO_ACK(ipv6_addr_t *destination);
* this function just calls the receiving function of the chosen mode.
*
*/
void recv_rpl_DIO(void);
void rpl_recv_DIO(void);
/**
* @brief Receives a DAO message
@ -152,7 +149,7 @@ void recv_rpl_DIO(void);
* this function just calls the receiving function of the chosen mode.
*
*/
void recv_rpl_DAO(void);
void rpl_recv_DAO(void);
/**
* @brief Receives a DIS message
@ -161,7 +158,7 @@ void recv_rpl_DAO(void);
* this function just calls the receiving function of the chosen mode.
*
*/
void recv_rpl_DIS(void);
void rpl_recv_DIS(void);
/**
* @brief Receives a DAO acknowledgment message
@ -170,7 +167,7 @@ void recv_rpl_DIS(void);
* this function just calls the receiving function of the chosen mode.
*
*/
void recv_rpl_DAO_ACK(void);
void rpl_recv_DAO_ACK(void);
/**
* @brief Initialization of RPl-root.
@ -255,9 +252,64 @@ void rpl_clear_routing_table(void);
* */
rpl_routing_entry_t *rpl_get_routing_table(void);
/**
* @brief Returns the network status of the actual node
*
* @return 1 if root, 0 otherwise
*
* */
uint8_t rpl_is_root(void);
#if RPL_DEFAULT_MOP == RPL_NON_STORING_MODE
/**
* @brief Adds one pair of child and its parent to the source routing table
*
* @deprecated This function is obsolete and will be removed shortly. This will be replaced with a
* common routing information base.
*
* @param[in] child Child IPv6-address
* @param[in] parent Parent IPv6-address
* @param[in] lifetime Lifetime of the relation
*
* */
void rpl_add_srh_entry(ipv6_addr_t *child, ipv6_addr_t *parent, uint16_t lifetime);
/**
* @brief Constructs a source routing header based on an original IPv6-header
*
* @param[in] act_ipv6_hdr Pointer to original IPv6-packet header
* @return Source routing header or NULL
*
* */
ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr);
/**
* @brief Manages sending an SRH-header integrated in an original IPv6-package to the next hop.
*
* @param[in] buf Pointer to original payload
* @param[in] len Length of the original payload
* @param[in] src Original source address
* @param[in] dest Destination address
* @param[in] srh_header Pre-build source routing header
* @param[in] srh_length Length of the pre-built source routing header
* @return Status of sending progress
* */
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);
/**
* @brief Sends IPC-message to the service, which is indicated by the next-header-field in the source routing header
*
* @param[in] ipv6_header Actual IPv6-header
* @return IPv6-address of the next-hop. Is NULL on error occurrence.
*
* */
void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nextheader);
#ifdef __cplusplus
}
#endif
#endif
/** @} */
#endif /* __RPL_H */

View File

@ -1,17 +1,21 @@
/**
* RPL data structs
*
/*
* 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
* 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_config.h
* @brief RPL Config
* @author Eric Engel <eric.engel@fu-berlin.de>
*
* @file rpl_config.h
* @brief RPL Config
*
* Configuration file, which defines all environmental variables for RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/
@ -42,11 +46,11 @@ extern "C" {
#define DAO_ACK_LEN 4
#define DAO_ACK_D_LEN 24
#define RPL_OPT_LEN 2
#define RPL_OPT_DODAG_CONF_LEN 14
#define RPL_OPT_PREFIX_INFO_LEN 30
#define RPL_OPT_SOLICITED_INFO_LEN 19
#define RPL_OPT_TARGET_LEN 18
#define RPL_OPT_TRANSIT_LEN 4
#define RPL_OPT_DODAG_CONF_LEN 16
#define RPL_OPT_PREFIX_INFO_LEN 32
#define RPL_OPT_SOLICITED_INFO_LEN 21
#define RPL_OPT_TARGET_LEN 20
#define RPL_OPT_TRANSIT_LEN 22
/* message options */
#define RPL_OPT_PAD1 0
@ -68,7 +72,7 @@ extern "C" {
static inline uint8_t RPL_COUNTER_INCREMENT(uint8_t counter)
{
return (counter > RPL_COUNTER_LOWER_REGION ? (counter == RPL_COUNTER_MAX ? counter=0 : ++counter) : (counter == RPL_COUNTER_LOWER_REGION ? counter=0 : ++counter));
return (counter > RPL_COUNTER_LOWER_REGION ? (counter == RPL_COUNTER_MAX ? counter = 0 : ++counter) : (counter == RPL_COUNTER_LOWER_REGION ? counter = 0 : ++counter));
}
static inline bool RPL_COUNTER_IS_INIT(uint8_t counter)
@ -76,14 +80,14 @@ static inline bool RPL_COUNTER_IS_INIT(uint8_t counter)
return (counter > RPL_COUNTER_LOWER_REGION);
}
static inline bool RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A,uint8_t B)
static inline bool RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
{
return (((A<B) && (RPL_COUNTER_LOWER_REGION + 1 - B + A < RPL_COUNTER_SEQ_WINDOW)) || ((A > B) && (A-B < RPL_COUNTER_SEQ_WINDOW)));
return (((A < B) && (RPL_COUNTER_LOWER_REGION + 1 - B + A < RPL_COUNTER_SEQ_WINDOW)) || ((A > B) && (A - B < RPL_COUNTER_SEQ_WINDOW)));
}
static inline bool RPL_COUNTER_GREATER_THAN(uint8_t A,uint8_t B)
static inline bool RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
{
return ((A>RPL_COUNTER_LOWER_REGION) ? ((B > RPL_COUNTER_LOWER_REGION ) ? RPL_COUNTER_GREATER_THAN_LOCAL(A,B) : 0): (( B>RPL_COUNTER_LOWER_REGION ) ? 1: RPL_COUNTER_GREATER_THAN_LOCAL(A,B)));
return ((A > RPL_COUNTER_LOWER_REGION) ? ((B > RPL_COUNTER_LOWER_REGION) ? RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) : ((B > RPL_COUNTER_LOWER_REGION) ? 1 : RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
}
/* Node Status */
@ -123,7 +127,10 @@ static inline bool RPL_COUNTER_GREATER_THAN(uint8_t A,uint8_t B)
#define RPL_MAX_DODAGS 3
#define RPL_MAX_INSTANCES 1
#define RPL_MAX_PARENTS 5
#define RPL_MAX_ROUTING_ENTRIES 128
#define RPL_MAX_ROUTING_ENTRIES_STORING 128
#define RPL_MAX_ROUTING_ENTRIES_NON_STORING 128
#define RPL_MAX_SRH_PATH_LENGTH 10;
#define RPL_SRH_ENTRIES 15
#define RPL_ROOT_RANK 256
#define RPL_DEFAULT_LIFETIME 0xff
#define RPL_LIFETIME_UNIT 2

View File

@ -1,6 +1,4 @@
/**
* RPL dodag prototypes
*
/*
* Copyright (C) 2013, 2014 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser
@ -9,9 +7,13 @@
*
* @ingroup rpl
* @{
* @file rpl_dodag.h
* @brief RPL dodag header
* @author Eric Engel <eric.engel@fu-berlin.de>
*
* @file rpl_dodag.h
* @brief RPL DODAG header
*
* Header file, which defines all public known DODAG-related functions for RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/

View File

@ -0,0 +1,162 @@
/*
* 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. Because send-functions are wrapped by a mutex in rpl.c, the same
* mutex applies here.
*
* @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

@ -7,20 +7,18 @@
*/
/**
* @defgroup net_rpl RPL
* @ingroup net
* @brief Routing Protocol for Low power and Lossy Networks
*
* 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.
*
* @{
*
* @file rpl_mode.h
* @brief RPL storing-mode header
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
* 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
@ -62,7 +60,19 @@ void rpl_init_mode(ipv6_addr_t *my_ipv6_address);
* @param[in] destination IPv6-address of the destination of the DIO. Should be a direct neighbor or multicast address.
*
*/
void send_DIO_mode(ipv6_addr_t *destination);
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
@ -75,7 +85,7 @@ void send_DIO_mode(ipv6_addr_t *destination);
* @param[in] start_index Describes whether a DAO must be split because of too many routing entries.
*
*/
void send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index);
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
@ -85,7 +95,7 @@ void send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_life
* @param[in] destination IPv6-address of the destination of the DIS. Should be a direct neighbor.
*
*/
void send_DIS_mode(ipv6_addr_t *destination);
void rpl_send_DIS_mode(ipv6_addr_t *destination);
/**
* @brief Sends a DAO acknowledgment-message to a given destination
@ -95,7 +105,7 @@ void send_DIS_mode(ipv6_addr_t *destination);
* @param[in] destination IPv6-address of the destination of the DAO_ACK. Should be a direct neighbor.
*
*/
void send_DAO_ACK_mode(ipv6_addr_t *destination);
void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination);
/**
* @brief Receives a DIO message
@ -103,7 +113,7 @@ void send_DAO_ACK_mode(ipv6_addr_t *destination);
* This function handles receiving a DIO message in any mode .
*
*/
void recv_rpl_DIO_mode(void);
void rpl_recv_DIO_mode(void);
/**
* @brief Receives a DAO message
@ -111,7 +121,7 @@ void recv_rpl_DIO_mode(void);
* This function handles receiving a DAO message in any mode.
*
*/
void recv_rpl_DAO_mode(void);
void rpl_recv_DAO_mode(void);
/**
* @brief Receives a DIS message
@ -119,7 +129,7 @@ void recv_rpl_DAO_mode(void);
* This function handles receiving a DIS message in any mode.
*
*/
void recv_rpl_DIS_mode(void);
void rpl_recv_DIS_mode(void);
/**
* @brief Receives a DAO acknowledgment message
@ -127,7 +137,7 @@ void recv_rpl_DIS_mode(void);
* This function handles receiving a DAO_ACK message in any mode.
*
*/
void recv_rpl_dao_ack_mode(void);
void rpl_recv_dao_ack_mode(void);
/**
* @brief Sends a RPL message to a given destination

View File

@ -1,16 +1,19 @@
/**
* RPL data structs
*
/*
* Copyright (C) 2013 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_structs.h
* @brief RPL data structs
*
* File, which defines all structs used by RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/
@ -116,6 +119,7 @@ typedef struct __attribute__((packed)) {
uint8_t path_control;
uint8_t path_sequence;
uint8_t path_lifetime;
ipv6_addr_t parent;
} rpl_opt_transit_t;
struct rpl_dodag_t;
@ -137,7 +141,6 @@ typedef struct {
uint8_t id;
uint8_t used;
uint8_t joined;
} rpl_instance_t;
//Node-internal representation of a DODAG, with nodespecific information

View File

@ -65,6 +65,12 @@ extern "C" {
*/
#define IPV6_PROTO_NUM_UDP (17)
/**
* @brief Next header value for source routing
* @see <a href="http://tools.ietf.org/html/rfc5095#section-1">
*/
#define IPV6_PROTO_NUM_SRH (43)
/**
* @brief L4 protocol number for ICMPv6.
*/
@ -103,6 +109,7 @@ ipv6_hdr_t *ipv6_get_buf(void);
* @param[in] next_header Next header ID of payload.
* @param[in] payload Payload of the packet.
* @param[in] payload_length Length of payload.
* @param[in] next_hop Optional next_hop. May be NULL if not provided at call.
*
* @return payload_length : on success
* -1 : if no route to the given dest could be obtained
@ -111,7 +118,7 @@ ipv6_hdr_t *ipv6_get_buf(void);
* is going to try to find a route
*/
int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
const uint8_t *payload, uint16_t payload_length);
const uint8_t *payload, uint16_t payload_length, ipv6_addr_t *next_hop);
/**
* @brief Send an IPv6 packet defined by its header.
@ -119,6 +126,8 @@ int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
* @param[in] packet Pointer to an prepared IPv6 packet header.
* The payload is expected directly after the
* packet.
* @param[in] next_hop Optional next-hop address. If NULL, than the function tries
* to find it by methods of the active routing protocol.
*
* @return length of payload : on success
* -1 : if no route to the given dest could be obtained
@ -126,7 +135,7 @@ int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
* In case of reactive routing: routing is going
* to try to find a route
*/
int ipv6_send_packet(ipv6_hdr_t *packet);
int ipv6_send_packet(ipv6_hdr_t *packet, ipv6_addr_t *next_hop);
/**
* @brief Determines if node is a router.
@ -531,6 +540,14 @@ void ipv6_net_if_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest);
*/
void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t *dest));
/**
* @brief Registers a function that decides if a node in a RPL-network is actually the
* root and therefore a source routing header should be integrated.
* Only used in RPL non-storing mode by now.
*
*/
void ipv6_iface_set_srh_indicator(uint8_t (*srh_indi)(void));
/**
* @brief Calculates the IPv6 upper-layer checksum.
*

View File

@ -85,8 +85,10 @@ typedef struct __attribute__((packed)) {
uint8_t routing_type; /**< identify srh-variant. */
uint8_t segments_left; /**< remaining route segments before reaching destination. */
unsigned int cmpri:4, cmpre:4; /**< 4+4 bit, expressing prefix octets from each/last segment. */
unsigned long pad:4; /**< number of octets used for padding after adresses. */
unsigned long reserved:20; /**< reserved. Set to 0. */
unsigned pad :4; /**< number of octets used for padding after adresses. */
unsigned reserved :10; /**< reserved. Set to 0. */
unsigned reserved2 :10; /**< reserved. Set to 0. */
ipv6_addr_t route[];
} ipv6_srh_t;
/**

View File

@ -48,7 +48,7 @@ void demultiplex(border_packet_t *packet)
switch (l3_header_buf->ethertype) {
case (BORDER_ETHERTYPE_IPV6): {
ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
break;
}

View File

@ -274,7 +274,7 @@ void icmpv6_send_echo_request(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq,
id, seq, data_len, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, uint8_t *data, size_t data_len)
@ -313,7 +313,7 @@ void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, ui
id, seq, data_len, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
/* send router solicitation message - RFC4861 section 4.1 */
@ -370,7 +370,7 @@ void icmpv6_send_router_sol(uint8_t sllao)
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
void recv_echo_req(void)
@ -699,7 +699,7 @@ void icmpv6_send_router_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
void recv_rtr_adv(void)
@ -990,7 +990,7 @@ void icmpv6_send_neighbor_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
void recv_nbr_sol(void)
@ -1264,7 +1264,7 @@ void icmpv6_send_neighbor_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *t
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
void recv_nbr_adv(void)
@ -1484,7 +1484,7 @@ void icmpv6_send_parameter_prob(ipv6_addr_t *src, ipv6_addr_t *dest,
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipv6_buf->destaddr));
#endif
ipv6_send_packet(ipv6_buf);
ipv6_send_packet(ipv6_buf, NULL);
}
//------------------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
/**
/*
* IPv6 implementation
*
* Copyright (C) 2013 INRIA.
@ -54,8 +54,10 @@ uint8_t *nextheader;
kernel_pid_t udp_packet_handler_pid = KERNEL_PID_UNDEF;
kernel_pid_t tcp_packet_handler_pid = KERNEL_PID_UNDEF;
static volatile kernel_pid_t _rpl_process_pid = KERNEL_PID_UNDEF;
ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t *) = 0;
static volatile kernel_pid_t _rpl_process_pid = KERNEL_PID_UNDEF;
ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t *);
uint8_t (*ip_srh_indicator)(void);
static ipv6_net_if_ext_t ipv6_net_if_ext[NET_IF_MAX];
static ipv6_net_if_addr_t ipv6_net_if_addr_buffer[IPV6_NET_IF_ADDR_BUFFER_LEN];
@ -67,27 +69,28 @@ static uint8_t default_hop_limit = MULTIHOP_HOPLIMIT;
/* registered upper layer threads */
kernel_pid_t sixlowip_reg[SIXLOWIP_MAX_REGISTERED];
int ipv6_send_packet(ipv6_hdr_t *packet)
int ipv6_send_packet(ipv6_hdr_t *packet, ipv6_addr_t *next_hop)
{
uint16_t length = IPV6_HDR_LEN + NTOHS(packet->length);
ndp_neighbor_cache_t *nce;
DEBUGF("Got a packet to send to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &packet->destaddr));
ipv6_net_if_get_best_src_addr(&packet->srcaddr, &packet->destaddr);
if (next_hop == NULL) {
DEBUGF("Got a packet to send to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &packet->destaddr));
ipv6_net_if_get_best_src_addr(&packet->srcaddr, &packet->destaddr);
}
if (!ipv6_addr_is_multicast(&packet->destaddr) &&
ndp_addr_is_on_link(&packet->destaddr)) {
if (!ipv6_addr_is_multicast(&packet->destaddr)
&& ndp_addr_is_on_link(&packet->destaddr)) {
/* not multicast, on-link */
nce = ndp_get_ll_address(&packet->destaddr);
if (nce == NULL || sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len,
(uint8_t *)packet,
length) < 0) {
if (nce == NULL
|| sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len, (uint8_t *) packet, length) < 0) {
/* XXX: this is wrong, but until ND does work correctly,
* this is the only way (aka the old way)*/
uint16_t raddr = NTOHS(packet->destaddr.uint16[7]);
sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *)packet, length);
sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *) packet, length);
/* return -1; */
}
@ -98,31 +101,49 @@ int ipv6_send_packet(ipv6_hdr_t *packet)
if (ipv6_addr_is_multicast(&packet->destaddr)) {
/* if_id will be ignored */
uint16_t addr = 0xffff;
return sixlowpan_lowpan_sendto(0, &addr, 2, (uint8_t *)packet,
return sixlowpan_lowpan_sendto(0, &addr, 2, (uint8_t *) packet,
length);
}
if (ip_get_next_hop == NULL) {
return -1;
if (next_hop == NULL) {
DEBUG("Trying to find the next hop for %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &packet->destaddr));
ipv6_addr_t *dest = ip_get_next_hop(&packet->destaddr);
if (ip_get_next_hop == NULL) {
return -1;
}
if (dest == NULL) {
return -1;
}
nce = ndp_get_ll_address(dest);
if (nce == NULL
|| sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len, (uint8_t *) packet, length) < 0) {
/* XXX: this is wrong, but until ND does work correctly,
* this is the only way (aka the old way)*/
uint16_t raddr = dest->uint16[7];
sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *) packet,
length);
/* return -1; */
}
}
else {
DEBUGF("Set destination based on next-hop: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, next_hop));
nce = ndp_get_ll_address(next_hop);
DEBUG("Trying to find the next hop for %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &packet->destaddr));
ipv6_addr_t *dest = ip_get_next_hop(&packet->destaddr);
if (dest == NULL) {
return -1;
}
nce = ndp_get_ll_address(dest);
if (nce == NULL || sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len,
(uint8_t *)packet, length) < 0) {
/* XXX: this is wrong, but until ND does work correctly,
* this is the only way (aka the old way)*/
uint16_t raddr = dest->uint16[7];
sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *)packet, length);
/* return -1; */
if (nce == NULL
|| sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len, (uint8_t *) packet, length) < 0) {
/* XXX: this is wrong, but until ND does work correctly,
* this is the only way (aka the old way)*/
uint16_t raddr = next_hop->uint16[7];
sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *) packet,
length);
/* return -1; */
}
}
return length;
@ -155,7 +176,7 @@ uint8_t *get_payload_buf(uint8_t ext_len)
}
int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
const uint8_t *payload, uint16_t payload_length)
const uint8_t *payload, uint16_t payload_length, ipv6_addr_t *next_hop)
{
uint8_t *p_ptr;
@ -176,10 +197,8 @@ int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
ipv6_buf->length = HTONS(payload_length);
memcpy(&(ipv6_buf->destaddr), dest, 16);
memcpy(p_ptr, payload, payload_length);
return ipv6_send_packet(ipv6_buf);
return ipv6_send_packet(ipv6_buf, next_hop);
}
void ipv6_set_default_hop_limit(uint8_t hop_limit)
@ -197,8 +216,9 @@ uint8_t ipv6_register_packet_handler(kernel_pid_t pid)
{
uint8_t i;
for (i = 0; ((i < SIXLOWIP_MAX_REGISTERED) && (sixlowip_reg[i] != pid) &&
(sixlowip_reg[i] != 0)); i++) {
for (i = 0;
((i < SIXLOWIP_MAX_REGISTERED) && (sixlowip_reg[i] != pid)
&& (sixlowip_reg[i] != 0)); i++) {
;
}
@ -261,7 +281,7 @@ int icmpv6_demultiplex(const icmpv6_hdr_t *hdr)
if (_rpl_process_pid != KERNEL_PID_UNDEF) {
msg_t m_send;
m_send.content.ptr = (char *) &hdr->code;
m_send.content.ptr = (char *) ipv6_buf;
msg_send(&m_send, _rpl_process_pid);
}
else {
@ -278,8 +298,7 @@ int icmpv6_demultiplex(const icmpv6_hdr_t *hdr)
return 0;
}
uint8_t ipv6_get_addr_match(const ipv6_addr_t *src,
const ipv6_addr_t *dst)
uint8_t ipv6_get_addr_match(const ipv6_addr_t *src, const ipv6_addr_t *dst)
{
uint8_t val = 0, xor;
@ -324,19 +343,24 @@ static int is_our_address(ipv6_addr_t *addr)
int if_id = -1;
int if_counter = -1;
DEBUGF("Is this my addres: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
DEBUGF("Is this my address: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
while ((if_id = net_if_iter_interfaces(if_id)) >= 0) {
ipv6_net_if_ext_t *net_if_ext = ipv6_net_if_get_ext(if_id);
ipv6_net_if_addr_t *myaddr = NULL;
uint8_t prefix = net_if_ext->prefix / 8;
uint8_t suffix = IPV6_ADDR_LEN - prefix;
while ((myaddr = (ipv6_net_if_addr_t *)net_if_iter_addresses(if_id,
while ((myaddr = (ipv6_net_if_addr_t *) net_if_iter_addresses(if_id,
(net_if_addr_t **) &myaddr)) != NULL) {
if_counter++;
DEBUGF("\tCompare with: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, (ipv6_addr_t*) myaddr->addr_data));
if ((ipv6_get_addr_match(myaddr->addr_data, addr) >= net_if_ext->prefix) &&
(memcmp(&addr->uint8[prefix], &myaddr->addr_data->uint8[prefix], suffix) == 0)) {
DEBUGF("\tCompare with: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, (ipv6_addr_t *) myaddr->addr_data));
if ((ipv6_get_addr_match(myaddr->addr_data, addr)
>= net_if_ext->prefix)
&& (memcmp(&addr->uint8[prefix],
&myaddr->addr_data->uint8[prefix], suffix) == 0)) {
DEBUGF("Found my address\n");
return 1;
}
}
@ -346,6 +370,7 @@ static int is_our_address(ipv6_addr_t *addr)
if (if_counter >= 0) {
return 0;
}
return -1;
}
@ -363,7 +388,7 @@ void *ipv6_process(void *arg)
while (1) {
msg_receive(&m_recv_lowpan);
ipv6_buf = (ipv6_hdr_t *)m_recv_lowpan.content.ptr;
ipv6_buf = (ipv6_hdr_t *) m_recv_lowpan.content.ptr;
/* identifiy packet */
nextheader = &ipv6_buf->nextheader;
@ -378,6 +403,7 @@ void *ipv6_process(void *arg)
}
int addr_match = is_our_address(&ipv6_buf->destaddr);
DEBUGF("Did it match? %d\n", addr_match);
/* no address configured for this node so far, exit early */
if (addr_match < 0) {
@ -391,8 +417,9 @@ void *ipv6_process(void *arg)
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
/* checksum test*/
if (ipv6_csum(ipv6_buf, (uint8_t *) icmp_buf, NTOHS(ipv6_buf->length),
IPV6_PROTO_NUM_ICMPV6) != 0xffff) {
if (ipv6_csum(ipv6_buf, (uint8_t *) icmp_buf,
NTOHS(ipv6_buf->length), IPV6_PROTO_NUM_ICMPV6)
!= 0xffff) {
DEBUG("ERROR: wrong checksum\n");
}
@ -424,6 +451,18 @@ void *ipv6_process(void *arg)
break;
}
case (IPV6_PROTO_NUM_SRH): {
if (_rpl_process_pid != KERNEL_PID_UNDEF) {
m_send.content.ptr = (char *) ipv6_buf;
msg_send(&m_send, _rpl_process_pid);
}
else {
DEBUG("INFO: no RPL handler registered\n");
}
break;
}
case (IPV6_PROTO_NUM_NONE): {
DEBUG("INFO: Packet with no Header following the IPv6 Header received.\n");
break;
@ -437,41 +476,57 @@ void *ipv6_process(void *arg)
/* destination is foreign address */
else {
DEBUG("That's not for me, destination is %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &ipv6_buf->destaddr));
packet_length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length);
ndp_neighbor_cache_t *nce;
ipv6_addr_t *dest;
if (ip_get_next_hop == NULL) {
dest = &ipv6_buf->destaddr;
if ((ip_srh_indicator != NULL)
&& (ipv6_buf->nextheader != IPV6_PROTO_NUM_ICMPV6)
&& (ip_srh_indicator() == 1)) {
if (_rpl_process_pid != KERNEL_PID_UNDEF) {
m_send.content.ptr = (char *) ipv6_buf;
msg_send(&m_send, _rpl_process_pid);
}
else {
DEBUG("INFO: no RPL handler registered\n");
}
}
else {
dest = ip_get_next_hop(&ipv6_buf->destaddr);
}
if ((dest == NULL) || ((--ipv6_buf->hoplimit) == 0)) {
DEBUG("!!! Packet not for me, routing handler is set, but I "\
" have no idea where to send or the hop limit is exceeded.\n");
msg_reply(&m_recv_lowpan, &m_send_lowpan);
continue;
}
packet_length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length);
ndp_neighbor_cache_t *nce;
nce = ndp_get_ll_address(dest);
ipv6_addr_t *dest;
/* copy received packet to send buffer */
memcpy(ipv6_get_buf_send(), ipv6_get_buf(), packet_length);
if (ip_get_next_hop == NULL) {
dest = &ipv6_buf->destaddr;
}
else {
dest = ip_get_next_hop(&ipv6_buf->destaddr);
}
/* send packet to node ID derived from dest IP */
if (nce != NULL) {
sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len,
(uint8_t *)ipv6_get_buf_send(),
packet_length);
} else {
/* XXX: this is wrong, but until ND does work correctly,
* this is the only way (aka the old way)*/
uint16_t raddr = dest->uint16[7];
sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *)ipv6_get_buf_send(), packet_length);
if ((dest == NULL) || ((--ipv6_buf->hoplimit) == 0)) {
DEBUG("!!! Packet not for me, routing handler is set, but I "
" have no idea where to send or the hop limit is exceeded.\n");
msg_reply(&m_recv_lowpan, &m_send_lowpan);
continue;
}
nce = ndp_get_ll_address(dest);
/* copy received packet to send buffer */
memcpy(ipv6_get_buf_send(), ipv6_get_buf(), packet_length);
/* send packet to node ID derived from dest IP */
if (nce != NULL) {
sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr,
nce->lladdr_len, (uint8_t *) ipv6_get_buf_send(),
packet_length);
}
else {
/* XXX: this is wrong, but until ND does work correctly,
* this is the only way (aka the old way)*/
uint16_t raddr = dest->uint16[7];
sixlowpan_lowpan_sendto(0, &raddr, 2,
(uint8_t *) ipv6_get_buf_send(), packet_length);
}
}
}
@ -490,8 +545,8 @@ ipv6_net_if_ext_t *ipv6_net_if_get_ext(int if_id)
}
int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr,
ndp_addr_state_t state, uint32_t val_ltime,
uint32_t pref_ltime, uint8_t is_anycast)
ndp_addr_state_t state, uint32_t val_ltime, uint32_t pref_ltime,
uint8_t is_anycast)
{
ipv6_net_if_hit_t hit;
@ -511,16 +566,18 @@ int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr,
}
if (ipv6_net_if_addr_buffer_count < IPV6_NET_IF_ADDR_BUFFER_LEN) {
timex_t valtime = {val_ltime, 0};
timex_t preftime = {pref_ltime, 0};
timex_t valtime = { val_ltime, 0 };
timex_t preftime = { pref_ltime, 0 };
timex_t now;
vtimer_now(&now);
ipv6_addr_t *addr_data = &ipv6_addr_buffer[ipv6_net_if_addr_buffer_count];
ipv6_addr_t *addr_data =
&ipv6_addr_buffer[ipv6_net_if_addr_buffer_count];
memcpy(addr_data, addr, sizeof(ipv6_addr_t));
ipv6_net_if_addr_t *addr_entry = &ipv6_net_if_addr_buffer[ipv6_net_if_addr_buffer_count];
ipv6_net_if_addr_t *addr_entry =
&ipv6_net_if_addr_buffer[ipv6_net_if_addr_buffer_count];
addr_entry->addr_data = addr_data;
addr_entry->addr_len = 128;
@ -541,7 +598,7 @@ int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr,
ipv6_net_if_addr_buffer_count++;
net_if_add_address(if_id, (net_if_addr_t *)addr_entry);
net_if_add_address(if_id, (net_if_addr_t *) addr_entry);
/* Register to Solicited-Node multicast address according to RFC 4291 */
if (is_anycast || !ipv6_addr_is_multicast(addr)) {
@ -567,16 +624,20 @@ ipv6_net_if_hit_t *ipv6_net_if_addr_match(ipv6_net_if_hit_t *hit,
ipv6_net_if_addr_t *addr_entry = NULL;
while ((if_id = net_if_iter_interfaces(if_id)) >= 0) {
while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr_entry) != NULL) {
while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr_entry)
!= NULL) {
if (addr_entry->addr_protocol & NET_IF_L3P_IPV6) {
uint8_t byte_al = addr_entry->addr_len / 8;
uint8_t mask[] = {0x00, 0x80, 0xc0, 0xe0,
0xf0, 0xf8, 0xfc, 0xfe
uint8_t mask[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc,
0xfe
};
if (memcmp(addr_entry->addr_data, addr, byte_al) == 0 &&
(addr_entry->addr_len % 8 == 0 ||
((addr_entry->addr_data->uint8[byte_al] - addr->uint8[byte_al]) & mask[addr_entry->addr_len - (byte_al * 8)]))) {
if (memcmp(addr_entry->addr_data, addr, byte_al) == 0
&& (addr_entry->addr_len % 8 == 0
|| ((addr_entry->addr_data->uint8[byte_al]
- addr->uint8[byte_al])
& mask[addr_entry->addr_len
- (byte_al * 8)]))) {
hit->if_id = if_id;
hit->addr = addr_entry;
return hit;
@ -595,7 +656,8 @@ ipv6_net_if_hit_t *ipv6_net_if_addr_prefix_eq(ipv6_net_if_hit_t *hit,
ipv6_net_if_addr_t *addr_entry = NULL;
while ((if_id = net_if_iter_interfaces(if_id)) >= 0) {
while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr_entry) != NULL) {
while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr_entry)
!= NULL) {
if (addr_entry->addr_protocol & NET_IF_L3P_IPV6) {
if (memcmp(addr_entry->addr_data, &addr, 8) == 0) {
hit->if_id = if_id;
@ -660,9 +722,11 @@ void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix,
}
memcpy(out, prefix, bytes);
if (bytes < 16) {
out->uint8[bytes] = prefix->uint8[bytes] & mask;
}
memset(&(out[bytes + 1]), 0, 15 - bytes);
}
@ -674,15 +738,17 @@ void ipv6_net_if_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest)
ipv6_net_if_addr_t *tmp_addr = NULL;
if (!(ipv6_addr_is_link_local(dest)) && !(ipv6_addr_is_multicast(dest))) {
while ((addr = (ipv6_net_if_addr_t *)net_if_iter_addresses(if_id,
(net_if_addr_t **)&addr))) {
while ((addr = (ipv6_net_if_addr_t *) net_if_iter_addresses(if_id,
(net_if_addr_t **) &addr))) {
if (addr->ndp_state == NDP_ADDR_STATE_PREFERRED) {
if (!ipv6_addr_is_link_local(addr->addr_data) &&
!ipv6_addr_is_multicast(addr->addr_data) &&
!ipv6_addr_is_unique_local_unicast(addr->addr_data)) {
if (!ipv6_addr_is_link_local(addr->addr_data)
&& !ipv6_addr_is_multicast(addr->addr_data)
&& !ipv6_addr_is_unique_local_unicast(
addr->addr_data)) {
uint8_t bmatch = 0;
uint8_t tmp = ipv6_get_addr_match(dest, addr->addr_data);
if (tmp >= bmatch) {
tmp_addr = addr;
}
@ -691,11 +757,11 @@ void ipv6_net_if_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest)
}
}
else {
while ((addr = (ipv6_net_if_addr_t *)net_if_iter_addresses(if_id,
(net_if_addr_t **)&addr))) {
if (addr->ndp_state == NDP_ADDR_STATE_PREFERRED &&
ipv6_addr_is_link_local(addr->addr_data) &&
!ipv6_addr_is_multicast(addr->addr_data)) {
while ((addr = (ipv6_net_if_addr_t *) net_if_iter_addresses(if_id,
(net_if_addr_t **) &addr))) {
if (addr->ndp_state == NDP_ADDR_STATE_PREFERRED
&& ipv6_addr_is_link_local(addr->addr_data)
&& !ipv6_addr_is_multicast(addr->addr_data)) {
tmp_addr = addr;
}
}
@ -710,8 +776,8 @@ void ipv6_net_if_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest)
}
void ipv6_addr_init(ipv6_addr_t *out, uint16_t addr0, uint16_t addr1,
uint16_t addr2, uint16_t addr3, uint16_t addr4,
uint16_t addr5, uint16_t addr6, uint16_t addr7)
uint16_t addr2, uint16_t addr3, uint16_t addr4, uint16_t addr5,
uint16_t addr6, uint16_t addr7)
{
out->uint16[0] = HTONS(addr0);
out->uint16[1] = HTONS(addr1);
@ -733,7 +799,7 @@ uint32_t get_remaining_time(timex_t *t)
void set_remaining_time(timex_t *t, uint32_t time)
{
timex_t tmp = {time, 0};
timex_t tmp = { time, 0 };
timex_t now;
vtimer_now(&now);
@ -757,7 +823,6 @@ int ipv6_init_as_router(void)
return 1;
}
uint8_t ipv6_is_router(void)
{
ipv6_addr_t addr;
@ -798,19 +863,29 @@ void ipv6_register_next_header_handler(uint8_t next_header, kernel_pid_t pid)
break;
}
}
#ifdef MODULE_RPL
/* register routing function */
void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t *dest))
{
ip_get_next_hop = next_hop;
}
/* register source-routing indicator function */
void ipv6_iface_set_srh_indicator(uint8_t (*srh_indi)(void))
{
ip_srh_indicator = srh_indi;
}
/* register rpl-process function */
void ipv6_register_rpl_handler(kernel_pid_t pid)
{
_rpl_process_pid = pid;
}
uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t proto)
#endif
uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len,
uint8_t proto)
{
uint16_t sum = 0;
DEBUG("Calculate checksum over src: %s, dst: %s, len: %04X, buf: %p, proto: %u\n",
@ -820,7 +895,8 @@ uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t
&ipv6_header->destaddr),
len, buf, proto);
sum = len + proto;
sum = net_help_csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
sum = net_help_csum(sum, (uint8_t *) &ipv6_header->srcaddr,
2 * sizeof(ipv6_addr_t));
sum = net_help_csum(sum, buf, len);
return (sum == 0) ? 0xffff : HTONS(sum);
}

View File

@ -1,4 +1,4 @@
/**
/*
* IPv6 constants, data structs, and prototypes
*
* Copyright (C) 2013 INRIA.
@ -51,6 +51,10 @@ extern "C" {
extern uint8_t ipv6_ext_hdr_len;
extern kernel_pid_t ip_process_pid;
#ifdef MODULE_RPL
extern int srh_handler_pid;
#endif
/* base header lengths */
#define LL_HDR_LEN (0x4)
#define ICMPV6_HDR_LEN (0x4)
@ -64,7 +68,8 @@ extern char ip_process_buf[IP_PROCESS_STACKSIZE];
extern kernel_pid_t sixlowip_reg[SIXLOWIP_MAX_REGISTERED];
typedef struct __attribute__((packed)) {
typedef struct __attribute__((packed))
{
struct net_if_addr_t *addr_next;
struct net_if_addr_t *addr_prev;
net_if_l3p_t addr_protocol;
@ -74,19 +79,24 @@ typedef struct __attribute__((packed)) {
timex_t valid_lifetime;
timex_t preferred_lifetime;
uint8_t is_anycast;
} ipv6_net_if_addr_t;
}
ipv6_net_if_addr_t;
typedef struct __attribute__((packed)) {
typedef struct __attribute__((packed))
{
ipv6_net_if_addr_t *addr;
int if_id;
} ipv6_net_if_hit_t;
}
ipv6_net_if_hit_t;
typedef struct __attribute__((packed)) {
typedef struct __attribute__((packed))
{
uint8_t prefix; ///< prefix length of the sub-net
uint8_t adv_cur_hop_limit;
uint32_t adv_reachable_time;
uint32_t adv_retrans_timer;
} ipv6_net_if_ext_t;
}
ipv6_net_if_ext_t;
/* function prototypes */
ipv6_net_if_ext_t *ipv6_net_if_get_ext(int if_id);

View File

@ -1 +1 @@
include $(RIOTBASE)/Makefile.base
include $(RIOTBASE)/Makefile.base

View File

@ -1,4 +1,4 @@
/**
/*
* ETX beaconing implementation
*
* Copyright (C) 2013 Stephan Arndt <arndtste@zedat.fu-berlin.de>
@ -6,15 +6,20 @@
* 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
*/
/**
* @ingroup rpl
* @{
* @file
* @file etx_beaconing.c
* @brief ETX-beaconing implementation
*
* Implementation for ETX-based beaconing.
*
* @author Stephan Arndt <arndtste@zedat.fu-berlin.de>
* @}
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1 +1,7 @@
MODE = $(shell grep "RPL_DEFAULT_MOP RPL_NON_STORING_MODE" ../../include/rpl/rpl_config.h)
ifneq (,$(MODE))
DIRS += rpl_nonstoring
else
DIRS += rpl_storing
endif
include $(RIOTBASE)/Makefile.base

View File

@ -1,17 +1,20 @@
/**
* Objective function 0 for RPL implementation
*
* Copyright (C) 2013 INRIA.
/*
* Copyright (C) 2014 Oliver Hahm <oliver.hahm@inria.fr>
*
* 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
*/
/**
* @ingroup rpl
* @{
* @file of0.c
* @brief RPL objective function 0
* @author Eric Engel <eric.engel@fu-berlin.de>
* @file of0.c
* @brief Objective Function Zero.
*
* Implementation of Objective Function Zero.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/

View File

@ -1,11 +1,23 @@
/*
* Copyright (C) 2014 Oliver Hahm <oliver.hahm@inria.fr>
* Copyright (C) 2014 Oliver Hahm <oliver.hahm@inria.fr>
*
* 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 of0.h
* @brief Objective Function Zero.
*
* Header-file, which defines all functions for the implementation of Objective Function Zero.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/
#ifndef OF0_H
#define OF0_H

View File

@ -1,16 +1,20 @@
/**
* OF MRHOF implementation
*
/*
* Copyright (C) 2013 Stephan Arndt <arndtste@zedat.fu-berlin.de>
*
* 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
*/
/**
* @ingroup rpl
* @{
* @file
* @author Stephan Arndt <arndtste@zedat.fu-berlin.de>
* @file of_mrhof.c
* @brief Objective Function MRHOF.
*
* Implementation of Objective Function MRHOF.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/

View File

@ -1,11 +1,23 @@
/*
* Copyright (C) 2014 Oliver Hahm <oliver.hahm@inria.fr>
* Copyright (C) 2013 Stephan Arndt <arndtste@zedat.fu-berlin.de>
*
* 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 of_mrhof.h
* @brief Objective Function MRHOF.
*
* Header-file, which defines all functions for the implementation of Objective Function MRHOF.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/
#ifndef OF_MRHOF_H
#define OF_MRHOF_H

View File

@ -1,19 +1,23 @@
/*
* 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.
*/
/**
* RPL implementation
*
* Copyright (C) 2013 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
* @ingroup rpl
* @{
* @file rpl.c
* @brief basic RPL functions
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @}
*
* @file rpl.c
* @brief Implementation of the RPL-core.
*
* Implementation of core RPL-functions. Normally it shouldn't be necessary to
* modify this file.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
*/
#include <string.h>
@ -34,6 +38,8 @@
/* You can only run Storing Mode by now. Other unsupported modes lead to default (Storing Mode) */
#if RPL_DEFAULT_MOP == RPL_STORING_MODE_NO_MC
#include "rpl/rpl_storing.h"
#elif RPL_DEFAULT_MOP == RPL_NON_STORING_MODE
#include "rpl/rpl_nonstoring.h"
#else
#include "rpl/rpl_storing.h"
#endif
@ -47,7 +53,6 @@ char addr_str[IPV6_MAX_ADDR_STR_LEN];
#include "debug.h"
/* global variables */
rpl_routing_entry_t rpl_routing_table[RPL_MAX_ROUTING_ENTRIES];
kernel_pid_t rpl_process_pid = KERNEL_PID_UNDEF;
mutex_t rpl_recv_mutex = MUTEX_INIT;
mutex_t rpl_send_mutex = MUTEX_INIT;
@ -55,8 +60,23 @@ msg_t rpl_msg_queue[RPL_PKT_RECV_BUF_SIZE];
char rpl_process_buf[RPL_PROCESS_STACKSIZE];
uint8_t rpl_buffer[BUFFER_SIZE - LL_HDR_LEN];
#if RPL_DEFAULT_MOP == RPL_NON_STORING_MODE
uint8_t srh_buffer[BUFFER_SIZE];
uint8_t srh_send_buffer[BUFFER_SIZE];
ipv6_addr_t *down_next_hop;
ipv6_srh_t *srh_header;
msg_t srh_m_send, srh_m_recv;
rpl_routing_entry_t rpl_routing_table[RPL_MAX_ROUTING_ENTRIES_NON_STORING];
#else
rpl_routing_entry_t rpl_routing_table[RPL_MAX_ROUTING_ENTRIES_STORING];
#endif
uint8_t rpl_max_routing_entries;
ipv6_addr_t my_address;
/* IPv6 message buffer */
ipv6_hdr_t *ipv6_buf;
icmpv6_hdr_t *icmp_buf;
uint8_t rpl_init(int if_id)
{
@ -64,6 +84,24 @@ uint8_t rpl_init(int if_id)
/* initialize routing table */
rpl_clear_routing_table();
if (RPL_DEFAULT_MOP == RPL_STORING_MODE_NO_MC) {
rpl_max_routing_entries = RPL_MAX_ROUTING_ENTRIES_STORING;
rpl_clear_routing_table();
}
else {
rpl_max_routing_entries = RPL_MAX_ROUTING_ENTRIES_NON_STORING;
rpl_clear_routing_table();
}
if (rpl_routing_table == NULL) {
DEBUGF("Routing table init failed!\n");
return SIXLOWERROR_NULLPTR;
}
else {
DEBUGF("Routing table init finished!\n");
}
init_trickle();
rpl_process_pid = thread_create(rpl_process_buf, RPL_PROCESS_STACKSIZE,
PRIORITY_MAIN - 1, CREATE_STACKTEST,
@ -71,15 +109,17 @@ uint8_t rpl_init(int if_id)
sixlowpan_lowpan_init_interface(if_id);
/* need link local prefix to query _our_ corresponding address */
ipv6_addr_t my_address;
ipv6_addr_t ll_address;
ipv6_addr_set_link_local_prefix(&ll_address);
ipv6_net_if_get_best_src_addr(&my_address, &ll_address);
ipv6_register_rpl_handler(rpl_process_pid);
ipv6_iface_set_srh_indicator(rpl_is_root);
ipv6_iface_set_routing_provider(rpl_get_next_hop);
DEBUGF("All addresses set!\n");
/* initialize objective function manager */
rpl_of_manager_init(&my_address);
rpl_init_mode(&my_address);
return SIXLOWERROR_SUCCESS;
}
@ -88,6 +128,32 @@ void rpl_init_root(void)
rpl_init_root_mode();
}
uint8_t rpl_is_root(void)
{
return rpl_is_root_mode();
}
#if RPL_DEFAULT_MOP == RPL_NON_STORING_MODE
void internal_srh_process(ipv6_srh_t *srh_header)
{
/* modify it accordingly - the number of entries is not depending on padding, because there is none. */
uint8_t n = srh_header->hdrextlen / sizeof(ipv6_addr_t);
if (srh_header->segments_left > n) {
memset(&down_next_hop, 0, sizeof(ipv6_addr_t));
DEBUGF("[Error] source-routing header is invalid.\n");
}
else {
uint8_t segs = srh_header->segments_left;
DEBUGF("SRH-length: %d\n", srh_header->hdrextlen);
down_next_hop = &srh_header->route[n - segs];
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));
}
}
#endif
void *rpl_process(void *arg)
{
(void) arg;
@ -98,131 +164,181 @@ void *rpl_process(void *arg)
while (1) {
msg_receive(&m_recv);
mutex_lock(&rpl_recv_mutex);
uint8_t *code;
code = ((uint8_t *)m_recv.content.ptr);
/* differentiate packet types */
ipv6_buf = ipv6_get_buf();
ipv6_buf = ((ipv6_hdr_t *)m_recv.content.ptr);
memcpy(&rpl_buffer, ipv6_buf, NTOHS(ipv6_buf->length) + IPV6_HDR_LEN);
DEBUGF("Received RPL information of type %04X and length %u\n", *code, NTOHS(ipv6_buf->length));
switch (*code) {
case (ICMP_CODE_DIS): {
recv_rpl_DIS();
mutex_unlock(&rpl_recv_mutex);
break;
/* This is an RPL-related message. */
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) {
icmp_buf = ((icmpv6_hdr_t *)(m_recv.content.ptr + IPV6_HDR_LEN));
/* get code for message-interpretation and process message */
DEBUGF("Received RPL information of type %04X and length %u\n", icmp_buf->code, NTOHS(ipv6_buf->length));
switch (icmp_buf->code) {
case (ICMP_CODE_DIS): {
rpl_recv_DIS();
mutex_unlock(&rpl_recv_mutex);
break;
}
case (ICMP_CODE_DIO): {
rpl_recv_DIO();
mutex_unlock(&rpl_recv_mutex);
break;
}
case (ICMP_CODE_DAO): {
rpl_recv_DAO();
mutex_unlock(&rpl_recv_mutex);
break;
}
case (ICMP_CODE_DAO_ACK): {
rpl_recv_DAO_ACK();
mutex_unlock(&rpl_recv_mutex);
break;
}
default:
mutex_unlock(&rpl_recv_mutex);
break;
}
case (ICMP_CODE_DIO): {
recv_rpl_DIO();
mutex_unlock(&rpl_recv_mutex);
break;
}
case (ICMP_CODE_DAO): {
recv_rpl_DAO();
mutex_unlock(&rpl_recv_mutex);
break;
}
case (ICMP_CODE_DAO_ACK): {
recv_rpl_DAO_ACK();
mutex_unlock(&rpl_recv_mutex);
break;
}
default:
mutex_unlock(&rpl_recv_mutex);
break;
}
#if RPL_DEFAULT_MOP == RPL_NON_STORING_MODE
/* If the message is not RPL-type, it relates to non-storing mode */
else if (RPL_DEFAULT_MOP == RPL_NON_STORING_MODE) {
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_SRH) {
srh_header = ((ipv6_srh_t *)(m_recv.content.ptr + IPV6_HDR_LEN));
/* 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);
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));
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);
}
}
}
else {
srh_header = rpl_get_srh_header(ipv6_buf);
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));
}
}
mutex_unlock(&rpl_recv_mutex);
}
#endif
}
}
/**************************************************************/
/* General RPL-send & -receive functions. Call mode-functions */
/**************************************************************/
void send_DIO(ipv6_addr_t *destination)
void rpl_send_DIO(ipv6_addr_t *destination)
{
DEBUGF("Send DIO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
if (destination) {
DEBUGF("Send DIO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
mutex_lock(&rpl_send_mutex);
send_DIO_mode(destination);
rpl_send_DIO_mode(destination);
mutex_unlock(&rpl_send_mutex);
}
void send_DAO(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)
{
DEBUG("Send DAO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
if (destination) {
DEBUGF("Send DAO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
mutex_lock(&rpl_send_mutex);
send_DAO_mode(destination, lifetime, default_lifetime, start_index);
rpl_send_DAO_mode(destination, lifetime, default_lifetime, start_index);
mutex_unlock(&rpl_send_mutex);
}
void send_DIS(ipv6_addr_t *destination)
void rpl_send_DIS(ipv6_addr_t *destination)
{
DEBUGF("Send DIS to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
if (destination) {
DEBUGF("Send DIS to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
mutex_lock(&rpl_send_mutex);
send_DIS_mode(destination);
rpl_send_DIS_mode(destination);
mutex_unlock(&rpl_send_mutex);
}
void send_DAO_ACK(ipv6_addr_t *destination)
void rpl_send_DAO_ACK(ipv6_addr_t *destination)
{
DEBUGF("Send DAO ACK to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
if (destination) {
DEBUGF("Send DAO ACK to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination));
}
mutex_lock(&rpl_send_mutex);
send_DAO_ACK_mode(destination);
rpl_send_DAO_ACK_mode(destination);
mutex_unlock(&rpl_send_mutex);
}
void recv_rpl_DIO(void)
void rpl_recv_DIO(void)
{
DEBUGF("DIO received\n");
recv_rpl_DIO_mode();
rpl_recv_DIO_mode();
}
void recv_rpl_DAO(void)
void rpl_recv_DAO(void)
{
DEBUGF("DAO received\n");
recv_rpl_DAO_mode();
rpl_recv_DAO_mode();
}
void recv_rpl_DIS(void)
void rpl_recv_DIS(void)
{
DEBUGF("DIS received\n");
recv_rpl_DIS_mode();
rpl_recv_DIS_mode();
}
void recv_rpl_DAO_ACK(void)
void rpl_recv_DAO_ACK(void)
{
DEBUGF("DAO ACK received\n");
recv_rpl_dao_ack_mode();
rpl_recv_dao_ack_mode();
}
/**************************************************************/
/**************************************************************/
/******************************************************************************/
/* Routing related functions are obsolete and will be replaced in near future */
/******************************************************************************/
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));
for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
DEBUGF("Looking up the next hop to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
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));
}
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));
return &rpl_routing_table[i].next_hop;
if ((RPL_DEFAULT_MOP == RPL_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));
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));
return &rpl_routing_table[i].next_hop;
}
}
}
@ -238,7 +354,9 @@ void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t li
return;
}
for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
DEBUGF("Adding routing entry %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (!rpl_routing_table[i].used) {
memcpy(&rpl_routing_table[i].address, addr, sizeof(ipv6_addr_t));
memcpy(&rpl_routing_table[i].next_hop, next_hop, sizeof(ipv6_addr_t));
@ -251,7 +369,10 @@ void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t li
void rpl_del_routing_entry(ipv6_addr_t *addr)
{
for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
DEBUGF("Deleting routing entry %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) {
memset(&rpl_routing_table[i], 0, sizeof(rpl_routing_table[i]));
return;
@ -261,7 +382,10 @@ void rpl_del_routing_entry(ipv6_addr_t *addr)
rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr)
{
for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
DEBUGF("Finding routing entry %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) {
return &rpl_routing_table[i];
}
@ -272,7 +396,10 @@ rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr)
void rpl_clear_routing_table(void)
{
memset(&rpl_routing_table, 0, sizeof(rpl_routing_table));
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
memset(&rpl_routing_table[i], 0, sizeof(rpl_routing_table[i]));
}
}
rpl_routing_entry_t *rpl_get_routing_table(void)
@ -280,5 +407,160 @@ rpl_routing_entry_t *rpl_get_routing_table(void)
return rpl_routing_table;
}
/******************************************************************************/
/******************************************************************************/
#if RPL_DEFAULT_MOP == RPL_NON_STORING_MODE
/* everything from here on is non-storing mode related */
void rpl_add_srh_entry(ipv6_addr_t *child, ipv6_addr_t *parent, uint16_t lifetime)
{
rpl_routing_entry_t *entry = rpl_find_routing_entry(child);
/* If we already have this entry and the parent from parent/child is the same as already
* registered, we only update the lifetime. If only the parent of the child changes, we
* delete the previous entry and add it below.
*/
if (entry != NULL) {
if (ipv6_addr_is_equal(parent, &entry->next_hop)) {
entry->lifetime = lifetime;
return;
}
else {
rpl_del_routing_entry(child);
}
}
/* This maybe a bit confusing since the root also using the standard routing table, but in this case
* the code stays cleaner - especially for rt_over_timer from trickle.c. Just keep in mind that
* address is now child (unique, iteration variable) and parent is now next_hop. The whole routing table
* transforms to a list of childs and their parents, 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));
DEBUGF("Adding source-routing entry parent: %s\n", 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) {
memcpy(&rpl_routing_table[i].address, child, sizeof(ipv6_addr_t));
memcpy(&rpl_routing_table[i].next_hop, parent, sizeof(ipv6_addr_t));
rpl_routing_table[i].lifetime = lifetime;
rpl_routing_table[i].used = 1;
break;
}
}
}
/**
* @brief Checks if two IPv6 host suffixes are equal.
*
* @param[in] a An IPv6 address.
* @param[in] b Another IPv6 address.
*
* @return 1 if *a* and *b* are equal for host suffixes, 0 otherwise.
*/
int ipv6_suffix_is_equal(const ipv6_addr_t *a, const ipv6_addr_t *b)
{
return (a->uint32[2] == b->uint32[2]) &&
(a->uint32[3] == b->uint32[3]);
}
ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr)
{
uint8_t route_length = RPL_MAX_SRH_PATH_LENGTH;
ipv6_addr_t rev_route[route_length];
ipv6_addr_t *actual_node;
uint8_t counter = 0;
uint8_t traceable;
ipv6_srh_t *srh_header = (ipv6_srh_t *)(&srh_buffer);
/* init source route with child */
actual_node = &(act_ipv6_hdr->destaddr);
DEBUGF("DESTINATION NODE: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, actual_node));
while (!(rpl_equal_id(actual_node, &my_address))) {
/* set check variable - this is reversed, if a child/parent-relation is found in one iteration of the routing table */
traceable = 0;
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)) {
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));
DEBUGF(" and C: %s\n", 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;
counter++;
traceable = 1;
if (counter > route_length) {
DEBUGF("[INFO] Both lengths are %d and %d\n", counter, route_length);
DEBUGF("Error with computing source routing header.\n");
return NULL;
}
break;
}
}
if (traceable == 0) {
DEBUGF("No route to destination.\n");
return NULL;
}
}
/* build real route based on reversed route. 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));
}
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 {
srh_header->hdrextlen = 0;
}
/* actually build SRH-header */
memcpy(&srh_header->nextheader, &(act_ipv6_hdr->nextheader), sizeof(uint8_t));
srh_header->routing_type = 3;
srh_header->segments_left = counter - 1;
/* cmpri & cmpre are both 0, because by now there is only support for full addresses */
srh_header->cmpri = 0;
srh_header->cmpre = 0;
/* since the route has exactly the length of its intermediate nodes, padding is zero. */
srh_header->pad = 0;
srh_header->reserved = 0;
/* set the destination-address in ipv6-buf->destaddr, which is the pointer of child */
return srh_header;
}
void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nextheader)
{
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&srh_send_buffer));
uint8_t *payload = &srh_send_buffer[IPV6_HDR_LEN];
memcpy(temp_ipv6_header, ipv6_header, sizeof(ipv6_hdr_t));
int msg_length = NTOHS(ipv6_header->length) - sizeof(ipv6_srh_t);
temp_ipv6_header->length = HTONS(msg_length);
temp_ipv6_header->nextheader = nextheader;
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));
srh_m_send.content.ptr = (char *) srh_send_buffer;
DEBUGF("Return from relay: %d\n", 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_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]));
uint8_t *payload = &srh_send_buffer[IPV6_HDR_LEN + srh_length];
memcpy(&(temp_ipv6_header->destaddr), dest, sizeof(ipv6_addr_t));
memcpy(&(temp_ipv6_header->srcaddr), src, sizeof(ipv6_addr_t));
memcpy(current_packet, srh_header, srh_length);
memcpy(payload, buf, len);
uint16_t plength = srh_length + len;
DEBUGF("Build SRH package finished. Going to send it.\n");
DEBUGF("SRH-length: %d\n", current_packet->hdrextlen);
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);
}
#endif

View File

@ -1,7 +1,5 @@
/**
* RPL dodag implementation
*
* Copyright (C) 2013 INRIA.
* 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
@ -9,9 +7,13 @@
*
* @ingroup rpl
* @{
* @file rpl_dodag.c
* @brief RPL dodag functions
* @author Eric Engel <eric.engel@fu-berlin.de>
*
* @file rpl_dodag.c
* @brief RPL DODAG
*
* Implementation of a DODAG for usage with RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/
@ -139,8 +141,10 @@ void rpl_leave_dodag(rpl_dodag_t *dodag)
bool rpl_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2)
{
for (uint8_t i = 0; i < 4; i++) {
if (id1->uint32[i] != id2->uint32[i]) {
for (uint8_t i = 0; i < 2; i++) {
DEBUGF("ID1: %d ID2: %d\n", id1->uint8[12 + i], id2->uint8[12 + i]);
if (id1->uint8[14 + i] != id2->uint8[14 + i]) {
return false;
}
}
@ -269,7 +273,7 @@ rpl_parent_t *rpl_find_preferred_parent(void)
if (!rpl_equal_id(&my_dodag->my_preferred_parent->addr, &best->addr)) {
if (my_dodag->mop != RPL_NO_DOWNWARD_ROUTES) {
/* send DAO with ZERO_LIFETIME to old parent */
send_DAO(&my_dodag->my_preferred_parent->addr, 0, false, 0);
rpl_send_DAO(&my_dodag->my_preferred_parent->addr, 0, false, 0);
}
my_dodag->my_preferred_parent = best;

View File

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

View File

@ -0,0 +1,855 @@
/*
* 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
#define DEBUG_ENABLED
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 struct rpl_dis_t *rpl_send_dis_buf;
static ipv6_hdr_t *ipv6_send_buf;
static struct rpl_dio_t *rpl_send_dio_buf;
static struct 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 struct rpl_dio_t *rpl_dio_buf;
static struct rpl_dao_t *rpl_dao_buf;
static struct 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 struct 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 struct rpl_dis_t *get_rpl_send_dis_buf(void)
{
return ((struct 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 struct rpl_dio_t *get_rpl_send_dio_buf(void)
{
return ((struct rpl_dio_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static struct rpl_dao_t *get_rpl_send_dao_buf(void)
{
return ((struct 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 struct rpl_dio_t *get_rpl_dio_buf(void)
{
return ((struct rpl_dio_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static struct rpl_dao_t *get_rpl_dao_buf(void)
{
return ((struct rpl_dao_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN]));
}
static struct rpl_dao_ack_t *get_rpl_dao_ack_buf(void)
{
return ((struct rpl_dao_ack_t *) & (buffer[(LL_HDR_LEN + IPV6_HDR_LEN + ICMPV6_HDR_LEN)]));
}
static struct rpl_dis_t *get_rpl_dis_buf(void)
{
return ((struct 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;
rpl_get_of_for_ocp(0);
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;
}
DEBUGF("Root init finished.\n");
start_trickle(dodag->dio_min, dodag->dio_interval_doubling, dodag->dio_redundancy);
}
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 = mydodag->my_rank;
DEBUG("rank %04X\n", 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 = mydodag->maxrankincrease;
rpl_send_opt_dodag_conf_buf->MinHopRankIncrease = mydodag->minhoprankincrease;
rpl_send_opt_dodag_conf_buf->ocp = 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 = mydodag->lifetime_unit;
opt_hdr_len += RPL_OPT_DODAG_CONF_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)
{
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;
/* 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;
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, 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 = rpl_opt_dodag_conf_buf->MaxRankIncrease;
dio_dodag.minhoprankincrease = rpl_opt_dodag_conf_buf->MinHopRankIncrease;
dio_dodag.default_lifetime = rpl_opt_dodag_conf_buf->default_lifetime;
dio_dodag.lifetime_unit = rpl_opt_dodag_conf_buf->lifetime_unit;
dio_dodag.of = (struct rpl_of_t *) rpl_get_of_for_ocp(rpl_opt_dodag_conf_buf->ocp);
len += RPL_OPT_DODAG_CONF_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;
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 (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 (rpl_dio_buf->rank != INFINITE_RANK) {
DEBUGF("Will join DODAG\n");
rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, 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);
reset_trickletimer();
}
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, rpl_dio_buf->rank);
}
return;
}
else if (RPL_COUNTER_GREATER_THAN(my_dodag->version, dio_dodag.version)) {
reset_trickletimer();
return;
}
}
/* version matches, DODAG matches */
if (rpl_dio_buf->rank == INFINITE_RANK) {
reset_trickletimer();
}
/* We are root, all done!*/
if (my_dodag->my_rank == ROOT_RANK) {
if (rpl_dio_buf->rank != INFINITE_RANK) {
trickle_increment_counter();
}
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, rpl_dio_buf->rank);
if (parent == NULL) {
return;
}
}
else {
/* DIO OK */
trickle_increment_counter();
}
/* update parent rank */
parent->rank = 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)) {
delay_dao();
}
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;
break;
}
case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += rpl_opt_buf->length;
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_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;
/* 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_NON_STORING_MODE
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;
break;
}
case (RPL_OPT_TARGET_DESC): {
len += rpl_opt_buf->length;
break;
}
default:
return;
}
}
if (increment_seq) {
RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
delay_dao();
}
}
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;
}
dao_ack_received();
}
/* 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);
}
if (ipv6_addr_is_multicast(&ipv6_send_buf->destaddr)) {
ipv6_send_packet(ipv6_send_buf, NULL);
}
else {
/* find appropriate next hop before sending */
ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_send_buf->destaddr);
DEBUGF("Trying to send to destination: %s\n", ipv6_addr_to_str(addr_str_mode,
IPV6_MAX_ADDR_STR_LEN, next_hop));
if (next_hop == NULL) {
if (i_am_root) {
DEBUGF("[Error] destination unknown: %s\n", ipv6_addr_to_str(addr_str_mode,
IPV6_MAX_ADDR_STR_LEN, &ipv6_send_buf->destaddr));
return;
}
else {
next_hop = rpl_get_my_preferred_parent();
if (next_hop == NULL) {
DEBUGF("[Error] no preferred parent, dropping package\n");
return;
}
}
}
DEBUGF("Sending done (for RPL)\n");
ipv6_send_packet(ipv6_send_buf, NULL);
}
}

View File

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

View File

@ -1,18 +1,22 @@
/*
* 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.
*/
/**
* RPL storing mode implementation
*
* 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
* @ingroup rpl
* @{
* @file rpl_storing.c
* @brief RPL Storing mode functions
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
* @}
*
* @file rpl_storing.c
* @brief RPL storing-mode
*
* Implementation of the storing mode of RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Fabian Brandt <fabianbr@zedat.fu-berlin.de>
*/
#include "rpl/rpl_storing.h"
@ -24,18 +28,19 @@
#define ENABLE_DEBUG (0)
#if ENABLE_DEBUG
#undef TRICKLE_TIMER_STACKSIZE
#define DEBUG_ENABLED
char addr_str[IPV6_MAX_ADDR_STR_LEN];
char addr_str_mode[IPV6_MAX_ADDR_STR_LEN];
#endif
#include "debug.h"
/* global variables */
char i_am_root = 0;
ipv6_addr_t my_address;
static ipv6_addr_t my_address;
/* Identification variables */
static char i_am_root;
/* in send buffer we need space fpr LL_HDR */
uint8_t rpl_send_buffer[BUFFER_SIZE];
static uint8_t rpl_send_buffer[BUFFER_SIZE];
/* SEND BUFFERS */
static icmpv6_hdr_t *icmp_send_buf;
@ -49,7 +54,7 @@ static rpl_opt_target_t *rpl_send_opt_target_buf;
static rpl_opt_transit_t *rpl_send_opt_transit_buf;
/* RECEIVE BUFFERS */
ipv6_hdr_t *ipv6_buf;
static ipv6_hdr_t *ipv6_buf;
static struct rpl_dio_t *rpl_dio_buf;
static struct rpl_dao_t *rpl_dao_buf;
static struct rpl_dao_ack_t *rpl_dao_ack_buf;
@ -216,7 +221,12 @@ void rpl_init_root_mode(void)
}
void send_DIO_mode(ipv6_addr_t *destination)
uint8_t rpl_is_root_mode(void)
{
return i_am_root;
}
void rpl_send_DIO_mode(ipv6_addr_t *destination)
{
rpl_dodag_t *mydodag;
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
@ -240,7 +250,8 @@ void send_DIO_mode(ipv6_addr_t *destination)
rpl_send_dio_buf->version_number = mydodag->version;
rpl_send_dio_buf->rank = mydodag->my_rank;
DEBUG("rank %04X\n", 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->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;
@ -262,13 +273,13 @@ void send_DIO_mode(ipv6_addr_t *destination)
rpl_send_opt_dodag_conf_buf->default_lifetime = mydodag->default_lifetime;
rpl_send_opt_dodag_conf_buf->lifetime_unit = mydodag->lifetime_unit;
opt_hdr_len += RPL_OPT_LEN + RPL_OPT_DODAG_CONF_LEN;
opt_hdr_len += RPL_OPT_DODAG_CONF_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 send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index)
void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index)
{
if (i_am_root) {
return;
@ -310,14 +321,15 @@ void send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_life
uint8_t entries = 0;
uint8_t continue_index = 0;
for (uint8_t i = start_index; i < RPL_MAX_ROUTING_ENTRIES; i++) {
for (uint8_t i = start_index; i < rpl_max_routing_entries; i++) {
if (rpl_get_routing_table()[i].used) {
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, &rpl_get_routing_table()[i].address, sizeof(ipv6_addr_t));
opt_len += RPL_OPT_TARGET_LEN + 2;
memcpy(&rpl_send_opt_target_buf->target, &rpl_get_routing_table()[i].address,
sizeof(ipv6_addr_t));
opt_len += RPL_OPT_TARGET_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;
rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN;
@ -325,7 +337,7 @@ void send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_life
rpl_send_opt_transit_buf->path_control = 0x00; /* not used */
rpl_send_opt_transit_buf->path_sequence = 0x00; /* not used */
rpl_send_opt_transit_buf->path_lifetime = lifetime;
opt_len += RPL_OPT_TRANSIT_LEN + 2;
opt_len += RPL_OPT_TRANSIT_LEN;
rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN + opt_len);
entries++;
}
@ -344,7 +356,7 @@ void send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_life
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));
opt_len += RPL_OPT_TARGET_LEN + 2;
opt_len += RPL_OPT_TARGET_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;
@ -353,17 +365,17 @@ void send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_life
rpl_send_opt_transit_buf->path_control = 0x00;
rpl_send_opt_transit_buf->path_sequence = 0x00;
rpl_send_opt_transit_buf->path_lifetime = lifetime;
opt_len += RPL_OPT_TRANSIT_LEN + 2;
opt_len += RPL_OPT_TRANSIT_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);
if (continue_index > 1) {
send_DAO(destination, lifetime, default_lifetime, continue_index);
rpl_send_DAO(destination, lifetime, default_lifetime, continue_index);
}
}
void send_DIS_mode(ipv6_addr_t *destination)
void rpl_send_DIS_mode(ipv6_addr_t *destination)
{
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
@ -376,7 +388,7 @@ void send_DIS_mode(ipv6_addr_t *destination)
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void send_DAO_ACK_mode(ipv6_addr_t *destination)
void rpl_send_DAO_ACK_mode(ipv6_addr_t *destination)
{
rpl_dodag_t *my_dodag;
my_dodag = rpl_get_my_dodag();
@ -400,7 +412,7 @@ void send_DAO_ACK_mode(ipv6_addr_t *destination)
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6);
}
void recv_rpl_DIO_mode(void)
void rpl_recv_DIO_mode(void)
{
ipv6_buf = get_rpl_ipv6_buf();
@ -469,17 +481,17 @@ void recv_rpl_DIO_mode(void)
}
case (RPL_OPT_PADN): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_ROUTE_INFO): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
@ -501,7 +513,7 @@ void recv_rpl_DIO_mode(void)
dio_dodag.default_lifetime = rpl_opt_dodag_conf_buf->default_lifetime;
dio_dodag.lifetime_unit = rpl_opt_dodag_conf_buf->lifetime_unit;
dio_dodag.of = (struct rpl_of_t *) rpl_get_of_for_ocp(rpl_opt_dodag_conf_buf->ocp);
len += RPL_OPT_DODAG_CONF_LEN + 2;
len += RPL_OPT_DODAG_CONF_LEN;
break;
}
@ -511,7 +523,7 @@ void recv_rpl_DIO_mode(void)
return;
}
len += RPL_OPT_PREFIX_INFO_LEN + 2;
len += RPL_OPT_PREFIX_INFO_LEN;
break;
}
@ -527,7 +539,7 @@ void recv_rpl_DIO_mode(void)
if (my_dodag == NULL) {
if (!has_dodag_conf_opt) {
DEBUGF("send DIS\n");
send_DIS(&ipv6_buf->srcaddr);
rpl_send_DIS(&ipv6_buf->srcaddr);
}
if (rpl_dio_buf->rank < ROOT_RANK) {
@ -562,7 +574,7 @@ void recv_rpl_DIO_mode(void)
reset_trickletimer();
}
else {
DEBUGF("my dodag has no preferred_parent yet - seems to be odd since I have a parent...\n");
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, rpl_dio_buf->rank);
}
@ -612,9 +624,10 @@ void recv_rpl_DIO_mode(void)
rpl_parent_update(parent);
if (my_dodag->my_preferred_parent == NULL) {
DEBUG("%s, %d: my dodag has no preferred_parent yet - seems to be odd since I have a parent...\n", __FILE__, __LINE__);
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)) {
else if (rpl_equal_id(&parent->addr, &my_dodag->my_preferred_parent->addr) &&
(parent->dtsn != rpl_dio_buf->dtsn)) {
delay_dao();
}
@ -622,7 +635,7 @@ void recv_rpl_DIO_mode(void)
}
void recv_rpl_DAO_mode(void)
void rpl_recv_DAO_mode(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
@ -650,12 +663,12 @@ void recv_rpl_DAO_mode(void)
}
case (RPL_OPT_PADN): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
@ -671,29 +684,31 @@ void recv_rpl_DAO_mode(void)
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);
DEBUGF("[Error] - no transit information for target option type = %d\n",
rpl_opt_transit_buf->type);
break;
}
len += rpl_opt_transit_buf->length + 2;
len += rpl_opt_transit_buf->length;
/* route lifetime seconds = (DAO lifetime) * (Unit Lifetime) */
DEBUG("Adding routing information: Target: %s, Source: %s, Lifetime: %u\n",
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_add_routing_entry(&rpl_opt_target_buf->target, &ipv6_buf->srcaddr,
rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit);
increment_seq = 1;
break;
}
case (RPL_OPT_TRANSIT): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_TARGET_DESC): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
@ -702,7 +717,7 @@ void recv_rpl_DAO_mode(void)
}
}
send_DAO_ACK(&ipv6_buf->srcaddr);
rpl_send_DAO_ACK(&ipv6_buf->srcaddr);
if (increment_seq) {
RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
@ -710,7 +725,7 @@ void recv_rpl_DAO_mode(void)
}
}
void recv_rpl_DIS_mode(void)
void rpl_recv_DIS_mode(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
@ -732,12 +747,12 @@ void recv_rpl_DIS_mode(void)
}
case (RPL_OPT_PADN): {
len += rpl_opt_buf->length + 2;
len += rpl_opt_buf->length;
break;
}
case (RPL_OPT_SOLICITED_INFO): {
len += RPL_OPT_SOLICITED_INFO_LEN + 2;
len += RPL_OPT_SOLICITED_INFO_LEN;
/* extract and check */
if (rpl_opt_buf->length != RPL_OPT_SOLICITED_INFO_LEN) {
@ -773,11 +788,11 @@ void recv_rpl_DIS_mode(void)
}
}
send_DIO(&ipv6_buf->srcaddr);
rpl_send_DIO(&ipv6_buf->srcaddr);
}
void recv_rpl_dao_ack_mode(void)
void rpl_recv_dao_ack_mode(void)
{
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
@ -828,7 +843,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
}
if (ipv6_addr_is_multicast(&ipv6_send_buf->destaddr)) {
ipv6_send_packet(ipv6_send_buf);
ipv6_send_packet(ipv6_send_buf, NULL);
}
else {
/* find appropriate next hop before sending */
@ -836,7 +851,8 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
if (next_hop == NULL) {
if (i_am_root) {
DEBUGF("[Error] destination unknown: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &ipv6_send_buf->destaddr));
DEBUGF("[Error] destination unknown: %s\n", ipv6_addr_to_str(addr_str,
IPV6_MAX_ADDR_STR_LEN, &ipv6_send_buf->destaddr));
return;
}
else {
@ -849,7 +865,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
}
}
ipv6_send_packet(ipv6_send_buf);
ipv6_send_packet(ipv6_send_buf, NULL);
}
}

View File

@ -1,17 +1,20 @@
/**
* Trickle implementation
*
* Copyright (C) 2013 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
*/
/**
* @ingroup rpl
* @{
* @file trickle.c
* @brief Trickle implementation
* @author Eric Engel <eric.engel@fu-berlin.de>
* @file trickle.c
* @brief Trickle
*
* Implementation of Trickle-Algorithm for RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/
@ -138,7 +141,7 @@ static void *trickle_timer_over(void *arg)
/* Handle k=0 like k=infinity (according to RFC6206, section 6.5) */
if ((c < k) || (k == 0)) {
send_DIO(&mcast);
rpl_send_DIO(&mcast);
}
}
@ -214,12 +217,13 @@ void long_delay_dao(void)
static void *dao_delay_over(void *arg)
{
(void) arg;
while (1) {
thread_sleep();
if ((ack_received == false) && (dao_counter < DAO_SEND_RETRIES)) {
dao_counter++;
send_DAO(NULL, 0, true, 0);
rpl_send_DAO(NULL, 0, true, 0);
dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK, 0);
vtimer_remove(&dao_timer);
vtimer_set_wakeup(&dao_timer, dao_time, dao_delay_over_pid);
@ -228,6 +232,7 @@ static void *dao_delay_over(void *arg)
long_delay_dao();
}
}
return NULL;
}
@ -249,7 +254,7 @@ static void *rt_timer_over(void *arg)
if (my_dodag != NULL) {
rt = rpl_get_routing_table();
for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
for (uint8_t i = 0; i < rpl_max_routing_entries; i++) {
if (rt[i].used) {
if (rt[i].lifetime <= 1) {
memset(&rt[i], 0, sizeof(rt[i]));

View File

@ -1,17 +1,20 @@
/**
* Trickle constants and prototypes
*
* Copyright (C) 2013 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
*/
/**
* @ingroup rpl
* @{
* @file trickle.h
* @brief Trickle
* @author Eric Engel <eric.engel@fu-berlin.de>
* @file trickle.h
* @brief Trickle
*
* Header-file, which defines all Trickle constants and prototypes
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @}
*/

View File

@ -181,6 +181,9 @@ void socket_base_print_internal_socket(socket_internal_t *current_socket_interna
int socket_base_exists_socket(int socket)
{
if (socket<1) {
return false;
}
if (socket_base_sockets[socket - 1].socket_id == 0) {
return false;
}

View File

@ -290,7 +290,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet,
switch_tcp_packet_byte_order(current_tcp_packet);
return ipv6_sendto(&current_tcp_socket->foreign_address.sin6_addr,
IPPROTO_TCP, (uint8_t *)(current_tcp_packet),
header_length * 4 + payload_length);
header_length * 4 + payload_length, NULL);
#endif
}

View File

@ -86,6 +86,7 @@ void *udp_packet_handler(void *arg)
if (udp_socket != NULL) {
m_send_udp.content.ptr = (char *)ipv6_header;
msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid);
}
else {
@ -201,7 +202,7 @@ int32_t udp_sendto(int s, const void *buf, uint32_t len, int flags,
return ipv6_sendto(&to->sin6_addr, IPPROTO_UDP,
(uint8_t *)(current_udp_packet),
NTOHS(current_udp_packet->length));
NTOHS(current_udp_packet->length), NULL);
}
else {
return -1;

View File

@ -35,7 +35,7 @@ void _rpl_route_handler(int argc, char **argv)
printf(" %-3s %-18s %-18s %s\n", "#", "target", "next hop", "lifetime");
puts("--------------------------------------------------------------------");
for (int i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
for (int i = 0; i < rpl_max_routing_entries; i++) {
if (rtable[i].used) {
c++;
printf(" %03d: %-18s ", i, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,