Skip to content

Commit

Permalink
[ncp] integrate SRP Server and Advertising Proxy for NCP (#2624)
Browse files Browse the repository at this point in the history
This commit integrates the mDNS Publisher with NcpHost to make
advertising proxy work under NCP mode.

The commit adds an expect test to verify the advertising proxy
function under NCP mode. To do the test, `avahi-browser` is used. So
it's added into the bootstrap of the CI for ncp_mode.

As an abstraction: 
1. The commit adds `NcpSpinel::SrpServerSetEnabled` and
   `NcpSpinel::SrpServerSetAutoEnableMode` to control the SRP server
   on the NCP.
2. The commit adds the handling of `SPINEL_PROP_DNSSD_HOST`,
   `SPINEL_PROP_DNSSD_SERVICE` and `SPINEL_PROP_DNSSD_KEY_RECORD` to
   help NCP to publish the dnssd entries (by using the mDNSPublisher
   on the host).
  • Loading branch information
Irving-cl authored Dec 5, 2024
1 parent 5102c52 commit ff4ea4e
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ncp_mode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
OTBR_MDNS: ${{ matrix.mdns }}
OTBR_COVERAGE: 1
OTBR_VERBOSE: 1
OTBR_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug -DOT_THREAD_VERSION=1.4 -DOTBR_COVERAGE=ON -DOTBR_DBUS=ON -DOTBR_FEATURE_FLAGS=ON -DOTBR_TELEMETRY_DATA_API=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON -DBUILD_TESTING=OFF"
OTBR_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug -DOT_THREAD_VERSION=1.4 -DOTBR_COVERAGE=ON -DOTBR_DBUS=ON -DOTBR_FEATURE_FLAGS=ON -DOTBR_TELEMETRY_DATA_API=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON -DOTBR_SRP_ADVERTISING_PROXY=ON -DBUILD_TESTING=OFF"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -76,6 +76,6 @@ jobs:
--build-arg OTBR_OPTIONS="${OTBR_OPTIONS}"
- name: Run
run: |
top_builddir="./build/temp" tests/scripts/ncp_mode build_ot_sim expect
top_builddir="./build/temp" tests/scripts/ncp_mode build_ot_sim expect
- name: Codecov
uses: codecov/codecov-action@v5
10 changes: 9 additions & 1 deletion src/agent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,22 @@ void Application::DeinitRcpMode(void)

void Application::InitNcpMode(void)
{
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
otbr::Ncp::NcpHost &ncpHost = static_cast<otbr::Ncp::NcpHost &>(mHost);
ncpHost.SetMdnsPublisher(mPublisher.get());
mMdnsStateSubject.AddObserver(ncpHost);
mPublisher->Start();
#endif
#if OTBR_ENABLE_DBUS_SERVER
mDBusAgent->Init(*mBorderAgent);
#endif
}

void Application::DeinitNcpMode(void)
{
/* empty */
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
mPublisher->Stop();
#endif
}

} // namespace otbr
1 change: 1 addition & 0 deletions src/agent/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#if OTBR_ENABLE_BORDER_AGENT
#include "border_agent/border_agent.hpp"
#endif
#include "ncp/ncp_host.hpp"
#include "ncp/rcp_host.hpp"
#if OTBR_ENABLE_BACKBONE_ROUTER
#include "backbone_router/backbone_agent.hpp"
Expand Down
23 changes: 22 additions & 1 deletion src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <openthread/openthread-system.h>

#include "lib/spinel/spinel_driver.hpp"

#include "ncp/async_task.hpp"

namespace otbr {
Expand Down Expand Up @@ -134,6 +133,16 @@ void NcpHost::Init(void)
{
mInfraIf.SetInfraIf(mConfig.mBackboneInterfaceName);
}

#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
#if OTBR_ENABLE_SRP_SERVER_AUTO_ENABLE_MODE
// Let SRP server use auto-enable mode. The auto-enable mode delegates the control of SRP server to the Border
// Routing Manager. SRP server automatically starts when bi-directional connectivity is ready.
mNcpSpinel.SrpServerSetAutoEnableMode(/* aEnabled */ true);
#else
mNcpSpinel.SrpServerSetEnabled(/* aEnabled */ true);
#endif
#endif
}

void NcpHost::Deinit(void)
Expand Down Expand Up @@ -264,5 +273,17 @@ void NcpHost::Update(MainloopContext &aMainloop)
mNetif.UpdateFdSet(&aMainloop);
}

#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
void NcpHost::SetMdnsPublisher(Mdns::Publisher *aPublisher)
{
mNcpSpinel.SetMdnsPublisher(aPublisher);
}

void NcpHost::HandleMdnsState(Mdns::Publisher::State aState)
{
mNcpSpinel.DnssdSetState(aState);
}
#endif

} // namespace Ncp
} // namespace otbr
16 changes: 15 additions & 1 deletion src/ncp/ncp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ class NcpNetworkProperties : virtual public NetworkProperties, public PropsObser
otOperationalDatasetTlvs mDatasetActiveTlvs;
};

class NcpHost : public MainloopProcessor, public ThreadHost, public NcpNetworkProperties
class NcpHost : public MainloopProcessor,
public ThreadHost,
public NcpNetworkProperties
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
,
public Mdns::StateObserver
#endif
{
public:
/**
Expand Down Expand Up @@ -119,7 +125,15 @@ class NcpHost : public MainloopProcessor, public ThreadHost, public NcpNetworkPr
void Update(MainloopContext &aMainloop) override;
void Process(const MainloopContext &aMainloop) override;

#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
void SetMdnsPublisher(Mdns::Publisher *aPublisher);
#endif

private:
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
void HandleMdnsState(Mdns::Publisher::State aState) override;
#endif

ot::Spinel::SpinelDriver &mSpinelDriver;
otPlatformConfig mConfig;
NcpSpinel mNcpSpinel;
Expand Down
Loading

0 comments on commit ff4ea4e

Please sign in to comment.