mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-09-09 23:54:32 +00:00
changed DAOs to be formatted according to the rpl-08 specification
This commit is contained in:
parent
f52e97111f
commit
ba2bf31c20
@ -33,7 +33,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: rpl-icmp6.c,v 1.14 2010/06/02 11:59:51 joxe Exp $
|
* $Id: rpl-icmp6.c,v 1.15 2010/06/03 14:49:15 joxe Exp $
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
@ -408,13 +408,20 @@ dao_input(void)
|
|||||||
uint16_t sequence;
|
uint16_t sequence;
|
||||||
uint8_t instance_id;
|
uint8_t instance_id;
|
||||||
uint32_t lifetime;
|
uint32_t lifetime;
|
||||||
uint8_t rank;
|
|
||||||
uint8_t prefixlen;
|
uint8_t prefixlen;
|
||||||
uint32_t route_tag;
|
uint8_t flags;
|
||||||
|
uint8_t subopt_type;
|
||||||
uip_ipaddr_t prefix;
|
uip_ipaddr_t prefix;
|
||||||
uip_ds6_route_t *rep;
|
uip_ds6_route_t *rep;
|
||||||
rpl_parent_t *n;
|
rpl_parent_t *n;
|
||||||
|
uint8_t buffer_length;
|
||||||
int pos;
|
int pos;
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
lifetime = 0;
|
||||||
|
prefixlen = 0;
|
||||||
|
|
||||||
|
|
||||||
/* Destination Advertisement Object */
|
/* Destination Advertisement Object */
|
||||||
PRINTF("RPL: Received a DAO from ");
|
PRINTF("RPL: Received a DAO from ");
|
||||||
@ -422,45 +429,61 @@ dao_input(void)
|
|||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
|
|
||||||
buffer = UIP_ICMP_PAYLOAD;
|
buffer = UIP_ICMP_PAYLOAD;
|
||||||
|
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
sequence = (buffer[pos] << 8) | buffer[pos + 1];
|
|
||||||
pos += 2;
|
|
||||||
|
|
||||||
rank = (buffer[pos] << 8) | buffer[pos + 1];
|
|
||||||
pos += 2;
|
|
||||||
|
|
||||||
/* pos = 4 */
|
|
||||||
instance_id = buffer[pos++];
|
instance_id = buffer[pos++];
|
||||||
|
flags = buffer[pos++];
|
||||||
route_tag = buffer[pos++];
|
/* reserved */
|
||||||
prefixlen = buffer[pos++];
|
|
||||||
/* ignore RRCount for now: rrcount = buffer[pos++]; */
|
|
||||||
pos++;
|
pos++;
|
||||||
/* pos = 8 */
|
sequence = buffer[pos++];
|
||||||
lifetime = get32(buffer, pos);
|
|
||||||
pos += 4;
|
|
||||||
|
|
||||||
|
/* is the DAGID present ? */
|
||||||
|
if(flags & RPL_DAO_D_FLAG) {
|
||||||
|
/* currently the DAG ID is ignored since we only use global
|
||||||
|
RPL Instance IDs... */
|
||||||
|
pos += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle the target option */
|
||||||
dag = rpl_get_dag(instance_id);
|
dag = rpl_get_dag(instance_id);
|
||||||
if(dag == NULL) {
|
if(dag == NULL) {
|
||||||
PRINTF("RPL: Ignoring a DAO for a different DAG instance (%u)\n",
|
PRINTF("RPL: Ignoring a DAO for a different DAG instance (%u)\n",
|
||||||
instance_id);
|
instance_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rank < dag->rank) {
|
/* Check if there are any DIO suboptions. */
|
||||||
PRINTF("RPL: Incoming DAO rank is %u, my rank is %u\n",
|
i = pos;
|
||||||
(unsigned)rank, (unsigned)dag->rank);
|
for(; i < buffer_length; i += len) {
|
||||||
return;
|
subopt_type = buffer[i];
|
||||||
|
if(subopt_type == RPL_DIO_SUBOPT_PAD1) {
|
||||||
|
len = 1;
|
||||||
|
} else {
|
||||||
|
/* Suboption with a two-byte header + payload */
|
||||||
|
len = 2 + buffer[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(subopt_type) {
|
||||||
|
case RPL_DIO_SUBOPT_TARGET:
|
||||||
|
prefixlen = buffer[i + 3];
|
||||||
|
memset(&prefix, 0, sizeof(prefix));
|
||||||
|
memcpy(&prefix, buffer + i + 4, prefixlen / CHAR_BIT);
|
||||||
|
break;
|
||||||
|
case RPL_DIO_SUBOPT_TRANSIT:
|
||||||
|
/* path sequence and control ignored */
|
||||||
|
lifetime = get32(buffer, i + 4);
|
||||||
|
/* parent address also ignored */
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&prefix, 0, sizeof(prefix));
|
PRINTF("RPL: DAO lifetime: %lu, prefix length: %u",
|
||||||
memcpy(&prefix, buffer + pos, prefixlen / CHAR_BIT);
|
(unsigned long)lifetime, (unsigned)prefixlen);
|
||||||
|
|
||||||
PRINTF("RPL: DAO rank: %u, lifetime: %lu, prefix length: %u",
|
|
||||||
(unsigned)rank, (unsigned long)lifetime, (unsigned)prefixlen);
|
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(lifetime == ZERO_LIFETIME) {
|
if(lifetime == ZERO_LIFETIME) {
|
||||||
/* No-DAO received; invoke the route purging routine. */
|
/* No-DAO received; invoke the route purging routine. */
|
||||||
rep = uip_ds6_route_lookup(&prefix);
|
rep = uip_ds6_route_lookup(&prefix);
|
||||||
@ -491,8 +514,7 @@ dao_input(void)
|
|||||||
PRINTF("RPL: Forwarding DAO to parent ");
|
PRINTF("RPL: Forwarding DAO to parent ");
|
||||||
PRINT6ADDR(&n->addr);
|
PRINT6ADDR(&n->addr);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
uip_icmp6_send(&n->addr, ICMP6_RPL, RPL_CODE_DAO,
|
uip_icmp6_send(&n->addr, ICMP6_RPL, RPL_CODE_DAO, buffer_length);
|
||||||
14 + (prefixlen / CHAR_BIT));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,11 +531,15 @@ dao_output(rpl_parent_t *n, uint32_t lifetime)
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
/* Destination Advertisement Object */
|
/* Destination Advertisement Object */
|
||||||
|
if(get_global_addr(&prefix) == 0) {
|
||||||
|
PRINTF("RPL: No global address set for this node - suppressing DAO\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(n == NULL) {
|
if(n == NULL) {
|
||||||
dag = rpl_get_dag(RPL_ANY_INSTANCE);
|
dag = rpl_get_dag(RPL_ANY_INSTANCE);
|
||||||
if(dag == NULL) {
|
if(dag == NULL) {
|
||||||
PRINTF("RPL: Did not join a DAG before receiving DAO\n");
|
PRINTF("RPL: Did not join a DAG before sending DAO\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -524,35 +550,29 @@ dao_output(rpl_parent_t *n, uint32_t lifetime)
|
|||||||
|
|
||||||
++sequence;
|
++sequence;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
buffer[pos++] = sequence >> 8;
|
|
||||||
|
buffer[pos++] = dag->instance_id;
|
||||||
|
buffer[pos++] = 0; /* no ack request, no DODAGID */
|
||||||
|
buffer[pos++] = 0; /* reserved */
|
||||||
buffer[pos++] = sequence & 0xff;
|
buffer[pos++] = sequence & 0xff;
|
||||||
|
|
||||||
buffer[pos++] = dag->rank >> 8;
|
/* create target subopt */
|
||||||
buffer[pos++] = dag->rank & 0xff;
|
|
||||||
|
|
||||||
/* pos = 4 */
|
|
||||||
buffer[pos++] = dag->instance_id;
|
|
||||||
/* Route tag. Unspecified in draft-ietf-roll-rpl-06. */
|
|
||||||
buffer[pos++] = 0;
|
|
||||||
|
|
||||||
prefixlen = sizeof(prefix) * CHAR_BIT;
|
prefixlen = sizeof(prefix) * CHAR_BIT;
|
||||||
|
buffer[pos++] = RPL_DIO_SUBOPT_TARGET;
|
||||||
|
buffer[pos++] = 2 + ((prefixlen + 7) / CHAR_BIT);
|
||||||
|
buffer[pos++] = 0; /* reserved */
|
||||||
buffer[pos++] = prefixlen;
|
buffer[pos++] = prefixlen;
|
||||||
/* Reverse route count. Not used because reverse routing is unscalable
|
memcpy(buffer + pos, &prefix, (prefixlen + 7) / CHAR_BIT);
|
||||||
beyond a few hops. */
|
pos += ((prefixlen + 7) / CHAR_BIT);
|
||||||
buffer[pos++] = 0;
|
|
||||||
/* pos = 8 */
|
/* create a transit information subopt */
|
||||||
/* DAO Lifetime. */
|
buffer[pos++] = RPL_DIO_SUBOPT_TRANSIT;
|
||||||
|
buffer[pos++] = 6;
|
||||||
|
buffer[pos++] = 0; /* path seq - ignored */
|
||||||
|
buffer[pos++] = 0; /* path control - ignored */
|
||||||
set32(buffer, pos, lifetime);
|
set32(buffer, pos, lifetime);
|
||||||
pos += 4;
|
pos += 4;
|
||||||
|
|
||||||
/* pos = 12 or 14 */
|
|
||||||
if(get_global_addr(&prefix) == 0) {
|
|
||||||
PRINTF("RPL: No global address set for this node - suppressing DAO\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
memcpy(buffer + pos, &prefix, prefixlen / CHAR_BIT);
|
|
||||||
pos += (prefixlen / CHAR_BIT);
|
|
||||||
|
|
||||||
if(n == NULL) {
|
if(n == NULL) {
|
||||||
uip_create_linklocal_allnodes_mcast(&addr);
|
uip_create_linklocal_allnodes_mcast(&addr);
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Joakim Eriksson, Nicolas Tsiftes
|
* Author: Joakim Eriksson, Nicolas Tsiftes
|
||||||
*
|
*
|
||||||
* $Id: rpl.h,v 1.10 2010/06/02 16:55:00 joxe Exp $
|
* $Id: rpl.h,v 1.11 2010/06/03 14:49:16 joxe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RPL_H
|
#ifndef RPL_H
|
||||||
@ -71,7 +71,7 @@
|
|||||||
#define RPL_CODE_SEC_DAO 0x82 /* DAO message */
|
#define RPL_CODE_SEC_DAO 0x82 /* DAO message */
|
||||||
#define RPL_CODE_SEC_DAO_ACK 0x83 /* DAO ACK message */
|
#define RPL_CODE_SEC_DAO_ACK 0x83 /* DAO ACK message */
|
||||||
|
|
||||||
/* RPL DIO suboption types */
|
/* RPL DIO/DAO suboption types */
|
||||||
#define RPL_DIO_SUBOPT_PAD1 0 /* Pad1 */
|
#define RPL_DIO_SUBOPT_PAD1 0 /* Pad1 */
|
||||||
#define RPL_DIO_SUBOPT_PADN 1 /* PadN */
|
#define RPL_DIO_SUBOPT_PADN 1 /* PadN */
|
||||||
#define RPL_DIO_SUBOPT_DAG_MC 2 /* DAG metric container */
|
#define RPL_DIO_SUBOPT_DAG_MC 2 /* DAG metric container */
|
||||||
@ -84,6 +84,9 @@
|
|||||||
|
|
||||||
#define RPL_DIO_SUBOPT_OCP 9 /* 5 in the MC document... */
|
#define RPL_DIO_SUBOPT_OCP 9 /* 5 in the MC document... */
|
||||||
|
|
||||||
|
#define RPL_DAO_K_FLAG 0x80 /* DAO ACK requested */
|
||||||
|
#define RPL_DAO_D_FLAG 0x40 /* DODAG ID Present */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Default values for RPL constants and variables. */
|
/* Default values for RPL constants and variables. */
|
||||||
|
|
||||||
@ -127,6 +130,8 @@
|
|||||||
/* Expire DAOs from neighbors that do not respond in this time. (seconds) */
|
/* Expire DAOs from neighbors that do not respond in this time. (seconds) */
|
||||||
#define DAO_EXPIRATION_TIMEOUT 60
|
#define DAO_EXPIRATION_TIMEOUT 60
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#define RPL_INSTANCE_LOCAL_FLAG 0x80
|
||||||
|
#define RPL_INSTANCE_D_FLAG 0x40
|
||||||
|
|
||||||
#define RPL_ROUTE_FROM_INTERNAL 0
|
#define RPL_ROUTE_FROM_INTERNAL 0
|
||||||
#define RPL_ROUTE_FROM_UNICAST_DAO 1
|
#define RPL_ROUTE_FROM_UNICAST_DAO 1
|
||||||
|
Loading…
Reference in New Issue
Block a user