Skip to content

Commit 9038416

Browse files
committed
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>
1 parent 411662d commit 9038416

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

tests/net/ipv6/prj.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ CONFIG_NET_BUF_TX_COUNT=20
2121
CONFIG_NET_6LO=y
2222
CONFIG_NET_6LO_CONTEXT=y
2323
CONFIG_NET_MAX_ROUTERS=2
24-
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=4
25-
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
24+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=7
25+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=7
2626
CONFIG_NET_IF_IPV6_PREFIX_COUNT=3
2727
CONFIG_SYS_LOG_NET_LEVEL=2
2828
#CONFIG_NET_DEBUG_IF=y

tests/net/ipv6/src/main.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ static const unsigned char ipv6_hbho[] = {
116116
};
117117

118118
static bool expecting_ra;
119+
static bool expecting_dad;
120+
static u32_t dad_time[3];
119121
static bool test_failed;
120122
static struct k_sem wait_data;
121123

@@ -229,6 +231,22 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
229231
}
230232
}
231233

234+
if (icmp->type == NET_ICMPV6_NS) {
235+
if (expecting_dad) {
236+
net_pkt_unref(pkt);
237+
238+
if (dad_time[0] == 0) {
239+
dad_time[0] = k_uptime_get_32();
240+
} else if (dad_time[1] == 0) {
241+
dad_time[1] = k_uptime_get_32();
242+
} else if (dad_time[2] == 0) {
243+
dad_time[2] = k_uptime_get_32();
244+
}
245+
246+
goto out;
247+
}
248+
}
249+
232250
/* Feed this data back to us */
233251
if (net_recv_data(iface, pkt) < 0) {
234252
TC_ERROR("Data receive failed.");
@@ -980,6 +998,49 @@ static void test_change_ll_addr(void)
980998
"Wrong link address 2");
981999
}
9821000

1001+
static void test_dad_timeout(void)
1002+
{
1003+
#if defined(CONFIG_NET_IPV6_DAD)
1004+
struct in6_addr addr1 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
1005+
0, 0, 0, 0, 0, 0, 0x99, 0x1 } } };
1006+
struct in6_addr addr2 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
1007+
0, 0, 0, 0, 0, 0, 0x99, 0x2 } } };
1008+
struct in6_addr addr3 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
1009+
0, 0, 0, 0, 0, 0, 0x99, 0x3 } } };
1010+
struct net_if *iface = net_if_get_default();
1011+
1012+
struct net_if_addr *ifaddr;
1013+
1014+
expecting_dad = true;
1015+
1016+
ifaddr = net_if_ipv6_addr_add(iface, &addr1, NET_ADDR_AUTOCONF, 0xffff);
1017+
zassert_not_null(ifaddr, "Address 1 cannot be added");
1018+
1019+
k_sleep(K_MSEC(10));
1020+
1021+
ifaddr = net_if_ipv6_addr_add(iface, &addr2, NET_ADDR_AUTOCONF, 0xffff);
1022+
zassert_not_null(ifaddr, "Address 2 cannot be added");
1023+
1024+
k_sleep(K_MSEC(10));
1025+
1026+
ifaddr = net_if_ipv6_addr_add(iface, &addr3, NET_ADDR_AUTOCONF, 0xffff);
1027+
zassert_not_null(ifaddr, "Address 3 cannot be added");
1028+
1029+
k_sleep(K_MSEC(200));
1030+
1031+
/* We should have received three DAD queries, make sure they are in
1032+
* proper order.
1033+
*/
1034+
zassert_true(dad_time[0] < dad_time[1], "DAD timer 1+2 failure");
1035+
zassert_true(dad_time[1] < dad_time[2], "DAD timer 2+3 failure");
1036+
zassert_true((dad_time[2] - dad_time[0]) < 100,
1037+
"DAD timers took too long time [%u] [%u] [%u]",
1038+
dad_time[0], dad_time[1], dad_time[2]);
1039+
1040+
expecting_dad = false;
1041+
#endif
1042+
}
1043+
9831044
void test_main(void)
9841045
{
9851046
ztest_test_suite(test_ipv6_fn,
@@ -997,7 +1058,8 @@ void test_main(void)
9971058
ztest_unit_test(test_hbho_message_2),
9981059
ztest_unit_test(test_hbho_message_3),
9991060
ztest_unit_test(test_change_ll_addr),
1000-
ztest_unit_test(test_prefix_timeout)
1061+
ztest_unit_test(test_prefix_timeout),
1062+
ztest_unit_test(test_dad_timeout)
10011063
);
10021064
ztest_run_test_suite(test_ipv6_fn);
10031065
}

0 commit comments

Comments
 (0)