diff --git a/code/DDSCodeTester.cpp b/code/DDSCodeTester.cpp index 9b2eb02f0..15c06ac66 100644 --- a/code/DDSCodeTester.cpp +++ b/code/DDSCodeTester.cpp @@ -4606,13 +4606,23 @@ void dds_transport_examples () tcp_transport->sendBufferSize = 9216; tcp_transport->receiveBufferSize = 9216; tcp_transport->add_listener_port(5100); - tcp_transport->set_WAN_address("80.80.99.45"); // Link the Transport Layer to the Participant. qos.transport().user_transports.push_back(tcp_transport); // Avoid using the default transport qos.transport().use_builtin_transports = false; + + // [OPTIONAL] Set unicast locators + Locator_t locator; + locator.kind = LOCATOR_KIND_TCPv4; + IPLocator::setIPv4(locator, "192.168.1.10"); + IPLocator::setPhysicalPort(locator, 5100); + // [OPTIONAL] Logical port default value is 0, automatically assigned. + IPLocator::setLogicalPort(locator, 5100); + + qos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(locator); + qos.wire_protocol().default_unicast_locator_list.push_back(locator); //!-- } @@ -4631,13 +4641,77 @@ void dds_transport_examples () // Set initial peers. Locator_t initial_peer_locator; initial_peer_locator.kind = LOCATOR_KIND_TCPv4; - IPLocator::setIPv4(initial_peer_locator, "80.80.99.45"); - initial_peer_locator.port = 5100; + IPLocator::setIPv4(initial_peer_locator, "192.168.1.10"); + IPLocator::setPhysicalPort(initial_peer_locator, 5100); + // If the logical port is set in the server side, it must be also set here with the same value. + // If not set in the server side in a unicast locator, do not set it here. + IPLocator::setLogicalPort(initial_peer_locator, 5100); qos.wire_protocol().builtin.initialPeersList.push_back(initial_peer_locator); + //!-- + } + + { + //CONF-TCP-TRANSPORT-SETTING-WAN-SERVER + eprosima::fastdds::dds::DomainParticipantQos qos; + + // Create a descriptor for the new transport. + auto tcp_transport = std::make_shared(); + tcp_transport->add_listener_port(5100); + tcp_transport->set_WAN_address("80.80.99.45"); + + // Link the Transport Layer to the Participant. + qos.transport().user_transports.push_back(tcp_transport); // Avoid using the default transport qos.transport().use_builtin_transports = false; + + // [OPTIONAL] Set unicast locators (do not use setWAN(), set_WAN_address() overwrites it) + Locator_t locator; + locator.kind = LOCATOR_KIND_TCPv4; + // [RECOMMENDED] Use the LAN address of the server + IPLocator::setIPv4(locator, "192.168.1.10"); + // [ALTERNATIVE] Use server's WAN address. In that case, initial peers must be configured + // only with server's WAN address. + // IPLocator::setIPv4(locator, "80.80.99.45"); + IPLocator::setPhysicalPort(locator, 5100); + // [OPTIONAL] Logical port default value is 0, automatically assigned. + IPLocator::setLogicalPort(locator, 5100); + + qos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(locator); + qos.wire_protocol().default_unicast_locator_list.push_back(locator); + //!-- + } + + { + //CONF-TCP-TRANSPORT-SETTING-WAN-CLIENT + eprosima::fastdds::dds::DomainParticipantQos qos; + + // Disable the built-in Transport Layer. + qos.transport().use_builtin_transports = false; + + // Create a descriptor for the new transport. + // Do not configure any listener port + auto tcp_transport = std::make_shared(); + // [RECOMMENDED] Use client's WAN address if there are more clients in other local networks. + tcp_transport->set_WAN_address("80.80.99.47"); + qos.transport().user_transports.push_back(tcp_transport); + + // Set initial peers. + Locator_t initial_peer_locator; + initial_peer_locator.kind = LOCATOR_KIND_TCPv4; + // [RECOMMENDED] Use both WAN and LAN server addresses + IPLocator::setIPv4(initial_peer_locator, "192.168.1.10"); + IPLocator::setWan(initial_peer_locator, "80.80.99.45"); + // [ALTERNATIVE] Use server's WAN address only. Valid if server specified its unicast locators + // with its LAN or WAN address. + // IPLocator::setIPv4(initial_peer_locator, "80.80.99.45"); + IPLocator::setPhysicalPort(initial_peer_locator, 5100); + // If the logical port is set in the server side, it must be also set here with the same value. + // If not set in the server side in a unicast locator, do not set it here. + IPLocator::setLogicalPort(initial_peer_locator, 5100); + + qos.wire_protocol().builtin.initialPeersList.push_back(initial_peer_locator); //!-- } @@ -4662,7 +4736,6 @@ void dds_transport_examples () tls_transport->sendBufferSize = 9216; tls_transport->receiveBufferSize = 9216; tls_transport->add_listener_port(5100); - tls_transport->set_WAN_address("80.80.99.45"); // Create the TLS configuration using TLSOptions = eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions; @@ -4687,7 +4760,7 @@ void dds_transport_examples () // Set initial peers. Locator_t initial_peer_locator; initial_peer_locator.kind = LOCATOR_KIND_TCPv4; - IPLocator::setIPv4(initial_peer_locator, "80.80.99.45"); + IPLocator::setIPv4(initial_peer_locator, "192.168.1.10"); initial_peer_locator.port = 5100; qos.wire_protocol().builtin.initialPeersList.push_back(initial_peer_locator); diff --git a/code/XMLTester.xml b/code/XMLTester.xml index 8f39ed712..f37180957 100644 --- a/code/XMLTester.xml +++ b/code/XMLTester.xml @@ -251,23 +251,46 @@ --> - tcp_transport + tcp_server_transport TCPv4 9216 9216 5100 - 80.80.99.45 - + - tcp_transport + tcp_server_transport false + + + + +
192.168.1.10
+ 5100 + + 5100 +
+
+
+ + + + + +
192.168.1.10
+ 5100 + + 5100 +
+
+
+
<--> @@ -279,23 +302,121 @@ --> - tcp2_transport + tcp_client_transport + TCPv4 + + + + + + + tcp_client_transport + + false + + + + +
192.168.1.10
+ 5100 + + 5100 +
+
+
+
+
+
+<--> + +CONF-TCP-TRANSPORT-SETTING-WAN-SERVER<--> + + + + tcp_server_wan_transport + TCPv4 + + 5100 + + 80.80.99.45 + + + + + + + tcp_server_wan_transport + + false + + + + +
192.168.1.10
+ + + 5100 + + 5100 +
+
+
+ + + + + +
192.168.1.10
+ + + 5100 + + 5100 +
+
+
+
+
+
+<--> + +CONF-TCP-TRANSPORT-SETTING-WAN-CLIENT<--> + + + + tcp_client_wan_transport TCPv4 + + 80.80.99.47 - + - tcp2_transport + tcp_client_wan_transport - false + false -
80.80.99.45
+ + 80.80.99.45 +
192.168.1.10
+ + 5100 + + 5100
@@ -352,7 +473,6 @@ 5100 - 80.80.99.45 @@ -399,7 +519,7 @@ -
80.80.99.45
+
192.168.1.10
5100
diff --git a/docs/01-figures/TCP_WAN.png b/docs/01-figures/TCP_WAN.png index e13929ccb..d83eb18e7 100644 Binary files a/docs/01-figures/TCP_WAN.png and b/docs/01-figures/TCP_WAN.png differ diff --git a/docs/01-figures/TCP_WAN.svg b/docs/01-figures/TCP_WAN.svg deleted file mode 100644 index be6a2554e..000000000 --- a/docs/01-figures/TCP_WAN.svg +++ /dev/null @@ -1,489 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - DomainChange - - - - INITIAL PEERS - - - - - - - - Integration Service - - - - 192.168.1.40 - - - - - - - - - Integration Service - - - - 80.80.99.45:5100 - - - - - - - - - - DomainChange - - - - LISTENING PORTS - - - - - - - - Integration Service - - - - 80.80.99.45 - - - - - - - - - - Integration Service - - - - 5100 - - - - - - - - - DDS World C - - - - - INTERNET - - - - TCP Client - TCP Server - - diff --git a/docs/fastdds/transport/tcp/tcp.rst b/docs/fastdds/transport/tcp/tcp.rst index 78d01c952..692ebc9f4 100644 --- a/docs/fastdds/transport/tcp/tcp.rst +++ b/docs/fastdds/transport/tcp/tcp.rst @@ -259,6 +259,12 @@ See :ref:`Simple Initial Peers` for more information about their configuration. :lines: 2-3,5- :append: +.. note:: + + Manually setting unicast locators is optional. If not setting them or setting them with a logical + port of ``0``, the client's initial peer shouldn't set its logical port (or set it to ``0``). Otherwise, + initial peer's logical port must match server's unicast logical port. + :ref:`transport_tcp_example` shows how to use and configure a TCP transport. .. _transport_tcp_wan: @@ -281,6 +287,47 @@ For example, imagine we have the scenario represented on the following figure: * Another DomainParticipant acts as a *TCP client* and has configured the server's IP address and port in its :ref:`Simple Initial Peers` list. +By using ``set_WAN_address(wan_ip)``, the WAN IP address is set on the participant's locators that +are communicated during the discovery phase. + +Like in the LAN case, manually setting unicast locators is optional. However, in this case, there are +some considerations to take into account when setting its IP addresses: + +* Setting the WAN IP address using the ``setWAN()`` method in unicast locators is ineffective because it + gets overridden by the ``set_WAN_address()`` call. + +* For assigning IP addresses to unicast locators, use only the ``setIPv4()`` or ``setIPv6()`` methods, which + are LAN IP setters. There are some configurations which allow using these setters with a WAN IP address. + +Depending on whether the server has manually set its metatraffic unicast locators and default unicast +locators, the client needs to adjust its initial peer list accordingly: + +* If the server's unicast locators are configured with the LAN IP address: + + * The initial peer can be set up with only the server's WAN IP using the LAN IP setter. + + * Alternatively, it can be configured with both the server's LAN and WAN IP addresses using the LAN + setter for the LAN IP and the WAN setter for the WAN IP. + +* If the server's unicast locators are configured with the WAN IP address: + + * The initial peer must be set up with only the server's WAN IP using the LAN setter. + + * Alternatively, it can be configured with the WAN IP address using both the LAN and WAN setters. + +* If the server has not set any unicast locators: + + * The initial peer can be configured with only the server's WAN IP using the LAN setter. + + * Alternatively, it can be configured with both the server's LAN and WAN IP addresses using the LAN + setter for the LAN IP and the WAN setter for the WAN IP. + +.. note:: + + Manually setting unicast locators is optional. If not setting them or setting them with a logical + port of ``0``, the client's initial peer shouldn't set its logical port (or set it to ``0``). Otherwise, + initial peer's logical port must match server's unicast logical port. + On the server side, the router must be configured to forward to the *TCP server* all traffic incoming to port ``5100``. Typically, a NAT routing of port ``5100`` to our machine is enough. Any existing firewall should be configured as well. @@ -296,7 +343,7 @@ The following examples show how to configure the DomainParticipant both in C++ a .. literalinclude:: /../code/DDSCodeTester.cpp :language: c++ - :start-after: //CONF-TCP-TRANSPORT-SETTING-SERVER + :start-after: //CONF-TCP-TRANSPORT-SETTING-WAN-SERVER :end-before: //!-- :dedent: 8 @@ -304,7 +351,7 @@ The following examples show how to configure the DomainParticipant both in C++ a .. literalinclude:: /../code/XMLTester.xml :language: xml - :start-after: CONF-TCP-TRANSPORT-SETTING-SERVER + :start-after: CONF-TCP-TRANSPORT-SETTING-WAN-SERVER :end-before: <--> :lines: 2-3,5- :append: @@ -319,7 +366,7 @@ with the **public** IP address and |TCPTransportDescriptor::listening_ports-api| .. literalinclude:: /../code/DDSCodeTester.cpp :language: c++ - :start-after: //CONF-TCP-TRANSPORT-SETTING-CLIENT + :start-after: //CONF-TCP-TRANSPORT-SETTING-WAN-CLIENT :end-before: //!-- :dedent: 8 @@ -327,7 +374,7 @@ with the **public** IP address and |TCPTransportDescriptor::listening_ports-api| .. literalinclude:: /../code/XMLTester.xml :language: xml - :start-after: CONF-TCP-TRANSPORT-SETTING-CLIENT + :start-after: CONF-TCP-TRANSPORT-SETTING-WAN-CLIENT :end-before: <--> :lines: 2-3,5- :append: @@ -341,6 +388,3 @@ A TCP version of helloworld example can be found in the `HelloWorldExampleTCP folder `_. It shows a publisher and a subscriber that communicate through TCP. The publisher is configured as *TCP server* while the Subscriber is acting as *TCP client*. - - -