tests: provide more test cases for source address selection
- ULA destination with global address on interface - Deprecated addresses
This commit is contained in:
parent
e9d75f5655
commit
020af4145a
@ -472,6 +472,60 @@ static void test_ipv6_addr_best_src__ula_src_dst(void)
|
||||
TEST_ASSERT(ipv6_addr_equal(&ula_src, out));
|
||||
}
|
||||
|
||||
static void test_ipv6_addr_best_src__global_src_ula_dst(void)
|
||||
{
|
||||
static const ipv6_addr_t src = { .u8 = NETIF0_IPV6_G };
|
||||
static const ipv6_addr_t ula_dst = { .u8 = { ULA1, ULA2, ULA3, ULA4,
|
||||
ULA5, ULA6, ULA7, ULA8,
|
||||
0, 0, 0, 0, 0, 0, 0, 1 } };
|
||||
ipv6_addr_t *out = NULL;
|
||||
int idx;
|
||||
|
||||
test_ipv6_addr_add__success(); /* adds link-local address */
|
||||
TEST_ASSERT(0 <= (idx = gnrc_netif_ipv6_addr_add_internal(netifs[0], &src, 64U,
|
||||
GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID)));
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID,
|
||||
netifs[0]->ipv6.addrs_flags[idx]);
|
||||
TEST_ASSERT(ipv6_addr_equal(&src, &netifs[0]->ipv6.addrs[idx]));
|
||||
|
||||
TEST_ASSERT_NOT_NULL((out = gnrc_netif_ipv6_addr_best_src(netifs[0],
|
||||
&ula_dst,
|
||||
false)));
|
||||
TEST_ASSERT(ipv6_addr_equal(&src, out));
|
||||
}
|
||||
|
||||
static void test_ipv6_addr_best_src__deprecated_addr(void)
|
||||
{
|
||||
static const ipv6_addr_t src = { .u8 = { LP1, LP2, LP3, LP4,
|
||||
LP5, LP6, LP7, LP8,
|
||||
0, 0, 0, 0, 0, 0, 0, 2 } };
|
||||
static const ipv6_addr_t dst = { .u8 = { LP1, LP2, LP3, LP4,
|
||||
LP5, LP6, LP7, LP8,
|
||||
0, 0, 0, 0, 0, 0, 0, 1 } };
|
||||
ipv6_addr_t *out = NULL;
|
||||
int idx;
|
||||
const unsigned exp_match = ipv6_addr_match_prefix(&src, &dst);
|
||||
|
||||
test_ipv6_addr_add__success(); /* adds EUI-64 based link-local address */
|
||||
/* ensure that current addresses have smaller matches */
|
||||
for (unsigned i = 0; i < GNRC_NETIF_IPV6_ADDRS_NUMOF; i++) {
|
||||
ipv6_addr_t *addr = &netifs[0]->ipv6.addrs[i];
|
||||
TEST_ASSERT(exp_match > ipv6_addr_match_prefix(addr, &dst));
|
||||
}
|
||||
/* add another link-local address but deprecated */
|
||||
TEST_ASSERT(0 <= (idx = gnrc_netif_ipv6_addr_add_internal(netifs[0], &src, 64U,
|
||||
GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_DEPRECATED)));
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_DEPRECATED,
|
||||
netifs[0]->ipv6.addrs_flags[idx]);
|
||||
TEST_ASSERT(ipv6_addr_equal(&src, &netifs[0]->ipv6.addrs[idx]));
|
||||
|
||||
TEST_ASSERT_NOT_NULL((out = gnrc_netif_ipv6_addr_best_src(netifs[0],
|
||||
&dst,
|
||||
false)));
|
||||
/* should be not `src` as it is deprecated */
|
||||
TEST_ASSERT(!ipv6_addr_equal(&src, out));
|
||||
}
|
||||
|
||||
static void test_get_by_ipv6_addr__empty(void)
|
||||
{
|
||||
static const ipv6_addr_t addr = { .u8 = NETIF0_IPV6_LL };
|
||||
@ -1494,6 +1548,8 @@ static Test *embunit_tests_gnrc_netif(void)
|
||||
new_TestFixture(test_ipv6_addr_best_src__unspecified_addr),
|
||||
new_TestFixture(test_ipv6_addr_best_src__other_subnet),
|
||||
new_TestFixture(test_ipv6_addr_best_src__ula_src_dst),
|
||||
new_TestFixture(test_ipv6_addr_best_src__global_src_ula_dst),
|
||||
new_TestFixture(test_ipv6_addr_best_src__deprecated_addr),
|
||||
new_TestFixture(test_get_by_ipv6_addr__empty),
|
||||
new_TestFixture(test_get_by_ipv6_addr__unspecified_addr),
|
||||
new_TestFixture(test_get_by_ipv6_addr__success),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user