diff --git a/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp b/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp index 0f040b583d7..27877422f34 100644 --- a/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp +++ b/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp @@ -24,6 +24,7 @@ #include #include +#include #include namespace eprosima { @@ -321,6 +322,14 @@ class DomainParticipantQos return flow_controllers_; } + /** + * Provides a way of easily configuring transport related configuration on certain pre-defined scenarios. + * + * @param transports Defines the transport configuration scenario to setup. + */ + RTPS_DllAPI void setup_transports( + rtps::BuiltinTransports transports); + private: //!UserData Qos, implemented in the library. diff --git a/include/fastdds/rtps/attributes/BuiltinTransports.hpp b/include/fastdds/rtps/attributes/BuiltinTransports.hpp new file mode 100644 index 00000000000..6f297d77567 --- /dev/null +++ b/include/fastdds/rtps/attributes/BuiltinTransports.hpp @@ -0,0 +1,85 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file BuiltinTransports.hpp + */ + +#ifndef _FASTDDS_RTPS_ATTRIBUTES__BUILTINTRANSPORTS_HPP_ +#define _FASTDDS_RTPS_ATTRIBUTES__BUILTINTRANSPORTS_HPP_ + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Defines the kind of transports automatically instantiated upon the creation of a participant + */ +enum class BuiltinTransports : uint16_t +{ + NONE = 0, //< No transport will be instantiated + DEFAULT = 1, //< Default value that will instantiate UDPv4 and SHM transports + DEFAULTv6 = 2, //< Instantiate UDPv6 and SHM transports + SHM = 3, //< Instantiate SHM transport only + UDPv4 = 4, //< Instantiate UDPv4 transport only + UDPv6 = 5, //< Instantiate UDPv6 transport only + LARGE_DATA = 6, //< Instantiate SHM, UDPv4 and TCPv4 transports, but UDPv4 is only used for bootstrapping discovery + LARGE_DATAv6 = 7 //< Instantiate SHM, UDPv6 and TCPv6 transports, but UDPv6 is only used for bootstrapping discovery +}; + +inline std::ostream& operator <<( + std::ostream& output, + BuiltinTransports transports) +{ + switch (transports) + { + case BuiltinTransports::NONE: + output << "NONE"; + break; + case BuiltinTransports::DEFAULT: + output << "DEFAULT"; + break; + case BuiltinTransports::DEFAULTv6: + output << "DEFAULTv6"; + break; + case BuiltinTransports::SHM: + output << "SHM"; + break; + case BuiltinTransports::UDPv4: + output << "UDPv4"; + break; + case BuiltinTransports::UDPv6: + output << "UDPv6"; + break; + case BuiltinTransports::LARGE_DATA: + output << "LARGE_DATA"; + break; + case BuiltinTransports::LARGE_DATAv6: + output << "LARGE_DATAv6"; + break; + default: + output << "UNKNOWN"; + break; + } + return output; +} + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_RTPS_ATTRIBUTES__BUILTINTRANSPORTS_HPP_ diff --git a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h index 09be3da4531..02fc6ea4906 100644 --- a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h +++ b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h @@ -19,6 +19,7 @@ #ifndef _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ #define _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ +#include #include #include #include @@ -36,14 +37,12 @@ #include namespace eprosima { - namespace fastdds { - namespace rtps { /** * Struct to define participant types to set participant type parameter property - *@ingroup DISCOVERY_MODULE + * @ingroup DISCOVERY_MODULE */ struct ParticipantType { @@ -57,14 +56,13 @@ struct ParticipantType static constexpr const char* UNKNOWN = "UNKNOWN"; }; -} /* namespace rtps */ -} /* namespace fastdds */ +} // namespace rtps +} // namespace fastdds namespace fastrtps { namespace rtps { - -//!PDP subclass choice +//! PDP subclass choice typedef enum DiscoveryProtocol { NONE, @@ -127,7 +125,7 @@ inline std::ostream& operator <<( return output; } -//!Filtering flags when discovering participants +//! Filtering flags when discovering participants typedef enum ParticipantFilteringFlags : uint32_t { NO_FILTER = 0, @@ -440,7 +438,7 @@ class BuiltinAttributes /** * Class RTPSParticipantAttributes used to define different aspects of a RTPSParticipant. - *@ingroup RTPS_ATTRIBUTES_MODULE + * @ingroup RTPS_ATTRIBUTES_MODULE */ class RTPSParticipantAttributes { @@ -448,18 +446,9 @@ class RTPSParticipantAttributes public: - RTPSParticipantAttributes() - { - setName("RTPSParticipant"); - sendSocketBufferSize = 0; - listenSocketBufferSize = 0; - participantID = -1; - useBuiltinTransports = true; - } + RTPSParticipantAttributes() = default; - virtual ~RTPSParticipantAttributes() - { - } + virtual ~RTPSParticipantAttributes() = default; bool operator ==( const RTPSParticipantAttributes& b) const @@ -482,6 +471,14 @@ class RTPSParticipantAttributes (this->flow_controllers == b.flow_controllers); } + /** + * Provides a way of easily configuring transport related configuration on certain pre-defined scenarios. + * + * @param transports Defines the transport configuration scenario to setup. + */ + RTPS_DllAPI void setup_transports( + fastdds::rtps::BuiltinTransports transports); + /** * Default list of Unicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the case * that it was defined with NO UnicastLocators. At least ONE locator should be included in this list. @@ -508,12 +505,12 @@ class RTPSParticipantAttributes * @brief Send socket buffer size for the send resource. Zero value indicates to use default system buffer size. * Default value: 0. */ - uint32_t sendSocketBufferSize; + uint32_t sendSocketBufferSize = 0; /*! Listen socket buffer for all listen resources. Zero value indicates to use default system buffer size. * Default value: 0. */ - uint32_t listenSocketBufferSize; + uint32_t listenSocketBufferSize = 0; //! Optionally allows user to define the GuidPrefix_t GuidPrefix_t prefix; @@ -534,7 +531,7 @@ class RTPSParticipantAttributes std::vector userData; //! Participant ID - int32_t participantID; + int32_t participantID = -1; /** * @brief Throughput controller parameters. Leave default for uncontrolled flow. @@ -546,8 +543,8 @@ class RTPSParticipantAttributes //! User defined transports to use alongside or in place of builtins. std::vector> userTransports; - //! Set as false to disable the default UDPv4 implementation. - bool useBuiltinTransports; + //! Set as false to disable the creation of the default transports. + bool useBuiltinTransports = true; //! Holds allocation limits affecting collections managed by a participant. RTPSParticipantAllocationAttributes allocation; @@ -574,11 +571,11 @@ class RTPSParticipantAttributes private: //! Name of the participant. - string_255 name; + string_255 name{"RTPSParticipant"}; }; -} /* namespace rtps */ -} /* namespace fastrtps */ -} /* namespace eprosima */ +} // namespace rtps +} // namespace fastrtps +} // namespace eprosima -#endif /* _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ */ +#endif // _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ diff --git a/include/fastrtps/xmlparser/XMLParser.h b/include/fastrtps/xmlparser/XMLParser.h index 8f8a1b46d7e..305ed0a94a5 100644 --- a/include/fastrtps/xmlparser/XMLParser.h +++ b/include/fastrtps/xmlparser/XMLParser.h @@ -603,6 +603,11 @@ class XMLParser tinyxml2::XMLElement* elem, SubscriberAttributes& subscriber, uint8_t ident); + + RTPS_DllAPI static XMLP_ret getXMLBuiltinTransports( + tinyxml2::XMLElement* elem, + eprosima::fastdds::rtps::BuiltinTransports* bt, + uint8_t ident); }; } // namespace xmlparser diff --git a/include/fastrtps/xmlparser/XMLParserCommon.h b/include/fastrtps/xmlparser/XMLParserCommon.h index c883eb902c8..0aa98e49607 100644 --- a/include/fastrtps/xmlparser/XMLParserCommon.h +++ b/include/fastrtps/xmlparser/XMLParserCommon.h @@ -117,6 +117,7 @@ extern const char* IP6_TO_SEND; extern const char* THROUGHPUT_CONT; extern const char* USER_TRANS; extern const char* USE_BUILTIN_TRANS; +extern const char* BUILTIN_TRANS; extern const char* PROPERTIES_POLICY; extern const char* NAME; extern const char* REMOTE_LOCATORS; @@ -175,6 +176,10 @@ extern const char* UDPv6; extern const char* TCPv4; extern const char* TCPv6; extern const char* SHM; +extern const char* DEFAULT_C; +extern const char* DEFAULTv6; +extern const char* LARGE_DATA; +extern const char* LARGE_DATAv6; extern const char* INIT_ACKNACK_DELAY; extern const char* HEARTB_RESP_DELAY; extern const char* INIT_HEARTB_DELAY; diff --git a/resources/xsd/fastRTPS_profiles.xsd b/resources/xsd/fastRTPS_profiles.xsd index d5a5b6ee6fd..c44dc28c2a9 100644 --- a/resources/xsd/fastRTPS_profiles.xsd +++ b/resources/xsd/fastRTPS_profiles.xsd @@ -112,6 +112,7 @@ ├ userTransports [0~1], | └ transport_id [1~*] [string], ├ useBuiltinTransports [bool], + ├ builtinTransports [0~1][string], ├ propertiesPolicy [0~1], ├ allocation [0~1], ├ userData [0~1], @@ -141,6 +142,20 @@ + + + + + + + + + + + + + + @@ -504,9 +519,6 @@ - - - + + transport + + + + + + 0 + + Participant.builtin_transports_default + DEFAULT + + + + + 0 + + Participant.builtin_transports_defaultv6 + DEFAULTv6 + + + + + 0 + + Participant.builtin_transports_shm + SHM + + + + + 0 + + Participant.builtin_transports_udp + UDPv4 + + + + + 0 + + Participant.builtin_transports_udpv6 + UDPv6 + + + + + 0 + + Participant.builtin_transports_largedata + LARGE_DATA + + + + + 0 + + Participant.builtin_transports_largedatav6 + LARGE_DATAv6 + + + + + diff --git a/test/blackbox/common/BlackboxTestsTransportCustom.cpp b/test/blackbox/common/BlackboxTestsTransportCustom.cpp index 8b879bd7249..7efc7747e3b 100644 --- a/test/blackbox/common/BlackboxTestsTransportCustom.cpp +++ b/test/blackbox/common/BlackboxTestsTransportCustom.cpp @@ -24,6 +24,8 @@ #include +using BuiltinTransports = eprosima::fastdds::rtps::BuiltinTransports; + class TestChainingTransportDescriptor : public eprosima::fastdds::rtps::ChainingTransportDescriptor { public: @@ -305,4 +307,191 @@ TEST(ChainingTransportTests, tcp_client_server_with_wan_correct_sender_resources //! is being created ASSERT_LE(times_writer_send_function_called.load(), 30); ASSERT_LE(times_reader_receive_function_called.load(), 30); -} \ No newline at end of file +} + +TEST(ChainingTransportTests, builtin_transports_basic_test) +{ + std::vector bt_list; + bt_list.push_back(BuiltinTransports::DEFAULT); + bt_list.push_back(BuiltinTransports::DEFAULTv6); + bt_list.push_back(BuiltinTransports::SHM); + bt_list.push_back(BuiltinTransports::UDPv4); + bt_list.push_back(BuiltinTransports::UDPv6); + bt_list.push_back(BuiltinTransports::LARGE_DATA); +#ifndef __APPLE__ + bt_list.push_back(BuiltinTransports::LARGE_DATAv6); +#endif // __APPLE__ + + for (auto test_transport : bt_list) + { + { + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubReader reader(TEST_TOPIC_NAME); + + writer.setup_transports(test_transport) + .history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS) + .init(); + + ASSERT_TRUE(writer.isInitialized()); + + reader.setup_transports(test_transport) + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS) + .history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS) + .init(); + + ASSERT_TRUE(reader.isInitialized()); + + // Wait for discovery. + writer.wait_discovery(); + reader.wait_discovery(); + + auto data = default_helloworld_data_generator(); + // size_t num_messages = data.size(); + reader.startReception(data); + writer.send(data); + ASSERT_TRUE(data.empty()); + reader.block_for_all(); + + // Check reception + // reader.wait_for_all_received(std::chrono::seconds(3), num_messages); + EXPECT_TRUE(writer.waitForAllAcked(std::chrono::seconds(3))); + } + } + + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubReader reader(TEST_TOPIC_NAME); + + BuiltinTransports test_transport = BuiltinTransports::NONE; + + writer.setup_transports(test_transport) + .init(); + + ASSERT_FALSE(writer.isInitialized()); + + reader.setup_transports(test_transport) + .init(); + + ASSERT_FALSE(reader.isInitialized()); +} + +TEST(ChainingTransportTests, builtin_transports_env_var_test) +{ + const std::string env_var_name("FASTDDS_BUILTIN_TRANSPORTS"); + + std::vector bt_list; + bt_list.push_back("DEFAULT"); + bt_list.push_back("DEFAULTv6"); + bt_list.push_back("SHM"); + bt_list.push_back("UDPv4"); + bt_list.push_back("UDPv6"); + bt_list.push_back("LARGE_DATA"); +#ifndef __APPLE__ + bt_list.push_back("LARGE_DATAv6"); +#endif // __APPLE__ + + for (auto test_transport : bt_list) + { + { +#ifdef _WIN32 + _putenv_s(env_var_name.c_str(), test_transport.c_str()); +#else + setenv(env_var_name.c_str(), test_transport.c_str(), 1); +#endif // _WIN32 + + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubReader reader(TEST_TOPIC_NAME); + + writer.history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS) + .init(); + + ASSERT_TRUE(writer.isInitialized()); + + reader.reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS) + .history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS) + .init(); + + ASSERT_TRUE(reader.isInitialized()); + + // Wait for discovery. + writer.wait_discovery(); + reader.wait_discovery(); + + auto data = default_helloworld_data_generator(); + // size_t num_messages = data.size(); + reader.startReception(data); + writer.send(data); + ASSERT_TRUE(data.empty()); + reader.block_for_all(); + + // Check reception + EXPECT_TRUE(writer.waitForAllAcked(std::chrono::seconds(3))); + } + } + + std::string value("NONE"); +#ifdef _WIN32 + _putenv_s(env_var_name.c_str(), value.c_str()); +#else + setenv(env_var_name.c_str(), value.c_str(), 1); +#endif // _WIN32 + + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubReader reader(TEST_TOPIC_NAME); + + writer.init(); + + ASSERT_FALSE(writer.isInitialized()); + + reader.init(); + + ASSERT_FALSE(reader.isInitialized()); +} + +TEST(ChainingTransportTests, builtin_transports_xml_test) +{ + std::vector bt_list; + bt_list.push_back("participant_none"); + bt_list.push_back("participant_default"); + bt_list.push_back("participant_defaultv6"); + bt_list.push_back("participant_shm"); + bt_list.push_back("participant_udp"); + bt_list.push_back("participant_udpv6"); + bt_list.push_back("participant_largedata"); +#ifndef __APPLE__ + bt_list.push_back("participant_largedatav6"); +#endif // __APPLE__ + + for (auto test_transport : bt_list) + { + { + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubReader reader(TEST_TOPIC_NAME); + + writer.set_xml_filename("builtin_transports_profile.xml"); + writer.set_participant_profile(test_transport); + writer.init(); + + ASSERT_TRUE(writer.isInitialized()); + + reader.set_xml_filename("builtin_transports_profile.xml"); + reader.set_participant_profile(test_transport); + reader.init(); + + ASSERT_TRUE(reader.isInitialized()); + + // Wait for discovery. + writer.wait_discovery(); + reader.wait_discovery(); + + auto data = default_helloworld_data_generator(); + // size_t num_messages = data.size(); + reader.startReception(data); + writer.send(data); + ASSERT_TRUE(data.empty()); + reader.block_for_all(); + + // Check reception + EXPECT_TRUE(writer.waitForAllAcked(std::chrono::seconds(3))); + } + } +} diff --git a/test/mock/rtps/RTPSParticipantAttributes/fastdds/rtps/attributes/RTPSParticipantAttributes.h b/test/mock/rtps/RTPSParticipantAttributes/fastdds/rtps/attributes/RTPSParticipantAttributes.h new file mode 100644 index 00000000000..f76ef5ff8b2 --- /dev/null +++ b/test/mock/rtps/RTPSParticipantAttributes/fastdds/rtps/attributes/RTPSParticipantAttributes.h @@ -0,0 +1,605 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file RTPSParticipantAttributes.h + */ + +#ifndef _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ +#define _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Struct to define participant types to set participant type parameter property + * @ingroup DISCOVERY_MODULE + */ +struct ParticipantType +{ + static constexpr const char* SIMPLE = "SIMPLE"; + static constexpr const char* SERVER = "SERVER"; + static constexpr const char* CLIENT = "CLIENT"; + static constexpr const char* SUPER_CLIENT = "SUPER_CLIENT"; + static constexpr const char* BACKUP = "BACKUP"; + static constexpr const char* NONE = "NONE"; + static constexpr const char* EXTERNAL = "EXTERNAL"; + static constexpr const char* UNKNOWN = "UNKNOWN"; +}; + +} // namespace rtps +} // namespace fastdds + +namespace fastrtps { +namespace rtps { + +//! PDP subclass choice +typedef enum DiscoveryProtocol +{ + NONE, + /*!< + NO discovery whatsoever would be used. + Publisher and Subscriber defined with the same topic name would NOT be linked. + All matching must be done manually through the addReaderLocator, addReaderProxy, addWriterProxy methods. + */ + SIMPLE, + /*!< + Discovery works according to 'The Real-time Publish-Subscribe Protocol(RTPS) DDS + Interoperability Wire Protocol Specification' + */ + EXTERNAL, + /*!< + A user defined PDP subclass object must be provided in the attributes that deals with the discovery. + Framework is not responsible of this object lifetime. + */ + CLIENT, /*!< The participant will behave as a client concerning discovery operation. + Server locators should be specified as attributes. */ + SERVER, /*!< The participant will behave as a server concerning discovery operation. + Discovery operation is volatile (discovery handshake must take place if shutdown). */ + BACKUP, /*!< The participant will behave as a server concerning discovery operation. + Discovery operation persist on a file (discovery handshake wouldn't repeat if shutdown). */ + SUPER_CLIENT /*!< The participant will behave as a client concerning all internal behaviour. + Remote servers will treat it as a server and will share every discovery information. */ + +} DiscoveryProtocol_t; + +inline std::ostream& operator <<( + std::ostream& output, + const DiscoveryProtocol& discovery_protocol) +{ + switch (discovery_protocol) + { + case DiscoveryProtocol::NONE: + output << fastdds::rtps::ParticipantType::NONE; + break; + case DiscoveryProtocol::SIMPLE: + output << fastdds::rtps::ParticipantType::SIMPLE; + break; + case DiscoveryProtocol::EXTERNAL: + output << fastdds::rtps::ParticipantType::EXTERNAL; + break; + case DiscoveryProtocol::CLIENT: + output << fastdds::rtps::ParticipantType::CLIENT; + break; + case DiscoveryProtocol::SUPER_CLIENT: + output << fastdds::rtps::ParticipantType::SUPER_CLIENT; + break; + case DiscoveryProtocol::SERVER: + output << fastdds::rtps::ParticipantType::SERVER; + break; + case DiscoveryProtocol::BACKUP: + output << fastdds::rtps::ParticipantType::BACKUP; + break; + default: + output << fastdds::rtps::ParticipantType::UNKNOWN; + } + return output; +} + +//! Filtering flags when discovering participants +typedef enum ParticipantFilteringFlags : uint32_t +{ + NO_FILTER = 0, + FILTER_DIFFERENT_HOST = 0x1, + FILTER_DIFFERENT_PROCESS = 0x2, + FILTER_SAME_PROCESS = 0x4 +} ParticipantFilteringFlags_t; + +#define BUILTIN_DATA_MAX_SIZE 512 + +//! PDP factory for EXTERNAL type +class PDP; +class BuiltinProtocols; + +typedef struct _PDPFactory +{ + // Pointer to the PDP creator + PDP* (*CreatePDPInstance)(BuiltinProtocols*); + // Pointer to the PDP destructor + void (* ReleasePDPInstance)( + PDP*); + + bool operator ==( + const struct _PDPFactory& e) const + { + return (CreatePDPInstance == e.CreatePDPInstance) + && (ReleasePDPInstance == e.ReleasePDPInstance); + } + +} PDPFactory; + +/** + * Class SimpleEDPAttributes, to define the attributes of the Simple Endpoint Discovery Protocol. + * @ingroup RTPS_ATTRIBUTES_MODULE + */ +class SimpleEDPAttributes +{ +public: + + //!Default value true. + bool use_PublicationWriterANDSubscriptionReader; + + //!Default value true. + bool use_PublicationReaderANDSubscriptionWriter; + +#if HAVE_SECURITY + bool enable_builtin_secure_publications_writer_and_subscriptions_reader; + + bool enable_builtin_secure_subscriptions_writer_and_publications_reader; +#endif // if HAVE_SECURITY + + SimpleEDPAttributes() + : use_PublicationWriterANDSubscriptionReader(true) + , use_PublicationReaderANDSubscriptionWriter(true) +#if HAVE_SECURITY + , enable_builtin_secure_publications_writer_and_subscriptions_reader(true) + , enable_builtin_secure_subscriptions_writer_and_publications_reader(true) +#endif // if HAVE_SECURITY + { + } + + bool operator ==( + const SimpleEDPAttributes& b) const + { + return (this->use_PublicationWriterANDSubscriptionReader == b.use_PublicationWriterANDSubscriptionReader) && +#if HAVE_SECURITY + (this->enable_builtin_secure_publications_writer_and_subscriptions_reader == + b.enable_builtin_secure_publications_writer_and_subscriptions_reader) && + (this->enable_builtin_secure_subscriptions_writer_and_publications_reader == + b.enable_builtin_secure_subscriptions_writer_and_publications_reader) && +#endif // if HAVE_SECURITY + (this->use_PublicationReaderANDSubscriptionWriter == b.use_PublicationReaderANDSubscriptionWriter); + } + +}; + +/** + * Struct InitialAnnouncementConfig defines the behavior of the RTPSParticipant initial announcements. + * @ingroup RTPS_ATTRIBUTES_MODULE + */ +struct InitialAnnouncementConfig +{ + /// Number of initial announcements with specific period (default 5) + uint32_t count = 5u; + + /// Specific period for initial announcements (default 100ms) + Duration_t period = { 0, 100000000u }; + + bool operator ==( + const InitialAnnouncementConfig& b) const + { + return (count == b.count) && (period == b.period); + } + +}; + +/** + * Class DiscoverySettings, to define the attributes of the several discovery protocols available + * @ingroup RTPS_ATTRIBUTES_MODULE + */ + +class DiscoverySettings +{ +public: + + //! Chosen discovery protocol + DiscoveryProtocol_t discoveryProtocol = DiscoveryProtocol_t::SIMPLE; + + /** + * If set to true, SimpleEDP would be used. + */ + bool use_SIMPLE_EndpointDiscoveryProtocol = true; + + /** + * If set to true, StaticEDP based on an XML file would be implemented. + * The XML filename must be provided. + */ + bool use_STATIC_EndpointDiscoveryProtocol = false; + + /** + * Lease Duration of the RTPSParticipant, + * indicating how much time remote RTPSParticipants should consider this RTPSParticipant alive. + */ + Duration_t leaseDuration = { 20, 0 }; + + /** + * The period for the RTPSParticipant to send its Discovery Message to all other discovered RTPSParticipants + * as well as to all Multicast ports. + */ + Duration_t leaseDuration_announcementperiod = { 3, 0 }; + + //!Initial announcements configuration + InitialAnnouncementConfig initial_announcements; + + //!Attributes of the SimpleEDP protocol + SimpleEDPAttributes m_simpleEDP; + + //! function that returns a PDP object (only if EXTERNAL selected) + PDPFactory m_PDPfactory{}; + /** + * The period for the RTPSParticipant to: + * send its Discovery Message to its servers + * check for EDP endpoints matching + */ + Duration_t discoveryServer_client_syncperiod = { 0, 450 * 1000000}; // 450 milliseconds + + //! Discovery Server settings, only needed if use_CLIENT_DiscoveryProtocol=true + eprosima::fastdds::rtps::RemoteServerList_t m_DiscoveryServers; + + //! Filtering participants out depending on location + ParticipantFilteringFlags_t ignoreParticipantFlags = ParticipantFilteringFlags::NO_FILTER; + + DiscoverySettings() = default; + + bool operator ==( + const DiscoverySettings& b) const + { + return (this->discoveryProtocol == b.discoveryProtocol) && + (this->use_SIMPLE_EndpointDiscoveryProtocol == b.use_SIMPLE_EndpointDiscoveryProtocol) && + (this->use_STATIC_EndpointDiscoveryProtocol == b.use_STATIC_EndpointDiscoveryProtocol) && + (this->discoveryServer_client_syncperiod == b.discoveryServer_client_syncperiod) && + (this->m_PDPfactory == b.m_PDPfactory) && + (this->leaseDuration == b.leaseDuration) && + (this->leaseDuration_announcementperiod == b.leaseDuration_announcementperiod) && + (this->initial_announcements == b.initial_announcements) && + (this->m_simpleEDP == b.m_simpleEDP) && + (this->static_edp_xml_config_ == b.static_edp_xml_config_) && + (this->m_DiscoveryServers == b.m_DiscoveryServers) && + (this->ignoreParticipantFlags == b.ignoreParticipantFlags); + } + + /** + * Get the static endpoint XML filename + * @return Static endpoint XML filename + */ + FASTRTPS_DEPRECATED("Use static_edp_xml_config()") + const char* getStaticEndpointXMLFilename() const + { + return static_edp_xml_config(); + } + + /** + * Set the static endpoint XML filename + * @param str Static endpoint XML filename + * @deprecated + */ + FASTRTPS_DEPRECATED("Use static_edp_xml_config()") + void setStaticEndpointXMLFilename( + const char* str) + { + static_edp_xml_config_ = "file://" + std::string(str); + } + + /** + * Set the static endpoint XML configuration. + * @param str URI specifying the static endpoint XML configuration. + * The string could contain a filename (file://) or the XML content directly (data://). + */ + void static_edp_xml_config( + const char* str) + { + static_edp_xml_config_ = str; + } + + /** + * Get the static endpoint XML configuration. + * @return URI specifying the static endpoint XML configuration. + * The string could contain a filename (file://) or the XML content directly (data://). + */ + const char* static_edp_xml_config() const + { + return static_edp_xml_config_.c_str(); + } + +private: + + //! URI specifying the static EDP XML configuration, only necessary if use_STATIC_EndpointDiscoveryProtocol=true + //! This string could contain a filename or the XML content directly. + std::string static_edp_xml_config_ = ""; +}; + +/** + * TypeLookupService settings. + */ +class TypeLookupSettings +{ +public: + + //!Indicates to use the TypeLookup Service client endpoints + bool use_client = false; + + //!Indicates to use the TypeLookup Service server endpoints + bool use_server = false; + +}; + +/** + * Class BuiltinAttributes, to define the behavior of the RTPSParticipant builtin protocols. + * @ingroup RTPS_ATTRIBUTES_MODULE + */ +class BuiltinAttributes +{ +public: + + //! Discovery protocol related attributes + DiscoverySettings discovery_config; + + //! Indicates to use the WriterLiveliness protocol. + bool use_WriterLivelinessProtocol = true; + + //! TypeLookup Service settings + TypeLookupSettings typelookup_config; + + //! Metatraffic Unicast Locator List + LocatorList_t metatrafficUnicastLocatorList; + + //! Metatraffic Multicast Locator List. + LocatorList_t metatrafficMulticastLocatorList; + + //! The collection of external locators to use for communication on metatraffic topics. + fastdds::rtps::ExternalLocators metatraffic_external_unicast_locators; + + //! Initial peers. + LocatorList_t initialPeersList; + + //! Memory policy for builtin readers + MemoryManagementPolicy_t readerHistoryMemoryPolicy = + MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + + //! Maximum payload size for builtin readers + uint32_t readerPayloadSize = BUILTIN_DATA_MAX_SIZE; + + //! Memory policy for builtin writers + MemoryManagementPolicy_t writerHistoryMemoryPolicy = + MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + + //! Maximum payload size for builtin writers + uint32_t writerPayloadSize = BUILTIN_DATA_MAX_SIZE; + + //! Mutation tries if the port is being used. + uint32_t mutation_tries = 100u; + + //! Set to true to avoid multicast traffic on builtin endpoints + bool avoid_builtin_multicast = true; + + BuiltinAttributes() = default; + + virtual ~BuiltinAttributes() = default; + + bool operator ==( + const BuiltinAttributes& b) const + { + return (this->discovery_config == b.discovery_config) && + (this->use_WriterLivelinessProtocol == b.use_WriterLivelinessProtocol) && + (typelookup_config.use_client == b.typelookup_config.use_client) && + (typelookup_config.use_server == b.typelookup_config.use_server) && + (this->metatrafficUnicastLocatorList == b.metatrafficUnicastLocatorList) && + (this->metatrafficMulticastLocatorList == b.metatrafficMulticastLocatorList) && + (this->metatraffic_external_unicast_locators == b.metatraffic_external_unicast_locators) && + (this->initialPeersList == b.initialPeersList) && + (this->readerHistoryMemoryPolicy == b.readerHistoryMemoryPolicy) && + (this->readerPayloadSize == b.readerPayloadSize) && + (this->writerHistoryMemoryPolicy == b.writerHistoryMemoryPolicy) && + (this->writerPayloadSize == b.writerPayloadSize) && + (this->mutation_tries == b.mutation_tries) && + (this->avoid_builtin_multicast == b.avoid_builtin_multicast); + } + +}; + +/** + * Class RTPSParticipantAttributes used to define different aspects of a RTPSParticipant. + * @ingroup RTPS_ATTRIBUTES_MODULE + */ +class RTPSParticipantAttributes +{ + using FlowControllerDescriptorList = std::vector>; + +public: + + RTPSParticipantAttributes() = default; + + virtual ~RTPSParticipantAttributes() = default; + + bool operator ==( + const RTPSParticipantAttributes& b) const + { + return (this->name == b.name) && + (this->defaultUnicastLocatorList == b.defaultUnicastLocatorList) && + (this->defaultMulticastLocatorList == b.defaultMulticastLocatorList) && + (this->default_external_unicast_locators == b.default_external_unicast_locators) && + (this->ignore_non_matching_locators == b.ignore_non_matching_locators) && + (this->sendSocketBufferSize == b.sendSocketBufferSize) && + (this->listenSocketBufferSize == b.listenSocketBufferSize) && + (this->builtin == b.builtin) && + (this->port == b.port) && + (this->userData == b.userData) && + (this->participantID == b.participantID) && + (this->throughputController == b.throughputController) && + (this->useBuiltinTransports == b.useBuiltinTransports) && + (this->properties == b.properties) && + (this->prefix == b.prefix) && + (this->flow_controllers == b.flow_controllers); + } + + /** + * Provides a way of easily configuring transport related configuration on certain pre-defined scenarios. + * + * @param transports Defines the transport configuration scenario to setup. + */ + void setup_transports( + fastdds::rtps::BuiltinTransports /*transports*/) + { + // Only include UDPv4 behavior for mock tests + setup_transports_default(*this); + useBuiltinTransports = false; + } + + static void setup_transports_default( + RTPSParticipantAttributes& att) + { + auto descriptor = create_udpv4_transport(att); + + att.userTransports.push_back(descriptor); + } + + static std::shared_ptr create_udpv4_transport( + const RTPSParticipantAttributes& att) + { + auto descriptor = std::make_shared(); + descriptor->sendBufferSize = att.sendSocketBufferSize; + descriptor->receiveBufferSize = att.listenSocketBufferSize; + + return descriptor; + } + + /** + * Default list of Unicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the case + * that it was defined with NO UnicastLocators. At least ONE locator should be included in this list. + */ + LocatorList_t defaultUnicastLocatorList; + + /** + * Default list of Multicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the + * case that it was defined with NO MulticastLocators. This is usually left empty. + */ + LocatorList_t defaultMulticastLocatorList; + + /** + * The collection of external locators to use for communication on user created topics. + */ + fastdds::rtps::ExternalLocators default_external_unicast_locators; + + /** + * Whether locators that don't match with the announced locators should be kept. + */ + bool ignore_non_matching_locators = false; + + /*! + * @brief Send socket buffer size for the send resource. Zero value indicates to use default system buffer size. + * Default value: 0. + */ + uint32_t sendSocketBufferSize = 0; + + /*! Listen socket buffer for all listen resources. Zero value indicates to use default system buffer size. + * Default value: 0. + */ + uint32_t listenSocketBufferSize = 0; + + //! Optionally allows user to define the GuidPrefix_t + GuidPrefix_t prefix; + + RTPS_DllAPI inline bool ReadguidPrefix( + const char* pfx) + { + return bool(std::istringstream(pfx) >> prefix); + } + + //! Builtin parameters. + BuiltinAttributes builtin; + + //! Port Parameters + PortParameters port; + + //! User Data of the participant + std::vector userData; + + //! Participant ID + int32_t participantID = -1; + + /** + * @brief Throughput controller parameters. Leave default for uncontrolled flow. + * + * @deprecated Use flow_controllers on RTPSParticipantAttributes + */ + ThroughputControllerDescriptor throughputController; + + //! User defined transports to use alongside or in place of builtins. + std::vector> userTransports; + + //! Set as false to disable the creation of the default transports. + bool useBuiltinTransports = true; + + //! Holds allocation limits affecting collections managed by a participant. + RTPSParticipantAllocationAttributes allocation; + + //! Property policies + PropertyPolicy properties; + + //! Set the name of the participant. + inline void setName( + const char* nam) + { + name = nam; + } + + //! Get the name of the participant. + inline const char* getName() const + { + return name.c_str(); + } + + //! Flow controllers. + FlowControllerDescriptorList flow_controllers; + +private: + + //! Name of the participant. + string_255 name{"RTPSParticipant"}; +}; + +} // namespace rtps +} // namespace fastrtps +} // namespace eprosima + +#endif // _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index f2c6c86df50..2c255276a2d 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -49,7 +49,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include #include @@ -76,6 +80,7 @@ #define GET_PID getpid #endif // if defined(_WIN32) + namespace eprosima { namespace fastdds { namespace dds { @@ -92,7 +97,6 @@ using fastrtps::types::TypeDescriptor; using fastrtps::xmlparser::XMLP_ret; using fastrtps::xmlparser::XMLProfileManager; - // Mocked TopicDataType for Topic creation tests class TopicDataTypeMock : public TopicDataType { @@ -3944,6 +3948,230 @@ TEST(ParticipantTests, TwoParticipantWithSameFixedId) } } + +TEST(ParticipantTests, ParticipantCreationWithBuiltinTransport) +{ + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::DEFAULT); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + return true; + } + } + return false; + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + } + + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::DEFAULTv6); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + return true; + } + } + return false; + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + } + + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::SHM); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + return true; + } + } + return false; + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + + } + + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::UDPv4); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + return true; + } + } + return false; + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + } + + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::UDPv6); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + return true; + } + } + return false; + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + } + + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::LARGE_DATA); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + bool hasSHM = false; + bool hasUDP = false; + bool hasTCP = false; + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + hasSHM = true; + } + else if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + hasUDP = true; + } + else if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + hasTCP = true; + } + } + + return (hasSHM && hasUDP && hasTCP); + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + } + + { + DomainParticipantQos qos; + fastrtps::rtps::RTPSParticipantAttributes attributes_; + qos.setup_transports(rtps::BuiltinTransports::LARGE_DATAv6); + + DomainParticipant* participant_ = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant_); + + get_rtps_attributes(participant_, attributes_); + + auto transport_check = [](fastrtps::rtps::RTPSParticipantAttributes& attributes_) -> bool + { + bool hasSHM = false; + bool hasUDP = false; + bool hasTCP = false; + for (auto& transportDescriptor : attributes_.userTransports) + { + if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + hasSHM = true; + } + else if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + hasUDP = true; + } + else if ( nullptr != + dynamic_cast(transportDescriptor.get())) + { + hasTCP = true; + } + } + + return (hasSHM && hasUDP && hasTCP); + }; + EXPECT_TRUE(transport_check(attributes_)); + EXPECT_FALSE(attributes_.useBuiltinTransports); + } +} + + + } // namespace dds } // namespace fastdds } // namespace eprosima diff --git a/test/unittest/dds/publisher/CMakeLists.txt b/test/unittest/dds/publisher/CMakeLists.txt index 4e74d08e9a8..af48e23af16 100644 --- a/test/unittest/dds/publisher/CMakeLists.txt +++ b/test/unittest/dds/publisher/CMakeLists.txt @@ -152,6 +152,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ExternalLocatorsProcessor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ReceiverResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/RTPSParticipantAttributes.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/participant/RTPSParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/participant/RTPSParticipantImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/persistence/PersistenceFactory.cpp diff --git a/test/unittest/dds/status/CMakeLists.txt b/test/unittest/dds/status/CMakeLists.txt index 80d2d823545..e9cb3fb34aa 100644 --- a/test/unittest/dds/status/CMakeLists.txt +++ b/test/unittest/dds/status/CMakeLists.txt @@ -160,6 +160,7 @@ target_include_directories(ListenerTests PRIVATE ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSWriter ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSDomain ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSDomainImpl + ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipantAttributes ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipant ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipantImpl ${PROJECT_SOURCE_DIR}/test/mock/rtps/Endpoint diff --git a/test/unittest/dynamic_types/CMakeLists.txt b/test/unittest/dynamic_types/CMakeLists.txt index a709601897a..8472c9c8108 100644 --- a/test/unittest/dynamic_types/CMakeLists.txt +++ b/test/unittest/dynamic_types/CMakeLists.txt @@ -115,13 +115,14 @@ target_compile_definitions(DynamicTypesTests PRIVATE ) target_include_directories(DynamicTypesTests PRIVATE ${Asio_INCLUDE_DIR} + ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv6TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor - ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor + ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipantAttributes $<$:${TINYXML2_INCLUDE_DIR}> ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/src/cpp diff --git a/test/unittest/statistics/dds/CMakeLists.txt b/test/unittest/statistics/dds/CMakeLists.txt index 7e6d3579e42..46371819708 100644 --- a/test/unittest/statistics/dds/CMakeLists.txt +++ b/test/unittest/statistics/dds/CMakeLists.txt @@ -215,6 +215,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ExternalLocatorsProcessor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ReceiverResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/RTPSParticipantAttributes.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/participant/RTPSParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/participant/RTPSParticipantImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/persistence/PersistenceFactory.cpp diff --git a/test/unittest/xmlparser/CMakeLists.txt b/test/unittest/xmlparser/CMakeLists.txt index d314e15da64..ec7277a215a 100644 --- a/test/unittest/xmlparser/CMakeLists.txt +++ b/test/unittest/xmlparser/CMakeLists.txt @@ -149,7 +149,9 @@ target_include_directories(XMLProfileParserTests PRIVATE ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor + ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipantAttributes ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include + ${PROJECT_SOURCE_DIR}/src/cpp ${Asio_INCLUDE_DIR} $<$:${ANDROID_IFADDRS_INCLUDE_DIR}> ) @@ -240,13 +242,14 @@ target_compile_definitions(XMLParserTests PRIVATE $<$:__INTERNALDEBUG> # Internal debug activated. ) target_include_directories(XMLParserTests PRIVATE + ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv6TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor - ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor + ${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipantAttributes ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/src/cpp diff --git a/test/unittest/xmlparser/XMLElementParserTests.cpp b/test/unittest/xmlparser/XMLElementParserTests.cpp index 768012ddb75..ffd179e8ae3 100644 --- a/test/unittest/xmlparser/XMLElementParserTests.cpp +++ b/test/unittest/xmlparser/XMLElementParserTests.cpp @@ -467,8 +467,8 @@ TEST_F(XMLParserTests, getXMLLocatorTCPv4) * 1. Correct parsing of a valid element. * 2. Check an empty definition of . * 3. Check an empty definition of . - * 5. Check an empty definition of
. - * 6. Check an bad element as a child xml element. + * 4. Check an empty definition of
. + * 5. Check an bad element as a child xml element. */ TEST_F(XMLParserTests, getXMLLocatorTCPv6) { @@ -537,8 +537,8 @@ TEST_F(XMLParserTests, getXMLLocatorTCPv6) * 1. Correct parsing of a valid descriptor present in the XmlProfileManager. * 2. Check a reference to a non existentTransportDescriptorInterface. * 3. Check an empty definition of . - * 5. Check an empty definition of . - * 6. Check an empty list of transports. + * 4. Check an empty definition of . + * 5. Check an empty list of transports. */ TEST_F(XMLParserTests, getXMLTransports) { @@ -602,14 +602,70 @@ TEST_F(XMLParserTests, getXMLTransports) xmlparser::XMLProfileManager::DeleteInstance(); } +/* + * This test checks the proper parsing of the xml elements and negative cases. + * 1. Correct parsing of all valid values of BuiltinTransport. + * 2. Check a wrong definition of . + * 3. Check an empty definition of . + */ +TEST_F(XMLParserTests, getXMLbuiltinTransports) +{ + uint8_t ident = 1; + eprosima::fastdds::rtps::BuiltinTransports bt; + tinyxml2::XMLDocument xml_doc; + tinyxml2::XMLElement* titleElement; + + // Parametrized XML + const char* xml_p = + "\ + %s\ + "; + constexpr size_t xml_len {500}; + char xml[xml_len]; + + // Valid XML + std::vector bt_list; + bt_list.push_back("NONE"); + bt_list.push_back("DEFAULT"); + bt_list.push_back("DEFAULTv6"); + bt_list.push_back("SHM"); + bt_list.push_back("UDPv4"); + bt_list.push_back("UDPv6"); + bt_list.push_back("LARGE_DATA"); + bt_list.push_back("LARGE_DATAv6"); + + for (auto test_transport : bt_list) + { + snprintf(xml, xml_len, xml_p, test_transport.c_str()); + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml)); + titleElement = xml_doc.RootElement(); + ASSERT_EQ(XMLP_ret::XML_OK, XMLParserTest::getXMLBuiltinTransports_wrapper(titleElement, &bt, ident)); + } + + // Wrong ID + snprintf(xml, xml_len, xml_p, "WrongBuiltinTransport"); + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml)); + titleElement = xml_doc.RootElement(); + ASSERT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::getXMLBuiltinTransports_wrapper(titleElement, &bt, ident)); + + // Missing data + snprintf(xml, xml_len, xml_p, ""); + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml)); + titleElement = xml_doc.RootElement(); + ASSERT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::getXMLBuiltinTransports_wrapper(titleElement, &bt, ident)); + + // Clean up + xmlparser::XMLProfileManager::DeleteInstance(); +} + /* * This test checks the proper parsing of the xml elements to a PropertyPolicy object, and negative * cases. * 1. Correct parsing of a valid . * 2. Check missing values for the possible elemnts of the properties. * 3. Check an empty list of . - * 5. Check an empty list of . - * 6. Check an wrong descriptor for properties. + * 4. Check an empty list of . + * 5. Check an wrong descriptor for properties. */ TEST_F(XMLParserTests, getXMLPropertiesPolicy) { diff --git a/test/unittest/xmlparser/wrapper/XMLParserTest.hpp b/test/unittest/xmlparser/wrapper/XMLParserTest.hpp index 20397426b06..f87c5886960 100644 --- a/test/unittest/xmlparser/wrapper/XMLParserTest.hpp +++ b/test/unittest/xmlparser/wrapper/XMLParserTest.hpp @@ -150,6 +150,14 @@ class XMLParserTest : public XMLParser return getXMLTransports(elem, transports, ident); } + static XMLP_ret getXMLBuiltinTransports_wrapper( + tinyxml2::XMLElement* elem, + eprosima::fastdds::rtps::BuiltinTransports* bt, + uint8_t ident) + { + return getXMLBuiltinTransports(elem, bt, ident); + } + static XMLP_ret getXMLguidPrefix_wrapper( tinyxml2::XMLElement* elem, GuidPrefix_t& prefix, diff --git a/versions.md b/versions.md index f004ef08779..2992d58bd62 100644 --- a/versions.md +++ b/versions.md @@ -1,6 +1,12 @@ Forthcoming ----------- +* Added the possibility to define a listening port equal to 0 in TCP Transport +* Added support for TCP to Fast DDS CLI and environment variable +* Enable Discovery Server example through TCP +* Added configuration of builtin transports through DomainParticipantQos, environment + variable and XML. + Version 2.10.2 --------------