Skip to content

Commit

Permalink
Merge branch 'main' into pd_daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsong-cnyn authored Nov 4, 2024
2 parents 558ca76 + 5c66507 commit 225b634
Show file tree
Hide file tree
Showing 22 changed files with 476 additions and 97 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/ncp_mode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ jobs:
matrix:
mdns: ["mDNSResponder", "avahi"]
env:
BUILD_TARGET: check
BUILD_TARGET: ncp_mode
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"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -60,8 +62,20 @@ jobs:
run: tests/scripts/bootstrap.sh
- name: Build
run: |
OTBR_BUILD_DIR="./build/temp" script/cmake-build -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_WEB=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON
OTBR_BUILD_DIR="./build/temp" script/cmake-build ${OTBR_OPTIONS}
- name: Build OTBR Docker Image
run: |
sudo docker build -t otbr-ncp \
-f ./etc/docker/Dockerfile . \
--build-arg NAT64=0 \
--build-arg NAT64_SERVICE=0 \
--build-arg DNS64=0 \
--build-arg WEB_GUI=0 \
--build-arg REST_API=0 \
--build-arg FIREWALL=0 \
--build-arg OTBR_OPTIONS="${OTBR_OPTIONS}"
- name: Run
run: OTBR_VERBOSE=1 OTBR_TOP_BUILDDIR="./build/temp" script/test ncp_mode
run: |
top_builddir="./build/temp" tests/scripts/ncp_mode build_ot_sim expect
- name: Codecov
uses: codecov/codecov-action@v4
5 changes: 1 addition & 4 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,11 @@ main()
do_doxygen
;;
help)
print_usage
print_usage 1
;;
meshcop)
top_builddir="${OTBR_TOP_BUILDDIR}" print_result ./tests/scripts/meshcop
;;
ncp_mode)
top_builddir="${OTBR_TOP_BUILDDIR}" print_result ./tests/scripts/ncp_mode
;;
openwrt)
print_result ./tests/scripts/openwrt
;;
Expand Down
41 changes: 21 additions & 20 deletions src/agent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@

namespace otbr {

#ifndef OTBR_MAINLOOP_POLL_TIMEOUT_SEC
#define OTBR_MAINLOOP_POLL_TIMEOUT_SEC 10
#endif

std::atomic_bool Application::sShouldTerminate(false);
const struct timeval Application::kPollTimeout = {10, 0};
const struct timeval Application::kPollTimeout = {OTBR_MAINLOOP_POLL_TIMEOUT_SEC, 0};

Application::Application(const std::string &aInterfaceName,
const std::vector<const char *> &aBackboneInterfaceNames,
Expand All @@ -66,7 +70,8 @@ Application::Application(const std::string &aInterfaceName,
/* aDryRun */ false,
aEnableAutoAttach))
#if OTBR_ENABLE_MDNS
, mPublisher(Mdns::Publisher::Create([this](Mdns::Publisher::State aState) { this->HandleMdnsState(aState); }))
, mPublisher(
Mdns::Publisher::Create([this](Mdns::Publisher::State aState) { mMdnsStateSubject.UpdateState(aState); }))
#endif
#if OTBR_ENABLE_DBUS_SERVER && OTBR_ENABLE_BORDER_AGENT
, mDBusAgent(MakeUnique<DBus::DBusAgent>(*mHost, *mPublisher))
Expand Down Expand Up @@ -191,24 +196,6 @@ otbrError Application::Run(void)
return error;
}

void Application::HandleMdnsState(Mdns::Publisher::State aState)
{
OTBR_UNUSED_VARIABLE(aState);

#if OTBR_ENABLE_BORDER_AGENT
mBorderAgent->HandleMdnsState(aState);
#endif
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
mAdvertisingProxy->HandleMdnsState(aState);
#endif
#if OTBR_ENABLE_DNSSD_DISCOVERY_PROXY
mDiscoveryProxy->HandleMdnsState(aState);
#endif
#if OTBR_ENABLE_TREL
mTrelDnssd->HandleMdnsState(aState);
#endif
}

void Application::HandleSignal(int aSignal)
{
sShouldTerminate = true;
Expand Down Expand Up @@ -249,6 +236,19 @@ void Application::CreateRcpMode(const std::string &aRestListenAddress, int aRest

void Application::InitRcpMode(void)
{
#if OTBR_ENABLE_BORDER_AGENT
mMdnsStateSubject.AddObserver(*mBorderAgent);
#endif
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
mMdnsStateSubject.AddObserver(*mAdvertisingProxy);
#endif
#if OTBR_ENABLE_DNSSD_DISCOVERY_PROXY
mMdnsStateSubject.AddObserver(*mDiscoveryProxy);
#endif
#if OTBR_ENABLE_TREL
mMdnsStateSubject.AddObserver(*mTrelDnssd);
#endif

#if OTBR_ENABLE_MDNS
mPublisher->Start();
#endif
Expand Down Expand Up @@ -296,6 +296,7 @@ void Application::DeinitRcpMode(void)
mBorderAgent->SetEnabled(false);
#endif
#if OTBR_ENABLE_MDNS
mMdnsStateSubject.Clear();
mPublisher->Stop();
#endif
}
Expand Down
8 changes: 1 addition & 7 deletions src/agent/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@ class Application : private NonCopyable
}
#endif

/**
* This method handles mDNS publisher's state changes.
*
* @param[in] aState The state of mDNS publisher.
*/
void HandleMdnsState(Mdns::Publisher::State aState);

private:
// Default poll timeout.
static const struct timeval kPollTimeout;
Expand All @@ -264,6 +257,7 @@ class Application : private NonCopyable
const char *mBackboneInterfaceName;
std::unique_ptr<Ncp::ThreadHost> mHost;
#if OTBR_ENABLE_MDNS
Mdns::StateSubject mMdnsStateSubject;
std::unique_ptr<Mdns::Publisher> mPublisher;
#endif
#if OTBR_ENABLE_BORDER_AGENT
Expand Down
20 changes: 17 additions & 3 deletions src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@
#endif
#endif

static const char kDefaultInterfaceName[] = "wpan0";
#define DEFAULT_INTERFACE_NAME "wpan0"
static const char kDefaultInterfaceName[] = DEFAULT_INTERFACE_NAME;

// Port number used by Rest server.
static const uint32_t kPortNumber = 8081;
#define HELP_DEFAULT_REST_PORT_NUMBER "8081"

enum
{
Expand Down Expand Up @@ -144,8 +146,20 @@ static void PrintHelp(const char *aProgramName)
fprintf(stderr,
"Usage: %s [-I interfaceName] [-B backboneIfName] [-d DEBUG_LEVEL] [-v] [-s] [--auto-attach[=0/1]] "
"RADIO_URL [RADIO_URL]\n"
" --auto-attach defaults to 1\n"
" -s disables syslog and prints to standard out\n",
" -I, --thread-ifname Name of the Thread network interface (default: " DEFAULT_INTERFACE_NAME ").\n"
" -B, --backbone-ifname Name of the backbone network interfaces (can be specified multiple times).\n"
" -d, --debug-level The log level (EMERG=0, ALERT=1, CRIT=2, ERR=3, WARNING=4, NOTICE=5, INFO=6, "
"DEBUG=7).\n"
" -v, --verbose Enable verbose logging.\n"
" -s, --syslog-disable Disable syslog and print to standard out.\n"
" -h, --help Show this help text.\n"
" -V, --version Print the application's version and exit.\n"
" --radio-version Print the radio coprocessor version and exit.\n"
" --auto-attach Whether or not to automatically attach to the saved network (default: 1).\n"
" --rest-listen-address Network address to listen on for the REST API (default: [::]).\n"
" --rest-listen-port Network port to listen on for the REST API "
"(default: " HELP_DEFAULT_REST_PORT_NUMBER ").\n"
"\n",
aProgramName);
fprintf(stderr, "%s", otSysGetRadioUrlHelpString());
}
Expand Down
4 changes: 2 additions & 2 deletions src/border_agent/border_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace otbr {
/**
* This class implements Thread border agent functionality.
*/
class BorderAgent : private NonCopyable
class BorderAgent : public Mdns::StateObserver, private NonCopyable
{
public:
/** The callback for receiving ephemeral key changes. */
Expand Down Expand Up @@ -139,7 +139,7 @@ class BorderAgent : private NonCopyable
*
* @param[in] aState The state of mDNS publisher.
*/
void HandleMdnsState(Mdns::Publisher::State aState);
void HandleMdnsState(Mdns::Publisher::State aState) override;

/**
* This method creates ephemeral key in the Border Agent.
Expand Down
18 changes: 18 additions & 0 deletions src/mdns/mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,24 @@ void Publisher::RemoveAddress(AddressList &aAddressList, const Ip6Address &aAddr
}
}

void StateSubject::AddObserver(StateObserver &aObserver)
{
mObservers.push_back(&aObserver);
}

void StateSubject::UpdateState(Publisher::State aState)
{
for (StateObserver *observer : mObservers)
{
observer->HandleMdnsState(aState);
}
}

void StateSubject::Clear(void)
{
mObservers.clear();
}

} // namespace Mdns
} // namespace otbr

Expand Down
58 changes: 58 additions & 0 deletions src/mdns/mdns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,64 @@ class Publisher : private NonCopyable
MdnsTelemetryInfo mTelemetryInfo{};
};

/**
* This interface is a mDNS State Observer.
*/
class StateObserver
{
public:
/**
* This method notifies the mDNS state to the observer.
*
* @param[in] aState The mDNS State.
*/
virtual void HandleMdnsState(Publisher::State aState) = 0;

/**
* The destructor.
*/
virtual ~StateObserver(void) = default;
};

/**
* This class defines a mDNS State Subject.
*/
class StateSubject
{
public:
/**
* Constructor.
*/
StateSubject(void) = default;

/**
* Destructor.
*/
~StateSubject(void) = default;

/**
* This method adds an mDNS State Observer to this subject.
*
* @param[in] aObserver A reference to the observer. If it's nullptr, it won't be added.
*/
void AddObserver(StateObserver &aObserver);

/**
* This method updates the mDNS State.
*
* @param[in] aState The mDNS State.
*/
void UpdateState(Publisher::State aState);

/**
* This method removes all the observers.
*/
void Clear(void);

private:
std::vector<StateObserver *> mObservers;
};

/**
* @}
*/
Expand Down
9 changes: 9 additions & 0 deletions src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ void NcpHost::GetChannelMasks(const ChannelMasksReceiver &aReceiver, const Async
mTaskRunner.Post([aErrReceiver](void) { aErrReceiver(OT_ERROR_NOT_IMPLEMENTED, "Not implemented!"); });
}

void NcpHost::SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver)
{
OT_UNUSED_VARIABLE(aChannelMaxPowers);

// TODO: Implement SetChannelMaxPowers under NCP mode.
mTaskRunner.Post([aReceiver](void) { aReceiver(OT_ERROR_NOT_IMPLEMENTED, "Not implemented!"); });
}

void NcpHost::Process(const MainloopContext &aMainloop)
{
mSpinelDriver.Process(&aMainloop);
Expand Down
2 changes: 2 additions & 0 deletions src/ncp/ncp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class NcpHost : public MainloopProcessor, public ThreadHost, public NcpNetworkPr
void SetThreadEnabled(bool aEnabled, const AsyncResultReceiver aReceiver) override;
void SetCountryCode(const std::string &aCountryCode, const AsyncResultReceiver &aReceiver) override;
void GetChannelMasks(const ChannelMasksReceiver &aReceiver, const AsyncResultReceiver &aErrReceiver) override;
void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) override;
CoprocessorType GetCoprocessorType(void) override { return OT_COPROCESSOR_NCP; }
const char *GetCoprocessorVersion(void) override;
const char *GetInterfaceName(void) const override { return mConfig.mInterfaceName; }
Expand Down
Loading

0 comments on commit 225b634

Please sign in to comment.