2012-01-19 17:35:50 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "rpl_dodag.h"
|
|
|
|
|
|
|
|
rpl_instance_t instances[RPL_MAX_INSTANCES];
|
|
|
|
rpl_dodag_t dodags[RPL_MAX_DODAGS];
|
|
|
|
rpl_parent_t parents[RPL_MAX_PARENTS];
|
|
|
|
|
|
|
|
rpl_instance_t *rpl_new_instance(uint8_t instanceid){
|
|
|
|
rpl_instance_t *inst;
|
|
|
|
rpl_instance_t *end ;
|
|
|
|
for(inst=&instances[0], end = inst+RPL_MAX_INSTANCES; inst < end;inst++){
|
|
|
|
if(inst->used == 0){
|
|
|
|
memset(inst, 0, sizeof(*inst));
|
2012-01-26 20:26:55 +01:00
|
|
|
inst->used = 1;
|
2012-01-19 17:35:50 +01:00
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rpl_instance_t *rpl_get_instance(uint8_t instanceid){
|
|
|
|
for(int i=0;i<RPL_MAX_INSTANCES;i++){
|
|
|
|
if( instances[i].used && (instances[i].id == instanceid)){
|
|
|
|
return &instances[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl_instance_t *rpl_get_my_instance(){
|
|
|
|
for(int i=0;i<RPL_MAX_INSTANCES;i++){
|
|
|
|
if(instances[i].joined){
|
|
|
|
return &instances[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-26 20:26:55 +01:00
|
|
|
rpl_dodag_t * rpl_new_dodag(uint8_t instanceid, ipv6_addr_t *dodagid){
|
2012-01-19 17:35:50 +01:00
|
|
|
rpl_instance_t * inst;
|
|
|
|
inst = rpl_get_instance(instanceid);
|
|
|
|
if(inst == NULL){
|
2012-01-26 20:26:55 +01:00
|
|
|
printf("Error - No instance found for id %d. This should not happen\n", instanceid);
|
2012-01-19 17:35:50 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl_dodag_t *dodag;
|
|
|
|
rpl_dodag_t *end;
|
|
|
|
|
|
|
|
for(dodag= &dodags[0], end=dodag+RPL_MAX_DODAGS; dodag < end; dodag++){
|
|
|
|
if( dodag->used == 0){
|
|
|
|
memset(dodag, 0,sizeof(*dodag));
|
|
|
|
dodag->instance = inst;
|
|
|
|
dodag->my_rank = INFINITE_RANK;
|
|
|
|
dodag->used = 1;
|
2012-01-26 20:26:55 +01:00
|
|
|
dodag->dodag_id = *dodagid;
|
2012-01-19 17:35:50 +01:00
|
|
|
return dodag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl_dodag_t *rpl_get_dodag(ipv6_addr_t *id){
|
|
|
|
for(int i=0;i<RPL_MAX_DODAGS;i++){
|
|
|
|
if( dodags[i].used && (rpl_equal_dodag_id(&dodags[i].dodag_id, id))){
|
|
|
|
return &dodags[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rpl_dodag_t *rpl_get_my_dodag(){
|
|
|
|
for(int i=0;i<RPL_MAX_DODAGS;i++){
|
|
|
|
if( dodags[i].joined){
|
|
|
|
return &dodags[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
void rpl_del_dodag(rpl_dodag_t *dodag){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void rpl_leave_dodag(rpl_dodag_t * dodag){
|
|
|
|
}
|
|
|
|
|
|
|
|
void rpl_join_dodag(){
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rpl_equal_dodag_id(ipv6_addr_t *id1, ipv6_addr_t *id2){
|
|
|
|
for(uint8_t i=0;i<4;i++){
|
|
|
|
if(id1->uint32[i] != id2->uint32[i]){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-26 20:26:55 +01:00
|
|
|
|
|
|
|
rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t rank){
|
|
|
|
rpl_parent_t *parent;
|
|
|
|
rpl_parent_t *end;
|
|
|
|
|
|
|
|
for(parent= &parents[0], end=parents+RPL_MAX_PARENTS; parent < end; parent++){
|
|
|
|
if(parent->used == 0){
|
|
|
|
memset(parent, 0, sizeof(*parent));
|
|
|
|
parent->used = 1;
|
|
|
|
parent->addr = *address;
|
|
|
|
parent->rank = rank;
|
|
|
|
parent->dodag = dodag;
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|