Skip to content

Commit

Permalink
TCP support for Discovery server CLI and env. var. (#4097) (#4135)
Browse files Browse the repository at this point in the history
* TCP support for Discovery server CLI and env var (#4097)

* Refs #20021: TCP support for CLI Discovery server

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Add TCP to Discovery Server Example

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: CLI: Add argument for TCP port and example

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Add TCP support to environment variable

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Use autofill feature & check existing transports

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Update BlackboxTestsDiscovery for TCPv4/6 dns support

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Apply Revision's Suggestions

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Add test for TCP single IP address & Fix DNS test

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Add default TCP interface to CLI

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Uncrustify

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Update tests with new locator syntax & fix CLI

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Update Readme

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs #20021: Fix warnings

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Refs 20021: Update versions.md

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

---------

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
(cherry picked from commit 2653efb)

# Conflicts:
#	examples/C++/DDS/BasicConfigurationExample/BasicConfigurationPublisher.cpp
#	examples/C++/DDS/BasicConfigurationExample/BasicConfigurationSubscriber.cpp
#	examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp
#	examples/cpp/dds/DiscoveryServerExample/DiscoveryServer_main.cpp
#	examples/cpp/dds/DiscoveryServerExample/README.md
#	examples/cpp/dds/DiscoveryServerExample/arg_configuration.h
#	examples/cpp/dds/DiscoveryServerExample/common.h
#	include/fastdds/rtps/attributes/ServerAttributes.h
#	src/cpp/rtps/RTPSDomain.cpp
#	src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
#	test/blackbox/common/BlackboxTestsDiscovery.cpp
#	tools/fds/server.cpp
#	tools/fds/server.h
#	versions.md

* Fix Conflicts

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Revert "Fix Conflicts"

This reverts commit b79bbe9.

* Fix building incompatibilities

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Remove Discovery Server example

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Apply changes & Fix env var reading

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Uncrustify

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Fix CLI tool

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

* Uncrustify

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>

---------

Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
Co-authored-by: Carlos Ferreira González <carlosferreira@eprosima.com>
  • Loading branch information
mergify[bot] and cferreiragonz authored Dec 21, 2023
1 parent f7e55aa commit 47e1161
Show file tree
Hide file tree
Showing 10 changed files with 625 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/UDPv6TransportDescriptor.h>
#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/TCPv6TransportDescriptor.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/attributes/SubscriberAttributes.h>

Expand Down
13 changes: 12 additions & 1 deletion include/fastdds/rtps/attributes/ServerAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,25 @@ class RemoteServerAttributes

// Live participant proxy reference
const fastrtps::rtps::ParticipantProxyData* proxy{};

// Check if there are specific transport locators associated
// the template parameter is the locator kind (e.g. LOCATOR_KIND_UDPv4)
template<int kind> bool requires_transport() const
{
return metatrafficUnicastLocatorList.has_kind<kind>() ||
metatrafficMulticastLocatorList.has_kind<kind>();
}

};

typedef std::list<RemoteServerAttributes> RemoteServerList_t;

// port use if the ros environment variable doesn't specified one
// port used if the ros environment variable doesn't specified one
constexpr uint16_t DEFAULT_ROS2_SERVER_PORT = 11811;
// default server base guidPrefix
const char* const DEFAULT_ROS2_SERVER_GUIDPREFIX = "44.53.00.5f.45.50.52.4f.53.49.4d.41";
// port used by default for tcp transport
constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 42100;

/* Environment variable to specify a semicolon-separated list of UDPv4 locators (ip:port) that define remote server
* locators.
Expand Down
10 changes: 9 additions & 1 deletion include/fastdds/rtps/common/Locator.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,15 @@ inline std::ostream& operator <<(
}

// Stream port
output << "]:" << loc.port;
if (loc.kind == LOCATOR_KIND_TCPv4 || loc.kind == LOCATOR_KIND_TCPv6)
{
output << "]:" << std::to_string(IPLocator::getPhysicalPort(loc)) << "-" << std::to_string(IPLocator::getLogicalPort(
loc));
}
else
{
output << "]:" << loc.port;
}

return output;
}
Expand Down
15 changes: 15 additions & 0 deletions include/fastdds/rtps/common/LocatorList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ class LocatorList
this->m_locators.swap(locatorList.m_locators);
}

// Check if there are specific transport locators associated
// the template parameter is the locator kind (e.g. LOCATOR_KIND_UDPv4)
template<int kind> bool has_kind() const
{
for (auto& loc : m_locators)
{
if ( kind == loc.kind )
{
return true;
}
}

return false;
}

private:

std::vector<Locator> m_locators;
Expand Down
51 changes: 46 additions & 5 deletions src/cpp/rtps/RTPSDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include <fastdds/rtps/writer/RTPSWriter.h>

#include <rtps/transport/UDPv4Transport.h>
#include <rtps/transport/UDPv6Transport.h>
#include <rtps/transport/test_UDPv4Transport.h>
#include <rtps/transport/TCPv4Transport.h>

#include <fastrtps/utils/IPFinder.h>
#include <fastrtps/utils/IPLocator.h>
Expand Down Expand Up @@ -463,17 +463,58 @@ RTPSParticipant* RTPSDomain::clientServerEnvironmentCreationOverride(
RTPSParticipantAttributes client_att(att);

// Retrieve the info from the environment variable
// TODO(jlbueno) This should be protected with the PDP mutex.
RemoteServerList_t& server_list = client_att.builtin.discovery_config.m_DiscoveryServers;
if (load_environment_server_info(client_att.builtin.discovery_config.m_DiscoveryServers) &&
client_att.builtin.discovery_config.m_DiscoveryServers.empty())
{
// it's not an error, the environment variable may not be set. Any issue with environment
// variable syntax is logError already
// It's not an error, the environment variable may not be set. Any issue with environment
// variable syntax is reported with a logError
return nullptr;
}

// Check if some server requires the TCPv4 transport
for (auto& server : server_list)
{
if (server.requires_transport<LOCATOR_KIND_TCPv4>())
{
// Check if a TCPv4 transport exists. Otherwise create it
fastdds::rtps::TCPTransportDescriptor* pT = nullptr;
std::shared_ptr<fastdds::rtps::TCPv4TransportDescriptor> p4;
bool no_tcpv4 = true;

for (auto sp : client_att.userTransports)
{
pT = dynamic_cast<fastdds::rtps::TCPTransportDescriptor*>(sp.get());

if (pT != nullptr)
{
if (!p4)
{
if ((p4 = std::dynamic_pointer_cast<fastdds::rtps::TCPv4TransportDescriptor>(sp)))
{
// TCPv4 transport already exists
no_tcpv4 = false;
break;
}
}
}
}
if (no_tcpv4)
{
// Extend builtin transports with the TCPv4 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv4TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}

}
}

logInfo(DOMAIN, "Detected auto client-server environment variable."
"Trying to create client with the default server setup.");
<< "Trying to create client with the default server setup");

client_att.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::CLIENT;
// RemoteServerAttributes already fill in above
Expand Down
Loading

0 comments on commit 47e1161

Please sign in to comment.