Skip to content

Commit

Permalink
gnrc: integrate NIB for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Aug 21, 2017
1 parent 7cd1ea0 commit 92c2d79
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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];

Expand All @@ -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 */
}
}

Expand Down
9 changes: 9 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 92c2d79

Please sign in to comment.