Skip to content

Commit

Permalink
Merge pull request #2155 from cgundogan/rpl_one_thread
Browse files Browse the repository at this point in the history
rpl: RPL/trickle with only *one* thread
  • Loading branch information
OlegHahm committed Jan 15, 2015
2 parents 079ff1b + c4b01b8 commit cadea97
Show file tree
Hide file tree
Showing 15 changed files with 520 additions and 440 deletions.
1 change: 1 addition & 0 deletions Makefile.dep
Expand Up @@ -32,6 +32,7 @@ ifneq (,$(filter sixlowborder,$(USEMODULE)))
endif

ifneq (,$(filter rpl,$(USEMODULE)))
USEMODULE += trickle
USEMODULE += routing
endif

Expand Down
3 changes: 3 additions & 0 deletions sys/Makefile
Expand Up @@ -71,6 +71,9 @@ endif
ifneq (,$(filter netapi,$(USEMODULE)))
DIRS += net/crosslayer/netapi
endif
ifneq (,$(filter trickle,$(USEMODULE)))
DIRS += trickle
endif

DIRS += $(dir $(wildcard $(addsuffix /Makefile, ${USEMODULE})))

Expand Down
114 changes: 114 additions & 0 deletions sys/include/trickle.h
@@ -0,0 +1,114 @@
/*
* Trickle constants and prototypes
*
* 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.
*/

/**
* @defgroup sys_trickle Trickle Timer
* @ingroup sys
* @{
*/

/**
* @file trickle.h
* @brief Implementation of a generic Trickle Algorithm (RFC 6206)
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/

#ifndef _TRICKLE_H
#define _TRICKLE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "vtimer.h"
#include "thread.h"

/** @brief a generic callback function with arguments that is called by trickle periodically */
typedef struct {
void (*func)(void *); /**< a generic callback function pointer */
void *args; /**< a generic parameter for the callback function pointer */
} trickle_callback_t;

/** @brief all state variables for a trickle timer */
typedef struct {
uint8_t k; /**< redundancy constant */
uint32_t Imin; /**< minimum interval size */
uint8_t Imax; /**< maximum interval size, described as a number of doublings */
uint32_t I; /**< current interval size */
uint32_t t; /**< time within the current interval */
uint16_t c; /**< counter */
kernel_pid_t pid; /**< pid of trickles target thread */
trickle_callback_t callback; /**< the callback function and parameter that trickle is calling
after each interval */
uint16_t interval_msg_type; /**< the msg_t.type that trickle should use after an interval */
timex_t msg_interval_time; /**< interval represented as timex_t */
vtimer_t msg_interval_timer; /**< vtimer to send a msg_t to the target thread for a new interval */
uint16_t callback_msg_type; /**< the msg_t.type that trickle should use after a callback */
timex_t msg_callback_time; /**< callback interval represented as timex_t */
vtimer_t msg_callback_timer; /**< vtimer to send a msg_t to the target thread for a callback */
} trickle_t;

/**
* @brief resets the trickle timer
*
* @param[in] trickle the trickle timer
*/
void trickle_reset_timer(trickle_t *trickle);

/**
* @brief start the trickle timer
*
* @param[in] pid target thread
* @param[in] trickle trickle timer
* @param[in] interval_msg_type msg_t.type for interval messages
* @param[in] callback_msg_type msg_t.type for callback messages
* @param[in] Imin minimum interval
* @param[in] Imax maximum interval
* @param[in] k redundancy constant
*/
void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t interval_msg_type,
uint16_t callback_msg_type, uint32_t Imin, uint8_t Imax, uint8_t k);

/**
* @brief stops the trickle timer
*
* @param[in] trickle trickle timer
*/
void trickle_stop(trickle_t *trickle);

/**
* @brief increments the counter by one
*
* @param[in] trickle trickle timer
*/
void trickle_increment_counter(trickle_t *trickle);

/**
* @brief is called after the interval is over and calculates the next interval
*
* @param[in] trickle trickle timer
*/
void trickle_interval(trickle_t *trickle);

/**
* @brief is called after the callback interval is over and calls the callback function
*
* @param[in] trickle trickle timer
*/
void trickle_callback(trickle_t *trickle);

#ifdef __cplusplus
}
#endif

#endif /* _TRICKLE_H */
/** @} */
20 changes: 15 additions & 5 deletions sys/net/include/rpl/rpl_config.h
Expand Up @@ -32,12 +32,21 @@ extern "C" {
#define RPL_STORING_MODE_NO_MC 0x02
#define RPL_STORING_MODE_MC 0x03

/* ICMP type */
#define RPL_SEQUENCE_WINDOW 16
#define ICMP_CODE_DIS 0x00
#define ICMP_CODE_DIO 0x01
#define ICMP_CODE_DAO 0x02
#define ICMP_CODE_DAO_ACK 0x03
/* RPL Message type */
enum RPL_MSG_CODE {
ICMP_CODE_DIS = 0,
ICMP_CODE_DIO,
ICMP_CODE_DAO,
ICMP_CODE_DAO_ACK,
/* put all ICMP codes before the end marker */
ICMP_CODE_END,
RPL_MSG_TYPE_DAO_HANDLE,
RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE,
RPL_MSG_TYPE_TRICKLE_INTERVAL,
RPL_MSG_TYPE_TRICKLE_CALLBACK
};

/* packet base lengths */
#define DIO_BASE_LEN 24
#define DIS_BASE_LEN 2
Expand Down Expand Up @@ -147,6 +156,7 @@ static inline bool RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
#define RPL_ROOT_RANK 256
#define RPL_DEFAULT_LIFETIME 0xff
#define RPL_LIFETIME_UNIT 2
#define RPL_LIFETIME_STEP 2
#define RPL_GROUNDED 1
#define RPL_PRF_MASK 0x7
#define RPL_MOP_SHIFT 3
Expand Down
2 changes: 2 additions & 0 deletions sys/net/include/rpl/rpl_dodag.h
Expand Up @@ -26,6 +26,8 @@
extern "C" {
#endif

void rpl_dao_ack_received(rpl_dodag_t *dodag);
void rpl_delay_dao(rpl_dodag_t *dodag);
void rpl_instances_init(void);
rpl_instance_t *rpl_new_instance(uint8_t instanceid);
rpl_instance_t *rpl_get_instance(uint8_t instanceid);
Expand Down
12 changes: 9 additions & 3 deletions sys/net/include/rpl/rpl_structs.h
Expand Up @@ -18,16 +18,17 @@
* @}
*/

#include <string.h>
#include "ipv6.h"

#ifndef RPL_STRUCTS_H_INCLUDED
#define RPL_STRUCTS_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

#include <string.h>
#include "ipv6.h"
#include "trickle.h"

/* Modes of Operation */

/* DIO Base Object (RFC 6550 Fig. 14) */
Expand Down Expand Up @@ -167,6 +168,11 @@ typedef struct rpl_dodag_t {
uint8_t joined;
rpl_parent_t *my_preferred_parent;
struct rpl_of_t *of;
trickle_t trickle;
bool ack_received;
uint8_t dao_counter;
timex_t dao_time;
vtimer_t dao_timer;
} rpl_dodag_t;

typedef struct rpl_of_t {
Expand Down
1 change: 1 addition & 0 deletions sys/net/network_layer/sixlowpan/ip.c
Expand Up @@ -282,6 +282,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 *) ipv6_buf;
m_send.type = ((icmpv6_hdr_t *)(m_send.content.ptr + IPV6_HDR_LEN))->code;
msg_send(&m_send, _rpl_process_pid);
}
else {
Expand Down

0 comments on commit cadea97

Please sign in to comment.