Skip to content

Commit

Permalink
manage smcroute service for multicast forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlingoogle committed Sep 16, 2020
1 parent 43a6758 commit 3447b8a
Show file tree
Hide file tree
Showing 32 changed files with 1,163 additions and 14 deletions.
6 changes: 6 additions & 0 deletions etc/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
FROM ubuntu:bionic


ARG BACKBONE_ROUTER
ARG OTBR_OPTIONS

ENV BACKBONE_ROUTER=${BACKBONE_ROUTER}
ENV OTBR_OPTIONS=${OTBR_OPTIONS}
ENV DEBIAN_FRONTEND noninteractive
ENV PLATFORM ubuntu
Expand All @@ -45,6 +48,7 @@ ENV OTBR_DOCKER_REQS sudo

# Required during build, could be removed
ENV OTBR_DOCKER_DEPS git
ENV BACKBONE_ROUTER_BUILD_DEPS ca-certificates automake autoconf build-essential pkg-config

# Required and installed during build (script/bootstrap), could be removed
ENV OTBR_BUILD_DEPS \
Expand All @@ -60,6 +64,7 @@ ENV OTBR_NORELEASE_DEPS \

RUN apt-get update \
&& apt-get install --no-install-recommends -y $OTBR_DOCKER_REQS $OTBR_DOCKER_DEPS \
&& [ "${BACKBONE_ROUTER}" = 1 ] || apt-get install --no-install-recommends -y $BACKBONE_ROUTER_BUILD_DEPS \
&& ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
&& ./script/bootstrap \
&& ./script/setup \
Expand All @@ -72,6 +77,7 @@ RUN apt-get update \
&& mv /tmp/etc . \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $OTBR_DOCKER_DEPS \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $OTBR_BUILD_DEPS \
&& [ "${BACKBONE_ROUTER}" = 1 ] || apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BACKBONE_ROUTER_BUILD_DEPS \
&& ([ "${RELEASE}" = 1 ] || apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false "$OTBR_NORELEASE_DEPS";) \
&& rm -rf /var/lib/apt/lists/*

Expand Down
1 change: 1 addition & 0 deletions examples/platforms/beagleboneblack/default
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ NAT64=0
DNS64=0
DHCPV6_PD=0
NETWORK_MANAGER=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
7 changes: 7 additions & 0 deletions script/_otbr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
readonly OTBR_TOP_BUILDDIR="${BUILD_DIR}/otbr"
readonly OTBR_TOP_SRCDIR="$PWD"
readonly OTBR_OPTIONS="${OTBR_OPTIONS:-}"
readonly BACKBONE_ROUTER="${BACKBONE_ROUTER:-0}"

otbr_uninstall()
{
Expand Down Expand Up @@ -69,6 +70,12 @@ otbr_install()
"${otbr_options[@]}"
)

if [[ ${BACKBONE_ROUTER} == "1" ]]; then
otbr_options+=(
"-DOTBR_BACKBONE_ROUTER=ON"
)
fi

(mkdir -p "${OTBR_TOP_BUILDDIR}" \
&& cd "${OTBR_TOP_BUILDDIR}" \
&& cmake -GNinja "${OTBR_TOP_SRCDIR}" "${otbr_options[@]}" \
Expand Down
67 changes: 67 additions & 0 deletions script/_smcroute
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/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

if have systemctl; then
sudo systemctl stop smcroute || true
sudo systemctl disable smcroute || true
fi

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

if command -v systemctl; then
sudo systemctl enable smcroute
sudo systemctl restart smcroute
fi
)
}
2 changes: 2 additions & 0 deletions script/server
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ main()
systemctl is-active rsyslog || sudo systemctl start rsyslog || die 'Failed to start rsyslog!'
systemctl is-active dbus || sudo systemctl start dbus || die 'Failed to start dbus!'
systemctl is-active avahi-daemon || sudo systemctl start avahi-daemon || die 'Failed to start avahi!'
systemctl is-active smcroute || sudo systemctl start smcroute || die 'Failed to start SMCRoute!'
systemctl is-active otbr-web || sudo systemctl start otbr-web || die 'Failed to start otbr-web!'
systemctl is-active otbr-agent || sudo systemctl start otbr-agent || die 'Failed to start otbr-agent!'
elif have service; then
sudo service rsyslog status || sudo service rsyslog start || die 'Failed to start rsyslog!'
sudo service dbus status || sudo service dbus start || die 'Failed to start dbus!'
sudo service avahi-daemon status || sudo service avahi-daemon start || die 'Failed to start avahi!'
sudo service smcroute status || sudo service smcroute start || die "Failed to start SMCRoute!"
sudo service otbr-agent status || sudo service otbr-agent start || die 'Failed to start otbr-agent!'
sudo service otbr-web status || sudo service otbr-web start || die 'Failed to start otbr-web!'
else
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()
1 change: 1 addition & 0 deletions src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ target_link_libraries(otbr-agent PRIVATE
$<$<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
4 changes: 2 additions & 2 deletions src/agent/agent_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ AgentInstance::AgentInstance(Ncp::Controller *aNcp)
{
}

otbrError AgentInstance::Init(void)
otbrError AgentInstance::Init(const std::string &aThreadIfName, const std::string &aBackboneIfName)
{
otbrError error = OTBR_ERROR_NONE;

SuccessOrExit(error = mNcp->Init());

mBorderAgent.Init();
mBorderAgent.Init(aThreadIfName, aBackboneIfName);

exit:
otbrLogResult("Initialize OpenThread Border Router Agent", error);
Expand Down
5 changes: 4 additions & 1 deletion src/agent/agent_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ class AgentInstance
/**
* This method initialize the agent.
*
* @param[in] aThreadIfName The Thread network interface name.
* @param[in] aBackboneIfName The Backbone network interface name.
*
* @retval OTBR_ERROR_NONE Agent initialized successfully.
* @retval OTBR_ERROR_ERRNO Failed due to error indicated in errno.
*
*/
otbrError Init(void);
otbrError Init(const std::string &aThreadIfName, const std::string &aBackboneIfName);

/**
* This method updates the file descriptor sets and timeout for mainloop.
Expand Down
53 changes: 52 additions & 1 deletion 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,12 +88,18 @@ BorderAgent::BorderAgent(Ncp::Controller *aNcp)
: mPublisher(nullptr)
#endif
, mNcp(aNcp)
#if OTBR_ENABLE_BACKBONE_ROUTER
, mBackboneAgent(*reinterpret_cast<Ncp::ControllerOpenThread *>(aNcp))
#endif
, mThreadStarted(false)
{
}

void BorderAgent::Init(void)
void BorderAgent::Init(const std::string &aThreadIfName, const std::string &aBackboneIfName)
{
OT_UNUSED_VARIABLE(aThreadIfName);
OT_UNUSED_VARIABLE(aBackboneIfName);

memset(mNetworkName, 0, sizeof(mNetworkName));
memset(mExtPanId, 0, sizeof(mExtPanId));
mExtPanIdInitialized = false;
Expand All @@ -106,6 +113,13 @@ void BorderAgent::Init(void)
mNcp->On(Ncp::kEventThreadState, HandleThreadState, this);
mNcp->On(Ncp::kEventPSKc, HandlePSKc, this);

#if OTBR_ENABLE_BACKBONE_ROUTER
mNcp->On(Ncp::kEventBackboneRouterState, HandleBackboneRouterState, this);
mNcp->On(Ncp::kEventBackboneRouterMulticastListenerEvent, HandleBackboneRouterMulticastListenerEvent, this);

mBackboneAgent.Init(aThreadIfName, aBackboneIfName);
#endif

otbrLogResult("Check if Thread is up", mNcp->RequestEvent(Ncp::kEventThreadState));
otbrLogResult("Check if PSKc is initialized", mNcp->RequestEvent(Ncp::kEventPSKc));
}
Expand Down Expand Up @@ -381,4 +395,41 @@ void BorderAgent::HandleThreadVersion(void *aContext, int aEvent, va_list aArgum
static_cast<BorderAgent *>(aContext)->SetThreadVersion(threadVersion);
}

#if OTBR_ENABLE_BACKBONE_ROUTER
void BorderAgent::HandleBackboneRouterState(void *aContext, int aEvent, va_list aArguments)
{
OT_UNUSED_VARIABLE(aEvent);
OT_UNUSED_VARIABLE(aArguments);
assert(aEvent == Ncp::kEventBackboneRouterState);

static_cast<BorderAgent *>(aContext)->HandleBackboneRouterState();
}

void BorderAgent::HandleBackboneRouterState(void)
{
mBackboneAgent.HandleBackboneRouterState();
}

void BorderAgent::HandleBackboneRouterMulticastListenerEvent(void *aContext, int aEvent, va_list aArguments)
{
OT_UNUSED_VARIABLE(aEvent);

otBackboneRouterMulticastListenerEvent event;
const otIp6Address * address;

assert(aEvent == Ncp::kEventBackboneRouterMulticastListenerEvent);

event = static_cast<otBackboneRouterMulticastListenerEvent>(va_arg(aArguments, int));
address = va_arg(aArguments, const otIp6Address *);
static_cast<BorderAgent *>(aContext)->HandleBackboneRouterMulticastListenerEvent(event, *address);
}

void BorderAgent::HandleBackboneRouterMulticastListenerEvent(otBackboneRouterMulticastListenerEvent aEvent,
const otIp6Address & aAddress)
{
mBackboneAgent.HandleBackboneRouterMulticastListenerEvent(aEvent, aAddress);
}

#endif

} // namespace otbr
17 changes: 16 additions & 1 deletion src/agent/border_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <stdint.h>

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

namespace otbr {
Expand Down Expand Up @@ -70,8 +71,11 @@ class BorderAgent
/**
* This method initialize border agent service.
*
* @param[in] aThreadIfName The Thread network interface name.
* @param[in] aBackboneIfName The Backbone network interface name.
*
*/
void Init(void);
void Init(const std::string &aThreadIfName, const std::string &aBackboneIfName);

/**
* This method updates the fd_set and timeout for mainloop.
Expand Down Expand Up @@ -131,9 +135,20 @@ class BorderAgent
static void HandleNetworkName(void *aContext, int aEvent, va_list aArguments);
static void HandleExtPanId(void *aContext, int aEvent, va_list aArguments);
static void HandleThreadVersion(void *aContext, int aEvent, va_list aArguments);
#if OTBR_ENABLE_BACKBONE_ROUTER
static void HandleBackboneRouterState(void *aContext, int aEvent, va_list aArguments);
void HandleBackboneRouterState(void);
static void HandleBackboneRouterMulticastListenerEvent(void *aContext, int aEvent, va_list aArguments);
void HandleBackboneRouterMulticastListenerEvent(otBackboneRouterMulticastListenerEvent aEvent,
const otIp6Address & aAddress);

#endif

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

uint8_t mExtPanId[kSizeExtPanId];
bool mExtPanIdInitialized;
Expand Down
2 changes: 1 addition & 1 deletion src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ int main(int argc, char *argv[])
{
otbr::AgentInstance instance(ncp);

SuccessOrExit(ret = instance.Init());
SuccessOrExit(ret = instance.Init(interfaceName, backboneInterfaceName));

if (printRadioVersion)
{
Expand Down
Loading

0 comments on commit 3447b8a

Please sign in to comment.