Skip to content

How to: Slip border router with Raspberry Pi and samr21 xpro

AppleInside edited this page Jun 6, 2016 · 10 revisions

Raspberry Pi Slip Border Router

This howto explains the steps needed, to setup a RaspberryPi together with a RIOT node connected via slip as a border router.

Though this tutorial uses a Raspberry Pi and a samr21-xpro, it should also work with any other computer running Linux and with any other RIOT node that has networking support.

NOTE: This howto expects, that your PI has direct IPv6 connectivity via Wifi/Ethernet for your connected RIOT network to be able to connect to the outside world (for enabling the ipv6 on Rpi there are a lot of tutorials). If this is not the case, you can configure the Pi to use some kind of IPv6 Tunnel, e.g. have a look here.

For further informations about the example gnrc_border_router visit this [page] (https://github.com/RIOT-OS/RIOT/blob/master/examples/gnrc_border_router/README.md).

Prerequisites

Hardware used

  • Raspberry Pi running Raspian
  • Atmel samr21-xpro
  • USB-to-serial converter
  • Clone RIOT git repo on your pi

Before we start

  • checkout RIOT on the Pi (we need the dist/tools/tunslip/tunslip6.sh script and pyterm)
  • build and flash the border router application examples/gnrc_border_router to the samr21-xpro as explained here
  • connect the USB-to-serial Adapter to the second UART on the samr21-xpro. the pin mapping is
SAM  <->  Converter
GND   -    GND
PA22  -    RX
PA23  -    TX
  • connect both the USB-to-serial converter and the samr21-xpro's USB to the Raspberry Pi

You should now be able to interact with the RIOT shell on the samr21-xpro through /dev/ttyACM0, while the external converter for the second UART should be accessible through /dev/ttyUSB0

  • next we need to enable IPv6 forwarding on the Raspberry Pi. For this we edit the file /etc/sysctl.conf and uncomment the line
net.ipv6.conf.all.forwarding=1

Run the border router

On the Pi

On the pi, we need to run tunslip6 script to set up the TUN device that receives network traffic through the slip interface. This is done by simply calling the tunslip6 script provided by RIOT (the examples expects the script to be in the PATH variable...):

NOTE: if tunslip6 is not compiled yet, go to RIOT/dist/tool and send make command:

riot@pi~ $ make

run the tunslip6 script now

riot@pi:~ $ sudo ./tunslip6 2001:470:53f9::99/48 -t tun0 -s /dev/ttyUSB0

The used IP address (2001:470:53f9::99) should be using your global IPv6 prefix as assigned by your router/ISP/whatever.

Now you should be able to see the tun device, so ip a should list the tun device:

6: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500
    link/none 
    inet 127.0.1.1/32 scope host tun0
       valid_lft forever preferred_lft forever
    inet6 affe::1/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::470:53f9:0:99/64 scope link 
       valid_lft forever preferred_lft forever`

Next step is to control the routes on your Pi. You can list the configured routes with ip -6 r. Here you need to make sure, that traffic with the destination of your configured prefix is forwarded to you tun interfaces.

Example (broken):

2001:470:53f9::1 dev he-ipv6  metric 1024 
2001:470:53f9::/48 dev he-ipv6  proto kernel  metric 256 
2001:470:53f9::/48 dev tun0  proto kernel  metric 256 
fe80::/64 dev he-ipv6  proto kernel  metric 256 
fe80::/64 dev eth0  proto kernel  metric 256 
fe80::/64 dev tun0  proto kernel  metric 256 
default via 2001:470:53f9::1 dev he-ipv6  metric 1024 

Here, the 2. route is preventing packets addressed to your prefix to be routed to the tun interface. So to fix this, simply remove the 2. route with sudo ip r d 2001:470:53f9::/48. The routes should now look like this:

2001:470:53f9::1 dev he-ipv6  metric 1024 
2001:470:53f9::/48 dev tun0  proto kernel  metric 256 
fe80::/64 dev he-ipv6  proto kernel  metric 256 
fe80::/64 dev eth0  proto kernel  metric 256 
fe80::/64 dev tun0  proto kernel  metric 256 
default via 2001:470:53f9::1 dev he-ipv6  metric 1024 

Thats it for the configuration of the Pi.

Configure RIOT

Now its time to configure RIOT. For this connect to the RIOT shell using for example pyterm from your Pi (again: the example expects that pyterm is in your PATH):

NOTE : if you don't have pyterm in your path yet, you can find it in the RIOT distro.

 riot@pi~ $ cd RIOT/dist/tool/pyterm
 riot@pi~ $ sudo python setup.py install
 riot@pi~ $ sudo python ./pyterm

if the command above gives back : "ImportError: No module named serial" , you need to install the pySerial utility :

riot@pi~ $  pip install pyserial
riot@pi~ $ sudo python ./pyterm

Then you should be able to run the pyterm utility

riot@pi:~ $ pyterm -p /dev/ttyACM0

Now on the RIOT shell you have to assign the slip interface a global IPv6 address:

ifconfig 6 add 2001:470:53f9::99

Next we have to add the address of the tun device on the Linux side to RIOT's neighbor cache. This step is needed, as RIOT is not responding to neighbor solicitations on the tun device:

ncache add 6 2001:470:53f9::99

Now you should be able to ping the Pi from the RIOT node:

 > ping6 2001:470:53f9::99
12 bytes from 2001:470:53f9::99: id=90 seq=1 hop limit=64 time = 11.064 ms
12 bytes from 2001:470:53f9::99: id=90 seq=2 hop limit=64 time = 11.686 ms
12 bytes from 2001:470:53f9::99: id=90 seq=3 hop limit=64 time = 10.716 ms
--- 2001:470:53f9::99 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2.0653684 s
rtt min/avg/max = 10.716/11.155/11.686 ms

As final step, we have to configure the default route. Currently (pre 2015.12) the default route is broken in the FIB, so we set routes explicitly for hosts we want to interact with. For example, if you want to ping one of google's DNS servers, you can add a route to the FIB like this:

fibroute add 2001:4860:4860::8888 via 2001:470:53f9::99 dev 6

Now you should be able to ping the google server:

> ping6  2001:4860:4860::8888
12 bytes from 2001:4860:4860::8888: id=91 seq=1 hop limit=55 time = 311.510 ms
12 bytes from 2001:4860:4860::8888: id=91 seq=2 hop limit=55 time = 90.758 ms
12 bytes from 2001:4860:4860::8888: id=91 seq=3 hop limit=55 time = 84.017 ms
--- 2001:4860:4860::8888 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2.06507501 s
rtt min/avg/max = 84.017/162.095/311.510 ms

Voila, now you have a Raspberry Pi/RIOT border router running via slip, and your RIOT network should be able to talk to anyone in the great Internet.

Clone this wiki locally