refactor: add rmw_zenoh_cpp compatible Zenoh configuration and use a Zenoh router by default#55
Merged
YuanYuYuan merged 9 commits intomainfrom Jan 6, 2026
Merged
Conversation
4fb7f98 to
c62c6c7
Compare
|
8df2693 to
bc4263e
Compare
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.
Motivation
This PR aligns ros-z with the official ROS 2 Zenoh middleware (
rmw_zenoh_cpp) by adopting its default Zenoh configuration. This ensures consistent behavior, better scalability, and compatibility with ROS 2 Zenoh-based systems. This closes #42.Key alignment:
Breaking Changes
Examples now require a Zenoh router
Before (main branch):
# Just run the example - multicast discovery worked automatically cargo run --example demo_nodes_talkerAfter (this PR):
Why this change?
The new configuration disables multicast discovery by default and uses a router-based architecture, matching rmw_zenoh_cpp behavior:
How to Run Examples
Quick Start
No code changes needed - existing examples work automatically with the new default config.
Managing Configuration Programmatically
Option 1: Use Default ROS Session Config (Recommended)
Option 2: Connect to Custom Router Endpoint
Option 3: Use Config Builders for Advanced Customization
Option 4: Revert to Old Behavior (No Router Required)
Option 5: Load from Config File
Generating Config Files
Config file generation is now opt-in via the
generate-configsfeature flag.Generate to Default Location
Generate to Custom Directory
Generated Files
DEFAULT_RMW_ZENOH_ROUTER_CONFIG.json5- Router configurationDEFAULT_RMW_ZENOH_SESSION_CONFIG.json5- Session/peer configurationBoth files include inline comments explaining each setting and match rmw_zenoh_cpp defaults.
What's New
1. Configuration Module (
src/config.rs)Introduces a type-safe, zero-cost configuration system using
LazyLockfor compile-time constant storage:Architecture:
Key configurations:
moderouter/peerscouting/multicast/enabledfalsescouting/gossip/targetlisten/endpointstcp/[::]:7447connect/endpointstcp/localhost:7447transport/unicast/*_timeout60000msqueries_default_timeout60000mstransport/unicast/max_sessions10000transport/unicast/accept_pending10000transport/link/tx/keep_alive2wait_before_close5swait_before_close60stransport/shared_memory/enabledfalse2. Build-Time Config Generation (
build.rs)Generates JSON5 config files at build time:
ConfigOverridepattern (single source of truth in Rust code)generate-configsflag (opt-in)ROS_Z_CONFIG_OUTPUT_DIRConfigOverride::reasonfields3. Zenoh Router Example
Provides a drop-in replacement for the rmw_zenoh_cpp router:
Features:
RUST_LOG)Users can still download and use the official Zenoh router.
Technical Details
Zero-Cost Abstraction with LazyLock
All configuration overrides are stored as
&'static [ConfigOverride]using Rust 1.80+'sstd::sync::LazyLock:Benefits:
Configuration Deduplication
Common settings are extracted to avoid duplication:
Changes to common settings automatically propagate to both configs.
Build-Time Validation
Integration tests ensure all configurations create valid Zenoh sessions:
Migration Guide
If you were using default Zenoh configs
Before:
After:
# Start router in separate terminal cargo run --example zenoh_routerIf you need multicast discovery (no router)
Compatibility
LazyLock