Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc_ipv6_nib: initial import of internal NIB functions #6325

Merged
merged 2 commits into from
Jun 9, 2017

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Jan 11, 2017

Reasoning for this PR

To put it mildly: the new NDP implementation will be a cluster fuck of interdependent PRs anyways, so I started with an import of the internal structure needed for a working Address Resolution/Registration (AR) and Neighbor Unreachable Discovery (NUD). Including tests, doc and headers this is already ~2000 loc, but thankfully the implementation itself is only 250 loc long ;-).

Structure

The internal structure of the NIB is made to waste the least amount of RAM considering its complex structure:

untitled diagram 1

Off-link entries are currently omitted from this PR, as they are not required for AR and NUD.

Edit: model was updated and is still WIP https://miri64.github.io/riot-ndp-model/

@miri64 miri64 added GNRC Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Jan 11, 2017
@miri64 miri64 added this to the Release 2017.01 milestone Jan 11, 2017
@miri64 miri64 requested a review from OlegHahm January 11, 2017 11:23
#define GNRC_IPV6_NIB_QUEUE_PACKETS (1)
#endif

#ifndef GNRC_IPV6_NIB_DO_HANDLE_NBR_SOL
Copy link
Member

Choose a reason for hiding this comment

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

What's the idea of incuding this long list of compile time flags? It should suffice to check their availability with if[n]def where they are needed. Maybe I misunderstand and they are used not as compile time switches, sorry if so, but there is no code using them currently (:

Copy link
Member Author

@miri64 miri64 Jan 11, 2017

Choose a reason for hiding this comment

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

They are used as compile switches, but I did not want them to be #ifndef enabled flags, but #if enabled flags, so you can deactivate them beyond the default config easily, too. This is actually more important than activating them, since e.g. 6Lo-ND doesn't need to handle TLLAOs or redirect messages.

Copy link
Member

Choose a reason for hiding this comment

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

okay 👍

@miri64
Copy link
Member Author

miri64 commented Jan 13, 2017

Added the default router selection algorithm from RFC 4861.

@miri64
Copy link
Member Author

miri64 commented Mar 20, 2017

Rebased to current master

@kaspar030 kaspar030 modified the milestone: Release 2017.04 Apr 21, 2017
@miri64 miri64 force-pushed the gnrc_ipv6_nib/feat/internal branch from 381f5c3 to 9c3a642 Compare April 25, 2017 14:55
@miri64
Copy link
Member Author

miri64 commented Apr 25, 2017

Rebased to current master and adapted to the new model

@miri64
Copy link
Member Author

miri64 commented Apr 26, 2017

Ready for review.

@miri64 miri64 mentioned this pull request Apr 26, 2017
@miri64
Copy link
Member Author

miri64 commented Apr 26, 2017

Just found another issue with this PR, when working with the NC component. Will fix asap.

@miri64
Copy link
Member Author

miri64 commented Apr 28, 2017

Issue resolved.

@miri64 miri64 force-pushed the gnrc_ipv6_nib/feat/internal branch 2 times, most recently from 2cdfc2b to bc182a5 Compare April 28, 2017 15:23
miri64 added a commit to miri64/RIOT that referenced this pull request May 1, 2017
@miri64 miri64 added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 1, 2017
miri64 added a commit to miri64/RIOT that referenced this pull request May 2, 2017

_nib_onl_entry_t *_nib_onl_iter(const _nib_onl_entry_t *last)
{
for (const _nib_onl_entry_t *node = (last) ? last + 1 : _nodes;
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the motivation for const here, since the array that is iterated over is also not an array of const elements. IMO there's no need for that and makes the below lines less verbose.

Copy link
Member

Choose a reason for hiding this comment

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

Const correctness is important for preventing coding mistakes and may help the compiler how to optimize.

Copy link
Member Author

Choose a reason for hiding this comment

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

What @gebart is saying

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO there's no need for that and makes the below lines less verbose.

How that?

assert(cstate != GNRC_IPV6_NIB_NC_INFO_NUD_STATE_PROBE);
assert(cstate != GNRC_IPV6_NIB_NC_INFO_NUD_STATE_REACHABLE);
_nib_onl_entry_t *node = _nib_onl_alloc(addr, iface);
if (node != NULL) {
Copy link
Member

@cgundogan cgundogan Jun 9, 2017

Choose a reason for hiding this comment

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

I would prefer

if (node == NULL) {
    return _cache_out_onl_entry(addr, iface, cstate);;
}

to remove the indentation below. Leads to a much better readability of the code.

@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

I wonder if we could merge the default router list with the off-link entry list.
I understand that separation has the advance of saving ram for :: and a prefix length information.
But maintaining the individual list with special member structs requires its own access and modification functions which rises code and the flash image size.

The members of the default router entry struct would still have to be required be added to the off-link-router entry struct, so we then would also waste memory there (since most of them would only be required for default routers). Since the default router list maintenance functions are one of the least complex I also think that the ROM salvage we get from this isn't as big as the RAM salvage we get (percent-wise). As soon as the whole NIB is in place however we can experiment with that. That's the nice thing about levels of abstraction :-).

@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Since the default router list maintenance functions are one of the least complex I also think that the ROM salvage we get from this isn't as big as the RAM salvage we get (percent-wise)

Just consider, that for a typical 6LN (where we need to save the most memory) we can assume, that it only has one off-link-entry (a prefix in its prefix list) and one default router, so by joining those to data structure we would double the required RAM, because they have completely orthogonally required fields (disregarding prefix, which we are currently saving by implicitly having it :: for the default router).

{
/* if there isn't already a default router selected or
* its reachability is suspect */
if ((_prime_def_router == NULL) ||
Copy link
Member

Choose a reason for hiding this comment

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

Can you also change this to an early exit? This function has 3 levels of indentation ..

TEST_ASSERT_NULL(_nib_drl_iter(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 remove empty line

TEST_ASSERT(nib_res == node);
TEST_ASSERT_NOT_NULL((nib_res = _nib_drl_get_dr()));
TEST_ASSERT(nib_res == node);
TEST_ASSERT_NOT_NULL((nib_res = _nib_drl_get_dr()));
Copy link
Member

Choose a reason for hiding this comment

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

testing nib_res == node 2 times is enough ..

}

/*
* Tries to get the default router from a list of two routers
Copy link
Member

Choose a reason for hiding this comment

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

tests with two routers are obsolete when you are testing the permutation of three routers below ..

@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Addressed latest batch of comments on tests

@cgundogan
Copy link
Member

cgundogan commented Jun 9, 2017

ACK from @BytesGalore and me ! please squash.

@miri64 miri64 force-pushed the gnrc_ipv6_nib/feat/internal branch from 65033f0 to 22ec0c1 Compare June 9, 2017 11:24
@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Squashed and rebased

@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 Jun 9, 2017
@cgundogan
Copy link
Member

please address murdock's findings.

@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Already on it :-)

@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Fixed (but not squashed in case you want to review those changes, because they are quite largish)

miri64 added a commit to miri64/RIOT that referenced this pull request Jun 9, 2017
@cgundogan
Copy link
Member

cgundogan commented Jun 9, 2017

The doc fixes look good. Please squash and then let's see what murdock has to say. It's getting real now (:

@miri64 miri64 force-pushed the gnrc_ipv6_nib/feat/internal branch from c4a5fd5 to 0bf52f0 Compare June 9, 2017 19:52
@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Squashed

@miri64
Copy link
Member Author

miri64 commented Jun 9, 2017

Murdock likes it :-)

@cgundogan cgundogan merged commit 72c3c9c into RIOT-OS:master Jun 9, 2017
@miri64 miri64 deleted the gnrc_ipv6_nib/feat/internal branch June 9, 2017 20:10
@aabadie aabadie modified the milestone: Release 2017.07 Jun 26, 2017
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.

9 participants