Skip to content

Conversation

@ludvigsj
Copy link
Contributor

@ludvigsj ludvigsj commented Oct 17, 2025

Adds functionality to filter out duplicate entries in the
Bridged Subnets List message.

This is done by iterating through the part of the table we have already
processed, to check if this is the first time we see a given key pair or
not.

Also, adds a babblesim test that checks

  • That duplicate net key index pairs are filtered out in the bridged
    subnets list.
  • That indexing into the filtered list works as expected (indexing
    happens into the already filtered list, not the full bridging table)

@zephyrbot zephyrbot added area: Bluetooth Mesh area: Bluetooth area: Tests Issues related to a particular existing or missing test platform: nRF BSIM Nordic Semiconductors, nRF BabbleSim labels Oct 17, 2025
@ludvigsj ludvigsj force-pushed the develop/brg_remove_subnets_duplicates_no_buf branch from 9e2fa29 to edda1ac Compare October 17, 2025 07:19
@ludvigsj
Copy link
Contributor Author

ludvigsj commented Oct 17, 2025

Quick explanation here

I considered several solutions:

  1. The current solution, just iterating through the (start of the) table again to identify duplicates.
    • $O(n^2)$ time. Creates an overhead of < 10ms on nRF52840 in the worst case, with a maxed out table (255 entries) where all subnet pairs are unique. Goes above 100ms when close to 1000 lines in the table (which is currently not allowed by Kconfig)
  2. Store the already seen pairs in a separate buffer/list
    • Will require 3 bytes to store each unique pair, meaning potentially 768 bytes of buffer if the table size is maxed out.
    • Does not give any advantage in the worst case where every pair is unique - in this case it will just become a copy of the bridging table and the runtime will be the same as solution 1.
    • Might give a small runtime advantage for long tables with a small/medium number of unique pairs.
      • Note: Also identical to solution 1 if there is only one unique pair (meaning every idx1 in the table is identical and every idx2 in the table is identical). They are both $O(n)$ in this best case.
  3. Sort the bridging table on insertion.
    • This allows $O(n)$ time to construct the filtered list, compared to $O(n^2)$ for the two other solutions.
    • If we want to support >1000 entries, I believe this is the solution, it is performant enough that the table size is limited by available RAM before we see slowdown.
    • I have not implemented this since we currently only support 255 entries, to save complexity in the code change.

Copy link
Contributor

@alxelax alxelax left a comment

Choose a reason for hiding this comment

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

In general, it looks Ok to me apart test scenario. Could you elaborate, how do you check start index? I would like to see that filtering exactly works.

@ludvigsj ludvigsj requested a review from alxelax October 20, 2025 10:27
alxelax
alxelax previously approved these changes Oct 20, 2025
Copy link
Contributor

@PavelVPV PavelVPV left a comment

Choose a reason for hiding this comment

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

LGTM, but I'd add few more entries into subnet_pairs to check filtering.

PavelVPV
PavelVPV previously approved these changes Oct 20, 2025
Copy link
Contributor

@PavelVPV PavelVPV left a comment

Choose a reason for hiding this comment

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

Approving. Up to you if you want to fix the minor comments.

This commit adds functionality to filter out duplicate entries in the
Bridged Subnets List message.

This is done by iterating through the part of the table we have already
processed, to check if this is the first time we see a given key pair or
not.

Signed-off-by: Ludvig Jordet <[email protected]>
This adds a babblesim test that checks

* That duplicate net key index pairs are filtered out in the bridged
  subnets list.
* That indexing into the filtered list works as expected (indexing
  happens into the already filtered list, not the full bridging table)

Signed-off-by: Ludvig Jordet <[email protected]>
@ludvigsj ludvigsj dismissed stale reviews from PavelVPV and alxelax via 64a8727 October 20, 2025 12:48
@ludvigsj ludvigsj force-pushed the develop/brg_remove_subnets_duplicates_no_buf branch from edda1ac to 64a8727 Compare October 20, 2025 12:48
@ludvigsj ludvigsj requested review from PavelVPV and alxelax October 20, 2025 12:48
@ludvigsj
Copy link
Contributor Author

Updated with Pavels requested style changes

@sonarqubecloud
Copy link

@jhedberg jhedberg merged commit c49e3fe into zephyrproject-rtos:main Oct 21, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth Mesh area: Bluetooth area: Tests Issues related to a particular existing or missing test platform: nRF BSIM Nordic Semiconductors, nRF BabbleSim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants