Linux RPL router

2014/11/16

Recently there have been huge developments in Linux 6LoWPAN support. Old linux-zigbee was renamed to more appropriate linux-wpan. Openlabs released an excellent tutorial on running 6LoWPAN on RaspberryPi. With it you can get running 6LoWPAN Border Router, even if you never compiled Linux kernel before. Openlabs also released 802.15.4 module for RaspberryPi - it is very reasonably priced, works as advertised, and is currently best choice to quickly start development. Delivery with USPS seems fast too (12 days to Poland, Europe in my case).

Following my previous experiments with Grinch Border Router, I decided to try to take it one step further, and run RPL routing protocol on top of RaspberryPi with 6LoWPAN. My results below.

Linux branch

Following Openlabs advice, I decided to go with linux-wpan-next branch. I had one problem running this branch on RaspberryPi - Ethernet stopped working. I found solution on elinux.org - the bug was caused by missing USB config directives in kernel. Take extra care to enable both CONFIG_USB_DWC2_HOST and CONFIG_USB_DWC2_PLATFORM in your kernel config.

Fixing RPL implementation

After checking the Internet for existing Linux RPL implementations, I found three feasible candidates:

After preliminary testing, I decided to go with linux-rpl, as it is a kernelspace implementation. Repository for linux-rpl contains code in a form of huge patches for Linux kernel 3.10, 3.11 and 3.12. After a few unsuccessful atempts to merge them I ported the 3.12 patch into linux-wpan-next branch manually. I left out patches related to XBee. My patched branch is available on Github.

To run RPL you should clone the test branch and then basically follow Openlabs tutorial:

  1. Run make menuconfig and enable proper kernel options (remember to enable CONFIG_IPV6_RPL and CONFIG_IPV6_RPL_OF_OF0 and USB options mentioned above)

  2. Build patched kernel

  3. Patch the device tree to add AT86RF233 transceiver and rebuild .dtb file

  4. Build U-Boot

  5. Move kernel, device tree file and U-Boot to the SD card with new Raspbian installation

  6. Boot up Raspberry and log-in using SSH (or keyboard/screen)

  7. Build userspace lowpan tools

  8. Configure wpan0 and lowpan0 interfaces

The steps above should give you working RaspberryPi with eth0 and lowpan0 interfaces.

Running RPL

First thing to do is to compile RPL userspace tools. Then you can enable RPL on chosen interface: for example lowpan0. You can run your RPi as a non-root RPL router. It will then search for a DODAG to join. To do that issue command:

sudo rpl-ctl enable lowpan0

You can also use sysctl:

sudo sysctl -w net.ipv6.conf.lowpan0.rpl_enabled=1

In most cases you will want your RPi to be DODAG root (it is useful when you plan to use your RPi to be a border router). As a DODAG root, your RPi will distribute address prefix for other RPL routers. To do that issue commands:

sudo sysctl -w net.ipv6.conf.lowpan0.rpl_dodag_root=1
sudo sysctl -w net.ipv6.conf.lowpan0.rpl_enabled=1

After that your RaspberryPi is be ready to communicate with RPL nodes. If you want to use your RPi as a Border Router there are other steps to take: enabling IPv6 forwarding, configuring IP address on eth0 interface, running radvd on eth0 interface, etc.

Communication with Contiki nodes

To determine which links should be used as a first choice, RPL protocol uses objective function (OF). All RPL nodes in a DODAG must use the same OF. The most basic objective function is OF0, and it is the only OF supported currently by Linux. Contiki OS 2.7 uses MRHOF objective function by default, but it supports OF0 too. To achieve communication between RaspberryPi with RPL, and Contiki, you need to compile Contiki with RPL using OF0 function. To do that add following line in your platform contiki-conf.h file:

#define RPL_CONF_OF rpl_of0

Remove other OF definitions if present. With this modification, your Contiki nodes should join DODAG formed by RaspberryPi.

Possible issues

I haven’t throughly tested this setup, so bugs can be expected. Few remarks:

  1. (Edit: 01 Feb 2015) Multihop doesn’t work - probable cause is lack of hop-by-hop RPL option support

  2. RPL userspace tools info commands (for example rpl-ctl list-neighbors) usually return nothing, it might be a bug

  3. I noticed nodes are slow to rejoin DODAG after restart.

Further tests are necessary.

Conclusions

RPL for Linux is usable. Joao Pedro Taveira’s implementation seems to work with Linux 3.17 and 6LoWPAN (after minimal patching). Linux box is a superior solution for Border Router than any embedded system (like my previous Grinch router). It would be nice to see it merged to mainline kernel one day.