Removed redundant code and improve code style and documentation.
This commit is contained in:
parent
e94718f95c
commit
534c734465
|
@ -88,7 +88,9 @@ rpl_instance_t *default_instance;
|
|||
/************************************************************************/
|
||||
/* 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 */
|
||||
if(a > RPL_LOLLIPOP_CIRCULAR_REGION && b <= RPL_LOLLIPOP_CIRCULAR_REGION) {
|
||||
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 */
|
||||
return p == instance->current_dag->preferred_parent &&
|
||||
(rpl_lollipop_greater_than(dio->dtsn, p->dtsn));
|
||||
(lollipop_greater_than(dio->dtsn, p->dtsn));
|
||||
}
|
||||
/************************************************************************/
|
||||
static int
|
||||
|
@ -418,6 +420,9 @@ rpl_alloc_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
|
|||
return dag;
|
||||
}
|
||||
}
|
||||
|
||||
RPL_STAT(rpl_stats.mem_overflows++);
|
||||
rpl_free_instance(instance);
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -825,8 +830,8 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||
|
||||
instance->of = of;
|
||||
instance->mop = dio->mop;
|
||||
instance->current_dag = dag;
|
||||
instance->dtsn_out = RPL_LOLLIPOP_INIT;
|
||||
instance->instance_id = dio->instance_id;
|
||||
|
||||
instance->max_rankinc = dio->dag_max_rankinc;
|
||||
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));
|
||||
|
||||
/* 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));
|
||||
|
||||
dag->preferred_parent = p;
|
||||
instance->of->update_metric_container(instance);
|
||||
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) {
|
||||
default_instance = instance;
|
||||
|
@ -1039,20 +1045,10 @@ rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p)
|
|||
old_rank = instance->current_dag->rank;
|
||||
return_value = 1;
|
||||
|
||||
if(p->rank == INFINITE_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)) {
|
||||
if(!acceptable_rank(p->dag, p->rank)) {
|
||||
/* The candidate parent is no longer valid: the rank increase resulting
|
||||
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) {
|
||||
rpl_nullify_parent(p->dag, p);
|
||||
return 0;
|
||||
|
@ -1120,7 +1116,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||
return;
|
||||
}
|
||||
|
||||
if(rpl_lollipop_greater_than(dio->version, dag->version)) {
|
||||
if(lollipop_greater_than(dio->version, dag->version)) {
|
||||
if(dag->rank == ROOT_RANK(instance)) {
|
||||
PRINTF("RPL: Root received inconsistent DIO version number\n");
|
||||
dag->version = dio->version;
|
||||
|
@ -1130,8 +1126,9 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||
global_repair(from, dag, dio);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if(rpl_lollipop_greater_than(dag->version, dio->version)) {
|
||||
}
|
||||
|
||||
if(lollipop_greater_than(dag->version, dio->version)) {
|
||||
/* The DIO sender is on an older version of the DAG. */
|
||||
PRINTF("RPL: old version received => inconsistency detected\n");
|
||||
if(dag->joined) {
|
||||
|
@ -1139,16 +1136,13 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dio->rank == INFINITE_RANK) {
|
||||
if(dag->joined) {
|
||||
rpl_reset_dio_timer(instance);
|
||||
}
|
||||
} else if(dio->rank < ROOT_RANK(instance)) {
|
||||
if(dio->rank < ROOT_RANK(instance)) {
|
||||
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
|
||||
(unsigned)dio->rank);
|
||||
return;
|
||||
} else if(dio->rank == INFINITE_RANK && dag->joined) {
|
||||
rpl_reset_dio_timer(instance);
|
||||
}
|
||||
|
||||
if(dag->rank == ROOT_RANK(instance)) {
|
||||
|
|
|
@ -188,12 +188,14 @@ dis_output(uip_ipaddr_t *addr)
|
|||
buffer[0] = buffer[1] = 0;
|
||||
|
||||
if(addr == NULL) {
|
||||
PRINTF("RPL: Sending a DIS\n");
|
||||
uip_create_linklocal_rplnodes_mcast(&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);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -410,7 +412,8 @@ dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr)
|
|||
#endif /* !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) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
*/
|
||||
/**
|
||||
* \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>
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue