Skip to content

Commit

Permalink
rpl: remove global variable indicating the root node
Browse files Browse the repository at this point in the history
  • Loading branch information
cgundogan committed Mar 19, 2015
1 parent 52017a9 commit e20fbbb
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions sys/net/routing/rpl/rpl_control_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ static char addr_str[IPV6_MAX_ADDR_STR_LEN];
#endif
#include "debug.h"

/* Identification variables */
static char i_am_root;

/* in send buffer we need space for LL_HDR */
static uint8_t rpl_send_buffer[BUFFER_SIZE];

Expand Down Expand Up @@ -244,17 +241,25 @@ void rpl_init_root(rpl_options_t *rpl_opts)
return;
}

i_am_root = 1;
trickle_start(rpl_process_pid, &dodag->trickle, RPL_MSG_TYPE_TRICKLE_INTERVAL,
RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), dodag->dio_interval_doubling,
dodag->dio_redundancy);
DEBUGF("ROOT INIT FINISHED\n");

}

/* TODO: this function is used by the ip layer for source routing (non-storing mode)
* to determine if the node is root and change the dodag direction (upwards -> downwards).
* This is a hack and needs to be refactored when the new network stack is ready.
*/
uint8_t rpl_is_root(void)
{
return i_am_root;
for (uint8_t i = 0; i < RPL_MAX_DODAGS; i++) {
if (rpl_dodags[i].node_status == ROOT_NODE) {
return 1;
}
}
return 0;
}

void rpl_send_DIO(rpl_dodag_t *mydodag, ipv6_addr_t *destination)
Expand Down Expand Up @@ -342,12 +347,12 @@ void rpl_send_DAO(rpl_dodag_t *my_dodag, ipv6_addr_t *destination, uint8_t lifet

#endif

if (i_am_root) {
if (my_dodag == NULL) {
DEBUGF("send_DAO: I have no my_dodag\n");
return;
}

if (my_dodag == NULL) {
DEBUGF("send_DAO: I have no my_dodag\n");
if (my_dodag->node_status == ROOT_NODE) {
return;
}

Expand Down Expand Up @@ -777,13 +782,9 @@ void rpl_recv_DAO(void)
}

#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE

if (!i_am_root) {
DEBUGF("[Error] something went wrong - got a DAO.\n");
return;
}

#endif
DEBUGF("[Error] something went wrong - got a DAO.\n");
return;
#else
ipv6_buf = get_rpl_ipv6_buf();
rpl_dao_buf = get_rpl_dao_buf();
DEBUG("instance %04X ", rpl_dao_buf->rpl_instanceid);
Expand Down Expand Up @@ -870,6 +871,7 @@ void rpl_recv_DAO(void)
RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
rpl_delay_dao(my_dodag);
}
#endif
}

void rpl_recv_DIS(void)
Expand Down

0 comments on commit e20fbbb

Please sign in to comment.