Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[posix] Add POSIX Cli Daemon module #2676

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yangsong-cnyn
Copy link
Contributor

@yangsong-cnyn yangsong-cnyn commented Jan 20, 2025

This PR introduces the CLI daemon module for OTBR on POSIX in NCP mode. This initial implementation focuses on setting up the module and establishing the listen socket. Further CLI functionalities and integration with NcpHost will be implemented in subsequent PRs.

Copy link

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 72.72727% with 12 lines in your changes missing coverage. Please review.

Project coverage is 43.41%. Comparing base (2b41187) to head (b5e7645).
Report is 952 commits behind head on main.

Files with missing lines Patch % Lines
src/host/posix/cli_daemon.cpp 72.41% 8 Missing ⚠️
tests/gtest/test_cli_daemon.cpp 73.33% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2676       +/-   ##
===========================================
- Coverage   55.77%   43.41%   -12.37%     
===========================================
  Files          87      110       +23     
  Lines        6890    13448     +6558     
  Branches        0      963      +963     
===========================================
+ Hits         3843     5838     +1995     
- Misses       3047     7303     +4256     
- Partials        0      307      +307     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yangsong-cnyn yangsong-cnyn requested a review from abtink January 20, 2025 07:19
@yangsong-cnyn yangsong-cnyn marked this pull request as draft January 20, 2025 08:02
@yangsong-cnyn yangsong-cnyn removed the request for review from abtink January 20, 2025 08:02
Copy link
Contributor

@Irving-cl Irving-cl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick implementation 👍

I have a few comments.

src/host/posix/daemon.cpp Outdated Show resolved Hide resolved
src/host/posix/daemon.cpp Outdated Show resolved Hide resolved
DieNow(otbrErrorString(OTBR_ERROR_ERRNO));
}

// TODO:: Send Spinel message to NCP to initialize CLI (otCliInit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the CLI module on NCP should initialize at first and the initialization isn't triggered by and message from the host. Thoughts?

src/host/posix/netif.hpp Outdated Show resolved Hide resolved
buffer[rval] = '\0';

otbrLogWarning("Received CLI command: %s", reinterpret_cast<char *>(buffer));
// TODO:: Send Spinel message to NCP to process the command (otCliInputLine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please abstract this process as an interface and this interface can be implememted by NcpSpinel (or some classes under RCP mode in the future). In this way, we can use this module for both NCP and RCP (later we transition to use this module). In addition, we can have a test implementation of this interface and write unit tests.

You may refer to Netif::Dependencies and tests/gtest/test_netif.cpp. The scheme will be very similar.

Then please add a unit test similar as test_netif.cpp. In the test, we simply create an instance of the Daemon class and a Mainloop. And we can also create a client socket and write cli commands to the socket. Then run the mainloop. Next we can check the call of our test implementation of the interface.

To run the gtest, build otbr-agent with -DBUILD_TESTING=ON flag. (By default it should be turned on)
Then run ${YOUR_BUILD_DIR}/tests/gtest/${YOUR_GTEST_PROGRAM}.

@Irving-cl Irving-cl changed the title [NCP] Implement OTBR Daemon for POSIX system [posix] Add Cli Daemon module Jan 20, 2025
@yangsong-cnyn yangsong-cnyn force-pushed the ncp_daemon branch 2 times, most recently from 251470f to e74d5b0 Compare February 19, 2025 08:35
@yangsong-cnyn yangsong-cnyn marked this pull request as ready for review February 19, 2025 08:37
@yangsong-cnyn yangsong-cnyn changed the title [posix] Add Cli Daemon module [posix] Add POSIX Cli Daemon module Feb 19, 2025
@yangsong-cnyn yangsong-cnyn marked this pull request as draft February 19, 2025 08:40
@yangsong-cnyn yangsong-cnyn force-pushed the ncp_daemon branch 2 times, most recently from b133533 to d95dc9c Compare February 19, 2025 08:51
@yangsong-cnyn yangsong-cnyn marked this pull request as ready for review February 19, 2025 09:50
src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Show resolved Hide resolved
src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@Irving-cl Irving-cl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thanks for breaking it into small ones.

src/host/posix/cli_daemon.cpp Outdated Show resolved Hide resolved
@yangsong-cnyn yangsong-cnyn requested a review from jwhui February 20, 2025 05:20
Copy link
Contributor

@superwhd superwhd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

src/host/posix/cli_daemon.hpp Outdated Show resolved Hide resolved
tests/gtest/test_cli_daemon.cpp Outdated Show resolved Hide resolved
@yangsong-cnyn yangsong-cnyn removed the request for review from abtink February 20, 2025 06:32
@yangsong-cnyn yangsong-cnyn force-pushed the ncp_daemon branch 2 times, most recently from 66e5031 to b9057c5 Compare February 20, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants