tests: net: ipv6: Add tests for verifying DAD timers
Make sure that DAD timers are triggered in proper order. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
411662d344
commit
9038416bdd
@ -21,8 +21,8 @@ CONFIG_NET_BUF_TX_COUNT=20
|
||||
CONFIG_NET_6LO=y
|
||||
CONFIG_NET_6LO_CONTEXT=y
|
||||
CONFIG_NET_MAX_ROUTERS=2
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=4
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=7
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=7
|
||||
CONFIG_NET_IF_IPV6_PREFIX_COUNT=3
|
||||
CONFIG_SYS_LOG_NET_LEVEL=2
|
||||
#CONFIG_NET_DEBUG_IF=y
|
||||
|
||||
@ -116,6 +116,8 @@ static const unsigned char ipv6_hbho[] = {
|
||||
};
|
||||
|
||||
static bool expecting_ra;
|
||||
static bool expecting_dad;
|
||||
static u32_t dad_time[3];
|
||||
static bool test_failed;
|
||||
static struct k_sem wait_data;
|
||||
|
||||
@ -229,6 +231,22 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
|
||||
}
|
||||
}
|
||||
|
||||
if (icmp->type == NET_ICMPV6_NS) {
|
||||
if (expecting_dad) {
|
||||
net_pkt_unref(pkt);
|
||||
|
||||
if (dad_time[0] == 0) {
|
||||
dad_time[0] = k_uptime_get_32();
|
||||
} else if (dad_time[1] == 0) {
|
||||
dad_time[1] = k_uptime_get_32();
|
||||
} else if (dad_time[2] == 0) {
|
||||
dad_time[2] = k_uptime_get_32();
|
||||
}
|
||||
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Feed this data back to us */
|
||||
if (net_recv_data(iface, pkt) < 0) {
|
||||
TC_ERROR("Data receive failed.");
|
||||
@ -980,6 +998,49 @@ static void test_change_ll_addr(void)
|
||||
"Wrong link address 2");
|
||||
}
|
||||
|
||||
static void test_dad_timeout(void)
|
||||
{
|
||||
#if defined(CONFIG_NET_IPV6_DAD)
|
||||
struct in6_addr addr1 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0x99, 0x1 } } };
|
||||
struct in6_addr addr2 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0x99, 0x2 } } };
|
||||
struct in6_addr addr3 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0x99, 0x3 } } };
|
||||
struct net_if *iface = net_if_get_default();
|
||||
|
||||
struct net_if_addr *ifaddr;
|
||||
|
||||
expecting_dad = true;
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(iface, &addr1, NET_ADDR_AUTOCONF, 0xffff);
|
||||
zassert_not_null(ifaddr, "Address 1 cannot be added");
|
||||
|
||||
k_sleep(K_MSEC(10));
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(iface, &addr2, NET_ADDR_AUTOCONF, 0xffff);
|
||||
zassert_not_null(ifaddr, "Address 2 cannot be added");
|
||||
|
||||
k_sleep(K_MSEC(10));
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(iface, &addr3, NET_ADDR_AUTOCONF, 0xffff);
|
||||
zassert_not_null(ifaddr, "Address 3 cannot be added");
|
||||
|
||||
k_sleep(K_MSEC(200));
|
||||
|
||||
/* We should have received three DAD queries, make sure they are in
|
||||
* proper order.
|
||||
*/
|
||||
zassert_true(dad_time[0] < dad_time[1], "DAD timer 1+2 failure");
|
||||
zassert_true(dad_time[1] < dad_time[2], "DAD timer 2+3 failure");
|
||||
zassert_true((dad_time[2] - dad_time[0]) < 100,
|
||||
"DAD timers took too long time [%u] [%u] [%u]",
|
||||
dad_time[0], dad_time[1], dad_time[2]);
|
||||
|
||||
expecting_dad = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(test_ipv6_fn,
|
||||
@ -997,7 +1058,8 @@ void test_main(void)
|
||||
ztest_unit_test(test_hbho_message_2),
|
||||
ztest_unit_test(test_hbho_message_3),
|
||||
ztest_unit_test(test_change_ll_addr),
|
||||
ztest_unit_test(test_prefix_timeout)
|
||||
ztest_unit_test(test_prefix_timeout),
|
||||
ztest_unit_test(test_dad_timeout)
|
||||
);
|
||||
ztest_run_test_suite(test_ipv6_fn);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user