Understand the router experiment

The Zenoh router helps ROS 2 nodes discover each other. When nodes start, they connect to the router, exchange locator information, and establish direct peer-to-peer links.

You can examine this behaviour by stopping the router after a talker and listener have connected. If their established communication continues, the router isn’t carrying the messages between these two processes.

Open three terminals in the robot container. Source the environment in each terminal:

    

        
        
source ~/workshop_env.bash

    

Start the router

In Terminal 1, start the Zenoh router:

    

        
        
just router

    

The output is similar to:

    

        
        Started Zenoh router with id 84e303525488529a304c8990ad9bed73

        
    

The router ID can differ on your system.

Start the ROS 2 nodes

In Terminal 2, start the talker:

    

        
        
ros2 run demo_nodes_cpp talker

    

In Terminal 3, start the listener:

    

        
        
ros2 run demo_nodes_cpp listener

    

The listener should receive every message published by the talker:

    

        
        [INFO] [listener]: I heard: [Hello World: 9]
[INFO] [listener]: I heard: [Hello World: 10]

        
    

Stop the router and observe the result

Press Ctrl+C in Terminal 1 to stop the router. Keep watching the talker and listener.

The message exchange should continue without interruption. The two nodes already established a direct peer-to-peer connection, so the router isn’t in this data path. This result demonstrates the router’s discovery role for this established local connection; it doesn’t imply that every Zenoh topology can operate without a router.

Nodes can also start before the router because each node periodically retries the router connection.

Restart the router in Terminal 1 before continuing:

    

        
        
just router

    

What you’ve learned and what’s next

You’ve observed that the router enables discovery while an established talker and listener continue to communicate directly after it stops. Next, you’ll replace the demonstration nodes with the Neobotix ROX simulation and Navigation2.

Back
Next