RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... ·...

74
RIOT Hands-on Tutorial Oleg Hahm

Transcript of RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... ·...

Page 1: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT Hands-on Tutorial

Oleg Hahm

Page 2: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Starting the RIOT

Page 3: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Preparations

For links go to https://github.com/RIOT-OS/TutorialsQuick Setup (Using a Virtual Machine)

▶ Install and set up git▶ Install VirtualBox & VirtualBox Extension Pack▶ Install Vagrant▶ git clone --recursive https://github.com/RIOT-OS/Tutorials▶ Go to RIOT root directory: cd Tutorials/RIOT▶ Run the Vagrant RIOT Setup▶ Make sure you’ve run vagrant ssh and clone the Tutorials folder again, now in your virtual machine: git

clone --recursive https://github.com/RIOT-OS/Tutorials

Recommended Setup (Without Using a VM)

▶ Install and set up git▶ Install the build-essential packet (make, gcc etc.). This varies based on the operating system in use.▶ Install Native dependencies▶ Install OpenOCD▶ Install GCC Arm Embedded Toolchain▶ On OS X: install Tuntap for OS X▶ additional tweaks necessary to work with the targeted hardware (ATSAMR21)▶ Install netcat with IPv6 support (if necessary)

sudo apt-get install netcat-openbsd▶ git clone --recursive https://github.com/RIOT-OS/Tutorials▶ Go to the Tutorials directory: cd Tutorials

Page 4: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Running RIOT

▶ Applications in RIOT consist at minimum of▶ a Makefile▶ a C-file, containing a main() function

▶ To see the code go to the task-01 directory:

cd task-01ls

Page 5: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Your first application – The Makefile# name of your applicationAPPLICATION = Task01

# If no BOARD is found in the environment, use this default:BOARD ?= native

# This has to be the absolute path to the RIOT base directory:RIOTBASE ?= $(CURDIR)/../../RIOT

# Comment this out to disable code in RIOT that does safety checking# which is not needed in a production environment but helps in the# development process:CFLAGS += -DDEVELHELP

# Change this to 0 show compiler invocation lines by default:QUIET ?= 1

# Modules to include:USEMODULE += shellUSEMODULE += shell_commandsUSEMODULE += ps

include $(RIOTBASE)/Makefile.include

Page 6: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Your first application – The C-file

#include <stdio.h>#include <string.h>

#include "shell.h"

int main(void){

puts("This is Task-01");

char line_buf[SHELL_DEFAULT_BUFSIZE];shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);

return 0;}

Page 7: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 1.1: Run your first application as Linux process

1. Compile & run on native: make all term2. Type help3. Type ps4. Modify your application:

▶ Add a printf("This application runs on %s",RIOT_BOARD); before shell_run()

▶ Recompile and restart make all term▶ Look at the result

Page 8: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 1.2: Run your first application on real hardware

1. Compile, flash and run on samr21-xproBOARD=samr21-xpro make all flash term(or other BOARD if available)

2. Verify output of RIOT_BOARD

Page 9: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Custom shell commands

Page 10: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Writing a shell handler

▶ Shell command handlers in RIOT are functions with signature

int cmd_handler(int argc, char **argv);

▶ argv: array of strings of arguments to the command

print hello world # argv == {"print", "hello", "world"}

▶ argc: length of argv

Page 11: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Adding a shell handler to the shell

▶ Shell commands need to be added manually to the shell oninitialization

#include "shell.h"

static const shell_command_t shell_commands[] = {{ "command name", "command description", cmd_handler },{ NULL, NULL, NULL }

};

/* ... */shell_run(commands, line_buf, SHELL_DEFAULT_BUFSIZE)

/* ... */

Page 12: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 2.1 – A simple echo command handler

▶ Go to task-02 directory (cd ../task-02)▶ Write a simple echo command handler in main.c:

▶ First argument to the echo command handler shall be printedto output

> echo "Hello World"Hello World> echo foobarfoobar

Page 13: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 2.2 – Control the hardware

▶ board.h defines a macro LED0_TOGGLE to toggle the primaryLED on the board.

▶ Write a command handler toggle in main.c that toggles theprimary LED on the board

Page 14: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Multithreading

Page 15: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Threads in RIOT

▶ Threads in RIOT are functions with signature

void *thread_handler(void *arg);

▶ Use thread_create() from thread.h to start:

pid = thread_create(stack, sizeof(stack),THREAD_PRIORITY_MAIN - 1,THREAD_CREATE_STACKTEST,thread_handler,NULL, "thread");

Page 16: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT kernel primer

Scheduler:▶ Tick-less scheduling policy (O(1)):

▶ Highest priority thread runs until finished or blocked▶ ISR can preempt any thread at all time▶ If all threads are blocked or finished:

▶ Special IDLE thread is run▶ Goes into low-power mode

IPC (not important for the following task):▶ Synchronous (default) and asynchronous (optional, by IPC

queue initialization)

Page 17: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 3.1 – Start a thread

▶ Go to task-03 directory (cd ../task-03)▶ Open main.c▶ Reminder:

pid = thread_create(stack, sizeof(stack),THREAD_PRIORITY_MAIN - 1,THREAD_CREATE_STACKTEST,thread_handler,NULL, "thread");

▶ Start the thread "thread" from within main()▶ Run the application on native: make all term▶ Check your output, it should read: I'm in "thread" now

Page 18: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Timers

Page 19: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

xtimer primer

▶ xtimer is the high level API of RIOT to multiplex hardwaretimers

▶ Examples for functionality:▶ xtimer_now() to get current system time in microseconds▶ xtimer_sleep(sec) to sleep sec seconds▶ xtimer_usleep(usec) to sleep usec microseconds

Page 20: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 4.1 – Use xtimer

▶ Reminder: Functions xtimer_now(), xtimer_sleep(), andxtimer_usleep() were introduced

▶ Go to task-04 directory (cd ../task-04)▶ Note the inclusion of xtimer in Makefile

USEMODULE += xtimer

▶ Create a thread in main.c that prints the current system timeevery 2 seconds

▶ Check the existence of the thread with ps shell command

Page 21: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

General networking architecture

Page 22: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT’s Networking architecture

▶ Designed to integrate any network stack into RIOT

Application / Library

conn

Network stack

Hardware

netdev

Driver

netdev

Driver

netdev

Driver

Page 23: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT’s Networking architecture

▶ Designed to integrate any network stack into RIOT

Hardware

netdev

Driver

netdev

Driver

netdev

Driver

Page 24: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Including the network device driver

▶ Go to task-05 directory (cd ../task-05)▶ Note inclusion of netdev modules in Makefile

USEMODULE += gnrc_netdev_defaultUSEMODULE += auto_init_gnrc_netif

Page 25: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Virtual network interface on native

▶ Use tapsetup script in RIOT repository:

./../RIOT/dist/tools/tapsetup/tapsetup -c 2

▶ Creates▶ Two TAP interfaces tap0 and tap1 and▶ A bridge between them (tapbr0 on Linux, bridge0 on OSX)

▶ Check with ifconfig or ip link!

Page 26: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Setting up your IoT-LAB account▶ Go to https://www.iot-lab.info/testbed/ and login

with the provided credentials▶ Open “Edit My Profile” in the upper right corner:

▶ Copy/paste your ssh key (you have to generate one first:ssh-keygen)

▶ Authenticate for CLI access with make iotlab-auth usingthe provided credentials

Page 27: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 5.1 – Your first networking application

▶ Run the application on native: PORT=tap0 make all term▶ Type help▶ Run a second instance with PORT=tap1 make term▶ Type ifconfig on both to get hardware address and interface

number▶ Use txtsnd command to exchange messages between the two

instances

Page 28: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 5.2 – Use your application on real hardware

▶ Compile, flash, and run on the board BOARD=samr21-xpromake all flash term

▶ Type ifconfig to get your hardware addresses▶ Use txtsnd to send one of your neighbors a friendly message

Page 29: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 5.3 – Use your application in the testbed

▶ Compile for the board BOARD=iotlab-m3 make all▶ Create an experiment and connect to the nodes:

IOTLAB_DURATION=60 IOTLAB_NODES=2 \IOTLAB_SITE=lille BOARD=iotlab-m3 \make iotlab-exp iotlab-term

▶ Find out which nodes you have (either via web inter or bytyping any command)

▶ Send commands to one node by using a corresponding prefix:m3-16;ifconfig

Page 30: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT’s Networking architecture

Application / Library

conn

Network stack

Hardware

netdev

Driver

netdev

Driver

netdev

Driver

Page 31: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT’s Networking architecture

Application / Library

conn

Page 32: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

conn

▶ collection of unified connectivity APIs to the transport layer▶ What’s the problem with POSIX sockets?

▶ too generic for most use-cases▶ numerical file descriptors (internal storage of state required)▶ in general: too complex for usage, too complex for porting

▶ protocol-specific APIs:▶ conn_ip (raw IP)▶ conn_udp (UDP)▶ conn_tcp (TCP)▶ …

▶ both IPv4 and IPv6 supported

Page 33: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 6.1 – Use UDP for messaging

▶ Go to task-06 directory cd ../task-06▶ Note the addition of gnrc_conn_udp to Makefile▶ udp.c utilizes conn_udp_sendto() and

conn_udp_recvfrom() to exchange UDP packets▶ Compile and run on two native instances▶ Type help▶ Use udps 8888 to start a UDP server on port 8888 on first

instance (check with ps)▶ Use ifconfig to get link-local IPv6 address of first instance▶ Send UDP packet from second instance using udp command

to first instance

Page 34: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 6.2 – Communicate with Linux

▶ Compile and run a native instance▶ Start a UDP server on port 8888 (using udps)▶ Send a packet to RIOT from Linux using netcat

echo "hello" | nc -6u <RIOT-IPv6-addr>%tap0 8888

▶ Start a UDP server on Linux nc -6lu 8888▶ Send a UDP packet from RIOT to Linux

udp <tap0-IPv6-addr> 8888 hello

Page 35: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 6.3 – Exchange UDP packets with your neighbors

▶ Compile, flash and run on the board BOARD=samr21-xpromake all flash term

▶ Send and receive UDP messages to and from your neighborsusing udp and udps

Page 36: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

GNRC

Page 37: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

The components of GNRCLegend:

ThreadModuleAPI

Application / Library

gnrc_connconn

netapi netapi

gnrc_udp

netapi

gnrc_tcp

netapi

netapi

netapi

gnrc_ipv6

Hardware

IntegratedDeviceDriver

netapi

netapi

gnrc_6lo

netapi

MAC

netdev

Driver

MAC

netdev

Driver

Page 38: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

netapi▶ Inter-modular API utilizing IPC▶ Two asynchronous message types (don’t expect reply) for data

transfer:▶ GNRC_NETAPI_MSG_TYPE_SND: pass “down” the stack (send)▶ GNRC_NETAPI_MSG_TYPE_RCV: pass “up” the stack (receive)

▶ Two synchronous message types (expect reply) for optionhandling:

▶ GNRC_NETAPI_MSG_TYPE_GET: get option value▶ GNRC_NETAPI_MSG_TYPE_SET: set option value

▶ Specification deliberately vague⇒ implementations can make own preconditions on data

netapi

UDPIPv66LoWPANMAC + drive

Page 39: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Network interfaces in GNRC (1)Legend:

ThreadModuleAPI

Application / Library

gnrc_connconn

netapi netapi

gnrc_udp

netapi

gnrc_tcp

netapi

netapi

netapi

gnrc_ipv6

Hardware

IntegratedDeviceDriver

netapi

netapi

gnrc_6lo

netapi

MAC

netdev

Driver

MAC

netdev

Driver

Page 40: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Network interfaces in GNRC (1)Legend:

ThreadModuleAPI

Application / Library

gnrc_connconn

netapi netapi

gnrc_udp

netapi

gnrc_tcp

netapi

netapi

netapi

gnrc_ipv6

Hardware

IntegratedDeviceDriver

netapi

netapi

gnrc_6lo

netapi

MAC

netdev

Driver

MAC

netdev

Driver

Page 41: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Network interfaces in GNRC (2)

▶ netapi-capable thread as any other protocol implementation▶ Implement MAC protocol▶ Communication to driver via netdev

⇐ timing requirements for e.g. TDMA-based MAC protocols

Hardware

netapi

MAC

netdev

Driver

Page 42: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

netreg

▶ How to know where to send netapi messages?

▶ Both protocol implementation and users can register to beinterested in type + certain context (e.g. port in UDP)

gnrc_netreg_entry_t ipv6_handler = { NULL,GNRC_NETREG_DEMUX_CTX_ALL,ipv6_handler_pid};

gnrc_netreg_register(GNRC_NETTYPE_IPV6, &ipv6_handler);

gnrc_netreg_entry_t dns_handler = { NULL, PORT_DNS,dns_handler_pid};

gnrc_netreg_register(GNRC_NETTYPE_UDP, &dns_handler);

⇒ Find handler for packets in registry

Page 43: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

netreg

▶ How to know where to send netapi messages?▶ Both protocol implementation and users can register to be

interested in type + certain context (e.g. port in UDP)

gnrc_netreg_entry_t ipv6_handler = { NULL,GNRC_NETREG_DEMUX_CTX_ALL,ipv6_handler_pid};

gnrc_netreg_register(GNRC_NETTYPE_IPV6, &ipv6_handler);

gnrc_netreg_entry_t dns_handler = { NULL, PORT_DNS,dns_handler_pid};

gnrc_netreg_register(GNRC_NETTYPE_UDP, &dns_handler);

⇒ Find handler for packets in registry

Page 44: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

pktbuf▶ Data packet stored in pktbuf▶ Representation: list of variable-length “packet snips”▶ Protocols can mark sections of data to create new snip▶ Keeping track of referencing threads: reference counter users

▶ If users == 0: packet removed from packet buffer▶ If users > 1 and write access requested: packet duplicated

(copy-on-write)

IPv6 headerdata

nextdata

lengthtypeusers

UDP headerdata

nextdata

lengthtypeusers

nextdata

lengthtypeusers

UDPpayload

datapacket

snipescriptor

Page 45: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

pktbuf – keeping duplication minimal▶ Only copy up to most current packet snip

⇒ Packets become tree-like⇒ Reverse order for received packets to only have one pointer

Packet in transmission

netif header

users = 1next

netif header

users = 1next

6Lo header

users = 1next

IPv6 header

users = 1next

ICMPv6 header

users = 2next

ICMPv6 payload

users = 2

Packet in reception

UDP payload

users = 1next

UDP payload

users = 1next

UDP header

users = 2next

IPv6 header

users = 2next

netif header

users = 2

data data data data

data data data

data data

data data

Page 46: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

RIOT examples

The remaining slides utilize the RIOT examples:cd ../RIOT/examples/ls

Page 47: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_minimal example (native)▶ * = name might be subject to change

gnrc_ipv6NDP[host]

Hardware

netapi

gnrc_netdevgnrc_netdev_eth

netdev

netdev2_tap

USEMODULE += gnrc_ipv6USEMODULE += gnrc_ndp_host*

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 48: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_minimal example (samr21-xpro)▶ * name might be subject to change

gnrc_ipv66Lo-ND[6LN]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += gnrc_ipv6USEMODULE += gnrc_sixlowpan_nd*

USEMODULE += gnrc_sixlowpanUSEMODULE += gnrc_sixlowpan_fragUSEMODULE += gnrc_sixlowpan_iphc

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 49: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Some short-cuts (Makefile.dep)

Pseudo-module dependencies▶ gnrc_sixlowpan_default:

▶ gnrc_sixlowpan▶ gnrc_sixlowpan_frag▶ gnrc_sixlowpan_iphc

▶ gnrc_ipv6_default:▶ gnrc_ipv6▶ gnrc_ndp_host (if non-6Lo interface present)▶ gnrc_sixlowpan_default (if 6Lo interface present)▶ gnrc_sixlowpan_nd (if 6Lo interface present)

Page 50: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_minimal example (native)▶ * = name might be subject to change

gnrc_ipv6NDP[host]

Hardware

netapi

gnrc_netdevgnrc_netdev_eth

netdev

netdev2_tap

USEMODULE += gnrc_ipv6_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 51: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_minimal example (samr21-xpro)▶ * = name might be subject to change

gnrc_ipv66Lo-ND[6LN]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += gnrc_ipv6_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 52: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 7.1 – Compile the gnrc_minimial application

▶ Go to the gnrc_minimal application (cd gnrc_minimal)▶ Compile and run on native▶ Should print something like My address is

fe80::d403:24ff:fe89:2460▶ Ping RIOT instance from Linux:

ping6 <RIOT-IPv6-addr>%tap0

Page 53: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_minimal example (samr21-xpro)▶ Adding a simple application▶ * = name might be subject to change

Application / Library

netapi

gnrc_ipv66Lo-ND[6LN]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

gnrc_netreg_t app = {NULL, PROTNUM_NONXT,

sched_active_pid};

gnrc_netreg_register(GNRC_NETTYPE_IPV6,

&app);

USEMODULE += gnrc_ipv6_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 54: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 7.2 – Extend gnrc_minimal application

▶ Add the gnrc_udp module to the application▶ Register for UDP packets of port 8888

/* include "sched.h", "net/gnrc/netreg.h", and "net/gnrc/pktbuf.h"! */unsigned int count = 0; msg_t msg;gnrc_netreg_t server = {NULL, 8888, sched_active_pid};gnrc_netreg_register(GNRC_NETTYPE_UDP, &app);

while (1) {gnrc_pktsnip_t *pkt;msg_receive(&msg);pkt = (gnrc_pktsnip_t *)msg.content.ptr;printf("Received %u UDP packets\n", ++count);gnrc_pktbuf_release(pkt);

}

▶ Compile and run on native▶ Send UDP packet to RIOT node using netcat

echo "hello" | nc -6u <RIOT-IPv6-addr>%tap0 8888

Page 55: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 8.1: Generate content and discover other content

▶ You can use the shell commands above to create somecontent chunks and send out interests for a specific name

▶ Create some content for /dagstuhl/m2m/▶ Send an interest for /dagstuhl/m2m/

Page 56: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 8.2: Modify the default shell commands

▶ Take a look at the default shell commands insys/shell/commands/sc_ccnl.c

▶ Create a new command to send an interest with a shortertimeout (seehttp://doc.riot-os.org/group__pkg__ccnlite.html

▶ Use ccnl_set_local_producer() to create content on thefly

Page 57: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_networking example (native)▶ * = name might be subject to change

Application / Library

netapi

netapignrc_udp

netapignrc_ipv6NDP[router]

Hardware

netapi

gnrc_netdevgnrc_netdev_eth

netdev

netdev2_tap

USEMODULE += shell_commands

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_routerUSEMODULE += gnrc_ndp_router*

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 58: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_networking example (samr21-xpro)▶ * = name might be subject to change

Application / Library

netapi

netapignrc_udp

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += shell_commands

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_routerUSEMODULE += gnrc_sixlowpan_nd_router*

USEMODULE += gnrc_sixlowpan_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 59: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

More short-cuts (Makefile.dep)

Pseudo-module dependencies▶ gnrc_ipv6_router_default:

▶ gnrc_ipv6▶ gnrc_ndp_router (if non-6Lo interface present)▶ gnrc_sixlowpan_default (if 6Lo interface present)▶ gnrc_sixlowpan_nd_router (if 6Lo interface present)

Page 60: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_networking example (native)▶ * = name might be subject to change

Application / Library

netapi

netapignrc_udp

netapignrc_ipv6NDP[router]

Hardware

netapi

gnrc_netdevgnrc_netdev_eth

netdev

netdev2_tap

USEMODULE += shell_commands

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 61: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_networking example (samr21-xpro)▶ * = name might be subject to change

Application / Library

netapi

netapignrc_udp

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += shell_commands

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 62: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Task 7.3 – Send your neighbor some messages again

▶ Go to gnrc_networking example: cd ../gnrc_networking▶ Have a look in udp.c how packets are constructed and send▶ Compile, flash, and run on the board BOARD=samr21-xpro

make all flash term▶ Type help▶ Start UDP server on port 8888 using udp server 8888▶ Get your IPv6 address using ifconfig▶ Send your neighbor some messages using udp send

Page 63: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_tftp example▶ for simplicity only the samr21-xpro examples from now on▶ * = name might be subject to change

Application / Library

gnrc_tftp

netapi

gnrc_udp

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += gnrc_tftp

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 64: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Make your application stack independent▶ * = name might be subject to change

Application / Library

gnrc_connconn

netapi

netapignrc_udp

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += gnrc_conn_udpUSEMODULE += gnrc_conn_ip

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 65: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

microcoap example▶ * = name might be subject to change

Application / Librarymicrocoap

gnrc_connconn

netapi

gnrc_udp

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEPKG += microcoap

USEMODULE += gnrc_conn_udp

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 66: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

posix_sockets example▶ * = name might be subject to change

Application / Libraryposix_sockets

gnrc_connconn

netapi

gnrc_udp

netapignrc_ipv66Lo-ND[6LN]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEMODULE += posix_sockets

USEMODULE += gnrc_conn_udp

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 67: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

lwIP instead of GNRC▶ * = name might differ on other devices

Application / Library

lwip_connconn

lwIP

Hardware

lwip_netdev

netdev

at86rf2xx

USEMODULE += lwip_conn_tcpUSEMODULE += lwip_conn_udpUSEMODULE += lwip_conn_ip

USEMODULE += lwip_tcpUSEMODULE += lwip_udpUSEMODULE += lwip_ipv6USEMODULE += lwip_ipv6_autoconfigUSEMODULE += lwip_ipv6_mldUSEMODULE += lwip_sixlowpan

USEMODULE += lwip_netdev

USEMODULE += at86rf233*

Page 68: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

emb6 (uIP-fork) instead of GNRC▶ * = name might differ on other devices

Application / Library

emb6_connconn

emb6

Hardware

emb6_netdev

netdev

at86rf2xx

USEMODULE += emb6_conn_udp

USEMODULE += emb6_router

USEMODULE += emb6_netdev

USEMODULE += at86rf233*

Page 69: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

ccn_lite_relay example▶ * = name might be subject to change

Application / Library

netapi

ccn_lite

Hardware

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEPKG += ccn-lite

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 70: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

CCN-lite over UDP example▶ * = name might be subject to change

Application / Library

ccn_lite

netapi

gnrc_udp

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEPKG += ccn_lite

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 71: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

CCN-lite over IPv6 example▶ * = name might be subject to change

Application / Library

netapi

ccn_lite

netapignrc_ipv66Lo-ND[6LR]

Hardware

netapi

gnrc_sixlowpan

netapignrc_netdev

gnrc_netdev_ieee802154

netdev

at86rf2xx

USEPKG += ccn_lite

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 72: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Example: multiple radios of the same type▶ * = name might be subject to change

Application / Library

gnrc_connconn

netapi

netapignrc_udp

netapignrc_ipv6

6Lo-ND[6LR] 6Lo-ND[6LR]

Hardware

netapi netapi

gnrc_sixlowpan

netapi netapignrc_netdev

gnrc_netdev_ieee…

netdev

at86rf2xx

gnrc_netdevgnrc_netdev_ieee…

netdev

USEMODULE += gnrc_conn_udpUSEMODULE += gnrc_conn_ip

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_default

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 73: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

gnrc_border_router example▶ * = name might be subject to change

Application / Library

gnrc_uhcpd

netapinetapi

netapignrc_udp

netapignrc_ipv6

NDP[router] 6Lo-ND[6LBR]

Hardware

netapi

netapi

gnrc_sixlowpan

netapignrc_netdevgnrc_netdev_eth

netdev

ethos

gnrc_netdevgnrc_netdev_ieee…

netdev

at86rf2xx

USEMODULE += shell_commands

USEMODULE += gnrc_uhcpd

USEMODULE += gnrc_udp

USEMODULE += gnrc_ipv6_router_defaultUSEMODULE += gnrc_sixlowpan_nd_border_router*

USEMODULE += auto_init_gnrc_netdev*

USEMODULE += gnrc_netdev_default*

Page 74: RIOT Hands-on Tutorial - Dagstuhlmaterials.dagstuhl.de/files/16/16353/16353.OliverHahm... · 2016-09-02 · Task 5.3 – Use your application in the testbed Compile for the board

Now go out and make something!