Skip to content

Commit

Permalink
ng_rpl: auto address configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cgundogan committed Aug 18, 2015
1 parent 147bf75 commit 5dde732
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sys/include/net/ng_rpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ static inline bool NG_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
*/
#define NG_RPL_LIFETIME_STEP (2)

/**
* @brief Default prefix length for the DODAG id
*/
#define NG_RPL_DEFAULT_PREFIX_LEN (64)

/**
* @brief Default prefix valid and preferred time for the DODAG id
*/
#define NG_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)

/**
* @brief A DODAG can be grounded or floating
* @see <a href="https://tools.ietf.org/html/rfc6550#section-3.2.4">
Expand Down
20 changes: 20 additions & 0 deletions sys/include/net/ng_rpl/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ typedef struct __attribute__((packed)) {
uint8_t path_lifetime; /**< lifetime of routes */
} ng_rpl_opt_transit_t;

/**
* @brief Prefix Information Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.10">
* Prefix Information
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t prefix_len; /**< prefix length */
uint8_t LAR_flags; /**< flags and resereved */
uint32_t valid_lifetime; /**< valid lifetime */
uint32_t pref_lifetime; /**< preferred lifetime */
uint32_t reserved; /**< reserved */
ipv6_addr_t prefix; /**< prefix */
} ng_rpl_opt_prefix_info_t;

typedef struct ng_rpl_dodag ng_rpl_dodag_t;
typedef struct ng_rpl_parent ng_rpl_parent_t;

Expand Down Expand Up @@ -201,6 +218,9 @@ struct ng_rpl_dodag {
ng_rpl_dodag_t *next; /**< pointer to the next dodag */
ng_rpl_parent_t *parents; /**< pointer to the parents list of this DODAG */
ipv6_addr_t dodag_id; /**< id of the DODAG */
uint8_t prefix_len; /**< length of the prefix for the DODAG id */
uint32_t addr_preferred; /**< time in seconds the DODAG id is preferred */
uint32_t addr_valid; /**< time in seconds the DODAG id is valid */
uint8_t state; /**< 0 for unused, 1 for used */
uint8_t dtsn; /**< DAO Trigger Sequence Number */
uint8_t prf; /**< preferred flag */
Expand Down
11 changes: 11 additions & 0 deletions sys/net/routing/ng_rpl/ng_rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static ng_rpl_dodag_t *_root_dodag_init(uint8_t instance_id, ipv6_addr_t *dodag_
}

ipv6_addr_t *configured_addr;
ng_ipv6_netif_addr_t *netif_addr = NULL;
ng_rpl_instance_t *inst = NULL;
ng_rpl_dodag_t *dodag = NULL;

Expand All @@ -120,6 +121,12 @@ static ng_rpl_dodag_t *_root_dodag_init(uint8_t instance_id, ipv6_addr_t *dodag_
return NULL;
}

if ((netif_addr = ng_ipv6_netif_addr_get(configured_addr)) == NULL) {
DEBUG("RPL: no netif address found for %s\n", ipv6_addr_to_str(addr_str, configured_addr,
sizeof(addr_str)));
return NULL;
}

if (ng_rpl_instance_add(instance_id, &inst)) {
inst->of = (ng_rpl_of_t *) ng_rpl_get_of_for_ocp(NG_RPL_DEFAULT_OCP);
inst->mop = mop;
Expand All @@ -141,6 +148,10 @@ static ng_rpl_dodag_t *_root_dodag_init(uint8_t instance_id, ipv6_addr_t *dodag_
return NULL;
}

dodag->prefix_len = netif_addr->prefix_len;
dodag->addr_preferred = netif_addr->preferred;
dodag->addr_valid = netif_addr->valid;

return dodag;
}

Expand Down
40 changes: 40 additions & 0 deletions sys/net/routing/ng_rpl/ng_rpl_control_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "net/ng_icmpv6.h"
#include "net/ng_rpl.h"
#include "inet_ntop.h"
#include "net/eui64.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand All @@ -30,8 +31,10 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#define NG_RPL_GROUNDED_SHIFT (7)
#define NG_RPL_MOP_SHIFT (3)
#define NG_RPL_OPT_DODAG_CONF_LEN (14)
#define NG_RPL_OPT_PREFIX_INFO_LEN (30)
#define NG_RPL_SHIFTED_MOP_MASK (0x7)
#define NG_RPL_PRF_MASK (0x7)
#define NG_RPL_PREFIX_AUTO_ADDRESS_BIT (1 << 6)

void _ng_rpl_send(ng_pktsnip_t *pkt, ipv6_addr_t *src, ipv6_addr_t *dst,
ipv6_addr_t *dodag_id)
Expand Down Expand Up @@ -100,6 +103,7 @@ void ng_rpl_send_DIO(ng_rpl_dodag_t *dodag, ipv6_addr_t *destination)

if ((dodag->dodag_conf_counter % 3) == 0) {
size += sizeof(ng_rpl_opt_dodag_conf_t);
size += sizeof(ng_rpl_opt_prefix_info_t);
}

if ((pkt = ng_icmpv6_build(NULL, ICMPV6_RPL_CTRL, NG_RPL_ICMPV6_CODE_DIO, size)) == NULL) {
Expand Down Expand Up @@ -138,6 +142,22 @@ void ng_rpl_send_DIO(ng_rpl_dodag_t *dodag, ipv6_addr_t *destination)
dodag_conf->default_lifetime = dodag->default_lifetime;
dodag_conf->lifetime_unit = byteorder_htons(dodag->lifetime_unit);
pos += sizeof(*dodag_conf);

ng_rpl_opt_prefix_info_t *prefix_info;
prefix_info = (ng_rpl_opt_prefix_info_t *) pos;
prefix_info->type = NG_RPL_OPT_PREFIX_INFO;
prefix_info->length = NG_RPL_OPT_PREFIX_INFO_LEN;
/* auto-address configuration */
prefix_info->LAR_flags = NG_RPL_PREFIX_AUTO_ADDRESS_BIT;
prefix_info->valid_lifetime = dodag->addr_valid;
prefix_info->pref_lifetime = dodag->addr_preferred;
prefix_info->prefix_len = dodag->prefix_len;
prefix_info->reserved = 0;

memset(&prefix_info->prefix, 0, sizeof(prefix_info->prefix));
ipv6_addr_init_prefix(&prefix_info->prefix, &dodag->dodag_id, dodag->prefix_len);

pos += sizeof(*prefix_info);
}

dodag->dodag_conf_counter++;
Expand Down Expand Up @@ -199,6 +219,7 @@ bool _parse_options(int msg_type, ng_rpl_dodag_t *dodag, ng_rpl_opt_t *opt, uint
{
uint16_t l = 0;
ng_rpl_opt_target_t *first_target = NULL;
eui64_t iid;
while(l < len) {
if ((opt->type != NG_RPL_OPT_PAD1) && (len < opt->length + sizeof(ng_rpl_opt_t) + l)) {
/* return false to delete the dodag,
Expand Down Expand Up @@ -244,6 +265,25 @@ bool _parse_options(int msg_type, ng_rpl_dodag_t *dodag, ng_rpl_opt_t *opt, uint
dodag->trickle.k = dodag->dio_redun;
break;
}
case (NG_RPL_OPT_PREFIX_INFO): {
if (msg_type != NG_RPL_ICMPV6_CODE_DIO) {
DEBUG("RPL: Ignore Prefix Information DIO option\n");
return true;
}
DEBUG("RPL: Prefix Information DIO option parsed\n");
ng_rpl_opt_prefix_info_t *pi = (ng_rpl_opt_prefix_info_t *) opt;
ipv6_addr_t all_RPL_nodes = NG_IPV6_ADDR_ALL_RPL_NODES;
kernel_pid_t if_id = ng_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes);
/* check for the auto address-configuration flag */
if ((ng_netapi_get(if_id, NETOPT_IPV6_IID, 0, &iid, sizeof(eui64_t)) < 0) &&
!(pi->LAR_flags & NG_RPL_PREFIX_AUTO_ADDRESS_BIT)) {
break;
}
ipv6_addr_set_aiid(&pi->prefix, iid.uint8);
ng_ipv6_netif_add_addr(if_id, &pi->prefix, pi->prefix_len, 0);

break;
}
case (NG_RPL_OPT_TARGET): {
if (msg_type != NG_RPL_ICMPV6_CODE_DAO) {
DEBUG("RPL: Ignore RPL TARGET DAO option\n");
Expand Down
4 changes: 4 additions & 0 deletions sys/net/routing/ng_rpl/ng_rpl_dodag.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "net/ng_rpl/dodag.h"
#include "net/ng_rpl/structs.h"
#include "utlist.h"
#include "net/ng_rpl.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand Down Expand Up @@ -135,6 +136,9 @@ bool ng_rpl_dodag_add(ng_rpl_instance_t *instance, ipv6_addr_t *dodag_id, ng_rpl
LL_APPEND(instance->dodags, *dodag);
(*dodag)->state = 1;
(*dodag)->dodag_id = *dodag_id;
(*dodag)->prefix_len = NG_RPL_DEFAULT_PREFIX_LEN;
(*dodag)->addr_preferred = NG_RPL_DEFAULT_PREFIX_LIFETIME;
(*dodag)->addr_valid = NG_RPL_DEFAULT_PREFIX_LIFETIME;
(*dodag)->my_rank = NG_RPL_INFINITE_RANK;
(*dodag)->trickle.callback.func = &rpl_trickle_send_dio;
(*dodag)->trickle.callback.args = *dodag;
Expand Down

0 comments on commit 5dde732

Please sign in to comment.