Monday, June 2, 2014

Border Router with Raspberry Pi for LLN with TelosBs

This tutorial aims to create a IPv6 Low-power and Lossy Network (LLN) of TelosB motes with a Rapsberry Pi (RPi) as a border router (LBR) to connect to other IPv6 networks. RPi is configured for routing traffic from the LLN to other IPv6 networks by creating a TUN network interface. An alternative to setup a LLN is to configure a bridge (TAP) as in Cetic-6LBR (https://github.com/cetic/6lbr/)

We are going to have two IPv6 networks associated to two network interfaces of the LBR RPi as shown in Fig.1.

Fig.1: Deployment


LBR
- eth0: bbbb::1/64 (Physical Ethernet interface to normal IPv6 network)
- tun0: aaaa::1/64 (TUN interface to LLN)

IPv6 Network:
- bbbb::2

LLN:
- aaaa::212:7400:13cb:44 (slip-radio)
- aaaa::212:7400:13cb:101a
- aaaa::212:7400:13ca:f3ac

1. LLN Network (see here)

- Flash radio-slip mote (contiki-2.7/examples/ipv6/slip-radio) to use as an IEEE 802.15.4 interface
- Flash other TelosB for LLN nodes (e.g., contiki-2.7/examples/ipv6/udp-server)

2. IPv6 Network
- Configure a machine with bbbb::/64 address (example with a Linux)
# sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet6 static
address bbbb::2
netmask 64
gateway bbbb::100 (border router address)

(you may need to deactivate other network interfaces to check if it works properly)

3. RPi Border Router
Prepare RPi OS
- Download Raspbian

- Create a boot disk using SD card (>4G) using Win32 DiskImager
(Check here for Raspbian essentials)

- Plug radio-slip mote to RPi, recognized as /dev/ttyUSB0

- Enable IPv6 module?

# sudo modprobe ipv6
or to automatically enable it at boot, add ipv6 on a line at the end of /etc/modules.

- Enable IPv6 forwarding
# sudo sysctl -w net.ipv6.conf.all.forwarding=1

or edit /etc/sysctl.conf uncomment the line: net.ipv6.conf.all.forwarding=1

- Configure IPv6 address for eth0
# sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet6 static
address bbbb::1
netmask 64

- Download contiki-2.7 source
- Go to examples/ipv6/native-border-router
- Fix source and build 
# vi border-router.c, line 161: remove ; (contiki 2.7 bug)
# vi slip-config.c, line 76: change -1 to 255 (RPi kernel??)
# make

- Run border router
# sudo modprobe ipv6 (optional)
# sudo sysctl -w net.ipv6.conf.all.forwarding=1 (optional)
# sudo ./border-router.native -L -v6 aaaa::1/64 (debug, ttyUSB0, 115200)

Autostart the border-router.native by adding it to /etc/rc.local (optional)
path_to_border-router.native aaaa::1/64

ex: /home/pi/contiki-2.7/examples/ipv6/native-border-router/border-router.native aaaa::1/64 &

4. Test

From IPv6 network computer ping to LLN
Ping: ping6 aaaa::212:7400:13cb:101a
Web browser: aaaa::212:7400:13cb:44

5 comments:

  1. native border router doesn't work on RPi 2 modelB (the latest). Do you know why?
    I use the same hardware as for 6lbr (6lbr runs OK, but no good for me)
    the application starts and resets immediately. Any hints?
    Have the following output:
    root@raspberrypi:/temp/contiki/examples/ipv6/native-border-router# uname -a
    Linux raspberrypi 4.1.6-v7+ #810 SMP PREEMPT Tue Aug 18 15:32:12 BST 2015 armv7l GNU/Linux

    root@raspberrypi:/temp/contiki/examples/ipv6/native-border-router# sudo ./border -router.native -s ttyACM0 aaaa::1/64
    Contiki-3.x-1608-g93cd91f started with IPV6, RPL
    Rime started with address 1.2.3.4.5.6.7.8
    MAC nullmac RDC br-rdc NETWORK sicslowpan
    Tentative link-local IPv6 address fe80:0000:0000:0000:0302:0304:0506:0708
    RPL-Border router started
    usage: ./border-router.native [options] ipaddress
    example: border-router.native -L -v2 -s ttyUSB1 aaaa::1/64
    Options are:
    -B baudrate 9600,19200,38400,57600,115200,921600 (default 115200)
    -H Hardware CTS/RTS flow control (default disabled)
    -L Log output format (adds time stamps)
    -s siodev Serial device (default /dev/ttyUSB0)
    -a host Connect via TCP to server at
    -p port Connect via TCP to server at :
    -t tundev Name of interface (default tun0)
    -v[level] Verbosity level
    -v0 No messages
    -v1 Encapsulated SLIP debug messages (default)
    -v2 Printable strings after they are received
    -v3 Printable strings and SLIP packet notifications
    -v4 All printable characters as they are received
    -v5 All SLIP packets in hex
    -v Equivalent to -v3
    -d[basedelay] Minimum delay between outgoing SLIP packets.
    Actual delay is basedelay*(#6LowPAN fragments) milliseconds.
    -d is equivalent to -d10.
    root@raspberrypi:/temp/contiki/examples/ipv6/native-border-router#

    ReplyDelete
    Replies
    1. The border router seems to work properly. What do you mean by "doesn't work"? RP2 or any kind of hardware here doesn't matter, I believe. You can try it with a Linux desktop/laptop to see if the problem persists, then your issue should be something else.

      Delete
    2. Yes. it works on desktop PC under Ubuntu15.10VM, but not on Raspberry PI using the same SLIP radio. As you can see from the listing, the application returns immediately to command line after invoking.

      Delete
    3. My suggestion is to try line by line debugging for the native-border-router to see what's not going right with RP2, there might be something to do with RP2 kernel.

      You also can try an alternative way to set up the router, porting border-router functionality to the TelosB mote + tunslip in RP, as in here: http://thingschat.blogspot.fr/2014/02/quickstart-rpl-network-setup-with.html

      Delete
    4. Thanks,
      I missed this:
      # vi slip-config.c, line 76: change -1 to 255 (RPi kernel??)
      After that and rebuilding all works.
      Cheers

      Delete