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_netif2: Introduction of a new GNRC network interface API #7370

Merged

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Jul 16, 2017

This unifies and consolidates the APIs of gnrc_netdev, gnrc_netif, gnrc_ipv6_netif, and gnrc_sixlowpan_netif. Currently there are only header definitions defined to start some discussion. Basically instead of splitting up the data upon several structs they are unified in one, which is protected by a struct-wise (recursive) mutex. The mutex is necessary, since beside the interface's thread the 6LoWPAN thread and the IPv6 thread will access the struct to save some valuable time otherwise wasted in IPC. GNRC externally the interface is supposed to be accessed via NETAPI_GET and NETAPI_SET. The required netopts still need to be defined in part.

TODO:

  • unittests

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

@miri64 miri64 added Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Jul 16, 2017
@miri64 miri64 requested a review from cgundogan July 16, 2017 12:03
@miri64
Copy link
Member Author

miri64 commented Jul 16, 2017

$ cloc $(git show --pretty="" --name-only)
       3 text files.
       3 unique files.                              
       0 files ignored.

http://cloc.sourceforge.net v 1.60  T=0.01 s (244.6 files/s, 76873.7 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C/C++ Header                     2             73            654            195
C                                1              5             14              2
-------------------------------------------------------------------------------
SUM:                             3             78            668            197
-------------------------------------------------------------------------------

@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch from d848738 to e5ffd7e Compare July 17, 2017 15:38
@miri64
Copy link
Member Author

miri64 commented Jul 17, 2017

Done with the implementation (I hope ^^). Now some unittests are missing. The stack integration and shell command I would prefer to do in a separate PR, since this PR already is quite large...

@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch from e5ffd7e to 732bf5b Compare July 17, 2017 17:01
@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch 2 times, most recently from db3cc0a to 0ac7db2 Compare July 24, 2017 14:48
@miri64 miri64 changed the title gnrc_netif2: Introduction of a new GNRC network interface API [WIP/RFC] gnrc_netif2: Introduction of a new GNRC network interface API [RFC] Jul 25, 2017
@miri64 miri64 added GNRC Area: network Area: Networking and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Jul 25, 2017
@miri64
Copy link
Member Author

miri64 commented Jul 25, 2017

(no longer WIP btw)

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

Briefly went though this one and found some issues with doxygen.
Will see if I can provide an adaption of #7356 in a separate PR.

* @param[in] netif The network interface.
*
* This is called after the default settings were set, right before the
* interface's thread starts receiving messages. It is not necessary lock
Copy link
Contributor

Choose a reason for hiding this comment

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

'It doesn't necessary lock'

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? That doesn't make any sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

'It is not necessary lock the interface's mutex gnrc_netif_t::mutex, since the thread will already lock it.'
I think there's a typo here, that's why I proposed:
'It doesn't necessary lock...'
Maybe some rephrasing is required.

Copy link
Member Author

@miri64 miri64 Aug 17, 2017

Choose a reason for hiding this comment

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

But that negates the the sentence... Lock in is not required, since the thread will do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok!

Copy link
Member Author

Choose a reason for hiding this comment

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

*locking

Mh... But if I wrote it like you quoted me (can't check, am on a phone), then a "to" is missing. Will fix if it is so.

Copy link
Member Author

Choose a reason for hiding this comment

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

"It doesn't necessary..." is in any way grammatically wrong ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for the missing 'to'.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

*
* @return The number of bytes actually sent on success
* @return -EBADMSG, if the @ref net_gnrc_netif_hdr in @p pkt is missing
* or of an unexpected format.
Copy link
Contributor

Choose a reason for hiding this comment

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

'or is in an unexpected format' ?

*
* @pre `netif != NULL`
*
* @note The function takes the bytes received from via
Copy link
Contributor

Choose a reason for hiding this comment

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

'from via' sounds weird

int (*get)(gnrc_netif2_t *netif, gnrc_netapi_opt_t *opt);

/**
* @brief Get an option from the network interface
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be 'Sets an option' ?
Next line should also be updated.

gnrc_pktsnip_t *(*recv)(gnrc_netif2_t *netif);

/**
* @brief Get an option from the network interface
Copy link
Contributor

Choose a reason for hiding this comment

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

Gets ?

#endif

/**
* @brief Number of multicast addressed needed for @ref net_gnrc_rpl "RPL".
Copy link
Contributor

Choose a reason for hiding this comment

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

s/addressed/addresses/

const ipv6_addr_t *addr);

/**
* @brief Get state from address flags
Copy link
Contributor

Choose a reason for hiding this comment

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

Gets ? This is no consistent in other places as well.

@miri64
Copy link
Member Author

miri64 commented Aug 17, 2017

Addressed @aabadie's comments.

@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch from c40338f to 943aab0 Compare August 17, 2017 17:35
@miri64
Copy link
Member Author

miri64 commented Aug 17, 2017

Rebased

@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch from f2d599b to d53ffd3 Compare August 18, 2017 15:35
Copy link
Member

@bergzand bergzand left a comment

Choose a reason for hiding this comment

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

Not a lot of technical remarks, mostly spelling and/or grammar related comments.

If I've got the time later today, I'd like to look a bit better at gnrc_netif2.c.

*
* @note The function re-formats the content of @p pkt to a format expected
* by the netdev_driver_t::send() method of gnrc_netif_t::dev and
* releases the it before returning (so no additional release should
Copy link
Member

Choose a reason for hiding this comment

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

"...releases the packet before..."

*
* @return @p out.
*/
char *gnrc_netif2_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense here to return an input parameter? Why not return the size of the formatted string?

Copy link
Member Author

Choose a reason for hiding this comment

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

strings are usually \0 terminate, so returning its length is not required (a non-fitting out is an error case) (this function is mostly used for debugging, so no machine short-cuts required).

Copy link
Member

Choose a reason for hiding this comment

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

👍

/**
* @brief Maximum number of network interfaces
*
* @note Intentially not calling it `GNRC_NETIF2_NUMOF` to not require
Copy link
Member

Choose a reason for hiding this comment

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

Intentionally

#define GNRC_NETIF2_L2ADDR_MAXLEN (IEEE802154_LONG_ADDRESS_LEN)
#elif MODULE_NETDEV_ETH
#define GNRC_NETIF2_L2ADDR_MAXLEN (ETHERNET_ADDR_LEN)
#elif MODULE_CC110X
Copy link
Member

Choose a reason for hiding this comment

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

It feels ugly to me to have a switch depending directly on a device driver. I don't know if there is a better solution for this though.

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 CC110X has a proprietary protocol that needs adressing. I do not see it as a dependency on the device driver but on the protocol.

The trick is not to worry about it

Copy link
Member

Choose a reason for hiding this comment

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

Never mind then :)

* @attention GHC not implemented yet
* @see [RFC 7400, section 3.3](https://tools.ietf.org/html/rfc7400#section-3.3)
*/
#define GNRC_NETIF2_FLAGS_6LO_BACKBONE (0x00000800U)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be something like GNRC_NETIF2_FLAGS_6LO_GHC?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this has nothing to do with GHC, but with multi-border-router management. Will update the comment above accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I assumed the comment to be correct here.

~GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_MASK) |
GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_VALID);
uint8_t pfx_len = (uint8_t)(opt->context >> 8U);
/* acquire locks a recursive mutex so we are save calling this
Copy link
Member

Choose a reason for hiding this comment

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

Should be "...are safe calling..."

break;
case NETOPT_IPV6_ADDR_REMOVE:
assert(opt->data_len == sizeof(ipv6_addr_t));
/* acquire locks a recursive mutex so we are save calling this
Copy link
Member

Choose a reason for hiding this comment

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

Safe

break;
case NETOPT_IPV6_GROUP:
assert(opt->data_len == sizeof(ipv6_addr_t));
/* acquire locks a recursive mutex so we are save calling this
Copy link
Member

Choose a reason for hiding this comment

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

Safe

break;
case NETOPT_IPV6_GROUP_LEAVE:
assert(opt->data_len == sizeof(ipv6_addr_t));
/* acquire locks a recursive mutex so we are save calling this
Copy link
Member

Choose a reason for hiding this comment

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

Safe

}

if (nread < bytes_expected) {
/* we've got less then the expected packet size,
Copy link
Member

Choose a reason for hiding this comment

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

Should be "less than".

@miri64
Copy link
Member Author

miri64 commented Oct 6, 2017

Thanks for reviewing, @bergzand. I addressed your comments.

miri64 added a commit to miri64/RIOT that referenced this pull request Oct 6, 2017
static inline int _mock_netif_send(gnrc_netif2_t *netif, gnrc_pktsnip_t *pkt);
static inline gnrc_pktsnip_t *_mock_netif_recv(gnrc_netif2_t * netif);
static int _get_netdev_address(netdev_t *dev, void *value, size_t max_len);
static int _set_netdev_address(netdev_t *dev, void *value, size_t value_len);
Copy link
Member

Choose a reason for hiding this comment

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

My compiler is complaining hard that value should be of type const void *.

@bergzand
Copy link
Member

bergzand commented Oct 6, 2017

Nothing more to add except for my remark above. gnrc_netif2.c looks good to me.

@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch from bfa8731 to 173756a Compare October 7, 2017 01:16
@miri64
Copy link
Member Author

miri64 commented Oct 7, 2017

Addressed latest comments and rebased (otherwise the test wouldn't build locally on my machine ;-))

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 7, 2017
*/
static inline void gnrc_netif2_acquire(gnrc_netif2_t *netif)
{
if (netif && (netif->ops)) {
Copy link
Member

Choose a reason for hiding this comment

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

Strange to check for netif->ops here. It's not even used for acquiring a mutex. Good you leave a hint in the doc that netif->ops != NULL is necessary to acquire the mutex?

Copy link
Member Author

Choose a reason for hiding this comment

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

netif->ops is NULL before the interface was initialized. If the interface is not initialized it is not necessary to lock its mutex.

*/
static inline void gnrc_netif2_release(gnrc_netif2_t *netif)
{
if (netif && (netif->ops)) {
Copy link
Member

Choose a reason for hiding this comment

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

same here

* @param[in] flags initial flags for the address.
* - Setting the address' state to
* @ref GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_TENTATIVE
* means thata this address is assumed to be added due to
Copy link
Member

Choose a reason for hiding this comment

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

thata

* - Setting the address' state to
* @ref GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_TENTATIVE
* means thata this address is assumed to be added due to
* state-less auto-address configuration and actions
Copy link
Member

Choose a reason for hiding this comment

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

state-less => stateless

const ipv6_addr_t *dst,
uint8_t *candidate_set)
{
/* create temporary set for assigning "points" to candidates wining in the
Copy link
Member

Choose a reason for hiding this comment

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

wining? :P

*
* @see net_gnrc_netif2_ipv6_addrs_flags
*
* @note Only available with module @ref net_gnrc_ipv6 "gnrc_ipv6".
Copy link
Member

Choose a reason for hiding this comment

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

Only available with module @ref net_gnrc_ipv6 "gnrc_ipv6".

shouldn't there be a guard around those struct members if they are only available with gnrc_ipv6?

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 is, not just around the single struct members, but around the whole struct ;-).

@cgundogan
Copy link
Member

I have no major issues besides those minor – mostly editorial – comments above. I think we can merge here as soon as they are addressed.

@miri64
Copy link
Member Author

miri64 commented Oct 9, 2017

Addressed comments

@cgundogan
Copy link
Member

Please squash!

@miri64 miri64 force-pushed the gnrc_netif2/feat/new-netif-api-for-gnrc branch from ae88270 to 77d9770 Compare October 10, 2017 08:36
@miri64
Copy link
Member Author

miri64 commented Oct 10, 2017

Squashed and rebased.

miri64 added a commit to miri64/RIOT that referenced this pull request Oct 10, 2017
miri64 added a commit to miri64/RIOT that referenced this pull request Oct 10, 2017
@miri64
Copy link
Member Author

miri64 commented Oct 10, 2017

Murdock likes it. @cgundogan or @aabadie, can I have an ACK? :)

@miri64
Copy link
Member Author

miri64 commented Oct 10, 2017

(3 people - 4 if I count @haukepetersen's inofficial offline review - looked at the code and I addressed all their comments, so I assume the PR is now ACK-worthy ;-))

miri64 added a commit to miri64/RIOT that referenced this pull request Oct 10, 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.

ACK

@cgundogan
Copy link
Member

@aabadie your comments have been addressed more than a month ago – I will dismiss your change request now to continue with merging (:

@cgundogan cgundogan dismissed aabadie’s stale review October 10, 2017 09:02

Comments have been addressed by @miri64

@cgundogan cgundogan merged commit d51c058 into RIOT-OS:master Oct 10, 2017
@miri64 miri64 deleted the gnrc_netif2/feat/new-netif-api-for-gnrc branch October 10, 2017 09:03
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants