From 5bd05a573b645a62b8f40d7cc1c16abc5dbef79b Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 27 Apr 2026 22:27:36 -0700 Subject: [PATCH] [nexus] dynamically sync radio range circles with simulator parameters (#12987) This commit exposes radio model parameters (path loss constant, exponent, and sensitivity) and the minimum link request margin from the Nexus simulator backend to the frontend. Changes in backend: - Expose constants in `RadioModel` and `Radio`. - Add `GetRadioParameters` RPC to `simulation.proto` and implement it in gRPC and WASM bindings. - Expose `OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN` and `OPENTHREAD_CONFIG_MLE_PARTITION_MERGE_MARGIN_MIN` via the new RPC. Changes in config: - Set `OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN` and `OPENTHREAD_CONFIG_MLE_PARTITION_MERGE_MARGIN_MIN` to 5 dB in `openthread-core-nexus-config.h`. This allows the frontend to calculate and render circles dynamically. --- tests/nexus/openthread-core-nexus-config.h | 2 ++ tests/nexus/platform/nexus_grpc.cpp | 14 ++++++++++++++ tests/nexus/platform/nexus_radio_model.cpp | 3 --- tests/nexus/platform/nexus_radio_model.hpp | 3 +++ tests/nexus/platform/nexus_wasm.cpp | 11 +++++++++++ tests/nexus/platform/simulation.proto | 14 ++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/nexus/openthread-core-nexus-config.h b/tests/nexus/openthread-core-nexus-config.h index c842e6367..10593bc86 100644 --- a/tests/nexus/openthread-core-nexus-config.h +++ b/tests/nexus/openthread-core-nexus-config.h @@ -109,6 +109,8 @@ #define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1 #define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1 #define OPENTHREAD_CONFIG_MLE_MAX_CHILDREN 128 +#define OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN 5 +#define OPENTHREAD_CONFIG_MLE_PARTITION_MERGE_MARGIN_MIN 5 #define OPENTHREAD_CONFIG_MLR_ENABLE 1 #define OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE 1 #define OPENTHREAD_CONFIG_MULTICAST_DNS_AUTO_ENABLE_ON_INFRA_IF 1 diff --git a/tests/nexus/platform/nexus_grpc.cpp b/tests/nexus/platform/nexus_grpc.cpp index f3ed98481..ddceedae5 100644 --- a/tests/nexus/platform/nexus_grpc.cpp +++ b/tests/nexus/platform/nexus_grpc.cpp @@ -44,6 +44,8 @@ #include "nexus_logging.hpp" #include "nexus_node.hpp" +#include "nexus_radio.hpp" +#include "nexus_radio_model.hpp" #include "simulation.grpc.pb.h" #include "common/clearable.hpp" #include "common/code_utils.hpp" @@ -269,6 +271,18 @@ public: return status; } + grpc::Status GetRadioParameters(grpc::ServerContext * /* aContext */, + const nexus::GetRadioParametersRequest * /* aRequest */, + nexus::GetRadioParametersResponse *aResponse) override + { + aResponse->set_path_loss_constant(RadioModel::kPathLossConstant); + aResponse->set_path_loss_exponent(RadioModel::kPathLossExponent); + aResponse->set_radio_sensitivity(Radio::kRadioSensitivity); + aResponse->set_mle_link_request_margin_min(OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN); + + return grpc::Status::OK; + } + private: GrpcServer *mServerPtr; }; diff --git a/tests/nexus/platform/nexus_radio_model.cpp b/tests/nexus/platform/nexus_radio_model.cpp index 068ab8cd9..25e6162fb 100644 --- a/tests/nexus/platform/nexus_radio_model.cpp +++ b/tests/nexus/platform/nexus_radio_model.cpp @@ -38,9 +38,6 @@ namespace Nexus { int16_t RadioModel::CalculateRssi(const Node &aTxNode, const Node &aRxNode) { - static constexpr double kPathLossConstant = 40.0; - static constexpr double kPathLossExponent = 20.0; - // Simple path loss model // RSSI = TxPower - PathLoss // PathLoss = kPathLossExponent * log10(distance) + kPathLossConstant diff --git a/tests/nexus/platform/nexus_radio_model.hpp b/tests/nexus/platform/nexus_radio_model.hpp index 6ef0578dc..22a18fec5 100644 --- a/tests/nexus/platform/nexus_radio_model.hpp +++ b/tests/nexus/platform/nexus_radio_model.hpp @@ -43,6 +43,9 @@ class Node; class RadioModel { public: + static constexpr double kPathLossConstant = 40.0; + static constexpr double kPathLossExponent = 20.0; + RadioModel(void) = delete; /** diff --git a/tests/nexus/platform/nexus_wasm.cpp b/tests/nexus/platform/nexus_wasm.cpp index a36d5ec86..4917685f9 100644 --- a/tests/nexus/platform/nexus_wasm.cpp +++ b/tests/nexus/platform/nexus_wasm.cpp @@ -46,6 +46,8 @@ #include "nexus_core.hpp" #include "nexus_node.hpp" +#include "nexus_radio.hpp" +#include "nexus_radio_model.hpp" #include "mac/mac.hpp" #include "thread/mle.hpp" #include "thread/neighbor_table.hpp" @@ -225,6 +227,15 @@ EMSCRIPTEN_BINDINGS(nexus_simulator) function("pollEvent", optional_override([]() -> val { return WasmManager::Get().PollEvent(); })); + function("getRadioParameters", optional_override([]() -> val { + val params = val::object(); + params.set("pathLossConstant", RadioModel::kPathLossConstant); + params.set("pathLossExponent", RadioModel::kPathLossExponent); + params.set("radioSensitivity", Radio::kRadioSensitivity); + params.set("mleLinkRequestMarginMin", OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN); + return params; + })); + function("getNow", optional_override([]() -> uint32_t { return Core::Get().GetNow().GetValue(); })); function("stepSimulation", optional_override([](uint32_t aElapsedMs) { Core::Get().AdvanceTime(aElapsedMs); })); diff --git a/tests/nexus/platform/simulation.proto b/tests/nexus/platform/simulation.proto index cd1975d61..ba5e42149 100644 --- a/tests/nexus/platform/simulation.proto +++ b/tests/nexus/platform/simulation.proto @@ -212,6 +212,20 @@ service NexusService { * Joins a node to a network. */ rpc JoinNetwork(JoinNetworkRequest) returns (JoinNetworkResponse); + + /** + * Retrieves the radio model parameters. + */ + rpc GetRadioParameters(GetRadioParametersRequest) returns (GetRadioParametersResponse); +} + +message GetRadioParametersRequest {} + +message GetRadioParametersResponse { + float path_loss_constant = 1; + float path_loss_exponent = 2; + float radio_sensitivity = 3; + int32 mle_link_request_margin_min = 4; } message StreamRequest {