From 1f2c6740264c9b05fde61c83362415b988e5943b Mon Sep 17 00:00:00 2001 From: test Date: Tue, 17 Nov 2015 19:53:26 +0100 Subject: [PATCH] rpl: reuse timer for periodic daos --- sys/include/net/gnrc/rpl/structs.h | 4 +-- sys/net/gnrc/routing/rpl/gnrc_rpl.c | 41 +++++++++++------------ sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c | 4 --- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/sys/include/net/gnrc/rpl/structs.h b/sys/include/net/gnrc/rpl/structs.h index 2fae3d969d..ee36f16e03 100644 --- a/sys/include/net/gnrc/rpl/structs.h +++ b/sys/include/net/gnrc/rpl/structs.h @@ -222,9 +222,7 @@ struct gnrc_rpl_dodag { bool dao_ack_received; /**< flag to check for DAO-ACK */ bool dodag_conf_requested; /**< flag to send DODAG_CONF options */ bool prefix_info_requested; /**< flag to send PREFIX_INFO options */ - 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 */ + uint8_t dao_time; /**< time to schedule a DAO in seconds */ trickle_t trickle; /**< trickle representation */ }; diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl.c b/sys/net/gnrc/routing/rpl/gnrc_rpl.c index 9d7d7f0432..2745bc89b7 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl.c @@ -165,8 +165,6 @@ static void *_event_loop(void *args) reply.type = GNRC_NETAPI_MSG_TYPE_ACK; trickle_t *trickle; - gnrc_rpl_instance_t *inst; - gnrc_rpl_dodag_t *dodag; /* start event loop */ while (1) { DEBUG("RPL: waiting for incoming message.\n"); @@ -191,14 +189,6 @@ static void *_event_loop(void *args) trickle_callback(trickle); } break; - case GNRC_RPL_MSG_TYPE_DAO_HANDLE: - DEBUG("RPL: GNRC_RPL_MSG_TYPE_DAO_HANDLE received\n"); - inst = (gnrc_rpl_instance_t *) msg.content.ptr; - dodag = &inst->dodag; - if (inst && (inst->state != 0)) { - _dao_handle_send(dodag); - } - break; case GNRC_NETAPI_MSG_TYPE_RCV: DEBUG("RPL: GNRC_NETAPI_MSG_TYPE_RCV received\n"); _receive((gnrc_pktsnip_t *)msg.content.ptr); @@ -243,12 +233,22 @@ void _update_lifetime(void) 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); + if (inst->state != 0) { + if ((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); + continue; + } + } + + if (inst->dodag.dao_time > GNRC_RPL_LIFETIME_UPDATE_STEP) { + inst->dodag.dao_time -= GNRC_RPL_LIFETIME_UPDATE_STEP; + } + else { + _dao_handle_send(&inst->dodag); } } } @@ -258,18 +258,16 @@ void _update_lifetime(void) void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag) { - dodag->dao_time = GNRC_RPL_DEFAULT_DAO_DELAY * SEC_IN_USEC; + dodag->dao_time = GNRC_RPL_DEFAULT_DAO_DELAY; dodag->dao_counter = 0; dodag->dao_ack_received = false; - xtimer_set_msg(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid); } void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag) { - dodag->dao_time = GNRC_RPL_REGULAR_DAO_INTERVAL * SEC_IN_USEC; + dodag->dao_time = GNRC_RPL_REGULAR_DAO_INTERVAL; dodag->dao_counter = 0; dodag->dao_ack_received = false; - xtimer_set_msg(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid); } void _dao_handle_send(gnrc_rpl_dodag_t *dodag) @@ -277,8 +275,7 @@ void _dao_handle_send(gnrc_rpl_dodag_t *dodag) if ((dodag->dao_ack_received == false) && (dodag->dao_counter < GNRC_RPL_DAO_SEND_RETRIES)) { dodag->dao_counter++; gnrc_rpl_send_DAO(dodag->instance, NULL, dodag->default_lifetime); - dodag->dao_time = GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK * SEC_IN_USEC; - xtimer_set_msg(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid); + dodag->dao_time = GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK; } else if (dodag->dao_ack_received == false) { gnrc_rpl_long_delay_dao(dodag); diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c b/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c index 84a7ed1c3d..9e58838137 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c @@ -100,7 +100,6 @@ bool gnrc_rpl_instance_remove(gnrc_rpl_instance_t *inst) gnrc_rpl_dodag_t *dodag = &inst->dodag; gnrc_rpl_dodag_remove_all_parents(dodag); trickle_stop(&dodag->trickle); - xtimer_remove(&dodag->dao_timer); memset(inst, 0, sizeof(gnrc_rpl_instance_t)); return true; } @@ -143,8 +142,6 @@ bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id) dodag->dtsn = 0; dodag->dao_ack_received = false; dodag->dao_counter = 0; - dodag->dao_msg.type = GNRC_RPL_MSG_TYPE_DAO_HANDLE; - dodag->dao_msg.content.ptr = (char *) instance; dodag->instance = instance; return true; @@ -156,7 +153,6 @@ void gnrc_rpl_dodag_remove_all_parents(gnrc_rpl_dodag_t *dodag) LL_FOREACH_SAFE(dodag->parents, elt, tmp) { gnrc_rpl_parent_remove(elt); } - dodag->instance->cleanup = GNRC_RPL_CLEANUP_TIME; } bool gnrc_rpl_parent_add_by_addr(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *addr,