mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
Refactored loop detection.
This commit is contained in:
parent
ac869185c0
commit
23a280e5eb
@ -66,6 +66,8 @@ int
|
|||||||
rpl_verify_header(int uip_ext_opt_offset)
|
rpl_verify_header(int uip_ext_opt_offset)
|
||||||
{
|
{
|
||||||
rpl_instance_t *instance;
|
rpl_instance_t *instance;
|
||||||
|
long diff;
|
||||||
|
int down;
|
||||||
|
|
||||||
if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|
if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|
||||||
PRINTF("RPL: Bad header option! (wrong length)\n");
|
PRINTF("RPL: Bad header option! (wrong length)\n");
|
||||||
@ -90,12 +92,18 @@ rpl_verify_header(int uip_ext_opt_offset)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
down = 0;
|
||||||
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) {
|
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) {
|
||||||
PRINTF("RPL: Packet going down :\n");
|
down = 1;
|
||||||
if(UIP_EXT_HDR_OPT_RPL_BUF->senderrank > instance->current_dag->rank) {
|
}
|
||||||
PRINTF("RPL: Loop detected: Sender rank > our rank\n");
|
|
||||||
|
PRINTF("RPL: Packet going %s\n", down == 1 ? "down" : "up");
|
||||||
|
|
||||||
|
diff = UIP_EXT_HDR_OPT_RPL_BUF->senderrank - instance->current_dag->rank;
|
||||||
|
if((down && diff > 0) || (!down && diff < 0)) {
|
||||||
|
PRINTF("RPL: Loop detected\n");
|
||||||
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) {
|
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) {
|
||||||
PRINTF("RPL: Loop detected !\n");
|
PRINTF("RPL: Rank error signalled in RPL option!\n");
|
||||||
/* We should try to repair it, not implemented for the moment */
|
/* We should try to repair it, not implemented for the moment */
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
@ -103,20 +111,6 @@ rpl_verify_header(int uip_ext_opt_offset)
|
|||||||
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
|
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
PRINTF("RPL: Packet going up :");
|
|
||||||
if(UIP_EXT_HDR_OPT_RPL_BUF->senderrank < instance->current_dag->rank) {
|
|
||||||
PRINTF("RPL: Rank error: Sender rank < our rank\n");
|
|
||||||
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) {
|
|
||||||
PRINTF("RPL: Loop detected !\n");
|
|
||||||
/* We should try to repair it, not implemented for the moment */
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
PRINTF("RPL: Single error tolerated\n");
|
|
||||||
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PRINTF("RPL: Rank OK\n");
|
PRINTF("RPL: Rank OK\n");
|
||||||
|
|
||||||
@ -247,7 +241,7 @@ rpl_remove_header(void)
|
|||||||
PRINTF("RPL: Verifying the presence of the RPL header option\n");
|
PRINTF("RPL: Verifying the presence of the RPL header option\n");
|
||||||
switch(UIP_IP_BUF->proto){
|
switch(UIP_IP_BUF->proto){
|
||||||
case UIP_PROTO_HBHO:
|
case UIP_PROTO_HBHO:
|
||||||
PRINTF("RPL: Removing the present RPL header option\n");
|
PRINTF("RPL: Removing the RPL header option\n");
|
||||||
UIP_IP_BUF->proto = UIP_HBHO_BUF->next;
|
UIP_IP_BUF->proto = UIP_HBHO_BUF->next;
|
||||||
temp_len = UIP_IP_BUF->len[1];
|
temp_len = UIP_IP_BUF->len[1];
|
||||||
uip_len -= UIP_HBHO_BUF->len + 8;
|
uip_len -= UIP_HBHO_BUF->len + 8;
|
||||||
@ -258,7 +252,7 @@ rpl_remove_header(void)
|
|||||||
memmove(UIP_EXT_BUF, UIP_HBHO_NEXT_BUF, uip_len - UIP_IPH_LEN);
|
memmove(UIP_EXT_BUF, UIP_HBHO_NEXT_BUF, uip_len - UIP_IPH_LEN);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PRINTF("RPL: No Hop-by-Hop Option found\n");
|
PRINTF("RPL: No hop-by-hop Option found\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
@ -277,13 +271,14 @@ rpl_invert_header(void)
|
|||||||
case UIP_PROTO_HBHO:
|
case UIP_PROTO_HBHO:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PRINTF("RPL: No Hop-by-Hop Option found\n");
|
PRINTF("RPL: No hop-by-hop Option found\n");
|
||||||
uip_ext_len = last_uip_ext_len;
|
uip_ext_len = last_uip_ext_len;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (UIP_EXT_HDR_OPT_BUF->type) {
|
switch (UIP_EXT_HDR_OPT_BUF->type) {
|
||||||
case UIP_EXT_HDR_OPT_RPL:
|
case UIP_EXT_HDR_OPT_RPL:
|
||||||
PRINTF("RPL: Updating RPL option (Inverting Up<->Down)\n");
|
PRINTF("RPL: Updating RPL option (switching direction)\n");
|
||||||
UIP_EXT_HDR_OPT_RPL_BUF->flags &= RPL_HDR_OPT_DOWN;
|
UIP_EXT_HDR_OPT_RPL_BUF->flags &= RPL_HDR_OPT_DOWN;
|
||||||
UIP_EXT_HDR_OPT_RPL_BUF->flags ^= RPL_HDR_OPT_DOWN;
|
UIP_EXT_HDR_OPT_RPL_BUF->flags ^= RPL_HDR_OPT_DOWN;
|
||||||
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank;
|
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank;
|
||||||
|
Loading…
Reference in New Issue
Block a user