Skip to content

Commit

Permalink
[SQUASH ME] exposed the "getter" for parents,
Browse files Browse the repository at this point in the history
            renamed `parents[]` to `rpl_parents[]` and made it `extern`
  • Loading branch information
BytesGalore authored and BytesGalore committed Jul 15, 2015
1 parent 1f1b8a0 commit 2eee29e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions sys/net/include/rpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern char rpl_process_buf[RPL_PROCESS_STACKSIZE];
extern uint8_t rpl_buffer[BUFFER_SIZE - LL_HDR_LEN];
extern kernel_pid_t rpl_if_id;
extern rpl_dodag_t rpl_dodags[RPL_MAX_DODAGS];
extern rpl_parent_t rpl_parents[RPL_MAX_PARENTS];

/**
* @brief Sends a RPL message to a given destination
Expand Down
1 change: 0 additions & 1 deletion sys/net/include/rpl/rpl_dodag.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ rpl_dodag_t *rpl_get_joined_dodag(uint8_t instanceid);
rpl_dodag_t *rpl_get_my_dodag(void);
void rpl_join_dodag(rpl_dodag_t *dodag, ipv6_addr_t *parent, uint16_t parent_rank);
void rpl_del_dodag(rpl_dodag_t *dodag);
rpl_parent_t *rpl_get_parents(void);
rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t rank);
rpl_parent_t *rpl_find_parent(rpl_dodag_t *dodag, ipv6_addr_t *address);
void rpl_leave_dodag(rpl_dodag_t *dodag);
Expand Down
4 changes: 2 additions & 2 deletions sys/net/routing/rpl/rpl_control_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,12 @@ void rpl_send_DAO(rpl_dodag_t *my_dodag, ipv6_addr_t *destination, uint8_t lifet
uint8_t continue_index = 0;

for (uint8_t i = start_index; i < RPL_MAX_PARENTS; i++) {
if(rpl_get_parents()[i].used) {
if(rpl_parents[i].used) {
rpl_send_opt_target_buf->type = RPL_OPT_TARGET;
rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN;
rpl_send_opt_target_buf->flags = 0x00;
rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN;
memcpy(&rpl_send_opt_target_buf->target, &rpl_get_parents()[i].addr,
memcpy(&rpl_send_opt_target_buf->target, &rpl_parents[i].addr,
sizeof(ipv6_addr_t));
opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN;
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
Expand Down
36 changes: 16 additions & 20 deletions sys/net/routing/rpl/rpl_dodag.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ char addr_str[IPV6_MAX_ADDR_STR_LEN];

static rpl_instance_t instances[RPL_MAX_INSTANCES];
rpl_dodag_t rpl_dodags[RPL_MAX_DODAGS];
static rpl_parent_t parents[RPL_MAX_PARENTS];
rpl_parent_t rpl_parents[RPL_MAX_PARENTS];

void rpl_trickle_send_dio(void *args)
{
Expand Down Expand Up @@ -162,11 +162,6 @@ bool rpl_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2)
return true;
}

rpl_parent_t *rpl_get_parents(void)
{
return &parents[0];
}

rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t rank)
{
rpl_parent_t *parent;
Expand All @@ -175,7 +170,7 @@ rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t
timex_t now;
vtimer_now(&now);

for (parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) {
for (parent = &rpl_parents[0], end = rpl_parents + RPL_MAX_PARENTS; parent < end; parent++) {
if (parent->used == 0) {
memset(parent, 0, sizeof(*parent));
parent->used = 1;
Expand All @@ -202,7 +197,7 @@ rpl_parent_t *rpl_find_parent(rpl_dodag_t *dodag, ipv6_addr_t *address)
rpl_parent_t *parent;
rpl_parent_t *end;

for (parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) {
for (parent = &rpl_parents[0], end = rpl_parents + RPL_MAX_PARENTS; parent < end; parent++) {
if ((parent->used) && (rpl_equal_id(address, &parent->addr)
&& (parent->dodag->instance->id == dodag->instance->id)
&& (!memcmp(&parent->dodag->dodag_id,
Expand Down Expand Up @@ -230,9 +225,9 @@ void rpl_delete_worst_parent(void)
uint16_t max_rank = 0x0000;

for (int i = 0; i < RPL_MAX_PARENTS; i++) {
if (parents[i].rank > max_rank) {
if (rpl_parents[i].rank > max_rank) {
worst = i;
max_rank = parents[i].rank;
max_rank = rpl_parents[i].rank;
}
}

Expand All @@ -241,7 +236,7 @@ void rpl_delete_worst_parent(void)
return;
}

rpl_delete_parent(&parents[worst]);
rpl_delete_parent(&rpl_parents[worst]);

}

Expand All @@ -250,9 +245,9 @@ void rpl_delete_all_parents(rpl_dodag_t *dodag)

dodag->my_preferred_parent = NULL;
for (int i = 0; i < RPL_MAX_PARENTS; i++) {
if (parents[i].dodag && (dodag->instance->id == parents[i].dodag->instance->id) &&
(!memcmp(&dodag->dodag_id, &parents[i].dodag->dodag_id, sizeof(ipv6_addr_t)))) {
memset(&parents[i], 0, sizeof(parents[i]));
if (rpl_parents[i].dodag && (dodag->instance->id == rpl_parents[i].dodag->instance->id) &&
(!memcmp(&dodag->dodag_id, &rpl_parents[i].dodag->dodag_id, sizeof(ipv6_addr_t)))) {
memset(&rpl_parents[i], 0, sizeof(rpl_parents[i]));
}
}
}
Expand All @@ -270,20 +265,21 @@ rpl_parent_t *rpl_find_preferred_parent(rpl_dodag_t *my_dodag)
}

for (uint8_t i = 0; i < RPL_MAX_PARENTS; i++) {
if (parents[i].used
&& (parents[i].dodag->instance->id == my_dodag->instance->id)
&& (!memcmp(&parents[i].dodag->dodag_id,
if (rpl_parents[i].used
&& (rpl_parents[i].dodag->instance->id == my_dodag->instance->id)
&& (!memcmp(&rpl_parents[i].dodag->dodag_id,
&my_dodag->dodag_id, sizeof(ipv6_addr_t)))) {
if ((parents[i].rank == INFINITE_RANK) || ((parents[i].lifetime.seconds-now.seconds) <= 1)) {
if ((rpl_parents[i].rank == INFINITE_RANK)
|| ((rpl_parents[i].lifetime.seconds-now.seconds) <= 1)) {
DEBUG("Infinite rank, bad parent\n");
continue;
}
else if (best == NULL) {
DEBUG("possible parent\n");
best = &parents[i];
best = &rpl_parents[i];
}
else {
best = my_dodag->of->which_parent(best, &parents[i]);
best = my_dodag->of->which_parent(best, &rpl_parents[i]);
}
}
}
Expand Down

0 comments on commit 2eee29e

Please sign in to comment.