Contiki-NG comes with rich network-stack features to allow communication with others. In this chapter, we will explore the available network features on the Contiki-NG platform. Several scenarios will be provided to enable practice with implementing projects-based Contiki-NG, either in physical motes or in mote simulations.
Networking in Contiki-NG
Contiki-NG still uses a traditional OSI (Open Systems Interconnection) stack to implement the Contiki-NG Network Protocol stack, called NETSTACK, to communicate among nodes. The Contiki-NG NETSTACK implements four layers, as follows:
Network layer (NETSTACK_NETWORK)
MAC layer (NETSTACK_MAC)
RDC (Radio Duty Cycling) layer (NETSTACK_RDC)
Radio layer (NETSTACK_RADIO)
The Network layer (NETSTACK_NETWORK) in an OSI layer can be represented as Application, Transport, Network, Routing, and Adaptation.
In NETSTACK implementation, Contiki-NG provides network libraries. We can find them in the <contiki-ng>/os/net folder. The following is several code-sample implementations for Contiki-NG NETSTACK:
Application layer: http-socket.c, websocket.c, websocket-http-client.c, and mqtt.c
Transport: udp-socket.c and tcp-socket.c
Network & Routing: uip6.c and rpl.c
MAC: mac.c and csma.c
The files can be obtained in the <contiki-ng>/os/net folder. Thus, we will get more knowledge about how Network project builds Contiki-NG system.
/* Routing protocol configuration. The Routing protocol is configured through the Makefile, via the flag MAKE_ROUTING */ #ifdef NETSTACK_CONF_ROUTING #define NETSTACK_ROUTING NETSTACK_CONF_ROUTING #else/* NETSTACK_CONF_ROUTING */ #if ROUTING_CONF_RPL_LITE #define NETSTACK_ROUTING rpl_lite_driver #elif ROUTING_CONF_RPL_CLASSIC #define NETSTACK_ROUTING rpl_classic_driver #elif ROUTING_CONF_NULLROUTING #define NETSTACK_ROUTING nullrouting_driver #else #error Unknown ROUTING configuration #endif #endif/* NETSTACK_CONF_ROUTING */
/* Network layer configuration. The NET layer is configured through the Makefile, via the flag MAKE_NET */ #ifdef NETSTACK_CONF_NETWORK #define NETSTACK_NETWORK NETSTACK_CONF_NETWORK #else/* NETSTACK_CONF_NETWORK */ #if NETSTACK_CONF_WITH_IPV6 #define NETSTACK_NETWORK sicslowpan_driver #elif NETSTACK_CONF_WITH_NULLNET #define NETSTACK_NETWORK nullnet_driver #else #error Unknown NET configuration #endif #endif/* NETSTACK_CONF_NETWORK */
/* MAC layer configuration. The MAC layer is configured through the Makefile, via the flag MAKE_MAC */ #ifdef NETSTACK_CONF_MAC #define NETSTACK_MAC NETSTACK_CONF_MAC #else/* NETSTACK_CONF_MAC */ #if MAC_CONF_WITH_NULLMAC #define NETSTACK_MAC nullmac_driver #elif MAC_CONF_WITH_CSMA #define NETSTACK_MAC csma_driver #elif MAC_CONF_WITH_TSCH #define NETSTACK_MAC tschmac_driver #elif MAC_CONF_WITH_BLE #define NETSTACK_MAC ble_l2cap_driver #else #error Unknown MAC configuration #endif #endif/* NETSTACK_CONF_MAC */
/* Radio driver configuration. Most often set by the platform. */ #ifdef NETSTACK_CONF_RADIO #define NETSTACK_RADIO NETSTACK_CONF_RADIO #else/* NETSTACK_CONF_RADIO */ #define NETSTACK_RADIO nullradio_driver #endif/* NETSTACK_CONF_RADIO */
/* Framer selection. The framer is used by the MAC implementation to build and parse frames. */ #ifdef NETSTACK_CONF_FRAMER #define NETSTACK_FRAMER NETSTACK_CONF_FRAMER #else/* NETSTACK_CONF_FRAMER */ #define NETSTACK_FRAMER framer_802154 #endif/* NETSTACK_CONF_FRAMER */
/* This function is intended for the IP stack to call whenever input/output callback needs to be called */ enum netstack_ip_action netstack_process_ip_callback(uint8_t type, constlinkaddr_t *localdest);