Removed redundant code and improve code style and documentation.

This commit is contained in:
nvt 2012-04-22 00:18:07 +02:00
parent e94718f95c
commit 534c734465
3 changed files with 38 additions and 40 deletions

View File

@ -88,7 +88,9 @@ rpl_instance_t *default_instance;
/************************************************************************/ /************************************************************************/
/* Greater-than function for the lollipop counter. */ /* Greater-than function for the lollipop counter. */
/************************************************************************/ /************************************************************************/
int rpl_lollipop_greater_than(int a, int b) { static int
lollipop_greater_than(int a, int b)
{
/* Check if we are comparing an initial value with an old value */ /* Check if we are comparing an initial value with an old value */
if(a > RPL_LOLLIPOP_CIRCULAR_REGION && b <= RPL_LOLLIPOP_CIRCULAR_REGION) { if(a > RPL_LOLLIPOP_CIRCULAR_REGION && b <= RPL_LOLLIPOP_CIRCULAR_REGION) {
return (RPL_LOLLIPOP_MAX_VALUE + 1 + b - a) > RPL_LOLLIPOP_SEQUENCE_WINDOWS; return (RPL_LOLLIPOP_MAX_VALUE + 1 + b - a) > RPL_LOLLIPOP_SEQUENCE_WINDOWS;
@ -163,7 +165,7 @@ should_send_dao(rpl_instance_t *instance, rpl_dio_t *dio, rpl_parent_t *p)
} }
/* check if the new DTSN is more recent */ /* check if the new DTSN is more recent */
return p == instance->current_dag->preferred_parent && return p == instance->current_dag->preferred_parent &&
(rpl_lollipop_greater_than(dio->dtsn, p->dtsn)); (lollipop_greater_than(dio->dtsn, p->dtsn));
} }
/************************************************************************/ /************************************************************************/
static int static int
@ -418,6 +420,9 @@ rpl_alloc_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
return dag; return dag;
} }
} }
RPL_STAT(rpl_stats.mem_overflows++);
rpl_free_instance(instance);
return NULL; return NULL;
} }
/************************************************************************/ /************************************************************************/
@ -814,7 +819,7 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
/* Autoconfigure an address if this node does not already have an address /* Autoconfigure an address if this node does not already have an address
with this prefix. */ with this prefix. */
if((dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) { if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
check_prefix(NULL, &dio->prefix_info); check_prefix(NULL, &dio->prefix_info);
} }
@ -825,8 +830,8 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
instance->of = of; instance->of = of;
instance->mop = dio->mop; instance->mop = dio->mop;
instance->current_dag = dag;
instance->dtsn_out = RPL_LOLLIPOP_INIT; instance->dtsn_out = RPL_LOLLIPOP_INIT;
instance->instance_id = dio->instance_id;
instance->max_rankinc = dio->dag_max_rankinc; instance->max_rankinc = dio->dag_max_rankinc;
instance->min_hoprankinc = dio->dag_min_hoprankinc; instance->min_hoprankinc = dio->dag_min_hoprankinc;
@ -839,13 +844,14 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id)); memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));
/* copy prefix information into the dag */ /* Copy prefix information from the DIO into the DAG object. */
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t)); memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
dag->preferred_parent = p; dag->preferred_parent = p;
instance->of->update_metric_container(instance); instance->of->update_metric_container(instance);
dag->rank = instance->of->calculate_rank(p, 0); dag->rank = instance->of->calculate_rank(p, 0);
dag->min_rank = dag->rank; /* So far this is the lowest rank we know of. */ /* So far this is the lowest rank we are aware of. */
dag->min_rank = dag->rank;
if(default_instance == NULL) { if(default_instance == NULL) {
default_instance = instance; default_instance = instance;
@ -966,7 +972,7 @@ global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
dag->rank = INFINITE_RANK; dag->rank = INFINITE_RANK;
} else { } else {
dag->rank = dag->instance->of->calculate_rank(p, 0); dag->rank = dag->instance->of->calculate_rank(p, 0);
dag->min_rank = dag->rank ; dag->min_rank = dag->rank;
rpl_process_parent_event(dag->instance, p); rpl_process_parent_event(dag->instance, p);
} }
@ -1039,20 +1045,10 @@ rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p)
old_rank = instance->current_dag->rank; old_rank = instance->current_dag->rank;
return_value = 1; return_value = 1;
if(p->rank == INFINITE_RANK) { if(!acceptable_rank(p->dag, p->rank)) {
/* This parent is no longer valid */
PRINTF("RPL: This parent is no longer valid \n");
if(p != instance->current_dag->preferred_parent) {
rpl_nullify_parent(p->dag, p);
return 0;
} else {
rpl_nullify_parent(p->dag, p);
return_value = 0;
}
} else if(!acceptable_rank(p->dag, p->rank)) {
/* The candidate parent is no longer valid: the rank increase resulting /* The candidate parent is no longer valid: the rank increase resulting
from the choice of it as a parent would be too high. */ from the choice of it as a parent would be too high. */
PRINTF("RPL: Unacceptable rank\n"); PRINTF("RPL: Unacceptable rank %u\n", (unsigned)p->rank);
if(p != instance->current_dag->preferred_parent) { if(p != instance->current_dag->preferred_parent) {
rpl_nullify_parent(p->dag, p); rpl_nullify_parent(p->dag, p);
return 0; return 0;
@ -1120,7 +1116,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
return; return;
} }
if(rpl_lollipop_greater_than(dio->version, dag->version)) { if(lollipop_greater_than(dio->version, dag->version)) {
if(dag->rank == ROOT_RANK(instance)) { if(dag->rank == ROOT_RANK(instance)) {
PRINTF("RPL: Root received inconsistent DIO version number\n"); PRINTF("RPL: Root received inconsistent DIO version number\n");
dag->version = dio->version; dag->version = dio->version;
@ -1130,25 +1126,23 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
global_repair(from, dag, dio); global_repair(from, dag, dio);
} }
return; return;
} else { }
if(rpl_lollipop_greater_than(dag->version, dio->version)) {
/* The DIO sender is on an older version of the DAG. */ if(lollipop_greater_than(dag->version, dio->version)) {
PRINTF("RPL: old version received => inconsistency detected\n"); /* The DIO sender is on an older version of the DAG. */
if(dag->joined) { PRINTF("RPL: old version received => inconsistency detected\n");
rpl_reset_dio_timer(instance); if(dag->joined) {
return; rpl_reset_dio_timer(instance);
} return;
} }
} }
if(dio->rank == INFINITE_RANK) { if(dio->rank < ROOT_RANK(instance)) {
if(dag->joined) {
rpl_reset_dio_timer(instance);
}
} else if(dio->rank < ROOT_RANK(instance)) {
PRINTF("RPL: Ignoring DIO with too low rank: %u\n", PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
(unsigned)dio->rank); (unsigned)dio->rank);
return; return;
} else if(dio->rank == INFINITE_RANK && dag->joined) {
rpl_reset_dio_timer(instance);
} }
if(dag->rank == ROOT_RANK(instance)) { if(dag->rank == ROOT_RANK(instance)) {

View File

@ -155,7 +155,7 @@ dis_input(void)
PRINTF("\n"); PRINTF("\n");
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) { for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
if(instance->used == 1 ) { if(instance->used == 1) {
#if RPL_LEAF_ONLY #if RPL_LEAF_ONLY
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) { if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
#else /* !RPL_LEAF_ONLY */ #else /* !RPL_LEAF_ONLY */
@ -177,7 +177,7 @@ dis_output(uip_ipaddr_t *addr)
unsigned char *buffer; unsigned char *buffer;
uip_ipaddr_t tmpaddr; uip_ipaddr_t tmpaddr;
/* DAG Information Solicitation - 2 bytes reserved */ /* DAG Information Solicitation - 2 bytes reserved */
/* 0 1 2 */ /* 0 1 2 */
/* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 */ /* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 */
/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
@ -188,12 +188,14 @@ dis_output(uip_ipaddr_t *addr)
buffer[0] = buffer[1] = 0; buffer[0] = buffer[1] = 0;
if(addr == NULL) { if(addr == NULL) {
PRINTF("RPL: Sending a DIS\n");
uip_create_linklocal_rplnodes_mcast(&tmpaddr); uip_create_linklocal_rplnodes_mcast(&tmpaddr);
addr = &tmpaddr; addr = &tmpaddr;
} else {
PRINTF("RPL: Sending a unicast DIS\n");
} }
PRINTF("RPL: Sending a DIS to ");
PRINT6ADDR(addr);
PRINTF("\n");
uip_icmp6_send(addr, ICMP6_RPL, RPL_CODE_DIS, 2); uip_icmp6_send(addr, ICMP6_RPL, RPL_CODE_DIS, 2);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -410,7 +412,8 @@ dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr)
#endif /* !RPL_LEAF_ONLY */ #endif /* !RPL_LEAF_ONLY */
#if RPL_LEAF_ONLY #if RPL_LEAF_ONLY
/* only respond to unicast DIS */ /* In leaf mode, we send DIO message only as unicasts in response to
unicast DIS messages. */
if(uc_addr == NULL) { if(uc_addr == NULL) {
return; return;
} }

View File

@ -34,7 +34,8 @@
*/ */
/** /**
* \file * \file
* ContikiRPL, an implementation of IETF ROLL RPL. * ContikiRPL, an implementation of RPL: IPv6 Routing Protocol
* for Low-Power and Lossy Networks (IETF RFC 6550)
* *
* \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se> * \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se>
*/ */