Skip to content

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Jun 20, 2017

Implementation off the off-link component of the NIB back-end.

I needed to move some stuff around, to keep consistency, but other than that the change should be straight forward.

This PR is part of the network layer remodelling effort:
PR dependencies

@miri64 miri64 added GNRC Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Jun 20, 2017
@miri64 miri64 requested a review from cgundogan June 20, 2017 13:28
/**
* @brief Number of off-link entries in NIB
*
* @note **This number has direct influence on the maximum number of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of enclosing this with ** ... ** you could rather use @attention instead of @note

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to keep the style of the original ones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand - and docu styling might be separate more general issue anyway 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix in a different PR ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabadie aabadie modified the milestone: Release 2017.07 Jun 26, 2017
miri64 added a commit to miri64/RIOT that referenced this pull request Jun 27, 2017
miri64 added a commit to miri64/RIOT that referenced this pull request Jun 29, 2017
Copy link
Member

@cgundogan cgundogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first round ..

/**
* @brief Number of off-link entries in NIB
*
* @attention This number has direct influence on the maximum number of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to clarify: how exactly does GNRC_IPV6_NIB_OFFL_NUMOF influences the max. number? I would assume it is the max. number, or is there another number that is added to that?

DEBUG("nib: Allocating on-link node entry (addr = %s, iface = %u)\n",
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), iface);
for (unsigned i = 0; i < GNRC_IPV6_NIB_NUMOF; i++) {
_nib_onl_entry_t *tmp = &_nodes[i];

if ((_nib_onl_get_if(tmp) == iface) &&
(ipv6_addr_equal(addr, &tmp->ipv6))) {
((addr == NULL) || (ipv6_addr_equal(addr, &tmp->ipv6)))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this check for addr == NULL here? There's a @pre in the doxygen of this function, that addr != NULL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably need to remove the doxygen @pre then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @pre is wrong. For prefix list entries the next-hop address may be NULL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found an error here, while debugging NDP-RD. Will fix.

@@ -62,14 +64,13 @@ _nib_onl_entry_t *_nib_onl_alloc(const ipv6_addr_t *addr, unsigned iface)
{
_nib_onl_entry_t *node = NULL;

assert(addr != NULL);
DEBUG("nib: Allocating on-link node entry (addr = %s, iface = %u)\n",
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), iface);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line will crash if addr == NULL

@@ -341,6 +343,96 @@ _nib_dr_entry_t *_nib_drl_get_dr(void)
return _prime_def_router;
}

_nib_offl_entry_t *_nib_offl_alloc(const ipv6_addr_t *next_hop, unsigned iface,
const ipv6_addr_t *pfx, unsigned pfx_len)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix your browser font :P

_nib_offl_entry_t *dst = NULL;

assert((pfx != NULL) && (!ipv6_addr_is_unspecified(pfx)) &&
(pfx_len != 0) && (pfx_len <= 128));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just taste, but I like pfx_len > 0 more, because it's in harmony with px_len <= 128

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito, don't know what came over me.

_nib_offl_entry_t *_nib_dst_alloc(const ipv6_addr_t *next_hop, unsigned iface,
const ipv6_addr_t *pfx, unsigned pfx_len);
_nib_offl_entry_t *_nib_offl_alloc(const ipv6_addr_t *next_hop, unsigned iface,
const ipv6_addr_t *pfx, unsigned pfx_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fixed here, I know :P

* @return NULL, if no space is left.
*/
static inline _nib_offl_entry_t *_nib_dc_add(const ipv6_addr_t *next_hop,
unsigned iface,
const ipv6_addr_t *dst)
{
return _nib_dst_add(next_hop, iface, dst, IPV6_ADDR_BIT_LEN, _DC);
assert(next_hop != NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add assert(dst != NULL);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's checked in _nib_offl_alloc() (which is called by _nib_offl_add())...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That may be true for now, but what if this code changes with time and possibly by another developer?. IMO these asserts also have a documentational character.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright...

* interfaces and then tries to add another.
* Expected result: should return NULL
*/
static void test_nib_offl_alloc__no_space_left_diff_next_hop_iface(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont' think you need the above two test cases when you introduce this test case that combines both

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, checking for behavior different addresses, different interfaces and different addresses and different interfaces are disjunct test-cases. One simple mix-up of && and || in the implementation would let fail at least one of them.

* tries to add another.
* Expected result: should return NULL
*/
static void test_nib_offl_alloc__no_space_left_diff_next_hop_iface_pfx(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the same, the above two test cases are not really necessary, are they?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above.

* equal to the last.
* Expected result: should return not NULL (the last)
*/
static void test_nib_offl_alloc__success_duplicate(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many test cases that are very similar .. can you collapse them? It is hard to maintain so many test cases in case of changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are subtle differences that are not easily parameterized out. Ideally, this API shouldn't change much.

@miri64
Copy link
Member Author

miri64 commented Aug 8, 2017

Comments addressed.

@miri64
Copy link
Member Author

miri64 commented Aug 15, 2017

Found an error here, while debugging NDP-RD. Will fix.

Done: the problem was, if a Prefix List entry was allocated first and a neighbor cache entry to the same interface later, the allocation would create a new entry. The last two commits add a fix and a corresponding test for this.

@miri64
Copy link
Member Author

miri64 commented Aug 15, 2017

Oops, now the address isn't set ^^ will fix

@miri64
Copy link
Member Author

miri64 commented Aug 15, 2017

(fixed and added updated corresponding test)

@miri64
Copy link
Member Author

miri64 commented Aug 21, 2017

Ping @cgundogan? You promised to review last week :(

Copy link
Member

@cgundogan cgundogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks better now .. the goal draws nearer (:

(_nib_onl_get_if(tmp_node) == iface) &&
((next_hop == NULL) || ipv6_addr_is_unspecified(&tmp_node->ipv6) ||
(ipv6_addr_equal(next_hop, &tmp_node->ipv6))) &&
(ipv6_addr_match_prefix(&tmp->pfx, pfx) >= pfx_len)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty ugly chain of conditions. Care to outsource into an inlined function or provide code documentation on what happens here?

@@ -232,8 +237,6 @@ static inline void _nib_onl_set_if(_nib_onl_entry_t *node, unsigned iface)
/**
* @brief Creates or gets an existing on-link entry by address
*
* @pre `(addr != NULL)`.
*
* @param[in] addr An IPv6 address. May not be NULL.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be NULL.

* @return NULL, if no space is left.
*/
static inline _nib_offl_entry_t *_nib_dc_add(const ipv6_addr_t *next_hop,
unsigned iface,
const ipv6_addr_t *dst)
{
return _nib_dst_add(next_hop, iface, dst, IPV6_ADDR_BIT_LEN, _DC);
assert(next_hop != NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That may be true for now, but what if this code changes with time and possibly by another developer?. IMO these asserts also have a documentational character.

@miri64
Copy link
Member Author

miri64 commented Oct 6, 2017

Addressed comments

@cgundogan
Copy link
Member

@miri64 great, thanks for your patience! Please squash the commits and then let's murdock have some fun!

@cgundogan cgundogan added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Oct 6, 2017
@miri64 miri64 force-pushed the gnrc_ipv6_nib/feat/internal-offl branch from 34ab23a to 124d6c8 Compare October 6, 2017 09:12
@miri64
Copy link
Member Author

miri64 commented Oct 6, 2017

Squashed

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Oct 6, 2017
@cgundogan cgundogan added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 6, 2017
@cgundogan
Copy link
Member

Murdock spits out some errors here.

@miri64 miri64 force-pushed the gnrc_ipv6_nib/feat/internal-offl branch from 124d6c8 to c1f9b15 Compare October 6, 2017 09:51
@miri64
Copy link
Member Author

miri64 commented Oct 6, 2017

Murdock spits out some errors here.

Problem was the amended inline function requested in #7212 (comment). Fixed and squashed immediately.

@cgundogan
Copy link
Member

Now murdock is happy (: GO

@cgundogan cgundogan merged commit c3d3e7d into RIOT-OS:master Oct 6, 2017
@miri64 miri64 deleted the gnrc_ipv6_nib/feat/internal-offl branch October 6, 2017 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants