Skip to content

Commit

Permalink
Configuration of Discovery Server using names instead of addresses (#282
Browse files Browse the repository at this point in the history
)

* Refs 12349: Add DNS section in Discovery Server

Signed-off-by: Eduardo Ponz Segrelles <eduardoponz@eprosima.com>

* Refs 12349: Add DNS explanation on CLI and env var

Signed-off-by: Eduardo Ponz Segrelles <eduardoponz@eprosima.com>
  • Loading branch information
EduPonz authored Aug 13, 2021
1 parent b6b6bce commit b1d9099
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 12 deletions.
14 changes: 14 additions & 0 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,20 @@ void dds_discovery_examples()
//!--
}

{
//CONF_SERVER_DNS_LOCATORS
Locator_t locator;
auto response = eprosima::fastrtps::rtps::IPLocator::resolveNameDNS("localhost");
// Get the first returned IPv4
if (response.first.size() > 0)
{
IPLocator::setIPv4(locator, response.first.begin()->data());
locator.port = 11811;
}
// Use the locator to create server or client
//!--
}

{
//CONF_SERVER_FULL_EXAMPLE
// Get default participant QoS
Expand Down
44 changes: 38 additions & 6 deletions code/XMLTester.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,11 @@
<port>7400</port>
<address>192.168.1.41</address>
</udpv4>
<udpv4>
<!-- Access as physical, typical UDP usage -->
<port>7600</port>
<address>localhost</address>
</udpv4>
</locator>
<locator>
<tcpv4>
Expand All @@ -1691,6 +1696,10 @@
<port>8844</port>
<address>::1</address>
</udpv6>
<udpv6>
<port>8888</port>
<address>localhost</address>
</udpv6>
</locator>
<locator>
<tcpv6>
Expand Down Expand Up @@ -2675,6 +2684,29 @@
</participant>
<!--><-->

<participant profile_name="part_ds_dns_locators">
<rtps>
<builtin>
<discovery_config>
<discoveryServersList>
<RemoteServer prefix="44.53.00.5f.45.50.52.4f.53.49.4d.41">
<metatrafficUnicastLocatorList>
<!-->CONF_SERVER_DNS_LOCATORS<-->
<locator>
<udpv4>
<port>11811</port>
<address>localhost</address>
</udpv4>
</locator>
<!--><-->
</metatrafficUnicastLocatorList>
</RemoteServer>
</discoveryServersList>
</discovery_config>
</builtin>
</rtps>
</participant>

<!-->CONF_SERVER_FULL_EXAMPLE<-->
<!--
<?xml version="1.0" encoding="UTF-8" ?>
Expand All @@ -2688,13 +2720,13 @@
<!-- Set participant as SERVER -->
<discovery_config>
<discoveryProtocol>SERVER</discoveryProtocol>
<!--
<!--
Set a list of remote servers to which this server connects.
This list may contain one or more <RemoteServer> tags
-->
<discoveryServersList>
<!--
Set remote server configuration:
<!--
Set remote server configuration:
- Prefix
- PDP listening locator
-->
Expand Down Expand Up @@ -2736,13 +2768,13 @@
<discovery_config>
<!-- Set participant as CLIENT -->
<discoveryProtocol>CLIENT</discoveryProtocol>
<!--
<!--
Set list of remote servers. This list may contain one or
more <RemoteServer> tags
-->
<discoveryServersList>
<!--
Set remote server configuration:
<!--
Set remote server configuration:
- Prefix
- PDP listening locator
-->
Expand Down
31 changes: 31 additions & 0 deletions docs/fastdds/discovery/discovery_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,37 @@ This is done by calling |DomainParticipant::set_qos-api| with a |DomainParticipa
| |
+---------------------------------------------------------------------+

.. _DS_dns_name:

Configure Discovery Server locators using names
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All the examples provided in :ref:`discovery_server` use IPv4 addresses to specify the servers' listening locators.
However, *Fast DDS* also allows to specify locator addresses using names.
When an address is specified by a name, *Fast DDS* will query the known hosts and available DNS servers to try to
resolve the IP address.
This address will in turn be used to create the listening locator in the case of *server*, or as the address of the
remote *server* in the case of *clients* (and *servers* that connect to other *servers*).

+---------------------------------------------------------------------+
| **C++** |
+---------------------------------------------------------------------+
| .. literalinclude:: /../code/DDSCodeTester.cpp |
| :language: c++ |
| :start-after: //CONF_SERVER_DNS_LOCATORS |
| :end-before: //!-- |
| :dedent: 8 |
| |
+---------------------------------------------------------------------+
| **XML** |
+---------------------------------------------------------------------+
| .. literalinclude:: /../code/XMLTester.xml |
| :language: xml |
| :start-after: <!-->CONF_SERVER_DNS_LOCATORS<--> |
| :end-before: <!--><--> |
| :dedent: 28 |
+---------------------------------------------------------------------+

.. _DS_full_example:

Full example
Expand Down
16 changes: 12 additions & 4 deletions docs/fastdds/env_vars/env_vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,38 @@ Setting this variable configures the :ref:`DomainParticipant<dds_layer_domainPar
is |SERVER| or |BACKUP|, then the variable is used to add remote *servers* to the given *server*, leaving the
:ref:`discovery protocol<discovery_protocol>` as |SERVER| or |BACKUP| respectively.

* The value of the variable must list the locator of the server in the form of the IP address (e.g., '192.168.2.23')
* The value of the variable must list the locator of the server in the form of the IPv4 address (e.g., '192.168.2.23')
or IP-port pair (e.g., '192.168.2.23:24353').
Instead of an IPv4 address, a name can be specified (e.g., 'localhost', 'localhost:12345').
This name would be used to query known hosts and available DNS servers to try to resolve a valid IPv4 address (see
:ref:`DS_dns_name`).
* If no port is specified, the default port 11811 is used.
* To set more than one *server*'s address, they must be separated by semicolons.
* The server's ID is determined by their position in the list.
Two semicolons together means the corresponding ID is free.

The following example shows how to set the address of two remote discovery servers with addresses
'84.22.259.329:8888' and '81.41.17.102:1234' and IDs 0 and 2 respectively.
'84.22.259.329:8888' and 'localhost:1234' and IDs 0 and 2 respectively.

+----------------------------------------------------------------------------+
| **Linux** |
+----------------------------------------------------------------------------+
| .. code-block:: bash |
| |
| export ROS_DISCOVERY_SERVER=84.22.259.329:8888;;81.41.17.102:1234 |
| export ROS_DISCOVERY_SERVER=84.22.259.329:8888;;localhost:1234 |
+----------------------------------------------------------------------------+
| **Windows** |
+----------------------------------------------------------------------------+
| .. code-block:: bash |
| |
| set ROS_DISCOVERY_SERVER=84.22.259.329:8888;;81.41.17.102:1234 |
| set ROS_DISCOVERY_SERVER=84.22.259.329:8888;;localhost:1234 |
+----------------------------------------------------------------------------+

.. important::
IP addresses specified in ``ROS_DISCOVERY_SERVER`` must be either valid IPv4 addresses or names.
If a name which can be translated into an address is specified, the first valid IPv4 returned from the query will be
used.

.. important::
This environment variable is meant to be used in combination with :ref:`Fast DDS discovery CLI<cli_discovery>`.
The *server*'s ID is used by *Fast DDS* to derived the |GuidPrefix_t-api| of the *server*.
Expand Down
21 changes: 19 additions & 2 deletions docs/fastddscli/cli/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Where the parameters are:
+--------------------------+-------------------------------------------------------------------------------------------+
| ``-h -help`` | Produce help message. |
+--------------------------+-------------------------------------------------------------------------------------------+
| ``-l --ip-address`` | IP address chosen to listen the clients. Defaults to any (0.0.0.0). |
| ``-l --ip-address`` | IPv4 address chosen to listen the clients. Defaults to any (0.0.0.0). Instead of an |br| |
| | address, a name can be specified (see :ref:`DS_dns_name`) |
+--------------------------+-------------------------------------------------------------------------------------------+
| ``-p --port`` | UDP port chosen to listen the clients. Defaults to '11811'. |
+--------------------------+-------------------------------------------------------------------------------------------+
Expand Down Expand Up @@ -164,7 +165,6 @@ Examples
backup file. If the server crashes it will automatically restore its
previous state when re-enacted.


.. code-block:: bash
fastdds discovery -i 3 -l 172.30.144.1 -p 12345 -b
Expand All @@ -179,6 +179,23 @@ Examples
Server GUID prefix: 44.53.03.5f.45.50.52.4f.53.49.4d.41
Server Addresses: UDPv4:[172.30.144.1]:12345
5. Launch a default server with id 0 (first on ``ROS_DISCOVERY_SERVER``)
listening on localhost with UDP port 14520. Only localhost clients
can reach the server defining as `ROS_DISCOVERY_SERVER=localhost:14520`.

.. code-block:: bash
fastdds discovery -i 0 -l localhost -p 14520
Output:

.. code-block:: bash
### Server is running ###
Participant Type: SERVER
Server ID: 0
Server GUID prefix: 44.53.00.5f.45.50.52.4f.53.49.4d.41
Server Addresses: UDPv4:[127.0.0.1]:14520
.. _cli_shm:

Expand Down

0 comments on commit b1d9099

Please sign in to comment.