diff --git a/code/DDSCodeTester.cpp b/code/DDSCodeTester.cpp index deee1204c..c37b28245 100644 --- a/code/DDSCodeTester.cpp +++ b/code/DDSCodeTester.cpp @@ -4647,7 +4647,6 @@ void dds_transport_examples () // 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"); // [OPTIONAL] ThreadSettings configuration tcp_transport->default_reception_threads(eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}); @@ -4661,10 +4660,12 @@ void dds_transport_examples () // Avoid using the default transport qos.transport().use_builtin_transports = false; + // [OPTIONAL] Set unicast locators eprosima::fastrtps::rtps::Locator_t locator; - eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, "80.80.99.45"); - eprosima::fastrtps::rtps::IPLocator::setWan(locator, "80.80.99.45"); + locator.kind = LOCATOR_KIND_TCPv4; + eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, "192.168.1.10"); eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, 5100); + // [OPTIONAL] Logical port default value is 0, automatically assigned. eprosima::fastrtps::rtps::IPLocator::setLogicalPort(locator, 5100); qos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(locator); @@ -4693,14 +4694,89 @@ void dds_transport_examples () // Set initial peers. eprosima::fastrtps::rtps::Locator_t initial_peer_locator; initial_peer_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastrtps::rtps::IPLocator::setIPv4(initial_peer_locator, "80.80.99.45"); + eprosima::fastrtps::rtps::IPLocator::setIPv4(initial_peer_locator, "192.168.1.10"); eprosima::fastrtps::rtps::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. eprosima::fastrtps::rtps::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"); + + // [OPTIONAL] ThreadSettings configuration + tcp_transport->default_reception_threads(eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}); + tcp_transport->set_thread_config_for_port(12345, eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}); + tcp_transport->keep_alive_thread = eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}; + tcp_transport->accept_thread = eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}; + + // 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) + eprosima::fastrtps::rtps::Locator_t locator; + locator.kind = LOCATOR_KIND_TCPv4; + // [RECOMMENDED] Use the LAN address of the server + eprosima::fastrtps::rtps::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. + // eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, "80.80.99.45"); + eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, 5100); + // [OPTIONAL] Logical port default value is 0, automatically assigned. + eprosima::fastrtps::rtps::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); + + // [OPTIONAL] ThreadSettings configuration + tcp_transport->default_reception_threads(eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}); + tcp_transport->set_thread_config_for_port(12345, eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}); + tcp_transport->keep_alive_thread = eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}; + tcp_transport->accept_thread = eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}; + + // Set initial peers. + eprosima::fastrtps::rtps::Locator_t initial_peer_locator; + initial_peer_locator.kind = LOCATOR_KIND_TCPv4; + // [RECOMMENDED] Use both WAN and LAN server addresses + eprosima::fastrtps::rtps::IPLocator::setIPv4(initial_peer_locator, "192.168.1.10"); + eprosima::fastrtps::rtps::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. + // eprosima::fastrtps::rtps::IPLocator::setIPv4(initial_peer_locator, "80.80.99.45"); + eprosima::fastrtps::rtps::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. + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(initial_peer_locator, 5100); + + qos.wire_protocol().builtin.initialPeersList.push_back(initial_peer_locator); //!-- } @@ -4745,7 +4821,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; @@ -4770,7 +4845,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 177f965a5..fa0160f73 100644 --- a/code/XMLTester.xml +++ b/code/XMLTester.xml @@ -319,7 +319,6 @@ 5100 - 80.80.99.45 -1 @@ -356,23 +355,25 @@ tcp_server_transport false + - 80.80.99.45 -
80.80.99.45
+
192.168.1.10
5100 + 5100
+ - 80.80.99.45 -
80.80.99.45
+
192.168.1.10
5100 + 5100
@@ -436,8 +437,167 @@ -
80.80.99.45
+
192.168.1.10
+ 5100 + + 5100 +
+
+
+
+ + + + + +<--> +<--> + +CONF-TCP-TRANSPORT-SETTING-WAN-SERVER<--> + + + + tcp_server_wan_transport + TCPv4 + + 5100 + + 80.80.99.45 + + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + + + + + + + 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 + + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + + + + + + + tcp_client_wan_transport + + false + + + + + + 80.80.99.45 +
192.168.1.10
+ + 5100 + 5100
@@ -548,7 +708,6 @@ 5100 - 80.80.99.45 @@ -595,7 +754,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 e4545e60d..1587005bf 100644 --- a/docs/fastdds/transport/tcp/tcp.rst +++ b/docs/fastdds/transport/tcp/tcp.rst @@ -252,7 +252,7 @@ TCP Server or TCP Client. :language: xml :start-after: CONF-TCP-TRANSPORT-SETTING-SERVER :end-before: <--> - :lines: 2-4,6-73,75-76 + :lines: 2-4,6-74,76-77 * **TCP Client**: If you provide |BuiltinAttributes::initialPeersList-api| to the DomainParticipant, it will act as *TCP client*, trying to connect to the remote *servers* at the given addresses and ports. @@ -275,7 +275,13 @@ TCP Server or TCP Client. :language: xml :start-after: CONF-TCP-TRANSPORT-SETTING-CLIENT :end-before: <--> - :lines: 2-4,6-58,60-61 + :lines: 2-4,6-59,61-62 + +.. 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. @@ -299,6 +305,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. @@ -314,7 +361,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 @@ -322,9 +369,9 @@ 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-4,6-73,75-76 + :lines: 2-4,6-79,81-82 On the client side, the DomainParticipant must be configured with the **public** IP address and |TCPTransportDescriptor::listening_ports-api| of the *TCP server* as @@ -336,7 +383,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 @@ -344,9 +391,9 @@ 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-4,6-58,60-61 + :lines: 2-4,6-65,67-68 .. _transport_tcp_example: