mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests: port gnrc_ipv6_nib tests for gnrc_netif2
This commit is contained in:
parent
a7d2c65b36
commit
801148eb6d
@ -6,7 +6,10 @@ BOARD_INSUFFICIENT_MEMORY := chronos nucleo32-f031 nucleo32-f042
|
||||
|
||||
USEMODULE += gnrc_ipv6
|
||||
USEMODULE += gnrc_ipv6_nib
|
||||
USEMODULE += gnrc_netif2
|
||||
USEMODULE += embunit
|
||||
USEMODULE += netdev_eth
|
||||
USEMODULE += netdev_test
|
||||
|
||||
CFLAGS += -DDEVELHELP
|
||||
CFLAGS += -DGNRC_NETTYPE_NDP2=GNRC_NETTYPE_TEST
|
||||
|
@ -22,14 +22,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "net/gnrc.h"
|
||||
#include "net/gnrc/netif2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _CALL(fn) _common_set_up(); _set_up(); puts("Calling " # fn); fn()
|
||||
#define _LL0 (0xce)
|
||||
#define _LL1 (0xab)
|
||||
#define _LL2 (0xfe)
|
||||
#define _LL3 (0xad)
|
||||
#define _LL4 (0xf7)
|
||||
#define _LL5 (0x26)
|
||||
|
||||
extern kernel_pid_t _mock_netif_pid;
|
||||
extern gnrc_netif2_t *_mock_netif;
|
||||
|
||||
void _tests_init(void);
|
||||
int _mock_netif_get(gnrc_netapi_opt_t *opt);
|
||||
|
@ -33,12 +33,6 @@
|
||||
#include "sched.h"
|
||||
|
||||
#define _BUFFER_SIZE (128)
|
||||
#define _LL0 (0xce)
|
||||
#define _LL1 (0xab)
|
||||
#define _LL2 (0xfe)
|
||||
#define _LL3 (0xad)
|
||||
#define _LL4 (0xf7)
|
||||
#define _LL5 (0x26)
|
||||
|
||||
static const uint8_t _loc_l2[] = { _LL0, _LL1, _LL2, _LL3, _LL4, _LL5 };
|
||||
static const ipv6_addr_t _loc_ll = { {
|
||||
@ -74,7 +68,7 @@ static void _set_up(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH(kernel_pid_t iface)
|
||||
static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH(gnrc_netif2_t *netif)
|
||||
{
|
||||
msg_t msg;
|
||||
gnrc_ipv6_nib_nc_t nce;
|
||||
@ -82,9 +76,9 @@ static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH(kernel_pid_t iface
|
||||
gnrc_pktsnip_t *pkt;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH,
|
||||
gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll, iface,
|
||||
gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll, netif,
|
||||
NULL, &nce));
|
||||
if (iface != KERNEL_PID_UNDEF) {
|
||||
if (netif != NULL) {
|
||||
ndp_nbr_sol_t *nbr_sol;
|
||||
bool contains_sl2ao = false;
|
||||
|
||||
@ -96,7 +90,7 @@ static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH(kernel_pid_t iface
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_NUD_STATE_INCOMPLETE,
|
||||
gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(iface, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_AR_STATE_GC,
|
||||
gnrc_ipv6_nib_nc_get_ar_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(1, msg_avail());
|
||||
@ -128,22 +122,22 @@ static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH(kernel_pid_t iface
|
||||
|
||||
static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH_no_iface(void)
|
||||
{
|
||||
test_get_next_hop_l2addr__link_local_EHOSTUNREACH(KERNEL_PID_UNDEF);
|
||||
test_get_next_hop_l2addr__link_local_EHOSTUNREACH(NULL);
|
||||
}
|
||||
|
||||
static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH_iface(void)
|
||||
{
|
||||
test_get_next_hop_l2addr__link_local_EHOSTUNREACH(_mock_netif_pid);
|
||||
test_get_next_hop_l2addr__link_local_EHOSTUNREACH(_mock_netif);
|
||||
}
|
||||
|
||||
static void test_get_next_hop_l2addr__link_local_static_conf(void)
|
||||
{
|
||||
gnrc_ipv6_nib_nc_t nce;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_nc_set(&_rem_ll, _mock_netif_pid,
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_nc_set(&_rem_ll, _mock_netif->pid,
|
||||
_rem_l2, sizeof(_rem_l2)));
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll,
|
||||
_mock_netif_pid,
|
||||
_mock_netif,
|
||||
NULL, &nce));
|
||||
TEST_ASSERT_MESSAGE((memcmp(&_rem_ll, &nce.ipv6, sizeof(_rem_ll)) == 0),
|
||||
"_rem_ll != nce.ipv6");
|
||||
@ -152,7 +146,7 @@ static void test_get_next_hop_l2addr__link_local_static_conf(void)
|
||||
"_rem_l2 != nce.l2addr");
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNMANAGED,
|
||||
gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_AR_STATE_MANUAL,
|
||||
gnrc_ipv6_nib_nc_get_ar_state(&nce));
|
||||
@ -172,7 +166,7 @@ void _simulate_ndp_handshake(const ipv6_addr_t *src, const ipv6_addr_t *dst,
|
||||
/* trigger sending of neighbor discovery */
|
||||
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH,
|
||||
gnrc_ipv6_nib_get_next_hop_l2addr(dst,
|
||||
_mock_netif_pid,
|
||||
_mock_netif,
|
||||
NULL, &nce));
|
||||
TEST_ASSERT_EQUAL_INT(1, msg_avail());
|
||||
/* clear message queue */
|
||||
@ -192,7 +186,7 @@ void _simulate_ndp_handshake(const ipv6_addr_t *src, const ipv6_addr_t *dst,
|
||||
tl2ao->type = NDP_OPT_TL2A;
|
||||
tl2ao->len = 1;
|
||||
memcpy(tl2ao + 1, _rem_l2, sizeof(_rem_l2));
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, (icmpv6_hdr_t *)nbr_adv,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, (icmpv6_hdr_t *)nbr_adv,
|
||||
sizeof(ndp_nbr_adv_t) + 8U);
|
||||
}
|
||||
|
||||
@ -202,7 +196,7 @@ static void test_get_next_hop_l2addr__link_local_after_handshake(uint8_t adv_fla
|
||||
|
||||
_simulate_ndp_handshake(&_loc_ll, &_rem_ll, adv_flags);
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll,
|
||||
_mock_netif_pid,
|
||||
_mock_netif,
|
||||
NULL, &nce));
|
||||
TEST_ASSERT_MESSAGE((memcmp(&_rem_ll, &nce.ipv6, sizeof(_rem_ll)) == 0),
|
||||
"_rem_ll != nce.ipv6");
|
||||
@ -211,7 +205,7 @@ static void test_get_next_hop_l2addr__link_local_after_handshake(uint8_t adv_fla
|
||||
"_rem_l2 != nce.l2addr");
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_NUD_STATE_REACHABLE,
|
||||
gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
if (adv_flags & NDP_NBR_ADV_FLAGS_R) {
|
||||
TEST_ASSERT(gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
}
|
||||
@ -242,7 +236,7 @@ static void test_get_next_hop_l2addr__link_local_after_handshake_no_iface(void)
|
||||
_simulate_ndp_handshake(&_loc_ll, &_rem_ll, NDP_NBR_ADV_FLAGS_S);
|
||||
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH,
|
||||
gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll,
|
||||
KERNEL_PID_UNDEF,
|
||||
NULL,
|
||||
NULL, &nce));
|
||||
}
|
||||
|
||||
@ -257,7 +251,7 @@ static void test_handle_pkt__unknown_type(void)
|
||||
memcpy(&ipv6->dst, &_rem_ll, sizeof(ipv6->dst));
|
||||
icmpv6->type = ICMPV6_ECHO_REQ;
|
||||
icmpv6->code = 0;
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6,
|
||||
sizeof(icmpv6_hdr_t));
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
@ -301,7 +295,7 @@ static void test_handle_pkt__nbr_sol__invalid_hl(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&_rem_ll, &_loc_sol_nodes, 194U, 0U,
|
||||
&_loc_ll, _rem_l2, sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -315,7 +309,7 @@ static void test_handle_pkt__nbr_sol__invalid_code(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&_rem_ll, &_loc_sol_nodes, 255U, 201U,
|
||||
&_loc_ll, _rem_l2, sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -330,7 +324,7 @@ static void test_handle_pkt__nbr_sol__invalid_icmpv6_len(void)
|
||||
_set_nbr_sol(&_rem_ll, &_loc_sol_nodes, 255U, 0U, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6,
|
||||
sizeof(ndp_nbr_sol_t) - 1);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
@ -346,7 +340,7 @@ static void test_handle_pkt__nbr_sol__invalid_tgt(void)
|
||||
&ipv6_addr_all_routers_site_local, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -364,7 +358,7 @@ static void test_handle_pkt__nbr_sol__invalid_opt_len(void)
|
||||
opt->type = NDP_OPT_SL2A;
|
||||
opt->len = 0U;
|
||||
icmpv6_len += sizeof(ndp_opt_t);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -378,7 +372,7 @@ static void test_handle_pkt__nbr_sol__invalid_dst(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&ipv6_addr_unspecified, &_loc_ll, 255U, 0U,
|
||||
&_loc_ll, NULL, 0);
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -393,7 +387,7 @@ static void test_handle_pkt__nbr_sol__invalid_sl2ao(void)
|
||||
255U, 0U, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -408,7 +402,7 @@ static void test_handle_pkt__nbr_sol__tgt_not_assigned(void)
|
||||
255U, 0U, &_rem_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -425,12 +419,12 @@ static void test_pkt_is_nbr_adv(gnrc_pktsnip_t *pkt, const ipv6_addr_t *dst,
|
||||
ndp_nbr_adv_t *nbr_adv;
|
||||
ndp_opt_t *tl2ao;
|
||||
|
||||
/* first snip is a netif header to _mock_netif_pid */
|
||||
/* first snip is a netif header to _mock_netif */
|
||||
TEST_ASSERT_NOT_NULL(pkt);
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_NETIF, pkt->type);
|
||||
TEST_ASSERT(sizeof(gnrc_netif_hdr_t) <= pkt->size);
|
||||
netif_hdr = pkt->data;
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, netif_hdr->if_pid);
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, netif_hdr->if_pid);
|
||||
/* second snip is an IPv6 header to dst */
|
||||
TEST_ASSERT_NOT_NULL(pkt->next);
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_IPV6, pkt->next->type);
|
||||
@ -475,7 +469,7 @@ static void test_handle_pkt__nbr_sol__ll_src(unsigned exp_nud_state,
|
||||
255U, 0U, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"Expected neighbor cache entry");
|
||||
TEST_ASSERT_MESSAGE(ipv6_addr_equal(&_rem_ll, &nce.ipv6),
|
||||
@ -485,7 +479,7 @@ static void test_handle_pkt__nbr_sol__ll_src(unsigned exp_nud_state,
|
||||
"_rem_l2 != nce.l2addr");
|
||||
TEST_ASSERT_EQUAL_INT(exp_nud_state, gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(exp_ar_state, gnrc_ipv6_nib_nc_get_ar_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(1, msg_avail());
|
||||
msg_receive(&msg);
|
||||
@ -518,7 +512,7 @@ static void test_handle_pkt__nbr_sol__ll_src_no_sl2ao(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&_rem_ll, &_loc_sol_nodes,
|
||||
255U, 0U, &_loc_ll, NULL, 0);
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
TEST_ASSERT_EQUAL_INT(1, msg_avail());
|
||||
@ -570,7 +564,7 @@ static void test_handle_pkt__nbr_adv__invalid_hl(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -585,7 +579,7 @@ static void test_handle_pkt__nbr_adv__invalid_code(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -601,7 +595,7 @@ static void test_handle_pkt__nbr_adv__invalid_icmpv6_len(void)
|
||||
&_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6,
|
||||
sizeof(ndp_nbr_adv_t) - 1);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
@ -618,7 +612,7 @@ static void test_handle_pkt__nbr_adv__invalid_tgt(void)
|
||||
&ipv6_addr_all_routers_site_local, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -633,7 +627,7 @@ static void test_handle_pkt__nbr_adv__invalid_flags(void)
|
||||
255U, 0U, NDP_NBR_ADV_FLAGS_S, &_loc_ll,
|
||||
NULL, 0);
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -652,7 +646,7 @@ static void test_handle_pkt__nbr_adv__invalid_opt_len(void)
|
||||
opt->type = NDP_OPT_SL2A;
|
||||
opt->len = 0U;
|
||||
icmpv6_len += sizeof(ndp_opt_t);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -667,7 +661,7 @@ static void test_handle_pkt__nbr_adv__unspecified_src(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -682,7 +676,7 @@ static void test_handle_pkt__nbr_adv__unsolicited(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll,
|
||||
_rem_l2, sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
TEST_ASSERT_EQUAL_INT(0, msg_avail());
|
||||
@ -752,20 +746,6 @@ int _mock_netif_get(gnrc_netapi_opt_t *opt)
|
||||
}
|
||||
memcpy(opt->data, _loc_l2, sizeof(_loc_l2));
|
||||
return sizeof(_loc_l2);
|
||||
case NETOPT_SRC_LEN: {
|
||||
uint16_t *val = opt->data;
|
||||
if (opt->data_len != sizeof(uint16_t)) {
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
*val = sizeof(_loc_l2);
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
case NETOPT_IPV6_IID:
|
||||
if (opt->data_len < sizeof(_loc_iid)) {
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
memcpy(opt->data, _loc_iid, sizeof(_loc_iid));
|
||||
return sizeof(_loc_iid);
|
||||
case NETOPT_IS_WIRED:
|
||||
return 1;
|
||||
case NETOPT_MAX_PACKET_SIZE: {
|
||||
|
@ -16,63 +16,73 @@
|
||||
#include "common.h"
|
||||
#include "msg.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "net/ethernet.h"
|
||||
#include "net/gnrc/ipv6/nib.h"
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
#include "net/gnrc/netdev.h"
|
||||
#include "net/gnrc/netif2/ethernet.h"
|
||||
#include "net/gnrc/netif2/internal.h"
|
||||
#include "net/netdev_test.h"
|
||||
#include "sched.h"
|
||||
#include "thread.h"
|
||||
|
||||
#define _MSG_QUEUE_SIZE (2)
|
||||
|
||||
kernel_pid_t _mock_netif_pid = KERNEL_PID_UNDEF;
|
||||
gnrc_netif2_t *_mock_netif = NULL;
|
||||
|
||||
static netdev_test_t _mock_netdev;
|
||||
static char _mock_netif_stack[THREAD_STACKSIZE_DEFAULT];
|
||||
static gnrc_netreg_entry_t dumper;
|
||||
static msg_t _main_msg_queue[_MSG_QUEUE_SIZE];
|
||||
static msg_t _mock_netif_msg_queue[_MSG_QUEUE_SIZE];
|
||||
|
||||
static void *_mock_netif_thread(void *args)
|
||||
{
|
||||
msg_t msg, reply = { .type = GNRC_NETAPI_MSG_TYPE_ACK };
|
||||
|
||||
(void)args;
|
||||
msg_init_queue(_mock_netif_msg_queue, _MSG_QUEUE_SIZE);
|
||||
while (1) {
|
||||
msg_receive(&msg);
|
||||
switch (msg.type) {
|
||||
case GNRC_NETAPI_MSG_TYPE_GET:
|
||||
reply.content.value = (uint32_t)_mock_netif_get(msg.content.ptr);
|
||||
break;
|
||||
case GNRC_NETAPI_MSG_TYPE_SET:
|
||||
reply.content.value = (uint32_t)(-ENOTSUP);
|
||||
break;
|
||||
case GNRC_NETAPI_MSG_TYPE_SND:
|
||||
case GNRC_NETAPI_MSG_TYPE_RCV:
|
||||
gnrc_pktbuf_release(msg.content.ptr);
|
||||
}
|
||||
msg_reply(&msg, &reply);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _common_set_up(void)
|
||||
{
|
||||
assert(_mock_netif != NULL);
|
||||
gnrc_ipv6_nib_init();
|
||||
gnrc_ipv6_nib_init_iface(_mock_netif_pid);
|
||||
gnrc_netif2_acquire(_mock_netif);
|
||||
gnrc_ipv6_nib_init_iface(_mock_netif);
|
||||
gnrc_netif2_release(_mock_netif);
|
||||
}
|
||||
|
||||
int _get_device_type(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
(void)dev;
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = NETDEV_TYPE_ETHERNET;
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int _get_max_packet_size(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
(void)dev;
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = ETHERNET_DATA_LEN;
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int _get_address(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
static const uint8_t addr[] = { _LL0, _LL1, _LL2, _LL3, _LL4, _LL5 };
|
||||
|
||||
(void)dev;
|
||||
assert(max_len >= sizeof(addr));
|
||||
memcpy(value, addr, sizeof(addr));
|
||||
return sizeof(addr);
|
||||
}
|
||||
|
||||
void _tests_init(void)
|
||||
{
|
||||
msg_init_queue(_main_msg_queue, _MSG_QUEUE_SIZE);
|
||||
_mock_netif_pid = thread_create(_mock_netif_stack,
|
||||
sizeof(_mock_netif_stack),
|
||||
GNRC_NETDEV_MAC_PRIO,
|
||||
THREAD_CREATE_STACKTEST,
|
||||
_mock_netif_thread, NULL, "mock_netif");
|
||||
assert(_mock_netif_pid > KERNEL_PID_UNDEF);
|
||||
gnrc_netif_add(_mock_netif_pid);
|
||||
gnrc_ipv6_netif_init_by_dev();
|
||||
thread_yield();
|
||||
netdev_test_setup(&_mock_netdev, 0);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_DEVICE_TYPE,
|
||||
_get_device_type);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_MAX_PACKET_SIZE,
|
||||
_get_max_packet_size);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_ADDRESS,
|
||||
_get_address);
|
||||
_mock_netif = gnrc_netif2_ethernet_create(
|
||||
_mock_netif_stack, THREAD_STACKSIZE_DEFAULT, GNRC_NETIF2_PRIO,
|
||||
"mockup_eth", &_mock_netdev.netdev
|
||||
);
|
||||
assert(_mock_netif != NULL);
|
||||
gnrc_netreg_entry_init_pid(&dumper, GNRC_NETREG_DEMUX_CTX_ALL,
|
||||
sched_active_pid);
|
||||
gnrc_netreg_register(GNRC_NETTYPE_NDP2, &dumper);
|
||||
|
@ -8,8 +8,10 @@ BOARD_INSUFFICIENT_MEMORY := chronos nucleo-f030 nucleo-l053 nucleo32-f031 \
|
||||
USEMODULE += gnrc_ipv6
|
||||
USEMODULE += gnrc_sixlowpan
|
||||
USEMODULE += gnrc_ipv6_nib_6ln
|
||||
USEMODULE += gnrc_netif2
|
||||
USEMODULE += embunit
|
||||
USEMODULE += netopt
|
||||
USEMODULE += netdev_ieee802154
|
||||
USEMODULE += netdev_test
|
||||
|
||||
CFLAGS += -DDEVELHELP
|
||||
CFLAGS += -DGNRC_NETTYPE_NDP2=GNRC_NETTYPE_TEST
|
||||
|
@ -22,14 +22,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "net/gnrc.h"
|
||||
#include "net/gnrc/netif2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _CALL(fn) _common_set_up(); _set_up(); puts("Calling " # fn); fn()
|
||||
#define _LL0 (0xce)
|
||||
#define _LL1 (0xab)
|
||||
#define _LL2 (0xfe)
|
||||
#define _LL3 (0xad)
|
||||
#define _LL4 (0xf7)
|
||||
#define _LL5 (0x26)
|
||||
#define _LL6 (0xef)
|
||||
#define _LL7 (0xa4)
|
||||
|
||||
extern kernel_pid_t _mock_netif_pid;
|
||||
extern gnrc_netif2_t *_mock_netif;
|
||||
|
||||
void _tests_init(void);
|
||||
int _mock_netif_get(gnrc_netapi_opt_t *opt);
|
||||
|
@ -33,14 +33,6 @@
|
||||
#include "sched.h"
|
||||
|
||||
#define _BUFFER_SIZE (128)
|
||||
#define _LL0 (0xce)
|
||||
#define _LL1 (0xab)
|
||||
#define _LL2 (0xfe)
|
||||
#define _LL3 (0xad)
|
||||
#define _LL4 (0xf7)
|
||||
#define _LL5 (0x26)
|
||||
#define _LL6 (0xef)
|
||||
#define _LL7 (0xa4)
|
||||
|
||||
static const uint8_t _loc_l2[] = { _LL0, _LL1, _LL2, _LL3,
|
||||
_LL4, _LL5, _LL6, _LL7 };
|
||||
@ -79,8 +71,7 @@ static void test_get_next_hop_l2addr__link_local_EHOSTUNREACH(void)
|
||||
gnrc_ipv6_nib_nc_t nce;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH,
|
||||
gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll,
|
||||
KERNEL_PID_UNDEF,
|
||||
gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll, NULL,
|
||||
NULL, &nce));
|
||||
TEST_ASSERT_EQUAL_INT(0, msg_avail());
|
||||
TEST_ASSERT(gnrc_pktbuf_is_empty());
|
||||
@ -90,10 +81,10 @@ static void test_get_next_hop_l2addr__link_local_static_conf(void)
|
||||
{
|
||||
gnrc_ipv6_nib_nc_t nce;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_nc_set(&_rem_ll, _mock_netif_pid,
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_nc_set(&_rem_ll, _mock_netif->pid,
|
||||
_rem_l2, sizeof(_rem_l2)));
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll,
|
||||
_mock_netif_pid,
|
||||
_mock_netif,
|
||||
NULL, &nce));
|
||||
TEST_ASSERT_MESSAGE((memcmp(&_rem_ll, &nce.ipv6, sizeof(_rem_ll)) == 0),
|
||||
"_rem_ll != nce.ipv6");
|
||||
@ -102,7 +93,7 @@ static void test_get_next_hop_l2addr__link_local_static_conf(void)
|
||||
"_rem_l2 != nce.l2addr");
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNMANAGED,
|
||||
gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_AR_STATE_MANUAL,
|
||||
gnrc_ipv6_nib_nc_get_ar_state(&nce));
|
||||
@ -115,7 +106,7 @@ static void test_get_next_hop_l2addr__link_local(void)
|
||||
gnrc_ipv6_nib_nc_t nce;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_get_next_hop_l2addr(&_rem_ll,
|
||||
_mock_netif_pid,
|
||||
_mock_netif,
|
||||
NULL, &nce));
|
||||
TEST_ASSERT_MESSAGE((memcmp(&_rem_ll, &nce.ipv6, sizeof(_rem_ll)) == 0),
|
||||
"_rem_ll != nce.ipv6");
|
||||
@ -124,7 +115,7 @@ static void test_get_next_hop_l2addr__link_local(void)
|
||||
"_rem_l2 != nce.l2addr");
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_NUD_STATE_REACHABLE,
|
||||
gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_IPV6_NIB_NC_INFO_AR_STATE_REGISTERED,
|
||||
gnrc_ipv6_nib_nc_get_ar_state(&nce));
|
||||
@ -143,7 +134,7 @@ static void test_handle_pkt__unknown_type(void)
|
||||
memcpy(&ipv6->dst, &_rem_ll, sizeof(ipv6->dst));
|
||||
icmpv6->type = ICMPV6_ECHO_REQ;
|
||||
icmpv6->code = 0;
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6,
|
||||
sizeof(icmpv6_hdr_t));
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
@ -187,7 +178,7 @@ static void test_handle_pkt__nbr_sol__invalid_hl(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&_rem_ll, &_loc_ll, 194U, 0U,
|
||||
&_loc_ll, _rem_l2, sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -201,7 +192,7 @@ static void test_handle_pkt__nbr_sol__invalid_code(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&_rem_ll, &_loc_ll, 255U, 201U,
|
||||
&_loc_ll, _rem_l2, sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -216,7 +207,7 @@ static void test_handle_pkt__nbr_sol__invalid_icmpv6_len(void)
|
||||
_set_nbr_sol(&_rem_ll, &_loc_ll, 255U, 0U, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6,
|
||||
sizeof(ndp_nbr_sol_t) - 1);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
@ -232,7 +223,7 @@ static void test_handle_pkt__nbr_sol__invalid_tgt(void)
|
||||
&ipv6_addr_all_routers_site_local, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -250,7 +241,7 @@ static void test_handle_pkt__nbr_sol__invalid_opt_len(void)
|
||||
opt->type = NDP_OPT_SL2A;
|
||||
opt->len = 0U;
|
||||
icmpv6_len += sizeof(ndp_opt_t);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -264,7 +255,7 @@ static void test_handle_pkt__nbr_sol__invalid_dst(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&ipv6_addr_unspecified, &_loc_ll, 255U, 0U,
|
||||
&_loc_ll, NULL, 0);
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -279,7 +270,7 @@ static void test_handle_pkt__nbr_sol__invalid_sl2ao(void)
|
||||
255U, 0U, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -294,7 +285,7 @@ static void test_handle_pkt__nbr_sol__tgt_not_assigned(void)
|
||||
255U, 0U, &_rem_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -308,12 +299,12 @@ static void test_pkt_is_nbr_adv(gnrc_pktsnip_t *pkt, const ipv6_addr_t *dst,
|
||||
ipv6_hdr_t *ipv6_hdr;
|
||||
ndp_nbr_adv_t *nbr_adv;
|
||||
|
||||
/* first snip is a netif header to _mock_netif_pid */
|
||||
/* first snip is a netif header to _mock_netif */
|
||||
TEST_ASSERT_NOT_NULL(pkt);
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_NETIF, pkt->type);
|
||||
TEST_ASSERT(sizeof(gnrc_netif_hdr_t) <= pkt->size);
|
||||
netif_hdr = pkt->data;
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, netif_hdr->if_pid);
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, netif_hdr->if_pid);
|
||||
/* second snip is an IPv6 header to dst */
|
||||
TEST_ASSERT_NOT_NULL(pkt->next);
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_IPV6, pkt->next->type);
|
||||
@ -348,7 +339,7 @@ static void test_handle_pkt__nbr_sol__ll_src(unsigned exp_nud_state,
|
||||
255U, 0U, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"Expected neighbor cache entry");
|
||||
TEST_ASSERT_MESSAGE(ipv6_addr_equal(&_rem_ll, &nce.ipv6),
|
||||
@ -358,7 +349,7 @@ static void test_handle_pkt__nbr_sol__ll_src(unsigned exp_nud_state,
|
||||
"_rem_l2 != nce.l2addr");
|
||||
TEST_ASSERT_EQUAL_INT(exp_nud_state, gnrc_ipv6_nib_nc_get_nud_state(&nce));
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_nc_is_router(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif_pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(_mock_netif->pid, gnrc_ipv6_nib_nc_get_iface(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(exp_ar_state, gnrc_ipv6_nib_nc_get_ar_state(&nce));
|
||||
TEST_ASSERT_EQUAL_INT(1, msg_avail());
|
||||
msg_receive(&msg);
|
||||
@ -390,7 +381,7 @@ static void test_handle_pkt__nbr_sol__ll_src_no_sl2ao(void)
|
||||
size_t icmpv6_len = _set_nbr_sol(&_rem_ll, &_loc_ll,
|
||||
255U, 0U, &_loc_ll, NULL, 0);
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
TEST_ASSERT_EQUAL_INT(1, msg_avail());
|
||||
@ -441,7 +432,7 @@ static void test_handle_pkt__nbr_adv__invalid_hl(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -456,7 +447,7 @@ static void test_handle_pkt__nbr_adv__invalid_code(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -472,7 +463,7 @@ static void test_handle_pkt__nbr_adv__invalid_icmpv6_len(void)
|
||||
&_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6,
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6,
|
||||
sizeof(ndp_nbr_adv_t) - 1);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
@ -489,7 +480,7 @@ static void test_handle_pkt__nbr_adv__invalid_tgt(void)
|
||||
&ipv6_addr_all_routers_site_local, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -504,7 +495,7 @@ static void test_handle_pkt__nbr_adv__invalid_flags(void)
|
||||
255U, 0U, NDP_NBR_ADV_FLAGS_S, &_loc_ll,
|
||||
NULL, 0);
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -523,7 +514,7 @@ static void test_handle_pkt__nbr_adv__invalid_opt_len(void)
|
||||
opt->type = NDP_OPT_SL2A;
|
||||
opt->len = 0U;
|
||||
icmpv6_len += sizeof(ndp_opt_t);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -538,7 +529,7 @@ static void test_handle_pkt__nbr_adv__unspecified_src(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll, _rem_l2,
|
||||
sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
/* TODO: check other views as well */
|
||||
@ -553,7 +544,7 @@ static void test_handle_pkt__nbr_adv__unsolicited(void)
|
||||
NDP_NBR_ADV_FLAGS_S, &_loc_ll,
|
||||
_rem_l2, sizeof(_rem_l2));
|
||||
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif_pid, ipv6, icmpv6, icmpv6_len);
|
||||
gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len);
|
||||
TEST_ASSERT_MESSAGE(!gnrc_ipv6_nib_nc_iter(0, &state, &nce),
|
||||
"There is an unexpected neighbor cache entry");
|
||||
TEST_ASSERT_EQUAL_INT(0, msg_avail());
|
||||
|
@ -16,63 +16,84 @@
|
||||
#include "common.h"
|
||||
#include "msg.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "net/ethernet.h"
|
||||
#include "net/gnrc/ipv6/nib.h"
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
#include "net/gnrc/netdev.h"
|
||||
#include "net/gnrc/netif2/ieee802154.h"
|
||||
#include "net/gnrc/netif2/internal.h"
|
||||
#include "net/netdev_test.h"
|
||||
#include "sched.h"
|
||||
#include "thread.h"
|
||||
|
||||
#define _MSG_QUEUE_SIZE (2)
|
||||
|
||||
kernel_pid_t _mock_netif_pid = KERNEL_PID_UNDEF;
|
||||
gnrc_netif2_t *_mock_netif = NULL;
|
||||
|
||||
static netdev_test_t _mock_netdev;
|
||||
static char _mock_netif_stack[THREAD_STACKSIZE_DEFAULT];
|
||||
static gnrc_netreg_entry_t dumper;
|
||||
static msg_t _main_msg_queue[_MSG_QUEUE_SIZE];
|
||||
static msg_t _mock_netif_msg_queue[_MSG_QUEUE_SIZE];
|
||||
|
||||
static void *_mock_netif_thread(void *args)
|
||||
{
|
||||
msg_t msg, reply = { .type = GNRC_NETAPI_MSG_TYPE_ACK };
|
||||
|
||||
(void)args;
|
||||
msg_init_queue(_mock_netif_msg_queue, _MSG_QUEUE_SIZE);
|
||||
while (1) {
|
||||
msg_receive(&msg);
|
||||
switch (msg.type) {
|
||||
case GNRC_NETAPI_MSG_TYPE_GET:
|
||||
reply.content.value = (uint32_t)_mock_netif_get(msg.content.ptr);
|
||||
break;
|
||||
case GNRC_NETAPI_MSG_TYPE_SET:
|
||||
reply.content.value = (uint32_t)(-ENOTSUP);
|
||||
break;
|
||||
case GNRC_NETAPI_MSG_TYPE_SND:
|
||||
case GNRC_NETAPI_MSG_TYPE_RCV:
|
||||
gnrc_pktbuf_release(msg.content.ptr);
|
||||
}
|
||||
msg_reply(&msg, &reply);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _common_set_up(void)
|
||||
{
|
||||
assert(_mock_netif != NULL);
|
||||
gnrc_ipv6_nib_init();
|
||||
gnrc_ipv6_nib_init_iface(_mock_netif_pid);
|
||||
gnrc_netif2_acquire(_mock_netif);
|
||||
gnrc_ipv6_nib_init_iface(_mock_netif);
|
||||
gnrc_netif2_release(_mock_netif);
|
||||
}
|
||||
|
||||
int _get_device_type(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
(void)dev;
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = NETDEV_TYPE_IEEE802154;
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int _get_max_packet_size(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
(void)dev;
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = 102U;
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int _get_src_len(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
(void)dev;
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = IEEE802154_LONG_ADDRESS_LEN;
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int _get_address_long(netdev_t *dev, void *value, size_t max_len)
|
||||
{
|
||||
static const uint8_t addr[] = { _LL0, _LL1, _LL2, _LL3,
|
||||
_LL4, _LL5, _LL6, _LL7 };
|
||||
|
||||
(void)dev;
|
||||
assert(max_len >= sizeof(addr));
|
||||
memcpy(value, addr, sizeof(addr));
|
||||
return sizeof(addr);
|
||||
}
|
||||
|
||||
void _tests_init(void)
|
||||
{
|
||||
msg_init_queue(_main_msg_queue, _MSG_QUEUE_SIZE);
|
||||
_mock_netif_pid = thread_create(_mock_netif_stack,
|
||||
sizeof(_mock_netif_stack),
|
||||
GNRC_NETDEV_MAC_PRIO,
|
||||
THREAD_CREATE_STACKTEST,
|
||||
_mock_netif_thread, NULL, "mock_netif");
|
||||
assert(_mock_netif_pid > KERNEL_PID_UNDEF);
|
||||
gnrc_netif_add(_mock_netif_pid);
|
||||
gnrc_ipv6_netif_init_by_dev();
|
||||
thread_yield();
|
||||
netdev_test_setup(&_mock_netdev, 0);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_DEVICE_TYPE,
|
||||
_get_device_type);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_MAX_PACKET_SIZE,
|
||||
_get_max_packet_size);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_SRC_LEN,
|
||||
_get_src_len);
|
||||
netdev_test_set_get_cb(&_mock_netdev, NETOPT_ADDRESS_LONG,
|
||||
_get_address_long);
|
||||
_mock_netif = gnrc_netif2_ieee802154_create(
|
||||
_mock_netif_stack, THREAD_STACKSIZE_DEFAULT, GNRC_NETIF2_PRIO,
|
||||
"mockup_wpan", &_mock_netdev.netdev.netdev
|
||||
);
|
||||
assert(_mock_netif != NULL);
|
||||
gnrc_netreg_entry_init_pid(&dumper, GNRC_NETREG_DEMUX_CTX_ALL,
|
||||
sched_active_pid);
|
||||
gnrc_netreg_register(GNRC_NETTYPE_NDP2, &dumper);
|
||||
|
Loading…
Reference in New Issue
Block a user