Skip to content

Commit

Permalink
Update TCP documentation (#654)
Browse files Browse the repository at this point in the history
* Refs #20314: Update TCP LAN example

Signed-off-by: Jesus Perez <[email protected]>

* Refs #20314: Update TCP WAN example

Signed-off-by: Jesus Perez <[email protected]>

* Refs #20314: Update TCP TLS example

Signed-off-by: Jesus Perez <[email protected]>

* Refs #20314: Minor fixes

Signed-off-by: Jesus Perez <[email protected]>

* Refs #20314: Extend WAN description, update image and modify examples

Signed-off-by: Jesus Perez <[email protected]>

---------

Signed-off-by: Jesus Perez <[email protected]>
  • Loading branch information
jepemi authored Feb 14, 2024
1 parent b74412f commit 6c2c47a
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 511 deletions.
87 changes: 81 additions & 6 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4647,7 +4647,6 @@ void dds_transport_examples ()
// Create a descriptor for the new transport.
auto tcp_transport = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
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});
Expand All @@ -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);
Expand Down Expand Up @@ -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<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
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<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
// [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);
//!--
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
175 changes: 167 additions & 8 deletions code/XMLTester.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@
<listening_ports>
<port>5100</port>
</listening_ports>
<wan_addr>80.80.99.45</wan_addr>
<!-- Optional thread configuration -->
<default_reception_threads>
<scheduling_policy>-1</scheduling_policy>
Expand Down Expand Up @@ -356,23 +355,25 @@
<transport_id>tcp_server_transport</transport_id>
</userTransports>
<useBuiltinTransports>false</useBuiltinTransports>
<!-- Optional unicast locator set -->
<defaultUnicastLocatorList>
<locator>
<tcpv4>
<wan_address>80.80.99.45</wan_address>
<address>80.80.99.45</address>
<address>192.168.1.10</address>
<physical_port>5100</physical_port>
<!-- Optional logical port set -->
<port>5100</port>
</tcpv4>
</locator>
</defaultUnicastLocatorList>
<!-- Optional metatraffic unicast locator set -->
<builtin>
<metatrafficUnicastLocatorList>
<locator>
<tcpv4>
<wan_address>80.80.99.45</wan_address>
<address>80.80.99.45</address>
<address>192.168.1.10</address>
<physical_port>5100</physical_port>
<!-- Optional logical port set -->
<port>5100</port>
</tcpv4>
</locator>
Expand Down Expand Up @@ -436,8 +437,167 @@
<initialPeersList>
<locator>
<tcpv4>
<address>80.80.99.45</address>
<address>192.168.1.10</address>
<physical_port>5100</physical_port>
<!-- To be set if set in server -->
<port>5100</port>
</tcpv4>
</locator>
</initialPeersList>
</builtin>
</rtps>
</participant>
<!-->
</profiles>
</dds>
<-->
<!--><-->

<!-->CONF-TCP-TRANSPORT-SETTING-WAN-SERVER<-->
<!--
<?xml version="1.0" encoding="UTF-8" ?>
<dds>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
-->
<transport_descriptors>
<transport_descriptor>
<transport_id>tcp_server_wan_transport</transport_id>
<type>TCPv4</type>
<listening_ports>
<port>5100</port>
</listening_ports>
<wan_addr>80.80.99.45</wan_addr>
<!-- Optional thread configuration -->
<default_reception_threads>
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</default_reception_threads>
<reception_threads>
<reception_thread port="12345">
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</reception_thread>
</reception_threads>
<keep_alive_thread>
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</keep_alive_thread>
<accept_thread>
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</accept_thread>
</transport_descriptor>
</transport_descriptors>

<participant profile_name="tcp_server_wan_participant">
<rtps>
<userTransports>
<transport_id>tcp_server_wan_transport</transport_id>
</userTransports>
<useBuiltinTransports>false</useBuiltinTransports>
<!-- Optional unicast locator set -->
<defaultUnicastLocatorList>
<locator>
<tcpv4>
<address>192.168.1.10</address>
<!-- Alternatively use WAN address -->
<!-- <address>80.80.99.45</address> -->
<physical_port>5100</physical_port>
<!-- Optional logical port set -->
<port>5100</port>
</tcpv4>
</locator>
</defaultUnicastLocatorList>
<!-- Optional metatraffic unicast locator set -->
<builtin>
<metatrafficUnicastLocatorList>
<locator>
<tcpv4>
<address>192.168.1.10</address>
<!-- Alternatively use WAN address -->
<!-- <address>80.80.99.45</address> -->
<physical_port>5100</physical_port>
<!-- Optional logical port set -->
<port>5100</port>
</tcpv4>
</locator>
</metatrafficUnicastLocatorList>
</builtin>
</rtps>
</participant>
<!-->
</profiles>
</dds>
<-->
<!--><-->

<!-->CONF-TCP-TRANSPORT-SETTING-WAN-CLIENT<-->
<!--
<?xml version="1.0" encoding="UTF-8" ?>
<dds>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
-->
<transport_descriptors>
<transport_descriptor>
<transport_id>tcp_client_wan_transport</transport_id>
<type>TCPv4</type>
<!-- Recommended client's WAN set -->
<wan_addr>80.80.99.47</wan_addr>
<!-- Optional thread configuration -->
<default_reception_threads>
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</default_reception_threads>
<reception_threads>
<reception_thread port="12345">
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</reception_thread>
</reception_threads>
<keep_alive_thread>
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</keep_alive_thread>
<accept_thread>
<scheduling_policy>-1</scheduling_policy>
<priority>0</priority>
<affinity>0</affinity>
<stack_size>-1</stack_size>
</accept_thread>
</transport_descriptor>
</transport_descriptors>

<participant profile_name="tcp_client_wan_participant">
<rtps>
<userTransports>
<transport_id>tcp_client_wan_transport</transport_id>
</userTransports>
<useBuiltinTransports>false</useBuiltinTransports>
<builtin>
<initialPeersList>
<locator>
<tcpv4>
<!-- Recommended use of both WAN and LAN server addresses -->
<wan_address>80.80.99.45</wan_address>
<address>192.168.1.10</address>
<!-- Alternatively use server's WAN addresses only -->
<!-- <address>80.80.99.45</address> -->
<physical_port>5100</physical_port>
<!-- To be set if set in server -->
<port>5100</port>
</tcpv4>
</locator>
Expand Down Expand Up @@ -548,7 +708,6 @@
<listening_ports>
<port>5100</port>
</listening_ports>
<wan_addr>80.80.99.45</wan_addr>
</transport_descriptor>
</transport_descriptors>

Expand Down Expand Up @@ -595,7 +754,7 @@
<initialPeersList>
<locator>
<tcpv4>
<address>80.80.99.45</address>
<address>192.168.1.10</address>
<physical_port>5100</physical_port>
</tcpv4>
</locator>
Expand Down
Binary file modified docs/01-figures/TCP_WAN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6c2c47a

Please sign in to comment.