Skip to content

[mle] introduce Attacher class - #11835

Merged
jwhui merged 1 commit into
openthread:mainfrom
abtink:mle/attacher-2
Aug 21, 2025
Merged

[mle] introduce Attacher class#11835
jwhui merged 1 commit into
openthread:mainfrom
abtink:mle/attacher-2

Conversation

@abtink

@abtink abtink commented Aug 20, 2025

Copy link
Copy Markdown
Member

This commit introduces a new Mle::Attacher class to encapsulate all logic and state related to the device attach process.

This change moves the attach state machine, parent candidate management, attach timer, and message handling for Parent Request, Parent Response, Child ID Request, and Child ID Response from Mle into the new nested Attacher class.

This refactoring improves code organization and modularity by separating the attach logic from the main Mle class.


This is resubmission of #11831.

This commit introduces a new `Mle::Attacher` class to encapsulate all
logic and state related to the device attach process.

This change moves the attach state machine, parent candidate
management, attach timer, and message handling for Parent Request,
Parent Response, Child ID Request, and Child ID Response from `Mle`
into the new nested `Attacher` class.

This refactoring improves code organization and modularity by
separating the attach logic from the main `Mle` class.

@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 @abtink, 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 Mle module by extracting the entire device attachment process into a dedicated Attacher class. This change aims to improve the overall architecture by centralizing the complex attachment logic, thereby enhancing modularity and maintainability. The Mle class now acts as a high-level orchestrator, delegating attachment-specific tasks to the new Attacher component, which encapsulates all related state and operations.

Highlights

  • New Attacher Class: A new Mle::Attacher class has been introduced to centralize all logic and state related to the device attachment process.
  • Logic and State Migration: The attach state machine, parent candidate management, attach timer, and message handling for Parent Request, Parent Response, Child ID Request, and Child ID Response have been moved from the Mle class into the new Attacher class.
  • Delegation of Responsibilities: The Mle class now delegates all attach-related operations to its mAttacher member, significantly reducing its complexity and improving separation of concerns.
  • Improved Code Structure: This refactoring enhances code organization and modularity, making the codebase easier to understand, maintain, and extend.
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 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 introduces a new Mle::Attacher class to encapsulate the logic and state related to the device attach process. This is a significant refactoring that moves the attach state machine, parent candidate management, attach timer, and related message handling from the Mle class into the new nested Attacher class. The changes improve code organization and modularity by separating the attach logic from the main Mle class. The refactoring has been done carefully and consistently across all modified files. The new Attacher class is well-defined, and the delegation of responsibilities from Mle to Attacher appears correct. The logic from the original implementation seems to be preserved. Overall, this is a high-quality refactoring that improves the codebase.

@jwhui
jwhui requested a review from Copilot August 20, 2025 21:36
@github-actions

Copy link
Copy Markdown

Merging #11835 into main

name branch text data bss total
ot-cli-ftd 364bbf5 479208 860 66556 546624
577e223 479448 860 66548 546856
+/- +240 +0 -8 +232
ot-ncp-ftd 364bbf5 444908 764 61800 507472
577e223 445164 764 61792 507720
+/- +256 +0 -8 +248
ot-cli-mtd 364bbf5 372048 764 51036 423848
577e223 372304 764 51020 424088
+/- +256 +0 -16 +240
ot-ncp-mtd 364bbf5 353148 764 46304 400216
577e223 353404 764 46288 400456
+/- +256 +0 -16 +240
ot-cli-ftd-br 364bbf5 579184 868 135724 715776
577e223 579480 868 135716 716064
+/- +296 +0 -8 +288
ot-rcp 364bbf5 63136 568 20804 84508
577e223 63136 568 20804 84508
+/- +0 +0 +0 +0
Library files
name branch text data bss total
libopenthread-ftd.a 364bbf5 246382 95 40334 286811
577e223 246640 95 40326 287061
+/- +258 +0 -8 +250
libopenthread-cli-ftd.a 364bbf5 60843 0 8083 68926
577e223 60843 0 8083 68926
+/- +0 +0 +0 +0
libopenthread-ncp-ftd.a 364bbf5 33257 0 5948 39205
577e223 33257 0 5948 39205
+/- +0 +0 +0 +0
libopenthread-mtd.a 364bbf5 164877 0 24838 189715
577e223 165145 0 24822 189967
+/- +268 +0 -16 +252
libopenthread-cli-mtd.a 364bbf5 41134 0 8059 49193
577e223 41134 0 8059 49193
+/- +0 +0 +0 +0
libopenthread-ncp-mtd.a 364bbf5 25785 0 5948 31733
577e223 25785 0 5948 31733
+/- +0 +0 +0 +0
libopenthread-ftd-br.a 364bbf5 349255 100 109470 458825
577e223 349545 100 109462 459107
+/- +290 +0 -8 +282
libopenthread-cli-ftd-br.a 364bbf5 77278 0 8115 85393
577e223 77278 0 8115 85393
+/- +0 +0 +0 +0
libopenthread-rcp.a 364bbf5 9932 0 5060 14992
577e223 9932 0 5060 14992
+/- +0 +0 +0 +0
libopenthread-radio.a 364bbf5 19423 0 238 19661
577e223 19423 0 238 19661
+/- +0 +0 +0 +0

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 introduces a new Mle::Attacher class to encapsulate all logic and state related to the device attach process. It moves the attach state machine, parent candidate management, attach timer, and message handling for Parent Request, Parent Response, Child ID Request, and Child ID Response from the Mle class into the new nested Attacher class.

Key changes include:

  • Creation of a nested Attacher class within Mle with its own state management and methods
  • Refactoring of attach-related methods and state variables from Mle to Attacher
  • Updates to method signatures and access patterns throughout the codebase

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/core/thread/mle.hpp Adds the new nested Attacher class definition and updates method signatures for attach-related functionality
src/core/thread/mle.cpp Moves attach logic implementation from Mle class to the new Attacher class
src/core/thread/mle_ftd.cpp Updates FTD-specific code to use the new Attacher class methods instead of direct Mle methods

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

@codecov

codecov Bot commented Aug 20, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.34973% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.97%. Comparing base (364bbf5) to head (9992a8e).

Files with missing lines Patch % Lines
src/core/thread/mle.cpp 93.33% 11 Missing ⚠️
src/core/thread/mle.hpp 81.81% 2 Missing ⚠️
src/core/thread/mle_ftd.cpp 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11835      +/-   ##
==========================================
+ Coverage   69.54%   73.97%   +4.42%     
==========================================
  Files         622      644      +22     
  Lines       94874    99935    +5061     
==========================================
+ Hits        65981    73923    +7942     
+ Misses      28893    26012    -2881     
Files with missing lines Coverage Δ
src/core/thread/mle_ftd.cpp 87.63% <85.71%> (+5.73%) ⬆️
src/core/thread/mle.hpp 89.78% <81.81%> (+0.71%) ⬆️
src/core/thread/mle.cpp 91.09% <93.33%> (+3.54%) ⬆️

... and 355 files with indirect coverage changes

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

@jwhui jwhui changed the title [mle] introduce Attacher class. [mle] introduce Attacher class Aug 21, 2025
@jwhui
jwhui merged commit 64e285b into openthread:main Aug 21, 2025
118 of 120 checks passed
abtink added a commit to abtink/openthread that referenced this pull request Aug 21, 2025
This commit improves the organization of `mle.cpp` by grouping all
`Attacher` method definitions together.

When the `Attacher` class was introduced in openthread#11835, its method
definitions were intentionally kept in their previous order to
minimize the `git diff` for easier review. This resulted in the
`Attacher` methods being interleaved with other `Mle` methods.

This commit acts as a follow-up to rearrange the file and group all
`Attacher` methods into a dedicated section for better readability
and organization.

No logic changes are included in this commit.
jwhui pushed a commit that referenced this pull request Aug 22, 2025
This commit improves the organization of `mle.cpp` by grouping all
`Attacher` method definitions together.

When the `Attacher` class was introduced in #11835, its method
definitions were intentionally kept in their previous order to
minimize the `git diff` for easier review. This resulted in the
`Attacher` methods being interleaved with other `Mle` methods.

This commit acts as a follow-up to rearrange the file and group all
`Attacher` methods into a dedicated section for better readability
and organization.

No logic changes are included in this commit.
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