Skip to content

[network-diag] introduce AnswerBuilder to manage answer messages - #12887

Merged
jwhui merged 1 commit into
openthread:mainfrom
abtink:netdaig/answer
Apr 17, 2026
Merged

[network-diag] introduce AnswerBuilder to manage answer messages#12887
jwhui merged 1 commit into
openthread:mainfrom
abtink:netdaig/answer

Conversation

@abtink

@abtink abtink commented Apr 14, 2026

Copy link
Copy Markdown
Member

This commit introduces AnswerBuilder class to track and manage Network Diagnostic answer messages. This class is used when the response to a query requires multiple CoAP answer messages. It automatically manages the inclusion of the Query ID and the Answer TLVs(providing message indexing and "more-to-follow" flags) in each allocated answer message, while maintaining all answer messages in a queue. The NetworkDiagnostic::Server is updated to use the AnswerBuilder, simplifying the logic for preparing and sending answers.

The AnswerBuilder class is added in a new header file network_diagnostic_types.hpp to allow for its reuse by other modules in the future.

@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 introduces a new AnswerBuilder utility class to handle the segmentation and management of Network Diagnostic answer messages. By centralizing the logic for tracking Query IDs, message indexing, and 'more-to-follow' flags, the change significantly simplifies the NetworkDiagnostic::Server implementation and provides a reusable component for future modules.

Highlights

  • Introduction of AnswerBuilder: Added the AnswerBuilder class to encapsulate the logic for managing and segmenting Network Diagnostic answer messages, improving code maintainability.
  • Message Queue Enhancement: Added MessageQueue::EnqueueAllFrom to efficiently transfer messages between queues, facilitating the management of segmented diagnostic responses.
  • Refactoring NetworkDiagnostic::Server: Updated NetworkDiagnostic::Server to utilize AnswerBuilder, which simplifies the preparation and transmission of diagnostic answers.

🧠 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.

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.

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.

@github-actions

github-actions Bot commented Apr 14, 2026

Copy link
Copy Markdown

Merging #12887 into main

name branch text data bss total
ot-cli-ftd 8a03257 483080 860 66540 550480
e307cfa 483144 860 66540 550544
+/- +64 +0 +0 +64
ot-ncp-ftd 8a03257 448916 764 61776 511456
e307cfa 448996 764 61776 511536
+/- +80 +0 +0 +80
ot-cli-mtd 8a03257 375184 764 50972 426920
e307cfa 375184 764 50972 426920
+/- +0 +0 +0 +0
ot-ncp-mtd 8a03257 356260 764 46240 403264
e307cfa 356260 764 46240 403264
+/- +0 +0 +0 +0
ot-cli-ftd-br 8a03257 599920 864 136732 737516
e307cfa 599984 864 136732 737580
+/- +64 +0 +0 +64
ot-rcp 8a03257 63344 568 20804 84716
e307cfa 63344 568 20804 84716
+/- +0 +0 +0 +0
Library files
name branch text data bss total
libopenthread-ftd.a 8a03257 251045 95 40319 291459
e307cfa 251111 95 40319 291525
+/- +66 +0 +0 +66
libopenthread-cli-ftd.a 8a03257 61765 0 8091 69856
e307cfa 61765 0 8091 69856
+/- +0 +0 +0 +0
libopenthread-ncp-ftd.a 8a03257 33583 0 5948 39531
e307cfa 33583 0 5948 39531
+/- +0 +0 +0 +0
libopenthread-mtd.a 8a03257 169389 0 24783 194172
e307cfa 169649 0 24783 194432
+/- +260 +0 +0 +260
libopenthread-cli-mtd.a 8a03257 41462 0 8059 49521
e307cfa 41462 0 8059 49521
+/- +0 +0 +0 +0
libopenthread-ncp-mtd.a 8a03257 25807 0 5948 31755
e307cfa 25807 0 5948 31755
+/- +0 +0 +0 +0
libopenthread-ftd-br.a 8a03257 368891 99 110471 479461
e307cfa 368957 99 110471 479527
+/- +66 +0 +0 +66
libopenthread-cli-ftd-br.a 8a03257 80972 0 8131 89103
e307cfa 80972 0 8131 89103
+/- +0 +0 +0 +0
libopenthread-rcp.a 8a03257 9946 0 5060 15006
e307cfa 9946 0 5060 15006
+/- +0 +0 +0 +0
libopenthread-radio.a 8a03257 19859 0 238 20097
e307cfa 19859 0 238 20097
+/- +0 +0 +0 +0

@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 refactors the Network Diagnostic answer generation logic by introducing a new AnswerBuilder class to manage message allocation, segmentation, and TLV insertion. It also adds a MessageQueue::EnqueueAllFrom utility to the core message library to facilitate moving messages between queues. The review feedback suggests initializing the mQueryId member in the AnswerBuilder constructor to ensure defined behavior if the Query ID TLV is not found in the request.

Comment thread src/core/thread/network_diagnostic_types.cpp
@codecov

codecov Bot commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.16981% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.79%. Comparing base (8a03257) to head (e49a966).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/core/thread/network_diagnostic_types.cpp 90.90% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12887      +/-   ##
==========================================
- Coverage   74.11%   73.79%   -0.33%     
==========================================
  Files         695      698       +3     
  Lines       95981    96448     +467     
==========================================
+ Hits        71139    71169      +30     
- Misses      24842    25279     +437     
Files with missing lines Coverage Δ
src/core/common/message.cpp 94.60% <100.00%> (+0.13%) ⬆️
src/core/common/message.hpp 93.42% <ø> (+10.18%) ⬆️
src/core/thread/network_diagnostic.cpp 67.69% <100.00%> (-10.94%) ⬇️
src/core/thread/network_diagnostic.hpp 66.66% <ø> (-15.16%) ⬇️
src/core/thread/network_diagnostic_types.hpp 100.00% <100.00%> (ø)
tests/unit/test_message_queue.cpp 100.00% <100.00%> (ø)
src/core/thread/network_diagnostic_types.cpp 90.90% <90.90%> (ø)

... and 168 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 marked this pull request as ready for review April 14, 2026 20:56
@abtink
abtink force-pushed the netdaig/answer branch 2 times, most recently from 44aa797 to dd87c24 Compare April 14, 2026 21:39
@jwhui

jwhui commented Apr 15, 2026

Copy link
Copy Markdown
Member

/gemini review

@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 refactors the Network Diagnostic answer generation logic by introducing a new AnswerBuilder class, which encapsulates the management of CoAP answer messages and TLVs. Additionally, it adds a MessageQueue::EnqueueAllFrom method to the core message library to allow moving all messages between queues, supported by new unit tests. The review feedback suggests adding a defensive check in the EnqueueAllFrom method to prevent potential circular references if a queue is enqueued into itself.

Comment thread src/core/common/message.cpp
This commit introduces `AnswerBuilder` class to track and manage
Network Diagnostic answer messages. This class is used when the
response to a query requires multiple CoAP answer messages. It
automatically manages the inclusion of the Query ID and the Answer
TLVs(providing message indexing and "more-to-follow" flags) in each
allocated answer message, while maintaining all answer messages in a
queue. The `NetworkDiagnostic::Server` is updated to use the
`AnswerBuilder`, simplifying the logic for preparing and sending
answers.

The `AnswerBuilder` class is added in a new header file
`network_diagnostic_types.hpp` to allow for its reuse by other
modules in the future.
@jwhui
jwhui merged commit 7eb59f7 into openthread:main Apr 17, 2026
132 of 135 checks passed
malano77 pushed a commit to malano77/openthread that referenced this pull request Apr 20, 2026
…penthread#12887)

This commit introduces `AnswerBuilder` class to track and manage
Network Diagnostic answer messages. This class is used when the
response to a query requires multiple CoAP answer messages. It
automatically manages the inclusion of the Query ID and the Answer
TLVs(providing message indexing and "more-to-follow" flags) in each
allocated answer message, while maintaining all answer messages in a
queue. The `NetworkDiagnostic::Server` is updated to use the
`AnswerBuilder`, simplifying the logic for preparing and sending
answers.

The `AnswerBuilder` class is added in a new header file
`network_diagnostic_types.hpp` to allow for its reuse by other
modules in the future.
@AlixBa

AlixBa commented Apr 20, 2026

Copy link
Copy Markdown

@jwhui could this break ot-br-posix rest API?

{
	"data":	{
		"id":	"90087999-7913-4a2c-b13f-6e0e3f3ce674",
		"type":	"getNetworkDiagnosticTask",
		"attributes":	{
			"destination":	"92844e00385b03db",
			"destinationType":	"extended",
			"types":	["extAddress", "rloc16", "ipv6Addresses", "childTable", "routerNeighbors"],
			"status":	"completed",
			"created":	"2026-04-20T15:03:13+00:00"
		},
		"relationships":	{
			"result":	{
				"data":	{
					"type":	"diagnostics",
					"id":	""
				}
			}
		}
	}

here is what I get after pulling the new openthread:border-router:latest image.
id: "" on a successful response(?)

@abtink

abtink commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

@jwhui could this break ot-br-posix rest API?

{
 "data": {
 "id": "90087999-7913-4a2c-b13f-6e0e3f3ce674",
 "type": "getNetworkDiagnosticTask",
 "attributes": {
 "destination": "92844e00385b03db",

@AlixBa, it is very unlikely.

  • There are existing tests in OT that already validate all diagnostic behavior (and they run on every PR).
  • This PR is related to NetDiagAnswer, which is the answer to the NetDiagQuery TMF command (which is different from the NetDiagGet command).
  • The REST API typically uses otThreadSendDiagnosticGet (which then uses NetDiagGet and not NetDiagQuery).

@AlixBa

AlixBa commented Apr 21, 2026

Copy link
Copy Markdown

@abtink Thanks, I'll try to pinpoint then. I don't see any particular commit on ot-br-posix so I guess it's somewhere around here. I might not look at the right place though, haha.

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