Add babel mesh routing protocol

This commit is contained in:
Bob Mottram 2018-01-17 13:42:40 +00:00
parent 97f9e3e3e2
commit 3d52e70630
5 changed files with 111 additions and 1 deletions

View File

@ -125,6 +125,9 @@ ENABLE_ZERONET=
MESH_TEXT_EDITOR='pluma'
BABEL_REPO="https://github.com/jech/babeld"
BABEL_COMMIT='d9390d1fee337c464e67255bbbd879d975e126e2'
OLSR2_REPO="https://github.com/OLSR/OONF"
OLSR2_COMMIT='81033251c4ee1c5699bfee9d2985112c6266ab0a'
@ -671,6 +674,42 @@ mesh_shutdown_script() {
chroot "$rootdir" systemctl enable meshshutdown
}
install_babel() {
git clone $BABEL_REPO $rootdir/etc/babel
cat <<EOF > $rootdir/usr/bin/install_babel
#!/bin/bash
cd /etc/babel
git checkout $BABEL_COMMIT -b $BABEL_COMMIT
cd /etc/babel
make
make install
EOF
chroot "$rootdir" chmod +x /usr/bin/install_babel
chroot "$rootdir" /usr/bin/install_babel
if [ ! -f $rootdir/usr/local/bin/babeld ]; then
echo $'Unable to build Babel'
exit 52382524
fi
rm $rootdir/usr/bin/install_babel
echo '[Unit]' > $rootdir/etc/systemd/system/babel.service
echo 'Description=Babel mesh routing protocol' >> $rootdir/etc/systemd/system/babel.service
echo 'Requires=network.target' >> $rootdir/etc/systemd/system/babel.service
echo 'After=network.target' >> $rootdir/etc/systemd/system/babel.service
echo '' >> $rootdir/etc/systemd/system/babel.service
echo '[Service]' >> $rootdir/etc/systemd/system/babel.service
echo 'User=root' >> $rootdir/etc/systemd/system/babel.service
echo 'Group=root' >> $rootdir/etc/systemd/system/babel.service
echo 'ExecStart=/usr/local/bin/babeld wlan0' >> $rootdir/etc/systemd/system/babel.service
echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/babel.service
echo '' >> $rootdir/etc/systemd/system/babel.service
echo '[Install]' >> $rootdir/etc/systemd/system/babel.service
echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/babel.service
}
install_olsr2() {
chroot "$rootdir" apt-get -yq install cmake libnl-3-dev
@ -896,6 +935,7 @@ initialise_mesh() {
install_bmx6
install_bmx7
install_olsr2
install_babel
mesh_shutdown_script
install_vpn
install_tomb

View File

@ -1456,6 +1456,10 @@ if [ -f $MESH_INSTALL_SETUP ]; then
systemctl disable olsr2
echo $'OLSR2 disabled' >> $INSTALL_LOG
systemctl stop babel
systemctl disable babel
echo $'Babel disabled' >> $INSTALL_LOG
#tomb slam all
tmp_ram_disk 100
enable_predictable_device_names

View File

@ -73,9 +73,11 @@ function stop {
systemctl stop bmx6
systemctl stop bmx7
systemctl stop olsr2
systemctl stop babel
systemctl disable bmx6
systemctl disable bmx7
systemctl disable olsr2
systemctl disable babel
systemctl stop dnsmasq
systemctl disable dnsmasq
@ -210,6 +212,7 @@ function start {
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE}|g" /etc/systemd/system/bmx6.service
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE}|g" /etc/systemd/system/bmx7.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE}|g" /etc/systemd/system/olsr2.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE}|g" /etc/systemd/system/babel.service
systemctl daemon-reload
add_wifi_interface $IFACE $WIFI_SSID ad-hoc $CHANNEL
@ -234,6 +237,7 @@ function start {
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
systemctl daemon-reload
else
echo $"$EIFACE is not connected"
@ -270,11 +274,23 @@ function start {
fi
if grep -q "olsr" $MESH_DEFAULT_PROTOCOL; then
IFACE=$(cat /etc/systemd/system/olsr2.service | grep ExecStart | awk -F ' ' '{print $2}')
mesh_generate_ipv6_address $IFACE
systemctl enable olsr2
systemctl restart olsr2
sed -i 's|<type>.*|<type>_olsr2._tcp</type>|g' /etc/avahi/services/routing.service
fi
if grep -q "babel" $MESH_DEFAULT_PROTOCOL; then
IFACE=$(cat /etc/systemd/system/babel.service | grep ExecStart | awk -F ' ' '{print $2}')
mesh_generate_ipv6_address $IFACE
systemctl enable babel
systemctl restart babel
sed -i 's|<type>.*|<type>_babel._tcp</type>|g' /etc/avahi/services/routing.service
fi
systemctl restart avahi-daemon
verify

View File

@ -34,10 +34,24 @@ export TEXTDOMAINDIR="/usr/share/locale"
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
clear
echo ''
echo $'Scanning for BMX6 protocol...'
bmx6_peers=$(avahi-browse -at | grep routing | grep bmx6 | wc -l)
clear
echo ''
echo $'Scanning for OLSR2 protocol...'
olsr2_peers=$(avahi-browse -at | grep routing | grep olsr2 | wc -l)
data=$(zenity --list 1 $"BMX6 ($bmx6_peers)" 2 $"OLSR2 ($olsr2_peers)" $"Select Mesh Protocol" --column="id" --title $"Mesh Protocol" --column=$"Choose the mesh protocol:" --hide-column=1 --print-column=1 --height=150)
clear
echo ''
echo $'Scanning for Babel protocol...'
babel_peers=$(avahi-browse -at | grep routing | grep babel | wc -l)
clear
data=$(zenity --list 1 $"BMX6 ($bmx6_peers)" 2 $"OLSR2 ($olsr2_peers)" 3 $"Babel ($babel_peers)" $"Select Mesh Protocol" --column="id" --title $"Mesh Protocol" --column=$"Choose the mesh protocol:" --hide-column=1 --print-column=1 --height=150)
sel=$?
case $sel in
@ -71,9 +85,23 @@ case $data in
sudo systemctl disable bmx7
sudo systemctl stop bmx6
sudo systemctl disable bmx6
IFACE=$(cat /etc/systemd/system/olsr2.service | grep ExecStart | awk -F ' ' '{print $2}')
mesh_generate_ipv6_address $IFACE
sudo systemctl enable olsr2
sudo systemctl start olsr2
;;
3) sudo /tmp/change_routing 'babel'
sudo systemctl stop bmx7
sudo systemctl disable bmx7
sudo systemctl stop bmx6
sudo systemctl disable bmx6
sudo systemctl stop olsr2
sudo systemctl disable olsr2
IFACE=$(cat /etc/systemd/system/babel.service | grep ExecStart | awk -F ' ' '{print $2}')
mesh_generate_ipv6_address $IFACE
sudo systemctl enable babel
sudo systemctl start babel
;;
esac
rm /tmp/change_routing

View File

@ -32,6 +32,28 @@
MESH_CURRENT_PROTOCOL=/root/.mesh_protocol
MESH_DEFAULT_PROTOCOL=/root/.mesh_protocol_default
function mesh_generate_ipv6_address {
network=fd66:66:66
if [ $1 ]; then
search_ipv6=$(ifconfig $1 | grep $network)
if [ $search_ipv6 ]; then
result=$(ifconfig $1 | grep $network | awk -F ' ' '{print $2}')
ip -6 addr add ${result}/128 dev wlan0
return
fi
fi
ipv6_array=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
a=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
b=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
c=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
d=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
e=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
result=$network:$a:$b:$c:$d:$e
ip -6 addr add ${result}/128 dev $1
}
function mesh_protocol_init {
if [[ $1 == "start" ]]; then
# install avahi