Skip to content

Commit

Permalink
[SQUASH ME] use configured prefix and valid/preferred time
Browse files Browse the repository at this point in the history
  • Loading branch information
cgundogan committed Jul 27, 2015
1 parent ef72c4d commit f863b8f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 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 @@ -208,6 +208,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
3 changes: 3 additions & 0 deletions sys/include/net/ng_rpl/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,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 */
ng_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
13 changes: 12 additions & 1 deletion sys/net/routing/ng_rpl/ng_rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static ng_rpl_dodag_t *_root_dodag_init(uint8_t instance_id, ng_ipv6_addr_t *dod
}

ng_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 @@ -115,7 +116,13 @@ static ng_rpl_dodag_t *_root_dodag_init(uint8_t instance_id, ng_ipv6_addr_t *dod

if (ng_ipv6_netif_find_by_addr(&configured_addr, dodag_id) == KERNEL_PID_UNDEF) {
DEBUG("RPL: no IPv6 address configured to match the given dodag id: %s\n",
ng_ipv6_addr_to_str(addr_str, dodag_id, sizeof(addr_str)));
ng_ipv6_addr_to_str(addr_str, dodag_id, sizeof(addr_str)));
return NULL;
}

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

Expand All @@ -140,6 +147,10 @@ static ng_rpl_dodag_t *_root_dodag_init(uint8_t instance_id, ng_ipv6_addr_t *dod
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
25 changes: 19 additions & 6 deletions sys/net/routing/ng_rpl/ng_rpl_control_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ static char addr_str[NG_IPV6_ADDR_MAX_STR_LEN];
#define NG_RPL_OPT_PREFIX_INFO_LEN (30)
#define NG_RPL_SHIFTED_MOP_MASK (0x7)
#define NG_RPL_PRF_MASK (0x7)
#define NG_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
#define NG_RPL_PREFIX_AUTO_ADDRESS_BIT (1 << 6)

void _ng_rpl_send(ng_pktsnip_t *pkt, ng_ipv6_addr_t *src, ng_ipv6_addr_t *dst,
Expand Down Expand Up @@ -147,12 +146,25 @@ void ng_rpl_send_DIO(ng_rpl_dodag_t *dodag, ng_ipv6_addr_t *destination)
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 = NG_RPL_DEFAULT_PREFIX_LIFETIME;
prefix_info->pref_lifetime = NG_RPL_DEFAULT_PREFIX_LIFETIME;
prefix_info->prefix_len = 64;
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));
memcpy(&prefix_info->prefix, &dodag->dodag_id, prefix_info->prefix_len/8);
prefix_info->prefix = dodag->dodag_id;
uint8_t pref_len = dodag->prefix_len;

uint8_t i = sizeof(prefix_info->prefix.u8) - 1;
while (8 < pref_len) {
prefix_info->prefix.u8[i] = 0;
pref_len -= 8;
i--;
}
if (pref_len != 0) {
prefix_info->prefix.u8[i] = (prefix_info->prefix.u8[i] & (0xFF << (8 - pref_len)));
}

pos += sizeof(*prefix_info);
}

Expand Down Expand Up @@ -254,7 +266,8 @@ bool _parse_options(ng_rpl_dodag_t *dodag, ng_rpl_opt_t *opt, uint16_t len, ng_i
case (NG_RPL_OPT_PREFIX_INFO): {
DEBUG("RPL: Prefix Information DIO option parsed\n");
ng_rpl_opt_prefix_info_t *pi = (ng_rpl_opt_prefix_info_t *) opt;
kernel_pid_t if_id = ng_ipv6_netif_find_by_prefix(NULL, &dodag->dodag_id);
ng_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, NETCONF_OPT_IPV6_IID, 0, &iid, sizeof(eui64_t)) < 0) &&
!(pi->LAR_flags & NG_RPL_PREFIX_AUTO_ADDRESS_BIT)) {
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, ng_ipv6_addr_t *dodag_id, ng_
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 f863b8f

Please sign in to comment.