0
$\begingroup$

I always assumed ROS2 nodes used sockets to communicate but it looks like they might also use shared memory or pipes. Regardless I'm curious how ROS2 nodes find each other?

Lets suppose each node periodically broadcasts a "I'm here" message, what port does it use and how do listening nodes share the same port? If there was a common port everyone could listen on it would make sense but AFAIK each port belongs to only one process.

$\endgroup$

2 Answers 2

2
$\begingroup$

I will try to answer it in steps :

  1. As you might know the middleware used in ROS2 for communication is DDS which creates different logical networks to share a Physical network.
  2. These different logical networks are created using different Domain IDs (you can set domain id in terminal by using export ROS_DOMAIN_ID=37 or any other number in range [0,101] and [215,232].
  3. For nodes to discover and communicate with each other they must be at same Domain ID.
  4. DDS computes the UDP ports used for discovery and communication (for more detail on how these are calculated)
  5. Each Domain ID will open two ports:
    • Discovery Multicast Port
    • User Multicast Port
  6. Each Domain participant(Nodes) also opens up two ports
    • Discovery Unicast Port
    • User Unicast Port
  7. On discovery ports : Nodes exchange info to discover each other and establish connection.
  8. On User Ports : After discovery phase actual data communication among Nodes happens here.
  9. Maximum number of participants on a single Domain ID can be 120 and less for some Domain IDs(for more info)
  10. You can try running a simple talker and listener nodes by exporting same and different Domain IDs in different terminals.
  11. You can also isolate environments when controlling multiple robots which has same node names and topics by using different Domain IDs.
$\endgroup$
6
  • $\begingroup$ Thanks, I'm still confused though. How do nodes on the same machine find each other since a port can only be owned by one process? Or is the definition of port different than the socket definition? Is it implemented differently? $\endgroup$ Commented Feb 23 at 13:18
  • $\begingroup$ As mentioned in the answer nodes find each other using discovery ports. There is one discovery multicast port for one domain ID and all nodes in that domain ID broadcast their discovery message(which contains info regarding its published and subscribed topics and other metadata). This communication happens over discovery ports. once the Nodes finds their compatible nodes(one is a publisher other a subscriber to same topic) they exchange actual messages(data) over user ports. $\endgroup$
    – nitish
    Commented Feb 24 at 7:36
  • $\begingroup$ What is a discovery port? If it's a socket type port then only one process can use a port at a time so how does this work? $\endgroup$ Commented Feb 24 at 15:26
  • $\begingroup$ It uses multicast communication $\endgroup$
    – nitish
    Commented Feb 24 at 15:36
  • $\begingroup$ Yes but again only one process can access a port at a time, which means there must be one process which communicated with all the nodes, so how do the nodes discover each other on the same computer? $\endgroup$ Commented Feb 24 at 15:46
1
$\begingroup$

The exact discover protocol/mechanism depends on the used DDS.

For Fast DDS the default mechanism is called Simple Discovery:

From the Fast DDS docs:

"[...] each RTPSParticipant [ROS2 node] must listen for incoming Participant Discovery Protocol (PDP) discovery metatraffic in two different ports, one linked to a multicast address and another one linked to a unicast address." (https://fast-dds.docs.eprosima.com/en/latest/fastdds/discovery/simple.html#simple-disc-settings)

Simple Discovery uses the multicast discovery if possible.

The unicast port is used when a initialPeerList is defined as shown here.

There are also different discovery mechanisms besides the Simple Discovery, for example the Discovery Server.

While the discovery process mainly works over network, the data/message transportation can be done in different ways: Shared-memory is one of multiple ways to transport messages in a ROS network. You can also configure Fast DDS to use UDP or TCP (e.g. to communicate with a remote node).

$\endgroup$
1
  • $\begingroup$ Do you know how nodes on the same computer discover each other? $\endgroup$ Commented Feb 23 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.