mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
rpl: replace fib with nib
This commit is contained in:
parent
21a55612b7
commit
5b5c479043
@ -105,7 +105,6 @@ ifneq (,$(filter gnrc_rpl_p2p,$(USEMODULE)))
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gnrc_rpl,$(USEMODULE)))
|
||||
USEMODULE += fib
|
||||
USEMODULE += gnrc_ipv6_router_default
|
||||
USEMODULE += trickle
|
||||
USEMODULE += xtimer
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
if (src == NULL) {
|
||||
int src_idx = gnrc_netif_ipv6_addr_match(netif, &ipv6_addr_link_local_prefix);
|
||||
if (dst == NULL) {
|
||||
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) {
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint32_t fib_dst_flags = 0;
|
||||
|
||||
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",
|
||||
DEBUG("RPL: adding FT entry %s/%d 0x%" PRIx32 "\n",
|
||||
ipv6_addr_to_str(addr_str, &(target->target), sizeof(addr_str)),
|
||||
target->prefix_length,
|
||||
fib_dst_flags);
|
||||
target->prefix_length);
|
||||
|
||||
fib_add_entry(&gnrc_ipv6_fib_table, dodag->iface, target->target.u8,
|
||||
sizeof(ipv6_addr_t), fib_dst_flags, src->u8,
|
||||
sizeof(ipv6_addr_t), FIB_FLAG_RPL_ROUTE,
|
||||
(dodag->default_lifetime * dodag->lifetime_unit) *
|
||||
MS_PER_SEC);
|
||||
gnrc_ipv6_nib_ft_add(&(target->target), target->prefix_length, src,
|
||||
dodag->iface,
|
||||
dodag->default_lifetime * dodag->lifetime_unit);
|
||||
break;
|
||||
|
||||
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 {
|
||||
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)),
|
||||
first_target->prefix_length);
|
||||
|
||||
fib_update_entry(&gnrc_ipv6_fib_table,
|
||||
first_target->target.u8,
|
||||
sizeof(ipv6_addr_t), src->u8,
|
||||
sizeof(ipv6_addr_t),
|
||||
((transit->e_flags & GNRC_RPL_OPT_TRANSIT_E_FLAG) ?
|
||||
0x0 : FIB_FLAG_RPL_ROUTE),
|
||||
(transit->path_lifetime *
|
||||
dodag->lifetime_unit * MS_PER_SEC));
|
||||
gnrc_ipv6_nib_ft_add(&(first_target->target),
|
||||
first_target->prefix_length, src,
|
||||
dodag->iface,
|
||||
transit->path_lifetime * dodag->lifetime_unit);
|
||||
|
||||
first_target = (gnrc_rpl_opt_target_t *) (((uint8_t *) (first_target)) +
|
||||
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);
|
||||
}
|
||||
|
||||
gnrc_pktsnip_t *pkt = NULL, **ptr = NULL, *tmp = NULL, *tr_int = NULL;
|
||||
gnrc_pktsnip_t *pkt = NULL, *tmp = NULL;
|
||||
gnrc_rpl_dao_t *dao;
|
||||
bool ext_processed = false, int_processed = false;
|
||||
|
||||
/* find my address */
|
||||
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;
|
||||
|
||||
if (netif == NULL) {
|
||||
DEBUG("RPL: no address configured\n");
|
||||
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];
|
||||
|
||||
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 */
|
||||
for (size_t i = 0; i < gnrc_ipv6_fib_table.size; ++i) {
|
||||
fib_entry_t *fentry = &gnrc_ipv6_fib_table.data.entries[i];
|
||||
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;
|
||||
}
|
||||
}
|
||||
if ((pkt = _dao_transit_build(NULL, lifetime, false)) == NULL) {
|
||||
DEBUG("RPL: Send DAO - no space left in packet buffer\n");
|
||||
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) {
|
||||
tr_int->next = tmp;
|
||||
}
|
||||
else {
|
||||
pkt = tmp;
|
||||
if ((pkt = _dao_target_build(pkt, &fte.dst, fte.dst_len)) == NULL) {
|
||||
DEBUG("RPL: Send DAO - no space left in packet buffer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* add own address */
|
||||
|
@ -216,22 +216,14 @@ bool gnrc_rpl_parent_remove(gnrc_rpl_parent_t *parent)
|
||||
gnrc_rpl_dodag_t *dodag = parent->dodag;
|
||||
|
||||
if (parent == dodag->parents) {
|
||||
fib_remove_entry(&gnrc_ipv6_fib_table,
|
||||
(uint8_t *) ipv6_addr_unspecified.u8,
|
||||
sizeof(ipv6_addr_t));
|
||||
gnrc_ipv6_nib_ft_del(NULL, 0);
|
||||
|
||||
/* set the default route to the next parent for now */
|
||||
if (parent->next) {
|
||||
uint32_t now = xtimer_now_usec() / US_PER_SEC;
|
||||
fib_add_entry(&gnrc_ipv6_fib_table,
|
||||
dodag->iface,
|
||||
(uint8_t *) ipv6_addr_unspecified.u8,
|
||||
sizeof(ipv6_addr_t),
|
||||
0x0,
|
||||
parent->next->addr.u8,
|
||||
sizeof(ipv6_addr_t),
|
||||
FIB_FLAG_RPL_ROUTE,
|
||||
(parent->next->lifetime - now) * MS_PER_SEC);
|
||||
gnrc_ipv6_nib_ft_add(NULL, 0,
|
||||
&parent->next->addr, dodag->iface,
|
||||
(parent->next->lifetime - now));
|
||||
}
|
||||
}
|
||||
LL_DELETE(dodag->parents, parent);
|
||||
@ -247,9 +239,7 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
|
||||
|
||||
if (dodag->parents) {
|
||||
gnrc_rpl_dodag_remove_all_parents(dodag);
|
||||
fib_remove_entry(&gnrc_ipv6_fib_table,
|
||||
(uint8_t *) ipv6_addr_unspecified.u8,
|
||||
sizeof(ipv6_addr_t));
|
||||
gnrc_ipv6_nib_ft_del(NULL, 0);
|
||||
}
|
||||
|
||||
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) {
|
||||
#endif
|
||||
if (parent == dodag->parents) {
|
||||
fib_add_entry(&gnrc_ipv6_fib_table,
|
||||
dodag->iface,
|
||||
(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);
|
||||
gnrc_ipv6_nib_ft_add(NULL, 0, &parent->addr, dodag->iface,
|
||||
dodag->default_lifetime * dodag->lifetime_unit);
|
||||
}
|
||||
#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
|
||||
if (dodag->instance->mop != GNRC_RPL_P2P_MOP) {
|
||||
#endif
|
||||
fib_add_entry(&gnrc_ipv6_fib_table,
|
||||
dodag->iface,
|
||||
(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);
|
||||
gnrc_ipv6_nib_ft_add(NULL, 0, &dodag->parents->addr, dodag->iface,
|
||||
dodag->default_lifetime * dodag->lifetime_unit);
|
||||
#ifdef MODULE_GNRC_RPL_P2P
|
||||
}
|
||||
#endif
|
||||
|
@ -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) {
|
||||
fib_add_entry(&gnrc_ipv6_fib_table, dodag->iface, p2p_ext->target.u8,
|
||||
sizeof(ipv6_addr_t), 0x0, src->u8,
|
||||
sizeof(ipv6_addr_t), FIB_FLAG_RPL_ROUTE,
|
||||
p2p_ext->dodag->default_lifetime *
|
||||
p2p_ext->dodag->lifetime_unit * MS_PER_SEC);
|
||||
gnrc_ipv6_nib_ft_add(&p2p_ext->target, IPV6_ADDR_BIT_LEN, src, dodag->iface,
|
||||
p2p_ext->dodag->default_lifetime *
|
||||
p2p_ext->dodag->lifetime_unit);
|
||||
|
||||
if (p2p_ext->dodag->node_status != GNRC_RPL_ROOT_NODE) {
|
||||
if ((rdo_snip = gnrc_pktbuf_start_write(rdo_snip)) == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user