Skip to content

Commit

Permalink
manage Backbone multicast routes using smcroute
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlingoogle committed Oct 24, 2020
1 parent 6f0c803 commit b7229fc
Show file tree
Hide file tree
Showing 40 changed files with 1,227 additions and 39 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ jobs:
submodules: true
- name: Build OTBR Docker Image
run: |
otbr_options="-DOTBR_BACKBONE_ROUTER=ON -DOT_DUA=ON -DOT_MLR=ON -DOTBR_COVERAGE=ON"
otbr_options="-DOT_DUA=ON -DOT_MLR=ON -DOTBR_COVERAGE=ON"
otbr_image_name="otbr-ot12-backbone-ci"
docker build -t "${otbr_image_name}" -f etc/docker/Dockerfile . --build-arg REFERENCE_DEVICE=1 --build-arg OT_BACKBONE_CI=1 --build-arg OTBR_OPTIONS="${otbr_options}"
docker build -t "${otbr_image_name}" -f etc/docker/Dockerfile . \
--build-arg BACKBONE_ROUTER=1 \
--build-arg REFERENCE_DEVICE=${REFERENCE_DEVICE} \
--build-arg OT_BACKBONE_CI=1 \
--build-arg NAT64=0 \
--build-arg OTBR_OPTIONS="${otbr_options}"
- name: Bootstrap OpenThread Test
run: |
sudo rm /etc/apt/sources.list.d/* && sudo apt-get update
Expand Down
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ LOCAL_CPPFLAGS += -std=c++14

LOCAL_SRC_FILES := \
src/agent/agent_instance.cpp \
src/agent/instance_params.cpp \
src/agent/border_agent.cpp \
src/agent/main.cpp \
src/agent/ncp_openthread.cpp \
Expand Down
7 changes: 5 additions & 2 deletions etc/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@

FROM ubuntu:bionic

ARG BACKBONE_ROUTER
ARG OT_BACKBONE_CI
ARG OTBR_OPTIONS
ARG DNS64
ARG NAT64
ARG REFERENCE_DEVICE
ARG RELEASE

ENV BACKBONE_ROUTER=${BACKBONE_ROUTER:-0}
ENV OT_BACKBONE_CI=${OT_BACKBONE_CI:-0}
ENV OTBR_OPTIONS=${OTBR_OPTIONS}
ENV DEBIAN_FRONTEND noninteractive
Expand All @@ -58,10 +60,11 @@ ENV OTBR_DOCKER_DEPS git ca-certificates
# Required and installed during build (script/bootstrap), could be removed
ENV OTBR_BUILD_DEPS apt-utils build-essential psmisc ninja-build cmake wget ca-certificates \
libreadline-dev libncurses-dev libcpputest-dev libdbus-1-dev libavahi-common-dev \
libavahi-client-dev libboost-dev libboost-filesystem-dev libboost-system-dev libjsoncpp-dev
libavahi-client-dev libboost-dev libboost-filesystem-dev libboost-system-dev libjsoncpp-dev \
autoconf automake pkg-config

# Required for OpenThread Backbone CI
ENV OTBR_OT_BACKBONE_CI_DEPS curl ca-certificates
ENV OTBR_OT_BACKBONE_CI_DEPS curl

# Required and installed during build (script/bootstrap) when RELEASE=1, could be removed
ENV OTBR_NORELEASE_DEPS \
Expand Down
1 change: 1 addition & 0 deletions examples/platforms/beagleboneblack/default
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ DHCPV6_PD=1
NETWORK_MANAGER=1
# disabled unless specifically added for the device
NETWORK_MANAGER_WIFI=0
BACKBONE_ROUTER=0
1 change: 1 addition & 0 deletions examples/platforms/fedora/default
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ NAT64=0
DNS64=0
DHCPV6_PD=0
NETWORK_MANAGER=0
BACKBONE_ROUTER=0
1 change: 1 addition & 0 deletions examples/platforms/raspbian/default
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ NAT64=1
DNS64=1
DHCPV6_PD=1
NETWORK_MANAGER=1
BACKBONE_ROUTER=0
1 change: 1 addition & 0 deletions examples/platforms/ubuntu/default
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ NAT64=1
DNS64=1
DHCPV6_PD=0
NETWORK_MANAGER=0
BACKBONE_ROUTER=0
17 changes: 7 additions & 10 deletions script/_otbr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
readonly OTBR_TOP_BUILDDIR="${BUILD_DIR}/otbr"
readonly OTBR_TOP_SRCDIR="$PWD"
readonly OTBR_OPTIONS="${OTBR_OPTIONS:-}"
readonly REFERENCE_DEVICE=${REFERENCE_DEVICE:-0}
readonly REFERENCE_DEVICE="${REFERENCE_DEVICE:-0}"
readonly BACKBONE_ROUTER="${BACKBONE_ROUTER:-0}"

otbr_uninstall()
{
Expand All @@ -53,13 +54,6 @@ otbr_uninstall()
fi
}

install_reference_device_deps()
{
with REFERENCE_DEVICE || return 0

sudo apt-get install -y --no-install-recommends radvd
}

otbr_install()
{
local otbr_options=()
Expand All @@ -82,6 +76,11 @@ otbr_install()
"-DOT_REFERENCE_DEVICE=ON"
)
fi
if [[ ${BACKBONE_ROUTER} == "1" ]]; then
otbr_options+=(
"-DOTBR_BACKBONE_ROUTER=ON"
)
fi

(mkdir -p "${OTBR_TOP_BUILDDIR}" \
&& cd "${OTBR_TOP_BUILDDIR}" \
Expand All @@ -98,8 +97,6 @@ otbr_install()
else
echo >&2 ' *** WARNING: systemctl not found. otbr cannot start on boot.'
fi

install_reference_device_deps
}

otbr_update()
Expand Down
59 changes: 59 additions & 0 deletions script/_smcroute
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
#
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Description:
# This script manipulates smcroute configuration.
#

smcroute_uninstall()
{
with BACKBONE_ROUTER || return 0

sudo smcroutectl kill || true

test -d "$BUILD_DIR"/smcroute || return 0

(cd "$BUILD_DIR"/smcroute \
&& (test ! -f config.status || sudo make uninstall))
}

smcroute_install()
{
with BACKBONE_ROUTER || return 0

test -d "$BUILD_DIR"/smcroute || (cd "$BUILD_DIR" \
&& git clone -b ip6_mf --depth 1 https://github.com/librasungirl/smcroute.git) || die 'Failed to download source code of SMCRoute!'

(
cd "$BUILD_DIR"/smcroute || return 1
test -f configure || ./autogen.sh
test -f config.status || ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make
sudo make install
)
}
7 changes: 5 additions & 2 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_packages_apt()
libreadline-dev \
libncurses-dev

sudo apt-get install --no-install-recommends -y build-essential ninja-build cmake
sudo apt-get install --no-install-recommends -y build-essential ninja-build cmake automake autoconf pkg-config

with RELEASE || sudo apt-get install --no-install-recommends -y libcpputest-dev

Expand Down Expand Up @@ -86,6 +86,9 @@ install_packages_apt()

# libjsoncpp
sudo apt-get install --no-install-recommends -y libjsoncpp1 libjsoncpp-dev

# reference device
without REFERENCE_DEVICE || sudo apt-get install --no-install-recommends -y radvd
}

install_packages_opkg()
Expand All @@ -100,7 +103,7 @@ install_packages_rpm()
else
PM=yum
fi
sudo $PM install -y gcc gcc-c++
sudo $PM install -y gcc gcc-c++ automake autoconf pkg-config
with RELEASE || sudo $PM install -y cmake ninja-build
sudo $PM install -y dbus-devel
sudo $PM install -y avahi avahi-devel
Expand Down
3 changes: 3 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
. script/_dns64
. script/_dhcpv6_pd
. script/_network_manager
. script/_smcroute
. script/_swapfile
. script/_sudo_extend
. script/_disable_services
Expand All @@ -53,9 +54,11 @@ main()
dhcpv6_pd_uninstall
nat64_uninstall
dns64_uninstall
smcroute_uninstall
ipforward_uninstall

ipforward_install
smcroute_install
nat64_install
dns64_install
network_manager_install
Expand Down
3 changes: 3 additions & 0 deletions script/update
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
. script/_nat64
. script/_dns64
. script/_dhcpv6_pd
. script/_smcroute

main()
{
Expand All @@ -48,9 +49,11 @@ main()
dhcpv6_pd_uninstall
nat64_uninstall
dns64_uninstall
smcroute_uninstall
ipforward_uninstall

ipforward_install
smcroute_install
nat64_install
dns64_install
dhcpv6_pd_install
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ if(OTBR_REST)
add_subdirectory(rest)
endif()

if (OTBR_BACKBONE_ROUTER)
add_subdirectory(backbone_router)
endif()
3 changes: 3 additions & 0 deletions src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ add_executable(otbr-agent
ncp_openthread.hpp
thread_helper.cpp
thread_helper.hpp
instance_params.cpp
instance_params.hpp
)

target_link_libraries(otbr-agent PRIVATE
$<$<BOOL:${OTBR_DBUS}>:otbr-dbus-server>
$<$<BOOL:${OTBR_MDNS}>:otbr-mdns>
$<$<BOOL:${OTBR_OPENWRT}>:otbr-ubus>
$<$<BOOL:${OTBR_REST}>:otbr-rest>
$<$<BOOL:${OTBR_BACKBONE_ROUTER}>:otbr-backbone-router>
openthread-cli-ftd
openthread-ftd
openthread-posix
Expand Down
2 changes: 1 addition & 1 deletion src/agent/agent_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ otbrError AgentInstance::Init(void)
mBorderAgent.Init();

exit:
otbrLogResult("Initialize OpenThread Border Router Agent", error);
otbrLogResult(error, "Initialize OpenThread Border Router Agent");
return error;
}

Expand Down
1 change: 1 addition & 0 deletions src/agent/agent_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <sys/types.h>

#include "agent/border_agent.hpp"
#include "agent/instance_params.hpp"
#include "agent/ncp.hpp"

namespace otbr {
Expand Down
14 changes: 11 additions & 3 deletions src/agent/border_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "agent/border_agent.hpp"
#include "agent/ncp.hpp"
#include "agent/ncp_openthread.hpp"
#include "agent/uris.hpp"
#include "common/code_utils.hpp"
#include "common/logging.hpp"
Expand Down Expand Up @@ -87,6 +88,9 @@ BorderAgent::BorderAgent(Ncp::Controller *aNcp)
: mPublisher(nullptr)
#endif
, mNcp(aNcp)
#if OTBR_ENABLE_BACKBONE_ROUTER
, mBackboneAgent(*reinterpret_cast<Ncp::ControllerOpenThread *>(aNcp))
#endif
, mThreadStarted(false)
{
}
Expand All @@ -106,8 +110,12 @@ void BorderAgent::Init(void)
mNcp->On(Ncp::kEventThreadState, HandleThreadState, this);
mNcp->On(Ncp::kEventPSKc, HandlePSKc, this);

otbrLogResult("Check if Thread is up", mNcp->RequestEvent(Ncp::kEventThreadState));
otbrLogResult("Check if PSKc is initialized", mNcp->RequestEvent(Ncp::kEventPSKc));
#if OTBR_ENABLE_BACKBONE_ROUTER
mBackboneAgent.Init();
#endif

otbrLogResult(mNcp->RequestEvent(Ncp::kEventThreadState), "Check if Thread is up");
otbrLogResult(mNcp->RequestEvent(Ncp::kEventPSKc), "Check if PSKc is initialized");
}

otbrError BorderAgent::Start(void)
Expand All @@ -131,7 +139,7 @@ otbrError BorderAgent::Start(void)
ExitNow();

exit:
otbrLogResult("Start Thread Border Agent", error);
otbrLogResult(error, "Start Thread Border Agent");
return error;
}

Expand Down
5 changes: 5 additions & 0 deletions src/agent/border_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

#include <stdint.h>

#include "agent/instance_params.hpp"
#include "agent/ncp.hpp"
#include "backbone_router/backbone_agent.hpp"
#include "mdns/mdns.hpp"

namespace otbr {
Expand Down Expand Up @@ -134,6 +136,9 @@ class BorderAgent

Mdns::Publisher *mPublisher;
Ncp::Controller *mNcp;
#if OTBR_ENABLE_BACKBONE_ROUTER
BackboneRouter::BackboneAgent mBackboneAgent;
#endif

uint8_t mExtPanId[kSizeExtPanId];
bool mExtPanIdInitialized;
Expand Down
Loading

0 comments on commit b7229fc

Please sign in to comment.