How ros2/rmw_zenoh works
Project type and purpose
• This is a ROS 2 “RMW” (ROS Middleware) plugin implementation named rmw_zenoh. Its purpose is to let ROS 2 nodes publish/subscribe and discover each other over the Zenoh network using C++ bindings. It also provides a Zenoh‐based “router” (a standalone process) and a security tools package to generate secure Zenoh configs.
File structure
Top-level modules:
• .github/ – CI/workflow definitions.
• docs/ – high-level design documentation.
• rmw_zenoh_cpp/ – the core RMW plugin package: CMakeLists, ROS 2 package.xml, source (src/detail implements all rmw_* APIs), default Zenoh config files.
• zenoh_cpp_vendor/ – vendored Zenoh C++ library build integration.
• zenoh_security_tools/ – a small CLI app to generate secure Zenoh configurations for authentication, encryption, access control.
README for key architectural insights
• There is a two‐process model for discovery: a Zenoh router (rmw_zenohd) plus one or more ROS 2 nodes linked against the rmw_zenoh_cpp plugin.
• Environment variables and JSON5 config files configure session modes, discovery (gossip vs. multicast), security, logging, and network endpoints.
Main components and their relationships
A. ROS 2 Application Layer
• User nodes written with rclcpp (e.g., talker/listener).
• They link against the RMW interface (rmw_zenoh_cpp).
B. rmw_zenoh_cpp Plugin
• Implements standard RMW interfaces: publishers, subscriptions, services, clients, guard conditions, wait sets, graph cache, QoS translation, type support.
• Internally delegates serialization, discovery, pub/sub, and RPC to Zenoh C++.
C. Zenoh C++ Vendor Library
• Underlying transport and discovery mechanism (vendored via zenoh_cpp_vendor CMake).
D. Zenoh Router Process (rmw_zenohd)
• Acts as a gossip‐based discovery and message router when direct peer‐to-peer is disabled.
• Exchanges discovery information and forwards data between sessions.
E. Zenoh Security Tools
• CLI utility to generate config files enabling Zenoh access control, authentication, and encryption.
Interactions (data flows):
1. Node ➔ RMW plugin: rclcpp calls rmw_create_publisher(), rmw_publish(), etc.
2. RMW plugin ➔ Zenoh session: plugin creates a Zenoh session (client or peer) using JSON5 config and environment overrides, then advertises topics or connects to the router.
3. Zenoh session ➔ Router or other sessions: over TCP/multicast/gossip, handles discovery and data exchange.
4. Router ➔ Router/Session: gossip between multiple routers, session autoconnects as routers come online.
5. Security Tools ➔ Config Files: precompute security credentials to be consumed by plugin or router at startup.
Architectural patterns and design principles
• Adapter pattern: rmw_zenoh_cpp adapts ROS 2 RMW API to Zenoh’s API.
• Layered architecture: clear separation of application (rclcpp), middleware plugin (rmw_zenoh_cpp), transport layer (Zenoh C++), and external router.
• Configuration‐driven behavior: everything from discovery mode to security is parameterized via JSON5 files and environment variables.
• Vendor encapsulation: Zenoh C++ is vendored to ensure reproducible builds and subset of features.
• Tooling separation: security config generation is extracted into a separate CLI package to keep the core plugin lean.
Final advice
• Be as granular as needed: break the plugin into its major functional units (discovery, serialization, pub/sub, service).
• Don’t forget to show the flow of configuration (JSON5 files + env vars) as part of the system initialization.