The primary role of the Zenoh router is to act as a discovery service for ROS nodes running on the same host. When a node starts, it automatically tries to connect to the local Zenoh router. If the connection fails, the node waits until the router becomes available. The router shares the locators (IP + port) of each node with others, allowing them to automatically establish peer-to-peer connections. Once nodes are connected, they no longer need the router to communicate with each other.
To test this, open three different terminals within the same container (using the login_container.sh
script under the docker
directory) and run the demo_nodes_cpp
package’s talker
and listener
:
ros2 run rmw_zenoh_cpp rmw_zenohd
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp listener
CTRL+C
to stop the Zenoh router. The talker and listener will continue exchanging messages without the router.[!NOTE] The router may be started after the Nodes! Each Node periodically tries to connect to the router. As soon as the router discovers the Nodes, it propagates their endpoints to each other via a gossip protocol and each peer establish a direct connection with each other peer.
You can also test with a ROS service:
ros2 run demo_nodes_cpp add_two_ints_server
ros2 run demo_nodes_cpp add_two_ints_client
And with an Action:
ros2 run action_tutorials_cpp fibonacci_action_server
ros2 run action_tutorials_cpp fibonacci_action_client
Additionally, you can use the ros2
command-line tool to inspect the system:
ros2 node list
ros2 topic list
ros2 service list
ros2 action list
Even if the Zenoh router is stopped, the ros2
command-line tool will continue to function.
Why?