mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-26 06:53:52 +01:00
Merge pull request #8083 from miri64/gnrc_ipv6_nib/api/prime-dr
gnrc_ipv6_nib: make user added default route the primary one
This commit is contained in:
commit
21a55612b7
@ -62,6 +62,9 @@ int gnrc_ipv6_nib_ft_get(const ipv6_addr_t *dst, gnrc_pktsnip_t *pkt,
|
||||
/**
|
||||
* @brief Adds a new route to the forwarding table
|
||||
*
|
||||
* If @p dst is the default route, the route will be configured to be the
|
||||
* default route.
|
||||
*
|
||||
* @param[in] dst The destination to the route. May be NULL or `::` for
|
||||
* default route.
|
||||
* @param[in] dst_len The prefix length of @p dst in bits. May be 0 for
|
||||
@ -83,6 +86,9 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len,
|
||||
/**
|
||||
* @brief Deletes a route from forwarding table.
|
||||
*
|
||||
* If @p dst is the default route, the function assures, that the current
|
||||
* primary default route is removed first.
|
||||
*
|
||||
* @param[in] dst The destination of the route. May be NULL or `::` for
|
||||
* default route.
|
||||
* @param[in] dst_len The prefix length of @p dst in bits. May be 0 for
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
#include "debug.h"
|
||||
|
||||
/* pointers for default router selection */
|
||||
static _nib_dr_entry_t *_prime_def_router = NULL;
|
||||
_nib_dr_entry_t *_prime_def_router = NULL;
|
||||
static clist_node_t _next_removable = { NULL };
|
||||
|
||||
static _nib_onl_entry_t _nodes[GNRC_IPV6_NIB_NUMOF];
|
||||
|
||||
@ -250,6 +250,16 @@ extern mutex_t _nib_mutex;
|
||||
*/
|
||||
extern evtimer_msg_t _nib_evtimer;
|
||||
|
||||
/**
|
||||
* @brief Primary default router.
|
||||
*
|
||||
* This value is returned by @ref @_nib_drl_get_dr() when it is not NULL and it
|
||||
* is reachable. Otherwise it is selected with the [default router selection
|
||||
* algoritm](https://tools.ietf.org/html/rfc4861#section-6.3.6) by that function.
|
||||
* Exposed to be settable by @ref net_gnrc_ipv6_nib_ft.
|
||||
*/
|
||||
extern _nib_dr_entry_t *_prime_def_router;
|
||||
|
||||
/**
|
||||
* @brief Initializes NIB internally
|
||||
*/
|
||||
|
||||
@ -51,9 +51,12 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len,
|
||||
if (ptr == NULL) {
|
||||
res = -ENOMEM;
|
||||
}
|
||||
else if (ltime > 0) {
|
||||
_evtimer_add(ptr, GNRC_IPV6_NIB_RTR_TIMEOUT,
|
||||
&ptr->rtr_timeout, ltime * MS_PER_SEC);
|
||||
else {
|
||||
_prime_def_router = ptr;
|
||||
if (ltime > 0) {
|
||||
_evtimer_add(ptr, GNRC_IPV6_NIB_RTR_TIMEOUT,
|
||||
&ptr->rtr_timeout, ltime * MS_PER_SEC);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if GNRC_IPV6_NIB_CONF_ROUTER
|
||||
|
||||
@ -568,6 +568,28 @@ static void test_nib_ft_add__success(void)
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_ft_iter(NULL, 0, &iter_state, &fte));
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a default route
|
||||
* Expected result: a new entry should exist and contain the given prefix,
|
||||
* interface, and lifetimes and it should be the primary default route
|
||||
*/
|
||||
static void test_nib_ft_add__success_dr(void)
|
||||
{
|
||||
gnrc_ipv6_nib_ft_t fte;
|
||||
void *iter_state = NULL;
|
||||
static const ipv6_addr_t next_hop = { .u64 = { { .u8 = LINK_LOCAL_PREFIX },
|
||||
{ .u64 = TEST_UINT64 } } };
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(NULL, 0, &next_hop, IFACE, 0));
|
||||
TEST_ASSERT(gnrc_ipv6_nib_ft_iter(NULL, 0, &iter_state, &fte));
|
||||
TEST_ASSERT(ipv6_addr_is_unspecified(&fte.dst));
|
||||
TEST_ASSERT_EQUAL_INT(0, fte.dst_len);
|
||||
TEST_ASSERT(ipv6_addr_equal(&fte.next_hop, &next_hop));
|
||||
TEST_ASSERT_EQUAL_INT(IFACE, fte.iface);
|
||||
TEST_ASSERT_EQUAL_INT(1, fte.primary);
|
||||
TEST_ASSERT(!gnrc_ipv6_nib_ft_iter(NULL, 0, &iter_state, &fte));
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates MAX_NUMOF routes with different destinations of to the different
|
||||
* next hops and interfaces and then tries to delete one with yet another
|
||||
@ -639,13 +661,19 @@ static void test_nib_ft_iter__empty_def_route_at_beginning(void)
|
||||
next_hop.u16[0].u16++;
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(NULL, 0,
|
||||
&next_hop, IFACE, 0));
|
||||
/* make first added route the primary default route again */
|
||||
next_hop.u16[0].u16 -= 2;
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(NULL, 0,
|
||||
&next_hop, IFACE, 0));
|
||||
/* remove primary default route */
|
||||
gnrc_ipv6_nib_ft_del(NULL, 0);
|
||||
next_hop.u16[0].u16--;
|
||||
next_hop.u16[0].u16++;
|
||||
while (gnrc_ipv6_nib_ft_iter(NULL, 0, &iter_state, &fte)) {
|
||||
TEST_ASSERT(ipv6_addr_is_unspecified(&fte.dst));
|
||||
TEST_ASSERT(ipv6_addr_equal(&fte.next_hop, &next_hop));
|
||||
TEST_ASSERT_EQUAL_INT(0, fte.dst_len);
|
||||
TEST_ASSERT_EQUAL_INT(IFACE, fte.iface);
|
||||
TEST_ASSERT(!fte.primary);
|
||||
count++;
|
||||
next_hop.u16[0].u16++;
|
||||
}
|
||||
@ -717,6 +745,7 @@ Test *tests_gnrc_ipv6_nib_ft_tests(void)
|
||||
new_TestFixture(test_nib_ft_add__success_duplicate),
|
||||
new_TestFixture(test_nib_ft_add__success_overwrite_unspecified),
|
||||
new_TestFixture(test_nib_ft_add__success),
|
||||
new_TestFixture(test_nib_ft_add__success_dr),
|
||||
new_TestFixture(test_nib_ft_del__unknown),
|
||||
new_TestFixture(test_nib_ft_del__success),
|
||||
/* most of gnrc_ipv6_nib_ft_iter() is tested during all the tests above */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user