Skip to content
Snippets Groups Projects
Commit 9a60fb30 authored by Martine Lenders's avatar Martine Lenders
Browse files

Merge pull request #5136 from cgundogan/pr/gnrc_rpl/netif_addr

gnrc_rpl: add netif_addr to DODAG
parents f4cad457 b2809848
No related branches found
No related tags found
No related merge requests found
...@@ -103,11 +103,13 @@ gnrc_rpl_instance_t *gnrc_rpl_instance_get(uint8_t instance_id); ...@@ -103,11 +103,13 @@ gnrc_rpl_instance_t *gnrc_rpl_instance_get(uint8_t instance_id);
* @param[in] instance Pointer to the instance to add the DODAG to * @param[in] instance Pointer to the instance to add the DODAG to
* @param[in] dodag_id The DODAG-ID of the new DODAG * @param[in] dodag_id The DODAG-ID of the new DODAG
* @param[in] iface Interface PID where the DODAG operates * @param[in] iface Interface PID where the DODAG operates
* @param[in] netif_addr netif address for this DODAG
* *
* @return true, if DODAG could be created. * @return true, if DODAG could be created.
* @return false, if DODAG could not be created or exists already. * @return false, if DODAG could not be created or exists already.
*/ */
bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, kernel_pid_t iface); bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, kernel_pid_t iface,
gnrc_ipv6_netif_addr_t *netif_addr);
/** /**
* @brief Remove all parents from the @p dodag. * @brief Remove all parents from the @p dodag.
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
extern "C" { extern "C" {
#endif #endif
#include "net/gnrc/ipv6/netif.h"
#include "net/ipv6/addr.h" #include "net/ipv6/addr.h"
#include "xtimer.h" #include "xtimer.h"
#include "trickle.h" #include "trickle.h"
...@@ -212,11 +213,9 @@ typedef struct { ...@@ -212,11 +213,9 @@ typedef struct {
*/ */
struct gnrc_rpl_dodag { struct gnrc_rpl_dodag {
ipv6_addr_t dodag_id; /**< id of the DODAG */ ipv6_addr_t dodag_id; /**< id of the DODAG */
gnrc_ipv6_netif_addr_t *netif_addr; /**< netif address for this DODAG */
gnrc_rpl_parent_t *parents; /**< pointer to the parents list of this DODAG */ gnrc_rpl_parent_t *parents; /**< pointer to the parents list of this DODAG */
gnrc_rpl_instance_t *instance; /**< pointer to the instance that this dodag is part of */ gnrc_rpl_instance_t *instance; /**< pointer to the instance that this dodag is part of */
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 dtsn; /**< DAO Trigger Sequence Number */ uint8_t dtsn; /**< DAO Trigger Sequence Number */
uint8_t prf; /**< preferred flag */ uint8_t prf; /**< preferred flag */
uint8_t dio_interval_doubl; /**< trickle Imax parameter */ uint8_t dio_interval_doubl; /**< trickle Imax parameter */
......
...@@ -84,7 +84,7 @@ gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_ ...@@ -84,7 +84,7 @@ gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_
gnrc_rpl_dodag_t *dodag = NULL; gnrc_rpl_dodag_t *dodag = NULL;
gnrc_rpl_instance_t *inst = gnrc_rpl_root_instance_init(instance_id, dodag_id, gnrc_rpl_instance_t *inst = gnrc_rpl_root_instance_init(instance_id, dodag_id,
GNRC_RPL_DEFAULT_MOP); GNRC_RPL_DEFAULT_MOP);
if (!inst) { if (!inst) {
return NULL; return NULL;
......
...@@ -140,13 +140,13 @@ gnrc_pktsnip_t *_dio_prefix_info_build(gnrc_pktsnip_t *pkt, gnrc_rpl_dodag_t *do ...@@ -140,13 +140,13 @@ gnrc_pktsnip_t *_dio_prefix_info_build(gnrc_pktsnip_t *pkt, gnrc_rpl_dodag_t *do
prefix_info->length = GNRC_RPL_OPT_PREFIX_INFO_LEN; prefix_info->length = GNRC_RPL_OPT_PREFIX_INFO_LEN;
/* auto-address configuration */ /* auto-address configuration */
prefix_info->LAR_flags = GNRC_RPL_PREFIX_AUTO_ADDRESS_BIT; prefix_info->LAR_flags = GNRC_RPL_PREFIX_AUTO_ADDRESS_BIT;
prefix_info->valid_lifetime = dodag->addr_valid; prefix_info->valid_lifetime = dodag->netif_addr->valid;
prefix_info->pref_lifetime = dodag->addr_preferred; prefix_info->pref_lifetime = dodag->netif_addr->preferred;
prefix_info->prefix_len = dodag->prefix_len; prefix_info->prefix_len = dodag->netif_addr->prefix_len;
prefix_info->reserved = 0; prefix_info->reserved = 0;
memset(&prefix_info->prefix, 0, sizeof(prefix_info->prefix)); memset(&prefix_info->prefix, 0, sizeof(prefix_info->prefix));
ipv6_addr_init_prefix(&prefix_info->prefix, &dodag->dodag_id, dodag->prefix_len); ipv6_addr_init_prefix(&prefix_info->prefix, &dodag->dodag_id, dodag->netif_addr->prefix_len);
return opt_snip; return opt_snip;
} }
#endif #endif
...@@ -375,6 +375,7 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt ...@@ -375,6 +375,7 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
gnrc_rpl_dodag_t *dodag = &inst->dodag; gnrc_rpl_dodag_t *dodag = &inst->dodag;
eui64_t iid; eui64_t iid;
*included_opts = 0; *included_opts = 0;
ipv6_addr_t *me;
if (!_gnrc_rpl_check_options_validity(msg_type, inst, opt, len)) { if (!_gnrc_rpl_check_options_validity(msg_type, inst, opt, len)) {
return false; return false;
...@@ -432,7 +433,10 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt ...@@ -432,7 +433,10 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
break; break;
} }
ipv6_addr_set_aiid(&pi->prefix, iid.uint8); ipv6_addr_set_aiid(&pi->prefix, iid.uint8);
gnrc_ipv6_netif_add_addr(dodag->iface, &pi->prefix, pi->prefix_len, 0); me = gnrc_ipv6_netif_add_addr(dodag->iface, &pi->prefix, pi->prefix_len, 0);
if (me) {
dodag->netif_addr = gnrc_ipv6_netif_addr_get(me);
}
break; break;
...@@ -542,12 +546,12 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src ...@@ -542,12 +546,12 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src
assert(iface != KERNEL_PID_UNDEF); assert(iface != KERNEL_PID_UNDEF);
} }
gnrc_rpl_dodag_init(inst, &dio->dodag_id, iface); gnrc_rpl_dodag_init(inst, &dio->dodag_id, iface, NULL);
dodag = &inst->dodag; dodag = &inst->dodag;
DEBUG("RPL: Joined DODAG (%s).\n", DEBUG("RPL: Joined DODAG (%s).\n",
ipv6_addr_to_str(addr_str, &dio->dodag_id, sizeof(addr_str))); ipv6_addr_to_str(addr_str, &dio->dodag_id, sizeof(addr_str)));
gnrc_rpl_parent_t *parent = NULL; gnrc_rpl_parent_t *parent = NULL;
...@@ -583,6 +587,25 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src ...@@ -583,6 +587,25 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src
#endif #endif
} }
/* if there was no netif_addr created manually or by a PIO, then leave this DODAG */
if (!dodag->netif_addr) {
ipv6_addr_t *configured_addr;
if (!(configured_addr = gnrc_ipv6_netif_match_prefix(dodag->iface, &dodag->dodag_id))) {
DEBUG("RPL: no IPv6 address configured to match the given dodag id: %s\n",
ipv6_addr_to_str(addr_str, dodag_id, sizeof(addr_str)));
gnrc_rpl_instance_remove(inst);
return;
}
if (!(dodag->netif_addr = gnrc_ipv6_netif_addr_get(configured_addr))) {
DEBUG("RPL: no netif address found for %s\n",
ipv6_addr_to_str(addr_str, configured_addr, sizeof(addr_str)));
gnrc_rpl_instance_remove(inst);
return;
}
}
gnrc_rpl_delay_dao(dodag); gnrc_rpl_delay_dao(dodag);
trickle_start(gnrc_rpl_pid, &dodag->trickle, GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL, trickle_start(gnrc_rpl_pid, &dodag->trickle, GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL,
GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min),
......
...@@ -113,21 +113,16 @@ gnrc_rpl_instance_t *gnrc_rpl_instance_get(uint8_t instance_id) ...@@ -113,21 +113,16 @@ gnrc_rpl_instance_t *gnrc_rpl_instance_get(uint8_t instance_id)
return NULL; return NULL;
} }
bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, kernel_pid_t iface) bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, kernel_pid_t iface,
gnrc_ipv6_netif_addr_t *netif_addr)
{ {
gnrc_rpl_dodag_t *dodag = NULL; /* TODO: check if netif_addr belongs to iface */
if ((instance == NULL) || instance->state == 0) { assert(instance && (instance->state > 0));
DEBUG("Instance is NULL or unused\n");
return false;
}
dodag = &instance->dodag; gnrc_rpl_dodag_t *dodag = &instance->dodag;
dodag->dodag_id = *dodag_id; dodag->dodag_id = *dodag_id;
dodag->prefix_len = GNRC_RPL_DEFAULT_PREFIX_LEN;
dodag->addr_preferred = GNRC_RPL_DEFAULT_PREFIX_LIFETIME;
dodag->addr_valid = GNRC_RPL_DEFAULT_PREFIX_LIFETIME;
dodag->my_rank = GNRC_RPL_INFINITE_RANK; dodag->my_rank = GNRC_RPL_INFINITE_RANK;
dodag->trickle.callback.func = &_rpl_trickle_send_dio; dodag->trickle.callback.func = &_rpl_trickle_send_dio;
dodag->trickle.callback.args = instance; dodag->trickle.callback.args = instance;
...@@ -143,6 +138,7 @@ bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, k ...@@ -143,6 +138,7 @@ bool gnrc_rpl_dodag_init(gnrc_rpl_instance_t *instance, ipv6_addr_t *dodag_id, k
dodag->dao_counter = 0; dodag->dao_counter = 0;
dodag->instance = instance; dodag->instance = instance;
dodag->iface = iface; dodag->iface = iface;
dodag->netif_addr = netif_addr;
return true; return true;
} }
...@@ -373,15 +369,13 @@ gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_ ...@@ -373,15 +369,13 @@ gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_
return NULL; return NULL;
} }
if (!gnrc_rpl_dodag_init(inst, dodag_id, iface)) { if (!gnrc_rpl_dodag_init(inst, dodag_id, iface, netif_addr)) {
DEBUG("RPL: could not initialize DODAG"); DEBUG("RPL: could not initialize DODAG");
gnrc_rpl_instance_remove(inst);
return NULL; return NULL;
} }
dodag = &inst->dodag; dodag = &inst->dodag;
dodag->prefix_len = netif_addr->prefix_len;
dodag->addr_preferred = netif_addr->preferred;
dodag->addr_valid = netif_addr->valid;
dodag->instance = inst; dodag->instance = inst;
return inst; return inst;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment