From 92c2d79f12842ba153dd6a4834790245cfb8088d Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 22 May 2017 15:52:11 +0200 Subject: [PATCH] gnrc: integrate NIB for testing --- sys/auto_init/auto_init.c | 9 ++++ .../gnrc/network_layer/icmpv6/gnrc_icmpv6.c | 17 +++++++ sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c | 49 +++++++++++++++++++ .../ipv6/netif/gnrc_ipv6_netif.c | 9 ++++ 4 files changed, 84 insertions(+) diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 21f392cbe7cc7..347491b22f7f9 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -88,6 +88,11 @@ #include "net/gcoap.h" #endif +#ifdef MODULE_GNRC_IPV6_NIB +#include "net/gnrc/ipv6/nib.h" +#endif + + #define ENABLE_DEBUG (0) #include "debug.h" @@ -157,6 +162,10 @@ void auto_init(void) extern void auto_init_devfs(void); auto_init_devfs(); #endif +#ifdef MODULE_GNRC_IPV6_NIB + DEBUG("Auto init gnrc_ipv6_nib module.\n"); + gnrc_ipv6_nib_init(); +#endif /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF diff --git a/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c b/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c index 539019b247928..1ce69e48ac146 100644 --- a/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c +++ b/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c @@ -23,7 +23,11 @@ #include "kernel_types.h" #include "net/ipv6/hdr.h" #include "net/gnrc.h" +#ifndef MODULE_GNRC_IPV6_NIB #include "net/gnrc/ndp.h" +#else +#include "net/gnrc/ipv6/nib.h" +#endif #include "net/protnum.h" #include "od.h" #include "utlist.h" @@ -94,6 +98,7 @@ void gnrc_icmpv6_demux(kernel_pid_t iface, gnrc_pktsnip_t *pkt) break; #endif +#ifndef MODULE_GNRC_IPV6_NIB #if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) case ICMPV6_RTR_SOL: DEBUG("icmpv6: router solicitation received\n"); @@ -126,6 +131,18 @@ void gnrc_icmpv6_demux(kernel_pid_t iface, gnrc_pktsnip_t *pkt) DEBUG("icmpv6: redirect message received\n"); /* TODO */ break; +#else /* MODULE_GNRC_IPV6_NIB */ + case ICMPV6_RTR_SOL: + case ICMPV6_RTR_ADV: + case ICMPV6_NBR_SOL: + case ICMPV6_NBR_ADV: + case ICMPV6_REDIRECT: + case ICMPV6_DAR: + case ICMPV6_DAC: + DEBUG("icmpv6: NDP message received. Handle with gnrc_ipv6_nib\n"); + gnrc_ipv6_nib_handle_pkt(iface, ipv6->data, hdr, icmpv6->size); + break; +#endif /* MODULE_GNRC_IPV6_NIB */ default: DEBUG("icmpv6: unknown type field %u\n", hdr->type); diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index 68c1b12126b6e..9dce3c988db6f 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -29,7 +29,11 @@ #include "thread.h" #include "utlist.h" +#ifndef MODULE_GNRC_IPV6_NIB #include "net/gnrc/ipv6/nc.h" +#else +#include "net/gnrc/ipv6/nib.h" +#endif #include "net/gnrc/ipv6/netif.h" #include "net/gnrc/ipv6/whitelist.h" #include "net/gnrc/ipv6/blacklist.h" @@ -286,6 +290,7 @@ static void *_event_loop(void *args) msg_reply(&msg, &reply); break; +#ifndef MODULE_GNRC_IPV6_NIB #ifdef MODULE_GNRC_NDP case GNRC_NDP_MSG_RTR_TIMEOUT: DEBUG("ipv6: Router timeout received\n"); @@ -361,6 +366,26 @@ static void *_event_loop(void *args) &(nc_entry->ipv6_addr), false); break; #endif +#else /* MODULE_GNRC_IPV6_NIB */ + case GNRC_IPV6_NIB_SND_UC_NS: + case GNRC_IPV6_NIB_SND_MC_NS: + case GNRC_IPV6_NIB_SND_NA: + case GNRC_IPV6_NIB_SEARCH_RTR: + case GNRC_IPV6_NIB_RECONFIRM_RTR: + case GNRC_IPV6_NIB_REPLY_RS: + case GNRC_IPV6_NIB_SND_MC_RA: + case GNRC_IPV6_NIB_REACH_TIMEOUT: + case GNRC_IPV6_NIB_DELAY_TIMEOUT: + case GNRC_IPV6_NIB_ADDR_REG_TIMEOUT: + case GNRC_IPV6_NIB_6LO_CTX_TIMEOUT: + case GNRC_IPV6_NIB_ABR_TIMEOUT: + case GNRC_IPV6_NIB_PFX_TIMEOUT: + case GNRC_IPV6_NIB_RTR_TIMEOUT: + case GNRC_IPV6_NIB_RECALC_REACH_TIME: + DEBUG("ipv6: NIB timer event received\n"); + gnrc_ipv6_nib_handle_timer_event(msg.content.ptr, msg.type); + break; +#endif /* MODULE_GNRC_IPV6_NIB */ default: break; } @@ -624,6 +649,7 @@ static void _send_multicast(kernel_pid_t iface, gnrc_pktsnip_t *pkt, #endif /* GNRC_NETIF_NUMOF */ } +#ifndef MODULE_GNRC_IPV6_NIB static inline kernel_pid_t _next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, kernel_pid_t iface, ipv6_addr_t *dst, gnrc_pktsnip_t *pkt) @@ -653,6 +679,7 @@ static inline kernel_pid_t _next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len #endif return found_iface; } +#endif /* MODULE_GNRC_IPV6_NIB */ static void _send(gnrc_pktsnip_t *pkt, bool prep_hdr) { @@ -744,6 +771,7 @@ static void _send(gnrc_pktsnip_t *pkt, bool prep_hdr) } } else { +#ifndef MODULE_GNRC_IPV6_NIB uint8_t l2addr_len = GNRC_IPV6_NC_L2_ADDR_MAX; uint8_t l2addr[l2addr_len]; @@ -764,6 +792,27 @@ static void _send(gnrc_pktsnip_t *pkt, bool prep_hdr) } _send_unicast(iface, l2addr, l2addr_len, pkt); +#else /* MODULE_GNRC_IPV6_NIB */ + gnrc_ipv6_nib_nc_t nce; + int res; + + if ((res = gnrc_ipv6_nib_get_next_hop_l2addr(&hdr->dst, iface, pkt, + &nce)) < 0) { + /* packet is released by NIB */ + return; + } + + if (prep_hdr) { + if (_fill_ipv6_hdr(iface, ipv6, payload) < 0) { + /* error on filling up header */ + gnrc_pktbuf_release(pkt); + return; + } + } + + _send_unicast(gnrc_ipv6_nib_nc_get_iface(&nce), nce.l2addr, + nce.l2addr_len, pkt); +#endif /* MODULE_GNRC_IPV6_NIB */ } } diff --git a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c index b9bf3934d451b..8d71d9092e028 100644 --- a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c +++ b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c @@ -25,6 +25,9 @@ #include "net/eui64.h" #include "net/ipv6/addr.h" +#ifdef MODULE_GNRC_IPV6_NIB +#include "net/gnrc/ipv6/nib.h" +#endif #include "net/gnrc/ndp.h" #include "net/gnrc/netapi.h" #include "net/gnrc/netif.h" @@ -173,9 +176,11 @@ static void _ipv6_netif_remove(gnrc_ipv6_netif_t *entry) return; } +#ifndef MODULE_GNRC_IPV6_NIB #ifdef MODULE_GNRC_NDP gnrc_ndp_netif_remove(entry); #endif +#endif /* MODULE_GNRC_IPV6_NIB */ mutex_lock(&entry->mutex); xtimer_remove(&entry->rtr_sol_timer); @@ -235,9 +240,13 @@ void gnrc_ipv6_netif_add(kernel_pid_t pid) mutex_unlock(&free_entry->mutex); +#ifndef MODULE_GNRC_IPV6_NIB #ifdef MODULE_GNRC_NDP gnrc_ndp_netif_add(free_entry); #endif +#else /* MODULE_GNRC_IPV6_NIB */ + gnrc_ipv6_nib_init_iface(pid); +#endif /* MODULE_GNRC_IPV6_NIB */ DEBUG(" * pid = %" PRIkernel_pid " ", free_entry->pid); DEBUG("cur_hl = %d ", free_entry->cur_hl);