4. WAN Example

In the following snippet we see a yaml file to configure a DDS Router to create a Simple Participant in domain 0 and a WAN Participant.

##################################
# CONFIGURATION VERSION
version: v3.0                                                     # 0

##################################
# ALLOWED TOPICS
# Allowing FastDDS and ROS2 HelloWorld demo examples topics

allowlist:
  - name: HelloWorldTopic                                         # 1
    type: HelloWorld                                              # 1
  - name: rt/chatter                                              # 2
    type: std_msgs::msg::dds_::String_

##################################
# PARTICIPANTS
participants:

##################################
# SIMPLE PARTICIPANT
# This participant will subscribe to topics in allowlist in domain 0 and listen every message published there

  - name: SimpleParticipant                                       # 3
    kind: local                                                   # 4
    domain: 0                                                     # 5

##################################
# WAN SERVER
# This participant will subscribe to topics in allowlist and connect to clients through Initial Peers.

  - name: WANServer                                               # 6
    kind: wan                                                     # 7
    listening-addresses:                                          # 8
      - ip: 1.1.1.1                                               # 9
        port: 11666                                               # 10
        transport: udp                                            # 11

4.1. Configuration

4.1.1. Allowed Topics

In this section are the Topics that the DDS Router will route from one Participant to the other. Topic HelloWorldTopic with datatype HelloWorld, and ROS 2 topic rt/chatter with datatype std_msgs::msg::dds_::String_ will be forwarded from one domain to the other, allowing different DDS domains to interact to each other.

allowlist:
  - name: HelloWorldTopic                                         # 1
    type: HelloWorld                                              # 1
  - name: rt/chatter                                              # 2
    type: std_msgs::msg::dds_::String_

4.1.2. Simple Participant

This Participant is configured by a name, a kind and the Domain Id, in this case 0.

  - name: SimpleParticipant                                       # 3
    kind: local                                                   # 4
    domain: 0                                                     # 5

4.1.3. WAN Participant Server

This Participant is configured with a name, a kind and the listening addresses where it will expect data from other remote WAN Participant Clients. This Participant act as a Server only to receive the discovery data from other WAN Participants. Once the connection has been established, the communication will be symmetrical (except in TCP case, in which case this Participant will work as TCP Server).

  - name: WANServer                                               # 6
    kind: wan                                                     # 7
    listening-addresses:                                          # 8
      - ip: 1.1.1.1                                               # 9
        port: 11666                                               # 10
        transport: udp                                            # 11

4.1.4. WAN Participant Client

In order to create a WAN Participant Client, check the configuration file <path/to/ddsrouter_tool>/share/resources/configurations/examples/wan_client.yaml

  - name: WANClient                                               # 6
    kind: wan                                                     # 7
    connection-addresses:                                         # 8
      - ip: 1.1.1.1                                               # 9
        port: 11666
    listening-addresses:                                          # 10
      - ip: 2.2.2.2                                               # 11
        port: 11670                                               # 12
        transport: udp                                            # 13

4.2. Execute example

In order to run this example, there must be two different hosts located in different local networks:

  • host HA with private IP 192.168.1.2 connected to network router RA with public IP 1.1.1.1.

  • host HB with private IP 192.168.2.2 connected to network router RB with public IP 2.2.2.2.

This example could be run in localhost or with two hosts in the same LAN, but it will not use the WAN communication features of the DDS Router.

4.2.1. Host HA

This host runs the DDS Router WAN Server, which will wait for other WAN Clients to connect to it. Execute DDS Router using file <path/to/ddsrouter_tool>/share/resources/configurations/examples/wan_server.yaml. Remember to change the IP and port on the configuration file to the actual public IP of RA, and be sure that the port forwarding rules are configured in RA so HA is accessible from the outside. Check the following section for further information about how to configure WAN in DDS Router. Refer to this section for a detailed explanation on how to execute the DDS Router.

First of all, execute a ROS 2 demo_nodes_cpp listener in domain 0. This listener will discover the Simple Participant in the DDS Router, but will not receive any data yet.

ROS_DOMAIN_ID=0 ros2 run demo_nodes_cpp listener

4.2.2. Host HB

This host runs the DDS Router WAN Client, which will connect to the previously launched WAN Server. Execute DDS Router using file <path/to/ddsrouter_tool>/share/resources/configurations/examples/wan_client.yaml. Remember to change the IPs and ports on the configuration file to the actual public IPs of RA and RB, and be sure that port forwarding is configured in RB so HB is accessible from the outside.

In this case, the Simple Participant is configured to use the Domain Id 1, so execute a ROS 2 demo_nodes_cpp talker in domain 1.

ROS_DOMAIN_ID=1 ros2 run demo_nodes_cpp talker

4.2.3. Result

After executing both DDS Router applications in both hosts, and talker and listener applications, the listener in HA will start receiving and printing data from the talker in HB. You are communicating DDS via WAN.

Remember that the Participants in every DDS Router could be configured as any Participant Kind, allowing to use local Discovery Server, connect to several domains in the same LAN, connect to several WANs, etc. Endless Possibilities. Just remember uncle Ben’s words: with great power comes great responsibility.