RIOT's modular default IP network stack. More...
RIOT's modular default IP network stack.
This module is currently the default network stack for RIOT and includes many components ranging from a Network interface API through a fully-featured IPv6 implementation with 6LowPAN extensions to an UDP implementation and RPL.
A list of all features contained in the Generic (GNRC) network stack is available in the Modules
section above.
From the application layer the Generic (GNRC) network stack can be accessed through the Sock API, while the interface to the Netdev - Network Device Driver API is defined by the Network interface API.
Each layer of the network stack runs in its own thread and each lower layer thread has a higher priority than any upper layer thread. In this regard, the thread of the MAC layer implementation has the highest priority and threads on the application layer have the lowest priority. The communication between threads is handled by the kernel's Messaging / IPC functionality and by the GNRC communication interface. Most of the times IPC will take place between threads of neighboring layers for packets that traverse the network stack up or down.
Due to the design of GNRC and the nature of inter-process communication, it is crucial for a new module that introduces a new thread to follow a certain programming construct if it desires to interact with other threads without blocking the system: Utilizing an event loop
.
Hence, a thread for GNRC will usually consist of four basic steps.
Packets can be received or transmitted by interacting with the GNRC communication interface.
The reception of a Packet from another thread is handled by the GNRC communication interface module. In order to receive a Packet of a specific type, it is necessary to register for the appropriate Protocol type first. Your thread will then be able to receive certain commands defined in the GNRC communication interface module (e.g. net_gnrc_netapi::GNRC_NETAPI_MSG_TYPE_RCV) for all Packets that your thread registered for.
The following example will sketch how to receive incoming and outgoing UDP traffic on port 80.
A packet is transmitted by relaying it to threads interested in handling (and dispatching) packets of its type. To do this, the GNRC communication interface offers dispatch helper functions called gnrc_netapi_dispatch_send() and gnrc_netapi_dispatch_receive().
The following example sketches the usage and assumes a valid Packet named pkt
.
First, the data to be sent is added to the packet buffer. This ensures its intactness during the sending process. After the data to be sent has been added to the packet buffer, its parent data structure can safely be freed or re-used.
Then, the pkt will be sent to all threads that registered for GNRC_NETTYPE_UDP and the demux context 80
. Every registered thread will receive a GNRC_NETAPI_MSG_TYPE_SND command and can access the Packet. Note that at this point, the threads receiving pkt act as its owners, so please don't modify pkt after calling any dispatch function.
If gnrc_netapi_dispatch_send() is replaced by gnrc_netapi_dispatch_receive() then threads will receive the GNRC_NETAPI_MSG_TYPE_RCV command instead, again with access to the Packet.
Generic (GNRC) network stack is highly modular and can be adjusted to include only the desired features. In the following several of the available modules will be stated that you can include in your application's Makefile.
You may choose to build either as an IPv6 Node
or as an IPv6 Router
An IPv6 Router can forward packets, while an IPv6 Node will simply drop packets not targeted to it. If an IEEE 802.15.4 network device is present 6LoWPAN (with 6LoWPAN Fragmentation and IPv6 header compression (IPHC)) will be included automatically.
For basic IPv6 (and 6LoWPAN) functionalities choose instead
or
respectively. Those modules provide the bare minimum of IPv6 functionalities (no ICMPv6). Because of that, the Neighbor Information Base for IPv6 needs to be configured manually. If an IEEE 802.15.4 device is present 6LoWPAN will be included automatically, but no fragmentation or header compression support will be provided.
To include the RPL module
This will include the RPL module. To provide forwarding capabilities it is necessary to build the application with gnrc_ipv6_router_default
(or gnrc_ipv6_router
), not gnrc_ipv6_default
(or gnrc_ipv6
).
Modules | |
6LoWPAN | |
GNRC's 6LoWPAN implementation. | |
Common MAC module | |
A MAC module for providing common MAC parameters and helper functions. | |
Dump Network Packets | |
Dump network packets to STDOUT for debugging. | |
Error reporting | |
Allows for asynchronous error reporting in the network stack. | |
GNRC LoRaWAN | |
GNRC LoRaWAN stack implementation. | |
GNRC communication interface | |
Generic interface for IPC communication between GNRC modules. | |
GNRC-specific implementation of the sock API | |
Provides an implementation of the Sock API by the Generic (GNRC) network stack. | |
GoMacH | |
A traffic-adaptive multi-channel MAC. | |
IPv6 | |
GNRC's IPv6 implementation. | |
LWMAC | |
A Lightweight duty-cycling 802.15.4 MAC protocol. | |
Network interface API | |
Abstraction layer for GNRC's network interfaces. | |
Network protocol registry | |
Registry to receive messages of a specified protocol type by GNRC. | |
Packet buffer | |
A global network packet buffer. | |
Packet queue | |
gnrc_pktsnip_t queue | |
Priority packet queue for GNRC | |
Wrapper for priority_queue that holds gnrc_pktsnip_t*. | |
Protocol type | |
Protocol type definitions and helper functions. | |
RPL | |
RPL implementation for GNRC. | |
TCP | |
RIOT's TCP implementation for the GNRC network stack. | |
UDP | |
GNRC's implementation of the UDP protocol. | |
Files | |
file | gnrc.h |
Includes all essential GNRC network stack base modules. | |