mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
rpl: switch to xtimer
This commit is contained in:
parent
0f10bb4a8d
commit
50392b6256
@ -28,7 +28,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "net/ipv6/addr.h"
|
#include "net/ipv6/addr.h"
|
||||||
#include "vtimer.h"
|
#include "xtimer.h"
|
||||||
#include "trickle.h"
|
#include "trickle.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,13 +170,13 @@ typedef struct gnrc_rpl_parent gnrc_rpl_parent_t;
|
|||||||
* @brief Parent representation
|
* @brief Parent representation
|
||||||
*/
|
*/
|
||||||
struct gnrc_rpl_parent {
|
struct gnrc_rpl_parent {
|
||||||
gnrc_rpl_parent_t *next; /**< pointer to the next parent */
|
gnrc_rpl_parent_t *next; /**< pointer to the next parent */
|
||||||
uint8_t state; /**< 0 for unsued, 1 for used */
|
uint8_t state; /**< 0 for unsued, 1 for used */
|
||||||
ipv6_addr_t addr; /**< link-local IPv6 address of this parent */
|
ipv6_addr_t addr; /**< link-local IPv6 address of this parent */
|
||||||
uint16_t rank; /**< rank of the parent */
|
uint16_t rank; /**< rank of the parent */
|
||||||
uint8_t dtsn; /**< last seen dtsn of this parent */
|
uint8_t dtsn; /**< last seen dtsn of this parent */
|
||||||
gnrc_rpl_dodag_t *dodag; /**< DODAG the parent belongs to */
|
gnrc_rpl_dodag_t *dodag; /**< DODAG the parent belongs to */
|
||||||
timex_t lifetime; /**< lifetime of this parent */
|
uint64_t lifetime; /**< lifetime of this parent */
|
||||||
double link_metric; /**< metric of the link */
|
double link_metric; /**< metric of the link */
|
||||||
uint8_t link_metric_type; /**< type of the metric */
|
uint8_t link_metric_type; /**< type of the metric */
|
||||||
};
|
};
|
||||||
@ -236,10 +236,12 @@ struct gnrc_rpl_dodag {
|
|||||||
uint8_t dao_counter; /**< amount of retried DAOs */
|
uint8_t dao_counter; /**< amount of retried DAOs */
|
||||||
bool dao_ack_received; /**< flag to check for DAO-ACK */
|
bool dao_ack_received; /**< flag to check for DAO-ACK */
|
||||||
uint8_t dodag_conf_counter; /**< limitation of the sending of DODAG_CONF options */
|
uint8_t dodag_conf_counter; /**< limitation of the sending of DODAG_CONF options */
|
||||||
timex_t dao_time; /**< time to schedule the next DAO */
|
msg_t dao_msg; /**< msg_t for firing a dao */
|
||||||
vtimer_t dao_timer; /**< timer to schedule the next DAO */
|
uint64_t dao_time; /**< time to schedule the next DAO */
|
||||||
timex_t cleanup_time; /**< time to schedula a DODAG cleanup */
|
xtimer_t dao_timer; /**< timer to schedule the next DAO */
|
||||||
vtimer_t cleanup_timer; /**< timer to schedula a DODAG cleanup */
|
msg_t cleanup_msg; /**< msg_t for firing a cleanup */
|
||||||
|
uint32_t cleanup_time; /**< time to schedula a DODAG cleanup */
|
||||||
|
xtimer_t cleanup_timer; /**< timer to schedula a DODAG cleanup */
|
||||||
trickle_t trickle; /**< trickle representation */
|
trickle_t trickle; /**< trickle representation */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,8 +30,9 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN];
|
|||||||
|
|
||||||
static char _stack[GNRC_RPL_STACK_SIZE];
|
static char _stack[GNRC_RPL_STACK_SIZE];
|
||||||
kernel_pid_t gnrc_rpl_pid = KERNEL_PID_UNDEF;
|
kernel_pid_t gnrc_rpl_pid = KERNEL_PID_UNDEF;
|
||||||
static timex_t _lt_time;
|
static uint32_t _lt_time = GNRC_RPL_LIFETIME_UPDATE_STEP * SEC_IN_USEC;
|
||||||
static vtimer_t _lt_timer;
|
static xtimer_t _lt_timer;
|
||||||
|
static msg_t _lt_msg = { .type = GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE };
|
||||||
static msg_t _msg_q[GNRC_RPL_MSG_QUEUE_SIZE];
|
static msg_t _msg_q[GNRC_RPL_MSG_QUEUE_SIZE];
|
||||||
static gnrc_netreg_entry_t _me_reg;
|
static gnrc_netreg_entry_t _me_reg;
|
||||||
|
|
||||||
@ -63,8 +64,7 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
|
|||||||
gnrc_netreg_register(GNRC_NETTYPE_ICMPV6, &_me_reg);
|
gnrc_netreg_register(GNRC_NETTYPE_ICMPV6, &_me_reg);
|
||||||
|
|
||||||
gnrc_rpl_of_manager_init();
|
gnrc_rpl_of_manager_init();
|
||||||
_lt_time = timex_set(GNRC_RPL_LIFETIME_UPDATE_STEP, 0);
|
xtimer_set_msg(&_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid);
|
||||||
vtimer_set_msg(&_lt_timer, _lt_time, gnrc_rpl_pid, GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* register all_RPL_nodes multicast address */
|
/* register all_RPL_nodes multicast address */
|
||||||
@ -217,44 +217,41 @@ static void *_event_loop(void *args)
|
|||||||
|
|
||||||
void _update_lifetime(void)
|
void _update_lifetime(void)
|
||||||
{
|
{
|
||||||
timex_t now;
|
uint64_t now = xtimer_now64();
|
||||||
vtimer_now(&now);
|
|
||||||
gnrc_rpl_parent_t *parent;
|
gnrc_rpl_parent_t *parent;
|
||||||
for (uint8_t i = 0; i < GNRC_RPL_PARENTS_NUMOF; ++i) {
|
for (uint8_t i = 0; i < GNRC_RPL_PARENTS_NUMOF; ++i) {
|
||||||
parent = &gnrc_rpl_parents[i];
|
parent = &gnrc_rpl_parents[i];
|
||||||
if (parent->state != 0) {
|
if (parent->state != 0) {
|
||||||
if ((signed)(parent->lifetime.seconds - now.seconds) <= GNRC_RPL_LIFETIME_UPDATE_STEP) {
|
if ((int64_t)(parent->lifetime - now) <= (int64_t) (GNRC_RPL_LIFETIME_UPDATE_STEP
|
||||||
|
* SEC_IN_USEC)) {
|
||||||
gnrc_rpl_dodag_t *dodag = parent->dodag;
|
gnrc_rpl_dodag_t *dodag = parent->dodag;
|
||||||
gnrc_rpl_parent_remove(parent);
|
gnrc_rpl_parent_remove(parent);
|
||||||
gnrc_rpl_parent_update(dodag, NULL);
|
gnrc_rpl_parent_update(dodag, NULL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (((signed)(parent->lifetime.seconds - now.seconds) <=
|
else if ((int64_t)(parent->lifetime - now) <= (int64_t) (GNRC_RPL_LIFETIME_UPDATE_STEP
|
||||||
GNRC_RPL_LIFETIME_UPDATE_STEP * 2)) {
|
* SEC_IN_USEC * 2)) {
|
||||||
gnrc_rpl_send_DIS(parent->dodag, &parent->addr);
|
gnrc_rpl_send_DIS(parent->dodag, &parent->addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtimer_remove(&_lt_timer);
|
xtimer_set_msg(&_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid);
|
||||||
vtimer_set_msg(&_lt_timer, _lt_time, gnrc_rpl_pid, GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag)
|
void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag)
|
||||||
{
|
{
|
||||||
dodag->dao_time = timex_set(GNRC_RPL_DEFAULT_DAO_DELAY, 0);
|
dodag->dao_time = GNRC_RPL_DEFAULT_DAO_DELAY * SEC_IN_USEC;
|
||||||
dodag->dao_counter = 0;
|
dodag->dao_counter = 0;
|
||||||
dodag->dao_ack_received = false;
|
dodag->dao_ack_received = false;
|
||||||
vtimer_remove(&dodag->dao_timer);
|
xtimer_set_msg64(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid);
|
||||||
vtimer_set_msg(&dodag->dao_timer, dodag->dao_time, gnrc_rpl_pid, GNRC_RPL_MSG_TYPE_DAO_HANDLE, dodag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag)
|
void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag)
|
||||||
{
|
{
|
||||||
dodag->dao_time = timex_set(GNRC_RPL_REGULAR_DAO_INTERVAL, 0);
|
dodag->dao_time = GNRC_RPL_REGULAR_DAO_INTERVAL * SEC_IN_USEC;
|
||||||
dodag->dao_counter = 0;
|
dodag->dao_counter = 0;
|
||||||
dodag->dao_ack_received = false;
|
dodag->dao_ack_received = false;
|
||||||
vtimer_remove(&dodag->dao_timer);
|
xtimer_set_msg64(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid);
|
||||||
vtimer_set_msg(&dodag->dao_timer, dodag->dao_time, gnrc_rpl_pid, GNRC_RPL_MSG_TYPE_DAO_HANDLE, dodag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _dao_handle_send(gnrc_rpl_dodag_t *dodag)
|
void _dao_handle_send(gnrc_rpl_dodag_t *dodag)
|
||||||
@ -262,10 +259,8 @@ void _dao_handle_send(gnrc_rpl_dodag_t *dodag)
|
|||||||
if ((dodag->dao_ack_received == false) && (dodag->dao_counter < GNRC_RPL_DAO_SEND_RETRIES)) {
|
if ((dodag->dao_ack_received == false) && (dodag->dao_counter < GNRC_RPL_DAO_SEND_RETRIES)) {
|
||||||
dodag->dao_counter++;
|
dodag->dao_counter++;
|
||||||
gnrc_rpl_send_DAO(dodag, NULL, dodag->default_lifetime);
|
gnrc_rpl_send_DAO(dodag, NULL, dodag->default_lifetime);
|
||||||
dodag->dao_time = timex_set(GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK, 0);
|
dodag->dao_time = GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK * SEC_IN_USEC;
|
||||||
vtimer_remove(&dodag->dao_timer);
|
xtimer_set_msg64(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid);
|
||||||
vtimer_set_msg(&dodag->dao_timer, dodag->dao_time,
|
|
||||||
gnrc_rpl_pid, GNRC_RPL_MSG_TYPE_DAO_HANDLE, dodag);
|
|
||||||
}
|
}
|
||||||
else if (dodag->dao_ack_received == false) {
|
else if (dodag->dao_ack_received == false) {
|
||||||
gnrc_rpl_long_delay_dao(dodag);
|
gnrc_rpl_long_delay_dao(dodag);
|
||||||
|
@ -161,7 +161,11 @@ bool gnrc_rpl_dodag_add(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, gn
|
|||||||
(*dodag)->dao_ack_received = false;
|
(*dodag)->dao_ack_received = false;
|
||||||
(*dodag)->dao_counter = 0;
|
(*dodag)->dao_counter = 0;
|
||||||
(*dodag)->parents = NULL;
|
(*dodag)->parents = NULL;
|
||||||
(*dodag)->cleanup_time = timex_set(GNRC_RPL_CLEANUP_TIME, 0);
|
(*dodag)->dao_msg.type = GNRC_RPL_MSG_TYPE_DAO_HANDLE;
|
||||||
|
(*dodag)->dao_msg.content.ptr = (char *) (*dodag);
|
||||||
|
(*dodag)->cleanup_time = GNRC_RPL_CLEANUP_TIME * SEC_IN_USEC;
|
||||||
|
(*dodag)->cleanup_msg.type = GNRC_RPL_MSG_TYPE_CLEANUP_HANDLE;
|
||||||
|
(*dodag)->cleanup_msg.content.ptr = (char *) (*dodag);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,8 +181,8 @@ bool gnrc_rpl_dodag_remove(gnrc_rpl_dodag_t *dodag)
|
|||||||
gnrc_rpl_instance_t *inst = dodag->instance;
|
gnrc_rpl_instance_t *inst = dodag->instance;
|
||||||
LL_DELETE(inst->dodags, dodag);
|
LL_DELETE(inst->dodags, dodag);
|
||||||
trickle_stop(&dodag->trickle);
|
trickle_stop(&dodag->trickle);
|
||||||
vtimer_remove(&dodag->dao_timer);
|
xtimer_remove(&dodag->dao_timer);
|
||||||
vtimer_remove(&dodag->cleanup_timer);
|
xtimer_remove(&dodag->cleanup_timer);
|
||||||
memset(dodag, 0, sizeof(gnrc_rpl_dodag_t));
|
memset(dodag, 0, sizeof(gnrc_rpl_dodag_t));
|
||||||
if (inst->dodags == NULL) {
|
if (inst->dodags == NULL) {
|
||||||
gnrc_rpl_instance_remove(inst);
|
gnrc_rpl_instance_remove(inst);
|
||||||
@ -192,9 +196,7 @@ void gnrc_rpl_dodag_remove_all_parents(gnrc_rpl_dodag_t *dodag)
|
|||||||
LL_FOREACH_SAFE(dodag->parents, elt, tmp) {
|
LL_FOREACH_SAFE(dodag->parents, elt, tmp) {
|
||||||
gnrc_rpl_parent_remove(elt);
|
gnrc_rpl_parent_remove(elt);
|
||||||
}
|
}
|
||||||
vtimer_remove(&dodag->cleanup_timer);
|
xtimer_set_msg(&dodag->cleanup_timer, dodag->cleanup_time, &dodag->cleanup_msg, gnrc_rpl_pid);
|
||||||
vtimer_set_msg(&dodag->cleanup_timer, dodag->cleanup_time, gnrc_rpl_pid,
|
|
||||||
GNRC_RPL_MSG_TYPE_CLEANUP_HANDLE, dodag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gnrc_rpl_dodag_t *gnrc_rpl_dodag_get(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id)
|
gnrc_rpl_dodag_t *gnrc_rpl_dodag_get(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id)
|
||||||
@ -325,9 +327,8 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
|
|||||||
|
|
||||||
if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) {
|
if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) {
|
||||||
trickle_reset_timer(&dodag->trickle);
|
trickle_reset_timer(&dodag->trickle);
|
||||||
vtimer_remove(&dodag->cleanup_timer);
|
xtimer_set_msg(&dodag->cleanup_timer, dodag->cleanup_time, &dodag->cleanup_msg,
|
||||||
vtimer_set_msg(&dodag->cleanup_timer, dodag->cleanup_time, gnrc_rpl_pid,
|
gnrc_rpl_pid);
|
||||||
GNRC_RPL_MSG_TYPE_CLEANUP_HANDLE, dodag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dodag->my_rank = GNRC_RPL_INFINITE_RANK;
|
dodag->my_rank = GNRC_RPL_INFINITE_RANK;
|
||||||
@ -336,14 +337,12 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
|
|||||||
void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent)
|
void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent)
|
||||||
{
|
{
|
||||||
uint16_t old_rank = dodag->my_rank;
|
uint16_t old_rank = dodag->my_rank;
|
||||||
timex_t now;
|
uint64_t now = xtimer_now64();
|
||||||
vtimer_now(&now);
|
|
||||||
ipv6_addr_t def = IPV6_ADDR_UNSPECIFIED;
|
ipv6_addr_t def = IPV6_ADDR_UNSPECIFIED;
|
||||||
|
|
||||||
/* update Parent lifetime */
|
/* update Parent lifetime */
|
||||||
if (parent != NULL) {
|
if (parent != NULL) {
|
||||||
parent->lifetime.seconds = now.seconds + (dodag->default_lifetime * dodag->lifetime_unit);
|
parent->lifetime = now + ((dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_USEC);
|
||||||
parent->lifetime.microseconds = 0;
|
|
||||||
if (parent == dodag->parents) {
|
if (parent == dodag->parents) {
|
||||||
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
|
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
|
||||||
kernel_pid_t if_id;
|
kernel_pid_t if_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user