mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #2908 from authmillenon/ipv6_nc/enh/opt
ipv6_nc: prepare for NDP
This commit is contained in:
commit
d1c2f7f72b
@ -21,13 +21,14 @@
|
||||
#ifndef NG_IPV6_NC_H_
|
||||
#define NG_IPV6_NC_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "net/ng_ipv6/addr.h"
|
||||
#include "net/ng_netif.h"
|
||||
#include "net/ng_pktqueue.h"
|
||||
#include "timex.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -123,6 +124,23 @@ typedef struct {
|
||||
uint8_t l2_addr_len; /**< Length of ng_ipv6_nc_t::l2_addr */
|
||||
uint8_t flags; /**< Flags as defined above */
|
||||
kernel_pid_t iface; /**< PID to the interface where the neighbor is */
|
||||
vtimer_t rtr_timeout; /**< timeout timer for router flag */
|
||||
|
||||
/**
|
||||
* @brief (Re)Transmission timer for neighbor solicitations of this entry and
|
||||
* timeout for states.
|
||||
*/
|
||||
vtimer_t nbr_sol_timer;
|
||||
|
||||
/**
|
||||
* @brief Delay timer for neighbor advertisements of this entry.
|
||||
*/
|
||||
vtimer_t nbr_adv_timer;
|
||||
|
||||
uint8_t unanswered_probes; /**< number of unanswered probes */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
} ng_ipv6_nc_t;
|
||||
|
||||
/**
|
||||
@ -141,16 +159,11 @@ void ng_ipv6_nc_init(void);
|
||||
* to NG_IPV6_L2_ADDR_MAX. 0 if unknown.
|
||||
* @param[in] flags Flags for the entry
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -EADDRINUSE, if @p ipv6_addr is already registered to the neighbor
|
||||
* cache.
|
||||
* @return -EFAULT, if @p ipv6_addr was NULL.
|
||||
* @return -EINVAL, if @p l2_addr_len is greater then @ref NG_IPV6_NC_L2_ADDR_MAX,
|
||||
* @p ipv6_addr is unspecified or @p iface is KERNEL_PID_UNDEF.
|
||||
* @return -ENOMEM, if no space is left to store entry.
|
||||
* @return Pointer to new neighbor cache entry on success
|
||||
* @return NULL, on failure
|
||||
*/
|
||||
int ng_ipv6_nc_add(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr,
|
||||
const void *l2_addr, size_t l2_addr_len, uint8_t flags);
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_add(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr,
|
||||
const void *l2_addr, size_t l2_addr_len, uint8_t flags);
|
||||
|
||||
/**
|
||||
* @brief Removes a neighbor from the neighbor cache
|
||||
@ -194,20 +207,49 @@ ng_ipv6_nc_t *ng_ipv6_nc_get_next(ng_ipv6_nc_t *prev);
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_get_next_router(ng_ipv6_nc_t *prev);
|
||||
|
||||
/**
|
||||
* @brief Searches for any neighbor cache entry fitting the @p ipv6_addr,
|
||||
* where you currently can send a packet to (do not confuse with
|
||||
* NG_IPV6_NC_STATE_REACHABLE).
|
||||
* @brief Returns the state of a neigbor cache entry.
|
||||
*
|
||||
* @param[in] iface PID to the interface where the neighbor is. If it
|
||||
* is KERNEL_PID_UNDEF it will be searched on all
|
||||
* interfaces.
|
||||
* @param[in] ipv6_addr An IPv6 address
|
||||
* @param[in] entry A neighbor cache entry
|
||||
*
|
||||
* @return The neighbor cache entry, if one is found.
|
||||
* @return NULL, if none is found.
|
||||
* @return The state of the neighbor cache entry as defined by its flags.
|
||||
*/
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_get_reachable(kernel_pid_t iface,
|
||||
const ng_ipv6_addr_t *ipv6_addr);
|
||||
static inline uint8_t ng_ipv6_nc_get_state(const ng_ipv6_nc_t *entry)
|
||||
{
|
||||
return (entry->flags & NG_IPV6_NC_STATE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the type of a neigbor cache entry.
|
||||
*
|
||||
* @param[in] entry A neighbor cache entry
|
||||
*
|
||||
* @return The type of the neighbor cache entry as defined by its flags.
|
||||
*/
|
||||
static inline uint8_t ng_ipv6_nc_get_type(const ng_ipv6_nc_t *entry)
|
||||
{
|
||||
return (entry->flags & NG_IPV6_NC_TYPE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if an entry is reachable (do not confuse with
|
||||
* @ref NG_IPV6_NC_STATE_REACHABLE).
|
||||
*
|
||||
* @param[in] entry A neighbor cache entry
|
||||
*
|
||||
* @return true, if you can send packets to @p entry
|
||||
* @return false, if you can't send packets to @p entry
|
||||
*/
|
||||
static inline bool ng_ipv6_nc_is_reachable(const ng_ipv6_nc_t *entry)
|
||||
{
|
||||
switch (ng_ipv6_nc_get_state(entry)) {
|
||||
case NG_IPV6_NC_STATE_UNREACHABLE:
|
||||
case NG_IPV6_NC_STATE_INCOMPLETE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Marks an entry as still reachable, if one with a fitting @p ipv6_addr
|
||||
|
@ -43,27 +43,40 @@ ng_ipv6_nc_t *_find_free_entry(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ng_ipv6_nc_add(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr,
|
||||
const void *l2_addr, size_t l2_addr_len, uint8_t flags)
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_add(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr,
|
||||
const void *l2_addr, size_t l2_addr_len, uint8_t flags)
|
||||
{
|
||||
if (ipv6_addr == NULL) {
|
||||
DEBUG("ipv6_nc: address was NULL\n");
|
||||
return -EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((l2_addr_len > NG_IPV6_NC_L2_ADDR_MAX) || (iface == KERNEL_PID_UNDEF) ||
|
||||
ng_ipv6_addr_is_unspecified(ipv6_addr)) {
|
||||
return -EINVAL;
|
||||
DEBUG("ipv6_nc: invalid parameters\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NG_IPV6_NC_SIZE; i++) {
|
||||
if (ng_ipv6_addr_equal(&(ncache[i].ipv6_addr), ipv6_addr)) {
|
||||
DEBUG("ipv6_nc: Address %s already registered\n",
|
||||
DEBUG("ipv6_nc: Address %s already registered.\n",
|
||||
ng_ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)));
|
||||
return -EADDRINUSE;
|
||||
|
||||
if ((l2_addr != NULL) && (l2_addr_len > 0)) {
|
||||
DEBUG("ipv6_nc: Update to L2 address %s",
|
||||
ng_netif_addr_to_str(addr_str, sizeof(addr_str),
|
||||
l2_addr, l2_addr_len));
|
||||
|
||||
memcpy(&(ncache[i].l2_addr), l2_addr, l2_addr_len);
|
||||
ncache[i].l2_addr_len = l2_addr_len;
|
||||
ncache[i].flags = flags;
|
||||
DEBUG(" with flags = 0x%0x\n", flags);
|
||||
|
||||
}
|
||||
return &ncache[i];
|
||||
}
|
||||
|
||||
if (ncache[i].iface == KERNEL_PID_UNDEF) {
|
||||
if (ng_ipv6_addr_is_unspecified(&(ncache[i].ipv6_addr))) {
|
||||
ncache[i].iface = iface;
|
||||
|
||||
ng_pktqueue_init(&(ncache[i].pkts));
|
||||
@ -73,30 +86,24 @@ int ng_ipv6_nc_add(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr,
|
||||
iface);
|
||||
|
||||
if ((l2_addr != NULL) && (l2_addr_len > 0)) {
|
||||
#if ENABLE_DEBUG
|
||||
DEBUG(" to L2 address ");
|
||||
|
||||
for (size_t i = 0; i < l2_addr_len; i++) {
|
||||
if (i > 0) {
|
||||
putchar(':');
|
||||
}
|
||||
|
||||
DEBUG("%02x", ((uint8_t *)l2_addr)[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
DEBUG(" to L2 address %s",
|
||||
ng_netif_addr_to_str(addr_str, sizeof(addr_str),
|
||||
l2_addr, l2_addr_len));
|
||||
memcpy(&(ncache[i].l2_addr), l2_addr, l2_addr_len);
|
||||
ncache[i].l2_addr_len = l2_addr_len;
|
||||
}
|
||||
|
||||
ncache[i].flags = flags;
|
||||
|
||||
DEBUG(" with flags = 0x%0x\n", flags);
|
||||
|
||||
return 0;
|
||||
return &ncache[i];
|
||||
}
|
||||
}
|
||||
|
||||
return -ENOMEM;
|
||||
DEBUG("ipv6_nc: neighbor cache full.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ng_ipv6_nc_remove(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr)
|
||||
@ -156,18 +163,6 @@ ng_ipv6_nc_t *ng_ipv6_nc_get_next(ng_ipv6_nc_t *prev)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline bool _is_reachable(ng_ipv6_nc_t *entry)
|
||||
{
|
||||
switch ((entry->flags & NG_IPV6_NC_STATE_MASK) >> NG_IPV6_NC_STATE_POS) {
|
||||
case NG_IPV6_NC_STATE_UNREACHABLE:
|
||||
case NG_IPV6_NC_STATE_INCOMPLETE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_get_next_router(ng_ipv6_nc_t *prev)
|
||||
{
|
||||
for (ng_ipv6_nc_t *router = ng_ipv6_nc_get_next(prev); router != NULL;
|
||||
@ -180,25 +175,6 @@ ng_ipv6_nc_t *ng_ipv6_nc_get_next_router(ng_ipv6_nc_t *prev)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_get_reachable(kernel_pid_t iface,
|
||||
const ng_ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
ng_ipv6_nc_t *entry = ng_ipv6_nc_get(iface, ipv6_addr);
|
||||
|
||||
if (entry == NULL) {
|
||||
DEBUG("ipv6_nc: No entry found for %s on interface %" PRIkernel_pid "\n",
|
||||
ng_ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)),
|
||||
iface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (_is_reachable(entry)) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ng_ipv6_nc_t *ng_ipv6_nc_still_reachable(const ng_ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
ng_ipv6_nc_t *entry = ng_ipv6_nc_get(KERNEL_PID_UNDEF, ipv6_addr);
|
||||
|
@ -144,7 +144,7 @@ static int _ipv6_nc_add(kernel_pid_t iface, char *ipv6_addr_str,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ng_ipv6_nc_add(iface, &ipv6_addr, l2_addr, l2_addr_len, 0) < 0) {
|
||||
if (ng_ipv6_nc_add(iface, &ipv6_addr, l2_addr, l2_addr_len, 0) == NULL) {
|
||||
puts("error: unable to add address to neighbor cache.");
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
APPLICATION = unittests
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_RAM := chronos msb-430 msb-430h redbee-econotag spark-core \
|
||||
stm32f0discovery telosb wsn430-v1_3b wsn430-v1_4 z1 \
|
||||
nucleo-f334
|
||||
BOARD_INSUFFICIENT_RAM := airfy-beacon chronos msb-430 msb-430h pca10000 \
|
||||
pca10005 redbee-econotag spark-core stm32f0discovery \
|
||||
telosb wsn430-v1_3b wsn430-v1_4 z1 nucleo-f334 \
|
||||
yunjia-nrf51822
|
||||
|
||||
USEMODULE += embunit
|
||||
|
||||
|
@ -52,69 +52,75 @@ static void set_up(void)
|
||||
ng_ipv6_nc_init();
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__EADDRINUSE(void)
|
||||
static void test_ipv6_nc_add__address_registered(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry1, *entry2;
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry1 = ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4),
|
||||
0)));
|
||||
TEST_ASSERT_NOT_NULL((entry2 = ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4),
|
||||
0)));
|
||||
TEST_ASSERT(entry1 == entry2);
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__address_NULL(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, NULL, TEST_STRING4,
|
||||
sizeof(TEST_STRING4), 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__iface_KERNEL_PID_UNDEF(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4),
|
||||
0));
|
||||
TEST_ASSERT_EQUAL_INT(-EADDRINUSE, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_add(KERNEL_PID_UNDEF, &addr, TEST_STRING4,
|
||||
sizeof(TEST_STRING4), 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__EFAULT(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(-EFAULT, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, NULL,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__EINVAL_KERNEL_PID_UNDEF(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-EINVAL, ng_ipv6_nc_add(KERNEL_PID_UNDEF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__EINVAL_ipv6_addr_unspecified(void)
|
||||
static void test_ipv6_nc_add__addr_unspecified(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = NG_IPV6_ADDR_UNSPECIFIED;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-EINVAL, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
|
||||
sizeof(TEST_STRING4), 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__EINVAL_l2addr_too_long(void)
|
||||
static void test_ipv6_nc_add__l2addr_too_long(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-EINVAL, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, NG_IPV6_NC_L2_ADDR_MAX + TEST_UINT8, 0));
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
|
||||
NG_IPV6_NC_L2_ADDR_MAX + TEST_UINT8, 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__ENOMEM(void)
|
||||
static void test_ipv6_nc_add__full(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
|
||||
for (int i = 0; i < NG_IPV6_NC_SIZE; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
TEST_ASSERT_NOT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
|
||||
sizeof(TEST_STRING4), 0));
|
||||
addr.u16[7].u16++;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-ENOMEM, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
|
||||
sizeof(TEST_STRING4), 0));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_add__success(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry1, *entry2;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4, sizeof(TEST_STRING4), 0));
|
||||
TEST_ASSERT_NOT_NULL((entry1 = ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING4,
|
||||
sizeof(TEST_STRING4), 0)));
|
||||
|
||||
TEST_ASSERT_NOT_NULL(ng_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
|
||||
TEST_ASSERT_NOT_NULL((entry2 = ng_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
|
||||
TEST_ASSERT(entry1 == entry2);
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_remove__no_entry_pid(void)
|
||||
@ -235,8 +241,8 @@ static void test_ipv6_nc_get_next__2_entries(void)
|
||||
ng_ipv6_nc_t *entry = NULL;
|
||||
|
||||
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
|
||||
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr,
|
||||
TEST_STRING8, sizeof(TEST_STRING8) - 1, 0));
|
||||
TEST_ASSERT_NOT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING8,
|
||||
sizeof(TEST_STRING8) - 1, 0));
|
||||
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_next(NULL)));
|
||||
@ -252,9 +258,8 @@ static void test_ipv6_nc_get_next__holey(void)
|
||||
|
||||
/* adds DEFAULT_TEST_IPV6_ADDR and OTHER_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
|
||||
test_ipv6_nc_get_next__2_entries();
|
||||
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr2,
|
||||
TEST_STRING8,
|
||||
sizeof(TEST_STRING8) - 2, 0));
|
||||
TEST_ASSERT_NOT_NULL(ng_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr2, TEST_STRING8,
|
||||
sizeof(TEST_STRING8) - 2, 0));
|
||||
TEST_ASSERT_NOT_NULL((exp_entry = ng_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr2)));
|
||||
ng_ipv6_nc_remove(DEFAULT_TEST_NETIF, &addr1);
|
||||
|
||||
@ -299,19 +304,7 @@ static void test_ipv6_nc_get_next_router__second_entry(void)
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_get_next_router(entry1));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_get_reachable__incomplete_if_local(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry = NULL;
|
||||
|
||||
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
|
||||
entry->flags = (NG_IPV6_NC_STATE_INCOMPLETE << NG_IPV6_NC_STATE_POS);
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_get_reachable(DEFAULT_TEST_NETIF, &addr));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_get_reachable__incomplete_if_global(void)
|
||||
static void test_ipv6_nc_is_reachable__incomplete(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry = NULL;
|
||||
@ -320,10 +313,10 @@ static void test_ipv6_nc_get_reachable__incomplete_if_global(void)
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
|
||||
entry->flags = (NG_IPV6_NC_STATE_INCOMPLETE << NG_IPV6_NC_STATE_POS);
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_get_reachable(KERNEL_PID_UNDEF, &addr));
|
||||
TEST_ASSERT(!ng_ipv6_nc_is_reachable(entry));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_get_reachable__reachable_if_local(void)
|
||||
static void test_ipv6_nc_is_reachable__reachable(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry = NULL;
|
||||
@ -332,44 +325,22 @@ static void test_ipv6_nc_get_reachable__reachable_if_local(void)
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
|
||||
entry->flags = (NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS);
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_reachable(DEFAULT_TEST_NETIF, &addr)));
|
||||
TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->iface);
|
||||
TEST_ASSERT(ng_ipv6_addr_equal(&(entry->ipv6_addr), &addr));
|
||||
TEST_ASSERT_EQUAL_STRING(TEST_STRING4, (char *)entry->l2_addr);
|
||||
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), entry->l2_addr_len);
|
||||
TEST_ASSERT_EQUAL_INT((NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS),
|
||||
entry->flags);
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_get_reachable__reachable_if_global(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry = NULL;
|
||||
|
||||
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
|
||||
entry->flags = (NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS);
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_reachable(KERNEL_PID_UNDEF, &addr)));
|
||||
TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->iface);
|
||||
TEST_ASSERT(ng_ipv6_addr_equal(&(entry->ipv6_addr), &addr));
|
||||
TEST_ASSERT_EQUAL_STRING(TEST_STRING4, (char *)entry->l2_addr);
|
||||
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), entry->l2_addr_len);
|
||||
TEST_ASSERT_EQUAL_INT((NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS),
|
||||
entry->flags);
|
||||
TEST_ASSERT(ng_ipv6_nc_is_reachable(entry));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_still_reachable__incomplete(void)
|
||||
{
|
||||
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
|
||||
ng_ipv6_nc_t *entry = NULL;
|
||||
|
||||
/* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF and sets flags to
|
||||
* (NG_IPV6_NC_STATE_INCOMPLETE << NG_IPV6_NC_STATE_POS) */
|
||||
test_ipv6_nc_get_reachable__incomplete_if_global();
|
||||
test_ipv6_nc_is_reachable__incomplete();
|
||||
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_get_reachable(KERNEL_PID_UNDEF, &addr));
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
|
||||
TEST_ASSERT(!ng_ipv6_nc_is_reachable(entry));
|
||||
TEST_ASSERT_NOT_NULL(ng_ipv6_nc_still_reachable(&addr));
|
||||
TEST_ASSERT_NULL(ng_ipv6_nc_get_reachable(KERNEL_PID_UNDEF, &addr));
|
||||
TEST_ASSERT(!ng_ipv6_nc_is_reachable(entry));
|
||||
}
|
||||
|
||||
static void test_ipv6_nc_still_reachable__success(void)
|
||||
@ -379,27 +350,26 @@ static void test_ipv6_nc_still_reachable__success(void)
|
||||
|
||||
/* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF and sets flags to
|
||||
* (NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS) */
|
||||
test_ipv6_nc_get_reachable__reachable_if_global();
|
||||
test_ipv6_nc_is_reachable__reachable();
|
||||
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_reachable(KERNEL_PID_UNDEF, &addr)));
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
|
||||
TEST_ASSERT(ng_ipv6_nc_is_reachable(entry));
|
||||
|
||||
entry->flags = (NG_IPV6_NC_STATE_STALE << NG_IPV6_NC_STATE_POS);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(ng_ipv6_nc_still_reachable(&addr));
|
||||
TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_reachable(KERNEL_PID_UNDEF, &addr)));
|
||||
TEST_ASSERT_EQUAL_INT((NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS),
|
||||
entry->flags);
|
||||
TEST_ASSERT(ng_ipv6_nc_is_reachable(entry));
|
||||
}
|
||||
|
||||
Test *tests_ipv6_nc_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_ipv6_nc_add__EADDRINUSE),
|
||||
new_TestFixture(test_ipv6_nc_add__EFAULT),
|
||||
new_TestFixture(test_ipv6_nc_add__EINVAL_KERNEL_PID_UNDEF),
|
||||
new_TestFixture(test_ipv6_nc_add__EINVAL_ipv6_addr_unspecified),
|
||||
new_TestFixture(test_ipv6_nc_add__EINVAL_l2addr_too_long),
|
||||
new_TestFixture(test_ipv6_nc_add__ENOMEM),
|
||||
new_TestFixture(test_ipv6_nc_add__address_registered),
|
||||
new_TestFixture(test_ipv6_nc_add__address_NULL),
|
||||
new_TestFixture(test_ipv6_nc_add__iface_KERNEL_PID_UNDEF),
|
||||
new_TestFixture(test_ipv6_nc_add__addr_unspecified),
|
||||
new_TestFixture(test_ipv6_nc_add__l2addr_too_long),
|
||||
new_TestFixture(test_ipv6_nc_add__full),
|
||||
new_TestFixture(test_ipv6_nc_add__success),
|
||||
new_TestFixture(test_ipv6_nc_remove__no_entry_pid),
|
||||
new_TestFixture(test_ipv6_nc_remove__no_entry_addr1),
|
||||
@ -417,10 +387,8 @@ Test *tests_ipv6_nc_tests(void)
|
||||
new_TestFixture(test_ipv6_nc_get_next_router__empty),
|
||||
new_TestFixture(test_ipv6_nc_get_next_router__first_entry),
|
||||
new_TestFixture(test_ipv6_nc_get_next_router__second_entry),
|
||||
new_TestFixture(test_ipv6_nc_get_reachable__incomplete_if_local),
|
||||
new_TestFixture(test_ipv6_nc_get_reachable__incomplete_if_global),
|
||||
new_TestFixture(test_ipv6_nc_get_reachable__reachable_if_local),
|
||||
new_TestFixture(test_ipv6_nc_get_reachable__reachable_if_global),
|
||||
new_TestFixture(test_ipv6_nc_is_reachable__incomplete),
|
||||
new_TestFixture(test_ipv6_nc_is_reachable__reachable),
|
||||
new_TestFixture(test_ipv6_nc_still_reachable__incomplete),
|
||||
new_TestFixture(test_ipv6_nc_still_reachable__success),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user