Contiki-6LOWPAN-BBB

From Texas Instruments Wiki
Jump to: navigation, search

BeableBone Black as 6LoWPAN Border Router.

This "out-of-the-box" guide will go through the process of deploying a BeagleBone Black as 6LoWPAN router and bridge 6LoWPAN devices to the IPv4/IPv6 Internet.

System overview

Requirements list

Hardware

  • A Windows XP, Windows 7 or Windows 8 PC (32-bit or 64-bit, x86 architecture)
  • Internet access
  • 1x BeableBone Black
  • 1x Network Cable (RJ-45)
  • 1x Mini-USB[M] to Standard-USB[M] cable [Included in box]
  • 1x SLIP-radio device (Ex. a CC2538EM)
  • (Optional) 1x 5V power adapter (500mA-1000mA should be sufficient)

Software

Deployment guide

Hardware setup

1. Unbox your BeagleBone Black [BBB]. The box should contain a BeagleBone Black development board, a USB cable and a "Quick-Start" card.
(1) BeagleBone Black Shipping Box
(1) Box contents
3. Connect the network cable to Ethernet port and the included mini-USB cable to the mini-USB port on the BBB. When this is done, connect the other end of the network cable to an available internet source, like a router or a switch. Connect the USB cable to your PC and continue to the next section.
(2+3) Connected network cable and mini-USB

Drivers

To be able to use the BBB from the PC correctly, a driver need to be installed.

1. Open "My Computer". The BBB will appear as a "Device with Removable Storage" (just like a USB memory).
My Computer overview
2. Enter the "BeagleBone Getting Started" device and navigate to the driver directory and the Windows driver folder. (Ex. "D:\Drivers\Windows"). Install the appropriate driver for your system. If you got a 32-bit system, choose BONE_DRV.exe or if you got a 64-bit system, choose BONE_D64.exe. During the installation phase, a warning about unsigned / untrusted drivers might appear. If this is the case, just accept/grant it. (This warning can appear multiple times in succession, accept them all).
Windows Drivers

When the drivers are installed, a network adapter over USB will be created. We will utilize this in the next chapter.

SSH

In this guide, a dedicated screen and keyboard for the BBB are not used. This means that we will need to access the BBB remotely. This is done via the USB network interface and SSH with PuTTY.

1. Open PuTTY. Choose SSH as connection type and enter the IP-address "192.168.7.2" in the "Host Name (or IP address)" field. Leave the port at 22.
PuTTY window
2. After pressing "Open" (at the bottom), a console with a security alert box will appear. Click "yes" to continue.
Security key warning
3. Write "root" as username ("login as") and hit the return/enter key. Leave the password field blank and hit the enter key again.
Logged in remotely to BBB

Now we are logged in to the BBB remotely as root user and are now able to install the required packages for the bridge.

Prerequisite software setup

Upgrade system

Before we get further into the guide, we will upgrade the system. This is needed by some of the modules we will build later. But before we go ahead with the upgrade, we need to clear some space on the BBB. For this purpose we will remove the Gnome desktop environment.


1. Remove all gnome related packages from the system. This will take around an hour. Issue this command in the terminal (Copy the command and right click in the putty window to paste it).
opkg remove *gnome* --force-removal-of-dependent-packages


2. Upgrade the system. This can take around an hour.
opkg update
opkg upgrade


3. When the upgrade is finished. Do a restart of the system.
shutdown -r now

The SSH connection will go down at this point. Wait for about a minute and then try to reconnect using the same instructions as before. If you cannot reconnect, try disconnecting the USB cable (and any other power supply to the BBB) and reconnect it.

Dependencies

This is the software dependencies needed throughout the guide.

1. Download and install the required the software. Update the clock as well before the update.
ntpdate -b -s -u pool.ntp.org
opkg update
opkg install wget bridge-utils kernel-dev kernel-headers task-native-sdk ethtool intltool intltool-dev libdbus-glib-1-dev

Build environment

We will have to build some modules from source in this guide and this requires few tweaks.

1. Navigate into the source files of the kernel.
cd /usr/src/kernel/


2. Issue the following make command to build the "build" scripts
make scripts


3. Now we need to create a link to where we can find the built scripts
ln -s /usr/src/kernel /lib/modules/`uname -r`/build


Disable Network Manager

The distribution shipped with the BBB uses Connman. Due to the way we will use the BBB in this guide, we will have to disable it and use static network settings.

Note: When disabling the network manager, the connection on the Ethernet (eth0) will be lost. But the USB network (usb0) connection will remain.

1. Stop and disable the network manager.
systemctl stop connman.service
systemctl disable connman.service


2. Copy the following command and paste it into the SSH console (just right click in the putty window) and hit enter. You might have to modify the IP address and gateway depending on your network setup.
cat > /etc/network/interfaces <<EOF
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
  address 192.168.0.190
  netmask 255.255.255.0
  gateway 192.168.0.1
EOF


3. Do the same for the DNS. Here we set the BBB to use Googles DNS server
cat > /etc/resolv.conf <<EOF
nameserver 8.8.8.8
EOF


4. Bring up the interface (eth0) and test it.
ifup eth0
ping google.com


(5.) If the ping fails, a restart of the BBB is required.
shutdown -r now

Remember to bring the interface (eth0) up after reboot

ifup eth0


6LoWPAN bridge to Ethernet

Overview

System overview

SLIP-radio

CC2531EMK

TODO: CC2531 USB with Contiki Slip Radio

CC2538EM

Slip Radio on the CC2538EM with USB Drivers

Build with latest Contiki code on Github

1. In the Slip-Radio (examples/ipv6/slip-radio/) Makefile, set SMALL=0

2. In the cc2538dk (platform/cc2538dk/) contiki-conf.h, make the following changes:

#define UART_CONF_ENABLE            0
#define SLIP_ARCH_CONF_USB          1
#define DBG_CONF_USB                1

Configure your radio and PAN settings:

#define CC2538_RF_CONF_CHANNEL              26
#define IEEE802154_CONF_PANID           0xABCD

3. Build the Slip-Radio (examples/ipv6/slip-radio/) with “make TARGET=cc2538dk”

4. Program the CC2538EM with SmartRF06 board, Flash Programmer 2 and the output slip-radio.bin file.

TODO: Make some example bins available.

Install Cetic-6LBR

We will install the Cetik 6LOWPAN Border Router [6LBR]. This guide is based on the official setup guide for the BBB from the Cetic-Team and can be found here.

1. First off, update the time on the BBB
ntpdate -b -s -u pool.ntp.org


2. Now download the setup package for 6LBR. (Note: this might not be the latest version when you follow this guide)
wget --no-check-certificate https://raw.github.com/wiki/cetic/6lbr/releases/cetic-6lbr_1.3.1-0_armv7a.ipk


3. Install the setup package
opkg install cetic-6lbr_1.3.1-0_armv7a.ipk


The Cetic-6LBR should now be installed, but not yet configured. Continue to the next chapter

Configure Cetic-6LBR

What configurations to use is depending on your setup and requirements. This guide will focus on the Smart Bridge mode.

1. Connect the Slip Radio to the USB port on the BBB.


2. Before we start editing the configuration file, we need to check that the SLIP radio is available and what device id it has.

Issue the following command:

ls /dev/ | grep tty


3. Identify your SLIP radio in the printed list, it will most likely be listed as a ttyUSB# (FTDI-chip) or ttyACM# (Direct USB drivers).


4. To open the configuration file we till use nano, enter the following:
nano /etc/6lbr/6lbr.conf


5. The default 6LBR look like this for the BeagleBone Black
#This file contains a default configuration for BeagleBone platform using
#a Telos SLIP Radio
#The full list of parameters and their meaning can be found in 6lbr.conf.example
MODE=ROUTER
#MODE=SMART-BRIDGE
#MODE=RPL-RELAY
#MODE=FULL-TRANSPARENT-BRIDGE
#MODE=NDP-ROUTER
#MODE=6LR
#MODE=RPL-ROOT
RAW_ETH=0
BRIDGE=1
DEV_BRIDGE=br0
DEV_TAP=tap0
DEV_ETH=eth0
RAW_ETH_FCS=0
DEV_RADIO=/dev/ttyACM0
BAUDRATE=115200
LOG_LEVEL=3 #INFO and above only
6. By navigating with your arrow keys, uncomment MODE=SMART-BRIDGE by removing the # and add it a # in front of MODE=Router:
#MODE=ROUTER
MODE=SMART-BRIDGE


This will put 6LBR into Smart Bridge operation mode, which will seamlessly bridge a 802.15.4 network with an Ethernet IPv6 network (Just like a normal Ethernet switch).


7. Set the device (DEV_RADIO) you want to use and specify buadrate (BAUDRATE) of the device (Default for Contiki in 115200):
DEV_RADIO=/dev/ttyACM0
BAUDRATE=115200

To continue this guide, there are two alternatives. Either you got a IPv6 network or you got a IPv4 network.

IPv6 network

If you got a IPv6 network connected to the BBB, we will connect 6LBR directly to our primary network interface, in most cases this will be eth0 if you use the Ethernet port.

IPv6 System setup
1. Set 6LBR to use raw_eth and set dev_eth to eth0
RAW_ETH=1
DEV_ETH=eth0


2. The settings file should now look something like this:
MODE=SMART-BRIDGE
RAW_ETH=1
BRIDGE=0
DEV_BRIDGE=br0
DEV_TAP=tap0
DEV_ETH=eth0
RAW_ETH_FCS=0
DEV_RADIO=/dev/ttyACM0
BAUDRATE=115200
LOG_LEVEL=3


3. To save the configurations we have made, hold down ctrl and press x. When prompted about if you want to modify the file, enter y and hit return/enter key. Accept the file name by hitting enter/return again.


4. Restart 6LBR with the following command and then we are done.
/etc/init.d/6lbr restart


We have now connected the 6LoWPAN network to the existing IPv6 network and we are now done with the guide.



IPv4 network

If you got a IPv4 network connected to your BBB, we will not connect our IPv6/6LoWPAN network directly to it. We will instead create a virtual network interface and later bridge it to our IPv6/6LoWPAN using Jool, a NAT64 solution.

IPv4 System setup


1. Set the following:
RAW_ETH=0
DEV_TAP=tap0
DEV_ETH=eth0


2. There is a bridge option present, but we will not use it. Make sure it is turned off:
BRIDGE=0
DEV_BRIDGE=br0


3. The settings file should now look something like this:
MODE=SMART-BRIDGE
RAW_ETH=0
BRIDGE=0
DEV_BRIDGE=br0
DEV_TAP=tap0
DEV_ETH=eth0
RAW_ETH_FCS=0
DEV_RADIO=/dev/ttyACM0
BAUDRATE=115200
LOG_LEVEL=3


4. To save the configurations we have made, hold down ctrl and press x. When prompted about if you want to modify the file, enter y and hit return/enter key. Accept the file name by hitting enter/return again.


Now continue with the DHCP IPv6 setup.

IPV6 DHCP

RADVD

RADVD is a IPv6 capable DHCP server use to distribute IPv6 addresses to the network. This server will distribute addresses to the 6LoWPAN network when 6LBR is running.

Installation

1. We need some more packages for this install to work
opkg install libcheck-dev libdaemon-dev


2. Create a folder in the home directory for RADVD
cd ~
mkdir radvd && cd radvd


3. Due to do a bug for one of the pre-installed modules on the BBB, we need to replace it. Download it
wget http://downloads.sourceforge.net/project/flex/flex/flex-2.5.35/flex-2.5.35.tar.bz2\?r=\&ts=1380059953\&use_mirror=softlayer-dal


4. Unpack and navigate into the unpacked directory.
tar xjf flex-2.5.35.tar.bz2\?r\=\&ts\=1380059953\&use_mirror\=softlayer-dal
cd flex-2.5.35


5. Do a normal ./configure, make, and make install
./configure
make
make install


6. Download RADVD (Use this version, confirmed to work on the BBB)
cd ~/radvd/
wget http://www.litech.org/radvd/dist/radvd-1.15.tar.gz


7. Unpack it and navigate into the unpacked directory
tar -xf radvd-1.15.tar.gz
cd radvd-1.15


8. Do a normal ./configure, make, and make install
./configure
make
make install


Configuration

1. Copy this into the SSH terminal
cat > /etc/radvd.conf << EOF
interface tap0
{
   AdvSendAdvert on;
   AdvManagedFlag off;     #stateless autoconfiguration
   AdvOtherConfigFlag on;  #clients get extra parameters via DHCPv6
   MaxRtrAdvInterval 10;   #resend RA @ random times, max 10sec delay
   prefix 2001:db8:2::/64  #announce prefix to clients
   {
       AdvOnLink on;
       AdvAutonomous on;
       AdvRouterAddr on;
   };
   RDNSS 2001:db8:2::2
   {
   };
};
EOF


2. Create a service for RADVD. Copy into the SSH terminal and hit enter
cat > /etc/systemd/system/radvd.service << EOF
[Unit]
Description=IPv6 Router Advertisement Daemon
Requires=network.target
After=network.target
[Service]
ExecStart=/etc/./radvd_start.sh
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/radvd/radvd.pid
[Install]
WantedBy=multi-user.target
EOF


3. Create this shell script. Copy into the SSH terminal and hit enter
cat > /etc/radvd_start.sh << EOF
#!/bin/bash
while true; do
if [ -d "/sys/class/net/tap0" ]; then
  sleep 1
  /usr/local/sbin/radvd --config=/etc/radvd.conf --pidfile=/run/radvd/radvd.pid -n
  exit
else
  sleep 1
fi
done
EOF


3. Make the shell script runnable
chmod +x /etc/radvd_start.sh


4. Set RADVD to autostart on boot
systemctl enable radvd.service


Continue with the NAT64 Setup

NAT64

Jool

Jool is an Open Source stateful NAT64 for Linux. It is used to translate packages between an IPv6- and an IPv4 network, which can be used by devices on an IPv6 network to access the IPv4 internet.

Installation

1. Download Jool: (Note: May not be the latest version. Go to https://www.jool.mx/download.html for latest version)
wget --no-check-certificate https://www.jool.mx/download/Jool-3.1.5.zip


2. Unpacked the zipped file:
unzip Jool-3.1.5.zip


3. Navigate into the unpacked folder:
cd Jool-3.1.5/mod


4. Issue the make command:
make


5. Install Jool
make modules_install


6. Refresh system modules by issuing this command. (Ignore the warnings of missing modules)
depmod -a 3.8.13


Configuration

Jool does no require any configurations. All required settings are loaded as parameters when Jool is started.

DNS64

BIND

TODO

Final configurations

There are a couple of final configurations we need to run everything automatically from boot.

Interface setup

The 6LBR system has the capability to run scripts when it connects to the SLIp radio, we will make use of this and create our own scripts to initialize entire bridge system.


1. This is the script used for bringing everything up. Copy the following and paste it into the SSH console (just right click in the putty window) and hit enter.
cat > /etc/6lbr/ifup.d/60dev <<EOF
#!/bin/bash
. $CETIC_6LBR_CONF
. $1/6lbr-functions
config_default
MODE_6LBR=$2
DEV=$3
OS=`uname`
ifup eth0
ip address add 192.168.0.200/24 dev eth0
ip -6 address add 2001:db8:2::2/64 dev tap0
sysctl -w net.ipv4.conf.all.forwarding=1
sysctl -w net.ipv6.conf.all.forwarding=1
ethtool --offload eth0 gso off
ethtool --offload eth0 gro off
ethtool --offload tap0 gso off
ethtool --offload tap0 gro off
sysctl -w net.ipv4.conf.all.log_martians=1
modprobe jool pool6=::ffff:0:0/96 pool4=192.168.0.200
EOF


2. This is the script used for tearing everything down. Copy the following and paste it into the SSH console (just right click in the putty window) and hit enter.
cat > /etc/6lbr/ifup.d/60dev <<EOF
#!/bin/bash
. $CETIC_6LBR_CONF
. $1/6lbr-functions
config_default
MODE_6LBR=$2
DEV=$3
OS=`uname`
modprobe -r jool
ip address del 192.168.0.200/24 dev eth0
sysctl -w net.ipv4.conf.all.forwarding=0
sysctl -w net.ipv6.conf.all.forwarding=0
EOF

Done

We are now done! Restart the system and everything should boot automatically.

shutdown -r now

Test

TODO