sim: ADAPTIVE flood routing with density-based relay selection and TX power saving#2466
Open
Heilo27 wants to merge 1 commit intomeshcore-dev:mainfrom
Open
sim: ADAPTIVE flood routing with density-based relay selection and TX power saving#2466Heilo27 wants to merge 1 commit intomeshcore-dev:mainfrom
Heilo27 wants to merge 1 commit intomeshcore-dev:mainfrom
Conversation
…aving Adds a complete simulation harness for the MeshCore radio platform, including: ### ADAPTIVE routing strategy (sim/src/RoutingStrategies.h) Hash-based relay gate selects a deterministic subset of nodes to forward each flood, with relay percentage adapted to local neighbour density: - SPARSE (<=4 neighbours): 100% relay -- no redundancy to spare - MEDIUM (5-14): 25% relay - DENSE (>=15): 15% relay Selection uses hash(packet_seed XOR node_seed) with no coordination required. Different packets select different subsets for stochastic load balancing. Relay suppression: nodes cancel queued outbound TX if they overhear another node already relaying the same flood (matched by packet hash). ### DensityEstimator (sim/src/DensityEstimator.h) Passive sliding-window neighbour count from normal traffic -- no extra messages. Only counts direct senders (hop_count==1) over a configurable window (default 60s). Uses std::unordered_set for unique counting; no fixed-array cap. ### Adaptive TX power saving (sim/src/SimNode.h) power_save_enabled reduces TX power in DENSE/MEDIUM tiers: DENSE: configurable (default 10 dBm, saves 75% TX current vs 20 dBm) MEDIUM: configurable (default 14 dBm, saves 60% TX current) SPARSE: always full power -- every hop counts on marginal links Validated: 100% delivery maintained at -10dBm DENSE reduction. Energy savings ~35% radio total. TX power reduction also lowers area RF noise floor. ### Scenario suite (sim/scenarios/) scenario_adaptive: ADAPTIVE vs DEFAULT vs PATH_SNR_HYBRID comparison scenario_concurrent: 2-8 simultaneous flood sources scenario_longchain: 20-hop chains at marginal SNR scenario_mixed: ADAPTIVE + legacy DEFAULT interoperability scenario_dutycycle: EU 1% duty cycle enforcement validation scenario_relay_pct_sweep: grid sweep to find optimal DENSE%/MEDIUM% operating point scenario_txpower: TX power saving vs delivery rate vs energy trade-off ### Key empirical results FM50 ADAPTIVE vs DEFAULT: equal delivery rate, -65% airtime, -70% collisions CH20 (chain): ADAPTIVE = SPARSE throughout, identical to DEFAULT TX power MODERATE (-10dB): 100% delivery, -35% energy across all topologies Legacy interop: zero delivery regression with mixed firmware ### Bug fixes - DensityEstimator: replace seen[64] array with unordered_set (was capping at 64 neighbours) - SimBus::onTransmit: add len > 255 guard before memcpy into 255-byte buffer - SimNode p_forward gate: >= -> > (was silently dropping relays at p_forward=1.0) - SimNode TX power reset: remove redundant !power_save_enabled clause - scenario_concurrent: fix stale ConcurrentResult* pointer after vector reallocation - scenario_relay_pct_sweep: update TxCallback from 4-arg to 5-arg (tx_power_dbm) - scenario_adaptive: remove unused variable last_suppressed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a full native-C++ simulation harness for MeshCore, along with a new ADAPTIVE routing strategy that has been empirically validated across multiple topologies. Everything in the
sim/directory is simulation-only — no firmware code is touched.What's new
ADAPTIVE routing strategy (
sim/src/RoutingStrategies.h)Hash-based relay gate selects a deterministic subset of nodes to relay each flood, with the subset size adapted to local neighbour density:
Selection:
hash(packet_seed XOR node_seed) % 100 < relay_pctDensityEstimator (
sim/src/DensityEstimator.h)Passive neighbour density measurement from normal traffic — no extra protocol messages. Counts unique direct senders (hop_count == 1) over a 60-second sliding window. Thresholds are compile-time overridable.
Adaptive TX power saving (
sim/src/SimNode.h)Opt-in feature (
power_save_enabled). ADAPTIVE-selected relay nodes reduce TX power in dense areas:Motivation: at a high-density event (festival, conference), nodes running at full power 100% of the time waste battery and raise the local RF noise floor. Reducing power when you have 15+ neighbours: (a) saves battery, (b) shrinks interference radius via the LoRa capture effect, (c) doesn't hurt local delivery since nearby nodes still receive well above sensitivity.
Validated: 100% delivery maintained at MODERATE (-10 dBm DENSE) across all topologies tested.
Simulation infrastructure
sim/src/SimBus.hsim/src/SimNode.hsim/src/SimRadio.hsim/src/SimMetrics.hsim/src/SimRuntime.hChannel models available:
FullMeshModel,ChainModel,GridModel,PositionalModel.Scenario suite
scenario_adaptivescenario_concurrentscenario_longchainscenario_mixedscenario_dutycyclescenario_relay_pct_sweepscenario_txpowerKey empirical results
Bug fixes (found during development)
DensityEstimator: replacedseen[64]fixed array withstd::unordered_set— was silently capping unique neighbour count at 64SimBus::onTransmit: addedlen > 255guard beforememcpyinto 255-byte bufferSimNodep_forward gate:>=→>— was silently suppressing relays at exactlyp_forward=1.0Building
Requires a C++17 compiler. No dependencies beyond what's already in the repo (uses
lib/ed25519,deps/arduinolibs/Crypto).Not in this PR
This PR is simulation-only. The ADAPTIVE strategy would need firmware integration work (replacing the node_seed with a pub-key-prefix hash, hooking
getRetransmitDelay()) before it could run on hardware. That's a separate conversation — wanted to get the algorithm validated first.