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

rpl: reuse xtimer for cleanup

This commit is contained in:
test 2015-11-17 14:39:32 +01:00
parent 20364ff36c
commit bbe1b6f125
5 changed files with 25 additions and 33 deletions

View File

@ -96,11 +96,6 @@ extern "C" {
*/
#define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
/**
* @brief Message type for handling DODAG cleanup
*/
#define GNRC_RPL_MSG_TYPE_CLEANUP_HANDLE (0x0904)
/**
* @brief Infinite rank
* @see <a href="https://tools.ietf.org/html/rfc6550#section-17">

View File

@ -225,9 +225,6 @@ struct gnrc_rpl_dodag {
msg_t dao_msg; /**< msg_t for firing a dao */
uint32_t dao_time; /**< time to schedule the next DAO */
xtimer_t dao_timer; /**< timer to schedule the next DAO */
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 */
};
@ -242,6 +239,7 @@ struct gnrc_rpl_instance {
gnrc_rpl_of_t *of; /**< configured Objective Function */
uint16_t min_hop_rank_inc; /**< minimum hop rank increase */
uint16_t max_rank_inc; /**< max increase in the rank */
int8_t cleanup; /**< cleanup time in seconds */
};
#ifdef __cplusplus

View File

@ -199,16 +199,6 @@ static void *_event_loop(void *args)
_dao_handle_send(dodag);
}
break;
case GNRC_RPL_MSG_TYPE_CLEANUP_HANDLE:
DEBUG("RPL: GNRC_RPL_MSG_TYPE_CLEANUP received\n");
inst = (gnrc_rpl_instance_t *) msg.content.ptr;
dodag = &inst->dodag;
if (inst && (inst->state != 0) && (dodag->parents == NULL)
&& (dodag->my_rank == GNRC_RPL_INFINITE_RANK)) {
/* no parents - delete this instance and DODAG */
gnrc_rpl_instance_remove(inst);
}
break;
case GNRC_NETAPI_MSG_TYPE_RCV:
DEBUG("RPL: GNRC_NETAPI_MSG_TYPE_RCV received\n");
_receive((gnrc_pktsnip_t *)msg.content.ptr);
@ -231,23 +221,38 @@ static void *_event_loop(void *args)
void _update_lifetime(void)
{
uint32_t now = xtimer_now();
uint16_t now_sec = now / SEC_IN_USEC;
gnrc_rpl_parent_t *parent;
gnrc_rpl_instance_t *inst;
for (uint8_t i = 0; i < GNRC_RPL_PARENTS_NUMOF; ++i) {
parent = &gnrc_rpl_parents[i];
if (parent->state != 0) {
if ((int32_t)(parent->lifetime - (now / SEC_IN_USEC)) <=
GNRC_RPL_LIFETIME_UPDATE_STEP) {
if ((int32_t)(parent->lifetime - now_sec) <= GNRC_RPL_LIFETIME_UPDATE_STEP) {
gnrc_rpl_dodag_t *dodag = parent->dodag;
gnrc_rpl_parent_remove(parent);
gnrc_rpl_parent_update(dodag, NULL);
continue;
}
else if ((int32_t)(parent->lifetime - (now / SEC_IN_USEC))
<= (GNRC_RPL_LIFETIME_UPDATE_STEP * 2)) {
else if ((int32_t)(parent->lifetime - now_sec) <= (GNRC_RPL_LIFETIME_UPDATE_STEP * 2)) {
gnrc_rpl_send_DIS(parent->dodag->instance, &parent->addr);
}
}
}
for (int i = 0; i < GNRC_RPL_INSTANCES_NUMOF; ++i) {
inst = &gnrc_rpl_instances[i];
if ((inst->state != 0) && (inst->cleanup > 0) && (inst->dodag.parents == NULL) &&
(inst->dodag.my_rank == GNRC_RPL_INFINITE_RANK)) {
inst->cleanup -= GNRC_RPL_LIFETIME_UPDATE_STEP;
if (inst->cleanup <= 0) {
/* no parents - delete this instance and DODAG */
gnrc_rpl_instance_remove(inst);
}
}
}
xtimer_set_msg(&_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid);
}

View File

@ -101,7 +101,6 @@ bool gnrc_rpl_instance_remove(gnrc_rpl_instance_t *inst)
gnrc_rpl_dodag_remove_all_parents(dodag);
trickle_stop(&dodag->trickle);
xtimer_remove(&dodag->dao_timer);
xtimer_remove(&dodag->cleanup_timer);
memset(inst, 0, sizeof(gnrc_rpl_instance_t));
return true;
}
@ -146,9 +145,6 @@ bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id)
dodag->dao_counter = 0;
dodag->dao_msg.type = GNRC_RPL_MSG_TYPE_DAO_HANDLE;
dodag->dao_msg.content.ptr = (char *) instance;
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 *) instance;
dodag->instance = instance;
return true;
@ -160,7 +156,7 @@ void gnrc_rpl_dodag_remove_all_parents(gnrc_rpl_dodag_t *dodag)
LL_FOREACH_SAFE(dodag->parents, elt, tmp) {
gnrc_rpl_parent_remove(elt);
}
xtimer_set_msg(&dodag->cleanup_timer, dodag->cleanup_time, &dodag->cleanup_msg, gnrc_rpl_pid);
dodag->instance->cleanup = GNRC_RPL_CLEANUP_TIME;
}
bool gnrc_rpl_parent_add_by_addr(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *addr,
@ -224,8 +220,7 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) {
dodag->my_rank = GNRC_RPL_INFINITE_RANK;
trickle_reset_timer(&dodag->trickle);
xtimer_set_msg(&dodag->cleanup_timer, dodag->cleanup_time, &dodag->cleanup_msg,
gnrc_rpl_pid);
dodag->instance->cleanup = GNRC_RPL_CLEANUP_TIME;
}
}

View File

@ -179,7 +179,7 @@ int _gnrc_rpl_dodag_show(void)
gnrc_rpl_dodag_t *dodag = NULL;
char addr_str[IPV6_ADDR_MAX_STR_LEN];
uint32_t cleanup;
int8_t cleanup;
uint64_t tc, ti, xnow = xtimer_now64();
for (uint8_t i = 0; i < GNRC_RPL_INSTANCES_NUMOF; ++i) {
@ -200,10 +200,9 @@ int _gnrc_rpl_dodag_show(void)
| dodag->trickle.msg_interval_timer.target) - xnow;
ti = (int64_t) ti < 0 ? 0 : ti / SEC_IN_USEC;
cleanup = dodag->cleanup_timer.target - xtimer_now();
cleanup = (int32_t) cleanup < 0 ? 0 : cleanup / SEC_IN_USEC;
cleanup = dodag->instance->cleanup < 0 ? 0 : dodag->instance->cleanup;
printf("\tdodag [%s | R: %d | OP: %s | CL: %" PRIu32 "s | "
printf("\tdodag [%s | R: %d | OP: %s | CL: %" PRIi8 "s | "
"TR(I=[%d,%d], k=%d, c=%d, TC=%" PRIu64 "s, TI=%" PRIu64 "s)]\n",
ipv6_addr_to_str(addr_str, &dodag->dodag_id, sizeof(addr_str)),
dodag->my_rank, (dodag->node_status == GNRC_RPL_LEAF_NODE ? "Leaf" : "Router"),