Skip to content

[network-diag] simplify ChildTableTlv generation and parsing - #12712

Merged
jwhui merged 1 commit into
openthread:mainfrom
abtink:netdiag/child-table-entry
Mar 20, 2026
Merged

[network-diag] simplify ChildTableTlv generation and parsing#12712
jwhui merged 1 commit into
openthread:mainfrom
abtink:netdiag/child-table-entry

Conversation

@abtink

@abtink abtink commented Mar 17, 2026

Copy link
Copy Markdown
Member

This commit updates ChildTableTlvEntry to better support the packing and parsing of child entries in a ChildTableTlv. It introduces an InitFrom() method to encode an entry directly from a Child object, and a Parse() method to extract values into a ParseInfo struct, improving modularity and simplifying usage.

Additionally, it consolidates the logic for calculating the timeout exponent and decoding it back to a timeout value directly within the ChildTableTlvEntry class. It also introduces ParseChildTable() in NetworkDiagnostic::Client to clean up the child table parsing loop.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly refactors the handling of ChildTableTlv entries within the network diagnostic module. By centralizing encoding and decoding logic into the ChildTableTlvEntry class and introducing a dedicated parsing function, the changes improve code modularity, simplify usage, and enhance readability for generating and interpreting child table information.

Highlights

  • Refactored ChildTableTlvEntry: The ChildTableTlvEntry class was updated to centralize the logic for packing and parsing child entries, improving code organization and maintainability.
  • New InitFrom() and Parse() methods: Introduced InitFrom() to encode an entry directly from a Child object and Parse() to extract values into a ParseInfo struct, enhancing modularity and simplifying usage.
  • Consolidated Timeout Logic: The calculation of the timeout exponent and its decoding back to a timeout value are now handled directly within the ChildTableTlvEntry class, centralizing related functionality.
  • Dedicated ParseChildTable() function: A new ParseChildTable() method was added to NetworkDiagnostic::Client to clean up and centralize child table parsing logic, making the code more readable and easier to manage.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/core/thread/network_diagnostic.cpp
    • Simplified Server::AppendChildTable by utilizing the new ChildTableTlvEntry::InitFrom method.
    • Introduced Client::ParseChildTable to encapsulate child table parsing logic.
    • Updated Client::GetNextDiagTlv to call the new Client::ParseChildTable for Tlv::kChildTable processing.
  • src/core/thread/network_diagnostic.hpp
    • Added a typedef for otNetworkDiagChildTable as ChildTable.
    • Declared the new static method Client::ParseChildTable.
  • src/core/thread/network_diagnostic_tlvs.cpp
    • Implemented ChildTableTlvEntry::InitFrom to initialize an entry from a Child object.
    • Implemented ChildTableTlvEntry::DetermineExponentFromTimeout to calculate the timeout exponent.
    • Implemented ChildTableTlvEntry::DetermineTimeoutFromExponent to convert an exponent back to a timeout.
    • Implemented ChildTableTlvEntry::Parse to extract values into a ParseInfo struct.
  • src/core/thread/network_diagnostic_tlvs.hpp
    • Renamed ChildTableEntry to ChildTableTlvEntry to clarify its purpose.
    • Refactored ChildTableTlvEntry to include InitFrom, Parse, DetermineTimeoutFromExponent, and DetermineExponentFromTimeout methods.
    • Replaced individual getter/setter methods with the new InitFrom and Parse interface.
    • Updated internal bitfield masks and member names for clarity.
  • src/core/utils/mesh_diag.cpp
    • Modified MeshDiag::ChildIterator::GetNextChildInfo to use the refactored ChildTableTlvEntry and its Parse method for retrieving child information.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

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

This pull request provides a good refactoring of the ChildTableTlv handling. The introduction of ChildTableTlvEntry::InitFrom() and ChildTableTlvEntry::Parse() methods effectively encapsulates the encoding and decoding logic, improving modularity. The new NetworkDiagnostic::Client::ParseChildTable() helper function further cleans up the parsing loop. The changes are well-implemented and improve code readability and maintainability.

@github-actions

github-actions Bot commented Mar 17, 2026

Copy link
Copy Markdown

Merging #12712 into main

name branch text data bss total
ot-cli-ftd aa2437a 482208 860 66540 549608
0a999ce 482240 860 66540 549640
+/- +32 +0 +0 +32
ot-ncp-ftd aa2437a 448100 764 61776 510640
0a999ce 448148 764 61776 510688
+/- +48 +0 +0 +48
ot-cli-mtd aa2437a 374880 764 50972 426616
0a999ce 374880 764 50972 426616
+/- +0 +0 +0 +0
ot-ncp-mtd aa2437a 356012 764 46240 403016
0a999ce 356012 764 46240 403016
+/- +0 +0 +0 +0
ot-cli-ftd-br aa2437a 598336 868 136596 735800
0a999ce 598368 868 136596 735832
+/- +32 +0 +0 +32
ot-rcp aa2437a 63328 568 20804 84700
0a999ce 63328 568 20804 84700
+/- +0 +0 +0 +0
Library files
name branch text data bss total
libopenthread-ftd.a aa2437a 249724 95 40319 290138
0a999ce 249754 95 40319 290168
+/- +30 +0 +0 +30
libopenthread-cli-ftd.a aa2437a 61746 0 8091 69837
0a999ce 61746 0 8091 69837
+/- +0 +0 +0 +0
libopenthread-ncp-ftd.a aa2437a 33581 0 5948 39529
0a999ce 33581 0 5948 39529
+/- +0 +0 +0 +0
libopenthread-mtd.a aa2437a 168508 0 24783 193291
0a999ce 168590 0 24783 193373
+/- +82 +0 +0 +82
libopenthread-cli-mtd.a aa2437a 41455 0 8059 49514
0a999ce 41455 0 8059 49514
+/- +0 +0 +0 +0
libopenthread-ncp-mtd.a aa2437a 25805 0 5948 31753
0a999ce 25805 0 5948 31753
+/- +0 +0 +0 +0
libopenthread-ftd-br.a aa2437a 366593 100 110335 477028
0a999ce 366619 100 110335 477054
+/- +26 +0 +0 +26
libopenthread-cli-ftd-br.a aa2437a 80953 0 8131 89084
0a999ce 80953 0 8131 89084
+/- +0 +0 +0 +0
libopenthread-rcp.a aa2437a 9944 0 5060 15004
0a999ce 9944 0 5060 15004
+/- +0 +0 +0 +0
libopenthread-radio.a aa2437a 19715 0 238 19953
0a999ce 19715 0 238 19953
+/- +0 +0 +0 +0

@codecov

codecov Bot commented Mar 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.41%. Comparing base (aa2437a) to head (9316d8e).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12712      +/-   ##
==========================================
- Coverage   76.38%   73.41%   -2.98%     
==========================================
  Files         696      698       +2     
  Lines       93522    96388    +2866     
==========================================
- Hits        71439    70761     -678     
- Misses      22083    25627    +3544     
Files with missing lines Coverage Δ
src/core/thread/network_diagnostic.cpp 78.63% <100.00%> (-0.37%) ⬇️
src/core/thread/network_diagnostic.hpp 81.81% <ø> (ø)
src/core/thread/network_diagnostic_tlvs.cpp 82.26% <100.00%> (+3.27%) ⬆️
src/core/thread/network_diagnostic_tlvs.hpp 97.67% <ø> (-0.61%) ⬇️
src/core/utils/mesh_diag.cpp 85.27% <100.00%> (+0.10%) ⬆️

... and 90 files with indirect coverage changes

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

@abtink
abtink force-pushed the netdiag/child-table-entry branch from d4fdcab to 54919b9 Compare March 18, 2026 00:17
This commit updates `ChildTableTlvEntry` to better support the packing
and parsing of child entries in a `ChildTableTlv`. It introduces an
`InitFrom()` method to encode an entry directly from a `Child`
object, and a `Parse()` method to extract values into a `ParseInfo`
struct, improving modularity and simplifying usage.

Additionally, it consolidates the logic for calculating the timeout
exponent and decoding it back to a timeout value directly within the
`ChildTableTlvEntry` class. It also introduces `ParseChildTable()` in
`NetworkDiagnostic::Client` to clean up the child table parsing
loop.
@abtink
abtink force-pushed the netdiag/child-table-entry branch from 54919b9 to 9316d8e Compare March 19, 2026 01:14
@abtink
abtink marked this pull request as ready for review March 19, 2026 01:19
@jwhui
jwhui merged commit 7b58719 into openthread:main Mar 20, 2026
109 of 110 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.

2 participants