Skip to content

[rcp] add support for OTNS - #11637

Merged
jwhui merged 9 commits into
openthread:mainfrom
francoismichel:upstream-to-openthread
Oct 3, 2025
Merged

[rcp] add support for OTNS#11637
jwhui merged 9 commits into
openthread:mainfrom
francoismichel:upstream-to-openthread

Conversation

@francoismichel

Copy link
Copy Markdown
Contributor

Hi folks,

This PR allows compiling the RCP in OTNS mode. This will allow OTBR to attach seamlessly to OTNS.
Once these changes are part of the OpenThread upstream, I will be able to submit a PR on OTNS that makes use of this.

Changes:

  • Add the mOtns attribute to Instance::Instance when compiled with OPENTHREAD_RADIO=1
  • Add src/core/utils/otns.cpp to the RCP build. Only the necessary functions are compiled in RCP mode. Other functions such as EmitPingRequest and EmitPingReply that require IPv6 stack support are not compiled in RCP and are therefore moved into adequate #if OPENTHREAD_MTD || OPENTHREAD_FTD guards.
  • Ensure the RCP emits the needed events in src/core/radio/radio.cpp when compiled with OTNS support.

@google-cla

google-cla Bot commented Jun 25, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello @francoismichel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces support for OpenThread Network Simulator (OTNS) within the Radio Co-Processor (RCP) build configuration. The primary goal is to enable OpenThread Border Routers (OTBR) to seamlessly integrate with OTNS by allowing the RCP to emit necessary events for simulation, ensuring proper behavior and visibility in the simulated environment.

Highlights

  • OTNS Support for RCP: Extended the Utils::Otns module to be compiled and utilized when OpenThread is built as a Radio Co-Processor (OPENTHREAD_RADIO), enabling OTBR to seamlessly integrate with OTNS.
  • Conditional OTNS Features: Refactored the Utils::Otns class to conditionally compile certain features (like IPv6-related ping events, CoAP events, and Thread-specific events) only when building for MTD (Minimal Thread Device) or FTD (Full Thread Device) modes, as these features are not relevant or available in the RCP build.
  • RCP Event Emission: Modified the radio layer to ensure that the RCP emits essential events, such as extended address, short address, and transmit events, to OTNS when enabled, providing necessary visibility for simulation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

Thank you for this contribution. This pull request successfully adds support for OTNS in RCP mode, which will be a valuable addition for testing OTBR with OTNS.

The changes are well-structured and correctly implemented. You've properly updated the build files to include otns.cpp for RCP builds, modified the Instance class to include the Otns member in RCP mode, and used conditional compilation to exclude FTD/MTD-specific functionality from otns.cpp and otns.hpp when building for RCP. The code appears correct and robust.

Overall, this is a great addition that will improve testing capabilities with OTNS. I have no further comments.

@jwhui
jwhui requested review from EskoDijk and Copilot June 25, 2025 15:36
@jwhui jwhui changed the title [rcp] Add support for OTNS [rcp] add support for OTNS Jun 25, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for OTNS when compiling the RCP mode by updating preprocessor conditions, extending the Instance class, and incorporating new OTNS functions. Key changes include:

  • Updating preprocessor guards in multiple files to include OPENTHREAD_RADIO.
  • Adding a new EmitTransmit function with its corresponding implementation.
  • Modifying Instance construction to instantiate an mOtns member and updating the build to include otns.cpp.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/core/utils/otns.hpp Updated preprocessor conditions and reordered includes; added EmitTransmit declaration.
src/core/utils/otns.cpp Updated preprocessor conditions; added implementation for EmitTransmit and moved OTNS‐guarded ping functions.
src/core/radio/radio.cpp Adjusted preprocessor guards for OTNS event emission in radio operations.
src/core/instance/instance.hpp Added and reconditioned the mOtns member with updated preprocessor guards.
src/core/instance/instance.cpp Updated constructor initialization for mOtns per revised preprocessor conditions.
src/core/CMakeLists.txt Added otns.cpp to the RCP build sources.

Comment thread src/core/utils/otns.hpp
Comment thread src/core/instance/instance.hpp Outdated
@size-report

size-report Bot commented Jun 25, 2025

Copy link
Copy Markdown

Size Report of OpenThread

Merging #11637 into main(3aab10a).

name branch text data bss total
ot-cli-ftd main 477984 860 66428 545272
#11637 477984 860 66428 545272
+/- 0 0 0 0
ot-ncp-ftd main 443532 764 61648 505944
#11637 443532 764 61648 505944
+/- 0 0 0 0
libopenthread-ftd.a main 245010 95 40206 285311
#11637 245010 95 40206 285311
+/- 0 0 0 0
libopenthread-cli-ftd.a main 60743 0 8083 68826
#11637 60743 0 8083 68826
+/- 0 0 0 0
libopenthread-ncp-ftd.a main 32931 0 5924 38855
#11637 32931 0 5924 38855
+/- 0 0 0 0
ot-cli-mtd main 371000 764 50908 422672
#11637 371000 764 50908 422672
+/- 0 0 0 0
ot-ncp-mtd main 351932 764 46152 398848
#11637 351932 764 46152 398848
+/- 0 0 0 0
libopenthread-mtd.a main 163641 0 24710 188351
#11637 163641 0 24710 188351
+/- 0 0 0 0
libopenthread-cli-mtd.a main 41134 0 8059 49193
#11637 41134 0 8059 49193
+/- 0 0 0 0
libopenthread-ncp-mtd.a main 25581 0 5924 31505
#11637 25581 0 5924 31505
+/- 0 0 0 0
ot-cli-ftd-br main 575048 868 133924 709840
#11637 575048 868 133924 709840
+/- 0 0 0 0
libopenthread-ftd-br.a main 345957 100 107670 453727
#11637 345957 100 107670 453727
+/- 0 0 0 0
libopenthread-cli-ftd-br.a main 75862 0 8115 83977
#11637 75862 0 8115 83977
+/- 0 0 0 0
ot-rcp main 63184 568 20804 84556
#11637 63184 568 20804 84556
+/- 0 0 0 0
libopenthread-rcp.a main 9932 0 5060 14992
#11637 9932 0 5060 14992
+/- 0 0 0 0
libopenthread-radio.a main 19269 0 238 19507
#11637 19269 0 238 19507
+/- 0 0 0 0

@abtink abtink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @francoismichel for the PR. Looks good overall.

Couple of smaller suggestions below:

Comment thread src/core/radio/radio.cpp Outdated
Comment thread src/core/utils/otns.hpp Outdated
Comment thread src/core/radio/radio.cpp

@EskoDijk EskoDijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @francoismichel ! Agree with Abtin's comments. Looks good for the rest.

@github-actions

Copy link
Copy Markdown

Size Report of OpenThread

Merging PR into main

name branch text data bss total
ot-cli-ftd 3019d3c 478472 860 66540 545872
4ded380 478488 860 66540 545888
+/- +16 +0 +0 +16
ot-ncp-ftd 3019d3c 444332 764 61784 506880
4ded380 444348 764 61784 506896
+/- +16 +0 +0 +16
ot-cli-mtd 3019d3c 371424 764 51004 423192
4ded380 371440 764 51004 423208
+/- +16 +0 +0 +16
ot-ncp-mtd 3019d3c 352556 764 46272 399592
4ded380 352572 764 46272 399608
+/- +16 +0 +0 +16
ot-cli-ftd-br 3019d3c 575944 868 134052 710864
4ded380 575944 868 134052 710864
+/- +0 +0 +0 +0
ot-rcp 3019d3c 63120 568 20804 84492
4ded380 63120 568 20804 84492
+/- +0 +0 +0 +0
Library files
name branch text data bss total
libopenthread-ftd.a 3019d3c 245716 95 40318 286129
4ded380 245728 95 40318 286141
+/- +12 +0 +0 +12
libopenthread-cli-ftd.a 3019d3c 60743 0 8083 68826
4ded380 60743 0 8083 68826
+/- +0 +0 +0 +0
libopenthread-ncp-ftd.a 3019d3c 33257 0 5948 39205
4ded380 33257 0 5948 39205
+/- +0 +0 +0 +0
libopenthread-mtd.a 3019d3c 164253 0 24806 189059
4ded380 164265 0 24806 189071
+/- +12 +0 +0 +12
libopenthread-cli-mtd.a 3019d3c 41134 0 8059 49193
4ded380 41134 0 8059 49193
+/- +0 +0 +0 +0
libopenthread-ncp-mtd.a 3019d3c 25785 0 5948 31733
4ded380 25785 0 5948 31733
+/- +0 +0 +0 +0
libopenthread-ftd-br.a 3019d3c 346971 100 107798 454869
4ded380 346983 100 107798 454881
+/- +12 +0 +0 +12
libopenthread-cli-ftd-br.a 3019d3c 75982 0 8115 84097
4ded380 75982 0 8115 84097
+/- +0 +0 +0 +0
libopenthread-rcp.a 3019d3c 9932 0 5060 14992
4ded380 9932 0 5060 14992
+/- +0 +0 +0 +0
libopenthread-radio.a 3019d3c 19383 0 238 19621
4ded380 19383 0 238 19621
+/- +0 +0 +0 +0

@francoismichel
francoismichel force-pushed the upstream-to-openthread branch from 51154b3 to 9640cc8 Compare July 19, 2025 14:14
@github-actions

github-actions Bot commented Jul 19, 2025

Copy link
Copy Markdown

Merging #11637 into main

name branch text data bss total
ot-cli-ftd 3e9c728 479848 860 66580 547288
036b224 479848 860 66580 547288
+/- +0 +0 +0 +0
ot-ncp-ftd 3e9c728 446252 764 61824 508840
036b224 446252 764 61824 508840
+/- +0 +0 +0 +0
ot-cli-mtd 3e9c728 372512 764 51052 424328
036b224 372512 764 51052 424328
+/- +0 +0 +0 +0
ot-ncp-mtd 3e9c728 353580 764 46320 400664
036b224 353580 764 46320 400664
+/- +0 +0 +0 +0
ot-cli-ftd-br 3e9c728 582528 868 136404 719800
036b224 582528 868 136404 719800
+/- +0 +0 +0 +0
ot-rcp 3e9c728 63136 568 20804 84508
036b224 63136 568 20804 84508
+/- +0 +0 +0 +0
Library files
name branch text data bss total
libopenthread-ftd.a 3e9c728 246946 95 40358 287399
036b224 246946 95 40358 287399
+/- +0 +0 +0 +0
libopenthread-cli-ftd.a 3e9c728 61027 0 8083 69110
036b224 61027 0 8083 69110
+/- +0 +0 +0 +0
libopenthread-ncp-ftd.a 3e9c728 33581 0 5948 39529
036b224 33581 0 5948 39529
+/- +0 +0 +0 +0
libopenthread-mtd.a 3e9c728 165267 0 24854 190121
036b224 165267 0 24854 190121
+/- +0 +0 +0 +0
libopenthread-cli-mtd.a 3e9c728 41251 0 8059 49310
036b224 41251 0 8059 49310
+/- +0 +0 +0 +0
libopenthread-ncp-mtd.a 3e9c728 25805 0 5948 31753
036b224 25805 0 5948 31753
+/- +0 +0 +0 +0
libopenthread-ftd-br.a 3e9c728 350899 100 110150 461149
036b224 350899 100 110150 461149
+/- +0 +0 +0 +0
libopenthread-cli-ftd-br.a 3e9c728 78917 0 8115 87032
036b224 78917 0 8115 87032
+/- +0 +0 +0 +0
libopenthread-rcp.a 3e9c728 9944 0 5060 15004
036b224 9944 0 5060 15004
+/- +0 +0 +0 +0
libopenthread-radio.a 3e9c728 19411 0 238 19649
036b224 19411 0 238 19649
+/- +0 +0 +0 +0

@francoismichel

Copy link
Copy Markdown
Contributor Author

I applied Abtin and Esko's suggestions and rebase the branch. Let me know what you think!

@EskoDijk EskoDijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks ok now - the CLA check looks to be failing, so @francoismichel you may need to check if you need to/can sign the CLA?

@abtink abtink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @francoismichel

@codecov

codecov Bot commented Jul 26, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.47826% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.29%. Comparing base (3e9c728) to head (8fdd67f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/core/utils/otns.cpp 42.10% 11 Missing ⚠️
src/core/instance/instance.hpp 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11637      +/-   ##
==========================================
- Coverage   75.91%   72.29%   -3.62%     
==========================================
  Files         658      656       -2     
  Lines       95991    96313     +322     
==========================================
- Hits        72867    69630    -3237     
- Misses      23124    26683    +3559     
Files with missing lines Coverage Δ
src/core/instance/instance.cpp 77.77% <100.00%> (-8.34%) ⬇️
src/core/radio/radio.cpp 83.69% <ø> (-2.18%) ⬇️
src/core/utils/otns.hpp 100.00% <ø> (ø)
src/core/instance/instance.hpp 17.89% <33.33%> (-78.59%) ⬇️
src/core/utils/otns.cpp 76.66% <42.10%> (ø)

... and 247 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@francoismichel
francoismichel force-pushed the upstream-to-openthread branch 2 times, most recently from 9b52bb2 to 30b2f85 Compare September 22, 2025 23:27
@francoismichel

Copy link
Copy Markdown
Contributor Author

I'm rebasing and doing a few tests to ensure everything works.
I'll let you know once I've verified that everything is fine and we can then go on. :-)

@francoismichel
francoismichel force-pushed the upstream-to-openthread branch 2 times, most recently from 213fc73 to 29fb6d9 Compare September 26, 2025 21:16
@francoismichel

Copy link
Copy Markdown
Contributor Author

@jwhui I confirm that it works well on a Linux VM. Could you re-trigger the tests here ? It seems I don't have the right to re-trigger the tests myself.

@jwhui

jwhui commented Sep 30, 2025

Copy link
Copy Markdown
Member

/gemini review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/core/utils/otns.hpp
Comment thread src/core/utils/otns.cpp Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request correctly enables OpenThread Network Simulator (OTNS) support for the Radio Co-processor (RCP) build configuration. The changes primarily involve refactoring preprocessor directives to conditionally compile OTNS-related code, moving MTD/FTD-specific functionalities into their own compilation guards, and ensuring that RCP builds include the necessary components for OTNS integration. The code modifications are clean, logical, and effectively achieve the stated goal. I have a couple of minor suggestions to improve code consistency.

Comment thread src/core/utils/otns.cpp Outdated
Comment thread src/core/utils/otns.hpp Outdated

@abtink abtink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me. Thanks @francoismichel
Couple of smaller suggestions belwo:

Comment thread src/core/instance/instance.hpp
Comment thread src/core/utils/otns.hpp Outdated
Comment thread src/core/utils/otns.hpp Outdated
@francoismichel
francoismichel force-pushed the upstream-to-openthread branch from 4989e21 to e4b83e8 Compare October 2, 2025 17:56
Comment thread src/core/CMakeLists.txt Outdated

@EskoDijk EskoDijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the updates!

This commit allows compiling the OpenThread RCP in OTNS mode.
This allows OTBR to attach seamlessly to OTNS.

 * Add the mOtns attribute to Instance::Instance when compiled
   with OPENTHREAD_RADIO=1
 * Add src/core/utils/otns.cpp to the RCP build.
   Only the necessary functions are compiled in RCP mode.
   Other functions such as EmitPingRequest and EmitPingReply
   that require IPv6 stack support are not compiled in RCP
   and are therefore moved into adequate
   `#if OPENTHREAD_MTD || OPENTHREAD_FTD` guards.
 * Ensure the RCP emits the needed events in src/core/radio/radio.cpp
   when compiled with OTNS support.
@francoismichel
francoismichel force-pushed the upstream-to-openthread branch from 4a1ec8f to 8fdd67f Compare October 3, 2025 15:08

@jwhui jwhui left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! 👍🏼

@jwhui
jwhui merged commit 6d93c7f into openthread:main Oct 3, 2025
111 of 112 checks passed
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.

5 participants