Merge pull request #8010 from cgundogan/pr/rpl_nib

gnrc_rpl: port to nib
This commit is contained in:
Martine Lenders 2017-11-20 00:42:03 +01:00 committed by GitHub
commit 8a79b6739a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 127 deletions

View File

@ -105,7 +105,6 @@ ifneq (,$(filter gnrc_rpl_p2p,$(USEMODULE)))
endif endif
ifneq (,$(filter gnrc_rpl,$(USEMODULE))) ifneq (,$(filter gnrc_rpl,$(USEMODULE)))
USEMODULE += fib
USEMODULE += gnrc_ipv6_router_default USEMODULE += gnrc_ipv6_router_default
USEMODULE += trickle USEMODULE += trickle
USEMODULE += xtimer USEMODULE += xtimer

View File

@ -1216,7 +1216,7 @@ static void *_gnrc_netif_thread(void *args)
DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_SET received. opt=%s\n", DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_SET received. opt=%s\n",
netopt2str(opt->opt)); netopt2str(opt->opt));
#else #else
DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_SET received. opt=%s\n", DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_SET received. opt=%d\n",
opt->opt); opt->opt);
#endif #endif
/* set option for device driver */ /* set option for device driver */
@ -1231,7 +1231,7 @@ static void *_gnrc_netif_thread(void *args)
DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_GET received. opt=%s\n", DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_GET received. opt=%s\n",
netopt2str(opt->opt)); netopt2str(opt->opt));
#else #else
DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_GET received. opt=%s\n", DEBUG("gnrc_netif: GNRC_NETAPI_MSG_TYPE_GET received. opt=%d\n",
opt->opt); opt->opt);
#endif #endif
/* get option from device driver */ /* get option from device driver */

View File

@ -281,7 +281,7 @@ void _handle_snd_ns(_nib_onl_entry_t *nbr)
_set_nud_state(netif, nbr, _set_nud_state(netif, nbr,
GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNREACHABLE); GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNREACHABLE);
} }
/* falls through intentionally */ /* intentionally falls through */
case GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNREACHABLE: case GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNREACHABLE:
_probe_nbr(nbr, false); _probe_nbr(nbr, false);
break; break;
@ -298,7 +298,7 @@ void _handle_state_timeout(_nib_onl_entry_t *nbr)
case GNRC_IPV6_NIB_NC_INFO_NUD_STATE_REACHABLE: case GNRC_IPV6_NIB_NC_INFO_NUD_STATE_REACHABLE:
DEBUG("nib: Timeout reachability\n"); DEBUG("nib: Timeout reachability\n");
new_state = GNRC_IPV6_NIB_NC_INFO_NUD_STATE_STALE; new_state = GNRC_IPV6_NIB_NC_INFO_NUD_STATE_STALE;
/* falls through intentionally */ /* intentionally falls through */
case GNRC_IPV6_NIB_NC_INFO_NUD_STATE_DELAY: { case GNRC_IPV6_NIB_NC_INFO_NUD_STATE_DELAY: {
gnrc_netif_t *netif = gnrc_netif_get_by_pid(_nib_onl_get_if(nbr)); gnrc_netif_t *netif = gnrc_netif_get_by_pid(_nib_onl_get_if(nbr));

View File

@ -89,10 +89,12 @@ void gnrc_rpl_send(gnrc_pktsnip_t *pkt, kernel_pid_t iface, ipv6_addr_t *src, ip
netif = gnrc_netif_get_by_pid(iface); netif = gnrc_netif_get_by_pid(iface);
} }
if (src == NULL) { if (dst == NULL) {
int src_idx = gnrc_netif_ipv6_addr_match(netif, &ipv6_addr_link_local_prefix); dst = (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes;
}
src = &netif->ipv6.addrs[src_idx]; if (src == NULL) {
src = gnrc_netif_ipv6_addr_best_src(netif, dst, true);
if (src == NULL) { if (src == NULL) {
DEBUG("RPL: no suitable src address found\n"); DEBUG("RPL: no suitable src address found\n");
@ -101,10 +103,6 @@ void gnrc_rpl_send(gnrc_pktsnip_t *pkt, kernel_pid_t iface, ipv6_addr_t *src, ip
} }
} }
if (dst == NULL) {
dst = (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes;
}
hdr = gnrc_ipv6_hdr_build(pkt, src, dst); hdr = gnrc_ipv6_hdr_build(pkt, src, dst);
if (hdr == NULL) { if (hdr == NULL) {
@ -420,22 +418,13 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
first_target = target; first_target = target;
} }
uint32_t fib_dst_flags = 0; DEBUG("RPL: adding FT entry %s/%d 0x%" PRIx32 "\n",
if (target->prefix_length <= IPV6_ADDR_BIT_LEN) {
fib_dst_flags = ((uint32_t)(target->prefix_length) << FIB_FLAG_NET_PREFIX_SHIFT);
}
DEBUG("RPL: adding fib entry %s/%d 0x%" PRIx32 "\n",
ipv6_addr_to_str(addr_str, &(target->target), sizeof(addr_str)), ipv6_addr_to_str(addr_str, &(target->target), sizeof(addr_str)),
target->prefix_length, target->prefix_length);
fib_dst_flags);
fib_add_entry(&gnrc_ipv6_fib_table, dodag->iface, target->target.u8, gnrc_ipv6_nib_ft_add(&(target->target), target->prefix_length, src,
sizeof(ipv6_addr_t), fib_dst_flags, src->u8, dodag->iface,
sizeof(ipv6_addr_t), FIB_FLAG_RPL_ROUTE, dodag->default_lifetime * dodag->lifetime_unit);
(dodag->default_lifetime * dodag->lifetime_unit) *
MS_PER_SEC);
break; break;
case (GNRC_RPL_OPT_TRANSIT): case (GNRC_RPL_OPT_TRANSIT):
@ -449,18 +438,15 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
} }
do { do {
DEBUG("RPL: updating fib entry %s/%d\n", DEBUG("RPL: updating FT entry %s/%d\n",
ipv6_addr_to_str(addr_str, &(first_target->target), sizeof(addr_str)), ipv6_addr_to_str(addr_str, &(first_target->target), sizeof(addr_str)),
first_target->prefix_length); first_target->prefix_length);
fib_update_entry(&gnrc_ipv6_fib_table, gnrc_ipv6_nib_ft_add(&(first_target->target),
first_target->target.u8, first_target->prefix_length, src,
sizeof(ipv6_addr_t), src->u8, dodag->iface,
sizeof(ipv6_addr_t), transit->path_lifetime * dodag->lifetime_unit);
((transit->e_flags & GNRC_RPL_OPT_TRANSIT_E_FLAG) ?
0x0 : FIB_FLAG_RPL_ROUTE),
(transit->path_lifetime *
dodag->lifetime_unit * MS_PER_SEC));
first_target = (gnrc_rpl_opt_target_t *) (((uint8_t *) (first_target)) + first_target = (gnrc_rpl_opt_target_t *) (((uint8_t *) (first_target)) +
sizeof(gnrc_rpl_opt_t) + first_target->length); sizeof(gnrc_rpl_opt_t) + first_target->length);
} }
@ -738,76 +724,43 @@ void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *inst, ipv6_addr_t *destination, uint
destination = &(dodag->parents->addr); destination = &(dodag->parents->addr);
} }
gnrc_pktsnip_t *pkt = NULL, **ptr = NULL, *tmp = NULL, *tr_int = NULL; gnrc_pktsnip_t *pkt = NULL, *tmp = NULL;
gnrc_rpl_dao_t *dao; gnrc_rpl_dao_t *dao;
bool ext_processed = false, int_processed = false;
/* find my address */ /* find my address */
ipv6_addr_t *me = NULL; ipv6_addr_t *me = NULL;
gnrc_netif_t *netif = gnrc_netif_get_by_ipv6_addr(&dodag->dodag_id); gnrc_netif_t *netif = gnrc_netif_get_by_prefix(&dodag->dodag_id);
int idx; int idx;
if (netif == NULL) { if (netif == NULL) {
DEBUG("RPL: no address configured\n"); DEBUG("RPL: no address configured\n");
return; return;
} }
idx = gnrc_netif_ipv6_addr_idx(netif, &dodag->dodag_id); idx = gnrc_netif_ipv6_addr_match(netif, &dodag->dodag_id);
me = &netif->ipv6.addrs[idx]; me = &netif->ipv6.addrs[idx];
mutex_lock(&(gnrc_ipv6_fib_table.mtx_access)); /* add external and RPL FT entries */
/* TODO: nib: dropped support for external transit options for now */
void *ft_state = NULL;
gnrc_ipv6_nib_ft_t fte;
while(gnrc_ipv6_nib_ft_iter(NULL, dodag->iface, &ft_state, &fte)) {
DEBUG("RPL: Send DAO - building transit option\n");
/* add external and RPL FIB entries */ if ((pkt = _dao_transit_build(NULL, lifetime, false)) == NULL) {
for (size_t i = 0; i < gnrc_ipv6_fib_table.size; ++i) { DEBUG("RPL: Send DAO - no space left in packet buffer\n");
fib_entry_t *fentry = &gnrc_ipv6_fib_table.data.entries[i]; return;
if (fentry->lifetime != 0) {
if (!(fentry->next_hop_flags & FIB_FLAG_RPL_ROUTE)) {
ptr = &tmp;
if (!ext_processed) {
DEBUG("RPL: Send DAO - building external transit\n");
if ((tmp = _dao_transit_build(NULL, lifetime, true)) == NULL) {
DEBUG("RPL: Send DAO - no space left in packet buffer\n");
mutex_unlock(&(gnrc_ipv6_fib_table.mtx_access));
return;
}
ext_processed = true;
}
}
else {
ptr = &pkt;
if (!int_processed) {
DEBUG("RPL: Send DAO - building internal transit\n");
if ((tr_int = pkt = _dao_transit_build(NULL, lifetime, false)) == NULL) {
DEBUG("RPL: Send DAO - no space left in packet buffer\n");
mutex_unlock(&(gnrc_ipv6_fib_table.mtx_access));
return;
}
int_processed = true;
}
}
ipv6_addr_t *addr = (ipv6_addr_t *) fentry->global->address;
if (ipv6_addr_is_global(addr)) {
size_t prefix_length = (fentry->global_flags >> FIB_FLAG_NET_PREFIX_SHIFT);
DEBUG("RPL: Send DAO - building target %s/%d\n",
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)),
(int) prefix_length);
if ((*ptr = _dao_target_build(*ptr, addr, (uint8_t) prefix_length)) == NULL) {
DEBUG("RPL: Send DAO - no space left in packet buffer\n");
mutex_unlock(&(gnrc_ipv6_fib_table.mtx_access));
return;
}
}
} }
}
mutex_unlock(&(gnrc_ipv6_fib_table.mtx_access)); if (ipv6_addr_is_global(&fte.dst)) {
DEBUG("RPL: Send DAO - building target %s/%d\n",
ipv6_addr_to_str(addr_str, &fte.dst, sizeof(addr_str)), fte.dst_len);
if (tr_int) { if ((pkt = _dao_target_build(pkt, &fte.dst, fte.dst_len)) == NULL) {
tr_int->next = tmp; DEBUG("RPL: Send DAO - no space left in packet buffer\n");
} return;
else { }
pkt = tmp;
}
} }
/* add own address */ /* add own address */

View File

@ -216,22 +216,14 @@ bool gnrc_rpl_parent_remove(gnrc_rpl_parent_t *parent)
gnrc_rpl_dodag_t *dodag = parent->dodag; gnrc_rpl_dodag_t *dodag = parent->dodag;
if (parent == dodag->parents) { if (parent == dodag->parents) {
fib_remove_entry(&gnrc_ipv6_fib_table, gnrc_ipv6_nib_ft_del(NULL, 0);
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t));
/* set the default route to the next parent for now */ /* set the default route to the next parent for now */
if (parent->next) { if (parent->next) {
uint32_t now = xtimer_now_usec() / US_PER_SEC; uint32_t now = xtimer_now_usec() / US_PER_SEC;
fib_add_entry(&gnrc_ipv6_fib_table, gnrc_ipv6_nib_ft_add(NULL, 0,
dodag->iface, &parent->next->addr, dodag->iface,
(uint8_t *) ipv6_addr_unspecified.u8, (parent->next->lifetime - now));
sizeof(ipv6_addr_t),
0x0,
parent->next->addr.u8,
sizeof(ipv6_addr_t),
FIB_FLAG_RPL_ROUTE,
(parent->next->lifetime - now) * MS_PER_SEC);
} }
} }
LL_DELETE(dodag->parents, parent); LL_DELETE(dodag->parents, parent);
@ -247,9 +239,7 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
if (dodag->parents) { if (dodag->parents) {
gnrc_rpl_dodag_remove_all_parents(dodag); gnrc_rpl_dodag_remove_all_parents(dodag);
fib_remove_entry(&gnrc_ipv6_fib_table, gnrc_ipv6_nib_ft_del(NULL, 0);
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t));
} }
if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) { if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) {
@ -268,15 +258,8 @@ void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent)
if (dodag->instance->mop != GNRC_RPL_P2P_MOP) { if (dodag->instance->mop != GNRC_RPL_P2P_MOP) {
#endif #endif
if (parent == dodag->parents) { if (parent == dodag->parents) {
fib_add_entry(&gnrc_ipv6_fib_table, gnrc_ipv6_nib_ft_add(NULL, 0, &parent->addr, dodag->iface,
dodag->iface, dodag->default_lifetime * dodag->lifetime_unit);
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t),
0x00,
parent->addr.u8,
sizeof(ipv6_addr_t),
FIB_FLAG_RPL_ROUTE,
(dodag->default_lifetime * dodag->lifetime_unit) * MS_PER_SEC);
} }
#ifdef MODULE_GNRC_RPL_P2P #ifdef MODULE_GNRC_RPL_P2P
} }
@ -325,15 +308,8 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
#ifdef MODULE_GNRC_RPL_P2P #ifdef MODULE_GNRC_RPL_P2P
if (dodag->instance->mop != GNRC_RPL_P2P_MOP) { if (dodag->instance->mop != GNRC_RPL_P2P_MOP) {
#endif #endif
fib_add_entry(&gnrc_ipv6_fib_table, gnrc_ipv6_nib_ft_add(NULL, 0, &dodag->parents->addr, dodag->iface,
dodag->iface, dodag->default_lifetime * dodag->lifetime_unit);
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t),
0x00,
dodag->parents->addr.u8,
sizeof(ipv6_addr_t),
FIB_FLAG_RPL_ROUTE,
(dodag->default_lifetime * dodag->lifetime_unit) * MS_PER_SEC);
#ifdef MODULE_GNRC_RPL_P2P #ifdef MODULE_GNRC_RPL_P2P
} }
#endif #endif

View File

@ -346,11 +346,9 @@ void gnrc_rpl_p2p_recv_DRO(gnrc_pktsnip_t *pkt, ipv6_addr_t *src)
} }
if (gnrc_ipv6_netif_find_by_addr(&me, &addr) == dodag->iface) { if (gnrc_ipv6_netif_find_by_addr(&me, &addr) == dodag->iface) {
fib_add_entry(&gnrc_ipv6_fib_table, dodag->iface, p2p_ext->target.u8, gnrc_ipv6_nib_ft_add(&p2p_ext->target, IPV6_ADDR_BIT_LEN, src, dodag->iface,
sizeof(ipv6_addr_t), 0x0, src->u8, p2p_ext->dodag->default_lifetime *
sizeof(ipv6_addr_t), FIB_FLAG_RPL_ROUTE, p2p_ext->dodag->lifetime_unit);
p2p_ext->dodag->default_lifetime *
p2p_ext->dodag->lifetime_unit * MS_PER_SEC);
if (p2p_ext->dodag->node_status != GNRC_RPL_ROOT_NODE) { if (p2p_ext->dodag->node_status != GNRC_RPL_ROOT_NODE) {
if ((rdo_snip = gnrc_pktbuf_start_write(rdo_snip)) == NULL) { if ((rdo_snip = gnrc_pktbuf_start_write(rdo_snip)) == NULL) {