Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional route config at startup #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ For _real_ IoT deployment you typically want to have your 6LoWPAN devices
created and configured during the boot process. Raspbian Jessie uses _Systemd_
to run services, so we want to use that to init a lowpan devices on startup.

### LowPAN setting at startup
The `lowpan.service` file provides a service definition to create `lowpan0`. It
requires the file `/etc/default/lowpan` to specify _channel_ (`CHN`), _panid_
(`PAN`), and (optional) the _link layer address_ (`MAC`). Further it uses the
Expand All @@ -79,6 +80,33 @@ To install the service, copy the files
```
_Note_: modify _channel_ and _panid_ if required in `/etc/default/lowpan`.

### LowPAN and a route setting at startup

When the Pi should not only span the lowPAN but also make the devices accessible
from other host in the network the `lowpan_route` service can be used instead of the
`lowpan service`. Make sure to only have one of them in `/etc/systemd/system/`.

The `lowpan_route.service` file provides a service definition to create `lowpan0`. It
requires the file `/etc/default/lowpan` to specify _channel_ (`CHN`), _panid_
(`PAN`), and (optional) the _link layer address_ (`MAC`). Further it uses the
scripts `create_lowpan` and `delete_lowpan` as described above, so install them
as well.

Additional it uses the skript `interface_add_IP_route` which sets an IP to an
interface and enables routing of the traffic from the lowPAN to the specified
interface by adding a route.
It requires the file `/etc/default/lowpan` to specify an _interface_ (`INTERFACE`),
a _IPv6 to add_ (`ADD_IPv6`), and the _route to the lowpan_ (`ROUTE_PREFIX`).
Further it uses the scripts `interface_add_IP_route` and `interface_del_IP_route`,
so install and make them executeable as well.

To install the service, copy the files
```
# cp <path/to/repo/clone>/etc/default/lowpan /etc/default/.
# cp <path/to/repo/clone>/etc/systemd/system/lowpan_route.service /etc/systemd/system/.
# systemctl enable lowpan_route.service
```

## Router Advertisement Daemon (radvd)

The 6LoWPAN standard states that there must be at least one router (6LR) in a
Expand All @@ -88,6 +116,28 @@ act as the _Authoritative Border Router_ and gateway (6LBR) between LoWPAN and
_real_ IPv6 networks such as the Internet. A simple way to transform the Pi
in a 6LBR is to run `radvd`. More detailed information can be found [here].

A radvd configuration file can be found in `wpan-raspian/etc/radvd.conf` it is
configured for `lowpan0` and `wlan0` to be used in a setup where the Pi bridges the
lowpan and the wlan and also advertises the prefixes for both networks.
This setup can be used to span a secondary network in parrallel to the running
network without affecting an existing network setup.
The additional hosts can join the network by adding an IP with the defined prefix.
Then they can ping the Pi, when they add a route to reach the lowpan over teh Pi other
host can then ping the lowpan devices through the Pi.

For example the Pi advertises

```
lowpan: fe18:a:b:2::/64
wlan: fe18:a:b:1::/64
```

Other linux host can join the network and ping the lowPAN devices like this.
```
sudo ifconfig wlan0 add fd18:a:b:1::2/64
ping fd18:a:b:2:dedc:20b7:3c21:8b3e
```


[Wiki]: https://github.com/RIOT-Makers/wpan-raspbian/wiki/Create-a-generic-Raspbian-image-with-6LoWPAN-support
[here]: https://github.com/RIOT-Makers/wpan-raspbian/wiki/Setup-native-6LoWPAN-router-using-Raspbian
8 changes: 7 additions & 1 deletion etc/default/lowpan
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ PAN="0x23"
# set MAC to "" for random mac/hw address
MAC="18:C0:FF:EE:1A:C0:FF:EE"
# set IP6 to "" if not required; note: set a prefix length
IP6="fdaa:bb:cc:dd::1/64"
#IP6="fdaa:bb:cc:dd::1/64"
IP6="fe18:a:b:2::1/64"
# Set ack requests (Only enable if all devices on your PAN support acks)
ACKREQ=0

# Setting up IP and Route at specified Interface
INTERFACE=wlan0
ADD_IPv6="fe18:a:b:1::1/64"
ROUTE_PREFIX="fe18:a:b:2::/64"
24 changes: 22 additions & 2 deletions etc/radvd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@ interface lowpan0
AdvCurHopLimit 255;
AdvSourceLLAddress on;

prefix fd00:1:2:3::/64
prefix 21a5::/64
{
AdvOnLink off;
AdvAutonomous on;
AdvRouterAddr on;
};

abro fd00:1:2:3:a:b:c:d
abro fe80::1ac0:ffee:1ac0:ffee
{
AdvVersionLow 10;
AdvVersionHigh 2;
AdvValidLifeTime 2;
};
};

interface wlan0
{
AdvSendAdvert on;
AdvSourceLLAddress on;

prefix fd18:a:b:1::/64
{
AdvOnLink off;
AdvAutonomous on;
AdvRouterAddr on;
};

abro fd18:a:b:1::1
{
AdvVersionLow 10;
AdvVersionHigh 2;
Expand Down
2 changes: 1 addition & 1 deletion etc/systemd/system/lowpan.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Create 6lowpan (IEEE802.15.4) network device
After=network.target
Conflicts=lowpan_monitor
Conflicts=lowpan_monitor lowpan_route

[Service]
EnvironmentFile=/etc/default/lowpan
Expand Down
2 changes: 1 addition & 1 deletion etc/systemd/system/lowpan_monitor.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Create lowpan (IEEE802.15.4) monitor device
After=network.target
Conflicts=lowpan
Conflicts=lowpan lowpan_route

[Service]
EnvironmentFile=/etc/default/lowpan_monitor
Expand Down
17 changes: 17 additions & 0 deletions etc/systemd/system/lowpan_route.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Create 6lowpan (IEEE802.15.4) network device
After=network.target
Conflicts=lowpan_monitor lowpan

[Service]
EnvironmentFile=/etc/default/lowpan
Type=oneshot
User=root
ExecStart=/usr/local/sbin/create_lowpan $CHN $PAN $MAC $IP6 $ACKREQ
ExecStart=/usr/local/sbin/interface_add_IP_route $INTERFACE $ADD_IPv6 $ROUTE_PREFIX
ExecStop=/usr/local/sbin/delete_lowpan
ExecStop=/usr/local/sbin/interface_del_IP_route $INTERFACE $ADD_IPv6 $ROUTE_PREFIX
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
38 changes: 38 additions & 0 deletions usr/local/sbin/interface_add_IP_route
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "You must be a root user" 2>&1
exit 1
fi

[ -z "$1" ] && {
echo "Missing network Interface!"
echo "USAGE: $0 <INTERFACE> <add IPv6> <route Prefix>"
exit 1
}

[ -z "$2" ] && {
echo "Missing IPv6 to add to interface!"
echo "USAGE: $0 <INTERFACE> <add IPv6> <route Prefix>"
exit 1
}
[ -z "$3" ] && {
echo "Missing network prefix to set route to!"
echo "USAGE: $0 <INTERFACE> <IPv6> <route Prefix>"
exit 1
}

INTERFACE=$1
IP=$2
PREFIX=$2

# check for interface
ip link show $INTERFACE 1> /dev/null 2>&1
if [[ $? == '0' ]] ; then
echo ". Add ip $IP and route $PREFIX to network interface $INTERFACE."
ifconfig $INTERFACE add $IP
sysctl -w net.ipv6.conf.all.forwarding=1
ip route add $PREFIX dev $INTERFACE
else
echo "! no network interface device found, exit!"
exit 1
fi
37 changes: 37 additions & 0 deletions usr/local/sbin/interface_del_IP_route
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "You must be a root user" 2>&1
exit 1
fi

[ -z "$1" ] && {
echo "Missing network Interface!"
echo "USAGE: $0 <INTERFACE> <add IPv6> <route Prefix>"
exit 1
}

[ -z "$2" ] && {
echo "Missing IPv6 to delete from interface!"
echo "USAGE: $0 <INTERFACE> <add IPv6> <route Prefix>"
exit 1
}
[ -z "$3" ] && {
echo "Missing network prefix to remove as route from interface!"
echo "USAGE: $0 <INTERFACE> <IPv6> <route Prefix>"
exit 1
}

INTERFACE=$1
IP=$2
PREFIX=$2

# check for interface
ip link show $INTERFACE 1> /dev/null 2>&1
if [[ $? == '0' ]] ; then
echo ". Delete ip $IP and route $PREFIX from network interface $INTERFACE."
ifconfig $INTERFACE del $IP
ip route del $PREFIX dev $INTERFACE
else
echo "! no network interface device found, exit!"
exit 1
fi