From 3c15103b4b51ecef19edecea7b0b8c5e1d28f635 Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 1 Feb 2023 08:04:33 +0100 Subject: [PATCH 01/38] Refactor code Signed-off-by: jparisu --- .dev/README.md | 12 + .../configuration/DDSRouterConfiguration.hpp | 17 +- .../DDSRouterReloadConfiguration.hpp | 2 +- .../include/ddsrouter_core/core/DDSRouter.hpp | 7 +- .../core/ParticipantsDatabase.hpp | 43 +-- .../dynamic/AllowedTopicList.hpp | 0 .../dynamic/DiscoveryDatabase.hpp | 0 .../cache_change/CacheChangePool.hpp | 0 .../efficiency/payload/CopyPayloadPool.hpp | 2 +- .../efficiency/payload/FastPayloadPool.hpp | 2 +- .../efficiency/payload/MapPayloadPool.hpp | 2 +- .../efficiency/payload/PayloadPool.hpp | 0 .../participant/IParticipant.hpp | 19 +- .../ddsrouter_core/participants/.dev.md | 1 + .../participant}/auxiliar/BaseParticipant.hpp | 67 +++-- .../auxiliar/BlankParticipant.hpp | 33 ++- .../auxiliar/DummyParticipant.hpp | 42 +-- .../participant}/auxiliar/EchoParticipant.hpp | 25 +- ...iscoveryServerParticipantConfiguration.hpp | 31 +-- .../EchoParticipantConfiguration.hpp | 8 +- .../InitialPeersParticipantConfiguration.hpp | 27 +- .../ParticipantConfiguration.hpp | 17 +- .../SimpleParticipantConfiguration.hpp | 15 +- .../participant}/rtps/CommonParticipant.hpp | 38 +-- .../rtps/DiscoveryServerParticipant.hpp | 16 +- .../rtps/InitialPeersParticipant.hpp | 16 +- .../participant}/rtps/SimpleParticipant.hpp | 14 +- .../reader}/auxiliar/BaseReader.hpp | 30 +-- .../reader}/auxiliar/BlankReader.hpp | 10 +- .../reader}/auxiliar/DummyReader.hpp | 12 +- .../reader}/rtps/CommonReader.hpp | 26 +- .../reader}/rtps/SimpleReader.hpp | 12 +- .../reader}/rtps/SpecificQoSReader.hpp | 22 +- .../writer}/auxiliar/BaseWriter.hpp | 24 +- .../writer}/auxiliar/BlankWriter.hpp | 10 +- .../writer}/auxiliar/DummyWriter.hpp | 14 +- .../writer}/auxiliar/EchoWriter.hpp | 12 +- .../writer}/rtps/CommonWriter.hpp | 34 +-- .../participants/writer}/rtps/MultiWriter.hpp | 24 +- .../writer}/rtps/QoSSpecificWriter.hpp | 20 +- .../writer}/rtps/SimpleWriter.hpp | 14 +- .../rtps/filter/RepeaterDataFilter.cpp | 8 +- .../rtps/filter/RepeaterDataFilter.hpp | 7 +- .../writer}/rtps/filter/SelfDataFilter.cpp | 6 +- .../writer}/rtps/filter/SelfDataFilter.hpp | 5 +- .../ddsrouter_core}/reader/IReader.hpp | 2 +- .../types/participant/ParticipantId.hpp | 106 +------- .../types/participant/ParticipantKind.hpp | 129 --------- .../ddsrouter_core}/writer/IWriter.hpp | 2 +- .../src/cpp/communication/DDSBridge.cpp | 1 - .../src/cpp/communication/Track.hpp | 6 +- .../src/cpp/communication/rpc/RPCBridge.cpp | 11 +- .../src/cpp/communication/rpc/RPCBridge.hpp | 18 +- .../configuration/DDSRouterConfiguration.cpp | 91 +------ ddsrouter_core/src/cpp/core/DDSRouter.cpp | 8 +- ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp | 75 +----- ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp | 19 +- .../src/cpp/core/ParticipantsDatabase.cpp | 44 +--- .../cache_change/CacheChangePool.cpp | 2 +- .../efficiency/payload/CopyPayloadPool.cpp | 2 +- .../efficiency/payload/FastPayloadPool.cpp | 2 +- .../cpp/efficiency/payload/MapPayloadPool.cpp | 2 +- .../cpp/efficiency/payload/PayloadPool.cpp | 2 +- .../participant}/auxiliar/BaseParticipant.cpp | 62 ++--- .../auxiliar/BlankParticipant.cpp | 29 +-- .../auxiliar/DummyParticipant.cpp | 22 +- .../participant}/auxiliar/EchoParticipant.cpp | 26 +- ...iscoveryServerParticipantConfiguration.cpp | 20 +- .../InitialPeersParticipantConfiguration.cpp | 28 +- .../ParticipantConfiguration.cpp | 22 +- .../SimpleParticipantConfiguration.cpp | 12 +- .../participant}/rtps/CommonParticipant.cpp | 83 +++--- .../rtps/DiscoveryServerParticipant.cpp | 24 +- .../rtps/InitialPeersParticipant.cpp | 18 +- .../participant}/rtps/SimpleParticipant.cpp | 12 +- .../reader}/auxiliar/BaseReader.cpp | 10 +- .../reader}/auxiliar/BlankReader.cpp | 8 +- .../reader}/auxiliar/DummyReader.cpp | 8 +- .../reader}/rtps/CommonReader.cpp | 32 ++- .../reader}/rtps/SimpleReader.cpp | 8 +- .../reader}/rtps/SpecificQoSReader.cpp | 20 +- .../writer}/auxiliar/BaseWriter.cpp | 10 +- .../writer}/auxiliar/BlankWriter.cpp | 8 +- .../writer}/auxiliar/DummyWriter.cpp | 8 +- .../writer}/auxiliar/EchoWriter.cpp | 10 +- .../writer}/rtps/CommonWriter.cpp | 35 +-- .../writer}/rtps/MultiWriter.cpp | 24 +- .../writer}/rtps/QoSSpecificWriter.cpp | 14 +- .../writer}/rtps/SimpleWriter.cpp | 14 +- .../writer/rtps/filter/RepeaterDataFilter.cpp | 61 +++++ .../writer/rtps/filter/RepeaterDataFilter.hpp | 58 +++++ .../writer/rtps/filter/SelfDataFilter.cpp | 42 +++ .../writer/rtps/filter/SelfDataFilter.hpp | 66 +++++ .../cpp/types/participant/ParticipantId.cpp | 99 ------- .../cpp/types/participant/ParticipantKind.cpp | 85 ------ ddsrouter_core/test/TestUtils/test_utils.cpp | 2 +- ddsrouter_core/test/TestUtils/test_utils.hpp | 10 +- .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 4 +- .../dds/types/test_participants.hpp | 2 +- .../ddsrouter_core/trivial/TrivialTest.cpp | 4 +- .../implementations/ImplementationsTest.cpp | 6 +- .../test/unittest/core/CMakeLists.txt | 1 - .../core/participant_factory/CMakeLists.txt | 43 --- .../ParticipantFactoryTest.cpp | 97 ------- .../core/participants_database/CMakeLists.txt | 8 +- .../ParticipantsDatabaseTest.cpp | 2 +- .../test/unittest/types/CMakeLists.txt | 1 - .../unittest/types/endpoint/CMakeLists.txt | 1 - .../unittest/types/participant/CMakeLists.txt | 79 ------ .../types/participant/ParticipantIdTest.cpp | 246 ------------------ .../types/participant/ParticipantKindTest.cpp | 107 -------- ddsrouter_participants/CMakeLists.txt | 78 ++++++ ddsrouter_participants/README.md | 5 + .../ParticipantFactory.hpp | 31 +-- .../ParticipantKind.hpp | 52 ++++ ddsrouter_participants/package.xml | 32 +++ ddsrouter_participants/project_settings.cmake | 35 +++ .../src/cpp}/ParticipantFactory.cpp | 83 +++--- ddsrouter_participants/test/CMakeLists.txt | 15 ++ .../include/ddsrouter_yaml/YamlReader.hpp | 14 + .../YamlReaderConfiguration.hpp | 30 ++- .../ddsrouter_yaml/impl/YamlReader.ipp | 38 +++ ddsrouter_yaml/package.xml | 1 + ddsrouter_yaml/project_settings.cmake | 3 +- ddsrouter_yaml/src/cpp/YamlReader.cpp | 177 ++++--------- .../src/cpp/YamlReaderConfiguration.cpp | 103 +++++++- ddsrouter_yaml/test/TestUtils/test_utils.hpp | 10 +- .../unittest/YamlConfigurationTestUtils.hpp | 2 +- .../YamlGetConfigurationDDSRouterTest.cpp | 2 +- ...lGetCommonParticipantConfigurationTest.cpp | 2 +- ...itialPeersParticipantConfigurationTest.cpp | 4 +- ...lGetSimpleParticipantConfigurationTest.cpp | 2 +- ...t_get_participant_connection_addresses.ipp | 2 +- ...nfigurationTest_get_participant_domain.ipp | 2 +- ...st_get_participant_listening_addresses.ipp | 2 +- ...figurationTest_get_participant_minimum.ipp | 2 +- ...igurationTest_get_participant_negative.ipp | 2 +- tools/ddsrouter_tool/package.xml | 1 + tools/ddsrouter_tool/project_settings.cmake | 3 +- tools/ddsrouter_tool/src/cpp/main.cpp | 59 ++++- 140 files changed, 1464 insertions(+), 2187 deletions(-) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/core/ParticipantsDatabase.hpp (72%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/dynamic/AllowedTopicList.hpp (100%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/dynamic/DiscoveryDatabase.hpp (100%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/efficiency/cache_change/CacheChangePool.hpp (100%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/efficiency/payload/CopyPayloadPool.hpp (96%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/efficiency/payload/FastPayloadPool.hpp (98%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/efficiency/payload/MapPayloadPool.hpp (98%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/efficiency/payload/PayloadPool.hpp (100%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/participant/IParticipant.hpp (86%) create mode 100644 ddsrouter_core/include/ddsrouter_core/participants/.dev.md rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/auxiliar/BaseParticipant.hpp (75%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/auxiliar/BlankParticipant.hpp (69%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/auxiliar/DummyParticipant.hpp (78%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/auxiliar/EchoParticipant.hpp (67%) rename ddsrouter_core/include/ddsrouter_core/{configuration/participant => participants/participant/configuration}/DiscoveryServerParticipantConfiguration.hpp (70%) rename ddsrouter_core/include/ddsrouter_core/{configuration/participant => participants/participant/configuration}/EchoParticipantConfiguration.hpp (90%) rename ddsrouter_core/include/ddsrouter_core/{configuration/participant => participants/participant/configuration}/InitialPeersParticipantConfiguration.hpp (73%) rename ddsrouter_core/include/ddsrouter_core/{configuration/participant => participants/participant/configuration}/ParticipantConfiguration.hpp (82%) rename ddsrouter_core/include/ddsrouter_core/{configuration/participant => participants/participant/configuration}/SimpleParticipantConfiguration.hpp (85%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/rtps/CommonParticipant.hpp (82%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/rtps/DiscoveryServerParticipant.hpp (72%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/rtps/InitialPeersParticipant.hpp (72%) rename ddsrouter_core/{src/cpp/participant/implementations => include/ddsrouter_core/participants/participant}/rtps/SimpleParticipant.hpp (79%) rename ddsrouter_core/{src/cpp/reader/implementations => include/ddsrouter_core/participants/reader}/auxiliar/BaseReader.hpp (87%) rename ddsrouter_core/{src/cpp/reader/implementations => include/ddsrouter_core/participants/reader}/auxiliar/BlankReader.hpp (88%) rename ddsrouter_core/{src/cpp/reader/implementations => include/ddsrouter_core/participants/reader}/auxiliar/DummyReader.hpp (88%) rename ddsrouter_core/{src/cpp/reader/implementations => include/ddsrouter_core/participants/reader}/rtps/CommonReader.hpp (91%) rename ddsrouter_core/{src/cpp/reader/implementations => include/ddsrouter_core/participants/reader}/rtps/SimpleReader.hpp (86%) rename ddsrouter_core/{src/cpp/reader/implementations => include/ddsrouter_core/participants/reader}/rtps/SpecificQoSReader.hpp (79%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/auxiliar/BaseWriter.hpp (86%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/auxiliar/BlankWriter.hpp (85%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/auxiliar/DummyWriter.hpp (88%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/auxiliar/EchoWriter.hpp (84%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/CommonWriter.hpp (89%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/MultiWriter.hpp (83%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/QoSSpecificWriter.hpp (80%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/SimpleWriter.hpp (87%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/filter/RepeaterDataFilter.cpp (89%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/filter/RepeaterDataFilter.hpp (93%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/filter/SelfDataFilter.cpp (90%) rename ddsrouter_core/{src/cpp/writer/implementations => include/ddsrouter_core/participants/writer}/rtps/filter/SelfDataFilter.hpp (97%) rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/reader/IReader.hpp (98%) delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantKind.hpp rename ddsrouter_core/{src/cpp => include/ddsrouter_core}/writer/IWriter.hpp (98%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/auxiliar/BaseParticipant.cpp (71%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/auxiliar/BlankParticipant.cpp (69%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/auxiliar/DummyParticipant.cpp (84%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/auxiliar/EchoParticipant.cpp (75%) rename ddsrouter_core/src/cpp/{configuration/participant => participants/participant/configuration}/DiscoveryServerParticipantConfiguration.cpp (87%) rename ddsrouter_core/src/cpp/{configuration/participant => participants/participant/configuration}/InitialPeersParticipantConfiguration.cpp (80%) rename ddsrouter_core/src/cpp/{configuration/participant => participants/participant/configuration}/ParticipantConfiguration.cpp (73%) rename ddsrouter_core/src/cpp/{configuration/participant => participants/participant/configuration}/SimpleParticipantConfiguration.cpp (85%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/rtps/CommonParticipant.cpp (80%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/rtps/DiscoveryServerParticipant.cpp (93%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/rtps/InitialPeersParticipant.cpp (95%) rename ddsrouter_core/src/cpp/{participant/implementations => participants/participant}/rtps/SimpleParticipant.cpp (78%) rename ddsrouter_core/src/cpp/{reader/implementations => participants/reader}/auxiliar/BaseReader.cpp (94%) rename ddsrouter_core/src/cpp/{reader/implementations => participants/reader}/auxiliar/BlankReader.cpp (85%) rename ddsrouter_core/src/cpp/{reader/implementations => participants/reader}/auxiliar/DummyReader.cpp (91%) rename ddsrouter_core/src/cpp/{reader/implementations => participants/reader}/rtps/CommonReader.cpp (93%) rename ddsrouter_core/src/cpp/{reader/implementations => participants/reader}/rtps/SimpleReader.cpp (88%) rename ddsrouter_core/src/cpp/{reader/implementations => participants/reader}/rtps/SpecificQoSReader.cpp (80%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/auxiliar/BaseWriter.cpp (90%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/auxiliar/BlankWriter.cpp (83%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/auxiliar/DummyWriter.cpp (91%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/auxiliar/EchoWriter.cpp (88%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/rtps/CommonWriter.cpp (91%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/rtps/MultiWriter.cpp (85%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/rtps/QoSSpecificWriter.cpp (84%) rename ddsrouter_core/src/cpp/{writer/implementations => participants/writer}/rtps/SimpleWriter.cpp (79%) create mode 100644 ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp create mode 100644 ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp create mode 100644 ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp create mode 100644 ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp delete mode 100644 ddsrouter_core/src/cpp/types/participant/ParticipantId.cpp delete mode 100644 ddsrouter_core/src/cpp/types/participant/ParticipantKind.cpp delete mode 100644 ddsrouter_core/test/unittest/core/participant_factory/CMakeLists.txt delete mode 100644 ddsrouter_core/test/unittest/core/participant_factory/ParticipantFactoryTest.cpp delete mode 100644 ddsrouter_core/test/unittest/types/participant/CMakeLists.txt delete mode 100644 ddsrouter_core/test/unittest/types/participant/ParticipantIdTest.cpp delete mode 100644 ddsrouter_core/test/unittest/types/participant/ParticipantKindTest.cpp create mode 100644 ddsrouter_participants/CMakeLists.txt create mode 100644 ddsrouter_participants/README.md rename {ddsrouter_core/src/cpp/core => ddsrouter_participants/include/ddsrouter_participants}/ParticipantFactory.hpp (66%) create mode 100644 ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp create mode 100644 ddsrouter_participants/package.xml create mode 100644 ddsrouter_participants/project_settings.cmake rename {ddsrouter_core/src/cpp/core => ddsrouter_participants/src/cpp}/ParticipantFactory.cpp (58%) create mode 100644 ddsrouter_participants/test/CMakeLists.txt diff --git a/.dev/README.md b/.dev/README.md index dd41b2b57..698f50ad7 100644 --- a/.dev/README.md +++ b/.dev/README.md @@ -155,3 +155,15 @@ must be created as an internal value and/or const to the object, or create some way that the configuration cannot be changed from outside without the internal object notice it. Also, configurations must support an `is_valid` method to check that it is in a coherent state. + +--- + +## WorkArounds + +> // TODO + +### RPC in Core refactor + +Doing the refactor to separate DDS Router from Core we encountered a difficulty because `RPCBridge` depends on `rtps::CommonReader`. +This makes impossible so far to separate Participants from the Core. +This should be solved in future versions by implementing a generic RPC Bridge without dependencies. diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp index bf903b8aa..6a02b625b 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -58,10 +57,9 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration * @todo use const & references or even eliminate this constructor */ DDSROUTER_CORE_DllAPI DDSRouterConfiguration( - std::set> allowlist, - std::set> blocklist, - std::set> builtin_topics, - std::set> participants_configurations, + const std::set>& allowlist, + const std::set>& blocklist, + const std::set>& builtin_topics, const SpecsConfiguration& advanced_options); ///////////////////////// @@ -80,18 +78,9 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration // VARIABLES ///////////////////////// - //! Participant configurations - std::set> participants_configurations = {}; - //! Advanced configurations SpecsConfiguration advanced_options; -protected: - - //! Auxiliar method to validate that class type of the participants are compatible with their kinds. - static bool check_correct_configuration_object_( - const std::shared_ptr configuration); - }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp index 3e8435f52..95cf43608 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp index 009d953e5..61134b6e1 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include namespace eprosima { @@ -55,7 +57,10 @@ class DDSRouter * @throw \c InitializationException in case \c IParticipants , \c IWriters or \c IReaders creation fails. */ DDSROUTER_CORE_DllAPI DDSRouter( - const configuration::DDSRouterConfiguration& configuration); + const configuration::DDSRouterConfiguration& configuration, + const std::shared_ptr& discovery_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& participants_database); /** * @brief Destroy the DDSRouter object diff --git a/ddsrouter_core/src/cpp/core/ParticipantsDatabase.hpp b/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp similarity index 72% rename from ddsrouter_core/src/cpp/core/ParticipantsDatabase.hpp rename to ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp index 8306ab7ce..c7c9d3d77 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantsDatabase.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp @@ -23,10 +23,9 @@ #include #include +#include #include -#include - namespace eprosima { namespace ddsrouter { namespace core { @@ -40,6 +39,8 @@ class ParticipantsDatabase { public: + ParticipantsDatabase() = default; + /** * Destructor * @@ -75,7 +76,7 @@ class ParticipantsDatabase * * @return map of pointers to participants indexed by ids */ - std::map> get_participants_map() const noexcept; + const std::map>& get_participants_map() const noexcept; //! Whether the database is empty bool empty() const noexcept; @@ -83,51 +84,25 @@ class ParticipantsDatabase //! Number of Participants in the Database size_t size() const noexcept; -protected: - - /** - * @brief Remove the Participant with this id from the database - * - * @warning this method should only be called from the DDSRouter - * - * @param [in] id: id of the participant to remove - * @return Pointer to Participant removed - */ - std::shared_ptr pop_( - const types::ParticipantId& id) noexcept; - - /** - * @brief Remove a Participant from the database - * - * This method calls \c pop_ with an arbitrary id (contained in the database) - * - * @param [in] id: id of the participant to remove - * @return Pointer to Participant removed - */ - std::shared_ptr pop_() noexcept; - /** * @brief Add a new participant * - * @warning this method should only be called from the DDSRouter - * * @param [in] id: Id of the new Participant * @param [in] participant: Pointer to the new Participant * * @throw \c IncosistentException if participant already exist (duplicated ids) */ - void add_participant_( - types::ParticipantId id, - std::shared_ptr participant); + void add_participant( + const types::ParticipantId& id, + const std::shared_ptr& participant); + +protected: //! Database variable to store participants pointers indexed by their ids std::map> participants_; //! Mutex to guard access to database mutable std::shared_timed_mutex mutex_; - - // DDSRouter must be friend class so it can call add_participant_ - friend class DDSRouterImpl; }; } /* namespace core */ diff --git a/ddsrouter_core/src/cpp/dynamic/AllowedTopicList.hpp b/ddsrouter_core/include/ddsrouter_core/dynamic/AllowedTopicList.hpp similarity index 100% rename from ddsrouter_core/src/cpp/dynamic/AllowedTopicList.hpp rename to ddsrouter_core/include/ddsrouter_core/dynamic/AllowedTopicList.hpp diff --git a/ddsrouter_core/src/cpp/dynamic/DiscoveryDatabase.hpp b/ddsrouter_core/include/ddsrouter_core/dynamic/DiscoveryDatabase.hpp similarity index 100% rename from ddsrouter_core/src/cpp/dynamic/DiscoveryDatabase.hpp rename to ddsrouter_core/include/ddsrouter_core/dynamic/DiscoveryDatabase.hpp diff --git a/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.hpp b/ddsrouter_core/include/ddsrouter_core/efficiency/cache_change/CacheChangePool.hpp similarity index 100% rename from ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.hpp rename to ddsrouter_core/include/ddsrouter_core/efficiency/cache_change/CacheChangePool.hpp diff --git a/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.hpp b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/CopyPayloadPool.hpp similarity index 96% rename from ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.hpp rename to ddsrouter_core/include/ddsrouter_core/efficiency/payload/CopyPayloadPool.hpp index 6e29a7f94..8ca8ec289 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.hpp +++ b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/CopyPayloadPool.hpp @@ -19,7 +19,7 @@ #ifndef __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_COPYPAYLOADPOOL_HPP_ #define __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_COPYPAYLOADPOOL_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.hpp b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/FastPayloadPool.hpp similarity index 98% rename from ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.hpp rename to ddsrouter_core/include/ddsrouter_core/efficiency/payload/FastPayloadPool.hpp index 6fafc4c41..dbf2b3808 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.hpp +++ b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/FastPayloadPool.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.hpp b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/MapPayloadPool.hpp similarity index 98% rename from ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.hpp rename to ddsrouter_core/include/ddsrouter_core/efficiency/payload/MapPayloadPool.hpp index 93f78be6d..657865595 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.hpp +++ b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/MapPayloadPool.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.hpp b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp similarity index 100% rename from ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.hpp rename to ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp diff --git a/ddsrouter_core/src/cpp/participant/IParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participant/IParticipant.hpp similarity index 86% rename from ddsrouter_core/src/cpp/participant/IParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participant/IParticipant.hpp index fafa15174..e92d96e65 100644 --- a/ddsrouter_core/src/cpp/participant/IParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participant/IParticipant.hpp @@ -21,12 +21,11 @@ #include #include -#include -#include -#include -#include -#include + +#include +#include +#include namespace eprosima { namespace ddsrouter { @@ -39,11 +38,8 @@ namespace core { * It also works as a factory for Writers and Readers. * * Every Participant is associated to a \c ParticipantId that uniquely identifies it. - * Every Participant is associated with a \c ParticipantKind depending on its implementation. * * @note In order to implement new Participants, create a subclass of this Interface and implement every method. - * @note Also it is needed to add the creation of the Participant in the \c ParticipantFactory and a new type of - * @note \c ParticipantKind . */ class IParticipant { @@ -56,12 +52,7 @@ class IParticipant */ virtual types::ParticipantId id() const noexcept = 0; - /** - * @brief Return the Participant kind - * - * @return This Participant kind - */ - virtual types::ParticipantKind kind() const noexcept = 0; + virtual void start() = 0; //! Whether this participant is RTPS virtual bool is_rtps_kind() const noexcept = 0; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/.dev.md b/ddsrouter_core/include/ddsrouter_core/participants/.dev.md new file mode 100644 index 000000000..e7bb78ed7 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/participants/.dev.md @@ -0,0 +1 @@ +This directory should be moved under ddsrouter_participants once it is solved the dependencies on the RPCBridge. diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp similarity index 75% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp index 7cf6fee95..cbec4c9b9 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp @@ -21,15 +21,15 @@ #include -#include +#include -#include -#include -#include +#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Abstract Participant that implements generic methods for every Participant. @@ -38,7 +38,7 @@ namespace core { * * This class stores every Endpoint created by this Participant. */ -class BaseParticipant : public IParticipant +class BaseParticipant : public core::IParticipant { public: @@ -53,9 +53,9 @@ class BaseParticipant : public IParticipant * @param discovery_database DDS Router shared Discovery Database */ BaseParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database); /** * @brief Destroy the Base Participant object @@ -71,16 +71,7 @@ class BaseParticipant : public IParticipant * * Thread safe with mutex \c mutex_ . */ - types::ParticipantId id() const noexcept override; - - /** - * @brief Override kind() IParticipant method - * - * It gets the kind from the configuration. - * - * Thread safe with mutex \c mutex_ . - */ - types::ParticipantKind kind() const noexcept override; + core::types::ParticipantId id() const noexcept override; /** * @brief Override is_rtps_kind() IParticipant method @@ -106,8 +97,8 @@ class BaseParticipant : public IParticipant * * Thread safe with mutex \c mutex_ . */ - std::shared_ptr create_writer( - types::DdsTopic topic) override; + std::shared_ptr create_writer( + core::types::DdsTopic topic) override; /** * @brief Override create_reader() IParticipant method @@ -117,8 +108,8 @@ class BaseParticipant : public IParticipant * * Thread safe with mutex \c mutex_ . */ - std::shared_ptr create_reader( - types::DdsTopic topic) override; + std::shared_ptr create_reader( + core::types::DdsTopic topic) override; /** * @brief Override delete_writer() IParticipant method @@ -128,7 +119,7 @@ class BaseParticipant : public IParticipant * Thread safe with mutex \c mutex_ . */ void delete_writer( - std::shared_ptr writer) noexcept override; + std::shared_ptr writer) noexcept override; /** * @brief Override delete_reader() IParticipant method @@ -138,7 +129,7 @@ class BaseParticipant : public IParticipant * Thread safe with mutex \c mutex_ . */ void delete_reader( - std::shared_ptr reader) noexcept override; + std::shared_ptr reader) noexcept override; protected: @@ -150,8 +141,8 @@ class BaseParticipant : public IParticipant * @param [in] topic : Topic that this Writer refers to. * @return Writer */ - virtual std::shared_ptr create_writer_( - types::DdsTopic topic) = 0; + virtual std::shared_ptr create_writer_( + core::types::DdsTopic topic) = 0; /** * @brief Create a reader object @@ -161,8 +152,8 @@ class BaseParticipant : public IParticipant * @param [in] topic : Topic that this Reader refers to. * @return Reader */ - virtual std::shared_ptr create_reader_( - types::DdsTopic topic) = 0; + virtual std::shared_ptr create_reader_( + core::types::DdsTopic topic) = 0; /** * @brief Do nothing @@ -172,7 +163,7 @@ class BaseParticipant : public IParticipant * @param [in] writer : Writer to delete */ virtual void delete_writer_( - std::shared_ptr writer) noexcept; + std::shared_ptr writer) noexcept; /** * @brief Do nothing @@ -182,7 +173,7 @@ class BaseParticipant : public IParticipant * @param [in] reader : Reader to delete */ virtual void delete_reader_( - std::shared_ptr reader) noexcept; + std::shared_ptr reader) noexcept; /** * @brief Get Id without locking a mutex @@ -194,22 +185,22 @@ class BaseParticipant : public IParticipant * @warning this method is called from discovery callbacks, that could be called from Fast DDS while * creating an endpoint. So it could lead to a dead lock. That is why it is not thread safe. */ - types::ParticipantId id_nts_() const noexcept; + core::types::ParticipantId id_nts_() const noexcept; //! Participant configuration - std::shared_ptr configuration_; + std::shared_ptr configuration_; //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; + std::shared_ptr payload_pool_; //! DDS Router shared Discovery Database - std::shared_ptr discovery_database_; + std::shared_ptr discovery_database_; //! Writers created by this Participant indexed by topic - std::map> writers_; + std::map> writers_; //! Readers created by this Participant indexed by topic - std::map> readers_; + std::map> readers_; //! Mutex that guards every access to the Participant mutable std::recursive_mutex mutex_; @@ -230,7 +221,7 @@ std::ostream& operator <<( std::ostream& os, const BaseParticipant& part); -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BlankParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp similarity index 69% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/BlankParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp index 4b2dd4ba9..9ea7f0364 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BlankParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp @@ -19,12 +19,12 @@ #ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BLANKPARTICIPANT_HPP_ #define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BLANKPARTICIPANT_HPP_ -#include -#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Participant that has an empty implementation. @@ -33,19 +33,16 @@ namespace core { * Writer: BlankWriter * Reader: BlankReader */ -class BlankParticipant : public IParticipant +class BlankParticipant : public core::IParticipant { public: //! Constructor with Id of this participant BlankParticipant( - const types::ParticipantId& id_); + const core::types::ParticipantId& id_); //! Override id() IParticipant method - types::ParticipantId id() const noexcept override; - - //! Override kind() IParticipant method - types::ParticipantKind kind() const noexcept override; + core::types::ParticipantId id() const noexcept override; //! Override is_repeater() IParticipant method bool is_repeater() const noexcept override; @@ -54,28 +51,30 @@ class BlankParticipant : public IParticipant bool is_rtps_kind() const noexcept override; //! Override create_writer() IParticipant method - std::shared_ptr create_writer( - types::DdsTopic topic) override; + std::shared_ptr create_writer( + core::types::DdsTopic topic) override; //! Override create_reader() IParticipant method - std::shared_ptr create_reader( - types::DdsTopic topic) override; + std::shared_ptr create_reader( + core::types::DdsTopic topic) override; //! Override delete_writer() IParticipant method void delete_writer( - std::shared_ptr writer) noexcept override; + std::shared_ptr writer) noexcept override; //! Override delete_reader() IParticipant method void delete_reader( - std::shared_ptr reader) noexcept override; + std::shared_ptr reader) noexcept override; + + virtual void start() override; protected: //! Participant Id - types::ParticipantId id_; + core::types::ParticipantId id_; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp similarity index 78% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp index 761154825..16c676312 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp @@ -19,15 +19,15 @@ #ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_DUMMYPARTICIPANT_HPP_ #define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_DUMMYPARTICIPANT_HPP_ -#include +#include -#include -#include -#include +#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Concrete Participant that allows to simulate a real remote network. @@ -50,9 +50,9 @@ class DummyParticipant : public BaseParticipant * the DDSRouter. */ DummyParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database); /** * @brief Destroy the Dummy Participant object @@ -67,7 +67,7 @@ class DummyParticipant : public BaseParticipant * @param new_endpoint : Endpoint discovered */ void simulate_discovered_endpoint( - const types::Endpoint& new_endpoint); + const core::types::Endpoint& new_endpoint); /** * @brief Get the discovered endpoint object referring to \c guid @@ -77,8 +77,8 @@ class DummyParticipant : public BaseParticipant * @param guid : \c Guid of the Endpoint to look for * @return Endpoint with this guid */ - types::Endpoint get_discovered_endpoint( - const types::Guid& guid) const; + core::types::Endpoint get_discovered_endpoint( + const core::types::Guid& guid) const; /** * @brief Simulate that the reader of the topic has received a message @@ -87,7 +87,7 @@ class DummyParticipant : public BaseParticipant * @param data : data received */ void simulate_data_reception( - types::DdsTopic topic, + core::types::DdsTopic topic, DummyDataReceived data); /** @@ -97,7 +97,7 @@ class DummyParticipant : public BaseParticipant * @return Vector of all the data that the Writer should have sent. */ std::vector get_data_that_should_have_been_sent( - types::DdsTopic topic); + core::types::DdsTopic topic); /** * @brief Make the thread wait until message \c n has arrived to Writer in topic \c topic @@ -106,7 +106,7 @@ class DummyParticipant : public BaseParticipant * @param [in] n : wait until data \c n has arrived and simulated to be sent */ void wait_until_n_data_sent( - types::DdsTopic topic, + core::types::DdsTopic topic, uint16_t n) const noexcept; /** @@ -122,17 +122,17 @@ class DummyParticipant : public BaseParticipant * @warning Do not remove this ptr */ static DummyParticipant* get_participant( - types::ParticipantId id); + core::types::ParticipantId id); protected: //! Override create_writer_() BaseParticipant method - std::shared_ptr create_writer_( - types::DdsTopic topic) override; + std::shared_ptr create_writer_( + core::types::DdsTopic topic) override; //! Override create_reader_() BaseParticipant method - std::shared_ptr create_reader_( - types::DdsTopic topic) override; + std::shared_ptr create_reader_( + core::types::DdsTopic topic) override; // Specific enable/disable do not need to be implemented @@ -140,10 +140,10 @@ class DummyParticipant : public BaseParticipant static std::mutex static_mutex_; //! Static map that stores every DummyParticipant running - static std::map participants_; + static std::map participants_; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/EchoParticipant.hpp similarity index 67% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/EchoParticipant.hpp index 97f0e973e..cd8f44fdf 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/EchoParticipant.hpp @@ -19,13 +19,13 @@ #ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_ECHOPARTICIPANT_HPP_ #define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_ECHOPARTICIPANT_HPP_ -#include +#include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Concrete Participant that prints in stdout each message that arrives. @@ -36,32 +36,29 @@ class EchoParticipant : public BlankParticipant //! Using parent class constructors EchoParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr discovery_database); - - //! Override kind() IParticipant method - types::ParticipantKind kind() const noexcept override; + std::shared_ptr participant_configuration, + std::shared_ptr discovery_database); //! Print discovery information from endpoint discovered void echo_discovery( - types::Endpoint endpoint_discovered) const noexcept; + core::types::Endpoint endpoint_discovered) const noexcept; //! Override create_writer() IParticipant method - std::shared_ptr create_writer( - types::DdsTopic topic) override; + std::shared_ptr create_writer( + core::types::DdsTopic topic) override; protected: // Deleters do not need to be implemented //! Reference to alias access of this object configuration without casting every time - std::shared_ptr configuration_; + std::shared_ptr configuration_; //! DDS Router shared Discovery Database - std::shared_ptr discovery_database_; + std::shared_ptr discovery_database_; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp similarity index 70% rename from ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp index 060c92c9e..53b07ae4e 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp @@ -19,19 +19,18 @@ #ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_DISCOVERYSERVERPARTICIPANTCONFIGURATION_HPP_ #define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_DISCOVERYSERVERPARTICIPANTCONFIGURATION_HPP_ -#include +#include #include #include #include #include #include #include -#include + namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { /** * This class joins Discovery Server Participant Configuration features and gives methods to interact with it. @@ -46,14 +45,13 @@ struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigu DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration() = default; DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration( - const types::ParticipantId& id, - const types::ParticipantKind& kind, + const core::types::ParticipantId& id, const bool is_repeater, - const types::DomainId& domain_id, - const types::GuidPrefix& discovery_server_guid_prefix, - const std::set& listening_addresses, - const std::set& connection_addresses, - const types::security::TlsConfiguration& tls_configuration); + const core::types::DomainId& domain_id, + const core::types::GuidPrefix& discovery_server_guid_prefix, + const std::set& listening_addresses, + const std::set& connection_addresses, + const core::types::security::TlsConfiguration& tls_configuration); ///////////////////////// // METHODS @@ -69,17 +67,16 @@ struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigu // VARIABLES ///////////////////////// - types::GuidPrefix discovery_server_guid_prefix = types::GuidPrefix(); + core::types::GuidPrefix discovery_server_guid_prefix = core::types::GuidPrefix(); - std::set listening_addresses = {}; + std::set listening_addresses = {}; - std::set connection_addresses = {}; + std::set connection_addresses = {}; - types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration(); + core::types::security::TlsConfiguration tls_configuration = core::types::security::TlsConfiguration(); }; -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/EchoParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/EchoParticipantConfiguration.hpp similarity index 90% rename from ddsrouter_core/include/ddsrouter_core/configuration/participant/EchoParticipantConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/EchoParticipantConfiguration.hpp index c013e3b57..76f8d9a9c 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/EchoParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/EchoParticipantConfiguration.hpp @@ -19,12 +19,11 @@ #ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_ECHOPARTICIPANTCONFIGURATION_HPP_ #define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_ECHOPARTICIPANTCONFIGURATION_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { struct EchoParticipantConfiguration : public ParticipantConfiguration { @@ -49,8 +48,7 @@ struct EchoParticipantConfiguration : public ParticipantConfiguration bool verbose = false; }; -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/InitialPeersParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp similarity index 73% rename from ddsrouter_core/include/ddsrouter_core/configuration/participant/InitialPeersParticipantConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp index 969dcea68..5eca7b991 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/InitialPeersParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp @@ -19,19 +19,18 @@ #ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_INITIALPEERSPARTICIPANTCONFIGURATION_HPP_ #define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_INITIALPEERSPARTICIPANTCONFIGURATION_HPP_ -#include +#include #include #include #include #include #include #include -#include + namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { /** * This data struct joins Initial Peers Participant Configuration features @@ -46,13 +45,12 @@ struct InitialPeersParticipantConfiguration : public SimpleParticipantConfigurat DDSROUTER_CORE_DllAPI InitialPeersParticipantConfiguration() = default; DDSROUTER_CORE_DllAPI InitialPeersParticipantConfiguration( - const types::ParticipantId& id, - const types::ParticipantKind& kind, + const core::types::ParticipantId& id, const bool is_repeater, - const types::DomainId& domain_id, - const std::set& listening_addresses, - const std::set& connection_addresses, - const types::security::TlsConfiguration& tls_configuration); + const core::types::DomainId& domain_id, + const std::set& listening_addresses, + const std::set& connection_addresses, + const core::types::security::TlsConfiguration& tls_configuration); ///////////////////////// // METHODS @@ -68,15 +66,14 @@ struct InitialPeersParticipantConfiguration : public SimpleParticipantConfigurat // VARIABLES ///////////////////////// - std::set listening_addresses = {}; + std::set listening_addresses = {}; - std::set connection_addresses = {}; + std::set connection_addresses = {}; - types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration(); + core::types::security::TlsConfiguration tls_configuration = core::types::security::TlsConfiguration(); }; -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp similarity index 82% rename from ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp index e4b25a7c4..e4469ace4 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp @@ -22,14 +22,12 @@ #include #include #include -#include namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { -struct ParticipantConfiguration : public BaseConfiguration +struct ParticipantConfiguration : public core::configuration::BaseConfiguration { ///////////////////////// @@ -39,8 +37,7 @@ struct ParticipantConfiguration : public BaseConfiguration DDSROUTER_CORE_DllAPI ParticipantConfiguration() = default; DDSROUTER_CORE_DllAPI ParticipantConfiguration( - const types::ParticipantId& id, - const types::ParticipantKind& kind, + const core::types::ParticipantId& id, const bool is_repeater) noexcept; ///////////////////////// @@ -60,17 +57,13 @@ struct ParticipantConfiguration : public BaseConfiguration utils::Formatter& error_msg) const noexcept override; //! Participant Id associated with this configuration - types::ParticipantId id; - - //! Participant Kind of the Participant that this configuration refers. - types::ParticipantKind kind; + core::types::ParticipantId id; //! Whether this Participant should connect its readers with its writers. bool is_repeater = false; }; -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp similarity index 85% rename from ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp index 8a34e2548..c4a973e6b 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp @@ -19,14 +19,13 @@ #ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_SIMPLEPARTICIPANTCONFIGURATION_HPP_ #define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_SIMPLEPARTICIPANTCONFIGURATION_HPP_ -#include +#include #include #include namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { /** * This data struct represents a configuration for a SimpleParticipant @@ -41,10 +40,9 @@ struct SimpleParticipantConfiguration : public ParticipantConfiguration DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration() = default; DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration( - const types::ParticipantId& id, - const types::ParticipantKind& kind, + const core::types::ParticipantId& id, const bool is_repeater, - const types::DomainId& domain_id) noexcept; + const core::types::DomainId& domain_id) noexcept; ///////////////////////// // METHODS @@ -66,11 +64,10 @@ struct SimpleParticipantConfiguration : public ParticipantConfiguration // VARIABLES ///////////////////////// - types::DomainId domain = types::DomainId(0u); + core::types::DomainId domain = core::types::DomainId(0u); }; -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/CommonParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp similarity index 82% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/CommonParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp index 3dc44e91e..23d6dac50 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/CommonParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp @@ -27,14 +27,14 @@ #include #include -#include +#include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -55,10 +55,10 @@ class CommonParticipant * @brief Construct a CommonParticipant */ CommonParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database, - const types::DomainId& domain_id, + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database, + const core::types::DomainId& domain_id, const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); //! Remove internal RTPS Participant @@ -105,13 +105,17 @@ class CommonParticipant fastrtps::rtps::RTPSParticipant* participant, fastrtps::rtps::WriterDiscoveryInfo&& info) override; + virtual bool is_rtps_kind() const noexcept override; + + virtual void start() override; + protected: /** * @brief Auxiliary method to create the internal RTPS participant. */ void create_participant_( - const types::DomainId& domain, + const core::types::DomainId& domain, const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); /** @@ -119,16 +123,16 @@ class CommonParticipant * * Depending on the Topic QoS creates a Basic or Specific Writer. */ - std::shared_ptr create_writer_( - types::DdsTopic topic) override; + std::shared_ptr create_writer_( + core::types::DdsTopic topic) override; /** * @brief Create a reader object * * Depending on the Topic QoS creates a Basic or Specific Reader. */ - std::shared_ptr create_reader_( - types::DdsTopic topic) override; + std::shared_ptr create_reader_( + core::types::DdsTopic topic) override; /** * @brief Create a endpoint from info object @@ -136,12 +140,12 @@ class CommonParticipant * Specialized for \c WriterDiscoveryInfo and \c ReaderDiscoveryInfo . */ template - types::Endpoint create_endpoint_from_info_( + core::types::Endpoint create_endpoint_from_info_( DiscoveryInfoKind& info); //! Create a endpoint from common info from method \c create_endpoint_from_info_ . template - types::Endpoint create_common_endpoint_from_info_( + core::types::Endpoint create_common_endpoint_from_info_( DiscoveryInfoKind& info); ///// @@ -153,7 +157,7 @@ class CommonParticipant * @note This method must be specialized from inherit classes. */ static fastrtps::rtps::RTPSParticipantAttributes get_participant_attributes_( - const configuration::ParticipantConfiguration* participant_configuration); + const ParticipantConfiguration* participant_configuration); ///// // VARIABLES @@ -161,14 +165,14 @@ class CommonParticipant eprosima::fastrtps::rtps::RTPSParticipant* rtps_participant_; //! Domain Id to create the internal RTPS Participant. - types::DomainId domain_id_; + core::types::DomainId domain_id_; //! Participant attributes to create the internal RTPS Participant. fastrtps::rtps::RTPSParticipantAttributes participant_attributes_; }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/DiscoveryServerParticipant.hpp similarity index 72% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/DiscoveryServerParticipant.hpp index 2e2a9181c..6aa9630ef 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/DiscoveryServerParticipant.hpp @@ -21,14 +21,14 @@ #include -#include +#include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -40,17 +40,17 @@ class DiscoveryServerParticipant public: DiscoveryServerParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database); static fastrtps::rtps::RTPSParticipantAttributes get_participant_attributes_( - const configuration::DiscoveryServerParticipantConfiguration* participant_configuration); + const DiscoveryServerParticipantConfiguration* participant_configuration); }; } /* namespace rpts */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/InitialPeersParticipant.hpp similarity index 72% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/InitialPeersParticipant.hpp index 07385b2d1..0fb69a67e 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/InitialPeersParticipant.hpp @@ -21,14 +21,14 @@ #include -#include +#include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -40,17 +40,17 @@ class InitialPeersParticipant public: InitialPeersParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database); static fastrtps::rtps::RTPSParticipantAttributes get_participant_attributes_( - const configuration::InitialPeersParticipantConfiguration* configuration); + const InitialPeersParticipantConfiguration* configuration); }; } /* namespace rpts */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/SimpleParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/SimpleParticipant.hpp similarity index 79% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/SimpleParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/SimpleParticipant.hpp index d092d6bb6..bbd8e128f 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/SimpleParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/SimpleParticipant.hpp @@ -19,12 +19,12 @@ #ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_SIMPLEPARTICIPANT_HPP_ #define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_SIMPLEPARTICIPANT_HPP_ -#include -#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -47,13 +47,13 @@ class SimpleParticipant : public CommonParticipant * @throw \c IConfigurationException in case configuration was incorrectly set */ SimpleParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database); }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BaseReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp similarity index 87% rename from ddsrouter_core/src/cpp/reader/implementations/auxiliar/BaseReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp index dfe96baa6..ac0ceea82 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BaseReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp @@ -23,12 +23,12 @@ #include #include - -#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Abstract Reader that implements generic methods for every Reader. @@ -36,7 +36,7 @@ namespace core { * In order to inherit from this class, create the protected method take_ . * Implement methods enabled_ and disabled_ in order to give specific functionality to these methods. */ -class BaseReader : public IReader +class BaseReader : public core::IReader { public: @@ -50,9 +50,9 @@ class BaseReader : public IReader * @param payload_pool DDS Router shared PayloadPool */ BaseReader( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool); + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool); /** * @brief Set this Reader as enabled @@ -110,13 +110,13 @@ class BaseReader : public IReader * Thread safe with mutex \c mutex_ . */ utils::ReturnCode take( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; //! Getter of \c participant_id_ attribute - types::ParticipantId participant_id() const noexcept; + core::types::ParticipantId participant_id() const noexcept; //! Getter of \c topic_ attribute - types::DdsTopic topic() const noexcept; + core::types::DdsTopic topic() const noexcept; protected: @@ -149,16 +149,16 @@ class BaseReader : public IReader * Implement this method in every inherited Reader class with take functionality. */ virtual utils::ReturnCode take_( - std::unique_ptr& data) noexcept = 0; + std::unique_ptr& data) noexcept = 0; //! Participant parent ID - types::ParticipantId participant_id_; + core::types::ParticipantId participant_id_; //! Topic that this Reader refers to - types::DdsTopic topic_; + core::types::DdsTopic topic_; //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; + std::shared_ptr payload_pool_; //! Lambda to call the callback whenever a new data arrives std::function on_data_available_lambda_; @@ -191,7 +191,7 @@ std::ostream& operator <<( std::ostream& os, const BaseReader& reader); -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BlankReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp similarity index 88% rename from ddsrouter_core/src/cpp/reader/implementations/auxiliar/BlankReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp index 608a4eb5d..26a9cee07 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BlankReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp @@ -19,18 +19,18 @@ #ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ #define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Reader that has an empty implementation. * It does not receive anything. * It does not have messages to take. */ -class BlankReader : public IReader +class BlankReader : public core::IReader { public: @@ -49,10 +49,10 @@ class BlankReader : public IReader //! Override take() IReader method utils::ReturnCode take( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/DummyReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/DummyReader.hpp similarity index 88% rename from ddsrouter_core/src/cpp/reader/implementations/auxiliar/DummyReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/DummyReader.hpp index 13a20cff6..f28c723bb 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/DummyReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/DummyReader.hpp @@ -23,22 +23,22 @@ #include #include -#include +#include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { //! Data that has been sent to a Dummy Reader in order to simulate data reception struct DummyDataReceived { //! Payload in a format of vector of bytes - std::vector payload; + std::vector payload; //! Guid of the source entity that has transmitted the data - types::Guid source_guid; + core::types::Guid source_guid; }; /** @@ -71,7 +71,7 @@ class DummyReader : public BaseReader * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty */ utils::ReturnCode take_( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; //! Stores the data that must be retrieved with \c take() method std::queue data_to_send_; @@ -80,7 +80,7 @@ class DummyReader : public BaseReader mutable std::recursive_mutex dummy_mutex_; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/rtps/CommonReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp similarity index 91% rename from ddsrouter_core/src/cpp/reader/implementations/rtps/CommonReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp index 2260ff306..555f9af7b 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/rtps/CommonReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp @@ -31,14 +31,14 @@ #include #include -#include +#include #include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using RecursiveTimedMutex = eprosima::fastrtps::RecursiveTimedMutex; @@ -104,7 +104,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener fastrtps::rtps::MatchingInfo& info) noexcept override; //! Get GUID of internal RTPS reader - types::Guid guid() const noexcept; + core::types::Guid guid() const noexcept; //! Get internal RTPS reader mutex RecursiveTimedMutex& get_rtps_mutex() const noexcept; @@ -124,9 +124,9 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @throw \c InitializationException in case any creation has failed */ CommonReader( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const fastrtps::rtps::HistoryAttributes& history_attributes, const fastrtps::rtps::ReaderAttributes& reader_attributes, @@ -149,7 +149,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener */ virtual void fill_received_data_( fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept; + std::unique_ptr& data_to_fill) const noexcept; // Specific enable/disable do not need to be implemented @@ -176,7 +176,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @return \c RETCODE_ERROR if there has been an error reading the data or the data read is corrupted */ virtual utils::ReturnCode take_( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; ///// // RTPS specific methods @@ -187,21 +187,21 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @return Default HistoryAttributes */ static fastrtps::rtps::HistoryAttributes get_history_attributes_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; /** * @brief Reader Attributes to create RTPS Reader */ static fastrtps::rtps::ReaderAttributes get_reader_attributes_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Topic Attributes to create RTPS Reader static fastrtps::TopicAttributes get_topic_attributes_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Reader QoS to create RTPS Reader static fastrtps::ReaderQos get_reader_qos_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; ///// // CommonReader specific methods @@ -247,7 +247,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/rtps/SimpleReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SimpleReader.hpp similarity index 86% rename from ddsrouter_core/src/cpp/reader/implementations/rtps/SimpleReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SimpleReader.hpp index 4cef0f495..661c56026 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/rtps/SimpleReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SimpleReader.hpp @@ -19,11 +19,11 @@ #ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SIMPLEREADER_HPP_ #define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SIMPLEREADER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -46,14 +46,14 @@ class SimpleReader : public CommonReader * @throw \c InitializationException in case any creation has failed */ SimpleReader( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant); }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/rtps/SpecificQoSReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp similarity index 79% rename from ddsrouter_core/src/cpp/reader/implementations/rtps/SpecificQoSReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp index 949744a69..8e000570e 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/rtps/SpecificQoSReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp @@ -19,12 +19,12 @@ #ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SPECIFICQOSREADER_HPP_ #define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SPECIFICQOSREADER_HPP_ -#include +#include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -50,34 +50,34 @@ class SpecificQoSReader : public CommonReader * @throw \c InitializationException in case any creation has failed */ SpecificQoSReader( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - std::shared_ptr discovery_database); + std::shared_ptr discovery_database); protected: /** * @brief Get the QoS from a Writer from the \c DiscoveryDatabase . */ - types::SpecificEndpointQoS specific_qos_of_writer_( - const types::Guid& guid) const; + core::types::SpecificEndpointQoS specific_qos_of_writer_( + const core::types::Guid& guid) const; /** * Specializes \c CommonReader method and set the QoS of the data received. */ virtual void fill_received_data_( fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept override; + std::unique_ptr& data_to_fill) const noexcept override; //! Reference to the \c DiscoveryDatabase . - std::shared_ptr discovery_database_; + std::shared_ptr discovery_database_; }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BaseWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp similarity index 86% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/BaseWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp index acb3a5141..b75234792 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BaseWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp @@ -24,11 +24,11 @@ #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Abstract Writer that implements generic methods for every Writer. @@ -36,7 +36,7 @@ namespace core { * In order to inherit from this class, create the protected method write_ . * Implement methods enabled_ and disabled_ in order to give specific functionality to these methods. */ -class BaseWriter : public IWriter +class BaseWriter : public core::IWriter { public: @@ -48,9 +48,9 @@ class BaseWriter : public IWriter * @param payload_pool DDS Router shared PayloadPool */ BaseWriter( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool); + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool); /** * @brief Set this Writer as enabled @@ -85,7 +85,7 @@ class BaseWriter : public IWriter * Thread safe with mutex \c mutex_ . */ virtual utils::ReturnCode write( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; protected: @@ -109,16 +109,16 @@ class BaseWriter : public IWriter * Implement this method in every inherited Writer class with write functionality. */ virtual utils::ReturnCode write_( - std::unique_ptr& data) noexcept = 0; + std::unique_ptr& data) noexcept = 0; //! Participant parent ID - types::ParticipantId participant_id_; + core::types::ParticipantId participant_id_; //! Topic that this Writer refers to - types::DdsTopic topic_; + core::types::DdsTopic topic_; //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; + std::shared_ptr payload_pool_; //! Whether the Writer is currently enabled std::atomic enabled_; @@ -142,7 +142,7 @@ std::ostream& operator <<( std::ostream& os, const BaseWriter& writer); -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BlankWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp similarity index 85% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/BlankWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp index 5e3ba9586..cb038ba54 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BlankWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp @@ -19,17 +19,17 @@ #ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ #define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Writer that has an empty implementation. * It does not send anything. */ -class BlankWriter : public IWriter +class BlankWriter : public core::IWriter { public: @@ -41,10 +41,10 @@ class BlankWriter : public IWriter //! Override write() IWriter method utils::ReturnCode write( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/DummyWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/DummyWriter.hpp similarity index 88% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/DummyWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/DummyWriter.hpp index 4b1990c35..9db968432 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/DummyWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/DummyWriter.hpp @@ -24,22 +24,22 @@ #include -#include -#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { //! Data kind that a Dummy Writer should have sent struct DummyDataStored { //! Payload in a format of vector of bytes - std::vector payload; + std::vector payload; //! Guid of the source entity that has transmitted the data - types::Guid source_guid; + core::types::Guid source_guid; //! Timestamp of the theoretic publication time utils::Timestamp timestamp; @@ -83,7 +83,7 @@ class DummyWriter : public BaseWriter * @return RETCODE_OK always */ utils::ReturnCode write_( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; //! Stores the data that should have been published std::vector data_stored_; @@ -97,7 +97,7 @@ class DummyWriter : public BaseWriter mutable std::mutex dummy_mutex_; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/EchoWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp similarity index 84% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/EchoWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp index 5db68912f..36e74b3bb 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/EchoWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp @@ -23,11 +23,11 @@ #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { /** * Writer Implementation that prints in stdout every message that is required to write. @@ -38,7 +38,7 @@ class EchoWriter : public BlankWriter //! Using parent class constructors EchoWriter( - const types::DdsTopic& topic, + const core::types::DdsTopic& topic, bool verbose); protected: @@ -50,16 +50,16 @@ class EchoWriter : public BlankWriter * @return RETCODE_OK always */ virtual utils::ReturnCode write( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; //! Topic that this Writer refers to - types::DdsTopic topic_; + core::types::DdsTopic topic_; // Specific enable/disable do not need to be implemented bool verbose_; }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/CommonWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp similarity index 89% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/CommonWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp index ada312117..d3cf8418f 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/CommonWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp @@ -29,18 +29,18 @@ #include #include -#include -#include +#include +#include ///// // Forward declarations namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { struct CacheChangePoolConfiguration; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ namespace fastdds { @@ -54,7 +54,7 @@ struct IReaderDataFilter; namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using WriteParams = eprosima::fastrtps::rtps::WriteParams; @@ -116,9 +116,9 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @throw \c InitializationException in case any creation has failed */ CommonWriter( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater, const fastrtps::rtps::HistoryAttributes& history_attributes, @@ -145,7 +145,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @return \c RETCODE_ERROR if error occurred */ virtual utils::ReturnCode write_( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; /** * @brief Auxiliary method used in \c write to fill the cache change to send. @@ -157,7 +157,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener virtual utils::ReturnCode fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - std::unique_ptr& data) const noexcept; + std::unique_ptr& data) const noexcept; /** * @brief Auxiliary method used after \c write to fill data value. @@ -167,7 +167,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ virtual void fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& params, - std::unique_ptr& data_to_fill) const noexcept; + std::unique_ptr& data_to_fill) const noexcept; ///// // RTPS specific methods @@ -191,25 +191,25 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @brief History Attributes to create RTPS Writer History */ static fastrtps::rtps::HistoryAttributes get_history_attributes_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; /** * @brief Writer Attributes to create RTPS Writer */ static fastrtps::rtps::WriterAttributes get_writer_attributes_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Topic Attributes to create RTPS Writer static fastrtps::TopicAttributes get_topic_attributes_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! QoS for RTPS Writer static fastrtps::WriterQos get_writer_qos_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Cache Change Pool Configuration static utils::PoolConfiguration cache_change_pool_configuration_( - const types::DdsTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Whether a guid references this Participant bool come_from_this_participant_( @@ -253,7 +253,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/MultiWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp similarity index 83% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/MultiWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp index a55baf3f1..9c4c32a54 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/MultiWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp @@ -22,12 +22,12 @@ #include #include -#include -#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -53,9 +53,9 @@ class MultiWriter : public BaseWriter * @throw \c InitializationException in case any creation has failed */ MultiWriter( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater = false); @@ -91,21 +91,21 @@ class MultiWriter : public BaseWriter * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty */ virtual utils::ReturnCode write_( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; bool exist_partition_( - const types::SpecificEndpointQoS& data_qos); + const core::types::SpecificEndpointQoS& data_qos); QoSSpecificWriter* get_writer_or_create_( - const types::SpecificEndpointQoS& data_qos); + const core::types::SpecificEndpointQoS& data_qos); QoSSpecificWriter* create_writer_nts_( - const types::SpecificEndpointQoS& data_qos); + const core::types::SpecificEndpointQoS& data_qos); ///// // VARIABLES // TODO: This could be an unordered_map avoiding the use of operator< with SpecificEndpointQoS, // what may be a problem. - using WritersMapType = utils::SharedAtomicable>; + using WritersMapType = utils::SharedAtomicable>; //! Map of writer indexed by Specific QoS of each. WritersMapType writers_map_; @@ -117,7 +117,7 @@ class MultiWriter : public BaseWriter }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/QoSSpecificWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/QoSSpecificWriter.hpp similarity index 80% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/QoSSpecificWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/QoSSpecificWriter.hpp index 64f22ce92..b9523d62e 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/QoSSpecificWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/QoSSpecificWriter.hpp @@ -19,11 +19,11 @@ #ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_QOSSPECIFICWRITER_HPP_ #define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_QOSSPECIFICWRITER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -48,26 +48,26 @@ class QoSSpecificWriter : public CommonWriter * @throw \c InitializationException in case any creation has failed */ QoSSpecificWriter( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - const types::SpecificEndpointQoS& specific_qos, + const core::types::SpecificEndpointQoS& specific_qos, const bool repeater = false); protected: //! Specific writer QoS to override (more or less) the CommonWriter qos static fastrtps::WriterQos get_writer_qos_( - const types::SpecificEndpointQoS& specific_qos, - const types::DdsTopic& topic) noexcept; + const core::types::SpecificEndpointQoS& specific_qos, + const core::types::DdsTopic& topic) noexcept; //! Specific QoS of the Endpoint - const types::SpecificEndpointQoS& specific_qos_; + const core::types::SpecificEndpointQoS& specific_qos_; }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/SimpleWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/SimpleWriter.hpp similarity index 87% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/SimpleWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/SimpleWriter.hpp index 695f642db..eb5980cf6 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/SimpleWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/SimpleWriter.hpp @@ -28,12 +28,12 @@ #include #include -#include -#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -59,16 +59,16 @@ class SimpleWriter : public CommonWriter * @throw \c InitializationException in case any creation has failed */ SimpleWriter( - const types::ParticipantId& participant_id, - const types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater = false); }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/RepeaterDataFilter.cpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp similarity index 89% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/filter/RepeaterDataFilter.cpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp index f28a36183..5fa39e0c3 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/RepeaterDataFilter.cpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp @@ -21,11 +21,11 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { bool RepeaterDataFilter::is_relevant( @@ -43,7 +43,7 @@ bool RepeaterDataFilter::is_relevant( } // As ChangePool is our own, and we use RouterCacheChange, we can cast this without problem - const auto& change_ref = static_cast(change); + const auto& change_ref = static_cast(change); bool is_relevant = change_ref.last_writer_guid_prefix != reader_guid.guidPrefix; @@ -56,6 +56,6 @@ bool RepeaterDataFilter::is_relevant( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/RepeaterDataFilter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.hpp similarity index 93% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/filter/RepeaterDataFilter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.hpp index 91f7737a9..c1a7c58d3 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/RepeaterDataFilter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.hpp @@ -19,11 +19,11 @@ #ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ #define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -51,9 +51,8 @@ class RepeaterDataFilter : public SelfDataFilter }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ #endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ */ - diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/SelfDataFilter.cpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp similarity index 90% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/filter/SelfDataFilter.cpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp index 396f81de5..b66686a40 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/SelfDataFilter.cpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp @@ -21,11 +21,11 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { bool SelfDataFilter::is_relevant( @@ -37,6 +37,6 @@ bool SelfDataFilter::is_relevant( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/SelfDataFilter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.hpp similarity index 97% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/filter/SelfDataFilter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.hpp index 3184819f7..52af7569f 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/filter/SelfDataFilter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.hpp @@ -36,7 +36,7 @@ struct GUID_t; namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { /** @@ -59,9 +59,8 @@ class SelfDataFilter : public fastdds::rtps::IReaderDataFilter }; } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ #endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ */ - diff --git a/ddsrouter_core/src/cpp/reader/IReader.hpp b/ddsrouter_core/include/ddsrouter_core/reader/IReader.hpp similarity index 98% rename from ddsrouter_core/src/cpp/reader/IReader.hpp rename to ddsrouter_core/include/ddsrouter_core/reader/IReader.hpp index c4f9382a7..b7b7d2b8b 100644 --- a/ddsrouter_core/src/cpp/reader/IReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/reader/IReader.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp b/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp index aa9dae928..4c5723050 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp @@ -32,112 +32,8 @@ namespace types { * @brief Unique Id for each DDSRouter Participant * * This class represents the ID that uniquely identifies a Participant inside the DDSRouter. - * This unique Id is a string that behaves as the key for the unique ID. - * Two IDs with the same string are the same ID. */ -class ParticipantId -{ -public: - - /** - * @brief Construct a new Participant invalid Id object - */ - DDSROUTER_CORE_DllAPI ParticipantId() noexcept; - - /** - * @brief Construct a new Participant Id object from a string value - * - * @param id uniquely identifies the new \c ParticipantId - */ - DDSROUTER_CORE_DllAPI ParticipantId( - const std::string& id) noexcept; - - /** - * @brief Whether this \c ParticipantId is valid - * - * For a \c ParticipantId to be invalid, it must contains a string that is not valid as an ID - * - * @return true if this Id is valid. False otherwise. - */ - DDSROUTER_CORE_DllAPI bool is_valid() const noexcept; - - /** - * @brief Name that uniquely identifies - * - * @return key string that represents the ID - */ - DDSROUTER_CORE_DllAPI std::string id_name() const noexcept; - - ///// - // OPERATOR OVERLOAD - - /** - * @brief Equality operator - * - * Check whether both objects identifies the same participant - * - * @param [in] other \c ParticipantId to compare with - * @return true if this Ids are equal. False otherwise. - */ - DDSROUTER_CORE_DllAPI bool operator ==( - const ParticipantId& other) const noexcept; - - /** - * @brief Not equals operator - * - * Check whether both objects identify different participants - * - * @param [in] other \c ParticipantId to compare with - * @return true if this Ids are not equal. False otherwise. - */ - DDSROUTER_CORE_DllAPI bool operator !=( - const ParticipantId& other) const noexcept; - - /** - * @brief Minor operator - * - * Check the internal strings to compare - * - * @param [in] other \c ParticipantId to compare with - * @return true if this Id is lower than \c other . False otherwise. - */ - DDSROUTER_CORE_DllAPI bool operator <( - const ParticipantId& other) const noexcept; - - ///// - // STATIC METHODS - - /** - * @brief Get an invalid \c ParticipantId . - * - * @note this method is equal to call default \c ParticipantId constructor. - * - * @return ParticipantId invalid - */ - DDSROUTER_CORE_DllAPI static ParticipantId invalid() noexcept; - - /** - * @brief Check whether a string is valid to create a \c ParticipantId - * - * @param [in] id string as unique key - * @return true in case the string is valid for an ID. False otherwise - */ - DDSROUTER_CORE_DllAPI static bool is_valid_id( - const std::string& id) noexcept; - -protected: - - //! Internal string that is the key for the ID - std::string id_; - - //! Static value that represents an invalid ID string - static const std::string INVALID_ID; // __invalid_DDSROUTERCORE_participant__ -}; - -//! \c ParticipantId to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const ParticipantId& id); +using ParticipantId = std::string; } /* namespace types */ } /* namespace core */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantKind.hpp b/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantKind.hpp deleted file mode 100644 index 9d19543e8..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantKind.hpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2021 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 ParticipantKind.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_PARTICIPANTKIND_HPP_ -#define _DDSROUTERCORE_TYPES_PARTICIPANTKIND_HPP_ - -#include -#include - -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -using ParticipantKindType = uint16_t; - -enum class ParticipantKind : ParticipantKindType -{ - invalid, //! Invalid Participant Kind - blank, //! Blank/Void Participant Kind - echo, //! Echo Participant Kind - dummy, //! Dummy Participant Kind - simple_rtps, //! Simple RTPS Participant Kind - local_discovery_server, //! Discovery Server RTPS Participant Kind - wan_discovery_server, //! Discovery Server Inter Router Participant Kind - wan_initial_peers, //! Initial Peers Inter Router Participant Kind -}; - -static constexpr unsigned PARTICIPANT_KIND_COUNT = 8; - -/** - * @brief All ParticipantKind enum values as a std::array. - */ -constexpr std::array ALL_PARTICIPANT_KINDS = { - ParticipantKind::invalid, - ParticipantKind::blank, - ParticipantKind::echo, - ParticipantKind::dummy, - ParticipantKind::simple_rtps, - ParticipantKind::local_discovery_server, - ParticipantKind::wan_discovery_server, - ParticipantKind::wan_initial_peers, -}; - -/** - * @brief All valid ParticipantKind enum values as a std::array. - */ -constexpr std::array ALL_VALID_PARTICIPANT_KINDS = { - // ParticipantKind::invalid, // Not valid, so not included in this array - ParticipantKind::blank, - ParticipantKind::echo, - ParticipantKind::dummy, - ParticipantKind::simple_rtps, - ParticipantKind::local_discovery_server, - ParticipantKind::wan_discovery_server, - ParticipantKind::wan_initial_peers, -}; - -constexpr std::array PARTICIPANT_KIND_STRINGS = { - "invalid", - "blank", - "echo", - "dummy", - "simple-rtps", - "local-discovery-server", - "wan-ds", - "wan-initial-peers", -}; - -static constexpr unsigned MAX_PARTICIPANT_KIND_ALIASES = 4; - -using ParticipantKindAliasesType = std::array; - -/** - * @brief All possible string aliases for each \c ParticipantKind. - */ -constexpr std::array PARTICIPANT_KIND_ALIASES = { - ParticipantKindAliasesType({"__invalid_participant_kind__", "", "", ""}), - ParticipantKindAliasesType({"blank", "void", "", ""}), - ParticipantKindAliasesType({"echo", "", "", ""}), - ParticipantKindAliasesType({"dummy", "", "", ""}), - ParticipantKindAliasesType({"local", "simple", "", ""}), - ParticipantKindAliasesType({"discovery-server", "ds", "local-ds", "local-discovery-server"}), - ParticipantKindAliasesType({"wan-ds", "wan-discovery-server", "", ""}), - ParticipantKindAliasesType({"wan", "router", "initial-peers", ""}), -}; - -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - ParticipantKind kind); - -/** - * @brief Create a Participant Kind regarding the string argument in lower case - * - * @note Kind name is case sensitive - * - * It compares the argument \c kind in lower case with any of the existing kind names, and in case it - * matches any of them, return the ParticipantKind associated with that name. - * It will return \c ParticipantKind::invalid in case no existing ParticipantKind name matches the argument or the argument is empty. - * - * @param [in] kind : string with the name of the kind to build - * @return ParticipantKind value, \c ParticipantKind::invalid if \c kind does not refer to any existing kind - */ -DDSROUTER_CORE_DllAPI ParticipantKind participant_kind_from_name( - std::string participant_kind_str); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_PARTICIPANTKIND_HPP_ */ diff --git a/ddsrouter_core/src/cpp/writer/IWriter.hpp b/ddsrouter_core/include/ddsrouter_core/writer/IWriter.hpp similarity index 98% rename from ddsrouter_core/src/cpp/writer/IWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/writer/IWriter.hpp index 9a73fedca..6f28de43e 100644 --- a/ddsrouter_core/src/cpp/writer/IWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/writer/IWriter.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/communication/DDSBridge.cpp b/ddsrouter_core/src/cpp/communication/DDSBridge.cpp index e1fe93803..f66204738 100644 --- a/ddsrouter_core/src/cpp/communication/DDSBridge.cpp +++ b/ddsrouter_core/src/cpp/communication/DDSBridge.cpp @@ -21,7 +21,6 @@ #include #include -#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/communication/Track.hpp b/ddsrouter_core/src/cpp/communication/Track.hpp index 90cd0e2b7..75f0e4941 100644 --- a/ddsrouter_core/src/cpp/communication/Track.hpp +++ b/ddsrouter_core/src/cpp/communication/Track.hpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include namespace eprosima { diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp index dbeb9b82f..ff49a2cca 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -124,7 +124,7 @@ void RPCBridge::create_proxy_server_nts_( // Safe casting as we are only getting RTPS participants reply_writers_[participant_id] = participant->create_writer(topic_.reply_topic()); request_readers_[participant_id] = - std::static_pointer_cast(participant->create_reader(topic_.request_topic())); + std::static_pointer_cast(participant->create_reader(topic_.request_topic())); create_slot_(request_readers_[participant_id]); } @@ -138,7 +138,7 @@ void RPCBridge::create_proxy_client_nts_( request_writers_[participant_id] = std::static_pointer_cast(participant->create_writer(topic_.request_topic())); reply_readers_[participant_id] = - std::static_pointer_cast(participant->create_reader(topic_.reply_topic())); + std::static_pointer_cast(participant->create_reader(topic_.reply_topic())); create_slot_(reply_readers_[participant_id]); @@ -296,7 +296,7 @@ void RPCBridge::data_available_( } void RPCBridge::transmit_( - std::shared_ptr reader) noexcept + std::shared_ptr reader) noexcept { // Avoid being disabled while transmitting std::shared_lock lock(on_transmission_mutex_); @@ -433,7 +433,8 @@ void RPCBridge::transmit_( // Not valid means: // Case 1: (SimpleParticipant) Request already replied by another server connected to the same participant as this one. // Case 2: (WAN Participant repeater) Request already replied by another PROXY server connected to the same participant as this one. - if (registry_entry.first.is_valid()) + // TODO: recheck ParticipantId non valid + if (!registry_entry.first.empty()) { data->properties.write_params.set_level(); data->properties.write_params.get_reference().related_sample_identity(registry_entry.second); @@ -464,7 +465,7 @@ void RPCBridge::transmit_( } void RPCBridge::create_slot_( - std::shared_ptr reader) noexcept + std::shared_ptr reader) noexcept { Guid reader_guid = reader->guid(); diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp index 997d05ba9..22186a8f5 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp +++ b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp @@ -30,8 +30,8 @@ #include #include #include -#include -#include +#include +#include namespace eprosima { @@ -111,7 +111,7 @@ class RPCBridge : public Bridge * * Called only once in execution (controlled by \c init_ flag). * - * @throw InitializationException in case \c IWriters or \c rtps::CommonReaders creation fails. + * @throw InitializationException in case \c IWriters or \c participants::rtps::CommonReaders creation fails. */ void init_nts_(); // throws exception, caught in enable @@ -120,7 +120,7 @@ class RPCBridge : public Bridge * * @param participant_id: Participant where proxy server is to be created * - * @throw InitializationException in case \c IWriters or \c rtps::CommonReaders creation fails. + * @throw InitializationException in case \c IWriters or \c participants::rtps::CommonReaders creation fails. */ void create_proxy_server_nts_( types::ParticipantId participant_id); @@ -131,14 +131,14 @@ class RPCBridge : public Bridge * * @param participant_id: Participant where proxy client is to be created * - * @throw InitializationException in case \c IWriters or \c rtps::CommonReaders creation fails. + * @throw InitializationException in case \c IWriters or \c participants::rtps::CommonReaders creation fails. */ void create_proxy_client_nts_( types::ParticipantId participant_id); //! Create slot in the thread pool for this reader void create_slot_( - std::shared_ptr reader) noexcept; + std::shared_ptr reader) noexcept; //! Callback to execute when a new cache change is added to this reader void data_available_( @@ -155,7 +155,7 @@ class RPCBridge : public Bridge * topic being blocked). */ void transmit_( - std::shared_ptr reader) noexcept; + std::shared_ptr reader) noexcept; //! Whether there are any servers in the database bool servers_available_() const noexcept; @@ -167,11 +167,11 @@ class RPCBridge : public Bridge bool init_; //! Proxy servers endpoints - std::map> request_readers_; + std::map> request_readers_; std::map> reply_writers_; //! Proxy clients endpoints - std::map> reply_readers_; + std::map> reply_readers_; std::map> request_writers_; //! Map readers' GUIDs to their associated thread pool tasks, and also keep a task emission flag. diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp index a74b4b3bf..c9219eb1e 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp @@ -18,14 +18,8 @@ */ #include -#include -#include -#include -#include -#include #include -#include -#include + #include namespace eprosima { @@ -36,13 +30,11 @@ namespace configuration { using namespace eprosima::ddsrouter::core::types; DDSRouterConfiguration::DDSRouterConfiguration( - std::set> allowlist, - std::set> blocklist, - std::set> builtin_topics, - std::set> participants_configurations, + const std::set>& allowlist, + const std::set>& blocklist, + const std::set>& builtin_topics, const SpecsConfiguration& advanced_options) : DDSRouterReloadConfiguration (allowlist, blocklist, builtin_topics) - , participants_configurations(participants_configurations) , advanced_options(advanced_options) { } @@ -56,51 +48,6 @@ bool DDSRouterConfiguration::is_valid( return false; } - // Check there are at least two participants - if (participants_configurations.size() < 1) - { - error_msg << "There must be at least 1 participant."; - return false; - } - - // Check Participant Configurations AND - // check Participant Configuration IDs are not repeated - std::set ids; - for (std::shared_ptr configuration : participants_configurations) - { - // Check configuration is not null - if (!configuration) - { - logDevError(DDSROUTER_CONFIGURATION, "Invalid ptr in participant configurations."); - error_msg << "nullptr ParticipantConfiguration in participant configurations. "; - return false; - } - - // Check configuration is valid - if (!configuration->is_valid(error_msg)) - { - error_msg << "Error in Participant " << configuration->id << ". "; - return false; - } - - // Check that the configuration is of type required - if (!check_correct_configuration_object_(configuration)) - { - error_msg << "Participant " << configuration->id << " is not of correct Configuration class. "; - return false; - } - - // Store every id in a set to see if there are repetitions - ids.insert(configuration->id); - } - - // If the number of ids are not equal the number of configurations, is because they are repeated - if (ids.size() != participants_configurations.size()) - { - error_msg << "Participant ids are not unique. "; - return false; - } - return true; } @@ -112,36 +59,6 @@ void DDSRouterConfiguration::reload( this->builtin_topics = new_configuration.builtin_topics; } -template -bool check_correct_configuration_object_by_type_( - const std::shared_ptr configuration) -{ - return nullptr != std::dynamic_pointer_cast(configuration); -} - -bool DDSRouterConfiguration::check_correct_configuration_object_( - const std::shared_ptr configuration) -{ - switch (configuration->kind) - { - case ParticipantKind::simple_rtps: - return check_correct_configuration_object_by_type_(configuration); - - case ParticipantKind::local_discovery_server: - case ParticipantKind::wan_discovery_server: - return check_correct_configuration_object_by_type_(configuration); - - case ParticipantKind::wan_initial_peers: - return check_correct_configuration_object_by_type_(configuration); - - case ParticipantKind::echo: - return check_correct_configuration_object_by_type_(configuration); - - default: - return check_correct_configuration_object_by_type_(configuration); - } -} - } /* namespace configuration */ } /* namespace core */ } /* namespace ddsrouter */ diff --git a/ddsrouter_core/src/cpp/core/DDSRouter.cpp b/ddsrouter_core/src/cpp/core/DDSRouter.cpp index e1a25402b..91dab1ab9 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DDSRouter.cpp @@ -27,8 +27,12 @@ namespace core { // TODO: Use initial topics to start execution and start bridges DDSRouter::DDSRouter( - const configuration::DDSRouterConfiguration& configuration) - : ddsrouter_impl_(std::make_unique(configuration)) + const configuration::DDSRouterConfiguration& configuration, + const std::shared_ptr& discovery_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& participants_database) + : ddsrouter_impl_(std::make_unique( + configuration, discovery_database, payload_pool, participants_database)) { } diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp index bf6d8611a..3d0976e91 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp @@ -28,7 +28,6 @@ #include #include -#include namespace eprosima { namespace ddsrouter { @@ -39,10 +38,13 @@ using namespace eprosima::ddsrouter::core::types; // TODO: Use initial topics to start execution and start bridges DDSRouterImpl::DDSRouterImpl( - const configuration::DDSRouterConfiguration& configuration) - : payload_pool_(new FastPayloadPool()) - , participants_database_(new ParticipantsDatabase()) - , discovery_database_(new DiscoveryDatabase()) + const configuration::DDSRouterConfiguration& configuration, + const std::shared_ptr& discovery_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& participants_database) + : participants_database_(participants_database) + , discovery_database_(discovery_database) + , payload_pool_(payload_pool) , configuration_(configuration) , enabled_(false) , thread_pool_(std::make_shared(configuration_.advanced_options.number_of_threads)) @@ -76,10 +78,12 @@ DDSRouterImpl::DDSRouterImpl( init_participants_(); // Create Bridges for builtin topics init_bridges_(); + // Init discovery database // The entities should not be added to the Discovery Database until the builtin topics have been created. // This is due to the fact that the Participants endpoints start discovering topics with different configuration // than the one specified in the yaml configuration file. + // TODO (custompart): this does not do anything, check discovery_database_->start(); @@ -102,21 +106,6 @@ DDSRouterImpl::~DDSRouterImpl() // Destroy RPCBridges, so Writers and Readers are destroyed before the Databases rpc_bridges_.clear(); - // Destroy Participants - while (!participants_database_->empty()) - { - auto participant = participants_database_->pop_(); - - if (!participant) - { - logDevError(DDSROUTER, "Error poping participant from database."); - } - else - { - participant_factory_.remove_participant(participant); - } - } - // There is no need to destroy shared ptrs as they will delete itslefs with 0 references logDebug(DDSROUTER, "DDS Router destroyed."); @@ -317,51 +306,9 @@ void DDSRouterImpl::init_allowed_topics_() void DDSRouterImpl::init_participants_() { - for (std::shared_ptr participant_config : - configuration_.participants_configurations) - { - std::shared_ptr new_participant; - - // Create participant - // This should not be in try catch case as if it fails the whole init must fail - new_participant = - participant_factory_.create_participant( - participant_config, - payload_pool_, - discovery_database_); - - // create_participant should throw an exception in fail, never return nullptr - if (!new_participant || !new_participant->id().is_valid() || - new_participant->kind() == ParticipantKind::invalid) - { - // Failed to create participant - throw utils::InitializationException(utils::Formatter() - << "Failed to create creating Participant " << participant_config->id); - } - - logInfo(DDSROUTER, "Participant created with id: " << new_participant->id() - << " and kind " << new_participant->kind() << "."); - - // Add this participant to the database. If it is repeated it will cause an exception - try - { - participants_database_->add_participant_( - new_participant->id(), - new_participant); - } - catch (const utils::InconsistencyException& ) - { - throw utils::ConfigurationException(utils::Formatter() - << "Participant ids must be unique. The id " << new_participant->id() << " is duplicated."); - } - } - - // If DDS Router has not two or more Participants configured, it should fail - if (participants_database_->size() < 1) + for (auto& participant : participants_database_->get_participants_map()) { - logError(DDSROUTER, "At least a Participant is required to initialize a DDS Router."); - throw utils::InitializationException(utils::Formatter() - << "DDS Router requires at least 1 Participant to start."); + participant.second->start(); } } diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp index b137e6862..faf5755d3 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp @@ -31,12 +31,12 @@ #include #include #include -#include -#include -#include +#include +#include #include #include #include +#include namespace eprosima { namespace ddsrouter { @@ -63,7 +63,10 @@ class DDSRouterImpl * @throw \c InitializationException in case \c IParticipants , \c IWriters or \c IReaders creation fails. */ DDSRouterImpl( - const configuration::DDSRouterConfiguration& configuration); + const configuration::DDSRouterConfiguration& configuration, + const std::shared_ptr& discovery_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& participants_database); /** * @brief Destroy the DDSRouterImpl object @@ -148,10 +151,7 @@ class DDSRouterImpl void init_allowed_topics_(); /** - * @brief Create participants and add them to the participants database - * - * @throw \c ConfigurationException in case a Participant is not well configured (e.g. No kind) - * @throw \c InitializationException in case \c IParticipants creation fails. + * @brief Enable participants */ void init_participants_(); @@ -330,9 +330,6 @@ class DDSRouterImpl //! List of allowed and blocked topics AllowedTopicList allowed_topics_; - //! Participant factory instance - ParticipantFactory participant_factory_; - ///// // AUXILIAR VARIABLES diff --git a/ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp b/ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp index ab886ebb7..167232a97 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp +++ b/ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp @@ -30,10 +30,7 @@ using namespace eprosima::ddsrouter::core::types; ParticipantsDatabase::~ParticipantsDatabase() { - if (!participants_.empty()) - { - logDevError(DDSROUTER_PARTICIPANT_DATABASE, "Erasing Participant Database with still Participants in it"); - } + // Let the map destroy itself } std::shared_ptr ParticipantsDatabase::get_participant( @@ -75,7 +72,7 @@ std::set ParticipantsDatabase::get_rtps_participants_ids() const return result; } -std::map> ParticipantsDatabase::get_participants_map() const noexcept +const std::map>& ParticipantsDatabase::get_participants_map() const noexcept { std::shared_lock lock(mutex_); return participants_; @@ -91,9 +88,9 @@ size_t ParticipantsDatabase::size() const noexcept return participants_.size(); } -void ParticipantsDatabase::add_participant_( - ParticipantId id, - std::shared_ptr participant) +void ParticipantsDatabase::add_participant( + const ParticipantId& id, + const std::shared_ptr& participant) { std::unique_lock lock(mutex_); @@ -111,37 +108,6 @@ void ParticipantsDatabase::add_participant_( participants_[id] = participant; } -std::shared_ptr ParticipantsDatabase::pop_( - const ParticipantId& id) noexcept -{ - auto it = participants_.find(id); - - if (it == participants_.end()) - { - // No this participant stored - return nullptr; - } - - std::shared_ptr participant_to_erase = it->second; - participants_.erase(it); - - logInfo(DDSROUTER_PARTICIPANT_DATABASE, "Poping Participant " << participant_to_erase->id()); - - return participant_to_erase; -} - -std::shared_ptr ParticipantsDatabase::pop_() noexcept -{ - if (participants_.empty()) - { - return nullptr; - } - else - { - return pop_(participants_.begin()->first); - } -} - } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp b/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp index 515ecca30..7083cbf9d 100644 --- a/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp +++ b/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp @@ -16,7 +16,7 @@ * @file CacheChangePool.cpp */ -#include +#include #include namespace eprosima { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp b/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp index 71916243a..cc55d00e9 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp +++ b/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp @@ -17,7 +17,7 @@ * */ -#include +#include #include namespace eprosima { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp b/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp index 993b64d4b..e45234c5f 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp +++ b/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp b/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp index f3b25cee9..7aa5ee363 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp +++ b/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp b/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp index 42dd5799e..61e88a415 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp +++ b/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp similarity index 71% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp index 65272b8e6..36850101e 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp @@ -18,21 +18,21 @@ #include -#include + #include #include -#include -#include -#include +#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { BaseParticipant::BaseParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database) : configuration_(participant_configuration) , payload_pool_(payload_pool) , discovery_database_(discovery_database) @@ -59,20 +59,13 @@ BaseParticipant::~BaseParticipant() logDebug(DDSROUTER_TRACK, "Participant " << *this << " destroyed."); } -types::ParticipantId BaseParticipant::id() const noexcept +core::types::ParticipantId BaseParticipant::id() const noexcept { std::lock_guard lock(mutex_); return configuration_->id; } -types::ParticipantKind BaseParticipant::kind() const noexcept -{ - std::lock_guard lock(mutex_); - - return configuration_->kind; -} - bool BaseParticipant::is_repeater() const noexcept { std::lock_guard lock(mutex_); @@ -82,20 +75,11 @@ bool BaseParticipant::is_repeater() const noexcept bool BaseParticipant::is_rtps_kind() const noexcept { - switch (kind()) - { - case types::ParticipantKind::simple_rtps: - case types::ParticipantKind::local_discovery_server: - case types::ParticipantKind::wan_discovery_server: - case types::ParticipantKind::wan_initial_peers: - return true; - default: - return false; - } + return false; } -std::shared_ptr BaseParticipant::create_writer( - types::DdsTopic topic) +std::shared_ptr BaseParticipant::create_writer( + core::types::DdsTopic topic) { std::lock_guard lock(mutex_); @@ -107,7 +91,7 @@ std::shared_ptr BaseParticipant::create_writer( ". Writer already exists."); } - std::shared_ptr new_writer = create_writer_(topic); + std::shared_ptr new_writer = create_writer_(topic); logInfo(DDSROUTER_BASEPARTICIPANT, "Created writer in Participant " << id() << " for topic " << topic); @@ -117,8 +101,8 @@ std::shared_ptr BaseParticipant::create_writer( return new_writer; } -std::shared_ptr BaseParticipant::create_reader( - types::DdsTopic topic) +std::shared_ptr BaseParticipant::create_reader( + core::types::DdsTopic topic) { std::lock_guard lock(mutex_); @@ -130,7 +114,7 @@ std::shared_ptr BaseParticipant::create_reader( ". Reader already exists."); } - std::shared_ptr new_reader = create_reader_(topic); + std::shared_ptr new_reader = create_reader_(topic); logInfo(DDSROUTER_BASEPARTICIPANT, "Created reader in Participant " << id() << " for topic " << topic); @@ -141,7 +125,7 @@ std::shared_ptr BaseParticipant::create_reader( } void BaseParticipant::delete_writer( - std::shared_ptr writer) noexcept + std::shared_ptr writer) noexcept { std::lock_guard lock(mutex_); @@ -157,7 +141,7 @@ void BaseParticipant::delete_writer( } void BaseParticipant::delete_reader( - std::shared_ptr reader) noexcept + std::shared_ptr reader) noexcept { std::lock_guard lock(mutex_); @@ -173,18 +157,18 @@ void BaseParticipant::delete_reader( } void BaseParticipant::delete_writer_( - std::shared_ptr ) noexcept + std::shared_ptr ) noexcept { // It does nothing. Override this method so it has functionality. } void BaseParticipant::delete_reader_( - std::shared_ptr ) noexcept + std::shared_ptr ) noexcept { // It does nothing. Override this method so it has functionality. } -types::ParticipantId BaseParticipant::id_nts_() const noexcept +core::types::ParticipantId BaseParticipant::id_nts_() const noexcept { return configuration_->id; } @@ -193,10 +177,10 @@ std::ostream& operator <<( std::ostream& os, const BaseParticipant& participant) { - os << "{" << participant.id() << ";" << participant.configuration_->kind << "}"; + os << "{" << participant.id() << "}"; return os; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BlankParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp similarity index 69% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/BlankParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp index 962918785..42c28a03d 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/BlankParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp @@ -16,14 +16,13 @@ * @file BlankParticipant.cpp */ -#include -#include -#include -#include +#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -38,11 +37,6 @@ ParticipantId BlankParticipant::id() const noexcept return id_; } -ParticipantKind BlankParticipant::kind() const noexcept -{ - return ParticipantKind::blank; -} - bool BlankParticipant::is_repeater() const noexcept { return false; @@ -53,28 +47,33 @@ bool BlankParticipant::is_rtps_kind() const noexcept return false; } -std::shared_ptr BlankParticipant::create_writer( +std::shared_ptr BlankParticipant::create_writer( DdsTopic topic) { return std::make_shared(); } -std::shared_ptr BlankParticipant::create_reader( +std::shared_ptr BlankParticipant::create_reader( DdsTopic topic) { return std::make_shared(); } void BlankParticipant::delete_writer( - std::shared_ptr writer) noexcept + std::shared_ptr writer) noexcept { } void BlankParticipant::delete_reader( - std::shared_ptr reader) noexcept + std::shared_ptr reader) noexcept +{ +} + +void BlankParticipant::start() { + // Do nothing } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp similarity index 84% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp index fd5fd33f8..7386ec3bc 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp @@ -16,15 +16,15 @@ * @file DummyParticipant.cpp */ -#include -#include -#include -#include + +#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -32,9 +32,9 @@ std::mutex DummyParticipant::static_mutex_; std::map DummyParticipant::participants_; DummyParticipant::DummyParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database) : BaseParticipant(participant_configuration, payload_pool, discovery_database) { std::unique_lock lock(static_mutex_); @@ -51,13 +51,13 @@ DummyParticipant::~DummyParticipant() participants_.erase(id()); } -std::shared_ptr DummyParticipant::create_writer_( +std::shared_ptr DummyParticipant::create_writer_( DdsTopic topic) { return std::make_shared(id(), topic, payload_pool_); } -std::shared_ptr DummyParticipant::create_reader_( +std::shared_ptr DummyParticipant::create_reader_( DdsTopic topic) { return std::make_shared(id(), topic, payload_pool_); @@ -129,6 +129,6 @@ DummyParticipant* DummyParticipant::get_participant( } } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/EchoParticipant.cpp similarity index 75% rename from ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/auxiliar/EchoParticipant.cpp index f87105a0f..76ac753a6 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/EchoParticipant.cpp @@ -18,21 +18,22 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; EchoParticipant::EchoParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr discovery_database) + std::shared_ptr participant_configuration, + std::shared_ptr discovery_database) : BlankParticipant(participant_configuration->id) , configuration_(participant_configuration) { @@ -58,7 +59,7 @@ void EchoParticipant::echo_discovery( "New endpoint discovered: " << endpoint_discovered << "."); } -std::shared_ptr EchoParticipant::create_writer( +std::shared_ptr EchoParticipant::create_writer( DdsTopic topic) { if (configuration_->echo_data) @@ -73,11 +74,6 @@ std::shared_ptr EchoParticipant::create_writer( } } -types::ParticipantKind EchoParticipant::kind() const noexcept -{ - return ParticipantKind::echo; -} - -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/participants/participant/configuration/DiscoveryServerParticipantConfiguration.cpp similarity index 87% rename from ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp rename to ddsrouter_core/src/cpp/participants/participant/configuration/DiscoveryServerParticipantConfiguration.cpp index 3a4a90c4a..ada325c18 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/configuration/DiscoveryServerParticipantConfiguration.cpp @@ -16,28 +16,27 @@ * @file DiscoveryServerParticipantConfiguration.cpp */ -#include #include -#include #include +#include +#include + namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { using namespace eprosima::ddsrouter::core::types; DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration( const ParticipantId& id, - const ParticipantKind& kind, const bool is_repeater, const DomainId& domain_id, const GuidPrefix& discovery_server_guid_prefix, const std::set
& listening_addresses, const std::set& connection_addresses, - const types::security::TlsConfiguration& tls_configuration) - : SimpleParticipantConfiguration(id, kind, is_repeater, domain_id) + const security::TlsConfiguration& tls_configuration) + : SimpleParticipantConfiguration(id, is_repeater, domain_id) , discovery_server_guid_prefix(discovery_server_guid_prefix) , listening_addresses(listening_addresses) , connection_addresses(connection_addresses) @@ -95,7 +94,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( // If has listening addresses, it should be able to provide TLS server configuration if (!listening_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -105,7 +104,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( // If has connection addresses, it should be able to provide TLS client configuration if (!connection_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; @@ -123,7 +122,6 @@ bool DiscoveryServerParticipantConfiguration::operator ==( return false; } -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/InitialPeersParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/participants/participant/configuration/InitialPeersParticipantConfiguration.cpp similarity index 80% rename from ddsrouter_core/src/cpp/configuration/participant/InitialPeersParticipantConfiguration.cpp rename to ddsrouter_core/src/cpp/participants/participant/configuration/InitialPeersParticipantConfiguration.cpp index 3bb01f5a6..dd90c8e3a 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/InitialPeersParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/configuration/InitialPeersParticipantConfiguration.cpp @@ -16,27 +16,26 @@ * @file InitialPeersParticipantConfiguration.cpp */ -#include #include -#include #include +#include +#include + namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { using namespace eprosima::ddsrouter::core::types; InitialPeersParticipantConfiguration::InitialPeersParticipantConfiguration( - const types::ParticipantId& id, - const types::ParticipantKind& kind, + const ParticipantId& id, const bool is_repeater, - const types::DomainId& domain_id, - const std::set& listening_addresses, - const std::set& connection_addresses, - const types::security::TlsConfiguration& tls_configuration) - : SimpleParticipantConfiguration(id, kind, is_repeater, domain_id) + const DomainId& domain_id, + const std::set
& listening_addresses, + const std::set
& connection_addresses, + const security::TlsConfiguration& tls_configuration) + : SimpleParticipantConfiguration(id, is_repeater, domain_id) , listening_addresses(listening_addresses) , connection_addresses(connection_addresses) , tls_configuration(tls_configuration) @@ -86,7 +85,7 @@ bool InitialPeersParticipantConfiguration::is_valid( // If has listening addresses, it should be able to provide TLS server configuration if (!listening_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -96,7 +95,7 @@ bool InitialPeersParticipantConfiguration::is_valid( // If has connection addresses, it should be able to provide TLS client configuration if (!connection_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; @@ -114,7 +113,6 @@ bool InitialPeersParticipantConfiguration::operator ==( return false; } -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/participants/participant/configuration/ParticipantConfiguration.cpp similarity index 73% rename from ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp rename to ddsrouter_core/src/cpp/participants/participant/configuration/ParticipantConfiguration.cpp index 3b30c8b3e..9a03d1834 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/configuration/ParticipantConfiguration.cpp @@ -16,24 +16,21 @@ * @file ParticipantConfiguration.cpp */ -#include #include -#include + +#include #include namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { using namespace eprosima::ddsrouter::core::types; ParticipantConfiguration::ParticipantConfiguration( const ParticipantId& id, - const ParticipantKind& kind, const bool is_repeater /* = false */) noexcept : id(id) - , kind(kind) , is_repeater(is_repeater) { } @@ -41,28 +38,21 @@ ParticipantConfiguration::ParticipantConfiguration( bool ParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { - if (!id.is_valid()) + if (id.empty()) { error_msg << "Non valid Participant Id " << id << ". "; return false; } - if (kind == ParticipantKind::invalid) - { - error_msg << "Non valid Participant kind " << kind << ". "; - return false; - } - return true; } bool ParticipantConfiguration::operator ==( const ParticipantConfiguration& other) const noexcept { - return this->id == other.id && this->kind == other.kind; + return this->id == other.id; } -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/participants/participant/configuration/SimpleParticipantConfiguration.cpp similarity index 85% rename from ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp rename to ddsrouter_core/src/cpp/participants/participant/configuration/SimpleParticipantConfiguration.cpp index cacb04cca..80894c692 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/configuration/SimpleParticipantConfiguration.cpp @@ -16,22 +16,21 @@ * @file SimpleParticipantConfiguration.cpp */ -#include #include +#include + namespace eprosima { namespace ddsrouter { -namespace core { -namespace configuration { +namespace participants { using namespace eprosima::ddsrouter::core::types; SimpleParticipantConfiguration::SimpleParticipantConfiguration( const ParticipantId& id, - const ParticipantKind& kind, const bool is_repeater, const DomainId& domain_id) noexcept - : ParticipantConfiguration(id, kind, is_repeater) + : ParticipantConfiguration(id, is_repeater) , domain(domain_id) { } @@ -61,7 +60,6 @@ bool SimpleParticipantConfiguration::operator ==( this->domain == other.domain; } -} /* namespace configuration */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/CommonParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp similarity index 80% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/CommonParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp index d04992eb7..a4f832bb1 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/CommonParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp @@ -28,24 +28,24 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { CommonParticipant::CommonParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database, - const types::DomainId& domain_id, + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database, + const core::types::DomainId& domain_id, const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes) : BaseParticipant(participant_configuration, payload_pool, discovery_database) , domain_id_(domain_id) @@ -96,15 +96,15 @@ void CommonParticipant::onParticipantDiscovery( } template -types::Endpoint CommonParticipant::create_common_endpoint_from_info_( +core::types::Endpoint CommonParticipant::create_common_endpoint_from_info_( DiscoveryInfoKind& info) { // Parse GUID - types::Guid info_guid; + core::types::Guid info_guid; info_guid = info.info.guid(); // Parse TopicQoS - types::TopicQoS discovered_topic_qos; + core::types::TopicQoS discovered_topic_qos; // Durability discovered_topic_qos.durability_qos = info.info.m_qos.m_durability.durabilityKind(); // Reliability @@ -128,20 +128,20 @@ types::Endpoint CommonParticipant::create_common_endpoint_from_info_( discovered_topic_qos.ownership_qos = info.info.m_qos.m_ownership.kind; // Parse Topic - types::DdsTopic info_topic(std::string(info.info.topicName()), std::string(info.info.typeName())); + core::types::DdsTopic info_topic(std::string(info.info.topicName()), std::string(info.info.typeName())); info_topic.keyed = info.info.topicKind() == eprosima::fastrtps::rtps::TopicKind_t::WITH_KEY; // Set qos as set, but fuzzy info_topic.topic_qos = discovered_topic_qos; info_topic.topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_fuzzy); - types::Endpoint endpoint = types::Endpoint( - types::EndpointKind::invalid, + core::types::Endpoint endpoint = core::types::Endpoint( + core::types::EndpointKind::invalid, info_guid, info_topic, this->id_nts_()); // Parse specific QoS of the entity - types::SpecificEndpointQoS specific_qos; + core::types::SpecificEndpointQoS specific_qos; if (discovered_topic_qos.has_partitions()) { specific_qos.partitions = info.info.m_qos.m_partition; @@ -153,11 +153,11 @@ types::Endpoint CommonParticipant::create_common_endpoint_from_info_( } template<> -types::Endpoint CommonParticipant::create_endpoint_from_info_( +core::types::Endpoint CommonParticipant::create_endpoint_from_info_( fastrtps::rtps::WriterDiscoveryInfo& info) { // Create Endpoint from common info - types::Endpoint endpoint = create_common_endpoint_from_info_(info); + core::types::Endpoint endpoint = create_common_endpoint_from_info_(info); if (endpoint.topic_qos().has_ownership()) { @@ -168,20 +168,20 @@ types::Endpoint CommonParticipant::create_endpoint_from_info_ -types::Endpoint CommonParticipant::create_endpoint_from_info_( +core::types::Endpoint CommonParticipant::create_endpoint_from_info_( fastrtps::rtps::ReaderDiscoveryInfo& info) { // Create Endpoint from common info - types::Endpoint endpoint = create_common_endpoint_from_info_(info); + core::types::Endpoint endpoint = create_common_endpoint_from_info_(info); // Set type - endpoint.kind(types::EndpointKind::reader); + endpoint.kind(core::types::EndpointKind::reader); return endpoint; } @@ -192,7 +192,7 @@ void CommonParticipant::onReaderDiscovery( { if (info.info.guid().guidPrefix != participant->getGuid().guidPrefix) { - types::Endpoint info_reader = create_endpoint_from_info_(info); + core::types::Endpoint info_reader = create_endpoint_from_info_(info); if (info.status == fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERED_READER) { @@ -230,7 +230,7 @@ void CommonParticipant::onWriterDiscovery( { if (info.info.guid().guidPrefix != participant->getGuid().guidPrefix) { - types::Endpoint info_writer = create_endpoint_from_info_(info); + core::types::Endpoint info_writer = create_endpoint_from_info_(info); if (info.status == fastrtps::rtps::WriterDiscoveryInfo::DISCOVERED_WRITER) { @@ -262,8 +262,18 @@ void CommonParticipant::onWriterDiscovery( } } +bool CommonParticipant::is_rtps_kind() const noexcept +{ + return true; +} + +void CommonParticipant::start() +{ + // TODO +} + void CommonParticipant::create_participant_( - const types::DomainId& domain, + const core::types::DomainId& domain, const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes) { logInfo(DDSROUTER_RTPS_PARTICIPANT, @@ -283,14 +293,13 @@ void CommonParticipant::create_participant_( } logInfo(DDSROUTER_RTPS_PARTICIPANT, - "New Participant " << this->configuration_->kind << - " created with id " << this->id() << + "New Participant created with id " << this->id() << " in domain " << domain << " with guid " << rtps_participant_->getGuid() << (this->is_repeater() ? " (repeater)" : " (non repeater)")); } -std::shared_ptr CommonParticipant::create_writer_( - types::DdsTopic topic) +std::shared_ptr CommonParticipant::create_writer_( + core::types::DdsTopic topic) { if (topic.topic_qos.get_reference().has_partitions() || topic.topic_qos.get_reference().has_ownership()) { @@ -316,8 +325,8 @@ std::shared_ptr CommonParticipant::create_writer_( } } -std::shared_ptr CommonParticipant::create_reader_( - types::DdsTopic topic) +std::shared_ptr CommonParticipant::create_reader_( + core::types::DdsTopic topic) { if (topic.topic_qos.get_reference().has_partitions() || topic.topic_qos.get_reference().has_ownership()) { @@ -346,17 +355,17 @@ std::shared_ptr CommonParticipant::create_reader_( fastrtps::rtps::RTPSParticipantAttributes CommonParticipant::get_participant_attributes_( - const configuration::ParticipantConfiguration* participant_configuration) + const ParticipantConfiguration* participant_configuration) { fastrtps::rtps::RTPSParticipantAttributes params; // Add Participant name - params.setName(participant_configuration->id.id_name().c_str()); + params.setName(participant_configuration->id.c_str()); return params; } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/rtps/DiscoveryServerParticipant.cpp similarity index 93% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/rtps/DiscoveryServerParticipant.cpp index ae6ec23ba..3fa864bc3 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/rtps/DiscoveryServerParticipant.cpp @@ -27,17 +27,17 @@ #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { DiscoveryServerParticipant::DiscoveryServerParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database) : CommonParticipant( participant_configuration, payload_pool, @@ -49,13 +49,13 @@ DiscoveryServerParticipant::DiscoveryServerParticipant( fastrtps::rtps::RTPSParticipantAttributes DiscoveryServerParticipant::get_participant_attributes_( - const configuration::DiscoveryServerParticipantConfiguration* configuration) + const DiscoveryServerParticipantConfiguration* configuration) { // Use default as base attributes fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::get_participant_attributes_(configuration); // Auxiliary variable to save characters and improve readability - const types::GuidPrefix& discovery_server_guid_prefix = configuration->discovery_server_guid_prefix; + const core::types::GuidPrefix& discovery_server_guid_prefix = configuration->discovery_server_guid_prefix; const auto& tls_config = configuration->tls_configuration; // Needed values to check at the end if descriptor must be set @@ -72,7 +72,7 @@ DiscoveryServerParticipant::get_participant_attributes_( ///// // Set listening addresses - for (types::Address address : configuration->listening_addresses) + for (core::types::Address address : configuration->listening_addresses) { if (!address.is_valid()) { @@ -197,7 +197,7 @@ DiscoveryServerParticipant::get_participant_attributes_( ///// // Set connection addresses - for (types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses) + for (core::types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses) { if (!connection_address.is_valid()) { @@ -210,9 +210,9 @@ DiscoveryServerParticipant::get_participant_attributes_( } // Set Server GUID - types::GuidPrefix server_prefix = connection_address.discovery_server_guid_prefix(); + core::types::GuidPrefix server_prefix = connection_address.discovery_server_guid_prefix(); - for (types::Address address : connection_address.addresses()) + for (core::types::Address address : connection_address.addresses()) { if (!address.is_valid()) { @@ -361,6 +361,6 @@ DiscoveryServerParticipant::get_participant_attributes_( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/rtps/InitialPeersParticipant.cpp similarity index 95% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/rtps/InitialPeersParticipant.cpp index 8b7593c06..a1f3c7c9e 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/rtps/InitialPeersParticipant.cpp @@ -23,19 +23,19 @@ #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; InitialPeersParticipant::InitialPeersParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database) : CommonParticipant( participant_configuration, payload_pool, @@ -46,7 +46,7 @@ InitialPeersParticipant::InitialPeersParticipant( } fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participant_attributes_( - const configuration::InitialPeersParticipantConfiguration* configuration) + const InitialPeersParticipantConfiguration* configuration) { // Use default as base attributes fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::get_participant_attributes_(configuration); @@ -69,7 +69,7 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participa ///// // Set listening addresses - for (const types::Address& address : configuration->listening_addresses) + for (const core::types::Address& address : configuration->listening_addresses) { if (!address.is_valid()) { @@ -195,7 +195,7 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participa ///// // Set connection addresses - for (const types::Address& connection_address : configuration->connection_addresses) + for (const core::types::Address& connection_address : configuration->connection_addresses) { if (!connection_address.is_valid()) { @@ -338,6 +338,6 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participa } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/SimpleParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/rtps/SimpleParticipant.cpp similarity index 78% rename from ddsrouter_core/src/cpp/participant/implementations/rtps/SimpleParticipant.cpp rename to ddsrouter_core/src/cpp/participants/participant/rtps/SimpleParticipant.cpp index 975b9defa..d530c4601 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/SimpleParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/rtps/SimpleParticipant.cpp @@ -21,19 +21,19 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; SimpleParticipant::SimpleParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + std::shared_ptr participant_configuration, + std::shared_ptr payload_pool, + std::shared_ptr discovery_database) : CommonParticipant( participant_configuration, payload_pool, @@ -44,6 +44,6 @@ SimpleParticipant::SimpleParticipant( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BaseReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp similarity index 94% rename from ddsrouter_core/src/cpp/reader/implementations/auxiliar/BaseReader.cpp rename to ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp index 51973b9dc..65a517204 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BaseReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp @@ -16,13 +16,13 @@ * @file BaseReader.cpp */ -#include +#include #include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -35,7 +35,7 @@ const std::function BaseReader::DEFAULT_ON_DATA_AVAILABLE_CALLBACK = BaseReader::BaseReader( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool) + std::shared_ptr payload_pool) : participant_id_(participant_id) , topic_(topic) , payload_pool_(payload_pool) @@ -104,7 +104,7 @@ void BaseReader::unset_on_data_available_callback() noexcept } utils::ReturnCode BaseReader::take( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { std::lock_guard lock(mutex_); @@ -161,6 +161,6 @@ std::ostream& operator <<( return os; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BlankReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp similarity index 85% rename from ddsrouter_core/src/cpp/reader/implementations/auxiliar/BlankReader.cpp rename to ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp index 0d30844cb..6d469db42 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/BlankReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp @@ -16,11 +16,11 @@ * @file BlankReader.cpp */ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -42,11 +42,11 @@ void BlankReader::unset_on_data_available_callback() noexcept } utils::ReturnCode BlankReader::take( - std::unique_ptr&) noexcept + std::unique_ptr&) noexcept { return utils::ReturnCode::RETCODE_NO_DATA; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/DummyReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp similarity index 91% rename from ddsrouter_core/src/cpp/reader/implementations/auxiliar/DummyReader.cpp rename to ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp index 6c189734f..9b96a67c9 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/auxiliar/DummyReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp @@ -16,12 +16,12 @@ * @file DummyReader.cpp */ -#include +#include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -38,7 +38,7 @@ void DummyReader::simulate_data_reception( } utils::ReturnCode DummyReader::take_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { std::lock_guard lock(dummy_mutex_); @@ -72,6 +72,6 @@ utils::ReturnCode DummyReader::take_( return utils::ReturnCode::RETCODE_OK; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/rtps/CommonReader.cpp b/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp similarity index 93% rename from ddsrouter_core/src/cpp/reader/implementations/rtps/CommonReader.cpp rename to ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp index bcd10f0a0..095e02f14 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/rtps/CommonReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp @@ -19,21 +19,24 @@ #include #include -#include #include #include +#include +#include + namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; +using eprosima::ddsrouter::core::types::operator<<; CommonReader::CommonReader( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const fastrtps::rtps::HistoryAttributes& history_attributes, const fastrtps::rtps::ReaderAttributes& reader_attributes, @@ -127,7 +130,7 @@ void CommonReader::internal_entities_creation_( topic_ << " with guid " << rtps_reader_->getGuid()); } -types::Guid CommonReader::guid() const noexcept +core::types::Guid CommonReader::guid() const noexcept { return rtps_reader_->getGuid(); } @@ -143,7 +146,7 @@ uint64_t CommonReader::get_unread_count() const noexcept } utils::ReturnCode CommonReader::take_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { // Check if there is data available if (!(get_unread_count() > 0)) @@ -185,7 +188,7 @@ utils::ReturnCode CommonReader::take_( void CommonReader::fill_received_data_( fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept + std::unique_ptr& data_to_fill) const noexcept { // Store the new data that has arrived in the Track data // Get the writer guid @@ -247,7 +250,7 @@ bool CommonReader::come_from_this_participant_( } fastrtps::rtps::HistoryAttributes CommonReader::get_history_attributes_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::HistoryAttributes att; att.memoryPolicy = @@ -259,7 +262,7 @@ fastrtps::rtps::HistoryAttributes CommonReader::get_history_attributes_( } fastrtps::rtps::ReaderAttributes CommonReader::get_reader_attributes_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::ReaderAttributes att; @@ -285,7 +288,7 @@ fastrtps::rtps::ReaderAttributes CommonReader::get_reader_attributes_( } fastrtps::TopicAttributes CommonReader::get_topic_attributes_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::TopicAttributes att; @@ -311,7 +314,7 @@ fastrtps::TopicAttributes CommonReader::get_topic_attributes_( } fastrtps::ReaderQos CommonReader::get_reader_qos_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::ReaderQos properties; @@ -349,9 +352,10 @@ void CommonReader::onNewCacheChangeAdded( if (enabled_) { // Call Track callback (by calling BaseReader callback method) - logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Data arrived to Reader " << *this << " with payload " << change->serializedPayload << " from " << - change->writerGUID); + // TODO (paris) Uncomment + // logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, + // "Data arrived to Reader " << *this << " with payload " << change->serializedPayload << " from " << + // change->writerGUID); on_data_available_(); } else @@ -426,6 +430,6 @@ utils::ReturnCode CommonReader::is_data_correct_( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/rtps/SimpleReader.cpp b/ddsrouter_core/src/cpp/participants/reader/rtps/SimpleReader.cpp similarity index 88% rename from ddsrouter_core/src/cpp/reader/implementations/rtps/SimpleReader.cpp rename to ddsrouter_core/src/cpp/participants/reader/rtps/SimpleReader.cpp index 79eb3c42b..71cc0b3d6 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/rtps/SimpleReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/rtps/SimpleReader.cpp @@ -19,13 +19,13 @@ #include #include -#include +#include #include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; @@ -33,7 +33,7 @@ using namespace eprosima::ddsrouter::core::types; SimpleReader::SimpleReader( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant) : CommonReader( participant_id, topic, payload_pool, rtps_participant, @@ -45,6 +45,6 @@ SimpleReader::SimpleReader( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/reader/implementations/rtps/SpecificQoSReader.cpp b/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp similarity index 80% rename from ddsrouter_core/src/cpp/reader/implementations/rtps/SpecificQoSReader.cpp rename to ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp index 396a034fd..06f4616a9 100644 --- a/ddsrouter_core/src/cpp/reader/implementations/rtps/SpecificQoSReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp @@ -22,21 +22,21 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; SpecificQoSReader::SpecificQoSReader( - const ParticipantId& participant_id, - const DdsTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - std::shared_ptr discovery_database) + std::shared_ptr discovery_database) : CommonReader( participant_id, topic, payload_pool, rtps_participant, get_history_attributes_(topic), @@ -47,15 +47,15 @@ SpecificQoSReader::SpecificQoSReader( { } -types::SpecificEndpointQoS SpecificQoSReader::specific_qos_of_writer_( - const types::Guid& guid) const +core::types::SpecificEndpointQoS SpecificQoSReader::specific_qos_of_writer_( + const core::types::Guid& guid) const { return discovery_database_->get_endpoint(guid).specific_qos(); } void SpecificQoSReader::fill_received_data_( fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept + std::unique_ptr& data_to_fill) const noexcept { CommonReader::fill_received_data_(received_change, data_to_fill); @@ -78,6 +78,6 @@ void SpecificQoSReader::fill_received_data_( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BaseWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp similarity index 90% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/BaseWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp index 8f34f98c2..15a8c4551 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BaseWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp @@ -18,18 +18,18 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; BaseWriter::BaseWriter( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool) + std::shared_ptr payload_pool) : participant_id_(participant_id) , topic_(topic) , payload_pool_(payload_pool) @@ -67,7 +67,7 @@ void BaseWriter::disable() noexcept } utils::ReturnCode BaseWriter::write( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { std::lock_guard lock(mutex_); @@ -101,6 +101,6 @@ std::ostream& operator <<( return os; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BlankWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp similarity index 83% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/BlankWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp index fe064abee..be6b8cca9 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/BlankWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp @@ -16,11 +16,11 @@ * @file BlankWriter.cpp */ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -33,11 +33,11 @@ void BlankWriter::disable() noexcept } utils::ReturnCode BlankWriter::write( - std::unique_ptr&) noexcept + std::unique_ptr&) noexcept { return utils::ReturnCode::RETCODE_OK; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/DummyWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp similarity index 91% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/DummyWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp index a39dd5524..1777a9ad9 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/DummyWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp @@ -16,16 +16,16 @@ * @file DummyWriter.cpp */ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; utils::ReturnCode DummyWriter::write_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { { std::lock_guard lock(dummy_mutex_); @@ -68,6 +68,6 @@ std::vector DummyWriter::get_data_that_should_have_been_sent() return data_stored_; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/EchoWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp similarity index 88% rename from ddsrouter_core/src/cpp/writer/implementations/auxiliar/EchoWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp index c74091b09..18590c012 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/auxiliar/EchoWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp @@ -18,16 +18,16 @@ #include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; EchoWriter::EchoWriter( - const types::DdsTopic& topic, + const core::types::DdsTopic& topic, bool verbose) : topic_(topic) , verbose_(verbose) @@ -39,7 +39,7 @@ EchoWriter::EchoWriter( } utils::ReturnCode EchoWriter::write( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { // TODO: Add Participant receiver Id when added to DataReceived if (!verbose_) @@ -65,6 +65,6 @@ utils::ReturnCode EchoWriter::write( return utils::ReturnCode::RETCODE_OK; } -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/CommonWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp similarity index 91% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/CommonWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp index 038849794..32f786265 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/CommonWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp @@ -22,23 +22,24 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; +using eprosima::ddsrouter::core::types::operator<<; CommonWriter::CommonWriter( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater, const fastrtps::rtps::HistoryAttributes& history_attributes, @@ -119,7 +120,7 @@ bool CommonWriter::come_from_this_participant_( // Specific enable/disable do not need to be implemented utils::ReturnCode CommonWriter::write_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { // Take new Change from history @@ -181,12 +182,12 @@ utils::ReturnCode CommonWriter::write_( utils::ReturnCode CommonWriter::fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - std::unique_ptr& data) const noexcept + std::unique_ptr& data) const noexcept { if (repeater_) { // Add origin to change in case the cache change is RouterCacheChange (only in repeater mode) - types::RouterCacheChange& change_ref = static_cast(*to_send_change_to_fill); + core::types::RouterCacheChange& change_ref = static_cast(*to_send_change_to_fill); change_ref.last_writer_guid_prefix = data->properties.source_guid.guidPrefix; } @@ -225,7 +226,7 @@ utils::ReturnCode CommonWriter::fill_to_send_data_( void CommonWriter::fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& params, - std::unique_ptr& data_to_fill) const noexcept + std::unique_ptr& data_to_fill) const noexcept { // Set data output parameters data_to_fill->sent_sequence_number = params.sample_identity().sequence_number(); @@ -255,7 +256,7 @@ void CommonWriter::internal_entities_creation_( rtps_participant_, non_const_writer_attributes, payload_pool_, - std::make_shared(pool_configuration), + std::make_shared(pool_configuration), rtps_history_, this); } @@ -306,7 +307,7 @@ void CommonWriter::internal_entities_creation_( } fastrtps::rtps::HistoryAttributes CommonWriter::get_history_attributes_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::HistoryAttributes att; @@ -319,7 +320,7 @@ fastrtps::rtps::HistoryAttributes CommonWriter::get_history_attributes_( } fastrtps::rtps::WriterAttributes CommonWriter::get_writer_attributes_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::WriterAttributes att; @@ -349,7 +350,7 @@ fastrtps::rtps::WriterAttributes CommonWriter::get_writer_attributes_( } fastrtps::TopicAttributes CommonWriter::get_topic_attributes_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::TopicAttributes att; @@ -371,7 +372,7 @@ fastrtps::TopicAttributes CommonWriter::get_topic_attributes_( } fastrtps::WriterQos CommonWriter::get_writer_qos_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { fastrtps::WriterQos qos; @@ -396,7 +397,7 @@ fastrtps::WriterQos CommonWriter::get_writer_qos_( } utils::PoolConfiguration CommonWriter::cache_change_pool_configuration_( - const types::DdsTopic& topic) noexcept + const core::types::DdsTopic& topic) noexcept { utils::PoolConfiguration config; config.maximum_size = topic.topic_qos.get_reference().history_depth; @@ -407,6 +408,6 @@ utils::PoolConfiguration CommonWriter::cache_change_pool_configuration_( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/MultiWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp similarity index 85% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/MultiWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp index 50e32d1cb..7e1c0144b 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/MultiWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp @@ -22,16 +22,16 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; @@ -39,7 +39,7 @@ using namespace eprosima::ddsrouter::core::types; MultiWriter::MultiWriter( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater /* = false */) : BaseWriter(participant_id, topic, payload_pool) @@ -84,14 +84,14 @@ void MultiWriter::disable_() noexcept } bool MultiWriter::exist_partition_( - const types::SpecificEndpointQoS& data_qos) + const core::types::SpecificEndpointQoS& data_qos) { std::shared_lock lock(writers_map_); return writers_map_.find(data_qos) != writers_map_.end(); } QoSSpecificWriter* MultiWriter::get_writer_or_create_( - const types::SpecificEndpointQoS& data_qos) + const core::types::SpecificEndpointQoS& data_qos) { // NOTE: it uses unique lock because it may change the database, and there is no way // to do so if taking share and unique must be done. @@ -119,7 +119,7 @@ QoSSpecificWriter* MultiWriter::get_writer_or_create_( } QoSSpecificWriter* MultiWriter::create_writer_nts_( - const types::SpecificEndpointQoS& data_qos) + const core::types::SpecificEndpointQoS& data_qos) { logDebug( DDSROUTER_MULTIWRITER, @@ -139,7 +139,7 @@ QoSSpecificWriter* MultiWriter::create_writer_nts_( // Specific enable/disable do not need to be implemented utils::ReturnCode MultiWriter::write_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { logDebug( DDSROUTER_MULTIWRITER, @@ -158,6 +158,6 @@ utils::ReturnCode MultiWriter::write_( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/QoSSpecificWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/QoSSpecificWriter.cpp similarity index 84% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/QoSSpecificWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/rtps/QoSSpecificWriter.cpp index c872ab5b7..a3eb8c4b4 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/QoSSpecificWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/QoSSpecificWriter.cpp @@ -16,11 +16,11 @@ * @file QoSSpecificWriter.cpp */ -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; @@ -28,9 +28,9 @@ using namespace eprosima::ddsrouter::core::types; QoSSpecificWriter::QoSSpecificWriter( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - const types::SpecificEndpointQoS& specific_qos, + const core::types::SpecificEndpointQoS& specific_qos, const bool repeater /* = false */) : CommonWriter( participant_id, topic, payload_pool, rtps_participant, repeater, @@ -44,8 +44,8 @@ QoSSpecificWriter::QoSSpecificWriter( } fastrtps::WriterQos QoSSpecificWriter::get_writer_qos_( - const types::SpecificEndpointQoS& specific_qos, - const types::DdsTopic& topic) noexcept + const core::types::SpecificEndpointQoS& specific_qos, + const core::types::DdsTopic& topic) noexcept { // Get QoS from parent class fastrtps::WriterQos qos = CommonWriter::get_writer_qos_(topic); @@ -69,6 +69,6 @@ fastrtps::WriterQos QoSSpecificWriter::get_writer_qos_( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/writer/implementations/rtps/SimpleWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/SimpleWriter.cpp similarity index 79% rename from ddsrouter_core/src/cpp/writer/implementations/rtps/SimpleWriter.cpp rename to ddsrouter_core/src/cpp/participants/writer/rtps/SimpleWriter.cpp index fd38edb60..2c5782ab8 100644 --- a/ddsrouter_core/src/cpp/writer/implementations/rtps/SimpleWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/SimpleWriter.cpp @@ -22,15 +22,15 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { namespace rtps { using namespace eprosima::ddsrouter::core::types; @@ -38,7 +38,7 @@ using namespace eprosima::ddsrouter::core::types; SimpleWriter::SimpleWriter( const ParticipantId& participant_id, const DdsTopic& topic, - std::shared_ptr payload_pool, + std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater /* = false */) : CommonWriter( @@ -52,6 +52,6 @@ SimpleWriter::SimpleWriter( } } /* namespace rtps */ -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp new file mode 100644 index 000000000..5fa39e0c3 --- /dev/null +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp @@ -0,0 +1,61 @@ +// Copyright 2022 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 RepeaterDataFilter.cpp + */ + +#include +#include +#include + +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { +namespace rtps { + +bool RepeaterDataFilter::is_relevant( + const fastrtps::rtps::CacheChange_t& change, + const fastrtps::rtps::GUID_t& reader_guid) const +{ + if (!SelfDataFilter::is_relevant(change, reader_guid)) + { + logDebug( + REPEATER_DATA_FILTER, + "Ignoring message by SelfDataFilter is_relevant result."); + + // If origin filter does not pass this change, it is discarded + return false; + } + + // As ChangePool is our own, and we use RouterCacheChange, we can cast this without problem + const auto& change_ref = static_cast(change); + + bool is_relevant = change_ref.last_writer_guid_prefix != reader_guid.guidPrefix; + + logDebug( + REPEATER_DATA_FILTER, + "Evaluating whether Change with origin writer GUID prefix " << change_ref.last_writer_guid_prefix << + " is relevant for reader GUID " << reader_guid << "? " << (is_relevant ? "TRUE" : "FALSE")); + + return is_relevant; +} + +} /* namespace rtps */ +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp new file mode 100644 index 000000000..c1a7c58d3 --- /dev/null +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp @@ -0,0 +1,58 @@ +// Copyright 2022 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 RepeaterDataFilter.hpp + */ + +#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ +#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ + +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { +namespace rtps { + +/** + * This filter allows to not send messages from this Writer to the Readers belonging to the source Participant. + * It is used in "repeater" participants in order to propagate information to external participants + * (participants not belonging to the same DDS-Router instance), + * leaving out the participant from which this information was received. + * + * This uses the RouterCacheChange extra information. + */ +class RepeaterDataFilter : public SelfDataFilter +{ +public: + + /** + * @brief Whether incoming change is relevant for this reader. + * + * @return true if the reader does not belong to Participant that previously sent this message. + * @return false otherwise. + */ + bool is_relevant( + const fastrtps::rtps::CacheChange_t& change, + const fastrtps::rtps::GUID_t& reader_guid + ) const override; +}; + +} /* namespace rtps */ +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp new file mode 100644 index 000000000..b66686a40 --- /dev/null +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp @@ -0,0 +1,42 @@ +// Copyright 2022 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 SelfDataFilter.cpp + */ + +#include +#include +#include + +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { +namespace rtps { + +bool SelfDataFilter::is_relevant( + const fastrtps::rtps::CacheChange_t& change, + const fastrtps::rtps::GUID_t& reader_guid) const +{ + // It is relevant only if the reader does not belong to same participant as writer + return change.writerGUID.guidPrefix != reader_guid.guidPrefix; +} + +} /* namespace rtps */ +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp new file mode 100644 index 000000000..52af7569f --- /dev/null +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp @@ -0,0 +1,66 @@ +// Copyright 2022 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 SelfDataFilter.hpp + */ + +#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ +#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ + +#include + +///// +// Forward declarations +namespace eprosima { +namespace fastrtps { +namespace rtps { + +struct CacheChange_t; +struct GUID_t; + +} /* namespace rtps */ +} /* namespace fastrtps */ +} /* namespace eprosima */ + +namespace eprosima { +namespace ddsrouter { +namespace participants { +namespace rtps { + +/** + * This filter allows to not send messages from this Writer to the Readers in the same Participant. + */ +class SelfDataFilter : public fastdds::rtps::IReaderDataFilter +{ +public: + + /** + * @brief Whether incoming change is relevant for this reader. + * + * @return true if the reader does not belong to same Participant. + * @return false otherwise. + */ + bool is_relevant( + const fastrtps::rtps::CacheChange_t& change, + const fastrtps::rtps::GUID_t& reader_guid + ) const override; +}; + +} /* namespace rtps */ +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ */ diff --git a/ddsrouter_core/src/cpp/types/participant/ParticipantId.cpp b/ddsrouter_core/src/cpp/types/participant/ParticipantId.cpp deleted file mode 100644 index 95e0a1e34..000000000 --- a/ddsrouter_core/src/cpp/types/participant/ParticipantId.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2021 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 ParticipantId.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -//! INVALID_ID key -const std::string ParticipantId::INVALID_ID = "__invalid_ddsrouter_participant__"; - -ParticipantId::ParticipantId( - const std::string& id) noexcept - : id_(id) -{ - // If the ID cannot be used as a ParticipantId, it must store the INVALID string - if (!ParticipantId::is_valid_id(id)) - { - id_ = INVALID_ID; - } -} - -ParticipantId::ParticipantId() noexcept - : id_(INVALID_ID) -{ -} - -ParticipantId ParticipantId::invalid() noexcept -{ - return ParticipantId(); -} - -bool ParticipantId::is_valid_id( - const std::string& tag) noexcept -{ - return !tag.empty() && tag != INVALID_ID; -} - -bool ParticipantId::is_valid() const noexcept -{ - return is_valid_id(id_); -} - -std::string ParticipantId::id_name() const noexcept -{ - return id_; -} - -bool ParticipantId::operator ==( - const ParticipantId& other) const noexcept -{ - return id_ == other.id_; -} - -bool ParticipantId::operator !=( - const ParticipantId& other) const noexcept -{ - return !(*this == other); -} - -bool ParticipantId::operator <( - const ParticipantId& other) const noexcept -{ - return id_ < other.id_; -} - -std::ostream& operator <<( - std::ostream& os, - const ParticipantId& id) -{ - os << "ParticipantId{" << id.id_name() << "}"; - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/participant/ParticipantKind.cpp b/ddsrouter_core/src/cpp/types/participant/ParticipantKind.cpp deleted file mode 100644 index 7f334550c..000000000 --- a/ddsrouter_core/src/cpp/types/participant/ParticipantKind.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2021 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 ParticipantKind.cpp - * - */ - -#include -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -std::ostream& operator <<( - std::ostream& os, - ParticipantKind kind) -{ - try - { - os << PARTICIPANT_KIND_STRINGS.at(static_cast(kind)); - } - catch (const std::out_of_range& oor) - { - utils::tsnh(utils::Formatter() << "Invalid Participant Kind." << static_cast(kind)); - } - return os; -} - -ParticipantKind participant_kind_from_name( - std::string kind_str) -{ - - // Empty strings are always invalid - if (kind_str.size() == 0) - { - return ParticipantKind::invalid; - } - - // Convert to lower case so that match is case-insensitive - utils::to_lowercase(kind_str); - - // Loop over each participant kind aliases, returning at first alias match - ParticipantKindType kind_idx = 0u; - for (const auto& aliases : PARTICIPANT_KIND_ALIASES) - { - if (std::find_if(std::cbegin(aliases), std::cend(aliases), - [kind_str](std::string str) - { - utils::to_lowercase(str); - return kind_str == str; - }) != std::cend(aliases)) - { - // Alias match, since std::find returned iterator before end - return ALL_PARTICIPANT_KINDS.at(kind_idx); - } - kind_idx++; - } - - // No alias match, so input string is not a valid alias - return ParticipantKind::invalid; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/test/TestUtils/test_utils.cpp b/ddsrouter_core/test/TestUtils/test_utils.cpp index 022872f6d..aa4b0013b 100644 --- a/ddsrouter_core/test/TestUtils/test_utils.cpp +++ b/ddsrouter_core/test/TestUtils/test_utils.cpp @@ -235,7 +235,7 @@ std::shared_ptr random_participan // Add cases where Participants need specific arguments default: - return std::make_shared(id, kind, false); + return std::make_shared(id, false); } } diff --git a/ddsrouter_core/test/TestUtils/test_utils.hpp b/ddsrouter_core/test/TestUtils/test_utils.hpp index cd8b03dcf..388c25039 100644 --- a/ddsrouter_core/test/TestUtils/test_utils.hpp +++ b/ddsrouter_core/test/TestUtils/test_utils.hpp @@ -19,11 +19,11 @@ #ifndef _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ #define _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp index 29f5fa612..e5ee8542f 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp index 485bcc78c..c154a1dbb 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp index 62732b078..8cc28ae08 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp @@ -20,10 +20,10 @@ #include #include -#include +#include #include #include -#include + #include using namespace eprosima::ddsrouter::test; diff --git a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp index cf7d6224e..4d3f91c42 100644 --- a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp +++ b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp @@ -24,9 +24,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/ddsrouter_core/test/unittest/core/CMakeLists.txt b/ddsrouter_core/test/unittest/core/CMakeLists.txt index 05f224f27..8d9fde3f3 100644 --- a/ddsrouter_core/test/unittest/core/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/core/CMakeLists.txt @@ -13,4 +13,3 @@ # limitations under the License. add_subdirectory(participants_database) -add_subdirectory(participant_factory) diff --git a/ddsrouter_core/test/unittest/core/participant_factory/CMakeLists.txt b/ddsrouter_core/test/unittest/core/participant_factory/CMakeLists.txt deleted file mode 100644 index 0f2fb11da..000000000 --- a/ddsrouter_core/test/unittest/core/participant_factory/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2021 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. - -####################### -# Participant Factory # -####################### - -set(TEST_NAME ParticipantFactoryTest) - -set(TEST_SOURCES - ParticipantFactoryTest.cpp - ) -all_library_sources("${TEST_SOURCES}") - -set(TEST_LIST - create_participant - create_invalid_participant - remove_participant - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddsrouter_core/test/unittest/core/participant_factory/ParticipantFactoryTest.cpp b/ddsrouter_core/test/unittest/core/participant_factory/ParticipantFactoryTest.cpp deleted file mode 100644 index bc8b9dbb0..000000000 --- a/ddsrouter_core/test/unittest/core/participant_factory/ParticipantFactoryTest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -namespace eprosima { -namespace ddsrouter { -namespace test { - -/* - * Generate all required objects for participant creation, - * and then create a participant from an id string - */ -std::shared_ptr create_participant( - ParticipantKind kind) -{ - ParticipantFactory participant_factory; - std::shared_ptr payload_pool = std::make_shared(); - std::shared_ptr discovery_database = std::make_shared(); - discovery_database->start(); - std::shared_ptr participant_configuration = - random_participant_configuration(kind); - - return participant_factory.create_participant(participant_configuration, payload_pool, discovery_database); -} - -} /* namespace test */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -/** - * Test \c ParticipantFactory \c create_participant method using each of the valid Participant kinds - */ -TEST(ParticipantFactoryTest, create_participant) -{ - // For each Participant Type - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::shared_ptr void_participant = test::create_participant(kind); - ASSERT_EQ(void_participant->kind(), kind) << "Failed in " << kind; - } -} - -/** - * Test \c ParticipantFactory \c create_participant method - * - * CASES: - * Invalid participant, should throw \c utils::ConfigurationException - */ -TEST(ParticipantFactoryTest, create_invalid_participant) -{ - ASSERT_THROW(test::create_participant(ParticipantKind::invalid), eprosima::utils::ConfigurationException); -} - -/** - * Test \c ParticipantFactory \c remove_participant method - * TODO: Test that actions performed in participant creation - * are correctly undone by \c remove_participant - */ -TEST(ParticipantFactoryTest, remove_participant) -{ - // TODO -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt b/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt index 1dc9b2b00..ac76d9057 100644 --- a/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt @@ -20,12 +20,10 @@ set(TEST_NAME ParticipantsDatabaseTest) set(TEST_SOURCES ParticipantsDatabaseTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participant/implementations/auxiliar/BlankParticipant.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participant/auxiliar/BlankParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantsDatabase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/reader/implementations/auxiliar/BlankReader.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/participant/ParticipantId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/participant/ParticipantKind.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/writer/implementations/auxiliar/BlankWriter.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/reader/auxiliar/BlankReader.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/writer/auxiliar/BlankWriter.cpp ) all_header_sources("${TEST_SOURCES}") diff --git a/ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp b/ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp index 612f15bab..97d97a073 100644 --- a/ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp +++ b/ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include diff --git a/ddsrouter_core/test/unittest/types/CMakeLists.txt b/ddsrouter_core/test/unittest/types/CMakeLists.txt index 96173c16d..6fbb0b168 100644 --- a/ddsrouter_core/test/unittest/types/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/types/CMakeLists.txt @@ -13,5 +13,4 @@ # limitations under the License. add_subdirectory(endpoint) -add_subdirectory(participant) add_subdirectory(topic) diff --git a/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt b/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt index a66d40b9f..828833eca 100644 --- a/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt @@ -58,7 +58,6 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/DataProperties.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/participant/ParticipantId.cpp ) set(TEST_LIST diff --git a/ddsrouter_core/test/unittest/types/participant/CMakeLists.txt b/ddsrouter_core/test/unittest/types/participant/CMakeLists.txt deleted file mode 100644 index 1ede3b9f8..000000000 --- a/ddsrouter_core/test/unittest/types/participant/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2021 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. - -################# -# ParticipantId # -################# - -set(TEST_NAME ParticipantIdTest) - -set(TEST_SOURCES - ParticipantIdTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/participant/ParticipantId.cpp - ) - -set(TEST_LIST - default_constructor - constructor - invalid - is_valid_id - is_valid - equal_operator - minor_operator - is_non_valid_id - is_non_valid - non_equal_operator - non_minor_operator - ) - -set(TEST_EXTRA_LIBRARIES - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - - -################### -# ParticipantKind # -################### - -set(TEST_NAME ParticipantKindTest) - -set(TEST_SOURCES - ParticipantKindTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/participant/ParticipantKind.cpp - ) - -set(TEST_LIST - int_conversions - string_conversions - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddsrouter_core/test/unittest/types/participant/ParticipantIdTest.cpp b/ddsrouter_core/test/unittest/types/participant/ParticipantIdTest.cpp deleted file mode 100644 index d0a3f5789..000000000 --- a/ddsrouter_core/test/unittest/types/participant/ParticipantIdTest.cpp +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/* - * List of valid names for participants - */ -std::vector random_valid_ids() -{ - return - { - "BARRO_p", - "lan_participant", - "wan", - }; -} - -/* - * List of non valid names for participants - */ -std::vector random_non_valid_ids() -{ - return - { - "", - "__invalid_ddsrouter_participant__", - }; -} - -/**************** -* CONSTRUCTORS * -****************/ - -/** - * Test ParticipantId constructor without arguments - */ -TEST(ParticipantIdTest, default_constructor) -{ - ParticipantId pi; - ASSERT_FALSE(pi.is_valid()); -} - -/** - * Test ParticipantId constructor with arguments - */ -TEST(ParticipantIdTest, constructor) -{ - for (std::string id : random_valid_ids()) - { - ParticipantId pi(id); - ASSERT_TRUE(pi.is_valid()); - } -} - -/****************** -* STATIC METHODS * -******************/ - -/** - * Test static \c ParticipantId \c is_valid_id method - */ -TEST(ParticipantIdTest, invalid) -{ - ParticipantId pi = ParticipantId::invalid(); - ASSERT_FALSE(pi.is_valid()); -} - -/****************** -* POSITIVE CASES * -******************/ - -/** - * Test static \c ParticipantId \c is_valid_id method - */ -TEST(ParticipantIdTest, is_valid_id) -{ - for (std::string id : random_valid_ids()) - { - ASSERT_TRUE(ParticipantId::is_valid_id(id)); - } -} - -/** - * Test \c ParticipantId \c is_valid method - * - * CASES: - * by default constructor - * by \c invalid getter - * by actual invalid name - */ -TEST(ParticipantIdTest, is_valid) -{ - // By default constructor - { - ParticipantId pi; - ASSERT_FALSE(pi.is_valid()); - } - - // By invalid getter - { - ParticipantId pi = ParticipantId::invalid(); - ASSERT_FALSE(pi.is_valid()); - } - - // By actual invalid name - { - ParticipantId pi("__invalid_ddsrouter_participant__"); - ASSERT_FALSE(pi.is_valid()); - } -} - -/** - * Test \c ParticipantId \c == operator - */ -TEST(ParticipantIdTest, equal_operator) -{ - for (std::string id : random_valid_ids()) - { - ParticipantId pi1(id); - ParticipantId pi2(id); - ASSERT_TRUE(pi1 == pi2); - } -} - -/** - * Test \c ParticipantId \c < operator - */ -TEST(ParticipantIdTest, minor_operator) -{ - std::vector ids = random_valid_ids(); - - // Sort ids by string comparison - std::sort(ids.begin(), ids.end()); - - for (unsigned int i = 0; i < ids.size(); ++i) - { - // Remove equal case - for (unsigned int j = (i + 1); j < ids.size(); ++j) - { - ParticipantId pi1(ids[i]); - ParticipantId pi2(ids[j]); - ASSERT_TRUE(pi1 < pi2); - } - } -} - -/****************** -* NEGATIVE CASES * -******************/ - -/** - * Test static \c ParticipantId \c is_valid_id method in negative cases - */ -TEST(ParticipantIdTest, is_non_valid_id) -{ - for (std::string id : random_non_valid_ids()) - { - ASSERT_FALSE(ParticipantId::is_valid_id(id)); - } -} - -/** - * Test \c ParticipantId \c is_valid method in negative cases - * - * NOTE: this test is the same as the non default constructor: \c constructor - */ -TEST(ParticipantIdTest, is_non_valid) -{ - for (std::string id : random_valid_ids()) - { - ParticipantId pi(id); - ASSERT_TRUE(pi.is_valid()); - } -} - -/** - * Test \c ParticipantId \c == operator in negative cases - */ -TEST(ParticipantIdTest, non_equal_operator) -{ - std::vector ids = random_valid_ids(); - - for (unsigned int i = 0; i < ids.size(); ++i) - { - for (unsigned int j = 0; j < ids.size(); ++j) - { - // Remove equal case - if (i != j) - { - ParticipantId pi1(ids[i]); - ParticipantId pi2(ids[j]); - ASSERT_FALSE(pi1 == pi2); - } - } - } -} - -/** - * Test \c ParticipantId \c < operator in negative cases - */ -TEST(ParticipantIdTest, non_minor_operator) -{ - std::vector ids = random_valid_ids(); - - // Sort ids by string comparison - std::sort(ids.begin(), ids.end()); - - for (unsigned int i = 0; i < ids.size(); ++i) - { - // Remove equal case - for (unsigned int j = i; j < ids.size(); ++j) - { - ParticipantId pi1(ids[i]); - ParticipantId pi2(ids[j]); - ASSERT_FALSE(pi2 < pi1); - } - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddsrouter_core/test/unittest/types/participant/ParticipantKindTest.cpp b/ddsrouter_core/test/unittest/types/participant/ParticipantKindTest.cpp deleted file mode 100644 index 8d142ad42..000000000 --- a/ddsrouter_core/test/unittest/types/participant/ParticipantKindTest.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include - -// using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/* - * Test \c ParticipantKind int conversions - */ -TEST(ParticipantKindTest, int_conversions) -{ - for (auto kind : ALL_PARTICIPANT_KINDS) - { - ASSERT_EQ(ALL_PARTICIPANT_KINDS[static_cast(kind)], kind); - } -} - -/* - * Test \c ParticipantKind string conversions - */ -TEST(ParticipantKindTest, string_conversions) -{ - // Check consistency between enum value and its associated string. - ASSERT_EQ(std::string( - PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::invalid)]), - std::string("invalid")); - ASSERT_EQ(std::string( - PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::blank)]), std::string( - "blank")); - ASSERT_EQ(std::string(PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::echo)]), - std::string("echo")); - ASSERT_EQ(std::string( - PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::dummy)]), std::string( - "dummy")); - ASSERT_EQ(std::string( - PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::simple_rtps)]), - std::string("simple-rtps")); - ASSERT_EQ(std::string(PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind:: - local_discovery_server)]), std::string("local-discovery-server")); - ASSERT_EQ(std::string( - PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::wan_initial_peers)]), - std::string("wan-initial-peers")); - ASSERT_EQ(std::string( - PARTICIPANT_KIND_STRINGS[static_cast(ParticipantKind::wan_discovery_server)]), - std::string("wan-ds")); - - // Test all possible aliases for each participant kind - - // Strings mapping to ParticipantKind::invalid - ASSERT_EQ(participant_kind_from_name(""), ParticipantKind::invalid); - ASSERT_EQ(participant_kind_from_name("unexisting-kind"), ParticipantKind::invalid); - ASSERT_EQ(participant_kind_from_name("__invalid_participant_kind__"), ParticipantKind::invalid); - - // Strings mapping to ParticipantKind::blank - ASSERT_EQ(participant_kind_from_name("blank"), ParticipantKind::blank); - ASSERT_EQ(participant_kind_from_name("void"), ParticipantKind::blank); - - // Strings mapping to ParticipantKind::echo - ASSERT_EQ(participant_kind_from_name("echo"), ParticipantKind::echo); - - // Strings mapping to ParticipantKind::dummy - ASSERT_EQ(participant_kind_from_name("dummy"), ParticipantKind::dummy); - - // Strings mapping to ParticipantKind::simple_rtps - ASSERT_EQ(participant_kind_from_name("local"), ParticipantKind::simple_rtps); - ASSERT_EQ(participant_kind_from_name("simple"), ParticipantKind::simple_rtps); - - // Strings mapping to ParticipantKind::local_discovery_server - ASSERT_EQ(participant_kind_from_name("discovery-server"), ParticipantKind::local_discovery_server); - ASSERT_EQ(participant_kind_from_name("ds"), ParticipantKind::local_discovery_server); - ASSERT_EQ(participant_kind_from_name("local-ds"), ParticipantKind::local_discovery_server); - ASSERT_EQ(participant_kind_from_name("local-discovery-server"), ParticipantKind::local_discovery_server); - - // Strings mapping to ParticipantKind::wan_initial_peers - ASSERT_EQ(participant_kind_from_name("wan"), ParticipantKind::wan_initial_peers); - ASSERT_EQ(participant_kind_from_name("router"), ParticipantKind::wan_initial_peers); - - // Strings mapping to ParticipantKind::wan_discovery_server - ASSERT_EQ(participant_kind_from_name("wan-ds"), ParticipantKind::wan_discovery_server); - ASSERT_EQ(participant_kind_from_name("wan-discovery-server"), ParticipantKind::wan_discovery_server); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddsrouter_participants/CMakeLists.txt b/ddsrouter_participants/CMakeLists.txt new file mode 100644 index 000000000..644d5c7d4 --- /dev/null +++ b/ddsrouter_participants/CMakeLists.txt @@ -0,0 +1,78 @@ +# Copyright 2022 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. + +############################################################################### +# CMake build rules for DDS Router Submodule +############################################################################### +cmake_minimum_required(VERSION 3.5) + +############################################################################### +# Find package cmake_utils +############################################################################### +# Package cmake_utils is required to get every cmake macro needed +find_package(cmake_utils REQUIRED) + +############################################################################### +# Project +############################################################################### +# Configure project by info set in project_settings.cmake +# - Load project_settings variables +# - Read version +# - Set installation paths +configure_project() + +# Call explictly project +project( + ${MODULE_NAME} + VERSION + ${MODULE_VERSION} + DESCRIPTION + ${MODULE_DESCRIPTION} + LANGUAGES + CXX +) + +############################################################################### +# C++ Project +############################################################################### +# Configure CPP project for dependencies and required flags: +# - Set CMake Build Type +# - Set C++ version +# - Set shared libraries by default +# - Find external packages and thirdparties +# - Activate Code coverage if flag CODE_COVERAGE +# - Activate Address sanitizer build if flag ASAN_BUILD +# - Activate Thread sanitizer build if flag TSAN_BUILD +# - Configure log depending on LOG_INFO flag and CMake type +configure_project_cpp() + +# Compile C++ library +compile_library( + "${PROJECT_SOURCE_DIR}/src/cpp" # Source directory + "${PROJECT_SOURCE_DIR}/include" # Include directory +) + +############################################################################### +# Test +############################################################################### +# Compile tests if CMake options requires it +compile_test_library( + "${PROJECT_SOURCE_DIR}/test" # Test directory +) + +############################################################################### +# Packaging +############################################################################### +# Install package +eprosima_packaging() diff --git a/ddsrouter_participants/README.md b/ddsrouter_participants/README.md new file mode 100644 index 000000000..1b37535de --- /dev/null +++ b/ddsrouter_participants/README.md @@ -0,0 +1,5 @@ +# eProsima DDS Router Core Library + +`ddsrouter_participants` subpackage. + +> :warning: **TODO** diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.hpp b/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp similarity index 66% rename from ddsrouter_core/src/cpp/core/ParticipantFactory.hpp rename to ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp index 3bc648925..57ad744e4 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.hpp +++ b/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp @@ -19,13 +19,16 @@ #ifndef __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ #define __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ -#include +#include +#include +#include +#include -#include +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { class ParticipantFactory { @@ -42,24 +45,14 @@ class ParticipantFactory * @param [in] discovery_database : Common Discovery Database to create the Participant * @return new Participant */ - std::shared_ptr create_participant( - std::shared_ptr participant_configuration, - std::shared_ptr payload, - std::shared_ptr discovery_database); - - /** - * @brief Delete correctly a Participant - * - * When calling this method, the participant shared ptr must only be referenced here, - * so this method should be able to destroy completely the Participant - * - * @param participant : participant to be deleted - */ - void remove_participant( - std::shared_ptr participant); + static std::shared_ptr create_participant( + const ParticipantKind& kind, + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database); }; -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp b/ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp new file mode 100644 index 000000000..91486ab14 --- /dev/null +++ b/ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp @@ -0,0 +1,52 @@ +// 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 ParticipantKind.hpp + */ + +#ifndef _DDSROUTERYAML_PARTICIPANTKIND_HPP_ +#define _DDSROUTERYAML_PARTICIPANTKIND_HPP_ + +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +ENUMERATION_BUILDER( + ParticipantKind, + simple, + initial_peers, + discovery_server, + echo +); + +eProsima_ENUMERATION_BUILDER( + ParticipantKindBuilder , + ParticipantKind , + { + { ParticipantKind::simple COMMA { "local" COMMA "simple" } } COMMA + { ParticipantKind::initial_peers COMMA {"wan" COMMA "router" COMMA "initial-peers"} } COMMA + { ParticipantKind::discovery_server COMMA {"discovery-server" COMMA "ds" COMMA "local-ds" COMMA "local-discovery-server" COMMA "wan-ds" COMMA "wan-discovery-server"} } COMMA + { ParticipantKind::echo COMMA {"echo"} } + } +); + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* _DDSROUTERYAML_PARTICIPANTKIND_HPP_ */ diff --git a/ddsrouter_participants/package.xml b/ddsrouter_participants/package.xml new file mode 100644 index 000000000..f8a362cf7 --- /dev/null +++ b/ddsrouter_participants/package.xml @@ -0,0 +1,32 @@ + + + + ddsrouter_participants + 1.1.0 + + Participants for Core that perform DDS and RTPS communication. + + Raul Sánchez-Mateos + Javier París + Juan López + Apache 2.0 + + https://www.eprosima.com/ + https://github.com/eProsima/DDS-Router/issues + https://github.com/eProsima/DDS-Router + + cmake + + fastrtps + cpp_utils + ddsrouter_core + cmake_utils + + doxygen + + googletest-distribution + + + cmake + + diff --git a/ddsrouter_participants/project_settings.cmake b/ddsrouter_participants/project_settings.cmake new file mode 100644 index 000000000..8248f60b8 --- /dev/null +++ b/ddsrouter_participants/project_settings.cmake @@ -0,0 +1,35 @@ +# Copyright 2022 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. + +############################################################################### +# Set settings for project ddsrouter_participants +############################################################################### + +set(MODULE_NAME + ddsrouter_participants) + +set(MODULE_SUMMARY + "C++ library to build and run a DDS Router.") + +set(MODULE_FIND_PACKAGES + fastcdr + fastrtps + cpp_utils + ddsrouter_core) + +set(fastrtps_MINIMUM_VERSION "2.8") + +set(MODULE_DEPENDENCIES + $<$:iphlpapi$Shlwapi> + ${MODULE_FIND_PACKAGES}) diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_participants/src/cpp/ParticipantFactory.cpp similarity index 58% rename from ddsrouter_core/src/cpp/core/ParticipantFactory.cpp rename to ddsrouter_participants/src/cpp/ParticipantFactory.cpp index 3d19c6f1e..a18219768 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp +++ b/ddsrouter_participants/src/cpp/ParticipantFactory.cpp @@ -20,53 +20,42 @@ #include #include #include - -#include -#include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +#include namespace eprosima { namespace ddsrouter { -namespace core { +namespace participants { using namespace eprosima::ddsrouter::core::types; using namespace eprosima::ddsrouter::core::configuration; -std::shared_ptr ParticipantFactory::create_participant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) +std::shared_ptr ParticipantFactory::create_participant( + const ParticipantKind& kind, + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) { - // Create a new Participant depending on the ParticipantKind specified by the configuration - switch (participant_configuration->kind) + // Create a new Participant depending on the ParticipantKind specified + switch (kind) { - case ParticipantKind::blank: - // BlankParticipant - return std::make_shared(participant_configuration->id); - - case ParticipantKind::dummy: - // DummyParticipant - return std::make_shared(participant_configuration, payload_pool, discovery_database); - case ParticipantKind::echo: // Echo Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << participant_configuration->kind); + " is not for Participant Kind: " << kind); } return std::make_shared ( @@ -74,17 +63,17 @@ std::shared_ptr ParticipantFactory::create_participant( discovery_database); } - case ParticipantKind::simple_rtps: + case ParticipantKind::simple: // Simple RTPS Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << participant_configuration->kind); + " is not for Participant Kind: " << kind); } auto participant = std::make_shared ( @@ -98,19 +87,18 @@ std::shared_ptr ParticipantFactory::create_participant( return participant; } - case ParticipantKind::local_discovery_server: - case ParticipantKind::wan_discovery_server: + case ParticipantKind::discovery_server: // Discovery Server RTPS Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); // TMP: Until Transparency TopicQoS module is available if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << - participant_configuration->kind); + kind); } auto participant = std::make_shared ( @@ -124,18 +112,18 @@ std::shared_ptr ParticipantFactory::create_participant( return participant; } - case ParticipantKind::wan_initial_peers: + case ParticipantKind::initial_peers: // Initial Peers RTPS Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); // TMP: Until Transparency TopicQoS module is available if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << - participant_configuration->kind); + kind); } auto participant = std::make_shared ( @@ -149,10 +137,6 @@ std::shared_ptr ParticipantFactory::create_participant( return participant; } - case ParticipantKind::invalid: - throw utils::ConfigurationException(utils::Formatter() << "Kind: " << participant_configuration->kind - << " is not a valid participant kind name."); - default: // This should not happen as every kind must be in the switch utils::tsnh( @@ -161,13 +145,6 @@ std::shared_ptr ParticipantFactory::create_participant( } } -void ParticipantFactory::remove_participant( - std::shared_ptr participant) -{ - // Currently there are no Participants that requires specific remove functionality. - // Add it in a switch case if in the future some functionality is required. -} - -} /* namespace core */ +} /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_participants/test/CMakeLists.txt b/ddsrouter_participants/test/CMakeLists.txt new file mode 100644 index 000000000..864442e5f --- /dev/null +++ b/ddsrouter_participants/test/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2022 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. + +# TODO add tests diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp index b3007b34c..679ad0e69 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp @@ -20,6 +20,7 @@ #define _DDSROUTERYAML_YAMLREADER_HPP_ #include +#include #include #include @@ -226,6 +227,19 @@ class DDSROUTER_YAML_DllAPI YamlReader const Yaml& yml, const TagType& tag, const std::map& enum_values); + + //! TODO comment + template + static T get_enumeration_from_builder( + const Yaml& yml, + const utils::EnumBuilder& enum_builder); + + //! Get enumeration value inside \c tag + template + static T get_enumeration_from_builder( + const Yaml& yml, + const TagType& tag, + const utils::EnumBuilder& enum_builder); }; /** diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp index 61237caa7..884b80ad7 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp @@ -20,6 +20,9 @@ #define _DDSROUTERYAML_YAMLREADERCONFIGURATION_HPP_ #include +#include + +#include #include #include @@ -33,19 +36,36 @@ namespace yaml { * * TODO: Add version configuration so it could load different versions */ -class DDSROUTER_YAML_DllAPI YamlReaderConfiguration : protected YamlReader +class DDSROUTER_YAML_DllAPI Configuration { public: - static core::configuration::DDSRouterConfiguration load_ddsrouter_configuration( + Configuration(const Yaml& yml); + + Configuration(const std::string& file_path); + + core::configuration::DDSRouterConfiguration configuration; + + using ParticipantConfigurationCollection = + std::vector< + std::pair< + participants::ParticipantKind, std::shared_ptr< + participants::ParticipantConfiguration>>>; + + ParticipantConfigurationCollection participants_configurations; + +protected: + + void load_ddsrouter_configuration_( const Yaml& yml); - static core::configuration::DDSRouterConfiguration load_ddsrouter_configuration_from_file( + void load_ddsrouter_configuration_from_file_( const std::string& file_path); -protected: + void load_participant_configurations_( + const Yaml& yml, const YamlReaderVersion& version); - static YamlReaderVersion default_yaml_version(); + static YamlReaderVersion default_yaml_version_(); }; } /* namespace yaml */ diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp b/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp index bd34ae02a..965f527fc 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp @@ -204,6 +204,44 @@ T YamlReader::get_enumeration( } } +template +T YamlReader::get_enumeration_from_builder( + const Yaml& yml, + const utils::EnumBuilder& enum_builder) +{ + std::string str_value = get_scalar(yml); + T enum_value; + bool found = enum_builder.string_to_enumeration(str_value, enum_value); + + if (found) + { + return enum_value; + } + else + { + throw eprosima::utils::ConfigurationException(utils::Formatter() + << "Value <" << str_value << "> cannot be parsed as enum <" << TYPE_NAME(T) << ">."); + } +} + +template +T YamlReader::get_enumeration_from_builder( + const Yaml& yml, + const TagType& tag, + const utils::EnumBuilder& enum_builder) +{ + try + { + return get_enumeration_from_builder(get_value_in_tag(yml, tag), enum_builder); + } + catch (const std::exception& e) + { + throw eprosima::utils::ConfigurationException(utils::Formatter() + << "Error reading enumeration from builder under tag <" + << tag << "> :\n " << e.what()); + } +} + } /* namespace yaml */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_yaml/package.xml b/ddsrouter_yaml/package.xml index 789bcb468..ad457fcaf 100644 --- a/ddsrouter_yaml/package.xml +++ b/ddsrouter_yaml/package.xml @@ -21,6 +21,7 @@ fastrtps cpp_utils ddsrouter_core + ddsrouter_participants cmake_utils doxygen diff --git a/ddsrouter_yaml/project_settings.cmake b/ddsrouter_yaml/project_settings.cmake index edbf76e8d..97f758bf7 100644 --- a/ddsrouter_yaml/project_settings.cmake +++ b/ddsrouter_yaml/project_settings.cmake @@ -27,7 +27,8 @@ set(MODULE_FIND_PACKAGES fastcdr fastrtps cpp_utils - ddsrouter_core) + ddsrouter_core + ddsrouter_participants) set(ddsrouter_core_MINIMUM_VERSION "1.0") diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp index 9ee0ae9e9..4c57a1270 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader.cpp @@ -17,23 +17,26 @@ * */ -#include -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include +#include #include #include #include #include #include #include -#include +#include #include #include #include -#include -#include + +#include #include #include @@ -169,32 +172,6 @@ PortType YamlReader::get( return PortType(get_scalar(yml)); } -template <> -ParticipantId YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // Participant name required - return ParticipantId(get_scalar(yml)); -} - -template <> -ParticipantKind YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - // Participant kind required - ParticipantKind kind = participant_kind_from_name(get_scalar(yml)); - - // In version lower than 3.0 wan means wan_discovery_server - if (version <= V_2_0 && kind == ParticipantKind::wan_initial_peers) - { - kind = ParticipantKind::wan_discovery_server; - } - - return kind; -} - template <> DomainId YamlReader::get( const Yaml& yml, @@ -630,28 +607,35 @@ security::TlsConfiguration YamlReader::get( * PARTICIPANTS * ************************/ +template <> +participants::ParticipantKind YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + + // Domain id required + return get_enumeration_from_builder(yml, *participants::ParticipantKindBuilder::get_instance()); +} + ////////////////////////////////// // ParticipantConfiguration template <> void YamlReader::fill( - configuration::ParticipantConfiguration& object, + participants::ParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { // Id required object.id = get(yml, PARTICIPANT_NAME_TAG, version); - - // Kind required - object.kind = get(yml, PARTICIPANT_KIND_TAG, version); } template <> -configuration::ParticipantConfiguration YamlReader::get( +participants::ParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - configuration::ParticipantConfiguration object; - fill(object, yml, version); + participants::ParticipantConfiguration object; + fill(object, yml, version); return object; } @@ -659,12 +643,12 @@ configuration::ParticipantConfiguration YamlReader::get( // EchoParticipantConfiguration template <> void YamlReader::fill( - configuration::EchoParticipantConfiguration& object, + participants::EchoParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { // Parent class fill - fill(object, yml, version); + fill(object, yml, version); // data optional if (is_tag_present(yml, ECHO_DATA_TAG)) @@ -686,12 +670,12 @@ void YamlReader::fill( } template <> -configuration::EchoParticipantConfiguration YamlReader::get( +participants::EchoParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - configuration::EchoParticipantConfiguration object; - fill(object, yml, version); + participants::EchoParticipantConfiguration object; + fill(object, yml, version); return object; } @@ -699,12 +683,12 @@ configuration::EchoParticipantConfiguration YamlReader::get( // SimpleParticipantConfiguration template <> void YamlReader::fill( - configuration::SimpleParticipantConfiguration& object, + participants::SimpleParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { // Parent class fill - fill(object, yml, version); + fill(object, yml, version); // Domain optional if (is_tag_present(yml, DOMAIN_ID_TAG)) @@ -714,12 +698,12 @@ void YamlReader::fill( } template <> -configuration::SimpleParticipantConfiguration YamlReader::get( +participants::SimpleParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - configuration::SimpleParticipantConfiguration object; - fill(object, yml, version); + participants::SimpleParticipantConfiguration object; + fill(object, yml, version); return object; } @@ -727,12 +711,12 @@ configuration::SimpleParticipantConfiguration YamlReader::get( // DiscoveryServerParticipantConfiguration template <> void YamlReader::fill( - configuration::DiscoveryServerParticipantConfiguration& object, + participants::DiscoveryServerParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { // Parent class fill - fill(object, yml, version); + fill(object, yml, version); // Optional listening addresses if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) @@ -774,12 +758,12 @@ void YamlReader::fill( } template <> -configuration::DiscoveryServerParticipantConfiguration YamlReader::get( +participants::DiscoveryServerParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - configuration::DiscoveryServerParticipantConfiguration object; - fill(object, yml, version); + participants::DiscoveryServerParticipantConfiguration object; + fill(object, yml, version); return object; } @@ -787,12 +771,12 @@ configuration::DiscoveryServerParticipantConfiguration YamlReader::get( // InitialPeersParticipantConfiguration template <> void YamlReader::fill( - configuration::InitialPeersParticipantConfiguration& object, + participants::InitialPeersParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { // Parent class fill - fill(object, yml, version); + fill(object, yml, version); // Optional listening addresses if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) @@ -826,12 +810,12 @@ void YamlReader::fill( } template <> -configuration::InitialPeersParticipantConfiguration YamlReader::get( +participants::InitialPeersParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - configuration::InitialPeersParticipantConfiguration object; - fill(object, yml, version); + participants::InitialPeersParticipantConfiguration object; + fill(object, yml, version); return object; } @@ -862,50 +846,6 @@ void YamlReader::fill( * DDS ROUTER CONFIGURATION * ****************************/ -template <> -std::shared_ptr -YamlReader::get>( - const Yaml& yml, - const YamlReaderVersion version) -{ - // Kind required - types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); - - logInfo(DDSROUTER_YAML_CONFIGURATION, "Loading Participant of kind " << kind << "."); - - switch (kind) - { - case types::ParticipantKind::blank: - case types::ParticipantKind::dummy: - return std::make_shared( - YamlReader::get(yml, version)); - - case types::ParticipantKind::echo: - return std::make_shared( - YamlReader::get(yml, version)); - - case types::ParticipantKind::simple_rtps: - return std::make_shared( - YamlReader::get(yml, version)); - - case types::ParticipantKind::local_discovery_server: - case types::ParticipantKind::wan_discovery_server: - return std::make_shared( - YamlReader::get(yml, version)); - - case types::ParticipantKind::wan_initial_peers: - return std::make_shared( - YamlReader::get(yml, version)); - - case types::ParticipantKind::invalid: - default: - std::string invalid_kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Unkown or non valid Participant kind: " << invalid_kind << "."); - break; - } -} - void _fill_ddsrouter_configuration_v1( core::configuration::DDSRouterConfiguration& object, const Yaml& yml, @@ -991,11 +931,8 @@ void _fill_ddsrouter_configuration_v1( // Set kind from type tag participant_yml[PARTICIPANT_KIND_TAG] = participant_yml[PARTICIPANT_KIND_TAG_V1]; - // Add new Participant with its configuration - object.participants_configurations.insert( - YamlReader::get>( - participant_yml, - version)); + // Participants configurations are no longer in Router configuration + // Also old yaml versions will be deprecated, so lets not worry about this for now } } @@ -1028,25 +965,7 @@ void _fill_ddsrouter_configuration_latest( YamlReader::get_set(yml, BUILTIN_TAG, version)); } - ///// - // Get participants configurations. Required field, if get_value_in_tag fail propagate exception. - auto participants_configurations_yml = YamlReader::get_value_in_tag(yml, COLLECTION_PARTICIPANTS_TAG); - - // TODO do it in a single instruction - // Check it is a list - if (!participants_configurations_yml.IsSequence()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Participant configurations must be specified in an array under tag: " << - COLLECTION_PARTICIPANTS_TAG); - } - - for (auto conf : participants_configurations_yml) - { - object.participants_configurations.insert( - YamlReader::get>(conf, version)); - } + // Participants configurations are no longer in Router configuration ///// // Get optional specs configuration diff --git a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp index 2eb5598d8..73e979d12 100644 --- a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp @@ -17,9 +17,11 @@ * */ -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -36,22 +38,31 @@ namespace yaml { using namespace eprosima::ddsrouter::core; -core::configuration::DDSRouterConfiguration -YamlReaderConfiguration::load_ddsrouter_configuration( +Configuration::Configuration (const Yaml& yml) +{ + load_ddsrouter_configuration_(yml); +} + +Configuration::Configuration (const std::string& file_path) +{ + load_ddsrouter_configuration_from_file_(file_path); +} + +void Configuration::load_ddsrouter_configuration_( const Yaml& yml) { try { YamlReaderVersion version; // Get version if present - if (is_tag_present(yml, VERSION_TAG)) + if (YamlReader::is_tag_present(yml, VERSION_TAG)) { - version = get(yml, VERSION_TAG, LATEST); + version = YamlReader::get(yml, VERSION_TAG, LATEST); } else { // Get default version - version = default_yaml_version(); + version = default_yaml_version_(); logWarning(DDSROUTER_YAML, "No version of yaml configuration given. Using version " << version << " by default. " << "Add " << VERSION_TAG << " tag to your configuration in order to not break compatibility " << @@ -60,10 +71,13 @@ YamlReaderConfiguration::load_ddsrouter_configuration( logInfo(DDSROUTER_YAML, "Loading DDSRouter configuration with version: " << version << "."); // Load DDS Router Configuration - core::configuration::DDSRouterConfiguration router_configuration = + configuration = yaml::YamlReader::get(yml, version); - return router_configuration; + ///// + // Load Participants Configurations + load_participant_configurations_(yml, version); + } catch (const std::exception& e) { @@ -72,8 +86,7 @@ YamlReaderConfiguration::load_ddsrouter_configuration( } } -core::configuration::DDSRouterConfiguration -YamlReaderConfiguration::load_ddsrouter_configuration_from_file( +void Configuration::load_ddsrouter_configuration_from_file_( const std::string& file_path) { yaml::Yaml yml; @@ -90,10 +103,72 @@ YamlReaderConfiguration::load_ddsrouter_configuration_from_file( "> :\n " << e.what()); } - return YamlReaderConfiguration::load_ddsrouter_configuration(yml); + Configuration::load_ddsrouter_configuration_(yml); +} + +void Configuration::load_participant_configurations_( + const Yaml& yml, + const YamlReaderVersion& version) +{ + // Get participants configurations. Required field, if get_value_in_tag fail propagate exception. + auto participants_configurations_yml = YamlReader::get_value_in_tag(yml, COLLECTION_PARTICIPANTS_TAG); + + // TODO do it in a single instruction + // Check it is a list + if (!participants_configurations_yml.IsSequence()) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << + "Participant configurations must be specified in an array under tag: " << + COLLECTION_PARTICIPANTS_TAG); + } + + for (auto conf : participants_configurations_yml) + { + // Get kind + participants::ParticipantKind kind = YamlReader::get(conf, PARTICIPANT_KIND_TAG, version); + + // Get Participant + std::shared_ptr configuration; + + logInfo(DDSROUTER_YAML_CONFIGURATION, "Loading Participant of kind " << kind << "."); + + switch (kind) + { + case participants::ParticipantKind::echo: + configuration = + std::make_shared( + YamlReader::get(conf, version)); + break; + + case participants::ParticipantKind::simple: + configuration = + std::make_shared( + YamlReader::get(conf, version)); + break; + + case participants::ParticipantKind::discovery_server: + configuration = + std::make_shared( + YamlReader::get(conf, version)); + break; + + case participants::ParticipantKind::initial_peers: + configuration = + std::make_shared( + YamlReader::get(conf, version)); + break; + + // No default possible + } + + participants_configurations.emplace_back( + kind, + std::move(configuration)); + } } -YamlReaderVersion YamlReaderConfiguration::default_yaml_version() +YamlReaderVersion Configuration::default_yaml_version_() { return V_1_0; } diff --git a/ddsrouter_yaml/test/TestUtils/test_utils.hpp b/ddsrouter_yaml/test/TestUtils/test_utils.hpp index cd8b03dcf..388c25039 100644 --- a/ddsrouter_yaml/test/TestUtils/test_utils.hpp +++ b/ddsrouter_yaml/test/TestUtils/test_utils.hpp @@ -19,11 +19,11 @@ #ifndef _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ #define _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include diff --git a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp b/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp index 4f5eeeaa5..238f99a79 100644 --- a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp +++ b/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp @@ -24,7 +24,7 @@ #include #include #include -#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index 6708c57d7..8340b85cb 100644 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index 4bf4e529c..e21f3b7f8 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -16,7 +16,7 @@ #include #include -#include + #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp index c57f50485..c5273228e 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index f5f40e897..a8bc533be 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -16,7 +16,7 @@ #include #include -#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index fa640c438..67e4bb415 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -16,7 +16,7 @@ #include #include -#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index 33375180d..c517796fe 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -16,7 +16,7 @@ #include #include -#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index 73947f7f6..6af356853 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -16,7 +16,7 @@ #include #include -#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index e074b3c34..a107a703d 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -16,7 +16,7 @@ #include #include -#include + #include #include #include diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp index 3e978de5c..6b75dfe5a 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp @@ -16,7 +16,7 @@ #include #include -#include + #include #include #include diff --git a/tools/ddsrouter_tool/package.xml b/tools/ddsrouter_tool/package.xml index 5e26919ee..e8025be79 100644 --- a/tools/ddsrouter_tool/package.xml +++ b/tools/ddsrouter_tool/package.xml @@ -22,6 +22,7 @@ cpp_utils ddsrouter_core + ddsrouter_participants ddsrouter_yaml doxygen diff --git a/tools/ddsrouter_tool/project_settings.cmake b/tools/ddsrouter_tool/project_settings.cmake index 0556d1528..0ee69d4ee 100644 --- a/tools/ddsrouter_tool/project_settings.cmake +++ b/tools/ddsrouter_tool/project_settings.cmake @@ -29,6 +29,7 @@ set(MODULE_FIND_PACKAGES cpp_utils ddsrouter_core ddsrouter_yaml + ddsrouter_participants ) set(MODULE_DEPENDENCIES @@ -50,4 +51,4 @@ set(MODULE_VERSION_FILE_PATH "../../VERSION") set(MODULE_TARGET_NAME - "ddsrouter") \ No newline at end of file + "ddsrouter") diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index a1f3b766e..205a5308c 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -17,8 +17,6 @@ * */ -#include -#include #include #include #include @@ -29,6 +27,14 @@ #include #include #include + +#include +#include +#include +#include + +#include + #include #include @@ -141,12 +147,43 @@ int main( ///// // DDS Router Initialization - // Load DDS Router Configuration - core::configuration::DDSRouterConfiguration router_configuration = - yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(file_path); + // Load Configuration from YAML + yaml::Configuration configuration(file_path); + core::configuration::DDSRouterConfiguration router_configuration = configuration.configuration; + + // Create Payload Pool + std::shared_ptr payload_pool = + std::make_shared(); + + // Create Discovery Database + std::shared_ptr discovery_database = + std::make_shared(); + + // Create and populate Participant Database + std::shared_ptr participant_database = + std::make_shared(); + + // Populate Participant Database + for (const auto& part_conf : configuration.participants_configurations) + { + participant_database->add_participant( + part_conf.second->id, + participants::ParticipantFactory::create_participant( + part_conf.first, + part_conf.second, + payload_pool, + discovery_database + ) + ); + } // Create DDS Router - core::DDSRouter router(router_configuration); + core::DDSRouter router( + router_configuration, + discovery_database, + payload_pool, + participant_database + ); ///// // File Watcher Handler @@ -163,9 +200,8 @@ int main( try { - core::configuration::DDSRouterConfiguration router_configuration = - yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(file_path); - router.reload_configuration(router_configuration); + yaml::Configuration new_configuration(file_path); + router.reload_configuration(new_configuration.configuration); } catch (const std::exception& e) { @@ -198,9 +234,8 @@ int main( try { - core::configuration::DDSRouterConfiguration router_configuration = - yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(file_path); - router.reload_configuration(router_configuration); + yaml::Configuration new_configuration(file_path); + router.reload_configuration(new_configuration.configuration); } catch (const std::exception& e) { From a00a9d939e5e1b3f1bd933d6647cc7e94167eee1 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 3 Feb 2023 08:59:59 +0100 Subject: [PATCH 02/38] TMP first data received refactor Signed-off-by: jparisu --- .../IParticipant.hpp | 2 - .../{reader => interfaces}/IReader.hpp | 4 +- .../{writer => interfaces}/IWriter.hpp | 4 +- .../participants/data/DataProperties.hpp | 96 +++++++++++++++++++ .../participants/data/Payload.hpp | 69 +++++++++++++ .../participants/data/RpcPayloadData.hpp | 58 +++++++++++ .../participants/data/RtpsPayloadData.hpp | 71 ++++++++++++++ .../participant/auxiliar/BlankParticipant.hpp | 2 - .../participant/rtps/CommonParticipant.hpp | 2 - .../writer/rtps/filter/RepeaterDataFilter.cpp | 61 ------------ .../writer/rtps/filter/SelfDataFilter.cpp | 42 -------- .../types/data/IRoutingData.hpp | 50 ++++++++++ .../include/ddsrouter_core/types/dds/Data.hpp | 87 ----------------- ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp | 11 --- ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp | 5 - .../participant/auxiliar/BlankParticipant.cpp | 5 - .../participant/rtps/CommonParticipant.cpp | 5 - 17 files changed, 348 insertions(+), 226 deletions(-) rename ddsrouter_core/include/ddsrouter_core/{participant => interfaces}/IParticipant.hpp (99%) rename ddsrouter_core/include/ddsrouter_core/{reader => interfaces}/IReader.hpp (97%) rename ddsrouter_core/include/ddsrouter_core/{writer => interfaces}/IWriter.hpp (96%) create mode 100644 ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp create mode 100644 ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp create mode 100644 ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp create mode 100644 ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp create mode 100644 ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/dds/Data.hpp diff --git a/ddsrouter_core/include/ddsrouter_core/participant/IParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/interfaces/IParticipant.hpp similarity index 99% rename from ddsrouter_core/include/ddsrouter_core/participant/IParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/interfaces/IParticipant.hpp index e92d96e65..3acc21907 100644 --- a/ddsrouter_core/include/ddsrouter_core/participant/IParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/interfaces/IParticipant.hpp @@ -52,8 +52,6 @@ class IParticipant */ virtual types::ParticipantId id() const noexcept = 0; - virtual void start() = 0; - //! Whether this participant is RTPS virtual bool is_rtps_kind() const noexcept = 0; diff --git a/ddsrouter_core/include/ddsrouter_core/reader/IReader.hpp b/ddsrouter_core/include/ddsrouter_core/interfaces/IReader.hpp similarity index 97% rename from ddsrouter_core/include/ddsrouter_core/reader/IReader.hpp rename to ddsrouter_core/include/ddsrouter_core/interfaces/IReader.hpp index b7b7d2b8b..7783cad52 100644 --- a/ddsrouter_core/include/ddsrouter_core/reader/IReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/interfaces/IReader.hpp @@ -23,7 +23,7 @@ #include -#include +#include #include #include @@ -100,7 +100,7 @@ class IReader * @return \c RETCODE_NOT_ENABLED if the reader is not enabled (this should not happen) */ virtual utils::ReturnCode take( - std::unique_ptr& data) noexcept = 0; + IRoutingData*& data) noexcept = 0; }; } /* namespace core */ diff --git a/ddsrouter_core/include/ddsrouter_core/writer/IWriter.hpp b/ddsrouter_core/include/ddsrouter_core/interfaces/IWriter.hpp similarity index 96% rename from ddsrouter_core/include/ddsrouter_core/writer/IWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/interfaces/IWriter.hpp index 6f28de43e..e18d746d8 100644 --- a/ddsrouter_core/include/ddsrouter_core/writer/IWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/interfaces/IWriter.hpp @@ -21,7 +21,7 @@ #include -#include +#include #include #include @@ -80,7 +80,7 @@ class IWriter * @return \c RETCODE_NOT_ENABLED if the writer is not enabled (this should not happen) */ virtual utils::ReturnCode write( - std::unique_ptr& data) noexcept = 0; + IRoutingData* data) noexcept = 0; }; } /* namespace core */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp b/ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp new file mode 100644 index 000000000..97d81feb7 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp @@ -0,0 +1,96 @@ +// Copyright 2022 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 DataProperties.hpp + */ + +#ifndef _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ +#define _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ + +#include + +#include +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace types { + +struct DDSROUTER_CORE_DllAPI RtpsDataProperties +{ + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + //! Default DataProperties with reader less restrictive parameters + DataProperties() = default; + + ///////////////////////// + // OPERATORS + ///////////////////////// + + //! Minor comparison operator + bool operator < ( + const DataProperties& other) const noexcept; + + //! Equality operator + bool operator == ( + const DataProperties& other) const noexcept; + + ///////////////////////// + // VARIABLES + ///////////////////////// + + //! Specific Writer QoS of the Data + SpecificEndpointQoS writer_qos{}; + + //! Instance of the message (default no instance) + InstanceHandle instanceHandle{}; + + //! Kind of the change + ChangeKind kind{}; + + //! Source time stamp of the message + DataTime source_timestamp{}; + + //! Guid of the source entity that has transmit the data + Guid source_guid{}; + + //! Id of the participant from which the Reader has received the data. + ParticipantId participant_receiver{}; + + //! Write params associated to the received cache change + utils::Fuzzy write_params{}; + + //! Sequence number of the received cache change + eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; +}; + +/** + * @brief \c DataProperties to stream serialization + */ +DDSROUTER_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const DataProperties& qos); + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp b/ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp new file mode 100644 index 000000000..3fdf920d6 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp @@ -0,0 +1,69 @@ +// 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 Payload.hpp + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +//! Durability kind enumeration +using PartitionQosPolicy = eprosima::fastdds::dds::PartitionQosPolicy; + +//! Partition configuration +using OwnershipStrengthQosPolicy = eprosima::fastdds::dds::OwnershipStrengthQosPolicy; + +//! Instance Handler type +using InstanceHandle = eprosima::fastrtps::rtps::InstanceHandle_t; + +//! Instance Handler type +using ChangeKind = eprosima::fastrtps::rtps::ChangeKind_t; + +//! Fast DDS Time +using DataTime = eprosima::fastrtps::rtps::Time_t; + +//! Kind of every unit that creates a Payload +using PayloadUnit = eprosima::fastrtps::rtps::octet; + +//! Payload references the raw data received. +using Payload = eprosima::fastrtps::rtps::SerializedPayload_t; + +//! \c octet to stream serializator +DDSROUTER_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const PayloadUnit& octet); + +//! \c SerializedPayload_t to stream serializator +DDSROUTER_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const Payload& payload); + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp b/ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp new file mode 100644 index 000000000..1905149f3 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp @@ -0,0 +1,58 @@ +// Copyright 2021 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 RpcPayloadData.hpp + */ + +#pragma once + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +/** + * @brief Structure of the Data received from a Reader containing the data itself and its properties. + * + * Properties are related information regarding the data and QoS of the source. + */ +struct RpcPayloadData : public RtpsPayloadData +{ + //! Write params associated to the received cache change + utils::Fuzzy write_params{}; + + //! Sequence number of the received cache change + eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; +}; + +//! \c octet to stream serializator +DDSROUTER_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const RpcPayloadData& octet); + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp b/ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp new file mode 100644 index 000000000..0466a0883 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp @@ -0,0 +1,71 @@ +// Copyright 2021 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 RtpsPayloadData.hpp + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +/** + * @brief Structure of the Data received from a Reader containing the data itself and its properties. + * + * Properties are related information regarding the data and QoS of the source. + */ +struct RtpsPayloadData : public core::types::IRoutingData +{ + //! Payload of the data received. The data in this payload must belong to the PayloadPool. + Payload payload{}; + + //! Specific Writer QoS of the Data + core::types::SpecificEndpointQoS writer_qos{}; + + //! Instance of the message (default no instance) + InstanceHandle instanceHandle{}; + + //! Kind of the change + ChangeKind kind{}; + + //! Source time stamp of the message + DataTime source_timestamp{}; + + //! Guid of the source entity that has transmit the data + core::types::Guid source_guid{}; + + //! Id of the participant from which the Reader has received the data. + core::types::ParticipantId participant_receiver{}; +}; + +//! \c octet to stream serializator +DDSROUTER_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const RtpsPayloadData& octet); + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp index 9ea7f0364..fe6d6cb79 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp @@ -66,8 +66,6 @@ class BlankParticipant : public core::IParticipant void delete_reader( std::shared_ptr reader) noexcept override; - virtual void start() override; - protected: //! Participant Id diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp index 23d6dac50..419be1da7 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp @@ -107,8 +107,6 @@ class CommonParticipant virtual bool is_rtps_kind() const noexcept override; - virtual void start() override; - protected: /** diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp deleted file mode 100644 index 5fa39e0c3..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022 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 RepeaterDataFilter.cpp - */ - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { -namespace rtps { - -bool RepeaterDataFilter::is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid) const -{ - if (!SelfDataFilter::is_relevant(change, reader_guid)) - { - logDebug( - REPEATER_DATA_FILTER, - "Ignoring message by SelfDataFilter is_relevant result."); - - // If origin filter does not pass this change, it is discarded - return false; - } - - // As ChangePool is our own, and we use RouterCacheChange, we can cast this without problem - const auto& change_ref = static_cast(change); - - bool is_relevant = change_ref.last_writer_guid_prefix != reader_guid.guidPrefix; - - logDebug( - REPEATER_DATA_FILTER, - "Evaluating whether Change with origin writer GUID prefix " << change_ref.last_writer_guid_prefix << - " is relevant for reader GUID " << reader_guid << "? " << (is_relevant ? "TRUE" : "FALSE")); - - return is_relevant; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp deleted file mode 100644 index b66686a40..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2022 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 SelfDataFilter.cpp - */ - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { -namespace rtps { - -bool SelfDataFilter::is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid) const -{ - // It is relevant only if the reader does not belong to same participant as writer - return change.writerGUID.guidPrefix != reader_guid.guidPrefix; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp new file mode 100644 index 000000000..210855b56 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp @@ -0,0 +1,50 @@ +// Copyright 2021 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 IRoutingData.hpp + */ + +#ifndef _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ +#define _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { + +/** + * @brief TODO + */ +class IRoutingData +{ + +public: + + /** + * @brief Virtual dtor. + * + * @note Default destructor. Force \c DataReceived to be polymorphic. Implemented here to avoid creating a .cpp . + */ + virtual ~IRoutingData() + { + } +}; + +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/Data.hpp b/ddsrouter_core/include/ddsrouter_core/types/dds/Data.hpp deleted file mode 100644 index c320c0cb9..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/Data.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2021 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 Data.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -//! Kind of every unit that creates a Payload -using PayloadUnit = eprosima::fastrtps::rtps::octet; - -//! Payload references the raw data received. -using Payload = eprosima::fastrtps::rtps::SerializedPayload_t; - -/** - * @brief Structure of the Data received from a Reader containing the data itself and its properties. - * - * Properties are related information regarding the data and QoS of the source. - */ -struct DataReceived -{ - /** - * @brief Destroy the Data Received object - * - * @note Default destructor. Force \c DataReceived to be polymorphic. Implemented here to avoid creating a .cpp . - */ - virtual ~DataReceived() - { - } - - //! Payload of the data received. The data in this payload must belong to the PayloadPool. - Payload payload; - - //! Specific QoS and attributes of the data received - DataProperties properties; - - /** - * @brief Sequence Number with which the internal writer (ddsrouter writer) has sent this message - * - * @warning This is not the sequence number of the data received. It is the one set by writer when sending it. - * - * @todo This could be removed in the future if ServiceRegistry is internal to a specific class and not in - * RPCBridge. - */ - eprosima::fastrtps::rtps::SequenceNumber_t sent_sequence_number; -}; - -//! \c octet to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const PayloadUnit& octet); - -//! \c SerializedPayload_t to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const Payload& payload); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ */ diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp index 3d0976e91..b699084f9 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp @@ -74,8 +74,6 @@ DDSRouterImpl::DDSRouterImpl( // Init topic allowed init_allowed_topics_(); - // Load Participants - init_participants_(); // Create Bridges for builtin topics init_bridges_(); @@ -83,7 +81,6 @@ DDSRouterImpl::DDSRouterImpl( // The entities should not be added to the Discovery Database until the builtin topics have been created. // This is due to the fact that the Participants endpoints start discovering topics with different configuration // than the one specified in the yaml configuration file. - // TODO (custompart): this does not do anything, check discovery_database_->start(); @@ -304,14 +301,6 @@ void DDSRouterImpl::init_allowed_topics_() logInfo(DDSROUTER, "DDS Router configured with allowed topics: " << allowed_topics_); } -void DDSRouterImpl::init_participants_() -{ - for (auto& participant : participants_database_->get_participants_map()) - { - participant.second->start(); - } -} - void DDSRouterImpl::init_bridges_() { for (std::shared_ptr topic : configuration_.builtin_topics) diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp index faf5755d3..63dbe0140 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp @@ -150,11 +150,6 @@ class DDSRouterImpl */ void init_allowed_topics_(); - /** - * @brief Enable participants - */ - void init_participants_(); - /** * @brief Create a disabled bridge for every real topic */ diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp index 42c28a03d..ca500821c 100644 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp @@ -69,11 +69,6 @@ void BlankParticipant::delete_reader( { } -void BlankParticipant::start() -{ - // Do nothing -} - } /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp index a4f832bb1..aeba5ea5e 100644 --- a/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp @@ -267,11 +267,6 @@ bool CommonParticipant::is_rtps_kind() const noexcept return true; } -void CommonParticipant::start() -{ - // TODO -} - void CommonParticipant::create_participant_( const core::types::DomainId& domain, const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes) From 5d6e4e9891125f016e4a3fbf5f9d3f4274786718 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 3 Feb 2023 13:50:39 +0100 Subject: [PATCH 03/38] Add implementation to data received Signed-off-by: jparisu --- .../core/ParticipantsDatabase.hpp | 2 +- .../efficiency/payload/PayloadPool.hpp | 2 +- .../IParticipant.hpp | 5 +- .../{interfaces => interface}/IReader.hpp | 2 +- .../{interfaces => interface}/IWriter.hpp | 2 +- .../participants/data/DataProperties.hpp | 96 ----------- .../participant/auxiliar/BaseParticipant.hpp | 2 +- .../participant/auxiliar/BlankParticipant.hpp | 2 +- .../participant/auxiliar/DummyParticipant.hpp | 150 ------------------ .../participant/auxiliar/MockParticipant.hpp | 75 +++++++++ .../reader/auxiliar/BaseReader.hpp | 12 +- .../reader/auxiliar/BlankReader.hpp | 4 +- .../{DummyReader.hpp => MockReader.hpp} | 39 ++--- .../participants/reader/rtps/CommonReader.hpp | 15 +- .../reader/rtps/SpecificQoSReader.hpp | 6 +- .../writer/auxiliar/BaseWriter.hpp | 6 +- .../writer/auxiliar/BlankWriter.hpp | 4 +- .../writer/auxiliar/EchoWriter.hpp | 2 +- .../{DummyWriter.hpp => MockWriter.hpp} | 50 ++---- .../participants/writer/rtps/CommonWriter.hpp | 9 +- .../participants/writer/rtps/MultiWriter.hpp | 2 +- .../types/data/IRoutingData.hpp | 7 +- .../{participants => types}/data/Payload.hpp | 6 +- .../data/RpcPayloadData.hpp | 8 +- .../data/RtpsPayloadData.hpp | 16 +- .../types/dds/DataProperties.hpp | 122 -------------- .../src/cpp/communication/Track.cpp | 14 +- .../src/cpp/communication/Track.hpp | 6 +- .../src/cpp/communication/rpc/RPCBridge.cpp | 38 ++--- .../src/cpp/communication/rpc/RPCBridge.hpp | 2 +- ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp | 2 +- .../reader/auxiliar/BaseReader.cpp | 12 +- .../reader/auxiliar/BlankReader.cpp | 2 +- .../reader/auxiliar/DummyReader.cpp | 2 +- .../participants/reader/rtps/CommonReader.cpp | 30 ++-- .../reader/rtps/SpecificQoSReader.cpp | 8 +- .../writer/auxiliar/BaseWriter.cpp | 2 +- .../writer/auxiliar/BlankWriter.cpp | 2 +- .../writer/auxiliar/EchoWriter.cpp | 14 +- .../participants/writer/rtps/CommonWriter.cpp | 31 ++-- .../participants/writer/rtps/MultiWriter.cpp | 2 +- .../types/{dds/Data.cpp => data/Payload.cpp} | 4 +- .../src/cpp/types/data/RtpsPayloadData.cpp | 37 +++++ .../src/cpp/types/dds/DataProperties.cpp | 68 -------- .../core/participants_database/CMakeLists.txt | 6 +- .../test/unittest/efficiency/CMakeLists.txt | 11 +- .../unittest/efficiency/PayloadPoolTest.cpp | 5 +- .../unittest/types/endpoint/CMakeLists.txt | 2 +- .../ParticipantFactory.hpp | 2 +- ddsrouter_yaml/src/cpp/YamlReader.cpp | 2 +- 50 files changed, 310 insertions(+), 640 deletions(-) rename ddsrouter_core/include/ddsrouter_core/{interfaces => interface}/IParticipant.hpp (97%) rename ddsrouter_core/include/ddsrouter_core/{interfaces => interface}/IReader.hpp (98%) rename ddsrouter_core/include/ddsrouter_core/{interfaces => interface}/IWriter.hpp (98%) delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp create mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp rename ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/{DummyReader.hpp => MockReader.hpp} (56%) rename ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/{DummyWriter.hpp => MockWriter.hpp} (54%) rename ddsrouter_core/include/ddsrouter_core/{participants => types}/data/Payload.hpp (96%) rename ddsrouter_core/include/ddsrouter_core/{participants => types}/data/RpcPayloadData.hpp (92%) rename ddsrouter_core/include/ddsrouter_core/{participants => types}/data/RtpsPayloadData.hpp (86%) delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/dds/DataProperties.hpp rename ddsrouter_core/src/cpp/types/{dds/Data.cpp => data/Payload.cpp} (95%) create mode 100644 ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp delete mode 100644 ddsrouter_core/src/cpp/types/dds/DataProperties.cpp diff --git a/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp b/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp index c7c9d3d77..ff6264620 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include namespace eprosima { diff --git a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp index e7744c325..695d823d5 100644 --- a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp +++ b/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/include/ddsrouter_core/interfaces/IParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/interface/IParticipant.hpp similarity index 97% rename from ddsrouter_core/include/ddsrouter_core/interfaces/IParticipant.hpp rename to ddsrouter_core/include/ddsrouter_core/interface/IParticipant.hpp index 3acc21907..bcc0eb239 100644 --- a/ddsrouter_core/include/ddsrouter_core/interfaces/IParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/interface/IParticipant.hpp @@ -22,10 +22,9 @@ #include #include - #include -#include -#include +#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/include/ddsrouter_core/interfaces/IReader.hpp b/ddsrouter_core/include/ddsrouter_core/interface/IReader.hpp similarity index 98% rename from ddsrouter_core/include/ddsrouter_core/interfaces/IReader.hpp rename to ddsrouter_core/include/ddsrouter_core/interface/IReader.hpp index 7783cad52..ee2b50326 100644 --- a/ddsrouter_core/include/ddsrouter_core/interfaces/IReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/interface/IReader.hpp @@ -100,7 +100,7 @@ class IReader * @return \c RETCODE_NOT_ENABLED if the reader is not enabled (this should not happen) */ virtual utils::ReturnCode take( - IRoutingData*& data) noexcept = 0; + std::unique_ptr& data) noexcept = 0; }; } /* namespace core */ diff --git a/ddsrouter_core/include/ddsrouter_core/interfaces/IWriter.hpp b/ddsrouter_core/include/ddsrouter_core/interface/IWriter.hpp similarity index 98% rename from ddsrouter_core/include/ddsrouter_core/interfaces/IWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/interface/IWriter.hpp index e18d746d8..f012c7337 100644 --- a/ddsrouter_core/include/ddsrouter_core/interfaces/IWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/interface/IWriter.hpp @@ -80,7 +80,7 @@ class IWriter * @return \c RETCODE_NOT_ENABLED if the writer is not enabled (this should not happen) */ virtual utils::ReturnCode write( - IRoutingData* data) noexcept = 0; + types::IRoutingData& data) noexcept = 0; }; } /* namespace core */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp b/ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp deleted file mode 100644 index 97d81feb7..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/data/DataProperties.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2022 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 DataProperties.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ -#define _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ - -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -struct DDSROUTER_CORE_DllAPI RtpsDataProperties -{ - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default DataProperties with reader less restrictive parameters - DataProperties() = default; - - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Minor comparison operator - bool operator < ( - const DataProperties& other) const noexcept; - - //! Equality operator - bool operator == ( - const DataProperties& other) const noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Specific Writer QoS of the Data - SpecificEndpointQoS writer_qos{}; - - //! Instance of the message (default no instance) - InstanceHandle instanceHandle{}; - - //! Kind of the change - ChangeKind kind{}; - - //! Source time stamp of the message - DataTime source_timestamp{}; - - //! Guid of the source entity that has transmit the data - Guid source_guid{}; - - //! Id of the participant from which the Reader has received the data. - ParticipantId participant_receiver{}; - - //! Write params associated to the received cache change - utils::Fuzzy write_params{}; - - //! Sequence number of the received cache change - eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; -}; - -/** - * @brief \c DataProperties to stream serialization - */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const DataProperties& qos); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp index cbec4c9b9..09fdab0bc 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp @@ -23,7 +23,7 @@ #include -#include +#include #include #include diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp index fe6d6cb79..753f5c4d6 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp @@ -20,7 +20,7 @@ #define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BLANKPARTICIPANT_HPP_ #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp deleted file mode 100644 index 16c676312..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/DummyParticipant.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2021 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 DummyParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_DUMMYPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_DUMMYPARTICIPANT_HPP_ - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -/** - * Concrete Participant that allows to simulate a real remote network. - * - * This Participant includes methods that allow to simulate the reception of a message - * and to get the messages that should have been sent. - * For this, a static map is created so it can store all the DummyParticipants created and have access to their methods. - * - * This Participant is used for Testing, as it could mock a DDS real network. - */ -class DummyParticipant : public BaseParticipant -{ -public: - - /** - * @brief Construct a new Dummy Participant object - * - * It uses the \c BaseParticipant constructor. - * Apart from BaseParticipant, it adds this new object to a static variable so it could be reached from outside - * the DDSRouter. - */ - DummyParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); - - /** - * @brief Destroy the Dummy Participant object - * - * Remove its reference from the static map - */ - virtual ~DummyParticipant(); - - /** - * @brief Simulate that this Participant has discovered a new endpoint - * - * @param new_endpoint : Endpoint discovered - */ - void simulate_discovered_endpoint( - const core::types::Endpoint& new_endpoint); - - /** - * @brief Get the discovered endpoint object referring to \c guid - * - * Search this guid in the endpoints in the Discovery Database - * - * @param guid : \c Guid of the Endpoint to look for - * @return Endpoint with this guid - */ - core::types::Endpoint get_discovered_endpoint( - const core::types::Guid& guid) const; - - /** - * @brief Simulate that the reader of the topic has received a message - * - * @param topic : Topic that refers to the Reader that should forward this data. - * @param data : data received - */ - void simulate_data_reception( - core::types::DdsTopic topic, - DummyDataReceived data); - - /** - * @brief Get the data that has arrived to this Writer in order to send it. - * - * @param topic : Topic that refers to the Writer that should have sent this data. - * @return Vector of all the data that the Writer should have sent. - */ - std::vector get_data_that_should_have_been_sent( - core::types::DdsTopic topic); - - /** - * @brief Make the thread wait until message \c n has arrived to Writer in topic \c topic - * - * @param topic : Topic that refers to the Writer that should have sent this data. - * @param [in] n : wait until data \c n has arrived and simulated to be sent - */ - void wait_until_n_data_sent( - core::types::DdsTopic topic, - uint16_t n) const noexcept; - - /** - * @brief Get a DummyParticipant by ID - * - * By this reference, the internal writers and readers of the Participant could be accessed in order to simulate - * the reception of data, and to get the data that must be sent. - * Use methods \c simulate_data_reception and \c get_data_that_should_have_been_sent for this purpose. - * - * @param id : Id of the participant - * - * @return raw pointer to the participant - * @warning Do not remove this ptr - */ - static DummyParticipant* get_participant( - core::types::ParticipantId id); - -protected: - - //! Override create_writer_() BaseParticipant method - std::shared_ptr create_writer_( - core::types::DdsTopic topic) override; - - //! Override create_reader_() BaseParticipant method - std::shared_ptr create_reader_( - core::types::DdsTopic topic) override; - - // Specific enable/disable do not need to be implemented - - //! Mutex to guard the static map \c participants_ - static std::mutex static_mutex_; - - //! Static map that stores every DummyParticipant running - static std::map participants_; -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_DUMMYPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp new file mode 100644 index 000000000..54e811a45 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp @@ -0,0 +1,75 @@ +// 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 MockParticipant.hpp + */ + +#pragma once + +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +/** + * TODO + */ +class MockParticipant : public BaseParticipant +{ +public: + + /** + * TODO + */ + MockParticipant( + std::shared_ptr participant_configuration, + std::shared_ptr discovery_database); + + /** + * @brief Destroy the Mock Participant object + */ + virtual ~MockParticipant(); + + /** + * @brief Simulate that this Participant has discovered a new endpoint + * + * @param new_endpoint : Endpoint discovered + */ + void simulate_discovered_endpoint( + const core::types::Endpoint& new_endpoint); + + std::shared_ptr get_reader( + core::types::DdsTopic topic); + + std::vector get_writer( + core::types::DdsTopic topic); + +protected: + + //! Override create_writer_() BaseParticipant method + std::shared_ptr create_writer_( + core::types::DdsTopic topic) override; + + //! Override create_reader_() BaseParticipant method + std::shared_ptr create_reader_( + core::types::DdsTopic topic) override; +}; + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp index ac0ceea82..a706aad86 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include namespace eprosima { @@ -110,7 +110,7 @@ class BaseReader : public core::IReader * Thread safe with mutex \c mutex_ . */ utils::ReturnCode take( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; //! Getter of \c participant_id_ attribute core::types::ParticipantId participant_id() const noexcept; @@ -134,22 +134,22 @@ class BaseReader : public core::IReader * * Implement this method class for a specific enable functionality. */ - virtual void enable_() noexcept; + virtual void enable_nts_() noexcept; /** * @brief Do nothing * * Implement this method class for a specific disable functionality. */ - virtual void disable_() noexcept; + virtual void disable_nts_() noexcept; /** * @brief Take method to implement by each Reader implementation * * Implement this method in every inherited Reader class with take functionality. */ - virtual utils::ReturnCode take_( - std::unique_ptr& data) noexcept = 0; + virtual utils::ReturnCode take_nts_( + std::unique_ptr& data) noexcept = 0; //! Participant parent ID core::types::ParticipantId participant_id_; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp index 26a9cee07..93df4d414 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp @@ -19,7 +19,7 @@ #ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ #define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { @@ -49,7 +49,7 @@ class BlankReader : public core::IReader //! Override take() IReader method utils::ReturnCode take( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; }; } /* namespace participants */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/DummyReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp similarity index 56% rename from ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/DummyReader.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp index f28c723bb..056758bd8 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/DummyReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp @@ -1,4 +1,4 @@ -// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// 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. @@ -13,38 +13,26 @@ // limitations under the License. /** - * @file DummyReader.hpp + * @file MockReader.hpp */ -#ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_DUMMYREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_DUMMYREADER_HPP_ +#pragma once -#include -#include #include #include -#include - namespace eprosima { namespace ddsrouter { namespace participants { -//! Data that has been sent to a Dummy Reader in order to simulate data reception -struct DummyDataReceived +class MockReader { - //! Payload in a format of vector of bytes - std::vector payload; - - //! Guid of the source entity that has transmitted the data - core::types::Guid source_guid; + virtual ~MockReader(); }; -/** - * Reader implementation that allows to simulate data reception - */ -class DummyReader : public BaseReader +template +class MockReaderSpecialization : public BaseReader { public: @@ -57,7 +45,7 @@ class DummyReader : public BaseReader * @param data : The data received (by simulation) */ void simulate_data_reception( - DummyDataReceived data) noexcept; + T data) noexcept; protected: @@ -70,18 +58,15 @@ class DummyReader : public BaseReader * @return \c RETCODE_OK if data has been correctly taken * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty */ - utils::ReturnCode take_( - std::unique_ptr& data) noexcept override; + virtual utils::ReturnCode take_( + std::unique_ptr& data) noexcept override = 0; //! Stores the data that must be retrieved with \c take() method - std::queue data_to_send_; + std::queue data_to_send_; - //! Guard access to \c data_to_send_ - mutable std::recursive_mutex dummy_mutex_; + mutable std::mutex mutex_; }; } /* namespace participants */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_DUMMYREADER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp index 555f9af7b..be0325af2 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp @@ -35,6 +35,7 @@ #include #include +#include namespace eprosima { namespace ddsrouter { @@ -144,12 +145,20 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener const fastrtps::TopicAttributes& topic_attributes, const fastrtps::ReaderQos& reader_qos); + /** + * @brief Return an allocated object + * + * @attention this method allocates memory. + */ + virtual core::types::RtpsPayloadData* create_data_( + const fastrtps::rtps::CacheChange_t& received_change) const noexcept; + /** * @brief Auxiliary method used in \c take to fill the received data. */ virtual void fill_received_data_( - fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept; + const fastrtps::rtps::CacheChange_t& received_change + core::types::RtpsPayloadData& data_to_fill) const noexcept; // Specific enable/disable do not need to be implemented @@ -176,7 +185,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @return \c RETCODE_ERROR if there has been an error reading the data or the data read is corrupted */ virtual utils::ReturnCode take_( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; ///// // RTPS specific methods diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp index 8e000570e..81644d963 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp @@ -67,9 +67,9 @@ class SpecificQoSReader : public CommonReader /** * Specializes \c CommonReader method and set the QoS of the data received. */ - virtual void fill_received_data_( - fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept override; + virtual IRoutingData* fill_received_data_( + fastrtps::rtps::CacheChange_t* received_change) const noexcept; + //! Reference to the \c DiscoveryDatabase . std::shared_ptr discovery_database_; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp index b75234792..a90d0dfbc 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp @@ -24,7 +24,7 @@ #include -#include +#include namespace eprosima { namespace ddsrouter { @@ -85,7 +85,7 @@ class BaseWriter : public core::IWriter * Thread safe with mutex \c mutex_ . */ virtual utils::ReturnCode write( - std::unique_ptr& data) noexcept override; + IRoutingData& data) noexcept override; protected: @@ -109,7 +109,7 @@ class BaseWriter : public core::IWriter * Implement this method in every inherited Writer class with write functionality. */ virtual utils::ReturnCode write_( - std::unique_ptr& data) noexcept = 0; + IRoutingData& data) noexcept = 0; //! Participant parent ID core::types::ParticipantId participant_id_; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp index cb038ba54..b85828c33 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp @@ -19,7 +19,7 @@ #ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ #define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ -#include +#include namespace eprosima { namespace ddsrouter { @@ -41,7 +41,7 @@ class BlankWriter : public core::IWriter //! Override write() IWriter method utils::ReturnCode write( - std::unique_ptr& data) noexcept override; + core::types::IRoutingData& data) noexcept override; }; } /* namespace participants */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp index 36e74b3bb..3e3daa897 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp @@ -50,7 +50,7 @@ class EchoWriter : public BlankWriter * @return RETCODE_OK always */ virtual utils::ReturnCode write( - std::unique_ptr& data) noexcept override; + IRoutingData& data) noexcept override; //! Topic that this Writer refers to core::types::DdsTopic topic_; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/DummyWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp similarity index 54% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/DummyWriter.hpp rename to ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp index 9db968432..6273b0004 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/DummyWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp @@ -1,4 +1,4 @@ -// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// 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. @@ -13,42 +13,27 @@ // limitations under the License. /** - * @file DummyWriter.hpp + * @file MockWriter.hpp */ -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_DUMMYWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_DUMMYWRITER_HPP_ - -#include -#include +#pragma once #include #include -#include +#include namespace eprosima { namespace ddsrouter { namespace participants { -//! Data kind that a Dummy Writer should have sent - -struct DummyDataStored +class MockWriter { - //! Payload in a format of vector of bytes - std::vector payload; - - //! Guid of the source entity that has transmitted the data - core::types::Guid source_guid; - - //! Timestamp of the theoretic publication time - utils::Timestamp timestamp; + virtual ~MockWriter(); }; -/** - * Writer implementation that allows to simulate data publication - */ -class DummyWriter : public BaseWriter +template +class MockWriterSpecialization : public BaseWriter { public: @@ -60,7 +45,7 @@ class DummyWriter : public BaseWriter * * @return vector of data */ - std::vector get_data_that_should_have_been_sent() const noexcept; + std::vector get_data_that_should_have_been_sent() const noexcept; /** @@ -68,8 +53,7 @@ class DummyWriter : public BaseWriter * * @param [in] n : wait until data number \c n has arrived and simulated to be sent */ - void wait_until_n_data_sent( - uint16_t n) const noexcept; + unsigned int count_data_received() const noexcept; protected: @@ -82,19 +66,13 @@ class DummyWriter : public BaseWriter * @param data : data to simulate publication * @return RETCODE_OK always */ - utils::ReturnCode write_( - std::unique_ptr& data) noexcept override; + virtual utils::ReturnCode write_( + IRoutingData& data) noexcept override = 0; //! Stores the data that should have been published - std::vector data_stored_; - - /** - * Condition variable to wait for new data available or track termination. - */ - mutable std::condition_variable wait_condition_variable_; + std::vector data_stored_; - //! Guard access to \c data_stored_ - mutable std::mutex dummy_mutex_; + mutable std::mutex mutex_; }; } /* namespace participants */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp index d3cf8418f..b2d88449c 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp @@ -31,6 +31,7 @@ #include #include #include +#include ///// // Forward declarations @@ -145,7 +146,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @return \c RETCODE_ERROR if error occurred */ virtual utils::ReturnCode write_( - std::unique_ptr& data) noexcept override; + IRoutingData& data) noexcept override; /** * @brief Auxiliary method used in \c write to fill the cache change to send. @@ -157,7 +158,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener virtual utils::ReturnCode fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - std::unique_ptr& data) const noexcept; + const RtpsPayloadData& data) const noexcept; /** * @brief Auxiliary method used after \c write to fill data value. @@ -166,8 +167,8 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @param [out] data data to be fulfilled with params. */ virtual void fill_sent_data_( - const eprosima::fastrtps::rtps::WriteParams& params, - std::unique_ptr& data_to_fill) const noexcept; + const eprosima::fastrtps::rtps::WriteParams& sent_params, + RtpsPayloadData& data_to_fill) const noexcept; ///// // RTPS specific methods diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp index 9c4c32a54..1827e3517 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp @@ -91,7 +91,7 @@ class MultiWriter : public BaseWriter * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty */ virtual utils::ReturnCode write_( - std::unique_ptr& data) noexcept override; + IRoutingData& data) noexcept override; bool exist_partition_( const core::types::SpecificEndpointQoS& data_qos); diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp index 210855b56..20f9f3a50 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp @@ -16,14 +16,14 @@ * @file IRoutingData.hpp */ -#ifndef _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ +#pragma once #include namespace eprosima { namespace ddsrouter { namespace core { +namespace types { /** * @brief TODO @@ -43,8 +43,7 @@ class IRoutingData } }; +} /* namespace types */ } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_DATA_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/Payload.hpp similarity index 96% rename from ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp rename to ddsrouter_core/include/ddsrouter_core/types/data/Payload.hpp index 3fdf920d6..95c936651 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/data/Payload.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/Payload.hpp @@ -31,7 +31,8 @@ namespace eprosima { namespace ddsrouter { -namespace participants { +namespace core { +namespace types { //! Durability kind enumeration using PartitionQosPolicy = eprosima::fastdds::dds::PartitionQosPolicy; @@ -64,6 +65,7 @@ DDSROUTER_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const Payload& payload); -} /* namespace participants */ +} /* namespace types */ +} /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp similarity index 92% rename from ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp rename to ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp index 1905149f3..75ea0c80b 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/data/RpcPayloadData.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -32,7 +32,8 @@ namespace eprosima { namespace ddsrouter { -namespace participants { +namespace core { +namespace types { /** * @brief Structure of the Data received from a Reader containing the data itself and its properties. @@ -53,6 +54,7 @@ DDSROUTER_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const RpcPayloadData& octet); -} /* namespace participants */ +} /* namespace types */ +} /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp similarity index 86% rename from ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp rename to ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp index 0466a0883..8890dcae8 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/data/RtpsPayloadData.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp @@ -22,7 +22,8 @@ #include #include -#include +#include +#include #include #include #include @@ -30,7 +31,8 @@ namespace eprosima { namespace ddsrouter { -namespace participants { +namespace core { +namespace types { /** * @brief Structure of the Data received from a Reader containing the data itself and its properties. @@ -39,9 +41,14 @@ namespace participants { */ struct RtpsPayloadData : public core::types::IRoutingData { + + virtual ~RtpsPayloadData(); + //! Payload of the data received. The data in this payload must belong to the PayloadPool. Payload payload{}; + core::PayloadPool* payload_owner{nullptr}; + //! Specific Writer QoS of the Data core::types::SpecificEndpointQoS writer_qos{}; @@ -61,11 +68,14 @@ struct RtpsPayloadData : public core::types::IRoutingData core::types::ParticipantId participant_receiver{}; }; +constexpr const char* RTPS_PAYLOAD_DATA = "rtps::payload@v0"; + //! \c octet to stream serializator DDSROUTER_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const RtpsPayloadData& octet); -} /* namespace participants */ +} /* namespace types */ +} /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/DataProperties.hpp b/ddsrouter_core/include/ddsrouter_core/types/dds/DataProperties.hpp deleted file mode 100644 index 456909129..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/DataProperties.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2022 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 DataProperties.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ -#define _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -//! Durability kind enumeration -using PartitionQosPolicy = eprosima::fastdds::dds::PartitionQosPolicy; - -//! Partition configuration -using OwnershipStrengthQosPolicy = eprosima::fastdds::dds::OwnershipStrengthQosPolicy; - -//! Instance Handler type -using InstanceHandle = eprosima::fastrtps::rtps::InstanceHandle_t; - -//! Instance Handler type -using ChangeKind = eprosima::fastrtps::rtps::ChangeKind_t; - -//! Fast DDS Time -using DataTime = eprosima::fastrtps::rtps::Time_t; - -/** - * Collection of attributes related with a Data. - */ -struct DDSROUTER_CORE_DllAPI DataProperties -{ - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default DataProperties with reader less restrictive parameters - DataProperties() = default; - - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Minor comparison operator - bool operator < ( - const DataProperties& other) const noexcept; - - //! Equality operator - bool operator == ( - const DataProperties& other) const noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Specific Writer QoS of the Data - SpecificEndpointQoS writer_qos{}; - - //! Instance of the message (default no instance) - InstanceHandle instanceHandle{}; - - //! Kind of the change - ChangeKind kind{}; - - //! Source time stamp of the message - DataTime source_timestamp{}; - - //! Guid of the source entity that has transmit the data - Guid source_guid{}; - - //! Id of the participant from which the Reader has received the data. - ParticipantId participant_receiver{}; - - //! Write params associated to the received cache change - utils::Fuzzy write_params{}; - - //! Sequence number of the received cache change - eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; -}; - -/** - * @brief \c DataProperties to stream serialization - */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const DataProperties& qos); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_ENDPOINT_DataProperties_HPP_ */ diff --git a/ddsrouter_core/src/cpp/communication/Track.cpp b/ddsrouter_core/src/cpp/communication/Track.cpp index fa2a19252..fb6ee5e5a 100644 --- a/ddsrouter_core/src/cpp/communication/Track.cpp +++ b/ddsrouter_core/src/cpp/communication/Track.cpp @@ -178,8 +178,8 @@ void Track::transmit_() noexcept // This will erase every previous value added in on_data_available and set 1 data_available_status_.store(DataAvailableStatus::transmitting_data); - // Get data received - std::unique_ptr data = std::make_unique(); + // Get data received (send empty data to be created(allocated) in reader) + std::unique_ptr data; utils::ReturnCode ret = reader_->take(data); if (ret == utils::ReturnCode::RETCODE_NO_DATA) @@ -210,7 +210,7 @@ void Track::transmit_() noexcept logDebug(DDSROUTER_TRACK, "Track " << reader_participant_id_ << " for topic " << topic_ << - " transmitting data from remote endpoint " << data->properties.source_guid << "."); + " transmitting data from remote endpoint."); // Send data through writers for (auto& writer_it : writers_) @@ -219,7 +219,7 @@ void Track::transmit_() noexcept DDSROUTER_TRACK, "Forwarding data to writer " << writer_it.first << "."); - ret = writer_it.second->write(data); + ret = writer_it.second->write(*data); if (!ret) { @@ -230,11 +230,7 @@ void Track::transmit_() noexcept } } - // Release payload in case it has length - if (data->payload.length > 0) - { - payload_pool_->release_payload(data->payload); - } + // Let the data to be removed by itself } } diff --git a/ddsrouter_core/src/cpp/communication/Track.hpp b/ddsrouter_core/src/cpp/communication/Track.hpp index 75f0e4941..6ad28f820 100644 --- a/ddsrouter_core/src/cpp/communication/Track.hpp +++ b/ddsrouter_core/src/cpp/communication/Track.hpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include namespace eprosima { diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp index ff49a2cca..4fba41991 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -330,9 +330,11 @@ void RPCBridge::transmit_( } // Get data received - std::unique_ptr data = std::make_unique(); + std::unique_ptr data; utils::ReturnCode ret = reader->take(data); + RpcPayloadData& pcr_data = dynamic_cast(data); + // Will never return \c RETCODE_NO_DATA, otherwise would have finished before if (!ret) { @@ -348,17 +350,17 @@ void RPCBridge::transmit_( { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << topic_ << - " transmitting request from remote endpoint " << data->properties.source_guid << "."); + " transmitting request from remote endpoint " << pcr_data->properties.source_guid << "."); SampleIdentity reply_related_sample_identity = - data->properties.write_params.get_reference().sample_identity(); - reply_related_sample_identity.sequence_number(data->properties.origin_sequence_number); + pcr_data->properties.write_params.get_reference().sample_identity(); + reply_related_sample_identity.sequence_number(pcr_data->properties.origin_sequence_number); if (reply_related_sample_identity == SampleIdentity::unknown()) { logWarning(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << topic_ << - " received ill-formed request from remote endpoint " << data->properties.source_guid << + " received ill-formed request from remote endpoint " << pcr_data->properties.source_guid << ". Ignoring..."); } else @@ -366,7 +368,7 @@ void RPCBridge::transmit_( for (auto& service_registry : service_registries_) { // Do not send request through same participant who received it (unless repeater), or if there are no servers to process it - if ((data->properties.participant_receiver == service_registry.first && + if ((pcr_data->properties.participant_receiver == service_registry.first && !participants_->get_participant(service_registry.first)->is_repeater()) || !service_registry.second->enabled()) { @@ -378,9 +380,9 @@ void RPCBridge::transmit_( // Set write params so writer set in related sample identity the correct value // Set it so writer use it - data->properties.write_params.set_level(); + pcr_data->properties.write_params.set_level(); // Attach the information the server needs in order to reply to the appropiate proxy client. - data->properties.write_params.get_reference().related_sample_identity().writer_guid( + pcr_data->properties.write_params.get_reference().related_sample_identity().writer_guid( reply_readers_[service_registry.first]->guid()); ret = request_writers_[service_registry.first]->write(data); @@ -393,11 +395,11 @@ void RPCBridge::transmit_( } eprosima::fastrtps::rtps::SequenceNumber_t sequence_number = - data->sent_sequence_number; + pcr_data->sent_sequence_number; // Add entry to registry associated to the transmission of this request through this proxy client. service_registry.second->add( sequence_number, - {data->properties.participant_receiver, reply_related_sample_identity}); + {pcr_data->properties.participant_receiver, reply_related_sample_identity}); } } @@ -406,16 +408,16 @@ void RPCBridge::transmit_( { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << topic_ << - " transmitting reply from remote endpoint " << data->properties.source_guid << "."); + " transmitting reply from remote endpoint " << pcr_data->properties.source_guid << "."); // A Server could be answering a different client in this same DDS Router or a remote client // Thus, it must be filtered so only replies to this client are processed. - if (data->properties.write_params.get_reference().sample_identity().writer_guid() != reader->guid()) + if (pcr_data->properties.write_params.get_reference().sample_identity().writer_guid() != reader->guid()) { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << *this << " from reader " << reader->guid() << " received response meant for other client: " << - data->properties.write_params.get_reference().sample_identity().writer_guid()); + pcr_data->properties.write_params.get_reference().sample_identity().writer_guid()); } else { @@ -427,7 +429,7 @@ void RPCBridge::transmit_( // Fetch information required for transmission; which proxy server should send it and with what parameters registry_entry = service_registries_[reader->participant_id()]->get( - data->properties.write_params.get_reference().sample_identity().sequence_number()); + pcr_data->properties.write_params.get_reference().sample_identity().sequence_number()); } // Not valid means: @@ -436,8 +438,8 @@ void RPCBridge::transmit_( // TODO: recheck ParticipantId non valid if (!registry_entry.first.empty()) { - data->properties.write_params.set_level(); - data->properties.write_params.get_reference().related_sample_identity(registry_entry.second); + pcr_data->properties.write_params.set_level(); + pcr_data->properties.write_params.get_reference().related_sample_identity(registry_entry.second); ret = reply_writers_[registry_entry.first]->write(data); @@ -449,7 +451,7 @@ void RPCBridge::transmit_( else { service_registries_[reader->participant_id()]->erase( - data->properties.write_params.get_reference().sample_identity().sequence_number()); + pcr_data->properties.write_params.get_reference().sample_identity().sequence_number()); } } } @@ -460,7 +462,7 @@ void RPCBridge::transmit_( utils::Formatter() << "Data to be transmitted in RPCBridge is not in RPCTopic."); } - payload_pool_->release_payload(data->payload); + payload_pool_->release_payload(pcr_data->payload); } } diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp index 22186a8f5..45f37ca00 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp +++ b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include namespace eprosima { diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp index 63dbe0140..259ba5d93 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp index 65a517204..69042f733 100644 --- a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp @@ -56,7 +56,7 @@ void BaseReader::enable() noexcept enabled_.store(true); // Call specific enable - enable_(); + enable_nts_(); } } @@ -70,7 +70,7 @@ void BaseReader::disable() noexcept enabled_.store(false); // Call specific disable - disable_(); + disable_nts_(); } } @@ -104,13 +104,13 @@ void BaseReader::unset_on_data_available_callback() noexcept } utils::ReturnCode BaseReader::take( - std::unique_ptr& data) noexcept + std::unique_ptr data) noexcept { std::lock_guard lock(mutex_); if (enabled_.load()) { - return take_(data); + return take_nts_(data); } else { @@ -143,12 +143,12 @@ void BaseReader::on_data_available_() const noexcept } } -void BaseReader::enable_() noexcept +void BaseReader::enable_nts_() noexcept { // It does nothing. Override this method so it has functionality. } -void BaseReader::disable_() noexcept +void BaseReader::disable_nts_() noexcept { // It does nothing. Override this method so it has functionality. } diff --git a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp index 6d469db42..44c24572d 100644 --- a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp @@ -42,7 +42,7 @@ void BlankReader::unset_on_data_available_callback() noexcept } utils::ReturnCode BlankReader::take( - std::unique_ptr&) noexcept + std::unique_ptr& /* data */) noexcept { return utils::ReturnCode::RETCODE_NO_DATA; } diff --git a/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp index 9b96a67c9..c81ca5491 100644 --- a/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp @@ -38,7 +38,7 @@ void DummyReader::simulate_data_reception( } utils::ReturnCode DummyReader::take_( - std::unique_ptr& data) noexcept + IRoutingData*& data) noexcept { std::lock_guard lock(dummy_mutex_); diff --git a/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp b/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp index 095e02f14..49ac8b721 100644 --- a/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp @@ -23,7 +23,8 @@ #include #include -#include +#include +#include namespace eprosima { namespace ddsrouter { @@ -146,7 +147,7 @@ uint64_t CommonReader::get_unread_count() const noexcept } utils::ReturnCode CommonReader::take_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { // Check if there is data available if (!(get_unread_count() > 0)) @@ -174,11 +175,9 @@ utils::ReturnCode CommonReader::take_( } // Store the new data that has arrived in the Track data - fill_received_data_(received_change, data); - - logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Data transmiting to track from Reader " << *this << " with payload " << - data->payload << " from remote writer " << data->properties.source_guid); + auto data_ptr = create_data_(received_change); + fill_received_data_(received_change, data_ptr*); + data.reset(data_ptr); // Remove the change in the History and release it in the reader rtps_reader_->getHistory()->remove_change(received_change); @@ -186,9 +185,15 @@ utils::ReturnCode CommonReader::take_( return utils::ReturnCode::RETCODE_OK; } +RtpsPayloadData* CommonReader::create_data_( + const fastrtps::rtps::CacheChange_t& received_change) const noexcept +{ + return new RtpsPayloadData(); +} + void CommonReader::fill_received_data_( fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept + RtpsPayloadData& data_to_fill) const noexcept { // Store the new data that has arrived in the Track data // Get the writer guid @@ -207,6 +212,8 @@ void CommonReader::fill_received_data_( received_change->serializedPayload, payload_owner, data_to_fill->payload); + + data_to_fill->payload_owner = payload_pool_->get(); } // Set Instance Handle to data_to_fill @@ -222,8 +229,13 @@ void CommonReader::fill_received_data_( data_to_fill->properties.origin_sequence_number = received_change->sequenceNumber; - // Note: do not fill writer specific properties in this data from this kind of Readers. + // Note: do not fill writer specific properties in this data_to_fill from this kind of Readers. // Implement specific class for filling it. + + logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, + "Data transmiting to track from Reader " << *this << " with payload " << + data_to_fill->payload << " from remote writer " << data_to_fill->properties.source_guid); + } void CommonReader::enable_() noexcept diff --git a/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp b/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp index 06f4616a9..5a0845fde 100644 --- a/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp @@ -53,9 +53,9 @@ core::types::SpecificEndpointQoS SpecificQoSReader::specific_qos_of_writer_( return discovery_database_->get_endpoint(guid).specific_qos(); } -void SpecificQoSReader::fill_received_data_( - fastrtps::rtps::CacheChange_t* received_change, - std::unique_ptr& data_to_fill) const noexcept +void fill_received_data_( + fastrtps::rtps::CacheChange_t* received_change, + RtpsPayloadData& data_to_fill) const noexcept { CommonReader::fill_received_data_(received_change, data_to_fill); @@ -75,6 +75,8 @@ void SpecificQoSReader::fill_received_data_( DDSROUTER_SpecificQoSReader, "Received a message from Writer " << data_to_fill->properties.source_guid << " that is not stored in DB."); } + + return data; } } /* namespace rtps */ diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp index 15a8c4551..9530fda62 100644 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp @@ -67,7 +67,7 @@ void BaseWriter::disable() noexcept } utils::ReturnCode BaseWriter::write( - std::unique_ptr& data) noexcept + IRoutingData& data) noexcept { std::lock_guard lock(mutex_); diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp index be6b8cca9..3138b0310 100644 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp @@ -33,7 +33,7 @@ void BlankWriter::disable() noexcept } utils::ReturnCode BlankWriter::write( - std::unique_ptr&) noexcept + core::types::IRoutingData& /* data */) noexcept { return utils::ReturnCode::RETCODE_OK; } diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp index 18590c012..084375852 100644 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace eprosima { namespace ddsrouter { @@ -39,14 +40,15 @@ EchoWriter::EchoWriter( } utils::ReturnCode EchoWriter::write( - std::unique_ptr& data) noexcept + IRoutingData& data) noexcept { + auto rtps_data = dynamic_cast(data); // TODO: Add Participant receiver Id when added to DataReceived if (!verbose_) { logUser( DDSROUTER_ECHO_DATA, - "Received data in Participant: " << data->properties.participant_receiver << + "Received data in Participant: " << rtps_data.properties.participant_receiver << " in topic: " << topic_ << "."); } @@ -54,11 +56,11 @@ utils::ReturnCode EchoWriter::write( { logUser( DDSROUTER_ECHO_DATA, - "In Endpoint: " << data->properties.source_guid << - " from Participant: " << data->properties.participant_receiver << + "In Endpoint: " << rtps_data.properties.source_guid << + " from Participant: " << rtps_data.properties.participant_receiver << " in topic: " << topic_ << - " payload received: " << data->payload << - " with specific qos: " << data->properties.writer_qos << + " payload received: " << rtps_data.payload << + " with specific qos: " << rtps_data.properties.writer_qos << "."); } diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp index 32f786265..776d7c99f 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp @@ -120,8 +120,9 @@ bool CommonWriter::come_from_this_participant_( // Specific enable/disable do not need to be implemented utils::ReturnCode CommonWriter::write_( - std::unique_ptr& data) noexcept + IRoutingData& data) noexcept { + auto rtps_data = dynamic_cast(data); // Take new Change from history fastrtps::rtps::CacheChange_t* new_change; @@ -129,12 +130,12 @@ utils::ReturnCode CommonWriter::write_( { new_change = rtps_writer_->new_change( - eprosima::fastrtps::rtps::ChangeKind_t::ALIVE, - data->properties.instanceHandle); + rtps_data.kind, + rtps_data.properties.instanceHandle); } else { - new_change = rtps_writer_->new_change(eprosima::fastrtps::rtps::ChangeKind_t::ALIVE); + new_change = rtps_writer_->new_change(rtps_data.kind); } // If still is not able to get a change, return an error code @@ -145,13 +146,13 @@ utils::ReturnCode CommonWriter::write_( logDebug(DDSROUTER_RTPS_COMMONWRITER, "CommonWriter " << *this << " sending payload " << new_change->serializedPayload << " from " << - data->properties.source_guid); + rtps_data.properties.source_guid); // Get params to write (if set) eprosima::fastrtps::rtps::WriteParams write_params; // Fill cache change with specific data to send - auto ret = fill_to_send_data_(new_change, write_params, data); + auto ret = fill_to_send_data_(new_change, write_params, rtps_data); if (!ret) { logError(DDSROUTER_RTPS_COMMONWRITER, "Error setting change to send."); @@ -162,7 +163,7 @@ utils::ReturnCode CommonWriter::write_( rtps_history_->add_change(new_change, write_params); // At this point, write params is now the output of adding change - fill_sent_data_(write_params, data); + fill_sent_data_(write_params, rtps_data); // Remove change could be done here in non reliable as it is synchronous because change has already been sent // and does not require to be resent under any circumstance. @@ -182,26 +183,26 @@ utils::ReturnCode CommonWriter::write_( utils::ReturnCode CommonWriter::fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - std::unique_ptr& data) const noexcept + const RtpsPayloadData& data) const noexcept { if (repeater_) { // Add origin to change in case the cache change is RouterCacheChange (only in repeater mode) core::types::RouterCacheChange& change_ref = static_cast(*to_send_change_to_fill); - change_ref.last_writer_guid_prefix = data->properties.source_guid.guidPrefix; + change_ref.last_writer_guid_prefix = data.properties.source_guid.guidPrefix; } // Set keys in case topic has keys if (topic_.keyed) { - to_send_change_to_fill->instanceHandle = data->properties.instanceHandle; + to_send_change_to_fill->instanceHandle = data.properties.instanceHandle; } // Get the Payload without copy only if it has length - if (data->payload.length > 0) + if (data.payload.length > 0) { eprosima::fastrtps::rtps::IPayloadPool* payload_owner = payload_pool_.get(); - if (!payload_pool_->get_payload(data->payload, payload_owner, (*to_send_change_to_fill))) + if (!payload_pool_->get_payload(data.payload, payload_owner, (*to_send_change_to_fill))) { logDevError(DDSROUTER_RTPS_COMMONWRITER, "Error getting Payload."); return utils::ReturnCode::RETCODE_ERROR; @@ -209,14 +210,14 @@ utils::ReturnCode CommonWriter::fill_to_send_data_( } // Set Change kind - to_send_change_to_fill->kind = data->properties.kind; + to_send_change_to_fill->kind = data.properties.kind; // Set source time stamp to be the original one - to_send_params.source_timestamp(data->properties.source_timestamp); + to_send_params.source_timestamp(data.properties.source_timestamp); // RPC support // If writer params has been set specifically, use them in change - if (data->properties.write_params.is_set()) + if (data.properties.write_params.is_set()) { to_send_params.related_sample_identity(data->properties.write_params.get_reference().related_sample_identity()); } diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp index 7e1c0144b..318a836eb 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp +++ b/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp @@ -139,7 +139,7 @@ QoSSpecificWriter* MultiWriter::create_writer_nts_( // Specific enable/disable do not need to be implemented utils::ReturnCode MultiWriter::write_( - std::unique_ptr& data) noexcept + IRoutingData& data) noexcept { logDebug( DDSROUTER_MULTIWRITER, diff --git a/ddsrouter_core/src/cpp/types/dds/Data.cpp b/ddsrouter_core/src/cpp/types/data/Payload.cpp similarity index 95% rename from ddsrouter_core/src/cpp/types/dds/Data.cpp rename to ddsrouter_core/src/cpp/types/data/Payload.cpp index 2b536e6d7..a4438c6c3 100644 --- a/ddsrouter_core/src/cpp/types/dds/Data.cpp +++ b/ddsrouter_core/src/cpp/types/data/Payload.cpp @@ -13,13 +13,13 @@ // limitations under the License. /** - * @file Data.cpp + * @file Payload.cpp * */ #include -#include +#include namespace eprosima { namespace ddsrouter { diff --git a/ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp b/ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp new file mode 100644 index 000000000..8236570a2 --- /dev/null +++ b/ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp @@ -0,0 +1,37 @@ +// Copyright 2021 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 RtpsPayloadData.cpp + */ + +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +RtpsPayloadData::~RtpsPayloadData() +{ + // If payload owner exists and payload has size, release it correctly in pool + if (payload_owner && payload.length > 0) + { + payload_owner->release_payload(payload); + } +} + + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/dds/DataProperties.cpp b/ddsrouter_core/src/cpp/types/dds/DataProperties.cpp deleted file mode 100644 index 31250934f..000000000 --- a/ddsrouter_core/src/cpp/types/dds/DataProperties.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2022 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 DataProperties.cpp - * - */ - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -bool DataProperties::operator < ( - const DataProperties& other) const noexcept -{ - if (this->writer_qos < other.writer_qos) - { - return true; - } - else if (this->writer_qos == other.writer_qos) - { - return this->instanceHandle < other.instanceHandle; - } - - // NOTE: operator> does not exist, so use == instead - // else => this->writer_qos > other.writer_qos - return false; - -} - -bool DataProperties::operator == ( - const DataProperties& other) const noexcept -{ - // NOTE: Ownership not supported - return this->writer_qos == other.writer_qos && this->instanceHandle == other.instanceHandle; -} - -std::ostream& operator <<( - std::ostream& os, - const DataProperties& qos) -{ - os << - "DataProperties{" << qos.writer_qos << - ";" << qos.instanceHandle << - "}"; - - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt b/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt index ac76d9057..bf91b8503 100644 --- a/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt @@ -20,10 +20,10 @@ set(TEST_NAME ParticipantsDatabaseTest) set(TEST_SOURCES ParticipantsDatabaseTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participant/auxiliar/BlankParticipant.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantsDatabase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/reader/auxiliar/BlankReader.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/writer/auxiliar/BlankWriter.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participants/reader/auxiliar/BlankReader.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participants/writer/auxiliar/BlankWriter.cpp ) all_header_sources("${TEST_SOURCES}") diff --git a/ddsrouter_core/test/unittest/efficiency/CMakeLists.txt b/ddsrouter_core/test/unittest/efficiency/CMakeLists.txt index 826d2a3e6..0fd30faee 100644 --- a/ddsrouter_core/test/unittest/efficiency/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/efficiency/CMakeLists.txt @@ -21,8 +21,7 @@ set(TEST_NAME PayloadPoolTest) set(TEST_SOURCES PayloadPoolTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.hpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Data.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp ) set(TEST_LIST @@ -61,10 +60,8 @@ set(TEST_NAME MapPayloadPoolTest) set(TEST_SOURCES MapPayloadPoolTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.hpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/MapPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/MapPayloadPool.hpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Data.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp ) set(TEST_LIST @@ -98,10 +95,8 @@ set(TEST_NAME FastPayloadPoolTest) set(TEST_SOURCES FastPayloadPoolTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.hpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/FastPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/FastPayloadPool.hpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Data.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp ) set(TEST_LIST diff --git a/ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp b/ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp index 5ef1fe65c..ca1bdb519 100644 --- a/ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp +++ b/ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp @@ -22,9 +22,8 @@ #include #include -#include - -#include +#include +#include using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::core; diff --git a/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt b/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt index 828833eca..d5b0070aa 100644 --- a/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt +++ b/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt @@ -55,7 +55,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RPCTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/SpecificEndpointQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/DataProperties.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ) diff --git a/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp b/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp index 57ad744e4..08918989f 100644 --- a/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp +++ b/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp @@ -19,7 +19,7 @@ #ifndef __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ #define __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ -#include +#include #include #include #include diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp index 4c57a1270..fb71b847d 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include From 51a7ed6bf779b921be6f6909c602e629a94499e5 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 7 Feb 2023 10:13:55 +0100 Subject: [PATCH 04/38] Data Received refactor with topic type id Signed-off-by: jparisu --- .../participant/auxiliar/BaseParticipant.hpp | 6 +- .../participant/auxiliar/MockParticipant.hpp | 75 ---------- .../reader/auxiliar/MockReader.hpp | 72 ---------- .../participants/reader/rtps/CommonReader.hpp | 2 +- .../writer/auxiliar/BaseWriter.hpp | 8 +- .../writer/auxiliar/EchoWriter.hpp | 2 +- .../writer/auxiliar/MockWriter.hpp | 82 ----------- .../participants/writer/rtps/CommonWriter.hpp | 9 +- .../types/data/IRoutingData.hpp | 6 +- .../types/data/RpcPayloadData.hpp | 10 +- .../types/data/RtpsPayloadData.hpp | 6 +- .../ddsrouter_core/types/data/SharedData.hpp | 57 ++++++++ .../ddsrouter_core/types/topic/Topic.hpp | 19 +-- .../types/topic/TopicInternalTypeId.hpp | 35 +++++ .../src/cpp/communication/rpc/RPCBridge.cpp | 2 + .../participant/auxiliar/BaseParticipant.cpp | 6 +- .../participant/auxiliar/DummyParticipant.cpp | 134 ------------------ .../participant/auxiliar/MockParticipant.cpp | 78 ++++++++++ .../reader/auxiliar/DummyReader.cpp | 77 ---------- .../participants/reader/rtps/CommonReader.cpp | 2 +- .../writer/auxiliar/DummyWriter.cpp | 73 ---------- ddsrouter_core/src/cpp/types/topic/Topic.cpp | 12 -- 22 files changed, 209 insertions(+), 564 deletions(-) delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp create mode 100644 ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp create mode 100644 ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp delete mode 100644 ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp create mode 100644 ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp delete mode 100644 ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp delete mode 100644 ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp index 09fdab0bc..1fc654178 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp @@ -53,9 +53,9 @@ class BaseParticipant : public core::IParticipant * @param discovery_database DDS Router shared Discovery Database */ BaseParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + const std::shared_ptr& participant_configuration, + const std::shared_ptr & payload_pool, + const std::shared_ptr& discovery_database); /** * @brief Destroy the Base Participant object diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp deleted file mode 100644 index 54e811a45..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/MockParticipant.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// 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 MockParticipant.hpp - */ - -#pragma once - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -/** - * TODO - */ -class MockParticipant : public BaseParticipant -{ -public: - - /** - * TODO - */ - MockParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr discovery_database); - - /** - * @brief Destroy the Mock Participant object - */ - virtual ~MockParticipant(); - - /** - * @brief Simulate that this Participant has discovered a new endpoint - * - * @param new_endpoint : Endpoint discovered - */ - void simulate_discovered_endpoint( - const core::types::Endpoint& new_endpoint); - - std::shared_ptr get_reader( - core::types::DdsTopic topic); - - std::vector get_writer( - core::types::DdsTopic topic); - -protected: - - //! Override create_writer_() BaseParticipant method - std::shared_ptr create_writer_( - core::types::DdsTopic topic) override; - - //! Override create_reader_() BaseParticipant method - std::shared_ptr create_reader_( - core::types::DdsTopic topic) override; -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp deleted file mode 100644 index 056758bd8..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/MockReader.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// 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 MockReader.hpp - */ - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -class MockReader -{ - virtual ~MockReader(); -}; - -template -class MockReaderSpecialization : public BaseReader -{ -public: - - //! Use parent constructors - using BaseReader::BaseReader; - - /** - * @brief Simulate data reception on Reader - * - * @param data : The data received (by simulation) - */ - void simulate_data_reception( - T data) noexcept; - -protected: - - /** - * @brief Take specific method - * - * After \c take method, the data will be removed from \c data_to_send_ . - * - * @param data : oldest data to take - * @return \c RETCODE_OK if data has been correctly taken - * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty - */ - virtual utils::ReturnCode take_( - std::unique_ptr& data) noexcept override = 0; - - //! Stores the data that must be retrieved with \c take() method - std::queue data_to_send_; - - mutable std::mutex mutex_; -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp index be0325af2..bd7b48ea6 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp @@ -157,7 +157,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @brief Auxiliary method used in \c take to fill the received data. */ virtual void fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change + const fastrtps::rtps::CacheChange_t& received_change, core::types::RtpsPayloadData& data_to_fill) const noexcept; // Specific enable/disable do not need to be implemented diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp index a90d0dfbc..25e0e8bd1 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp @@ -22,9 +22,9 @@ #include #include -#include - #include +#include +#include namespace eprosima { namespace ddsrouter { @@ -85,7 +85,7 @@ class BaseWriter : public core::IWriter * Thread safe with mutex \c mutex_ . */ virtual utils::ReturnCode write( - IRoutingData& data) noexcept override; + core::types::IRoutingData& data) noexcept override; protected: @@ -109,7 +109,7 @@ class BaseWriter : public core::IWriter * Implement this method in every inherited Writer class with write functionality. */ virtual utils::ReturnCode write_( - IRoutingData& data) noexcept = 0; + core::types::IRoutingData& data) noexcept = 0; //! Participant parent ID core::types::ParticipantId participant_id_; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp index 3e3daa897..361c16f73 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp @@ -50,7 +50,7 @@ class EchoWriter : public BlankWriter * @return RETCODE_OK always */ virtual utils::ReturnCode write( - IRoutingData& data) noexcept override; + core::types::IRoutingData& data) noexcept override; //! Topic that this Writer refers to core::types::DdsTopic topic_; diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp deleted file mode 100644 index 6273b0004..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/MockWriter.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// 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 MockWriter.hpp - */ - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -class MockWriter -{ - virtual ~MockWriter(); -}; - -template -class MockWriterSpecialization : public BaseWriter -{ -public: - - //! Use parent constructors - using BaseWriter::BaseWriter; - - /** - * @brief Get the data that should have been sent by this writer - * - * @return vector of data - */ - std::vector get_data_that_should_have_been_sent() const noexcept; - - - /** - * @brief Make the thread wait until message \c n has been received - * - * @param [in] n : wait until data number \c n has arrived and simulated to be sent - */ - unsigned int count_data_received() const noexcept; - -protected: - - /** - * @brief Write specific method - * - * This method stores the data received in \c data_stored as if it - * had published. - * - * @param data : data to simulate publication - * @return RETCODE_OK always - */ - virtual utils::ReturnCode write_( - IRoutingData& data) noexcept override = 0; - - //! Stores the data that should have been published - std::vector data_stored_; - - mutable std::mutex mutex_; -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_DUMMYWRITER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp index b2d88449c..a86af5c71 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp @@ -58,9 +58,6 @@ namespace ddsrouter { namespace participants { namespace rtps { -using WriteParams = eprosima::fastrtps::rtps::WriteParams; -using SequenceNumber = eprosima::fastrtps::rtps::SequenceNumber_t; - /** * Abstract generic class for a RTPS Writer wrapper. * @@ -146,7 +143,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @return \c RETCODE_ERROR if error occurred */ virtual utils::ReturnCode write_( - IRoutingData& data) noexcept override; + core::types::IRoutingData& data) noexcept override; /** * @brief Auxiliary method used in \c write to fill the cache change to send. @@ -158,7 +155,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener virtual utils::ReturnCode fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - const RtpsPayloadData& data) const noexcept; + const core::types::RtpsPayloadData& data) const noexcept; /** * @brief Auxiliary method used after \c write to fill data value. @@ -168,7 +165,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ virtual void fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& sent_params, - RtpsPayloadData& data_to_fill) const noexcept; + core::types::RtpsPayloadData& data_to_fill) const noexcept; ///// // RTPS specific methods diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp index 20f9f3a50..ff0eec584 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp @@ -35,12 +35,8 @@ class IRoutingData /** * @brief Virtual dtor. - * - * @note Default destructor. Force \c DataReceived to be polymorphic. Implemented here to avoid creating a .cpp . */ - virtual ~IRoutingData() - { - } + virtual ~IRoutingData() = default; }; } /* namespace types */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp index 75ea0c80b..97f1b3669 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace eprosima { namespace ddsrouter { @@ -43,13 +44,18 @@ namespace types { struct RpcPayloadData : public RtpsPayloadData { //! Write params associated to the received cache change - utils::Fuzzy write_params{}; + eprosima::fastrtps::rtps::WriteParams write_params{}; //! Sequence number of the received cache change eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; }; -//! \c octet to stream serializator +/** + * @brief Id to identify the internal topic type id that uses \c RpcPayloadData . + */ +constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; + +//! \c RpcPayloadData to stream serializator DDSROUTER_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const RpcPayloadData& octet); diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp index 8890dcae8..eec841328 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace eprosima { namespace ddsrouter { @@ -68,7 +69,10 @@ struct RtpsPayloadData : public core::types::IRoutingData core::types::ParticipantId participant_receiver{}; }; -constexpr const char* RTPS_PAYLOAD_DATA = "rtps::payload@v0"; +/** + * @brief Id to identify the internal topic type id that uses \c RtpsPayloadData . + */ +constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; //! \c octet to stream serializator DDSROUTER_CORE_DllAPI std::ostream& operator <<( diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp new file mode 100644 index 000000000..dd781c869 --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp @@ -0,0 +1,57 @@ +// 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 SharedData.hpp + */ + +#pragma once + +#include + +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace types { + +/** + * TODO + */ +template +struct SharedData : public IRoutingData +{ + std::shared_ptr ref; + + static TopicInternalTypeId get_topic_internal_type_id(); + + static bool is_shared_internal_type(TopicInternalTypeId internal_topic_type_id); +}; + +/** + * TODO + */ +constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_SHARED_GENERIC_PREFIX = "shared::v0::"; + +template +constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_SHARED_GENERIC = + INTERNAL_TOPIC_TYPE_SHARED_GENERIC_PREFIX + TYPE_NAME(T); + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp b/ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp index 565e5d655..9474d671b 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace eprosima { namespace ddsrouter { @@ -64,24 +65,18 @@ struct Topic DDSROUTER_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept; - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Minor operator. Compares \c topic_name . - DDSROUTER_CORE_DllAPI bool operator < ( - const Topic& other) const noexcept; - - //! Equal operator. Compares \c topic_name . - DDSROUTER_CORE_DllAPI bool operator == ( - const Topic& other) const noexcept; - ///////////////////////// // VARIABLES ///////////////////////// //! Topic name std::string topic_name{}; + + /** + * This refers to an internal used identifier that declares which kind of data type is going to be + * transmitted in this topic inside the core. + */ + TopicInternalTypeId internal_topic_type_discriminator{INTERNAL_TOPIC_TYPE_NONE}; }; /** diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp b/ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp new file mode 100644 index 000000000..f022439ad --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp @@ -0,0 +1,35 @@ +// 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 TopicInternalTypeId.hpp + */ + +#pragma once + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace types { + +using TopicInternalTypeId = const char*; + +constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_NONE = ""; + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp index 4fba41991..ede976aa1 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace eprosima { namespace ddsrouter { namespace core { diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp index 36850101e..ab93baefb 100644 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp @@ -30,9 +30,9 @@ namespace ddsrouter { namespace participants { BaseParticipant::BaseParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + const std::shared_ptr & participant_configuration, + const std::shared_ptr & payload_pool, + const std::shared_ptr & discovery_database) : configuration_(participant_configuration) , payload_pool_(payload_pool) , discovery_database_(discovery_database) diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp deleted file mode 100644 index 7386ec3bc..000000000 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/DummyParticipant.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2021 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 DummyParticipant.cpp - */ - - - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -using namespace eprosima::ddsrouter::core::types; - -std::mutex DummyParticipant::static_mutex_; -std::map DummyParticipant::participants_; - -DummyParticipant::DummyParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) - : BaseParticipant(participant_configuration, payload_pool, discovery_database) -{ - std::unique_lock lock(static_mutex_); - - // Add this participant to the static list of all participants - participants_[id()] = this; -} - -DummyParticipant::~DummyParticipant() -{ - std::unique_lock lock(static_mutex_); - - // Remove this participant from the static list of all participants - participants_.erase(id()); -} - -std::shared_ptr DummyParticipant::create_writer_( - DdsTopic topic) -{ - return std::make_shared(id(), topic, payload_pool_); -} - -std::shared_ptr DummyParticipant::create_reader_( - DdsTopic topic) -{ - return std::make_shared(id(), topic, payload_pool_); -} - -void DummyParticipant::simulate_discovered_endpoint( - const Endpoint& new_endpoint) -{ - discovery_database_->add_endpoint(new_endpoint); -} - -Endpoint DummyParticipant::get_discovered_endpoint( - const Guid& guid) const -{ - return discovery_database_->get_endpoint(guid); -} - -void DummyParticipant::simulate_data_reception( - DdsTopic topic, - DummyDataReceived data) -{ - auto it = readers_.find(topic); - if (it != readers_.end()) - { - std::shared_ptr reader = std::dynamic_pointer_cast(it->second); - reader->simulate_data_reception(data); - } -} - -std::vector DummyParticipant::get_data_that_should_have_been_sent( - DdsTopic topic) -{ - auto it = writers_.find(topic); - if (it != writers_.end()) - { - std::shared_ptr writer = std::dynamic_pointer_cast(it->second); - return writer->get_data_that_should_have_been_sent(); - } - else - { - return std::vector(); - } -} - -void DummyParticipant::wait_until_n_data_sent( - DdsTopic topic, - uint16_t n) const noexcept -{ - auto it = writers_.find(topic); - if (it != writers_.end()) - { - std::shared_ptr writer = std::dynamic_pointer_cast(it->second); - writer->wait_until_n_data_sent(n); - } -} - -DummyParticipant* DummyParticipant::get_participant( - ParticipantId id) -{ - auto it = participants_.find(id); - - if (it == participants_.end()) - { - return nullptr; - } - else - { - return it->second; - } -} - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp b/ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp new file mode 100644 index 000000000..8a438fb3a --- /dev/null +++ b/ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp @@ -0,0 +1,78 @@ +// 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 MockParticipant.cpp + */ + + + +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace participants { + +using namespace eprosima::ddsrouter::core::types; + +MockParticipant::MockParticipant( + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) + : BaseParticipant(participant_configuration, payload_pool, discovery_database) +{ + // Do nothing +} + +std::shared_ptr MockParticipant::create_writer_( + DdsTopic topic) +{ + return std::make_shared(id(), topic, payload_pool_); +} + +std::shared_ptr MockParticipant::create_reader_( + DdsTopic topic) +{ + return std::make_shared(id(), topic, payload_pool_); +} + +std::shared_ptr MockParticipant::get_reader( + core::types::DdsTopic topic) +{ + std::lock_guard _(mutex_); + auto it = readers_.find(topic); + if (it != readers_.end()) + { + return it.second; + } + return std::shared_ptr(); +} + +std::vector MockParticipant::get_writer( + core::types::DdsTopic topic) +{ + std::lock_guard _(mutex_); + auto it = writers_.find(topic); + if (it != writers_.end()) + { + return it.second; + } + return std::shared_ptr(); +} + +} /* namespace participants */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp b/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp deleted file mode 100644 index c81ca5491..000000000 --- a/ddsrouter_core/src/cpp/participants/reader/auxiliar/DummyReader.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2021 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 DummyReader.cpp - */ - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -using namespace eprosima::ddsrouter::core::types; - -void DummyReader::simulate_data_reception( - DummyDataReceived data) noexcept -{ - std::lock_guard lock(dummy_mutex_); - - // Even if disabled, the data will be stored - data_to_send_.push(data); - - // Call on data available callback - on_data_available_(); -} - -utils::ReturnCode DummyReader::take_( - IRoutingData*& data) noexcept -{ - std::lock_guard lock(dummy_mutex_); - - // Enable check is done in BaseReader - - // There is no data pending sent - if (data_to_send_.empty()) - { - return utils::ReturnCode::RETCODE_NO_DATA; - } - - // Get next data received - DummyDataReceived next_data_to_send = data_to_send_.front(); - data_to_send_.pop(); - - // Write (copy) values in data - data->properties.source_guid = next_data_to_send.source_guid; - - // Move Payload to DDSRouter Payload Pool - payload_pool_->get_payload( - static_cast(next_data_to_send.payload.size() * sizeof(PayloadUnit)), - data->payload); - - // Set values in Payload as the data was not in the DDSRouter Payload Pool - for (unsigned int i = 0; i < next_data_to_send.payload.size(); i++) - { - data->payload.data[i] = next_data_to_send.payload[i]; - } - data->payload.length = data->payload.max_size; - - return utils::ReturnCode::RETCODE_OK; -} - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp b/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp index 49ac8b721..c62091de2 100644 --- a/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp +++ b/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp @@ -176,7 +176,7 @@ utils::ReturnCode CommonReader::take_( // Store the new data that has arrived in the Track data auto data_ptr = create_data_(received_change); - fill_received_data_(received_change, data_ptr*); + fill_received_data_(received_change, *data_ptr); data.reset(data_ptr); // Remove the change in the History and release it in the reader diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp b/ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp deleted file mode 100644 index 1777a9ad9..000000000 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/DummyWriter.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021 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 DummyWriter.cpp - */ - -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -using namespace eprosima::ddsrouter::core::types; - -utils::ReturnCode DummyWriter::write_( - std::unique_ptr& data) noexcept -{ - { - std::lock_guard lock(dummy_mutex_); - - // Fill the data to store - DummyDataStored new_data_to_store; - new_data_to_store.timestamp = utils::now(); - new_data_to_store.source_guid = data->properties.source_guid; - - // Copying data as it should not be stored in PayloadPool - for (uint32_t i = 0; i < data->payload.length; i++) - { - new_data_to_store.payload.push_back(data->payload.data[i]); - } - - data_stored_.push_back(new_data_to_store); - } - - // Notify that a new message has been sent - wait_condition_variable_.notify_all(); - - return utils::ReturnCode::RETCODE_OK; -} - -void DummyWriter::wait_until_n_data_sent( - uint16_t n) const noexcept -{ - std::unique_lock lock(dummy_mutex_); - wait_condition_variable_.wait( - lock, - [n, this] - { - return data_stored_.size() >= n; - }); -} - -std::vector DummyWriter::get_data_that_should_have_been_sent() const noexcept -{ - std::lock_guard lock(dummy_mutex_); - return data_stored_; -} - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/topic/Topic.cpp b/ddsrouter_core/src/cpp/types/topic/Topic.cpp index 27376b799..83b26a6bf 100644 --- a/ddsrouter_core/src/cpp/types/topic/Topic.cpp +++ b/ddsrouter_core/src/cpp/types/topic/Topic.cpp @@ -42,18 +42,6 @@ bool Topic::is_valid( return true; } -bool Topic::operator < ( - const Topic& other) const noexcept -{ - return this->topic_name < other.topic_name; -} - -bool Topic::operator == ( - const Topic& other) const noexcept -{ - return this->topic_name == other.topic_name; -} - std::ostream& operator <<( std::ostream& os, const Topic& t) From 46780f14a080fb1921040aaa813e79fe49c78af1 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 10 Feb 2023 11:45:04 +0100 Subject: [PATCH 05/38] Headers of the whole DDS Pipe and DDS Router Signed-off-by: jparisu --- .../CMakeLists.txt | 0 ddspipe_core/README.md | 55 + .../ddspipe_core}/communication/Bridge.hpp | 45 +- .../communication/dds/DdsBridge.hpp | 66 +- .../ddspipe_core/communication/dds}/Track.hpp | 40 +- .../communication/rpc/RPCBridge.hpp | 48 +- .../communication/rpc/ServiceRegistry.hpp | 31 +- .../configuration/BaseConfiguration.hpp | 23 +- .../include/ddspipe_core/core/DdsPipe.hpp | 147 +-- .../dynamic/AllowedTopicList.hpp | 43 +- .../dynamic/DiscoveryDatabase.hpp | 21 +- .../dynamic}/ParticipantsDatabase.hpp | 17 +- .../cache_change/CacheChangePool.hpp | 13 +- .../efficiency/payload/CopyPayloadPool.hpp | 15 +- .../efficiency/payload/FastPayloadPool.hpp | 15 +- .../efficiency/payload/MapPayloadPool.hpp | 15 +- .../efficiency/payload/PayloadPool.hpp | 15 +- .../ddspipe_core}/interface/IParticipant.hpp | 56 +- .../ddspipe_core}/interface/IReader.hpp | 43 +- .../ddspipe_core/interface}/IRoutingData.hpp | 20 +- .../include/ddspipe_core/interface/ITopic.hpp | 65 ++ .../ddspipe_core}/interface/IWriter.hpp | 25 +- .../ddspipe_core/testing}/test_utils.hpp | 42 +- .../ddspipe_core/types/dds/DomainId.hpp | 66 ++ .../ddspipe_core/types/dds/Endpoint.hpp | 98 ++ .../include/ddspipe_core}/types/dds/Guid.hpp | 21 +- .../ddspipe_core}/types/dds/GuidPrefix.hpp | 32 +- .../ddspipe_core/types/dds}/Payload.hpp | 13 +- .../types/dds/SpecificEndpointQoS.hpp | 25 +- .../ddspipe_core}/types/dds/TopicQoS.hpp | 30 +- .../types/participant/ParticipantId.hpp | 17 +- .../ddspipe_core}/types/topic/Topic.hpp | 67 +- .../topic/TopicInternalTypeDiscriminator.hpp | 13 +- .../ddspipe_core/types/topic/dds/DdsTopic.hpp | 98 ++ .../types/topic/dds/DistributedTopic.hpp | 51 + .../types/topic/filter/IFilterTopic.hpp | 43 +- .../topic/filter/WildcardDdsFilterTopic.hpp | 51 +- .../ddspipe_core/types/topic/rpc/RpcTopic.hpp | 29 +- .../package.xml | 5 +- ddspipe_core/project_settings.cmake | 34 + ddspipe_core/src/cpp/_dummy.cpp | 2 + .../src_}/cpp/communication/Bridge.cpp | 4 +- .../src_}/cpp/communication/DDSBridge.cpp | 34 +- .../src_}/cpp/communication/Track.cpp | 6 +- .../src_}/cpp/communication/rpc/RPCBridge.cpp | 14 +- .../cpp/communication/rpc/ServiceRegistry.cpp | 8 +- .../configuration/DDSRouterConfiguration.cpp | 10 +- .../DDSRouterReloadConfiguration.cpp | 14 +- .../cpp/configuration/SpecsConfiguration.cpp | 8 +- .../src_}/cpp/core/DDSRouterImpl.cpp | 40 +- .../src_}/cpp/dynamic/AllowedTopicList.cpp | 8 +- .../src_}/cpp/dynamic/DiscoveryDatabase.cpp | 6 +- .../cpp/dynamic}/ParticipantsDatabase.cpp | 6 +- .../cache_change/CacheChangePool.cpp | 9 +- .../efficiency/payload/CopyPayloadPool.cpp | 6 +- .../efficiency/payload/FastPayloadPool.cpp | 6 +- .../cpp/efficiency/payload/MapPayloadPool.cpp | 6 +- .../cpp/efficiency/payload/PayloadPool.cpp | 6 +- .../src_/cpp/testing}/test_utils.cpp | 12 +- .../src_}/cpp/types/address/Address.cpp | 6 +- .../DiscoveryServerConnectionAddress.cpp | 6 +- .../src_}/cpp/types/data/Payload.cpp | 6 +- .../src_}/cpp/types/data/RtpsPayloadData.cpp | 9 +- .../src_}/cpp/types/dds/DomainId.cpp | 6 +- .../src_}/cpp/types/dds/Guid.cpp | 6 +- .../src_}/cpp/types/dds/GuidPrefix.cpp | 6 +- .../src_}/cpp/types/dds/RouterCacheChange.hpp | 16 +- .../cpp/types/dds/SpecificEndpointQoS.cpp | 6 +- .../src_}/cpp/types/dds/TopicQoS.cpp | 6 +- .../src_}/cpp/types/endpoint/Endpoint.cpp | 12 +- .../types/security/tls/TlsConfiguration.cpp | 12 +- .../src_}/cpp/types/topic/Topic.cpp | 19 +- .../src_}/cpp/types/topic/dds/DdsTopic.cpp | 30 +- .../cpp/types/topic/filter/DdsFilterTopic.cpp | 6 +- .../topic/filter/WildcardDdsFilterTopic.cpp | 8 +- .../src_}/cpp/types/topic/rpc/RPCTopic.cpp | 56 +- .../test/CMakeLists.txt | 0 .../test/blackbox/CMakeLists.txt | 0 .../blackbox/ddsrouter_core/CMakeLists.txt | 0 .../ddsrouter_core/dds/CMakeLists.txt | 16 + .../ddsrouter_core/dds/WAN/CMakeLists.txt | 0 .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 38 +- .../blackbox/ddsrouter_core/dds/WAN/README.md | 0 .../ddsrouter_core/dds/WAN/TEST_XFAIL.list | 0 .../ddsrouter_core/dds/WAN/TEST_XTSAN.list | 0 .../ddsrouter_core/dds/local/CMakeLists.txt | 0 .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 28 +- .../dds/local/DDSTestLocalDisposeKey.cpp | 26 +- .../ddsrouter_core/dds/local/README.md | 0 .../dds/types/HelloWorld/HelloWorld.cxx | 0 .../dds/types/HelloWorld/HelloWorld.h | 5 +- .../dds/types/HelloWorld/HelloWorld.idl | 0 .../HelloWorld/HelloWorldPubSubTypes.cxx | 0 .../types/HelloWorld/HelloWorldPubSubTypes.h | 5 +- .../types/HelloWorldKeyed/HelloWorldKeyed.cxx | 0 .../types/HelloWorldKeyed/HelloWorldKeyed.h | 7 +- .../types/HelloWorldKeyed/HelloWorldKeyed.idl | 0 .../HelloWorldKeyedPubSubTypes.cxx | 0 .../HelloWorldKeyedPubSubTypes.h | 7 +- .../dds/types/test_participants.hpp | 19 +- .../ddsrouter_core/resources/tls/ca.crt | 0 .../resources/tls/ddsrouter.crt | 0 .../resources/tls/ddsrouter.key | 0 .../resources/tls/dh_params.pem | 0 .../ddsrouter_core/trivial/CMakeLists.txt | 0 .../ddsrouter_core/trivial/TrivialTest.cpp | 38 +- .../blackbox/implementations/CMakeLists.txt | 0 .../implementations/ImplementationsTest.cpp | 34 +- .../test/unittest/CMakeLists.txt | 0 .../unittest/_configuration/CMakeLists.txt | 0 .../test/unittest/_configuration/TODO.md | 0 .../_configuration/_ConfigurationTest.cpp | 20 +- .../test/unittest/core/CMakeLists.txt | 0 .../core/participants_database/CMakeLists.txt | 0 .../ParticipantsDatabaseTest.cpp | 255 ++++ .../test/unittest/dynamic/CMakeLists.txt | 0 .../AllowedTopicListTest.cpp | 8 +- .../dynamic/allowed_topic_list/CMakeLists.txt | 4 +- .../dynamic/discovery_database/CMakeLists.txt | 0 .../DiscoveryDatabaseTest.cpp | 28 +- .../test/unittest/efficiency/CMakeLists.txt | 118 ++ .../efficiency/FastPayloadPoolTest.cpp | 324 ++++++ .../efficiency/MapPayloadPoolTest.cpp | 366 ++++++ .../unittest/efficiency/PayloadPoolTest.cpp | 413 +++++++ .../test/unittest/types/CMakeLists.txt | 0 .../unittest/types/endpoint/CMakeLists.txt | 4 +- .../unittest/types/endpoint/EndpointTest.cpp | 28 +- .../test/unittest/types/endpoint/GuidTest.cpp | 2 +- .../test/unittest/types/topic/CMakeLists.txt | 6 +- .../unittest/types/topic/DdsTopicTest.cpp | 10 +- .../test/unittest/types/topic/TopicTest.cpp | 2 +- .../topic/WildcardDdsFilterTopicTest.cpp | 12 +- ddspipe_participants/CMakeLists.txt | 78 ++ ddspipe_participants/README.md | 53 + ...iscoveryServerParticipantConfiguration.hpp | 64 + .../EchoParticipantConfiguration.hpp | 19 +- .../InitialPeersParticipantConfiguration.hpp | 64 + .../ParticipantConfiguration.hpp | 52 + .../SimpleParticipantConfiguration.hpp | 53 + .../participant/auxiliar/BlankParticipant.hpp | 28 +- .../participant/auxiliar/EchoParticipant.hpp | 20 +- .../participant/rtps/CommonParticipant.hpp | 112 +- .../rtps/DiscoveryServerParticipant.hpp | 30 +- .../rtps/InitialPeersParticipant.hpp | 29 +- .../participant/rtps/SimpleParticipant.hpp | 23 +- .../reader/auxiliar/BaseReader.hpp | 99 +- .../reader/auxiliar/BlankReader.hpp | 32 +- .../reader/rpc/SimpleReader.hpp | 64 + .../reader/rtps/CommonReader.hpp | 62 +- .../reader/rtps/SimpleReader.hpp | 17 +- .../reader/rtps/SpecificQoSReader.hpp | 19 +- .../types/address/Address.hpp | 76 +- .../DiscoveryServerConnectionAddress.hpp | 42 +- .../types/data/RpcPayloadData.hpp | 29 +- .../types/data/RtpsPayloadData.hpp | 51 +- .../types/security/tls/TlsConfiguration.hpp | 41 +- .../writer/auxiliar/BaseWriter.hpp | 76 +- .../writer/auxiliar/BlankWriter.hpp | 17 +- .../writer/auxiliar/RtpsEchoWriter.hpp | 19 +- .../writer/rpc/SimpleWriter.hpp | 78 ++ .../writer/rtps/CommonWriter.hpp | 66 +- .../writer/rtps/MultiWriter.hpp | 51 +- .../writer/rtps/QoSSpecificWriter.hpp | 23 +- .../writer/rtps/SimpleWriter.hpp | 21 +- .../writer/rtps/filter/RepeaterDataFilter.hpp | 15 +- .../writer/rtps/filter/SelfDataFilter.hpp | 13 +- ddspipe_participants/package.xml | 32 + .../project_settings.cmake | 6 +- ddspipe_participants/src/cpp/_dummy.cpp | 8 + .../participant/auxiliar/BaseParticipant.cpp | 17 +- .../participant/auxiliar/BlankParticipant.cpp | 17 +- .../participant/auxiliar/EchoParticipant.cpp | 19 +- .../participant/auxiliar/MockParticipant.cpp | 21 +- ...iscoveryServerParticipantConfiguration.cpp | 19 +- .../InitialPeersParticipantConfiguration.cpp | 17 +- .../ParticipantConfiguration.cpp | 11 +- .../SimpleParticipantConfiguration.cpp | 9 +- .../participant/rtps/CommonParticipant.cpp | 31 +- .../rtps/DiscoveryServerParticipant.cpp | 11 +- .../rtps/InitialPeersParticipant.cpp | 9 +- .../participant/rtps/SimpleParticipant.cpp | 9 +- .../src_/cpp}/reader/auxiliar/BaseReader.cpp | 15 +- .../src_/cpp}/reader/auxiliar/BlankReader.cpp | 11 +- .../src_/cpp}/reader/rtps/CommonReader.cpp | 25 +- .../src_/cpp}/reader/rtps/SimpleReader.cpp | 11 +- .../cpp}/reader/rtps/SpecificQoSReader.cpp | 11 +- .../src_/cpp}/writer/auxiliar/BaseWriter.cpp | 13 +- .../src_/cpp}/writer/auxiliar/BlankWriter.cpp | 11 +- .../src_/cpp}/writer/auxiliar/EchoWriter.cpp | 13 +- .../src_/cpp}/writer/rtps/CommonWriter.cpp | 27 +- .../src_/cpp}/writer/rtps/MultiWriter.cpp | 19 +- .../cpp}/writer/rtps/QoSSpecificWriter.cpp | 13 +- .../src_/cpp}/writer/rtps/SimpleWriter.cpp | 17 +- .../writer/rtps/filter/RepeaterDataFilter.cpp | 9 +- .../writer/rtps/filter/RepeaterDataFilter.hpp | 15 +- .../writer/rtps/filter/SelfDataFilter.cpp | 9 +- .../writer/rtps/filter/SelfDataFilter.hpp | 13 +- ddspipe_participants/test/CMakeLists.txt | 20 + .../test/TestUtils/test_utils.cpp | 273 +++++ .../test/TestUtils/test_utils.hpp | 126 ++ .../test/blackbox/CMakeLists.txt | 17 + .../blackbox/ddsrouter_core/CMakeLists.txt | 16 + .../ddsrouter_core/dds/CMakeLists.txt | 0 .../ddsrouter_core/dds/WAN/CMakeLists.txt | 80 ++ .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 705 +++++++++++ .../blackbox/ddsrouter_core/dds/WAN/README.md | 7 + .../ddsrouter_core/dds/WAN/TEST_XFAIL.list | 8 + .../ddsrouter_core/dds/WAN/TEST_XTSAN.list | 5 + .../ddsrouter_core/dds/local/CMakeLists.txt | 84 ++ .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 329 ++++++ .../dds/local/DDSTestLocalDisposeKey.cpp | 201 ++++ .../ddsrouter_core/dds/local/README.md | 6 + .../dds/types/HelloWorld/HelloWorld.cxx | 207 ++++ .../dds/types/HelloWorld/HelloWorld.h | 216 ++++ .../dds/types/HelloWorld/HelloWorld.idl | 5 + .../HelloWorld/HelloWorldPubSubTypes.cxx | 133 +++ .../types/HelloWorld/HelloWorldPubSubTypes.h | 64 + .../types/HelloWorldKeyed/HelloWorldKeyed.cxx | 283 +++++ .../types/HelloWorldKeyed/HelloWorldKeyed.h | 249 ++++ .../types/HelloWorldKeyed/HelloWorldKeyed.idl | 6 + .../HelloWorldKeyedPubSubTypes.cxx | 170 +++ .../HelloWorldKeyedPubSubTypes.h | 98 ++ .../dds/types/test_participants.hpp | 495 ++++++++ .../ddsrouter_core/resources/tls/ca.crt | 1 + .../resources/tls/ddsrouter.crt | 1 + .../resources/tls/ddsrouter.key | 1 + .../resources/tls/dh_params.pem | 1 + .../ddsrouter_core/trivial/CMakeLists.txt | 37 + .../ddsrouter_core/trivial/TrivialTest.cpp | 170 +++ .../blackbox/implementations/CMakeLists.txt | 41 + .../implementations/ImplementationsTest.cpp | 246 ++++ .../test/unittest/CMakeLists.txt | 20 + .../unittest/_configuration/CMakeLists.txt | 37 + .../test/unittest/_configuration/TODO.md | 5 + .../_configuration/_ConfigurationTest.cpp | 668 +++++++++++ .../test/unittest/core}/CMakeLists.txt | 4 +- .../core/participants_database/CMakeLists.txt | 52 + .../ParticipantsDatabaseTest.cpp | 12 +- .../test/unittest/dynamic/CMakeLists.txt | 16 + .../AllowedTopicListTest.cpp | 502 ++++++++ .../dynamic/allowed_topic_list/CMakeLists.txt | 53 + .../dynamic/discovery_database/CMakeLists.txt | 47 + .../DiscoveryDatabaseTest.cpp | 250 ++++ .../test/unittest/efficiency/CMakeLists.txt | 0 .../efficiency/FastPayloadPoolTest.cpp | 12 +- .../efficiency/MapPayloadPoolTest.cpp | 12 +- .../unittest/efficiency/PayloadPoolTest.cpp | 8 +- .../test/unittest/types/CMakeLists.txt | 16 + .../unittest/types/endpoint/CMakeLists.txt | 86 ++ .../unittest/types/endpoint/EndpointTest.cpp | 343 ++++++ .../test/unittest/types/endpoint/GuidTest.cpp | 92 ++ .../test/unittest/types/topic/CMakeLists.txt | 109 ++ .../unittest/types/topic/DdsTopicTest.cpp | 90 ++ .../test/unittest/types/topic/TopicTest.cpp | 68 ++ .../topic/WildcardDdsFilterTopicTest.cpp | 224 ++++ ddspipe_yaml/CMakeLists.txt | 78 ++ ddspipe_yaml/README.md | 42 + .../include/ddspipe_yaml}/Yaml.hpp | 13 - .../include/ddspipe_yaml}/YamlManager.hpp | 19 +- .../include/ddspipe_yaml}/YamlReader.hpp | 21 +- .../include/ddspipe_yaml}/impl/YamlReader.ipp | 8 +- .../ddspipe_yaml}/yaml_configuration_tags.hpp | 22 +- ddspipe_yaml/package.xml | 34 + ddspipe_yaml/project_settings.cmake | 35 + .../src/cpp/YamlManager.cpp | 8 +- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 122 ++ .../src/cpp/YamlReader_participants.cpp | 258 +++++ ddspipe_yaml/src/cpp/YamlReader_types.cpp | 542 +++++++++ .../test/CMakeLists.txt | 0 .../test/TestUtils/test_utils.cpp | 4 +- .../test/TestUtils/test_utils.hpp | 6 +- .../test/unittest/CMakeLists.txt | 0 .../unittest/YamlConfigurationTestUtils.hpp | 10 +- .../unittest/configuration/CMakeLists.txt | 0 .../YamlReaderConfigurationTest.cpp | 4 +- .../test/unittest/entities/CMakeLists.txt | 0 .../unittest/entities/address/CMakeLists.txt | 0 .../address/YamlGetEntityAddressTest.cpp | 0 ...amlGetEntityDiscoveryServerAddressTest.cpp | 0 ...EntityAddressTest_get_address_defaults.ipp | 4 +- ...etEntityAddressTest_get_address_domain.ipp | 4 +- ...amlGetEntityAddressTest_get_address_ip.ipp | 4 +- .../YamlGetEntityAddressTest_get_ip.ipp | 4 +- ...amlGetEntityAddressTest_get_ip_version.ipp | 4 +- .../YamlGetEntityAddressTest_get_port.ipp | 4 +- ...tityAddressTest_get_transport_protocol.ipp | 4 +- ...YamlGetEntityAddressTest_ip_and_domain.ipp | 4 +- ...coveryServerAddressTest_get_ds_address.ipp | 4 +- ...verAddressTest_get_ds_address_negative.ipp | 4 +- .../entities/ddsrouter/CMakeLists.txt | 0 .../YamlGetConfigurationDDSRouterTest.cpp | 4 +- .../unittest/entities/guid/CMakeLists.txt | 0 .../guid/YamlGetEntityGuidPrefixTest.cpp | 4 +- .../unittest/entities/topic/CMakeLists.txt | 0 .../entities/topic/YamlGetEntityTopicTest.cpp | 8 +- .../test/unittest/participants/CMakeLists.txt | 0 ...lGetCommonParticipantConfigurationTest.cpp | 2 +- ...veryServerParticipantConfigurationTest.cpp | 0 ...itialPeersParticipantConfigurationTest.cpp | 2 +- ...lGetSimpleParticipantConfigurationTest.cpp | 2 +- ...t_get_participant_connection_addresses.ipp | 2 +- ...nfigurationTest_get_participant_domain.ipp | 2 +- ...st_get_participant_listening_addresses.ipp | 2 +- ...figurationTest_get_participant_minimum.ipp | 2 +- ...igurationTest_get_participant_negative.ipp | 2 +- ...tConfigurationTest_get_participant_tls.ipp | 2 +- .../test/unittest/yaml_manager/CMakeLists.txt | 0 .../unittest/yaml_manager/YamlManagerTest.cpp | 0 .../test/unittest/yaml_reader/CMakeLists.txt | 0 .../yaml_reader/YamlReaderScalarTest.cpp | 0 .../yaml_reader/YamlReaderTest_common.hpp | 6 +- .../test/unittest/yaml_tags/CMakeLists.txt | 0 .../test/unittest/yaml_tags/YamlTagsTest.cpp | 2 +- ddsrouter_core/README.md | 8 +- ...uration.hpp => DdsRouterConfiguration.hpp} | 62 +- ...n.hpp => DdsRouterReloadConfiguration.hpp} | 34 +- .../configuration/SpecsConfiguration.hpp | 24 +- .../core/{DDSRouter.hpp => DdsRouter.hpp} | 61 +- .../core}/ParticipantFactory.hpp | 32 +- .../ddsrouter_core/participants/.dev.md | 1 - .../participant/auxiliar/BaseParticipant.hpp | 228 ---- ...iscoveryServerParticipantConfiguration.hpp | 83 -- .../InitialPeersParticipantConfiguration.hpp | 80 -- .../ParticipantConfiguration.hpp | 70 -- .../SimpleParticipantConfiguration.hpp | 74 -- .../ddsrouter_core/types}/ParticipantKind.hpp | 15 +- .../ddsrouter_core/types/data/SharedData.hpp | 57 - .../ddsrouter_core/types/dds/DomainId.hpp | 94 -- .../types/endpoint/Endpoint.hpp | 163 --- .../types/topic/dds/DdsTopic.hpp | 131 --- ddsrouter_core/package.xml | 3 +- ddsrouter_core/project_settings.cmake | 4 +- ddsrouter_core/src/cpp/_dummy.cpp | 8 + ddsrouter_core/src/cpp/core/DDSRouter.cpp | 61 - ddsrouter_participants/README.md | 5 - .../src/cpp/ParticipantFactory.cpp | 150 --- ddsrouter_yaml/README.md | 47 +- .../YamlReaderConfiguration.hpp | 45 +- ddsrouter_yaml/package.xml | 6 +- ddsrouter_yaml/project_settings.cmake | 11 +- ddsrouter_yaml/src/cpp/YamlReader.cpp | 1030 ----------------- .../src/cpp/YamlReaderConfiguration.cpp | 178 --- ddsrouter_yaml/src/cpp/_dummy.cpp | 8 + .../src/cpp/yaml_configuration_tags.cpp | 81 -- tools/ddsrouter_tool/package.xml | 6 - tools/ddsrouter_tool/project_settings.cmake | 4 +- tools/ddsrouter_tool/src/cpp/main.cpp | 62 +- .../arguments_configuration.cpp | 2 +- .../src/cpp/user_interface/constants.hpp | 2 +- 349 files changed, 12335 insertions(+), 4731 deletions(-) rename {ddsrouter_participants => ddspipe_core}/CMakeLists.txt (100%) create mode 100644 ddspipe_core/README.md rename {ddsrouter_core/src/cpp => ddspipe_core/include/ddspipe_core}/communication/Bridge.hpp (65%) rename ddsrouter_core/src/cpp/communication/DDSBridge.hpp => ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp (67%) rename {ddsrouter_core/src/cpp/communication => ddspipe_core/include/ddspipe_core/communication/dds}/Track.hpp (88%) rename {ddsrouter_core/src/cpp => ddspipe_core/include/ddspipe_core}/communication/rpc/RPCBridge.hpp (84%) rename {ddsrouter_core/src/cpp => ddspipe_core/include/ddspipe_core}/communication/rpc/ServiceRegistry.hpp (83%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/configuration/BaseConfiguration.hpp (59%) rename ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp => ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp (76%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/dynamic/AllowedTopicList.hpp (73%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/dynamic/DiscoveryDatabase.hpp (94%) rename {ddsrouter_core/include/ddsrouter_core/core => ddspipe_core/include/ddspipe_core/dynamic}/ParticipantsDatabase.hpp (87%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/efficiency/cache_change/CacheChangePool.hpp (86%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/efficiency/payload/CopyPayloadPool.hpp (81%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/efficiency/payload/FastPayloadPool.hpp (93%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/efficiency/payload/MapPayloadPool.hpp (91%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/efficiency/payload/PayloadPool.hpp (96%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/interface/IParticipant.hpp (65%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/interface/IReader.hpp (80%) rename {ddsrouter_core/include/ddsrouter_core/types/data => ddspipe_core/include/ddspipe_core/interface}/IRoutingData.hpp (63%) create mode 100644 ddspipe_core/include/ddspipe_core/interface/ITopic.hpp rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/interface/IWriter.hpp (84%) rename {ddsrouter_yaml/test/TestUtils => ddspipe_core/include/ddspipe_core/testing}/test_utils.hpp (70%) create mode 100644 ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp create mode 100644 ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/dds/Guid.hpp (78%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/dds/GuidPrefix.hpp (80%) rename {ddsrouter_core/include/ddsrouter_core/types/data => ddspipe_core/include/ddspipe_core/types/dds}/Payload.hpp (90%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/dds/SpecificEndpointQoS.hpp (80%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/dds/TopicQoS.hpp (88%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/participant/ParticipantId.hpp (74%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/topic/Topic.hpp (52%) rename ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp => ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp (75%) create mode 100644 ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp create mode 100644 ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp rename ddsrouter_core/include/ddsrouter_core/types/topic/filter/DdsFilterTopic.hpp => ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp (66%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_core/include/ddspipe_core}/types/topic/filter/WildcardDdsFilterTopic.hpp (58%) rename ddsrouter_core/include/ddsrouter_core/types/topic/rpc/RPCTopic.hpp => ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp (84%) rename {ddsrouter_participants => ddspipe_core}/package.xml (87%) create mode 100644 ddspipe_core/project_settings.cmake create mode 100644 ddspipe_core/src/cpp/_dummy.cpp rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/communication/Bridge.cpp (96%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/communication/DDSBridge.cpp (85%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/communication/Track.cpp (98%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/communication/rpc/RPCBridge.cpp (98%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/communication/rpc/ServiceRegistry.cpp (95%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/configuration/DDSRouterConfiguration.cpp (87%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/configuration/DDSRouterReloadConfiguration.cpp (86%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/configuration/SpecsConfiguration.cpp (87%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/core/DDSRouterImpl.cpp (93%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/dynamic/AllowedTopicList.cpp (97%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/dynamic/DiscoveryDatabase.cpp (99%) rename {ddsrouter_core/src/cpp/core => ddspipe_core/src_/cpp/dynamic}/ParticipantsDatabase.cpp (96%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/efficiency/cache_change/CacheChangePool.cpp (89%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/efficiency/payload/CopyPayloadPool.cpp (93%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/efficiency/payload/FastPayloadPool.cpp (97%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/efficiency/payload/MapPayloadPool.cpp (97%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/efficiency/payload/PayloadPool.cpp (97%) rename {ddsrouter_core/test/TestUtils => ddspipe_core/src_/cpp/testing}/test_utils.cpp (96%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/address/Address.cpp (99%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/address/DiscoveryServerConnectionAddress.cpp (95%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/data/Payload.cpp (93%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/data/RtpsPayloadData.cpp (87%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/dds/DomainId.cpp (95%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/dds/Guid.cpp (93%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/dds/GuidPrefix.cpp (95%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/dds/RouterCacheChange.hpp (83%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/dds/SpecificEndpointQoS.cpp (96%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/dds/TopicQoS.cpp (97%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/endpoint/Endpoint.cpp (91%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/security/tls/TlsConfiguration.cpp (94%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/topic/Topic.cpp (68%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/topic/dds/DdsTopic.cpp (79%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/topic/filter/DdsFilterTopic.cpp (91%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp (93%) rename {ddsrouter_core/src => ddspipe_core/src_}/cpp/types/topic/rpc/RPCTopic.cpp (75%) rename {ddsrouter_core => ddspipe_core}/test/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/CMakeLists.txt (100%) create mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp (95%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/WAN/README.md (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp (93%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp (90%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/local/README.md (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h (99%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h (97%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h (97%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h (94%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp (96%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/resources/tls/ca.crt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp (77%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/implementations/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/blackbox/implementations/ImplementationsTest.cpp (89%) rename {ddsrouter_core => ddspipe_core}/test/unittest/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/_configuration/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/_configuration/TODO.md (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/_configuration/_ConfigurationTest.cpp (96%) rename {ddsrouter_core => ddspipe_core}/test/unittest/core/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/core/participants_database/CMakeLists.txt (100%) create mode 100644 ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp rename {ddsrouter_core => ddspipe_core}/test/unittest/dynamic/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp (97%) rename {ddsrouter_core => ddspipe_core}/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt (93%) rename {ddsrouter_core => ddspipe_core}/test/unittest/dynamic/discovery_database/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp (92%) create mode 100644 ddspipe_core/test/unittest/efficiency/CMakeLists.txt create mode 100644 ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp create mode 100644 ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp create mode 100644 ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp rename {ddsrouter_core => ddspipe_core}/test/unittest/types/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/endpoint/CMakeLists.txt (93%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/endpoint/EndpointTest.cpp (90%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/endpoint/GuidTest.cpp (98%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/topic/CMakeLists.txt (93%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/topic/DdsTopicTest.cpp (84%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/topic/TopicTest.cpp (97%) rename {ddsrouter_core => ddspipe_core}/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp (93%) create mode 100644 ddspipe_participants/CMakeLists.txt create mode 100644 ddspipe_participants/README.md create mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp rename {ddsrouter_core/include/ddsrouter_core/participants/participant => ddspipe_participants/include/ddspipe_participants}/configuration/EchoParticipantConfiguration.hpp (70%) create mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp create mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp create mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/participant/auxiliar/BlankParticipant.hpp (64%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/participant/auxiliar/EchoParticipant.hpp (74%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/participant/rtps/CommonParticipant.hpp (73%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/participant/rtps/DiscoveryServerParticipant.hpp (52%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/participant/rtps/InitialPeersParticipant.hpp (52%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/participant/rtps/SimpleParticipant.hpp (66%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/reader/auxiliar/BaseReader.hpp (73%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/reader/auxiliar/BlankReader.hpp (68%) create mode 100644 ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/reader/rtps/CommonReader.hpp (84%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/reader/rtps/SimpleReader.hpp (79%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/reader/rtps/SpecificQoSReader.hpp (82%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_participants/include/ddspipe_participants}/types/address/Address.hpp (80%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_participants/include/ddspipe_participants}/types/address/DiscoveryServerConnectionAddress.hpp (67%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_participants/include/ddspipe_participants}/types/data/RpcPayloadData.hpp (70%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_participants/include/ddspipe_participants}/types/data/RtpsPayloadData.hpp (60%) rename {ddsrouter_core/include/ddsrouter_core => ddspipe_participants/include/ddspipe_participants}/types/security/tls/TlsConfiguration.hpp (76%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/auxiliar/BaseWriter.hpp (75%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/auxiliar/BlankWriter.hpp (71%) rename ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp => ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp (72%) create mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/rtps/CommonWriter.hpp (83%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/rtps/MultiWriter.hpp (62%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/rtps/QoSSpecificWriter.hpp (77%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/rtps/SimpleWriter.hpp (79%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/include/ddspipe_participants}/writer/rtps/filter/RepeaterDataFilter.hpp (78%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/include/ddspipe_participants}/writer/rtps/filter/SelfDataFilter.hpp (80%) create mode 100644 ddspipe_participants/package.xml rename {ddsrouter_participants => ddspipe_participants}/project_settings.cmake (91%) create mode 100644 ddspipe_participants/src/cpp/_dummy.cpp rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/auxiliar/BaseParticipant.cpp (92%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/auxiliar/BlankParticipant.cpp (80%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/auxiliar/EchoParticipant.cpp (81%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/auxiliar/MockParticipant.cpp (81%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/configuration/DiscoveryServerParticipantConfiguration.cpp (86%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/configuration/InitialPeersParticipantConfiguration.cpp (86%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/configuration/ParticipantConfiguration.cpp (84%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/configuration/SimpleParticipantConfiguration.cpp (89%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/rtps/CommonParticipant.cpp (93%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/rtps/DiscoveryServerParticipant.cpp (98%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/rtps/InitialPeersParticipant.cpp (98%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/participant/rtps/SimpleParticipant.cpp (89%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/reader/auxiliar/BaseReader.cpp (93%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/reader/auxiliar/BlankReader.cpp (83%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/reader/rtps/CommonReader.cpp (96%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/reader/rtps/SimpleReader.cpp (88%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/reader/rtps/SpecificQoSReader.cpp (92%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/auxiliar/BaseWriter.cpp (91%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/auxiliar/BlankWriter.cpp (81%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/auxiliar/EchoWriter.cpp (88%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/CommonWriter.cpp (95%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/MultiWriter.cpp (90%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/QoSSpecificWriter.cpp (89%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/SimpleWriter.cpp (80%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/filter/RepeaterDataFilter.cpp (91%) rename {ddsrouter_core/include/ddsrouter_core/participants => ddspipe_participants/src_/cpp}/writer/rtps/filter/RepeaterDataFilter.hpp (78%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/filter/SelfDataFilter.cpp (88%) rename {ddsrouter_core/src/cpp/participants => ddspipe_participants/src_/cpp}/writer/rtps/filter/SelfDataFilter.hpp (80%) create mode 100644 ddspipe_participants/test/CMakeLists.txt create mode 100644 ddspipe_participants/test/TestUtils/test_utils.cpp create mode 100644 ddspipe_participants/test/TestUtils/test_utils.hpp create mode 100644 ddspipe_participants/test/blackbox/CMakeLists.txt create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt rename {ddsrouter_core => ddspipe_participants}/test/blackbox/ddsrouter_core/dds/CMakeLists.txt (100%) create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp create mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt create mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt create mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key create mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt create mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp create mode 100644 ddspipe_participants/test/blackbox/implementations/CMakeLists.txt create mode 100644 ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp create mode 100644 ddspipe_participants/test/unittest/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/_configuration/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/_configuration/TODO.md create mode 100644 ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp rename {ddsrouter_participants/test => ddspipe_participants/test/unittest/core}/CMakeLists.txt (84%) create mode 100644 ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt rename {ddsrouter_core => ddspipe_participants}/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp (97%) create mode 100644 ddspipe_participants/test/unittest/dynamic/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp create mode 100644 ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp rename {ddsrouter_core => ddspipe_participants}/test/unittest/efficiency/CMakeLists.txt (100%) rename {ddsrouter_core => ddspipe_participants}/test/unittest/efficiency/FastPayloadPoolTest.cpp (97%) rename {ddsrouter_core => ddspipe_participants}/test/unittest/efficiency/MapPayloadPoolTest.cpp (98%) rename {ddsrouter_core => ddspipe_participants}/test/unittest/efficiency/PayloadPoolTest.cpp (99%) create mode 100644 ddspipe_participants/test/unittest/types/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp create mode 100644 ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp create mode 100644 ddspipe_participants/test/unittest/types/topic/CMakeLists.txt create mode 100644 ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp create mode 100644 ddspipe_participants/test/unittest/types/topic/TopicTest.cpp create mode 100644 ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp create mode 100644 ddspipe_yaml/CMakeLists.txt create mode 100644 ddspipe_yaml/README.md rename {ddsrouter_yaml/include/ddsrouter_yaml => ddspipe_yaml/include/ddspipe_yaml}/Yaml.hpp (79%) rename {ddsrouter_yaml/include/ddsrouter_yaml => ddspipe_yaml/include/ddspipe_yaml}/YamlManager.hpp (72%) rename {ddsrouter_yaml/include/ddsrouter_yaml => ddspipe_yaml/include/ddspipe_yaml}/YamlReader.hpp (95%) rename {ddsrouter_yaml/include/ddsrouter_yaml => ddspipe_yaml/include/ddspipe_yaml}/impl/YamlReader.ipp (97%) rename {ddsrouter_yaml/include/ddsrouter_yaml => ddspipe_yaml/include/ddspipe_yaml}/yaml_configuration_tags.hpp (90%) create mode 100644 ddspipe_yaml/package.xml create mode 100644 ddspipe_yaml/project_settings.cmake rename {ddsrouter_yaml => ddspipe_yaml}/src/cpp/YamlManager.cpp (90%) create mode 100644 ddspipe_yaml/src/cpp/YamlReader_generic.cpp create mode 100644 ddspipe_yaml/src/cpp/YamlReader_participants.cpp create mode 100644 ddspipe_yaml/src/cpp/YamlReader_types.cpp rename {ddsrouter_yaml => ddspipe_yaml}/test/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/TestUtils/test_utils.cpp (99%) rename {ddsrouter_core => ddspipe_yaml}/test/TestUtils/test_utils.hpp (97%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/YamlConfigurationTestUtils.hpp (95%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/configuration/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/configuration/YamlReaderConfigurationTest.cpp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/YamlGetEntityAddressTest.cpp (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp (95%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp (96%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp (96%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp (94%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp (96%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp (95%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp (96%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp (95%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp (97%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/ddsrouter/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp (99%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/guid/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/topic/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp (99%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp (99%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp (99%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp (99%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp (98%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp (99%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_manager/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_manager/YamlManagerTest.cpp (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_reader/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_reader/YamlReaderScalarTest.cpp (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_reader/YamlReaderTest_common.hpp (93%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_tags/CMakeLists.txt (100%) rename {ddsrouter_yaml => ddspipe_yaml}/test/unittest/yaml_tags/YamlTagsTest.cpp (97%) rename ddsrouter_core/include/ddsrouter_core/configuration/{DDSRouterConfiguration.hpp => DdsRouterConfiguration.hpp} (53%) rename ddsrouter_core/include/ddsrouter_core/configuration/{DDSRouterReloadConfiguration.hpp => DdsRouterReloadConfiguration.hpp} (50%) rename ddsrouter_core/include/ddsrouter_core/core/{DDSRouter.hpp => DdsRouter.hpp} (67%) rename {ddsrouter_participants/include/ddsrouter_participants => ddsrouter_core/include/ddsrouter_core/core}/ParticipantFactory.hpp (58%) delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/.dev.md delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp rename {ddsrouter_participants/include/ddsrouter_participants => ddsrouter_core/include/ddsrouter_core/types}/ParticipantKind.hpp (86%) delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/dds/DomainId.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/endpoint/Endpoint.hpp delete mode 100644 ddsrouter_core/include/ddsrouter_core/types/topic/dds/DdsTopic.hpp create mode 100644 ddsrouter_core/src/cpp/_dummy.cpp delete mode 100644 ddsrouter_core/src/cpp/core/DDSRouter.cpp delete mode 100644 ddsrouter_participants/README.md delete mode 100644 ddsrouter_participants/src/cpp/ParticipantFactory.cpp delete mode 100644 ddsrouter_yaml/src/cpp/YamlReader.cpp delete mode 100644 ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp create mode 100644 ddsrouter_yaml/src/cpp/_dummy.cpp delete mode 100644 ddsrouter_yaml/src/cpp/yaml_configuration_tags.cpp diff --git a/ddsrouter_participants/CMakeLists.txt b/ddspipe_core/CMakeLists.txt similarity index 100% rename from ddsrouter_participants/CMakeLists.txt rename to ddspipe_core/CMakeLists.txt diff --git a/ddspipe_core/README.md b/ddspipe_core/README.md new file mode 100644 index 000000000..90d290c4b --- /dev/null +++ b/ddspipe_core/README.md @@ -0,0 +1,55 @@ +# eProsima DDS Router Core Library + +> TODO + +This library contain main functionality of the DDS Router. +Include module is the public API used to configure a DDS Router and to interact with a running one: + +* **Types**: data types used to configure a router. + * Address + * DDS info (Guid, Qos, Topic, etc.) + +* **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: + * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. + * *DDSRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. + * *DDSRouterReloadConfiguration*: configuration to change topics in a running DDS Router. + +* **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. + It allows to execute a DDS Router, and to interact with it while running. + +--- + +## Example of usage + +```cpp +// START AND STOP DDS ROUTER FROM CONFIGURATION + +core::configuration::DDSRouterConfiguration router_configuration; + +// ... populate router_configuration + +core::DDSRouter router(router_configuration); +router.start(); + +// ... wait for event + +router.stop(); +``` + +--- + +## Dependencies + +* `fastrtps` +* `cpp_utils` + +--- + +## How to use it in your project + +Just import library `ddsrouter_core` into your CMake project. + +```cmake +find_package(ddsrouter_core) +target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_core) +``` diff --git a/ddsrouter_core/src/cpp/communication/Bridge.hpp b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp similarity index 65% rename from ddsrouter_core/src/cpp/communication/Bridge.hpp rename to ddspipe_core/include/ddspipe_core/communication/Bridge.hpp index b29ea3105..8f8a8512b 100644 --- a/ddsrouter_core/src/cpp/communication/Bridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp @@ -12,27 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Bridge.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_COMMUNICATION_BRIDGE_HPP_ -#define __SRC_DDSROUTERCORE_COMMUNICATION_BRIDGE_HPP_ +#pragma once -#include -#include #include +#include +#include +#include + namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** - * Bridge object manages the communication of a DDS Topic (or \c RPCTopic ). + * Bridge object manages the communication of a DDS Topic (or \c RpcTopic ). * It could be seen as a channel of communication as a DDS Topic, with several Participants that * could publish or subscribe in this specific Topic. * - * It is implemented by \c DDSBridge and \c RPCBridge , which handle \c DdsTopic and \c RPCTopic , respectively. + * It is implemented by \c DdsBridge and \c RPCBridge , which handle \c DistributedTopic and \c RpcTopic , respectively. */ class Bridge { @@ -49,9 +46,18 @@ class Bridge * */ Bridge( - std::shared_ptr participants_database, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool); + const std::shared_ptr& topic, + const std::shared_ptr& participants_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool); + + /** + * Copy method not allowed + * + * Bridge creates in constructor all the inside Tracks needed, and thus it should not be copied + */ + void operator =( + const Bridge&) = delete; /** * Enable bridge @@ -65,21 +71,22 @@ class Bridge protected: + //! Topic that refers to this Bridge + const std::shared_ptr topic; + //! Collection of Participants to manage communication const std::shared_ptr participants_; //! Common shared payload pool - std::shared_ptr payload_pool_; + const std::shared_ptr payload_pool_; //! Common shared thread pool - std::shared_ptr thread_pool_; + const std::shared_ptr thread_pool_; //! Whether the Bridge is currently enabled std::atomic enabled_; }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_COMMUNICATION_BRIDGE_HPP_ */ diff --git a/ddsrouter_core/src/cpp/communication/DDSBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp similarity index 67% rename from ddsrouter_core/src/cpp/communication/DDSBridge.hpp rename to ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp index a8d3e7f06..cccf02134 100644 --- a/ddsrouter_core/src/cpp/communication/DDSBridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp @@ -12,33 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DDSBridge.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_COMMUNICATION_DDSBRIDGE_HPP_ -#define __SRC_DDSROUTERCORE_COMMUNICATION_DDSBRIDGE_HPP_ +#pragma once #include -#include - -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** - * Bridge object manages the communication of a \c DdsTopic. + * Bridge object manages the communication of a \c DistributedTopic. * It could be seen as a channel of communication as a DDS Topic, whit several Participants that * could publish or subscribe in this specific Topic. * * It contains N \c Tracks that will manage each direction of the communication, * being N the number of Participants of this communication channel. */ -class DDSBridge : public Bridge +class DdsBridge : public Bridge { public: @@ -56,30 +50,11 @@ class DDSBridge : public Bridge * * @throw InitializationException in case \c IWriters or \c IReaders creation fails. */ - DDSBridge( - const types::DdsTopic& topic, - std::shared_ptr participants_database, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool, - bool enable = false); - - /** - * @brief Destructor - * - * Before deleting, it calls \c disable. - * It deletes all the tracks created and all Writers and Readers. - */ - virtual ~DDSBridge(); - - // virtual void init_(); - - /** - * Copy method not allowed - * - * Bridge creates in constructor all the inside Tracks needed, and thus it should not be copied - */ - void operator =( - const Track&) = delete; + DdsBridge( + const std::shared_ptr& topic, + const std::shared_ptr& participants_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool); /** * Enable bridge in case it is not enabled @@ -99,13 +74,6 @@ class DDSBridge : public Bridge protected: - /** - * Topic of which this Bridge manages communication - * - * @note: This variable is only used for log - */ - const types::DdsTopic topic_; - /** * Inside \c Tracks * They are indexed by the Id of the participant that is source @@ -124,21 +92,19 @@ class DDSBridge : public Bridge // Allow operator << to use private variables friend std::ostream& operator <<( std::ostream&, - const DDSBridge&); + const DdsBridge&); }; /** - * @brief \c DDSBridge to stream serialization + * @brief \c DdsBridge to stream serialization * * This method is merely a to_string of a Bridge definition. * It serialize the topic */ std::ostream& operator <<( std::ostream& os, - const DDSBridge& bridge); + const DdsBridge& bridge); } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_COMMUNICATION_DDSBRIDGE_HPP_ */ diff --git a/ddsrouter_core/src/cpp/communication/Track.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp similarity index 88% rename from ddsrouter_core/src/cpp/communication/Track.hpp rename to ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp index 6ad28f820..8ca78f9fc 100644 --- a/ddsrouter_core/src/cpp/communication/Track.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp @@ -12,23 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Track.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_COMMUNICATION_TRACK_HPP_ -#define __SRC_DDSROUTERCORE_COMMUNICATION_TRACK_HPP_ +#pragma once #include #include -#include -#include -#include #include +#include +#include +#include +#include + namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -47,16 +44,14 @@ class Track * @param topic: Topic that this Track manages communication * @param reader: Reader that will receive the remote data * @param writers: Map of Writers that will send the data received by \c source indexed by Participant id - * @param enable: Whether the \c Track should be initialized as enabled. False by default */ Track( - const types::DdsTopic& topic, - types::ParticipantId reader_participant_id, - std::shared_ptr reader, + const std::shared_ptr& topic, + const types::ParticipantId& reader_participant_id, + const std::shared_ptr& reader, std::map>&& writers, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool, - bool enable = false) noexcept; + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool) noexcept; /** * @brief Destructor @@ -151,13 +146,6 @@ class Track */ types::ParticipantId reader_participant_id_; - /** - * Topic that this bridge manages communication - * - * @note: This variable is only used for log - */ - types::DdsTopic topic_; - //! Reader that will read data std::shared_ptr reader_; @@ -229,7 +217,5 @@ std::ostream& operator <<( const Track& track); } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_COMMUNICATION_TRACK_HPP_ */ diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp similarity index 84% rename from ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp rename to ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp index 45f37ca00..65debfb27 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RPCBridge.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_COMMUNICATION_RPC_RPCBRIDGE_HPP_ -#define __SRC_DDSROUTERCORE_COMMUNICATION_RPC_RPCBRIDGE_HPP_ +#pragma once #include #include @@ -25,21 +20,18 @@ #include #include -#include - -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** - * Bridge object manages the communication of a \c RPCTopic. + * Bridge object manages the communication of a \c RpcTopic. * * Contains a proxy server and client in each participant. * @@ -65,7 +57,7 @@ class RPCBridge : public Bridge * @note Always created disabled, manual enable required. First enable creates all endpoints. */ RPCBridge( - const types::RPCTopic& topic, + const types::RpcTopic& topic, std::shared_ptr participants_database, std::shared_ptr payload_pool, std::shared_ptr thread_pool); @@ -111,7 +103,7 @@ class RPCBridge : public Bridge * * Called only once in execution (controlled by \c init_ flag). * - * @throw InitializationException in case \c IWriters or \c participants::rtps::CommonReaders creation fails. + * @throw InitializationException in case \c IWriters or \c IReaders creation fails. */ void init_nts_(); // throws exception, caught in enable @@ -120,7 +112,7 @@ class RPCBridge : public Bridge * * @param participant_id: Participant where proxy server is to be created * - * @throw InitializationException in case \c IWriters or \c participants::rtps::CommonReaders creation fails. + * @throw InitializationException in case \c IWriters or \c IReaders creation fails. */ void create_proxy_server_nts_( types::ParticipantId participant_id); @@ -131,14 +123,14 @@ class RPCBridge : public Bridge * * @param participant_id: Participant where proxy client is to be created * - * @throw InitializationException in case \c IWriters or \c participants::rtps::CommonReaders creation fails. + * @throw InitializationException in case \c IWriters or \c IReaders creation fails. */ void create_proxy_client_nts_( types::ParticipantId participant_id); //! Create slot in the thread pool for this reader void create_slot_( - std::shared_ptr reader) noexcept; + std::shared_ptr reader) noexcept; //! Callback to execute when a new cache change is added to this reader void data_available_( @@ -155,23 +147,23 @@ class RPCBridge : public Bridge * topic being blocked). */ void transmit_( - std::shared_ptr reader) noexcept; + std::shared_ptr reader) noexcept; //! Whether there are any servers in the database bool servers_available_() const noexcept; - //! RPCTopic (service) that this bridge manages communication - const types::RPCTopic topic_; + //! RpcTopic (service) that this bridge manages communication + const types::RpcTopic topic_; //! Flag set to true when proxy clients and servers are created, so it can only be done once bool init_; //! Proxy servers endpoints - std::map> request_readers_; + std::map> request_readers_; std::map> reply_writers_; //! Proxy clients endpoints - std::map> reply_readers_; + std::map> reply_readers_; std::map> request_writers_; //! Map readers' GUIDs to their associated thread pool tasks, and also keep a task emission flag. @@ -213,7 +205,5 @@ std::ostream& operator <<( const RPCBridge& bridge); } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_COMMUNICATION_RPC_RPCBRIDGE_HPP_ */ diff --git a/ddsrouter_core/src/cpp/communication/rpc/ServiceRegistry.hpp b/ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp similarity index 83% rename from ddsrouter_core/src/cpp/communication/rpc/ServiceRegistry.hpp rename to ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp index 970b1a444..d69bd417e 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/ServiceRegistry.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp @@ -10,14 +10,9 @@ // 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. +// limitations under the License\. -/** - * @file ServiceRegistry.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_DDS_SERVICEREGISTRY_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_SERVICEREGISTRY_HPP_ +#pragma once #include #include @@ -25,12 +20,12 @@ #include -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using SampleIdentity = eprosima::fastrtps::rtps::SampleIdentity; @@ -60,7 +55,7 @@ class ServiceRegistry * @note Always created disabled. It is first enabled when a server is discovered. */ ServiceRegistry( - const types::RPCTopic& topic, + const types::RpcTopic& topic, const types::ParticipantId& participant_id); //! Enable registry @@ -87,16 +82,16 @@ class ServiceRegistry void erase( SequenceNumber idx) noexcept; - //! RPCTopic getter - types::RPCTopic topic() const noexcept; + //! RpcTopic getter + types::RpcTopic topic() const noexcept; //! Get \c mutex_ std::recursive_mutex& get_mutex() noexcept; protected: - //! RPCTopic (service) that this ServiceRegistry manages communication - types::RPCTopic topic_; + //! RpcTopic (service) that this ServiceRegistry manages communication + types::RpcTopic topic_; //! Id of participant for which this registry is created types::ParticipantId participant_id_; @@ -115,7 +110,5 @@ class ServiceRegistry }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_SERVICEREGISTRY_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp b/ddspipe_core/include/ddspipe_core/configuration/BaseConfiguration.hpp similarity index 59% rename from ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp rename to ddspipe_core/include/ddspipe_core/configuration/BaseConfiguration.hpp index 3d6edc6a6..210c6a86e 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp +++ b/ddspipe_core/include/ddspipe_core/configuration/BaseConfiguration.hpp @@ -12,36 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BaseConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_BASECONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_BASECONFIGURATION_HPP_ +#pragma once #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { -namespace configuration { /** - * Configurations in DDS Router are data structures with public access to its internal methods. + * Configurations in DDS Pipe are data structures with public access to its internal methods. * Thus, they are not forced to be correct in construction. - * This is an Interface class that forces every configuration in ddsrouter to have an \c is_valid method. + * This is an Interface class that forces every configuration to have an \c is_valid method. */ struct BaseConfiguration { - DDSROUTER_CORE_DllAPI virtual bool is_valid( + DDSPIPE_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept = 0; }; -} /* namespace configuration */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_BASECONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp similarity index 76% rename from ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp rename to ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp index 259ba5d93..dafc57666 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.hpp +++ b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp @@ -10,49 +10,42 @@ // 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. +// limitations under the License\. -/** - * @file DDSRouterImpl.hpp - */ - -#ifndef __SRC__SRC_DDSROUTERCORE_CORE_DDSROUTERIMPL_HPP_ -#define __SRC__SRC_DDSROUTERCORE_CORE_DDSROUTERIMPL_HPP_ +#pragma once -#include -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** * TODO */ -class DDSRouterImpl +class DdsPipe { public: + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + /** - * @brief Construct a new DDSRouterImpl object + * @brief Construct a new DdsPipe object * - * Initialize a whole DDSRouterImpl: + * Initialize a whole DdsPipe: * - Create its associated AllowedTopicList * - Create Participants and add them to \c ParticipantsDatabase * - Create the Bridges for (allowed) builtin topics @@ -61,23 +54,30 @@ class DDSRouterImpl * * @throw \c ConfigurationException in case the yaml inside allowlist is not well-formed * @throw \c InitializationException in case \c IParticipants , \c IWriters or \c IReaders creation fails. + * + * @todo change SlotThreadPool for a IThreadPool when exist. */ - DDSRouterImpl( - const configuration::DDSRouterConfiguration& configuration, + DDSPIPE_CORE_DllAPI DdsPipe( + const std::shared_ptr& allowed_topics, const std::shared_ptr& discovery_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& participants_database); + const std::shared_ptr& payload_pool, + const std::shared_ptr& participants_database, + const std::shared_ptr& thread_pool, + const std::set>& builtin_topics = {}); /** - * @brief Destroy the DDSRouterImpl object + * @brief Destroy the DdsPipe object * - * Stop the DDSRouterImpl + * Stop the DdsPipe * Destroy all Bridges * Destroy all Participants */ - virtual ~DDSRouterImpl(); + DDSPIPE_CORE_DllAPI ~DdsPipe(); + + ///////////////////////// + // INTERACTION METHODS + ///////////////////////// - // EVENTS /** * @brief Reload the allowed topic configuration * @@ -89,8 +89,12 @@ class DDSRouterImpl * * @throw \c ConfigurationException in case the new yaml is not well-formed */ - utils::ReturnCode reload_configuration( - const configuration::DDSRouterReloadConfiguration& configuration); + DDSPIPE_CORE_DllAPI utils::ReturnCode reload_allowed_topics( + const std::shared_ptr& allowed_topics); + + ///////////////////////// + // ENABLING METHODS + ///////////////////////// /** * @brief Start communication in DDS Router @@ -101,7 +105,7 @@ class DDSRouterImpl * * @return \c RETCODE_OK always */ - utils::ReturnCode start() noexcept; + DDSPIPE_CORE_DllAPI utils::ReturnCode start() noexcept; /** * @brief Stop communication in DDS Router @@ -112,7 +116,7 @@ class DDSRouterImpl * * @return \c RETCODE_OK always */ - utils::ReturnCode stop() noexcept; + DDSPIPE_CORE_DllAPI utils::ReturnCode stop() noexcept; protected: @@ -169,7 +173,7 @@ class DDSRouterImpl * @param [in] topic : topic discovered */ void discovered_topic_( - const types::DdsTopic& topic) noexcept; + const types::DistributedTopic& topic) noexcept; /** * @brief Method called every time a new endpoint (corresponding to a server) has been discovered/updated @@ -184,7 +188,7 @@ class DDSRouterImpl * @param [in] server_guid_prefix : GUID Prefix of discovered server */ void discovered_service_( - const types::RPCTopic& topic, + const types::RpcTopic& topic, const types::ParticipantId& server_participant_id, const types::GuidPrefix& server_guid_prefix) noexcept; @@ -198,7 +202,7 @@ class DDSRouterImpl * @param [in] server_guid_prefix : GUID Prefix of discovered server */ void removed_service_( - const types::RPCTopic& topic, + const types::RpcTopic& topic, const types::ParticipantId& server_participant_id, const types::GuidPrefix& server_guid_prefix) noexcept; @@ -221,14 +225,14 @@ class DDSRouterImpl const types::Endpoint& endpoint) noexcept; /** - * @brief Create a new \c DDSBridge object + * @brief Create a new \c DdsBridge object * * It is created enabled if the DDSRouterImpl is enabled. * * @param [in] topic : new topic */ void create_new_bridge( - const types::DdsTopic& topic, + const types::DistributedTopic& topic, bool enabled = false) noexcept; /** @@ -239,7 +243,7 @@ class DDSRouterImpl * @param [in] topic : new topic */ void create_new_service( - const types::RPCTopic& topic) noexcept; + const types::RpcTopic& topic) noexcept; /** * @brief Enable a specific topic @@ -249,7 +253,7 @@ class DDSRouterImpl * @param [in] topic : Topic to be enabled */ void activate_topic_( - const types::DdsTopic& topic) noexcept; + const types::DistributedTopic& topic) noexcept; /** * @brief Disable a specific topic. @@ -259,7 +263,7 @@ class DDSRouterImpl * @param [in] topic : Topic to be disabled */ void deactivate_topic_( - const types::DdsTopic& topic) noexcept; + const types::DistributedTopic& topic) noexcept; /** * @brief Activate all Topics that are allowed by the allowed topics list @@ -271,8 +275,21 @@ class DDSRouterImpl */ void deactivate_all_topics_() noexcept; - ///// - // DATA STORAGE + ///////////////////////// + // SHARED DATA STORAGE + ///////////////////////// + + //! List of allowed and blocked topics + std::shared_ptr allowed_topics_; + + /** + * @brief Common discovery database + * + * This object is shared by every Participant. + * Every time an endpoint is discovered by any Participant, it should be + * added to the database. + */ + std::shared_ptr discovery_database_; /** * @brief Common payload pool where every payload will be stored @@ -288,20 +305,18 @@ class DDSRouterImpl */ std::shared_ptr participants_database_; - /** - * @brief Common discovery database - * - * This object is shared by every Participant. - * Every time an endpoint is discovered by any Participant, it should be - * added to the database. - */ - std::shared_ptr discovery_database_; + //! Thread Pool for tracks + std::shared_ptr thread_pool_; + + ///////////////////////// + // INTERNAL DATA STORAGE + ///////////////////////// //! Map of bridges indexed by their topic - std::map> bridges_; + std::map> bridges_; //! Map of RPC bridges indexed by their topic - std::map> rpc_bridges_; + std::map> rpc_bridges_; /** * @brief List of topics discovered @@ -309,7 +324,7 @@ class DDSRouterImpl * Every topic discovered would be added to this map. * If the value is true, it means this topic is currently activated. */ - std::map current_topics_; + std::map current_topics_; /** * @brief List of RPC topics discovered @@ -317,13 +332,7 @@ class DDSRouterImpl * Every RPC topic discovered would is added to this map. * If the value is true, it means this service is allowed. */ - std::map current_services_; - - //! DDSRouterImpl configuration - configuration::DDSRouterConfiguration configuration_; - - //! List of allowed and blocked topics - AllowedTopicList allowed_topics_; + std::map current_services_; ///// // AUXILIAR VARIABLES @@ -332,13 +341,9 @@ class DDSRouterImpl std::atomic enabled_; //! Internal mutex for concurrent calls - std::recursive_mutex mutex_; - - std::shared_ptr thread_pool_; + std::mutex mutex_; }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC__SRC_DDSROUTERCORE_CORE_DDSROUTERIMPL_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/dynamic/AllowedTopicList.hpp b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp similarity index 73% rename from ddsrouter_core/include/ddsrouter_core/dynamic/AllowedTopicList.hpp rename to ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp index 8c9bc8876..229197193 100644 --- a/ddsrouter_core/include/ddsrouter_core/dynamic/AllowedTopicList.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file AllowedTopicList.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_DYNAMIC_ALLOWEDTOPICLIST_HPP_ -#define __SRC_DDSROUTERCORE_DYNAMIC_ALLOWEDTOPICLIST_HPP_ +#pragma once #include #include @@ -25,13 +20,13 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -51,8 +46,8 @@ class AllowedTopicList //! Constructor by initialization lists AllowedTopicList( - const std::set>& allowlist, - const std::set>& blocklist) noexcept; + const std::set>& allowlist, + const std::set>& blocklist) noexcept; //! Copy constructor. It copies internal lists. AllowedTopicList& operator =( @@ -77,12 +72,12 @@ class AllowedTopicList * @return True if the topic is allowed, false otherwise */ bool is_topic_allowed( - const types::DdsTopic& topic) const noexcept; + const types::DistributedTopic& topic) const noexcept; /** - * Whether RPCTopic \c topic is allowed by the lists that constitute this object + * Whether RpcTopic \c topic is allowed by the lists that constitute this object * - * For a RPCTopic to be allowed it must: + * For a RpcTopic to be allowed it must: * 1. Request topic allowed * 2. Reply topic allowed * @@ -91,7 +86,7 @@ class AllowedTopicList * @return True if the topic is allowed, false otherwise */ bool is_service_allowed( - const types::RPCTopic& topic) const noexcept; + const types::RpcTopic& topic) const noexcept; /** * Equal operator. @@ -99,7 +94,7 @@ class AllowedTopicList * Two lists are the same if they have the same topics stored. * * @todo: Two lists are the same when they filter the same topics. Thus, method \c contains in - * \c DdsFilterTopic must be implemented completely. + * \c IFilterTopic must be implemented completely. * * @param other: other \c AllowedTopicList object to compare with \c this * @@ -116,14 +111,14 @@ class AllowedTopicList * @param [in] list: list of topics with redundancy * @return Set of topics without redundancy */ - static std::set> get_topic_list_without_repetition_( - const std::set>& list) noexcept; + static std::set> get_topic_list_without_repetition_( + const std::set>& list) noexcept; //! List of topics that are not allowed - std::set> blocklist_; + std::set> blocklist_; //! List of topics that are allowed - std::set> allowlist_; + std::set> allowlist_; //! Mutex to restrict access to the class mutable std::recursive_mutex mutex_; @@ -140,7 +135,5 @@ std::ostream& operator <<( const AllowedTopicList& atl); } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_TOPIC_ALLOWEDTOPICLIST_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/dynamic/DiscoveryDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp similarity index 94% rename from ddsrouter_core/include/ddsrouter_core/dynamic/DiscoveryDatabase.hpp rename to ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp index e1eb303a1..aa65944c6 100644 --- a/ddsrouter_core/include/ddsrouter_core/dynamic/DiscoveryDatabase.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DiscoveryDatabase.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_DYNAMIC_DISCOVERYDATABASE_HPP_ -#define __SRC_DDSROUTERCORE_DYNAMIC_DISCOVERYDATABASE_HPP_ +#pragma once #include #include @@ -30,13 +25,13 @@ #include -#include -#include +#include +#include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { //! Operations to perform on a DiscoveryDatabase @@ -95,7 +90,7 @@ class DiscoveryDatabase * @return true if any endpoint has this topic, false otherwise */ bool topic_exists( - const types::DdsTopic& topic) const noexcept; + const types::DistributedTopic& topic) const noexcept; //! Whether this guid is in the database bool endpoint_exists( @@ -258,7 +253,5 @@ class DiscoveryDatabase }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_DYNAMIC_DISCOVERYDATABASE_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp similarity index 87% rename from ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp rename to ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp index ff6264620..23e59e5d2 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/ParticipantsDatabase.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp @@ -12,22 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file ParticipantsDatabase.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_CORE_PARTICIPANTSDATABASE_HPP_ -#define __SRC_DDSROUTERCORE_CORE_PARTICIPANTSDATABASE_HPP_ +#pragma once #include #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -106,7 +101,5 @@ class ParticipantsDatabase }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_CORE_PARTICIPANTSDATABASE_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/efficiency/cache_change/CacheChangePool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp similarity index 86% rename from ddsrouter_core/include/ddsrouter_core/efficiency/cache_change/CacheChangePool.hpp rename to ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp index ba74b51af..88b62477e 100644 --- a/ddsrouter_core/include/ddsrouter_core/efficiency/cache_change/CacheChangePool.hpp +++ b/ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CacheChangePool.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_EFFICIENCY_CACHECHANGE_CACHACHANGEPOOL_HPP_ -#define __SRC_DDSROUTERCORE_EFFICIENCY_CACHECHANGE_CACHACHANGEPOOL_HPP_ +#pragma once #include @@ -25,7 +20,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -65,7 +60,5 @@ class CacheChangePool : public fastrtps::rtps::IChangePool, public utils::Unboun }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_EFFICIENCY_CACHECHANGE_CACHACHANGEPOOL_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/CopyPayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp similarity index 81% rename from ddsrouter_core/include/ddsrouter_core/efficiency/payload/CopyPayloadPool.hpp rename to ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp index 8ca8ec289..0dd16a707 100644 --- a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/CopyPayloadPool.hpp +++ b/ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CopyPayloadPool.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_COPYPAYLOADPOOL_HPP_ -#define __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_COPYPAYLOADPOOL_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -54,7 +49,5 @@ class CopyPayloadPool : public PayloadPool }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_COPYPAYLOADPOOL_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/FastPayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp similarity index 93% rename from ddsrouter_core/include/ddsrouter_core/efficiency/payload/FastPayloadPool.hpp rename to ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp index dbf2b3808..be4190067 100644 --- a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/FastPayloadPool.hpp +++ b/ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp @@ -12,21 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file FastPayloadPool.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_FASTPAYLOADPOOL_HPP_ -#define __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_FASTPAYLOADPOOL_HPP_ +#pragma once #include #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -144,7 +139,5 @@ class FastPayloadPool : public PayloadPool }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_FASTPAYLOADPOOL_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/MapPayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp similarity index 91% rename from ddsrouter_core/include/ddsrouter_core/efficiency/payload/MapPayloadPool.hpp rename to ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp index 657865595..ee2a38016 100644 --- a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/MapPayloadPool.hpp +++ b/ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp @@ -12,21 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file MapPayloadPool.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_MAPPAYLOADPOOL_HPP_ -#define __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_MAPPAYLOADPOOL_HPP_ +#pragma once #include #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -113,7 +108,5 @@ class MapPayloadPool : public PayloadPool }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_MAPPAYLOADPOOL_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp similarity index 96% rename from ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp rename to ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp index 695d823d5..3c1207fe6 100644 --- a/ddsrouter_core/include/ddsrouter_core/efficiency/payload/PayloadPool.hpp +++ b/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file PayloadPool.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_PAYLOADPOOL_HPP_ -#define __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_PAYLOADPOOL_HPP_ +#pragma once #include @@ -25,10 +20,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -242,7 +237,5 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_EFFICIENCY_PAYLOAD_PAYLOADPOOL_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/interface/IParticipant.hpp b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp similarity index 65% rename from ddsrouter_core/include/ddsrouter_core/interface/IParticipant.hpp rename to ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp index bcc0eb239..095d2d13b 100644 --- a/ddsrouter_core/include/ddsrouter_core/interface/IParticipant.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp @@ -12,22 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file IParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IPARTICIPANT_HPP_ +#pragma once -#include -#include - -#include -#include -#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -44,6 +37,11 @@ class IParticipant { public: + /** + * @brief Virtual dtor to allow inheritance. + */ + virtual ~IParticipant() = default; + /** * @brief Return the unique identifier of this Participant. * @@ -72,7 +70,7 @@ class IParticipant * @throw \c InitializationException in case the writer creation fails. */ virtual std::shared_ptr create_writer( - types::DdsTopic topic) = 0; + const ITopic& topic) = 0; /** * @brief Return a new Reader @@ -87,35 +85,9 @@ class IParticipant * @throw \c InitializationException in case the reader creation fails. */ virtual std::shared_ptr create_reader( - types::DdsTopic topic) = 0; - - /** - * @brief Delete Writer - * - * This method deletes a Writer that has been created by this Participant. - * - * @note This method should be able to destroy the Writer as it should not have any other reference. - * - * @param [in] writer : Writer to delete - */ - virtual void delete_writer( - std::shared_ptr writer) noexcept = 0; - - /** - * @brief Delete Reader - * - * This method deletes a Reader that has been created by this Participant. - * - * @note This method should be able to destroy the Reader as it should not have any other reference. - * - * @param [in] writer : Reader to delete - */ - virtual void delete_reader( - std::shared_ptr reader) noexcept = 0; + const ITopic& topic) = 0; }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/interface/IReader.hpp b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp similarity index 80% rename from ddsrouter_core/include/ddsrouter_core/interface/IReader.hpp rename to ddspipe_core/include/ddspipe_core/interface/IReader.hpp index ee2b50326..3ba8018a5 100644 --- a/ddsrouter_core/include/ddsrouter_core/interface/IReader.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp @@ -12,24 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file IReader.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_READER_IDDS_ROUTERREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IDDS_ROUTERREADER_HPP_ +#pragma once #include -#include +#include -#include -#include +#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -47,6 +42,11 @@ class IReader { public: + /** + * @brief Virtual dtor to allow inheritance. + */ + virtual ~IReader() = default; + /** * @brief Enable Reader * @@ -100,11 +100,24 @@ class IReader * @return \c RETCODE_NOT_ENABLED if the reader is not enabled (this should not happen) */ virtual utils::ReturnCode take( - std::unique_ptr& data) noexcept = 0; + std::unique_ptr& data) noexcept = 0; + + ///////////////////////// + // RPC REQUIRED METHODS + ///////////////////////// + // TODO remove these methods once the double reference is solved + + //! Get GUID of internal RTPS reader + virtual core::types::Guid guid() const noexcept = 0; + + //! Get internal RTPS reader mutex + virtual fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept = 0; + + //! Get number of unread cache changes in internal RTPS reader + virtual uint64_t get_unread_count() const noexcept = 0; + ///////////////////////// }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IDDS_ROUTERREADER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp similarity index 63% rename from ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp rename to ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp index ff0eec584..a0ade635d 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/IRoutingData.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp @@ -12,18 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file IRoutingData.hpp - */ #pragma once -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { -namespace types { /** * @brief TODO @@ -34,12 +31,17 @@ class IRoutingData public: /** - * @brief Virtual dtor. + * @brief Virtual dtor to allow inheritance. */ virtual ~IRoutingData() = default; + + /** + * This refers to an internal used identifier that declares which kind of data type is going to be + * transmitted in this Itopic inside the core. + */ + const types::TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept; }; -} /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp new file mode 100644 index 000000000..4a79fd57f --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp @@ -0,0 +1,65 @@ +// Copyright 2021 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\. + +#pragma once + +#include +#include + +#include + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { + +/** + * Generic data struct that represents an ITopic of data flow in the Router. + */ +class ITopic +{ +public: + + /** + * @brief Virtual dtor to allow inheritance. + */ + virtual ~ITopic() = default; + + /** + * @brief Compare 2 ITopics + * + * @note this method should be specialized for each subclass so it can differentiate between specific fields. + * 2 different Topic kinds should not have same discriminator, and if possible same topic name. + * + * @param [in] other other topic to compare this with + * @return true if both topics are the same + * @return false otherwise + */ + virtual bool operator==(const ITopic& other) const noexcept; + + //! ITopic name + virtual const std::string& topic_name() const noexcept = 0; + + /** + * This refers to an internal used identifier that declares which kind of data type is going to be + * transmitted in this Itopic inside the core. + */ + virtual const types::TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept = 0; +}; + +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/interface/IWriter.hpp b/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp similarity index 84% rename from ddsrouter_core/include/ddsrouter_core/interface/IWriter.hpp rename to ddspipe_core/include/ddspipe_core/interface/IWriter.hpp index f012c7337..38ea88b64 100644 --- a/ddsrouter_core/include/ddsrouter_core/interface/IWriter.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp @@ -12,22 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file IWriter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_WRITER_IDDS_ROUTERWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IDDS_ROUTERWRITER_HPP_ +#pragma once #include -#include -#include - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { /** @@ -44,6 +36,11 @@ class IWriter { public: + /** + * @brief Virtual dtor to allow inheritance. + */ + virtual ~IWriter() = default; + /** * @brief Enable Writer * @@ -80,11 +77,9 @@ class IWriter * @return \c RETCODE_NOT_ENABLED if the writer is not enabled (this should not happen) */ virtual utils::ReturnCode write( - types::IRoutingData& data) noexcept = 0; + IRoutingData& data) noexcept = 0; }; } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IDDS_ROUTERWRITER_HPP_ */ diff --git a/ddsrouter_yaml/test/TestUtils/test_utils.hpp b/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp similarity index 70% rename from ddsrouter_yaml/test/TestUtils/test_utils.hpp rename to ddspipe_core/include/ddspipe_core/testing/test_utils.hpp index 388c25039..31b3aba69 100644 --- a/ddsrouter_yaml/test/TestUtils/test_utils.hpp +++ b/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp @@ -10,30 +10,27 @@ // 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. +// limitations under the License\. -/** - * @file test_utils.hpp - */ +#pragma once -#ifndef _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ -#define _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace eprosima { -namespace ddsrouter { +namespace ddspipe { +namespace core { namespace test { using namespace eprosima::ddsrouter::core::types; @@ -94,7 +91,7 @@ struct WildcardTopicInput : public TopicInput bool type_set; }; -std::set> topic_set( +std::set> topic_set( std::vector topics); std::set> topic_set( @@ -127,7 +124,6 @@ ParticipantKind random_participant_kind( uint16_t seed = 0); } /* namespace test */ -} /* namespace ddsrouter */ +} /* namespace core */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp new file mode 100644 index 000000000..31d996ed4 --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp @@ -0,0 +1,66 @@ +// Copyright 2021 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\. + +#pragma once + +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { + +// Use FastDDS Domain Id type +using DomainIdType = eprosima::fastdds::dds::DomainId_t; + +/** + * @brief RTPS Domain ID. + */ +struct DomainId +{ + + DDSPIPE_CORE_DllAPI DomainId (); + + DDSPIPE_CORE_DllAPI DomainId (bool discovery_server) noexcept; + + DDSPIPE_CORE_DllAPI operator DomainIdType() const noexcept; + + //! Value of Fast DDS Domain ID + DomainIdType domain_id = DEFAULT_DOMAIN_ID; + + ///////////////////////// + // STATIC CONST VALUES + ///////////////////////// + + //! Default value for Simple Discovery + static constexpr const DomainIdType DEFAULT_DOMAIN_ID = 0; + + //! Default value for Discovery Server + static constexpr const DomainIdType DEFAULT_DISCOVERY_SERVER_DOMAIN_ID = 66; + + //! Maximum Domain Id valid + static constexpr const DomainIdType MAX_DOMAIN_ID = 223; +}; + +//! \c DomainId serializator +DDSPIPE_CORE_DllAPI std::ostream& operator <<( + std::ostream& output, + const DomainId& domain); + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp new file mode 100644 index 000000000..97436de5a --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp @@ -0,0 +1,98 @@ +// Copyright 2021 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\. + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { + +using EndpointKindType = unsigned int; + +//! Possible kinds of the endpoint +ENUMERATION_BUILDER( + EndpointKind, + invalid, + writer, + reader + ); + +/** + * Data collection to describe an Endpoint + * + * This class works as a data storage struct with the information of a discovered Endpoint + */ +struct Endpoint +{ + + //! Default Endpoint that returns an invalid one + DDSPIPE_CORE_DllAPI Endpoint() noexcept; + + /******************** + * SPECIFIC GETTERS * + ********************/ + + //! Whether the endpoint is a writer + DDSPIPE_CORE_DllAPI bool is_writer() const noexcept; + + //! Whether the endpoint is a reader + DDSPIPE_CORE_DllAPI bool is_reader() const noexcept; + + //! Whether the endpoint belongs to a RPC server (i.e. is request reader or reply writer) + DDSPIPE_CORE_DllAPI bool is_server_endpoint() const noexcept; + + //! Equality operator (does not take \c active and \c discoverer_participant_id into consideration) + DDSPIPE_CORE_DllAPI bool operator ==( + const Endpoint& other) const noexcept; + + //! Kind of the endpoint + EndpointKind kind; + + //! Unique id of the endpoint + Guid guid; + + //! Topic that this endpoint belongs to + DistributedTopic topic; + + //! Specific QoS of the entity + SpecificEndpointQoS specific_qos; + + //! Whether the endpoint is currently active + bool active; + + //! Id of participant who discovered this endpoint + ParticipantId discoverer_participant_id; +}; + +/** + * @brief \c Endpoint to stream serialization + */ +DDSPIPE_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const Endpoint& endpoint); + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/Guid.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp similarity index 78% rename from ddsrouter_core/include/ddsrouter_core/types/dds/Guid.hpp rename to ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp index f63d498c5..61a7a9b66 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/Guid.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp @@ -10,27 +10,22 @@ // 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. +// limitations under the License\. -/** - * @file Guid.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_DDS_GUID_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_GUID_HPP_ +#pragma once #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { //! Unique Id of every Endpoint -class DDSROUTER_CORE_DllAPI Guid : public fastrtps::rtps::GUID_t +class DDSPIPE_CORE_DllAPI Guid : public fastrtps::rtps::GUID_t { public: @@ -65,7 +60,5 @@ class DDSROUTER_CORE_DllAPI Guid : public fastrtps::rtps::GUID_t } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_GUID_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/GuidPrefix.hpp b/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp similarity index 80% rename from ddsrouter_core/include/ddsrouter_core/types/dds/GuidPrefix.hpp rename to ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp index cbc04cee7..955960c2d 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/GuidPrefix.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp @@ -10,21 +10,16 @@ // 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. +// limitations under the License\. -/** - * @file GuidPrefix.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_DDS_GUIDPREFIX_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_GUIDPREFIX_HPP_ +#pragma once #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -34,7 +29,7 @@ namespace types { * This class extends the \c GuidPrefix_t class in FastDDS, which is a RTPS Participant Unique Id. * This class does not belong to class \c Guid due to a design flaw in OOP (parallel hierarchy is the future). */ -class DDSROUTER_CORE_DllAPI GuidPrefix : public fastrtps::rtps::GuidPrefix_t +class DDSPIPE_CORE_DllAPI GuidPrefix : public fastrtps::rtps::GuidPrefix_t { public: @@ -95,25 +90,14 @@ class DDSROUTER_CORE_DllAPI GuidPrefix : public fastrtps::rtps::GuidPrefix_t GuidPrefix& operator = ( const fastrtps::rtps::GuidPrefix_t& other) noexcept; - /** - * Whether the guid prefix is a valid one - * - * To be valid, the GuidPrefix must not be unknown - */ - bool is_valid() const noexcept; - -protected: - //! Default DDSRouter Discovery Server Guid Prefix - static const char* SERVER_DEFAULT_GUID_PREFIX_STR_; // 01.0f.00.00.00.00.00.00.00.00.ca.fe + static constexpr const char* SERVER_DEFAULT_GUID_PREFIX_STR = "01.0f.00.00.00.00.00.00.00.00.ca.fe"; //! Default ROS2 Discovery Server Guid Prefix - static const char* ROS_DISCOVERY_SERVER_GUID_PREFIX_STR_; // 44.53.00.5f.45.50.52.4f.53.49.4d.41 + static constexpr const char* ROS_DISCOVERY_SERVER_GUID_PREFIX_STR = "44.53.00.5f.45.50.52.4f.53.49.4d.41"; }; } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_GUIDPREFIX_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/Payload.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp similarity index 90% rename from ddsrouter_core/include/ddsrouter_core/types/data/Payload.hpp rename to ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp index 95c936651..c5cebf6b1 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/Payload.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Payload.hpp - */ #pragma once @@ -27,10 +24,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -56,16 +53,16 @@ using PayloadUnit = eprosima::fastrtps::rtps::octet; using Payload = eprosima::fastrtps::rtps::SerializedPayload_t; //! \c octet to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const PayloadUnit& octet); //! \c SerializedPayload_t to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const Payload& payload); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/SpecificEndpointQoS.hpp b/ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp similarity index 80% rename from ddsrouter_core/include/ddsrouter_core/types/dds/SpecificEndpointQoS.hpp rename to ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp index c34df5bbf..d5da28dbe 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/SpecificEndpointQoS.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp @@ -10,23 +10,18 @@ // 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. +// limitations under the License\. -/** - * @file SpecificEndpointQoS.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_ENDPOINT_SpecificEndpointQoS_HPP_ -#define _DDSROUTERCORE_TYPES_ENDPOINT_SpecificEndpointQoS_HPP_ +#pragma once #include #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -41,7 +36,7 @@ using OwnershipStrengthQosPolicy = eprosima::fastdds::dds::OwnershipStrengthQosP * * @todo Divide this in Common, Reader and Writer QoS */ -struct DDSROUTER_CORE_DllAPI SpecificEndpointQoS +struct DDSPIPE_CORE_DllAPI SpecificEndpointQoS { ///////////////////////// // CONSTRUCTORS @@ -76,27 +71,25 @@ struct DDSROUTER_CORE_DllAPI SpecificEndpointQoS /** * @brief \c PartitionQosPolicy to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const PartitionQosPolicy& qos); /** * @brief \c OwnershipStrengthQosPolicy to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const OwnershipStrengthQosPolicy& qos); /** * @brief \c SpecificEndpointQoS to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const SpecificEndpointQoS& qos); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_ENDPOINT_SpecificEndpointQoS_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/TopicQoS.hpp b/ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp similarity index 88% rename from ddsrouter_core/include/ddsrouter_core/types/dds/TopicQoS.hpp rename to ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp index 72ccf9042..719cf6f9d 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/TopicQoS.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp @@ -10,22 +10,17 @@ // 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. +// limitations under the License\. -/** - * @file TopicQoS.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_DDS_QOS_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_QOS_HPP_ +#pragma once #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -56,7 +51,7 @@ using OwnershipQosPolicyKind = eprosima::fastdds::dds::OwnershipQosPolicyKind; * * @todo add keys to Topic QoS */ -struct DDSROUTER_CORE_DllAPI TopicQoS +struct DDSPIPE_CORE_DllAPI TopicQoS { ///////////////////////// // CONSTRUCTORS @@ -124,39 +119,40 @@ struct DDSROUTER_CORE_DllAPI TopicQoS * @note It only stores the depth because in router it will always be keep last, as RTPS has not resource limits. */ HistoryDepthType history_depth = 5000; + + //! Whether the topic has key or not + bool keyed = false; }; /** * @brief \c DurabilityKind to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const DurabilityKind& kind); /** * @brief \c ReliabilityKind to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const ReliabilityKind& kind); /** * @brief \c OwnershipQosPolicyKind to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const OwnershipQosPolicyKind& qos); /** * @brief \c TopicQoS to stream serialization */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const TopicQoS& qos); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_QOS_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp b/ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp similarity index 74% rename from ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp rename to ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp index 4c5723050..f21231b3f 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp +++ b/ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp @@ -10,21 +10,16 @@ // 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. +// limitations under the License\. -/** - * @file ParticipantId.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_PARTICIPANTID_HPP_ -#define _DDSROUTERCORE_TYPES_PARTICIPANTID_HPP_ +#pragma once #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -37,7 +32,5 @@ using ParticipantId = std::string; } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_PARTICIPANTID_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp similarity index 52% rename from ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp rename to ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp index 9474d671b..4fb299145 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/Topic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp @@ -10,34 +10,28 @@ // 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. +// limitations under the License\. -/** - * @file Topic.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_TOPIC_TOPIC_HPP_ -#define _DDSROUTERCORE_TYPES_TOPIC_TOPIC_HPP_ +#pragma once #include #include #include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { /** * Generic data struct that represents a Topic of data flow in the Router. - * - * @todo remove argument constructors. */ -struct Topic +struct Topic : public ITopic { ///////////////////////// @@ -45,50 +39,59 @@ struct Topic ///////////////////////// //! Default constructor - DDSROUTER_CORE_DllAPI Topic() = default; - - //! Construct a Topic with name - DDSROUTER_CORE_DllAPI Topic( - const std::string& topic_name) noexcept; + DDSPIPE_CORE_DllAPI Topic() = default; ///////////////////////// - // METHODS + // OPERATORS ///////////////////////// + //! Compare this with other std Topic + virtual bool operator==(const Topic& other) const noexcept; + /** - * @brief Whether this object is valid. + * @brief Specialize parent compare operator * - * @param [out] error_msg not validity reason in case it is not valid. - * @return true if valid. - * @return false otherwise. + * This is specialized so if the comparison object is a std Topic it is compared as it. */ - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept; + virtual bool operator==(const ITopic& other) const noexcept override; + + ///////////////////////// + // METHODS + ///////////////////////// + + //! ITopic name + virtual const std::string& topic_name() const noexcept override; + + virtual const TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept override; ///////////////////////// // VARIABLES ///////////////////////// - //! Topic name - std::string topic_name{}; + /** + * @brief Topic name + * + * @note it is called with m_ because the name \c topic_name was already in used by parent. + */ + std::string m_topic_name{}; /** * This refers to an internal used identifier that declares which kind of data type is going to be * transmitted in this topic inside the core. + * + * @note it is called with m_ because the name \c topic_name was already in used by parent. */ - TopicInternalTypeId internal_topic_type_discriminator{INTERNAL_TOPIC_TYPE_NONE}; + TopicInternalTypeDiscriminator m_internal_type_discriminator{INTERNAL_TOPIC_TYPE_NONE}; }; /** * Serialization method for \c Topic object. */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const Topic& t); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_TOPIC_TOPIC_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp similarity index 75% rename from ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp rename to ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp index f022439ad..1d4418b4c 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/TopicInternalTypeId.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp @@ -12,24 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file TopicInternalTypeId.hpp - */ #pragma once -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { -using TopicInternalTypeId = const char*; +using TopicInternalTypeDiscriminator = std::string; -constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_NONE = ""; +const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_NONE = ""; } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp new file mode 100644 index 000000000..5d7f1a91a --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp @@ -0,0 +1,98 @@ +// Copyright 2022 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\. + +#pragma once + +#include +#include + +#include + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { + +/** + * Data struct that represents a DDS Topic of data flow in the Router. + */ +struct DdsTopic : public DistributedTopic +{ + + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + //! Default constructor + DDSPIPE_CORE_DllAPI DdsTopic() = default; + + ///////////////////////// + // OPERATORS + ///////////////////////// + + //! Equal operator. + DDSPIPE_CORE_DllAPI bool operator == ( + const Topic& other) const noexcept; + + //! Equal operator. + DDSPIPE_CORE_DllAPI bool operator == ( + const DdsTopic& other) const noexcept; + + ///////////////////////// + // METHODS + ///////////////////////// + + //! Override parent method + virtual const TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept override; + + ///////////////////////// + // STATIC METHODS + ///////////////////////// + + //! Whether a name and type can refer to a correct DDS Topic. + DDSPIPE_CORE_DllAPI static bool is_valid_dds_topic( + const std::string& topic_name, + const std::string& type_name) noexcept; + + ///////////////////////// + // VARIABLES + ///////////////////////// + + //! Topic Type name + std::string type_name{}; + + /** + * @brief Topic QoS + * + * @todo this makes few sense here as the qos does not depend on the QoS itself but in the discovery of it. + * This Topic class is a proxy, not an actual Topic Entity of DDS, so it should not have QoS. + */ + types::TopicQoS topic_qos{}; +}; + +/** + * Serialization method for \c DdsTopic object. + */ +DDSPIPE_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const DdsTopic& t); + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp new file mode 100644 index 000000000..d5ebcc95e --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp @@ -0,0 +1,51 @@ +// Copyright 2022 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\. + +#pragma once + +#include +#include + +#include + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { + +/** + * Data struct that represents a Distributed Topic of data flow in the Router. + * + * @note this not represents a real DDS network topic, but an "abstract" distributed one. + */ +struct DistributedTopic : public Topic +{ + // Extend nothing +}; + +/** + * Serialization method for \c DistributedTopic object. + */ +DDSPIPE_CORE_DllAPI std::ostream& operator <<( + std::ostream& os, + const DistributedTopic& t); + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/filter/DdsFilterTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp similarity index 66% rename from ddsrouter_core/include/ddsrouter_core/types/topic/filter/DdsFilterTopic.hpp rename to ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp index 5ab2a0d18..cb942a855 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/filter/DdsFilterTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp @@ -10,30 +10,25 @@ // 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. +// limitations under the License\. -/** - * @file DdsFilterTopic.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_TOPIC_FILTER_DDSFILTERTOPIC_HPP_ -#define _DDSROUTERCORE_TYPES_TOPIC_FILTER_DDSFILTERTOPIC_HPP_ +#pragma once #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { /** * Generic data struct that represent a filter for a DDS Topic. */ -struct DDSROUTER_CORE_DllAPI DdsFilterTopic +struct DDSPIPE_CORE_DllAPI IFilterTopic { ///////////////////////// @@ -41,10 +36,10 @@ struct DDSROUTER_CORE_DllAPI DdsFilterTopic ///////////////////////// virtual bool operator < ( - const DdsFilterTopic& other) const noexcept; + const IFilterTopic& other) const noexcept; virtual bool operator == ( - const DdsFilterTopic& other) const noexcept; + const IFilterTopic& other) const noexcept; ///////////////////////// // FILTER METHODS @@ -56,27 +51,27 @@ struct DDSROUTER_CORE_DllAPI DdsFilterTopic * This method is used to prevent duplications in filter topic lists. * If the topic \c other filters a subset of the topics filtered by \c this, it returns true. * - * Example: {<*>:<*>} contains every DdsFilterTopic. - * Example: {<>:<>} is contained by every DdsFilterTopic. + * Example: {<*>:<*>} contains every IFilterTopic. + * Example: {<>:<>} is contained by every IFilterTopic. * * @param other: Other topic to check if it is contained * * @return: True if \c other topic filters a subset of \c this */ virtual bool contains( - const DdsFilterTopic& other) const = 0; + const IFilterTopic& other) const = 0; /** * Whether a Real Topic matches the filter of this topic. * * Virtual method. This method should be implemented in subclasses. * - * @param real_topic: Real topic to check if it is filtered + * @param topic: Real topic to check if it is filtered * - * @return: True if \c real_topic matches with \c this filter + * @return: True if \c topic matches with \c this filter */ virtual bool matches( - const DdsTopic& real_topic) const = 0; + const ITopic& topic) const = 0; /** * @brief Serialize the method in a \c ostream object. @@ -92,15 +87,13 @@ struct DDSROUTER_CORE_DllAPI DdsFilterTopic }; /** - * Serialization method for \c DdsFilterTopic object. + * Serialization method for \c IFilterTopic object. */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, - const DdsFilterTopic& t); + const IFilterTopic& t); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_TOPIC_FILTER_DDSFILTERTOPIC_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/filter/WildcardDdsFilterTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp similarity index 58% rename from ddsrouter_core/include/ddsrouter_core/types/topic/filter/WildcardDdsFilterTopic.hpp rename to ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp index 1f94cf6d9..29167612b 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/filter/WildcardDdsFilterTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp @@ -10,60 +10,52 @@ // 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. +// limitations under the License\. -/** - * @file WildcardDdsFilterTopic.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_TOPIC_FILTER_WILDCARDDDSFILTERTOPIC_HPP_ -#define _DDSROUTERCORE_TYPES_TOPIC_FILTER_WILDCARDDDSFILTERTOPIC_HPP_ +#pragma once #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { /** * Data struct that uses wildcards (*, ?) to filter a DDS Router. */ -struct WildcardDdsFilterTopic : public DdsFilterTopic +struct WildcardDdsFilterTopic : public IFilterTopic { ///////////////////////// // CONSTRUCTORS ///////////////////////// - //! Using parent constructos - using DdsFilterTopic::DdsFilterTopic; - - DDSROUTER_CORE_DllAPI WildcardDdsFilterTopic( - const std::string topic_name = "*"); + //! Default ctor that does match with every topic. + DDSPIPE_CORE_DllAPI WildcardDdsFilterTopic() = default; ///////////////////////// // FILTER METHODS ///////////////////////// //! Implement \c contains parent method. - DDSROUTER_CORE_DllAPI virtual bool contains( - const DdsFilterTopic& other) const; + DDSPIPE_CORE_DllAPI virtual bool contains( + const IFilterTopic& other) const override; - //! Implement \c contains parent method. - DDSROUTER_CORE_DllAPI virtual bool matches( - const DdsTopic& real_topic) const; + //! Implement \c matches parent method. + DDSPIPE_CORE_DllAPI virtual bool matches( + const ITopic& topic) const override; ///////////////////////// // SERIALIZATION METHODS ///////////////////////// //! Override parent \c serialize method. - DDSROUTER_CORE_DllAPI virtual std::ostream& serialize( + DDSPIPE_CORE_DllAPI virtual std::ostream& serialize( std::ostream& os) const override; ///////////////////////// @@ -71,25 +63,26 @@ struct WildcardDdsFilterTopic : public DdsFilterTopic ///////////////////////// //! Topic name filter - std::string topic_name; + utils::Fuzzy topic_name; //! Type name filter. If not set matches with all. utils::Fuzzy type_name; - //! Whether the topic has key or not - utils::Fuzzy keyed; +protected: + + //! Specialization for DDS Topics. + DDSPIPE_CORE_DllAPI virtual bool matches_( + const DistributedTopic& real_topic) const; }; /** * Serialization method for \c WildcardDdsFilterTopic object. */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_CORE_DllAPI std::ostream& operator <<( std::ostream& os, const WildcardDdsFilterTopic& t); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_TOPIC_FILTER_WILDCARDDDSFILTERTOPIC_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/rpc/RPCTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp similarity index 84% rename from ddsrouter_core/include/ddsrouter_core/types/topic/rpc/RPCTopic.hpp rename to ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp index f4b20d787..79528dc3c 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/rpc/RPCTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp @@ -10,19 +10,14 @@ // 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. +// limitations under the License\. -/** - * @file RPCTopic.hpp - */ +#pragma once -#ifndef _DDSROUTERCORE_TYPES_TOPIC_RPCTOPIC_HPP_ -#define _DDSROUTERCORE_TYPES_TOPIC_RPCTOPIC_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -31,18 +26,18 @@ namespace types { * It is composed of a pair of DDS topics; one for request and other for reply. * These two DDS topics are formed by mangling a \c service_name with different prefix and suffixes. */ -class RPCTopic +class RpcTopic { public: //! Constructor by service name, request topic and reply topic - RPCTopic( + RpcTopic( const std::string& service_name, const DdsTopic& topic_request, const DdsTopic& topic_reply) noexcept; //! Constructor by request/reply topic only (infers service name and the other request/reply topic) - RPCTopic( + RpcTopic( const DdsTopic& topic) noexcept; //! Service name getter @@ -72,7 +67,7 @@ class RPCTopic * It compares both service names lexicographically */ bool operator <( - const RPCTopic& other) const; + const RpcTopic& other) const; protected: @@ -96,15 +91,13 @@ class RPCTopic * Serialization method * * It prints the service name inside "{}" - * Example: RPCTopic{ServiceName} + * Example: RpcTopic{ServiceName} */ std::ostream& operator <<( std::ostream& os, - const RPCTopic& a); + const RpcTopic& a); } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_TOPIC_RPCTOPIC_HPP_ */ diff --git a/ddsrouter_participants/package.xml b/ddspipe_core/package.xml similarity index 87% rename from ddsrouter_participants/package.xml rename to ddspipe_core/package.xml index f8a362cf7..f24165755 100644 --- a/ddsrouter_participants/package.xml +++ b/ddspipe_core/package.xml @@ -1,10 +1,10 @@ - ddsrouter_participants + ddspipe_core 1.1.0 - Participants for Core that perform DDS and RTPS communication. + *eprosima DDS Pipe* C++ library to communicate different interfaces. Raul Sánchez-Mateos Javier París @@ -19,7 +19,6 @@ fastrtps cpp_utils - ddsrouter_core cmake_utils doxygen diff --git a/ddspipe_core/project_settings.cmake b/ddspipe_core/project_settings.cmake new file mode 100644 index 000000000..a876dad87 --- /dev/null +++ b/ddspipe_core/project_settings.cmake @@ -0,0 +1,34 @@ +# Copyright 2022 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. + +############################################################################### +# Set settings for project ddspipe_core +############################################################################### + +set(MODULE_NAME + ddspipe_core) + +set(MODULE_SUMMARY + "C++ library to build and run a DDS Router.") + +set(MODULE_FIND_PACKAGES + fastcdr + fastrtps + cpp_utils) + +set(fastrtps_MINIMUM_VERSION "2.8") + +set(MODULE_DEPENDENCIES + $<$:iphlpapi$Shlwapi> + ${MODULE_FIND_PACKAGES}) diff --git a/ddspipe_core/src/cpp/_dummy.cpp b/ddspipe_core/src/cpp/_dummy.cpp new file mode 100644 index 000000000..5afa3c4d1 --- /dev/null +++ b/ddspipe_core/src/cpp/_dummy.cpp @@ -0,0 +1,2 @@ + +#include diff --git a/ddsrouter_core/src/cpp/communication/Bridge.cpp b/ddspipe_core/src_/cpp/communication/Bridge.cpp similarity index 96% rename from ddsrouter_core/src/cpp/communication/Bridge.cpp rename to ddspipe_core/src_/cpp/communication/Bridge.cpp index 8ffa75fee..2a3d1d0c3 100644 --- a/ddsrouter_core/src/cpp/communication/Bridge.cpp +++ b/ddspipe_core/src_/cpp/communication/Bridge.cpp @@ -23,7 +23,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -40,5 +40,5 @@ Bridge::Bridge( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/communication/DDSBridge.cpp b/ddspipe_core/src_/cpp/communication/DDSBridge.cpp similarity index 85% rename from ddsrouter_core/src/cpp/communication/DDSBridge.cpp rename to ddspipe_core/src_/cpp/communication/DDSBridge.cpp index f66204738..43e7e1494 100644 --- a/ddsrouter_core/src/cpp/communication/DDSBridge.cpp +++ b/ddspipe_core/src_/cpp/communication/DDSBridge.cpp @@ -13,23 +13,23 @@ // limitations under the License. /** - * @file DDSBridge.cpp + * @file DdsBridge.cpp * */ -#include +#include #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; -DDSBridge::DDSBridge( - const DdsTopic& topic, +DdsBridge::DdsBridge( + const DistributedTopic& topic, std::shared_ptr participants_database, std::shared_ptr payload_pool, std::shared_ptr thread_pool, @@ -37,7 +37,7 @@ DDSBridge::DDSBridge( : Bridge(participants_database, payload_pool, thread_pool) , topic_(topic) { - logDebug(DDSROUTER_DDSBRIDGE, "Creating DDSBridge " << *this << "."); + logDebug(DDSROUTER_DDSBRIDGE, "Creating DdsBridge " << *this << "."); std::set ids = participants_->get_participants_ids(); @@ -85,12 +85,12 @@ DDSBridge::DDSBridge( this->enable(); } - logDebug(DDSROUTER_DDSBRIDGE, "DDSBridge " << *this << " created."); + logDebug(DDSROUTER_DDSBRIDGE, "DdsBridge " << *this << " created."); } -DDSBridge::~DDSBridge() +DdsBridge::~DdsBridge() { - logDebug(DDSROUTER_DDSBRIDGE, "Destroying DDSBridge " << *this << "."); + logDebug(DDSROUTER_DDSBRIDGE, "Destroying DdsBridge " << *this << "."); // Disable every Track before destruction disable(); @@ -118,16 +118,16 @@ DDSBridge::~DDSBridge() // Participants must not be removed as they belong to the Participant Database - logDebug(DDSROUTER_DDSBRIDGE, "DDSBridge " << *this << " destroyed."); + logDebug(DDSROUTER_DDSBRIDGE, "DdsBridge " << *this << " destroyed."); } -void DDSBridge::enable() noexcept +void DdsBridge::enable() noexcept { std::lock_guard lock(mutex_); if (!enabled_) { - logInfo(DDSROUTER_DDSBRIDGE, "Enabling DDSBridge for topic " << topic_ << "."); + logInfo(DDSROUTER_DDSBRIDGE, "Enabling DdsBridge for topic " << topic_ << "."); // ATTENTION: reference needed or it would copy Track for (auto& track_it : tracks_) @@ -139,13 +139,13 @@ void DDSBridge::enable() noexcept } } -void DDSBridge::disable() noexcept +void DdsBridge::disable() noexcept { std::lock_guard lock(mutex_); if (enabled_) { - logInfo(DDSROUTER_DDSBRIDGE, "Disabling DDSBridge for topic " << topic_ << "."); + logInfo(DDSROUTER_DDSBRIDGE, "Disabling DdsBridge for topic " << topic_ << "."); // ATTENTION: reference needed or it would copy Track for (auto& track_it : tracks_) @@ -159,12 +159,12 @@ void DDSBridge::disable() noexcept std::ostream& operator <<( std::ostream& os, - const DDSBridge& bridge) + const DdsBridge& bridge) { - os << "DDSBridge{" << bridge.topic_ << "}"; + os << "DdsBridge{" << bridge.topic_ << "}"; return os; } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/communication/Track.cpp b/ddspipe_core/src_/cpp/communication/Track.cpp similarity index 98% rename from ddsrouter_core/src/cpp/communication/Track.cpp rename to ddspipe_core/src_/cpp/communication/Track.cpp index fb6ee5e5a..1e23225f8 100644 --- a/ddsrouter_core/src/cpp/communication/Track.cpp +++ b/ddspipe_core/src_/cpp/communication/Track.cpp @@ -25,7 +25,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -33,7 +33,7 @@ using namespace eprosima::ddsrouter::core::types; const unsigned int Track::MAX_MESSAGES_TRANSMIT_LOOP_ = 100; Track::Track( - const DdsTopic& topic, + const DistributedTopic& topic, ParticipantId reader_participant_id, std::shared_ptr reader, std::map>&& writers, @@ -243,5 +243,5 @@ std::ostream& operator <<( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddspipe_core/src_/cpp/communication/rpc/RPCBridge.cpp similarity index 98% rename from ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp rename to ddspipe_core/src_/cpp/communication/rpc/RPCBridge.cpp index ede976aa1..4fdfe4802 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddspipe_core/src_/cpp/communication/rpc/RPCBridge.cpp @@ -25,16 +25,16 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; RPCBridge::RPCBridge( - const RPCTopic& topic, + const RpcTopic& topic, std::shared_ptr participants_database, std::shared_ptr payload_pool, std::shared_ptr thread_pool) @@ -348,7 +348,7 @@ void RPCBridge::transmit_( continue; } - if (RPCTopic::is_request_topic(reader->topic())) + if (RpcTopic::is_request_topic(reader->topic())) { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << topic_ << @@ -406,7 +406,7 @@ void RPCBridge::transmit_( } } } - else if (RPCTopic::is_reply_topic(reader->topic())) + else if (RpcTopic::is_reply_topic(reader->topic())) { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << topic_ << @@ -461,7 +461,7 @@ void RPCBridge::transmit_( else { utils::tsnh( - utils::Formatter() << "Data to be transmitted in RPCBridge is not in RPCTopic."); + utils::Formatter() << "Data to be transmitted in RPCBridge is not in RpcTopic."); } payload_pool_->release_payload(pcr_data->payload); @@ -499,5 +499,5 @@ std::ostream& operator <<( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/communication/rpc/ServiceRegistry.cpp b/ddspipe_core/src_/cpp/communication/rpc/ServiceRegistry.cpp similarity index 95% rename from ddsrouter_core/src/cpp/communication/rpc/ServiceRegistry.cpp rename to ddspipe_core/src_/cpp/communication/rpc/ServiceRegistry.cpp index 9d474e4a1..2e2d93863 100644 --- a/ddsrouter_core/src/cpp/communication/rpc/ServiceRegistry.cpp +++ b/ddspipe_core/src_/cpp/communication/rpc/ServiceRegistry.cpp @@ -25,7 +25,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -33,7 +33,7 @@ using namespace eprosima::ddsrouter::core::types; const unsigned int ServiceRegistry::DEFAULT_MAX_ENTRIES_ = 5000; ServiceRegistry::ServiceRegistry( - const RPCTopic& topic, + const RpcTopic& topic, const ParticipantId& participant_id) : topic_(topic) , participant_id_(participant_id) @@ -113,7 +113,7 @@ void ServiceRegistry::erase( } } -RPCTopic ServiceRegistry::topic() const noexcept +RpcTopic ServiceRegistry::topic() const noexcept { return topic_; } @@ -124,5 +124,5 @@ std::recursive_mutex& ServiceRegistry::get_mutex() noexcept } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp b/ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp similarity index 87% rename from ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp rename to ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp index c9219eb1e..c1a433aec 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp +++ b/ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp @@ -17,22 +17,21 @@ * */ -#include +#include #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { -namespace configuration { using namespace eprosima::ddsrouter::core::types; DDSRouterConfiguration::DDSRouterConfiguration( const std::set>& allowlist, const std::set>& blocklist, - const std::set>& builtin_topics, + const std::set>& builtin_topics, const SpecsConfiguration& advanced_options) : DDSRouterReloadConfiguration (allowlist, blocklist, builtin_topics) , advanced_options(advanced_options) @@ -59,7 +58,6 @@ void DDSRouterConfiguration::reload( this->builtin_topics = new_configuration.builtin_topics; } -} /* namespace configuration */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp b/ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp similarity index 86% rename from ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp rename to ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp index 36e090ea9..e747d0197 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp +++ b/ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp @@ -17,22 +17,21 @@ * */ -#include +#include #include -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { -namespace configuration { using namespace eprosima::ddsrouter::core::types; DDSRouterReloadConfiguration::DDSRouterReloadConfiguration( std::set> allowlist, std::set> blocklist, - std::set> builtin_topics) + std::set> builtin_topics) : allowlist(allowlist) , blocklist(blocklist) , builtin_topics(builtin_topics) @@ -65,7 +64,7 @@ bool DDSRouterReloadConfiguration::is_valid( } // Check Builtin list topics - for (std::shared_ptr topic : builtin_topics) + for (std::shared_ptr topic : builtin_topics) { if (!topic) { @@ -84,7 +83,6 @@ bool DDSRouterReloadConfiguration::is_valid( return true; } -} /* namespace configuration */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp b/ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp similarity index 87% rename from ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp rename to ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp index 01d869833..dd5031f7e 100644 --- a/ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp +++ b/ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp @@ -17,12 +17,11 @@ * */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { -namespace configuration { bool SpecsConfiguration::is_valid( utils::Formatter& error_msg) const noexcept @@ -41,7 +40,6 @@ bool SpecsConfiguration::is_valid( return true; } -} /* namespace configuration */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp b/ddspipe_core/src_/cpp/core/DDSRouterImpl.cpp similarity index 93% rename from ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp rename to ddspipe_core/src_/cpp/core/DDSRouterImpl.cpp index b699084f9..ed2710f5e 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp +++ b/ddspipe_core/src_/cpp/core/DDSRouterImpl.cpp @@ -25,12 +25,12 @@ #include #include -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -132,7 +132,7 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( new_configuration.blocklist); // Check if there are any new builtin topics - std::set new_builtin_topics; + std::set new_builtin_topics; for (auto builtin_topic : new_configuration.builtin_topics) { if (current_topics_.find(*builtin_topic) == current_topics_.end()) @@ -175,7 +175,7 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( } // Create bridges for newly added builtin topics - for (DdsTopic topic : new_builtin_topics) + for (DistributedTopic topic : new_builtin_topics) { discovered_topic_(topic); } @@ -303,14 +303,14 @@ void DDSRouterImpl::init_allowed_topics_() void DDSRouterImpl::init_bridges_() { - for (std::shared_ptr topic : configuration_.builtin_topics) + for (std::shared_ptr topic : configuration_.builtin_topics) { discovered_topic_(*topic); } } void DDSRouterImpl::discovered_topic_( - const DdsTopic& topic) noexcept + const DistributedTopic& topic) noexcept { std::lock_guard lock(mutex_); @@ -335,7 +335,7 @@ void DDSRouterImpl::discovered_topic_( } void DDSRouterImpl::discovered_service_( - const RPCTopic& topic, + const RpcTopic& topic, const ParticipantId& server_participant_id, const GuidPrefix& server_guid_prefix) noexcept { @@ -368,7 +368,7 @@ void DDSRouterImpl::discovered_service_( } void DDSRouterImpl::removed_service_( - const RPCTopic& topic, + const RpcTopic& topic, const ParticipantId& server_participant_id, const GuidPrefix& server_guid_prefix) noexcept { @@ -393,15 +393,15 @@ void DDSRouterImpl::discovered_endpoint_( // If non Readers in topics, it is considered as non discovered if (endpoint.is_reader()) { - DdsTopic topic = endpoint.topic(); - if (!RPCTopic::is_service_topic(topic)) + DistributedTopic topic = endpoint.topic(); + if (!RpcTopic::is_service_topic(topic)) { discovered_topic_(topic); } else if (endpoint.is_server_endpoint()) { // Service server discovered - discovered_service_(RPCTopic(topic), endpoint.discoverer_participant_id(), endpoint.guid().guid_prefix()); + discovered_service_(RpcTopic(topic), endpoint.discoverer_participant_id(), endpoint.guid().guid_prefix()); } } } @@ -411,19 +411,19 @@ void DDSRouterImpl::removed_endpoint_( { logDebug(DDSROUTER, "Endpoint removed/dropped: " << endpoint << "."); - DdsTopic topic = endpoint.topic(); - if (RPCTopic::is_service_topic(topic)) + DistributedTopic topic = endpoint.topic(); + if (RpcTopic::is_service_topic(topic)) { if (endpoint.is_server_endpoint()) { // Service server removed/dropped - removed_service_(RPCTopic(topic), endpoint.discoverer_participant_id(), endpoint.guid().guid_prefix()); + removed_service_(RpcTopic(topic), endpoint.discoverer_participant_id(), endpoint.guid().guid_prefix()); } } } void DDSRouterImpl::create_new_bridge( - const DdsTopic& topic, + const DistributedTopic& topic, bool enabled /*= false*/) noexcept { std::lock_guard lock(mutex_); @@ -432,7 +432,7 @@ void DDSRouterImpl::create_new_bridge( try { - bridges_[topic] = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_, + bridges_[topic] = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_, enabled); } catch (const utils::InitializationException& e) @@ -444,7 +444,7 @@ void DDSRouterImpl::create_new_bridge( } void DDSRouterImpl::create_new_service( - const RPCTopic& topic) noexcept + const RpcTopic& topic) noexcept { std::lock_guard lock(mutex_); @@ -455,7 +455,7 @@ void DDSRouterImpl::create_new_service( } void DDSRouterImpl::activate_topic_( - const DdsTopic& topic) noexcept + const DistributedTopic& topic) noexcept { std::lock_guard lock(mutex_); @@ -480,7 +480,7 @@ void DDSRouterImpl::activate_topic_( } void DDSRouterImpl::deactivate_topic_( - const DdsTopic& topic) noexcept + const DistributedTopic& topic) noexcept { std::lock_guard lock(mutex_); @@ -522,5 +522,5 @@ void DDSRouterImpl::deactivate_all_topics_() noexcept } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/dynamic/AllowedTopicList.cpp b/ddspipe_core/src_/cpp/dynamic/AllowedTopicList.cpp similarity index 97% rename from ddsrouter_core/src/cpp/dynamic/AllowedTopicList.cpp rename to ddspipe_core/src_/cpp/dynamic/AllowedTopicList.cpp index 5b50cfa91..2ebe5c642 100644 --- a/ddsrouter_core/src/cpp/dynamic/AllowedTopicList.cpp +++ b/ddspipe_core/src_/cpp/dynamic/AllowedTopicList.cpp @@ -24,7 +24,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -65,7 +65,7 @@ void AllowedTopicList::clear() noexcept } bool AllowedTopicList::is_topic_allowed( - const DdsTopic& topic) const noexcept + const DistributedTopic& topic) const noexcept { std::lock_guard lock(mutex_); @@ -102,7 +102,7 @@ bool AllowedTopicList::is_topic_allowed( } bool AllowedTopicList::is_service_allowed( - const RPCTopic& topic) const noexcept + const RpcTopic& topic) const noexcept { // Lock mutex to perform the verification atomically std::lock_guard lock(mutex_); @@ -181,5 +181,5 @@ std::ostream& operator <<( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/dynamic/DiscoveryDatabase.cpp b/ddspipe_core/src_/cpp/dynamic/DiscoveryDatabase.cpp similarity index 99% rename from ddsrouter_core/src/cpp/dynamic/DiscoveryDatabase.cpp rename to ddspipe_core/src_/cpp/dynamic/DiscoveryDatabase.cpp index f06941e1a..9bdd4ed9a 100644 --- a/ddsrouter_core/src/cpp/dynamic/DiscoveryDatabase.cpp +++ b/ddspipe_core/src_/cpp/dynamic/DiscoveryDatabase.cpp @@ -23,7 +23,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -79,7 +79,7 @@ void DiscoveryDatabase::stop() noexcept } bool DiscoveryDatabase::topic_exists( - const DdsTopic& topic) const noexcept + const DistributedTopic& topic) const noexcept { std::shared_lock lock(mutex_); @@ -343,5 +343,5 @@ void DiscoveryDatabase::process_queue_() noexcept } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp b/ddspipe_core/src_/cpp/dynamic/ParticipantsDatabase.cpp similarity index 96% rename from ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp rename to ddspipe_core/src_/cpp/dynamic/ParticipantsDatabase.cpp index 167232a97..aafc3bd23 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantsDatabase.cpp +++ b/ddspipe_core/src_/cpp/dynamic/ParticipantsDatabase.cpp @@ -20,10 +20,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -109,5 +109,5 @@ void ParticipantsDatabase::add_participant( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp b/ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp similarity index 89% rename from ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp rename to ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp index 7083cbf9d..b13df427e 100644 --- a/ddsrouter_core/src/cpp/efficiency/cache_change/CacheChangePool.cpp +++ b/ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp @@ -12,15 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CacheChangePool.cpp - */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { CacheChangePool::CacheChangePool( @@ -48,5 +45,5 @@ fastrtps::rtps::CacheChange_t* CacheChangePool::new_element_() } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp b/ddspipe_core/src_/cpp/efficiency/payload/CopyPayloadPool.cpp similarity index 93% rename from ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp rename to ddspipe_core/src_/cpp/efficiency/payload/CopyPayloadPool.cpp index cc55d00e9..c5cefc891 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp +++ b/ddspipe_core/src_/cpp/efficiency/payload/CopyPayloadPool.cpp @@ -17,11 +17,11 @@ * */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -62,5 +62,5 @@ bool CopyPayloadPool::release_payload( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp b/ddspipe_core/src_/cpp/efficiency/payload/FastPayloadPool.cpp similarity index 97% rename from ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp rename to ddspipe_core/src_/cpp/efficiency/payload/FastPayloadPool.cpp index e45234c5f..8437bbd6e 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/FastPayloadPool.cpp +++ b/ddspipe_core/src_/cpp/efficiency/payload/FastPayloadPool.cpp @@ -21,10 +21,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -151,5 +151,5 @@ bool FastPayloadPool::release_( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp b/ddspipe_core/src_/cpp/efficiency/payload/MapPayloadPool.cpp similarity index 97% rename from ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp rename to ddspipe_core/src_/cpp/efficiency/payload/MapPayloadPool.cpp index 7aa5ee363..9041815ba 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/MapPayloadPool.cpp +++ b/ddspipe_core/src_/cpp/efficiency/payload/MapPayloadPool.cpp @@ -21,10 +21,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -140,5 +140,5 @@ bool MapPayloadPool::release_payload( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp b/ddspipe_core/src_/cpp/efficiency/payload/PayloadPool.cpp similarity index 97% rename from ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp rename to ddspipe_core/src_/cpp/efficiency/payload/PayloadPool.cpp index 61e88a415..fad2ccc1f 100644 --- a/ddsrouter_core/src/cpp/efficiency/payload/PayloadPool.cpp +++ b/ddspipe_core/src_/cpp/efficiency/payload/PayloadPool.cpp @@ -20,10 +20,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { using namespace eprosima::ddsrouter::core::types; @@ -169,5 +169,5 @@ bool PayloadPool::release_( } } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/test/TestUtils/test_utils.cpp b/ddspipe_core/src_/cpp/testing/test_utils.cpp similarity index 96% rename from ddsrouter_core/test/TestUtils/test_utils.cpp rename to ddspipe_core/src_/cpp/testing/test_utils.cpp index aa4b0013b..99cb3d413 100644 --- a/ddsrouter_core/test/TestUtils/test_utils.cpp +++ b/ddspipe_core/src_/cpp/testing/test_utils.cpp @@ -23,7 +23,8 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { +namespace core { namespace test { using namespace eprosima::ddsrouter::core::types; @@ -74,13 +75,13 @@ WildcardTopicInput::WildcardTopicInput( { } -std::set> topic_set( +std::set> topic_set( std::vector topics) { - std::set> result; + std::set> result; for (DdsTopicInput input : topics) { - auto new_topic = std::make_shared(); + auto new_topic = std::make_shared(); new_topic->topic_name = input.name; new_topic->type_name = input.type; @@ -269,5 +270,6 @@ ParticipantKind random_participant_kind( } } /* namespace test */ -} /* namespace ddsrouter */ +} /* namespace core */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/address/Address.cpp b/ddspipe_core/src_/cpp/types/address/Address.cpp similarity index 99% rename from ddsrouter_core/src/cpp/types/address/Address.cpp rename to ddspipe_core/src_/cpp/types/address/Address.cpp index 33f4743ad..73eb94adc 100644 --- a/ddsrouter_core/src/cpp/types/address/Address.cpp +++ b/ddspipe_core/src_/cpp/types/address/Address.cpp @@ -20,11 +20,11 @@ #include #include -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -438,5 +438,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp b/ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp similarity index 95% rename from ddsrouter_core/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp rename to ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp index ef42259f6..479e54070 100644 --- a/ddsrouter_core/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp +++ b/ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp @@ -17,10 +17,10 @@ * */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -97,5 +97,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/data/Payload.cpp b/ddspipe_core/src_/cpp/types/data/Payload.cpp similarity index 93% rename from ddsrouter_core/src/cpp/types/data/Payload.cpp rename to ddspipe_core/src_/cpp/types/data/Payload.cpp index a4438c6c3..3398872e7 100644 --- a/ddsrouter_core/src/cpp/types/data/Payload.cpp +++ b/ddspipe_core/src_/cpp/types/data/Payload.cpp @@ -19,10 +19,10 @@ #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -58,5 +58,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp b/ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp similarity index 87% rename from ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp rename to ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp index 8236570a2..414eee999 100644 --- a/ddsrouter_core/src/cpp/types/data/RtpsPayloadData.cpp +++ b/ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp @@ -12,14 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RtpsPayloadData.cpp - */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { RtpsPayloadData::~RtpsPayloadData() @@ -33,5 +30,5 @@ RtpsPayloadData::~RtpsPayloadData() } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/dds/DomainId.cpp b/ddspipe_core/src_/cpp/types/dds/DomainId.cpp similarity index 95% rename from ddsrouter_core/src/cpp/types/dds/DomainId.cpp rename to ddspipe_core/src_/cpp/types/dds/DomainId.cpp index df0854f06..ec32ee4e2 100644 --- a/ddsrouter_core/src/cpp/types/dds/DomainId.cpp +++ b/ddspipe_core/src_/cpp/types/dds/DomainId.cpp @@ -17,10 +17,10 @@ * */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -81,5 +81,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/dds/Guid.cpp b/ddspipe_core/src_/cpp/types/dds/Guid.cpp similarity index 93% rename from ddsrouter_core/src/cpp/types/dds/Guid.cpp rename to ddspipe_core/src_/cpp/types/dds/Guid.cpp index 2a257a8e0..f6816c54e 100644 --- a/ddsrouter_core/src/cpp/types/dds/Guid.cpp +++ b/ddspipe_core/src_/cpp/types/dds/Guid.cpp @@ -17,10 +17,10 @@ * */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -59,5 +59,5 @@ GuidPrefix Guid::guid_prefix() const noexcept } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/dds/GuidPrefix.cpp b/ddspipe_core/src_/cpp/types/dds/GuidPrefix.cpp similarity index 95% rename from ddsrouter_core/src/cpp/types/dds/GuidPrefix.cpp rename to ddspipe_core/src_/cpp/types/dds/GuidPrefix.cpp index e37ef7fb6..02c356351 100644 --- a/ddsrouter_core/src/cpp/types/dds/GuidPrefix.cpp +++ b/ddspipe_core/src_/cpp/types/dds/GuidPrefix.cpp @@ -19,10 +19,10 @@ #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -93,5 +93,5 @@ bool GuidPrefix::is_valid() const noexcept } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/dds/RouterCacheChange.hpp b/ddspipe_core/src_/cpp/types/dds/RouterCacheChange.hpp similarity index 83% rename from ddsrouter_core/src/cpp/types/dds/RouterCacheChange.hpp rename to ddspipe_core/src_/cpp/types/dds/RouterCacheChange.hpp index 4369934f9..e42cc0eb9 100644 --- a/ddsrouter_core/src/cpp/types/dds/RouterCacheChange.hpp +++ b/ddspipe_core/src_/cpp/types/dds/RouterCacheChange.hpp @@ -12,20 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RouterCacheChange.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_TYPES_DDS_ROUTERCACHECHANGE_HPP_ -#define __SRC_DDSROUTERCORE_TYPES_DDS_ROUTERCACHECHANGE_HPP_ +#pragma once #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -55,8 +50,5 @@ struct RouterCacheChange : public fastrtps::rtps::CacheChange_t } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_TYPES_DDS_ROUTERCACHECHANGE_HPP_ */ - diff --git a/ddsrouter_core/src/cpp/types/dds/SpecificEndpointQoS.cpp b/ddspipe_core/src_/cpp/types/dds/SpecificEndpointQoS.cpp similarity index 96% rename from ddsrouter_core/src/cpp/types/dds/SpecificEndpointQoS.cpp rename to ddspipe_core/src_/cpp/types/dds/SpecificEndpointQoS.cpp index 4d3477160..ffc46afdf 100644 --- a/ddsrouter_core/src/cpp/types/dds/SpecificEndpointQoS.cpp +++ b/ddspipe_core/src_/cpp/types/dds/SpecificEndpointQoS.cpp @@ -17,11 +17,11 @@ * */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -107,5 +107,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/dds/TopicQoS.cpp b/ddspipe_core/src_/cpp/types/dds/TopicQoS.cpp similarity index 97% rename from ddsrouter_core/src/cpp/types/dds/TopicQoS.cpp rename to ddspipe_core/src_/cpp/types/dds/TopicQoS.cpp index 363d9bd50..57b4a29fd 100644 --- a/ddsrouter_core/src/cpp/types/dds/TopicQoS.cpp +++ b/ddspipe_core/src_/cpp/types/dds/TopicQoS.cpp @@ -17,11 +17,11 @@ * */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -155,5 +155,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/endpoint/Endpoint.cpp b/ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp similarity index 91% rename from ddsrouter_core/src/cpp/types/endpoint/Endpoint.cpp rename to ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp index 2ea22d479..da5483893 100644 --- a/ddsrouter_core/src/cpp/types/endpoint/Endpoint.cpp +++ b/ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp @@ -17,11 +17,11 @@ * */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -33,7 +33,7 @@ Endpoint::Endpoint() noexcept Endpoint::Endpoint( const EndpointKind& kind, const Guid& guid, - const DdsTopic& topic, + const DistributedTopic& topic, const ParticipantId& discoverer_participant_id, const SpecificEndpointQoS& specific_qos) noexcept : kind_(kind) @@ -77,7 +77,7 @@ void Endpoint::specific_qos( specific_qos_ = specific_qos; } -DdsTopic Endpoint::topic() const noexcept +DistributedTopic Endpoint::topic() const noexcept { return topic_; } @@ -115,7 +115,7 @@ bool Endpoint::is_reader() const noexcept bool Endpoint::is_server_endpoint() const noexcept { - return (is_reader() && RPCTopic::is_request_topic(topic_)) || (is_writer() && RPCTopic::is_reply_topic(topic_)); + return (is_reader() && RpcTopic::is_request_topic(topic_)) || (is_writer() && RpcTopic::is_reply_topic(topic_)); } Endpoint& Endpoint::operator =( @@ -156,5 +156,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/security/tls/TlsConfiguration.cpp b/ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp similarity index 94% rename from ddsrouter_core/src/cpp/types/security/tls/TlsConfiguration.cpp rename to ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp index 8652e9cb7..6dde92b78 100644 --- a/ddsrouter_core/src/cpp/types/security/tls/TlsConfiguration.cpp +++ b/ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp @@ -23,10 +23,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { namespace security { @@ -133,7 +133,7 @@ void TlsConfiguration::enable_tls_server( } template <> -DDSROUTER_CORE_DllAPI bool TlsConfiguration::is_valid_kind( +DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( utils::Formatter& error_msg) const noexcept { if (verify_peer) @@ -149,7 +149,7 @@ DDSROUTER_CORE_DllAPI bool TlsConfiguration::is_valid_kind( } template <> -DDSROUTER_CORE_DllAPI bool TlsConfiguration::is_valid_kind( +DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( utils::Formatter& error_msg) const noexcept { if (private_key_file.empty()) @@ -178,7 +178,7 @@ DDSROUTER_CORE_DllAPI bool TlsConfiguration::is_valid_kind( } template <> -DDSROUTER_CORE_DllAPI bool TlsConfiguration::is_valid_kind( +DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( utils::Formatter& error_msg) const noexcept { return is_valid_kind(error_msg) && is_valid_kind(error_msg); @@ -207,5 +207,5 @@ bool TlsConfiguration::is_valid( } /* namespace security */ } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/topic/Topic.cpp b/ddspipe_core/src_/cpp/types/topic/Topic.cpp similarity index 68% rename from ddsrouter_core/src/cpp/types/topic/Topic.cpp rename to ddspipe_core/src_/cpp/types/topic/Topic.cpp index 83b26a6bf..b520f0058 100644 --- a/ddsrouter_core/src/cpp/types/topic/Topic.cpp +++ b/ddspipe_core/src_/cpp/types/topic/Topic.cpp @@ -17,17 +17,20 @@ * */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { Topic::Topic( - const std::string& topic_name) noexcept + const std::string& topic_name, + const TopicInternalTypeDiscriminator& internal_type_discriminator) : topic_name(topic_name) + , internal_type_discriminator(internal_type_discriminator) { + // Do nothing } bool Topic::is_valid( @@ -39,6 +42,12 @@ bool Topic::is_valid( return false; } + if (internal_type_discriminator == INTERNAL_TOPIC_TYPE_NONE) + { + error_msg << "Internal type discriminator could not be None. "; + return false; + } + return true; } @@ -46,11 +55,11 @@ std::ostream& operator <<( std::ostream& os, const Topic& t) { - os << "Topic{" << t.topic_name << "}"; + os << "Topic{" << t.topic_name << "," << t.internal_type_discriminator << "}"; return os; } } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/topic/dds/DdsTopic.cpp b/ddspipe_core/src_/cpp/types/topic/dds/DdsTopic.cpp similarity index 79% rename from ddsrouter_core/src/cpp/types/topic/dds/DdsTopic.cpp rename to ddspipe_core/src_/cpp/types/topic/dds/DdsTopic.cpp index 65f912bc2..9532d0b84 100644 --- a/ddsrouter_core/src/cpp/types/topic/dds/DdsTopic.cpp +++ b/ddspipe_core/src_/cpp/types/topic/dds/DdsTopic.cpp @@ -13,22 +13,22 @@ // limitations under the License. /** - * @file DdsTopic.cpp + * @file DistributedTopic.cpp * */ #include #include -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { -DdsTopic::DdsTopic( +DistributedTopic::DistributedTopic( const std::string& topic_name, const std::string& type_name) noexcept : Topic(topic_name) @@ -36,7 +36,7 @@ DdsTopic::DdsTopic( { } -DdsTopic::DdsTopic( +DistributedTopic::DistributedTopic( const std::string& topic_name, const std::string& type_name, const bool keyed, @@ -48,7 +48,7 @@ DdsTopic::DdsTopic( { } -bool DdsTopic::is_valid( +bool DistributedTopic::is_valid( utils::Formatter& error_msg) const noexcept { if (!Topic::is_valid(error_msg)) @@ -85,8 +85,8 @@ bool DdsTopic::is_valid( return true; } -bool DdsTopic::operator < ( - const DdsTopic& other) const noexcept +bool DistributedTopic::operator < ( + const DistributedTopic& other) const noexcept { if (Topic::operator ==(other)) { @@ -95,33 +95,33 @@ bool DdsTopic::operator < ( return Topic::operator <(other); } -bool DdsTopic::operator == ( - const DdsTopic& other) const noexcept +bool DistributedTopic::operator == ( + const DistributedTopic& other) const noexcept { return Topic::operator ==(other) && this->type_name == other.type_name; } -bool DdsTopic::is_valid_dds_topic( +bool DistributedTopic::is_valid_dds_topic( const std::string& topic_name, const std::string& type_name) noexcept { utils::Formatter __f; - return DdsTopic(topic_name, type_name).is_valid(__f); + return DistributedTopic(topic_name, type_name).is_valid(__f); } std::ostream& operator <<( std::ostream& os, - const DdsTopic& t) + const DistributedTopic& t) { std::string keyed_str = t.keyed ? ";keyed;" : ";"; - os << "DdsTopic{" << t.topic_name << ";" << t.type_name << keyed_str << t.topic_qos << "}"; + os << "DistributedTopic{" << t.topic_name << ";" << t.type_name << keyed_str << t.topic_qos << "}"; return os; } } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/topic/filter/DdsFilterTopic.cpp b/ddspipe_core/src_/cpp/types/topic/filter/DdsFilterTopic.cpp similarity index 91% rename from ddsrouter_core/src/cpp/types/topic/filter/DdsFilterTopic.cpp rename to ddspipe_core/src_/cpp/types/topic/filter/DdsFilterTopic.cpp index efef606f0..43920887a 100644 --- a/ddsrouter_core/src/cpp/types/topic/filter/DdsFilterTopic.cpp +++ b/ddspipe_core/src_/cpp/types/topic/filter/DdsFilterTopic.cpp @@ -17,11 +17,11 @@ * */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -47,5 +47,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp b/ddspipe_core/src_/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp similarity index 93% rename from ddsrouter_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp rename to ddspipe_core/src_/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp index f95ac9be8..66c4b99e2 100644 --- a/ddsrouter_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp +++ b/ddspipe_core/src_/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp @@ -17,11 +17,11 @@ * */ -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { @@ -40,7 +40,7 @@ bool WildcardDdsFilterTopic::contains( } bool WildcardDdsFilterTopic::matches( - const DdsTopic& other) const + const DistributedTopic& other) const { // Compare key if (this->keyed.is_set()) @@ -93,5 +93,5 @@ std::ostream& operator <<( } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/types/topic/rpc/RPCTopic.cpp b/ddspipe_core/src_/cpp/types/topic/rpc/RPCTopic.cpp similarity index 75% rename from ddsrouter_core/src/cpp/types/topic/rpc/RPCTopic.cpp rename to ddspipe_core/src_/cpp/types/topic/rpc/RPCTopic.cpp index 82e366e08..0ac555398 100644 --- a/ddsrouter_core/src/cpp/types/topic/rpc/RPCTopic.cpp +++ b/ddspipe_core/src_/cpp/types/topic/rpc/RPCTopic.cpp @@ -13,38 +13,38 @@ // limitations under the License. /** - * @file RPCTopic.cpp + * @file RpcTopic.cpp * */ #include -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace types { -const std::string RPCTopic::REQUEST_PREFIX_STR = "rq/"; -const std::string RPCTopic::REPLY_PREFIX_STR = "rr/"; -const std::string RPCTopic::REQUEST_STR = "Request"; -const std::string RPCTopic::REPLY_STR = "Reply"; -const std::string RPCTopic::RESPONSE_STR = "Response"; +const std::string RpcTopic::REQUEST_PREFIX_STR = "rq/"; +const std::string RpcTopic::REPLY_PREFIX_STR = "rr/"; +const std::string RpcTopic::REQUEST_STR = "Request"; +const std::string RpcTopic::REPLY_STR = "Reply"; +const std::string RpcTopic::RESPONSE_STR = "Response"; -RPCTopic::RPCTopic( +RpcTopic::RpcTopic( const std::string& service_name, - const DdsTopic& request_topic, - const DdsTopic& reply_topic) noexcept + const DistributedTopic& request_topic, + const DistributedTopic& reply_topic) noexcept : service_name_(service_name) , request_topic_(request_topic) , reply_topic_(reply_topic) { } -RPCTopic::RPCTopic( - const DdsTopic& topic) noexcept +RpcTopic::RpcTopic( + const DistributedTopic& topic) noexcept { if (is_request_topic(topic)) { @@ -77,7 +77,7 @@ RPCTopic::RPCTopic( else { utils::tsnh( - utils::Formatter() << "Attempting to create RPCTopic from invalid topic."); + utils::Formatter() << "Attempting to create RpcTopic from invalid topic."); } // Set both topic qos as the one found @@ -85,23 +85,23 @@ RPCTopic::RPCTopic( reply_topic_.topic_qos = topic.topic_qos; } -const std::string& RPCTopic::service_name() const +const std::string& RpcTopic::service_name() const { return service_name_; } -const DdsTopic& RPCTopic::request_topic() const +const DistributedTopic& RpcTopic::request_topic() const { return request_topic_; } -const DdsTopic& RPCTopic::reply_topic() const +const DistributedTopic& RpcTopic::reply_topic() const { return reply_topic_; } -bool RPCTopic::is_request_topic( - const DdsTopic& topic) +bool RpcTopic::is_request_topic( + const DistributedTopic& topic) { std::string topic_name = topic.topic_name; std::string type_name = topic.type_name; @@ -111,8 +111,8 @@ bool RPCTopic::is_request_topic( (type_name.rfind(REQUEST_STR) + REQUEST_STR.length() + 1 == type_name.length()); } -bool RPCTopic::is_reply_topic( - const DdsTopic& topic) +bool RpcTopic::is_reply_topic( + const DistributedTopic& topic) { std::string topic_name = topic.topic_name; std::string type_name = topic.type_name; @@ -122,14 +122,14 @@ bool RPCTopic::is_reply_topic( (type_name.rfind(RESPONSE_STR) + RESPONSE_STR.length() + 1 == type_name.length()); } -bool RPCTopic::is_service_topic( - const DdsTopic& topic) +bool RpcTopic::is_service_topic( + const DistributedTopic& topic) { return is_request_topic(topic) || is_reply_topic(topic); } -bool RPCTopic::operator <( - const RPCTopic& other) const +bool RpcTopic::operator <( + const RpcTopic& other) const { int name_comparison = service_name_.compare(other.service_name()); if (name_comparison < 0) @@ -144,13 +144,13 @@ bool RPCTopic::operator <( std::ostream& operator <<( std::ostream& os, - const RPCTopic& a) + const RpcTopic& a) { - os << "RPCTopic{" << a.service_name() << "}"; + os << "RpcTopic{" << a.service_name() << "}"; return os; } } /* namespace types */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/test/CMakeLists.txt b/ddspipe_core/test/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/CMakeLists.txt rename to ddspipe_core/test/CMakeLists.txt diff --git a/ddsrouter_core/test/blackbox/CMakeLists.txt b/ddspipe_core/test/blackbox/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/CMakeLists.txt rename to ddspipe_core/test/blackbox/CMakeLists.txt diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/CMakeLists.txt rename to ddspipe_core/test/blackbox/ddsrouter_core/CMakeLists.txt diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt new file mode 100644 index 000000000..e0dd990dd --- /dev/null +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2021 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. + +add_subdirectory(local) +add_subdirectory(WAN) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp similarity index 95% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp index e5ee8542f..5ed89d797 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -19,17 +19,17 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace test { @@ -237,9 +237,9 @@ std::shared_ptr wan_participant_configu * Create 1 simple participants with domains \c domain * Create 1 custom participant by the configuration in \c participant_configuration * - * @return configuration::DDSRouterConfiguration + * @return configuration::DdsRouterConfiguration */ -configuration::DDSRouterConfiguration router_configuration( +configuration::DdsRouterConfiguration router_configuration( std::shared_ptr participant_configuration, types::DomainIdType domain) { @@ -252,7 +252,7 @@ configuration::DDSRouterConfiguration router_configuration( std::set> blocklist; // empty - std::set> builtin_topics; // empty + std::set> builtin_topics; // empty // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 std::set> participants_configurations( @@ -270,7 +270,7 @@ configuration::DDSRouterConfiguration router_configuration( } ); - return configuration::DDSRouterConfiguration( + return configuration::DdsRouterConfiguration( allowlist, blocklist, builtin_topics, @@ -284,8 +284,8 @@ configuration::DDSRouterConfiguration router_configuration( * instances communicate with the DDS Participants through Simple Participants deployed at those domains. */ void test_WAN_communication( - configuration::DDSRouterConfiguration ddsrouter_server_configuration, - configuration::DDSRouterConfiguration ddsrouter_client_configuration, + configuration::DdsRouterConfiguration ddsrouter_server_configuration, + configuration::DdsRouterConfiguration ddsrouter_client_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE) @@ -305,7 +305,7 @@ void test_WAN_communication( // Add this string as many times as the msg size requires for (uint32_t i = 0; i < msg_size; i++) { - msg_str += "Testing DDSRouter Blackbox Local Communication ..."; + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; } msg.message(msg_str); @@ -317,12 +317,12 @@ void test_WAN_communication( TestSubscriber subscriber; ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - // Create DDSRouter entity whose WAN Participant is configured as server - DDSRouter server_router(ddsrouter_server_configuration); + // Create DdsRouter entity whose WAN Participant is configured as server + DdsRouter server_router(ddsrouter_server_configuration); server_router.start(); - // Create DDSRouter entity whose WAN Participant is configured as client - DDSRouter client_router(ddsrouter_client_configuration); + // Create DdsRouter entity whose WAN Participant is configured as client + DdsRouter client_router(ddsrouter_client_configuration); client_router.start(); // Start publishing @@ -448,7 +448,7 @@ void test_WAN_communication_all( } /* namespace test */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ using namespace eprosima::ddsrouter::core; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/README.md b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/README.md similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/README.md rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/README.md diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp similarity index 93% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index deee9c54e..c6240e112 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -20,14 +20,14 @@ #include -#include -#include +#include +#include #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace test { @@ -42,9 +42,9 @@ constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. * Create 2 simple participants with domains 0 and 1 * - * @return configuration::DDSRouterConfiguration + * @return configuration::DdsRouterConfiguration */ -configuration::DDSRouterConfiguration dds_test_simple_configuration( +configuration::DdsRouterConfiguration dds_test_simple_configuration( bool disable_dynamic_discovery = false, bool transient_local_readers = false) { @@ -54,7 +54,7 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration( std::set> blocklist; // empty - std::set> builtin_topics; // empty + std::set> builtin_topics; // empty if (disable_dynamic_discovery) { @@ -71,9 +71,9 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration( } builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); + std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); + std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); } // Two simple participants @@ -94,7 +94,7 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration( } ); - return configuration::DDSRouterConfiguration( + return configuration::DdsRouterConfiguration( allowlist, blocklist, builtin_topics, @@ -111,7 +111,7 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration( */ template void test_local_communication( - configuration::DDSRouterConfiguration ddsrouter_configuration, + configuration::DdsRouterConfiguration ddsrouter_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE, @@ -133,7 +133,7 @@ void test_local_communication( // Add this string as many times as the msg size requires for (uint32_t i = 0; i < msg_size; i++) { - msg_str += "Testing DDSRouter Blackbox Local Communication ..."; + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; } msg.message(msg_str); @@ -145,9 +145,9 @@ void test_local_communication( TestSubscriber subscriber(msg.isKeyDefined(), transient_local); ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - // Create DDSRouter entity + // Create DdsRouter entity // The DDS Router does not start here in order to test a transient_local communication - DDSRouter router(ddsrouter_configuration); + DdsRouter router(ddsrouter_configuration); if (transient_local) { @@ -199,7 +199,7 @@ void test_local_communication( } /* namespace test */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ using namespace eprosima::ddsrouter::core; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp similarity index 90% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp index 30d6a9942..bf785388e 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp @@ -20,15 +20,15 @@ #include -#include -#include -#include +#include +#include +#include #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace test { @@ -44,9 +44,9 @@ constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. * Create 2 simple participants with domains 0 and 1 * - * @return configuration::DDSRouterConfiguration + * @return configuration::DdsRouterConfiguration */ -configuration::DDSRouterConfiguration dds_test_simple_configuration() +configuration::DdsRouterConfiguration dds_test_simple_configuration() { // Always filter the test topics by topic name std::set> allowlist; // only this topic @@ -54,7 +54,7 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration() std::set> blocklist; // empty - std::set> builtin_topics; // empty + std::set> builtin_topics; // empty // Two simple participants std::set> participants_configurations( @@ -78,7 +78,7 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration() auto specs = configuration::SpecsConfiguration(); specs.number_of_threads = 2; - return configuration::DDSRouterConfiguration( + return configuration::DdsRouterConfiguration( allowlist, blocklist, builtin_topics, @@ -94,7 +94,7 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration() * to Late Joiners. */ void test_local_communication_key_dispose( - configuration::DDSRouterConfiguration ddsrouter_configuration, + configuration::DdsRouterConfiguration ddsrouter_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE) @@ -114,7 +114,7 @@ void test_local_communication_key_dispose( // Add this string as many times as the msg size requires for (uint32_t i = 0; i < msg_size; i++) { - msg_str += "Testing DDSRouter Blackbox Local Communication ..."; + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; } msg.message(msg_str); msg.id(666); @@ -127,9 +127,9 @@ void test_local_communication_key_dispose( TestSubscriber subscriber(msg.isKeyDefined()); ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - // Create DDSRouter entity + // Create DdsRouter entity // The DDS Router does not start here in order to test a reliable communication - DDSRouter router(ddsrouter_configuration); + DdsRouter router(ddsrouter_configuration); // Start DDS Router router.start(); @@ -176,7 +176,7 @@ void test_local_communication_key_dispose( } /* namespace test */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ using namespace eprosima::ddsrouter::core; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/README.md b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/README.md similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/README.md rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/local/README.md diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h similarity index 99% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h index fa8952126..c445fff76 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h @@ -17,10 +17,7 @@ * This header file contains the declaration of the described types in the IDL file. * * This file was generated by the tool gen. - */ - -#ifndef _HELLOWORLD_H_ -#define _HELLOWORLD_H_ + */#pragma once // TODO Poner en el contexto. diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h similarity index 97% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h index 3fd9b2c65..44f12a5b5 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h @@ -18,10 +18,7 @@ * * This file was generated by the tool fastcdrgen. */ - - -#ifndef _HELLOWORLD_PUBSUBTYPES_H_ -#define _HELLOWORLD_PUBSUBTYPES_H_ +#pragma once #include #include diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h similarity index 97% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h index e1f8eb462..8b1d2787e 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h @@ -17,10 +17,7 @@ * This header file contains the declaration of the described types in the IDL file. * * This file was generated by the tool gen. - */ - -#ifndef _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ -#define _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ + */#pragma once #include @@ -249,4 +246,4 @@ class HelloWorldKeyed std::string m_message; }; -#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ \ No newline at end of file +#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h similarity index 94% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h index fe9248a00..d4a3a204f 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h @@ -18,10 +18,7 @@ * * This file was generated by the tool fastcdrgen. */ - - -#ifndef _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ +#pragma once #include #include @@ -98,4 +95,4 @@ class HelloWorldKeyedPubSubType : public eprosima::fastdds::dds::TopicDataType unsigned char* m_keyBuffer; }; -#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ \ No newline at end of file +#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp similarity index 96% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp rename to ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp index c154a1dbb..d9dc0f9c9 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp +++ b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp @@ -10,14 +10,9 @@ // 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. +// limitations under the License\. -/** - * @file test_participants.hpp - */ - -#ifndef _TEST_BLACKBOX_DDSROUTERCORE_DDS_TYPES_TEST_PARTICIPANTS_HPP_ -#define _TEST_BLACKBOX_DDSROUTERCORE_DDS_TYPES_TEST_PARTICIPANTS_HPP_ +#pragma once #include #include @@ -28,8 +23,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -55,7 +50,7 @@ #include "HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h" namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace test { @@ -496,7 +491,5 @@ class TestSubscriber } /* namespace test */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _TEST_BLACKBOX_DDSROUTERCORE_DDS_TYPES_TEST_PARTICIPANTS_HPP_ */ diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt rename to ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt rename to ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key rename to ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem rename to ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt rename to ddspipe_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp similarity index 77% rename from ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp rename to ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp index 8cc28ae08..d1e872325 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ b/ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp @@ -19,10 +19,10 @@ #include #include -#include -#include +#include +#include #include -#include +#include #include @@ -43,9 +43,9 @@ std::vector random_payload( return payload; } -configuration::DDSRouterConfiguration void_configuration() +configuration::DdsRouterConfiguration void_configuration() { - configuration::DDSRouterConfiguration configuration; + configuration::DdsRouterConfiguration configuration; configuration.participants_configurations = { std::make_shared( @@ -64,21 +64,21 @@ configuration::DDSRouterConfiguration void_configuration() } /** - * @brief Create a \c DDSRouterConfiguration with 2 dummy participants and one builtin topic + * @brief Create a \c DdsRouterConfiguration with 2 dummy participants and one builtin topic * - * @return configuration::DDSRouterConfiguration + * @return configuration::DdsRouterConfiguration */ -configuration::DDSRouterConfiguration simple_configuration( +configuration::DdsRouterConfiguration simple_configuration( const std::string& participant_1_name = "Participant1", const std::string& participant_2_name = "Participant2", const std::string& topic_name = "topic_dummy", const std::string& topic_type = "type_dummy") { - configuration::DDSRouterConfiguration configuration; + configuration::DdsRouterConfiguration configuration; configuration.builtin_topics = { - std::set>({std::make_shared(topic_name, topic_type)}), + std::set>({std::make_shared(topic_name, topic_type)}), }; configuration.participants_configurations = @@ -99,12 +99,12 @@ configuration::DDSRouterConfiguration simple_configuration( } /** - * Test Whole DDSRouter initialization by initializing two EmptyParticipants + * Test Whole DdsRouter initialization by initializing two EmptyParticipants */ TEST(TrivialTest, trivial_void_initialization) { - // Create DDSRouter entity - DDSRouter router(void_configuration()); + // Create DdsRouter entity + DdsRouter router(void_configuration()); router.start(); router.stop(); @@ -112,12 +112,12 @@ TEST(TrivialTest, trivial_void_initialization) } /** - * Test Whole DDSRouter initialization by initializing two DummyParticipants and a DdsTopic + * Test Whole DdsRouter initialization by initializing two DummyParticipants and a DistributedTopic */ TEST(TrivialTest, trivial_dummy_initialization) { - // Create DDSRouter entity - DDSRouter router(simple_configuration()); + // Create DdsRouter entity + DdsRouter router(simple_configuration()); router.start(); router.stop(); @@ -125,13 +125,13 @@ TEST(TrivialTest, trivial_dummy_initialization) } /** - * Test Whole DDSRouter interfaces by using two DummyParticipants and send one message from one to the other + * Test Whole DdsRouter interfaces by using two DummyParticipants and send one message from one to the other * * TODO */ TEST(TrivialTest, trivial_communication) { - DDSRouter router(simple_configuration()); + DdsRouter router(simple_configuration()); router.start(); DummyParticipant* participant_1 = DummyParticipant::get_participant(ParticipantId("Participant1")); @@ -139,7 +139,7 @@ TEST(TrivialTest, trivial_communication) ASSERT_NE(participant_1, nullptr); ASSERT_NE(participant_2, nullptr); - DdsTopic topic("topic_dummy", "type_dummy"); + DistributedTopic topic("topic_dummy", "type_dummy"); Guid guid = random_guid(); std::vector payload = random_payload(3); diff --git a/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt b/ddspipe_core/test/blackbox/implementations/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/implementations/CMakeLists.txt rename to ddspipe_core/test/blackbox/implementations/CMakeLists.txt diff --git a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp similarity index 89% rename from ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp rename to ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp index 4d3f91c42..6b1720df4 100644 --- a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp +++ b/ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp @@ -21,30 +21,30 @@ #include -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace test { constexpr const unsigned int DEFAULT_THREAD_POOL_SIZE = 2; constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; } /* namespace test */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ using namespace eprosima::ddsrouter; @@ -81,7 +81,7 @@ TEST(ImplementationsTest, pair_implementation) configuration::DDSRouterConfiguration configuration( std::set>(), std::set>(), - std::set>(), + std::set>(), participant_configurations, specs); @@ -116,7 +116,7 @@ TEST(ImplementationsTest, pair_implementation_with_topic) // For each Participant kind for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) { - std::set> builtin_topics = test::topic_set( + std::set> builtin_topics = test::topic_set( {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); std::set> participant_configurations; @@ -166,7 +166,7 @@ TEST(ImplementationsTest, all_implementations) { // Set topic to active - std::set> builtin_topics = test::topic_set( + std::set> builtin_topics = test::topic_set( {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); std::set> participant_configurations; @@ -188,7 +188,7 @@ TEST(ImplementationsTest, all_implementations) configuration::DDSRouterConfiguration configuration( std::set>(), std::set>(), - std::set>(), + std::set>(), participant_configurations, specs); @@ -228,7 +228,7 @@ TEST(ImplementationsTest, duplicated_ids) configuration::DDSRouterConfiguration configuration( std::set>(), std::set>(), - std::set>(), + std::set>(), participant_configurations, specs); diff --git a/ddsrouter_core/test/unittest/CMakeLists.txt b/ddspipe_core/test/unittest/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/CMakeLists.txt rename to ddspipe_core/test/unittest/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/_configuration/CMakeLists.txt b/ddspipe_core/test/unittest/_configuration/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/_configuration/CMakeLists.txt rename to ddspipe_core/test/unittest/_configuration/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/_configuration/TODO.md b/ddspipe_core/test/unittest/_configuration/TODO.md similarity index 100% rename from ddsrouter_core/test/unittest/_configuration/TODO.md rename to ddspipe_core/test/unittest/_configuration/TODO.md diff --git a/ddsrouter_core/test/unittest/_configuration/_ConfigurationTest.cpp b/ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp similarity index 96% rename from ddsrouter_core/test/unittest/_configuration/_ConfigurationTest.cpp rename to ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp index 0de29e249..daafed6c3 100644 --- a/ddsrouter_core/test/unittest/_configuration/_ConfigurationTest.cpp +++ b/ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp @@ -18,11 +18,11 @@ #include #include -#include +#include #include -#include -#include -#include +#include +#include +#include using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; @@ -104,10 +104,10 @@ bool topic_in_list( * Check if a topic is inside a list returned by real_topics DDSRouter methods */ bool topic_in_real_list( - std::set list, - DdsTopic compared_topic) + std::set list, + DistributedTopic compared_topic) { - for (DdsTopic topic : list) + for (DistributedTopic topic : list) { // Check class and internal variables if (typeid(topic) == typeid(compared_topic) && @@ -419,7 +419,7 @@ TEST(ConfigurationTest, real_topics) EXPECT_FALSE(result4.empty()); for (auto random_topic : random_real_topic_names()) { - DdsTopic topic(random_topic.first, random_topic.second); + DistributedTopic topic(random_topic.first, random_topic.second); EXPECT_TRUE(topic_in_real_list(result4, topic)); } @@ -433,12 +433,12 @@ TEST(ConfigurationTest, real_topics) uint16_t real_topics = 0; for (auto random_topic : random_topic_names()) { - bool real_topic = DdsTopic::is_valid_dds_topic(random_topic.first, random_topic.second); + bool real_topic = DistributedTopic::is_valid_dds_topic(random_topic.first, random_topic.second); if (real_topic) { ++real_topics; - DdsTopic topic(random_topic.first, random_topic.second); + DistributedTopic topic(random_topic.first, random_topic.second); EXPECT_TRUE(topic_in_real_list(result5, topic)) << topic; } } diff --git a/ddsrouter_core/test/unittest/core/CMakeLists.txt b/ddspipe_core/test/unittest/core/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/core/CMakeLists.txt rename to ddspipe_core/test/unittest/core/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt b/ddspipe_core/test/unittest/core/participants_database/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/core/participants_database/CMakeLists.txt rename to ddspipe_core/test/unittest/core/participants_database/CMakeLists.txt diff --git a/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp b/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp new file mode 100644 index 000000000..6f60a9715 --- /dev/null +++ b/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp @@ -0,0 +1,255 @@ +// Copyright 2021 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. + +#include + +#include +#include + +#include +#include +#include +#include + +using namespace eprosima::ddsrouter; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace test { + +/** + * This class is used to expose protected methods of the parent class + * so they can be tested. + */ +class ParticipantsDatabase : public eprosima::ddsrouter::core::ParticipantsDatabase +{ +public: + + ParticipantsDatabase() + { + } + + ParticipantsDatabase( + std::map> participants) + : ParticipantsDatabase() + { + participants_ = participants; + } + + std::shared_ptr pop( + const ParticipantId& id) noexcept + { + return pop_(id); + } + + std::shared_ptr pop() noexcept + { + return pop_(); + } + + void add_participant( + ParticipantId id, + std::shared_ptr participant, + std::size_t expected_size) + { + add_participant_(id, participant); + // Verify correct insertion + auto it = participants_.find(id); + ASSERT_EQ(it->second, participant); + ASSERT_EQ(participants_.size(), expected_size); + } + +}; + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +/********************* +* PROTECTED METHODS ** +*********************/ + +/** + * Test the addition of a participant to the database + * + * CASES: + * + * Add not stored participant + * Add already stored participant + */ +TEST(ParticipantsDatabaseTest, add_participant) +{ + std::shared_ptr participants_database = std::make_shared(); + // Check database is empty + ASSERT_TRUE(participants_database->empty()); + + ParticipantId id("void_part"); + std::shared_ptr participant = std::make_shared(id); + // Insert participant + participants_database->add_participant(participant->id(), participant, 1); + + // Reinsert and check it throws an error + ASSERT_THROW( + participants_database->add_participant( + participant->id(), + participant, 1), + eprosima::utils::InconsistencyException); +} + +/** + * Test the extraction of a participant from the database + * + * CASES: + * Empty database + * Pop random participant + * Pop specific participant + * Pop not stored participant + * Pop stored participant + */ +TEST(ParticipantsDatabaseTest, pop) +{ + std::shared_ptr participants_database = std::make_shared(); + ASSERT_TRUE(participants_database->empty()); + // Empty database, no participant should be popped + ASSERT_TRUE(participants_database->pop() == nullptr); + + ParticipantId id1("void_p1"); + std::shared_ptr participant1 = std::make_shared(id1); + ParticipantId id2("void_p2"); + std::shared_ptr participant2 = std::make_shared(id2); + // Pop not yet stored participant + ASSERT_TRUE(participants_database->pop(id1) == nullptr); + ASSERT_TRUE(participants_database->pop(id2) == nullptr); + + // Insert participants into database + participants_database->add_participant(participant1->id(), participant1, 1); + participants_database->add_participant(participant2->id(), participant2, 2); + + // Pop stored participants + ASSERT_EQ(participants_database->pop(id1), participant1); + ASSERT_EQ(participants_database->pop(), participant2); + // Participants should have been removed + ASSERT_TRUE(participants_database->get_participant(id1) == nullptr); + ASSERT_TRUE(participants_database->get_participant(id2) == nullptr); + ASSERT_TRUE(participants_database->empty()); +} + +/********************* +* PUBLIC METHODS ** +*********************/ + +/** + * Test \c ParticipantsDatabase \c empty method + * + * CASES: + * Empty database + * Non-empty database + */ +TEST(ParticipantsDatabaseTest, empty) +{ + std::shared_ptr participants_database = std::make_shared(); + // Empty database + ASSERT_TRUE(participants_database->empty()); + + // Non-empty database + ParticipantId id("void_part"); + std::shared_ptr participant = std::make_shared(id); + participants_database->add_participant(participant->id(), participant, 1); + ASSERT_FALSE(participants_database->empty()); +} + +/** + * Test \c ParticipantsDatabase \c get_participant method + * + * CASES: + * Empty configuration + * Random configuration + */ +TEST(ParticipantsDatabaseTest, get_participant) +{ + std::shared_ptr participants_database = std::make_shared(); + + ParticipantId id("void_part"); + std::shared_ptr participant = std::make_shared(id); + participants_database->add_participant(participant->id(), participant, 1); + + ASSERT_EQ(participants_database->get_participant(id), participant); +} + +/** + * Test \c ParticipantsDatabase \c get_participants_ids method + */ +TEST(ParticipantsDatabaseTest, get_participants_ids) +{ + std::shared_ptr participants_database = std::make_shared(); + + ParticipantId id1("void_p1"); + std::shared_ptr participant1 = std::make_shared(id1); + participants_database->add_participant(participant1->id(), participant1, 1); + + ParticipantId id2("void_p2"); + std::shared_ptr participant2 = std::make_shared(id2); + participants_database->add_participant(participant2->id(), participant2, 2); + + std::set ids {id2, id1}; + ASSERT_EQ(ids, participants_database->get_participants_ids()); +} + +/** + * Test \c ParticipantsDatabase \c get_participants_map getter method + */ +TEST(ParticipantsDatabaseTest, get_participants_map) +{ + ParticipantId id("void_part"); + std::shared_ptr participant = std::make_shared(id); + std::map> participants = {{id, participant}}; + + std::shared_ptr participants_database = std::make_shared( + participants); + ASSERT_EQ(participants_database->get_participants_map(), participants); +} + +/** + * Test \c ParticipantsDatabase \c size getter method + */ +TEST(ParticipantsDatabaseTest, size) +{ + std::shared_ptr participants_database = std::make_shared(); + // Check database is empty + ASSERT_EQ(participants_database->size(), 0u); + + ParticipantId id_1("void_part"); + std::shared_ptr participant_1 = std::make_shared(id_1); + // Insert participant_1 + participants_database->add_participant(participant_1->id(), participant_1, 1); + ASSERT_EQ(participants_database->size(), 1u); + + ParticipantId id_2("simple_part"); + std::shared_ptr participant_2 = std::make_shared(id_2); + // Insert participant_2 + participants_database->add_participant(participant_2->id(), participant_2, 2); + ASSERT_EQ(participants_database->size(), 2u); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_core/test/unittest/dynamic/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/dynamic/CMakeLists.txt rename to ddspipe_core/test/unittest/dynamic/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp similarity index 97% rename from ddsrouter_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp rename to ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp index 9a7685c9c..7bae70698 100644 --- a/ddsrouter_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp +++ b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; @@ -93,14 +93,14 @@ void generic_test( // Test positive cases for (pair_topic_type topic_name : real_topics_positive) { - DdsTopic topic(topic_name.first, topic_name.second); + DistributedTopic topic(topic_name.first, topic_name.second); ASSERT_TRUE(atl.is_topic_allowed(topic)); } // Test negative cases for (pair_topic_type topic_name : real_topics_negative) { - DdsTopic topic(topic_name.first, topic_name.second); + DistributedTopic topic(topic_name.first, topic_name.second); ASSERT_FALSE(atl.is_topic_allowed(topic)); } } @@ -124,7 +124,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__default_constructor) for (pair_topic_type topic_name : real_topics) { - DdsTopic topic(topic_name.first, topic_name.second); + DistributedTopic topic(topic_name.first, topic_name.second); ASSERT_TRUE(atl.is_topic_allowed(topic)); } diff --git a/ddsrouter_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt similarity index 93% rename from ddsrouter_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt rename to ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt index b7492f301..a145292df 100644 --- a/ddsrouter_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt +++ b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt @@ -17,9 +17,9 @@ set(TEST_NAME AllowedTopicListTest) set(TEST_SOURCES AllowedTopicListTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic/AllowedTopicList.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RPCTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp diff --git a/ddsrouter_core/test/unittest/dynamic/discovery_database/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/discovery_database/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/dynamic/discovery_database/CMakeLists.txt rename to ddspipe_core/test/unittest/dynamic/discovery_database/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp b/ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp similarity index 92% rename from ddsrouter_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp rename to ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp index 36fda19e7..87d7fdee5 100644 --- a/ddsrouter_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp +++ b/ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp @@ -18,11 +18,11 @@ #include #include -#include -#include -#include +#include +#include +#include #include -#include +#include using namespace eprosima::ddsrouter::test; using namespace eprosima::utils; @@ -30,7 +30,7 @@ using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace core { namespace test { @@ -70,7 +70,7 @@ class DiscoveryDatabase : public eprosima::ddsrouter::core::DiscoveryDatabase } /* namespace test */ } /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ /** @@ -85,7 +85,7 @@ TEST(DiscoveryDatabaseTest, topic_exists) test::DiscoveryDatabase discovery_database; Guid guid_1 = random_guid(1); Guid guid_2 = random_guid(2); - DdsTopic topic("test", "test"); + DistributedTopic topic("test", "test"); Endpoint endpoint_1(EndpointKind::reader, guid_1, topic); Endpoint endpoint_2(EndpointKind::reader, guid_2, topic); @@ -111,7 +111,7 @@ TEST(DiscoveryDatabaseTest, endpoint_exists) { test::DiscoveryDatabase discovery_database; Guid guid; - DdsTopic topic("test", "test"); + DistributedTopic topic("test", "test"); Endpoint endpoint(EndpointKind::reader, guid, topic); ASSERT_FALSE(discovery_database.endpoint_exists(guid)); @@ -132,7 +132,7 @@ TEST(DiscoveryDatabaseTest, endpoint_exists) TEST(DiscoveryDatabaseTest, add_endpoint) { test::DiscoveryDatabase discovery_database; - DdsTopic topic("original", "original"); + DistributedTopic topic("original", "original"); // Create active endpoint Guid active_guid = random_guid(1); Endpoint active_endpoint(EndpointKind::reader, active_guid, topic); @@ -149,7 +149,7 @@ TEST(DiscoveryDatabaseTest, add_endpoint) // Add new endpoint with same guid as already stored active endpoint // Should throw \c InconsistencyException - DdsTopic new_topic("new", "new"); + DistributedTopic new_topic("new", "new"); Endpoint active_new_endpoint(EndpointKind::reader, active_guid, new_topic); ASSERT_THROW(discovery_database.add_endpoint_protected(active_new_endpoint), InconsistencyException); @@ -171,9 +171,9 @@ TEST(DiscoveryDatabaseTest, update_endpoint) { test::DiscoveryDatabase discovery_database; Guid guid = random_guid(1); - DdsTopic topic("original", "original"); + DistributedTopic topic("original", "original"); Endpoint endpoint(EndpointKind::reader, guid, topic); - DdsTopic new_topic("new", "new"); + DistributedTopic new_topic("new", "new"); Endpoint new_endpoint(EndpointKind::reader, guid, new_topic); // Endpoint to be updated not yet inserted ASSERT_THROW(discovery_database.update_endpoint_protected(new_endpoint), InconsistencyException); @@ -202,7 +202,7 @@ TEST(DiscoveryDatabaseTest, erase_endpoint) { test::DiscoveryDatabase discovery_database; Guid guid = random_guid(1); - DdsTopic topic("test", "test"); + DistributedTopic topic("test", "test"); Endpoint endpoint(EndpointKind::reader, guid, topic); // Endpoint to erase not yet inserted @@ -228,7 +228,7 @@ TEST(DiscoveryDatabaseTest, get_endpoint) { test::DiscoveryDatabase discovery_database; Guid guid = random_guid(1); - DdsTopic topic("test", "test"); + DistributedTopic topic("test", "test"); Endpoint endpoint(EndpointKind::reader, guid, topic); // Try to fetch a not stored endpoint diff --git a/ddspipe_core/test/unittest/efficiency/CMakeLists.txt b/ddspipe_core/test/unittest/efficiency/CMakeLists.txt new file mode 100644 index 000000000..692997a73 --- /dev/null +++ b/ddspipe_core/test/unittest/efficiency/CMakeLists.txt @@ -0,0 +1,118 @@ +# Copyright 2022 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. + +############################## +# Interface PayloadPool Test # +############################## + +set(TEST_NAME PayloadPoolTest) + +set(TEST_SOURCES + PayloadPoolTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ) + +set(TEST_LIST + reserve + release + reserve_and_release_counter + is_clean + get_payload_cache_change + get_payload_from_src_cache_change + release_payload_cache_change + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) + +######################## +# Map PayloadPool Test # +######################## + +set(TEST_NAME MapPayloadPoolTest) + +set(TEST_SOURCES + MapPayloadPoolTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/MapPayloadPool.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ) + +set(TEST_LIST + get_payload + get_payload_from_src + get_payload_from_src_no_owner + get_payload_from_src_negative + release_payload + release_payload_negative + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) + +######################## +# Fast PayloadPool Test # +######################## + +set(TEST_NAME FastPayloadPoolTest) + +set(TEST_SOURCES + FastPayloadPoolTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/FastPayloadPool.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ) + +set(TEST_LIST + get_payload + get_payload_from_src + get_payload_from_src_no_owner + get_payload_from_src_negative + release_payload + release_payload_negative + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp new file mode 100644 index 000000000..7283a2221 --- /dev/null +++ b/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp @@ -0,0 +1,324 @@ +// Copyright 2022 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. + +#include +#include + +#include + +#include +#include +#include + +using namespace eprosima::ddsrouter; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +const constexpr unsigned int TEST_NUMBER = 5; +const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace test { + +/** + * @brief Mock over FastPayloadPool implementing public access to private variables. + * + */ +class MockFastPayloadPool : public FastPayloadPool +{ +public: + + using FastPayloadPool::FastPayloadPool; + + uint64_t pointers_stored() + { + return reserve_count_ - release_count_; + } + + void release_all( + std::vector& payloads) + { + for (auto& payload : payloads) + { + release_payload(payload); + } + } + +}; + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +/* + * This tests does not check the methods calling cacheChange, this is tested in generic PayloadPool test. + */ + +/** + * Test get_payload method for new changes + * + * CASES: + * Get N different pointers + * fail reserve memory + */ +TEST(FastPayloadPoolTest, get_payload) +{ + // Get N different pointers + { + test::MockFastPayloadPool pool; + std::vector payloads(TEST_NUMBER); + + for (unsigned int i = 0; i < TEST_NUMBER; i++) + { + pool.get_payload(DEFAULT_SIZE, payloads[i]); + + ASSERT_EQ(payloads[i].max_size, DEFAULT_SIZE); + ASSERT_EQ(pool.pointers_stored(), i + 1); + } + + // END : Clean all remaining payloads + pool.release_all(payloads); + } + + // fail reserve memory + { + test::MockFastPayloadPool pool; + Payload payload; + + ASSERT_FALSE(pool.get_payload(0, payload)); + } +} + +/** + * Check to get_payload from a source that has been created in same pool increase references. + * + * STEPS: + * get payload0 + * get payload1 from src payload0 + * get payload2 from src payload1 + * release payload0 + * get payload3 from src payload1 + * get payload4 + * get payload5 from src payload4 + * release all + */ +TEST(FastPayloadPoolTest, get_payload_from_src) +{ + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockFastPayloadPool* pool_ = static_cast(pool); + + Payload payload0; + Payload payload1; + Payload payload2; + Payload payload3; + Payload payload4; + Payload payload5; + + // get payload0 + ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE, payload0)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + + // get payload1 from src payload0 + ASSERT_TRUE(pool_->get_payload(payload0, pool, payload1)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(payload1.max_size, payload0.max_size); + ASSERT_EQ(payload1.data, payload0.data); + + // get payload2 from src payload1 + ASSERT_TRUE(pool_->get_payload(payload1, pool, payload2)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(payload2.max_size, payload0.max_size); + ASSERT_EQ(payload2.data, payload0.data); + + // release payload0 + ASSERT_TRUE(pool_->release_payload(payload0)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + + // get payload3 from src payload1 + ASSERT_TRUE(pool_->get_payload(payload1, pool, payload3)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(payload3.max_size, payload1.max_size); + ASSERT_EQ(payload3.data, payload1.data); + + // get payload4 + ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE * 0x100, payload4)); + ASSERT_EQ(pool_->pointers_stored(), 2u); + + // get payload5 from src payload4 + ASSERT_TRUE(pool_->get_payload(payload4, pool, payload5)); + ASSERT_EQ(pool_->pointers_stored(), 2u); + ASSERT_EQ(payload5.max_size, payload4.max_size); + ASSERT_EQ(payload5.data, payload4.data); + + // release all + ASSERT_TRUE(pool_->release_payload(payload1)); + ASSERT_TRUE(pool_->release_payload(payload2)); + ASSERT_TRUE(pool_->release_payload(payload3)); + ASSERT_TRUE(pool_->release_payload(payload4)); + ASSERT_TRUE(pool_->release_payload(payload5)); + + // Check payload pool is empty + ASSERT_TRUE(pool_->is_clean()); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + delete pool; +} + +/** + * Check to get_payload from a source that has been created in a different pool + * + * STEPS: + * get payload aux from pool aux + * get payload from src payload aux + * release payload aux from pool aux + * release payload + */ +TEST(FastPayloadPoolTest, get_payload_from_src_no_owner) +{ + // Each pool has a IPayloadPool and a MockFastPayloadPool so it can be called to get_payload from source + // and specific methods from mock + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockFastPayloadPool* pool_ = static_cast(pool); + eprosima::fastrtps::rtps::IPayloadPool* pool_aux = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockFastPayloadPool* pool_aux_ = static_cast(pool_aux); + + Payload payload_src; + Payload payload_target; + + // get payload aux from pool aux + pool_aux_->get_payload(DEFAULT_SIZE, payload_src); + ASSERT_EQ(pool_aux_->pointers_stored(), 1u); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + // get payload from src payload aux + ASSERT_TRUE(pool_->get_payload(payload_src, pool_aux, payload_target)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + + // release payload aux from pool aux + pool_aux_->release_payload(payload_src); + ASSERT_EQ(pool_aux_->pointers_stored(), 0u); + ASSERT_EQ(pool_->pointers_stored(), 1u); + + // release payload + pool_->release_payload(payload_target); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + delete pool_aux; + delete pool; +} + +/** + * Check negative cases for get_payload from source + * + * CASES: + * Source has size 0 and different owner + */ +TEST(FastPayloadPoolTest, get_payload_from_src_negative) +{ + // Source has size 0 and different owner + { + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockFastPayloadPool* pool_ = static_cast(pool); + eprosima::fastrtps::rtps::IPayloadPool* pool_aux = nullptr; // nullptr + + Payload payload_src; + Payload payload_target; + + ASSERT_FALSE( + pool_->get_payload( + payload_src, + pool_aux, + payload_target)); + + delete pool; + } +} + +/** + * Get some payloads from pool from src and release each of them separatly checking reference count + * + * STEPS: + * get first payload + * get N-1 payloads from first + * release N-2 payloads + * get N-2 more payloads from first + * release N payloads + */ +TEST(FastPayloadPoolTest, release_payload) +{ + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockFastPayloadPool* pool_ = static_cast(pool); + std::vector payloads(TEST_NUMBER); + + // get first payload + pool_->get_payload(DEFAULT_SIZE, payloads[0]); + + // get N-1 payloads from first + for (unsigned int i = 1; i < TEST_NUMBER; i++) + { + pool_->get_payload(payloads[0], pool, payloads[i]); + } + + // release N-2 payloads + for (unsigned int i = 2; i < TEST_NUMBER; i++) + { + ASSERT_TRUE(pool_->release_payload(payloads[i])); + } + + // get N-2 more payloads from first + for (unsigned int i = 2; i < TEST_NUMBER; i++) + { + pool_->get_payload(payloads[0], pool, payloads[i]); + } + + // release N payloads + for (unsigned int i = 1; i < TEST_NUMBER; i++) + { + ASSERT_TRUE(pool_->release_payload(payloads[i])); + } + // Removing last payload because if not the reference count cannot be done + ASSERT_TRUE(pool_->release_payload(payloads[0])); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + // Check payload pool is empty + ASSERT_TRUE(pool_->is_clean()); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + delete pool; +} + +/** + * Check release a payload that has been get from a different payload pool + */ +TEST(FastPayloadPoolTest, release_payload_negative) +{ + test::MockFastPayloadPool pool; + test::MockFastPayloadPool pool_aux; + Payload payload; + + pool_aux.get_payload(DEFAULT_SIZE, payload); + + ASSERT_THROW(pool.release_payload(payload), eprosima::utils::InconsistencyException); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp new file mode 100644 index 000000000..d57178816 --- /dev/null +++ b/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp @@ -0,0 +1,366 @@ +// Copyright 2022 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. + +#include +#include + +#include + +#include +#include +#include + +using namespace eprosima::ddsrouter; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +const constexpr unsigned int TEST_NUMBER = 5; +const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace test { + +/** + * @brief Mock over MapPayloadPool implementing public access to private variables. + * + */ +class MockMapPayloadPool : public MapPayloadPool +{ +public: + + using MapPayloadPool::MapPayloadPool; + + uint64_t pointers_stored() + { + return reserved_payloads_.size(); + } + + uint64_t reference_count( + const Payload& payload) + { + return reserved_payloads_[payload.data]; + } + + void clean_all( + std::vector& payloads) + { + for (Payload& payload : payloads) + { + release_payload(payload); + } + } + +}; + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +/* + * This tests does not check the methods calling cacheChange, this is tested in generic PayloadPool test. + */ + +/** + * Test get_payload method for new changes + * + * CASES: + * Get N different pointers + * fail reserve memory + */ +TEST(MapPayloadPoolTest, get_payload) +{ + // Get N different pointers + { + test::MockMapPayloadPool pool; + std::vector payloads(TEST_NUMBER); + + for (unsigned int i = 0; i < TEST_NUMBER; i++) + { + pool.get_payload(DEFAULT_SIZE, payloads[i]); + + ASSERT_EQ(payloads[i].max_size, DEFAULT_SIZE); + ASSERT_EQ(pool.pointers_stored(), i + 1); + ASSERT_EQ(pool.reference_count(payloads[i]), 1u); + } + + // END : Clean all remaining payloads + pool.clean_all(payloads); + } + + // fail reserve memory + { + test::MockMapPayloadPool pool; + Payload payload; + + ASSERT_FALSE(pool.get_payload(0, payload)); + } +} + +/** + * Check to get_payload from a source that has been created in same pool increase references. + * + * STEPS: + * get payload0 + * get payload1 from src payload0 + * get payload2 from src payload1 + * release payload0 + * get payload3 from src payload1 + * get payload4 + * get payload5 from src payload4 + * release all + */ +TEST(MapPayloadPoolTest, get_payload_from_src) +{ + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockMapPayloadPool* pool_ = static_cast(pool); + + Payload payload0; + Payload payload1; + Payload payload2; + Payload payload3; + Payload payload4; + Payload payload5; + + // get payload0 + ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE, payload0)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(pool_->reference_count(payload0), 1u); + + // get payload1 from src payload0 + ASSERT_TRUE(pool_->get_payload(payload0, pool, payload1)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(pool_->reference_count(payload1), 2u); + ASSERT_EQ(payload1.max_size, payload0.max_size); + ASSERT_EQ(payload1.data, payload0.data); + + // get payload2 from src payload1 + ASSERT_TRUE(pool_->get_payload(payload1, pool, payload2)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(pool_->reference_count(payload2), 3u); + ASSERT_EQ(payload2.max_size, payload0.max_size); + ASSERT_EQ(payload2.data, payload0.data); + + // release payload0 + ASSERT_TRUE(pool_->release_payload(payload0)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(pool_->reference_count(payload2), 2u); + + // get payload3 from src payload1 + ASSERT_TRUE(pool_->get_payload(payload1, pool, payload3)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + ASSERT_EQ(pool_->reference_count(payload3), 3u); + ASSERT_EQ(payload3.max_size, payload1.max_size); + ASSERT_EQ(payload3.data, payload1.data); + + // get payload4 + ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE * 0x100, payload4)); + ASSERT_EQ(pool_->pointers_stored(), 2u); + ASSERT_EQ(pool_->reference_count(payload1), 3u); + ASSERT_EQ(pool_->reference_count(payload4), 1u); + + // get payload5 from src payload4 + ASSERT_TRUE(pool_->get_payload(payload4, pool, payload5)); + ASSERT_EQ(pool_->pointers_stored(), 2u); + ASSERT_EQ(pool_->reference_count(payload1), 3u); + ASSERT_EQ(pool_->reference_count(payload5), 2u); + ASSERT_EQ(payload5.max_size, payload4.max_size); + ASSERT_EQ(payload5.data, payload4.data); + + // release all + ASSERT_TRUE(pool_->release_payload(payload1)); + ASSERT_TRUE(pool_->release_payload(payload2)); + ASSERT_TRUE(pool_->release_payload(payload3)); + ASSERT_TRUE(pool_->release_payload(payload4)); + ASSERT_TRUE(pool_->release_payload(payload5)); + + // Check payload pool is empty + ASSERT_TRUE(pool_->is_clean()); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + delete pool; +} + +/** + * Check to get_payload from a source that has been created in a different pool + * + * STEPS: + * get payload aux from pool aux + * get payload from src payload aux + * release payload aux from pool aux + * release payload + */ +TEST(MapPayloadPoolTest, get_payload_from_src_no_owner) +{ + // Each pool has a IPayloadPool and a MockMapPayloadPool so it can be called to get_payload from source + // and specific methods from mock + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockMapPayloadPool* pool_ = static_cast(pool); + eprosima::fastrtps::rtps::IPayloadPool* pool_aux = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockMapPayloadPool* pool_aux_ = static_cast(pool_aux); + + Payload payload_src; + Payload payload_target; + + // get payload aux from pool aux + pool_aux_->get_payload(DEFAULT_SIZE, payload_src); + ASSERT_EQ(pool_aux_->pointers_stored(), 1u); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + // get payload from src payload aux + ASSERT_TRUE(pool_->get_payload(payload_src, pool_aux, payload_target)); + ASSERT_EQ(pool_->pointers_stored(), 1u); + + // release payload aux from pool aux + pool_aux_->release_payload(payload_src); + ASSERT_EQ(pool_aux_->pointers_stored(), 0u); + ASSERT_EQ(pool_->pointers_stored(), 1u); + + // release payload + pool_->release_payload(payload_target); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + delete pool_aux; + delete pool; +} + +/** + * Check negative cases for get_payload from source + * + * CASES: + * The source says the owner is the same pool, but is not + * Source has size 0 and different owner + */ +TEST(MapPayloadPoolTest, get_payload_from_src_negative) +{ + // The source says the owner is the same pool, but is not + { + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockMapPayloadPool* pool_ = static_cast(pool); + test::MockMapPayloadPool pool_aux; + + Payload payload_src; + Payload payload_target; + + // Get payload for source + pool_aux.get_payload(DEFAULT_SIZE, payload_src); + + // In a different pool, try to source it as if it was from same pool + ASSERT_THROW(pool_->get_payload(payload_src, pool, payload_target), eprosima::utils::InconsistencyException); + + // END : release payload + pool_aux.release_payload(payload_src); + + delete pool; + } + + // Source has size 0 and different owner + { + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockMapPayloadPool* pool_ = static_cast(pool); + eprosima::fastrtps::rtps::IPayloadPool* pool_aux = nullptr; // nullptr + + Payload payload_src; + Payload payload_target; + + ASSERT_FALSE( + pool_->get_payload( + payload_src, + pool_aux, + payload_target)); + + delete pool; + } +} + +/** + * Get some payloads from pool from src and release each of them separatly checking reference count + * + * STEPS: + * get first payload + * get N-1 payloads from first + * release N-2 payloads + * get N-2 more payloads from first + * release N payloads + */ +TEST(MapPayloadPoolTest, release_payload) +{ + eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload + test::MockMapPayloadPool* pool_ = static_cast(pool); + std::vector payloads(TEST_NUMBER); + + // get first payload + pool_->get_payload(DEFAULT_SIZE, payloads[0]); + + // get N-1 payloads from first + for (unsigned int i = 1; i < TEST_NUMBER; i++) + { + pool_->get_payload(payloads[0], pool, payloads[i]); + ASSERT_EQ(pool_->reference_count(payloads[0]), i + 1) << i; + } + + // release N-2 payloads + for (unsigned int i = 2; i < TEST_NUMBER; i++) + { + ASSERT_TRUE(pool_->release_payload(payloads[i])); + ASSERT_EQ(pool_->reference_count(payloads[0]), TEST_NUMBER + 1 - i) << i; + } + + // get N-2 more payloads from first + for (unsigned int i = 2; i < TEST_NUMBER; i++) + { + pool_->get_payload(payloads[0], pool, payloads[i]); + ASSERT_EQ(pool_->reference_count(payloads[0]), i + 1) << i; + } + + // release N payloads + for (unsigned int i = 1; i < TEST_NUMBER; i++) + { + ASSERT_TRUE(pool_->release_payload(payloads[i])); + ASSERT_EQ(pool_->reference_count(payloads[0]), TEST_NUMBER - i) << i; + } + // Removing last payload because if not the reference count cannot be done + ASSERT_TRUE(pool_->release_payload(payloads[0])); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + // Check payload pool is empty + ASSERT_TRUE(pool_->is_clean()); + ASSERT_EQ(pool_->pointers_stored(), 0u); + + delete pool; +} + +/** + * Check release a payload that has been get from a different payload pool + */ +TEST(MapPayloadPoolTest, release_payload_negative) +{ + test::MockMapPayloadPool pool; + test::MockMapPayloadPool pool_aux; + Payload payload; + + pool_aux.get_payload(DEFAULT_SIZE, payload); + + ASSERT_THROW(pool.release_payload(payload), eprosima::utils::InconsistencyException); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp new file mode 100644 index 000000000..60f64b654 --- /dev/null +++ b/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp @@ -0,0 +1,413 @@ +// Copyright 2022 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. + +#include +#include +#include + +#include +#include + +#include +#include +#include + +using namespace eprosima::ddsrouter; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +// Using for gmock +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; + +namespace eprosima { +namespace fastrtps { +namespace rtps { + +/* + * WORKAROUND: + * This definition is needed due to googletest-distribution (1.11.0) requires to every class used inside ASSERT macro + * to have the operator << defined in SAME namespace than the class. + * In our case, Payload is defined as eprosima::fastrtps::rtps::SerializedPayload_t but redefined as + * eprosima::ddsrouter::core::types::Payload and the operator << is defined in eprosima::ddsrouter::core::types + * Thus, gtest could not find this definition (arising a very messy and cryptic compilation error). + * This definition corrects that problem. + * + * NOTE: + * In googletest-distribution release-1.10.0 this does not happen. + */ +void PrintTo( + const SerializedPayload_t, + std::ostream* os) +{ + *os << "::eprosima::fastrtps::rtps::SerializedPayload_t"; +} + +} /* namespace rtps */ +} /* namespace fastrtps */ +} /* namespace eprosima */ + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace test { + +/** + * @brief Mock over Payload Pool re-implementing the needed methods returning error and + * implementing public access to private variables. + * + */ +class MockPayloadPool : public PayloadPool +{ +public: + + // Using parent methods and variables as public + using PayloadPool::PayloadPool; + using PayloadPool::get_payload; + using PayloadPool::release_payload; + using PayloadPool::reserve_; + using PayloadPool::release_; + using PayloadPool::reserve_count_; + using PayloadPool::release_count_; + + // Mock this virtual methods not implemented in parent class + MOCK_METHOD( + bool, + get_payload, + (uint32_t size, eprosima::ddsrouter::core::types::Payload& target_payload), + (override)); + + MOCK_METHOD( + bool, + get_payload, + ( + const Payload& src_payload, + eprosima::fastrtps::rtps::IPayloadPool*&data_owner, + eprosima::ddsrouter::core::types::Payload& target_payload + ), + (override)); + + MOCK_METHOD( + bool, + release_payload, + (eprosima::ddsrouter::core::types::Payload& target_payload), + (override)); +}; + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +/** + * Test reserve_ method + * + * CASES: + * small size + * large size + * 0 size + */ +TEST(PayloadPoolTest, reserve) +{ + // small size + { + test::MockPayloadPool pool; + Payload payload; + + ASSERT_EQ(payload.max_size, 0u); + ASSERT_EQ(payload.data, nullptr); + + ASSERT_TRUE(pool.reserve_(sizeof(PayloadUnit), payload)); + + ASSERT_EQ(payload.max_size, sizeof(PayloadUnit)); + ASSERT_NE(payload.data, nullptr); + + // This would (maybe) fail with SEG FAULT if the data has not been correctly set + payload.data[0] = 16u; + } + + // large size + { + test::MockPayloadPool pool; + Payload payload; + + ASSERT_EQ(payload.max_size, 0u); + ASSERT_EQ(payload.data, nullptr); + + ASSERT_TRUE(pool.reserve_(sizeof(PayloadUnit) * 0x1000, payload)); + + ASSERT_EQ(payload.max_size, sizeof(PayloadUnit) * 0x1000); + ASSERT_NE(payload.data, nullptr); + + // This would (maybe) fail with SEG FAULT if the data has not been correctly set + payload.data[0] = 4u; + payload.data[0x1000 - 1] = 5u; + } + + // 0 size + { + test::MockPayloadPool pool; + Payload payload; + + ASSERT_EQ(payload.max_size, 0u); + + ASSERT_FALSE(pool.reserve_(0, payload)); + + ASSERT_EQ(payload.max_size, 0u); + } +} + +/** + * Test release_ method + * + * CASES: + * small size + * large size + */ +TEST(PayloadPoolTest, release) +{ + // small size + { + test::MockPayloadPool pool; + Payload payload; + pool.reserve_(sizeof(PayloadUnit), payload); + + ASSERT_EQ(payload.max_size, sizeof(PayloadUnit)); + ASSERT_NE(payload.data, nullptr); + + ASSERT_TRUE(pool.release_(payload)); + + ASSERT_EQ(payload.max_size, 0u); + ASSERT_EQ(payload.data, nullptr); + } + + // large size + { + test::MockPayloadPool pool; + Payload payload; + pool.reserve_(sizeof(PayloadUnit) * 0x1000, payload); + + ASSERT_EQ(payload.max_size, sizeof(PayloadUnit) * 0x1000); + ASSERT_NE(payload.data, nullptr); + + ASSERT_TRUE(pool.release_(payload)); + + ASSERT_EQ(payload.max_size, 0u); + ASSERT_EQ(payload.data, nullptr); + } +} + +/** + * Test release_ method + * + * STEPS: + * store 5 values + * release 4 values + * store 5 more values + * release 6 values + * release more values than reserved + */ +TEST(PayloadPoolTest, reserve_and_release_counter) +{ + test::MockPayloadPool pool; + std::vector payloads(11); + + // store 5 values + for (unsigned int i = 0; i < 5u; ++i) + { + ASSERT_EQ(pool.reserve_count_, i); + pool.reserve_(sizeof(PayloadUnit), payloads[i]); + } + ASSERT_EQ(pool.reserve_count_, 5u); + + // release 4 values + for (unsigned int i = 0; i < 4u; ++i) + { + ASSERT_EQ(pool.release_count_, i); + pool.release_(payloads[i]); + } + ASSERT_EQ(pool.release_count_, 4u); + + // store 5 values + for (unsigned int i = 5; i < 10u; ++i) + { + ASSERT_EQ(pool.reserve_count_, i); + pool.reserve_(sizeof(PayloadUnit), payloads[i]); + } + ASSERT_EQ(pool.reserve_count_, 10u); + + // release 6 values + for (unsigned int i = 4; i < 10u; ++i) + { + ASSERT_EQ(pool.release_count_, i); + pool.release_(payloads[i]); + } + ASSERT_EQ(pool.release_count_, 10u); + + // release more values than reserved + ASSERT_THROW(pool.release_(payloads[10]), eprosima::utils::InconsistencyException); +} + +/** + * Test clean method + * + * STEPS: + * start clean + * reserve and not clean + * release and clean + */ +TEST(PayloadPoolTest, is_clean) +{ + test::MockPayloadPool pool; + + // start clean + ASSERT_TRUE(pool.is_clean()); + + // reserve and not clean + eprosima::fastrtps::rtps::CacheChange_t cc; + pool.reserve_(sizeof(PayloadUnit), cc.serializedPayload); + ASSERT_FALSE(pool.is_clean()); + + // release and clean + pool.release_(cc.serializedPayload); + ASSERT_TRUE(pool.is_clean()); +} + +/** + * Test get_payload cache_change fails if the child class fails + * + * CASES: + * - get_payload for payload goes ok + * - get_payload for payload fails + */ +TEST(PayloadPoolTest, get_payload_cache_change) +{ + // get_payload for payload goes ok + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t cc; + + EXPECT_CALL(pool, get_payload(_, _)).Times(1).WillOnce(Return(true)); + + EXPECT_TRUE(pool.get_payload(sizeof(PayloadUnit), cc)); + + // Clean cache change correctly so process dont break + cc.payload_owner(nullptr); + } + + // get_payload for payload goes ok + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t cc; + + EXPECT_CALL(pool, get_payload(_, _)).Times(1).WillOnce(Return(false)); + + EXPECT_FALSE(pool.get_payload(sizeof(PayloadUnit), cc)); + } +} + +/** + * Test get_payload cache_change with source fails if the child class fails + * + * CASES: + * - get_payload for payload goes ok + * - get_payload for payload fails + */ +TEST(PayloadPoolTest, get_payload_from_src_cache_change) +{ + // get_payload for payload goes ok + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t target; + Payload source; + eprosima::fastrtps::rtps::IPayloadPool* aux_pool; + + EXPECT_CALL(pool, get_payload(_, _, _)).Times(1).WillOnce(Return(true)); + + EXPECT_TRUE(pool.get_payload(source, aux_pool, target)); + + // Clean cache change correctly so process dont break + target.payload_owner(nullptr); + } + + // get_payload for payload goes ok + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t target; + Payload source; + eprosima::fastrtps::rtps::IPayloadPool* aux_pool; + + EXPECT_CALL(pool, get_payload(_, _, _)).Times(1).WillOnce(Return(false)); + + EXPECT_FALSE(pool.get_payload(source, aux_pool, target)); + } +} + +/** + * Test release_payload cache_change method using MockPayloadPool when inside get_payload method fails + * + * CASES: + * different ownership + * this ownership release ok + * this ownership release fail + */ +TEST(PayloadPoolTest, release_payload_cache_change) +{ + // different ownership + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t cc; + cc.payload_owner(nullptr); + + EXPECT_THROW(pool.release_payload(cc), eprosima::utils::InconsistencyException); + } + + // this ownership release ok + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t cc; + + // ownership must be this pool + cc.payload_owner(&pool); + + EXPECT_CALL(pool, release_payload(_)).Times(1).WillOnce(Return(true)); + + EXPECT_TRUE(pool.release_payload(cc)); + } + + // this ownership release fail + { + test::MockPayloadPool pool; + eprosima::fastrtps::rtps::CacheChange_t cc; + + // ownership must be this pool + cc.payload_owner(&pool); + + EXPECT_CALL(pool, release_payload(_)).Times(1).WillOnce(Return(false)); + + EXPECT_FALSE(pool.release_payload(cc)); + + // Clean cache change correctly so process dont break + cc.payload_owner(nullptr); + } +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_core/test/unittest/types/CMakeLists.txt b/ddspipe_core/test/unittest/types/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/types/CMakeLists.txt rename to ddspipe_core/test/unittest/types/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt b/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt similarity index 93% rename from ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt rename to ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt index d5b0070aa..927ffbf5d 100644 --- a/ddsrouter_core/test/unittest/types/endpoint/CMakeLists.txt +++ b/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt @@ -52,11 +52,11 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/types/endpoint/Endpoint.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RPCTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/SpecificEndpointQoS.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ) diff --git a/ddsrouter_core/test/unittest/types/endpoint/EndpointTest.cpp b/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp similarity index 90% rename from ddsrouter_core/test/unittest/types/endpoint/EndpointTest.cpp rename to ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp index 1426f5516..7bac737ce 100644 --- a/ddsrouter_core/test/unittest/types/endpoint/EndpointTest.cpp +++ b/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp @@ -15,9 +15,9 @@ #include #include -#include -#include -#include +#include +#include +#include using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; @@ -63,10 +63,10 @@ TopicQoS random_qos( } // Get a random topic name -DdsTopic random_topic( +DistributedTopic random_topic( uint16_t seed = 0) { - return DdsTopic("TopicName_" + std::to_string(seed), "TopicType_" + std::to_string(seed), false, random_qos(seed)); + return DistributedTopic("TopicName_" + std::to_string(seed), "TopicType_" + std::to_string(seed), false, random_qos(seed)); } // Get a random topic name @@ -101,7 +101,7 @@ TEST(EndpointTest, constructor) { EndpointKind kind; Guid guid; - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); // TODO: add data qos Endpoint endpoint(kind, guid, topic); @@ -122,7 +122,7 @@ TEST(EndpointTest, constructor) TEST(EndpointTest, kind_getter) { Guid guid; - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); // Writer { @@ -146,7 +146,7 @@ TEST(EndpointTest, kind_getter) */ TEST(EndpointTest, guid_getter) { - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); EndpointKind kind = random_endpoint_kind(); // Default guid @@ -176,7 +176,7 @@ TEST(EndpointTest, guid_getter) TEST(EndpointTest, qos_getter) { Guid guid = random_valid_guid(); - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); EndpointKind kind = random_endpoint_kind(); // Random guids @@ -204,7 +204,7 @@ TEST(EndpointTest, topic_getter) { for (uint16_t i = 0; i < 10u; i++) { - DdsTopic topic = random_topic(i); + DistributedTopic topic = random_topic(i); Endpoint endpoint(kind, guid, topic); ASSERT_EQ(endpoint.topic(), random_topic(i)) << i; } @@ -222,7 +222,7 @@ TEST(EndpointTest, topic_getter) TEST(EndpointTest, active_getter) { Guid guid = random_valid_guid(); - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); EndpointKind kind = random_endpoint_kind(); // Default value @@ -259,7 +259,7 @@ TEST(EndpointTest, active_getter) TEST(EndpointTest, active_setter) { Guid guid = random_valid_guid(); - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); EndpointKind kind = random_endpoint_kind(); // Default value @@ -294,7 +294,7 @@ TEST(EndpointTest, active_setter) TEST(EndpointTest, is_writer) { Guid guid; - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); // Writer { @@ -319,7 +319,7 @@ TEST(EndpointTest, is_writer) TEST(EndpointTest, is_reader) { Guid guid; - DdsTopic topic = random_topic(); + DistributedTopic topic = random_topic(); // Writer { diff --git a/ddsrouter_core/test/unittest/types/endpoint/GuidTest.cpp b/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp similarity index 98% rename from ddsrouter_core/test/unittest/types/endpoint/GuidTest.cpp rename to ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp index 32a93f552..0c5884add 100644 --- a/ddsrouter_core/test/unittest/types/endpoint/GuidTest.cpp +++ b/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; diff --git a/ddsrouter_core/test/unittest/types/topic/CMakeLists.txt b/ddspipe_core/test/unittest/types/topic/CMakeLists.txt similarity index 93% rename from ddsrouter_core/test/unittest/types/topic/CMakeLists.txt rename to ddspipe_core/test/unittest/types/topic/CMakeLists.txt index bcbfba457..1eeb42b1f 100644 --- a/ddsrouter_core/test/unittest/types/topic/CMakeLists.txt +++ b/ddspipe_core/test/unittest/types/topic/CMakeLists.txt @@ -39,14 +39,14 @@ add_unittest_executable( ) ############# -# DdsTopic # +# DistributedTopic # ############# set(TEST_NAME DdsTopicTest) set(TEST_SOURCES DdsTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp ) @@ -77,7 +77,7 @@ set(TEST_NAME WildcardTopicTest) set(TEST_SOURCES WildcardDdsFilterTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp diff --git a/ddsrouter_core/test/unittest/types/topic/DdsTopicTest.cpp b/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp similarity index 84% rename from ddsrouter_core/test/unittest/types/topic/DdsTopicTest.cpp rename to ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp index 17a196c91..4a6f610ce 100644 --- a/ddsrouter_core/test/unittest/types/topic/DdsTopicTest.cpp +++ b/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; @@ -23,7 +23,7 @@ using namespace eprosima::ddsrouter::core::types; using pair_topic_type = std::pair; /** - * Test DdsTopic is_valid_dds_topic method for positive cases + * Test DistributedTopic is_valid_dds_topic method for positive cases */ TEST(DdsTopicTest, is_valid_dds_topic) { @@ -39,12 +39,12 @@ TEST(DdsTopicTest, is_valid_dds_topic) for (pair_topic_type topic : topics) { - ASSERT_TRUE(DdsTopic::is_valid_dds_topic(topic.first, topic.second)); + ASSERT_TRUE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); } } /** - * Test DdsTopic is_valid_dds_topic method for negative cases + * Test DistributedTopic is_valid_dds_topic method for negative cases */ TEST(DdsTopicTest, is_valid_dds_topic_negative) { @@ -77,7 +77,7 @@ TEST(DdsTopicTest, is_valid_dds_topic_negative) for (pair_topic_type topic : topics) { - ASSERT_FALSE(DdsTopic::is_valid_dds_topic(topic.first, topic.second)); + ASSERT_FALSE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); } } diff --git a/ddsrouter_core/test/unittest/types/topic/TopicTest.cpp b/ddspipe_core/test/unittest/types/topic/TopicTest.cpp similarity index 97% rename from ddsrouter_core/test/unittest/types/topic/TopicTest.cpp rename to ddspipe_core/test/unittest/types/topic/TopicTest.cpp index 98382aeef..4d33842c9 100644 --- a/ddsrouter_core/test/unittest/types/topic/TopicTest.cpp +++ b/ddspipe_core/test/unittest/types/topic/TopicTest.cpp @@ -17,7 +17,7 @@ #include -#include +#include using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::core::types; diff --git a/ddsrouter_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp b/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp similarity index 93% rename from ddsrouter_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp rename to ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp index cd3f417f4..9d4c3d9dd 100644 --- a/ddsrouter_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp +++ b/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; @@ -115,10 +115,10 @@ TEST(WildcardTopicTest, matches) wt.topic_name = test_case.first.first; wt.type_name = test_case.first.second; - // For every topic to test, create a DdsTopic and test + // For every topic to test, create a DistributedTopic and test for (auto real_topic_names : test_case.second) { - DdsTopic real_topic(real_topic_names.first, real_topic_names.second); + DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); ASSERT_TRUE(wt.matches(real_topic)) << "wildcard: " << wt << " ; real: " << real_topic; } @@ -159,7 +159,7 @@ TEST(WildcardTopicTest, non_contains_wildcard) wt.topic_name = test_case.first.first; wt.type_name = test_case.first.second; - // For every topic to test, create a DdsTopic and test + // For every topic to test, create a DistributedTopic and test for (auto real_topic_names : test_case.second) { WildcardDdsFilterTopic contained_topic; @@ -205,10 +205,10 @@ TEST(WildcardTopicTest, non_matches) wt.topic_name = test_case.first.first; wt.type_name = test_case.first.second; - // For every topic to test, create a DdsTopic and test + // For every topic to test, create a DistributedTopic and test for (auto real_topic_names : test_case.second) { - DdsTopic real_topic(real_topic_names.first, real_topic_names.second); + DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); ASSERT_FALSE(wt.matches(real_topic)); } diff --git a/ddspipe_participants/CMakeLists.txt b/ddspipe_participants/CMakeLists.txt new file mode 100644 index 000000000..644d5c7d4 --- /dev/null +++ b/ddspipe_participants/CMakeLists.txt @@ -0,0 +1,78 @@ +# Copyright 2022 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. + +############################################################################### +# CMake build rules for DDS Router Submodule +############################################################################### +cmake_minimum_required(VERSION 3.5) + +############################################################################### +# Find package cmake_utils +############################################################################### +# Package cmake_utils is required to get every cmake macro needed +find_package(cmake_utils REQUIRED) + +############################################################################### +# Project +############################################################################### +# Configure project by info set in project_settings.cmake +# - Load project_settings variables +# - Read version +# - Set installation paths +configure_project() + +# Call explictly project +project( + ${MODULE_NAME} + VERSION + ${MODULE_VERSION} + DESCRIPTION + ${MODULE_DESCRIPTION} + LANGUAGES + CXX +) + +############################################################################### +# C++ Project +############################################################################### +# Configure CPP project for dependencies and required flags: +# - Set CMake Build Type +# - Set C++ version +# - Set shared libraries by default +# - Find external packages and thirdparties +# - Activate Code coverage if flag CODE_COVERAGE +# - Activate Address sanitizer build if flag ASAN_BUILD +# - Activate Thread sanitizer build if flag TSAN_BUILD +# - Configure log depending on LOG_INFO flag and CMake type +configure_project_cpp() + +# Compile C++ library +compile_library( + "${PROJECT_SOURCE_DIR}/src/cpp" # Source directory + "${PROJECT_SOURCE_DIR}/include" # Include directory +) + +############################################################################### +# Test +############################################################################### +# Compile tests if CMake options requires it +compile_test_library( + "${PROJECT_SOURCE_DIR}/test" # Test directory +) + +############################################################################### +# Packaging +############################################################################### +# Install package +eprosima_packaging() diff --git a/ddspipe_participants/README.md b/ddspipe_participants/README.md new file mode 100644 index 000000000..5599ab6cf --- /dev/null +++ b/ddspipe_participants/README.md @@ -0,0 +1,53 @@ +# eProsima DDS Router Core Library + +This library contain main functionality of the DDS Router. +Include module is the public API used to configure a DDS Router and to interact with a running one: + +* **Types**: data types used to configure a router. + * Address + * DDS info (Guid, Qos, Topic, etc.) + +* **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: + * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. + * *DDSRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. + * *DDSRouterReloadConfiguration*: configuration to change topics in a running DDS Router. + +* **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. + It allows to execute a DDS Router, and to interact with it while running. + +--- + +## Example of usage + +```cpp +// START AND STOP DDS ROUTER FROM CONFIGURATION + +core::DDSRouterConfiguration router_configuration; + +// ... populate router_configuration + +core::DDSRouter router(router_configuration); +router.start(); + +// ... wait for event + +router.stop(); +``` + +--- + +## Dependencies + +* `fastrtps` +* `cpp_utils` + +--- + +## How to use it in your project + +Just import library `ddsrouter_core` into your CMake project. + +```cmake +find_package(ddsrouter_core) +target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_core) +``` diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp new file mode 100644 index 000000000..50bdc37b8 --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp @@ -0,0 +1,64 @@ +// Copyright 2021 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\. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + + +namespace eprosima { +namespace ddspipe { +namespace participants { + +/** + * This class joins Discovery Server Participant Configuration features and gives methods to interact with it. + */ +struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration +{ + + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI DiscoveryServerParticipantConfiguration() = default; + + ///////////////////////// + // METHODS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + + ///////////////////////// + // VARIABLES + ///////////////////////// + + core::types::GuidPrefix discovery_server_guid_prefix {}; + + std::set listening_addresses {}; + + std::set connection_addresses {}; + + types::TlsConfiguration tls_configuration {}; +}; + +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/EchoParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp similarity index 70% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/EchoParticipantConfiguration.hpp rename to ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp index 76f8d9a9c..81074a3ac 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/EchoParticipantConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp @@ -10,19 +10,14 @@ // 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. +// limitations under the License\. -/** - * @file EchoParticipantConfiguration.hpp - */ +#pragma once -#ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_ECHOPARTICIPANTCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_ECHOPARTICIPANTCONFIGURATION_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { struct EchoParticipantConfiguration : public ParticipantConfiguration @@ -34,7 +29,7 @@ struct EchoParticipantConfiguration : public ParticipantConfiguration ///////////////////////// // CONSTRUCTORS ///////////////////////// - DDSROUTER_CORE_DllAPI EchoParticipantConfiguration() = default; + DDSPIPE_PARTICIPANTS_DllAPI EchoParticipantConfiguration() = default; ///////////////////////// // VARIABLES @@ -49,7 +44,5 @@ struct EchoParticipantConfiguration : public ParticipantConfiguration }; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_ECHOPARTICIPANTCONFIGURATION_HPP_ */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp new file mode 100644 index 000000000..26a76b80e --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp @@ -0,0 +1,64 @@ +// Copyright 2022 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\. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + + +namespace eprosima { +namespace ddspipe { +namespace participants { + +/** + * This data struct joins Initial Peers Participant Configuration features + */ +struct InitialPeersParticipantConfiguration : public SimpleParticipantConfiguration +{ + + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI InitialPeersParticipantConfiguration() = default; + + + ///////////////////////// + // METHODS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + + + ///////////////////////// + // VARIABLES + ///////////////////////// + + std::set listening_addresses {}; + + std::set connection_addresses {}; + + types::TlsConfiguration tls_configuration {}; +}; + +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp new file mode 100644 index 000000000..ae1f7a7dc --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp @@ -0,0 +1,52 @@ +// Copyright 2021 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\. + +#pragma once + +#include + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { + +struct ParticipantConfiguration : public core::BaseConfiguration +{ + + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI ParticipantConfiguration() = default; + + + ///////////////////////// + // METHODS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + + //! Participant Id associated with this configuration + core::types::ParticipantId id {}; + + //! Whether this Participant should connect its readers with its writers. + bool is_repeater {false}; +}; + +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp new file mode 100644 index 000000000..31a00e2b0 --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp @@ -0,0 +1,53 @@ +// Copyright 2021 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\. + +#pragma once + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { + +/** + * This data struct represents a configuration for a SimpleParticipant + */ +struct SimpleParticipantConfiguration : public ParticipantConfiguration +{ +public: + + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + DDSPIPE_PARTICIPANTS_DllAPI SimpleParticipantConfiguration() = default; + + ///////////////////////// + // METHODS + ///////////////////////// + + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + + ///////////////////////// + // VARIABLES + ///////////////////////// + + core::types::DomainId domain {0u}; +}; + +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp similarity index 64% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp rename to ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp index 753f5c4d6..be68f413d 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BlankParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp @@ -12,18 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BlankParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BLANKPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BLANKPARTICIPANT_HPP_ +#pragma once -#include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -52,19 +46,11 @@ class BlankParticipant : public core::IParticipant //! Override create_writer() IParticipant method std::shared_ptr create_writer( - core::types::DdsTopic topic) override; + const core::ITopic& topic) override; //! Override create_reader() IParticipant method std::shared_ptr create_reader( - core::types::DdsTopic topic) override; - - //! Override delete_writer() IParticipant method - void delete_writer( - std::shared_ptr writer) noexcept override; - - //! Override delete_reader() IParticipant method - void delete_reader( - std::shared_ptr reader) noexcept override; + const core::ITopic& topic) override; protected: @@ -73,7 +59,5 @@ class BlankParticipant : public core::IParticipant }; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BLANKPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/EchoParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp similarity index 74% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/EchoParticipant.hpp rename to ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp index cd8f44fdf..f4fc7d8d1 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/EchoParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp @@ -12,19 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file EchoParticipant.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_ECHOPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_ECHOPARTICIPANT_HPP_ +#include -#include - -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -45,7 +41,7 @@ class EchoParticipant : public BlankParticipant //! Override create_writer() IParticipant method std::shared_ptr create_writer( - core::types::DdsTopic topic) override; + const core::ITopic& topic) override; protected: @@ -59,7 +55,5 @@ class EchoParticipant : public BlankParticipant }; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_ECHOPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp similarity index 73% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp rename to ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp index 419be1da7..b9c0bd104 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/CommonParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CommonParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_COMMONPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_COMMONPARTICIPANT_HPP_ +#pragma once #include #include @@ -27,13 +22,15 @@ #include #include -#include -#include +#include +#include +#include +#include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -46,20 +43,16 @@ namespace rtps { * @warning This object is not RAII and must be initialized before used. */ class CommonParticipant - : public BaseParticipant + : public core::IParticipant , public fastrtps::rtps::RTPSParticipantListener { public: - /** - * @brief Construct a CommonParticipant - */ - CommonParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database, - const core::types::DomainId& domain_id, - const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + // Protected ctor to make class abstract (only built by their childs). //! Remove internal RTPS Participant virtual ~CommonParticipant(); @@ -78,6 +71,39 @@ class CommonParticipant */ void init(); + ///////////////////////// + // I PARTICIPANT METHODS + ///////////////////////// + + //! Implement parent method \c is_repeater . + bool is_repeater() const noexcept override; + + //! Implement parent method \c id . + core::types::ParticipantId id() const noexcept override; + + //! Implement parent method \c is_rtps_kind . + virtual bool is_rtps_kind() const noexcept override; + + /** + * @brief Create a writer object + * + * Depending on the Topic QoS creates a Basic or Specific Writer. + */ + std::shared_ptr create_writer( + const core::ITopic& topic) override; + + /** + * @brief Create a reader object + * + * Depending on the Topic QoS creates a Basic or Specific Reader. + */ + std::shared_ptr create_reader( + const core::ITopic& topic) override; + + ///////////////////////// + // RTPS LISTENER METHODS + ///////////////////////// + /** * @brief Override method from \c RTPSParticipantListener . * @@ -105,32 +131,26 @@ class CommonParticipant fastrtps::rtps::RTPSParticipant* participant, fastrtps::rtps::WriterDiscoveryInfo&& info) override; - virtual bool is_rtps_kind() const noexcept override; - protected: /** - * @brief Auxiliary method to create the internal RTPS participant. - */ - void create_participant_( - const core::types::DomainId& domain, - const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); - - /** - * @brief Create a writer object + * @brief Construct a CommonParticipant * - * Depending on the Topic QoS creates a Basic or Specific Writer. + * @note This is meant to be called from child classes. */ - std::shared_ptr create_writer_( - core::types::DdsTopic topic) override; + CommonParticipant( + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database, + const core::types::DomainId& domain_id, + const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); /** - * @brief Create a reader object - * - * Depending on the Topic QoS creates a Basic or Specific Reader. + * @brief Auxiliary method to create the internal RTPS participant. */ - std::shared_ptr create_reader_( - core::types::DdsTopic topic) override; + void create_participant_( + const core::types::DomainId& domain, + const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); /** * @brief Create a endpoint from info object @@ -154,11 +174,21 @@ class CommonParticipant * * @note This method must be specialized from inherit classes. */ - static fastrtps::rtps::RTPSParticipantAttributes get_participant_attributes_( + static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_( const ParticipantConfiguration* participant_configuration); ///// // VARIABLES + + //! Participant configuration + const std::shared_ptr configuration_; + + //! DDS Router shared Payload Pool + const std::shared_ptr payload_pool_; + + //! DDS Router shared Discovery Database + const std::shared_ptr discovery_database_; + //! Internal RTPS Participant eprosima::fastrtps::rtps::RTPSParticipant* rtps_participant_; @@ -171,7 +201,5 @@ class CommonParticipant } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_COMMONPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/DiscoveryServerParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp similarity index 52% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/DiscoveryServerParticipant.hpp rename to ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp index 6aa9630ef..cfb204771 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/DiscoveryServerParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp @@ -12,22 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DiscoveryServerParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_DISCOVERYSERVERPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_DISCOVERYSERVERPARTICIPANT_HPP_ +#pragma once #include -#include -#include - -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -40,18 +34,18 @@ class DiscoveryServerParticipant public: DiscoveryServerParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database); + +protected: - static fastrtps::rtps::RTPSParticipantAttributes get_participant_attributes_( + static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_( const DiscoveryServerParticipantConfiguration* participant_configuration); }; } /* namespace rpts */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_DISCOVERYSERVERPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/InitialPeersParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp similarity index 52% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/InitialPeersParticipant.hpp rename to ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp index 0fb69a67e..3868c1df2 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/InitialPeersParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp @@ -12,22 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file InitialPeersParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_InitialPeersParticipant_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_InitialPeersParticipant_HPP_ +#pragma once #include -#include -#include +#include +#include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -40,18 +35,18 @@ class InitialPeersParticipant public: InitialPeersParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + core std::shared_ptr& participant_configuration, + core std::shared_ptr& payload_pool, + core std::shared_ptr& discovery_database); - static fastrtps::rtps::RTPSParticipantAttributes get_participant_attributes_( +protected: + + static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_( const InitialPeersParticipantConfiguration* configuration); }; } /* namespace rpts */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_InitialPeersParticipant_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/SimpleParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp similarity index 66% rename from ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/SimpleParticipant.hpp rename to ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp index bbd8e128f..de3ffb3d1 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/rtps/SimpleParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp @@ -12,18 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleParticipant.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_SIMPLEPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_SIMPLEPARTICIPANT_HPP_ - -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -47,14 +42,12 @@ class SimpleParticipant : public CommonParticipant * @throw \c IConfigurationException in case configuration was incorrectly set */ SimpleParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database); + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database); }; } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_SIMPLEPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp similarity index 73% rename from ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp rename to ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp index a706aad86..8c1af7ce3 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BaseReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp @@ -12,22 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BaseReader.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_BASEREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_BASEREADER_HPP_ +#pragma once #include #include -#include -#include -#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -40,19 +36,17 @@ class BaseReader : public core::IReader { public: + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + // TODO Implement a way that if messages arrive when not enabled, when enable again call on_data_available - /** - * @brief Construct a new Base Reader object - * - * @param participant_id parent participant id - * @param topic topic that this Reader will refer to - * @param payload_pool DDS Router shared PayloadPool - */ - BaseReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - std::shared_ptr payload_pool); + // Protected ctor to make class abstract (only built by their childs). + + ///////////////////////// + // I READER METHODS + ///////////////////////// /** * @brief Set this Reader as enabled @@ -110,16 +104,52 @@ class BaseReader : public core::IReader * Thread safe with mutex \c mutex_ . */ utils::ReturnCode take( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; + + ///////////////////////// + // AUXILIARY METHODS + ///////////////////////// //! Getter of \c participant_id_ attribute core::types::ParticipantId participant_id() const noexcept; - //! Getter of \c topic_ attribute - core::types::DdsTopic topic() const noexcept; + ///////////////////////// + // RPC REQUIRED METHODS + ///////////////////////// + // TODO remove these methods once the double reference is solved + + //! Get GUID of internal RTPS reader + core::types::Guid guid() const noexcept; + + //! Get internal RTPS reader mutex + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept; + + //! Get number of unread cache changes in internal RTPS reader + uint64_t get_unread_count() const noexcept; + ///////////////////////// protected: + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + /** + * @brief Construct a new Base Reader object + * + * @param participant_id parent participant id + * @param topic topic that this Reader will refer to + * @param payload_pool DDS Router shared PayloadPool + */ + BaseReader( + const core::types::ParticipantId& participant_id, + const core::ITopic& topic, + const std::shared_ptr& payload_pool); + + ///////////////////////// + // PROTECTED METHODS + ///////////////////////// + /** * @brief Call from inherit objects whenever there are available data to read * @@ -129,6 +159,10 @@ class BaseReader : public core::IReader */ void on_data_available_() const noexcept; + ///////////////////////// + // METHODS TO IMPLEMENT BY SUBCLASSES + ///////////////////////// + /** * @brief Do nothing * @@ -149,16 +183,17 @@ class BaseReader : public core::IReader * Implement this method in every inherited Reader class with take functionality. */ virtual utils::ReturnCode take_nts_( - std::unique_ptr& data) noexcept = 0; + std::unique_ptr& data) noexcept = 0; - //! Participant parent ID - core::types::ParticipantId participant_id_; + ///////////////////////// + // INTERNAL VARIABLES + ///////////////////////// - //! Topic that this Reader refers to - core::types::DdsTopic topic_; + //! Participant parent ID + const core::types::ParticipantId participant_id_; //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; + const std::shared_ptr payload_pool_; //! Lambda to call the callback whenever a new data arrives std::function on_data_available_lambda_; @@ -192,7 +227,5 @@ std::ostream& operator <<( const BaseReader& reader); } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_BASEREADER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp similarity index 68% rename from ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp rename to ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp index 93df4d414..0de91bd1d 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/auxiliar/BlankReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BlankReader.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -49,11 +44,24 @@ class BlankReader : public core::IReader //! Override take() IReader method utils::ReturnCode take( - std::unique_ptr& data) noexcept override; + std::unique_ptr& data) noexcept override; + + ///////////////////////// + // RPC REQUIRED METHODS + ///////////////////////// + // TODO remove these methods once the double reference is solved + + //! Get GUID of internal RTPS reader + core::types::Guid guid() const noexcept; + + //! Get internal RTPS reader mutex + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept; + + //! Get number of unread cache changes in internal RTPS reader + uint64_t get_unread_count() const noexcept; + ///////////////////////// }; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_AUXILIAR_VOIDREADER_HPP_ */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp new file mode 100644 index 000000000..479e4497d --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp @@ -0,0 +1,64 @@ +// Copyright 2021 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. + +#pragma once + +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace rpc { + +/** + * Base RTPS Reader concrete class that implements abstract CommonReader one. + */ +class SimpleReader : public rtps::CommonReader +{ +public: + + /** + * @brief Construct a new SimpleReader object + * + * Get the Attributes and TopicQoS and create the SimpleReader History and the RTPS SimpleReader. + * + * @param participant_id Router Id of the Participant that has created this SimpleReader. + * @param topic Topic that this SimpleReader subscribes to. + * @param payload_pool Shared Payload Pool to received data and take it. + * @param rtps_participant RTPS Participant pointer (this is not stored). + * + * @throw \c InitializationException in case any creation has failed + */ + SimpleReader( + const core::types::ParticipantId& participant_id, + const core::types::RpcTopic& topic, + const std::shared_ptr& payload_pool, + fastrtps::rtps::RTPSParticipant* rtps_participant); + + //! Override Parent method to create an RPC data type. + virtual types::RtpsPayloadData* create_data_( + const fastrtps::rtps::CacheChange_t& received_change) const noexcept; + + //! Override Parent method to fill fields exclusive from RPC. + virtual void fill_received_data_( + const fastrtps::rtps::CacheChange_t& received_change, + types::RtpsPayloadData& data_to_fill) const noexcept; +}; + +} /* namespace rpc */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp similarity index 84% rename from ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp rename to ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp index bd7b48ea6..1bccb430d 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/CommonReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CommonReader.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_COMMONREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_COMMONREADER_HPP_ +#pragma once #include @@ -31,19 +26,18 @@ #include #include -#include +#include +#include +#include -#include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { -using RecursiveTimedMutex = eprosima::fastrtps::RecursiveTimedMutex; - /** * Abstract generic class for a RTPS Reader wrapper. * @@ -55,6 +49,12 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener { public: + ///////////////////////// + // CONSTRUCTOR + ///////////////////////// + + // Protected ctor to make class abstract (only built by their childs). + /** * @brief Destroy the CommonReader object * @@ -76,8 +76,9 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener */ void init(); - ///// - // LISTENER METHODS + ///////////////////////// + // RTPS LISTENER METHODS + ///////////////////////// /** * @brief CommonReader Listener callback when a new data is added to History @@ -104,11 +105,16 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener fastrtps::rtps::RTPSReader*, fastrtps::rtps::MatchingInfo& info) noexcept override; + ///////////////////////// + // RPC REQUIRED METHODS + ///////////////////////// + // TODO remove these methods once the double reference is solved + //! Get GUID of internal RTPS reader core::types::Guid guid() const noexcept; //! Get internal RTPS reader mutex - RecursiveTimedMutex& get_rtps_mutex() const noexcept; + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept; //! Get number of unread cache changes in internal RTPS reader uint64_t get_unread_count() const noexcept; @@ -126,8 +132,8 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener */ CommonReader( const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::ITopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const fastrtps::rtps::HistoryAttributes& history_attributes, const fastrtps::rtps::ReaderAttributes& reader_attributes, @@ -150,7 +156,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * * @attention this method allocates memory. */ - virtual core::types::RtpsPayloadData* create_data_( + virtual types::RtpsPayloadData* create_data_( const fastrtps::rtps::CacheChange_t& received_change) const noexcept; /** @@ -158,7 +164,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener */ virtual void fill_received_data_( const fastrtps::rtps::CacheChange_t& received_change, - core::types::RtpsPayloadData& data_to_fill) const noexcept; + types::RtpsPayloadData& data_to_fill) const noexcept; // Specific enable/disable do not need to be implemented @@ -184,8 +190,8 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @return \c RETCODE_NO_DATA if there is no data to send * @return \c RETCODE_ERROR if there has been an error reading the data or the data read is corrupted */ - virtual utils::ReturnCode take_( - std::unique_ptr& data) noexcept override; + virtual utils::ReturnCode take_nts_( + std::unique_ptr& data) noexcept override; ///// // RTPS specific methods @@ -195,21 +201,21 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * * @return Default HistoryAttributes */ - static fastrtps::rtps::HistoryAttributes get_history_attributes_( + static fastrtps::rtps::HistoryAttributes reckon_history_attributes_( const core::types::DdsTopic& topic) noexcept; /** * @brief Reader Attributes to create RTPS Reader */ - static fastrtps::rtps::ReaderAttributes get_reader_attributes_( + static fastrtps::rtps::ReaderAttributes reckon_reader_attributes_( const core::types::DdsTopic& topic) noexcept; //! Topic Attributes to create RTPS Reader - static fastrtps::TopicAttributes get_topic_attributes_( + static fastrtps::TopicAttributes reckon_topic_attributes_( const core::types::DdsTopic& topic) noexcept; //! Reader QoS to create RTPS Reader - static fastrtps::ReaderQos get_reader_qos_( + static fastrtps::ReaderQos reckon_reader_qos_( const core::types::DdsTopic& topic) noexcept; ///// @@ -257,7 +263,5 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_COMMONREADER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp similarity index 79% rename from ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SimpleReader.hpp rename to ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp index 661c56026..36b452df7 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SimpleReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleReader.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SIMPLEREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SIMPLEREADER_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -48,13 +43,11 @@ class SimpleReader : public CommonReader SimpleReader( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, - std::shared_ptr payload_pool, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant); }; } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SIMPLEREADER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp similarity index 82% rename from ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp rename to ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp index 81644d963..bf2a645a8 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/reader/rtps/SpecificQoSReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp @@ -12,18 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SpecificQoSReader.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SPECIFICQOSREADER_HPP_ -#define __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SPECIFICQOSREADER_HPP_ - -#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -52,9 +47,9 @@ class SpecificQoSReader : public CommonReader SpecificQoSReader( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, - std::shared_ptr payload_pool, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - std::shared_ptr discovery_database); + const std::shared_ptr& discovery_database); protected: @@ -78,7 +73,5 @@ class SpecificQoSReader : public CommonReader } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_READER_IMPLEMENTATIONS_RTPS_SPECIFICQOSREADER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/address/Address.hpp b/ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp similarity index 80% rename from ddsrouter_core/include/ddsrouter_core/types/address/Address.hpp rename to ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp index 5c59f2f42..4a99ab611 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/address/Address.hpp +++ b/ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp @@ -12,23 +12,17 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // limitations under the License. -/** - * @file Address.hpp - * - */ - -#ifndef _DDSROUTERCORE_TYPES_ADDRESS_ADDRESS_HPP_ -#define _DDSROUTERCORE_TYPES_ADDRESS_ADDRESS_HPP_ +#pragma once #include #include -#include +#include namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace types { // Data type for Locator kind (this is because FastDDS does not have an enum but defines (dishonor on your cow)) @@ -74,7 +68,7 @@ class Address * @param ip_version ip version (4 or 6) * @param transport_protocol transport protocol (UDP or TCP) */ - DDSROUTER_CORE_DllAPI Address( + DDSPIPE_PARTICIPANTS_DllAPI Address( const IpType& ip, const PortType& port, const PortType& external_port, @@ -90,7 +84,7 @@ class Address * @param domain address domain name to call DNS * @param transport_protocol transport protocol (UDP or TCP) */ - DDSROUTER_CORE_DllAPI Address( + DDSPIPE_PARTICIPANTS_DllAPI Address( const PortType& port, const PortType& external_port, const IpVersion& ip_version, @@ -104,7 +98,7 @@ class Address * If the IP is a string with format IPv6, version will be set to IpVersion::v6. * If the IP has an incorrect format, version will be set to IpVersion::v4 and address will be invalid. */ - DDSROUTER_CORE_DllAPI Address( + DDSPIPE_PARTICIPANTS_DllAPI Address( const IpType& ip, const PortType& port, const PortType& external_port, @@ -118,38 +112,38 @@ class Address * @param domain address domain name to call DNS * @param transport_protocol transport protocol (UDP or TCP) */ - DDSROUTER_CORE_DllAPI Address( + DDSPIPE_PARTICIPANTS_DllAPI Address( const PortType& port, const PortType& external_port, const DomainType& domain, const TransportProtocol& transport_protocol) noexcept; //! Construct a default IP by default values (set in this class) - DDSROUTER_CORE_DllAPI Address(); + DDSPIPE_PARTICIPANTS_DllAPI Address(); //! Address internal Port getter - DDSROUTER_CORE_DllAPI PortType port() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI PortType port() const noexcept; //! Address external Port getter - DDSROUTER_CORE_DllAPI PortType external_port() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI PortType external_port() const noexcept; //! Address IP getter - DDSROUTER_CORE_DllAPI IpType ip() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI IpType ip() const noexcept; //! Address IP version getter - DDSROUTER_CORE_DllAPI IpVersion ip_version() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI IpVersion ip_version() const noexcept; //! Address transport protocol version getter - DDSROUTER_CORE_DllAPI TransportProtocol transport_protocol() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI TransportProtocol transport_protocol() const noexcept; //! Whether transport is UDP - DDSROUTER_CORE_DllAPI bool is_udp() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI bool is_udp() const noexcept; //! Whether transport is TCP - DDSROUTER_CORE_DllAPI bool is_tcp() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI bool is_tcp() const noexcept; //! Whether ip version is IpVersion::v4 - DDSROUTER_CORE_DllAPI bool is_ipv4() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI bool is_ipv4() const noexcept; //! Whether ip version is IpVersion::v6 - DDSROUTER_CORE_DllAPI bool is_ipv6() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI bool is_ipv6() const noexcept; //! Get FastDDS Locator kind - DDSROUTER_CORE_DllAPI LocatorType get_locator_kind() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI LocatorType get_locator_kind() const noexcept; /** * @brief Whether the address is correct @@ -157,33 +151,33 @@ class Address * Checks if IP is in correct format regarding the IP version. * Checks if Port is correct. */ - DDSROUTER_CORE_DllAPI virtual bool is_valid() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid() const noexcept; //! Minor operator - DDSROUTER_CORE_DllAPI bool operator <( + DDSPIPE_PARTICIPANTS_DllAPI bool operator <( const Address& other) const noexcept; //! Equal operator - DDSROUTER_CORE_DllAPI bool operator ==( + DDSPIPE_PARTICIPANTS_DllAPI bool operator ==( const Address& other) const noexcept; //! Whether string \c ip has correct IpVersion::v4 format. - DDSROUTER_CORE_DllAPI static bool is_ipv4_correct( + DDSPIPE_PARTICIPANTS_DllAPI static bool is_ipv4_correct( const IpType& ip) noexcept; //! Whether string \c ip has correct IpVersion::v6 format. - DDSROUTER_CORE_DllAPI static bool is_ipv6_correct( + DDSPIPE_PARTICIPANTS_DllAPI static bool is_ipv6_correct( const IpType& ip) noexcept; //! Default port for address when is not set: 11600 - DDSROUTER_CORE_DllAPI static PortType default_port() noexcept; + DDSPIPE_PARTICIPANTS_DllAPI static PortType default_port() noexcept; //! Default ip for address when is not set: 127.0.0.1 - DDSROUTER_CORE_DllAPI static IpType default_ip( + DDSPIPE_PARTICIPANTS_DllAPI static IpType default_ip( IpVersion ip_version = default_ip_version()) noexcept; //! Default ip version for address when is not set: IpVersion::v4 - DDSROUTER_CORE_DllAPI static IpVersion default_ip_version() noexcept; + DDSPIPE_PARTICIPANTS_DllAPI static IpVersion default_ip_version() noexcept; //! Default transport protocol for address when is not set: UDP - DDSROUTER_CORE_DllAPI static TransportProtocol default_transport_protocol() noexcept; + DDSPIPE_PARTICIPANTS_DllAPI static TransportProtocol default_transport_protocol() noexcept; /** * @brief Return the IP corresponding to the \c domain name given with IP version specified in \c ip_version @@ -197,7 +191,7 @@ class Address * * @throw DNSException in case an IP for this domain could not be retrieved */ - DDSROUTER_CORE_DllAPI static IpType resolve_dns( + DDSPIPE_PARTICIPANTS_DllAPI static IpType resolve_dns( DomainType domain, IpVersion ip_version); @@ -214,7 +208,7 @@ class Address * * @throw DNSException in case an IP for this domain could not be retrieved */ - DDSROUTER_CORE_DllAPI static std::pair resolve_dns( + DDSPIPE_PARTICIPANTS_DllAPI static std::pair resolve_dns( DomainType domain); protected: @@ -248,19 +242,17 @@ class Address static const TransportProtocol DEFAULT_TRANSPORT_PROTOCOL_; // UDP // Allow operator << to use domain info - DDSROUTER_CORE_DllAPI friend std::ostream& operator <<( + DDSPIPE_PARTICIPANTS_DllAPI friend std::ostream& operator <<( std::ostream& output, const Address& address); }; //! \c Address to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( std::ostream& output, const Address& address); } /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_ADDRESS_ADDRESS_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/address/DiscoveryServerConnectionAddress.hpp b/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp similarity index 67% rename from ddsrouter_core/include/ddsrouter_core/types/address/DiscoveryServerConnectionAddress.hpp rename to ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp index 1cd24b0fe..d9250d6ff 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/address/DiscoveryServerConnectionAddress.hpp +++ b/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp @@ -12,24 +12,18 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // limitations under the License. -/** - * @file DiscoveryServerConnectionAddress.hpp - * - */ - -#ifndef _DDSROUTERCORE_TYPES_ADDRESS_DISCOVERYSERVERCONNECTIONADDRESS_HPP_ -#define _DDSROUTERCORE_TYPES_ADDRESS_DISCOVERYSERVERCONNECTIONADDRESS_HPP_ +#pragma once #include #include -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace types { /** @@ -49,15 +43,15 @@ class DiscoveryServerConnectionAddress * @param discovery_server_guid_ : Guid Prefix of the remote Discovery Server * @param addresses_ collection of addresses */ - DDSROUTER_CORE_DllAPI DiscoveryServerConnectionAddress( - GuidPrefix discovery_server_guid, + DDSPIPE_PARTICIPANTS_DllAPI DiscoveryServerConnectionAddress( + core::types::GuidPrefix discovery_server_guid, std::set
addresses); //! Discovery Server \c GuidPrefix Port getter - DDSROUTER_CORE_DllAPI GuidPrefix discovery_server_guid_prefix() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI core::types::GuidPrefix discovery_server_guid_prefix() const noexcept; //! Addresses getter - DDSROUTER_CORE_DllAPI std::set
addresses() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI std::set
addresses() const noexcept; /** * @brief Whether the address is correct @@ -65,33 +59,31 @@ class DiscoveryServerConnectionAddress * Checks if GuidPrefix is correct. * Checks if it has at least one correct address. */ - DDSROUTER_CORE_DllAPI virtual bool is_valid() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid() const noexcept; //! Minor operator - DDSROUTER_CORE_DllAPI bool operator <( + DDSPIPE_PARTICIPANTS_DllAPI bool operator <( const DiscoveryServerConnectionAddress& other) const noexcept; //! Equal operator - DDSROUTER_CORE_DllAPI bool operator ==( + DDSPIPE_PARTICIPANTS_DllAPI bool operator ==( const DiscoveryServerConnectionAddress& other) const noexcept; protected: //! Internal Discovery Server Guid Prefix object - GuidPrefix discovery_server_guid_prefix_; + core::types::GuidPrefix discovery_server_guid_prefix_; //! Internal Addresses object std::set
addresses_; }; //! \c DiscoveryServerConnectionAddress to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( std::ostream& output, const DiscoveryServerConnectionAddress& address); } /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_ADDRESS_DISCOVERYSERVERCONNECTIONADDRESS_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp b/ddspipe_participants/include/ddspipe_participants/types/data/RpcPayloadData.hpp similarity index 70% rename from ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp rename to ddspipe_participants/include/ddspipe_participants/types/data/RpcPayloadData.hpp index 97f1b3669..49110e670 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/RpcPayloadData.hpp +++ b/ddspipe_participants/include/ddspipe_participants/types/data/RpcPayloadData.hpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RpcPayloadData.hpp - */ #pragma once @@ -23,17 +20,17 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace types { /** @@ -53,14 +50,14 @@ struct RpcPayloadData : public RtpsPayloadData /** * @brief Id to identify the internal topic type id that uses \c RpcPayloadData . */ -constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; +constexpr const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; //! \c RpcPayloadData to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( std::ostream& os, const RpcPayloadData& octet); } /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp b/ddspipe_participants/include/ddspipe_participants/types/data/RtpsPayloadData.hpp similarity index 60% rename from ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp rename to ddspipe_participants/include/ddspipe_participants/types/data/RtpsPayloadData.hpp index eec841328..d26ee8f75 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/data/RtpsPayloadData.hpp +++ b/ddspipe_participants/include/ddspipe_participants/types/data/RtpsPayloadData.hpp @@ -12,27 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RtpsPayloadData.hpp - */ #pragma once #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace types { /** @@ -40,27 +37,37 @@ namespace types { * * Properties are related information regarding the data and QoS of the source. */ -struct RtpsPayloadData : public core::types::IRoutingData +struct RtpsPayloadData : public core::IRoutingData { + /** + * @brief Destroy the Rtps Payload Data object + * + * Free the memory for the payload in the corresponding payload pool (if defined). + */ virtual ~RtpsPayloadData(); //! Payload of the data received. The data in this payload must belong to the PayloadPool. - Payload payload{}; + core::types::Payload payload{}; + /** + * @brief PayloadPool owner of the payload. + * + * If nullptr, the owner has not been set. + */ core::PayloadPool* payload_owner{nullptr}; //! Specific Writer QoS of the Data core::types::SpecificEndpointQoS writer_qos{}; //! Instance of the message (default no instance) - InstanceHandle instanceHandle{}; + core::types::InstanceHandle instanceHandle{}; //! Kind of the change - ChangeKind kind{}; + core::types::ChangeKind kind{}; //! Source time stamp of the message - DataTime source_timestamp{}; + core::types::DataTime source_timestamp{}; //! Guid of the source entity that has transmit the data core::types::Guid source_guid{}; @@ -72,14 +79,14 @@ struct RtpsPayloadData : public core::types::IRoutingData /** * @brief Id to identify the internal topic type id that uses \c RtpsPayloadData . */ -constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; +const core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; //! \c octet to stream serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( +DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( std::ostream& os, const RtpsPayloadData& octet); } /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/security/tls/TlsConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp similarity index 76% rename from ddsrouter_core/include/ddsrouter_core/types/security/tls/TlsConfiguration.hpp rename to ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp index dad76d696..c07c8ee4b 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/security/tls/TlsConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp @@ -10,14 +10,9 @@ // 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. +// limitations under the License\. -/** - * @file TlsConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_SECURITY_TLS_TLSCONFIGURATION_HPP_ -#define _DDSROUTERCORE_SECURITY_TLS_TLSCONFIGURATION_HPP_ +#pragma once #include #include @@ -26,14 +21,13 @@ #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace types { -namespace security { /** * @brief Enumeration of kinds of TLS configurations. @@ -49,18 +43,18 @@ ENUMERATION_BUILDER( /** * Configuration holding TLS parameters. */ -struct TlsConfiguration : public configuration::BaseConfiguration +struct TlsConfiguration : public core::BaseConfiguration { /** * @brief Constructs an undefined or inactive (valid nonetheless) TLSConfiguration */ - DDSROUTER_CORE_DllAPI TlsConfiguration() = default; + DDSPIPE_PARTICIPANTS_DllAPI TlsConfiguration() = default; /** * @brief Returns whether configuration is active */ - DDSROUTER_CORE_DllAPI bool is_active() const noexcept; + DDSPIPE_PARTICIPANTS_DllAPI bool is_active() const noexcept; /** * @brief Check configuration kind compatibility @@ -79,24 +73,24 @@ struct TlsConfiguration : public configuration::BaseConfiguration } template - DDSROUTER_CORE_DllAPI bool is_valid_kind( + DDSPIPE_PARTICIPANTS_DllAPI bool is_valid_kind( utils::Formatter& error_msg) const noexcept; //! Activate TLS configuration in a TCP transport descriptor - DDSROUTER_CORE_DllAPI void enable_tls( + DDSPIPE_PARTICIPANTS_DllAPI void enable_tls( std::shared_ptr descriptor, bool client = false) const; //! Activate TLS client configuration in a TCP transport descriptor - DDSROUTER_CORE_DllAPI void enable_tls_client( + DDSPIPE_PARTICIPANTS_DllAPI void enable_tls_client( std::shared_ptr descriptor, bool only_client) const; //! Activate TLS server configuration in a TCP transport descriptor - DDSROUTER_CORE_DllAPI void enable_tls_server( + DDSPIPE_PARTICIPANTS_DllAPI void enable_tls_server( std::shared_ptr descriptor) const; - DDSROUTER_CORE_DllAPI virtual bool is_valid( + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; //////// @@ -119,10 +113,7 @@ struct TlsConfiguration : public configuration::BaseConfiguration std::string dh_params_file = ""; }; -} /* namespace security */ } /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_SECURITY_TLS_TLSCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp similarity index 75% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp index 25e0e8bd1..2fc323eff 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BaseWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp @@ -12,22 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BaseWriter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_BASEWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_BASEWRITER_HPP_ +#pragma once #include #include -#include -#include -#include +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -40,17 +37,15 @@ class BaseWriter : public core::IWriter { public: - /** - * @brief Construct a new Base Writer object - * - * @param participant_id id of participant - * @param topic topic that this Writer will refer to - * @param payload_pool DDS Router shared PayloadPool - */ - BaseWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - std::shared_ptr payload_pool); + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + // Protected ctor to make class abstract (only built by their childs). + + ///////////////////////// + // I WRITER METHODS + ///////////////////////// /** * @brief Set this Writer as enabled @@ -85,10 +80,30 @@ class BaseWriter : public core::IWriter * Thread safe with mutex \c mutex_ . */ virtual utils::ReturnCode write( - core::types::IRoutingData& data) noexcept override; + core::IRoutingData& data) noexcept override; protected: + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + /** + * @brief Construct a new Base Writer object + * + * @param participant_id id of participant + * @param topic topic that this Writer will refer to + * @param payload_pool DDS Router shared PayloadPool + */ + BaseWriter( + const core::types::ParticipantId& participant_id, + const core::ITopic& topic, + const std::shared_ptr& payload_pool); + + ///////////////////////// + // METHODS TO IMPLEMENT BY SUBCLASSES + ///////////////////////// + /** * @brief Do nothing * @@ -109,16 +124,17 @@ class BaseWriter : public core::IWriter * Implement this method in every inherited Writer class with write functionality. */ virtual utils::ReturnCode write_( - core::types::IRoutingData& data) noexcept = 0; + core::IRoutingData& data) noexcept = 0; - //! Participant parent ID - core::types::ParticipantId participant_id_; + ///////////////////////// + // INTERNAL VARIABLES + ///////////////////////// - //! Topic that this Writer refers to - core::types::DdsTopic topic_; + //! Participant parent ID + const core::types::ParticipantId participant_id_; //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; + const std::shared_ptr payload_pool_; //! Whether the Writer is currently enabled std::atomic enabled_; @@ -143,7 +159,5 @@ std::ostream& operator <<( const BaseWriter& writer); } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_BASEWRITER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp similarity index 71% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp index b85828c33..a51e00ed7 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/BlankWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BlankWriter.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -41,11 +36,9 @@ class BlankWriter : public core::IWriter //! Override write() IWriter method utils::ReturnCode write( - core::types::IRoutingData& data) noexcept override; + core::IRoutingData& data) noexcept override; }; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_VOIDWRITER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp similarity index 72% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp index 361c16f73..1a55e9466 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/auxiliar/EchoWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp @@ -12,21 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file EchoWriter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_ECHOWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_ECHOWRITER_HPP_ +#pragma once #include -#include +#include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { /** @@ -50,7 +45,7 @@ class EchoWriter : public BlankWriter * @return RETCODE_OK always */ virtual utils::ReturnCode write( - core::types::IRoutingData& data) noexcept override; + core::IRoutingData& data) noexcept override; //! Topic that this Writer refers to core::types::DdsTopic topic_; @@ -60,7 +55,5 @@ class EchoWriter : public BlankWriter }; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_AUXILIAR_ECHOWRITER_HPP_ */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp new file mode 100644 index 000000000..83fd4b67a --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp @@ -0,0 +1,78 @@ +// Copyright 2021 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. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace rpc { + +/** + * Base RTPS Writer concrete class that implements abstract CommonWriter one. + */ +class SimpleWriter : public CommonWriter +{ +public: + + /** + * @brief Construct a new SimpleWriter object + * + * Get the Attributes and TopicQoS and create the SimpleWriter History and the RTPS SimpleWriter. + * + * @note use protected constructor so this class is not called but from subclasses + * (Basically make abstract class without a pure virtual function). + * + * @param participant_id Router Id of the Participant that has created this SimpleWriter. + * @param topic Topic that this SimpleWriter subscribes to. + * @param payload_pool Shared Payload Pool to received data and take it. + * @param rtps_participant RTPS Participant pointer (this is not stored). + * + * @throw \c InitializationException in case any creation has failed + */ + SimpleWriter( + const core::types::ParticipantId& participant_id, + const core::types::RPCTopic& topic, + const std::shared_ptr& payload_pool, + fastrtps::rtps::RTPSParticipant* rtps_participant, + const bool repeater = false); + + //! Override Parent method to fill fields only required for RPC. + virtual utils::ReturnCode fill_to_send_data_( + fastrtps::rtps::CacheChange_t* to_send_change_to_fill, + eprosima::fastrtps::rtps::WriteParams& to_send_params, + const core::types::RtpsPayloadData& data) const noexcept; + + //! Override Parent method to fill fields after message is sent only required for RPC. + virtual void fill_sent_data_( + const eprosima::fastrtps::rtps::WriteParams& sent_params, + core::types::RtpsPayloadData& data_to_fill) const noexcept; +}; + +} /* namespace rpc */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp similarity index 83% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp index a86af5c71..9e80ac341 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/CommonWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CommonWriter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_COMMONWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_COMMONWRITER_HPP_ +#pragma once #include #include @@ -28,21 +23,22 @@ #include #include -#include -#include -#include -#include +#include +#include + +#include +#include ///// // Forward declarations namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { struct CacheChangePoolConfiguration; } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ namespace fastdds { namespace rtps { @@ -54,7 +50,7 @@ struct IReaderDataFilter; } /* namespace eprosima */ namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -69,6 +65,12 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener { public: + ///////////////////////// + // CONSTRUCTOR + ///////////////////////// + + // Protected ctor to make class abstract (only built by their childs). + /** * @brief Destroy the Writer object * @@ -90,6 +92,10 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ void init(); + ///////////////////////// + // RTPS LISTENER METHODS + ///////////////////////// + /** * @brief CommonWriter Listener callback when a new Reader is matched or unmatched * @@ -115,8 +121,8 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ CommonWriter( const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::ITopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater, const fastrtps::rtps::HistoryAttributes& history_attributes, @@ -143,7 +149,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @return \c RETCODE_ERROR if error occurred */ virtual utils::ReturnCode write_( - core::types::IRoutingData& data) noexcept override; + core::IRoutingData& data) noexcept override; /** * @brief Auxiliary method used in \c write to fill the cache change to send. @@ -155,7 +161,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener virtual utils::ReturnCode fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - const core::types::RtpsPayloadData& data) const noexcept; + const types::RtpsPayloadData& data) const noexcept; /** * @brief Auxiliary method used after \c write to fill data value. @@ -165,7 +171,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ virtual void fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& sent_params, - core::types::RtpsPayloadData& data_to_fill) const noexcept; + types::RtpsPayloadData& data_to_fill) const noexcept; ///// // RTPS specific methods @@ -188,26 +194,26 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener /** * @brief History Attributes to create RTPS Writer History */ - static fastrtps::rtps::HistoryAttributes get_history_attributes_( - const core::types::DdsTopic& topic) noexcept; + static fastrtps::rtps::HistoryAttributes reckon_history_attributes_( + const core::types::DistributedTopic& topic) noexcept; /** * @brief Writer Attributes to create RTPS Writer */ - static fastrtps::rtps::WriterAttributes get_writer_attributes_( - const core::types::DdsTopic& topic) noexcept; + static fastrtps::rtps::WriterAttributes reckon_writer_attributes_( + const core::types::DistributedTopic& topic) noexcept; //! Topic Attributes to create RTPS Writer - static fastrtps::TopicAttributes get_topic_attributes_( - const core::types::DdsTopic& topic) noexcept; + static fastrtps::TopicAttributes reckon_topic_attributes_( + const core::types::DistributedTopic& topic) noexcept; //! QoS for RTPS Writer - static fastrtps::WriterQos get_writer_qos_( - const core::types::DdsTopic& topic) noexcept; + static fastrtps::WriterQos reckon_writer_qos_( + const core::types::DistributedTopic& topic) noexcept; //! Cache Change Pool Configuration - static utils::PoolConfiguration cache_change_pool_configuration_( - const core::types::DdsTopic& topic) noexcept; + static utils::PoolConfiguration reckon_cache_change_pool_configuration_( + const core::types::DistributedTopic& topic) noexcept; //! Whether a guid references this Participant bool come_from_this_participant_( @@ -252,7 +258,5 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_COMMONWRITER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp similarity index 62% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp index 1827e3517..e232247dd 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/MultiWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp @@ -12,21 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file MultiWriter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_PARTITIONSWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_PARTITIONSWRITER_HPP_ +#pragma once #include -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -54,8 +49,8 @@ class MultiWriter : public BaseWriter */ MultiWriter( const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - std::shared_ptr payload_pool, + const core::ITopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater = false); @@ -71,27 +66,16 @@ class MultiWriter : public BaseWriter protected: - // Specific enable/disable. + //! Override specific enable to call enable in internal writers. virtual void enable_() noexcept override; + //! Override specific disable to call disable in internal writers. virtual void disable_() noexcept override; /** - * @brief Write specific method - * - * Store new data as message to send (asynchronously) (it could use PayloadPool to not copy payload). - * Take next Untaken Change. - * Set \c data with the message taken (data payload must be stored from PayloadPool). - * Remove this change from Reader History and release. - * - * It does not require mutex, it will be guarded by RTPS MultiWriter mutex in internal methods. - * - * @param data : oldest data to take - * @return \c RETCODE_OK if data has been correctly taken - * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty - * @return \c RETCODE_NO_DATA if \c data_to_send_ is empty + * TODO */ virtual utils::ReturnCode write_( - IRoutingData& data) noexcept override; + core::IRoutingData& data) noexcept override; bool exist_partition_( const core::types::SpecificEndpointQoS& data_qos); @@ -100,12 +84,11 @@ class MultiWriter : public BaseWriter QoSSpecificWriter* create_writer_nts_( const core::types::SpecificEndpointQoS& data_qos); - ///// - // VARIABLES + ///////////////////////// + // INTERNAL VARIABLES + ///////////////////////// - // TODO: This could be an unordered_map avoiding the use of operator< with SpecificEndpointQoS, - // what may be a problem. - using WritersMapType = utils::SharedAtomicable>; + using WritersMapType = utils::SharedAtomicable>; //! Map of writer indexed by Specific QoS of each. WritersMapType writers_map_; @@ -118,7 +101,5 @@ class MultiWriter : public BaseWriter } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_PARTITIONSWRITER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/QoSSpecificWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp similarity index 77% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/QoSSpecificWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp index b9523d62e..ccb2e76aa 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/QoSSpecificWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file QoSSpecificWriter.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_QOSSPECIFICWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_QOSSPECIFICWRITER_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -49,7 +44,7 @@ class QoSSpecificWriter : public CommonWriter */ QoSSpecificWriter( const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, + const core::ITopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const core::types::SpecificEndpointQoS& specific_qos, @@ -58,17 +53,15 @@ class QoSSpecificWriter : public CommonWriter protected: //! Specific writer QoS to override (more or less) the CommonWriter qos - static fastrtps::WriterQos get_writer_qos_( + static fastrtps::WriterQos reckon_writer_qos_( const core::types::SpecificEndpointQoS& specific_qos, - const core::types::DdsTopic& topic) noexcept; + const core::types::DistributedTopic& topic) noexcept; //! Specific QoS of the Endpoint - const core::types::SpecificEndpointQoS& specific_qos_; + core::types::SpecificEndpointQoS specific_qos_; }; } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_QOSSPECIFICWRITER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp similarity index 79% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/SimpleWriter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp index eb5980cf6..4ea220a97 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/SimpleWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleWriter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_SIMPLEWRITER_HPP_ -#define __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_SIMPLEWRITER_HPP_ +#pragma once #include #include @@ -27,12 +22,12 @@ #include #include -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -61,7 +56,7 @@ class SimpleWriter : public CommonWriter SimpleWriter( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, - std::shared_ptr payload_pool, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater = false); @@ -69,7 +64,5 @@ class SimpleWriter : public CommonWriter } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_WRITER_IMPLEMENTATIONS_RTPS_SIMPLEWRITER_HPP_ */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp similarity index 78% rename from ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp index c1a7c58d3..4e7d66d07 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RepeaterDataFilter.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -52,7 +47,5 @@ class RepeaterDataFilter : public SelfDataFilter } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp similarity index 80% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.hpp rename to ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp index 52af7569f..f4cf2248f 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/SelfDataFilter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SelfDataFilter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ +#pragma once #include @@ -35,7 +30,7 @@ struct GUID_t; } /* namespace eprosima */ namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -60,7 +55,5 @@ class SelfDataFilter : public fastdds::rtps::IReaderDataFilter } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ */ diff --git a/ddspipe_participants/package.xml b/ddspipe_participants/package.xml new file mode 100644 index 000000000..97945cbef --- /dev/null +++ b/ddspipe_participants/package.xml @@ -0,0 +1,32 @@ + + + + ddspipe_participants + 1.1.0 + + *eprosima DDS Pipe* C++ Std Participant implementations. + + Raul Sánchez-Mateos + Javier París + Juan López + Apache 2.0 + + https://www.eprosima.com/ + https://github.com/eProsima/DDS-Router/issues + https://github.com/eProsima/DDS-Router + + cmake + + fastrtps + cpp_utils + cmake_utils + ddspipe_core + + doxygen + + googletest-distribution + + + cmake + + diff --git a/ddsrouter_participants/project_settings.cmake b/ddspipe_participants/project_settings.cmake similarity index 91% rename from ddsrouter_participants/project_settings.cmake rename to ddspipe_participants/project_settings.cmake index 8248f60b8..8278021ac 100644 --- a/ddsrouter_participants/project_settings.cmake +++ b/ddspipe_participants/project_settings.cmake @@ -13,11 +13,11 @@ # limitations under the License. ############################################################################### -# Set settings for project ddsrouter_participants +# Set settings for project ddspipe_participants ############################################################################### set(MODULE_NAME - ddsrouter_participants) + ddspipe_participants) set(MODULE_SUMMARY "C++ library to build and run a DDS Router.") @@ -26,7 +26,7 @@ set(MODULE_FIND_PACKAGES fastcdr fastrtps cpp_utils - ddsrouter_core) + ddspipe_core) set(fastrtps_MINIMUM_VERSION "2.8") diff --git a/ddspipe_participants/src/cpp/_dummy.cpp b/ddspipe_participants/src/cpp/_dummy.cpp new file mode 100644 index 000000000..d353d8800 --- /dev/null +++ b/ddspipe_participants/src/cpp/_dummy.cpp @@ -0,0 +1,8 @@ + +#include +#include +#include +#include +#include +#include +#include diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp b/ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp similarity index 92% rename from ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp index ab93baefb..730385fae 100644 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BaseParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp @@ -12,21 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BaseParticipant.cpp - */ #include #include #include -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { BaseParticipant::BaseParticipant( @@ -79,7 +76,7 @@ bool BaseParticipant::is_rtps_kind() const noexcept } std::shared_ptr BaseParticipant::create_writer( - core::types::DdsTopic topic) + core::types::DistributedTopic topic) { std::lock_guard lock(mutex_); @@ -102,7 +99,7 @@ std::shared_ptr BaseParticipant::create_writer( } std::shared_ptr BaseParticipant::create_reader( - core::types::DdsTopic topic) + core::types::DistributedTopic topic) { std::lock_guard lock(mutex_); @@ -182,5 +179,5 @@ std::ostream& operator <<( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp b/ddspipe_participants/src_/cpp/participant/auxiliar/BlankParticipant.cpp similarity index 80% rename from ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/auxiliar/BlankParticipant.cpp index ca500821c..de49601cf 100644 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/auxiliar/BlankParticipant.cpp @@ -12,16 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BlankParticipant.cpp - */ -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -48,13 +45,13 @@ bool BlankParticipant::is_rtps_kind() const noexcept } std::shared_ptr BlankParticipant::create_writer( - DdsTopic topic) + DistributedTopic topic) { return std::make_shared(); } std::shared_ptr BlankParticipant::create_reader( - DdsTopic topic) + DistributedTopic topic) { return std::make_shared(); } @@ -70,5 +67,5 @@ void BlankParticipant::delete_reader( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/EchoParticipant.cpp b/ddspipe_participants/src_/cpp/participant/auxiliar/EchoParticipant.cpp similarity index 81% rename from ddsrouter_core/src/cpp/participants/participant/auxiliar/EchoParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/auxiliar/EchoParticipant.cpp index 76ac753a6..fde466a89 100644 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/EchoParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/auxiliar/EchoParticipant.cpp @@ -12,21 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file EchoParticipant.cpp - */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -60,7 +57,7 @@ void EchoParticipant::echo_discovery( } std::shared_ptr EchoParticipant::create_writer( - DdsTopic topic) + DistributedTopic topic) { if (configuration_->echo_data) { @@ -75,5 +72,5 @@ std::shared_ptr EchoParticipant::create_writer( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp b/ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp similarity index 81% rename from ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp index 8a438fb3a..8713623bf 100644 --- a/ddsrouter_core/src/cpp/participants/participant/auxiliar/MockParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp @@ -12,18 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file MockParticipant.cpp - */ -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -38,19 +35,19 @@ MockParticipant::MockParticipant( } std::shared_ptr MockParticipant::create_writer_( - DdsTopic topic) + DistributedTopic topic) { return std::make_shared(id(), topic, payload_pool_); } std::shared_ptr MockParticipant::create_reader_( - DdsTopic topic) + DistributedTopic topic) { return std::make_shared(id(), topic, payload_pool_); } std::shared_ptr MockParticipant::get_reader( - core::types::DdsTopic topic) + core::types::DistributedTopic topic) { std::lock_guard _(mutex_); auto it = readers_.find(topic); @@ -62,7 +59,7 @@ std::shared_ptr MockParticipant::get_reader( } std::vector MockParticipant::get_writer( - core::types::DdsTopic topic) + core::types::DistributedTopic topic) { std::lock_guard _(mutex_); auto it = writers_.find(topic); @@ -74,5 +71,5 @@ std::vector MockParticipant::get_writer( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/configuration/DiscoveryServerParticipantConfiguration.cpp b/ddspipe_participants/src_/cpp/participant/configuration/DiscoveryServerParticipantConfiguration.cpp similarity index 86% rename from ddsrouter_core/src/cpp/participants/participant/configuration/DiscoveryServerParticipantConfiguration.cpp rename to ddspipe_participants/src_/cpp/participant/configuration/DiscoveryServerParticipantConfiguration.cpp index ada325c18..7dc448ca7 100644 --- a/ddsrouter_core/src/cpp/participants/participant/configuration/DiscoveryServerParticipantConfiguration.cpp +++ b/ddspipe_participants/src_/cpp/participant/configuration/DiscoveryServerParticipantConfiguration.cpp @@ -12,22 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DiscoveryServerParticipantConfiguration.cpp - */ #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration( const ParticipantId& id, const bool is_repeater, @@ -35,7 +30,7 @@ DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration const GuidPrefix& discovery_server_guid_prefix, const std::set
& listening_addresses, const std::set& connection_addresses, - const security::TlsConfiguration& tls_configuration) + const TlsConfiguration& tls_configuration) : SimpleParticipantConfiguration(id, is_repeater, domain_id) , discovery_server_guid_prefix(discovery_server_guid_prefix) , listening_addresses(listening_addresses) @@ -94,7 +89,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( // If has listening addresses, it should be able to provide TLS server configuration if (!listening_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -104,7 +99,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( // If has connection addresses, it should be able to provide TLS client configuration if (!connection_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; @@ -123,5 +118,5 @@ bool DiscoveryServerParticipantConfiguration::operator ==( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/configuration/InitialPeersParticipantConfiguration.cpp b/ddspipe_participants/src_/cpp/participant/configuration/InitialPeersParticipantConfiguration.cpp similarity index 86% rename from ddsrouter_core/src/cpp/participants/participant/configuration/InitialPeersParticipantConfiguration.cpp rename to ddspipe_participants/src_/cpp/participant/configuration/InitialPeersParticipantConfiguration.cpp index dd90c8e3a..ae11b87d4 100644 --- a/ddsrouter_core/src/cpp/participants/participant/configuration/InitialPeersParticipantConfiguration.cpp +++ b/ddspipe_participants/src_/cpp/participant/configuration/InitialPeersParticipantConfiguration.cpp @@ -12,18 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file InitialPeersParticipantConfiguration.cpp - */ #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -34,7 +31,7 @@ InitialPeersParticipantConfiguration::InitialPeersParticipantConfiguration( const DomainId& domain_id, const std::set
& listening_addresses, const std::set
& connection_addresses, - const security::TlsConfiguration& tls_configuration) + const TlsConfiguration& tls_configuration) : SimpleParticipantConfiguration(id, is_repeater, domain_id) , listening_addresses(listening_addresses) , connection_addresses(connection_addresses) @@ -85,7 +82,7 @@ bool InitialPeersParticipantConfiguration::is_valid( // If has listening addresses, it should be able to provide TLS server configuration if (!listening_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -95,7 +92,7 @@ bool InitialPeersParticipantConfiguration::is_valid( // If has connection addresses, it should be able to provide TLS client configuration if (!connection_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; @@ -114,5 +111,5 @@ bool InitialPeersParticipantConfiguration::operator ==( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/configuration/ParticipantConfiguration.cpp b/ddspipe_participants/src_/cpp/participant/configuration/ParticipantConfiguration.cpp similarity index 84% rename from ddsrouter_core/src/cpp/participants/participant/configuration/ParticipantConfiguration.cpp rename to ddspipe_participants/src_/cpp/participant/configuration/ParticipantConfiguration.cpp index 9a03d1834..62081eddc 100644 --- a/ddsrouter_core/src/cpp/participants/participant/configuration/ParticipantConfiguration.cpp +++ b/ddspipe_participants/src_/cpp/participant/configuration/ParticipantConfiguration.cpp @@ -12,17 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file ParticipantConfiguration.cpp - */ #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -54,5 +51,5 @@ bool ParticipantConfiguration::operator ==( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/configuration/SimpleParticipantConfiguration.cpp b/ddspipe_participants/src_/cpp/participant/configuration/SimpleParticipantConfiguration.cpp similarity index 89% rename from ddsrouter_core/src/cpp/participants/participant/configuration/SimpleParticipantConfiguration.cpp rename to ddspipe_participants/src_/cpp/participant/configuration/SimpleParticipantConfiguration.cpp index 80894c692..7f3cb526a 100644 --- a/ddsrouter_core/src/cpp/participants/participant/configuration/SimpleParticipantConfiguration.cpp +++ b/ddspipe_participants/src_/cpp/participant/configuration/SimpleParticipantConfiguration.cpp @@ -12,16 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleParticipantConfiguration.cpp - */ #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -61,5 +58,5 @@ bool SimpleParticipantConfiguration::operator ==( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp b/ddspipe_participants/src_/cpp/participant/rtps/CommonParticipant.cpp similarity index 93% rename from ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/rtps/CommonParticipant.cpp index aeba5ea5e..f5a871531 100644 --- a/ddsrouter_core/src/cpp/participants/participant/rtps/CommonParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/rtps/CommonParticipant.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CommonParticipant.cpp - */ #include @@ -25,19 +22,19 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -128,7 +125,7 @@ core::types::Endpoint CommonParticipant::create_common_endpoint_from_info_( discovered_topic_qos.ownership_qos = info.info.m_qos.m_ownership.kind; // Parse Topic - core::types::DdsTopic info_topic(std::string(info.info.topicName()), std::string(info.info.typeName())); + core::types::DistributedTopic info_topic(std::string(info.info.topicName()), std::string(info.info.typeName())); info_topic.keyed = info.info.topicKind() == eprosima::fastrtps::rtps::TopicKind_t::WITH_KEY; // Set qos as set, but fuzzy info_topic.topic_qos = discovered_topic_qos; @@ -294,7 +291,7 @@ void CommonParticipant::create_participant_( } std::shared_ptr CommonParticipant::create_writer_( - core::types::DdsTopic topic) + core::types::DistributedTopic topic) { if (topic.topic_qos.get_reference().has_partitions() || topic.topic_qos.get_reference().has_ownership()) { @@ -321,7 +318,7 @@ std::shared_ptr CommonParticipant::create_writer_( } std::shared_ptr CommonParticipant::create_reader_( - core::types::DdsTopic topic) + core::types::DistributedTopic topic) { if (topic.topic_qos.get_reference().has_partitions() || topic.topic_qos.get_reference().has_ownership()) { @@ -362,5 +359,5 @@ CommonParticipant::get_participant_attributes_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/rtps/DiscoveryServerParticipant.cpp b/ddspipe_participants/src_/cpp/participant/rtps/DiscoveryServerParticipant.cpp similarity index 98% rename from ddsrouter_core/src/cpp/participants/participant/rtps/DiscoveryServerParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/rtps/DiscoveryServerParticipant.cpp index 3fa864bc3..543a92b1a 100644 --- a/ddsrouter_core/src/cpp/participants/participant/rtps/DiscoveryServerParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/rtps/DiscoveryServerParticipant.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DiscoveryServerParticipant.cpp - */ #include #include @@ -25,12 +22,12 @@ #include #include -#include +#include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -362,5 +359,5 @@ DiscoveryServerParticipant::get_participant_attributes_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/rtps/InitialPeersParticipant.cpp b/ddspipe_participants/src_/cpp/participant/rtps/InitialPeersParticipant.cpp similarity index 98% rename from ddsrouter_core/src/cpp/participants/participant/rtps/InitialPeersParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/rtps/InitialPeersParticipant.cpp index a1f3c7c9e..26763d540 100644 --- a/ddsrouter_core/src/cpp/participants/participant/rtps/InitialPeersParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/rtps/InitialPeersParticipant.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file InitialPeersParticipant.cpp - */ #include #include @@ -23,10 +20,10 @@ #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -339,5 +336,5 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participa } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/participant/rtps/SimpleParticipant.cpp b/ddspipe_participants/src_/cpp/participant/rtps/SimpleParticipant.cpp similarity index 89% rename from ddsrouter_core/src/cpp/participants/participant/rtps/SimpleParticipant.cpp rename to ddspipe_participants/src_/cpp/participant/rtps/SimpleParticipant.cpp index d530c4601..b686ab94d 100644 --- a/ddsrouter_core/src/cpp/participants/participant/rtps/SimpleParticipant.cpp +++ b/ddspipe_participants/src_/cpp/participant/rtps/SimpleParticipant.cpp @@ -12,19 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleRTPSRouterParticipant.cpp - */ #include #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -45,5 +42,5 @@ SimpleParticipant::SimpleParticipant( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp b/ddspipe_participants/src_/cpp/reader/auxiliar/BaseReader.cpp similarity index 93% rename from ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp rename to ddspipe_participants/src_/cpp/reader/auxiliar/BaseReader.cpp index 69042f733..9a3c66426 100644 --- a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BaseReader.cpp +++ b/ddspipe_participants/src_/cpp/reader/auxiliar/BaseReader.cpp @@ -12,16 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BaseReader.cpp - */ -#include +#include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -34,7 +31,7 @@ const std::function BaseReader::DEFAULT_ON_DATA_AVAILABLE_CALLBACK = BaseReader::BaseReader( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool) : participant_id_(participant_id) , topic_(topic) @@ -125,7 +122,7 @@ ParticipantId BaseReader::participant_id() const noexcept return participant_id_; } -DdsTopic BaseReader::topic() const noexcept +DistributedTopic BaseReader::topic() const noexcept { return topic_; } @@ -162,5 +159,5 @@ std::ostream& operator <<( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp b/ddspipe_participants/src_/cpp/reader/auxiliar/BlankReader.cpp similarity index 83% rename from ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp rename to ddspipe_participants/src_/cpp/reader/auxiliar/BlankReader.cpp index 44c24572d..0d6d4949f 100644 --- a/ddsrouter_core/src/cpp/participants/reader/auxiliar/BlankReader.cpp +++ b/ddspipe_participants/src_/cpp/reader/auxiliar/BlankReader.cpp @@ -12,14 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BlankReader.cpp - */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -42,11 +39,11 @@ void BlankReader::unset_on_data_available_callback() noexcept } utils::ReturnCode BlankReader::take( - std::unique_ptr& /* data */) noexcept + std::unique_ptr& /* data */) noexcept { return utils::ReturnCode::RETCODE_NO_DATA; } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp b/ddspipe_participants/src_/cpp/reader/rtps/CommonReader.cpp similarity index 96% rename from ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp rename to ddspipe_participants/src_/cpp/reader/rtps/CommonReader.cpp index c62091de2..4786ae3dd 100644 --- a/ddsrouter_core/src/cpp/participants/reader/rtps/CommonReader.cpp +++ b/ddspipe_participants/src_/cpp/reader/rtps/CommonReader.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CommonReader.cpp - */ #include #include @@ -22,12 +19,12 @@ #include #include -#include -#include -#include +#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -36,7 +33,7 @@ using eprosima::ddsrouter::core::types::operator<<; CommonReader::CommonReader( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const fastrtps::rtps::HistoryAttributes& history_attributes, @@ -147,7 +144,7 @@ uint64_t CommonReader::get_unread_count() const noexcept } utils::ReturnCode CommonReader::take_( - std::unique_ptr& data) noexcept + std::unique_ptr& data) noexcept { // Check if there is data available if (!(get_unread_count() > 0)) @@ -262,7 +259,7 @@ bool CommonReader::come_from_this_participant_( } fastrtps::rtps::HistoryAttributes CommonReader::get_history_attributes_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::rtps::HistoryAttributes att; att.memoryPolicy = @@ -274,7 +271,7 @@ fastrtps::rtps::HistoryAttributes CommonReader::get_history_attributes_( } fastrtps::rtps::ReaderAttributes CommonReader::get_reader_attributes_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::rtps::ReaderAttributes att; @@ -300,7 +297,7 @@ fastrtps::rtps::ReaderAttributes CommonReader::get_reader_attributes_( } fastrtps::TopicAttributes CommonReader::get_topic_attributes_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::TopicAttributes att; @@ -326,7 +323,7 @@ fastrtps::TopicAttributes CommonReader::get_topic_attributes_( } fastrtps::ReaderQos CommonReader::get_reader_qos_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::ReaderQos properties; @@ -443,5 +440,5 @@ utils::ReturnCode CommonReader::is_data_correct_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/rtps/SimpleReader.cpp b/ddspipe_participants/src_/cpp/reader/rtps/SimpleReader.cpp similarity index 88% rename from ddsrouter_core/src/cpp/participants/reader/rtps/SimpleReader.cpp rename to ddspipe_participants/src_/cpp/reader/rtps/SimpleReader.cpp index 71cc0b3d6..5e9ac6ace 100644 --- a/ddsrouter_core/src/cpp/participants/reader/rtps/SimpleReader.cpp +++ b/ddspipe_participants/src_/cpp/reader/rtps/SimpleReader.cpp @@ -12,19 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleReader.cpp - */ #include #include -#include +#include #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -32,7 +29,7 @@ using namespace eprosima::ddsrouter::core::types; SimpleReader::SimpleReader( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant) : CommonReader( @@ -46,5 +43,5 @@ SimpleReader::SimpleReader( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp b/ddspipe_participants/src_/cpp/reader/rtps/SpecificQoSReader.cpp similarity index 92% rename from ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp rename to ddspipe_participants/src_/cpp/reader/rtps/SpecificQoSReader.cpp index 5a0845fde..a5d94a6e5 100644 --- a/ddsrouter_core/src/cpp/participants/reader/rtps/SpecificQoSReader.cpp +++ b/ddspipe_participants/src_/cpp/reader/rtps/SpecificQoSReader.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SpecificQoSReader.cpp - */ #include #include @@ -22,10 +19,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -33,7 +30,7 @@ using namespace eprosima::ddsrouter::core::types; SpecificQoSReader::SpecificQoSReader( const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, + const core::types::DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, std::shared_ptr discovery_database) @@ -81,5 +78,5 @@ void fill_received_data_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp b/ddspipe_participants/src_/cpp/writer/auxiliar/BaseWriter.cpp similarity index 91% rename from ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp rename to ddspipe_participants/src_/cpp/writer/auxiliar/BaseWriter.cpp index 9530fda62..7ab687921 100644 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BaseWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/auxiliar/BaseWriter.cpp @@ -12,23 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BaseWriter.cpp - */ #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; BaseWriter::BaseWriter( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool) : participant_id_(participant_id) , topic_(topic) @@ -102,5 +99,5 @@ std::ostream& operator <<( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp b/ddspipe_participants/src_/cpp/writer/auxiliar/BlankWriter.cpp similarity index 81% rename from ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp rename to ddspipe_participants/src_/cpp/writer/auxiliar/BlankWriter.cpp index 3138b0310..715064210 100644 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/BlankWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/auxiliar/BlankWriter.cpp @@ -12,14 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file BlankWriter.cpp - */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; @@ -33,11 +30,11 @@ void BlankWriter::disable() noexcept } utils::ReturnCode BlankWriter::write( - core::types::IRoutingData& /* data */) noexcept + core::IRoutingData& /* data */) noexcept { return utils::ReturnCode::RETCODE_OK; } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp b/ddspipe_participants/src_/cpp/writer/auxiliar/EchoWriter.cpp similarity index 88% rename from ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp rename to ddspipe_participants/src_/cpp/writer/auxiliar/EchoWriter.cpp index 084375852..5d314b6ab 100644 --- a/ddsrouter_core/src/cpp/participants/writer/auxiliar/EchoWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/auxiliar/EchoWriter.cpp @@ -12,23 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file EchoWriter.cpp - */ #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { using namespace eprosima::ddsrouter::core::types; EchoWriter::EchoWriter( - const core::types::DdsTopic& topic, + const core::types::DistributedTopic& topic, bool verbose) : topic_(topic) , verbose_(verbose) @@ -68,5 +65,5 @@ utils::ReturnCode EchoWriter::write( } } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp b/ddspipe_participants/src_/cpp/writer/rtps/CommonWriter.cpp similarity index 95% rename from ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp rename to ddspipe_participants/src_/cpp/writer/rtps/CommonWriter.cpp index 776d7c99f..e6b7fdc7c 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/CommonWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/CommonWriter.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file CommonWriter.cpp - */ #include #include @@ -22,14 +19,14 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -38,7 +35,7 @@ using eprosima::ddsrouter::core::types::operator<<; CommonWriter::CommonWriter( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater, @@ -308,7 +305,7 @@ void CommonWriter::internal_entities_creation_( } fastrtps::rtps::HistoryAttributes CommonWriter::get_history_attributes_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::rtps::HistoryAttributes att; @@ -321,7 +318,7 @@ fastrtps::rtps::HistoryAttributes CommonWriter::get_history_attributes_( } fastrtps::rtps::WriterAttributes CommonWriter::get_writer_attributes_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::rtps::WriterAttributes att; @@ -351,7 +348,7 @@ fastrtps::rtps::WriterAttributes CommonWriter::get_writer_attributes_( } fastrtps::TopicAttributes CommonWriter::get_topic_attributes_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::TopicAttributes att; @@ -373,7 +370,7 @@ fastrtps::TopicAttributes CommonWriter::get_topic_attributes_( } fastrtps::WriterQos CommonWriter::get_writer_qos_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { fastrtps::WriterQos qos; @@ -398,7 +395,7 @@ fastrtps::WriterQos CommonWriter::get_writer_qos_( } utils::PoolConfiguration CommonWriter::cache_change_pool_configuration_( - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { utils::PoolConfiguration config; config.maximum_size = topic.topic_qos.get_reference().history_depth; @@ -410,5 +407,5 @@ utils::PoolConfiguration CommonWriter::cache_change_pool_configuration_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp b/ddspipe_participants/src_/cpp/writer/rtps/MultiWriter.cpp similarity index 90% rename from ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp rename to ddspipe_participants/src_/cpp/writer/rtps/MultiWriter.cpp index 318a836eb..f895ee71f 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/MultiWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/MultiWriter.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file MultiWriter.cpp - */ #include #include @@ -22,15 +19,15 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -38,7 +35,7 @@ using namespace eprosima::ddsrouter::core::types; MultiWriter::MultiWriter( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater /* = false */) @@ -159,5 +156,5 @@ utils::ReturnCode MultiWriter::write_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/QoSSpecificWriter.cpp b/ddspipe_participants/src_/cpp/writer/rtps/QoSSpecificWriter.cpp similarity index 89% rename from ddsrouter_core/src/cpp/participants/writer/rtps/QoSSpecificWriter.cpp rename to ddspipe_participants/src_/cpp/writer/rtps/QoSSpecificWriter.cpp index a3eb8c4b4..a5ae8c6a8 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/QoSSpecificWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/QoSSpecificWriter.cpp @@ -12,14 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file QoSSpecificWriter.cpp - */ -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -27,7 +24,7 @@ using namespace eprosima::ddsrouter::core::types; QoSSpecificWriter::QoSSpecificWriter( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const core::types::SpecificEndpointQoS& specific_qos, @@ -45,7 +42,7 @@ QoSSpecificWriter::QoSSpecificWriter( fastrtps::WriterQos QoSSpecificWriter::get_writer_qos_( const core::types::SpecificEndpointQoS& specific_qos, - const core::types::DdsTopic& topic) noexcept + const core::types::DistributedTopic& topic) noexcept { // Get QoS from parent class fastrtps::WriterQos qos = CommonWriter::get_writer_qos_(topic); @@ -70,5 +67,5 @@ fastrtps::WriterQos QoSSpecificWriter::get_writer_qos_( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/SimpleWriter.cpp b/ddspipe_participants/src_/cpp/writer/rtps/SimpleWriter.cpp similarity index 80% rename from ddsrouter_core/src/cpp/participants/writer/rtps/SimpleWriter.cpp rename to ddspipe_participants/src_/cpp/writer/rtps/SimpleWriter.cpp index 2c5782ab8..d18fbe989 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/SimpleWriter.cpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/SimpleWriter.cpp @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SimpleWriter.cpp - */ #include #include @@ -22,14 +19,14 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -37,7 +34,7 @@ using namespace eprosima::ddsrouter::core::types; SimpleWriter::SimpleWriter( const ParticipantId& participant_id, - const DdsTopic& topic, + const DistributedTopic& topic, std::shared_ptr payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater /* = false */) @@ -53,5 +50,5 @@ SimpleWriter::SimpleWriter( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp b/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.cpp similarity index 91% rename from ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp rename to ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.cpp index 5fa39e0c3..d95c00ff5 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/RepeaterDataFilter.cpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.cpp @@ -12,19 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RepeaterDataFilter.cpp - */ #include #include #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -57,5 +54,5 @@ bool RepeaterDataFilter::is_relevant( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.hpp b/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp similarity index 78% rename from ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.hpp rename to ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp index c1a7c58d3..4e7d66d07 100644 --- a/ddsrouter_core/include/ddsrouter_core/participants/writer/rtps/filter/RepeaterDataFilter.hpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file RepeaterDataFilter.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ - -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -52,7 +47,5 @@ class RepeaterDataFilter : public SelfDataFilter } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_REPEATERDATAFILTER_HPP_ */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp b/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.cpp similarity index 88% rename from ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp rename to ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.cpp index b66686a40..03876cc43 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.cpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.cpp @@ -12,19 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SelfDataFilter.cpp - */ #include #include #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -38,5 +35,5 @@ bool SelfDataFilter::is_relevant( } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp b/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp similarity index 80% rename from ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp rename to ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp index 52af7569f..f4cf2248f 100644 --- a/ddsrouter_core/src/cpp/participants/writer/rtps/filter/SelfDataFilter.hpp +++ b/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file SelfDataFilter.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ +#pragma once #include @@ -35,7 +30,7 @@ struct GUID_t; } /* namespace eprosima */ namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace participants { namespace rtps { @@ -60,7 +55,5 @@ class SelfDataFilter : public fastdds::rtps::IReaderDataFilter } /* namespace rtps */ } /* namespace participants */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_RTPS_FILTER_SelfParticipantDataFilter_HPP_ */ diff --git a/ddspipe_participants/test/CMakeLists.txt b/ddspipe_participants/test/CMakeLists.txt new file mode 100644 index 000000000..7ff304e5d --- /dev/null +++ b/ddspipe_participants/test/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright 2022 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. + +# Include utils for this specific test +include_directories("TestUtils") + +# Add subdirectory with tests +add_subdirectory(unittest) +add_subdirectory(blackbox) diff --git a/ddspipe_participants/test/TestUtils/test_utils.cpp b/ddspipe_participants/test/TestUtils/test_utils.cpp new file mode 100644 index 000000000..5ca42dbc1 --- /dev/null +++ b/ddspipe_participants/test/TestUtils/test_utils.cpp @@ -0,0 +1,273 @@ +// Copyright 2021 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 test_utils.cpp + * + */ + +#include +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace test { + +using namespace eprosima::ddsrouter::core::types; + +Guid random_guid( + uint16_t seed /* = 1 */) +{ + Guid guid; + guid.entityId.value[3] = static_cast(seed); + guid.guidPrefix.value[0] = 0x01; + guid.guidPrefix.value[1] = 0x0f; + return guid; +} + +TopicInput::TopicInput( + std::string name, + std::string type, + bool keyed, + bool key_set) + : name(name) + , type(type) + , keyed(keyed) + , key_set(key_set) +{ +} + +DdsTopicInput::DdsTopicInput( + std::string name, + std::string type, + bool keyed, + bool key_set, + bool reliable, + bool reliable_set) + : TopicInput(name, type, keyed, key_set) + , reliable(reliable) + , reliable_set(reliable_set) +{ +} + +WildcardTopicInput::WildcardTopicInput( + std::string name, + std::string type, + bool keyed, + bool key_set, + bool type_set) + : TopicInput(name, type, keyed, key_set) + , type_set(type_set) +{ +} + +std::set> topic_set( + std::vector topics) +{ + std::set> result; + for (DdsTopicInput input : topics) + { + auto new_topic = std::make_shared(); + new_topic->topic_name = input.name; + new_topic->type_name = input.type; + + if (input.key_set) + { + new_topic->keyed = input.keyed; + } + + + if (input.reliable_set) + { + TopicQoS qos; + if (input.reliable) + { + qos.reliability_qos = ReliabilityKind::RELIABLE; + } + else + { + qos.reliability_qos = ReliabilityKind::BEST_EFFORT; + } + new_topic->topic_qos = qos; + new_topic->topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_fuzzy); + } + + result.insert(new_topic); + } + return result; +} + +std::set> topic_set( + std::vector topics) +{ + std::set> result; + for (WildcardTopicInput input : topics) + { + auto new_topic = std::make_shared(); + new_topic->topic_name = input.name; + new_topic->type_name = input.type; + + if (input.key_set) + { + new_topic->keyed = input.type_set; + } + + result.insert(new_topic); + + } + return result; +} + +DomainId random_domain( + uint16_t seed /* = 0 */) +{ + return DomainId(static_cast(seed)); +} + +GuidPrefix random_guid_prefix( + uint16_t seed /* = 0 */, + bool ros /* = false */) +{ + if (ros) + { + return GuidPrefix(true, seed); + } + else + { + return GuidPrefix(static_cast(seed)); + } +} + +Address random_address( + uint16_t seed /* = 0 */) +{ + return Address("127.0.0.1", seed, seed, TransportProtocol::udp); +} + +std::set random_connection_addresses( + uint16_t seed /* = 0 */, + uint16_t size /* = 1 */, + bool ros /* = false */) +{ + std::set result; + + for (int i = 0; i < size; ++i) + { + result.insert( + DiscoveryServerConnectionAddress( + random_guid_prefix((seed * size + i) * i), + std::set
({ + random_address((seed * size + i) * i), + random_address((seed * size + i) * i + 1)}))); + } + return result; +} + +std::shared_ptr random_participant_configuration( + ParticipantKind kind, + uint16_t seed /* = 0 */) +{ + ParticipantId id("Participant" + std::to_string(seed)); + + switch (kind) + { + case ParticipantKind::simple_rtps: + return std::make_shared( + id, + kind, + false, + random_domain(seed)); + + case ParticipantKind::local_discovery_server: + case ParticipantKind::wan_discovery_server: + + { + // TODO get random values + DiscoveryServerConnectionAddress connection_address = DiscoveryServerConnectionAddress( + GuidPrefix(), + std::set
({Address()}) + ); + + return std::make_shared( + id, + kind, + false, + random_domain(seed), + random_guid_prefix(seed), + std::set
(), + std::set({connection_address}), + TlsConfiguration()); + } + + case ParticipantKind::wan_initial_peers: + + { + return std::make_shared( + id, + kind, + false, + random_domain(seed), + std::set
(), + std::set
({Address()}), + TlsConfiguration()); + } + + case ParticipantKind::echo: + { + return std::make_shared( + id, + kind, + false); + } + + // Add cases where Participants need specific arguments + default: + return std::make_shared(id, false); + } +} + +ParticipantId random_participant_id( + uint16_t seed /* = 0 */) +{ + std::vector names = { + "participant", + "PART_1", + "echo", + "Barro_p", + }; + + return ParticipantId(names[seed % names.size()] + std::to_string(seed)); +} + +ParticipantKind random_participant_kind( + bool valid /* = true */, + uint16_t seed /* = 0 */) +{ + std::vector kinds(std::begin(ALL_VALID_PARTICIPANT_KINDS), std::end(ALL_VALID_PARTICIPANT_KINDS)); + if (valid) + { + return kinds[seed % kinds.size()]; + } + else + { + kinds.push_back(ParticipantKind::invalid); + return kinds[seed % kinds.size()]; + } +} + +} /* namespace test */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/test/TestUtils/test_utils.hpp b/ddspipe_participants/test/TestUtils/test_utils.hpp new file mode 100644 index 000000000..edf261c27 --- /dev/null +++ b/ddspipe_participants/test/TestUtils/test_utils.hpp @@ -0,0 +1,126 @@ +// Copyright 2021 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\. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace test { + +using namespace eprosima::ddsrouter::core::types; + +// TODO: most of the methods from this test_utils that generate random types are not very "random". +// They must be refactored to generate real random values. + +constexpr const int TEST_NUMBER_ITERATIONS = 5; + +/** + * @brief Create a \c Guid with some of its bits determined by the input + * + * @param [in] seed : differentiating value for guid creation + * @return generated Guid + * @todo Make truly random using \c seed as such + * + */ +Guid random_guid( + uint16_t seed = 1); + +struct TopicInput +{ + TopicInput( + std::string name, + std::string type, + bool keyed, + bool key_set); + + std::string name; + std::string type; + bool keyed; + bool key_set; +}; + +struct DdsTopicInput : public TopicInput +{ + DdsTopicInput( + std::string name, + std::string type, + bool keyed, + bool key_set, + bool reliable, + bool reliable_set); + + bool reliable; + bool reliable_set; +}; + +struct WildcardTopicInput : public TopicInput +{ + WildcardTopicInput( + std::string name, + std::string type, + bool keyed, + bool key_set, + bool type_set); + + bool type_set; +}; + +std::set> topic_set( + std::vector topics); + +std::set> topic_set( + std::vector topics); + +DomainId random_domain( + uint16_t seed = 0); + +GuidPrefix random_guid_prefix( + uint16_t seed = 0, + bool ros = false); + +Address random_address( + uint16_t seed = 0); + +std::set random_connection_addresses( + uint16_t seed = 0, + uint16_t size = 1, + bool ros = false); + +std::shared_ptr random_participant_configuration( + ParticipantKind kind, + uint16_t seed = 0); + +ParticipantId random_participant_id( + uint16_t seed = 0); + +ParticipantKind random_participant_kind( + bool valid = true, + uint16_t seed = 0); + +} /* namespace test */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/test/blackbox/CMakeLists.txt b/ddspipe_participants/test/blackbox/CMakeLists.txt new file mode 100644 index 000000000..992066726 --- /dev/null +++ b/ddspipe_participants/test/blackbox/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2021 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. + + +add_subdirectory(ddsrouter_core) +add_subdirectory(implementations) diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt new file mode 100644 index 000000000..4757aaf44 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2021 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. + +add_subdirectory(trivial) +add_subdirectory(dds) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt rename to ddspipe_participants/test/blackbox/ddsrouter_core/dds/CMakeLists.txt diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt new file mode 100644 index 000000000..3c70390c2 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt @@ -0,0 +1,80 @@ +# Copyright 2021 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. + +################ +# DDS Test WAN # +################ + +set(TEST_NAME + DDSTestWAN) + +set(TEST_SOURCES + DDSTestWAN.cpp + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) + +set(TEST_LIST + end_to_end_discovery_server_WAN_communication_UDPv4 + end_to_end_initial_peers_WAN_communication_UDPv4 + + end_to_end_discovery_server_WAN_communication_UDPv6 + end_to_end_initial_peers_WAN_communication_UDPv6 + + end_to_end_discovery_server_WAN_communication_TCPv4 + end_to_end_initial_peers_WAN_communication_TCPv4 + + end_to_end_discovery_server_WAN_communication_TCPv6 + end_to_end_initial_peers_WAN_communication_TCPv6 + + end_to_end_discovery_server_WAN_communication_TLSv4 + end_to_end_initial_peers_WAN_communication_TLSv4 + + end_to_end_discovery_server_WAN_communication_TLSv6 + end_to_end_initial_peers_WAN_communication_TLSv6 + + end_to_end_discovery_server_WAN_communication_high_throughput + end_to_end_initial_peers_WAN_communication_high_throughput + ) + + +set(TEST_NEEDED_SOURCES + # TLS security files + ../../resources/tls/ca.crt + ../../resources/tls/ddsrouter.crt + ../../resources/tls/ddsrouter.key + ../../resources/tls/dh_params.pem + ) + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") + +# Set flaky tests as xfail +add_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XFAIL.list) + +# Set as TSAN errors due to Fast DDS +# TODO: use a cmake_utils macro +file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/TEST_XTSAN.list TEST_LIST) +foreach(XTSAN_TEST ${TEST_LIST}) + set_property(TEST ${XTSAN_TEST} PROPERTY LABELS xtsan) +endforeach() diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp new file mode 100644 index 000000000..cc2948143 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -0,0 +1,705 @@ +// Copyright 2021 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. + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace test { + +enum class WanParticipantKind +{ + discovery_server, + initial_peers +}; + +enum class WanKind +{ + server, + client, + server_and_client +}; + +bool is_client( + WanKind wan_kind) +{ + return wan_kind == WanKind::client || wan_kind == WanKind::server_and_client; +} + +bool is_server( + WanKind wan_kind) +{ + return wan_kind == WanKind::server || wan_kind == WanKind::server_and_client; +} + +constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; +constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; +constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes + +types::TlsConfiguration tls_configuration( + WanKind wan_kind) +{ + // TODO: test that using server with only Server required files works + // It fails when connecting to other server + if (is_server(wan_kind)) + { + types::TlsConfiguration tls; + tls.certificate_authority_file = "../../resources/tls/ca.crt"; + tls.private_key_file = "../../resources/tls/ddsrouter.key"; + tls.certificate_chain_file = "../../resources/tls/ddsrouter.crt"; + tls.dh_params_file = "../../resources/tls/dh_params.pem"; + return tls; + } + else + { + types::TlsConfiguration tls; + tls.certificate_authority_file = "../../resources/tls/ca.crt"; + return tls; + } +} + +std::shared_ptr discovery_server_participant_configuration( + bool this_server_id_is_1, + WanKind wan_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool tls = false) +{ + std::set listening_addresses; + std::set connection_addresses; + + if (is_client(wan_kind)) + { + connection_addresses.insert( + types::DiscoveryServerConnectionAddress( + types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), + { + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 0u : 1u), + 11666 + (this_server_id_is_1 ? 0u : 1u), + ip_version, + transport_protocol) + } + ) + ); + } + + if (is_server(wan_kind)) + { + listening_addresses.insert( + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 1u : 0u), + 11666 + (this_server_id_is_1 ? 1u : 0u), + ip_version, + transport_protocol) + ); + } + + if (tls) + { + return std::make_shared( + types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_discovery_server, + false, + types::DomainId(0u), + types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), + listening_addresses, + connection_addresses, + tls_configuration(wan_kind)); + + } + else + { + return std::make_shared( + types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_discovery_server, + false, + types::DomainId(0u), + types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), + listening_addresses, + connection_addresses, + types::TlsConfiguration()); + } +} + +std::shared_ptr initial_peers_participant_configuration( + bool this_server_id_is_1, + WanKind wan_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool tls = false) +{ + std::set listening_addresses; + std::set connection_addresses; + types::DomainId domain(60u); + + if (is_client(wan_kind)) + { + connection_addresses.insert( + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 0u : 1u), + 11666 + (this_server_id_is_1 ? 0u : 1u), + ip_version, + transport_protocol) + ); + } + + if (is_server(wan_kind)) + { + listening_addresses.insert( + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 1u : 0u), + 11666 + (this_server_id_is_1 ? 1u : 0u), + ip_version, + transport_protocol) + ); + } + + if (tls) + { + return std::make_shared( + types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_initial_peers, + false, + domain, + listening_addresses, + connection_addresses, + tls_configuration(wan_kind)); + + } + else + { + return std::make_shared( + types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_initial_peers, + false, + domain, + listening_addresses, + connection_addresses, + types::TlsConfiguration()); + } +} + +std::shared_ptr wan_participant_configuration( + WanParticipantKind wan_participant_kind, + bool this_server_id_is_1, + WanKind wan_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool tls = false) +{ + if (wan_participant_kind == WanParticipantKind::discovery_server) + { + return discovery_server_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, + tls); + } + else // WanParticipantKind::initial_peers + { + return initial_peers_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, + tls); + } +} + +/** + * @brief Create a simple configuration for a DDS Router + * + * Create a configuration with 1 topic + * Create 1 simple participants with domains \c domain + * Create 1 custom participant by the configuration in \c participant_configuration + * + * @return DdsRouterConfiguration + */ +DdsRouterConfiguration router_configuration( + std::shared_ptr participant_configuration, + types::DomainIdType domain) +{ + // One topic + auto new_topic = std::make_shared(); + new_topic->topic_name = TOPIC_NAME; + new_topic->type_name = std::string("HelloWorld"); + + std::set> allowlist({new_topic}); + + std::set> blocklist; // empty + + std::set> builtin_topics; // empty + + // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 + std::set> participants_configurations( + { + // custom + participant_configuration, + + // simple + std::make_shared( + types::ParticipantId("simple_participant_" + std::to_string(domain)), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(domain) + ), + } + ); + + return DdsRouterConfiguration( + allowlist, + blocklist, + builtin_topics, + participants_configurations, + SpecsConfiguration()); +} + +/** + * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. + * This is accomplished by connecting two WAN Participants belonging to different DDS Router instances. These router + * instances communicate with the DDS Participants through Simple Participants deployed at those domains. + */ +void test_WAN_communication( + DdsRouterConfiguration ddsrouter_server_configuration, + DdsRouterConfiguration ddsrouter_client_configuration, + uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, + uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, + uint32_t msg_size = DEFAULT_MESSAGE_SIZE) +{ + // Check there are no warnings/errors + // TODO: Uncomment when having no listening addresses is no longer considered an error by the middleware + // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved + // test::LogChecker test_log_handler(Log::Kind::Error); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + // Create a message with size specified by repeating the same string + HelloWorld msg; + std::string msg_str; + + // Add this string as many times as the msg size requires + for (uint32_t i = 0; i < msg_size; i++) + { + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + } + msg.message(msg_str); + + // Create DDS Publisher in domain 0 + TestPublisher publisher; + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber; + ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); + + // Create DdsRouter entity whose WAN Participant is configured as server + DdsRouter server_router(ddsrouter_server_configuration); + server_router.start(); + + // Create DdsRouter entity whose WAN Participant is configured as client + DdsRouter client_router(ddsrouter_client_configuration); + client_router.start(); + + // Start publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + publisher.publish(msg); + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + client_router.stop(); + server_router.stop(); +} + +/** + * Test communication between WAN participants by running \c test_WAN_communication for different configurations. + * Different combinations of server/client configurations are tested. + * + * CASES: + * server <-> client + * server <-> server-client + * server-client <-> server-client (only when basic_only is deactivate) + */ +void test_WAN_communication_all( + WanParticipantKind wan_participant_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool basic_only = false, + bool tls = false) +{ + // Test architecture server <-> client + test::test_WAN_communication( + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + true, // is server 1 + WanKind::server, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 0 // domain + ), + + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + false, // is server 1 + WanKind::client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 1 // domain + ) + ); + + // Test architecture server <-> server-client + test::test_WAN_communication( + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + true, // is server 1 + WanKind::server, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 0 // domain + ), + + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + false, // is server 1 + WanKind::server_and_client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 1 // domain + ) + ); + + // This test is disabled for TCPv6 and TLSv6, as an underlying middleware issue resulting in no matching for this + // scenario exists. + // TODO: Test this as well for TCPv6 and TLSv6 cases when issue is fixed + if (!basic_only) + { + // Test architecture server-client <-> server-client + test::test_WAN_communication( + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + true, // is server 1 + WanKind::server_and_client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 0 // domain + ), + + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + false, // is server 1 + WanKind::server_and_client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 1 // domain + ) + ); + } +} + +} /* namespace test */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through UDPv4. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::udp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through UDPv4. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::udp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through UDPv6. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::udp, + types::IpVersion::v6); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through UDPv6. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::udp, + types::IpVersion::v6); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TCPv4. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TCPv4. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TCPv6. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TCPv6. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TLSv4. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v4, + false, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TLSv4. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v4, + false, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TLSv6. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TLSv6. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true, + true); +} + +/** + * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through UDPv4. + * + * PARAMETERS: + * - Frequency: 1ms + * - Sample size: 50K + * -> Throughput: 50MBps + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_high_throughput) +{ + test::test_WAN_communication( + test::router_configuration( + test::discovery_server_participant_configuration( + true, // is server 1 + test::WanKind::server, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 0 // domain + ), + + test::router_configuration( + test::discovery_server_participant_configuration( + false, // is server 1 + test::WanKind::client, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 1 // domain + ), + + 500, + 1, + 1000); // 50K message size +} + +/** + * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through UDPv4. + * + * PARAMETERS: + * - Frequency: 1ms + * - Sample size: 50K + * -> Throughput: 50MBps + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_high_throughput) +{ + test::test_WAN_communication( + test::router_configuration( + test::initial_peers_participant_configuration( + true, // is server 1 + test::WanKind::server, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 0 // domain + ), + + test::router_configuration( + test::initial_peers_participant_configuration( + false, // is server 1 + test::WanKind::client, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 1 // domain + ), + + 500, + 1, + 1000); // 50K message size +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md new file mode 100644 index 000000000..943086ca9 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md @@ -0,0 +1,7 @@ +# DDS Test WAN + +Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. +This is accomplished by connecting two (`DiscoveryServer` / `InitialPeers`) WAN Participants belonging to different DDS Router instances. +These router instances communicate with the DDS Participants through Simple Participants deployed at those domains. +Note that, although data transmission is accomplished by connecting two WAN Participants, the resulting communication +is still local (i.e. WAN communication is not tested here). diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list new file mode 100644 index 000000000..7aded2b7b --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list @@ -0,0 +1,8 @@ +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv6 diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list new file mode 100644 index 000000000..78996681f --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list @@ -0,0 +1,5 @@ +DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt new file mode 100644 index 000000000..f98f1006c --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt @@ -0,0 +1,84 @@ +# Copyright 2021 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. + +################## +# DDS Test local # +################## + +set(TEST_NAME + DDSTestLocal) + +set(TEST_SOURCES + DDSTestLocal.cpp + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) + +set(TEST_LIST + end_to_end_local_communication + end_to_end_local_communication_keyed + end_to_end_local_communication_disable_dynamic_discovery + end_to_end_local_communication_disable_dynamic_discovery_keyed + end_to_end_local_communication_high_frequency + end_to_end_local_communication_high_size + end_to_end_local_communication_high_throughput + end_to_end_local_communication_transient_local + end_to_end_local_communication_transient_local_disable_dynamic_discovery) + +set(TEST_NEEDED_SOURCES + ) + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") + +############################## +# DDS Test local Dispose Key # +############################## + +set(TEST_NAME + DDSTestLocalDisposeKey) + +set(TEST_SOURCES + DDSTestLocalDisposeKey.cpp + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) + +set(TEST_LIST + end_to_end_local_communication_key_dispose) + +set(TEST_NEEDED_SOURCES + ) + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp new file mode 100644 index 000000000..c176c5065 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -0,0 +1,329 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace test { + +constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; +constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; +constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes + +/** + * @brief Create a simple configuration for a DDS Router + * + * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME + * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. + * Create 2 simple participants with domains 0 and 1 + * + * @return DdsRouterConfiguration + */ +DdsRouterConfiguration dds_test_simple_configuration( + bool disable_dynamic_discovery = false, + bool transient_local_readers = false) +{ + // Always filter the test topics by topic name + std::set> allowlist; // empty + allowlist.insert(std::make_shared(TOPIC_NAME)); + + std::set> blocklist; // empty + + std::set> builtin_topics; // empty + + if (disable_dynamic_discovery) + { + types::TopicQoS qos; + if (transient_local_readers) + { + qos.reliability_qos = types::ReliabilityKind::RELIABLE; + qos.durability_qos = types::DurabilityKind::TRANSIENT_LOCAL; + } + else + { + qos.reliability_qos = types::ReliabilityKind::BEST_EFFORT; + qos.durability_qos = types::DurabilityKind::VOLATILE; + } + + builtin_topics.insert( + std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); + builtin_topics.insert( + std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); + } + + // Two simple participants + std::set> participants_configurations( + { + std::make_shared( + types::ParticipantId("participant_0"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(0u) + ), + std::make_shared( + types::ParticipantId("participant_1"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(1u) + ) + } + ); + + return DdsRouterConfiguration( + allowlist, + blocklist, + builtin_topics, + participants_configurations, + SpecsConfiguration()); +} + +/** + * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. + * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. + * + * The transient_local option changes the test behavior to verify that the communication is transient_local and all old data is sent + * to Late Joiners. + */ +template +void test_local_communication( + DdsRouterConfiguration ddsrouter_configuration, + uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, + uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, + uint32_t msg_size = DEFAULT_MESSAGE_SIZE, + bool transient_local = false) +{ + + // Check there are no warnings/errors + // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved + // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + // Create a message with size specified by repeating the same string + MsgStruct msg; + std::string msg_str; + + // Add this string as many times as the msg size requires + for (uint32_t i = 0; i < msg_size; i++) + { + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + } + msg.message(msg_str); + + // Create DDS Publisher in domain 0 + TestPublisher publisher(msg.isKeyDefined()); + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(msg.isKeyDefined(), transient_local); + ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); + + // Create DdsRouter entity + // The DDS Router does not start here in order to test a transient_local communication + DdsRouter router(ddsrouter_configuration); + + if (transient_local) + { + // To check that the communication is transient_local and all previous published samples are sent to late joiner, + // the publisher publish all data at once. + for (samples_sent = 0; samples_sent < samples_to_receive; samples_sent++) + { + msg.index(samples_sent); + ASSERT_TRUE(publisher.publish(msg)); + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + // Once the publisher has already publish all its samples, the DDS Router starts. + router.start(); + + // The subscriber should receive all samples sent by the publisher when the communication was not + // already established. + while (samples_received.load() < samples_to_receive) + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + } + else + { + // Start DDS Router + router.start(); + + // Start publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + publisher.publish(msg); + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + } + + router.stop(); +} + +} /* namespace test */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + */ +TEST(DDSTestLocal, end_to_end_local_communication) +{ + test::test_local_communication( + test::dds_test_simple_configuration()); +} + +/** + * Test communication in HelloWorldKeyed topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + */ +TEST(DDSTestLocal, end_to_end_local_communication_keyed) +{ + test::test_local_communication( + test::dds_test_simple_configuration()); +} + +/** + * Test communication both in HelloWorld and HelloWorldKeyed topics between two DDS participants created in + * different domains, by using a router with two Simple Participants at each domain. + * In this test allowlist and blocklist are left empty, while only builtin topics are provided. + */ +TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery) +{ + test::test_local_communication( + test::dds_test_simple_configuration(true)); +} + +TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery_keyed) +{ + test::test_local_communication( + test::dds_test_simple_configuration(true)); +} + +/** + * Test high frequency communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + * + * PARAMETERS: + * - Frequency: max + */ +TEST(DDSTestLocal, end_to_end_local_communication_high_frequency) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + 1000, // wait for 1000 samples received + 0); // send it without waiting from one sample to the other +} + +/** + * Test high message size communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + * + * PARAMETERS: + * - Sample size: 500K + */ +TEST(DDSTestLocal, end_to_end_local_communication_high_size) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + test::DEFAULT_SAMPLES_TO_RECEIVE, + test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, + 10000); // 500K message size +} + +/** + * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + * + * PARAMETERS: + * - Frequency: 1ms + * - Sample size: 50K + * -> Throughput: 50MBps + */ +TEST(DDSTestLocal, end_to_end_local_communication_high_throughput) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + 500, + 1, + 1000); // 50K message size +} + +/** + * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + */ +TEST(DDSTestLocal, end_to_end_local_communication_transient_local) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + test::DEFAULT_SAMPLES_TO_RECEIVE, + test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, + test::DEFAULT_MESSAGE_SIZE, + true); +} + +/** + * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain and using builtin-topics + */ +TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynamic_discovery) +{ + test::test_local_communication( + test::dds_test_simple_configuration(true, true), + test::DEFAULT_SAMPLES_TO_RECEIVE, + test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, + test::DEFAULT_MESSAGE_SIZE, + true); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp new file mode 100644 index 000000000..9a563bf3e --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp @@ -0,0 +1,201 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace test { + +constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; +constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; +constexpr const uint32_t DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION = 500; +constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes + +/** + * @brief Create a simple configuration for a DDS Router + * + * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME + * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. + * Create 2 simple participants with domains 0 and 1 + * + * @return DdsRouterConfiguration + */ +DdsRouterConfiguration dds_test_simple_configuration() +{ + // Always filter the test topics by topic name + std::set> allowlist; // only this topic + allowlist.insert(std::make_shared(TOPIC_NAME)); + + std::set> blocklist; // empty + + std::set> builtin_topics; // empty + + // Two simple participants + std::set> participants_configurations( + { + std::make_shared( + types::ParticipantId("participant_0"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(0u) + ), + std::make_shared( + types::ParticipantId("participant_1"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(1u) + ) + } + ); + + // TODO: this could be removed to use default number of threads + auto specs = SpecsConfiguration(); + specs.number_of_threads = 2; + + return DdsRouterConfiguration( + allowlist, + blocklist, + builtin_topics, + participants_configurations, + specs); +} + +/** + * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. + * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. + * + * The reliable option changes the test behavior to verify that the communication is reliable and all old data is sent + * to Late Joiners. + */ +void test_local_communication_key_dispose( + DdsRouterConfiguration ddsrouter_configuration, + uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, + uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, + uint32_t msg_size = DEFAULT_MESSAGE_SIZE) +{ + // Check there are no warnings/errors + // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved + // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + // Create a message with size specified by repeating the same string + HelloWorldKeyed msg; + std::string msg_str; + + // Add this string as many times as the msg size requires + for (uint32_t i = 0; i < msg_size; i++) + { + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + } + msg.message(msg_str); + msg.id(666); + + // Create DDS Publisher in domain 0 + TestPublisher publisher(msg.isKeyDefined()); + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(msg.isKeyDefined()); + ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); + + // Create DdsRouter entity + // The DDS Router does not start here in order to test a reliable communication + DdsRouter router(ddsrouter_configuration); + + // Start DDS Router + router.start(); + + // Start publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + ASSERT_TRUE(publisher.publish(msg)) << samples_sent; + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + // All samples received, now dispose key from publisher and check that subscriber has receive it + ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); + std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); + samples_received.store(0); + + // Keep publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + ASSERT_TRUE(publisher.publish(msg)) << samples_sent; + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + // All samples received, now dispose key from publisher and check that subscriber has receive it + ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); + std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); + + ASSERT_EQ(2u, subscriber.n_disposed()); + + router.stop(); +} + +} /* namespace test */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test that dispose values from the publisher are correctly received by the subscriber from the router. + */ +TEST(DDSTestLocalDisposeKey, end_to_end_local_communication_key_dispose) +{ + test::test_local_communication_key_dispose( + test::dds_test_simple_configuration()); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md new file mode 100644 index 000000000..a94c61e34 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md @@ -0,0 +1,6 @@ +# DDS Test Local + +Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. +This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. +First, router initialization is tested, and then communication between the DDS Participants is tested both for topics +*HelloWorld* and *HelloWorldKeyed*. diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx new file mode 100644 index 000000000..b850b4501 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx @@ -0,0 +1,207 @@ +// Copyright 2016 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 HelloWorld.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { char dummy; } +#endif + +#include "HelloWorld.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +HelloWorld::HelloWorld() +{ + // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@1622f1b + m_index = 0; + // m_message com.eprosima.idl.parser.typecode.StringTypeCode@70e8f8e + m_message =""; + +} + +HelloWorld::~HelloWorld() +{ + + +} + +HelloWorld::HelloWorld(const HelloWorld &x) +{ + m_index = x.m_index; + m_message = x.m_message; +} + +HelloWorld::HelloWorld(HelloWorld &&x) +{ + m_index = x.m_index; + m_message = std::move(x.m_message); +} + +HelloWorld& HelloWorld::operator=(const HelloWorld &x) +{ + + m_index = x.m_index; + m_message = x.m_message; + + return *this; +} + +HelloWorld& HelloWorld::operator=(HelloWorld &&x) +{ + + m_index = x.m_index; + m_message = std::move(x.m_message); + + return *this; +} + +size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; + + + return current_alignment - initial_alignment; +} + +size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; + + + return current_alignment - initial_alignment; +} + +void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const +{ + + scdr << m_index; + scdr << m_message; +} + +void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr) +{ + + dcdr >> m_index; + dcdr >> m_message; +} + +/*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ +void HelloWorld::index(uint32_t _index) +{ +m_index = _index; +} + +/*! + * @brief This function returns the value of member index + * @return Value of member index + */ +uint32_t HelloWorld::index() const +{ + return m_index; +} + +/*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ +uint32_t& HelloWorld::index() +{ + return m_index; +} + +/*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ +void HelloWorld::message(const std::string &_message) +{ +m_message = _message; +} + +/*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ +void HelloWorld::message(std::string &&_message) +{ +m_message = std::move(_message); +} + +/*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ +const std::string& HelloWorld::message() const +{ + return m_message; +} + +/*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ +std::string& HelloWorld::message() +{ + return m_message; +} + +size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment) +{ + size_t current_align = current_alignment; + + + + + + return current_align; +} + +bool HelloWorld::isKeyDefined() +{ + return false; +} + +void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const +{ + (void) scdr; + + +} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h new file mode 100644 index 000000000..c445fff76 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h @@ -0,0 +1,216 @@ +// Copyright 2016 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 HelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */#pragma once + +// TODO Poner en el contexto. + +#include +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // if defined(EPROSIMA_USER_DLL_EXPORT) +#else +#define eProsima_user_DllExport +#endif // if defined(_WIN32) + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(HelloWorld_SOURCE) +#define HelloWorld_DllAPI __declspec( dllexport ) +#else +#define HelloWorld_DllAPI __declspec( dllimport ) +#endif // HelloWorld_SOURCE +#else +#define HelloWorld_DllAPI +#endif // if defined(EPROSIMA_USER_DLL_EXPORT) +#else +#define HelloWorld_DllAPI +#endif // _WIN32 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +class HelloWorld +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport HelloWorld(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~HelloWorld(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld( + const HelloWorld& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld( + HelloWorld&& x); + + /*! + * @brief Copy assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator =( + const HelloWorld& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator =( + HelloWorld&& x); + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ + eProsima_user_DllExport void message( + const std::string& _message); + + /*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ + eProsima_user_DllExport void message( + std::string&& _message); + + /*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ + eProsima_user_DllExport const std::string& message() const; + + /*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ + eProsima_user_DllExport std::string& message(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const HelloWorld& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + uint32_t m_index; + std::string m_message; +}; + +#endif // _HELLOWORLD_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl new file mode 100644 index 000000000..0fd2c355a --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx new file mode 100644 index 000000000..a2a27e7bc --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx @@ -0,0 +1,133 @@ +// Copyright 2016 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 HelloWorldPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#include +#include + +#include "HelloWorldPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + +HelloWorldPubSubType::HelloWorldPubSubType() +{ + setName("HelloWorld"); + m_typeSize = static_cast(HelloWorld::getMaxCdrSerializedSize()) + 4 /*encapsulation*/; + m_isGetKeyDefined = HelloWorld::isKeyDefined(); + size_t keyLength = HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +HelloWorldPubSubType::~HelloWorldPubSubType() +{ + if(m_keyBuffer!=nullptr) + free(m_keyBuffer); +} + +bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) +{ + HelloWorld *p_type = static_cast(data); + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + // Serialize encapsulation + ser.serialize_encapsulation(); + + try + { + p_type->serialize(ser); // Serialize the object: + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + payload->length = static_cast(ser.getSerializedDataLength()); //Get the serialized length + return true; +} + +bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) +{ + HelloWorld* p_type = static_cast(data); //Convert DATA to pointer of your type + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data. + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + p_type->deserialize(deser); //Deserialize the object: + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + return true; +} + +std::function HelloWorldPubSubType::getSerializedSizeProvider(void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + 4 /*encapsulation*/; + }; +} + +void* HelloWorldPubSubType::createData() +{ + return reinterpret_cast(new HelloWorld()); +} + +void HelloWorldPubSubType::deleteData(void* data) +{ + delete(reinterpret_cast(data)); +} + +bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5) +{ + if(!m_isGetKeyDefined) + return false; + HelloWorld* p_type = static_cast(data); + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer),HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data. + p_type->serializeKey(ser); + if(force_md5 || HelloWorld::getKeyMaxCdrSerializedSize()>16) { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + m_md5.finalize(); + for(uint8_t i = 0;i<16;++i) { + handle->value[i] = m_md5.digest[i]; + } + } + else { + for(uint8_t i = 0;i<16;++i) { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h new file mode 100644 index 000000000..44f12a5b5 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h @@ -0,0 +1,64 @@ +// Copyright 2016 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 HelloWorldPubSubTypes.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ +#pragma once + +#include +#include + +#include "HelloWorld.h" + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#error Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // if !defined(GEN_API_VER) || (GEN_API_VER != 1) + +/*! + * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef HelloWorld type; + + eProsima_user_DllExport HelloWorldPubSubType(); + + eProsima_user_DllExport virtual ~HelloWorldPubSubType(); + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + eProsima_user_DllExport virtual void* createData() override; + eProsima_user_DllExport virtual void deleteData( + void* data) override; + MD5 m_md5; + unsigned char* m_keyBuffer; +}; + +#endif // _HELLOWORLD_PUBSUBTYPES_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx new file mode 100644 index 000000000..43e4eb3b9 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx @@ -0,0 +1,283 @@ +// Copyright 2016 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 HelloWorldKeyed.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { +char dummy; +} // namespace +#endif // _WIN32 + +#include "HelloWorldKeyed.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +HelloWorldKeyed::HelloWorldKeyed() +{ + // m_id com.eprosima.idl.parser.typecode.PrimitiveTypeCode@77a57272 + m_id = 0; + // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@7181ae3f + m_index = 0; + // m_message com.eprosima.idl.parser.typecode.StringTypeCode@46238e3f + m_message =""; + +} + +HelloWorldKeyed::~HelloWorldKeyed() +{ + + + +} + +HelloWorldKeyed::HelloWorldKeyed( + const HelloWorldKeyed& x) +{ + m_id = x.m_id; + m_index = x.m_index; + m_message = x.m_message; +} + +HelloWorldKeyed::HelloWorldKeyed( + HelloWorldKeyed&& x) +{ + m_id = x.m_id; + m_index = x.m_index; + m_message = std::move(x.m_message); +} + +HelloWorldKeyed& HelloWorldKeyed::operator =( + const HelloWorldKeyed& x) +{ + + m_id = x.m_id; + m_index = x.m_index; + m_message = x.m_message; + + return *this; +} + +HelloWorldKeyed& HelloWorldKeyed::operator =( + HelloWorldKeyed&& x) +{ + + m_id = x.m_id; + m_index = x.m_index; + m_message = std::move(x.m_message); + + return *this; +} + +bool HelloWorldKeyed::operator ==( + const HelloWorldKeyed& x) const +{ + + return (m_id == x.m_id && m_index == x.m_index && m_message == x.m_message); +} + +bool HelloWorldKeyed::operator !=( + const HelloWorldKeyed& x) const +{ + return !(*this == x); +} + +size_t HelloWorldKeyed::getMaxCdrSerializedSize( + size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; + + + return current_alignment - initial_alignment; +} + +size_t HelloWorldKeyed::getCdrSerializedSize( + const HelloWorldKeyed& data, + size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; + + + return current_alignment - initial_alignment; +} + +void HelloWorldKeyed::serialize( + eprosima::fastcdr::Cdr& scdr) const +{ + + scdr << m_id; + scdr << m_index; + scdr << m_message; + +} + +void HelloWorldKeyed::deserialize( + eprosima::fastcdr::Cdr& dcdr) +{ + + dcdr >> m_id; + dcdr >> m_index; + dcdr >> m_message; +} + +/*! + * @brief This function sets a value in member id + * @param _id New value for member id + */ +void HelloWorldKeyed::id( + int32_t _id) +{ + m_id = _id; +} + +/*! + * @brief This function returns the value of member id + * @return Value of member id + */ +int32_t HelloWorldKeyed::id() const +{ + return m_id; +} + +/*! + * @brief This function returns a reference to member id + * @return Reference to member id + */ +int32_t& HelloWorldKeyed::id() +{ + return m_id; +} + +/*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ +void HelloWorldKeyed::index( + uint32_t _index) +{ + m_index = _index; +} + +/*! + * @brief This function returns the value of member index + * @return Value of member index + */ +uint32_t HelloWorldKeyed::index() const +{ + return m_index; +} + +/*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ +uint32_t& HelloWorldKeyed::index() +{ + return m_index; +} + +/*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ +void HelloWorldKeyed::message( + const std::string& _message) +{ + m_message = _message; +} + +/*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ +void HelloWorldKeyed::message( + std::string&& _message) +{ + m_message = std::move(_message); +} + +/*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ +const std::string& HelloWorldKeyed::message() const +{ + return m_message; +} + +/*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ +std::string& HelloWorldKeyed::message() +{ + return m_message; +} + +size_t HelloWorldKeyed::getKeyMaxCdrSerializedSize( + size_t current_alignment) +{ + size_t current_align = current_alignment; + + + current_align += 4 + eprosima::fastcdr::Cdr::alignment(current_align, 4); + + + + + + return current_align; +} + +bool HelloWorldKeyed::isKeyDefined() +{ + return true; +} + +void HelloWorldKeyed::serializeKey( + eprosima::fastcdr::Cdr& scdr) const +{ + (void) scdr; + scdr << m_id; + +} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h new file mode 100644 index 000000000..8b1d2787e --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h @@ -0,0 +1,249 @@ +// Copyright 2016 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 HelloWorldKeyed.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */#pragma once + + +#include +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(HelloWorldKeyed_SOURCE) +#define HelloWorldKeyed_DllAPI __declspec( dllexport ) +#else +#define HelloWorldKeyed_DllAPI __declspec( dllimport ) +#endif // HelloWorldKeyed_SOURCE +#else +#define HelloWorldKeyed_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define HelloWorldKeyed_DllAPI +#endif // _WIN32 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the structure HelloWorldKeyed defined by the user in the IDL file. + * @ingroup HELLOWORLDKEYED + */ +class HelloWorldKeyed +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport HelloWorldKeyed(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~HelloWorldKeyed(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed( + const HelloWorldKeyed& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed( + HelloWorldKeyed&& x); + + /*! + * @brief Copy assignment. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed& operator =( + const HelloWorldKeyed& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed& operator =( + HelloWorldKeyed&& x); + + /*! + * @brief Comparison operator. + * @param x HelloWorldKeyed object to compare. + */ + eProsima_user_DllExport bool operator ==( + const HelloWorldKeyed& x) const; + + /*! + * @brief Comparison operator. + * @param x HelloWorldKeyed object to compare. + */ + eProsima_user_DllExport bool operator !=( + const HelloWorldKeyed& x) const; + + /*! + * @brief This function sets a value in member id + * @param _id New value for member id + */ + eProsima_user_DllExport void id( + int32_t _id); + + /*! + * @brief This function returns the value of member id + * @return Value of member id + */ + eProsima_user_DllExport int32_t id() const; + + /*! + * @brief This function returns a reference to member id + * @return Reference to member id + */ + eProsima_user_DllExport int32_t& id(); + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ + eProsima_user_DllExport void message( + const std::string& _message); + + /*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ + eProsima_user_DllExport void message( + std::string&& _message); + + /*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ + eProsima_user_DllExport const std::string& message() const; + + /*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ + eProsima_user_DllExport std::string& message(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const HelloWorldKeyed& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + int32_t m_id; + uint32_t m_index; + std::string m_message; +}; + +#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl new file mode 100644 index 000000000..6cebe626d --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl @@ -0,0 +1,6 @@ +struct HelloWorldKeyed +{ + @Key long id; + unsigned long index; + string message; +}; diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx new file mode 100644 index 000000000..61eb7c992 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx @@ -0,0 +1,170 @@ +// Copyright 2016 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 HelloWorldKeyedPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#include +#include + +#include "HelloWorldKeyedPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + +HelloWorldKeyedPubSubType::HelloWorldKeyedPubSubType() +{ + setName("HelloWorldKeyed"); + auto type_size = HelloWorldKeyed::getMaxCdrSerializedSize(); + type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ + m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ + m_isGetKeyDefined = HelloWorldKeyed::isKeyDefined(); + size_t keyLength = HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16 ? + HelloWorldKeyed::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +HelloWorldKeyedPubSubType::~HelloWorldKeyedPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool HelloWorldKeyedPubSubType::serialize( + void* data, + SerializedPayload_t* payload) +{ + HelloWorldKeyed* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + // Serialize encapsulation + ser.serialize_encapsulation(); + + try + { + // Serialize the object. + p_type->serialize(ser); + } + catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + // Get the serialized length + payload->length = static_cast(ser.getSerializedDataLength()); + return true; +} + +bool HelloWorldKeyedPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + //Convert DATA to pointer of your type + HelloWorldKeyed* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + // Deserialize the object. + p_type->deserialize(deser); + } + catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + return true; +} + +std::function HelloWorldKeyedPubSubType::getSerializedSizeProvider( + void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; + }; +} + +void* HelloWorldKeyedPubSubType::createData() +{ + return reinterpret_cast(new HelloWorldKeyed()); +} + +void HelloWorldKeyedPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool HelloWorldKeyedPubSubType::getKey( + void* data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + HelloWorldKeyed* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + HelloWorldKeyed::getKeyMaxCdrSerializedSize()); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); + p_type->serializeKey(ser); + if (force_md5 || HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16) + { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h new file mode 100644 index 000000000..d4a3a204f --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h @@ -0,0 +1,98 @@ +// Copyright 2016 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 HelloWorldKeyedPubSubTypes.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ +#pragma once + +#include +#include + +#include "HelloWorldKeyed.h" + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#error \ + Generated HelloWorldKeyed is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + +/*! + * @brief This class represents the TopicDataType of the type HelloWorldKeyed defined by the user in the IDL file. + * @ingroup HELLOWORLDKEYED + */ +class HelloWorldKeyedPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef HelloWorldKeyed type; + + eProsima_user_DllExport HelloWorldKeyedPubSubType(); + + eProsima_user_DllExport virtual ~HelloWorldKeyedPubSubType(); + + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport virtual void* createData() override; + + eProsima_user_DllExport virtual void deleteData( + void* data) override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + (void)memory; + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + MD5 m_md5; + unsigned char* m_keyBuffer; +}; + +#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp new file mode 100644 index 000000000..7bcde346e --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp @@ -0,0 +1,495 @@ +// Copyright 2021 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\. + +#pragma once + +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "HelloWorld/HelloWorldPubSubTypes.h" +#include "HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h" + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace test { + +constexpr const char* TOPIC_NAME = "DDS-Router-Test"; + +/** + * Class used to group into a single working unit a Publisher with a DataWriter and a TypeSupport member corresponding + * to the HelloWorld datatype + */ +template +class TestPublisher +{ +public: + + TestPublisher( + bool keyed = false) + : participant_(nullptr) + , publisher_(nullptr) + , topic_(nullptr) + , writer_(nullptr) + , keyed_(keyed) + { + } + + ~TestPublisher() + { + if (participant_ != nullptr) + { + if (publisher_ != nullptr) + { + if (writer_ != nullptr) + { + publisher_->delete_datawriter(writer_); + } + participant_->delete_publisher(publisher_); + } + if (topic_ != nullptr) + { + participant_->delete_topic(topic_); + } + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); + } + } + + //! Initialize the publisher + bool init( + uint32_t domain) + { + // CREATE THE PARTICIPANT + eprosima::fastdds::dds::DomainParticipantQos pqos; + + pqos.name("Participant_pub"); + participant_ = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); + + if (participant_ == nullptr) + { + return false; + } + + // REGISTER THE TYPE + eprosima::fastdds::dds::TypeSupport type; + if (keyed_) + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); + } + else + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); + } + type.register_type(participant_); + + // CREATE THE PUBLISHER + publisher_ = participant_->create_publisher(eprosima::fastdds::dds::PUBLISHER_QOS_DEFAULT, nullptr); + + if (publisher_ == nullptr) + { + return false; + } + + // CREATE THE TOPIC + std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; + topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); + + if (topic_ == nullptr) + { + return false; + } + + // CREATE THE WRITER + // Set memory management policy so it uses realloc + eprosima::fastdds::dds::DataWriterQos wqos = eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT; + wqos.endpoint().history_memory_policy = + eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + wqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; + writer_ = publisher_->create_datawriter(topic_, wqos, &listener_); + + if (writer_ == nullptr) + { + return false; + } + + return true; + } + + //! Publish a sample + bool publish( + MsgStruct msg) + { + hello_.index(msg.index()); + hello_.message(msg.message()); + return writer_->write(&hello_); + } + + //! Dispose instance + eprosima::fastrtps::types::ReturnCode_t dispose_key( + MsgStruct msg); + + void wait_discovery( + uint32_t n_subscribers = 1) + { + listener_.wait_discovery(n_subscribers); + } + +private: + + MsgStruct hello_; + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Publisher* publisher_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::DataWriter* writer_; + + bool keyed_; + + class PubListener : public eprosima::fastdds::dds::DataWriterListener + { + public: + + PubListener() + : discovered(0) + { + } + + void wait_discovery( + uint32_t n_subscribers = 1) + { + if (discovered < n_subscribers) + { + std::unique_lock lock(wait_discovery_cv_mtx); + wait_discovery_cv.wait(lock, [this, n_subscribers] + { + return discovered >= n_subscribers; + }); + } + } + + void on_publication_matched( + eprosima::fastdds::dds::DataWriter*, + const eprosima::fastdds::dds::PublicationMatchedStatus& info) + { + if (info.current_count_change == 1) + { + discovered = info.current_count; + wait_discovery_cv.notify_all(); + } + else if (info.current_count_change == -1) + { + discovered = info.current_count; + } + } + + private: + + //! Number of DataReaders discovered + std::atomic discovered; + + //! Protects wait_discovery condition variable + std::mutex wait_discovery_cv_mtx; + + //! Waits to discovery enough DataReaders + std::condition_variable wait_discovery_cv; + } + listener_; +}; + +template <> +bool TestPublisher::publish( + HelloWorldKeyed msg) +{ + hello_.index(msg.index()); + hello_.message(msg.message()); + hello_.id(msg.id()); + return writer_->write(&hello_); +} + +template <> +eprosima::fastrtps::types::ReturnCode_t TestPublisher::dispose_key( + HelloWorldKeyed msg) +{ + hello_.id(msg.id()); + return writer_->dispose(&hello_, eprosima::fastdds::dds::HANDLE_NIL); +} + +/** + * Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member + * corresponding to the HelloWorld datatype + */ +template +class TestSubscriber +{ +public: + + TestSubscriber( + bool keyed = false, + bool reliable = false) + : participant_(nullptr) + , subscriber_(nullptr) + , topic_(nullptr) + , reader_(nullptr) + , keyed_(keyed) + , reliable_ (reliable) + { + } + + ~TestSubscriber() + { + if (participant_ != nullptr) + { + if (topic_ != nullptr) + { + participant_->delete_topic(topic_); + } + if (subscriber_ != nullptr) + { + if (reader_ != nullptr) + { + subscriber_->delete_datareader(reader_); + } + participant_->delete_subscriber(subscriber_); + } + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); + } + } + + //! Initialize the subscriber + bool init( + uint32_t domain, + MsgStruct* msg_should_receive, + std::atomic* samples_received) + { + // INITIALIZE THE LISTENER + listener_.init(msg_should_receive, samples_received); + + // CREATE THE PARTICIPANT + eprosima::fastdds::dds::DomainParticipantQos pqos; + pqos.name("Participant_sub"); + participant_ = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); + + if (participant_ == nullptr) + { + return false; + } + + // REGISTER THE TYPE + eprosima::fastdds::dds::TypeSupport type; + if (keyed_) + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); + } + else + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); + } + type.register_type(participant_); + + // CREATE THE SUBSCRIBER + subscriber_ = participant_->create_subscriber(eprosima::fastdds::dds::SUBSCRIBER_QOS_DEFAULT, nullptr); + + if (subscriber_ == nullptr) + { + return false; + } + + // CREATE THE TOPIC + std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; + topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); + + if (topic_ == nullptr) + { + return false; + } + + // CREATE THE READER + // Set memory management policy so it uses realloc + eprosima::fastdds::dds::DataReaderQos rqos = eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT; + rqos.endpoint().history_memory_policy = + eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + rqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; + if (reliable_) + { + rqos.durability().kind = eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; + rqos.reliability().kind = eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; + } + + reader_ = subscriber_->create_datareader(topic_, rqos, &listener_); + + if (reader_ == nullptr) + { + return false; + } + + return true; + } + + void wait_discovery( + uint32_t n_publishers = 1) + { + listener_.wait_discovery(n_publishers); + } + + uint32_t n_disposed() const + { + return listener_.n_key_disposed; + } + +private: + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Subscriber* subscriber_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::DataReader* reader_; + + bool keyed_; + + bool reliable_; + + /** + * Class handling dataflow events + */ + class SubListener : public eprosima::fastdds::dds::DataReaderListener + { + public: + + SubListener() + : discovered(0) + { + } + + //! Initialize the listener + void init( + MsgStruct* msg_should_receive_arg, + std::atomic* samples_received_arg) + { + msg_should_receive = msg_should_receive_arg; + samples_received = samples_received_arg; + n_key_disposed = 0; + } + + void wait_discovery( + uint32_t n_publishers = 1) + { + if (discovered < n_publishers) + { + std::unique_lock lock(wait_discovery_cv_mtx); + wait_discovery_cv.wait(lock, [this, n_publishers] + { + return discovered >= n_publishers; + }); + } + } + + //! Callback executed when a new sample is received + void on_data_available( + eprosima::fastdds::dds::DataReader* reader) override + { + eprosima::fastdds::dds::SampleInfo info; + while (reader->take_next_sample(&msg_received, &info) == ReturnCode_t::RETCODE_OK) + { + if (info.instance_state == eprosima::fastdds::dds::ALIVE_INSTANCE_STATE) + { + if (msg_received.message() == msg_should_receive->message()) + { + (*samples_received)++; + } + } + else if (info.instance_state == eprosima::fastdds::dds::NOT_ALIVE_DISPOSED_INSTANCE_STATE) + { + n_key_disposed++; + } + } + } + + void on_subscription_matched( + eprosima::fastdds::dds::DataReader*, + const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) + { + if (info.current_count_change == 1) + { + discovered = info.current_count; + wait_discovery_cv.notify_all(); + } + else if (info.current_count_change == -1) + { + discovered = info.current_count; + } + } + + //! Placeholder where received data is stored + MsgStruct msg_received; + + std::atomic n_key_disposed; + + //! Reference to the sample sent by the publisher + MsgStruct* msg_should_receive; + + //! Reference to received messages counter + std::atomic* samples_received; + + //! Number of DataWriters discovered + std::atomic discovered; + + //! Protects wait_discovery condition variable + std::mutex wait_discovery_cv_mtx; + + //! Waits to discovery enough DataWriters + std::condition_variable wait_discovery_cv; + } + listener_; +}; + +} /* namespace test */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt new file mode 120000 index 000000000..470d47e16 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/ca.crt \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt new file mode 120000 index 000000000..19c9a0d73 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/ddsrouter.crt \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key new file mode 120000 index 000000000..9f58dfbe3 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/ddsrouter.key \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem new file mode 120000 index 000000000..65a440083 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/dh_params.pem \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt new file mode 100644 index 000000000..939063479 --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright 2021 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. + +################ +# Trivial Test # +################ + +set(TEST_NAME + TrivialTest) + +set(TEST_SOURCES + TrivialTest.cpp) + +set(TEST_LIST + trivial_void_initialization + trivial_dummy_initialization + trivial_communication) + +set(TEST_NEEDED_SOURCES + ) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}") diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp new file mode 100644 index 000000000..08df465cb --- /dev/null +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp @@ -0,0 +1,170 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +using namespace eprosima::ddsrouter::test; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +std::vector random_payload( + uint16_t seed = 1) +{ + std::vector payload; + + for (int i = 0; i < seed; i++) + { + payload.push_back(i); + } + + return payload; +} + +DdsRouterConfiguration void_configuration() +{ + DdsRouterConfiguration configuration; + configuration.participants_configurations = + { + std::make_shared( + ParticipantId("ParticipantVoid1"), + ParticipantKind::blank, + false + ), + std::make_shared( + ParticipantId("ParticipantVoid2"), + ParticipantKind::blank, + false + ) + }; + + return configuration; +} + +/** + * @brief Create a \c DdsRouterConfiguration with 2 dummy participants and one builtin topic + * + * @return DdsRouterConfiguration + */ +DdsRouterConfiguration simple_configuration( + const std::string& participant_1_name = "Participant1", + const std::string& participant_2_name = "Participant2", + const std::string& topic_name = "topic_dummy", + const std::string& topic_type = "type_dummy") +{ + DdsRouterConfiguration configuration; + + configuration.builtin_topics = + { + std::set>({std::make_shared(topic_name, topic_type)}), + }; + + configuration.participants_configurations = + { + std::make_shared( + ParticipantId(participant_1_name), + ParticipantKind::dummy, + false + ), + std::make_shared( + ParticipantId(participant_2_name), + ParticipantKind::dummy, + false + ) + }; + + return configuration; +} + +/** + * Test Whole DdsRouter initialization by initializing two EmptyParticipants + */ +TEST(TrivialTest, trivial_void_initialization) +{ + // Create DdsRouter entity + DdsRouter router(void_configuration()); + router.start(); + router.stop(); + + // Let test finish without failing +} + +/** + * Test Whole DdsRouter initialization by initializing two DummyParticipants and a DistributedTopic + */ +TEST(TrivialTest, trivial_dummy_initialization) +{ + // Create DdsRouter entity + DdsRouter router(simple_configuration()); + router.start(); + router.stop(); + + // Let test finish without failing +} + +/** + * Test Whole DdsRouter interfaces by using two DummyParticipants and send one message from one to the other + * + * TODO + */ +TEST(TrivialTest, trivial_communication) +{ + DdsRouter router(simple_configuration()); + router.start(); + + DummyParticipant* participant_1 = DummyParticipant::get_participant(ParticipantId("Participant1")); + DummyParticipant* participant_2 = DummyParticipant::get_participant(ParticipantId("Participant2")); + ASSERT_NE(participant_1, nullptr); + ASSERT_NE(participant_2, nullptr); + + DistributedTopic topic("topic_dummy", "type_dummy"); + Guid guid = random_guid(); + std::vector payload = random_payload(3); + + DummyDataReceived data; + data.source_guid = guid; + data.payload = payload; + + participant_1->simulate_data_reception(topic, data); + + // Sleep until first data arrives to the writer + participant_2->wait_until_n_data_sent(topic, 1); + + std::vector data_received = participant_2->get_data_that_should_have_been_sent(topic); + + ASSERT_EQ(data_received.size(), 1u); + ASSERT_EQ(data_received[0].source_guid, guid); + ASSERT_EQ(data_received[0].payload, payload); + + router.stop(); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/blackbox/implementations/CMakeLists.txt b/ddspipe_participants/test/blackbox/implementations/CMakeLists.txt new file mode 100644 index 000000000..fc76ab846 --- /dev/null +++ b/ddspipe_participants/test/blackbox/implementations/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright 2021 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. + +######################## +# Implementations Test # +######################## + +set(TEST_NAME + ImplementationsTest) + +set(TEST_SOURCES + ImplementationsTest.cpp + ) + +set(TEST_LIST + pair_implementation + pair_implementation_with_topic + all_implementations + duplicated_ids + ) + +set(TEST_NEEDED_SOURCES + ) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + ) diff --git a/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp b/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp new file mode 100644 index 000000000..6b8effbc6 --- /dev/null +++ b/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp @@ -0,0 +1,246 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace test { + +constexpr const unsigned int DEFAULT_THREAD_POOL_SIZE = 2; +constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; + +} /* namespace test */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test that creates a DDSRouter with a Pair of Participants of same kind. + * It creates a DDSRouter with two Participants of same kind, starts it, then stops it and finally destroys it. + * + * This test will fail if it crashes. + */ +TEST(ImplementationsTest, pair_implementation) +{ + // TODO: Change to warning when fastdds warning: + // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: + // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> + // Function eprosima::fastdds::rtps::UDPChannelResource::Receive + // test::LogChecker test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + // For each Participant Kind + for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) + { + std::set> participant_configurations; + participant_configurations.insert(test::random_participant_configuration(kind, 1)); + participant_configurations.insert(test::random_participant_configuration(kind, 2)); + + SpecsConfiguration specs; + specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; + specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; + + // Generate configuration + DDSRouterConfiguration configuration( + std::set>(), + std::set>(), + std::set>(), + participant_configurations, + specs); + + // Create DDSRouter entity + DDSRouter router(configuration); + // Start DDSRouter + router.start(); + + // Stop DDS Router + router.stop(); + + // Let DDSRouter object destroy for the next iteration + } +} + +/** + * Test that creates a DDSRouter with a Pair of Participants of same kind. + * It creates a DDSRouter with two Participants of same kind, starts it with an active topic, + * then stops it and finally destroys it. + * + * This test will fail if it crashes. + */ +TEST(ImplementationsTest, pair_implementation_with_topic) +{ + // TODO: Change to warning when fastdds warning: + // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: + // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> + // Function eprosima::fastdds::rtps::UDPChannelResource::Receive + // test::LogChecker test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + // For each Participant kind + for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) + { + std::set> builtin_topics = test::topic_set( + {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); + + std::set> participant_configurations; + participant_configurations.insert(test::random_participant_configuration(kind, 1)); + participant_configurations.insert(test::random_participant_configuration(kind, 2)); + + SpecsConfiguration specs; + specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; + specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; + + // Generate configuration + DDSRouterConfiguration configuration( + std::set>(), + std::set>(), + builtin_topics, + participant_configurations, + specs); + + // Create DDSRouter entity + DDSRouter router(configuration); + + // Start DDSRouter + router.start(); + + // Stop DDS Router + router.stop(); + + // Let DDSRouter object destroy for the next iteration + } +} + +/** + * Test that creates a DDSRouter with several Participants, one of each kind + * It creates a DDSRouter with a Participant of each kind, + * starts it with an active topic, then stops it and finally destroys it. + * + * This test will fail if it crashes. + */ +TEST(ImplementationsTest, all_implementations) +{ + // TODO: Change to warning when fastdds warning: + // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: + // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> + // Function eprosima::fastdds::rtps::UDPChannelResource::Receive + // test::LogChecker test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + { + // Set topic to active + std::set> builtin_topics = test::topic_set( + {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); + + std::set> participant_configurations; + + uint16_t participant_number = 0; + + // For each Participant Kind set it in configuration + for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) + { + // Add participant + participant_configurations.insert(test::random_participant_configuration(kind, participant_number++)); + } + + SpecsConfiguration specs; + specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; + specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; + + // Generate configuration + DDSRouterConfiguration configuration( + std::set>(), + std::set>(), + std::set>(), + participant_configurations, + specs); + + // Create DDSRouter entity + DDSRouter router(configuration); + + // Start DDSRouter + router.start(); + + // Stop DDS Router + router.stop(); + + // Let DDSRouter object destroy for the next iteration + } +} + +/** + * Test that creates a DDSRouter with 3 simple configurations, 2 of them with same id, fails + * + * There is no easy way to test this case as the yaml will be ill-formed with two keys. + * Thus, it must be implemented from a yaml in string format. + */ +TEST(ImplementationsTest, duplicated_ids) +{ + // For each Participant Kind + for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) + { + std::set> participant_configurations; + participant_configurations.insert(test::random_participant_configuration(kind, 0)); + participant_configurations.insert(test::random_participant_configuration(kind, 0)); + + SpecsConfiguration specs; + specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; + specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; + + // Generate configuration + DDSRouterConfiguration configuration( + std::set>(), + std::set>(), + std::set>(), + participant_configurations, + specs); + + // Create DDSRouter entity + ASSERT_THROW(DDSRouter router(configuration), eprosima::utils::ConfigurationException) << kind; + } +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/unittest/CMakeLists.txt b/ddspipe_participants/test/unittest/CMakeLists.txt new file mode 100644 index 000000000..a2f25d2b5 --- /dev/null +++ b/ddspipe_participants/test/unittest/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright 2021 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. + +# TODO(annapurna) redo this tests using new configuration +# add_subdirectory(configuration) +add_subdirectory(core) +add_subdirectory(dynamic) +add_subdirectory(efficiency) +add_subdirectory(types) diff --git a/ddspipe_participants/test/unittest/_configuration/CMakeLists.txt b/ddspipe_participants/test/unittest/_configuration/CMakeLists.txt new file mode 100644 index 000000000..fb3995783 --- /dev/null +++ b/ddspipe_participants/test/unittest/_configuration/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright 2021 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. + +################################ +# DDSRouter Configuration Test # +################################ + +set(TEST_NAME ValidConfigurationTest) + +set(TEST_SOURCES + ValidConfigurationTest.cpp + ) +all_library_sources("${TEST_SOURCES}") + +set(TEST_LIST + ) + +set(TEST_EXTRA_LIBRARIES + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_participants/test/unittest/_configuration/TODO.md b/ddspipe_participants/test/unittest/_configuration/TODO.md new file mode 100644 index 000000000..1b0c59243 --- /dev/null +++ b/ddspipe_participants/test/unittest/_configuration/TODO.md @@ -0,0 +1,5 @@ + +# CONFIGURATION TESTS + +These tests are developed using an old API. +They should be redo in the current API when possible. diff --git a/ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp b/ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp new file mode 100644 index 000000000..daafed6c3 --- /dev/null +++ b/ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp @@ -0,0 +1,668 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/*************** +* CONSTRUCTOR * +***************/ + +/* + * Add a topic to a list in a yaml + * If name or type is not given, that tag will not be added + */ +void add_topic_to_list_to_yaml( + RawConfiguration& yaml, + const char* list_tag, + std::string topic_name = "", + std::string topic_type = "") +{ + RawConfiguration topic; + + if (topic_name != "") + { + topic[TOPIC_NAME_TAG] = topic_name; + } + + if (topic_type != "") + { + topic[TOPIC_TYPE_NAME_TAG] = topic_type; + } + + yaml[list_tag].push_back(topic); +} + +/* + * Add a list of topics to a list in a yaml + * If name or type is not given, that tag will not be added + */ +void add_topics_to_list_to_yaml( + RawConfiguration& yaml, + const char* list_tag, + std::set> names) +{ + for (std::pair name : names) + { + add_topic_to_list_to_yaml(yaml, list_tag, name.first, name.second); + } +} + +/* + * Add a tag with empty value + */ +void add_empty_tag_to_yaml( + RawConfiguration& yaml, + std::string tag) +{ + yaml[tag] = RawConfiguration(); +} + +/* + * Check if a topic is inside a list returned by allowlist or blocklist DDSRouter methods + */ +bool topic_in_list( + std::list> list, + WildcardDdsFilterTopic compared_topic) +{ + for (std::shared_ptr topic : list) + { + // Check class and internal variables + if (typeid(*topic) == typeid(compared_topic) && + compared_topic == *topic) + { + return true; + } + } + return false; +} + +/* + * Check if a topic is inside a list returned by real_topics DDSRouter methods + */ +bool topic_in_real_list( + std::set list, + DistributedTopic compared_topic) +{ + for (DistributedTopic topic : list) + { + // Check class and internal variables + if (typeid(topic) == typeid(compared_topic) && + compared_topic == topic) + { + return true; + } + } + return false; +} + +/* + * Random Real topic names to test different configurations + */ +std::set> random_real_topic_names() +{ + return + { + {"TopicName1", "TopicType1"}, + {"TopicName2", "TopicType2"}, + {"TopicName3", "TopicType3"}, + + {"rt/chatter", "std::str::main::other_namespace"}, + + {"real/rare_topic.name", "real/rare_topic.type"}, + }; +} + +/* + * Random Non Valid topics + */ +std::set> random_non_valid_topic_names() +{ + return + { + {"", ""}, + {"", "*"}, + }; +} + +/* + * Random Non Real topic names to test different configurations + */ +std::set> random_filter_topic_names() +{ + return + { + {"rt/chatter", "*"}, + {"*", "std::str"}, + + {"rt/chatter", "std::str*"}, + {"rt/chatter/*", "std::str"}, + {"rt/chatter/*", "std::str*"}, + + {"rt/chatter", "*::std::str"}, + {"*/rt/chatter", "std::str"}, + {"*/rt/chatter", "*::std::str"}, + + {"rt/chatter", "*::std::str*"}, + {"*/rt/chatter/*", "std::str"}, + {"*/rt/chatter/*", "*::std::str*"}, + + {"rt/chatter", ""}, + {"*/rt/chatter/*", ""}, + }; +} + +/* + * Unioin of real and non real topic names + */ +std::set> random_topic_names() +{ + std::set> all_topics; + + std::set> real_topics = random_real_topic_names(); + std::set> abs_topics = random_filter_topic_names(); + std::set_union( + real_topics.begin(), real_topics.end(), + abs_topics.begin(), abs_topics.end(), + std::inserter(all_topics, all_topics.begin())); + + std::set> non_valid_topics = random_non_valid_topic_names(); + all_topics.insert(non_valid_topics.begin(), non_valid_topics.end()); + + return all_topics; +} + +/* + * Number of valid topics in random_topic_names() + */ +size_t random_topic_names_number_valid_topics() +{ + return random_real_topic_names().size() + random_filter_topic_names().size(); +} + +/* + * Random participant id + * + * TODO: create really random names + */ +std::string random_participant_name( + uint16_t seed) +{ + return std::string("PartName_") + std::to_string(seed); +} + +/* + * Random participant kind + * + * WARNING: the max_types_available must be updated with each new type added + */ +ParticipantKind random_participant_kind( + uint16_t seed = 0) +{ + // Avoid Invalid type + return ALL_VALID_PARTICIPANT_KINDS[seed % ALL_VALID_PARTICIPANT_KINDS.size()]; +} + +/* + * Random participant configuration + * + * TODO: create really random configurations + */ +RawConfiguration random_participant_configuration( + uint16_t seed) +{ + RawConfiguration config; + + for (int i = (seed); i > 0; i--) + { + std::string tag("tag" + std::to_string(i)); + + if (i % 4 == 0) + { + // Each 4 tags add an array + config[tag].push_back("value1"); + config[tag].push_back("value2"); + } + else if (i % 2 == 0) + { + // Each 4 tags add a map + RawConfiguration sub_map; + sub_map["x"] = "y"; + sub_map["a"] = "b"; + config[tag] = sub_map; + } + else + { + // The rest are direct values + config[tag] = "Random value"; + } + } + + config[PARTICIPANT_KIND_TAG] = random_participant_kind().to_string(); + + return config; +} + +/** + * Test Configuration constructor to check it does not fail + * + * CASES: + * Empty configuration + * Random configuration + */ +TEST(ConfigurationTest, constructor) +{ + // Empty case + RawConfiguration empty_yaml; + DDSRouterConfiguration config_empty(empty_yaml); + + // Random case + RawConfiguration random_config; + random_config["RAND_TAG_1"] = "rand_val_1"; + random_config["RAND_TAG_2"] = "rand_val_2"; + random_config["RAND_TAG_3"].push_back(314); + DDSRouterConfiguration config_random(random_config); +} + +/**************************** +* PUBLIC METHODS STD CASES * +****************************/ + +/** + * Test get participants configurations + * + * CASES: + * Empty configuration + * Other tags that are not participant valid ids + * One Participant Configuration + * Many Participant Configurations + * + * TODO: Change yaml tags for their proper external tags (constexpr) + */ +TEST(ConfigurationTest, participants_configurations) +{ + { + // Empty configuration + RawConfiguration yaml1; + DDSRouterConfiguration config1(yaml1); + EXPECT_TRUE(config1.participants_configurations().empty()); + } + + { + // Other tags that are not participant valid ids + RawConfiguration yaml2; + add_topics_to_list_to_yaml(yaml2, ALLOWLIST_TAG, random_filter_topic_names()); + add_topics_to_list_to_yaml(yaml2, BLOCKLIST_TAG, random_real_topic_names()); + DDSRouterConfiguration config2(yaml2); + EXPECT_TRUE(config2.participants_configurations().empty()); + } + + { + // One Participant Configuration + RawConfiguration listening_addresses; + RawConfiguration address1; + RawConfiguration address2; + address1["ip"] = "127.0.0.1"; + address1["port"] = "31415"; + listening_addresses.push_back(address1); + address2["ip"] = "8.8.8.8"; + address2["port"] = "6666"; + listening_addresses.push_back(address2); + + RawConfiguration participant_config; + participant_config[PARTICIPANT_KIND_TAG] = random_participant_kind().to_string(); + participant_config["listening-addresses"] = listening_addresses; + + std::string participant_name_str = "wanParticipant"; + ParticipantId participant_name(participant_name_str); + RawConfiguration yaml3; + yaml3[participant_name_str] = participant_config; + + DDSRouterConfiguration config3(yaml3); + auto result3 = config3.participants_configurations(); + ASSERT_EQ(1, result3.size()); + EXPECT_EQ(participant_name, result3.front().id()); + EXPECT_EQ(ParticipantConfiguration(ParticipantId(participant_name_str), participant_config), result3.front()); + } + + { + // Many Participant Configurations + uint16_t participants_num = 10; + RawConfiguration yaml4; + for (int i = 0; i < participants_num; i++) + { + yaml4[random_participant_name(i)] = random_participant_configuration(i); + } + DDSRouterConfiguration config4(yaml4); + auto result4 = config4.participants_configurations(); + ASSERT_EQ(result4.size(), participants_num); + + // For every participant in participants_configurations, check that the id is inside the actual ids stored + // TODO: check the configurations are actually the same, implement yaml compare + for (int i = 0; i < participants_num; i++) + { + ParticipantId expected_id(random_participant_name(i)); + bool in_configurations = false; + for (auto part_config: result4) + { + // They may not be sorted, so it must be checked that this is the actual participant config + // it is being tested + if (part_config.id() == expected_id) + { + in_configurations = true; + break; + } + } + ASSERT_TRUE(in_configurations); + } + } +} + +/** + * Test get real topics from allowlist + * + * CASES: + * Empty configuration + * Empty allowlist + * Allowlist with only non Real topics + * Allowlist with only Real topics + * Allowlist with random topics + */ +TEST(ConfigurationTest, real_topics) +{ + // Empty configuration + RawConfiguration yaml1; + DDSRouterConfiguration config1(yaml1); + EXPECT_TRUE(config1.real_topics().empty()); + + // Empty allowlist + RawConfiguration yaml2; + add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic1", "type1"); + add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic2", "type2"); + DDSRouterConfiguration config2(yaml2); + EXPECT_TRUE(config2.real_topics().empty()); + + // Allowlist with only non Real topics + RawConfiguration yaml3; + add_topics_to_list_to_yaml(yaml3, ALLOWLIST_TAG, random_filter_topic_names()); + DDSRouterConfiguration config3(yaml3); + EXPECT_TRUE(config3.real_topics().empty()); + + // Allowlist with only Real topics + RawConfiguration yaml4; + add_topics_to_list_to_yaml(yaml4, ALLOWLIST_TAG, random_real_topic_names()); + DDSRouterConfiguration config4(yaml4); + auto result4 = config4.real_topics(); + EXPECT_FALSE(result4.empty()); + for (auto random_topic : random_real_topic_names()) + { + DistributedTopic topic(random_topic.first, random_topic.second); + EXPECT_TRUE(topic_in_real_list(result4, topic)); + } + + // Allowlist with random topics + RawConfiguration yaml5; + add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_topic_names()); + DDSRouterConfiguration config5(yaml5); + auto result5 = config5.real_topics(); + EXPECT_FALSE(result5.empty()); + + uint16_t real_topics = 0; + for (auto random_topic : random_topic_names()) + { + bool real_topic = DistributedTopic::is_valid_dds_topic(random_topic.first, random_topic.second); + + if (real_topic) + { + ++real_topics; + DistributedTopic topic(random_topic.first, random_topic.second); + EXPECT_TRUE(topic_in_real_list(result5, topic)) << topic; + } + } + EXPECT_EQ(real_topics, result5.size()); +} + +/********************************* +* PUBLIC METHODS SPECIFIC CASES * +*********************************/ + +/** + * Test get allowlist with wildcards from yaml + * + * TODO: when regex is implemented, create a common test case + * + * CASES: + * Empty configuration + * Empty allowlist + * Allowlist with some examples + * Allowlist with random topics + * Allowlist and blocklist with random topics + */ +TEST(ConfigurationTest, allowlist_wildcard) +{ + // Empty configuration + RawConfiguration yaml1; + DDSRouterConfiguration config1(yaml1); + EXPECT_TRUE(config1.allowlist().empty()); + + // Empty allowlist + RawConfiguration yaml2; + add_empty_tag_to_yaml(yaml2, ALLOWLIST_TAG); + add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic1", "type1"); + add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic2", "type2"); + DDSRouterConfiguration config2(yaml2); + EXPECT_TRUE(config2.allowlist().empty()); + + // Empty allowlist + RawConfiguration yaml3; + add_topic_to_list_to_yaml(yaml3, ALLOWLIST_TAG, "topic1", "type1"); + add_topic_to_list_to_yaml(yaml3, ALLOWLIST_TAG, "topic2*", "type2*"); + DDSRouterConfiguration config3(yaml3); + auto result3 = config3.allowlist(); + EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic1"), std::string("type1")))); + EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic2*"), std::string("type2*")))); + + // Allowlist with random topics + RawConfiguration yaml4; + add_topics_to_list_to_yaml(yaml4, ALLOWLIST_TAG, random_topic_names()); + DDSRouterConfiguration config4(yaml4); + EXPECT_EQ(config4.allowlist().size(), random_topic_names_number_valid_topics()); + + // Allowlist and blocklist with random topics + RawConfiguration yaml5; + add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_filter_topic_names()); + add_topics_to_list_to_yaml(yaml5, BLOCKLIST_TAG, random_real_topic_names()); + DDSRouterConfiguration config5(yaml5); + EXPECT_EQ(config5.allowlist().size(), random_filter_topic_names().size()); +} + +/** + * Test get blocklist with wildcards from yaml + * + * TODO: when regex is implemented, create a common test case + * + * CASES: + * Empty configuration + * Empty blocklist + * Blocklist with some examples + * Blocklist with random topics + * Blocklist and allowlist with random topics + */ +TEST(ConfigurationTest, blocklist_wildcard) +{ + // Empty configuration + RawConfiguration yaml1; + DDSRouterConfiguration config1(yaml1); + EXPECT_TRUE(config1.blocklist().empty()); + + // Empty blocklist + RawConfiguration yaml2; + add_empty_tag_to_yaml(yaml2, BLOCKLIST_TAG); + add_topic_to_list_to_yaml(yaml2, ALLOWLIST_TAG, "topic1", "type1"); + add_topic_to_list_to_yaml(yaml2, ALLOWLIST_TAG, "topic2", "type2"); + DDSRouterConfiguration config2(yaml2); + EXPECT_TRUE(config2.blocklist().empty()); + + // Empty blocklist + RawConfiguration yaml3; + add_topic_to_list_to_yaml(yaml3, BLOCKLIST_TAG, "topic1", "type1"); + add_topic_to_list_to_yaml(yaml3, BLOCKLIST_TAG, "topic2*", "type2*"); + DDSRouterConfiguration config3(yaml3); + auto result3 = config3.blocklist(); + EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic1"), std::string("type1")))); + EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic2*"), std::string("type2*")))); + + // Blocklist with random topics + RawConfiguration yaml4; + add_topics_to_list_to_yaml(yaml4, BLOCKLIST_TAG, random_topic_names()); + DDSRouterConfiguration config4(yaml4); + EXPECT_EQ(config4.blocklist().size(), random_topic_names_number_valid_topics()); + + // Blocklist and allowlist with random topics + RawConfiguration yaml5; + add_topics_to_list_to_yaml(yaml5, BLOCKLIST_TAG, random_filter_topic_names()); + add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_real_topic_names()); + DDSRouterConfiguration config5(yaml5); + EXPECT_EQ(config5.blocklist().size(), random_filter_topic_names().size()); +} + +/** + * Test get blocklist with wildcards from yaml + * + * TODO: when regex is implemented, create a common test case + */ +TEST(ConfigurationTest, allowlist_and_blocklist) +{ + RawConfiguration yaml; + add_topics_to_list_to_yaml(yaml, ALLOWLIST_TAG, random_real_topic_names()); + add_topics_to_list_to_yaml(yaml, BLOCKLIST_TAG, random_filter_topic_names()); + DDSRouterConfiguration config(yaml); + EXPECT_EQ(config.allowlist().size(), random_real_topic_names().size()); + EXPECT_EQ(config.blocklist().size(), random_filter_topic_names().size()); +} + +/****************************** +* PUBLIC METHODS ERROR CASES * +******************************/ + +/** + * Test DDSRouterConfiguration constructor to check it does not fail + * + * CASES: + * Array as base configuration + * Scalar as base configuration + * String as base configuration + */ +TEST(ConfigurationTest, constructor_fail) +{ + // Array case + RawConfiguration array_config; + array_config.push_back("rand_val_1"); + array_config.push_back("rand_val_2"); + EXPECT_THROW(DDSRouterConfiguration dc(array_config), utils::ConfigurationException); + + // Scalar case + RawConfiguration scalar_config; + scalar_config = 42; + EXPECT_THROW(DDSRouterConfiguration dc(scalar_config), utils::ConfigurationException); + + // Scalar case + RawConfiguration string_config; + string_config = "non_valid_config"; + EXPECT_THROW(DDSRouterConfiguration dc(string_config), utils::ConfigurationException); +} + +/** + * Test get participants configurations negative cases + */ +TEST(ConfigurationTest, participants_configurations_fail) +{ + // There is currently no way to induce an error when getting participant configurations + ASSERT_TRUE(true); +} + +/** + * Test get real topics from allowlist negative cases + * + * CASES: + * Map instead of array in topics + */ +TEST(ConfigurationTest, real_topics_fail) +{ + // Map instead of array in allowlist + RawConfiguration map_config; + map_config["key1"] = "value1"; + RawConfiguration yaml1; + yaml1[ALLOWLIST_TAG] = map_config; + DDSRouterConfiguration dc(yaml1); + EXPECT_THROW(dc.real_topics(), utils::ConfigurationException); +} + +/** + * Test get allowlist with wildcards from yaml negative cases + * + * TODO: when regex is implemented, create a common test case + * + * CASES: + * Map instead of array in topics + */ +TEST(ConfigurationTest, allowlist_wildcard_fail) +{ + // Map instead of array in allowlist + RawConfiguration map_config; + map_config["key1"] = "value1"; + RawConfiguration yaml1; + yaml1[ALLOWLIST_TAG] = map_config; + DDSRouterConfiguration dc(yaml1); + EXPECT_THROW(dc.allowlist(), utils::ConfigurationException); +} + +/** + * Test get blocklist with wildcards from yaml negative cases + * + * TODO: when regex is implemented, create a common test case + * + * CASES: + * Map instead of array in topics + */ +TEST(ConfigurationTest, blocklist_wildcard_fail) +{ + // Map instead of array in blocklist + RawConfiguration map_config; + map_config["key1"] = "value1"; + RawConfiguration yaml1; + yaml1[BLOCKLIST_TAG] = map_config; + DDSRouterConfiguration dc(yaml1); + EXPECT_THROW(dc.blocklist(), utils::ConfigurationException); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_participants/test/CMakeLists.txt b/ddspipe_participants/test/unittest/core/CMakeLists.txt similarity index 84% rename from ddsrouter_participants/test/CMakeLists.txt rename to ddspipe_participants/test/unittest/core/CMakeLists.txt index 864442e5f..8d9fde3f3 100644 --- a/ddsrouter_participants/test/CMakeLists.txt +++ b/ddspipe_participants/test/unittest/core/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# Copyright 2021 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. @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO add tests +add_subdirectory(participants_database) diff --git a/ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt b/ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt new file mode 100644 index 000000000..bf91b8503 --- /dev/null +++ b/ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright 2021 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. + +######################### +# Participants Database # +######################### + +set(TEST_NAME ParticipantsDatabaseTest) + +set(TEST_SOURCES + ParticipantsDatabaseTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantsDatabase.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participants/reader/auxiliar/BlankReader.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/participants/writer/auxiliar/BlankWriter.cpp + ) +all_header_sources("${TEST_SOURCES}") + +set(TEST_LIST + add_participant + empty + get_participant + get_participants_ids + get_participants_map + pop + size + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp b/ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp similarity index 97% rename from ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp rename to ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp index 97d97a073..34ec3b6b5 100644 --- a/ddsrouter_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp +++ b/ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp @@ -18,17 +18,17 @@ #include #include -#include +#include #include -#include +#include using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace test { /** @@ -76,8 +76,8 @@ class ParticipantsDatabase : public eprosima::ddsrouter::core::ParticipantsDatab }; } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ /********************* diff --git a/ddspipe_participants/test/unittest/dynamic/CMakeLists.txt b/ddspipe_participants/test/unittest/dynamic/CMakeLists.txt new file mode 100644 index 000000000..1175745b3 --- /dev/null +++ b/ddspipe_participants/test/unittest/dynamic/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2021 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. + +add_subdirectory(allowed_topic_list) +add_subdirectory(discovery_database) diff --git a/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp b/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp new file mode 100644 index 000000000..7bae70698 --- /dev/null +++ b/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp @@ -0,0 +1,502 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +using pair_topic_type = std::pair; + +/****************** +* FILTER METHODS * +******************/ + +/* + * Add a topic to a list + * + * TODO: Add regex when implemented + */ +void add_topic_to_list( + std::set>& list, + pair_topic_type topic_name, + bool wildcard = true) +{ + if (wildcard) + { + auto new_topic = std::make_shared(); + new_topic->topic_name = topic_name.first; + new_topic->type_name = topic_name.second; + + list.insert(new_topic); + } +} + +/* + * Add several topic to a list + * + * TODO: Add regex when implemented + */ +void add_topics_to_list( + std::set>& list, + std::vector topic_names, + bool wildcard = true) +{ + if (wildcard) + { + for (pair_topic_type topic_name : topic_names) + { + auto new_topic = std::make_shared(); + new_topic->topic_name = topic_name.first; + new_topic->type_name = topic_name.second; + + list.insert(new_topic); + } + } +} + +/* + * Create an AllowedTopicList object with the allowlist and blocklist given by argument + * Check that all topics in real_topics_positive are allowed by the AllowedTopicList + * Check that all topics in real_topics_negative are not allowed by the AllowedTopicList + */ +void generic_test( + const std::vector& allowlist_topics, + const std::vector& blocklist_topics, + const std::vector& real_topics_positive, + const std::vector& real_topics_negative) +{ + // Create AllowedTopicList object + std::set> allowlist; + std::set> blocklist; + + add_topics_to_list(allowlist, allowlist_topics); + add_topics_to_list(blocklist, blocklist_topics); + + AllowedTopicList atl(allowlist, blocklist); + + // Test positive cases + for (pair_topic_type topic_name : real_topics_positive) + { + DistributedTopic topic(topic_name.first, topic_name.second); + ASSERT_TRUE(atl.is_topic_allowed(topic)); + } + + // Test negative cases + for (pair_topic_type topic_name : real_topics_negative) + { + DistributedTopic topic(topic_name.first, topic_name.second); + ASSERT_FALSE(atl.is_topic_allowed(topic)); + } +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using default constructor + */ +TEST(AllowedTopicListTest, is_topic_allowed__default_constructor) +{ + AllowedTopicList atl; + + std::vector real_topics = + { + {"topic1", "type1"}, + {"topic2", "type2"}, + {"HelloWorldTopic", "HelloWorld"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + for (pair_topic_type topic_name : real_topics) + { + DistributedTopic topic(topic_name.first, topic_name.second); + + ASSERT_TRUE(atl.is_topic_allowed(topic)); + } +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using empty lists + */ +TEST(AllowedTopicListTest, is_topic_allowed__empty_list) +{ + std::vector allowlist_topics; + std::vector blocklist_topics; + std::vector real_topics_negative; + + std::vector real_topics_positive = + { + {"topic1", "type1"}, + {"topic2", "type2"}, + {"HelloWorldTopic", "HelloWorld"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using simple blocklist: only with real topics + */ +TEST(AllowedTopicListTest, is_topic_allowed__simple_blocklist) +{ + std::vector allowlist_topics; + + std::vector blocklist_topics = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + std::vector real_topics_positive = + { + {"topic2", "type2"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + std::vector real_topics_negative = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using complex blocklist: with wildcards that superpose + */ +TEST(AllowedTopicListTest, is_topic_allowed__complex_blocklist) +{ + std::vector allowlist_topics; + + std::vector blocklist_topics = + { + {"topic1", "*"}, + {"*", "HelloWorld"}, + {"rt/chatter*", "std::*"}, + }; + + std::vector real_topics_positive = + { + {"topic2", "type2"}, + {"rt/topic_info", "std::std_msgs::string"}, + {"rt/chatter/pub", "std_type"}, + }; + + std::vector real_topics_negative = + { + {"topic1", "type1"}, + {"topic1", "type2"}, + {"HelloWorldTopic", "HelloWorld"}, + {"rt/chatter", "std::std_msgs::string"}, + {"rt/chatter/pub", "std::type"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using simple allowlist: only with real topics + */ +TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist) +{ + std::vector blocklist_topics; + + std::vector allowlist_topics = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + std::vector real_topics_positive = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + std::vector real_topics_negative = + { + {"topic1", "type1_"}, + {"topic1_", "type1"}, + {"topic2", "type2"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using complex allowlist: with wildcards that superpose + */ +TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist) +{ + std::vector blocklist_topics; + + std::vector allowlist_topics = + { + {"topic1", "*"}, + {"*", "HelloWorld"}, + {"rt/chatter*", "std::*"}, + }; + + std::vector real_topics_positive = + { + {"topic1", "type1"}, + {"topic1", "type2"}, + {"HelloWorldTopic", "HelloWorld"}, + {"OtherTopic", "HelloWorld"}, + {"rt/chatter", "std::std_msgs::string"}, + {"rt/chatter/pub", "std::string"}, + }; + + std::vector real_topics_negative = + { + {"topic2", "type1"}, + {"topic2", "type2"}, + {"HelloWorldTopic", "HelloWorldType"}, + {"rt/pub", "std::std_msgs::string"}, + {"rt/chatter", "std_type"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using simple allowlist and simple blocklist: only with real topics + * Lists do not superpose to each other + */ +TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist) +{ + std::vector allowlist_topics = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + std::vector blocklist_topics = + { + {"topic2", "type2"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + std::vector real_topics_positive = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + std::vector real_topics_negative = + { + {"topic1", "type2"}, + {"topic2", "type1"}, + {"topic2", "type2"}, + {"HelloWorldTopic", "HelloWorldType"}, + {"rt/chatter", "std::std_msgs::string"}, + {"rt/pub", "std"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using complex allowlist and complex blocklist: with wildcards that superpose + * Lists do not superpose to each other + */ +TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist) +{ + std::vector allowlist_topics = + { + {"topic1", "*"}, + {"*", "HelloWorld"}, + {"rt/pub*", "std_type::*"}, + }; + + std::vector blocklist_topics = + { + {"topic2", "*"}, + {"*", "HelloWorldType"}, + {"rt/chatter*", "std*"}, + }; + + std::vector real_topics_positive = + { + {"topic1", "type1"}, + {"topic1", "type2"}, + {"HelloWorldTopic", "HelloWorld"}, + {"OtherTopic", "HelloWorld"}, + {"rt/pub/topic", "std_type::string"}, + {"rt/pub", "std_type::string"}, + }; + + std::vector real_topics_negative = + { + {"topic2", "type1"}, + {"topic2", "type2"}, + {"HelloWorldTopic", "HelloWorldType"}, + {"OtherTopic", "HelloWorldType"}, + {"rt/chatter", "std::std_msgs::string"}, + {"rt/chatter/pub", "std"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using simple allowlist and simple blocklist: only with real topics + * Blocklist has topics that block the allowlist ones + */ +TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist_entangled) +{ + std::vector allowlist_topics = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + std::vector blocklist_topics = + { + {"topic2", "type2"}, + {"rt/chatter", "std::std_msgs::string"}, + }; + + std::vector real_topics_positive = + { + {"topic1", "type1"}, + {"HelloWorldTopic", "HelloWorld"}, + }; + + std::vector real_topics_negative = + { + {"topic1", "type2"}, + {"topic2", "type1"}, + {"topic2", "type2"}, + {"HelloWorldTopic", "HelloWorldType"}, + {"rt/chatter", "std::std_msgs::string"}, + {"rt/pub", "std"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +/** + * Test \c AllowedTopicList \c is_topic_allowed method + * + * Case using complex allowlist and complex blocklist: with wildcards that superpose + * Blocklist has topics that block the allowlist ones + */ +TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist_entangled) +{ + std::vector allowlist_topics = + { + {"topic1", "*"}, + {"*", "HelloWorld"}, + {"rt*", "std*"}, + }; + + std::vector blocklist_topics = + { + {"topic1", "type*"}, + {"*HelloWorld", "HelloWorld"}, + {"rt/chatter*", "std_type::std_msgs*"}, + }; + + std::vector real_topics_positive = + { + {"topic1", "wtype1"}, + {"topic1", "wtype2"}, + {"HelloWorldTopic", "HelloWorld"}, + {"OtherTopic", "HelloWorld"}, + {"rt/pub", "std_type::std_msgs::string"}, + {"rt/chatter", "std::string"}, + }; + + std::vector real_topics_negative = + { + {"topic1", "type1"}, + {"topic1", "type2"}, + {"TopicHelloWorld", "HelloWorld"}, + {"OtherHelloWorld", "HelloWorld"}, + {"rt/chatter", "std_type::std_msgs::string"}, + {"rt/chatter/pub", "std_type::std_msgs::string"}, + {"chatter", "std::std_msgs::int"}, + }; + + generic_test( + allowlist_topics, + blocklist_topics, + real_topics_positive, + real_topics_negative); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt b/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt new file mode 100644 index 000000000..a145292df --- /dev/null +++ b/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright 2021 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. + +set(TEST_NAME AllowedTopicListTest) + +set(TEST_SOURCES + AllowedTopicListTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic/AllowedTopicList.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp + ) +all_header_sources("${TEST_SOURCES}") + +set(TEST_LIST + is_topic_allowed__default_constructor + is_topic_allowed__empty_list + is_topic_allowed__simple_blocklist + is_topic_allowed__complex_blocklist + is_topic_allowed__simple_allowlist + is_topic_allowed__complex_allowlist + is_topic_allowed__simple_allowlist_and_blocklist + is_topic_allowed__complex_allowlist_and_blocklist + is_topic_allowed__simple_allowlist_and_blocklist_entangled + is_topic_allowed__complex_allowlist_and_blocklist_entangled + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt b/ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt new file mode 100644 index 000000000..ebcac32bc --- /dev/null +++ b/ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright 2021 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. + +###################### +# Discovery Database # +###################### + +set(TEST_NAME DiscoveryDatabaseTest) + +set(TEST_SOURCES + DiscoveryDatabaseTest.cpp + ) +all_library_sources("${TEST_SOURCES}") # Add all requirements for use test_utils + +set(TEST_LIST + topic_exists + endpoint_exists + add_endpoint + update_endpoint + erase_endpoint + get_endpoint + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp b/ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp new file mode 100644 index 000000000..14fc05046 --- /dev/null +++ b/ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp @@ -0,0 +1,250 @@ +// Copyright 2021 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. + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace eprosima::ddsrouter::test; +using namespace eprosima::utils; +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace test { + +/** + * This class is used to expose protected methods of the parent class + * so they can be tested. + */ +class DiscoveryDatabase : public eprosima::ddsrouter::core::DiscoveryDatabase +{ +public: + + DiscoveryDatabase() + : eprosima::ddsrouter::core::DiscoveryDatabase() + { + start(); + } + + bool add_endpoint_protected( + const Endpoint& new_endpoint) + { + return add_endpoint_(new_endpoint); + } + + bool update_endpoint_protected( + const Endpoint& new_endpoint) + { + return update_endpoint_(new_endpoint); + } + + ReturnCode erase_endpoint_protected( + const Endpoint& endpoint_to_erase) + { + return erase_endpoint_(endpoint_to_erase); + } + +}; + +} /* namespace test */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ + +/** + * Test \c DiscoveryDatabase \c topic_exists method + * + * CASES: + * Topic not present in database + * Topic present in database + */ +TEST(DiscoveryDatabaseTest, topic_exists) +{ + test::DiscoveryDatabase discovery_database; + Guid guid_1 = random_guid(1); + Guid guid_2 = random_guid(2); + DistributedTopic topic("test", "test"); + Endpoint endpoint_1(EndpointKind::reader, guid_1, topic); + Endpoint endpoint_2(EndpointKind::reader, guid_2, topic); + + ASSERT_FALSE(discovery_database.topic_exists(topic)); + discovery_database.add_endpoint_protected(endpoint_1); + ASSERT_TRUE(discovery_database.topic_exists(topic)); + discovery_database.add_endpoint_protected(endpoint_2); + ASSERT_TRUE(discovery_database.topic_exists(topic)); + discovery_database.erase_endpoint_protected(endpoint_1); + ASSERT_TRUE(discovery_database.topic_exists(topic)); + discovery_database.erase_endpoint_protected(endpoint_2); + ASSERT_FALSE(discovery_database.topic_exists(topic)); +} + +/** + * Test \c DiscoveryDatabase \c endpoint_exists method + * + * CASES: + * Endpoint not present in database + * Endpoint present in database + */ +TEST(DiscoveryDatabaseTest, endpoint_exists) +{ + test::DiscoveryDatabase discovery_database; + Guid guid; + DistributedTopic topic("test", "test"); + Endpoint endpoint(EndpointKind::reader, guid, topic); + + ASSERT_FALSE(discovery_database.endpoint_exists(guid)); + discovery_database.add_endpoint_protected(endpoint); + ASSERT_TRUE(discovery_database.endpoint_exists(guid)); + discovery_database.erase_endpoint_protected(endpoint); + ASSERT_FALSE(discovery_database.endpoint_exists(guid)); +} + +/** + * Test \c DiscoveryDatabase \c add_endpoint method + * + * CASES: + * Endpoint to insert not present + * Endpoint to insert already present and active + * Endpoint to insert already present but inactive + */ +TEST(DiscoveryDatabaseTest, add_endpoint) +{ + test::DiscoveryDatabase discovery_database; + DistributedTopic topic("original", "original"); + // Create active endpoint + Guid active_guid = random_guid(1); + Endpoint active_endpoint(EndpointKind::reader, active_guid, topic); + // Create inactive endpoint + Guid inactive_guid = random_guid(2); + Endpoint inactive_endpoint(EndpointKind::reader, inactive_guid, topic); + inactive_endpoint.active(false); + + // Insert endpoints + ASSERT_TRUE(discovery_database.add_endpoint_protected(active_endpoint)); + ASSERT_EQ(discovery_database.get_endpoint(active_guid), active_endpoint); + ASSERT_TRUE(discovery_database.add_endpoint_protected(inactive_endpoint)); + ASSERT_EQ(discovery_database.get_endpoint(inactive_guid), inactive_endpoint); + + // Add new endpoint with same guid as already stored active endpoint + // Should throw \c InconsistencyException + DistributedTopic new_topic("new", "new"); + Endpoint active_new_endpoint(EndpointKind::reader, active_guid, new_topic); + ASSERT_THROW(discovery_database.add_endpoint_protected(active_new_endpoint), InconsistencyException); + + // Add new endpoint with same guid as already stored inactive endpoint + // Should update entry + Endpoint inactive_new_endpoint(EndpointKind::reader, inactive_guid, new_topic); + ASSERT_TRUE(discovery_database.add_endpoint_protected(inactive_new_endpoint)); + ASSERT_EQ(discovery_database.get_endpoint(inactive_guid), inactive_new_endpoint); +} + +/** + * Test \c DiscoveryDatabase \c update_endpoint method + * + * CASES: + * Endpoint to be updated not present in database + * Endpoint to be updated present in database + */ +TEST(DiscoveryDatabaseTest, update_endpoint) +{ + test::DiscoveryDatabase discovery_database; + Guid guid = random_guid(1); + DistributedTopic topic("original", "original"); + Endpoint endpoint(EndpointKind::reader, guid, topic); + DistributedTopic new_topic("new", "new"); + Endpoint new_endpoint(EndpointKind::reader, guid, new_topic); + // Endpoint to be updated not yet inserted + ASSERT_THROW(discovery_database.update_endpoint_protected(new_endpoint), InconsistencyException); + + // Insert endpoint + ASSERT_TRUE(discovery_database.add_endpoint_protected(endpoint)); + ASSERT_TRUE(discovery_database.topic_exists(topic)); + ASSERT_FALSE(discovery_database.topic_exists(new_topic)); + ASSERT_EQ(discovery_database.get_endpoint(guid), endpoint); + + // Update endpoint + ASSERT_TRUE(discovery_database.update_endpoint_protected(new_endpoint)); + ASSERT_FALSE(discovery_database.topic_exists(topic)); + ASSERT_TRUE(discovery_database.topic_exists(new_topic)); + ASSERT_EQ(discovery_database.get_endpoint(guid), new_endpoint); +} + +/** + * Test \c DiscoveryDatabase \c erase_endpoint method + * + * CASES: + * Endpoint to erase not present in database + * Endpoint to erase present in database + */ +TEST(DiscoveryDatabaseTest, erase_endpoint) +{ + test::DiscoveryDatabase discovery_database; + Guid guid = random_guid(1); + DistributedTopic topic("test", "test"); + Endpoint endpoint(EndpointKind::reader, guid, topic); + + // Endpoint to erase not yet inserted + ASSERT_THROW(discovery_database.erase_endpoint_protected(endpoint), InconsistencyException); + + // Insert endpoint + discovery_database.add_endpoint_protected(endpoint); + ASSERT_TRUE(discovery_database.endpoint_exists(guid)); + + // Erase endpoint + ASSERT_EQ(discovery_database.erase_endpoint_protected(endpoint), ReturnCode::RETCODE_OK); + ASSERT_FALSE(discovery_database.endpoint_exists(guid)); +} + +/** + * Test \c DiscoveryDatabase \c get_endpoint method + * + * CASES: + * Endpoint to retrieve not present in database + * Endpoint to retrieve present in database + */ +TEST(DiscoveryDatabaseTest, get_endpoint) +{ + test::DiscoveryDatabase discovery_database; + Guid guid = random_guid(1); + DistributedTopic topic("test", "test"); + Endpoint endpoint(EndpointKind::reader, guid, topic); + + // Try to fetch a not stored endpoint + ASSERT_FALSE(discovery_database.endpoint_exists(guid)); + ASSERT_THROW(discovery_database.get_endpoint(guid).kind(), InconsistencyException); + + // Insert and get endpoint + discovery_database.add_endpoint_protected(endpoint); + ASSERT_TRUE(discovery_database.endpoint_exists(guid)); + ASSERT_EQ(discovery_database.get_endpoint(guid), endpoint); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_core/test/unittest/efficiency/CMakeLists.txt b/ddspipe_participants/test/unittest/efficiency/CMakeLists.txt similarity index 100% rename from ddsrouter_core/test/unittest/efficiency/CMakeLists.txt rename to ddspipe_participants/test/unittest/efficiency/CMakeLists.txt diff --git a/ddsrouter_core/test/unittest/efficiency/FastPayloadPoolTest.cpp b/ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp similarity index 97% rename from ddsrouter_core/test/unittest/efficiency/FastPayloadPoolTest.cpp rename to ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp index 435daaf49..497878c7c 100644 --- a/ddsrouter_core/test/unittest/efficiency/FastPayloadPoolTest.cpp +++ b/ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::core; @@ -31,8 +31,8 @@ const constexpr unsigned int TEST_NUMBER = 5; const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace test { /** @@ -62,8 +62,8 @@ class MockFastPayloadPool : public FastPayloadPool }; } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ /* diff --git a/ddsrouter_core/test/unittest/efficiency/MapPayloadPoolTest.cpp b/ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp similarity index 98% rename from ddsrouter_core/test/unittest/efficiency/MapPayloadPoolTest.cpp rename to ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp index 1afc961fa..2815c2f26 100644 --- a/ddsrouter_core/test/unittest/efficiency/MapPayloadPoolTest.cpp +++ b/ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::core; @@ -31,8 +31,8 @@ const constexpr unsigned int TEST_NUMBER = 5; const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace test { /** @@ -68,8 +68,8 @@ class MockMapPayloadPool : public MapPayloadPool }; } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ /* diff --git a/ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp b/ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp similarity index 99% rename from ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp rename to ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp index ca1bdb519..9ca790045 100644 --- a/ddsrouter_core/test/unittest/efficiency/PayloadPoolTest.cpp +++ b/ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp @@ -62,8 +62,8 @@ void PrintTo( } /* namespace eprosima */ namespace eprosima { -namespace ddsrouter { -namespace core { +namespace ddspipe { +namespace participants { namespace test { /** @@ -109,8 +109,8 @@ class MockPayloadPool : public PayloadPool }; } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ +} /* namespace participants */ +} /* namespace ddspipe */ } /* namespace eprosima */ /** diff --git a/ddspipe_participants/test/unittest/types/CMakeLists.txt b/ddspipe_participants/test/unittest/types/CMakeLists.txt new file mode 100644 index 000000000..6fbb0b168 --- /dev/null +++ b/ddspipe_participants/test/unittest/types/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2021 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. + +add_subdirectory(endpoint) +add_subdirectory(topic) diff --git a/ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt b/ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt new file mode 100644 index 000000000..927ffbf5d --- /dev/null +++ b/ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt @@ -0,0 +1,86 @@ +# Copyright 2021 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. + +######## +# GUID # +######## + +set(TEST_NAME GuidTest) + +set(TEST_SOURCES + GuidTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp + ) + +set(TEST_LIST + is_valid + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) + +############ +# Endpoint # +############ + +set(TEST_NAME EndpointTest) + +set(TEST_SOURCES + EndpointTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/endpoint/Endpoint.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/SpecificEndpointQoS.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp + ) + +set(TEST_LIST + constructor + kind_getter + guid_getter + qos_getter + topic_getter + active_getter + active_setter + is_writer + is_reader + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp b/ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp new file mode 100644 index 000000000..70bcd0a50 --- /dev/null +++ b/ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp @@ -0,0 +1,343 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include +#include + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +// Get a random TopicQoS configuration +TopicQoS random_qos( + uint16_t seed = 0) +{ + TopicQoS qos; + + if (seed % 2) + { + qos.reliability_qos = ReliabilityKind::BEST_EFFORT; + } + else + { + qos.reliability_qos = ReliabilityKind::RELIABLE; + } + + switch ((seed / 2) % 4) + { + case 0: + qos.durability_qos = DurabilityKind::VOLATILE; + break; + + case 1: + qos.durability_qos = DurabilityKind::TRANSIENT_LOCAL; + break; + + case 2: + qos.durability_qos = DurabilityKind::TRANSIENT; + break; + + case 3: + qos.durability_qos = DurabilityKind::PERSISTENT; + break; + + default: + break; + } + + return qos; +} + +// Get a random topic name +DistributedTopic random_topic( + uint16_t seed = 0) +{ + return DistributedTopic("TopicName_" + std::to_string(seed), "TopicType_" + std::to_string(seed), false, random_qos(seed)); +} + +// Get a random topic name +EndpointKind random_endpoint_kind( + uint16_t seed = 0) +{ + if (seed % 2) + { + return EndpointKind::reader; + } + else + { + return EndpointKind::writer; + } +} + +// Get a random guid +Guid random_valid_guid( + uint16_t seed = 0) +{ + eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; + std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d." + std::to_string(seed)) >> guid_prefix; + return Guid( + guid_prefix, + seed); +} + +/** + * Test \c Endpoint constructor + */ +TEST(EndpointTest, constructor) +{ + EndpointKind kind; + Guid guid; + DistributedTopic topic = random_topic(); + // TODO: add data qos + + Endpoint endpoint(kind, guid, topic); + + ASSERT_EQ(endpoint.kind(), kind); + ASSERT_EQ(endpoint.guid(), guid); + ASSERT_EQ(endpoint.topic_qos(), topic.topic_qos.get_reference()); + ASSERT_EQ(endpoint.topic(), topic); +} + +/** + * Test \c Endpoint \c kind getter method + * + * CASES: + * Writer + * Reader + */ +TEST(EndpointTest, kind_getter) +{ + Guid guid; + DistributedTopic topic = random_topic(); + + // Writer + { + Endpoint endpoint(EndpointKind::writer, guid, topic); + ASSERT_EQ(endpoint.kind(), EndpointKind::writer); + } + + // Reader + { + Endpoint endpoint(EndpointKind::reader, guid, topic); + ASSERT_EQ(endpoint.kind(), EndpointKind::reader); + } +} + +/** + * Test \c Endpoint \c guid getter method + * + * CASES: + * Default guid + * Random guids + */ +TEST(EndpointTest, guid_getter) +{ + DistributedTopic topic = random_topic(); + EndpointKind kind = random_endpoint_kind(); + + // Default guid + { + Guid guid; + Endpoint endpoint(kind, guid, topic); + ASSERT_EQ(endpoint.guid(), guid); + } + + // Random guids + { + for (uint16_t i = 0; i < 10; i++) + { + Guid guid = random_valid_guid(i); + Endpoint endpoint(kind, guid, topic); + ASSERT_EQ(endpoint.guid(), random_valid_guid(i)) << i; + } + } +} + +/** + * Test \c Endpoint \c qos getter method + * + * CASES: + * Random TopicQoS + */ +TEST(EndpointTest, qos_getter) +{ + Guid guid = random_valid_guid(); + DistributedTopic topic = random_topic(); + EndpointKind kind = random_endpoint_kind(); + + // Random guids + { + for (uint16_t i = 0; i < 8; i++) + { + Endpoint endpoint(kind, guid, topic); + ASSERT_EQ(topic.topic_qos, endpoint.topic_qos()) << i; + } + } +} + +/** + * Test \c Endpoint \c topic getter method + * + * CASES: + * Random Topics + */ +TEST(EndpointTest, topic_getter) +{ + Guid guid = random_valid_guid(); + EndpointKind kind = random_endpoint_kind(); + + // Random guids + { + for (uint16_t i = 0; i < 10u; i++) + { + DistributedTopic topic = random_topic(i); + Endpoint endpoint(kind, guid, topic); + ASSERT_EQ(endpoint.topic(), random_topic(i)) << i; + } + } +} + +/** + * Test \c Endpoint \c active getter method + * + * CASES: + * Default value + * Change to invalid + * Change to invalid and to valid + */ +TEST(EndpointTest, active_getter) +{ + Guid guid = random_valid_guid(); + DistributedTopic topic = random_topic(); + EndpointKind kind = random_endpoint_kind(); + + // Default value + { + Endpoint endpoint(kind, guid, topic); + ASSERT_TRUE(endpoint.active()); + } + + // Change to invalid + { + Endpoint endpoint(kind, guid, topic); + endpoint.active(false); + ASSERT_FALSE(endpoint.active()); + } + + // Change to invalid and to valid + { + Endpoint endpoint(kind, guid, topic); + endpoint.active(false); + endpoint.active(true); + ASSERT_TRUE(endpoint.active()); + } +} + +/** + * Test \c Endpoint \c active setter method + * + * Same test as active_setter + * CASES: + * Default value + * Change to invalid + * Change to invalid and to valid + */ +TEST(EndpointTest, active_setter) +{ + Guid guid = random_valid_guid(); + DistributedTopic topic = random_topic(); + EndpointKind kind = random_endpoint_kind(); + + // Default value + { + Endpoint endpoint(kind, guid, topic); + ASSERT_TRUE(endpoint.active()); + } + + // Change to invalid + { + Endpoint endpoint(kind, guid, topic); + endpoint.active(false); + ASSERT_FALSE(endpoint.active()); + } + + // Change to invalid and to valid + { + Endpoint endpoint(kind, guid, topic); + endpoint.active(false); + endpoint.active(true); + ASSERT_TRUE(endpoint.active()); + } +} + +/** + * Test \c Endpoint \c is_writer getter method + * + * CASES: + * Writer + * Reader + */ +TEST(EndpointTest, is_writer) +{ + Guid guid; + DistributedTopic topic = random_topic(); + + // Writer + { + Endpoint endpoint(EndpointKind::writer, guid, topic); + ASSERT_TRUE(endpoint.is_writer()); + } + + // Reader + { + Endpoint endpoint(EndpointKind::reader, guid, topic); + ASSERT_FALSE(endpoint.is_writer()); + } +} + +/** + * Test \c Endpoint \c is_reader getter method + * + * CASES: + * Writer + * Reader + */ +TEST(EndpointTest, is_reader) +{ + Guid guid; + DistributedTopic topic = random_topic(); + + // Writer + { + Endpoint endpoint(EndpointKind::writer, guid, topic); + ASSERT_FALSE(endpoint.is_reader()); + } + + // Reader + { + Endpoint endpoint(EndpointKind::reader, guid, topic); + ASSERT_TRUE(endpoint.is_reader()); + } +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp b/ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp new file mode 100644 index 000000000..0c5884add --- /dev/null +++ b/ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp @@ -0,0 +1,92 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test \c Guid \c is_valid method + * + * CASES: + * Default constructor invalid + * Unknown guid invalid + * GuidPrefix invalid + * EntityId invalid + * Constrcutor with valid value + */ +TEST(GuidTest, is_valid) +{ + // Default constructor invalid + { + Guid invalid_guid; + ASSERT_FALSE(invalid_guid.is_valid()); + } + + // Unknown guid invalid + { + Guid invalid_guid_1( + eprosima::fastrtps::rtps::GuidPrefix_t::unknown(), + eprosima::fastrtps::rtps::EntityId_t::unknown()); + ASSERT_FALSE(invalid_guid_1.is_valid()); + + Guid invalid_guid_2( + eprosima::fastrtps::rtps::GUID_t::unknown().guidPrefix, + eprosima::fastrtps::rtps::GUID_t::unknown().entityId); + ASSERT_FALSE(invalid_guid_2.is_valid()); + } + + // GuidPrefix invalid + { + Guid invalid_guid( + eprosima::fastrtps::rtps::GuidPrefix_t(), // Invalid GuidPrefix + eprosima::fastrtps::rtps::EntityId_t(1)); // Valid EntityId + ASSERT_FALSE(invalid_guid.is_valid()); + } + + // EntityId invalid + { + eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; + std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d.41") >> guid_prefix; + Guid valid_guid( + guid_prefix, // Valid GuidPrefix + eprosima::fastrtps::rtps::EntityId_t()); // Invalid EntityId + ASSERT_FALSE(valid_guid.is_valid()); + } + + // Constrcutor with valid value + { + eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; + std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d.41") >> guid_prefix; + Guid valid_guid( + guid_prefix, // Valid GuidPrefix + eprosima::fastrtps::rtps::EntityId_t(1)); // Valid EntityId + ASSERT_TRUE(valid_guid.is_valid()); + } +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/unittest/types/topic/CMakeLists.txt b/ddspipe_participants/test/unittest/types/topic/CMakeLists.txt new file mode 100644 index 000000000..1eeb42b1f --- /dev/null +++ b/ddspipe_participants/test/unittest/types/topic/CMakeLists.txt @@ -0,0 +1,109 @@ +# Copyright 2021 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. + +################### +# Topic # +################### + +set(TEST_NAME TopicTest) + +set(TEST_SOURCES + TopicTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp + ) + +set(TEST_LIST + is_valid + ) + +set(TEST_EXTRA_LIBRARIES + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) + +############# +# DistributedTopic # +############# + +set(TEST_NAME DdsTopicTest) + +set(TEST_SOURCES + DdsTopicTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp + ) + +set(TEST_LIST + is_valid_dds_topic + is_valid_dds_topic_negative + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) + +################# +# WildcardDdsFilterTopic # +################# + +set(TEST_NAME WildcardTopicTest) + +set(TEST_SOURCES + WildcardDdsFilterTopicTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp + ) + +set(TEST_LIST + matches + non_matches + + # Not supported (TODO) + # non_contains_wildcard + # contains_wildcard + ) + +set(TEST_EXTRA_LIBRARIES + $<$:iphlpapi$Shlwapi> + fastcdr + fastrtps + cpp_utils + + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp b/ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp new file mode 100644 index 000000000..4a6f610ce --- /dev/null +++ b/ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp @@ -0,0 +1,90 @@ +// Copyright 2021 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. + +#include +#include + +#include + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +using pair_topic_type = std::pair; + +/** + * Test DistributedTopic is_valid_dds_topic method for positive cases + */ +TEST(DdsTopicTest, is_valid_dds_topic) +{ + std::vector topics = { + {"topic1", "type1"}, + {"topic1", "type2"}, + {"topic2", "type1"}, + + {"rt/chatter", "std::std_msg::string"}, + + {"HelloWorldTopic", "HelloWorld"}, + }; + + for (pair_topic_type topic : topics) + { + ASSERT_TRUE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); + } +} + +/** + * Test DistributedTopic is_valid_dds_topic method for negative cases + */ +TEST(DdsTopicTest, is_valid_dds_topic_negative) +{ + std::vector topics = { + {"topic", "type*"}, + {"topic*", "type"}, + {"topic*", "type*"}, + + {"topic", "*type"}, + {"*topic", "type"}, + {"*topic", "*type"}, + + {"topic", "*type*"}, + {"*topic*", "type"}, + {"*topic*", "*type*"}, + + {"topic", "ty*pe"}, + {"top*ic", "type"}, + {"top*ic", "ty*pe"}, + + {"*", "type"}, + {"topic", "*"}, + {"*", "*"}, + + {"topic", ""}, + {"", "type"}, + {"", ""}, + // TODO add regex cases + }; + + for (pair_topic_type topic : topics) + { + ASSERT_FALSE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); + } +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/unittest/types/topic/TopicTest.cpp b/ddspipe_participants/test/unittest/types/topic/TopicTest.cpp new file mode 100644 index 000000000..4d33842c9 --- /dev/null +++ b/ddspipe_participants/test/unittest/types/topic/TopicTest.cpp @@ -0,0 +1,68 @@ +// Copyright 2021 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. + +#include +#include + +#include + +#include + +using namespace eprosima::ddsrouter; +using namespace eprosima::ddsrouter::core::types; + +/* + * Return a list of non repeated random topic names + */ +std::vector random_topic_names() +{ + return + { + {"topic1"}, + {"topic2"}, + {"topic3"}, + + {"*"}, + {"*rt"}, + {"rt*"}, + {"rt"}, + {"rt*"}, + + {"."}, + }; +} + +/** + * Test Topic constructor and std getter methods + */ +TEST(TopicTest, is_valid) +{ + eprosima::utils::Formatter __f; + + for (const std::string& topic_name : random_topic_names()) + { + Topic topic(topic_name); + ASSERT_TRUE(topic.is_valid(__f)); + } + + ASSERT_FALSE(Topic().is_valid(__f)); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp b/ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp new file mode 100644 index 000000000..9d4c3d9dd --- /dev/null +++ b/ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp @@ -0,0 +1,224 @@ +// Copyright 2022 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. + +#include +#include + +#include + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +using pair_topic_type = std::pair; + +// TODO: extend contains tests for regex topics + +/** + * Test WildcardDdsFilterTopic construct only with topic name + */ +TEST(WildcardTopicTest, topic_name_constructor) +{ + WildcardDdsFilterTopic topic1("topic1"); + WildcardDdsFilterTopic topic2; + + ASSERT_EQ(topic1, topic2); +} + +/** + * Test WildcardDdsFilterTopic contains method for positive cases + */ +TEST(WildcardTopicTest, contains_wildcard) +{ + std::vector< // Test cases + std::pair< + pair_topic_type, // Wildcard Topic + std::vector // List of accepted DdsTopics + >> test_cases = { + + {{"topic", "*"}, + {{"topic", "type"}, {"topic", "type*"}, {"topic", "*type"}, {"topic", "type1*"}}}, + + {{"topic", "type*"}, + {{"topic", "type"}, {"topic", "type1"}, {"topic", "type1*"}}}, + + {{"*", "type"}, + {{"topic", "type"}, {"*topic", "type"}, {"topic*", "type"}, {"*rt/topic", "type"}}}, + + {{"*topic", "type"}, + {{"topic", "type"}, {"std_topic", "type"}, {"*rt/topic", "type"}}}, + + {{"topic*", "type*"}, + {{"topic", "type"}}}, + }; + + for (auto test_case : test_cases) + { + // Create Wildcard topic + WildcardDdsFilterTopic wt; + wt.topic_name = test_case.first.first; + wt.type_name = test_case.first.second; + + // For every topic to test, create a FilterDdsTopic and test + for (auto real_topic_names : test_case.second) + { + WildcardDdsFilterTopic contained_topic; + contained_topic.topic_name = real_topic_names.first; + contained_topic.type_name = real_topic_names.second; + + ASSERT_TRUE(wt.contains(contained_topic)); + } + } +} + +/** + * Test WildcardDdsFilterTopic matches method for positive cases + */ +TEST(WildcardTopicTest, matches) +{ + std::vector< // Test cases + std::pair< + pair_topic_type, // Wildcard Topic + std::vector // List of accepted DdsTopics + >> test_cases = { + + {{"topic", "*"}, + {{"topic", "type"}, {"topic", "type1"}, {"topic", "type2"}}}, + + {{"topic", "type*"}, + {{"topic", "type"}, {"topic", "type1"}, {"topic", "type2"}}}, + + {{"*", "type"}, + {{"topic", "type"}, {"std_topic", "type"}, {"rt/topic", "type"}}}, + + {{"*topic", "type"}, + {{"topic", "type"}, {"std_topic", "type"}, {"rt/topic", "type"}}}, + + {{"topic", "type"}, + {{"topic", "type"}}}, + }; + + for (auto test_case : test_cases) + { + // Create Wildcard topic + WildcardDdsFilterTopic wt; + wt.topic_name = test_case.first.first; + wt.type_name = test_case.first.second; + + // For every topic to test, create a DistributedTopic and test + for (auto real_topic_names : test_case.second) + { + DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); + + ASSERT_TRUE(wt.matches(real_topic)) << "wildcard: " << wt << " ; real: " << real_topic; + } + } +} + +/** + * Test WildcardDdsFilterTopic contains method for negative cases + */ +TEST(WildcardTopicTest, non_contains_wildcard) +{ + std::vector< // Test cases + std::pair< + pair_topic_type, // Wildcard Topic + std::vector // List of accepted DdsTopics + >> test_cases = { + + {{"topic", "*"}, + {{"topic1", "type"}, {"topic*", "type"}, {"*", "type"}, {"*topic", "*"}, {"*", "*"}}}, + + {{"topic", "type*"}, + {{"topic*", "type"}, {"topic", "*type"}, {"*", "*"}}}, + + {{"*", "type"}, + {{"topic", "type1"}, {"topic", "type*"}, {"topic*", "*"}, {"*", "type*"}, {"*", "*"}}}, + + {{"*topic", "type"}, + {{"topic", "type*"}, {"topic*", "type"}, {"*", "*"}}}, + + {{"topic*", "type*"}, + {{"*topic", "type"}, {"topic", "*type"}, {"*", "*"}}}, + }; + + for (auto test_case : test_cases) + { + // Create Wildcard topic + WildcardDdsFilterTopic wt; + wt.topic_name = test_case.first.first; + wt.type_name = test_case.first.second; + + // For every topic to test, create a DistributedTopic and test + for (auto real_topic_names : test_case.second) + { + WildcardDdsFilterTopic contained_topic; + contained_topic.topic_name = real_topic_names.first; + contained_topic.type_name = real_topic_names.second; + + ASSERT_FALSE(wt.contains(contained_topic)); + } + } +} + +/** + * Test WildcardDdsFilterTopic matches method for negative cases + */ +TEST(WildcardTopicTest, non_matches) +{ + std::vector< // Test cases + std::pair< + pair_topic_type, // Wildcard Topic + std::vector // List of accepted DdsTopics + >> test_cases = { + + {{"topic", "*"}, + {{"topic1", "type"}, {"topic1", "type1"}, {"std_topic", "type1"}}}, + + {{"topic", "type*"}, + {{"topic1", "type"}, {"topic", "std::type"}, {"topic", "std::type1"}}}, + + {{"*", "type"}, + {{"topic", "type1"}, {"std_topic", "type1"}, {"topic", "std::type"}}}, + + {{"*topic", "type"}, + {{"topic", "type1"}, {"std_topic1", "type"}, {"rt/topic1", "type"}}}, + + {{"topic", "type"}, + {{"topic", "type1"}, {"topic1", "type"}, {"topic1", "type1"}, {"std_topic", "type"}}}, + }; + + for (auto test_case : test_cases) + { + // Create Wildcard topic + WildcardDdsFilterTopic wt; + wt.topic_name = test_case.first.first; + wt.type_name = test_case.first.second; + + // For every topic to test, create a DistributedTopic and test + for (auto real_topic_names : test_case.second) + { + DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); + + ASSERT_FALSE(wt.matches(real_topic)); + } + } +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddspipe_yaml/CMakeLists.txt b/ddspipe_yaml/CMakeLists.txt new file mode 100644 index 000000000..644d5c7d4 --- /dev/null +++ b/ddspipe_yaml/CMakeLists.txt @@ -0,0 +1,78 @@ +# Copyright 2022 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. + +############################################################################### +# CMake build rules for DDS Router Submodule +############################################################################### +cmake_minimum_required(VERSION 3.5) + +############################################################################### +# Find package cmake_utils +############################################################################### +# Package cmake_utils is required to get every cmake macro needed +find_package(cmake_utils REQUIRED) + +############################################################################### +# Project +############################################################################### +# Configure project by info set in project_settings.cmake +# - Load project_settings variables +# - Read version +# - Set installation paths +configure_project() + +# Call explictly project +project( + ${MODULE_NAME} + VERSION + ${MODULE_VERSION} + DESCRIPTION + ${MODULE_DESCRIPTION} + LANGUAGES + CXX +) + +############################################################################### +# C++ Project +############################################################################### +# Configure CPP project for dependencies and required flags: +# - Set CMake Build Type +# - Set C++ version +# - Set shared libraries by default +# - Find external packages and thirdparties +# - Activate Code coverage if flag CODE_COVERAGE +# - Activate Address sanitizer build if flag ASAN_BUILD +# - Activate Thread sanitizer build if flag TSAN_BUILD +# - Configure log depending on LOG_INFO flag and CMake type +configure_project_cpp() + +# Compile C++ library +compile_library( + "${PROJECT_SOURCE_DIR}/src/cpp" # Source directory + "${PROJECT_SOURCE_DIR}/include" # Include directory +) + +############################################################################### +# Test +############################################################################### +# Compile tests if CMake options requires it +compile_test_library( + "${PROJECT_SOURCE_DIR}/test" # Test directory +) + +############################################################################### +# Packaging +############################################################################### +# Install package +eprosima_packaging() diff --git a/ddspipe_yaml/README.md b/ddspipe_yaml/README.md new file mode 100644 index 000000000..eb195bc2a --- /dev/null +++ b/ddspipe_yaml/README.md @@ -0,0 +1,42 @@ +# eProsima DDS Router Yaml Module + +This library implements the required functions to translate a DDS Router configuration written in *yaml* +format into C++ source code. +It is powered by `yaml-cpp` library. + +It provides methods: + +- to create every type of object from a *yaml* node, +- to read a *yaml* file, and +- to interact with a *yaml* object using `YAML::Node` class from `yaml-cpp`. + +--- + +## Example of usage + +```cpp +// LOAD DDS ROUTER CONFIGURATION FROM FILE + +core::configuration::DDSRouterConfiguration router_configuration = + yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file("configuration.yaml"); +``` + +--- + +## Dependencies + +* `yaml-cpp` +* `cpp_utils` +* `ddsrouter_core` + + +--- + +## How to use it in your project + +Just import library `ddsrouter_yaml` into your CMake project. + +```cmake +find_package(ddsrouter_yaml) +target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_yaml) +``` diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/Yaml.hpp b/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp similarity index 79% rename from ddsrouter_yaml/include/ddsrouter_yaml/Yaml.hpp rename to ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp index 4c86b0fac..08ae3204b 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/Yaml.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp @@ -12,18 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Yaml.hpp - */ - -#ifndef _DDSROUTERYAML_YAML_HPP_ -#define _DDSROUTERYAML_YAML_HPP_ - #include namespace eprosima { -namespace ddsrouter { -namespace yaml { /** * Configuration is in dictionary format @@ -34,8 +25,4 @@ namespace yaml { */ using Yaml = YAML::Node; -} /* namespace yaml */ -} /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERYAML_YAML_HPP_ */ diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlManager.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp similarity index 72% rename from ddsrouter_yaml/include/ddsrouter_yaml/YamlManager.hpp rename to ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp index 83c050f81..b32d9d82a 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlManager.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp @@ -12,24 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file YamlManager.hpp - */ - -#ifndef _DDSROUTERYAML_YAMLMANAGER_HPP_ -#define _DDSROUTERYAML_YAMLMANAGER_HPP_ - -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { /** * Class that manages generic methods related with yaml load and yaml validation. */ -class DDSROUTER_YAML_DllAPI YamlManager +class DDSPIPE_YAML_DllAPI YamlManager { public: @@ -38,7 +31,5 @@ class DDSROUTER_YAML_DllAPI YamlManager }; } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERYAML_YAMLMANAGER_HPP_ */ diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp similarity index 95% rename from ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp rename to ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp index 679ad0e69..2226ee73d 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp @@ -12,21 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file YamlReader.hpp - */ - -#ifndef _DDSROUTERYAML_YAMLREADER_HPP_ -#define _DDSROUTERYAML_YAMLREADER_HPP_ - #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { /** @@ -98,7 +91,7 @@ using TagType = std::string; * * Every method is implemented */ -class DDSROUTER_YAML_DllAPI YamlReader +class DDSPIPE_YAML_DllAPI YamlReader { public: @@ -250,10 +243,8 @@ std::ostream& operator <<( const YamlReaderVersion& version); } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ // Include implementation template file -#include - -#endif /* _DDSROUTERYAML_YAMLREADER_HPP_ */ +#include diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp b/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp similarity index 97% rename from ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp rename to ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp index 965f527fc..4cf1013d1 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp +++ b/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp @@ -17,8 +17,6 @@ * */ -#ifndef _DDSROUTERYAML_IMPL_YAMLREADER_IPP_ -#define _DDSROUTERYAML_IMPL_YAMLREADER_IPP_ #include #include @@ -26,7 +24,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { template @@ -243,7 +241,5 @@ T YamlReader::get_enumeration_from_builder( } } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERYAML_IMPL_YAMLREADER_IPP_ */ diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/yaml_configuration_tags.hpp b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp similarity index 90% rename from ddsrouter_yaml/include/ddsrouter_yaml/yaml_configuration_tags.hpp rename to ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp index 26b8d9d61..87360fdb8 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/yaml_configuration_tags.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp @@ -12,29 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file yaml_configuration_tags.hpp - * - * This file contains constant values common for the whole project - */ - -#ifndef _DDSROUTERYAML_YAMLCONFIGURATIONTAGS_HPP_ -#define _DDSROUTERYAML_YAMLCONFIGURATIONTAGS_HPP_ - #include #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { -//! Retrieve a set with every tag used in the configuration of the DDSRouter or the Participants -std::set ddsrouter_tags() noexcept; - -//! Whether a string is a tag / key word -bool is_tag( - const std::string& str) noexcept; - // Yaml related tags constexpr const char* VERSION_TAG("version"); //! Version to parse the yaml with constexpr const char* VERSION_TAG_V_1_0("v1.0"); //! Version v1.0 @@ -117,7 +101,5 @@ constexpr const char* PARTICIPANT_KIND_TAG_V1("type"); //! Participant Kind } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTERYAML_YAMLCONFIGURATIONTAGS_HPP_ */ diff --git a/ddspipe_yaml/package.xml b/ddspipe_yaml/package.xml new file mode 100644 index 000000000..a302acf26 --- /dev/null +++ b/ddspipe_yaml/package.xml @@ -0,0 +1,34 @@ + + + + ddspipe_yaml + 1.1.0 + + *eprosima DDS Router* Yaml Module is a C++ implementation for handling events in multithreading executions as PeriodicTimers, Signals, FileWatchers, etc. + + Raul Sánchez-Mateos + Javier París + Juan López + Apache 2.0 + + https://www.eprosima.com/ + https://github.com/eProsima/DDS-Router/issues + https://github.com/eProsima/DDS-Router + + cmake + + yamlcpp + fastrtps + cpp_utils + ddspipe_core + ddspipe_participants + cmake_utils + + doxygen + + googletest-distribution + + + cmake + + diff --git a/ddspipe_yaml/project_settings.cmake b/ddspipe_yaml/project_settings.cmake new file mode 100644 index 000000000..2bbb1bd0f --- /dev/null +++ b/ddspipe_yaml/project_settings.cmake @@ -0,0 +1,35 @@ +# Copyright 2022 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. + +############################################################################### +# Set settings for project ddspipe_yaml +############################################################################### + +set(MODULE_NAME + ddspipe_yaml) + +set(MODULE_SUMMARY + "C++ library to create a DDS Router configuration from a YAML.") + +set(MODULE_FIND_PACKAGES + yaml-cpp + fastcdr + fastrtps + cpp_utils + ddspipe_core + ddspipe_participants) + +set(MODULE_DEPENDENCIES + $<$:iphlpapi$Shlwapi> + ${MODULE_FIND_PACKAGES}) diff --git a/ddsrouter_yaml/src/cpp/YamlManager.cpp b/ddspipe_yaml/src/cpp/YamlManager.cpp similarity index 90% rename from ddsrouter_yaml/src/cpp/YamlManager.cpp rename to ddspipe_yaml/src/cpp/YamlManager.cpp index 0024084ce..9c310c8b2 100644 --- a/ddsrouter_yaml/src/cpp/YamlManager.cpp +++ b/ddspipe_yaml/src/cpp/YamlManager.cpp @@ -19,11 +19,11 @@ #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { Yaml YamlManager::load_file( @@ -42,5 +42,5 @@ Yaml YamlManager::load_file( } } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp new file mode 100644 index 000000000..6bd97011a --- /dev/null +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -0,0 +1,122 @@ +// Copyright 2022 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 YamlReader.cpp + * + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { + +using namespace eprosima::ddspipe::core::types; +using namespace eprosima::ddspipe::participants::types; + +/************************ +* GENERIC * +************************/ + +bool YamlReader::is_tag_present( + const Yaml& yml, + const TagType& tag) +{ + if (!yml.IsMap() && !yml.IsNull()) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "Trying to find a tag: <" << tag << "> in a not yaml object map."); + } + + // Explicit conversion to avoid windows format warning + // This method performace is the same as only retrieving bool + return (yml[tag]) ? true : false; +} + +Yaml YamlReader::get_value_in_tag( + const Yaml& yml, + const TagType& tag) +{ + if (is_tag_present(yml, tag)) + { + return yml[tag]; + } + else + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "Required tag not found: <" << tag << ">."); + } +} + +/************************ +* STANDARD * +************************/ + +template <> +int YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version /* version */) +{ + return get_scalar(yml); +} + +template <> +unsigned int YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version /* version */) +{ + return get_scalar(yml); +} + +template <> +bool YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version /* version */) +{ + return get_scalar(yml); +} + +template <> +std::string YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version /* version */) +{ + return get_scalar(yml); +} + +} /* namespace yaml */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp new file mode 100644 index 000000000..988ab3a85 --- /dev/null +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -0,0 +1,258 @@ +// Copyright 2022 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 YamlReader.cpp + * + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { + +using namespace eprosima::ddspipe::core::types; +using namespace eprosima::ddspipe::participants::types; + +/************************ +* PARTICIPANTS * +************************/ + +////////////////////////////////// +// ParticipantConfiguration +template <> +void YamlReader::fill( + participants::ParticipantConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Id required + object.id = get(yml, PARTICIPANT_NAME_TAG, version); +} + +template <> +participants::ParticipantConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + participants::ParticipantConfiguration object; + fill(object, yml, version); + return object; +} + +////////////////////////////////// +// EchoParticipantConfiguration +template <> +void YamlReader::fill( + participants::EchoParticipantConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Parent class fill + fill(object, yml, version); + + // data optional + if (is_tag_present(yml, ECHO_DATA_TAG)) + { + object.echo_data = get(yml, ECHO_DATA_TAG, version); + } + + // discovery optional + if (is_tag_present(yml, ECHO_DISCOVERY_TAG)) + { + object.echo_discovery = get(yml, ECHO_DISCOVERY_TAG, version); + } + + // verbose optional + if (is_tag_present(yml, ECHO_VERBOSE_TAG)) + { + object.verbose = get(yml, ECHO_VERBOSE_TAG, version); + } +} + +template <> +participants::EchoParticipantConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + participants::EchoParticipantConfiguration object; + fill(object, yml, version); + return object; +} + +////////////////////////////////// +// SimpleParticipantConfiguration +template <> +void YamlReader::fill( + participants::SimpleParticipantConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Parent class fill + fill(object, yml, version); + + // Domain optional + if (is_tag_present(yml, DOMAIN_ID_TAG)) + { + object.domain = get(yml, DOMAIN_ID_TAG, version); + } +} + +template <> +participants::SimpleParticipantConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + participants::SimpleParticipantConfiguration object; + fill(object, yml, version); + return object; +} + +////////////////////////////////// +// DiscoveryServerParticipantConfiguration +template <> +void YamlReader::fill( + participants::DiscoveryServerParticipantConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Parent class fill + fill(object, yml, version); + + // Optional listening addresses + if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) + { + object.listening_addresses = YamlReader::get_set
(yml, LISTENING_ADDRESSES_TAG, version); + } + + // Optional connection addresses + if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) + { + object.connection_addresses = YamlReader::get_set( + yml, + CONNECTION_ADDRESSES_TAG, + version); + } + + // Optional TLS + if (YamlReader::is_tag_present(yml, TLS_TAG)) + { + YamlReader::fill( + object.tls_configuration, + YamlReader::get_value_in_tag(yml, TLS_TAG), + version); + } + + // NOTE: The only field that change regarding the version is the GuidPrefix. + switch (version) + { + case V_1_0: + object.discovery_server_guid_prefix = + YamlReader::get(yml, version); + break; + + default: + object.discovery_server_guid_prefix = + YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); + break; + } +} + +template <> +participants::DiscoveryServerParticipantConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + participants::DiscoveryServerParticipantConfiguration object; + fill(object, yml, version); + return object; +} + +////////////////////////////////// +// InitialPeersParticipantConfiguration +template <> +void YamlReader::fill( + participants::InitialPeersParticipantConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Parent class fill + fill(object, yml, version); + + // Optional listening addresses + if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) + { + object.listening_addresses = YamlReader::get_set
(yml, LISTENING_ADDRESSES_TAG, version); + } + + // Optional connection addresses + if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) + { + object.connection_addresses = YamlReader::get_set
( + yml, + CONNECTION_ADDRESSES_TAG, + version); + } + + // Optional TLS + if (YamlReader::is_tag_present(yml, TLS_TAG)) + { + YamlReader::fill( + object.tls_configuration, + YamlReader::get_value_in_tag(yml, TLS_TAG), + version); + } + + // Optional Repeater + if (YamlReader::is_tag_present(yml, IS_REPEATER_TAG)) + { + object.is_repeater = YamlReader::get(yml, IS_REPEATER_TAG, version); + } +} + +template <> +participants::InitialPeersParticipantConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + participants::InitialPeersParticipantConfiguration object; + fill(object, yml, version); + return object; +} + +} /* namespace yaml */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp new file mode 100644 index 000000000..9322a0124 --- /dev/null +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -0,0 +1,542 @@ +// Copyright 2022 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 YamlReader.cpp + * + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { + +using namespace eprosima::ddspipe::core::types; +using namespace eprosima::ddspipe::participants::types; + +template <> +YamlReaderVersion YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + return get_enumeration( + yml, + { + {VERSION_TAG_V_1_0, YamlReaderVersion::V_1_0}, + {VERSION_TAG_V_2_0, YamlReaderVersion::V_2_0}, + {VERSION_TAG_V_3_0, YamlReaderVersion::V_3_0}, + }); +} + +template <> +TransportProtocol YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + return get_enumeration( + yml, + { + {ADDRESS_TRANSPORT_TCP_TAG, TransportProtocol::tcp}, + {ADDRESS_TRANSPORT_UDP_TAG, TransportProtocol::udp}, + }); +} + +template <> +IpVersion YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + return get_enumeration( + yml, + { + {ADDRESS_IP_VERSION_V4_TAG, IpVersion::v4}, + {ADDRESS_IP_VERSION_V6_TAG, IpVersion::v6}, + }); +} + +template <> +PortType YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + // Domain id required + return PortType(get_scalar(yml)); +} + +template <> +DomainId YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + // Domain id required + return DomainId(get_scalar(yml)); +} + +template <> +GuidPrefix YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + // If guid exists, use it. Non mandatory. + if (is_tag_present(yml, DISCOVERY_SERVER_GUID_TAG)) + { + std::string guid = get_scalar(yml, DISCOVERY_SERVER_GUID_TAG); + return GuidPrefix(guid); + } + + // ROS DS is optional. + bool ros_id; + bool ros_id_set = is_tag_present(yml, DISCOVERY_SERVER_ID_ROS_TAG); + if (ros_id_set) + { + ros_id = get_scalar(yml, DISCOVERY_SERVER_ID_ROS_TAG); + } + + // Id is mandatory if guid is not present + uint32_t id = get_scalar(yml, DISCOVERY_SERVER_ID_TAG); + + // Create GuidPrefix + if (ros_id_set) + { + return GuidPrefix(ros_id, id); + } + else + { + return GuidPrefix(id); + } +} + +template <> +Address YamlReader::get
( + const Yaml& yml, + const YamlReaderVersion version) +{ + // Optional get IP version + IpVersion ip_version; + bool ip_version_set = is_tag_present(yml, ADDRESS_IP_VERSION_TAG); + if (ip_version_set) + { + // Get IP Version from enumeration + ip_version = get(yml, ADDRESS_IP_VERSION_TAG, version); + } + + // Optional get IP + IpType ip; + bool ip_set = is_tag_present(yml, ADDRESS_IP_TAG); + if (ip_set) + { + ip = get(yml, ADDRESS_IP_TAG, version); + } + + // Optional get Domain tag for DNS + std::string domain_name; + bool domain_name_set = is_tag_present(yml, ADDRESS_DNS_TAG); + if (domain_name_set) + { + domain_name = get_scalar(yml, ADDRESS_DNS_TAG); + } + + // If IP and domain_name set, warning that domain_name will not be used + // If only domain_name set, get DNS response + // If neither set, get default + if (ip_set && domain_name_set) + { + logWarning(ddspipe_YAML, + "Tag <" << ADDRESS_DNS_TAG << "> will not be used as <" << ADDRESS_IP_TAG << "> is set."); + domain_name_set = false; + } + else if (!ip_set && !domain_name_set) + { + throw eprosima::utils::ConfigurationException(utils::Formatter() << + "Address requires to specify <" << ADDRESS_IP_TAG << "> or <" << ADDRESS_DNS_TAG << ">."); + } + + // Optional get port + PortType port; + bool port_set = is_tag_present(yml, ADDRESS_PORT_TAG); + if (port_set) + { + port = get(yml, ADDRESS_PORT_TAG, version); + } + else + { + port = Address::default_port(); + } + + // WARNING: This adds logic to the parse of the entity, + // This may not be the best place to do so. In the future move this logic to the Address class. + + // Optional get external port + // If it is not set, same as internal port is used + PortType external_port; + bool external_port_set = is_tag_present(yml, ADDRESS_EXTERNAL_PORT_TAG); + if (external_port_set) + { + external_port = get(yml, ADDRESS_EXTERNAL_PORT_TAG, version); + } + else + { + external_port = port; + } + + // Optional get Transport protocol + TransportProtocol tp; + bool tp_set = is_tag_present(yml, ADDRESS_TRANSPORT_TAG); + if (tp_set) + { + tp = get(yml, ADDRESS_TRANSPORT_TAG, version); + } + else + { + tp = Address::default_transport_protocol(); + } + + // Construct Address object + if (domain_name_set) + { + if (ip_version_set) + { + return Address(port, external_port, ip_version, domain_name, tp); + } + else + { + return Address(port, external_port, domain_name, tp); + } + } + else + { + if (ip_version_set) + { + return Address(ip, port, external_port, ip_version, tp); + } + else + { + return Address(ip, port, external_port, tp); + } + } +} + +DiscoveryServerConnectionAddress _get_discovery_server_connection_address_v1( + const Yaml& yml, + const YamlReaderVersion version) +{ + // GuidPrefix required + GuidPrefix server_guid = YamlReader::get(yml, version); + + // Addresses required + std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); + + // Create Connection Address + return DiscoveryServerConnectionAddress(server_guid, addresses); +} + +DiscoveryServerConnectionAddress _get_discovery_server_connection_address_latest( + const Yaml& yml, + const YamlReaderVersion version) +{ + // GuidPrefix required + GuidPrefix server_guid = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); + + // Addresses required + std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); + + // Create Connection Address + return DiscoveryServerConnectionAddress(server_guid, addresses); +} + +template <> +DiscoveryServerConnectionAddress YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + switch (version) + { + case V_1_0: + return _get_discovery_server_connection_address_v1(yml, version); + + default: + return _get_discovery_server_connection_address_latest(yml, version); + } +} + +/************************ +* QoS * +************************/ + +template <> +void YamlReader::fill( + TopicQoS& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Reliability optional + if (is_tag_present(yml, QOS_RELIABLE_TAG)) + { + if (get(yml, QOS_RELIABLE_TAG, version)) + { + object.reliability_qos = eprosima::ddspipe::core::types::ReliabilityKind::RELIABLE; + } + else + { + object.reliability_qos = eprosima::ddspipe::core::types::ReliabilityKind::BEST_EFFORT; + } + } + + // Durability optional + if (is_tag_present(yml, QOS_TRANSIENT_TAG)) + { + if (get(yml, QOS_TRANSIENT_TAG, version)) + { + object.durability_qos = eprosima::ddspipe::core::types::DurabilityKind::TRANSIENT_LOCAL; + } + else + { + object.durability_qos = eprosima::ddspipe::core::types::DurabilityKind::VOLATILE; + } + } + + // History depth optional + if (is_tag_present(yml, QOS_HISTORY_DEPTH_TAG)) + { + object.history_depth = get(yml, QOS_HISTORY_DEPTH_TAG, version); + } + + // Durability optional + if (is_tag_present(yml, QOS_PARTITION_TAG)) + { + object.use_partitions = get(yml, QOS_PARTITION_TAG, version); + } + + // Optional keyed + if (is_tag_present(yml, TOPIC_KIND_TAG)) + { + object.keyed = get(yml, TOPIC_KIND_TAG, version); + } + + // Ownership optional + if (is_tag_present(yml, QOS_OWNERSHIP_TAG)) + { + if (get(yml, QOS_OWNERSHIP_TAG, version)) + { + object.ownership_qos = eprosima::ddspipe::core::types::OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS; + } + else + { + object.ownership_qos = eprosima::ddspipe::core::types::OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS; + } + } +} + +/************************ +* TOPICS * +************************/ + +template <> +void YamlReader::fill( + DdsTopic& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Name required + object.m_topic_name = get(yml, TOPIC_NAME_TAG, version); + + // Data Type required + object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); + + // Optional QoS + if (is_tag_present(yml, TOPIC_QOS_TAG)) + { + fill(object.topic_qos, get_value_in_tag(yml, TOPIC_QOS_TAG), version); + } +} + +template <> +DdsTopic YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + DdsTopic object; + fill(object, yml, version); + return object; +} + +template <> +void YamlReader::fill( + WildcardDdsFilterTopic& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Required name + object.topic_name = get(yml, TOPIC_NAME_TAG, version); + + // Optional data type + if (is_tag_present(yml, TOPIC_TYPE_NAME_TAG)) + { + object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); + } + + // TODO: decide whether we want to use QoS as filtering +} + +template <> +WildcardDdsFilterTopic YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + WildcardDdsFilterTopic object; + fill(object, yml, version); + return object; +} + +/************************ +* TLS CONFIGURATION * +************************/ + +template <> +void YamlReader::fill( + TlsConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Optional private key + if (is_tag_present(yml, TLS_PRIVATE_KEY_TAG)) + { + object.private_key_file = get(yml, TLS_PRIVATE_KEY_TAG, version); + } + + // Optional private key password + if (is_tag_present(yml, TLS_PASSWORD_TAG)) + { + object.private_key_file_password = get(yml, TLS_PASSWORD_TAG, version); + } + + // Optional certificate authority + if (is_tag_present(yml, TLS_CA_TAG)) + { + object.certificate_authority_file = get(yml, TLS_CA_TAG, version); + } + + // Optional certificate chain + if (is_tag_present(yml, TLS_CERT_TAG)) + { + object.certificate_chain_file = get(yml, TLS_CERT_TAG, version); + } + + // Optional SNI server name + if (is_tag_present(yml, TLS_SNI_HOST_TAG)) + { + object.sni_server_name = get(yml, TLS_SNI_HOST_TAG, version); + } + + // Optional dh params + if (is_tag_present(yml, TLS_DHPARAMS_TAG)) + { + object.dh_params_file = get(yml, TLS_DHPARAMS_TAG, version); + } + + // Optional peer verification + if (is_tag_present(yml, TLS_PEER_VERIFICATION_TAG)) + { + object.verify_peer = get(yml, TLS_PEER_VERIFICATION_TAG, version); + } + + // Check if it should be client or server + utils::Formatter dummy_formatter__; + utils::Formatter error_msg_client; + utils::Formatter error_msg_server; + if (object.is_valid_kind(dummy_formatter__)) + { + object.kind = TlsKind::both; + } + else if (object.is_valid_kind(error_msg_client)) + { + object.kind = TlsKind::client; + } + else if (object.is_valid_kind(error_msg_server)) + { + object.kind = TlsKind::server; + } + else + { + throw eprosima::utils::ConfigurationException( + STR_ENTRY << "Incorrect TLS configuration." << + " Could not be client because: " << error_msg_client << + " Neither server because: " << error_msg_server << + "." + ); + } +} + +template <> +TlsConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + TlsConfiguration object; + fill(object, yml, version); + return object; +} + +std::ostream& operator <<( + std::ostream& os, + const YamlReaderVersion& version) +{ + switch (version) + { + case V_1_0: + os << VERSION_TAG_V_1_0; + break; + + case V_2_0: + os << VERSION_TAG_V_2_0; + break; + + case V_3_0: + case LATEST: + os << VERSION_TAG_V_3_0; + break; + + default: + utils::tsnh(STR_ENTRY << "Value of YamlReaderVersion out of enumeration."); + break; + } + + return os; +} + +} /* namespace yaml */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddsrouter_yaml/test/CMakeLists.txt b/ddspipe_yaml/test/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/CMakeLists.txt rename to ddspipe_yaml/test/CMakeLists.txt diff --git a/ddsrouter_yaml/test/TestUtils/test_utils.cpp b/ddspipe_yaml/test/TestUtils/test_utils.cpp similarity index 99% rename from ddsrouter_yaml/test/TestUtils/test_utils.cpp rename to ddspipe_yaml/test/TestUtils/test_utils.cpp index 022872f6d..9c5a004e4 100644 --- a/ddsrouter_yaml/test/TestUtils/test_utils.cpp +++ b/ddspipe_yaml/test/TestUtils/test_utils.cpp @@ -23,7 +23,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace test { using namespace eprosima::ddsrouter::core::types; @@ -269,5 +269,5 @@ ParticipantKind random_participant_kind( } } /* namespace test */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_core/test/TestUtils/test_utils.hpp b/ddspipe_yaml/test/TestUtils/test_utils.hpp similarity index 97% rename from ddsrouter_core/test/TestUtils/test_utils.hpp rename to ddspipe_yaml/test/TestUtils/test_utils.hpp index 388c25039..1d1e8be7c 100644 --- a/ddsrouter_core/test/TestUtils/test_utils.hpp +++ b/ddspipe_yaml/test/TestUtils/test_utils.hpp @@ -33,7 +33,7 @@ #include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace test { using namespace eprosima::ddsrouter::core::types; @@ -127,7 +127,5 @@ ParticipantKind random_participant_kind( uint16_t seed = 0); } /* namespace test */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ */ diff --git a/ddsrouter_yaml/test/unittest/CMakeLists.txt b/ddspipe_yaml/test/unittest/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/CMakeLists.txt rename to ddspipe_yaml/test/unittest/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp b/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp similarity index 95% rename from ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp rename to ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp index 238f99a79..9816ec95e 100644 --- a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp +++ b/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp @@ -26,11 +26,11 @@ #include #include -#include -#include +#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { namespace test { @@ -176,7 +176,5 @@ void repeater_to_yaml( } /* namespace test */ } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ - -#endif /* _DDSROUTER_TEST_UNITTEST_YAML_YAMLCONFIGURATIONTESTUTILS_HPP_ */ diff --git a/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt b/ddspipe_yaml/test/unittest/configuration/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt rename to ddspipe_yaml/test/unittest/configuration/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp similarity index 98% rename from ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp rename to ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index 5f98470a0..2f184fb0b 100644 --- a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include #include "../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/CMakeLists.txt rename to ddspipe_yaml/test/unittest/entities/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/entities/address/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/address/CMakeLists.txt rename to ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp b/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp rename to ddspipe_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp diff --git a/ddsrouter_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp b/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp rename to ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp similarity index 95% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp index 6ffce27b8..1cc866a93 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp similarity index 96% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp index 7bfd4cca3..966650dff 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp similarity index 96% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp index b2eaac288..97d9173b0 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp similarity index 94% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp index 30968b5af..55d91790f 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp similarity index 96% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp index 76893c4d0..d219fd6f8 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp similarity index 95% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp index 809ce052d..fe1c099b8 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp similarity index 96% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp index 938166a2c..fc0cc12fe 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp similarity index 95% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp index 4b38f9426..079d56fa2 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp similarity index 97% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp index 67fb3debc..51c5f15fd 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp similarity index 98% rename from ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp rename to ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp index ac20def0e..c7234194b 100644 --- a/ddsrouter_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt rename to ddspipe_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp similarity index 99% rename from ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp rename to ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index 8340b85cb..dcea4ca26 100644 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::yaml; diff --git a/ddsrouter_yaml/test/unittest/entities/guid/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/guid/CMakeLists.txt rename to ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp similarity index 98% rename from ddsrouter_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp rename to ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp index 2075ac62a..43fd3776b 100644 --- a/ddsrouter_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/entities/topic/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/entities/topic/CMakeLists.txt rename to ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp similarity index 98% rename from ddsrouter_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp rename to ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp index 78eb49b4e..4a4883c54 100644 --- a/ddsrouter_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp @@ -19,8 +19,8 @@ #include #include #include -#include -#include +#include +#include #include "../../YamlConfigurationTestUtils.hpp" @@ -28,7 +28,7 @@ using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::yaml; namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { namespace test { @@ -124,7 +124,7 @@ void compare_wildcard_topic( } /* namespace test */ } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ /** diff --git a/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt b/ddspipe_yaml/test/unittest/participants/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/participants/CMakeLists.txt rename to ddspipe_yaml/test/unittest/participants/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp similarity index 98% rename from ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp rename to ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index e21f3b7f8..e6e988a68 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -18,7 +18,7 @@ #include -#include +#include #include "../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp similarity index 100% rename from ddsrouter_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp rename to ddspipe_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp similarity index 99% rename from ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp rename to ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp index c5273228e..ec6cb5909 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include "../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp similarity index 99% rename from ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp rename to ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index a8bc533be..0d9932749 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp similarity index 99% rename from ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp rename to ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index 67e4bb415..a71bbf9d3 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp similarity index 98% rename from ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp rename to ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index c517796fe..1efc6e334 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp similarity index 99% rename from ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp rename to ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index 6af356853..38e6db973 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp similarity index 98% rename from ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp rename to ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index a107a703d..d71be77a9 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp similarity index 98% rename from ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp rename to ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp index 6b75dfe5a..5a433ec33 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp similarity index 99% rename from ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp rename to ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index 20d3b0a8e..9a8c681c7 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include "../../YamlConfigurationTestUtils.hpp" diff --git a/ddsrouter_yaml/test/unittest/yaml_manager/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_manager/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/yaml_manager/CMakeLists.txt rename to ddspipe_yaml/test/unittest/yaml_manager/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp b/ddspipe_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp similarity index 100% rename from ddsrouter_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp rename to ddspipe_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp diff --git a/ddsrouter_yaml/test/unittest/yaml_reader/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/yaml_reader/CMakeLists.txt rename to ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp similarity index 100% rename from ddsrouter_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp rename to ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp diff --git a/ddsrouter_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp similarity index 93% rename from ddsrouter_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp rename to ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp index d2cf3dc08..7312e96d6 100644 --- a/ddsrouter_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp +++ b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp @@ -15,10 +15,10 @@ #include #include -#include +#include namespace eprosima { -namespace ddsrouter { +namespace ddspipe { namespace yaml { namespace test { @@ -46,5 +46,5 @@ class MockYamlReader : public YamlReader } /* namespace test */ } /* namespace yaml */ -} /* namespace ddsrouter */ +} /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddsrouter_yaml/test/unittest/yaml_tags/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_tags/CMakeLists.txt similarity index 100% rename from ddsrouter_yaml/test/unittest/yaml_tags/CMakeLists.txt rename to ddspipe_yaml/test/unittest/yaml_tags/CMakeLists.txt diff --git a/ddsrouter_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp b/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp similarity index 97% rename from ddsrouter_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp rename to ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp index 9e3cfad52..b7e5fbad9 100644 --- a/ddsrouter_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp +++ b/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include using namespace eprosima::ddsrouter::yaml; diff --git a/ddsrouter_core/README.md b/ddsrouter_core/README.md index 0d7362f1b..8b90a4555 100644 --- a/ddsrouter_core/README.md +++ b/ddsrouter_core/README.md @@ -9,8 +9,8 @@ Include module is the public API used to configure a DDS Router and to interact * **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. - * *DDSRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. - * *DDSRouterReloadConfiguration*: configuration to change topics in a running DDS Router. + * *DdsRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. + * *DdsRouterReloadConfiguration*: configuration to change topics in a running DDS Router. * **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. It allows to execute a DDS Router, and to interact with it while running. @@ -22,11 +22,11 @@ Include module is the public API used to configure a DDS Router and to interact ```cpp // START AND STOP DDS ROUTER FROM CONFIGURATION -core::configuration::DDSRouterConfiguration router_configuration; +core::configuration::DdsRouterConfiguration router_configuration; // ... populate router_configuration -core::DDSRouter router(router_configuration); +core::DdsRouter router(router_configuration); router.start(); // ... wait for event diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp similarity index 53% rename from ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp index 6a02b625b..65544931d 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp @@ -12,36 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DDSRouterConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_DDSROUTERCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_DDSROUTERCONFIGURATION_HPP_ +#pragma once #include #include -#include +#include + +#include -#include -#include #include -#include -#include +#include +#include +#include namespace eprosima { namespace ddsrouter { namespace core { -namespace configuration { /** - * This data struct joins every DDSRouter feature configuration such as: - * - Modifiable values (from \c DDSRouterReloadConfiguration ). + * This data struct joins every DdsRouter feature configuration such as: + * - Modifiable values (from \c DdsRouterReloadConfiguration ). * - Participant configurations. * - Advanced configurations. */ -struct DDSRouterConfiguration : public DDSRouterReloadConfiguration +struct DdsRouterConfiguration : public DdsRouterReloadConfiguration { ///////////////////////// @@ -49,18 +44,7 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration ///////////////////////// //! Default constructor - DDSROUTER_CORE_DllAPI DDSRouterConfiguration() = default; - - /** - * @brief Constructor with arguments to fill new object. - * - * @todo use const & references or even eliminate this constructor - */ - DDSROUTER_CORE_DllAPI DDSRouterConfiguration( - const std::set>& allowlist, - const std::set>& blocklist, - const std::set>& builtin_topics, - const SpecsConfiguration& advanced_options); + DDSROUTER_CORE_DllAPI DdsRouterConfiguration() = default; ///////////////////////// // METHODS @@ -68,7 +52,7 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration //! Set internal values with the values reloaded DDSROUTER_CORE_DllAPI void reload( - const DDSRouterReloadConfiguration& new_configuration); + const DdsRouterReloadConfiguration& new_configuration); //! Override \c is_valid method. DDSROUTER_CORE_DllAPI bool is_valid( @@ -78,14 +62,28 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration // VARIABLES ///////////////////////// + //! Builtin topics to create at the beggining of the execution + std::set> builtin_topics {}; + + //! Participant configurations + std::set< + std::pair< + types::ParticipantKind, + std::shared_ptr< + ddspipe::participants::ParticipantConfiguration>>> + participants_configurations {}; + //! Advanced configurations - SpecsConfiguration advanced_options; + SpecsConfiguration advanced_options {}; + +protected: + + //! Auxiliar method to validate that class type of the participants are compatible with their kinds. + static bool check_correct_configuration_object_( + const std::shared_ptr configuration); }; -} /* namespace configuration */ } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_DDSROUTERCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp similarity index 50% rename from ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp rename to ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp index 95cf43608..73a0f1239 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp @@ -12,46 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DDSRouterReloadConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_DDSROUTERRELOADCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_DDSROUTERRELOADCONFIGURATION_HPP_ +#pragma once #include #include #include -#include -#include +#include +#include + #include -#include -#include namespace eprosima { namespace ddsrouter { namespace core { -namespace configuration { /** - * This class joins every DDSRouter feature configuration and includes methods + * This class joins every DdsRouter feature configuration and includes methods * to interact with this configuration. */ -struct DDSRouterReloadConfiguration : public BaseConfiguration +struct DdsRouterReloadConfiguration : public ddspipe::core::BaseConfiguration { ///////////////////////// // CONSTRUCTORS ///////////////////////// - DDSROUTER_CORE_DllAPI DDSRouterReloadConfiguration() = default; - - DDSROUTER_CORE_DllAPI DDSRouterReloadConfiguration( - std::set> allowlist, - std::set> blocklist, - std::set> builtin_topics); + DDSROUTER_CORE_DllAPI DdsRouterReloadConfiguration() = default; ///////////////////////// // METHODS @@ -64,16 +52,12 @@ struct DDSRouterReloadConfiguration : public BaseConfiguration // VARIABLES ///////////////////////// - std::set> allowlist = {}; + std::set> allowlist {}; - std::set> blocklist = {}; + std::set> blocklist {}; - std::set> builtin_topics = {}; }; -} /* namespace configuration */ } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_DDSROUTERRELOADCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index 2a758977a..18918965d 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -10,35 +10,30 @@ // 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. +// limitations under the License\. -/** - * @file SpecsConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_SPECSCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_SPECSCONFIGURATION_HPP_ +#pragma once #include #include #include -#include +#include +#include + #include -#include namespace eprosima { namespace ddsrouter { namespace core { -namespace configuration { /** * This data struct contains the values for advance configuration of the DDS Router such as: * - Number of threads to Thread Pool * - Default maximum history depth */ -struct SpecsConfiguration : public BaseConfiguration +struct SpecsConfiguration : public ddspipe::core::BaseConfiguration { ///////////////////////// @@ -51,7 +46,7 @@ struct SpecsConfiguration : public BaseConfiguration // METHODS ///////////////////////// - DDSROUTER_CORE_DllAPI bool is_valid( + DDSROUTER_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; ///////////////////////// @@ -65,12 +60,9 @@ struct SpecsConfiguration : public BaseConfiguration * * @note Default value is 5000 as in Fast DDS. */ - types::HistoryDepthType max_history_depth = 5000; + ddspipe::core::types::HistoryDepthType max_history_depth = 5000; }; -} /* namespace configuration */ } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_SPECSCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp similarity index 67% rename from ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp rename to ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp index 61134b6e1..a3847bff8 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DDSRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp @@ -12,41 +12,35 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DDSRouter.hpp - */ - -#ifndef _DDSROUTERCORE_CORE_DDSROUTERCORE_HPP_ -#define _DDSROUTERCORE_CORE_DDSROUTERCORE_HPP_ - -#include +#pragma once #include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace eprosima { namespace ddsrouter { namespace core { -class DDSRouterImpl; - /** * TODO */ -class DDSRouter +class DdsRouter { public: /** - * @brief Construct a new DDSRouter object + * @brief Construct a new DdsRouter object * - * Initialize a whole DDSRouter: + * Initialize a whole DdsRouter: * - Create its associated AllowedTopicList * - Create Participants and add them to \c ParticipantsDatabase * - Create the Bridges for (allowed) builtin topics @@ -56,20 +50,17 @@ class DDSRouter * @throw \c ConfigurationException in case the yaml inside allowlist is not well-formed * @throw \c InitializationException in case \c IParticipants , \c IWriters or \c IReaders creation fails. */ - DDSROUTER_CORE_DllAPI DDSRouter( - const configuration::DDSRouterConfiguration& configuration, - const std::shared_ptr& discovery_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& participants_database); + DDSROUTER_CORE_DllAPI DdsRouter( + const DdsRouterConfiguration& configuration); /** - * @brief Destroy the DDSRouter object + * @brief Destroy the DdsRouter object * - * Stop the DDSRouter + * Stop the DdsRouter * Destroy all Bridges * Destroy all Participants */ - DDSROUTER_CORE_DllAPI virtual ~DDSRouter(); + DDSROUTER_CORE_DllAPI virtual ~DdsRouter(); // EVENTS /** @@ -84,7 +75,7 @@ class DDSRouter * @throw \c ConfigurationException in case the new yaml is not well-formed */ DDSROUTER_CORE_DllAPI utils::ReturnCode reload_configuration( - const configuration::DDSRouterReloadConfiguration& configuration); + const DdsRouterReloadConfiguration& configuration); /** * @brief Start communication in DDS Router @@ -110,11 +101,21 @@ class DDSRouter protected: - std::unique_ptr ddsrouter_impl_; + DdsRouterConfiguration configuration_; + + std::shared_ptr allowed_topics_; + + std::shared_ptr discovery_database_; + + std::shared_ptr payload_pool_; + + std::shared_ptr participants_database_; + + std::shared_ptr thread_pool_; + + ParticipantFactory participant_factory_; }; } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CORE_DDSROUTERCORE_HPP_ */ diff --git a/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp b/ddsrouter_core/include/ddsrouter_core/core/ParticipantFactory.hpp similarity index 58% rename from ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp rename to ddsrouter_core/include/ddsrouter_core/core/ParticipantFactory.hpp index 08918989f..f52f4160f 100644 --- a/ddsrouter_participants/include/ddsrouter_participants/ParticipantFactory.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/ParticipantFactory.hpp @@ -12,23 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file ParticipantFactory.hpp - */ +#pragma once -#ifndef __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ -#define __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ +#include +#include +#include -#include -#include -#include -#include +#include -#include +#include namespace eprosima { namespace ddsrouter { -namespace participants { +namespace core { class ParticipantFactory { @@ -45,15 +41,13 @@ class ParticipantFactory * @param [in] discovery_database : Common Discovery Database to create the Participant * @return new Participant */ - static std::shared_ptr create_participant( - const ParticipantKind& kind, - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database); + static std::shared_ptr create_participant( + const types::ParticipantKind& kind, + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database); }; -} /* namespace participants */ +} /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_CORE_DDS_ROUTERPARTICIPANTFACTORY_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/.dev.md b/ddsrouter_core/include/ddsrouter_core/participants/.dev.md deleted file mode 100644 index e7bb78ed7..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/.dev.md +++ /dev/null @@ -1 +0,0 @@ -This directory should be moved under ddsrouter_participants once it is solved the dependencies on the RPCBridge. diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp deleted file mode 100644 index 1fc654178..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/auxiliar/BaseParticipant.hpp +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2021 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 BaseParticipant.hpp - */ - -#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_HPP_ -#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_HPP_ - -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -/** - * Abstract Participant that implements generic methods for every Participant. - * - * In order to inherit from this class, create the protected methods create_writer_ and create_reader_ - * - * This class stores every Endpoint created by this Participant. - */ -class BaseParticipant : public core::IParticipant -{ - -public: - - /** - * @brief Generic constructor for a Participant - * - * Id and kind are taken from the configuration. - * - * @param participant_configuration Configuration for the Participant. Participant Kind is taken from here. - * @param payload_pool DDS Router shared PayloadPool - * @param discovery_database DDS Router shared Discovery Database - */ - BaseParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr & payload_pool, - const std::shared_ptr& discovery_database); - - /** - * @brief Destroy the Base Participant object - * - * If any writer or reader still exists, removes it and shows a warning - */ - virtual ~BaseParticipant(); - - /** - * @brief Override id() IParticipant method - * - * It gets the id from the configuration. - * - * Thread safe with mutex \c mutex_ . - */ - core::types::ParticipantId id() const noexcept override; - - /** - * @brief Override is_rtps_kind() IParticipant method - * - * @return whether the participant is RTPS - */ - bool is_rtps_kind() const noexcept override; - - /** - * @brief Override is_repeater_ IParticipant method - * - * It gets the kind from the configuration. - * - * Thread safe with mutex \c mutex_ . - */ - bool is_repeater() const noexcept override; - - /** - * @brief Override create_writer() IParticipant method - * - * This method calls the protected method \c create_writer_ in order to create the actual Writer. - * The Writer created is stored in a map. - * - * Thread safe with mutex \c mutex_ . - */ - std::shared_ptr create_writer( - core::types::DdsTopic topic) override; - - /** - * @brief Override create_reader() IParticipant method - * - * This method calls the protected method \c create_reader_ in order to create the actual Reader. - * The Reader created is stored in a map. - * - * Thread safe with mutex \c mutex_ . - */ - std::shared_ptr create_reader( - core::types::DdsTopic topic) override; - - /** - * @brief Override delete_writer() IParticipant method - * - * This method calls the protected method \c delete_writer_ in order to delete the Writer. - * - * Thread safe with mutex \c mutex_ . - */ - void delete_writer( - std::shared_ptr writer) noexcept override; - - /** - * @brief Override delete_reader() IParticipant method - * - * This method calls the protected method \c delete_reader_ in order to delete the Reader. - * - * Thread safe with mutex \c mutex_ . - */ - void delete_reader( - std::shared_ptr reader) noexcept override; - -protected: - - /** - * @brief Create a writer object - * - * @note Implement this method in every Participant in order to create a class specific Writer - * - * @param [in] topic : Topic that this Writer refers to. - * @return Writer - */ - virtual std::shared_ptr create_writer_( - core::types::DdsTopic topic) = 0; - - /** - * @brief Create a reader object - * - * @note Implement this method in every Participant in order to create a class specific Reader - * - * @param [in] topic : Topic that this Reader refers to. - * @return Reader - */ - virtual std::shared_ptr create_reader_( - core::types::DdsTopic topic) = 0; - - /** - * @brief Do nothing - * - * @note Implement this method in order to delete a class specific Writer - * - * @param [in] writer : Writer to delete - */ - virtual void delete_writer_( - std::shared_ptr writer) noexcept; - - /** - * @brief Do nothing - * - * @note Implement this method in order to delete a class specific Reader - * - * @param [in] reader : Reader to delete - */ - virtual void delete_reader_( - std::shared_ptr reader) noexcept; - - /** - * @brief Get Id without locking a mutex - * - * It gets the id from the configuration. - * - * Not Thread safe. - * - * @warning this method is called from discovery callbacks, that could be called from Fast DDS while - * creating an endpoint. So it could lead to a dead lock. That is why it is not thread safe. - */ - core::types::ParticipantId id_nts_() const noexcept; - - //! Participant configuration - std::shared_ptr configuration_; - - //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; - - //! DDS Router shared Discovery Database - std::shared_ptr discovery_database_; - - //! Writers created by this Participant indexed by topic - std::map> writers_; - - //! Readers created by this Participant indexed by topic - std::map> readers_; - - //! Mutex that guards every access to the Participant - mutable std::recursive_mutex mutex_; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const BaseParticipant&); -}; - -/** - * @brief \c BaseParticipant to stream serialization - * - * This method is merely a to_string of a BaseParticipant definition. - * It serialize the Id and kind - */ -std::ostream& operator <<( - std::ostream& os, - const BaseParticipant& part); - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp deleted file mode 100644 index 53b07ae4e..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/DiscoveryServerParticipantConfiguration.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2021 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 DiscoveryServerParticipantConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_DISCOVERYSERVERPARTICIPANTCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_DISCOVERYSERVERPARTICIPANTCONFIGURATION_HPP_ - -#include -#include -#include -#include -#include -#include -#include - - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -/** - * This class joins Discovery Server Participant Configuration features and gives methods to interact with it. - */ -struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration() = default; - - DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration( - const core::types::ParticipantId& id, - const bool is_repeater, - const core::types::DomainId& domain_id, - const core::types::GuidPrefix& discovery_server_guid_prefix, - const std::set& listening_addresses, - const std::set& connection_addresses, - const core::types::security::TlsConfiguration& tls_configuration); - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - DDSROUTER_CORE_DllAPI bool operator ==( - const DiscoveryServerParticipantConfiguration& other) const noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - core::types::GuidPrefix discovery_server_guid_prefix = core::types::GuidPrefix(); - - std::set listening_addresses = {}; - - std::set connection_addresses = {}; - - core::types::security::TlsConfiguration tls_configuration = core::types::security::TlsConfiguration(); -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_DISCOVERYSERVERPARTICIPANTCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp deleted file mode 100644 index 5eca7b991..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/InitialPeersParticipantConfiguration.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2022 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 InitialPeersParticipantConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_INITIALPEERSPARTICIPANTCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_INITIALPEERSPARTICIPANTCONFIGURATION_HPP_ - -#include -#include -#include -#include -#include -#include -#include - - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -/** - * This data struct joins Initial Peers Participant Configuration features - */ -struct InitialPeersParticipantConfiguration : public SimpleParticipantConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - DDSROUTER_CORE_DllAPI InitialPeersParticipantConfiguration() = default; - - DDSROUTER_CORE_DllAPI InitialPeersParticipantConfiguration( - const core::types::ParticipantId& id, - const bool is_repeater, - const core::types::DomainId& domain_id, - const std::set& listening_addresses, - const std::set& connection_addresses, - const core::types::security::TlsConfiguration& tls_configuration); - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - DDSROUTER_CORE_DllAPI bool operator ==( - const InitialPeersParticipantConfiguration& other) const noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - std::set listening_addresses = {}; - - std::set connection_addresses = {}; - - core::types::security::TlsConfiguration tls_configuration = core::types::security::TlsConfiguration(); -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_INITIALPEERSPARTICIPANTCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp deleted file mode 100644 index e4469ace4..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/ParticipantConfiguration.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 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 ParticipantConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_PARTICIPANTCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_PARTICIPANTCONFIGURATION_HPP_ - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -struct ParticipantConfiguration : public core::configuration::BaseConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - DDSROUTER_CORE_DllAPI ParticipantConfiguration() = default; - - DDSROUTER_CORE_DllAPI ParticipantConfiguration( - const core::types::ParticipantId& id, - const bool is_repeater) noexcept; - - ///////////////////////// - // METHODS - ///////////////////////// - - /** - * @brief Equal comparator - * - * @param [in] other: ParticipantConfiguration to compare. - * @return True if both configurations are the same, False otherwise. - */ - DDSROUTER_CORE_DllAPI bool operator ==( - const ParticipantConfiguration& other) const noexcept; - - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - //! Participant Id associated with this configuration - core::types::ParticipantId id; - - //! Whether this Participant should connect its readers with its writers. - bool is_repeater = false; -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_PARTICIPANTCONFIGURATION_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp deleted file mode 100644 index c4a973e6b..000000000 --- a/ddsrouter_core/include/ddsrouter_core/participants/participant/configuration/SimpleParticipantConfiguration.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2021 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 SimpleParticipantConfiguration.hpp - */ - -#ifndef _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_SIMPLEPARTICIPANTCONFIGURATION_HPP_ -#define _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_SIMPLEPARTICIPANTCONFIGURATION_HPP_ - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -/** - * This data struct represents a configuration for a SimpleParticipant - */ -struct SimpleParticipantConfiguration : public ParticipantConfiguration -{ -public: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration() = default; - - DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration( - const core::types::ParticipantId& id, - const bool is_repeater, - const core::types::DomainId& domain_id) noexcept; - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - /** - * @brief Equal comparator - * - * @param [in] other: SimpleParticipantConfiguration to compare. - * @return True if both configurations are the same, False otherwise. - */ - DDSROUTER_CORE_DllAPI bool operator ==( - const SimpleParticipantConfiguration& other) const noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - core::types::DomainId domain = core::types::DomainId(0u); -}; - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_CONFIGURATION_PARTICIPANT_SIMPLEPARTICIPANTCONFIGURATION_HPP_ */ diff --git a/ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp b/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp similarity index 86% rename from ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp rename to ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp index 91486ab14..4ab5ab09a 100644 --- a/ddsrouter_participants/include/ddsrouter_participants/ParticipantKind.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp @@ -12,19 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file ParticipantKind.hpp - */ - -#ifndef _DDSROUTERYAML_PARTICIPANTKIND_HPP_ -#define _DDSROUTERYAML_PARTICIPANTKIND_HPP_ +#pragma once #include #include namespace eprosima { namespace ddsrouter { -namespace participants { +namespace core { +namespace types { ENUMERATION_BUILDER( ParticipantKind, @@ -45,8 +41,7 @@ eProsima_ENUMERATION_BUILDER( } ); -} /* namespace participants */ +} /* namespace types */ +} /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERYAML_PARTICIPANTKIND_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp b/ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp deleted file mode 100644 index dd781c869..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/data/SharedData.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// 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 SharedData.hpp - */ - -#pragma once - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -/** - * TODO - */ -template -struct SharedData : public IRoutingData -{ - std::shared_ptr ref; - - static TopicInternalTypeId get_topic_internal_type_id(); - - static bool is_shared_internal_type(TopicInternalTypeId internal_topic_type_id); -}; - -/** - * TODO - */ -constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_SHARED_GENERIC_PREFIX = "shared::v0::"; - -template -constexpr const TopicInternalTypeId INTERNAL_TOPIC_TYPE_SHARED_GENERIC = - INTERNAL_TOPIC_TYPE_SHARED_GENERIC_PREFIX + TYPE_NAME(T); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/dds/DomainId.hpp b/ddsrouter_core/include/ddsrouter_core/types/dds/DomainId.hpp deleted file mode 100644 index 51c5e207b..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/dds/DomainId.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2021 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 DomainId.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_DDS_DOMAINID_HPP_ -#define _DDSROUTERCORE_TYPES_DDS_DOMAINID_HPP_ - -#include - -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -// Use FastDDS Domain Id type -using DomainIdType = eprosima::fastdds::dds::DomainId_t; - -/** - * @brief RTPS Domain ID. - */ -class DomainId -{ -public: - - /** - * @brief Domain ID by default for DDS Routers - * - * In case of Discovery Server, default domain is 66 - * In case of Simple Discovery, default domain is 0 - * - * @param discovery_server - */ - DDSROUTER_CORE_DllAPI DomainId ( - bool discovery_server = false) noexcept; - - //! Standar constructor by number - DDSROUTER_CORE_DllAPI DomainId ( - const DomainIdType& domain) noexcept; - - //! Return Fast DDS value for Domain ID - DDSROUTER_CORE_DllAPI DomainIdType operator ()() const noexcept; - - //! Return Fast DDS value for Domain ID - DDSROUTER_CORE_DllAPI DomainIdType domain_id() const noexcept; - - DDSROUTER_CORE_DllAPI bool is_valid() const noexcept; - - DDSROUTER_CORE_DllAPI bool operator ==( - const DomainId& other) const noexcept; - - DDSROUTER_CORE_DllAPI operator DomainIdType() const noexcept; - -protected: - - //! Value of Fast DDS Domain ID - DomainIdType domain_id_; - - //! Default value for Simple Discovery - static const DomainIdType DEFAULT_DOMAIN_ID_; // 0 - - //! Default value for Discovery Server - static const DomainIdType DEFAULT_DISCOVERY_SERVER_DOMAIN_ID_; // 66 - - //! Maximum Domain Id valid - static const DomainIdType MAX_DOMAIN_ID_; // 250 -}; - -//! \c DomainId serializator -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& output, - const DomainId& domain); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_DDS_DOMAINID_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/endpoint/Endpoint.hpp b/ddsrouter_core/include/ddsrouter_core/types/endpoint/Endpoint.hpp deleted file mode 100644 index a7da74b7e..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/endpoint/Endpoint.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2021 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 Endpoint.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_ENDPOINT_ENDPOINT_HPP_ -#define _DDSROUTERCORE_TYPES_ENDPOINT_ENDPOINT_HPP_ - -#include - -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -using EndpointKindType = unsigned int; - -//! Possible kinds of the endpoint -ENUMERATION_BUILDER( - EndpointKind, - invalid, - writer, - reader - ); - -/** - * Data collection to describe an Endpoint - * - * This class works as a data storage struct with the information of a discovered Endpoint - */ -class Endpoint -{ -public: - - //! Default Endpoint that returns an invalid one - DDSROUTER_CORE_DllAPI Endpoint() noexcept; - - /** - * Constructor with Endpoint information - */ - DDSROUTER_CORE_DllAPI Endpoint( - const EndpointKind& kind, - const Guid& guid, - const DdsTopic& topic, - const ParticipantId& discoverer_participant_id = ParticipantId(), - const SpecificEndpointQoS& specific_qos = SpecificEndpointQoS()) noexcept; - - //! Endpoint kind getter - DDSROUTER_CORE_DllAPI EndpointKind kind() const noexcept; - - //! Endpoint kind setter - DDSROUTER_CORE_DllAPI void kind( - const EndpointKind& kind) noexcept; - - //! Guid getter - DDSROUTER_CORE_DllAPI Guid guid() const noexcept; - - //! TopicQoS getter - DDSROUTER_CORE_DllAPI TopicQoS topic_qos() const noexcept; - - //! SpecificQoS getter - DDSROUTER_CORE_DllAPI SpecificEndpointQoS specific_qos() const noexcept; - - //! SpecificQoS setter - DDSROUTER_CORE_DllAPI void specific_qos( - const SpecificEndpointQoS& specific_qos) noexcept; - - //! Topic getter - DDSROUTER_CORE_DllAPI DdsTopic topic() const noexcept; - - //! Id of participant who discovered this endpoint - DDSROUTER_CORE_DllAPI ParticipantId discoverer_participant_id() const noexcept; - - //! Whether the endpoint referenced is currently active - DDSROUTER_CORE_DllAPI bool active() const noexcept; - - //! Set active status of the Endpoint - DDSROUTER_CORE_DllAPI void active( - bool status) noexcept; - - //! Whether the endpoint referenced is valid - DDSROUTER_CORE_DllAPI bool is_valid() const noexcept; - - /******************** - * SPECIFIC GETTERS * - ********************/ - - //! Whether the endpoint is a writer - DDSROUTER_CORE_DllAPI bool is_writer() const noexcept; - - //! Whether the endpoint is a reader - DDSROUTER_CORE_DllAPI bool is_reader() const noexcept; - - //! Whether the endpoint belongs to a RPC server (i.e. is request reader or reply writer) - DDSROUTER_CORE_DllAPI bool is_server_endpoint() const noexcept; - - //! Copy operator - DDSROUTER_CORE_DllAPI Endpoint& operator =( - const Endpoint& other) noexcept; - - //! Equality operator (does not take \c active_ into consideration) - DDSROUTER_CORE_DllAPI bool operator ==( - const Endpoint& other) const noexcept; - -protected: - - //! Kind of the endpoint - EndpointKind kind_; - - //! Unique id of the endpoint - Guid guid_; - - //! Topic that this endpoint belongs to - DdsTopic topic_; - - //! Whether the endpoint is currently active - bool active_; - - //! Id of participant who discovered this endpoint - ParticipantId discoverer_participant_id_; - - //! Specific QoS of the entity - SpecificEndpointQoS specific_qos_; - - // Allow operator << to use private variables - DDSROUTER_CORE_DllAPI friend std::ostream& operator <<( - std::ostream&, - const Endpoint&); -}; - -/** - * @brief \c Endpoint to stream serialization - */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const Endpoint& endpoint); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_ENDPOINT_ENDPOINT_HPP_ */ diff --git a/ddsrouter_core/include/ddsrouter_core/types/topic/dds/DdsTopic.hpp b/ddsrouter_core/include/ddsrouter_core/types/topic/dds/DdsTopic.hpp deleted file mode 100644 index 959713e38..000000000 --- a/ddsrouter_core/include/ddsrouter_core/types/topic/dds/DdsTopic.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2022 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 Topic.hpp - */ - -#ifndef _DDSROUTERCORE_TYPES_TOPIC_DDS_DDSTOPIC_HPP_ -#define _DDSROUTERCORE_TYPES_TOPIC_DDS_DDSTOPIC_HPP_ - -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { -namespace types { - -/** - * Data struct that represents a DDS Topic of data flow in the Router. - * - * @todo remove argument constructors. - */ -struct DdsTopic : public Topic -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default constructor - DDSROUTER_CORE_DllAPI DdsTopic() = default; - - //! Main values constructor - DDSROUTER_CORE_DllAPI DdsTopic( - const std::string& topic_name, - const std::string& type_name) noexcept; - - //! Values constructor - DDSROUTER_CORE_DllAPI DdsTopic( - const std::string& topic_name, - const std::string& type_name, - const bool keyed, - const types::TopicQoS& qos) noexcept; - - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Minor operator. - DDSROUTER_CORE_DllAPI bool operator < ( - const DdsTopic& other) const noexcept; - - //! Equal operator. - DDSROUTER_CORE_DllAPI bool operator == ( - const DdsTopic& other) const noexcept; - - ///////////////////////// - // METHODS - ///////////////////////// - - /** - * @brief Whether this object is valid. - * - * @param [out] error_msg not validity reason in case it is not valid. - * @return true if valid. - * @return false otherwise. - */ - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept; - - ///////////////////////// - // STATIC METHODS - ///////////////////////// - - //! Whether a name and type can refer to a correct DDS Topic. - DDSROUTER_CORE_DllAPI static bool is_valid_dds_topic( - const std::string& topic_name, - const std::string& type_name) noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Topic Type name - std::string type_name; - - // TODO: this could be set as TopicQoS - //! Whether the topic has key or not - bool keyed = false; - - /** - * @brief Topic QoS - * - * @note This is Fuzzy to solve the case where different QoS for same topic are found - * (e.g. Writer and Reader default). In these cases the fuzzy level must declare which one should be used. - * However, as we finally decided that only readers generate bridges, this Fuzzy level is actually not needed (yet). - */ - utils::Fuzzy topic_qos{}; -}; - -/** - * Serialization method for \c DdsTopic object. - */ -DDSROUTER_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const DdsTopic& t); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _DDSROUTERCORE_TYPES_TOPIC_DDS_DDSTOPIC_HPP_ */ diff --git a/ddsrouter_core/package.xml b/ddsrouter_core/package.xml index 696663099..8607d6f47 100644 --- a/ddsrouter_core/package.xml +++ b/ddsrouter_core/package.xml @@ -17,9 +17,8 @@ cmake - fastrtps - cpp_utils cmake_utils + ddspipe_participants doxygen diff --git a/ddsrouter_core/project_settings.cmake b/ddsrouter_core/project_settings.cmake index 362c17ae4..570760798 100644 --- a/ddsrouter_core/project_settings.cmake +++ b/ddsrouter_core/project_settings.cmake @@ -25,7 +25,9 @@ set(MODULE_SUMMARY set(MODULE_FIND_PACKAGES fastcdr fastrtps - cpp_utils) + cpp_utils + ddspipe_core + ddspipe_participants) set(fastrtps_MINIMUM_VERSION "2.8") diff --git a/ddsrouter_core/src/cpp/_dummy.cpp b/ddsrouter_core/src/cpp/_dummy.cpp new file mode 100644 index 000000000..d353d8800 --- /dev/null +++ b/ddsrouter_core/src/cpp/_dummy.cpp @@ -0,0 +1,8 @@ + +#include +#include +#include +#include +#include +#include +#include diff --git a/ddsrouter_core/src/cpp/core/DDSRouter.cpp b/ddsrouter_core/src/cpp/core/DDSRouter.cpp deleted file mode 100644 index 91dab1ab9..000000000 --- a/ddsrouter_core/src/cpp/core/DDSRouter.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2021 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 DDSRouter.cpp - * - */ - -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace core { - -// TODO: Use initial topics to start execution and start bridges - -DDSRouter::DDSRouter( - const configuration::DDSRouterConfiguration& configuration, - const std::shared_ptr& discovery_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& participants_database) - : ddsrouter_impl_(std::make_unique( - configuration, discovery_database, payload_pool, participants_database)) -{ -} - -DDSRouter::~DDSRouter() -{ -} - -utils::ReturnCode DDSRouter::reload_configuration( - const configuration::DDSRouterReloadConfiguration& new_configuration) -{ - return ddsrouter_impl_->reload_configuration(new_configuration); -} - -utils::ReturnCode DDSRouter::start() noexcept -{ - return ddsrouter_impl_->start(); -} - -utils::ReturnCode DDSRouter::stop() noexcept -{ - return ddsrouter_impl_->stop(); -} - -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_participants/README.md b/ddsrouter_participants/README.md deleted file mode 100644 index 1b37535de..000000000 --- a/ddsrouter_participants/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# eProsima DDS Router Core Library - -`ddsrouter_participants` subpackage. - -> :warning: **TODO** diff --git a/ddsrouter_participants/src/cpp/ParticipantFactory.cpp b/ddsrouter_participants/src/cpp/ParticipantFactory.cpp deleted file mode 100644 index a18219768..000000000 --- a/ddsrouter_participants/src/cpp/ParticipantFactory.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2021 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 ParticipantFactory.cpp - * - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddsrouter { -namespace participants { - -using namespace eprosima::ddsrouter::core::types; -using namespace eprosima::ddsrouter::core::configuration; - -std::shared_ptr ParticipantFactory::create_participant( - const ParticipantKind& kind, - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database) -{ - // Create a new Participant depending on the ParticipantKind specified - switch (kind) - { - case ParticipantKind::echo: - // Echo Participant - { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( - participant_configuration); - if (!conf_) - { - throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << kind); - } - - return std::make_shared ( - conf_, - discovery_database); - } - - case ParticipantKind::simple: - // Simple RTPS Participant - { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( - participant_configuration); - if (!conf_) - { - throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << kind); - } - - auto participant = std::make_shared ( - conf_, - payload_pool, - discovery_database); - - // Initialize Participant (this is needed as Participant is not RAII because of Listener) - participant->init(); - - return participant; - } - - case ParticipantKind::discovery_server: - // Discovery Server RTPS Participant - { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( - participant_configuration); - // TMP: Until Transparency TopicQoS module is available - if (!conf_) - { - throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << - kind); - } - - auto participant = std::make_shared ( - conf_, - payload_pool, - discovery_database); - - // Initialize Participant (this is needed as Participant is not RAII because of Listener) - participant->init(); - - return participant; - } - - case ParticipantKind::initial_peers: - // Initial Peers RTPS Participant - { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( - participant_configuration); - // TMP: Until Transparency TopicQoS module is available - if (!conf_) - { - throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << - kind); - } - - auto participant = std::make_shared ( - conf_, - payload_pool, - discovery_database); - - // Initialize Participant (this is needed as Participant is not RAII because of Listener) - participant->init(); - - return participant; - } - - default: - // This should not happen as every kind must be in the switch - utils::tsnh( - utils::Formatter() << "Value of ParticipantKind out of enumeration."); - return nullptr; // Unreachable code - } -} - -} /* namespace participants */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_yaml/README.md b/ddsrouter_yaml/README.md index eb195bc2a..08494fa46 100644 --- a/ddsrouter_yaml/README.md +++ b/ddsrouter_yaml/README.md @@ -1,42 +1,55 @@ -# eProsima DDS Router Yaml Module +# eProsima DDS Router Core Library -This library implements the required functions to translate a DDS Router configuration written in *yaml* -format into C++ source code. -It is powered by `yaml-cpp` library. +> TODO -It provides methods: +This library contain main functionality of the DDS Router. +Include module is the public API used to configure a DDS Router and to interact with a running one: -- to create every type of object from a *yaml* node, -- to read a *yaml* file, and -- to interact with a *yaml* object using `YAML::Node` class from `yaml-cpp`. +* **Types**: data types used to configure a router. + * Address + * DDS info (Guid, Qos, Topic, etc.) + +* **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: + * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. + * *DdsRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. + * *DdsRouterReloadConfiguration*: configuration to change topics in a running DDS Router. + +* **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. + It allows to execute a DDS Router, and to interact with it while running. --- ## Example of usage ```cpp -// LOAD DDS ROUTER CONFIGURATION FROM FILE +// START AND STOP DDS ROUTER FROM CONFIGURATION + +core::configuration::DdsRouterConfiguration router_configuration; + +// ... populate router_configuration -core::configuration::DDSRouterConfiguration router_configuration = - yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file("configuration.yaml"); +core::DdsRouter router(router_configuration); +router.start(); + +// ... wait for event + +router.stop(); ``` --- ## Dependencies -* `yaml-cpp` +* `fastrtps` * `cpp_utils` -* `ddsrouter_core` - --- ## How to use it in your project -Just import library `ddsrouter_yaml` into your CMake project. +Just import library `ddsrouter_core` into your CMake project. ```cmake -find_package(ddsrouter_yaml) -target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_yaml) +find_package(ddsrouter_core) +target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_core) ``` diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp index 884b80ad7..025296090 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp @@ -12,64 +12,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file YamlReaderConfiguration.hpp - */ - -#ifndef _DDSROUTERYAML_YAMLREADERCONFIGURATION_HPP_ -#define _DDSROUTERYAML_YAMLREADERCONFIGURATION_HPP_ +#pragma once -#include -#include +#include +#include -#include +#include #include -#include namespace eprosima { namespace ddsrouter { namespace yaml { /** - * @brief Class that encapsulates specific methods to get a full DDSRouter Configuration from a yaml node. + * @brief Class that encapsulates specific methods to get a full DdsRouter Configuration from a yaml node. * * TODO: Add version configuration so it could load different versions */ -class DDSROUTER_YAML_DllAPI Configuration +class DDSROUTER_YAML_DllAPI YamlReaderConfiguration { public: - Configuration(const Yaml& yml); - - Configuration(const std::string& file_path); - - core::configuration::DDSRouterConfiguration configuration; - - using ParticipantConfigurationCollection = - std::vector< - std::pair< - participants::ParticipantKind, std::shared_ptr< - participants::ParticipantConfiguration>>>; - - ParticipantConfigurationCollection participants_configurations; - -protected: - - void load_ddsrouter_configuration_( + static core::DdsRouterConfiguration load_ddsrouter_configuration( const Yaml& yml); - void load_ddsrouter_configuration_from_file_( + static core::DdsRouterConfiguration load_ddsrouter_configuration_from_file( const std::string& file_path); - void load_participant_configurations_( - const Yaml& yml, const YamlReaderVersion& version); +protected: - static YamlReaderVersion default_yaml_version_(); + static ddspipe::yaml::YamlReaderVersion default_yaml_version(); }; } /* namespace yaml */ } /* namespace ddsrouter */ } /* namespace eprosima */ - -#endif /* _DDSROUTERYAML_YAMLREADERCONFIGURATION_HPP_ */ diff --git a/ddsrouter_yaml/package.xml b/ddsrouter_yaml/package.xml index ad457fcaf..fc1f2802c 100644 --- a/ddsrouter_yaml/package.xml +++ b/ddsrouter_yaml/package.xml @@ -4,7 +4,7 @@ ddsrouter_yaml 1.2.0 - *eprosima DDS Router* Yaml Module is a C++ implementation for handling events in multithreading executions as PeriodicTimers, Signals, FileWatchers, etc. + *eprosima DDS Router* C++ library to communicate isolated DDS networks between each other. Use in isolated machines an WAN scenarios. Raul Sánchez-Mateos Javier París @@ -17,11 +17,9 @@ cmake - yamlcpp fastrtps - cpp_utils ddsrouter_core - ddsrouter_participants + ddspipe_yaml cmake_utils doxygen diff --git a/ddsrouter_yaml/project_settings.cmake b/ddsrouter_yaml/project_settings.cmake index 97f758bf7..1d39158e7 100644 --- a/ddsrouter_yaml/project_settings.cmake +++ b/ddsrouter_yaml/project_settings.cmake @@ -20,17 +20,18 @@ set(MODULE_NAME ddsrouter_yaml) set(MODULE_SUMMARY - "C++ library to create a DDS Router configuration from a YAML.") + "C++ library to build and run a DDS Router.") set(MODULE_FIND_PACKAGES - yaml-cpp fastcdr fastrtps cpp_utils - ddsrouter_core - ddsrouter_participants) + ddspipe_core + ddspipe_participants + ddspipe_yaml + ddsrouter_core) -set(ddsrouter_core_MINIMUM_VERSION "1.0") +set(fastrtps_MINIMUM_VERSION "2.8") set(MODULE_DEPENDENCIES $<$:iphlpapi$Shlwapi> diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp deleted file mode 100644 index fb71b847d..000000000 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ /dev/null @@ -1,1030 +0,0 @@ -// Copyright 2022 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 YamlReader.cpp - * - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace yaml { - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/************************ -* GENERIC * -************************/ - -bool YamlReader::is_tag_present( - const Yaml& yml, - const TagType& tag) -{ - if (!yml.IsMap() && !yml.IsNull()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Trying to find a tag: <" << tag << "> in a not yaml object map."); - } - - // Explicit conversion to avoid windows format warning - // This method performace is the same as only retrieving bool - return (yml[tag]) ? true : false; -} - -Yaml YamlReader::get_value_in_tag( - const Yaml& yml, - const TagType& tag) -{ - if (is_tag_present(yml, tag)) - { - return yml[tag]; - } - else - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Required tag not found: <" << tag << ">."); - } -} - -template <> -YamlReaderVersion YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - return get_enumeration( - yml, - { - {VERSION_TAG_V_1_0, YamlReaderVersion::V_1_0}, - {VERSION_TAG_V_2_0, YamlReaderVersion::V_2_0}, - {VERSION_TAG_V_3_0, YamlReaderVersion::V_3_0}, - }); -} - -/************************ -* STANDARD * -************************/ - -template <> -int YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -template <> -unsigned int YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -template <> -bool YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -template <> -std::string YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -/************************ -* ENTITIES * -************************/ - -template <> -TransportProtocol YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - return get_enumeration( - yml, - { - {ADDRESS_TRANSPORT_TCP_TAG, TransportProtocol::tcp}, - {ADDRESS_TRANSPORT_UDP_TAG, TransportProtocol::udp}, - }); -} - -template <> -IpVersion YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - return get_enumeration( - yml, - { - {ADDRESS_IP_VERSION_V4_TAG, IpVersion::v4}, - {ADDRESS_IP_VERSION_V6_TAG, IpVersion::v6}, - }); -} - -template <> -PortType YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // Domain id required - return PortType(get_scalar(yml)); -} - -template <> -DomainId YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // Domain id required - return DomainId(get_scalar(yml)); -} - -template <> -GuidPrefix YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // If guid exists, use it. Non mandatory. - if (is_tag_present(yml, DISCOVERY_SERVER_GUID_TAG)) - { - std::string guid = get_scalar(yml, DISCOVERY_SERVER_GUID_TAG); - return GuidPrefix(guid); - } - - // ROS DS is optional. - bool ros_id; - bool ros_id_set = is_tag_present(yml, DISCOVERY_SERVER_ID_ROS_TAG); - if (ros_id_set) - { - ros_id = get_scalar(yml, DISCOVERY_SERVER_ID_ROS_TAG); - } - - // Id is mandatory if guid is not present - uint32_t id = get_scalar(yml, DISCOVERY_SERVER_ID_TAG); - - // Create GuidPrefix - if (ros_id_set) - { - return GuidPrefix(ros_id, id); - } - else - { - return GuidPrefix(id); - } -} - -template <> -Address YamlReader::get
( - const Yaml& yml, - const YamlReaderVersion version) -{ - // Optional get IP version - IpVersion ip_version; - bool ip_version_set = is_tag_present(yml, ADDRESS_IP_VERSION_TAG); - if (ip_version_set) - { - // Get IP Version from enumeration - ip_version = get(yml, ADDRESS_IP_VERSION_TAG, version); - } - - // Optional get IP - IpType ip; - bool ip_set = is_tag_present(yml, ADDRESS_IP_TAG); - if (ip_set) - { - ip = get(yml, ADDRESS_IP_TAG, version); - } - - // Optional get Domain tag for DNS - std::string domain_name; - bool domain_name_set = is_tag_present(yml, ADDRESS_DNS_TAG); - if (domain_name_set) - { - domain_name = get_scalar(yml, ADDRESS_DNS_TAG); - } - - // If IP and domain_name set, warning that domain_name will not be used - // If only domain_name set, get DNS response - // If neither set, get default - if (ip_set && domain_name_set) - { - logWarning(DDSROUTER_YAML, - "Tag <" << ADDRESS_DNS_TAG << "> will not be used as <" << ADDRESS_IP_TAG << "> is set."); - domain_name_set = false; - } - else if (!ip_set && !domain_name_set) - { - throw eprosima::utils::ConfigurationException(utils::Formatter() << - "Address requires to specify <" << ADDRESS_IP_TAG << "> or <" << ADDRESS_DNS_TAG << ">."); - } - - // Optional get port - PortType port; - bool port_set = is_tag_present(yml, ADDRESS_PORT_TAG); - if (port_set) - { - port = get(yml, ADDRESS_PORT_TAG, version); - } - else - { - port = Address::default_port(); - } - - // WARNING: This adds logic to the parse of the entity, - // This may not be the best place to do so. In the future move this logic to the Address class. - - // Optional get external port - // If it is not set, same as internal port is used - PortType external_port; - bool external_port_set = is_tag_present(yml, ADDRESS_EXTERNAL_PORT_TAG); - if (external_port_set) - { - external_port = get(yml, ADDRESS_EXTERNAL_PORT_TAG, version); - } - else - { - external_port = port; - } - - // Optional get Transport protocol - TransportProtocol tp; - bool tp_set = is_tag_present(yml, ADDRESS_TRANSPORT_TAG); - if (tp_set) - { - tp = get(yml, ADDRESS_TRANSPORT_TAG, version); - } - else - { - tp = Address::default_transport_protocol(); - } - - // Construct Address object - if (domain_name_set) - { - if (ip_version_set) - { - return Address(port, external_port, ip_version, domain_name, tp); - } - else - { - return Address(port, external_port, domain_name, tp); - } - } - else - { - if (ip_version_set) - { - return Address(ip, port, external_port, ip_version, tp); - } - else - { - return Address(ip, port, external_port, tp); - } - } -} - -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_v1( - const Yaml& yml, - const YamlReaderVersion version) -{ - // GuidPrefix required - GuidPrefix server_guid = YamlReader::get(yml, version); - - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(server_guid, addresses); -} - -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_latest( - const Yaml& yml, - const YamlReaderVersion version) -{ - // GuidPrefix required - GuidPrefix server_guid = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); - - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(server_guid, addresses); -} - -template <> -DiscoveryServerConnectionAddress YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - switch (version) - { - case V_1_0: - return _get_discovery_server_connection_address_v1(yml, version); - - default: - return _get_discovery_server_connection_address_latest(yml, version); - } -} - -/************************ -* QoS * -************************/ - -template <> -void YamlReader::fill( - types::TopicQoS& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Reliability optional - if (is_tag_present(yml, QOS_RELIABLE_TAG)) - { - if (get(yml, QOS_RELIABLE_TAG, version)) - { - object.reliability_qos = eprosima::ddsrouter::core::types::ReliabilityKind::RELIABLE; - } - else - { - object.reliability_qos = eprosima::ddsrouter::core::types::ReliabilityKind::BEST_EFFORT; - } - } - - // Durability optional - if (is_tag_present(yml, QOS_TRANSIENT_TAG)) - { - if (get(yml, QOS_TRANSIENT_TAG, version)) - { - object.durability_qos = eprosima::ddsrouter::core::types::DurabilityKind::TRANSIENT_LOCAL; - } - else - { - object.durability_qos = eprosima::ddsrouter::core::types::DurabilityKind::VOLATILE; - } - } - - // History depth optional - if (is_tag_present(yml, QOS_HISTORY_DEPTH_TAG)) - { - object.history_depth = get(yml, QOS_HISTORY_DEPTH_TAG, version); - } - - // Durability optional - if (is_tag_present(yml, QOS_PARTITION_TAG)) - { - object.use_partitions = get(yml, QOS_PARTITION_TAG, version); - } - - // Ownership optional - if (is_tag_present(yml, QOS_OWNERSHIP_TAG)) - { - if (get(yml, QOS_OWNERSHIP_TAG, version)) - { - object.ownership_qos = eprosima::ddsrouter::core::types::OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS; - } - else - { - object.ownership_qos = eprosima::ddsrouter::core::types::OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS; - } - } -} - -/************************ -* TOPICS * -************************/ - -template <> -void YamlReader::fill( - types::Topic& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Name required - object.topic_name = get(yml, TOPIC_NAME_TAG, version); -} - -template <> -void YamlReader::fill( - types::DdsTopic& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Fill parent class - fill(object, yml, version); - - // Data Type required - object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); - - // Optional keyed - if (is_tag_present(yml, TOPIC_KIND_TAG)) - { - object.keyed = get(yml, TOPIC_KIND_TAG, version); - } - - // Optional QoS - if (is_tag_present(yml, TOPIC_QOS_TAG)) - { - fill(object.topic_qos.get_reference(), get_value_in_tag(yml, TOPIC_QOS_TAG), version); - object.topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_hard); - } -} - -template <> -types::DdsTopic YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - types::DdsTopic object; - fill(object, yml, version); - return object; -} - -template <> -void YamlReader::fill( - types::WildcardDdsFilterTopic& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Required name - object.topic_name = get(yml, TOPIC_NAME_TAG, version); - - // Optional data type - if (is_tag_present(yml, TOPIC_TYPE_NAME_TAG)) - { - object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); - } - - // Optional keyed - if (is_tag_present(yml, TOPIC_KIND_TAG)) - { - object.keyed = get(yml, TOPIC_KIND_TAG, version); - } - - // TODO: decide whether we want to use QoS as filtering -} - -template <> -types::WildcardDdsFilterTopic YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - types::WildcardDdsFilterTopic object; - fill(object, yml, version); - return object; -} - -/************************ -* TLS CONFIGURATION * -************************/ - -template <> -void YamlReader::fill( - security::TlsConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Optional private key - if (is_tag_present(yml, TLS_PRIVATE_KEY_TAG)) - { - object.private_key_file = get(yml, TLS_PRIVATE_KEY_TAG, version); - } - - // Optional private key password - if (is_tag_present(yml, TLS_PASSWORD_TAG)) - { - object.private_key_file_password = get(yml, TLS_PASSWORD_TAG, version); - } - - // Optional certificate authority - if (is_tag_present(yml, TLS_CA_TAG)) - { - object.certificate_authority_file = get(yml, TLS_CA_TAG, version); - } - - // Optional certificate chain - if (is_tag_present(yml, TLS_CERT_TAG)) - { - object.certificate_chain_file = get(yml, TLS_CERT_TAG, version); - } - - // Optional SNI server name - if (is_tag_present(yml, TLS_SNI_HOST_TAG)) - { - object.sni_server_name = get(yml, TLS_SNI_HOST_TAG, version); - } - - // Optional dh params - if (is_tag_present(yml, TLS_DHPARAMS_TAG)) - { - object.dh_params_file = get(yml, TLS_DHPARAMS_TAG, version); - } - - // Optional peer verification - if (is_tag_present(yml, TLS_PEER_VERIFICATION_TAG)) - { - object.verify_peer = get(yml, TLS_PEER_VERIFICATION_TAG, version); - } - - // Check if it should be client or server - utils::Formatter dummy_formatter__; - utils::Formatter error_msg_client; - utils::Formatter error_msg_server; - if (object.is_valid_kind(dummy_formatter__)) - { - object.kind = security::TlsKind::both; - } - else if (object.is_valid_kind(error_msg_client)) - { - object.kind = security::TlsKind::client; - } - else if (object.is_valid_kind(error_msg_server)) - { - object.kind = security::TlsKind::server; - } - else - { - throw eprosima::utils::ConfigurationException( - STR_ENTRY << "Incorrect TLS configuration." << - " Could not be client because: " << error_msg_client << - " Neither server because: " << error_msg_server << - "." - ); - } -} - -template <> -security::TlsConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - security::TlsConfiguration object; - fill(object, yml, version); - return object; -} - -/************************ -* PARTICIPANTS * -************************/ - -template <> -participants::ParticipantKind YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - - // Domain id required - return get_enumeration_from_builder(yml, *participants::ParticipantKindBuilder::get_instance()); -} - -////////////////////////////////// -// ParticipantConfiguration -template <> -void YamlReader::fill( - participants::ParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Id required - object.id = get(yml, PARTICIPANT_NAME_TAG, version); -} - -template <> -participants::ParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::ParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// EchoParticipantConfiguration -template <> -void YamlReader::fill( - participants::EchoParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // data optional - if (is_tag_present(yml, ECHO_DATA_TAG)) - { - object.echo_data = get(yml, ECHO_DATA_TAG, version); - } - - // discovery optional - if (is_tag_present(yml, ECHO_DISCOVERY_TAG)) - { - object.echo_discovery = get(yml, ECHO_DISCOVERY_TAG, version); - } - - // verbose optional - if (is_tag_present(yml, ECHO_VERBOSE_TAG)) - { - object.verbose = get(yml, ECHO_VERBOSE_TAG, version); - } -} - -template <> -participants::EchoParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::EchoParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// SimpleParticipantConfiguration -template <> -void YamlReader::fill( - participants::SimpleParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // Domain optional - if (is_tag_present(yml, DOMAIN_ID_TAG)) - { - object.domain = get(yml, DOMAIN_ID_TAG, version); - } -} - -template <> -participants::SimpleParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::SimpleParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// DiscoveryServerParticipantConfiguration -template <> -void YamlReader::fill( - participants::DiscoveryServerParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // Optional listening addresses - if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) - { - object.listening_addresses = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); - } - - // Optional connection addresses - if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) - { - object.connection_addresses = YamlReader::get_set( - yml, - CONNECTION_ADDRESSES_TAG, - version); - } - - // Optional TLS - if (YamlReader::is_tag_present(yml, TLS_TAG)) - { - YamlReader::fill( - object.tls_configuration, - YamlReader::get_value_in_tag(yml, TLS_TAG), - version); - } - - // NOTE: The only field that change regarding the version is the GuidPrefix. - switch (version) - { - case V_1_0: - object.discovery_server_guid_prefix = - YamlReader::get(yml, version); - break; - - default: - object.discovery_server_guid_prefix = - YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); - break; - } -} - -template <> -participants::DiscoveryServerParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::DiscoveryServerParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// InitialPeersParticipantConfiguration -template <> -void YamlReader::fill( - participants::InitialPeersParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // Optional listening addresses - if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) - { - object.listening_addresses = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); - } - - // Optional connection addresses - if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) - { - object.connection_addresses = YamlReader::get_set( - yml, - CONNECTION_ADDRESSES_TAG, - version); - } - - // Optional TLS - if (YamlReader::is_tag_present(yml, TLS_TAG)) - { - YamlReader::fill( - object.tls_configuration, - YamlReader::get_value_in_tag(yml, TLS_TAG), - version); - } - - // Optional Repeater - if (YamlReader::is_tag_present(yml, IS_REPEATER_TAG)) - { - object.is_repeater = YamlReader::get(yml, IS_REPEATER_TAG, version); - } -} - -template <> -participants::InitialPeersParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::InitialPeersParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// SpecsConfiguration -template <> -void YamlReader::fill( - configuration::SpecsConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - ///// - // Get optional number of threads - if (YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG)) - { - object.number_of_threads = YamlReader::get(yml, NUMBER_THREADS_TAG, version); - } - - ///// - // Get optional maximum history depth - if (YamlReader::is_tag_present(yml, MAX_HISTORY_DEPTH_TAG)) - { - object.max_history_depth = YamlReader::get(yml, MAX_HISTORY_DEPTH_TAG, version); - } -} - -/*************************** - * DDS ROUTER CONFIGURATION * - ****************************/ - -void _fill_ddsrouter_configuration_v1( - core::configuration::DDSRouterConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - ///// - // Get optional allowlist - if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) - { - object.allowlist = utils::convert_set_to_shared( - YamlReader::get_set(yml, ALLOWLIST_TAG, version)); - } - - ///// - // Get optional blocklist - if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) - { - object.blocklist = utils::convert_set_to_shared( - YamlReader::get_set(yml, BLOCKLIST_TAG, version)); - } - - ///// - // Get builtin topics from allowlist - for (const std::shared_ptr& topic : object.allowlist) - { - auto wildcard_topic = std::dynamic_pointer_cast(topic); - - if (wildcard_topic) - { - if (DdsTopic::is_valid_dds_topic(wildcard_topic->topic_name, wildcard_topic->type_name)) - { - auto real_topic = std::make_shared( - wildcard_topic->topic_name, - wildcard_topic->type_name); - - if (wildcard_topic->keyed.is_set()) - { - real_topic->keyed = wildcard_topic->keyed; - } - - object.builtin_topics.emplace(real_topic); - } - } - - } - - ///// - // Get participants configurations from this yaml level - for (Yaml::const_iterator participant_it = yml.begin(); - participant_it != yml.end(); - ++participant_it) - { - std::string name_str = participant_it->first.as(); - - // Check if it is not a key word - if (is_tag(name_str)) - { - continue; - } - - // WORKAROUND: the name is not in the participant, as it is the key - // In order to avoid creating a new ParticipantConfiguration get method for this version, - // hack the participant info so it is read by latest versions - Yaml participant_yml = participant_it->second; - - // Check the participant is correct - // It must be a map - if (!participant_yml.IsMap()) - { - throw eprosima::utils::ConfigurationException("Each Participant block must be a map."); - } - // It must have "type" tag - if (!participant_yml[PARTICIPANT_KIND_TAG_V1]) - { - throw eprosima::utils::ConfigurationException( - STR_ENTRY << - "Each Participant block must have <" << PARTICIPANT_KIND_TAG_V1 << - "> tag with Participant Kind."); - } - - // Set name - participant_yml[PARTICIPANT_NAME_TAG] = name_str; - // Set kind from type tag - participant_yml[PARTICIPANT_KIND_TAG] = participant_yml[PARTICIPANT_KIND_TAG_V1]; - - // Participants configurations are no longer in Router configuration - // Also old yaml versions will be deprecated, so lets not worry about this for now - } -} - -void _fill_ddsrouter_configuration_latest( - core::configuration::DDSRouterConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - ///// - // Get optional allowlist - if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) - { - object.allowlist = utils::convert_set_to_shared( - YamlReader::get_set(yml, ALLOWLIST_TAG, version)); - } - - ///// - // Get optional blocklist - if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) - { - object.blocklist = utils::convert_set_to_shared( - YamlReader::get_set(yml, BLOCKLIST_TAG, version)); - } - - ///// - // Get optional builtin topics - if (YamlReader::is_tag_present(yml, BUILTIN_TAG)) - { - object.builtin_topics = utils::convert_set_to_shared( - YamlReader::get_set(yml, BUILTIN_TAG, version)); - } - - // Participants configurations are no longer in Router configuration - - ///// - // Get optional specs configuration - if (YamlReader::is_tag_present(yml, SPECS_TAG)) - { - YamlReader::fill( - object.advanced_options, - YamlReader::get_value_in_tag(yml, SPECS_TAG), - version); - } -} - -template <> -core::configuration::DDSRouterConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - core::configuration::DDSRouterConfiguration object; - switch (version) - { - case V_1_0: - _fill_ddsrouter_configuration_v1(object, yml, version); - break; - - case V_2_0: - default: - _fill_ddsrouter_configuration_latest(object, yml, version); - break; - } - return object; -} - -std::ostream& operator <<( - std::ostream& os, - const YamlReaderVersion& version) -{ - switch (version) - { - case V_1_0: - os << VERSION_TAG_V_1_0; - break; - - case V_2_0: - os << VERSION_TAG_V_2_0; - break; - - case V_3_0: - case LATEST: - os << VERSION_TAG_V_3_0; - break; - - default: - utils::tsnh(STR_ENTRY << "Value of YamlReaderVersion out of enumeration."); - break; - } - - return os; -} - -} /* namespace yaml */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp deleted file mode 100644 index 73e979d12..000000000 --- a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2022 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 YamlReaderConfiguration.cpp - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddsrouter { -namespace yaml { - -using namespace eprosima::ddsrouter::core; - -Configuration::Configuration (const Yaml& yml) -{ - load_ddsrouter_configuration_(yml); -} - -Configuration::Configuration (const std::string& file_path) -{ - load_ddsrouter_configuration_from_file_(file_path); -} - -void Configuration::load_ddsrouter_configuration_( - const Yaml& yml) -{ - try - { - YamlReaderVersion version; - // Get version if present - if (YamlReader::is_tag_present(yml, VERSION_TAG)) - { - version = YamlReader::get(yml, VERSION_TAG, LATEST); - } - else - { - // Get default version - version = default_yaml_version_(); - logWarning(DDSROUTER_YAML, - "No version of yaml configuration given. Using version " << version << " by default. " << - "Add " << VERSION_TAG << " tag to your configuration in order to not break compatibility " << - "in future releases."); - } - logInfo(DDSROUTER_YAML, "Loading DDSRouter configuration with version: " << version << "."); - - // Load DDS Router Configuration - configuration = - yaml::YamlReader::get(yml, version); - - ///// - // Load Participants Configurations - load_participant_configurations_(yml, version); - - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error loading DDS Router configuration from yaml:\n " << e.what()); - } -} - -void Configuration::load_ddsrouter_configuration_from_file_( - const std::string& file_path) -{ - yaml::Yaml yml; - - // Load file - try - { - yml = yaml::YamlManager::load_file(file_path); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error loading DDSRouter configuration from file: <" << file_path << - "> :\n " << e.what()); - } - - Configuration::load_ddsrouter_configuration_(yml); -} - -void Configuration::load_participant_configurations_( - const Yaml& yml, - const YamlReaderVersion& version) -{ - // Get participants configurations. Required field, if get_value_in_tag fail propagate exception. - auto participants_configurations_yml = YamlReader::get_value_in_tag(yml, COLLECTION_PARTICIPANTS_TAG); - - // TODO do it in a single instruction - // Check it is a list - if (!participants_configurations_yml.IsSequence()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Participant configurations must be specified in an array under tag: " << - COLLECTION_PARTICIPANTS_TAG); - } - - for (auto conf : participants_configurations_yml) - { - // Get kind - participants::ParticipantKind kind = YamlReader::get(conf, PARTICIPANT_KIND_TAG, version); - - // Get Participant - std::shared_ptr configuration; - - logInfo(DDSROUTER_YAML_CONFIGURATION, "Loading Participant of kind " << kind << "."); - - switch (kind) - { - case participants::ParticipantKind::echo: - configuration = - std::make_shared( - YamlReader::get(conf, version)); - break; - - case participants::ParticipantKind::simple: - configuration = - std::make_shared( - YamlReader::get(conf, version)); - break; - - case participants::ParticipantKind::discovery_server: - configuration = - std::make_shared( - YamlReader::get(conf, version)); - break; - - case participants::ParticipantKind::initial_peers: - configuration = - std::make_shared( - YamlReader::get(conf, version)); - break; - - // No default possible - } - - participants_configurations.emplace_back( - kind, - std::move(configuration)); - } -} - -YamlReaderVersion Configuration::default_yaml_version_() -{ - return V_1_0; -} - -} /* namespace yaml */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/ddsrouter_yaml/src/cpp/_dummy.cpp b/ddsrouter_yaml/src/cpp/_dummy.cpp new file mode 100644 index 000000000..d353d8800 --- /dev/null +++ b/ddsrouter_yaml/src/cpp/_dummy.cpp @@ -0,0 +1,8 @@ + +#include +#include +#include +#include +#include +#include +#include diff --git a/ddsrouter_yaml/src/cpp/yaml_configuration_tags.cpp b/ddsrouter_yaml/src/cpp/yaml_configuration_tags.cpp deleted file mode 100644 index 1f65104ac..000000000 --- a/ddsrouter_yaml/src/cpp/yaml_configuration_tags.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2022 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 yaml_configuration_tags.cpp - * - */ - -#include - -#include - -namespace eprosima { -namespace ddsrouter { -namespace yaml { - -std::set ddsrouter_tags() noexcept -{ - return - { - ALLOWLIST_TAG, - BLOCKLIST_TAG, - TOPIC_NAME_TAG, - TOPIC_TYPE_NAME_TAG, - TOPIC_KIND_TAG, - PARTICIPANT_KIND_TAG, - PARTICIPANT_NAME_TAG, - COLLECTION_PARTICIPANTS_TAG, - DOMAIN_ID_TAG, - DISCOVERY_SERVER_GUID_PREFIX_TAG, - LISTENING_ADDRESSES_TAG, - CONNECTION_ADDRESSES_TAG, - COLLECTION_ADDRESSES_TAG, - TLS_TAG, - TLS_CA_TAG, - TLS_PASSWORD_TAG, - TLS_PRIVATE_KEY_TAG, - TLS_CERT_TAG, - TLS_DHPARAMS_TAG, - TLS_SNI_HOST_TAG, - ADDRESS_IP_TAG, - ADDRESS_DNS_TAG, - ADDRESS_PORT_TAG, - ADDRESS_IP_VERSION_TAG, - ADDRESS_IP_VERSION_V4_TAG, - ADDRESS_IP_VERSION_V6_TAG, - ADDRESS_TRANSPORT_TAG, - ADDRESS_TRANSPORT_UDP_TAG, - ADDRESS_TRANSPORT_TCP_TAG, - DISCOVERY_SERVER_GUID_TAG, - DISCOVERY_SERVER_ID_TAG, - DISCOVERY_SERVER_ID_ROS_TAG, - VERSION_TAG, - VERSION_TAG_V_1_0, - VERSION_TAG_V_2_0, - VERSION_TAG_V_3_0, - PARTICIPANT_KIND_TAG_V1, - }; -} - -bool is_tag( - const std::string& str) noexcept -{ - std::set tags = ddsrouter_tags(); - return tags.find(str) != tags.end(); -} - -} /* namespace yaml */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ diff --git a/tools/ddsrouter_tool/package.xml b/tools/ddsrouter_tool/package.xml index e8025be79..0fd8d9d7c 100644 --- a/tools/ddsrouter_tool/package.xml +++ b/tools/ddsrouter_tool/package.xml @@ -17,12 +17,6 @@ cmake - yamlcpp - fastrtps - cpp_utils - - ddsrouter_core - ddsrouter_participants ddsrouter_yaml doxygen diff --git a/tools/ddsrouter_tool/project_settings.cmake b/tools/ddsrouter_tool/project_settings.cmake index 0ee69d4ee..7f5c8716f 100644 --- a/tools/ddsrouter_tool/project_settings.cmake +++ b/tools/ddsrouter_tool/project_settings.cmake @@ -27,9 +27,11 @@ set(MODULE_FIND_PACKAGES fastcdr fastrtps cpp_utils + ddspipe_core + ddspipe_participants + ddspipe_yaml ddsrouter_core ddsrouter_yaml - ddsrouter_participants ) set(MODULE_DEPENDENCIES diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index 205a5308c..320483553 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -28,15 +28,10 @@ #include #include -#include -#include -#include -#include - -#include +#include +#include #include -#include #include "user_interface/constants.hpp" #include "user_interface/arguments_configuration.hpp" @@ -147,48 +142,17 @@ int main( ///// // DDS Router Initialization - // Load Configuration from YAML - yaml::Configuration configuration(file_path); - core::configuration::DDSRouterConfiguration router_configuration = configuration.configuration; - - // Create Payload Pool - std::shared_ptr payload_pool = - std::make_shared(); - - // Create Discovery Database - std::shared_ptr discovery_database = - std::make_shared(); - - // Create and populate Participant Database - std::shared_ptr participant_database = - std::make_shared(); - - // Populate Participant Database - for (const auto& part_conf : configuration.participants_configurations) - { - participant_database->add_participant( - part_conf.second->id, - participants::ParticipantFactory::create_participant( - part_conf.first, - part_conf.second, - payload_pool, - discovery_database - ) - ); - } + // Load DDS Router Configuration + core::DdsRouterConfiguration router_configuration = + yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(file_path); // Create DDS Router - core::DDSRouter router( - router_configuration, - discovery_database, - payload_pool, - participant_database - ); + core::DdsRouter router(router_configuration); ///// // File Watcher Handler - // Callback will reload configuration and pass it to DDSRouter + // Callback will reload configuration and pass it to DdsRouter // WARNING: it is needed to pass file_path, as FileWatcher only retrieves file_name std::function filewatcher_callback = [&router, file_path] @@ -200,8 +164,9 @@ int main( try { - yaml::Configuration new_configuration(file_path); - router.reload_configuration(new_configuration.configuration); + core::DdsRouterConfiguration router_configuration = + yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(file_path); + router.reload_configuration(router_configuration); } catch (const std::exception& e) { @@ -223,7 +188,7 @@ int main( // If reload time is higher than 0, create a periodic event to reload configuration if (reload_time > 0) { - // Callback will reload configuration and pass it to DDSRouter + // Callback will reload configuration and pass it to DdsRouter std::function periodic_callback = [&router, file_path] () @@ -234,8 +199,9 @@ int main( try { - yaml::Configuration new_configuration(file_path); - router.reload_configuration(new_configuration.configuration); + core::DdsRouterConfiguration router_configuration = + yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(file_path); + router.reload_configuration(router_configuration); } catch (const std::exception& e) { diff --git a/tools/ddsrouter_tool/src/cpp/user_interface/arguments_configuration.cpp b/tools/ddsrouter_tool/src/cpp/user_interface/arguments_configuration.cpp index 012ca3638..1eb5e562f 100644 --- a/tools/ddsrouter_tool/src/cpp/user_interface/arguments_configuration.cpp +++ b/tools/ddsrouter_tool/src/cpp/user_interface/arguments_configuration.cpp @@ -164,7 +164,7 @@ const option::Descriptor usage[] = { void print_version() { - std::cout << "DDSRouter " << DDSROUTER_CORE_VERSION_STRING << "\ncommit hash: " << DDSROUTER_CORE_COMMIT_HASH << + std::cout << "DdsRouter " << DDSROUTER_CORE_VERSION_STRING << "\ncommit hash: " << DDSROUTER_CORE_COMMIT_HASH << std::endl; } diff --git a/tools/ddsrouter_tool/src/cpp/user_interface/constants.hpp b/tools/ddsrouter_tool/src/cpp/user_interface/constants.hpp index 1da7607db..94a1d4b3a 100644 --- a/tools/ddsrouter_tool/src/cpp/user_interface/constants.hpp +++ b/tools/ddsrouter_tool/src/cpp/user_interface/constants.hpp @@ -25,7 +25,7 @@ namespace eprosima { namespace ddsrouter { namespace ui { -//! Default DDSRouter configuration file +//! Default DdsRouter configuration file constexpr const char* DEFAULT_CONFIGURATION_FILE_NAME("DDS_ROUTER_CONFIGURATION.yaml"); } /* namespace ui */ From 9b0a1803aae9f219b15c5507a6053c1300c8dcfa Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 13 Feb 2023 16:13:43 +0100 Subject: [PATCH 06/38] Implementation of src of ddspipe_core Signed-off-by: jparisu --- .../ddspipe_core/communication/Bridge.hpp | 2 +- .../communication/dds/DdsBridge.hpp | 10 +- .../ddspipe_core/communication/dds/Track.hpp | 4 + .../communication/rpc/RPCBridge.hpp | 13 +- ...seConfiguration.hpp => IConfiguration.hpp} | 2 +- .../include/ddspipe_core/core/DdsPipe.hpp | 35 +- .../ddspipe_core/dynamic/AllowedTopicList.hpp | 16 +- .../dynamic/DiscoveryDatabase.hpp | 2 +- .../cache_change/CacheChangePool.hpp | 64 --- .../ddspipe_core/interface/IReader.hpp | 6 + .../include/ddspipe_core/interface/ITopic.hpp | 19 +- .../ddspipe_core/testing/test_utils.hpp | 94 +--- .../types/data/RpcPayloadData.hpp | 18 +- .../types/data/RtpsPayloadData.hpp | 13 +- .../ddspipe_core/types/dds/DomainId.hpp | 2 +- .../ddspipe_core/types/dds/Endpoint.hpp | 17 +- .../ddspipe_core/types/dds/GuidPrefix.hpp | 14 +- .../ddspipe_core/types/topic/Topic.hpp | 18 +- .../ddspipe_core/types/topic/dds/DdsTopic.hpp | 22 +- .../types/topic/dds/DistributedTopic.hpp | 7 - .../topic/filter/WildcardDdsFilterTopic.hpp | 13 +- .../ddspipe_core/types/topic/rpc/RpcTopic.hpp | 2 + ddspipe_core/src/cpp/_dummy.cpp | 2 - .../cpp/communication/Bridge.cpp | 21 +- .../cpp/communication/dds/DdsBridge.cpp} | 79 +--- .../cpp/communication/dds}/Track.cpp | 28 +- .../cpp/communication/rpc/RPCBridge.cpp | 134 ++---- .../cpp/communication/rpc/ServiceRegistry.cpp | 2 +- .../cpp/core/DdsPipe.cpp} | 238 ++++------ .../cpp/dynamic/AllowedTopicList.cpp | 36 +- .../cpp/dynamic/DiscoveryDatabase.cpp | 18 +- .../cpp/dynamic/ParticipantsDatabase.cpp | 16 +- .../efficiency/payload/CopyPayloadPool.cpp | 2 +- .../efficiency/payload/FastPayloadPool.cpp | 2 +- .../cpp/efficiency/payload/MapPayloadPool.cpp | 2 +- .../cpp/efficiency/payload/PayloadPool.cpp | 2 +- ddspipe_core/src/cpp/testing/test_utils.cpp | 70 +++ .../{src_ => src}/cpp/types/dds/DomainId.cpp | 46 +- ddspipe_core/src/cpp/types/dds/Endpoint.cpp | 64 +++ .../{src_ => src}/cpp/types/dds/Guid.cpp | 5 - .../cpp/types/dds/GuidPrefix.cpp | 14 +- .../data => src/cpp/types/dds}/Payload.cpp | 5 - .../cpp/types/dds/SpecificEndpointQoS.cpp | 0 .../{src_ => src}/cpp/types/dds/TopicQoS.cpp | 0 .../{src_ => src}/cpp/types/topic/Topic.cpp | 52 ++- .../cpp/types/topic/dds/DdsTopic.cpp | 85 ++-- .../cpp/types/topic/filter/IFilterTopic.cpp} | 17 +- .../topic/filter/WildcardDdsFilterTopic.cpp | 74 ++- .../cpp/types/topic/rpc/RPCTopic.cpp | 48 +- .../configuration/DDSRouterConfiguration.cpp | 63 --- .../DDSRouterReloadConfiguration.cpp | 88 ---- .../cpp/configuration/SpecsConfiguration.cpp | 45 -- .../cache_change/CacheChangePool.cpp | 49 -- ddspipe_core/src_/cpp/testing/test_utils.cpp | 275 ----------- .../src_/cpp/types/address/Address.cpp | 442 ------------------ .../DiscoveryServerConnectionAddress.cpp | 101 ---- .../src_/cpp/types/data/RtpsPayloadData.cpp | 34 -- .../src_/cpp/types/endpoint/Endpoint.cpp | 160 ------- .../types/security/tls/TlsConfiguration.cpp | 211 --------- .../ParticipantConfiguration.hpp | 4 +- .../types/dds/RouterCacheChange.hpp | 0 .../types/security/tls/TlsConfiguration.hpp | 4 +- .../DdsRouterReloadConfiguration.hpp | 4 +- .../configuration/SpecsConfiguration.hpp | 4 +- 64 files changed, 632 insertions(+), 2307 deletions(-) rename ddspipe_core/include/ddspipe_core/configuration/{BaseConfiguration.hpp => IConfiguration.hpp} (98%) delete mode 100644 ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp rename {ddspipe_participants/include/ddspipe_participants => ddspipe_core/include/ddspipe_core}/types/data/RpcPayloadData.hpp (80%) rename {ddspipe_participants/include/ddspipe_participants => ddspipe_core/include/ddspipe_core}/types/data/RtpsPayloadData.hpp (89%) delete mode 100644 ddspipe_core/src/cpp/_dummy.cpp rename ddspipe_core/{src_ => src}/cpp/communication/Bridge.cpp (72%) rename ddspipe_core/{src_/cpp/communication/DDSBridge.cpp => src/cpp/communication/dds/DdsBridge.cpp} (63%) rename ddspipe_core/{src_/cpp/communication => src/cpp/communication/dds}/Track.cpp (92%) rename ddspipe_core/{src_ => src}/cpp/communication/rpc/RPCBridge.cpp (74%) rename ddspipe_core/{src_ => src}/cpp/communication/rpc/ServiceRegistry.cpp (98%) rename ddspipe_core/{src_/cpp/core/DDSRouterImpl.cpp => src/cpp/core/DdsPipe.cpp} (59%) rename ddspipe_core/{src_ => src}/cpp/dynamic/AllowedTopicList.cpp (75%) rename ddspipe_core/{src_ => src}/cpp/dynamic/DiscoveryDatabase.cpp (95%) rename ddspipe_core/{src_ => src}/cpp/dynamic/ParticipantsDatabase.cpp (83%) rename ddspipe_core/{src_ => src}/cpp/efficiency/payload/CopyPayloadPool.cpp (97%) rename ddspipe_core/{src_ => src}/cpp/efficiency/payload/FastPayloadPool.cpp (98%) rename ddspipe_core/{src_ => src}/cpp/efficiency/payload/MapPayloadPool.cpp (98%) rename ddspipe_core/{src_ => src}/cpp/efficiency/payload/PayloadPool.cpp (98%) create mode 100644 ddspipe_core/src/cpp/testing/test_utils.cpp rename ddspipe_core/{src_ => src}/cpp/types/dds/DomainId.cpp (55%) create mode 100644 ddspipe_core/src/cpp/types/dds/Endpoint.cpp rename ddspipe_core/{src_ => src}/cpp/types/dds/Guid.cpp (98%) rename ddspipe_core/{src_ => src}/cpp/types/dds/GuidPrefix.cpp (85%) rename ddspipe_core/{src_/cpp/types/data => src/cpp/types/dds}/Payload.cpp (97%) rename ddspipe_core/{src_ => src}/cpp/types/dds/SpecificEndpointQoS.cpp (100%) rename ddspipe_core/{src_ => src}/cpp/types/dds/TopicQoS.cpp (100%) rename ddspipe_core/{src_ => src}/cpp/types/topic/Topic.cpp (54%) rename ddspipe_core/{src_ => src}/cpp/types/topic/dds/DdsTopic.cpp (58%) rename ddspipe_core/{src_/cpp/types/topic/filter/DdsFilterTopic.cpp => src/cpp/types/topic/filter/IFilterTopic.cpp} (78%) rename ddspipe_core/{src_ => src}/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp (67%) rename ddspipe_core/{src_ => src}/cpp/types/topic/rpc/RPCTopic.cpp (66%) delete mode 100644 ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp delete mode 100644 ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp delete mode 100644 ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp delete mode 100644 ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp delete mode 100644 ddspipe_core/src_/cpp/testing/test_utils.cpp delete mode 100644 ddspipe_core/src_/cpp/types/address/Address.cpp delete mode 100644 ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp delete mode 100644 ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp delete mode 100644 ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp delete mode 100644 ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp rename {ddspipe_core/src_/cpp => ddspipe_participants/include/ddspipe_participants}/types/dds/RouterCacheChange.hpp (100%) diff --git a/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp index 8f8a8512b..830070475 100644 --- a/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp @@ -72,7 +72,7 @@ class Bridge protected: //! Topic that refers to this Bridge - const std::shared_ptr topic; + const std::shared_ptr topic_; //! Collection of Participants to manage communication const std::shared_ptr participants_; diff --git a/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp index cccf02134..8367879b2 100644 --- a/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp @@ -56,6 +56,8 @@ class DdsBridge : public Bridge const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool); + ~DdsBridge(); + /** * Enable bridge in case it is not enabled * Does nothing if it is already enabled @@ -80,14 +82,8 @@ class DdsBridge : public Bridge */ std::map> tracks_; - //! One writer for each Participant, indexed by \c ParticipantId of the Participant the writer belongs to - std::map> writers_; - - //! One reader for each Participant, indexed by \c ParticipantId of the Participant the reader belongs to - std::map> readers_; - //! Mutex to prevent simultaneous calls to enable and/or disable - std::recursive_mutex mutex_; + std::mutex mutex_; // Allow operator << to use private variables friend std::ostream& operator <<( diff --git a/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp index 8ca78f9fc..212bf0e14 100644 --- a/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace eprosima { namespace ddspipe { @@ -139,6 +140,9 @@ class Track */ void transmit_() noexcept; + //! Topic that refers to this Bridge + const std::shared_ptr topic_; + /** * @brief Id of the Participant of the Reader * diff --git a/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp index 65debfb27..e7d11ea4e 100644 --- a/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp @@ -57,10 +57,10 @@ class RPCBridge : public Bridge * @note Always created disabled, manual enable required. First enable creates all endpoints. */ RPCBridge( - const types::RpcTopic& topic, - std::shared_ptr participants_database, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool); + const std::shared_ptr& topic, + const std::shared_ptr& participants_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool); /** * @brief Destructor @@ -152,9 +152,6 @@ class RPCBridge : public Bridge //! Whether there are any servers in the database bool servers_available_() const noexcept; - //! RpcTopic (service) that this bridge manages communication - const types::RpcTopic topic_; - //! Flag set to true when proxy clients and servers are created, so it can only be done once bool init_; @@ -188,6 +185,8 @@ class RPCBridge : public Bridge */ std::shared_timed_mutex on_transmission_mutex_; + std::shared_ptr rpc_topic_; + // Allow operator << to use private variables friend std::ostream& operator <<( std::ostream&, diff --git a/ddspipe_core/include/ddspipe_core/configuration/BaseConfiguration.hpp b/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp similarity index 98% rename from ddspipe_core/include/ddspipe_core/configuration/BaseConfiguration.hpp rename to ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp index 210c6a86e..a0821a7fb 100644 --- a/ddspipe_core/include/ddspipe_core/configuration/BaseConfiguration.hpp +++ b/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp @@ -27,7 +27,7 @@ namespace core { * Thus, they are not forced to be correct in construction. * This is an Interface class that forces every configuration to have an \c is_valid method. */ -struct BaseConfiguration +struct IConfiguration { DDSPIPE_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept = 0; diff --git a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp index dafc57666..5754b5bab 100644 --- a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp +++ b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp @@ -147,17 +147,10 @@ class DdsPipe ///// // INTERNAL INITIALIZATION METHODS - /** - * @brief Load allowed topics from configuration - * - * @throw \c ConfigurationException in case the yaml inside allowlist is not well-formed - */ - void init_allowed_topics_(); - /** * @brief Create a disabled bridge for every real topic */ - void init_bridges_(); + void init_bridges_(const std::set>& builtin_topics); ///// // INTERNAL AUXILIAR METHODS @@ -173,7 +166,7 @@ class DdsPipe * @param [in] topic : topic discovered */ void discovered_topic_( - const types::DistributedTopic& topic) noexcept; + const std::shared_ptr& topic) noexcept; /** * @brief Method called every time a new endpoint (corresponding to a server) has been discovered/updated @@ -188,7 +181,7 @@ class DdsPipe * @param [in] server_guid_prefix : GUID Prefix of discovered server */ void discovered_service_( - const types::RpcTopic& topic, + const std::shared_ptr& topic, const types::ParticipantId& server_participant_id, const types::GuidPrefix& server_guid_prefix) noexcept; @@ -202,7 +195,7 @@ class DdsPipe * @param [in] server_guid_prefix : GUID Prefix of discovered server */ void removed_service_( - const types::RpcTopic& topic, + const std::shared_ptr& topic, const types::ParticipantId& server_participant_id, const types::GuidPrefix& server_guid_prefix) noexcept; @@ -231,8 +224,8 @@ class DdsPipe * * @param [in] topic : new topic */ - void create_new_bridge( - const types::DistributedTopic& topic, + void create_new_bridge_( + const std::shared_ptr& topic, bool enabled = false) noexcept; /** @@ -242,8 +235,8 @@ class DdsPipe * * @param [in] topic : new topic */ - void create_new_service( - const types::RpcTopic& topic) noexcept; + void create_new_service_( + const std::shared_ptr& topic) noexcept; /** * @brief Enable a specific topic @@ -253,7 +246,7 @@ class DdsPipe * @param [in] topic : Topic to be enabled */ void activate_topic_( - const types::DistributedTopic& topic) noexcept; + const std::shared_ptr& topic) noexcept; /** * @brief Disable a specific topic. @@ -263,7 +256,7 @@ class DdsPipe * @param [in] topic : Topic to be disabled */ void deactivate_topic_( - const types::DistributedTopic& topic) noexcept; + const std::shared_ptr& topic) noexcept; /** * @brief Activate all Topics that are allowed by the allowed topics list @@ -313,10 +306,10 @@ class DdsPipe ///////////////////////// //! Map of bridges indexed by their topic - std::map> bridges_; + std::map, std::unique_ptr> bridges_; //! Map of RPC bridges indexed by their topic - std::map> rpc_bridges_; + std::map, std::unique_ptr> rpc_bridges_; /** * @brief List of topics discovered @@ -324,7 +317,7 @@ class DdsPipe * Every topic discovered would be added to this map. * If the value is true, it means this topic is currently activated. */ - std::map current_topics_; + std::map, bool> current_topics_; /** * @brief List of RPC topics discovered @@ -332,7 +325,7 @@ class DdsPipe * Every RPC topic discovered would is added to this map. * If the value is true, it means this service is allowed. */ - std::map current_services_; + std::map, bool> current_services_; ///// // AUXILIAR VARIABLES diff --git a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp index 229197193..cdeda252b 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -46,8 +48,8 @@ class AllowedTopicList //! Constructor by initialization lists AllowedTopicList( - const std::set>& allowlist, - const std::set>& blocklist) noexcept; + const std::set>& allowlist, + const std::set>& blocklist) noexcept; //! Copy constructor. It copies internal lists. AllowedTopicList& operator =( @@ -72,7 +74,7 @@ class AllowedTopicList * @return True if the topic is allowed, false otherwise */ bool is_topic_allowed( - const types::DistributedTopic& topic) const noexcept; + const ITopic& topic) const noexcept; /** * Whether RpcTopic \c topic is allowed by the lists that constitute this object @@ -111,14 +113,14 @@ class AllowedTopicList * @param [in] list: list of topics with redundancy * @return Set of topics without redundancy */ - static std::set> get_topic_list_without_repetition_( - const std::set>& list) noexcept; + static std::set> get_topic_list_without_repetition_( + const std::set>& list) noexcept; //! List of topics that are not allowed - std::set> blocklist_; + std::set> blocklist_; //! List of topics that are allowed - std::set> allowlist_; + std::set> allowlist_; //! Mutex to restrict access to the class mutable std::recursive_mutex mutex_; diff --git a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp index aa65944c6..31fe6db18 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp @@ -90,7 +90,7 @@ class DiscoveryDatabase * @return true if any endpoint has this topic, false otherwise */ bool topic_exists( - const types::DistributedTopic& topic) const noexcept; + const types::DdsTopic& topic) const noexcept; //! Whether this guid is in the database bool endpoint_exists( diff --git a/ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp deleted file mode 100644 index 88b62477e..000000000 --- a/ddspipe_core/include/ddspipe_core/efficiency/cache_change/CacheChangePool.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief This class implements a pool of CacheChange objects specialized as RouterCacheChanges. - * - * It reuses the UnboundedPool implementation, what allow to create an unbounded reusable pool. - * - * TODO: implement this class as an IPool (or having an internal pool), without being force to be unbounded. - */ -class CacheChangePool : public fastrtps::rtps::IChangePool, public utils::UnboundedPool -{ -public: - - /** - * @brief Construct a new Cache Change Pool object from a Pool Configuration - * - * @param configuration pool configuration - * - * @warning max size will not be used as it is Unbounded - */ - CacheChangePool( - utils::PoolConfiguration configuration); - - //! Call UnboundedPool::reserve - virtual bool reserve_cache( - fastrtps::rtps::CacheChange_t*& cache_change) override; - - //! Call UnboundedPool::release - virtual bool release_cache( - fastrtps::rtps::CacheChange_t* cache_change) override; - -protected: - - //! Override the UnboundedPool::create_element method to create a RouterCacheChange object. - virtual fastrtps::rtps::CacheChange_t* new_element_() override; - -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp index 3ba8018a5..17945d5da 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp @@ -22,6 +22,8 @@ #include #include +#include +#include namespace eprosima { namespace ddspipe { @@ -115,6 +117,10 @@ class IReader //! Get number of unread cache changes in internal RTPS reader virtual uint64_t get_unread_count() const noexcept = 0; + + virtual types::DdsTopic topic() const noexcept = 0; + + virtual types::ParticipantId participant_id() const noexcept = 0; ///////////////////////// }; diff --git a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp index 4a79fd57f..cacf12f34 100644 --- a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp @@ -38,21 +38,18 @@ class ITopic */ virtual ~ITopic() = default; - /** - * @brief Compare 2 ITopics - * - * @note this method should be specialized for each subclass so it can differentiate between specific fields. - * 2 different Topic kinds should not have same discriminator, and if possible same topic name. - * - * @param [in] other other topic to compare this with - * @return true if both topics are the same - * @return false otherwise - */ - virtual bool operator==(const ITopic& other) const noexcept; + virtual bool operator < ( + const ITopic& other) const noexcept = 0; + + virtual bool operator == ( + const ITopic& other) const noexcept = 0; //! ITopic name virtual const std::string& topic_name() const noexcept = 0; + //! ITopic unique name in processs + virtual std::string topic_unique_name() const noexcept = 0; + /** * This refers to an internal used identifier that declares which kind of data type is going to be * transmitted in this Itopic inside the core. diff --git a/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp b/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp index 31b3aba69..fe2788820 100644 --- a/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp +++ b/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp @@ -16,30 +16,16 @@ #include -#include -#include -#include -#include -#include #include #include #include -#include -#include -#include +#include namespace eprosima { namespace ddspipe { namespace core { namespace test { -using namespace eprosima::ddsrouter::core::types; - -// TODO: most of the methods from this test_utils that generate random types are not very "random". -// They must be refactored to generate real random values. - -constexpr const int TEST_NUMBER_ITERATIONS = 5; - /** * @brief Create a \c Guid with some of its bits determined by the input * @@ -48,80 +34,18 @@ constexpr const int TEST_NUMBER_ITERATIONS = 5; * @todo Make truly random using \c seed as such * */ -Guid random_guid( - uint16_t seed = 1); - -struct TopicInput -{ - TopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set); - - std::string name; - std::string type; - bool keyed; - bool key_set; -}; - -struct DdsTopicInput : public TopicInput -{ - DdsTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool reliable, - bool reliable_set); - - bool reliable; - bool reliable_set; -}; - -struct WildcardTopicInput : public TopicInput -{ - WildcardTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool type_set); +types::Guid random_guid( + unsigned int seed = 1); - bool type_set; -}; +types::DomainId random_domain( + unsigned int seed = 0); -std::set> topic_set( - std::vector topics); - -std::set> topic_set( - std::vector topics); - -DomainId random_domain( - uint16_t seed = 0); - -GuidPrefix random_guid_prefix( - uint16_t seed = 0, - bool ros = false); - -Address random_address( - uint16_t seed = 0); - -std::set random_connection_addresses( - uint16_t seed = 0, - uint16_t size = 1, +types::GuidPrefix random_guid_prefix( + unsigned int seed = 0, bool ros = false); -std::shared_ptr random_participant_configuration( - ParticipantKind kind, - uint16_t seed = 0); - -ParticipantId random_participant_id( - uint16_t seed = 0); - -ParticipantKind random_participant_kind( - bool valid = true, - uint16_t seed = 0); +types::ParticipantId random_participant_id( + unsigned int seed = 0); } /* namespace test */ } /* namespace core */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp similarity index 80% rename from ddspipe_participants/include/ddspipe_participants/types/data/RpcPayloadData.hpp rename to ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp index 49110e670..2fa6700f4 100644 --- a/ddspipe_participants/include/ddspipe_participants/types/data/RpcPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp @@ -20,8 +20,8 @@ #include -#include -#include +#include +#include #include #include #include @@ -30,7 +30,7 @@ namespace eprosima { namespace ddspipe { -namespace participants { +namespace core { namespace types { /** @@ -45,19 +45,17 @@ struct RpcPayloadData : public RtpsPayloadData //! Sequence number of the received cache change eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; + + //! Sequence Number with which the internal writer (ddsrouter writer) has sent this message + eprosima::fastrtps::rtps::SequenceNumber_t sent_sequence_number; }; /** * @brief Id to identify the internal topic type id that uses \c RpcPayloadData . */ -constexpr const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; - -//! \c RpcPayloadData to stream serializator -DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( - std::ostream& os, - const RpcPayloadData& octet); +const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; } /* namespace types */ -} /* namespace participants */ +} /* namespace core */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/data/RtpsPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp similarity index 89% rename from ddspipe_participants/include/ddspipe_participants/types/data/RtpsPayloadData.hpp rename to ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp index d26ee8f75..f91c61756 100644 --- a/ddspipe_participants/include/ddspipe_participants/types/data/RtpsPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp @@ -1,4 +1,4 @@ -// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// 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. @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -29,7 +29,7 @@ namespace eprosima { namespace ddspipe { -namespace participants { +namespace core { namespace types { /** @@ -81,12 +81,7 @@ struct RtpsPayloadData : public core::IRoutingData */ const core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; -//! \c octet to stream serializator -DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( - std::ostream& os, - const RtpsPayloadData& octet); - } /* namespace types */ -} /* namespace participants */ +} /* namespace core */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp index 31d996ed4..a3ac53040 100644 --- a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp @@ -32,7 +32,7 @@ using DomainIdType = eprosima::fastdds::dds::DomainId_t; struct DomainId { - DDSPIPE_CORE_DllAPI DomainId (); + DDSPIPE_CORE_DllAPI DomainId () noexcept = default; DDSPIPE_CORE_DllAPI DomainId (bool discovery_server) noexcept; diff --git a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp index 97436de5a..f7b62e93f 100644 --- a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp @@ -47,12 +47,15 @@ struct Endpoint { //! Default Endpoint that returns an invalid one - DDSPIPE_CORE_DllAPI Endpoint() noexcept; + DDSPIPE_CORE_DllAPI Endpoint() noexcept = default; /******************** * SPECIFIC GETTERS * ********************/ + //! Qos of the topic + DDSPIPE_CORE_DllAPI TopicQoS topic_qos() const noexcept; + //! Whether the endpoint is a writer DDSPIPE_CORE_DllAPI bool is_writer() const noexcept; @@ -67,22 +70,22 @@ struct Endpoint const Endpoint& other) const noexcept; //! Kind of the endpoint - EndpointKind kind; + EndpointKind kind {EndpointKind::invalid}; //! Unique id of the endpoint - Guid guid; + Guid guid {}; //! Topic that this endpoint belongs to - DistributedTopic topic; + DdsTopic topic {}; //! Specific QoS of the entity - SpecificEndpointQoS specific_qos; + SpecificEndpointQoS specific_qos {}; //! Whether the endpoint is currently active - bool active; + bool active {true}; //! Id of participant who discovered this endpoint - ParticipantId discoverer_participant_id; + ParticipantId discoverer_participant_id {}; }; /** diff --git a/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp b/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp index 955960c2d..ef6190e6a 100644 --- a/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp @@ -14,6 +14,7 @@ #pragma once +#include #include #include @@ -90,10 +91,21 @@ class DDSPIPE_CORE_DllAPI GuidPrefix : public fastrtps::rtps::GuidPrefix_t GuidPrefix& operator = ( const fastrtps::rtps::GuidPrefix_t& other) noexcept; + /** + * Whether the guid prefix is a valid one + * + * To be valid, the GuidPrefix must not be invalid / unknown + */ + bool is_valid() const noexcept; + //! Default DDSRouter Discovery Server Guid Prefix static constexpr const char* SERVER_DEFAULT_GUID_PREFIX_STR = "01.0f.00.00.00.00.00.00.00.00.ca.fe"; - //! Default ROS2 Discovery Server Guid Prefix + /** + * @brief Default ROS2 Discovery Server Guid Prefix + * + * @note This coulde reuse fastdds \c DEFAULT_ROS2_SERVER_GUIDPREFIX if it was constexpr. + */ static constexpr const char* ROS_DISCOVERY_SERVER_GUID_PREFIX_STR = "44.53.00.5f.45.50.52.4f.53.49.4d.41"; }; diff --git a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp index 4fb299145..60595ebbf 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -31,7 +32,7 @@ namespace types { /** * Generic data struct that represents a Topic of data flow in the Router. */ -struct Topic : public ITopic +struct Topic : public ITopic , public IConfiguration { ///////////////////////// @@ -45,9 +46,6 @@ struct Topic : public ITopic // OPERATORS ///////////////////////// - //! Compare this with other std Topic - virtual bool operator==(const Topic& other) const noexcept; - /** * @brief Specialize parent compare operator * @@ -55,6 +53,8 @@ struct Topic : public ITopic */ virtual bool operator==(const ITopic& other) const noexcept override; + virtual bool operator<(const ITopic& other) const noexcept override; + ///////////////////////// // METHODS ///////////////////////// @@ -64,6 +64,16 @@ struct Topic : public ITopic virtual const TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept override; + virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + + ///////////////////////// + // METHODS TO OVERRIDE + ///////////////////////// + + //! ITopic unique name in processs + virtual std::string topic_unique_name() const noexcept override; + ///////////////////////// // VARIABLES ///////////////////////// diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp index 5d7f1a91a..cc8cae190 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp @@ -41,24 +41,14 @@ struct DdsTopic : public DistributedTopic //! Default constructor DDSPIPE_CORE_DllAPI DdsTopic() = default; - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Equal operator. - DDSPIPE_CORE_DllAPI bool operator == ( - const Topic& other) const noexcept; - - //! Equal operator. - DDSPIPE_CORE_DllAPI bool operator == ( - const DdsTopic& other) const noexcept; - ///////////////////////// // METHODS ///////////////////////// - //! Override parent method - virtual const TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept override; + virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + + virtual std::string topic_unique_name() const noexcept override; ///////////////////////// // STATIC METHODS @@ -67,7 +57,8 @@ struct DdsTopic : public DistributedTopic //! Whether a name and type can refer to a correct DDS Topic. DDSPIPE_CORE_DllAPI static bool is_valid_dds_topic( const std::string& topic_name, - const std::string& type_name) noexcept; + const std::string& type_name, + utils::Formatter& error_msg) noexcept; ///////////////////////// // VARIABLES @@ -83,6 +74,7 @@ struct DdsTopic : public DistributedTopic * This Topic class is a proxy, not an actual Topic Entity of DDS, so it should not have QoS. */ types::TopicQoS topic_qos{}; + }; /** diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp index d5ebcc95e..de75cb5b3 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp @@ -38,13 +38,6 @@ struct DistributedTopic : public Topic // Extend nothing }; -/** - * Serialization method for \c DistributedTopic object. - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const DistributedTopic& t); - } /* namespace types */ } /* namespace core */ } /* namespace ddspipe */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp index 29167612b..a60f1d746 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp @@ -17,8 +17,11 @@ #include #include +#include + #include #include +#include namespace eprosima { namespace ddspipe { @@ -70,9 +73,13 @@ struct WildcardDdsFilterTopic : public IFilterTopic protected: - //! Specialization for DDS Topics. - DDSPIPE_CORE_DllAPI virtual bool matches_( - const DistributedTopic& real_topic) const; + ///////////////////////// + // INTERNAL METHODS + ///////////////////////// + + //! Specialization for type of topic. Only specialized for DdsTopic. + DDSPIPE_CORE_DllAPI bool matches_( + const DdsTopic& real_topic) const; }; /** diff --git a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp index 79528dc3c..091b60df5 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp @@ -40,6 +40,8 @@ class RpcTopic RpcTopic( const DdsTopic& topic) noexcept; + RpcTopic(const RpcTopic& topic) noexcept; + //! Service name getter const std::string& service_name() const; diff --git a/ddspipe_core/src/cpp/_dummy.cpp b/ddspipe_core/src/cpp/_dummy.cpp deleted file mode 100644 index 5afa3c4d1..000000000 --- a/ddspipe_core/src/cpp/_dummy.cpp +++ /dev/null @@ -1,2 +0,0 @@ - -#include diff --git a/ddspipe_core/src_/cpp/communication/Bridge.cpp b/ddspipe_core/src/cpp/communication/Bridge.cpp similarity index 72% rename from ddspipe_core/src_/cpp/communication/Bridge.cpp rename to ddspipe_core/src/cpp/communication/Bridge.cpp index 2a3d1d0c3..4e69527a7 100644 --- a/ddspipe_core/src_/cpp/communication/Bridge.cpp +++ b/ddspipe_core/src/cpp/communication/Bridge.cpp @@ -12,27 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Bridge.cpp - * - */ - -#include - #include #include +#include + namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; - Bridge::Bridge( - std::shared_ptr participants_database, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool) - : participants_(participants_database) + const std::shared_ptr& topic, + const std::shared_ptr& participants_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool) + : topic_(topic) + , participants_(participants_database) , payload_pool_(payload_pool) , thread_pool_(thread_pool) , enabled_(false) diff --git a/ddspipe_core/src_/cpp/communication/DDSBridge.cpp b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp similarity index 63% rename from ddspipe_core/src_/cpp/communication/DDSBridge.cpp rename to ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp index 43e7e1494..8ef902b37 100644 --- a/ddspipe_core/src_/cpp/communication/DDSBridge.cpp +++ b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp @@ -12,43 +12,38 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DdsBridge.cpp - * - */ - -#include - #include #include +#include + namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; DdsBridge::DdsBridge( - const DistributedTopic& topic, - std::shared_ptr participants_database, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool, - bool enable /* = false */) - : Bridge(participants_database, payload_pool, thread_pool) - , topic_(topic) + const std::shared_ptr& topic, + const std::shared_ptr& participants_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool) + : Bridge(topic, participants_database, payload_pool, thread_pool) { logDebug(DDSROUTER_DDSBRIDGE, "Creating DdsBridge " << *this << "."); std::set ids = participants_->get_participants_ids(); + std::map> writers; + std::map> readers; + // Generate readers and writers for each participant - for (ParticipantId id: ids) + for (const auto& id: ids) { - std::shared_ptr participant = participants_->get_participant(id); - - writers_[id] = participant->create_writer(topic); - readers_[id] = participant->create_reader(topic); + std::shared_ptr participant = participants_database->get_participant(id); + writers[id] = participant->create_writer(*topic); + readers[id] = participant->create_reader(*topic); } // Generate tracks @@ -56,7 +51,7 @@ DdsBridge::DdsBridge( { // List of all Participants std::map> writers_except_one = - writers_; // Create a copy of the map + writers; // Create a copy of the map if (!participants_->get_participant(id)->is_repeater()) { @@ -72,17 +67,12 @@ DdsBridge::DdsBridge( // Tracks are always created disabled and then enabled with Bridge enable() method tracks_[id] = std::make_unique( - topic_, + topic, id, - readers_[id], std::move(writers_except_one), - payload_pool_, - thread_pool, - false); - } - - if (enable) - { - this->enable(); + readers[id], + std::move(writers_except_one), + payload_pool, + thread_pool); } logDebug(DDSROUTER_DDSBRIDGE, "DdsBridge " << *this << " created."); @@ -95,35 +85,12 @@ DdsBridge::~DdsBridge() // Disable every Track before destruction disable(); - // Force deleting tracks before deleting Bridge - tracks_.clear(); - - // Remove all Writers and Readers that were created in construction - for (ParticipantId id: participants_->get_participants_ids()) - { - std::shared_ptr participant = participants_->get_participant(id); - auto writer = writers_.find(id); - auto reader = readers_.find(id); - - // Writer and Reader must exist in this Bridge Map for each participant - assert(writer != writers_.end()); - assert(reader != readers_.end()); - - participant->delete_writer(writer->second); - participant->delete_reader(reader->second); - - writers_.erase(writer); - readers_.erase(reader); - } - - // Participants must not be removed as they belong to the Participant Database - logDebug(DDSROUTER_DDSBRIDGE, "DdsBridge " << *this << " destroyed."); } void DdsBridge::enable() noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!enabled_) { @@ -141,7 +108,7 @@ void DdsBridge::enable() noexcept void DdsBridge::disable() noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (enabled_) { diff --git a/ddspipe_core/src_/cpp/communication/Track.cpp b/ddspipe_core/src/cpp/communication/dds/Track.cpp similarity index 92% rename from ddspipe_core/src_/cpp/communication/Track.cpp rename to ddspipe_core/src/cpp/communication/dds/Track.cpp index 1e23225f8..50280e5e1 100644 --- a/ddspipe_core/src_/cpp/communication/Track.cpp +++ b/ddspipe_core/src/cpp/communication/dds/Track.cpp @@ -22,28 +22,27 @@ #include #include -#include +#include namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; const unsigned int Track::MAX_MESSAGES_TRANSMIT_LOOP_ = 100; Track::Track( - const DistributedTopic& topic, - ParticipantId reader_participant_id, - std::shared_ptr reader, - std::map>&& writers, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool, - bool enable /* = false */) noexcept - : reader_participant_id_(reader_participant_id) - , topic_(topic) + const std::shared_ptr& topic, + const types::ParticipantId& reader_participant_id, + const std::shared_ptr& reader, + std::map>&& writers, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool) noexcept + : topic_(topic) + , reader_participant_id_(reader_participant_id) , reader_(reader) - , writers_(writers) + , writers_(std::move(writers)) , payload_pool_(payload_pool) , enabled_(false) , exit_(false) @@ -61,11 +60,6 @@ Track::Track( transmit_task_id_, std::bind(&Track::transmit_, this)); - if (enable) - { - // Activate Track - this->enable(); - } logDebug(DDSROUTER_TRACK, "Track " << *this << " created."); } diff --git a/ddspipe_core/src_/cpp/communication/rpc/RPCBridge.cpp b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp similarity index 74% rename from ddspipe_core/src_/cpp/communication/rpc/RPCBridge.cpp rename to ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp index 4fdfe4802..4c95ba7d0 100644 --- a/ddspipe_core/src_/cpp/communication/rpc/RPCBridge.cpp +++ b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -19,28 +19,28 @@ #include -#include #include #include #include #include +#include namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; RPCBridge::RPCBridge( - const RpcTopic& topic, - std::shared_ptr participants_database, - std::shared_ptr payload_pool, - std::shared_ptr thread_pool) - : Bridge(participants_database, payload_pool, thread_pool) - , topic_(topic) + const std::shared_ptr& topic, + const std::shared_ptr& participants_database, + const std::shared_ptr& payload_pool, + const std::shared_ptr& thread_pool) + : Bridge(std::shared_ptr(), participants_database, payload_pool, thread_pool) , init_(false) + , rpc_topic_(topic) { logDebug(DDSROUTER_RPCBRIDGE, "Creating RPCBridge " << *this << "."); @@ -54,48 +54,12 @@ RPCBridge::~RPCBridge() // Disable all entities before destruction disable(); - // Remove all created Writers and Readers - for (ParticipantId id: participants_->get_participants_ids()) - { - std::shared_ptr participant = participants_->get_participant(id); - - auto request_writer = request_writers_.find(id); - if (request_writer != request_writers_.end()) - { - participant->delete_writer(request_writer->second); - request_writers_.erase(request_writer); - } - - auto reply_writer = reply_writers_.find(id); - if (reply_writer != reply_writers_.end()) - { - participant->delete_writer(reply_writer->second); - reply_writers_.erase(reply_writer); - } - - auto request_reader = request_readers_.find(id); - if (request_reader != request_readers_.end()) - { - participant->delete_reader(request_reader->second); - request_readers_.erase(request_reader); - } - - auto reply_reader = reply_readers_.find(id); - if (reply_reader != reply_readers_.end()) - { - participant->delete_reader(reply_reader->second); - reply_readers_.erase(reply_reader); - } - } - - // Participants must not be removed as they belong to the Participant Database - logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << " destroyed."); } void RPCBridge::init_nts_() { - logInfo(DDSROUTER_RPCBRIDGE, "Creating endpoints in RPCBridge for service " << topic_ << "."); + logInfo(DDSROUTER_RPCBRIDGE, "Creating endpoints in RPCBridge for service " << rpc_topic_ << "."); // TODO: remove and use every participant std::set ids = participants_->get_rtps_participants_ids(); @@ -113,7 +77,7 @@ void RPCBridge::init_nts_() // TODO: This should not be done // Wait for the new entities created to match before sending data from one side to the other - // utils::sleep_for(500); + utils::sleep_for(500); init_ = true; } @@ -123,10 +87,8 @@ void RPCBridge::create_proxy_server_nts_( { std::shared_ptr participant = participants_->get_participant(participant_id); - // Safe casting as we are only getting RTPS participants - reply_writers_[participant_id] = participant->create_writer(topic_.reply_topic()); - request_readers_[participant_id] = - std::static_pointer_cast(participant->create_reader(topic_.request_topic())); + reply_writers_[participant_id] = participant->create_writer(rpc_topic_->reply_topic()); + request_readers_[participant_id] = participant->create_reader(rpc_topic_->request_topic()); create_slot_(request_readers_[participant_id]); } @@ -137,15 +99,13 @@ void RPCBridge::create_proxy_client_nts_( std::shared_ptr participant = participants_->get_participant(participant_id); // Safe casting as we are only getting RTPS participants - request_writers_[participant_id] = - std::static_pointer_cast(participant->create_writer(topic_.request_topic())); - reply_readers_[participant_id] = - std::static_pointer_cast(participant->create_reader(topic_.reply_topic())); + request_writers_[participant_id] = participant->create_writer(rpc_topic_->request_topic()); + reply_readers_[participant_id] = participant->create_reader(rpc_topic_->reply_topic()); create_slot_(reply_readers_[participant_id]); // Create service registry associated to this proxy client - service_registries_[participant_id] = std::make_shared(topic_, participant_id); + service_registries_[participant_id] = std::make_shared(*rpc_topic_, participant_id); } void RPCBridge::enable() noexcept @@ -154,7 +114,7 @@ void RPCBridge::enable() noexcept if (!enabled_ && servers_available_()) { - logInfo(DDSROUTER_RPCBRIDGE, "Enabling RPCBridge for service " << topic_ << "."); + logInfo(DDSROUTER_RPCBRIDGE, "Enabling RPCBridge for service " << rpc_topic_ << "."); if (!init_) { @@ -165,7 +125,7 @@ void RPCBridge::enable() noexcept catch (const utils::InitializationException& e) { logError(DDSROUTER_RPCBRIDGE, - "Error while creating endpoints in RPCBridge for service " << topic_ << + "Error while creating endpoints in RPCBridge for service " << rpc_topic_ << ". Error code:" << e.what() << "."); return; } @@ -204,7 +164,7 @@ void RPCBridge::disable() noexcept if (enabled_) { - logInfo(DDSROUTER_RPCBRIDGE, "Disabling RPCBridge for service " << topic_ << "."); + logInfo(DDSROUTER_RPCBRIDGE, "Disabling RPCBridge for service " << rpc_topic_ << "."); enabled_ = false; @@ -298,7 +258,7 @@ void RPCBridge::data_available_( } void RPCBridge::transmit_( - std::shared_ptr reader) noexcept + std::shared_ptr reader) noexcept { // Avoid being disabled while transmitting std::shared_lock lock(on_transmission_mutex_); @@ -335,7 +295,7 @@ void RPCBridge::transmit_( std::unique_ptr data; utils::ReturnCode ret = reader->take(data); - RpcPayloadData& pcr_data = dynamic_cast(data); + RpcPayloadData& pcr_data = dynamic_cast(*data); // Will never return \c RETCODE_NO_DATA, otherwise would have finished before if (!ret) @@ -351,18 +311,18 @@ void RPCBridge::transmit_( if (RpcTopic::is_request_topic(reader->topic())) { logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << topic_ << - " transmitting request from remote endpoint " << pcr_data->properties.source_guid << "."); + "RPCBridge for service " << rpc_topic_ << + " transmitting request from remote endpoint " << pcr_data.source_guid << "."); SampleIdentity reply_related_sample_identity = - pcr_data->properties.write_params.get_reference().sample_identity(); - reply_related_sample_identity.sequence_number(pcr_data->properties.origin_sequence_number); + pcr_data.write_params.sample_identity(); + reply_related_sample_identity.sequence_number(pcr_data.origin_sequence_number); if (reply_related_sample_identity == SampleIdentity::unknown()) { logWarning(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << topic_ << - " received ill-formed request from remote endpoint " << pcr_data->properties.source_guid << + "RPCBridge for service " << rpc_topic_ << + " received ill-formed request from remote endpoint " << pcr_data.source_guid << ". Ignoring..."); } else @@ -370,7 +330,7 @@ void RPCBridge::transmit_( for (auto& service_registry : service_registries_) { // Do not send request through same participant who received it (unless repeater), or if there are no servers to process it - if ((pcr_data->properties.participant_receiver == service_registry.first && + if ((pcr_data.participant_receiver == service_registry.first && !participants_->get_participant(service_registry.first)->is_repeater()) || !service_registry.second->enabled()) { @@ -380,28 +340,25 @@ void RPCBridge::transmit_( // Perform write + add entry to registry atomically -> avoid reply processed before entry added to registry std::lock_guard lock(service_registry.second->get_mutex()); - // Set write params so writer set in related sample identity the correct value - // Set it so writer use it - pcr_data->properties.write_params.set_level(); // Attach the information the server needs in order to reply to the appropiate proxy client. - pcr_data->properties.write_params.get_reference().related_sample_identity().writer_guid( + pcr_data.write_params.related_sample_identity().writer_guid( reply_readers_[service_registry.first]->guid()); - ret = request_writers_[service_registry.first]->write(data); + ret = request_writers_[service_registry.first]->write(*data); if (!ret) { logWarning(DDSROUTER_RPCBRIDGE, "Error writting request in RPCBridge for service " - << topic_ << ". Error code " << ret << ". Skipping data for this writer and continue."); + << rpc_topic_ << ". Error code " << ret << ". Skipping data for this writer and continue."); continue; } eprosima::fastrtps::rtps::SequenceNumber_t sequence_number = - pcr_data->sent_sequence_number; + pcr_data.sent_sequence_number; // Add entry to registry associated to the transmission of this request through this proxy client. service_registry.second->add( sequence_number, - {pcr_data->properties.participant_receiver, reply_related_sample_identity}); + {pcr_data.participant_receiver, reply_related_sample_identity}); } } @@ -409,17 +366,17 @@ void RPCBridge::transmit_( else if (RpcTopic::is_reply_topic(reader->topic())) { logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << topic_ << - " transmitting reply from remote endpoint " << pcr_data->properties.source_guid << "."); + "RPCBridge for service " << rpc_topic_ << + " transmitting reply from remote endpoint " << pcr_data.source_guid << "."); // A Server could be answering a different client in this same DDS Router or a remote client // Thus, it must be filtered so only replies to this client are processed. - if (pcr_data->properties.write_params.get_reference().sample_identity().writer_guid() != reader->guid()) + if (pcr_data.write_params.sample_identity().writer_guid() != reader->guid()) { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << *this << " from reader " << reader->guid() << " received response meant for other client: " << - pcr_data->properties.write_params.get_reference().sample_identity().writer_guid()); + pcr_data.write_params.sample_identity().writer_guid()); } else { @@ -431,7 +388,7 @@ void RPCBridge::transmit_( // Fetch information required for transmission; which proxy server should send it and with what parameters registry_entry = service_registries_[reader->participant_id()]->get( - pcr_data->properties.write_params.get_reference().sample_identity().sequence_number()); + pcr_data.write_params.sample_identity().sequence_number()); } // Not valid means: @@ -440,20 +397,19 @@ void RPCBridge::transmit_( // TODO: recheck ParticipantId non valid if (!registry_entry.first.empty()) { - pcr_data->properties.write_params.set_level(); - pcr_data->properties.write_params.get_reference().related_sample_identity(registry_entry.second); + pcr_data.write_params.related_sample_identity(registry_entry.second); - ret = reply_writers_[registry_entry.first]->write(data); + ret = reply_writers_[registry_entry.first]->write(*data); if (!ret) { logWarning(DDSROUTER_RPCBRIDGE, "Error writting reply in RPCBridge for service " - << topic_ << ". Error code " << ret << "."); + << rpc_topic_ << ". Error code " << ret << "."); } else { service_registries_[reader->participant_id()]->erase( - pcr_data->properties.write_params.get_reference().sample_identity().sequence_number()); + pcr_data.write_params.sample_identity().sequence_number()); } } } @@ -464,12 +420,12 @@ void RPCBridge::transmit_( utils::Formatter() << "Data to be transmitted in RPCBridge is not in RpcTopic."); } - payload_pool_->release_payload(pcr_data->payload); - } + payload_pool_->release_payload(pcr_data.payload); + }/* */ } void RPCBridge::create_slot_( - std::shared_ptr reader) noexcept + std::shared_ptr reader) noexcept { Guid reader_guid = reader->guid(); @@ -494,7 +450,7 @@ std::ostream& operator <<( std::ostream& os, const RPCBridge& bridge) { - os << "RPCBridge{" << bridge.topic_ << "}"; + os << "RPCBridge{" << bridge.rpc_topic_ << "}"; return os; } diff --git a/ddspipe_core/src_/cpp/communication/rpc/ServiceRegistry.cpp b/ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp similarity index 98% rename from ddspipe_core/src_/cpp/communication/rpc/ServiceRegistry.cpp rename to ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp index 2e2d93863..4091cd64b 100644 --- a/ddspipe_core/src_/cpp/communication/rpc/ServiceRegistry.cpp +++ b/ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp @@ -28,7 +28,7 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; const unsigned int ServiceRegistry::DEFAULT_MAX_ENTRIES_ = 5000; diff --git a/ddspipe_core/src_/cpp/core/DDSRouterImpl.cpp b/ddspipe_core/src/cpp/core/DdsPipe.cpp similarity index 59% rename from ddspipe_core/src_/cpp/core/DDSRouterImpl.cpp rename to ddspipe_core/src/cpp/core/DdsPipe.cpp index ed2710f5e..3f6f228df 100644 --- a/ddspipe_core/src_/cpp/core/DDSRouterImpl.cpp +++ b/ddspipe_core/src/cpp/core/DdsPipe.cpp @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DDSRouterImpl.cpp - * - */ - #include #include @@ -25,57 +20,44 @@ #include #include -#include - -#include +#include namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; // TODO: Use initial topics to start execution and start bridges -DDSRouterImpl::DDSRouterImpl( - const configuration::DDSRouterConfiguration& configuration, +DdsPipe::DdsPipe( + const std::shared_ptr& allowed_topics, const std::shared_ptr& discovery_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& participants_database) - : participants_database_(participants_database) + const std::shared_ptr& payload_pool, + const std::shared_ptr& participants_database, + const std::shared_ptr& thread_pool, + const std::set>& builtin_topics /* = {} */) + : allowed_topics_(allowed_topics) , discovery_database_(discovery_database) , payload_pool_(payload_pool) - , configuration_(configuration) + , participants_database_(participants_database) + , thread_pool_(thread_pool) , enabled_(false) - , thread_pool_(std::make_shared(configuration_.advanced_options.number_of_threads)) { - logDebug(DDSROUTER, "Creating DDS Router."); + logDebug(DDSROUTER, "Creating DDS Pipe."); - // Check that the configuration is correct - utils::Formatter error_msg; - if (!configuration_.is_valid(error_msg)) - { - throw utils::ConfigurationException( - utils::Formatter() << - "Configuration for DDS Router is invalid: " << error_msg); - } - - // Set default value for history - types::TopicQoS::default_history_depth.store( - configuration_.advanced_options.max_history_depth); + // TODO set default history qos somewhere else // Add callback to be called by the discovery database when an Endpoint is discovered - discovery_database_->add_endpoint_discovered_callback(std::bind(&DDSRouterImpl::discovered_endpoint_, this, + discovery_database_->add_endpoint_discovered_callback(std::bind(&DdsPipe::discovered_endpoint_, this, std::placeholders::_1)); // Add callback to be called by the discovery database when an Endpoint is removed/dropped - discovery_database_->add_endpoint_erased_callback(std::bind(&DDSRouterImpl::removed_endpoint_, this, + discovery_database_->add_endpoint_erased_callback(std::bind(&DdsPipe::removed_endpoint_, this, std::placeholders::_1)); - // Init topic allowed - init_allowed_topics_(); // Create Bridges for builtin topics - init_bridges_(); + init_bridges_(builtin_topics); // Init discovery database // The entities should not be added to the Discovery Database until the builtin topics have been created. @@ -83,13 +65,12 @@ DDSRouterImpl::DDSRouterImpl( // than the one specified in the yaml configuration file. discovery_database_->start(); - - logDebug(DDSROUTER, "DDS Router created."); + logDebug(DDSROUTER, "DDS Pipe created."); } -DDSRouterImpl::~DDSRouterImpl() +DdsPipe::~DdsPipe() { - logDebug(DDSROUTER, "Destroying DDS Router."); + logDebug(DDSROUTER, "Destroying DDS Pipe."); // Stop Discovery Database discovery_database_->stop(); @@ -105,53 +86,29 @@ DDSRouterImpl::~DDSRouterImpl() // There is no need to destroy shared ptrs as they will delete itslefs with 0 references - logDebug(DDSROUTER, "DDS Router destroyed."); + logDebug(DDSROUTER, "DDS Pipe destroyed."); } -utils::ReturnCode DDSRouterImpl::reload_configuration( - const configuration::DDSRouterReloadConfiguration& new_configuration) +utils::ReturnCode DdsPipe::reload_allowed_topics( + const std::shared_ptr& allowed_topics) { - // Check that the configuration is correct - utils::Formatter error_msg; - if (!new_configuration.is_valid(error_msg)) - { - throw utils::ConfigurationException( - utils::Formatter() << - "Configuration for Reload DDS Router is invalid: " << error_msg); - } - - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (enabled_.load()) { - logDebug(DDSROUTER, "Reloading DDS Router configuration..."); - - // Load new configuration and check it is okey - AllowedTopicList new_allowed_topic_list( - new_configuration.allowlist, - new_configuration.blocklist); - - // Check if there are any new builtin topics - std::set new_builtin_topics; - for (auto builtin_topic : new_configuration.builtin_topics) - { - if (current_topics_.find(*builtin_topic) == current_topics_.end()) - { - new_builtin_topics.insert(*builtin_topic); - } - } + logDebug(DDSROUTER, "Reloading DDS Pipe configuration..."); // Check if it should change or is the same configuration - if (new_allowed_topic_list == allowed_topics_ && new_builtin_topics.empty()) + if (*allowed_topics == *allowed_topics_) { logDebug(DDSROUTER, "Same configuration, do nothing in reload."); return utils::ReturnCode::RETCODE_NO_DATA; } // Set new Allowed list - allowed_topics_ = new_allowed_topic_list; + allowed_topics_ = allowed_topics; - logDebug(DDSROUTER, "New DDS Router allowed topics configuration: " << allowed_topics_); + logDebug(DDSROUTER, "New DDS Pipe allowed topics configuration: " << allowed_topics_); // It must change the configuration. Check every topic discovered and activate/deactivate it if needed. for (auto& topic_it : current_topics_) @@ -159,7 +116,7 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( // If topic is active and it is blocked, deactivate it if (topic_it.second) { - if (!allowed_topics_.is_topic_allowed(topic_it.first)) + if (!allowed_topics_->is_topic_allowed(*topic_it.first)) { deactivate_topic_(topic_it.first); } @@ -167,23 +124,17 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( else { // If topic is not active and it is allowed, activate it - if (allowed_topics_.is_topic_allowed(topic_it.first)) + if (allowed_topics_->is_topic_allowed(*topic_it.first)) { activate_topic_(topic_it.first); } } } - // Create bridges for newly added builtin topics - for (DistributedTopic topic : new_builtin_topics) - { - discovered_topic_(topic); - } - // Check every service discovered and activate/deactivate it if needed. for (auto& service_it : current_services_) { - if (allowed_topics_.is_service_allowed(service_it.first)) + if (allowed_topics_->is_service_allowed(*service_it.first)) { service_it.second = true; rpc_bridges_[service_it.first]->enable(); @@ -195,55 +146,54 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( } } - configuration_.reload(new_configuration); - return utils::ReturnCode::RETCODE_OK; } else { return utils::ReturnCode::RETCODE_NOT_ENABLED; + allowed_topics_ = allowed_topics; } } -utils::ReturnCode DDSRouterImpl::start() noexcept +utils::ReturnCode DdsPipe::start() noexcept { utils::ReturnCode ret = start_(); if (ret == utils::ReturnCode::RETCODE_OK) { - logInfo(DDSROUTER, "Starting DDS Router."); + logInfo(DDSROUTER, "Starting DDS Pipe."); } else if (ret == utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET) { - logInfo(DDSROUTER, "Trying to start an enabled DDS Router."); + logInfo(DDSROUTER, "Trying to start an enabled DDS Pipe."); } return ret; } -utils::ReturnCode DDSRouterImpl::stop() noexcept +utils::ReturnCode DdsPipe::stop() noexcept { utils::ReturnCode ret = stop_(); if (ret == utils::ReturnCode::RETCODE_OK) { - logInfo(DDSROUTER, "Stopping DDS Router."); + logInfo(DDSROUTER, "Stopping DDS Pipe."); } else if (ret == utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET) { - logInfo(DDSROUTER, "Trying to stop a not enabled DDS Router."); + logInfo(DDSROUTER, "Trying to stop a not enabled DDS Pipe."); } return ret; } -utils::ReturnCode DDSRouterImpl::start_() noexcept +utils::ReturnCode DdsPipe::start_() noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!enabled_.load()) { enabled_.store(true); - logInfo(DDSROUTER, "Starting DDS Router."); + logInfo(DDSROUTER, "Starting DDS Pipe."); // Enable thread pool thread_pool_->enable(); @@ -264,20 +214,20 @@ utils::ReturnCode DDSRouterImpl::start_() noexcept } else { - logInfo(DDSROUTER, "Trying to start an already enabled DDS Router."); + logInfo(DDSROUTER, "Trying to start an already enabled DDS Pipe."); return utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET; } } -utils::ReturnCode DDSRouterImpl::stop_() noexcept +utils::ReturnCode DdsPipe::stop_() noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (enabled_.load()) { enabled_.store(false); - logInfo(DDSROUTER, "Stopping DDS Router."); + logInfo(DDSROUTER, "Stopping DDS Pipe."); // Disable thread pool so tasks running finish and new tasks are not taken by threads thread_pool_->disable(); @@ -287,32 +237,23 @@ utils::ReturnCode DDSRouterImpl::stop_() noexcept } else { - logInfo(DDSROUTER, "Trying to stop a disabled DDS Router."); + logInfo(DDSROUTER, "Trying to stop a disabled DDS Pipe."); return utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET; } } -void DDSRouterImpl::init_allowed_topics_() +void DdsPipe::init_bridges_(const std::set>& builtin_topics) { - allowed_topics_ = AllowedTopicList( - configuration_.allowlist, - configuration_.blocklist); - - logInfo(DDSROUTER, "DDS Router configured with allowed topics: " << allowed_topics_); -} - -void DDSRouterImpl::init_bridges_() -{ - for (std::shared_ptr topic : configuration_.builtin_topics) + for (const auto& topic : builtin_topics) { - discovered_topic_(*topic); + discovered_topic_(topic); } } -void DDSRouterImpl::discovered_topic_( - const DistributedTopic& topic) noexcept +void DdsPipe::discovered_topic_( + const std::shared_ptr& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Discovered topic: " << topic << "."); @@ -327,19 +268,19 @@ void DDSRouterImpl::discovered_topic_( // Add topic to current_topics as non activated current_topics_.emplace(topic, false); - // If Router is enabled and topic allowed, activate it - if (enabled_.load() && allowed_topics_.is_topic_allowed(topic)) + // If Pipe is enabled and topic allowed, activate it + if (enabled_.load() && allowed_topics_->is_topic_allowed(*topic)) { activate_topic_(topic); } } -void DDSRouterImpl::discovered_service_( - const RpcTopic& topic, +void DdsPipe::discovered_service_( + const std::shared_ptr& topic, const ParticipantId& server_participant_id, const GuidPrefix& server_guid_prefix) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Discovered service: " << topic << "."); @@ -348,9 +289,9 @@ void DDSRouterImpl::discovered_service_( if (it_bridge == rpc_bridges_.end()) { // Create RPCBridge even if topic not allowed, as we need to store server in database - create_new_service(topic); + create_new_service_(topic); - if (allowed_topics_.is_service_allowed(topic)) + if (allowed_topics_->is_service_allowed(*topic)) { current_services_[topic] = true; } @@ -367,12 +308,12 @@ void DDSRouterImpl::discovered_service_( } } -void DDSRouterImpl::removed_service_( - const RpcTopic& topic, +void DdsPipe::removed_service_( + const std::shared_ptr& topic, const ParticipantId& server_participant_id, const GuidPrefix& server_guid_prefix) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Removed service: " << topic << "."); @@ -384,56 +325,59 @@ void DDSRouterImpl::removed_service_( } } -void DDSRouterImpl::discovered_endpoint_( +void DdsPipe::discovered_endpoint_( const Endpoint& endpoint) noexcept { - logDebug(DDSROUTER, "Endpoint discovered in DDS Router core: " << endpoint << "."); + logDebug(DDSROUTER, "Endpoint discovered in DDS Pipe core: " << endpoint << "."); // Set as discovered only if the endpoint is a Reader // If non Readers in topics, it is considered as non discovered if (endpoint.is_reader()) { - DistributedTopic topic = endpoint.topic(); - if (!RpcTopic::is_service_topic(topic)) + if (!RpcTopic::is_service_topic(endpoint.topic)) { - discovered_topic_(topic); + discovered_topic_(std::make_shared(endpoint.topic)); } else if (endpoint.is_server_endpoint()) { // Service server discovered - discovered_service_(RpcTopic(topic), endpoint.discoverer_participant_id(), endpoint.guid().guid_prefix()); + discovered_service_(std::make_shared(endpoint.topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); } } } -void DDSRouterImpl::removed_endpoint_( +void DdsPipe::removed_endpoint_( const Endpoint& endpoint) noexcept { logDebug(DDSROUTER, "Endpoint removed/dropped: " << endpoint << "."); - DistributedTopic topic = endpoint.topic(); + const DdsTopic& topic = endpoint.topic; if (RpcTopic::is_service_topic(topic)) { if (endpoint.is_server_endpoint()) { // Service server removed/dropped - removed_service_(RpcTopic(topic), endpoint.discoverer_participant_id(), endpoint.guid().guid_prefix()); + removed_service_(std::make_shared(topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); } } } -void DDSRouterImpl::create_new_bridge( - const DistributedTopic& topic, +void DdsPipe::create_new_bridge_( + const std::shared_ptr& topic, bool enabled /*= false*/) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Creating Bridge for topic: " << topic << "."); try { - bridges_[topic] = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_, - enabled); + auto new_bridge = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_); + if (enabled_) + { + new_bridge->enable(); + } + bridges_[topic] = std::move(new_bridge); } catch (const utils::InitializationException& e) { @@ -443,10 +387,10 @@ void DDSRouterImpl::create_new_bridge( } } -void DDSRouterImpl::create_new_service( - const RpcTopic& topic) noexcept +void DdsPipe::create_new_service_( + const std::shared_ptr& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Creating Service: " << topic << "."); @@ -454,10 +398,10 @@ void DDSRouterImpl::create_new_service( rpc_bridges_[topic] = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_); } -void DDSRouterImpl::activate_topic_( - const DistributedTopic& topic) noexcept +void DdsPipe::activate_topic_( + const std::shared_ptr& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Activating topic: " << topic << "."); @@ -470,7 +414,7 @@ void DDSRouterImpl::activate_topic_( if (it_bridge == bridges_.end()) { // The Bridge did not exist - create_new_bridge(topic, true); + create_new_bridge_(topic, true); } else { @@ -479,10 +423,10 @@ void DDSRouterImpl::activate_topic_( } } -void DDSRouterImpl::deactivate_topic_( - const DistributedTopic& topic) noexcept +void DdsPipe::deactivate_topic_( + const std::shared_ptr& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Deactivating topic: " << topic << "."); @@ -500,19 +444,19 @@ void DDSRouterImpl::deactivate_topic_( // If the Bridge does not exist, is not need to create it } -void DDSRouterImpl::activate_all_topics_() noexcept +void DdsPipe::activate_all_topics_() noexcept { for (auto it : current_topics_) { // Activate all topics allowed - if (allowed_topics_.is_topic_allowed(it.first)) + if (allowed_topics_->is_topic_allowed(*it.first)) { activate_topic_(it.first); } } } -void DDSRouterImpl::deactivate_all_topics_() noexcept +void DdsPipe::deactivate_all_topics_() noexcept { for (auto it : current_topics_) { diff --git a/ddspipe_core/src_/cpp/dynamic/AllowedTopicList.cpp b/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp similarity index 75% rename from ddspipe_core/src_/cpp/dynamic/AllowedTopicList.cpp rename to ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp index 2ebe5c642..43b7c3477 100644 --- a/ddspipe_core/src_/cpp/dynamic/AllowedTopicList.cpp +++ b/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp @@ -27,12 +27,10 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; - // TODO: Add logs AllowedTopicList::AllowedTopicList( - const std::set>& allowlist, - const std::set>& blocklist) noexcept + const std::set>& allowlist, + const std::set>& blocklist) noexcept { allowlist_ = AllowedTopicList::get_topic_list_without_repetition_(allowlist); blocklist_ = AllowedTopicList::get_topic_list_without_repetition_(blocklist); @@ -65,7 +63,7 @@ void AllowedTopicList::clear() noexcept } bool AllowedTopicList::is_topic_allowed( - const DistributedTopic& topic) const noexcept + const ITopic& topic) const noexcept { std::lock_guard lock(mutex_); @@ -73,7 +71,7 @@ bool AllowedTopicList::is_topic_allowed( bool accepted = allowlist_.empty(); // Check if allowlist filter it (this will do anything if empty and accepted will be true) - for (std::shared_ptr filter : allowlist_) + for (const auto& filter : allowlist_) { if (filter->matches(topic)) { @@ -89,7 +87,7 @@ bool AllowedTopicList::is_topic_allowed( } // Allowlist passed, check blocklist - for (std::shared_ptr filter : blocklist_) + for (const auto& filter : blocklist_) { if (filter->matches(topic)) { @@ -102,7 +100,7 @@ bool AllowedTopicList::is_topic_allowed( } bool AllowedTopicList::is_service_allowed( - const RpcTopic& topic) const noexcept + const types::RpcTopic& topic) const noexcept { // Lock mutex to perform the verification atomically std::lock_guard lock(mutex_); @@ -113,24 +111,22 @@ bool AllowedTopicList::is_service_allowed( bool AllowedTopicList::operator ==( const AllowedTopicList& other) const noexcept { - return - utils::are_set_of_ptr_equal(allowlist_, other.allowlist_) && - utils::are_set_of_ptr_equal(blocklist_, other.blocklist_); + return allowlist_ == other.allowlist_ && blocklist_ == other.blocklist_; } -std::set> AllowedTopicList::get_topic_list_without_repetition_( - const std::set>& list) noexcept +std::set> AllowedTopicList::get_topic_list_without_repetition_( + const std::set>& list) noexcept { - std::set> non_repeated_list; + std::set> non_repeated_list; // Store each topic without repetition - for (std::shared_ptr new_topic : list) + for (utils::Heritable new_topic : list) { bool add_it = true; - std::set> repeated; + std::set> repeated; // Check if it is contained or contains any topic already in the list - for (std::shared_ptr topic_stored : non_repeated_list) + for (utils::Heritable topic_stored : non_repeated_list) { if (topic_stored->contains(*new_topic)) { @@ -146,7 +142,7 @@ std::set> AllowedTopicList::get_topic_list_witho } // Remove topics repeated - for (std::shared_ptr topic_repeated : repeated) + for (utils::Heritable topic_repeated : repeated) { non_repeated_list.erase(topic_repeated); } @@ -169,11 +165,11 @@ std::ostream& operator <<( // Allowed topics os << "allowed"; - utils::container_to_stream, true>(os, atl.allowlist_); + utils::container_to_stream, true>(os, atl.allowlist_); // Blocked topics os << "blocked"; - utils::container_to_stream, true>(os, atl.blocklist_); + utils::container_to_stream, true>(os, atl.blocklist_); os << "}"; diff --git a/ddspipe_core/src_/cpp/dynamic/DiscoveryDatabase.cpp b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp similarity index 95% rename from ddspipe_core/src_/cpp/dynamic/DiscoveryDatabase.cpp rename to ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp index 9bdd4ed9a..f2ad83f11 100644 --- a/ddspipe_core/src_/cpp/dynamic/DiscoveryDatabase.cpp +++ b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp @@ -26,7 +26,7 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; DiscoveryDatabase::DiscoveryDatabase() noexcept : exit_(false) @@ -79,15 +79,15 @@ void DiscoveryDatabase::stop() noexcept } bool DiscoveryDatabase::topic_exists( - const DistributedTopic& topic) const noexcept + const DdsTopic& topic) const noexcept { std::shared_lock lock(mutex_); // Loop over every Endpoint checking if topic matches // It is not required to be reference - for (auto entity : entities_) + for (const auto& entity : entities_) { - if (entity.second.topic() == topic) + if (entity.second.topic == topic) { return true; } @@ -108,11 +108,11 @@ bool DiscoveryDatabase::add_endpoint_( { std::unique_lock lock(mutex_); - auto it = entities_.find(new_endpoint.guid()); + auto it = entities_.find(new_endpoint.guid); if (it != entities_.end()) { // Already exists - if (it->second.active()) + if (it->second.active) { throw utils::InconsistencyException( utils::Formatter() << @@ -134,7 +134,7 @@ bool DiscoveryDatabase::add_endpoint_( logInfo(DDSROUTER_DISCOVERY_DATABASE, "Inserting a new discovered Endpoint " << new_endpoint << "."); // Add it to the dictionary - entities_.insert(std::pair(new_endpoint.guid(), new_endpoint)); + entities_.insert(std::pair(new_endpoint.guid, new_endpoint)); } } @@ -153,7 +153,7 @@ bool DiscoveryDatabase::update_endpoint_( { std::unique_lock lock(mutex_); - auto it = entities_.find(endpoint_to_update.guid()); + auto it = entities_.find(endpoint_to_update.guid); if (it == entities_.end()) { // Entry not found @@ -189,7 +189,7 @@ utils::ReturnCode DiscoveryDatabase::erase_endpoint_( logInfo(DDSROUTER_DISCOVERY_DATABASE, "Erasing Endpoint " << endpoint_to_erase << "."); - auto erased = entities_.erase(endpoint_to_erase.guid()); + auto erased = entities_.erase(endpoint_to_erase.guid); if (erased == 0) { diff --git a/ddspipe_core/src_/cpp/dynamic/ParticipantsDatabase.cpp b/ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp similarity index 83% rename from ddspipe_core/src_/cpp/dynamic/ParticipantsDatabase.cpp rename to ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp index aafc3bd23..ef8936abe 100644 --- a/ddspipe_core/src_/cpp/dynamic/ParticipantsDatabase.cpp +++ b/ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp @@ -26,15 +26,13 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; - ParticipantsDatabase::~ParticipantsDatabase() { // Let the map destroy itself } std::shared_ptr ParticipantsDatabase::get_participant( - const ParticipantId& id) const noexcept + const types::ParticipantId& id) const noexcept { std::shared_lock lock(mutex_); auto it = participants_.find(id); @@ -47,10 +45,10 @@ std::shared_ptr ParticipantsDatabase::get_participant( return it->second; } -std::set ParticipantsDatabase::get_participants_ids() const noexcept +std::set ParticipantsDatabase::get_participants_ids() const noexcept { std::shared_lock lock(mutex_); - std::set result; + std::set result; for (auto it : participants_) { result.insert(it.first); @@ -58,10 +56,10 @@ std::set ParticipantsDatabase::get_participants_ids() const noexc return result; } -std::set ParticipantsDatabase::get_rtps_participants_ids() const noexcept +std::set ParticipantsDatabase::get_rtps_participants_ids() const noexcept { std::shared_lock lock(mutex_); - std::set result; + std::set result; for (auto it : participants_) { if (it.second->is_rtps_kind()) @@ -72,7 +70,7 @@ std::set ParticipantsDatabase::get_rtps_participants_ids() const return result; } -const std::map>& ParticipantsDatabase::get_participants_map() const noexcept +const std::map>& ParticipantsDatabase::get_participants_map() const noexcept { std::shared_lock lock(mutex_); return participants_; @@ -89,7 +87,7 @@ size_t ParticipantsDatabase::size() const noexcept } void ParticipantsDatabase::add_participant( - const ParticipantId& id, + const types::ParticipantId& id, const std::shared_ptr& participant) { std::unique_lock lock(mutex_); diff --git a/ddspipe_core/src_/cpp/efficiency/payload/CopyPayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp similarity index 97% rename from ddspipe_core/src_/cpp/efficiency/payload/CopyPayloadPool.cpp rename to ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp index c5cefc891..a0a55e10b 100644 --- a/ddspipe_core/src_/cpp/efficiency/payload/CopyPayloadPool.cpp +++ b/ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp @@ -24,7 +24,7 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; bool CopyPayloadPool::get_payload( uint32_t size, diff --git a/ddspipe_core/src_/cpp/efficiency/payload/FastPayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp similarity index 98% rename from ddspipe_core/src_/cpp/efficiency/payload/FastPayloadPool.cpp rename to ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp index 8437bbd6e..085347769 100644 --- a/ddspipe_core/src_/cpp/efficiency/payload/FastPayloadPool.cpp +++ b/ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp @@ -27,7 +27,7 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; bool FastPayloadPool::get_payload( uint32_t size, diff --git a/ddspipe_core/src_/cpp/efficiency/payload/MapPayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp similarity index 98% rename from ddspipe_core/src_/cpp/efficiency/payload/MapPayloadPool.cpp rename to ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp index 9041815ba..452afff11 100644 --- a/ddspipe_core/src_/cpp/efficiency/payload/MapPayloadPool.cpp +++ b/ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp @@ -27,7 +27,7 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; MapPayloadPool::~MapPayloadPool() { diff --git a/ddspipe_core/src_/cpp/efficiency/payload/PayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp similarity index 98% rename from ddspipe_core/src_/cpp/efficiency/payload/PayloadPool.cpp rename to ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp index fad2ccc1f..c426605d5 100644 --- a/ddspipe_core/src_/cpp/efficiency/payload/PayloadPool.cpp +++ b/ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp @@ -26,7 +26,7 @@ namespace eprosima { namespace ddspipe { namespace core { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; PayloadPool::PayloadPool() : reserve_count_(0) diff --git a/ddspipe_core/src/cpp/testing/test_utils.cpp b/ddspipe_core/src/cpp/testing/test_utils.cpp new file mode 100644 index 000000000..1dba5993f --- /dev/null +++ b/ddspipe_core/src/cpp/testing/test_utils.cpp @@ -0,0 +1,70 @@ +// Copyright 2021 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. + +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace test { + +using namespace eprosima::ddspipe::core::types; + +Guid random_guid( + uint16_t seed /* = 1 */) +{ + Guid guid; + guid.entityId.value[3] = static_cast(seed); + guid.guidPrefix.value[0] = 0x01; + guid.guidPrefix.value[1] = 0x0f; + return guid; +} + +DomainId random_domain( + uint16_t seed /* = 0 */) +{ + return DomainId(static_cast(seed)); +} + +GuidPrefix random_guid_prefix( + uint16_t seed /* = 0 */, + bool ros /* = false */) +{ + if (ros) + { + return GuidPrefix(true, seed); + } + else + { + return GuidPrefix(static_cast(seed)); + } +} + +ParticipantId random_participant_id( + uint16_t seed /* = 0 */) +{ + std::vector names = { + "participant", + "PART_1", + "echo", + "Barro_p", + }; + + return ParticipantId(names[seed % names.size()] + std::to_string(seed)); +} + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/dds/DomainId.cpp b/ddspipe_core/src/cpp/types/dds/DomainId.cpp similarity index 55% rename from ddspipe_core/src_/cpp/types/dds/DomainId.cpp rename to ddspipe_core/src/cpp/types/dds/DomainId.cpp index ec32ee4e2..76358019b 100644 --- a/ddspipe_core/src_/cpp/types/dds/DomainId.cpp +++ b/ddspipe_core/src/cpp/types/dds/DomainId.cpp @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DomainId.cpp - * - */ - #include namespace eprosima { @@ -24,58 +19,27 @@ namespace ddspipe { namespace core { namespace types { -const DomainIdType DomainId::DEFAULT_DOMAIN_ID_ = 0; -const DomainIdType DomainId::DEFAULT_DISCOVERY_SERVER_DOMAIN_ID_ = 66; -const DomainIdType DomainId::MAX_DOMAIN_ID_ = 230; - DomainId::DomainId ( - bool discovery_server /*= false*/) noexcept - : domain_id_(DEFAULT_DOMAIN_ID_) + bool discovery_server) noexcept + : domain_id(DEFAULT_DOMAIN_ID) { // Discovery Server case has a different default value if (discovery_server) { - domain_id_ = DEFAULT_DISCOVERY_SERVER_DOMAIN_ID_; + domain_id = DEFAULT_DISCOVERY_SERVER_DOMAIN_ID; } } -DomainId::DomainId ( - const DomainIdType& domain) noexcept - : domain_id_(domain) -{ -} - -DomainIdType DomainId::operator ()() const noexcept -{ - return domain_id_; -} - -DomainIdType DomainId::domain_id() const noexcept -{ - return domain_id_; -} - -bool DomainId::is_valid() const noexcept -{ - return domain_id_ <= MAX_DOMAIN_ID_; -} - -bool DomainId::operator ==( - const DomainId& other) const noexcept -{ - return this->domain_id() == other.domain_id(); -} - DomainId::operator DomainIdType() const noexcept { - return this->domain_id(); + return this->domain_id; } std::ostream& operator <<( std::ostream& output, const DomainId& domain) { - output << "DomainId{" << domain.domain_id() << "}"; + output << "DomainId{" << domain.domain_id << "}"; return output; } diff --git a/ddspipe_core/src/cpp/types/dds/Endpoint.cpp b/ddspipe_core/src/cpp/types/dds/Endpoint.cpp new file mode 100644 index 000000000..e3fbbfe14 --- /dev/null +++ b/ddspipe_core/src/cpp/types/dds/Endpoint.cpp @@ -0,0 +1,64 @@ +// Copyright 2021 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. + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { + +TopicQoS Endpoint::topic_qos() const noexcept +{ + return topic.topic_qos; +} + +bool Endpoint::is_writer() const noexcept +{ + return kind == EndpointKind::writer; +} + +bool Endpoint::is_reader() const noexcept +{ + return kind == EndpointKind::reader; +} + +bool Endpoint::is_server_endpoint() const noexcept +{ + return (is_reader() && RpcTopic::is_request_topic(topic)) || (is_writer() && RpcTopic::is_reply_topic(topic)); +} + +std::ostream& operator <<( + std::ostream& os, + const Endpoint& endpoint) +{ + std::string active_str = endpoint.active ? "Active" : "Inactive"; + + os << + "Endpoint{" << endpoint.guid << + ";" << endpoint.kind << + ";" << endpoint.topic << + ";" << endpoint.specific_qos << + ";" << active_str << + ";" << endpoint.discoverer_participant_id << + "}"; + + return os; +} + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/dds/Guid.cpp b/ddspipe_core/src/cpp/types/dds/Guid.cpp similarity index 98% rename from ddspipe_core/src_/cpp/types/dds/Guid.cpp rename to ddspipe_core/src/cpp/types/dds/Guid.cpp index f6816c54e..8d5113a99 100644 --- a/ddspipe_core/src_/cpp/types/dds/Guid.cpp +++ b/ddspipe_core/src/cpp/types/dds/Guid.cpp @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Guid.cpp - * - */ - #include namespace eprosima { diff --git a/ddspipe_core/src_/cpp/types/dds/GuidPrefix.cpp b/ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp similarity index 85% rename from ddspipe_core/src_/cpp/types/dds/GuidPrefix.cpp rename to ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp index 02c356351..3e329652a 100644 --- a/ddspipe_core/src_/cpp/types/dds/GuidPrefix.cpp +++ b/ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp @@ -12,13 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file GuidPrefix.cpp - * - */ - -#include - #include namespace eprosima { @@ -26,9 +19,6 @@ namespace ddspipe { namespace core { namespace types { -const char* GuidPrefix::SERVER_DEFAULT_GUID_PREFIX_STR_("01.0f.00.00.00.00.00.00.00.00.ca.fe"); -const char* GuidPrefix::ROS_DISCOVERY_SERVER_GUID_PREFIX_STR_(fastdds::rtps::DEFAULT_ROS2_SERVER_GUIDPREFIX); - GuidPrefix::GuidPrefix ( const GuidPrefix_t& guid_prefix) noexcept : GuidPrefix_t(guid_prefix) @@ -56,12 +46,12 @@ GuidPrefix::GuidPrefix ( { if (ros) { - std::stringstream ss(ROS_DISCOVERY_SERVER_GUID_PREFIX_STR_); + std::stringstream ss(ROS_DISCOVERY_SERVER_GUID_PREFIX_STR); ss >> *this; } else { - std::stringstream ss(SERVER_DEFAULT_GUID_PREFIX_STR_); + std::stringstream ss(SERVER_DEFAULT_GUID_PREFIX_STR); ss >> *this; } diff --git a/ddspipe_core/src_/cpp/types/data/Payload.cpp b/ddspipe_core/src/cpp/types/dds/Payload.cpp similarity index 97% rename from ddspipe_core/src_/cpp/types/data/Payload.cpp rename to ddspipe_core/src/cpp/types/dds/Payload.cpp index 3398872e7..8633ea169 100644 --- a/ddspipe_core/src_/cpp/types/data/Payload.cpp +++ b/ddspipe_core/src/cpp/types/dds/Payload.cpp @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file Payload.cpp - * - */ - #include #include diff --git a/ddspipe_core/src_/cpp/types/dds/SpecificEndpointQoS.cpp b/ddspipe_core/src/cpp/types/dds/SpecificEndpointQoS.cpp similarity index 100% rename from ddspipe_core/src_/cpp/types/dds/SpecificEndpointQoS.cpp rename to ddspipe_core/src/cpp/types/dds/SpecificEndpointQoS.cpp diff --git a/ddspipe_core/src_/cpp/types/dds/TopicQoS.cpp b/ddspipe_core/src/cpp/types/dds/TopicQoS.cpp similarity index 100% rename from ddspipe_core/src_/cpp/types/dds/TopicQoS.cpp rename to ddspipe_core/src/cpp/types/dds/TopicQoS.cpp diff --git a/ddspipe_core/src_/cpp/types/topic/Topic.cpp b/ddspipe_core/src/cpp/types/topic/Topic.cpp similarity index 54% rename from ddspipe_core/src_/cpp/types/topic/Topic.cpp rename to ddspipe_core/src/cpp/types/topic/Topic.cpp index b520f0058..465d9caae 100644 --- a/ddspipe_core/src_/cpp/types/topic/Topic.cpp +++ b/ddspipe_core/src/cpp/types/topic/Topic.cpp @@ -24,25 +24,45 @@ namespace ddspipe { namespace core { namespace types { -Topic::Topic( - const std::string& topic_name, - const TopicInternalTypeDiscriminator& internal_type_discriminator) - : topic_name(topic_name) - , internal_type_discriminator(internal_type_discriminator) +///////////////////////// +// OPERATORS +///////////////////////// + +bool Topic::operator==(const ITopic& other) const noexcept +{ + return + topic_unique_name() == other.topic_unique_name(); +} + +bool Topic::operator<(const ITopic& other) const noexcept +{ + return topic_unique_name() < other.topic_unique_name(); +} + +///////////////////////// +// METHODS +///////////////////////// + +const std::string& Topic::topic_name() const noexcept { - // Do nothing + return m_topic_name; +} + +const TopicInternalTypeDiscriminator& Topic::internal_type_discriminator() const noexcept +{ + return m_internal_type_discriminator; } bool Topic::is_valid( utils::Formatter& error_msg) const noexcept { - if (topic_name.empty()) + if (m_topic_name.empty()) { error_msg << "Topic name could not be empty. "; return false; } - if (internal_type_discriminator == INTERNAL_TOPIC_TYPE_NONE) + if (m_internal_type_discriminator == INTERNAL_TOPIC_TYPE_NONE) { error_msg << "Internal type discriminator could not be None. "; return false; @@ -51,11 +71,25 @@ bool Topic::is_valid( return true; } +///////////////////////// +// METHODS TO OVERRIDE +///////////////////////// + +//! ITopic unique name in processs +std::string Topic::topic_unique_name() const noexcept +{ + return m_topic_name + m_internal_type_discriminator; +} + +///////////////////////// +// SERIALIZE +///////////////////////// + std::ostream& operator <<( std::ostream& os, const Topic& t) { - os << "Topic{" << t.topic_name << "," << t.internal_type_discriminator << "}"; + os << "Topic{" << t.m_topic_name << ";(" << t.m_internal_type_discriminator << ")}"; return os; } diff --git a/ddspipe_core/src_/cpp/types/topic/dds/DdsTopic.cpp b/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp similarity index 58% rename from ddspipe_core/src_/cpp/types/topic/dds/DdsTopic.cpp rename to ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp index 9532d0b84..cc3f4e41d 100644 --- a/ddspipe_core/src_/cpp/types/topic/dds/DdsTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp @@ -13,42 +13,33 @@ // limitations under the License. /** - * @file DistributedTopic.cpp + * @file DdsTopic.cpp * */ #include #include -#include -#include +#include namespace eprosima { namespace ddspipe { namespace core { namespace types { -DistributedTopic::DistributedTopic( - const std::string& topic_name, - const std::string& type_name) noexcept - : Topic(topic_name) - , type_name(type_name) +std::ostream& operator <<( + std::ostream& os, + const DdsTopic& t) { + os << "DdsTopic{" << t.topic_name() << ";" << t.type_name << t.topic_qos << "}"; + return os; } -DistributedTopic::DistributedTopic( - const std::string& topic_name, - const std::string& type_name, - const bool keyed, - const types::TopicQoS& qos) noexcept - : Topic(topic_name) - , type_name(type_name) - , keyed(keyed) - , topic_qos(qos) -{ -} +///////////////////////// +// METHODS +///////////////////////// -bool DistributedTopic::is_valid( +bool DdsTopic::is_valid( utils::Formatter& error_msg) const noexcept { if (!Topic::is_valid(error_msg)) @@ -56,6 +47,24 @@ bool DistributedTopic::is_valid( return false; } + return is_valid_dds_topic(m_topic_name, type_name, error_msg); +} + +std::string DdsTopic::topic_unique_name() const noexcept +{ + return Topic::topic_unique_name() + type_name; +} + +///////////////////////// +// STATIC METHODS +///////////////////////// + +bool DdsTopic::is_valid_dds_topic( + const std::string& topic_name, + const std::string& type_name, + utils::Formatter& error_msg) noexcept +{ + if (type_name.empty()) { error_msg << "Topic type name could not be empty. "; @@ -85,42 +94,6 @@ bool DistributedTopic::is_valid( return true; } -bool DistributedTopic::operator < ( - const DistributedTopic& other) const noexcept -{ - if (Topic::operator ==(other)) - { - return this->type_name < other.type_name; - } - return Topic::operator <(other); -} - -bool DistributedTopic::operator == ( - const DistributedTopic& other) const noexcept -{ - return - Topic::operator ==(other) && - this->type_name == other.type_name; -} - -bool DistributedTopic::is_valid_dds_topic( - const std::string& topic_name, - const std::string& type_name) noexcept -{ - utils::Formatter __f; - return DistributedTopic(topic_name, type_name).is_valid(__f); -} - -std::ostream& operator <<( - std::ostream& os, - const DistributedTopic& t) -{ - std::string keyed_str = t.keyed ? ";keyed;" : ";"; - - os << "DistributedTopic{" << t.topic_name << ";" << t.type_name << keyed_str << t.topic_qos << "}"; - return os; -} - } /* namespace types */ } /* namespace core */ } /* namespace ddspipe */ diff --git a/ddspipe_core/src_/cpp/types/topic/filter/DdsFilterTopic.cpp b/ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp similarity index 78% rename from ddspipe_core/src_/cpp/types/topic/filter/DdsFilterTopic.cpp rename to ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp index 43920887a..e833b721c 100644 --- a/ddspipe_core/src_/cpp/types/topic/filter/DdsFilterTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file DdsFilterTopic.cpp - * - */ - -#include +#include #include namespace eprosima { @@ -25,21 +20,21 @@ namespace ddspipe { namespace core { namespace types { -bool DdsFilterTopic::operator < ( - const DdsFilterTopic& other) const noexcept +bool IFilterTopic::operator < ( + const IFilterTopic& other) const noexcept { return utils::generic_to_string(other) < utils::generic_to_string(*this); } -bool DdsFilterTopic::operator == ( - const DdsFilterTopic& other) const noexcept +bool IFilterTopic::operator == ( + const IFilterTopic& other) const noexcept { return utils::generic_to_string(other) == utils::generic_to_string(*this); } std::ostream& operator <<( std::ostream& os, - const DdsFilterTopic& t) + const IFilterTopic& t) { t.serialize(os); return os; diff --git a/ddspipe_core/src_/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp b/ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp similarity index 67% rename from ddspipe_core/src_/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp rename to ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp index 66c4b99e2..e80d2c669 100644 --- a/ddspipe_core/src_/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp @@ -12,56 +12,36 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file WildcardDdsFilterTopic.cpp - * - */ +#include +#include #include -#include namespace eprosima { namespace ddspipe { namespace core { namespace types { -WildcardDdsFilterTopic::WildcardDdsFilterTopic( - const std::string topic_name /* = "*" */) - : topic_name(topic_name) -{ -} - bool WildcardDdsFilterTopic::contains( - const DdsFilterTopic& other) const + const IFilterTopic& other) const { + if (!IS_SAME_TYPE_AS_THIS(other)) + { + return false; + } // TODO: implement static_cast (other); return false; } bool WildcardDdsFilterTopic::matches( - const DistributedTopic& other) const + const ITopic& other) const { - // Compare key - if (this->keyed.is_set()) + if (utils::can_cast(other)) { - if (this->keyed != other.keyed) - { - return false; - } + return matches_(static_cast(other)); } - - // Compare type_name - if (this->type_name.is_set()) - { - if (!utils::match_pattern(this->type_name.get_reference(), other.type_name)) - { - return false; - } - } - - // Compare topic name - return utils::match_pattern(this->topic_name, other.topic_name); + return false; } ///////////////////////// @@ -79,16 +59,32 @@ std::ostream& operator <<( std::ostream& os, const WildcardDdsFilterTopic& t) { - std::string keyed_str = t.keyed.is_set() - ? STR_ENTRY << ";keyed" - : STR_ENTRY << ""; + os << "WildcardDdsFilterTopic{" << t.topic_name << ";" << t.type_name << "}"; + return os; +} + +bool WildcardDdsFilterTopic::matches_( + const DdsTopic& real_topic) const +{ + // Compare topic_name + if (this->topic_name.is_set()) + { + if (!utils::match_pattern(this->topic_name.get_reference(), real_topic.topic_name())) + { + return false; + } + } - std::string type_name_str = t.type_name.is_set() - ? STR_ENTRY << ";" << t.type_name - : STR_ENTRY << ""; + // Compare type_name + if (this->type_name.is_set()) + { + if (!utils::match_pattern(this->type_name.get_reference(), real_topic.type_name)) + { + return false; + } + } - os << "WildcardDdsFilterTopic{" << t.topic_name << type_name_str << keyed_str << "}"; - return os; + return true; } } /* namespace types */ diff --git a/ddspipe_core/src_/cpp/types/topic/rpc/RPCTopic.cpp b/ddspipe_core/src/cpp/types/topic/rpc/RPCTopic.cpp similarity index 66% rename from ddspipe_core/src_/cpp/types/topic/rpc/RPCTopic.cpp rename to ddspipe_core/src/cpp/types/topic/rpc/RPCTopic.cpp index 0ac555398..056790019 100644 --- a/ddspipe_core/src_/cpp/types/topic/rpc/RPCTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/rpc/RPCTopic.cpp @@ -35,8 +35,8 @@ const std::string RpcTopic::RESPONSE_STR = "Response"; RpcTopic::RpcTopic( const std::string& service_name, - const DistributedTopic& request_topic, - const DistributedTopic& reply_topic) noexcept + const DdsTopic& request_topic, + const DdsTopic& reply_topic) noexcept : service_name_(service_name) , request_topic_(request_topic) , reply_topic_(reply_topic) @@ -44,35 +44,35 @@ RpcTopic::RpcTopic( } RpcTopic::RpcTopic( - const DistributedTopic& topic) noexcept + const DdsTopic& topic) noexcept { if (is_request_topic(topic)) { request_topic_ = topic; reply_topic_ = topic; - reply_topic_.topic_name = - std::regex_replace(reply_topic_.topic_name, std::regex(REQUEST_PREFIX_STR), REPLY_PREFIX_STR); - reply_topic_.topic_name = - std::regex_replace(reply_topic_.topic_name, std::regex(REQUEST_STR), REPLY_STR); + reply_topic_.m_topic_name = + std::regex_replace(reply_topic_.m_topic_name, std::regex(REQUEST_PREFIX_STR), REPLY_PREFIX_STR); + reply_topic_.m_topic_name = + std::regex_replace(reply_topic_.m_topic_name, std::regex(REQUEST_STR), REPLY_STR); reply_topic_.type_name = std::regex_replace(reply_topic_.type_name, std::regex(REQUEST_STR), RESPONSE_STR); - service_name_ = std::regex_replace(topic.topic_name, std::regex(REQUEST_PREFIX_STR + "|" + REQUEST_STR), ""); + service_name_ = std::regex_replace(topic.m_topic_name, std::regex(REQUEST_PREFIX_STR + "|" + REQUEST_STR), ""); } else if (is_reply_topic(topic)) { reply_topic_ = topic; request_topic_ = topic; - request_topic_.topic_name = - std::regex_replace(request_topic_.topic_name, std::regex(REPLY_PREFIX_STR), REQUEST_PREFIX_STR); - request_topic_.topic_name = - std::regex_replace(request_topic_.topic_name, std::regex(REPLY_STR), REQUEST_STR); + request_topic_.m_topic_name = + std::regex_replace(request_topic_.m_topic_name, std::regex(REPLY_PREFIX_STR), REQUEST_PREFIX_STR); + request_topic_.m_topic_name = + std::regex_replace(request_topic_.m_topic_name, std::regex(REPLY_STR), REQUEST_STR); request_topic_.type_name = std::regex_replace(request_topic_.type_name, std::regex(RESPONSE_STR), REQUEST_STR); - service_name_ = std::regex_replace(topic.topic_name, std::regex(REPLY_PREFIX_STR + "|" + REPLY_STR), ""); + service_name_ = std::regex_replace(topic.m_topic_name, std::regex(REPLY_PREFIX_STR + "|" + REPLY_STR), ""); } else { @@ -90,40 +90,40 @@ const std::string& RpcTopic::service_name() const return service_name_; } -const DistributedTopic& RpcTopic::request_topic() const +const DdsTopic& RpcTopic::request_topic() const { return request_topic_; } -const DistributedTopic& RpcTopic::reply_topic() const +const DdsTopic& RpcTopic::reply_topic() const { return reply_topic_; } bool RpcTopic::is_request_topic( - const DistributedTopic& topic) + const DdsTopic& topic) { - std::string topic_name = topic.topic_name; + std::string m_topic_name = topic.m_topic_name; std::string type_name = topic.type_name; - return (topic_name.find(REQUEST_PREFIX_STR) == 0) && - (topic_name.rfind(REQUEST_STR) + REQUEST_STR.length() == topic_name.length()) && + return (m_topic_name.find(REQUEST_PREFIX_STR) == 0) && + (m_topic_name.rfind(REQUEST_STR) + REQUEST_STR.length() == m_topic_name.length()) && (type_name.rfind(REQUEST_STR) + REQUEST_STR.length() + 1 == type_name.length()); } bool RpcTopic::is_reply_topic( - const DistributedTopic& topic) + const DdsTopic& topic) { - std::string topic_name = topic.topic_name; + std::string m_topic_name = topic.m_topic_name; std::string type_name = topic.type_name; - return (topic_name.find(REPLY_PREFIX_STR) == 0) && - (topic_name.rfind(REPLY_STR) + REPLY_STR.length() == topic_name.length()) && + return (m_topic_name.find(REPLY_PREFIX_STR) == 0) && + (m_topic_name.rfind(REPLY_STR) + REPLY_STR.length() == m_topic_name.length()) && (type_name.rfind(RESPONSE_STR) + RESPONSE_STR.length() + 1 == type_name.length()); } bool RpcTopic::is_service_topic( - const DistributedTopic& topic) + const DdsTopic& topic) { return is_request_topic(topic) || is_reply_topic(topic); } diff --git a/ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp b/ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp deleted file mode 100644 index c1a433aec..000000000 --- a/ddspipe_core/src_/cpp/configuration/DDSRouterConfiguration.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2021 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 DDSRouterConfiguration.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddsrouter::core::types; - -DDSRouterConfiguration::DDSRouterConfiguration( - const std::set>& allowlist, - const std::set>& blocklist, - const std::set>& builtin_topics, - const SpecsConfiguration& advanced_options) - : DDSRouterReloadConfiguration (allowlist, blocklist, builtin_topics) - , advanced_options(advanced_options) -{ -} - -bool DDSRouterConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - // Check Allow list topics - if (!DDSRouterReloadConfiguration::is_valid(error_msg)) - { - return false; - } - - return true; -} - -void DDSRouterConfiguration::reload( - const DDSRouterReloadConfiguration& new_configuration) -{ - this->allowlist = new_configuration.allowlist; - this->blocklist = new_configuration.blocklist; - this->builtin_topics = new_configuration.builtin_topics; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp b/ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp deleted file mode 100644 index e747d0197..000000000 --- a/ddspipe_core/src_/cpp/configuration/DDSRouterReloadConfiguration.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2021 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 DDSRouterReloadConfiguration.cpp - * - */ - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddsrouter::core::types; - -DDSRouterReloadConfiguration::DDSRouterReloadConfiguration( - std::set> allowlist, - std::set> blocklist, - std::set> builtin_topics) - : allowlist(allowlist) - , blocklist(blocklist) - , builtin_topics(builtin_topics) -{ -} - -bool DDSRouterReloadConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - // Check Allow list topics - for (std::shared_ptr topic : allowlist) - { - if (!topic) - { - logDevError(DDSROUTER_CONFIGURATION, "Invalid ptr in allowlist topics."); - error_msg << "nullptr Filter Topic in allowlist. "; - return false; - } - } - - // Check Block list topics - for (std::shared_ptr topic : blocklist) - { - if (!topic) - { - logDevError(DDSROUTER_CONFIGURATION, "Invalid ptr in blocklist topics."); - error_msg << "nullptr Filter Topic in blocklist. "; - return false; - } - } - - // Check Builtin list topics - for (std::shared_ptr topic : builtin_topics) - { - if (!topic) - { - logDevError(DDSROUTER_CONFIGURATION, "Invalid ptr in builtin topics."); - error_msg << "nullptr Topic in builtin. "; - return false; - } - - if (!topic->is_valid(error_msg)) - { - error_msg << "Invalid Topic " << topic << " in Builtin list. "; - return false; - } - } - - return true; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp b/ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp deleted file mode 100644 index dd5031f7e..000000000 --- a/ddspipe_core/src_/cpp/configuration/SpecsConfiguration.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022 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 SpecsConfiguration.cpp - * - */ - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -bool SpecsConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - if (number_of_threads < 1) - { - error_msg << "Number of Threads must be at least 1."; - return false; - } - - if (max_history_depth == 0) - { - logWarning(DDSROUTER_SPECS, "Using non limited histories could lead to memory exhaustion in long executions."); - } - - return true; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp b/ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp deleted file mode 100644 index b13df427e..000000000 --- a/ddspipe_core/src_/cpp/efficiency/cache_change/CacheChangePool.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2022 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. - - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -CacheChangePool::CacheChangePool( - utils::PoolConfiguration configuration) - : utils::UnboundedPool(configuration) -{ - initialize_vector_(); -} - -bool CacheChangePool::reserve_cache( - fastrtps::rtps::CacheChange_t*& cache_change) -{ - return loan(cache_change); -} - -bool CacheChangePool::release_cache( - fastrtps::rtps::CacheChange_t* cache_change) -{ - return return_loan(cache_change); -} - -fastrtps::rtps::CacheChange_t* CacheChangePool::new_element_() -{ - return new types::RouterCacheChange(); -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/testing/test_utils.cpp b/ddspipe_core/src_/cpp/testing/test_utils.cpp deleted file mode 100644 index 99cb3d413..000000000 --- a/ddspipe_core/src_/cpp/testing/test_utils.cpp +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright 2021 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 test_utils.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -using namespace eprosima::ddsrouter::core::types; - -Guid random_guid( - uint16_t seed /* = 1 */) -{ - Guid guid; - guid.entityId.value[3] = static_cast(seed); - guid.guidPrefix.value[0] = 0x01; - guid.guidPrefix.value[1] = 0x0f; - return guid; -} - -TopicInput::TopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set) - : name(name) - , type(type) - , keyed(keyed) - , key_set(key_set) -{ -} - -DdsTopicInput::DdsTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool reliable, - bool reliable_set) - : TopicInput(name, type, keyed, key_set) - , reliable(reliable) - , reliable_set(reliable_set) -{ -} - -WildcardTopicInput::WildcardTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool type_set) - : TopicInput(name, type, keyed, key_set) - , type_set(type_set) -{ -} - -std::set> topic_set( - std::vector topics) -{ - std::set> result; - for (DdsTopicInput input : topics) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = input.name; - new_topic->type_name = input.type; - - if (input.key_set) - { - new_topic->keyed = input.keyed; - } - - - if (input.reliable_set) - { - TopicQoS qos; - if (input.reliable) - { - qos.reliability_qos = ReliabilityKind::RELIABLE; - } - else - { - qos.reliability_qos = ReliabilityKind::BEST_EFFORT; - } - new_topic->topic_qos = qos; - new_topic->topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_fuzzy); - } - - result.insert(new_topic); - } - return result; -} - -std::set> topic_set( - std::vector topics) -{ - std::set> result; - for (WildcardTopicInput input : topics) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = input.name; - new_topic->type_name = input.type; - - if (input.key_set) - { - new_topic->keyed = input.type_set; - } - - result.insert(new_topic); - - } - return result; -} - -DomainId random_domain( - uint16_t seed /* = 0 */) -{ - return DomainId(static_cast(seed)); -} - -GuidPrefix random_guid_prefix( - uint16_t seed /* = 0 */, - bool ros /* = false */) -{ - if (ros) - { - return GuidPrefix(true, seed); - } - else - { - return GuidPrefix(static_cast(seed)); - } -} - -Address random_address( - uint16_t seed /* = 0 */) -{ - return Address("127.0.0.1", seed, seed, TransportProtocol::udp); -} - -std::set random_connection_addresses( - uint16_t seed /* = 0 */, - uint16_t size /* = 1 */, - bool ros /* = false */) -{ - std::set result; - - for (int i = 0; i < size; ++i) - { - result.insert( - DiscoveryServerConnectionAddress( - random_guid_prefix((seed * size + i) * i), - std::set
({ - random_address((seed * size + i) * i), - random_address((seed * size + i) * i + 1)}))); - } - return result; -} - -std::shared_ptr random_participant_configuration( - ParticipantKind kind, - uint16_t seed /* = 0 */) -{ - ParticipantId id("Participant" + std::to_string(seed)); - - switch (kind) - { - case ParticipantKind::simple_rtps: - return std::make_shared( - id, - kind, - false, - random_domain(seed)); - - case ParticipantKind::local_discovery_server: - case ParticipantKind::wan_discovery_server: - - { - // TODO get random values - DiscoveryServerConnectionAddress connection_address = DiscoveryServerConnectionAddress( - GuidPrefix(), - std::set
({Address()}) - ); - - return std::make_shared( - id, - kind, - false, - random_domain(seed), - random_guid_prefix(seed), - std::set
(), - std::set({connection_address}), - security::TlsConfiguration()); - } - - case ParticipantKind::wan_initial_peers: - - { - return std::make_shared( - id, - kind, - false, - random_domain(seed), - std::set
(), - std::set
({Address()}), - security::TlsConfiguration()); - } - - case ParticipantKind::echo: - { - return std::make_shared( - id, - kind, - false); - } - - // Add cases where Participants need specific arguments - default: - return std::make_shared(id, false); - } -} - -ParticipantId random_participant_id( - uint16_t seed /* = 0 */) -{ - std::vector names = { - "participant", - "PART_1", - "echo", - "Barro_p", - }; - - return ParticipantId(names[seed % names.size()] + std::to_string(seed)); -} - -ParticipantKind random_participant_kind( - bool valid /* = true */, - uint16_t seed /* = 0 */) -{ - std::vector kinds(std::begin(ALL_VALID_PARTICIPANT_KINDS), std::end(ALL_VALID_PARTICIPANT_KINDS)); - if (valid) - { - return kinds[seed % kinds.size()]; - } - else - { - kinds.push_back(ParticipantKind::invalid); - return kinds[seed % kinds.size()]; - } -} - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/address/Address.cpp b/ddspipe_core/src_/cpp/types/address/Address.cpp deleted file mode 100644 index 73eb94adc..000000000 --- a/ddspipe_core/src_/cpp/types/address/Address.cpp +++ /dev/null @@ -1,442 +0,0 @@ -// Copyright 2021 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 Address.cpp - * - */ - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -const PortType Address::DEFAULT_PORT_ = 11666; -const IpType Address::DEFAULT_IP_v4_ = "127.0.0.1"; -const IpType Address::DEFAULT_IP_v6_ = "::1"; -const IpVersion Address::DEFAULT_IP_VERSION_ = IpVersion::v4; -const TransportProtocol Address::DEFAULT_TRANSPORT_PROTOCOL_ = TransportProtocol::udp; - -Address::Address() - : Address(DEFAULT_IP_v4_, DEFAULT_PORT_, DEFAULT_PORT_, DEFAULT_IP_VERSION_, DEFAULT_TRANSPORT_PROTOCOL_) -{ -} - -Address::Address( - const IpType& ip, - const PortType& port, - const PortType& external_port, - const IpVersion& ip_version, - const TransportProtocol& transport_protocol) noexcept - : ip_(ip) - , domain_() - , has_domain_(false) - , has_valid_domain_(false) - , port_(port) - , external_port_(external_port) - , ip_version_(ip_version) - , transport_protocol_(transport_protocol) -{ -} - -Address::Address( - const PortType& port, - const PortType& external_port, - const IpVersion& ip_version, - const DomainType& domain, - const TransportProtocol& transport_protocol) noexcept - : ip_() - , domain_(domain) - , has_domain_(true) - , has_valid_domain_(false) - , port_(port) - , external_port_(external_port) - , ip_version_(ip_version) - , transport_protocol_(transport_protocol) -{ - try - { - ip_ = Address::resolve_dns(domain_, ip_version_); - has_valid_domain_ = true; - } - catch (const utils::DNSException& ) - { - logWarning( - DDSROUTER_ADDRESS, "Address created without IP because given domain " << domain << " was not found."); - } -} - -Address::Address( - const IpType& ip, - const PortType& port, - const PortType& external_port, - const TransportProtocol& transport_protocol) noexcept - : Address(ip, port, external_port, IpVersion::v4, transport_protocol) -{ - if (is_ipv6_correct(ip_)) - { - ip_version_ = IpVersion::v6; - } -} - -Address::Address( - const PortType& port, - const PortType& external_port, - const DomainType& domain, - const TransportProtocol& transport_protocol) noexcept - : ip_() - , domain_(domain) - , has_domain_(true) - , has_valid_domain_(false) - , port_(port) - , external_port_(external_port) - , transport_protocol_(transport_protocol) -{ - try - { - auto dns_respone = Address::resolve_dns(domain_); - ip_ = dns_respone.first; - ip_version_ = dns_respone.second; - has_valid_domain_ = true; - } - catch (const utils::DNSException& ) - { - logWarning( - DDSROUTER_ADDRESS, "Address created without IP because given domain " << domain << " was not found."); - } -} - -PortType Address::port() const noexcept -{ - return port_; -} - -PortType Address::external_port() const noexcept -{ - return external_port_; -} - -IpType Address::ip() const noexcept -{ - return ip_; -} - -IpVersion Address::ip_version() const noexcept -{ - return ip_version_; -} - -TransportProtocol Address::transport_protocol() const noexcept -{ - return transport_protocol_; -} - -bool Address::is_udp() const noexcept -{ - return transport_protocol_ == TransportProtocol::udp; -} - -bool Address::is_tcp() const noexcept -{ - return transport_protocol_ == TransportProtocol::tcp; -} - -bool Address::is_ipv4() const noexcept -{ - return ip_version_ == IpVersion::v4; -} - -bool Address::is_ipv6() const noexcept -{ - return ip_version_ == IpVersion::v6; -} - -LocatorType Address::get_locator_kind() const noexcept -{ - if (ip_version_ == IpVersion::v4) - { - if (transport_protocol_ == TransportProtocol::udp) - { - return LOCATOR_KIND_UDPv4; - } - else if (transport_protocol_ == TransportProtocol::tcp) - { - return LOCATOR_KIND_TCPv4; - } - } - else if (ip_version_ == IpVersion::v6) - { - if (transport_protocol_ == TransportProtocol::udp) - { - return LOCATOR_KIND_UDPv6; - } - else if (transport_protocol_ == TransportProtocol::tcp) - { - return LOCATOR_KIND_TCPv6; - } - } - - return LOCATOR_KIND_INVALID; -} - -bool Address::is_valid() const noexcept -{ - if (has_domain_ && !has_valid_domain_) - { - return false; - } - - // Check that if UDP, external port must be not set (must be equal to internal port) - if (is_udp()) - { - if (port_ != external_port_) - { - return false; - } - } - - // Check correct ip - switch (ip_version_) - { - case IpVersion::v4: - return is_ipv4_correct(ip_); - - case IpVersion::v6: - return is_ipv6_correct(ip_); - - default: - utils::tsnh( - utils::Formatter() << "Ip version value out of IpVersion."); - return false; // Unreachable code - } -} - -bool Address::operator <( - const Address& other) const noexcept -{ - // Compare IPs - int ip_comparison = this->ip_.compare(other.ip_); - if (ip_comparison < 0) - { - return true; - } - else if (ip_comparison > 0) - { - return false; - } - else - { - // Compare Ports - if (this->port_ < other.port_) - { - return true; - } - else if (this->port_ > other.port_) - { - return false; - } - else - { - // Compare Protocol - if (this->transport_protocol_ < other.transport_protocol_) - { - return true; - } - else if (this->transport_protocol_ > other.transport_protocol_) - { - return false; - } - else - { - // Compare Ip Version - return this->ip_version_ < other.ip_version_; - } - } - } -} - -bool Address::operator ==( - const Address& other) const noexcept -{ - return this->ip() == other.ip() && - this->port() == other.port() && - this->transport_protocol() == other.transport_protocol() && - this->is_valid() == other.is_valid(); -} - -bool Address::is_ipv4_correct( - const IpType& ip) noexcept -{ - return eprosima::fastrtps::rtps::IPLocator::isIPv4(ip); -} - -bool Address::is_ipv6_correct( - const IpType& ip) noexcept -{ - return eprosima::fastrtps::rtps::IPLocator::isIPv6(ip); -} - -PortType Address::default_port() noexcept -{ - return DEFAULT_PORT_; -} - -IpType Address::default_ip( - IpVersion ip_version /* = default_ip_version() */) noexcept -{ - if (ip_version == IpVersion::v4) - { - return DEFAULT_IP_v4_; - } - else if (ip_version == IpVersion::v6) - { - return DEFAULT_IP_v6_; - } - else - { - utils::tsnh(utils::Formatter() << "Value v" << static_cast(ip_version) << - " is not allowed for IpVersion."); - return DEFAULT_IP_v4_; - } -} - -IpVersion Address::default_ip_version() noexcept -{ - return DEFAULT_IP_VERSION_; -} - -TransportProtocol Address::default_transport_protocol() noexcept -{ - return DEFAULT_TRANSPORT_PROTOCOL_; -} - -IpType Address::resolve_dns( - DomainType domain, - IpVersion ip_version) -{ - std::pair, std::set> dns_response = - fastrtps::rtps::IPLocator::resolveNameDNS(domain); - - if (ip_version == IpVersion::v4) - { - if (dns_response.first.empty()) - { - throw utils::DNSException( - utils::Formatter() << "Could not resolve IpVersion::v4 for domain name <" << domain << ">."); - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v4: " << dns_response.first.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << dns_response.first.size() << " valid IPs."); - return dns_response.first.begin()->data(); - } - } - else - { - if (dns_response.second.empty()) - { - throw utils::DNSException( - utils::Formatter() << "Could not resolve IpVersion::v6 for domain name <" << domain << ">."); - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v6: " << dns_response.second.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << dns_response.second.size() << " valid IPs."); - return dns_response.second.begin()->data(); - } - } -} - -std::pair Address::resolve_dns( - DomainType domain) -{ - std::pair, std::set> dns_response = - fastrtps::rtps::IPLocator::resolveNameDNS(domain); - - if (dns_response.first.empty()) - { - if (dns_response.second.empty()) - { - throw utils::DNSException( - utils::Formatter() << - "Could not resolve IP for IpVersion::v4 nor IpVersion::v6 for domain name <" << domain << - ">."); - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v6: " << dns_response.second.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << dns_response.second.size() << " valid IPs."); - return {dns_response.second.begin()->data(), IpVersion::v6}; - } - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v4: " << dns_response.first.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << (dns_response.first.size() + dns_response.second.size()) << - " valid IPs."); - return {dns_response.first.begin()->data(), IpVersion::v4}; - } -} - -std::ostream& operator <<( - std::ostream& output, - const Address& address) -{ - output << "{"; - - if (address.has_domain_) - { - output << address.domain_ << "(" << address.ip() << ");"; - } - else - { - output << address.ip() << ";"; - } - output << address.port() << ";"; - - if (address.is_udp()) - { - output << "udp}"; - } - else - { - // TODO change for else if cause there may be more transports - output << "tcp}"; - } - - return output; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp b/ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp deleted file mode 100644 index 479e54070..000000000 --- a/ddspipe_core/src_/cpp/types/address/DiscoveryServerConnectionAddress.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2021 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 DiscoveryServerConnectionAddress.cpp - * - */ - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -DiscoveryServerConnectionAddress::DiscoveryServerConnectionAddress( - GuidPrefix discovery_server_guid, - std::set
addresses) - : discovery_server_guid_prefix_(discovery_server_guid) - , addresses_(addresses) -{ -} - -GuidPrefix DiscoveryServerConnectionAddress::discovery_server_guid_prefix() const noexcept -{ - return discovery_server_guid_prefix_; -} - -std::set
DiscoveryServerConnectionAddress::addresses() const noexcept -{ - return addresses_; -} - -bool DiscoveryServerConnectionAddress::is_valid() const noexcept -{ - if (!discovery_server_guid_prefix_.is_valid()) - { - return false; - } - - for (auto address : addresses_) - { - if (address.is_valid()) - { - return true; - } - } - - return false; -} - -bool DiscoveryServerConnectionAddress::operator <( - const DiscoveryServerConnectionAddress& other) const noexcept -{ - if (this->discovery_server_guid_prefix() == other.discovery_server_guid_prefix()) - { - // Same Guid - return this->addresses() < other.addresses(); - } - else - { - // Different guid - return this->discovery_server_guid_prefix() < other.discovery_server_guid_prefix(); - } -} - -bool DiscoveryServerConnectionAddress::operator ==( - const DiscoveryServerConnectionAddress& other) const noexcept -{ - return (this->discovery_server_guid_prefix() == other.discovery_server_guid_prefix()) && - (this->addresses() == other.addresses()); -} - -std::ostream& operator <<( - std::ostream& output, - const DiscoveryServerConnectionAddress& address) -{ - output << "{{" << address.discovery_server_guid_prefix() << "}["; - for (auto a : address.addresses()) - { - output << a << ","; - } - output << "]}"; - return output; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp b/ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp deleted file mode 100644 index 414eee999..000000000 --- a/ddspipe_core/src_/cpp/types/data/RtpsPayloadData.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2021 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. - - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -RtpsPayloadData::~RtpsPayloadData() -{ - // If payload owner exists and payload has size, release it correctly in pool - if (payload_owner && payload.length > 0) - { - payload_owner->release_payload(payload); - } -} - - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp b/ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp deleted file mode 100644 index da5483893..000000000 --- a/ddspipe_core/src_/cpp/types/endpoint/Endpoint.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2021 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 Endpoint.cpp - * - */ - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -Endpoint::Endpoint() noexcept - : kind_(EndpointKind::invalid) -{ -} - -Endpoint::Endpoint( - const EndpointKind& kind, - const Guid& guid, - const DistributedTopic& topic, - const ParticipantId& discoverer_participant_id, - const SpecificEndpointQoS& specific_qos) noexcept - : kind_(kind) - , guid_(guid) - , topic_(topic) - , active_(true) - , discoverer_participant_id_(discoverer_participant_id) - , specific_qos_(specific_qos) -{ -} - -EndpointKind Endpoint::kind() const noexcept -{ - return kind_; -} - -void Endpoint::kind( - const EndpointKind& kind) noexcept -{ - kind_ = kind; -} - -Guid Endpoint::guid() const noexcept -{ - return guid_; -} - -TopicQoS Endpoint::topic_qos() const noexcept -{ - return topic_.topic_qos; -} - -SpecificEndpointQoS Endpoint::specific_qos() const noexcept -{ - return specific_qos_; -} - -void Endpoint::specific_qos( - const SpecificEndpointQoS& specific_qos) noexcept -{ - specific_qos_ = specific_qos; -} - -DistributedTopic Endpoint::topic() const noexcept -{ - return topic_; -} - -ParticipantId Endpoint::discoverer_participant_id() const noexcept -{ - return discoverer_participant_id_; -} - -bool Endpoint::active() const noexcept -{ - return active_; -} - -void Endpoint::active( - bool status) noexcept -{ - active_ = status; -} - -bool Endpoint::is_valid() const noexcept -{ - return kind_ != EndpointKind::invalid; -} - -bool Endpoint::is_writer() const noexcept -{ - return kind() == EndpointKind::writer; -} - -bool Endpoint::is_reader() const noexcept -{ - return kind() == EndpointKind::reader; -} - -bool Endpoint::is_server_endpoint() const noexcept -{ - return (is_reader() && RpcTopic::is_request_topic(topic_)) || (is_writer() && RpcTopic::is_reply_topic(topic_)); -} - -Endpoint& Endpoint::operator =( - const Endpoint& other) noexcept -{ - this->guid_ = other.guid_; - this->active_ = other.active_; - this->kind_ = other.kind_; - this->topic_ = other.topic_; - this->discoverer_participant_id_ = other.discoverer_participant_id_; - return *this; -} - -bool Endpoint::operator ==( - const Endpoint& other) const noexcept -{ - // TODO: compare discoverer_participant_id_? - return guid_ == other.guid() && kind_ == other.kind() && topic_ == other.topic(); -} - -std::ostream& operator <<( - std::ostream& os, - const Endpoint& endpoint) -{ - std::string active_str = endpoint.active_ ? "Active" : "Inactive"; - - os << - "Endpoint{" << endpoint.guid_ << - ";" << endpoint.kind_ << - ";" << endpoint.topic_ << - ";" << endpoint.specific_qos_ << - ";" << active_str << - ";" << endpoint.discoverer_participant_id_ << - "}"; - - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp b/ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp deleted file mode 100644 index 6dde92b78..000000000 --- a/ddspipe_core/src_/cpp/types/security/tls/TlsConfiguration.cpp +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright 2022 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 TlsConfiguration.cpp - * - */ - -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { -namespace security { - -bool TlsConfiguration::is_active() const noexcept -{ - return this->kind != TlsKind::inactive; -} - -void TlsConfiguration::enable_tls( - std::shared_ptr descriptor, - bool client /* = false */) const -{ - // Apply security ON - descriptor->apply_security = true; - - // Options - descriptor->tls_config.add_option( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::DEFAULT_WORKAROUNDS); - descriptor->tls_config.add_option( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::SINGLE_DH_USE); - descriptor->tls_config.add_option( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::NO_SSLV2); // not safe - - if (verify_peer) - { - // Perform verification of the server - descriptor->tls_config.add_verify_mode( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_PEER); - } - else - { - descriptor->tls_config.add_verify_mode( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_NONE); - } - - if (client) - { - if (!compatible()) - { - logError(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "TLS Configuration expected a Client configuration."); - throw utils::ConfigurationException("TLS Configuration expected a Client configuration."); - } - else - { - enable_tls_client(descriptor, true); - } - } - else - { - if (!compatible()) - { - logError(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "TLS Configuration expected a Server configuration."); - throw utils::ConfigurationException("TLS Configuration expected a Server configuration."); - } - else - { - // Add configuration for server - enable_tls_server(descriptor); - - // In case it could also be client, add tls config - if (compatible()) - { - enable_tls_client(descriptor, false); - } - } - } - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "TLS configured."); -} - -void TlsConfiguration::enable_tls_client( - std::shared_ptr descriptor, - bool only_client) const -{ - if (only_client && verify_peer) - { - // Fail verification if the server has no certificate - descriptor->tls_config.add_verify_mode( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_FAIL_IF_NO_PEER_CERT); - } - - // CA certificate - descriptor->tls_config.verify_file = certificate_authority_file; - - // SNI server name - descriptor->tls_config.server_name = sni_server_name; -} - -void TlsConfiguration::enable_tls_server( - std::shared_ptr descriptor) const -{ - // Password - descriptor->tls_config.password = private_key_file_password; - // Private key - descriptor->tls_config.private_key_file = private_key_file; - // DDS-Router certificate - descriptor->tls_config.cert_chain_file = certificate_chain_file; - // DH - descriptor->tls_config.tmp_dh_file = dh_params_file; -} - -template <> -DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( - utils::Formatter& error_msg) const noexcept -{ - if (verify_peer) - { - if (certificate_authority_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid certificate_authority_file while server verification must be done."; - return false; - } - } - return true; -} - -template <> -DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( - utils::Formatter& error_msg) const noexcept -{ - if (private_key_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid private_key_file."; - return false; - } - - if (dh_params_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid dh_params_file."; - return false; - } - - // chain cert is not required, however is usually needed - if (certificate_chain_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid certificate_chain_file."; - return false; - } - - return true; -} - -template <> -DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( - utils::Formatter& error_msg) const noexcept -{ - return is_valid_kind(error_msg) && is_valid_kind(error_msg); -} - -bool TlsConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - switch (kind) - { - case TlsKind::client: - return is_valid_kind(error_msg); - - case TlsKind::server: - return is_valid_kind(error_msg); - - case TlsKind::both: - return is_valid_kind(error_msg); - - default: - // None - return true; - } -} - -} /* namespace security */ -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp index ae1f7a7dc..1469db09e 100644 --- a/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp @@ -16,14 +16,14 @@ #include -#include +#include #include namespace eprosima { namespace ddspipe { namespace participants { -struct ParticipantConfiguration : public core::BaseConfiguration +struct ParticipantConfiguration : public core::IConfiguration { ///////////////////////// diff --git a/ddspipe_core/src_/cpp/types/dds/RouterCacheChange.hpp b/ddspipe_participants/include/ddspipe_participants/types/dds/RouterCacheChange.hpp similarity index 100% rename from ddspipe_core/src_/cpp/types/dds/RouterCacheChange.hpp rename to ddspipe_participants/include/ddspipe_participants/types/dds/RouterCacheChange.hpp diff --git a/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp index c07c8ee4b..adc6b9859 100644 --- a/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include namespace eprosima { namespace ddspipe { @@ -43,7 +43,7 @@ ENUMERATION_BUILDER( /** * Configuration holding TLS parameters. */ -struct TlsConfiguration : public core::BaseConfiguration +struct TlsConfiguration : public core::IConfiguration { /** diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp index 73a0f1239..39541fa14 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include @@ -32,7 +32,7 @@ namespace core { * This class joins every DdsRouter feature configuration and includes methods * to interact with this configuration. */ -struct DdsRouterReloadConfiguration : public ddspipe::core::BaseConfiguration +struct DdsRouterReloadConfiguration : public ddspipe::core::IConfiguration { ///////////////////////// diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index 18918965d..35841647b 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -19,7 +19,7 @@ #include -#include +#include #include #include @@ -33,7 +33,7 @@ namespace core { * - Number of threads to Thread Pool * - Default maximum history depth */ -struct SpecsConfiguration : public ddspipe::core::BaseConfiguration +struct SpecsConfiguration : public ddspipe::core::IConfiguration { ///////////////////////// From 14270dc5b01c67bee3b8af02afc588513e9b4014 Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 13 Feb 2023 19:05:18 +0100 Subject: [PATCH 07/38] Implement participants srcs Signed-off-by: jparisu --- .../ddspipe_core/interface/IReader.hpp | 10 +- .../types/data/RpcPayloadData.hpp | 2 +- .../ddspipe_core/types/dds/DomainId.hpp | 8 +- .../src/cpp/communication/rpc/RPCBridge.cpp | 16 +- ddspipe_core/src/cpp/types/dds/DomainId.cpp | 11 + .../EchoParticipantConfiguration.hpp | 3 - .../InitialPeersParticipantConfiguration.hpp | 2 - .../cache_change/CacheChangePool.hpp | 64 +++ .../participant/auxiliar/EchoParticipant.hpp | 8 +- .../rtps/InitialPeersParticipant.hpp | 6 +- .../reader/auxiliar/BaseReader.hpp | 13 +- .../reader/auxiliar/BlankReader.hpp | 10 +- .../reader/rpc/SimpleReader.hpp | 8 +- .../reader/rtps/CommonReader.hpp | 19 +- .../reader/rtps/SpecificQoSReader.hpp | 8 +- .../writer/auxiliar/BaseWriter.hpp | 3 +- .../writer/auxiliar/RtpsEchoWriter.hpp | 5 +- .../writer/rpc/SimpleWriter.hpp | 7 +- .../writer/rtps/CommonWriter.hpp | 23 +- .../writer/rtps/MultiWriter.hpp | 8 +- .../writer/rtps/QoSSpecificWriter.hpp | 6 +- .../writer/rtps/SimpleWriter.hpp | 3 +- ddspipe_participants/src/cpp/_dummy.cpp | 8 - ...iscoveryServerParticipantConfiguration.cpp | 35 +- .../InitialPeersParticipantConfiguration.cpp | 34 +- .../ParticipantConfiguration.cpp | 16 - .../SimpleParticipantConfiguration.cpp | 22 +- .../cache_change/CacheChangePool.cpp | 48 ++ .../participant/auxiliar/BlankParticipant.cpp | 20 +- .../participant/auxiliar/EchoParticipant.cpp | 37 +- .../participant/rtps/CommonParticipant.cpp | 216 +++++---- .../rtps/DiscoveryServerParticipant.cpp | 19 +- .../rtps/InitialPeersParticipant.cpp | 19 +- .../participant/rtps/SimpleParticipant.cpp | 11 +- .../cpp/reader/auxiliar/BaseReader.cpp | 22 +- .../cpp/reader/auxiliar/BlankReader.cpp | 28 +- .../src/cpp/reader/rpc/SimpleReader.cpp | 68 +++ .../cpp/reader/rtps/CommonReader.cpp | 101 ++-- .../cpp/reader/rtps/SimpleReader.cpp | 17 +- .../cpp/reader/rtps/SpecificQoSReader.cpp | 32 +- .../src/cpp/types/address/Address.cpp | 438 ++++++++++++++++++ .../DiscoveryServerConnectionAddress.cpp | 96 ++++ .../types/security/tls/TlsConfiguration.cpp | 204 ++++++++ .../cpp/writer/auxiliar/BaseWriter.cpp | 13 +- .../cpp/writer/auxiliar/BlankWriter.cpp | 2 - .../cpp/writer/auxiliar/RtpsEchoWriter.cpp} | 30 +- .../src/cpp/writer/rpc/SimpleWriter.cpp | 82 ++++ .../cpp/writer/rtps/CommonWriter.cpp | 93 ++-- .../cpp/writer/rtps/MultiWriter.cpp | 21 +- .../cpp/writer/rtps/QoSSpecificWriter.cpp | 34 +- .../cpp/writer/rtps/SimpleWriter.cpp | 23 +- .../writer/rtps/filter/RepeaterDataFilter.cpp | 0 .../cpp/writer/rtps/filter/SelfDataFilter.cpp | 0 .../participant/auxiliar/BaseParticipant.cpp | 183 -------- .../participant/auxiliar/MockParticipant.cpp | 75 --- .../writer/rtps/filter/RepeaterDataFilter.hpp | 51 -- .../cpp/writer/rtps/filter/SelfDataFilter.hpp | 59 --- 57 files changed, 1511 insertions(+), 889 deletions(-) create mode 100644 ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp delete mode 100644 ddspipe_participants/src/cpp/_dummy.cpp rename ddspipe_participants/{src_/cpp/participant => src/cpp}/configuration/DiscoveryServerParticipantConfiguration.cpp (71%) rename ddspipe_participants/{src_/cpp/participant => src/cpp}/configuration/InitialPeersParticipantConfiguration.cpp (72%) rename ddspipe_participants/{src_/cpp/participant => src/cpp}/configuration/ParticipantConfiguration.cpp (76%) rename ddspipe_participants/{src_/cpp/participant => src/cpp}/configuration/SimpleParticipantConfiguration.cpp (68%) create mode 100644 ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp rename ddspipe_participants/{src_ => src}/cpp/participant/auxiliar/BlankParticipant.cpp (78%) rename ddspipe_participants/{src_ => src}/cpp/participant/auxiliar/EchoParticipant.cpp (68%) rename ddspipe_participants/{src_ => src}/cpp/participant/rtps/CommonParticipant.cpp (60%) rename ddspipe_participants/{src_ => src}/cpp/participant/rtps/DiscoveryServerParticipant.cpp (95%) rename ddspipe_participants/{src_ => src}/cpp/participant/rtps/InitialPeersParticipant.cpp (95%) rename ddspipe_participants/{src_ => src}/cpp/participant/rtps/SimpleParticipant.cpp (77%) rename ddspipe_participants/{src_ => src}/cpp/reader/auxiliar/BaseReader.cpp (89%) rename ddspipe_participants/{src_ => src}/cpp/reader/auxiliar/BlankReader.cpp (60%) create mode 100644 ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp rename ddspipe_participants/{src_ => src}/cpp/reader/rtps/CommonReader.cpp (81%) rename ddspipe_participants/{src_ => src}/cpp/reader/rtps/SimpleReader.cpp (78%) rename ddspipe_participants/{src_ => src}/cpp/reader/rtps/SpecificQoSReader.cpp (66%) create mode 100644 ddspipe_participants/src/cpp/types/address/Address.cpp create mode 100644 ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp create mode 100644 ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp rename ddspipe_participants/{src_ => src}/cpp/writer/auxiliar/BaseWriter.cpp (87%) rename ddspipe_participants/{src_ => src}/cpp/writer/auxiliar/BlankWriter.cpp (95%) rename ddspipe_participants/{src_/cpp/writer/auxiliar/EchoWriter.cpp => src/cpp/writer/auxiliar/RtpsEchoWriter.cpp} (63%) create mode 100644 ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp rename ddspipe_participants/{src_ => src}/cpp/writer/rtps/CommonWriter.cpp (82%) rename ddspipe_participants/{src_ => src}/cpp/writer/rtps/MultiWriter.cpp (88%) rename ddspipe_participants/{src_ => src}/cpp/writer/rtps/QoSSpecificWriter.cpp (61%) rename ddspipe_participants/{src_ => src}/cpp/writer/rtps/SimpleWriter.cpp (73%) rename ddspipe_participants/{src_ => src}/cpp/writer/rtps/filter/RepeaterDataFilter.cpp (100%) rename ddspipe_participants/{src_ => src}/cpp/writer/rtps/filter/SelfDataFilter.cpp (100%) delete mode 100644 ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp delete mode 100644 ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp delete mode 100644 ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp delete mode 100644 ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp diff --git a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp index 17945d5da..eb96afa2c 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp @@ -110,17 +110,17 @@ class IReader // TODO remove these methods once the double reference is solved //! Get GUID of internal RTPS reader - virtual core::types::Guid guid() const noexcept = 0; + virtual core::types::Guid guid() const = 0; //! Get internal RTPS reader mutex - virtual fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept = 0; + virtual fastrtps::RecursiveTimedMutex& get_rtps_mutex() const = 0; //! Get number of unread cache changes in internal RTPS reader - virtual uint64_t get_unread_count() const noexcept = 0; + virtual uint64_t get_unread_count() const = 0; - virtual types::DdsTopic topic() const noexcept = 0; + virtual types::DdsTopic topic() const = 0; - virtual types::ParticipantId participant_id() const noexcept = 0; + virtual types::ParticipantId participant_id() const = 0; ///////////////////////// }; diff --git a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp index 2fa6700f4..56f1e97ad 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp @@ -41,7 +41,7 @@ namespace types { struct RpcPayloadData : public RtpsPayloadData { //! Write params associated to the received cache change - eprosima::fastrtps::rtps::WriteParams write_params{}; + utils::Fuzzy write_params{}; //! Sequence number of the received cache change eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; diff --git a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp index a3ac53040..6c81b35d3 100644 --- a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp @@ -17,6 +17,7 @@ #include #include +#include namespace eprosima { namespace ddspipe { @@ -29,7 +30,7 @@ using DomainIdType = eprosima::fastdds::dds::DomainId_t; /** * @brief RTPS Domain ID. */ -struct DomainId +struct DomainId : public IConfiguration { DDSPIPE_CORE_DllAPI DomainId () noexcept = default; @@ -38,6 +39,9 @@ struct DomainId DDSPIPE_CORE_DllAPI operator DomainIdType() const noexcept; + DDSPIPE_CORE_DllAPI virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; + //! Value of Fast DDS Domain ID DomainIdType domain_id = DEFAULT_DOMAIN_ID; @@ -52,7 +56,7 @@ struct DomainId static constexpr const DomainIdType DEFAULT_DISCOVERY_SERVER_DOMAIN_ID = 66; //! Maximum Domain Id valid - static constexpr const DomainIdType MAX_DOMAIN_ID = 223; + static constexpr const DomainIdType MAX_DOMAIN_ID = 232; }; //! \c DomainId serializator diff --git a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp index 4c95ba7d0..df69124e4 100644 --- a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -315,7 +315,7 @@ void RPCBridge::transmit_( " transmitting request from remote endpoint " << pcr_data.source_guid << "."); SampleIdentity reply_related_sample_identity = - pcr_data.write_params.sample_identity(); + pcr_data.write_params.get_reference().sample_identity(); reply_related_sample_identity.sequence_number(pcr_data.origin_sequence_number); if (reply_related_sample_identity == SampleIdentity::unknown()) @@ -341,7 +341,8 @@ void RPCBridge::transmit_( std::lock_guard lock(service_registry.second->get_mutex()); // Attach the information the server needs in order to reply to the appropiate proxy client. - pcr_data.write_params.related_sample_identity().writer_guid( + pcr_data.write_params.set_level(); + pcr_data.write_params.get_reference().related_sample_identity().writer_guid( reply_readers_[service_registry.first]->guid()); ret = request_writers_[service_registry.first]->write(*data); @@ -371,12 +372,12 @@ void RPCBridge::transmit_( // A Server could be answering a different client in this same DDS Router or a remote client // Thus, it must be filtered so only replies to this client are processed. - if (pcr_data.write_params.sample_identity().writer_guid() != reader->guid()) + if (pcr_data.write_params.get_reference().sample_identity().writer_guid() != reader->guid()) { logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge for service " << *this << " from reader " << reader->guid() << " received response meant for other client: " << - pcr_data.write_params.sample_identity().writer_guid()); + pcr_data.write_params.get_reference().sample_identity().writer_guid()); } else { @@ -388,7 +389,7 @@ void RPCBridge::transmit_( // Fetch information required for transmission; which proxy server should send it and with what parameters registry_entry = service_registries_[reader->participant_id()]->get( - pcr_data.write_params.sample_identity().sequence_number()); + pcr_data.write_params.get_reference().sample_identity().sequence_number()); } // Not valid means: @@ -397,7 +398,8 @@ void RPCBridge::transmit_( // TODO: recheck ParticipantId non valid if (!registry_entry.first.empty()) { - pcr_data.write_params.related_sample_identity(registry_entry.second); + pcr_data.write_params.set_level(); + pcr_data.write_params.get_reference().related_sample_identity(registry_entry.second); ret = reply_writers_[registry_entry.first]->write(*data); @@ -409,7 +411,7 @@ void RPCBridge::transmit_( else { service_registries_[reader->participant_id()]->erase( - pcr_data.write_params.sample_identity().sequence_number()); + pcr_data.write_params.get_reference().sample_identity().sequence_number()); } } } diff --git a/ddspipe_core/src/cpp/types/dds/DomainId.cpp b/ddspipe_core/src/cpp/types/dds/DomainId.cpp index 76358019b..cce8d7728 100644 --- a/ddspipe_core/src/cpp/types/dds/DomainId.cpp +++ b/ddspipe_core/src/cpp/types/dds/DomainId.cpp @@ -35,6 +35,17 @@ DomainId::operator DomainIdType() const noexcept return this->domain_id; } +bool DomainId::is_valid( + utils::Formatter& error_msg) const noexcept +{ + if (domain_id > MAX_DOMAIN_ID) + { + error_msg << "Domain could not be higher than " << MAX_DOMAIN_ID << ". "; + return false; + } + return true; +} + std::ostream& operator <<( std::ostream& output, const DomainId& domain) diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp index 81074a3ac..0d4884924 100644 --- a/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp @@ -23,9 +23,6 @@ namespace participants { struct EchoParticipantConfiguration : public ParticipantConfiguration { - //! Use default parent constructors - using ParticipantConfiguration::ParticipantConfiguration; - ///////////////////////// // CONSTRUCTORS ///////////////////////// diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp index 26a76b80e..8ed01d21a 100644 --- a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp @@ -39,7 +39,6 @@ struct InitialPeersParticipantConfiguration : public SimpleParticipantConfigurat DDSPIPE_PARTICIPANTS_DllAPI InitialPeersParticipantConfiguration() = default; - ///////////////////////// // METHODS ///////////////////////// @@ -47,7 +46,6 @@ struct InitialPeersParticipantConfiguration : public SimpleParticipantConfigurat DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; - ///////////////////////// // VARIABLES ///////////////////////// diff --git a/ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp b/ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp new file mode 100644 index 000000000..88b62477e --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp @@ -0,0 +1,64 @@ +// Copyright 2022 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. + +#pragma once + +#include + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { + +/** + * @brief This class implements a pool of CacheChange objects specialized as RouterCacheChanges. + * + * It reuses the UnboundedPool implementation, what allow to create an unbounded reusable pool. + * + * TODO: implement this class as an IPool (or having an internal pool), without being force to be unbounded. + */ +class CacheChangePool : public fastrtps::rtps::IChangePool, public utils::UnboundedPool +{ +public: + + /** + * @brief Construct a new Cache Change Pool object from a Pool Configuration + * + * @param configuration pool configuration + * + * @warning max size will not be used as it is Unbounded + */ + CacheChangePool( + utils::PoolConfiguration configuration); + + //! Call UnboundedPool::reserve + virtual bool reserve_cache( + fastrtps::rtps::CacheChange_t*& cache_change) override; + + //! Call UnboundedPool::release + virtual bool release_cache( + fastrtps::rtps::CacheChange_t* cache_change) override; + +protected: + + //! Override the UnboundedPool::create_element method to create a RouterCacheChange object. + virtual fastrtps::rtps::CacheChange_t* new_element_() override; + +}; + +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp index f4fc7d8d1..5474171c5 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp @@ -32,8 +32,8 @@ class EchoParticipant : public BlankParticipant //! Using parent class constructors EchoParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr discovery_database); + const std::shared_ptr& participant_configuration, + const std::shared_ptr& discovery_database); //! Print discovery information from endpoint discovered void echo_discovery( @@ -48,10 +48,10 @@ class EchoParticipant : public BlankParticipant // Deleters do not need to be implemented //! Reference to alias access of this object configuration without casting every time - std::shared_ptr configuration_; + const std::shared_ptr configuration_; //! DDS Router shared Discovery Database - std::shared_ptr discovery_database_; + const std::shared_ptr discovery_database_; }; } /* namespace participants */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp index 3868c1df2..c09e3e305 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp @@ -35,9 +35,9 @@ class InitialPeersParticipant public: InitialPeersParticipant( - core std::shared_ptr& participant_configuration, - core std::shared_ptr& payload_pool, - core std::shared_ptr& discovery_database); + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database); protected: diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp index 8c1af7ce3..17ec4d7c7 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp @@ -31,6 +31,8 @@ namespace participants { * * In order to inherit from this class, create the protected method take_ . * Implement methods enabled_ and disabled_ in order to give specific functionality to these methods. + * + * @todo make topic somehow to can hold it. */ class BaseReader : public core::IReader { @@ -111,7 +113,7 @@ class BaseReader : public core::IReader ///////////////////////// //! Getter of \c participant_id_ attribute - core::types::ParticipantId participant_id() const noexcept; + core::types::ParticipantId participant_id() const noexcept override; ///////////////////////// // RPC REQUIRED METHODS @@ -119,13 +121,15 @@ class BaseReader : public core::IReader // TODO remove these methods once the double reference is solved //! Get GUID of internal RTPS reader - core::types::Guid guid() const noexcept; + core::types::Guid guid() const override = 0; //! Get internal RTPS reader mutex - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept; + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override = 0; //! Get number of unread cache changes in internal RTPS reader - uint64_t get_unread_count() const noexcept; + uint64_t get_unread_count() const override = 0; + + core::types::DdsTopic topic() const override = 0; ///////////////////////// protected: @@ -143,7 +147,6 @@ class BaseReader : public core::IReader */ BaseReader( const core::types::ParticipantId& participant_id, - const core::ITopic& topic, const std::shared_ptr& payload_pool); ///////////////////////// diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp index 0de91bd1d..5e94f5a0e 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp @@ -52,13 +52,17 @@ class BlankReader : public core::IReader // TODO remove these methods once the double reference is solved //! Get GUID of internal RTPS reader - core::types::Guid guid() const noexcept; + core::types::Guid guid() const override; //! Get internal RTPS reader mutex - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept; + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override; //! Get number of unread cache changes in internal RTPS reader - uint64_t get_unread_count() const noexcept; + uint64_t get_unread_count() const override; + + core::types::DdsTopic topic() const override; + + core::types::ParticipantId participant_id() const override; ///////////////////////// }; diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp index 479e4497d..06365ebfd 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp @@ -44,18 +44,18 @@ class SimpleReader : public rtps::CommonReader */ SimpleReader( const core::types::ParticipantId& participant_id, - const core::types::RpcTopic& topic, + const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant); //! Override Parent method to create an RPC data type. - virtual types::RtpsPayloadData* create_data_( - const fastrtps::rtps::CacheChange_t& received_change) const noexcept; + virtual core::types::RtpsPayloadData* create_data_( + const fastrtps::rtps::CacheChange_t& received_change) const noexcept override; //! Override Parent method to fill fields exclusive from RPC. virtual void fill_received_data_( const fastrtps::rtps::CacheChange_t& received_change, - types::RtpsPayloadData& data_to_fill) const noexcept; + core::types::RtpsPayloadData& data_to_fill) const noexcept override; }; } /* namespace rpc */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp index 1bccb430d..2d7460321 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp @@ -29,9 +29,9 @@ #include #include #include +#include #include -#include namespace eprosima { namespace ddspipe { @@ -111,13 +111,15 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener // TODO remove these methods once the double reference is solved //! Get GUID of internal RTPS reader - core::types::Guid guid() const noexcept; + core::types::Guid guid() const noexcept override; //! Get internal RTPS reader mutex - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept; + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept override; //! Get number of unread cache changes in internal RTPS reader - uint64_t get_unread_count() const noexcept; + uint64_t get_unread_count() const noexcept override; + + core::types::DdsTopic topic() const noexcept override; protected: @@ -132,7 +134,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener */ CommonReader( const core::types::ParticipantId& participant_id, - const core::ITopic& topic, + const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const fastrtps::rtps::HistoryAttributes& history_attributes, @@ -156,7 +158,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * * @attention this method allocates memory. */ - virtual types::RtpsPayloadData* create_data_( + virtual core::types::RtpsPayloadData* create_data_( const fastrtps::rtps::CacheChange_t& received_change) const noexcept; /** @@ -164,7 +166,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener */ virtual void fill_received_data_( const fastrtps::rtps::CacheChange_t& received_change, - types::RtpsPayloadData& data_to_fill) const noexcept; + core::types::RtpsPayloadData& data_to_fill) const noexcept; // Specific enable/disable do not need to be implemented @@ -241,6 +243,9 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener ///// // INTERNAL VARIABLES + //! + core::types::DdsTopic topic_; + //! RTPS Reader pointer fastrtps::rtps::RTPSReader* rtps_reader_; diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp index bf2a645a8..aa4ce45cc 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp @@ -14,8 +14,9 @@ #pragma once +#include + #include -#include namespace eprosima { namespace ddspipe { @@ -62,8 +63,9 @@ class SpecificQoSReader : public CommonReader /** * Specializes \c CommonReader method and set the QoS of the data received. */ - virtual IRoutingData* fill_received_data_( - fastrtps::rtps::CacheChange_t* received_change) const noexcept; + virtual void fill_received_data_( + const fastrtps::rtps::CacheChange_t& received_change, + core::types::RtpsPayloadData& data_to_fill) const noexcept override; //! Reference to the \c DiscoveryDatabase . diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp index 2fc323eff..db7307a33 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp @@ -97,7 +97,6 @@ class BaseWriter : public core::IWriter */ BaseWriter( const core::types::ParticipantId& participant_id, - const core::ITopic& topic, const std::shared_ptr& payload_pool); ///////////////////////// @@ -134,7 +133,7 @@ class BaseWriter : public core::IWriter const core::types::ParticipantId participant_id_; //! DDS Router shared Payload Pool - const std::shared_ptr payload_pool_; + std::shared_ptr payload_pool_; //! Whether the Writer is currently enabled std::atomic enabled_; diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp index 1a55e9466..3885cee8f 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp @@ -17,6 +17,7 @@ #include #include +#include #include @@ -27,12 +28,12 @@ namespace participants { /** * Writer Implementation that prints in stdout every message that is required to write. */ -class EchoWriter : public BlankWriter +class RtpsEchoWriter : public BlankWriter { public: //! Using parent class constructors - EchoWriter( + RtpsEchoWriter( const core::types::DdsTopic& topic, bool verbose); diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp index 83fd4b67a..938bfcc2c 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp @@ -23,8 +23,9 @@ #include #include + #include -#include +#include namespace eprosima { namespace ddspipe { @@ -34,7 +35,7 @@ namespace rpc { /** * Base RTPS Writer concrete class that implements abstract CommonWriter one. */ -class SimpleWriter : public CommonWriter +class SimpleWriter : public rtps::CommonWriter { public: @@ -55,7 +56,7 @@ class SimpleWriter : public CommonWriter */ SimpleWriter( const core::types::ParticipantId& participant_id, - const core::types::RPCTopic& topic, + const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater = false); diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp index 9e80ac341..53c95b4eb 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp @@ -24,9 +24,10 @@ #include #include -#include +#include +#include -#include +#include #include ///// @@ -121,7 +122,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ CommonWriter( const core::types::ParticipantId& participant_id, - const core::ITopic& topic, + const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater, @@ -161,7 +162,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener virtual utils::ReturnCode fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, - const types::RtpsPayloadData& data) const noexcept; + const core::types::RtpsPayloadData& data) const noexcept; /** * @brief Auxiliary method used after \c write to fill data value. @@ -171,7 +172,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener */ virtual void fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& sent_params, - types::RtpsPayloadData& data_to_fill) const noexcept; + core::types::RtpsPayloadData& data_to_fill) const noexcept; ///// // RTPS specific methods @@ -195,25 +196,25 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @brief History Attributes to create RTPS Writer History */ static fastrtps::rtps::HistoryAttributes reckon_history_attributes_( - const core::types::DistributedTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; /** * @brief Writer Attributes to create RTPS Writer */ static fastrtps::rtps::WriterAttributes reckon_writer_attributes_( - const core::types::DistributedTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Topic Attributes to create RTPS Writer static fastrtps::TopicAttributes reckon_topic_attributes_( - const core::types::DistributedTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! QoS for RTPS Writer static fastrtps::WriterQos reckon_writer_qos_( - const core::types::DistributedTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Cache Change Pool Configuration static utils::PoolConfiguration reckon_cache_change_pool_configuration_( - const core::types::DistributedTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Whether a guid references this Participant bool come_from_this_participant_( @@ -231,6 +232,8 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener ///// // INTERNAL VARIABLES + core::types::DdsTopic topic_; + //! RTPS CommonWriter pointer fastrtps::rtps::RTPSWriter* rtps_writer_; diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp index e232247dd..e01b6cbde 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp @@ -17,6 +17,8 @@ #include #include +#include + #include #include @@ -49,7 +51,7 @@ class MultiWriter : public BaseWriter */ MultiWriter( const core::types::ParticipantId& participant_id, - const core::ITopic& topic, + const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater = false); @@ -88,10 +90,12 @@ class MultiWriter : public BaseWriter // INTERNAL VARIABLES ///////////////////////// - using WritersMapType = utils::SharedAtomicable>; + using WritersMapType = utils::SharedAtomicable>; //! Map of writer indexed by Specific QoS of each. WritersMapType writers_map_; + core::types::DdsTopic topic_; + //! Reference to RTPS Participant. fastrtps::rtps::RTPSParticipant* rtps_participant_; diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp index ccb2e76aa..915597f89 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp @@ -44,8 +44,8 @@ class QoSSpecificWriter : public CommonWriter */ QoSSpecificWriter( const core::types::ParticipantId& participant_id, - const core::ITopic& topic, - std::shared_ptr payload_pool, + const core::types::DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const core::types::SpecificEndpointQoS& specific_qos, const bool repeater = false); @@ -55,7 +55,7 @@ class QoSSpecificWriter : public CommonWriter //! Specific writer QoS to override (more or less) the CommonWriter qos static fastrtps::WriterQos reckon_writer_qos_( const core::types::SpecificEndpointQoS& specific_qos, - const core::types::DistributedTopic& topic) noexcept; + const core::types::DdsTopic& topic) noexcept; //! Specific QoS of the Endpoint core::types::SpecificEndpointQoS specific_qos_; diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp index 4ea220a97..bde22b6c1 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp @@ -23,8 +23,9 @@ #include #include + +#include #include -#include namespace eprosima { namespace ddspipe { diff --git a/ddspipe_participants/src/cpp/_dummy.cpp b/ddspipe_participants/src/cpp/_dummy.cpp deleted file mode 100644 index d353d8800..000000000 --- a/ddspipe_participants/src/cpp/_dummy.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include diff --git a/ddspipe_participants/src_/cpp/participant/configuration/DiscoveryServerParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp similarity index 71% rename from ddspipe_participants/src_/cpp/participant/configuration/DiscoveryServerParticipantConfiguration.cpp rename to ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp index 7dc448ca7..0af034b34 100644 --- a/ddspipe_participants/src_/cpp/participant/configuration/DiscoveryServerParticipantConfiguration.cpp +++ b/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp @@ -12,34 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include #include +#include +#include namespace eprosima { namespace ddspipe { namespace participants { -DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration( - const ParticipantId& id, - const bool is_repeater, - const DomainId& domain_id, - const GuidPrefix& discovery_server_guid_prefix, - const std::set
& listening_addresses, - const std::set& connection_addresses, - const TlsConfiguration& tls_configuration) - : SimpleParticipantConfiguration(id, is_repeater, domain_id) - , discovery_server_guid_prefix(discovery_server_guid_prefix) - , listening_addresses(listening_addresses) - , connection_addresses(connection_addresses) - , tls_configuration(tls_configuration) -{ - // Do nothing -} - bool DiscoveryServerParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { @@ -57,7 +41,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // Check listening addresses - for (Address address : listening_addresses) + for (types::Address address : listening_addresses) { if (!address.is_valid()) { @@ -67,7 +51,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // Check connection addresses - for (DiscoveryServerConnectionAddress address : connection_addresses) + for (types::DiscoveryServerConnectionAddress address : connection_addresses) { if (!address.is_valid()) { @@ -89,7 +73,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( // If has listening addresses, it should be able to provide TLS server configuration if (!listening_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -99,7 +83,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( // If has connection addresses, it should be able to provide TLS client configuration if (!connection_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; @@ -110,13 +94,6 @@ bool DiscoveryServerParticipantConfiguration::is_valid( return true; } -bool DiscoveryServerParticipantConfiguration::operator ==( - const DiscoveryServerParticipantConfiguration& other) const noexcept -{ - // TODO - return false; -} - } /* namespace participants */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/participant/configuration/InitialPeersParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp similarity index 72% rename from ddspipe_participants/src_/cpp/participant/configuration/InitialPeersParticipantConfiguration.cpp rename to ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp index ae11b87d4..cdff3f3e6 100644 --- a/ddspipe_participants/src_/cpp/participant/configuration/InitialPeersParticipantConfiguration.cpp +++ b/ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp @@ -12,34 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include #include +#include namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - -InitialPeersParticipantConfiguration::InitialPeersParticipantConfiguration( - const ParticipantId& id, - const bool is_repeater, - const DomainId& domain_id, - const std::set
& listening_addresses, - const std::set
& connection_addresses, - const TlsConfiguration& tls_configuration) - : SimpleParticipantConfiguration(id, is_repeater, domain_id) - , listening_addresses(listening_addresses) - , connection_addresses(connection_addresses) - , tls_configuration(tls_configuration) -{ - // Do nothing -} - bool InitialPeersParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { @@ -50,7 +33,7 @@ bool InitialPeersParticipantConfiguration::is_valid( } // Check listening addresses - for (Address address : listening_addresses) + for (types::Address address : listening_addresses) { if (!address.is_valid()) { @@ -60,7 +43,7 @@ bool InitialPeersParticipantConfiguration::is_valid( } // Check connection addresses - for (Address address : connection_addresses) + for (types::Address address : connection_addresses) { if (!address.is_valid()) { @@ -82,7 +65,7 @@ bool InitialPeersParticipantConfiguration::is_valid( // If has listening addresses, it should be able to provide TLS server configuration if (!listening_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -92,7 +75,7 @@ bool InitialPeersParticipantConfiguration::is_valid( // If has connection addresses, it should be able to provide TLS client configuration if (!connection_addresses.empty()) { - if (!tls_configuration.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; @@ -103,13 +86,6 @@ bool InitialPeersParticipantConfiguration::is_valid( return true; } -bool InitialPeersParticipantConfiguration::operator ==( - const InitialPeersParticipantConfiguration& other) const noexcept -{ - // TODO - return false; -} - } /* namespace participants */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/participant/configuration/ParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp similarity index 76% rename from ddspipe_participants/src_/cpp/participant/configuration/ParticipantConfiguration.cpp rename to ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp index 62081eddc..23a14d20b 100644 --- a/ddspipe_participants/src_/cpp/participant/configuration/ParticipantConfiguration.cpp +++ b/ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp @@ -22,16 +22,6 @@ namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - -ParticipantConfiguration::ParticipantConfiguration( - const ParticipantId& id, - const bool is_repeater /* = false */) noexcept - : id(id) - , is_repeater(is_repeater) -{ -} - bool ParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { @@ -44,12 +34,6 @@ bool ParticipantConfiguration::is_valid( return true; } -bool ParticipantConfiguration::operator ==( - const ParticipantConfiguration& other) const noexcept -{ - return this->id == other.id; -} - } /* namespace participants */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/participant/configuration/SimpleParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp similarity index 68% rename from ddspipe_participants/src_/cpp/participant/configuration/SimpleParticipantConfiguration.cpp rename to ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp index 7f3cb526a..8c5f34e89 100644 --- a/ddspipe_participants/src_/cpp/participant/configuration/SimpleParticipantConfiguration.cpp +++ b/ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include @@ -21,17 +20,6 @@ namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - -SimpleParticipantConfiguration::SimpleParticipantConfiguration( - const ParticipantId& id, - const bool is_repeater, - const DomainId& domain_id) noexcept - : ParticipantConfiguration(id, is_repeater) - , domain(domain_id) -{ -} - bool SimpleParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { @@ -40,7 +28,7 @@ bool SimpleParticipantConfiguration::is_valid( return false; } - if (!domain.is_valid()) + if (!domain.is_valid(error_msg)) { error_msg << "Incorrect domain " << domain << ". "; return false; @@ -49,14 +37,6 @@ bool SimpleParticipantConfiguration::is_valid( return true; } -bool SimpleParticipantConfiguration::operator ==( - const SimpleParticipantConfiguration& other) const noexcept -{ - return ParticipantConfiguration::operator ==( - other) && - this->domain == other.domain; -} - } /* namespace participants */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp b/ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp new file mode 100644 index 000000000..4c8d50a71 --- /dev/null +++ b/ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp @@ -0,0 +1,48 @@ +// Copyright 2022 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. + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { + +CacheChangePool::CacheChangePool( + utils::PoolConfiguration configuration) + : utils::UnboundedPool(configuration) +{ + initialize_vector_(); +} + +bool CacheChangePool::reserve_cache( + fastrtps::rtps::CacheChange_t*& cache_change) +{ + return loan(cache_change); +} + +bool CacheChangePool::release_cache( + fastrtps::rtps::CacheChange_t* cache_change) +{ + return return_loan(cache_change); +} + +fastrtps::rtps::CacheChange_t* CacheChangePool::new_element_() +{ + return new types::RouterCacheChange(); +} + +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/participant/auxiliar/BlankParticipant.cpp b/ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp similarity index 78% rename from ddspipe_participants/src_/cpp/participant/auxiliar/BlankParticipant.cpp rename to ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp index de49601cf..4d6539f73 100644 --- a/ddspipe_participants/src_/cpp/participant/auxiliar/BlankParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp @@ -21,15 +21,13 @@ namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - BlankParticipant::BlankParticipant( - const ParticipantId& id) + const core::types::ParticipantId& id) : id_(id) { } -ParticipantId BlankParticipant::id() const noexcept +core::types::ParticipantId BlankParticipant::id() const noexcept { return id_; } @@ -45,27 +43,17 @@ bool BlankParticipant::is_rtps_kind() const noexcept } std::shared_ptr BlankParticipant::create_writer( - DistributedTopic topic) + const core::ITopic& topic) { return std::make_shared(); } std::shared_ptr BlankParticipant::create_reader( - DistributedTopic topic) + const core::ITopic& topic) { return std::make_shared(); } -void BlankParticipant::delete_writer( - std::shared_ptr writer) noexcept -{ -} - -void BlankParticipant::delete_reader( - std::shared_ptr reader) noexcept -{ -} - } /* namespace participants */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/participant/auxiliar/EchoParticipant.cpp b/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp similarity index 68% rename from ddspipe_participants/src_/cpp/participant/auxiliar/EchoParticipant.cpp rename to ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp index fde466a89..f27283cd8 100644 --- a/ddspipe_participants/src_/cpp/participant/auxiliar/EchoParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp @@ -12,25 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include +#include + #include #include #include -#include +#include #include - namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - EchoParticipant::EchoParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr discovery_database) + const std::shared_ptr& participant_configuration, + const std::shared_ptr& discovery_database) : BlankParticipant(participant_configuration->id) , configuration_(participant_configuration) { @@ -40,7 +38,7 @@ EchoParticipant::EchoParticipant( { // Register in Discovery DB a callback to be notified each time an endpoint is discovered discovery_database->add_endpoint_discovered_callback( - [this](const Endpoint& endpoint_discovered) + [this](const core::types::Endpoint& endpoint_discovered) { this->echo_discovery(endpoint_discovered); }); @@ -48,7 +46,7 @@ EchoParticipant::EchoParticipant( } void EchoParticipant::echo_discovery( - Endpoint endpoint_discovered) const noexcept + core::types::Endpoint endpoint_discovered) const noexcept { // TODO write this in a way that is efficient and easy to read and allow verbose option logUser( @@ -57,18 +55,21 @@ void EchoParticipant::echo_discovery( } std::shared_ptr EchoParticipant::create_writer( - DistributedTopic topic) + const core::ITopic& topic) { - if (configuration_->echo_data) + // Check if topic is of type RTPS + if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RTPS) { - return std::make_shared( - topic, - configuration_->verbose); - } - else - { - return std::make_shared(); + if (configuration_->echo_data) + { + const core::types::DdsTopic& dds_topic = dynamic_cast(topic); + return std::make_shared( + dds_topic, + configuration_->verbose); + } } + + return std::make_shared(); } } /* namespace participants */ diff --git a/ddspipe_participants/src_/cpp/participant/rtps/CommonParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp similarity index 60% rename from ddspipe_participants/src_/cpp/participant/rtps/CommonParticipant.cpp rename to ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp index f5a871531..116934f60 100644 --- a/ddspipe_participants/src_/cpp/participant/rtps/CommonParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp @@ -24,14 +24,19 @@ #include #include +#include +#include -#include -#include +#include +#include +#include #include +#include +#include +#include +#include #include #include -#include -#include namespace eprosima { namespace ddspipe { @@ -39,12 +44,14 @@ namespace participants { namespace rtps { CommonParticipant::CommonParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database, + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database, const core::types::DomainId& domain_id, const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes) - : BaseParticipant(participant_configuration, payload_pool, discovery_database) + : configuration_(participant_configuration) + , payload_pool_(payload_pool) + , discovery_database_(discovery_database) , domain_id_(domain_id) , participant_attributes_(participant_attributes) { @@ -96,22 +103,23 @@ template core::types::Endpoint CommonParticipant::create_common_endpoint_from_info_( DiscoveryInfoKind& info) { + // Endpoint struct to fill + core::types::Endpoint endpoint; + // Parse GUID - core::types::Guid info_guid; - info_guid = info.info.guid(); + endpoint.guid = info.info.guid(); // Parse TopicQoS - core::types::TopicQoS discovered_topic_qos; // Durability - discovered_topic_qos.durability_qos = info.info.m_qos.m_durability.durabilityKind(); + endpoint.topic.topic_qos.durability_qos = info.info.m_qos.m_durability.durabilityKind(); // Reliability if (info.info.m_qos.m_reliability.kind == fastdds::dds::BEST_EFFORT_RELIABILITY_QOS) { - discovered_topic_qos.reliability_qos = fastrtps::rtps::BEST_EFFORT; + endpoint.topic.topic_qos.reliability_qos = fastrtps::rtps::BEST_EFFORT; } else if (info.info.m_qos.m_reliability.kind == fastdds::dds::RELIABLE_RELIABILITY_QOS) { - discovered_topic_qos.reliability_qos = fastrtps::rtps::RELIABLE; + endpoint.topic.topic_qos.reliability_qos = fastrtps::rtps::RELIABLE; } else { @@ -120,30 +128,23 @@ core::types::Endpoint CommonParticipant::create_common_endpoint_from_info_( "Invalid ReliabilityQoS value found while parsing DiscoveryInfo for Endpoint creation."); } // Set Topic with Partitions - discovered_topic_qos.use_partitions = !info.info.m_qos.m_partition.empty(); + endpoint.topic.topic_qos.use_partitions = !info.info.m_qos.m_partition.empty(); // Set Topic with ownership - discovered_topic_qos.ownership_qos = info.info.m_qos.m_ownership.kind; + endpoint.topic.topic_qos.ownership_qos = info.info.m_qos.m_ownership.kind; + // Set Topic key + endpoint.topic.topic_qos.keyed = info.info.topicKind() == eprosima::fastrtps::rtps::TopicKind_t::WITH_KEY; // Parse Topic - core::types::DistributedTopic info_topic(std::string(info.info.topicName()), std::string(info.info.typeName())); - info_topic.keyed = info.info.topicKind() == eprosima::fastrtps::rtps::TopicKind_t::WITH_KEY; - // Set qos as set, but fuzzy - info_topic.topic_qos = discovered_topic_qos; - info_topic.topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_fuzzy); - - core::types::Endpoint endpoint = core::types::Endpoint( - core::types::EndpointKind::invalid, - info_guid, - info_topic, - this->id_nts_()); + core::types::DdsTopic info_topic; + endpoint.topic.m_topic_name = std::string(info.info.topicName()); + endpoint.topic.type_name = std::string(info.info.typeName()); + endpoint.topic.m_internal_type_discriminator = core::types::INTERNAL_TOPIC_TYPE_RTPS; // Parse specific QoS of the entity - core::types::SpecificEndpointQoS specific_qos; - if (discovered_topic_qos.has_partitions()) + if (endpoint.topic.topic_qos.has_partitions()) { - specific_qos.partitions = info.info.m_qos.m_partition; + endpoint.specific_qos.partitions = info.info.m_qos.m_partition; } - endpoint.specific_qos(specific_qos); // NOTE: ownership is only for Writer return endpoint; @@ -156,16 +157,14 @@ core::types::Endpoint CommonParticipant::create_endpoint_from_info_discovery_database_->erase_endpoint(info_reader); + info_reader.active = false; + this->discovery_database_->update_endpoint(info_reader); } else { logInfo(DDSROUTER_DISCOVERY, "Reader " << info.info.guid() << " dropped."); - info_reader.active(false); - this->discovery_database_->erase_endpoint(info_reader); + info_reader.active = false; + this->discovery_database_->update_endpoint(info_reader); } } } @@ -246,15 +245,15 @@ void CommonParticipant::onWriterDiscovery( { logInfo(DDSROUTER_DISCOVERY, "Writer " << info.info.guid() << " removed."); - info_writer.active(false); - this->discovery_database_->erase_endpoint(info_writer); + info_writer.active = false; + this->discovery_database_->update_endpoint(info_writer); } else { logInfo(DDSROUTER_DISCOVERY, "Writer " << info.info.guid() << " dropped."); - info_writer.active(false); - this->discovery_database_->erase_endpoint(info_writer); + info_writer.active = false; + this->discovery_database_->update_endpoint(info_writer); } } } @@ -290,63 +289,118 @@ void CommonParticipant::create_participant_( (this->is_repeater() ? " (repeater)" : " (non repeater)")); } -std::shared_ptr CommonParticipant::create_writer_( - core::types::DistributedTopic topic) +std::shared_ptr CommonParticipant::create_writer( + const core::ITopic& topic) { - if (topic.topic_qos.get_reference().has_partitions() || topic.topic_qos.get_reference().has_ownership()) + // Can only create DDS Topics + const core::types::DdsTopic* dds_topic_ptr = dynamic_cast(&topic); + if (!dds_topic_ptr) { - // Notice that MultiWriter does not require an init call - return std::make_shared( - this->id(), - topic, - this->payload_pool_, - rtps_participant_, - this->configuration_->is_repeater); + return std::make_shared(); + } + const core::types::DdsTopic& dds_topic = *dds_topic_ptr; + + if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RPC) + { + auto writer = std::make_shared( + this->id(), + dds_topic, + this->payload_pool_, + rtps_participant_, + this->configuration_->is_repeater); + writer->init(); + + return writer; + } + else if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RTPS) + { + if (dds_topic.topic_qos.has_partitions() || dds_topic.topic_qos.has_ownership()) + { + // Notice that MultiWriter does not require an init call + return std::make_shared( + this->id(), + dds_topic, + this->payload_pool_, + rtps_participant_, + this->configuration_->is_repeater); + } + else + { + auto writer = std::make_shared( + this->id(), + dds_topic, + this->payload_pool_, + rtps_participant_, + this->configuration_->is_repeater); + writer->init(); + + return writer; + } } else { - auto writer = std::make_shared( - this->id(), - topic, - this->payload_pool_, - rtps_participant_, - this->configuration_->is_repeater); - writer->init(); - - return writer; + logDevError(DDSROUTER_RTPS_PARTICIPANT, "Incorrect dds Topic in Writer creation."); + return std::make_shared(); } } -std::shared_ptr CommonParticipant::create_reader_( - core::types::DistributedTopic topic) +std::shared_ptr CommonParticipant::create_reader( + const core::ITopic& topic) { - if (topic.topic_qos.get_reference().has_partitions() || topic.topic_qos.get_reference().has_ownership()) + // Can only create DDS Topics + const core::types::DdsTopic* dds_topic_ptr = dynamic_cast(&topic); + if (!dds_topic_ptr) { - auto reader = std::make_shared( - this->id(), - topic, - this->payload_pool_, - rtps_participant_, - discovery_database_); - reader->init(); - - return reader; + return std::make_shared(); } - else + const core::types::DdsTopic& dds_topic = *dds_topic_ptr; + + if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RPC) { - auto reader = std::make_shared( + auto reader = std::make_shared( this->id(), - topic, + dds_topic, this->payload_pool_, rtps_participant_); reader->init(); return reader; } + else if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RTPS) + { + if (dds_topic.topic_qos.has_partitions() || dds_topic.topic_qos.has_ownership()) + { + auto reader = std::make_shared( + this->id(), + dds_topic, + this->payload_pool_, + rtps_participant_, + discovery_database_); + reader->init(); + + return reader; + } + else + { + auto reader = std::make_shared( + this->id(), + dds_topic, + this->payload_pool_, + rtps_participant_); + reader->init(); + + return reader; + } + } + else + { + logDevError(DDSROUTER_RTPS_PARTICIPANT, "Incorrect dds Topic in Reader creation."); + return std::make_shared(); + } } fastrtps::rtps::RTPSParticipantAttributes -CommonParticipant::get_participant_attributes_( +CommonParticipant::reckon_participant_attributes_( const ParticipantConfiguration* participant_configuration) { fastrtps::rtps::RTPSParticipantAttributes params; diff --git a/ddspipe_participants/src_/cpp/participant/rtps/DiscoveryServerParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp similarity index 95% rename from ddspipe_participants/src_/cpp/participant/rtps/DiscoveryServerParticipant.cpp rename to ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp index 543a92b1a..102907ca3 100644 --- a/ddspipe_participants/src_/cpp/participant/rtps/DiscoveryServerParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -32,24 +31,24 @@ namespace participants { namespace rtps { DiscoveryServerParticipant::DiscoveryServerParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) : CommonParticipant( participant_configuration, payload_pool, discovery_database, participant_configuration->domain, - get_participant_attributes_(participant_configuration.get())) + reckon_participant_attributes_(participant_configuration.get())) { } fastrtps::rtps::RTPSParticipantAttributes -DiscoveryServerParticipant::get_participant_attributes_( +DiscoveryServerParticipant::reckon_participant_attributes_( const DiscoveryServerParticipantConfiguration* configuration) { // Use default as base attributes - fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::get_participant_attributes_(configuration); + fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); // Auxiliary variable to save characters and improve readability const core::types::GuidPrefix& discovery_server_guid_prefix = configuration->discovery_server_guid_prefix; @@ -69,7 +68,7 @@ DiscoveryServerParticipant::get_participant_attributes_( ///// // Set listening addresses - for (core::types::Address address : configuration->listening_addresses) + for (types::Address address : configuration->listening_addresses) { if (!address.is_valid()) { @@ -194,7 +193,7 @@ DiscoveryServerParticipant::get_participant_attributes_( ///// // Set connection addresses - for (core::types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses) + for (types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses) { if (!connection_address.is_valid()) { @@ -209,7 +208,7 @@ DiscoveryServerParticipant::get_participant_attributes_( // Set Server GUID core::types::GuidPrefix server_prefix = connection_address.discovery_server_guid_prefix(); - for (core::types::Address address : connection_address.addresses()) + for (types::Address address : connection_address.addresses()) { if (!address.is_valid()) { diff --git a/ddspipe_participants/src_/cpp/participant/rtps/InitialPeersParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp similarity index 95% rename from ddspipe_participants/src_/cpp/participant/rtps/InitialPeersParticipant.cpp rename to ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp index 26763d540..5a45d7e48 100644 --- a/ddspipe_participants/src_/cpp/participant/rtps/InitialPeersParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -27,26 +26,24 @@ namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; - InitialPeersParticipant::InitialPeersParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) : CommonParticipant( participant_configuration, payload_pool, discovery_database, participant_configuration->domain, - get_participant_attributes_(participant_configuration.get())) + reckon_participant_attributes_(participant_configuration.get())) { } -fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participant_attributes_( +fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_participant_attributes_( const InitialPeersParticipantConfiguration* configuration) { // Use default as base attributes - fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::get_participant_attributes_(configuration); + fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); // Auxiliary variable to save characters and improve readability const auto& tls_config = configuration->tls_configuration; @@ -66,7 +63,7 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participa ///// // Set listening addresses - for (const core::types::Address& address : configuration->listening_addresses) + for (const types::Address& address : configuration->listening_addresses) { if (!address.is_valid()) { @@ -192,7 +189,7 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::get_participa ///// // Set connection addresses - for (const core::types::Address& connection_address : configuration->connection_addresses) + for (const types::Address& connection_address : configuration->connection_addresses) { if (!connection_address.is_valid()) { diff --git a/ddspipe_participants/src_/cpp/participant/rtps/SimpleParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp similarity index 77% rename from ddspipe_participants/src_/cpp/participant/rtps/SimpleParticipant.cpp rename to ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp index b686ab94d..e8745d7ee 100644 --- a/ddspipe_participants/src_/cpp/participant/rtps/SimpleParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include @@ -25,18 +24,16 @@ namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; - SimpleParticipant::SimpleParticipant( - std::shared_ptr participant_configuration, - std::shared_ptr payload_pool, - std::shared_ptr discovery_database) + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) : CommonParticipant( participant_configuration, payload_pool, discovery_database, participant_configuration->domain, - CommonParticipant::get_participant_attributes_(participant_configuration.get())) + CommonParticipant::reckon_participant_attributes_(participant_configuration.get())) { } diff --git a/ddspipe_participants/src_/cpp/reader/auxiliar/BaseReader.cpp b/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp similarity index 89% rename from ddspipe_participants/src_/cpp/reader/auxiliar/BaseReader.cpp rename to ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp index 9a3c66426..23361074a 100644 --- a/ddspipe_participants/src_/cpp/reader/auxiliar/BaseReader.cpp +++ b/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp @@ -12,17 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include #include -#include #include namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - const std::function BaseReader::DEFAULT_ON_DATA_AVAILABLE_CALLBACK = []() { @@ -30,11 +29,9 @@ const std::function BaseReader::DEFAULT_ON_DATA_AVAILABLE_CALLBACK = }; BaseReader::BaseReader( - const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool) + const core::types::ParticipantId& participant_id, + const std::shared_ptr& payload_pool) : participant_id_(participant_id) - , topic_(topic) , payload_pool_(payload_pool) , on_data_available_lambda_(DEFAULT_ON_DATA_AVAILABLE_CALLBACK) , on_data_available_lambda_set_(false) @@ -101,7 +98,7 @@ void BaseReader::unset_on_data_available_callback() noexcept } utils::ReturnCode BaseReader::take( - std::unique_ptr data) noexcept + std::unique_ptr& data) noexcept { std::lock_guard lock(mutex_); @@ -117,16 +114,11 @@ utils::ReturnCode BaseReader::take( } } -ParticipantId BaseReader::participant_id() const noexcept +core::types::ParticipantId BaseReader::participant_id() const noexcept { return participant_id_; } -DistributedTopic BaseReader::topic() const noexcept -{ - return topic_; -} - void BaseReader::on_data_available_() const noexcept { if (on_data_available_lambda_set_) @@ -154,7 +146,7 @@ std::ostream& operator <<( std::ostream& os, const BaseReader& reader) { - os << "Reader{" << reader.participant_id_ << ";" << reader.topic_ << "}"; + os << "Reader{" << reader.participant_id_ << "}"; return os; } diff --git a/ddspipe_participants/src_/cpp/reader/auxiliar/BlankReader.cpp b/ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp similarity index 60% rename from ddspipe_participants/src_/cpp/reader/auxiliar/BlankReader.cpp rename to ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp index 0d6d4949f..1f824b10d 100644 --- a/ddspipe_participants/src_/cpp/reader/auxiliar/BlankReader.cpp +++ b/ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include @@ -19,8 +20,6 @@ namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - void BlankReader::enable() noexcept { } @@ -44,6 +43,31 @@ utils::ReturnCode BlankReader::take( return utils::ReturnCode::RETCODE_NO_DATA; } +core::types::Guid BlankReader::guid() const +{ + throw utils::UnsupportedException("guid method not allowed for non RTPS readers."); +} + +fastrtps::RecursiveTimedMutex& BlankReader::get_rtps_mutex() const +{ + throw utils::UnsupportedException("get_rtps_mutex method not allowed for non RTPS readers."); +} + +uint64_t BlankReader::get_unread_count() const +{ + throw utils::UnsupportedException("get_unread_count method not allowed for non RTPS readers."); +} + +core::types::DdsTopic BlankReader::topic() const +{ + throw utils::UnsupportedException("topic method not allowed for non RTPS readers."); +} + +core::types::ParticipantId BlankReader::participant_id() const +{ + throw utils::UnsupportedException("participant_id method not allowed for non RTPS readers."); +} + } /* namespace participants */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp b/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp new file mode 100644 index 000000000..1f09cafac --- /dev/null +++ b/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp @@ -0,0 +1,68 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace rpc { + +SimpleReader::SimpleReader( + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + const std::shared_ptr& payload_pool, + fastrtps::rtps::RTPSParticipant* rtps_participant) + : CommonReader( + participant_id, topic, payload_pool, rtps_participant, + reckon_history_attributes_(topic), + reckon_reader_attributes_(topic), + reckon_topic_attributes_(topic), + reckon_reader_qos_(topic)) +{ +} + +//! Override Parent method to create an RPC data type. +core::types::RtpsPayloadData* SimpleReader::create_data_( + const fastrtps::rtps::CacheChange_t& received_change) const noexcept +{ + return new core::types::RpcPayloadData(); +} + +//! Override Parent method to fill fields exclusive from RPC. +void SimpleReader::fill_received_data_( + const fastrtps::rtps::CacheChange_t& received_change, + core::types::RtpsPayloadData& data_to_fill) const noexcept +{ + CommonReader::fill_received_data_(received_change, data_to_fill); + + // Get internal RpcPayload + core::types::RpcPayloadData& rpc_data = dynamic_cast(data_to_fill); + // Set write params and origin sequence number + rpc_data.write_params = received_change.write_params; + rpc_data.origin_sequence_number = received_change.sequenceNumber; +} + +} /* namespace rpc */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/reader/rtps/CommonReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp similarity index 81% rename from ddspipe_participants/src_/cpp/reader/rtps/CommonReader.cpp rename to ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp index 4786ae3dd..8724cce80 100644 --- a/ddspipe_participants/src_/cpp/reader/rtps/CommonReader.cpp +++ b/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp @@ -12,35 +12,36 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include #include -#include #include -#include +#include + +#include namespace eprosima { namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; -using eprosima::ddsrouter::core::types::operator<<; +using namespace eprosima::ddspipe::core::types; +using eprosima::ddspipe::core::types::operator<<; CommonReader::CommonReader( const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool, + const DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const fastrtps::rtps::HistoryAttributes& history_attributes, const fastrtps::rtps::ReaderAttributes& reader_attributes, const fastrtps::TopicAttributes& topic_attributes, const fastrtps::ReaderQos& reader_qos) - : BaseReader(participant_id, topic, payload_pool) + : BaseReader(participant_id, payload_pool) + , topic_(topic) , rtps_participant_(rtps_participant) , history_attributes_(history_attributes) , reader_attributes_(reader_attributes) @@ -133,7 +134,7 @@ core::types::Guid CommonReader::guid() const noexcept return rtps_reader_->getGuid(); } -RecursiveTimedMutex& CommonReader::get_rtps_mutex() const noexcept +fastrtps::RecursiveTimedMutex& CommonReader::get_rtps_mutex() const noexcept { return rtps_reader_->getMutex(); } @@ -143,11 +144,11 @@ uint64_t CommonReader::get_unread_count() const noexcept return rtps_reader_->get_unread_count(); } -utils::ReturnCode CommonReader::take_( +utils::ReturnCode CommonReader::take_nts_( std::unique_ptr& data) noexcept { // Check if there is data available - if (!(get_unread_count() > 0)) + if (!(rtps_reader_->get_unread_count() > 0)) { return utils::ReturnCode::RETCODE_NO_DATA; } @@ -172,8 +173,8 @@ utils::ReturnCode CommonReader::take_( } // Store the new data that has arrived in the Track data - auto data_ptr = create_data_(received_change); - fill_received_data_(received_change, *data_ptr); + auto data_ptr = create_data_(*received_change); + fill_received_data_(*received_change, *data_ptr); data.reset(data_ptr); // Remove the change in the History and release it in the reader @@ -189,49 +190,45 @@ RtpsPayloadData* CommonReader::create_data_( } void CommonReader::fill_received_data_( - fastrtps::rtps::CacheChange_t* received_change, + const fastrtps::rtps::CacheChange_t& received_change, RtpsPayloadData& data_to_fill) const noexcept { // Store the new data that has arrived in the Track data // Get the writer guid - data_to_fill->properties.source_guid = received_change->writerGUID; + data_to_fill.source_guid = received_change.writerGUID; // Get source timestamp - data_to_fill->properties.source_timestamp = received_change->sourceTimestamp; + data_to_fill.source_timestamp = received_change.sourceTimestamp; // Get Participant receiver - data_to_fill->properties.participant_receiver = participant_id_; + data_to_fill.participant_receiver = participant_id_; // Store it in DDSRouter PayloadPool if size is bigger than 0 // NOTE: in case of keyed topics an empty payload is possible - if (received_change->serializedPayload.length > 0) + if (received_change.serializedPayload.length > 0) { - eprosima::fastrtps::rtps::IPayloadPool* payload_owner = received_change->payload_owner(); + eprosima::fastrtps::rtps::IPayloadPool* payload_owner = const_cast(received_change.payload_owner()); payload_pool_->get_payload( - received_change->serializedPayload, + received_change.serializedPayload, payload_owner, - data_to_fill->payload); + data_to_fill.payload); - data_to_fill->payload_owner = payload_pool_->get(); + data_to_fill.payload_owner = payload_pool_.get(); } // Set Instance Handle to data_to_fill - if (topic_.keyed) + if (topic_.topic_qos.keyed) { - data_to_fill->properties.instanceHandle = received_change->instanceHandle; + data_to_fill.instanceHandle = received_change.instanceHandle; } // Set change kind - data_to_fill->properties.kind = received_change->kind; - - data_to_fill->properties.write_params.set_value(received_change->write_params); - - data_to_fill->properties.origin_sequence_number = received_change->sequenceNumber; + data_to_fill.kind = received_change.kind; // Note: do not fill writer specific properties in this data_to_fill from this kind of Readers. // Implement specific class for filling it. logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, "Data transmiting to track from Reader " << *this << " with payload " << - data_to_fill->payload << " from remote writer " << data_to_fill->properties.source_guid); + data_to_fill.payload << " from remote writer " << data_to_fill.source_guid); } @@ -239,7 +236,7 @@ void CommonReader::enable_() noexcept { // If the topic is reliable, the reader will keep the samples received when it was disabled. // However, if the topic is best_effort, the reader will discard the samples received when it was disabled. - if (topic_.topic_qos.get_reference().is_reliable()) + if (topic_.topic_qos.is_reliable()) { std::lock_guard lock(get_rtps_mutex()); on_data_available_(); @@ -258,31 +255,31 @@ bool CommonReader::come_from_this_participant_( return guid.guidPrefix == rtps_reader_->getGuid().guidPrefix; } -fastrtps::rtps::HistoryAttributes CommonReader::get_history_attributes_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::rtps::HistoryAttributes CommonReader::reckon_history_attributes_( + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::HistoryAttributes att; att.memoryPolicy = eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - att.maximumReservedCaches = topic.topic_qos.get_reference().history_depth; + att.maximumReservedCaches = topic.topic_qos.history_depth; return att; } -fastrtps::rtps::ReaderAttributes CommonReader::get_reader_attributes_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::rtps::ReaderAttributes CommonReader::reckon_reader_attributes_( + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::ReaderAttributes att; // Set Durability - att.endpoint.durabilityKind = topic.topic_qos.get_reference().durability_qos; + att.endpoint.durabilityKind = topic.topic_qos.durability_qos; // Set Reliability - att.endpoint.reliabilityKind = topic.topic_qos.get_reference().reliability_qos; + att.endpoint.reliabilityKind = topic.topic_qos.reliability_qos; // Set if topic has key - if (topic.keyed) + if (topic.topic_qos.keyed) { att.endpoint.topicKind = eprosima::fastrtps::rtps::WITH_KEY; } @@ -296,13 +293,13 @@ fastrtps::rtps::ReaderAttributes CommonReader::get_reader_attributes_( return att; } -fastrtps::TopicAttributes CommonReader::get_topic_attributes_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::TopicAttributes CommonReader::reckon_topic_attributes_( + const core::types::DdsTopic& topic) noexcept { fastrtps::TopicAttributes att; // Set if topic has key - if (topic.keyed) + if (topic.topic_qos.keyed) { att.topicKind = eprosima::fastrtps::rtps::WITH_KEY; } @@ -312,41 +309,41 @@ fastrtps::TopicAttributes CommonReader::get_topic_attributes_( } // Set Topic attributes - att.topicName = topic.topic_name; + att.topicName = topic.m_topic_name; att.topicDataType = topic.type_name; // Set Topic history attributes att.historyQos.kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS; - att.historyQos.depth = topic.topic_qos.get_reference().history_depth; + att.historyQos.depth = topic.topic_qos.history_depth; return att; } -fastrtps::ReaderQos CommonReader::get_reader_qos_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::ReaderQos CommonReader::reckon_reader_qos_( + const core::types::DdsTopic& topic) noexcept { fastrtps::ReaderQos properties; // Set Durability properties.m_durability.kind = - (topic.topic_qos.get_reference().is_transient_local() + (topic.topic_qos.is_transient_local() ? eprosima::fastdds::dds::DurabilityQosPolicyKind_t::TRANSIENT_LOCAL_DURABILITY_QOS : eprosima::fastdds::dds::DurabilityQosPolicyKind_t::VOLATILE_DURABILITY_QOS); // Set Reliability properties.m_reliability.kind = - (topic.topic_qos.get_reference().is_reliable() + (topic.topic_qos.is_reliable() ? eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS : eprosima::fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS); // If topic with partitions, set this CommonReader in * - if (topic.topic_qos.get_reference().use_partitions) + if (topic.topic_qos.use_partitions) { properties.m_partition.push_back("*"); } // If topic is with ownership - properties.m_ownership.kind = topic.topic_qos.get_reference().ownership_qos; + properties.m_ownership.kind = topic.topic_qos.ownership_qos; return properties; } @@ -371,7 +368,7 @@ void CommonReader::onNewCacheChangeAdded( { // Remove received change if the CommonReader is disbled and the topic is not reliable // NOTE: this should be is_reliable and not is_transient_local for RPC sake - if (!topic_.topic_qos.get_reference().is_reliable()) + if (!topic_.topic_qos.is_reliable()) { reader->getHistory()->remove_change((fastrtps::rtps::CacheChange_t*)change); logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, @@ -426,7 +423,7 @@ utils::ReturnCode CommonReader::is_data_correct_( if (!(received_change->serializedPayload.max_size > 0)) { // Data with 0 bytes is only correct if keyed topic and if data is being disposed - if (!(topic_.keyed && received_change->kind != eprosima::fastrtps::rtps::ChangeKind_t::ALIVE)) + if (!(topic_.topic_qos.keyed && received_change->kind != eprosima::fastrtps::rtps::ChangeKind_t::ALIVE)) { logWarning(DDSROUTER_RTPS_COMMONREADER_LISTENER, "Error taking data with length " << received_change->serializedPayload.length << "."); diff --git a/ddspipe_participants/src_/cpp/reader/rtps/SimpleReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp similarity index 78% rename from ddspipe_participants/src_/cpp/reader/rtps/SimpleReader.cpp rename to ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp index 5e9ac6ace..5f80bdaad 100644 --- a/ddspipe_participants/src_/cpp/reader/rtps/SimpleReader.cpp +++ b/ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include @@ -25,19 +24,17 @@ namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; - SimpleReader::SimpleReader( - const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant) : CommonReader( participant_id, topic, payload_pool, rtps_participant, - get_history_attributes_(topic), - get_reader_attributes_(topic), - get_topic_attributes_(topic), - get_reader_qos_(topic)) + reckon_history_attributes_(topic), + reckon_reader_attributes_(topic), + reckon_topic_attributes_(topic), + reckon_reader_qos_(topic)) { } diff --git a/ddspipe_participants/src_/cpp/reader/rtps/SpecificQoSReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp similarity index 66% rename from ddspipe_participants/src_/cpp/reader/rtps/SpecificQoSReader.cpp rename to ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp index a5d94a6e5..ac6185819 100644 --- a/ddspipe_participants/src_/cpp/reader/rtps/SpecificQoSReader.cpp +++ b/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp @@ -26,20 +26,18 @@ namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; - SpecificQoSReader::SpecificQoSReader( const core::types::ParticipantId& participant_id, - const core::types::DistributedTopic& topic, - std::shared_ptr payload_pool, + const core::types::DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - std::shared_ptr discovery_database) + const std::shared_ptr& discovery_database) : CommonReader( participant_id, topic, payload_pool, rtps_participant, - get_history_attributes_(topic), - get_reader_attributes_(topic), - get_topic_attributes_(topic), - get_reader_qos_(topic)) + reckon_history_attributes_(topic), + reckon_reader_attributes_(topic), + reckon_topic_attributes_(topic), + reckon_reader_qos_(topic)) , discovery_database_(discovery_database) { } @@ -47,22 +45,22 @@ SpecificQoSReader::SpecificQoSReader( core::types::SpecificEndpointQoS SpecificQoSReader::specific_qos_of_writer_( const core::types::Guid& guid) const { - return discovery_database_->get_endpoint(guid).specific_qos(); + return discovery_database_->get_endpoint(guid).specific_qos; } -void fill_received_data_( - fastrtps::rtps::CacheChange_t* received_change, - RtpsPayloadData& data_to_fill) const noexcept +void SpecificQoSReader::fill_received_data_( + const fastrtps::rtps::CacheChange_t& received_change, + core::types::RtpsPayloadData& data_to_fill) const noexcept { CommonReader::fill_received_data_(received_change, data_to_fill); // Find qos of writer try { - data_to_fill->properties.writer_qos = specific_qos_of_writer_(data_to_fill->properties.source_guid); + data_to_fill.writer_qos = specific_qos_of_writer_(data_to_fill.source_guid); logDebug( DDSROUTER_SpecificQoSReader, - "Set QoS " << data_to_fill->properties << " for data from " << data_to_fill->properties.source_guid << "."); + "Set QoS " << data_to_fill.<< " for data from " << data_to_fill.source_guid << "."); } catch (const utils::InconsistencyException& e) { @@ -70,10 +68,8 @@ void fill_received_data_( // Remove data and make as it has not been received. logError( DDSROUTER_SpecificQoSReader, - "Received a message from Writer " << data_to_fill->properties.source_guid << " that is not stored in DB."); + "Received a message from Writer " << data_to_fill.source_guid << " that is not stored in DB."); } - - return data; } } /* namespace rtps */ diff --git a/ddspipe_participants/src/cpp/types/address/Address.cpp b/ddspipe_participants/src/cpp/types/address/Address.cpp new file mode 100644 index 000000000..780be65c0 --- /dev/null +++ b/ddspipe_participants/src/cpp/types/address/Address.cpp @@ -0,0 +1,438 @@ +// Copyright 2021 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. + +#include + +#include +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace types { + +const PortType Address::DEFAULT_PORT_ = 11666; +const IpType Address::DEFAULT_IP_v4_ = "127.0.0.1"; +const IpType Address::DEFAULT_IP_v6_ = "::1"; +const IpVersion Address::DEFAULT_IP_VERSION_ = IpVersion::v4; +const TransportProtocol Address::DEFAULT_TRANSPORT_PROTOCOL_ = TransportProtocol::udp; + +Address::Address() + : Address(DEFAULT_IP_v4_, DEFAULT_PORT_, DEFAULT_PORT_, DEFAULT_IP_VERSION_, DEFAULT_TRANSPORT_PROTOCOL_) +{ +} + +Address::Address( + const IpType& ip, + const PortType& port, + const PortType& external_port, + const IpVersion& ip_version, + const TransportProtocol& transport_protocol) noexcept + : ip_(ip) + , domain_() + , has_domain_(false) + , has_valid_domain_(false) + , port_(port) + , external_port_(external_port) + , ip_version_(ip_version) + , transport_protocol_(transport_protocol) +{ +} + +Address::Address( + const PortType& port, + const PortType& external_port, + const IpVersion& ip_version, + const DomainType& domain, + const TransportProtocol& transport_protocol) noexcept + : ip_() + , domain_(domain) + , has_domain_(true) + , has_valid_domain_(false) + , port_(port) + , external_port_(external_port) + , ip_version_(ip_version) + , transport_protocol_(transport_protocol) +{ + try + { + ip_ = Address::resolve_dns(domain_, ip_version_); + has_valid_domain_ = true; + } + catch (const utils::DNSException& ) + { + logWarning( + DDSROUTER_ADDRESS, "Address created without IP because given domain " << domain << " was not found."); + } +} + +Address::Address( + const IpType& ip, + const PortType& port, + const PortType& external_port, + const TransportProtocol& transport_protocol) noexcept + : Address(ip, port, external_port, IpVersion::v4, transport_protocol) +{ + if (is_ipv6_correct(ip_)) + { + ip_version_ = IpVersion::v6; + } +} + +Address::Address( + const PortType& port, + const PortType& external_port, + const DomainType& domain, + const TransportProtocol& transport_protocol) noexcept + : ip_() + , domain_(domain) + , has_domain_(true) + , has_valid_domain_(false) + , port_(port) + , external_port_(external_port) + , transport_protocol_(transport_protocol) +{ + try + { + auto dns_respone = Address::resolve_dns(domain_); + ip_ = dns_respone.first; + ip_version_ = dns_respone.second; + has_valid_domain_ = true; + } + catch (const utils::DNSException& ) + { + logWarning( + DDSROUTER_ADDRESS, "Address created without IP because given domain " << domain << " was not found."); + } +} + +PortType Address::port() const noexcept +{ + return port_; +} + +PortType Address::external_port() const noexcept +{ + return external_port_; +} + +IpType Address::ip() const noexcept +{ + return ip_; +} + +IpVersion Address::ip_version() const noexcept +{ + return ip_version_; +} + +TransportProtocol Address::transport_protocol() const noexcept +{ + return transport_protocol_; +} + +bool Address::is_udp() const noexcept +{ + return transport_protocol_ == TransportProtocol::udp; +} + +bool Address::is_tcp() const noexcept +{ + return transport_protocol_ == TransportProtocol::tcp; +} + +bool Address::is_ipv4() const noexcept +{ + return ip_version_ == IpVersion::v4; +} + +bool Address::is_ipv6() const noexcept +{ + return ip_version_ == IpVersion::v6; +} + +LocatorType Address::get_locator_kind() const noexcept +{ + if (ip_version_ == IpVersion::v4) + { + if (transport_protocol_ == TransportProtocol::udp) + { + return LOCATOR_KIND_UDPv4; + } + else if (transport_protocol_ == TransportProtocol::tcp) + { + return LOCATOR_KIND_TCPv4; + } + } + else if (ip_version_ == IpVersion::v6) + { + if (transport_protocol_ == TransportProtocol::udp) + { + return LOCATOR_KIND_UDPv6; + } + else if (transport_protocol_ == TransportProtocol::tcp) + { + return LOCATOR_KIND_TCPv6; + } + } + + return LOCATOR_KIND_INVALID; +} + +bool Address::is_valid() const noexcept +{ + if (has_domain_ && !has_valid_domain_) + { + return false; + } + + // Check that if UDP, external port must be not set (must be equal to internal port) + if (is_udp()) + { + if (port_ != external_port_) + { + return false; + } + } + + // Check correct ip + switch (ip_version_) + { + case IpVersion::v4: + return is_ipv4_correct(ip_); + + case IpVersion::v6: + return is_ipv6_correct(ip_); + + default: + utils::tsnh( + utils::Formatter() << "Ip version value out of IpVersion."); + return false; // Unreachable code + } +} + +bool Address::operator <( + const Address& other) const noexcept +{ + // Compare IPs + int ip_comparison = this->ip_.compare(other.ip_); + if (ip_comparison < 0) + { + return true; + } + else if (ip_comparison > 0) + { + return false; + } + else + { + // Compare Ports + if (this->port_ < other.port_) + { + return true; + } + else if (this->port_ > other.port_) + { + return false; + } + else + { + // Compare Protocol + if (this->transport_protocol_ < other.transport_protocol_) + { + return true; + } + else if (this->transport_protocol_ > other.transport_protocol_) + { + return false; + } + else + { + // Compare Ip Version + return this->ip_version_ < other.ip_version_; + } + } + } +} + +bool Address::operator ==( + const Address& other) const noexcept +{ + return this->ip() == other.ip() && + this->port() == other.port() && + this->transport_protocol() == other.transport_protocol() && + this->is_valid() == other.is_valid(); +} + +bool Address::is_ipv4_correct( + const IpType& ip) noexcept +{ + return eprosima::fastrtps::rtps::IPLocator::isIPv4(ip); +} + +bool Address::is_ipv6_correct( + const IpType& ip) noexcept +{ + return eprosima::fastrtps::rtps::IPLocator::isIPv6(ip); +} + +PortType Address::default_port() noexcept +{ + return DEFAULT_PORT_; +} + +IpType Address::default_ip( + IpVersion ip_version /* = default_ip_version() */) noexcept +{ + if (ip_version == IpVersion::v4) + { + return DEFAULT_IP_v4_; + } + else if (ip_version == IpVersion::v6) + { + return DEFAULT_IP_v6_; + } + else + { + utils::tsnh(utils::Formatter() << "Value v" << static_cast(ip_version) << + " is not allowed for IpVersion."); + return DEFAULT_IP_v4_; + } +} + +IpVersion Address::default_ip_version() noexcept +{ + return DEFAULT_IP_VERSION_; +} + +TransportProtocol Address::default_transport_protocol() noexcept +{ + return DEFAULT_TRANSPORT_PROTOCOL_; +} + +IpType Address::resolve_dns( + DomainType domain, + IpVersion ip_version) +{ + std::pair, std::set> dns_response = + fastrtps::rtps::IPLocator::resolveNameDNS(domain); + + if (ip_version == IpVersion::v4) + { + if (dns_response.first.empty()) + { + throw utils::DNSException( + utils::Formatter() << "Could not resolve IpVersion::v4 for domain name <" << domain << ">."); + } + else + { + logInfo( + DDSROUTER_ADDRESS, + "Getting first IpVersion::v4: " << dns_response.first.begin()->data() << + " for Domain name: " << domain << + " from DNS response from " << dns_response.first.size() << " valid IPs."); + return dns_response.first.begin()->data(); + } + } + else + { + if (dns_response.second.empty()) + { + throw utils::DNSException( + utils::Formatter() << "Could not resolve IpVersion::v6 for domain name <" << domain << ">."); + } + else + { + logInfo( + DDSROUTER_ADDRESS, + "Getting first IpVersion::v6: " << dns_response.second.begin()->data() << + " for Domain name: " << domain << + " from DNS response from " << dns_response.second.size() << " valid IPs."); + return dns_response.second.begin()->data(); + } + } +} + +std::pair Address::resolve_dns( + DomainType domain) +{ + std::pair, std::set> dns_response = + fastrtps::rtps::IPLocator::resolveNameDNS(domain); + + if (dns_response.first.empty()) + { + if (dns_response.second.empty()) + { + throw utils::DNSException( + utils::Formatter() << + "Could not resolve IP for IpVersion::v4 nor IpVersion::v6 for domain name <" << domain << + ">."); + } + else + { + logInfo( + DDSROUTER_ADDRESS, + "Getting first IpVersion::v6: " << dns_response.second.begin()->data() << + " for Domain name: " << domain << + " from DNS response from " << dns_response.second.size() << " valid IPs."); + return {dns_response.second.begin()->data(), IpVersion::v6}; + } + } + else + { + logInfo( + DDSROUTER_ADDRESS, + "Getting first IpVersion::v4: " << dns_response.first.begin()->data() << + " for Domain name: " << domain << + " from DNS response from " << (dns_response.first.size() + dns_response.second.size()) << + " valid IPs."); + return {dns_response.first.begin()->data(), IpVersion::v4}; + } +} + +std::ostream& operator <<( + std::ostream& output, + const Address& address) +{ + output << "{"; + + if (address.has_domain_) + { + output << address.domain_ << "(" << address.ip() << ");"; + } + else + { + output << address.ip() << ";"; + } + output << address.port() << ";"; + + if (address.is_udp()) + { + output << "udp}"; + } + else + { + // TODO change for else if cause there may be more transports + output << "tcp}"; + } + + return output; +} + +} /* namespace types */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp b/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp new file mode 100644 index 000000000..d23de30cd --- /dev/null +++ b/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp @@ -0,0 +1,96 @@ +// Copyright 2021 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. + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace types { + +DiscoveryServerConnectionAddress::DiscoveryServerConnectionAddress( + core::types::GuidPrefix discovery_server_guid, + std::set
addresses) + : discovery_server_guid_prefix_(discovery_server_guid) + , addresses_(addresses) +{ +} + +core::types::GuidPrefix DiscoveryServerConnectionAddress::discovery_server_guid_prefix() const noexcept +{ + return discovery_server_guid_prefix_; +} + +std::set
DiscoveryServerConnectionAddress::addresses() const noexcept +{ + return addresses_; +} + +bool DiscoveryServerConnectionAddress::is_valid() const noexcept +{ + if (!discovery_server_guid_prefix_.is_valid()) + { + return false; + } + + for (auto address : addresses_) + { + if (address.is_valid()) + { + return true; + } + } + + return false; +} + +bool DiscoveryServerConnectionAddress::operator <( + const DiscoveryServerConnectionAddress& other) const noexcept +{ + if (this->discovery_server_guid_prefix() == other.discovery_server_guid_prefix()) + { + // Same Guid + return this->addresses() < other.addresses(); + } + else + { + // Different guid + return this->discovery_server_guid_prefix() < other.discovery_server_guid_prefix(); + } +} + +bool DiscoveryServerConnectionAddress::operator ==( + const DiscoveryServerConnectionAddress& other) const noexcept +{ + return (this->discovery_server_guid_prefix() == other.discovery_server_guid_prefix()) && + (this->addresses() == other.addresses()); +} + +std::ostream& operator <<( + std::ostream& output, + const DiscoveryServerConnectionAddress& address) +{ + output << "{{" << address.discovery_server_guid_prefix() << "}["; + for (auto a : address.addresses()) + { + output << a << ","; + } + output << "]}"; + return output; +} + +} /* namespace types */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp b/ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp new file mode 100644 index 000000000..8ccbae2f0 --- /dev/null +++ b/ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp @@ -0,0 +1,204 @@ +// Copyright 2022 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. + +#include +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace types { + +bool TlsConfiguration::is_active() const noexcept +{ + return this->kind != TlsKind::inactive; +} + +void TlsConfiguration::enable_tls( + std::shared_ptr descriptor, + bool client /* = false */) const +{ + // Apply security ON + descriptor->apply_security = true; + + // Options + descriptor->tls_config.add_option( + eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::DEFAULT_WORKAROUNDS); + descriptor->tls_config.add_option( + eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::SINGLE_DH_USE); + descriptor->tls_config.add_option( + eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::NO_SSLV2); // not safe + + if (verify_peer) + { + // Perform verification of the server + descriptor->tls_config.add_verify_mode( + eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_PEER); + } + else + { + descriptor->tls_config.add_verify_mode( + eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_NONE); + } + + if (client) + { + if (!compatible()) + { + logError(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, + "TLS Configuration expected a Client configuration."); + throw utils::ConfigurationException("TLS Configuration expected a Client configuration."); + } + else + { + enable_tls_client(descriptor, true); + } + } + else + { + if (!compatible()) + { + logError(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, + "TLS Configuration expected a Server configuration."); + throw utils::ConfigurationException("TLS Configuration expected a Server configuration."); + } + else + { + // Add configuration for server + enable_tls_server(descriptor); + + // In case it could also be client, add tls config + if (compatible()) + { + enable_tls_client(descriptor, false); + } + } + } + + logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, + "TLS configured."); +} + +void TlsConfiguration::enable_tls_client( + std::shared_ptr descriptor, + bool only_client) const +{ + if (only_client && verify_peer) + { + // Fail verification if the server has no certificate + descriptor->tls_config.add_verify_mode( + eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_FAIL_IF_NO_PEER_CERT); + } + + // CA certificate + descriptor->tls_config.verify_file = certificate_authority_file; + + // SNI server name + descriptor->tls_config.server_name = sni_server_name; +} + +void TlsConfiguration::enable_tls_server( + std::shared_ptr descriptor) const +{ + // Password + descriptor->tls_config.password = private_key_file_password; + // Private key + descriptor->tls_config.private_key_file = private_key_file; + // DDS-Router certificate + descriptor->tls_config.cert_chain_file = certificate_chain_file; + // DH + descriptor->tls_config.tmp_dh_file = dh_params_file; +} + +template <> +DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( + utils::Formatter& error_msg) const noexcept +{ + if (verify_peer) + { + if (certificate_authority_file.empty()) + { + // TODO check it is a correct file + error_msg << "Invalid certificate_authority_file while server verification must be done."; + return false; + } + } + return true; +} + +template <> +DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( + utils::Formatter& error_msg) const noexcept +{ + if (private_key_file.empty()) + { + // TODO check it is a correct file + error_msg << "Invalid private_key_file."; + return false; + } + + if (dh_params_file.empty()) + { + // TODO check it is a correct file + error_msg << "Invalid dh_params_file."; + return false; + } + + // chain cert is not required, however is usually needed + if (certificate_chain_file.empty()) + { + // TODO check it is a correct file + error_msg << "Invalid certificate_chain_file."; + return false; + } + + return true; +} + +template <> +DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( + utils::Formatter& error_msg) const noexcept +{ + return is_valid_kind(error_msg) && is_valid_kind(error_msg); +} + +bool TlsConfiguration::is_valid( + utils::Formatter& error_msg) const noexcept +{ + switch (kind) + { + case TlsKind::client: + return is_valid_kind(error_msg); + + case TlsKind::server: + return is_valid_kind(error_msg); + + case TlsKind::both: + return is_valid_kind(error_msg); + + default: + // None + return true; + } +} + +} /* namespace types */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/writer/auxiliar/BaseWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp similarity index 87% rename from ddspipe_participants/src_/cpp/writer/auxiliar/BaseWriter.cpp rename to ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp index 7ab687921..25fb83409 100644 --- a/ddspipe_participants/src_/cpp/writer/auxiliar/BaseWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -21,14 +20,10 @@ namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - BaseWriter::BaseWriter( - const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool) + const core::types::ParticipantId& participant_id, + const std::shared_ptr& payload_pool) : participant_id_(participant_id) - , topic_(topic) , payload_pool_(payload_pool) , enabled_(false) { @@ -64,7 +59,7 @@ void BaseWriter::disable() noexcept } utils::ReturnCode BaseWriter::write( - IRoutingData& data) noexcept + core::IRoutingData& data) noexcept { std::lock_guard lock(mutex_); @@ -94,7 +89,7 @@ std::ostream& operator <<( std::ostream& os, const BaseWriter& writer) { - os << "Writer{" << writer.participant_id_ << ";" << writer.topic_ << "}"; + os << "Writer{" << writer.participant_id_ << "}"; return os; } diff --git a/ddspipe_participants/src_/cpp/writer/auxiliar/BlankWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp similarity index 95% rename from ddspipe_participants/src_/cpp/writer/auxiliar/BlankWriter.cpp rename to ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp index 715064210..e9e11a44c 100644 --- a/ddspipe_participants/src_/cpp/writer/auxiliar/BlankWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp @@ -19,8 +19,6 @@ namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; - void BlankWriter::enable() noexcept { } diff --git a/ddspipe_participants/src_/cpp/writer/auxiliar/EchoWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp similarity index 63% rename from ddspipe_participants/src_/cpp/writer/auxiliar/EchoWriter.cpp rename to ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp index 5d314b6ab..e8611bafb 100644 --- a/ddspipe_participants/src_/cpp/writer/auxiliar/EchoWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp @@ -12,20 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include -#include -#include +#include + +#include namespace eprosima { namespace ddspipe { namespace participants { -using namespace eprosima::ddsrouter::core::types; +using eprosima::ddspipe::core::types::operator<<; -EchoWriter::EchoWriter( - const core::types::DistributedTopic& topic, +RtpsEchoWriter::RtpsEchoWriter( + const core::types::DdsTopic& topic, bool verbose) : topic_(topic) , verbose_(verbose) @@ -36,28 +36,28 @@ EchoWriter::EchoWriter( (verbose_ ? "active" : "inactive") << "."); } -utils::ReturnCode EchoWriter::write( - IRoutingData& data) noexcept +utils::ReturnCode RtpsEchoWriter::write( + core::IRoutingData& data) noexcept { - auto rtps_data = dynamic_cast(data); + auto rtps_data = dynamic_cast(data); // TODO: Add Participant receiver Id when added to DataReceived if (!verbose_) { logUser( DDSROUTER_ECHO_DATA, - "Received data in Participant: " << rtps_data.properties.participant_receiver << - " in topic: " << topic_ << + "Received data in Participant: " << rtps_data.participant_receiver << + " in topic: " << topic_.topic_name() << "."); } else { logUser( DDSROUTER_ECHO_DATA, - "In Endpoint: " << rtps_data.properties.source_guid << - " from Participant: " << rtps_data.properties.participant_receiver << - " in topic: " << topic_ << + "In Endpoint: " << rtps_data.source_guid << + " from Participant: " << rtps_data.participant_receiver << + " in topic: " << topic_.topic_name() << " payload received: " << rtps_data.payload << - " with specific qos: " << rtps_data.properties.writer_qos << + " with specific qos: " << rtps_data.writer_qos << "."); } diff --git a/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp b/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp new file mode 100644 index 000000000..61687229c --- /dev/null +++ b/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp @@ -0,0 +1,82 @@ +// Copyright 2021 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. + + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace rpc { + +SimpleWriter::SimpleWriter( + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + const std::shared_ptr& payload_pool, + fastrtps::rtps::RTPSParticipant* rtps_participant, + const bool repeater /* = false */) + : CommonWriter( + participant_id, topic, payload_pool, rtps_participant, repeater, + reckon_history_attributes_(topic), + reckon_writer_attributes_(topic), + reckon_topic_attributes_(topic), + reckon_writer_qos_(topic), + reckon_cache_change_pool_configuration_(topic)) +{ +} + +utils::ReturnCode SimpleWriter::fill_to_send_data_( + fastrtps::rtps::CacheChange_t* to_send_change_to_fill, + eprosima::fastrtps::rtps::WriteParams& to_send_params, + const core::types::RtpsPayloadData& data) const noexcept +{ + CommonWriter::fill_to_send_data_( + to_send_change_to_fill, + to_send_params, + data); + + const core::types::RpcPayloadData& rpc_data = dynamic_cast(data); + if (rpc_data.write_params.is_set()) + { + to_send_params.related_sample_identity(rpc_data.write_params.get_reference().related_sample_identity()); + } + + return utils::ReturnCode::RETCODE_OK; +} + +void SimpleWriter::fill_sent_data_( + const eprosima::fastrtps::rtps::WriteParams& sent_params, + core::types::RtpsPayloadData& data_to_fill) const noexcept +{ + core::types::RpcPayloadData& rpc_data = dynamic_cast(data_to_fill); + rpc_data.sent_sequence_number = sent_params.sample_identity().sequence_number(); +} + +} /* namespace rpc */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/writer/rtps/CommonWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp similarity index 82% rename from ddspipe_participants/src_/cpp/writer/rtps/CommonWriter.cpp rename to ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp index e6b7fdc7c..947bc0260 100644 --- a/ddspipe_participants/src_/cpp/writer/rtps/CommonWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp @@ -19,24 +19,25 @@ #include #include -#include + +#include #include #include #include -#include +#include namespace eprosima { namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; -using eprosima::ddsrouter::core::types::operator<<; +using namespace eprosima::ddspipe::core::types; +using eprosima::ddspipe::core::types::operator<<; CommonWriter::CommonWriter( const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool, + const DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater, const fastrtps::rtps::HistoryAttributes& history_attributes, @@ -44,7 +45,7 @@ CommonWriter::CommonWriter( const fastrtps::TopicAttributes& topic_attributes, const fastrtps::WriterQos& writer_qos, const utils::PoolConfiguration& pool_configuration) - : BaseWriter(participant_id, topic, payload_pool) + : BaseWriter(participant_id, payload_pool) , rtps_participant_(rtps_participant) , repeater_(repeater) , history_attributes_(history_attributes) @@ -52,6 +53,7 @@ CommonWriter::CommonWriter( , topic_attributes_(topic_attributes) , writer_qos_(writer_qos) , pool_configuration_(pool_configuration) + , topic_(topic) { // Do nothing } @@ -117,18 +119,18 @@ bool CommonWriter::come_from_this_participant_( // Specific enable/disable do not need to be implemented utils::ReturnCode CommonWriter::write_( - IRoutingData& data) noexcept + core::IRoutingData& data) noexcept { auto rtps_data = dynamic_cast(data); // Take new Change from history fastrtps::rtps::CacheChange_t* new_change; - if (topic_.keyed) + if (topic_.topic_qos.keyed) { new_change = rtps_writer_->new_change( rtps_data.kind, - rtps_data.properties.instanceHandle); + rtps_data.instanceHandle); } else { @@ -143,7 +145,7 @@ utils::ReturnCode CommonWriter::write_( logDebug(DDSROUTER_RTPS_COMMONWRITER, "CommonWriter " << *this << " sending payload " << new_change->serializedPayload << " from " << - rtps_data.properties.source_guid); + rtps_data.source_guid); // Get params to write (if set) eprosima::fastrtps::rtps::WriteParams write_params; @@ -164,7 +166,7 @@ utils::ReturnCode CommonWriter::write_( // Remove change could be done here in non reliable as it is synchronous because change has already been sent // and does not require to be resent under any circumstance. - if (!topic_.topic_qos.get_reference().is_reliable()) + if (!topic_.topic_qos.is_reliable()) { rtps_history_->remove_change(new_change); } @@ -186,20 +188,23 @@ utils::ReturnCode CommonWriter::fill_to_send_data_( { // Add origin to change in case the cache change is RouterCacheChange (only in repeater mode) core::types::RouterCacheChange& change_ref = static_cast(*to_send_change_to_fill); - change_ref.last_writer_guid_prefix = data.properties.source_guid.guidPrefix; + change_ref.last_writer_guid_prefix = data.source_guid.guidPrefix; } // Set keys in case topic has keys - if (topic_.keyed) + if (topic_.topic_qos.keyed) { - to_send_change_to_fill->instanceHandle = data.properties.instanceHandle; + to_send_change_to_fill->instanceHandle = data.instanceHandle; } // Get the Payload without copy only if it has length if (data.payload.length > 0) { eprosima::fastrtps::rtps::IPayloadPool* payload_owner = payload_pool_.get(); - if (!payload_pool_->get_payload(data.payload, payload_owner, (*to_send_change_to_fill))) + if (!payload_pool_->get_payload( + const_cast(data.payload), + payload_owner, + (*to_send_change_to_fill))) { logDevError(DDSROUTER_RTPS_COMMONWRITER, "Error getting Payload."); return utils::ReturnCode::RETCODE_ERROR; @@ -207,27 +212,29 @@ utils::ReturnCode CommonWriter::fill_to_send_data_( } // Set Change kind - to_send_change_to_fill->kind = data.properties.kind; + to_send_change_to_fill->kind = data.kind; // Set source time stamp to be the original one - to_send_params.source_timestamp(data.properties.source_timestamp); + to_send_params.source_timestamp(data.source_timestamp); // RPC support // If writer params has been set specifically, use them in change - if (data.properties.write_params.is_set()) - { - to_send_params.related_sample_identity(data->properties.write_params.get_reference().related_sample_identity()); - } + // TODO move to rpc + // if (data.write_params.is_set()) + // { + // to_send_params.related_sample_identity(data->properties.write_params.get_reference().related_sample_identity()); + // } return utils::ReturnCode::RETCODE_OK; } void CommonWriter::fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& params, - std::unique_ptr& data_to_fill) const noexcept + core::types::RtpsPayloadData& data_to_fill) const noexcept { // Set data output parameters - data_to_fill->sent_sequence_number = params.sample_identity().sequence_number(); + // TODO move to RPC + // data_to_fill->sent_sequence_number = params.sample_identity().sequence_number(); } void CommonWriter::internal_entities_creation_( @@ -304,32 +311,32 @@ void CommonWriter::internal_entities_creation_( " with guid " << rtps_writer_->getGuid()); } -fastrtps::rtps::HistoryAttributes CommonWriter::get_history_attributes_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::rtps::HistoryAttributes CommonWriter::reckon_history_attributes_( + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::HistoryAttributes att; att.memoryPolicy = eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - att.maximumReservedCaches = topic.topic_qos.get_reference().history_depth; + att.maximumReservedCaches = topic.topic_qos.history_depth; return att; } -fastrtps::rtps::WriterAttributes CommonWriter::get_writer_attributes_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::rtps::WriterAttributes CommonWriter::reckon_writer_attributes_( + const core::types::DdsTopic& topic) noexcept { fastrtps::rtps::WriterAttributes att; // Set Durability - att.endpoint.durabilityKind = topic.topic_qos.get_reference().durability_qos; + att.endpoint.durabilityKind = topic.topic_qos.durability_qos; // Set Reliability - att.endpoint.reliabilityKind = topic.topic_qos.get_reference().reliability_qos; + att.endpoint.reliabilityKind = topic.topic_qos.reliability_qos; // Set if topic has key - if (topic.keyed) + if (topic.topic_qos.keyed) { att.endpoint.topicKind = eprosima::fastrtps::rtps::WITH_KEY; } @@ -347,13 +354,13 @@ fastrtps::rtps::WriterAttributes CommonWriter::get_writer_attributes_( return att; } -fastrtps::TopicAttributes CommonWriter::get_topic_attributes_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::TopicAttributes CommonWriter::reckon_topic_attributes_( + const core::types::DdsTopic& topic) noexcept { fastrtps::TopicAttributes att; // Set if topic has key - if (topic.keyed) + if (topic.topic_qos.keyed) { att.topicKind = eprosima::fastrtps::rtps::WITH_KEY; } @@ -363,26 +370,26 @@ fastrtps::TopicAttributes CommonWriter::get_topic_attributes_( } // Set Topic attributes - att.topicName = topic.topic_name; + att.topicName = topic.m_topic_name; att.topicDataType = topic.type_name; return att; } -fastrtps::WriterQos CommonWriter::get_writer_qos_( - const core::types::DistributedTopic& topic) noexcept +fastrtps::WriterQos CommonWriter::reckon_writer_qos_( + const core::types::DdsTopic& topic) noexcept { fastrtps::WriterQos qos; // Set Durability qos.m_durability.kind = - (topic.topic_qos.get_reference().is_transient_local() + (topic.topic_qos.is_transient_local() ? eprosima::fastdds::dds::DurabilityQosPolicyKind_t::TRANSIENT_LOCAL_DURABILITY_QOS : eprosima::fastdds::dds::DurabilityQosPolicyKind_t::VOLATILE_DURABILITY_QOS); // Set Reliability qos.m_reliability.kind = - (topic.topic_qos.get_reference().is_reliable() + (topic.topic_qos.is_reliable() ? eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS : eprosima::fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS); @@ -394,11 +401,11 @@ fastrtps::WriterQos CommonWriter::get_writer_qos_( return qos; } -utils::PoolConfiguration CommonWriter::cache_change_pool_configuration_( - const core::types::DistributedTopic& topic) noexcept +utils::PoolConfiguration CommonWriter::reckon_cache_change_pool_configuration_( + const core::types::DdsTopic& topic) noexcept { utils::PoolConfiguration config; - config.maximum_size = topic.topic_qos.get_reference().history_depth; + config.maximum_size = topic.topic_qos.history_depth; config.initial_size = 20; config.batch_size = 20; diff --git a/ddspipe_participants/src_/cpp/writer/rtps/MultiWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp similarity index 88% rename from ddspipe_participants/src_/cpp/writer/rtps/MultiWriter.cpp rename to ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp index f895ee71f..f91bf6da9 100644 --- a/ddspipe_participants/src_/cpp/writer/rtps/MultiWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp @@ -19,29 +19,32 @@ #include #include -#include + +#include + #include #include #include #include -#include +#include namespace eprosima { namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; MultiWriter::MultiWriter( const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool, + const DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater /* = false */) - : BaseWriter(participant_id, topic, payload_pool) + : BaseWriter(participant_id, payload_pool) , rtps_participant_(rtps_participant) , repeater_(repeater) + , topic_(topic) { // Do nothing } @@ -136,15 +139,17 @@ QoSSpecificWriter* MultiWriter::create_writer_nts_( // Specific enable/disable do not need to be implemented utils::ReturnCode MultiWriter::write_( - IRoutingData& data) noexcept + core::IRoutingData& data) noexcept { + auto rtps_data = dynamic_cast(data); + logDebug( DDSROUTER_MULTIWRITER, "Writing in Partitions Writer " << *this << " a data with qos " << data->properties << " from " << data->properties.source_guid); // Take Writer - auto this_qos_writer = get_writer_or_create_(data->properties.writer_qos); + auto this_qos_writer = get_writer_or_create_(rtps_data.writer_qos); logDebug( DDSROUTER_MULTIWRITER, diff --git a/ddspipe_participants/src_/cpp/writer/rtps/QoSSpecificWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp similarity index 61% rename from ddspipe_participants/src_/cpp/writer/rtps/QoSSpecificWriter.cpp rename to ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp index a5ae8c6a8..7bfd9431b 100644 --- a/ddspipe_participants/src_/cpp/writer/rtps/QoSSpecificWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp @@ -20,44 +20,44 @@ namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; QoSSpecificWriter::QoSSpecificWriter( const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool, + const DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, - const core::types::SpecificEndpointQoS& specific_qos, + const SpecificEndpointQoS& specific_qos, const bool repeater /* = false */) : CommonWriter( - participant_id, topic, payload_pool, rtps_participant, repeater, - get_history_attributes_(topic), - get_writer_attributes_(topic), - get_topic_attributes_(topic), - get_writer_qos_(specific_qos, topic), // this modifies the qos of the Common Writer - cache_change_pool_configuration_(topic)) + participant_id, topic, payload_pool, rtps_participant, repeater + , reckon_history_attributes_(topic) + , reckon_writer_attributes_(topic) + , reckon_topic_attributes_(topic) + , reckon_writer_qos_(specific_qos, topic) // this modifies the qos of the Common Writer + , reckon_cache_change_pool_configuration_(topic)) , specific_qos_(specific_qos) { } -fastrtps::WriterQos QoSSpecificWriter::get_writer_qos_( - const core::types::SpecificEndpointQoS& specific_qos, - const core::types::DistributedTopic& topic) noexcept +fastrtps::WriterQos QoSSpecificWriter::reckon_writer_qos_( + const SpecificEndpointQoS& specific_qos, + const DdsTopic& topic) noexcept { // Get QoS from parent class - fastrtps::WriterQos qos = CommonWriter::get_writer_qos_(topic); + fastrtps::WriterQos qos = CommonWriter::reckon_writer_qos_(topic); // Set Partitions - if (topic.topic_qos.get_reference().has_partitions()) + if (topic.topic_qos.has_partitions()) { qos.m_partition = specific_qos.partitions; } // Set Ownership - if (topic.topic_qos.get_reference().has_ownership()) + if (topic.topic_qos.has_ownership()) { // Set ownership - qos.m_ownership.kind = topic.topic_qos.get_reference().ownership_qos; + qos.m_ownership.kind = topic.topic_qos.ownership_qos; qos.m_ownershipStrength = specific_qos.ownership_strength; } diff --git a/ddspipe_participants/src_/cpp/writer/rtps/SimpleWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp similarity index 73% rename from ddspipe_participants/src_/cpp/writer/rtps/SimpleWriter.cpp rename to ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp index d18fbe989..e49539536 100644 --- a/ddspipe_participants/src_/cpp/writer/rtps/SimpleWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp @@ -19,32 +19,31 @@ #include #include -#include + +#include #include #include #include -#include +#include namespace eprosima { namespace ddspipe { namespace participants { namespace rtps { -using namespace eprosima::ddsrouter::core::types; - SimpleWriter::SimpleWriter( - const ParticipantId& participant_id, - const DistributedTopic& topic, - std::shared_ptr payload_pool, + const core::types::ParticipantId& participant_id, + const core::types::DdsTopic& topic, + const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant, const bool repeater /* = false */) : CommonWriter( participant_id, topic, payload_pool, rtps_participant, repeater, - get_history_attributes_(topic), - get_writer_attributes_(topic), - get_topic_attributes_(topic), - get_writer_qos_(topic), - cache_change_pool_configuration_(topic)) + reckon_history_attributes_(topic), + reckon_writer_attributes_(topic), + reckon_topic_attributes_(topic), + reckon_writer_qos_(topic), + reckon_cache_change_pool_configuration_(topic)) { } diff --git a/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.cpp b/ddspipe_participants/src/cpp/writer/rtps/filter/RepeaterDataFilter.cpp similarity index 100% rename from ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.cpp rename to ddspipe_participants/src/cpp/writer/rtps/filter/RepeaterDataFilter.cpp diff --git a/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.cpp b/ddspipe_participants/src/cpp/writer/rtps/filter/SelfDataFilter.cpp similarity index 100% rename from ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.cpp rename to ddspipe_participants/src/cpp/writer/rtps/filter/SelfDataFilter.cpp diff --git a/ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp b/ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp deleted file mode 100644 index 730385fae..000000000 --- a/ddspipe_participants/src_/cpp/participant/auxiliar/BaseParticipant.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2021 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. - - -#include - - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -BaseParticipant::BaseParticipant( - const std::shared_ptr & participant_configuration, - const std::shared_ptr & payload_pool, - const std::shared_ptr & discovery_database) - : configuration_(participant_configuration) - , payload_pool_(payload_pool) - , discovery_database_(discovery_database) -{ - logDebug(DDSROUTER_TRACK, "Creating Participant " << *this << "."); -} - -BaseParticipant::~BaseParticipant() -{ - logDebug(DDSROUTER_TRACK, "Destroying Participant " << *this << "."); - - if (!writers_.empty()) - { - logDevError(DDSROUTER_BASEPARTICIPANT, "Deleting Participant " << id() << " with still alive writers"); - writers_.clear(); - } - - if (!readers_.empty()) - { - logDevError(DDSROUTER_BASEPARTICIPANT, "Deleting Participant " << id() << " with still alive readers"); - readers_.clear(); - } - - logDebug(DDSROUTER_TRACK, "Participant " << *this << " destroyed."); -} - -core::types::ParticipantId BaseParticipant::id() const noexcept -{ - std::lock_guard lock(mutex_); - - return configuration_->id; -} - -bool BaseParticipant::is_repeater() const noexcept -{ - std::lock_guard lock(mutex_); - - return configuration_->is_repeater; -} - -bool BaseParticipant::is_rtps_kind() const noexcept -{ - return false; -} - -std::shared_ptr BaseParticipant::create_writer( - core::types::DistributedTopic topic) -{ - std::lock_guard lock(mutex_); - - if (writers_.find(topic) != writers_.end()) - { - throw utils::InitializationException( - utils::Formatter() << - "Error creating writer for topic " << topic << " in participant " << id() << - ". Writer already exists."); - } - - std::shared_ptr new_writer = create_writer_(topic); - - logInfo(DDSROUTER_BASEPARTICIPANT, "Created writer in Participant " << id() << " for topic " << topic); - - // Insertion must not fail as we already know it does not exist - writers_.emplace(topic, new_writer); - - return new_writer; -} - -std::shared_ptr BaseParticipant::create_reader( - core::types::DistributedTopic topic) -{ - std::lock_guard lock(mutex_); - - if (readers_.find(topic) != readers_.end()) - { - throw utils::InitializationException( - utils::Formatter() << - "Error creating Reader for topic " << topic << " in participant " << id() << - ". Reader already exists."); - } - - std::shared_ptr new_reader = create_reader_(topic); - - logInfo(DDSROUTER_BASEPARTICIPANT, "Created reader in Participant " << id() << " for topic " << topic); - - // Insertion must not fail as we already know it does not exist - readers_.emplace(topic, new_reader); - - return new_reader; -} - -void BaseParticipant::delete_writer( - std::shared_ptr writer) noexcept -{ - std::lock_guard lock(mutex_); - - for (auto it_writer : writers_) - { - if (it_writer.second == writer) - { - writers_.erase(it_writer.first); - delete_writer_(writer); - return; - } - } -} - -void BaseParticipant::delete_reader( - std::shared_ptr reader) noexcept -{ - std::lock_guard lock(mutex_); - - for (auto it_reader : readers_) - { - if (it_reader.second == reader) - { - readers_.erase(it_reader.first); - delete_reader_(reader); - return; - } - } -} - -void BaseParticipant::delete_writer_( - std::shared_ptr ) noexcept -{ - // It does nothing. Override this method so it has functionality. -} - -void BaseParticipant::delete_reader_( - std::shared_ptr ) noexcept -{ - // It does nothing. Override this method so it has functionality. -} - -core::types::ParticipantId BaseParticipant::id_nts_() const noexcept -{ - return configuration_->id; -} - -std::ostream& operator <<( - std::ostream& os, - const BaseParticipant& participant) -{ - os << "{" << participant.id() << "}"; - return os; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp b/ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp deleted file mode 100644 index 8713623bf..000000000 --- a/ddspipe_participants/src_/cpp/participant/auxiliar/MockParticipant.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// 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. - - - - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -using namespace eprosima::ddsrouter::core::types; - -MockParticipant::MockParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database) - : BaseParticipant(participant_configuration, payload_pool, discovery_database) -{ - // Do nothing -} - -std::shared_ptr MockParticipant::create_writer_( - DistributedTopic topic) -{ - return std::make_shared(id(), topic, payload_pool_); -} - -std::shared_ptr MockParticipant::create_reader_( - DistributedTopic topic) -{ - return std::make_shared(id(), topic, payload_pool_); -} - -std::shared_ptr MockParticipant::get_reader( - core::types::DistributedTopic topic) -{ - std::lock_guard _(mutex_); - auto it = readers_.find(topic); - if (it != readers_.end()) - { - return it.second; - } - return std::shared_ptr(); -} - -std::vector MockParticipant::get_writer( - core::types::DistributedTopic topic) -{ - std::lock_guard _(mutex_); - auto it = writers_.find(topic); - if (it != writers_.end()) - { - return it.second; - } - return std::shared_ptr(); -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp b/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp deleted file mode 100644 index 4e7d66d07..000000000 --- a/ddspipe_participants/src_/cpp/writer/rtps/filter/RepeaterDataFilter.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * This filter allows to not send messages from this Writer to the Readers belonging to the source Participant. - * It is used in "repeater" participants in order to propagate information to external participants - * (participants not belonging to the same DDS-Router instance), - * leaving out the participant from which this information was received. - * - * This uses the RouterCacheChange extra information. - */ -class RepeaterDataFilter : public SelfDataFilter -{ -public: - - /** - * @brief Whether incoming change is relevant for this reader. - * - * @return true if the reader does not belong to Participant that previously sent this message. - * @return false otherwise. - */ - bool is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid - ) const override; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp b/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp deleted file mode 100644 index f4cf2248f..000000000 --- a/ddspipe_participants/src_/cpp/writer/rtps/filter/SelfDataFilter.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -///// -// Forward declarations -namespace eprosima { -namespace fastrtps { -namespace rtps { - -struct CacheChange_t; -struct GUID_t; - -} /* namespace rtps */ -} /* namespace fastrtps */ -} /* namespace eprosima */ - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * This filter allows to not send messages from this Writer to the Readers in the same Participant. - */ -class SelfDataFilter : public fastdds::rtps::IReaderDataFilter -{ -public: - - /** - * @brief Whether incoming change is relevant for this reader. - * - * @return true if the reader does not belong to same Participant. - * @return false otherwise. - */ - bool is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid - ) const override; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ From 0871df84012ee517360698108bd5c2176c62ca35 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 10:00:32 +0100 Subject: [PATCH 08/38] Implement ddspipe_core tests Signed-off-by: jparisu --- .../dynamic/DiscoveryDatabase.hpp | 6 +- .../ddspipe_core/interface/IRoutingData.hpp | 2 +- .../include/ddspipe_core/interface/ITopic.hpp | 4 +- .../testing/entities/blank_entities.hpp | 104 +++ .../testing/entities/mock_entities.hpp | 90 +++ .../{test_utils.hpp => random_values.hpp} | 30 +- .../types/data/RpcPayloadData.hpp | 2 +- .../types/data/RtpsPayloadData.hpp | 2 +- .../ddspipe_core/types/topic/Topic.hpp | 4 +- .../topic/TopicInternalTypeDiscriminator.hpp | 9 +- .../ddspipe_core/types/topic/dds/DdsTopic.hpp | 3 +- .../types/topic/filter/IFilterTopic.hpp | 2 + .../ddspipe_core/types/topic/rpc/RpcTopic.hpp | 2 +- ddspipe_core/src/cpp/core/DdsPipe.cpp | 2 +- .../src/cpp/dynamic/DiscoveryDatabase.cpp | 10 +- .../cpp/testing/entities/blank_entities.cpp | 25 + .../src/cpp/testing/random_values.cpp | 144 ++++ ddspipe_core/src/cpp/testing/test_utils.cpp | 70 -- .../src/cpp/types/data/RtpsPayloadData.cpp | 34 + ddspipe_core/src/cpp/types/dds/Endpoint.cpp | 6 + ddspipe_core/src/cpp/types/topic/Topic.cpp | 4 +- .../src/cpp/types/topic/dds/DdsTopic.cpp | 11 + .../topic/rpc/{RPCTopic.cpp => RpcTopic.cpp} | 8 + ddspipe_core/test/CMakeLists.txt | 5 +- ddspipe_core/test/blackbox/CMakeLists.txt | 17 - .../blackbox/ddsrouter_core/CMakeLists.txt | 16 - .../ddsrouter_core/dds/CMakeLists.txt | 16 - .../ddsrouter_core/dds/WAN/CMakeLists.txt | 80 -- .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 705 ------------------ .../blackbox/ddsrouter_core/dds/WAN/README.md | 7 - .../ddsrouter_core/dds/WAN/TEST_XFAIL.list | 8 - .../ddsrouter_core/dds/WAN/TEST_XTSAN.list | 5 - .../ddsrouter_core/dds/local/CMakeLists.txt | 84 --- .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 329 -------- .../dds/local/DDSTestLocalDisposeKey.cpp | 201 ----- .../ddsrouter_core/dds/local/README.md | 6 - .../dds/types/HelloWorld/HelloWorld.cxx | 207 ----- .../dds/types/HelloWorld/HelloWorld.h | 216 ------ .../dds/types/HelloWorld/HelloWorld.idl | 5 - .../HelloWorld/HelloWorldPubSubTypes.cxx | 133 ---- .../types/HelloWorld/HelloWorldPubSubTypes.h | 64 -- .../types/HelloWorldKeyed/HelloWorldKeyed.cxx | 283 ------- .../types/HelloWorldKeyed/HelloWorldKeyed.h | 249 ------- .../types/HelloWorldKeyed/HelloWorldKeyed.idl | 6 - .../HelloWorldKeyedPubSubTypes.cxx | 170 ----- .../HelloWorldKeyedPubSubTypes.h | 98 --- .../dds/types/test_participants.hpp | 495 ------------ .../ddsrouter_core/resources/tls/ca.crt | 1 - .../resources/tls/ddsrouter.crt | 1 - .../resources/tls/ddsrouter.key | 1 - .../resources/tls/dh_params.pem | 1 - .../ddsrouter_core/trivial/CMakeLists.txt | 37 - .../ddsrouter_core/trivial/TrivialTest.cpp | 170 ----- .../blackbox/implementations/CMakeLists.txt | 41 - .../implementations/ImplementationsTest.cpp | 246 ------ ddspipe_core/test/unittest/CMakeLists.txt | 5 +- .../unittest/_configuration/CMakeLists.txt | 37 - .../test/unittest/_configuration/TODO.md | 5 - .../_configuration/_ConfigurationTest.cpp | 668 ----------------- .../ParticipantsDatabaseTest.cpp | 54 +- .../test/unittest/dynamic/CMakeLists.txt | 1 - .../AllowedTopicListTest.cpp | 54 +- .../dynamic/allowed_topic_list/CMakeLists.txt | 4 +- .../dynamic/discovery_database/CMakeLists.txt | 47 -- .../DiscoveryDatabaseTest.cpp | 250 ------- .../test/unittest/efficiency/CMakeLists.txt | 6 +- .../efficiency/FastPayloadPoolTest.cpp | 6 +- .../efficiency/MapPayloadPoolTest.cpp | 6 +- .../unittest/efficiency/PayloadPoolTest.cpp | 13 +- .../unittest/types/endpoint/CMakeLists.txt | 21 +- .../unittest/types/endpoint/EndpointTest.cpp | 298 +------- .../test/unittest/types/endpoint/GuidTest.cpp | 4 +- .../test/unittest/types/topic/CMakeLists.txt | 36 +- .../unittest/types/topic/DdsTopicTest.cpp | 18 +- .../test/unittest/types/topic/TopicTest.cpp | 68 -- .../topic/WildcardDdsFilterTopicTest.cpp | 39 +- .../test/TestUtils/test_utils.cpp | 273 ------- .../test/TestUtils/test_utils.hpp | 126 ---- .../test/blackbox/CMakeLists.txt | 1 - .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 4 +- .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 4 +- .../dds/local/DDSTestLocalDisposeKey.cpp | 4 +- .../ddsrouter_core/trivial/TrivialTest.cpp | 6 +- .../implementations/ImplementationsTest.cpp | 6 +- .../test/unittest/CMakeLists.txt | 20 - .../unittest/_configuration/CMakeLists.txt | 37 - .../test/unittest/_configuration/TODO.md | 5 - .../_configuration/_ConfigurationTest.cpp | 668 ----------------- .../test/unittest/core/CMakeLists.txt | 15 - .../core/participants_database/CMakeLists.txt | 52 -- .../ParticipantsDatabaseTest.cpp | 255 ------- .../test/unittest/dynamic/CMakeLists.txt | 16 - .../AllowedTopicListTest.cpp | 502 ------------- .../dynamic/allowed_topic_list/CMakeLists.txt | 53 -- .../dynamic/discovery_database/CMakeLists.txt | 47 -- .../DiscoveryDatabaseTest.cpp | 250 ------- .../test/unittest/efficiency/CMakeLists.txt | 122 --- .../efficiency/FastPayloadPoolTest.cpp | 329 -------- .../efficiency/MapPayloadPoolTest.cpp | 374 ---------- .../unittest/efficiency/PayloadPoolTest.cpp | 477 ------------ .../test/unittest/types/CMakeLists.txt | 16 - .../unittest/types/endpoint/CMakeLists.txt | 86 --- .../unittest/types/endpoint/EndpointTest.cpp | 343 --------- .../test/unittest/types/endpoint/GuidTest.cpp | 92 --- .../test/unittest/types/topic/CMakeLists.txt | 109 --- .../unittest/types/topic/DdsTopicTest.cpp | 90 --- .../test/unittest/types/topic/TopicTest.cpp | 68 -- .../topic/WildcardDdsFilterTopicTest.cpp | 224 ------ ddspipe_yaml/test/TestUtils/test_utils.cpp | 2 +- ddspipe_yaml/test/TestUtils/test_utils.hpp | 2 +- .../YamlReaderConfigurationTest.cpp | 4 +- ...EntityAddressTest_get_address_defaults.ipp | 4 +- ...etEntityAddressTest_get_address_domain.ipp | 4 +- ...amlGetEntityAddressTest_get_address_ip.ipp | 4 +- .../YamlGetEntityAddressTest_get_ip.ipp | 4 +- ...amlGetEntityAddressTest_get_ip_version.ipp | 4 +- .../YamlGetEntityAddressTest_get_port.ipp | 4 +- ...tityAddressTest_get_transport_protocol.ipp | 4 +- ...YamlGetEntityAddressTest_ip_and_domain.ipp | 4 +- ...coveryServerAddressTest_get_ds_address.ipp | 4 +- ...verAddressTest_get_ds_address_negative.ipp | 4 +- .../YamlGetConfigurationDDSRouterTest.cpp | 4 +- .../guid/YamlGetEntityGuidPrefixTest.cpp | 4 +- .../entities/topic/YamlGetEntityTopicTest.cpp | 4 +- ...lGetCommonParticipantConfigurationTest.cpp | 4 +- ...itialPeersParticipantConfigurationTest.cpp | 4 +- ...lGetSimpleParticipantConfigurationTest.cpp | 4 +- ...t_get_participant_connection_addresses.ipp | 4 +- ...nfigurationTest_get_participant_domain.ipp | 4 +- ...st_get_participant_listening_addresses.ipp | 4 +- ...figurationTest_get_participant_minimum.ipp | 4 +- ...igurationTest_get_participant_negative.ipp | 4 +- ...tConfigurationTest_get_participant_tls.ipp | 4 +- .../yaml_reader/YamlReaderScalarTest.cpp | 4 +- .../test/unittest/yaml_tags/YamlTagsTest.cpp | 2 +- 135 files changed, 666 insertions(+), 10227 deletions(-) create mode 100644 ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp create mode 100644 ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp rename ddspipe_core/include/ddspipe_core/testing/{test_utils.hpp => random_values.hpp} (74%) create mode 100644 ddspipe_core/src/cpp/testing/entities/blank_entities.cpp create mode 100644 ddspipe_core/src/cpp/testing/random_values.cpp delete mode 100644 ddspipe_core/src/cpp/testing/test_utils.cpp create mode 100644 ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp rename ddspipe_core/src/cpp/types/topic/rpc/{RPCTopic.cpp => RpcTopic.cpp} (96%) delete mode 100644 ddspipe_core/test/blackbox/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/README.md delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/local/README.md delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp delete mode 120000 ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt delete mode 120000 ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt delete mode 120000 ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key delete mode 120000 ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp delete mode 100644 ddspipe_core/test/blackbox/implementations/CMakeLists.txt delete mode 100644 ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp delete mode 100644 ddspipe_core/test/unittest/_configuration/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/_configuration/TODO.md delete mode 100644 ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp delete mode 100644 ddspipe_core/test/unittest/dynamic/discovery_database/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp delete mode 100644 ddspipe_core/test/unittest/types/topic/TopicTest.cpp delete mode 100644 ddspipe_participants/test/TestUtils/test_utils.cpp delete mode 100644 ddspipe_participants/test/TestUtils/test_utils.hpp delete mode 100644 ddspipe_participants/test/unittest/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/_configuration/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/_configuration/TODO.md delete mode 100644 ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp delete mode 100644 ddspipe_participants/test/unittest/core/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp delete mode 100644 ddspipe_participants/test/unittest/dynamic/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp delete mode 100644 ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp delete mode 100644 ddspipe_participants/test/unittest/efficiency/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp delete mode 100644 ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp delete mode 100644 ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp delete mode 100644 ddspipe_participants/test/unittest/types/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp delete mode 100644 ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp delete mode 100644 ddspipe_participants/test/unittest/types/topic/CMakeLists.txt delete mode 100644 ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp delete mode 100644 ddspipe_participants/test/unittest/types/topic/TopicTest.cpp delete mode 100644 ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp diff --git a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp index 31fe6db18..e202c141d 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp @@ -105,7 +105,7 @@ class DiscoveryDatabase * @param [in] new_endpoint: new endpoint to store */ void add_endpoint( - const types::Endpoint& new_endpoint) noexcept; + const types::Endpoint& new_endpoint); /** * @brief Add update operation to the database @@ -116,7 +116,7 @@ class DiscoveryDatabase * @param [in] endpoint_to_update: endpoint to update */ void update_endpoint( - const types::Endpoint& endpoint_to_update) noexcept; + const types::Endpoint& endpoint_to_update); /** * @brief Add erase operation to the database @@ -127,7 +127,7 @@ class DiscoveryDatabase * @param [in] endpoint_to_erase endpoint that will be erased */ void erase_endpoint( - const types::Endpoint& endpoint_to_erase) noexcept; + const types::Endpoint& endpoint_to_erase); /** * @brief Get the endpoint object with this guid diff --git a/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp index a0ade635d..ed6b72e9a 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp @@ -39,7 +39,7 @@ class IRoutingData * This refers to an internal used identifier that declares which kind of data type is going to be * transmitted in this Itopic inside the core. */ - const types::TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept; + virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept = 0; }; } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp index cacf12f34..ce823fa05 100644 --- a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp @@ -45,7 +45,7 @@ class ITopic const ITopic& other) const noexcept = 0; //! ITopic name - virtual const std::string& topic_name() const noexcept = 0; + virtual std::string topic_name() const noexcept = 0; //! ITopic unique name in processs virtual std::string topic_unique_name() const noexcept = 0; @@ -54,7 +54,7 @@ class ITopic * This refers to an internal used identifier that declares which kind of data type is going to be * transmitted in this Itopic inside the core. */ - virtual const types::TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept = 0; + virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept = 0; }; } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp b/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp new file mode 100644 index 000000000..7636cc7f7 --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp @@ -0,0 +1,104 @@ +// 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. + +#pragma once + +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace testing { + +struct BlankParticipant : public IParticipant +{ + types::ParticipantId id() const noexcept override; + + bool is_rtps_kind() const noexcept override; + + bool is_repeater() const noexcept override; + + std::shared_ptr create_writer( + const ITopic& topic) override; + + std::shared_ptr create_reader( + const ITopic& topic) override; +}; + +struct BlankReader : public IReader +{ + void enable() noexcept override; + + void disable() noexcept override; + + void set_on_data_available_callback( + std::function on_data_available_lambda) noexcept override; + + void unset_on_data_available_callback() noexcept override; + + utils::ReturnCode take( + std::unique_ptr& data) noexcept override; + + core::types::Guid guid() const override; + + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override; + + uint64_t get_unread_count() const override; + + types::DdsTopic topic() const override; + + types::ParticipantId participant_id() const override; +}; + +struct BlankWriter : public IWriter +{ + void enable() noexcept override; + + void disable() noexcept override; + + utils::ReturnCode write( + IRoutingData& data) noexcept override; +}; + +struct BlankTopic : public ITopic +{ + + bool operator < ( + const ITopic& other) const noexcept override; + + bool operator == ( + const ITopic& other) const noexcept override; + + std::string topic_name() const noexcept override; + + std::string topic_unique_name() const noexcept override; + + types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; +}; + +struct BlankRoutingData : public IRoutingData +{ + types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; +}; + +constexpr types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "test_type::blank::v0"; + +} /* namespace testing */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp b/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp new file mode 100644 index 000000000..1e5f39808 --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp @@ -0,0 +1,90 @@ +// 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. + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace testing { + +struct MockParticipant : public BlankParticipant +{ + types::ParticipantId id() const noexcept override; + + std::shared_ptr create_writer( + const ITopic& topic) override; + + std::shared_ptr create_reader( + const ITopic& topic) override; +}; + +struct MockReader : public BlankReader +{ + void enable() noexcept override; + + void disable() noexcept override; + + void set_on_data_available_callback( + std::function on_data_available_lambda) noexcept override; + + void unset_on_data_available_callback() noexcept override; + + utils::ReturnCode take( + std::unique_ptr& data) noexcept override; + + core::types::Guid guid() const override; + + fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override; + + uint64_t get_unread_count() const override; + + types::DdsTopic topic() const override; + + types::ParticipantId participant_id() const override; +}; + +struct MockReader : public BlankWriter +{ + void enable() noexcept override; + + void disable() noexcept override; + + utils::ReturnCode write( + IRoutingData& data) noexcept override; +}; + +struct MockTopic : public BlankTopic +{ + types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; +}; + +struct MockRoutingData : public BlankRoutingData +{ + types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; +}; + +constexpr types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "testing_type::mock::v0"; + +} /* namespace testing */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp b/ddspipe_core/include/ddspipe_core/testing/random_values.hpp similarity index 74% rename from ddspipe_core/include/ddspipe_core/testing/test_utils.hpp rename to ddspipe_core/include/ddspipe_core/testing/random_values.hpp index fe2788820..a1a47554b 100644 --- a/ddspipe_core/include/ddspipe_core/testing/test_utils.hpp +++ b/ddspipe_core/include/ddspipe_core/testing/random_values.hpp @@ -17,25 +17,19 @@ #include #include +#include #include #include #include +#include namespace eprosima { namespace ddspipe { namespace core { -namespace test { - -/** - * @brief Create a \c Guid with some of its bits determined by the input - * - * @param [in] seed : differentiating value for guid creation - * @return generated Guid - * @todo Make truly random using \c seed as such - * - */ +namespace testing { + types::Guid random_guid( - unsigned int seed = 1); + unsigned int seed = 0); types::DomainId random_domain( unsigned int seed = 0); @@ -47,7 +41,19 @@ types::GuidPrefix random_guid_prefix( types::ParticipantId random_participant_id( unsigned int seed = 0); -} /* namespace test */ +types::DdsTopic random_dds_topic( + unsigned int seed = 0); + +types::EndpointKind random_endpoint_kind( + unsigned int seed = 0); + +types::Endpoint random_endpoint( + unsigned int seed = 0); + +types::TopicQoS random_topic_qos( + unsigned int seed = 0); + +} /* namespace testing */ } /* namespace core */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp index 56f1e97ad..f01166b3b 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp @@ -53,7 +53,7 @@ struct RpcPayloadData : public RtpsPayloadData /** * @brief Id to identify the internal topic type id that uses \c RpcPayloadData . */ -const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; +constexpr TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; } /* namespace types */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp index f91c61756..10b263588 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp @@ -79,7 +79,7 @@ struct RtpsPayloadData : public core::IRoutingData /** * @brief Id to identify the internal topic type id that uses \c RtpsPayloadData . */ -const core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; +constexpr core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; } /* namespace types */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp index 60595ebbf..e8ddf5904 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp @@ -60,9 +60,9 @@ struct Topic : public ITopic , public IConfiguration ///////////////////////// //! ITopic name - virtual const std::string& topic_name() const noexcept override; + virtual std::string topic_name() const noexcept override; - virtual const TopicInternalTypeDiscriminator& internal_type_discriminator() const noexcept override; + virtual TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; diff --git a/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp index 1d4418b4c..6ecc37b66 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp @@ -22,9 +22,14 @@ namespace ddspipe { namespace core { namespace types { -using TopicInternalTypeDiscriminator = std::string; +/** + * @brief Reference the type that is used internally in the DDS Pipe to hold the data transmitted. + * + * @warning as this is a const char* it is strongly suggested to only use constexpr or static values. + */ +using TopicInternalTypeDiscriminator = const char*; -const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_NONE = ""; +constexpr TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_NONE = ""; } /* namespace types */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp index cc8cae190..f8bdce918 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp @@ -39,7 +39,7 @@ struct DdsTopic : public DistributedTopic ///////////////////////// //! Default constructor - DDSPIPE_CORE_DllAPI DdsTopic() = default; + DDSPIPE_CORE_DllAPI DdsTopic(); ///////////////////////// // METHODS @@ -74,7 +74,6 @@ struct DdsTopic : public DistributedTopic * This Topic class is a proxy, not an actual Topic Entity of DDS, so it should not have QoS. */ types::TopicQoS topic_qos{}; - }; /** diff --git a/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp index cb942a855..fac307f6b 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp @@ -31,6 +31,8 @@ namespace types { struct DDSPIPE_CORE_DllAPI IFilterTopic { + virtual ~IFilterTopic() = default; + ///////////////////////// // OPERATORS ///////////////////////// diff --git a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp index 091b60df5..fd07bb0b3 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp @@ -40,7 +40,7 @@ class RpcTopic RpcTopic( const DdsTopic& topic) noexcept; - RpcTopic(const RpcTopic& topic) noexcept; + RpcTopic(const RpcTopic& other) noexcept; //! Service name getter const std::string& service_name() const; diff --git a/ddspipe_core/src/cpp/core/DdsPipe.cpp b/ddspipe_core/src/cpp/core/DdsPipe.cpp index 3f6f228df..a460ced42 100644 --- a/ddspipe_core/src/cpp/core/DdsPipe.cpp +++ b/ddspipe_core/src/cpp/core/DdsPipe.cpp @@ -150,8 +150,8 @@ utils::ReturnCode DdsPipe::reload_allowed_topics( } else { - return utils::ReturnCode::RETCODE_NOT_ENABLED; allowed_topics_ = allowed_topics; + return utils::ReturnCode::RETCODE_NOT_ENABLED; } } diff --git a/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp index f2ad83f11..69e5b6f60 100644 --- a/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp +++ b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp @@ -91,6 +91,10 @@ bool DiscoveryDatabase::topic_exists( { return true; } + else + { + logError(DEBUG, "Topics not equal " << topic << " != " << entity.second.topic); + } } return false; } @@ -210,19 +214,19 @@ utils::ReturnCode DiscoveryDatabase::erase_endpoint_( } void DiscoveryDatabase::add_endpoint( - const Endpoint& new_endpoint) noexcept + const Endpoint& new_endpoint) { push_item_to_queue_(std::make_tuple(DatabaseOperation::add, new_endpoint)); } void DiscoveryDatabase::update_endpoint( - const Endpoint& endpoint_to_update) noexcept + const Endpoint& endpoint_to_update) { push_item_to_queue_(std::make_tuple(DatabaseOperation::update, endpoint_to_update)); } void DiscoveryDatabase::erase_endpoint( - const Endpoint& endpoint_to_erase) noexcept + const Endpoint& endpoint_to_erase) { push_item_to_queue_(std::make_tuple(DatabaseOperation::erase, endpoint_to_erase)); } diff --git a/ddspipe_core/src/cpp/testing/entities/blank_entities.cpp b/ddspipe_core/src/cpp/testing/entities/blank_entities.cpp new file mode 100644 index 000000000..626569a5d --- /dev/null +++ b/ddspipe_core/src/cpp/testing/entities/blank_entities.cpp @@ -0,0 +1,25 @@ +// 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. + +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace testing { + +} /* namespace testing */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/testing/random_values.cpp b/ddspipe_core/src/cpp/testing/random_values.cpp new file mode 100644 index 000000000..13d8d35e2 --- /dev/null +++ b/ddspipe_core/src/cpp/testing/random_values.cpp @@ -0,0 +1,144 @@ +// Copyright 2021 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. + +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace testing { + +using namespace eprosima::ddspipe::core::types; + +Guid random_guid( + unsigned int seed /* = 1 */) +{ + Guid guid; + guid.entityId.value[3] = static_cast(seed); + guid.guidPrefix.value[0] = 0x01; + guid.guidPrefix.value[1] = 0x0f; + return guid; +} + +DomainId random_domain( + unsigned int seed /* = 0 */) +{ + return DomainId(static_cast(seed)); +} + +GuidPrefix random_guid_prefix( + unsigned int seed /* = 0 */, + bool ros /* = false */) +{ + if (ros) + { + return GuidPrefix(true, seed); + } + else + { + return GuidPrefix(static_cast(seed)); + } +} + +ParticipantId random_participant_id( + unsigned int seed /* = 0 */) +{ + std::vector names = { + "participant", + "PART_1", + "echo", + "Barro_p", + }; + + return ParticipantId(names[seed % names.size()] + std::to_string(seed)); +} + +DdsTopic random_dds_topic( + unsigned int seed /* = 0 */) +{ + DdsTopic topic; + topic.m_topic_name = "TopicName_" + std::to_string(seed); + topic.type_name = "TopicType_" + std::to_string(seed); + topic.topic_qos = random_topic_qos(seed); + return topic; +} + +EndpointKind random_endpoint_kind( + unsigned int seed /* = 0 */) +{ + if (seed % 2) + { + return EndpointKind::reader; + } + else + { + return EndpointKind::writer; + } +} + +Endpoint random_endpoint( + unsigned int seed /* = 0 */) +{ + Endpoint endpoint; + endpoint.active = (seed % 2); + endpoint.guid = random_guid(seed); + endpoint.discoverer_participant_id = random_participant_id(seed); + endpoint.kind = random_endpoint_kind(seed); + endpoint.topic = random_dds_topic(seed); + return endpoint; +} + +TopicQoS random_topic_qos( + unsigned int seed /* = 0 */) +{ + TopicQoS qos; + + if (seed % 2) + { + qos.reliability_qos = ReliabilityKind::BEST_EFFORT; + } + else + { + qos.reliability_qos = ReliabilityKind::RELIABLE; + } + + switch ((seed / 2) % 4) + { + case 0: + qos.durability_qos = DurabilityKind::VOLATILE; + break; + + case 1: + qos.durability_qos = DurabilityKind::TRANSIENT_LOCAL; + break; + + case 2: + qos.durability_qos = DurabilityKind::TRANSIENT; + break; + + case 3: + qos.durability_qos = DurabilityKind::PERSISTENT; + break; + + default: + break; + } + + return qos; +} + +} /* namespace testing */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/testing/test_utils.cpp b/ddspipe_core/src/cpp/testing/test_utils.cpp deleted file mode 100644 index 1dba5993f..000000000 --- a/ddspipe_core/src/cpp/testing/test_utils.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -using namespace eprosima::ddspipe::core::types; - -Guid random_guid( - uint16_t seed /* = 1 */) -{ - Guid guid; - guid.entityId.value[3] = static_cast(seed); - guid.guidPrefix.value[0] = 0x01; - guid.guidPrefix.value[1] = 0x0f; - return guid; -} - -DomainId random_domain( - uint16_t seed /* = 0 */) -{ - return DomainId(static_cast(seed)); -} - -GuidPrefix random_guid_prefix( - uint16_t seed /* = 0 */, - bool ros /* = false */) -{ - if (ros) - { - return GuidPrefix(true, seed); - } - else - { - return GuidPrefix(static_cast(seed)); - } -} - -ParticipantId random_participant_id( - uint16_t seed /* = 0 */) -{ - std::vector names = { - "participant", - "PART_1", - "echo", - "Barro_p", - }; - - return ParticipantId(names[seed % names.size()] + std::to_string(seed)); -} - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp b/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp new file mode 100644 index 000000000..236b6ea81 --- /dev/null +++ b/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp @@ -0,0 +1,34 @@ +// 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. + +#include + +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { + +RtpsPayloadData::~RtpsPayloadData() +{ + // If payload owner exists and payload has size, release it correctly in pool + if (payload_owner && payload.length > 0) + { + payload_owner->release_payload(payload); + } +} + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/Endpoint.cpp b/ddspipe_core/src/cpp/types/dds/Endpoint.cpp index e3fbbfe14..747b33aec 100644 --- a/ddspipe_core/src/cpp/types/dds/Endpoint.cpp +++ b/ddspipe_core/src/cpp/types/dds/Endpoint.cpp @@ -40,6 +40,12 @@ bool Endpoint::is_server_endpoint() const noexcept return (is_reader() && RpcTopic::is_request_topic(topic)) || (is_writer() && RpcTopic::is_reply_topic(topic)); } +bool Endpoint::operator ==( + const Endpoint& other) const noexcept +{ + return guid == other.guid; +} + std::ostream& operator <<( std::ostream& os, const Endpoint& endpoint) diff --git a/ddspipe_core/src/cpp/types/topic/Topic.cpp b/ddspipe_core/src/cpp/types/topic/Topic.cpp index 465d9caae..8537afa3e 100644 --- a/ddspipe_core/src/cpp/types/topic/Topic.cpp +++ b/ddspipe_core/src/cpp/types/topic/Topic.cpp @@ -43,12 +43,12 @@ bool Topic::operator<(const ITopic& other) const noexcept // METHODS ///////////////////////// -const std::string& Topic::topic_name() const noexcept +std::string Topic::topic_name() const noexcept { return m_topic_name; } -const TopicInternalTypeDiscriminator& Topic::internal_type_discriminator() const noexcept +TopicInternalTypeDiscriminator Topic::internal_type_discriminator() const noexcept { return m_internal_type_discriminator; } diff --git a/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp b/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp index cc3f4e41d..aa8bbc084 100644 --- a/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp @@ -21,12 +21,18 @@ #include #include +#include namespace eprosima { namespace ddspipe { namespace core { namespace types { +DdsTopic::DdsTopic() +{ + m_internal_type_discriminator = INTERNAL_TOPIC_TYPE_RTPS; +} + std::ostream& operator <<( std::ostream& os, const DdsTopic& t) @@ -64,6 +70,11 @@ bool DdsTopic::is_valid_dds_topic( const std::string& type_name, utils::Formatter& error_msg) noexcept { + if (topic_name.empty()) + { + error_msg << "Topic name could not be empty. "; + return false; + } if (type_name.empty()) { diff --git a/ddspipe_core/src/cpp/types/topic/rpc/RPCTopic.cpp b/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp similarity index 96% rename from ddspipe_core/src/cpp/types/topic/rpc/RPCTopic.cpp rename to ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp index 056790019..ab5c3b404 100644 --- a/ddspipe_core/src/cpp/types/topic/rpc/RPCTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp @@ -85,6 +85,14 @@ RpcTopic::RpcTopic( reply_topic_.topic_qos = topic.topic_qos; } +RpcTopic::RpcTopic(const RpcTopic& other) noexcept + : service_name_(other.service_name_) + , request_topic_(other.request_topic_) + , reply_topic_(other.reply_topic_) +{ + +} + const std::string& RpcTopic::service_name() const { return service_name_; diff --git a/ddspipe_core/test/CMakeLists.txt b/ddspipe_core/test/CMakeLists.txt index 7ff304e5d..eefcda457 100644 --- a/ddspipe_core/test/CMakeLists.txt +++ b/ddspipe_core/test/CMakeLists.txt @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Include utils for this specific test -include_directories("TestUtils") - # Add subdirectory with tests add_subdirectory(unittest) -add_subdirectory(blackbox) +# add_subdirectory(blackbox) diff --git a/ddspipe_core/test/blackbox/CMakeLists.txt b/ddspipe_core/test/blackbox/CMakeLists.txt deleted file mode 100644 index 992066726..000000000 --- a/ddspipe_core/test/blackbox/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2021 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. - - -add_subdirectory(ddsrouter_core) -add_subdirectory(implementations) diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/CMakeLists.txt deleted file mode 100644 index 4757aaf44..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(trivial) -add_subdirectory(dds) diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt deleted file mode 100644 index e0dd990dd..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(local) -add_subdirectory(WAN) diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt deleted file mode 100644 index 3c70390c2..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2021 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. - -################ -# DDS Test WAN # -################ - -set(TEST_NAME - DDSTestWAN) - -set(TEST_SOURCES - DDSTestWAN.cpp - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) - -set(TEST_LIST - end_to_end_discovery_server_WAN_communication_UDPv4 - end_to_end_initial_peers_WAN_communication_UDPv4 - - end_to_end_discovery_server_WAN_communication_UDPv6 - end_to_end_initial_peers_WAN_communication_UDPv6 - - end_to_end_discovery_server_WAN_communication_TCPv4 - end_to_end_initial_peers_WAN_communication_TCPv4 - - end_to_end_discovery_server_WAN_communication_TCPv6 - end_to_end_initial_peers_WAN_communication_TCPv6 - - end_to_end_discovery_server_WAN_communication_TLSv4 - end_to_end_initial_peers_WAN_communication_TLSv4 - - end_to_end_discovery_server_WAN_communication_TLSv6 - end_to_end_initial_peers_WAN_communication_TLSv6 - - end_to_end_discovery_server_WAN_communication_high_throughput - end_to_end_initial_peers_WAN_communication_high_throughput - ) - - -set(TEST_NEEDED_SOURCES - # TLS security files - ../../resources/tls/ca.crt - ../../resources/tls/ddsrouter.crt - ../../resources/tls/ddsrouter.key - ../../resources/tls/dh_params.pem - ) - -set(TEST_EXTRA_HEADERS - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - "${TEST_EXTRA_HEADERS}") - -# Set flaky tests as xfail -add_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XFAIL.list) - -# Set as TSAN errors due to Fast DDS -# TODO: use a cmake_utils macro -file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/TEST_XTSAN.list TEST_LIST) -foreach(XTSAN_TEST ${TEST_LIST}) - set_property(TEST ${XTSAN_TEST} PROPERTY LABELS xtsan) -endforeach() diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp deleted file mode 100644 index 5ed89d797..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ /dev/null @@ -1,705 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -enum class WanParticipantKind -{ - discovery_server, - initial_peers -}; - -enum class WanKind -{ - server, - client, - server_and_client -}; - -bool is_client( - WanKind wan_kind) -{ - return wan_kind == WanKind::client || wan_kind == WanKind::server_and_client; -} - -bool is_server( - WanKind wan_kind) -{ - return wan_kind == WanKind::server || wan_kind == WanKind::server_and_client; -} - -constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; -constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; -constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes - -types::security::TlsConfiguration tls_configuration( - WanKind wan_kind) -{ - // TODO: test that using server with only Server required files works - // It fails when connecting to other server - if (is_server(wan_kind)) - { - types::security::TlsConfiguration tls; - tls.certificate_authority_file = "../../resources/tls/ca.crt"; - tls.private_key_file = "../../resources/tls/ddsrouter.key"; - tls.certificate_chain_file = "../../resources/tls/ddsrouter.crt"; - tls.dh_params_file = "../../resources/tls/dh_params.pem"; - return tls; - } - else - { - types::security::TlsConfiguration tls; - tls.certificate_authority_file = "../../resources/tls/ca.crt"; - return tls; - } -} - -std::shared_ptr discovery_server_participant_configuration( - bool this_server_id_is_1, - WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool tls = false) -{ - std::set listening_addresses; - std::set connection_addresses; - - if (is_client(wan_kind)) - { - connection_addresses.insert( - types::DiscoveryServerConnectionAddress( - types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), - { - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 0u : 1u), - 11666 + (this_server_id_is_1 ? 0u : 1u), - ip_version, - transport_protocol) - } - ) - ); - } - - if (is_server(wan_kind)) - { - listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 1u : 0u), - 11666 + (this_server_id_is_1 ? 1u : 0u), - ip_version, - transport_protocol) - ); - } - - if (tls) - { - return std::make_shared( - types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_discovery_server, - false, - types::DomainId(0u), - types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), - listening_addresses, - connection_addresses, - tls_configuration(wan_kind)); - - } - else - { - return std::make_shared( - types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_discovery_server, - false, - types::DomainId(0u), - types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), - listening_addresses, - connection_addresses, - types::security::TlsConfiguration()); - } -} - -std::shared_ptr initial_peers_participant_configuration( - bool this_server_id_is_1, - WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool tls = false) -{ - std::set listening_addresses; - std::set connection_addresses; - types::DomainId domain(60u); - - if (is_client(wan_kind)) - { - connection_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 0u : 1u), - 11666 + (this_server_id_is_1 ? 0u : 1u), - ip_version, - transport_protocol) - ); - } - - if (is_server(wan_kind)) - { - listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 1u : 0u), - 11666 + (this_server_id_is_1 ? 1u : 0u), - ip_version, - transport_protocol) - ); - } - - if (tls) - { - return std::make_shared( - types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_initial_peers, - false, - domain, - listening_addresses, - connection_addresses, - tls_configuration(wan_kind)); - - } - else - { - return std::make_shared( - types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_initial_peers, - false, - domain, - listening_addresses, - connection_addresses, - types::security::TlsConfiguration()); - } -} - -std::shared_ptr wan_participant_configuration( - WanParticipantKind wan_participant_kind, - bool this_server_id_is_1, - WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool tls = false) -{ - if (wan_participant_kind == WanParticipantKind::discovery_server) - { - return discovery_server_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, - tls); - } - else // WanParticipantKind::initial_peers - { - return initial_peers_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, - tls); - } -} - -/** - * @brief Create a simple configuration for a DDS Router - * - * Create a configuration with 1 topic - * Create 1 simple participants with domains \c domain - * Create 1 custom participant by the configuration in \c participant_configuration - * - * @return configuration::DdsRouterConfiguration - */ -configuration::DdsRouterConfiguration router_configuration( - std::shared_ptr participant_configuration, - types::DomainIdType domain) -{ - // One topic - auto new_topic = std::make_shared(); - new_topic->topic_name = TOPIC_NAME; - new_topic->type_name = std::string("HelloWorld"); - - std::set> allowlist({new_topic}); - - std::set> blocklist; // empty - - std::set> builtin_topics; // empty - - // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 - std::set> participants_configurations( - { - // custom - participant_configuration, - - // simple - std::make_shared( - types::ParticipantId("simple_participant_" + std::to_string(domain)), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(domain) - ), - } - ); - - return configuration::DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - configuration::SpecsConfiguration()); -} - -/** - * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. - * This is accomplished by connecting two WAN Participants belonging to different DDS Router instances. These router - * instances communicate with the DDS Participants through Simple Participants deployed at those domains. - */ -void test_WAN_communication( - configuration::DdsRouterConfiguration ddsrouter_server_configuration, - configuration::DdsRouterConfiguration ddsrouter_client_configuration, - uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, - uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, - uint32_t msg_size = DEFAULT_MESSAGE_SIZE) -{ - // Check there are no warnings/errors - // TODO: Uncomment when having no listening addresses is no longer considered an error by the middleware - // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved - // test::LogChecker test_log_handler(Log::Kind::Error); - - uint32_t samples_sent = 0; - std::atomic samples_received(0); - - // Create a message with size specified by repeating the same string - HelloWorld msg; - std::string msg_str; - - // Add this string as many times as the msg size requires - for (uint32_t i = 0; i < msg_size; i++) - { - msg_str += "Testing DdsRouter Blackbox Local Communication ..."; - } - msg.message(msg_str); - - // Create DDS Publisher in domain 0 - TestPublisher publisher; - ASSERT_TRUE(publisher.init(0)); - - // Create DDS Subscriber in domain 1 - TestSubscriber subscriber; - ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - - // Create DdsRouter entity whose WAN Participant is configured as server - DdsRouter server_router(ddsrouter_server_configuration); - server_router.start(); - - // Create DdsRouter entity whose WAN Participant is configured as client - DdsRouter client_router(ddsrouter_client_configuration); - client_router.start(); - - // Start publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - publisher.publish(msg); - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - client_router.stop(); - server_router.stop(); -} - -/** - * Test communication between WAN participants by running \c test_WAN_communication for different configurations. - * Different combinations of server/client configurations are tested. - * - * CASES: - * server <-> client - * server <-> server-client - * server-client <-> server-client (only when basic_only is deactivate) - */ -void test_WAN_communication_all( - WanParticipantKind wan_participant_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool basic_only = false, - bool tls = false) -{ - // Test architecture server <-> client - test::test_WAN_communication( - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - true, // is server 1 - WanKind::server, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 0 // domain - ), - - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - false, // is server 1 - WanKind::client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 1 // domain - ) - ); - - // Test architecture server <-> server-client - test::test_WAN_communication( - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - true, // is server 1 - WanKind::server, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 0 // domain - ), - - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - false, // is server 1 - WanKind::server_and_client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 1 // domain - ) - ); - - // This test is disabled for TCPv6 and TLSv6, as an underlying middleware issue resulting in no matching for this - // scenario exists. - // TODO: Test this as well for TCPv6 and TLSv6 cases when issue is fixed - if (!basic_only) - { - // Test architecture server-client <-> server-client - test::test_WAN_communication( - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - true, // is server 1 - WanKind::server_and_client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 0 // domain - ), - - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - false, // is server 1 - WanKind::server_and_client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 1 // domain - ) - ); - } -} - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through UDPv4. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::udp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through UDPv4. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::udp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through UDPv6. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::udp, - types::IpVersion::v6); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through UDPv6. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::udp, - types::IpVersion::v6); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TCPv4. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TCPv4. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TCPv6. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TCPv6. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TLSv4. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v4, - false, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TLSv4. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v4, - false, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TLSv6. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TLSv6. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true, - true); -} - -/** - * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through UDPv4. - * - * PARAMETERS: - * - Frequency: 1ms - * - Sample size: 50K - * -> Throughput: 50MBps - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_high_throughput) -{ - test::test_WAN_communication( - test::router_configuration( - test::discovery_server_participant_configuration( - true, // is server 1 - test::WanKind::server, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 0 // domain - ), - - test::router_configuration( - test::discovery_server_participant_configuration( - false, // is server 1 - test::WanKind::client, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 1 // domain - ), - - 500, - 1, - 1000); // 50K message size -} - -/** - * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through UDPv4. - * - * PARAMETERS: - * - Frequency: 1ms - * - Sample size: 50K - * -> Throughput: 50MBps - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_high_throughput) -{ - test::test_WAN_communication( - test::router_configuration( - test::initial_peers_participant_configuration( - true, // is server 1 - test::WanKind::server, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 0 // domain - ), - - test::router_configuration( - test::initial_peers_participant_configuration( - false, // is server 1 - test::WanKind::client, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 1 // domain - ), - - 500, - 1, - 1000); // 50K message size -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/README.md b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/README.md deleted file mode 100644 index 943086ca9..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# DDS Test WAN - -Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. -This is accomplished by connecting two (`DiscoveryServer` / `InitialPeers`) WAN Participants belonging to different DDS Router instances. -These router instances communicate with the DDS Participants through Simple Participants deployed at those domains. -Note that, although data transmission is accomplished by connecting two WAN Participants, the resulting communication -is still local (i.e. WAN communication is not tested here). diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list deleted file mode 100644 index 7aded2b7b..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list +++ /dev/null @@ -1,8 +0,0 @@ -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv6 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv6 diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list b/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list deleted file mode 100644 index 78996681f..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list +++ /dev/null @@ -1,5 +0,0 @@ -DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt deleted file mode 100644 index f98f1006c..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2021 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. - -################## -# DDS Test local # -################## - -set(TEST_NAME - DDSTestLocal) - -set(TEST_SOURCES - DDSTestLocal.cpp - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) - -set(TEST_LIST - end_to_end_local_communication - end_to_end_local_communication_keyed - end_to_end_local_communication_disable_dynamic_discovery - end_to_end_local_communication_disable_dynamic_discovery_keyed - end_to_end_local_communication_high_frequency - end_to_end_local_communication_high_size - end_to_end_local_communication_high_throughput - end_to_end_local_communication_transient_local - end_to_end_local_communication_transient_local_disable_dynamic_discovery) - -set(TEST_NEEDED_SOURCES - ) - -set(TEST_EXTRA_HEADERS - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - "${TEST_EXTRA_HEADERS}") - -############################## -# DDS Test local Dispose Key # -############################## - -set(TEST_NAME - DDSTestLocalDisposeKey) - -set(TEST_SOURCES - DDSTestLocalDisposeKey.cpp - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) - -set(TEST_LIST - end_to_end_local_communication_key_dispose) - -set(TEST_NEEDED_SOURCES - ) - -set(TEST_EXTRA_HEADERS - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - "${TEST_EXTRA_HEADERS}") diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp deleted file mode 100644 index c6240e112..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; -constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; -constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes - -/** - * @brief Create a simple configuration for a DDS Router - * - * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME - * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. - * Create 2 simple participants with domains 0 and 1 - * - * @return configuration::DdsRouterConfiguration - */ -configuration::DdsRouterConfiguration dds_test_simple_configuration( - bool disable_dynamic_discovery = false, - bool transient_local_readers = false) -{ - // Always filter the test topics by topic name - std::set> allowlist; // empty - allowlist.insert(std::make_shared(TOPIC_NAME)); - - std::set> blocklist; // empty - - std::set> builtin_topics; // empty - - if (disable_dynamic_discovery) - { - types::TopicQoS qos; - if (transient_local_readers) - { - qos.reliability_qos = types::ReliabilityKind::RELIABLE; - qos.durability_qos = types::DurabilityKind::TRANSIENT_LOCAL; - } - else - { - qos.reliability_qos = types::ReliabilityKind::BEST_EFFORT; - qos.durability_qos = types::DurabilityKind::VOLATILE; - } - - builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); - builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); - } - - // Two simple participants - std::set> participants_configurations( - { - std::make_shared( - types::ParticipantId("participant_0"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(0u) - ), - std::make_shared( - types::ParticipantId("participant_1"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(1u) - ) - } - ); - - return configuration::DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - configuration::SpecsConfiguration()); -} - -/** - * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. - * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. - * - * The transient_local option changes the test behavior to verify that the communication is transient_local and all old data is sent - * to Late Joiners. - */ -template -void test_local_communication( - configuration::DdsRouterConfiguration ddsrouter_configuration, - uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, - uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, - uint32_t msg_size = DEFAULT_MESSAGE_SIZE, - bool transient_local = false) -{ - - // Check there are no warnings/errors - // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved - // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - uint32_t samples_sent = 0; - std::atomic samples_received(0); - - // Create a message with size specified by repeating the same string - MsgStruct msg; - std::string msg_str; - - // Add this string as many times as the msg size requires - for (uint32_t i = 0; i < msg_size; i++) - { - msg_str += "Testing DdsRouter Blackbox Local Communication ..."; - } - msg.message(msg_str); - - // Create DDS Publisher in domain 0 - TestPublisher publisher(msg.isKeyDefined()); - ASSERT_TRUE(publisher.init(0)); - - // Create DDS Subscriber in domain 1 - TestSubscriber subscriber(msg.isKeyDefined(), transient_local); - ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - - // Create DdsRouter entity - // The DDS Router does not start here in order to test a transient_local communication - DdsRouter router(ddsrouter_configuration); - - if (transient_local) - { - // To check that the communication is transient_local and all previous published samples are sent to late joiner, - // the publisher publish all data at once. - for (samples_sent = 0; samples_sent < samples_to_receive; samples_sent++) - { - msg.index(samples_sent); - ASSERT_TRUE(publisher.publish(msg)); - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - // Once the publisher has already publish all its samples, the DDS Router starts. - router.start(); - - // The subscriber should receive all samples sent by the publisher when the communication was not - // already established. - while (samples_received.load() < samples_to_receive) - { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - } - else - { - // Start DDS Router - router.start(); - - // Start publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - publisher.publish(msg); - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - } - - router.stop(); -} - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - */ -TEST(DDSTestLocal, end_to_end_local_communication) -{ - test::test_local_communication( - test::dds_test_simple_configuration()); -} - -/** - * Test communication in HelloWorldKeyed topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - */ -TEST(DDSTestLocal, end_to_end_local_communication_keyed) -{ - test::test_local_communication( - test::dds_test_simple_configuration()); -} - -/** - * Test communication both in HelloWorld and HelloWorldKeyed topics between two DDS participants created in - * different domains, by using a router with two Simple Participants at each domain. - * In this test allowlist and blocklist are left empty, while only builtin topics are provided. - */ -TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery) -{ - test::test_local_communication( - test::dds_test_simple_configuration(true)); -} - -TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery_keyed) -{ - test::test_local_communication( - test::dds_test_simple_configuration(true)); -} - -/** - * Test high frequency communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - * - * PARAMETERS: - * - Frequency: max - */ -TEST(DDSTestLocal, end_to_end_local_communication_high_frequency) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - 1000, // wait for 1000 samples received - 0); // send it without waiting from one sample to the other -} - -/** - * Test high message size communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - * - * PARAMETERS: - * - Sample size: 500K - */ -TEST(DDSTestLocal, end_to_end_local_communication_high_size) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - test::DEFAULT_SAMPLES_TO_RECEIVE, - test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, - 10000); // 500K message size -} - -/** - * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - * - * PARAMETERS: - * - Frequency: 1ms - * - Sample size: 50K - * -> Throughput: 50MBps - */ -TEST(DDSTestLocal, end_to_end_local_communication_high_throughput) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - 500, - 1, - 1000); // 50K message size -} - -/** - * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - */ -TEST(DDSTestLocal, end_to_end_local_communication_transient_local) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - test::DEFAULT_SAMPLES_TO_RECEIVE, - test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, - test::DEFAULT_MESSAGE_SIZE, - true); -} - -/** - * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain and using builtin-topics - */ -TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynamic_discovery) -{ - test::test_local_communication( - test::dds_test_simple_configuration(true, true), - test::DEFAULT_SAMPLES_TO_RECEIVE, - test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, - test::DEFAULT_MESSAGE_SIZE, - true); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp deleted file mode 100644 index bf785388e..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; -constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; -constexpr const uint32_t DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION = 500; -constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes - -/** - * @brief Create a simple configuration for a DDS Router - * - * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME - * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. - * Create 2 simple participants with domains 0 and 1 - * - * @return configuration::DdsRouterConfiguration - */ -configuration::DdsRouterConfiguration dds_test_simple_configuration() -{ - // Always filter the test topics by topic name - std::set> allowlist; // only this topic - allowlist.insert(std::make_shared(TOPIC_NAME)); - - std::set> blocklist; // empty - - std::set> builtin_topics; // empty - - // Two simple participants - std::set> participants_configurations( - { - std::make_shared( - types::ParticipantId("participant_0"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(0u) - ), - std::make_shared( - types::ParticipantId("participant_1"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(1u) - ) - } - ); - - // TODO: this could be removed to use default number of threads - auto specs = configuration::SpecsConfiguration(); - specs.number_of_threads = 2; - - return configuration::DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - specs); -} - -/** - * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. - * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. - * - * The reliable option changes the test behavior to verify that the communication is reliable and all old data is sent - * to Late Joiners. - */ -void test_local_communication_key_dispose( - configuration::DdsRouterConfiguration ddsrouter_configuration, - uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, - uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, - uint32_t msg_size = DEFAULT_MESSAGE_SIZE) -{ - // Check there are no warnings/errors - // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved - // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - uint32_t samples_sent = 0; - std::atomic samples_received(0); - - // Create a message with size specified by repeating the same string - HelloWorldKeyed msg; - std::string msg_str; - - // Add this string as many times as the msg size requires - for (uint32_t i = 0; i < msg_size; i++) - { - msg_str += "Testing DdsRouter Blackbox Local Communication ..."; - } - msg.message(msg_str); - msg.id(666); - - // Create DDS Publisher in domain 0 - TestPublisher publisher(msg.isKeyDefined()); - ASSERT_TRUE(publisher.init(0)); - - // Create DDS Subscriber in domain 1 - TestSubscriber subscriber(msg.isKeyDefined()); - ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - - // Create DdsRouter entity - // The DDS Router does not start here in order to test a reliable communication - DdsRouter router(ddsrouter_configuration); - - // Start DDS Router - router.start(); - - // Start publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - ASSERT_TRUE(publisher.publish(msg)) << samples_sent; - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - // All samples received, now dispose key from publisher and check that subscriber has receive it - ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); - std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); - samples_received.store(0); - - // Keep publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - ASSERT_TRUE(publisher.publish(msg)) << samples_sent; - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - // All samples received, now dispose key from publisher and check that subscriber has receive it - ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); - std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); - - ASSERT_EQ(2u, subscriber.n_disposed()); - - router.stop(); -} - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/** - * Test that dispose values from the publisher are correctly received by the subscriber from the router. - */ -TEST(DDSTestLocalDisposeKey, end_to_end_local_communication_key_dispose) -{ - test::test_local_communication_key_dispose( - test::dds_test_simple_configuration()); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/README.md b/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/README.md deleted file mode 100644 index a94c61e34..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/local/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# DDS Test Local - -Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. -This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. -First, router initialization is tested, and then communication between the DDS Participants is tested both for topics -*HelloWorld* and *HelloWorldKeyed*. diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx deleted file mode 100644 index b850b4501..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2016 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 HelloWorld.cpp - * This source file contains the definition of the described types in the IDL file. - * - * This file was generated by the tool gen. - */ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { char dummy; } -#endif - -#include "HelloWorld.h" -#include - -#include -using namespace eprosima::fastcdr::exception; - -#include - -HelloWorld::HelloWorld() -{ - // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@1622f1b - m_index = 0; - // m_message com.eprosima.idl.parser.typecode.StringTypeCode@70e8f8e - m_message =""; - -} - -HelloWorld::~HelloWorld() -{ - - -} - -HelloWorld::HelloWorld(const HelloWorld &x) -{ - m_index = x.m_index; - m_message = x.m_message; -} - -HelloWorld::HelloWorld(HelloWorld &&x) -{ - m_index = x.m_index; - m_message = std::move(x.m_message); -} - -HelloWorld& HelloWorld::operator=(const HelloWorld &x) -{ - - m_index = x.m_index; - m_message = x.m_message; - - return *this; -} - -HelloWorld& HelloWorld::operator=(HelloWorld &&x) -{ - - m_index = x.m_index; - m_message = std::move(x.m_message); - - return *this; -} - -size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment) -{ - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; - - - return current_alignment - initial_alignment; -} - -size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; - - - return current_alignment - initial_alignment; -} - -void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const -{ - - scdr << m_index; - scdr << m_message; -} - -void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr) -{ - - dcdr >> m_index; - dcdr >> m_message; -} - -/*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ -void HelloWorld::index(uint32_t _index) -{ -m_index = _index; -} - -/*! - * @brief This function returns the value of member index - * @return Value of member index - */ -uint32_t HelloWorld::index() const -{ - return m_index; -} - -/*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ -uint32_t& HelloWorld::index() -{ - return m_index; -} - -/*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ -void HelloWorld::message(const std::string &_message) -{ -m_message = _message; -} - -/*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ -void HelloWorld::message(std::string &&_message) -{ -m_message = std::move(_message); -} - -/*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ -const std::string& HelloWorld::message() const -{ - return m_message; -} - -/*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ -std::string& HelloWorld::message() -{ - return m_message; -} - -size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment) -{ - size_t current_align = current_alignment; - - - - - - return current_align; -} - -bool HelloWorld::isKeyDefined() -{ - return false; -} - -void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const -{ - (void) scdr; - - -} diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h deleted file mode 100644 index c445fff76..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright 2016 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 HelloWorld.h - * This header file contains the declaration of the described types in the IDL file. - * - * This file was generated by the tool gen. - */#pragma once - -// TODO Poner en el contexto. - -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // if defined(EPROSIMA_USER_DLL_EXPORT) -#else -#define eProsima_user_DllExport -#endif // if defined(_WIN32) - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined(HelloWorld_SOURCE) -#define HelloWorld_DllAPI __declspec( dllexport ) -#else -#define HelloWorld_DllAPI __declspec( dllimport ) -#endif // HelloWorld_SOURCE -#else -#define HelloWorld_DllAPI -#endif // if defined(EPROSIMA_USER_DLL_EXPORT) -#else -#define HelloWorld_DllAPI -#endif // _WIN32 - -namespace eprosima { -namespace fastcdr { -class Cdr; -} // namespace fastcdr -} // namespace eprosima - - -/*! - * @brief This class represents the structure HelloWorld defined by the user in the IDL file. - * @ingroup HELLOWORLD - */ -class HelloWorld -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport HelloWorld(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~HelloWorld(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld( - const HelloWorld& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld( - HelloWorld&& x); - - /*! - * @brief Copy assignment. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld& operator =( - const HelloWorld& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld& operator =( - HelloWorld&& x); - - /*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ - eProsima_user_DllExport void index( - uint32_t _index); - - /*! - * @brief This function returns the value of member index - * @return Value of member index - */ - eProsima_user_DllExport uint32_t index() const; - - /*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ - eProsima_user_DllExport uint32_t& index(); - - /*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ - eProsima_user_DllExport void message( - const std::string& _message); - - /*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ - eProsima_user_DllExport void message( - std::string&& _message); - - /*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ - eProsima_user_DllExport const std::string& message() const; - - /*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ - eProsima_user_DllExport std::string& message(); - - /*! - * @brief This function returns the maximum serialized size of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function returns the serialized size of a data depending on the buffer alignment. - * @param data Data which is calculated its serialized size. - * @param current_alignment Buffer alignment. - * @return Serialized size. - */ - eProsima_user_DllExport static size_t getCdrSerializedSize( - const HelloWorld& data, - size_t current_alignment = 0); - - - /*! - * @brief This function serializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serialize( - eprosima::fastcdr::Cdr& cdr) const; - - /*! - * @brief This function deserializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void deserialize( - eprosima::fastcdr::Cdr& cdr); - - - - /*! - * @brief This function returns the maximum serialized size of the Key of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function tells you if the Key has been defined for this type - */ - eProsima_user_DllExport static bool isKeyDefined(); - - /*! - * @brief This function serializes the key members of an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serializeKey( - eprosima::fastcdr::Cdr& cdr) const; - -private: - - uint32_t m_index; - std::string m_message; -}; - -#endif // _HELLOWORLD_H_ diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl deleted file mode 100644 index 0fd2c355a..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl +++ /dev/null @@ -1,5 +0,0 @@ -struct HelloWorld -{ - unsigned long index; - string message; -}; diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx deleted file mode 100644 index a2a27e7bc..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2016 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 HelloWorldPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ - - -#include -#include - -#include "HelloWorldPubSubTypes.h" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; - -HelloWorldPubSubType::HelloWorldPubSubType() -{ - setName("HelloWorld"); - m_typeSize = static_cast(HelloWorld::getMaxCdrSerializedSize()) + 4 /*encapsulation*/; - m_isGetKeyDefined = HelloWorld::isKeyDefined(); - size_t keyLength = HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -HelloWorldPubSubType::~HelloWorldPubSubType() -{ - if(m_keyBuffer!=nullptr) - free(m_keyBuffer); -} - -bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) -{ - HelloWorld *p_type = static_cast(data); - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - // Serialize encapsulation - ser.serialize_encapsulation(); - - try - { - p_type->serialize(ser); // Serialize the object: - } - catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - payload->length = static_cast(ser.getSerializedDataLength()); //Get the serialized length - return true; -} - -bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) -{ - HelloWorld* p_type = static_cast(data); //Convert DATA to pointer of your type - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data. - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - try - { - p_type->deserialize(deser); //Deserialize the object: - } - catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloWorldPubSubType::getSerializedSizeProvider(void* data) -{ - return [data]() -> uint32_t - { - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + 4 /*encapsulation*/; - }; -} - -void* HelloWorldPubSubType::createData() -{ - return reinterpret_cast(new HelloWorld()); -} - -void HelloWorldPubSubType::deleteData(void* data) -{ - delete(reinterpret_cast(data)); -} - -bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5) -{ - if(!m_isGetKeyDefined) - return false; - HelloWorld* p_type = static_cast(data); - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer),HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data. - p_type->serializeKey(ser); - if(force_md5 || HelloWorld::getKeyMaxCdrSerializedSize()>16) { - m_md5.init(); - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); - m_md5.finalize(); - for(uint8_t i = 0;i<16;++i) { - handle->value[i] = m_md5.digest[i]; - } - } - else { - for(uint8_t i = 0;i<16;++i) { - handle->value[i] = m_keyBuffer[i]; - } - } - return true; -} - diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h deleted file mode 100644 index 44f12a5b5..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 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 HelloWorldPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ -#pragma once - -#include -#include - -#include "HelloWorld.h" - -#if !defined(GEN_API_VER) || (GEN_API_VER != 1) -#error Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // if !defined(GEN_API_VER) || (GEN_API_VER != 1) - -/*! - * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. - * @ingroup HELLOWORLD - */ -class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorld type; - - eProsima_user_DllExport HelloWorldPubSubType(); - - eProsima_user_DllExport virtual ~HelloWorldPubSubType(); - eProsima_user_DllExport virtual bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; - eProsima_user_DllExport virtual bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - eProsima_user_DllExport virtual std::function getSerializedSizeProvider( - void* data) override; - eProsima_user_DllExport virtual bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - eProsima_user_DllExport virtual void* createData() override; - eProsima_user_DllExport virtual void deleteData( - void* data) override; - MD5 m_md5; - unsigned char* m_keyBuffer; -}; - -#endif // _HELLOWORLD_PUBSUBTYPES_H_ diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx deleted file mode 100644 index 43e4eb3b9..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyed.cpp - * This source file contains the definition of the described types in the IDL file. - * - * This file was generated by the tool gen. - */ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { -char dummy; -} // namespace -#endif // _WIN32 - -#include "HelloWorldKeyed.h" -#include - -#include -using namespace eprosima::fastcdr::exception; - -#include - -HelloWorldKeyed::HelloWorldKeyed() -{ - // m_id com.eprosima.idl.parser.typecode.PrimitiveTypeCode@77a57272 - m_id = 0; - // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@7181ae3f - m_index = 0; - // m_message com.eprosima.idl.parser.typecode.StringTypeCode@46238e3f - m_message =""; - -} - -HelloWorldKeyed::~HelloWorldKeyed() -{ - - - -} - -HelloWorldKeyed::HelloWorldKeyed( - const HelloWorldKeyed& x) -{ - m_id = x.m_id; - m_index = x.m_index; - m_message = x.m_message; -} - -HelloWorldKeyed::HelloWorldKeyed( - HelloWorldKeyed&& x) -{ - m_id = x.m_id; - m_index = x.m_index; - m_message = std::move(x.m_message); -} - -HelloWorldKeyed& HelloWorldKeyed::operator =( - const HelloWorldKeyed& x) -{ - - m_id = x.m_id; - m_index = x.m_index; - m_message = x.m_message; - - return *this; -} - -HelloWorldKeyed& HelloWorldKeyed::operator =( - HelloWorldKeyed&& x) -{ - - m_id = x.m_id; - m_index = x.m_index; - m_message = std::move(x.m_message); - - return *this; -} - -bool HelloWorldKeyed::operator ==( - const HelloWorldKeyed& x) const -{ - - return (m_id == x.m_id && m_index == x.m_index && m_message == x.m_message); -} - -bool HelloWorldKeyed::operator !=( - const HelloWorldKeyed& x) const -{ - return !(*this == x); -} - -size_t HelloWorldKeyed::getMaxCdrSerializedSize( - size_t current_alignment) -{ - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; - - - return current_alignment - initial_alignment; -} - -size_t HelloWorldKeyed::getCdrSerializedSize( - const HelloWorldKeyed& data, - size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; - - - return current_alignment - initial_alignment; -} - -void HelloWorldKeyed::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - - scdr << m_id; - scdr << m_index; - scdr << m_message; - -} - -void HelloWorldKeyed::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - - dcdr >> m_id; - dcdr >> m_index; - dcdr >> m_message; -} - -/*! - * @brief This function sets a value in member id - * @param _id New value for member id - */ -void HelloWorldKeyed::id( - int32_t _id) -{ - m_id = _id; -} - -/*! - * @brief This function returns the value of member id - * @return Value of member id - */ -int32_t HelloWorldKeyed::id() const -{ - return m_id; -} - -/*! - * @brief This function returns a reference to member id - * @return Reference to member id - */ -int32_t& HelloWorldKeyed::id() -{ - return m_id; -} - -/*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ -void HelloWorldKeyed::index( - uint32_t _index) -{ - m_index = _index; -} - -/*! - * @brief This function returns the value of member index - * @return Value of member index - */ -uint32_t HelloWorldKeyed::index() const -{ - return m_index; -} - -/*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ -uint32_t& HelloWorldKeyed::index() -{ - return m_index; -} - -/*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ -void HelloWorldKeyed::message( - const std::string& _message) -{ - m_message = _message; -} - -/*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ -void HelloWorldKeyed::message( - std::string&& _message) -{ - m_message = std::move(_message); -} - -/*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ -const std::string& HelloWorldKeyed::message() const -{ - return m_message; -} - -/*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ -std::string& HelloWorldKeyed::message() -{ - return m_message; -} - -size_t HelloWorldKeyed::getKeyMaxCdrSerializedSize( - size_t current_alignment) -{ - size_t current_align = current_alignment; - - - current_align += 4 + eprosima::fastcdr::Cdr::alignment(current_align, 4); - - - - - - return current_align; -} - -bool HelloWorldKeyed::isKeyDefined() -{ - return true; -} - -void HelloWorldKeyed::serializeKey( - eprosima::fastcdr::Cdr& scdr) const -{ - (void) scdr; - scdr << m_id; - -} diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h deleted file mode 100644 index 8b1d2787e..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyed.h - * This header file contains the declaration of the described types in the IDL file. - * - * This file was generated by the tool gen. - */#pragma once - - -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined(HelloWorldKeyed_SOURCE) -#define HelloWorldKeyed_DllAPI __declspec( dllexport ) -#else -#define HelloWorldKeyed_DllAPI __declspec( dllimport ) -#endif // HelloWorldKeyed_SOURCE -#else -#define HelloWorldKeyed_DllAPI -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define HelloWorldKeyed_DllAPI -#endif // _WIN32 - -namespace eprosima { -namespace fastcdr { -class Cdr; -} // namespace fastcdr -} // namespace eprosima - - -/*! - * @brief This class represents the structure HelloWorldKeyed defined by the user in the IDL file. - * @ingroup HELLOWORLDKEYED - */ -class HelloWorldKeyed -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport HelloWorldKeyed(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~HelloWorldKeyed(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed( - const HelloWorldKeyed& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed( - HelloWorldKeyed&& x); - - /*! - * @brief Copy assignment. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed& operator =( - const HelloWorldKeyed& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed& operator =( - HelloWorldKeyed&& x); - - /*! - * @brief Comparison operator. - * @param x HelloWorldKeyed object to compare. - */ - eProsima_user_DllExport bool operator ==( - const HelloWorldKeyed& x) const; - - /*! - * @brief Comparison operator. - * @param x HelloWorldKeyed object to compare. - */ - eProsima_user_DllExport bool operator !=( - const HelloWorldKeyed& x) const; - - /*! - * @brief This function sets a value in member id - * @param _id New value for member id - */ - eProsima_user_DllExport void id( - int32_t _id); - - /*! - * @brief This function returns the value of member id - * @return Value of member id - */ - eProsima_user_DllExport int32_t id() const; - - /*! - * @brief This function returns a reference to member id - * @return Reference to member id - */ - eProsima_user_DllExport int32_t& id(); - - /*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ - eProsima_user_DllExport void index( - uint32_t _index); - - /*! - * @brief This function returns the value of member index - * @return Value of member index - */ - eProsima_user_DllExport uint32_t index() const; - - /*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ - eProsima_user_DllExport uint32_t& index(); - - /*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ - eProsima_user_DllExport void message( - const std::string& _message); - - /*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ - eProsima_user_DllExport void message( - std::string&& _message); - - /*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ - eProsima_user_DllExport const std::string& message() const; - - /*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ - eProsima_user_DllExport std::string& message(); - - /*! - * @brief This function returns the maximum serialized size of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function returns the serialized size of a data depending on the buffer alignment. - * @param data Data which is calculated its serialized size. - * @param current_alignment Buffer alignment. - * @return Serialized size. - */ - eProsima_user_DllExport static size_t getCdrSerializedSize( - const HelloWorldKeyed& data, - size_t current_alignment = 0); - - - /*! - * @brief This function serializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serialize( - eprosima::fastcdr::Cdr& cdr) const; - - /*! - * @brief This function deserializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void deserialize( - eprosima::fastcdr::Cdr& cdr); - - - - /*! - * @brief This function returns the maximum serialized size of the Key of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function tells you if the Key has been defined for this type - */ - eProsima_user_DllExport static bool isKeyDefined(); - - /*! - * @brief This function serializes the key members of an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serializeKey( - eprosima::fastcdr::Cdr& cdr) const; - -private: - - int32_t m_id; - uint32_t m_index; - std::string m_message; -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl deleted file mode 100644 index 6cebe626d..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl +++ /dev/null @@ -1,6 +0,0 @@ -struct HelloWorldKeyed -{ - @Key long id; - unsigned long index; - string message; -}; diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx deleted file mode 100644 index 61eb7c992..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyedPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ - - -#include -#include - -#include "HelloWorldKeyedPubSubTypes.h" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; - -HelloWorldKeyedPubSubType::HelloWorldKeyedPubSubType() -{ - setName("HelloWorldKeyed"); - auto type_size = HelloWorldKeyed::getMaxCdrSerializedSize(); - type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ - m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ - m_isGetKeyDefined = HelloWorldKeyed::isKeyDefined(); - size_t keyLength = HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16 ? - HelloWorldKeyed::getKeyMaxCdrSerializedSize() : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -HelloWorldKeyedPubSubType::~HelloWorldKeyedPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool HelloWorldKeyedPubSubType::serialize( - void* data, - SerializedPayload_t* payload) -{ - HelloWorldKeyed* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - // Serialize encapsulation - ser.serialize_encapsulation(); - - try - { - // Serialize the object. - p_type->serialize(ser); - } - catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - // Get the serialized length - payload->length = static_cast(ser.getSerializedDataLength()); - return true; -} - -bool HelloWorldKeyedPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - //Convert DATA to pointer of your type - HelloWorldKeyed* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - try - { - // Deserialize the object. - p_type->deserialize(deser); - } - catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloWorldKeyedPubSubType::getSerializedSizeProvider( - void* data) -{ - return [data]() -> uint32_t - { - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; - }; -} - -void* HelloWorldKeyedPubSubType::createData() -{ - return reinterpret_cast(new HelloWorldKeyed()); -} - -void HelloWorldKeyedPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool HelloWorldKeyedPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - HelloWorldKeyed* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - HelloWorldKeyed::getKeyMaxCdrSerializedSize()); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); - p_type->serializeKey(ser); - if (force_md5 || HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16) - { - m_md5.init(); - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); - m_md5.finalize(); - for (uint8_t i = 0; i < 16; ++i) - { - handle->value[i] = m_md5.digest[i]; - } - } - else - { - for (uint8_t i = 0; i < 16; ++i) - { - handle->value[i] = m_keyBuffer[i]; - } - } - return true; -} - diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h deleted file mode 100644 index d4a3a204f..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyedPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ -#pragma once - -#include -#include - -#include "HelloWorldKeyed.h" - -#if !defined(GEN_API_VER) || (GEN_API_VER != 1) -#error \ - Generated HelloWorldKeyed is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - -/*! - * @brief This class represents the TopicDataType of the type HelloWorldKeyed defined by the user in the IDL file. - * @ingroup HELLOWORLDKEYED - */ -class HelloWorldKeyedPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorldKeyed type; - - eProsima_user_DllExport HelloWorldKeyedPubSubType(); - - eProsima_user_DllExport virtual ~HelloWorldKeyedPubSubType(); - - eProsima_user_DllExport virtual bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; - - eProsima_user_DllExport virtual bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport virtual std::function getSerializedSizeProvider( - void* data) override; - - eProsima_user_DllExport virtual bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport virtual void* createData() override; - - eProsima_user_DllExport virtual void deleteData( - void* data) override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - (void)memory; - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp deleted file mode 100644 index d9dc0f9c9..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp +++ /dev/null @@ -1,495 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorld/HelloWorldPubSubTypes.h" -#include "HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h" - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -constexpr const char* TOPIC_NAME = "DDS-Router-Test"; - -/** - * Class used to group into a single working unit a Publisher with a DataWriter and a TypeSupport member corresponding - * to the HelloWorld datatype - */ -template -class TestPublisher -{ -public: - - TestPublisher( - bool keyed = false) - : participant_(nullptr) - , publisher_(nullptr) - , topic_(nullptr) - , writer_(nullptr) - , keyed_(keyed) - { - } - - ~TestPublisher() - { - if (participant_ != nullptr) - { - if (publisher_ != nullptr) - { - if (writer_ != nullptr) - { - publisher_->delete_datawriter(writer_); - } - participant_->delete_publisher(publisher_); - } - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); - } - } - - //! Initialize the publisher - bool init( - uint32_t domain) - { - // CREATE THE PARTICIPANT - eprosima::fastdds::dds::DomainParticipantQos pqos; - - pqos.name("Participant_pub"); - participant_ = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); - - if (participant_ == nullptr) - { - return false; - } - - // REGISTER THE TYPE - eprosima::fastdds::dds::TypeSupport type; - if (keyed_) - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); - } - else - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); - } - type.register_type(participant_); - - // CREATE THE PUBLISHER - publisher_ = participant_->create_publisher(eprosima::fastdds::dds::PUBLISHER_QOS_DEFAULT, nullptr); - - if (publisher_ == nullptr) - { - return false; - } - - // CREATE THE TOPIC - std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; - topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - // CREATE THE WRITER - // Set memory management policy so it uses realloc - eprosima::fastdds::dds::DataWriterQos wqos = eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT; - wqos.endpoint().history_memory_policy = - eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - wqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; - writer_ = publisher_->create_datawriter(topic_, wqos, &listener_); - - if (writer_ == nullptr) - { - return false; - } - - return true; - } - - //! Publish a sample - bool publish( - MsgStruct msg) - { - hello_.index(msg.index()); - hello_.message(msg.message()); - return writer_->write(&hello_); - } - - //! Dispose instance - eprosima::fastrtps::types::ReturnCode_t dispose_key( - MsgStruct msg); - - void wait_discovery( - uint32_t n_subscribers = 1) - { - listener_.wait_discovery(n_subscribers); - } - -private: - - MsgStruct hello_; - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Publisher* publisher_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataWriter* writer_; - - bool keyed_; - - class PubListener : public eprosima::fastdds::dds::DataWriterListener - { - public: - - PubListener() - : discovered(0) - { - } - - void wait_discovery( - uint32_t n_subscribers = 1) - { - if (discovered < n_subscribers) - { - std::unique_lock lock(wait_discovery_cv_mtx); - wait_discovery_cv.wait(lock, [this, n_subscribers] - { - return discovered >= n_subscribers; - }); - } - } - - void on_publication_matched( - eprosima::fastdds::dds::DataWriter*, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) - { - if (info.current_count_change == 1) - { - discovered = info.current_count; - wait_discovery_cv.notify_all(); - } - else if (info.current_count_change == -1) - { - discovered = info.current_count; - } - } - - private: - - //! Number of DataReaders discovered - std::atomic discovered; - - //! Protects wait_discovery condition variable - std::mutex wait_discovery_cv_mtx; - - //! Waits to discovery enough DataReaders - std::condition_variable wait_discovery_cv; - } - listener_; -}; - -template <> -bool TestPublisher::publish( - HelloWorldKeyed msg) -{ - hello_.index(msg.index()); - hello_.message(msg.message()); - hello_.id(msg.id()); - return writer_->write(&hello_); -} - -template <> -eprosima::fastrtps::types::ReturnCode_t TestPublisher::dispose_key( - HelloWorldKeyed msg) -{ - hello_.id(msg.id()); - return writer_->dispose(&hello_, eprosima::fastdds::dds::HANDLE_NIL); -} - -/** - * Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member - * corresponding to the HelloWorld datatype - */ -template -class TestSubscriber -{ -public: - - TestSubscriber( - bool keyed = false, - bool reliable = false) - : participant_(nullptr) - , subscriber_(nullptr) - , topic_(nullptr) - , reader_(nullptr) - , keyed_(keyed) - , reliable_ (reliable) - { - } - - ~TestSubscriber() - { - if (participant_ != nullptr) - { - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - if (subscriber_ != nullptr) - { - if (reader_ != nullptr) - { - subscriber_->delete_datareader(reader_); - } - participant_->delete_subscriber(subscriber_); - } - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); - } - } - - //! Initialize the subscriber - bool init( - uint32_t domain, - MsgStruct* msg_should_receive, - std::atomic* samples_received) - { - // INITIALIZE THE LISTENER - listener_.init(msg_should_receive, samples_received); - - // CREATE THE PARTICIPANT - eprosima::fastdds::dds::DomainParticipantQos pqos; - pqos.name("Participant_sub"); - participant_ = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); - - if (participant_ == nullptr) - { - return false; - } - - // REGISTER THE TYPE - eprosima::fastdds::dds::TypeSupport type; - if (keyed_) - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); - } - else - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); - } - type.register_type(participant_); - - // CREATE THE SUBSCRIBER - subscriber_ = participant_->create_subscriber(eprosima::fastdds::dds::SUBSCRIBER_QOS_DEFAULT, nullptr); - - if (subscriber_ == nullptr) - { - return false; - } - - // CREATE THE TOPIC - std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; - topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - // CREATE THE READER - // Set memory management policy so it uses realloc - eprosima::fastdds::dds::DataReaderQos rqos = eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT; - rqos.endpoint().history_memory_policy = - eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - rqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; - if (reliable_) - { - rqos.durability().kind = eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; - rqos.reliability().kind = eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; - } - - reader_ = subscriber_->create_datareader(topic_, rqos, &listener_); - - if (reader_ == nullptr) - { - return false; - } - - return true; - } - - void wait_discovery( - uint32_t n_publishers = 1) - { - listener_.wait_discovery(n_publishers); - } - - uint32_t n_disposed() const - { - return listener_.n_key_disposed; - } - -private: - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Subscriber* subscriber_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataReader* reader_; - - bool keyed_; - - bool reliable_; - - /** - * Class handling dataflow events - */ - class SubListener : public eprosima::fastdds::dds::DataReaderListener - { - public: - - SubListener() - : discovered(0) - { - } - - //! Initialize the listener - void init( - MsgStruct* msg_should_receive_arg, - std::atomic* samples_received_arg) - { - msg_should_receive = msg_should_receive_arg; - samples_received = samples_received_arg; - n_key_disposed = 0; - } - - void wait_discovery( - uint32_t n_publishers = 1) - { - if (discovered < n_publishers) - { - std::unique_lock lock(wait_discovery_cv_mtx); - wait_discovery_cv.wait(lock, [this, n_publishers] - { - return discovered >= n_publishers; - }); - } - } - - //! Callback executed when a new sample is received - void on_data_available( - eprosima::fastdds::dds::DataReader* reader) override - { - eprosima::fastdds::dds::SampleInfo info; - while (reader->take_next_sample(&msg_received, &info) == ReturnCode_t::RETCODE_OK) - { - if (info.instance_state == eprosima::fastdds::dds::ALIVE_INSTANCE_STATE) - { - if (msg_received.message() == msg_should_receive->message()) - { - (*samples_received)++; - } - } - else if (info.instance_state == eprosima::fastdds::dds::NOT_ALIVE_DISPOSED_INSTANCE_STATE) - { - n_key_disposed++; - } - } - } - - void on_subscription_matched( - eprosima::fastdds::dds::DataReader*, - const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) - { - if (info.current_count_change == 1) - { - discovered = info.current_count; - wait_discovery_cv.notify_all(); - } - else if (info.current_count_change == -1) - { - discovered = info.current_count; - } - } - - //! Placeholder where received data is stored - MsgStruct msg_received; - - std::atomic n_key_disposed; - - //! Reference to the sample sent by the publisher - MsgStruct* msg_should_receive; - - //! Reference to received messages counter - std::atomic* samples_received; - - //! Number of DataWriters discovered - std::atomic discovered; - - //! Protects wait_discovery condition variable - std::mutex wait_discovery_cv_mtx; - - //! Waits to discovery enough DataWriters - std::condition_variable wait_discovery_cv; - } - listener_; -}; - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt deleted file mode 120000 index 470d47e16..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/ca.crt \ No newline at end of file diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt deleted file mode 120000 index 19c9a0d73..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/ddsrouter.crt \ No newline at end of file diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key deleted file mode 120000 index 9f58dfbe3..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/ddsrouter.key \ No newline at end of file diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem b/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem deleted file mode 120000 index 65a440083..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/dh_params.pem \ No newline at end of file diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt b/ddspipe_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt deleted file mode 100644 index 939063479..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2021 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. - -################ -# Trivial Test # -################ - -set(TEST_NAME - TrivialTest) - -set(TEST_SOURCES - TrivialTest.cpp) - -set(TEST_LIST - trivial_void_initialization - trivial_dummy_initialization - trivial_communication) - -set(TEST_NEEDED_SOURCES - ) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}") diff --git a/ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp deleted file mode 100644 index d1e872325..000000000 --- a/ddspipe_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include - -using namespace eprosima::ddsrouter::test; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -std::vector random_payload( - uint16_t seed = 1) -{ - std::vector payload; - - for (int i = 0; i < seed; i++) - { - payload.push_back(i); - } - - return payload; -} - -configuration::DdsRouterConfiguration void_configuration() -{ - configuration::DdsRouterConfiguration configuration; - configuration.participants_configurations = - { - std::make_shared( - ParticipantId("ParticipantVoid1"), - ParticipantKind::blank, - false - ), - std::make_shared( - ParticipantId("ParticipantVoid2"), - ParticipantKind::blank, - false - ) - }; - - return configuration; -} - -/** - * @brief Create a \c DdsRouterConfiguration with 2 dummy participants and one builtin topic - * - * @return configuration::DdsRouterConfiguration - */ -configuration::DdsRouterConfiguration simple_configuration( - const std::string& participant_1_name = "Participant1", - const std::string& participant_2_name = "Participant2", - const std::string& topic_name = "topic_dummy", - const std::string& topic_type = "type_dummy") -{ - configuration::DdsRouterConfiguration configuration; - - configuration.builtin_topics = - { - std::set>({std::make_shared(topic_name, topic_type)}), - }; - - configuration.participants_configurations = - { - std::make_shared( - ParticipantId(participant_1_name), - ParticipantKind::dummy, - false - ), - std::make_shared( - ParticipantId(participant_2_name), - ParticipantKind::dummy, - false - ) - }; - - return configuration; -} - -/** - * Test Whole DdsRouter initialization by initializing two EmptyParticipants - */ -TEST(TrivialTest, trivial_void_initialization) -{ - // Create DdsRouter entity - DdsRouter router(void_configuration()); - router.start(); - router.stop(); - - // Let test finish without failing -} - -/** - * Test Whole DdsRouter initialization by initializing two DummyParticipants and a DistributedTopic - */ -TEST(TrivialTest, trivial_dummy_initialization) -{ - // Create DdsRouter entity - DdsRouter router(simple_configuration()); - router.start(); - router.stop(); - - // Let test finish without failing -} - -/** - * Test Whole DdsRouter interfaces by using two DummyParticipants and send one message from one to the other - * - * TODO - */ -TEST(TrivialTest, trivial_communication) -{ - DdsRouter router(simple_configuration()); - router.start(); - - DummyParticipant* participant_1 = DummyParticipant::get_participant(ParticipantId("Participant1")); - DummyParticipant* participant_2 = DummyParticipant::get_participant(ParticipantId("Participant2")); - ASSERT_NE(participant_1, nullptr); - ASSERT_NE(participant_2, nullptr); - - DistributedTopic topic("topic_dummy", "type_dummy"); - Guid guid = random_guid(); - std::vector payload = random_payload(3); - - DummyDataReceived data; - data.source_guid = guid; - data.payload = payload; - - participant_1->simulate_data_reception(topic, data); - - // Sleep until first data arrives to the writer - participant_2->wait_until_n_data_sent(topic, 1); - - std::vector data_received = participant_2->get_data_that_should_have_been_sent(topic); - - ASSERT_EQ(data_received.size(), 1u); - ASSERT_EQ(data_received[0].source_guid, guid); - ASSERT_EQ(data_received[0].payload, payload); - - router.stop(); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/blackbox/implementations/CMakeLists.txt b/ddspipe_core/test/blackbox/implementations/CMakeLists.txt deleted file mode 100644 index fc76ab846..000000000 --- a/ddspipe_core/test/blackbox/implementations/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2021 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. - -######################## -# Implementations Test # -######################## - -set(TEST_NAME - ImplementationsTest) - -set(TEST_SOURCES - ImplementationsTest.cpp - ) - -set(TEST_LIST - pair_implementation - pair_implementation_with_topic - all_implementations - duplicated_ids - ) - -set(TEST_NEEDED_SOURCES - ) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - ) diff --git a/ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp deleted file mode 100644 index 6b1720df4..000000000 --- a/ddspipe_core/test/blackbox/implementations/ImplementationsTest.cpp +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace test { - -constexpr const unsigned int DEFAULT_THREAD_POOL_SIZE = 2; -constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; - -} /* namespace test */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/** - * Test that creates a DDSRouter with a Pair of Participants of same kind. - * It creates a DDSRouter with two Participants of same kind, starts it, then stops it and finally destroys it. - * - * This test will fail if it crashes. - */ -TEST(ImplementationsTest, pair_implementation) -{ - // TODO: Change to warning when fastdds warning: - // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: - // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> - // Function eprosima::fastdds::rtps::UDPChannelResource::Receive - // test::LogChecker test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - // For each Participant Kind - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::set> participant_configurations; - participant_configurations.insert(test::random_participant_configuration(kind, 1)); - participant_configurations.insert(test::random_participant_configuration(kind, 2)); - - configuration::SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - configuration::DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - std::set>(), - participant_configurations, - specs); - - // Create DDSRouter entity - DDSRouter router(configuration); - // Start DDSRouter - router.start(); - - // Stop DDS Router - router.stop(); - - // Let DDSRouter object destroy for the next iteration - } -} - -/** - * Test that creates a DDSRouter with a Pair of Participants of same kind. - * It creates a DDSRouter with two Participants of same kind, starts it with an active topic, - * then stops it and finally destroys it. - * - * This test will fail if it crashes. - */ -TEST(ImplementationsTest, pair_implementation_with_topic) -{ - // TODO: Change to warning when fastdds warning: - // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: - // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> - // Function eprosima::fastdds::rtps::UDPChannelResource::Receive - // test::LogChecker test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - // For each Participant kind - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::set> builtin_topics = test::topic_set( - {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); - - std::set> participant_configurations; - participant_configurations.insert(test::random_participant_configuration(kind, 1)); - participant_configurations.insert(test::random_participant_configuration(kind, 2)); - - configuration::SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - configuration::DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - builtin_topics, - participant_configurations, - specs); - - // Create DDSRouter entity - DDSRouter router(configuration); - - // Start DDSRouter - router.start(); - - // Stop DDS Router - router.stop(); - - // Let DDSRouter object destroy for the next iteration - } -} - -/** - * Test that creates a DDSRouter with several Participants, one of each kind - * It creates a DDSRouter with a Participant of each kind, - * starts it with an active topic, then stops it and finally destroys it. - * - * This test will fail if it crashes. - */ -TEST(ImplementationsTest, all_implementations) -{ - // TODO: Change to warning when fastdds warning: - // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: - // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> - // Function eprosima::fastdds::rtps::UDPChannelResource::Receive - // test::LogChecker test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - { - // Set topic to active - std::set> builtin_topics = test::topic_set( - {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); - - std::set> participant_configurations; - - uint16_t participant_number = 0; - - // For each Participant Kind set it in configuration - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - // Add participant - participant_configurations.insert(test::random_participant_configuration(kind, participant_number++)); - } - - configuration::SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - configuration::DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - std::set>(), - participant_configurations, - specs); - - // Create DDSRouter entity - DDSRouter router(configuration); - - // Start DDSRouter - router.start(); - - // Stop DDS Router - router.stop(); - - // Let DDSRouter object destroy for the next iteration - } -} - -/** - * Test that creates a DDSRouter with 3 simple configurations, 2 of them with same id, fails - * - * There is no easy way to test this case as the yaml will be ill-formed with two keys. - * Thus, it must be implemented from a yaml in string format. - */ -TEST(ImplementationsTest, duplicated_ids) -{ - // For each Participant Kind - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::set> participant_configurations; - participant_configurations.insert(test::random_participant_configuration(kind, 0)); - participant_configurations.insert(test::random_participant_configuration(kind, 0)); - - configuration::SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - configuration::DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - std::set>(), - participant_configurations, - specs); - - // Create DDSRouter entity - ASSERT_THROW(DDSRouter router(configuration), eprosima::utils::ConfigurationException) << kind; - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/CMakeLists.txt b/ddspipe_core/test/unittest/CMakeLists.txt index a2f25d2b5..45c3e49c1 100644 --- a/ddspipe_core/test/unittest/CMakeLists.txt +++ b/ddspipe_core/test/unittest/CMakeLists.txt @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO(annapurna) redo this tests using new configuration -# add_subdirectory(configuration) -add_subdirectory(core) +# TODO do these tests +# add_subdirectory(core) add_subdirectory(dynamic) add_subdirectory(efficiency) add_subdirectory(types) diff --git a/ddspipe_core/test/unittest/_configuration/CMakeLists.txt b/ddspipe_core/test/unittest/_configuration/CMakeLists.txt deleted file mode 100644 index fb3995783..000000000 --- a/ddspipe_core/test/unittest/_configuration/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2021 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. - -################################ -# DDSRouter Configuration Test # -################################ - -set(TEST_NAME ValidConfigurationTest) - -set(TEST_SOURCES - ValidConfigurationTest.cpp - ) -all_library_sources("${TEST_SOURCES}") - -set(TEST_LIST - ) - -set(TEST_EXTRA_LIBRARIES - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_core/test/unittest/_configuration/TODO.md b/ddspipe_core/test/unittest/_configuration/TODO.md deleted file mode 100644 index 1b0c59243..000000000 --- a/ddspipe_core/test/unittest/_configuration/TODO.md +++ /dev/null @@ -1,5 +0,0 @@ - -# CONFIGURATION TESTS - -These tests are developed using an old API. -They should be redo in the current API when possible. diff --git a/ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp b/ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp deleted file mode 100644 index daafed6c3..000000000 --- a/ddspipe_core/test/unittest/_configuration/_ConfigurationTest.cpp +++ /dev/null @@ -1,668 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/*************** -* CONSTRUCTOR * -***************/ - -/* - * Add a topic to a list in a yaml - * If name or type is not given, that tag will not be added - */ -void add_topic_to_list_to_yaml( - RawConfiguration& yaml, - const char* list_tag, - std::string topic_name = "", - std::string topic_type = "") -{ - RawConfiguration topic; - - if (topic_name != "") - { - topic[TOPIC_NAME_TAG] = topic_name; - } - - if (topic_type != "") - { - topic[TOPIC_TYPE_NAME_TAG] = topic_type; - } - - yaml[list_tag].push_back(topic); -} - -/* - * Add a list of topics to a list in a yaml - * If name or type is not given, that tag will not be added - */ -void add_topics_to_list_to_yaml( - RawConfiguration& yaml, - const char* list_tag, - std::set> names) -{ - for (std::pair name : names) - { - add_topic_to_list_to_yaml(yaml, list_tag, name.first, name.second); - } -} - -/* - * Add a tag with empty value - */ -void add_empty_tag_to_yaml( - RawConfiguration& yaml, - std::string tag) -{ - yaml[tag] = RawConfiguration(); -} - -/* - * Check if a topic is inside a list returned by allowlist or blocklist DDSRouter methods - */ -bool topic_in_list( - std::list> list, - WildcardDdsFilterTopic compared_topic) -{ - for (std::shared_ptr topic : list) - { - // Check class and internal variables - if (typeid(*topic) == typeid(compared_topic) && - compared_topic == *topic) - { - return true; - } - } - return false; -} - -/* - * Check if a topic is inside a list returned by real_topics DDSRouter methods - */ -bool topic_in_real_list( - std::set list, - DistributedTopic compared_topic) -{ - for (DistributedTopic topic : list) - { - // Check class and internal variables - if (typeid(topic) == typeid(compared_topic) && - compared_topic == topic) - { - return true; - } - } - return false; -} - -/* - * Random Real topic names to test different configurations - */ -std::set> random_real_topic_names() -{ - return - { - {"TopicName1", "TopicType1"}, - {"TopicName2", "TopicType2"}, - {"TopicName3", "TopicType3"}, - - {"rt/chatter", "std::str::main::other_namespace"}, - - {"real/rare_topic.name", "real/rare_topic.type"}, - }; -} - -/* - * Random Non Valid topics - */ -std::set> random_non_valid_topic_names() -{ - return - { - {"", ""}, - {"", "*"}, - }; -} - -/* - * Random Non Real topic names to test different configurations - */ -std::set> random_filter_topic_names() -{ - return - { - {"rt/chatter", "*"}, - {"*", "std::str"}, - - {"rt/chatter", "std::str*"}, - {"rt/chatter/*", "std::str"}, - {"rt/chatter/*", "std::str*"}, - - {"rt/chatter", "*::std::str"}, - {"*/rt/chatter", "std::str"}, - {"*/rt/chatter", "*::std::str"}, - - {"rt/chatter", "*::std::str*"}, - {"*/rt/chatter/*", "std::str"}, - {"*/rt/chatter/*", "*::std::str*"}, - - {"rt/chatter", ""}, - {"*/rt/chatter/*", ""}, - }; -} - -/* - * Unioin of real and non real topic names - */ -std::set> random_topic_names() -{ - std::set> all_topics; - - std::set> real_topics = random_real_topic_names(); - std::set> abs_topics = random_filter_topic_names(); - std::set_union( - real_topics.begin(), real_topics.end(), - abs_topics.begin(), abs_topics.end(), - std::inserter(all_topics, all_topics.begin())); - - std::set> non_valid_topics = random_non_valid_topic_names(); - all_topics.insert(non_valid_topics.begin(), non_valid_topics.end()); - - return all_topics; -} - -/* - * Number of valid topics in random_topic_names() - */ -size_t random_topic_names_number_valid_topics() -{ - return random_real_topic_names().size() + random_filter_topic_names().size(); -} - -/* - * Random participant id - * - * TODO: create really random names - */ -std::string random_participant_name( - uint16_t seed) -{ - return std::string("PartName_") + std::to_string(seed); -} - -/* - * Random participant kind - * - * WARNING: the max_types_available must be updated with each new type added - */ -ParticipantKind random_participant_kind( - uint16_t seed = 0) -{ - // Avoid Invalid type - return ALL_VALID_PARTICIPANT_KINDS[seed % ALL_VALID_PARTICIPANT_KINDS.size()]; -} - -/* - * Random participant configuration - * - * TODO: create really random configurations - */ -RawConfiguration random_participant_configuration( - uint16_t seed) -{ - RawConfiguration config; - - for (int i = (seed); i > 0; i--) - { - std::string tag("tag" + std::to_string(i)); - - if (i % 4 == 0) - { - // Each 4 tags add an array - config[tag].push_back("value1"); - config[tag].push_back("value2"); - } - else if (i % 2 == 0) - { - // Each 4 tags add a map - RawConfiguration sub_map; - sub_map["x"] = "y"; - sub_map["a"] = "b"; - config[tag] = sub_map; - } - else - { - // The rest are direct values - config[tag] = "Random value"; - } - } - - config[PARTICIPANT_KIND_TAG] = random_participant_kind().to_string(); - - return config; -} - -/** - * Test Configuration constructor to check it does not fail - * - * CASES: - * Empty configuration - * Random configuration - */ -TEST(ConfigurationTest, constructor) -{ - // Empty case - RawConfiguration empty_yaml; - DDSRouterConfiguration config_empty(empty_yaml); - - // Random case - RawConfiguration random_config; - random_config["RAND_TAG_1"] = "rand_val_1"; - random_config["RAND_TAG_2"] = "rand_val_2"; - random_config["RAND_TAG_3"].push_back(314); - DDSRouterConfiguration config_random(random_config); -} - -/**************************** -* PUBLIC METHODS STD CASES * -****************************/ - -/** - * Test get participants configurations - * - * CASES: - * Empty configuration - * Other tags that are not participant valid ids - * One Participant Configuration - * Many Participant Configurations - * - * TODO: Change yaml tags for their proper external tags (constexpr) - */ -TEST(ConfigurationTest, participants_configurations) -{ - { - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.participants_configurations().empty()); - } - - { - // Other tags that are not participant valid ids - RawConfiguration yaml2; - add_topics_to_list_to_yaml(yaml2, ALLOWLIST_TAG, random_filter_topic_names()); - add_topics_to_list_to_yaml(yaml2, BLOCKLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.participants_configurations().empty()); - } - - { - // One Participant Configuration - RawConfiguration listening_addresses; - RawConfiguration address1; - RawConfiguration address2; - address1["ip"] = "127.0.0.1"; - address1["port"] = "31415"; - listening_addresses.push_back(address1); - address2["ip"] = "8.8.8.8"; - address2["port"] = "6666"; - listening_addresses.push_back(address2); - - RawConfiguration participant_config; - participant_config[PARTICIPANT_KIND_TAG] = random_participant_kind().to_string(); - participant_config["listening-addresses"] = listening_addresses; - - std::string participant_name_str = "wanParticipant"; - ParticipantId participant_name(participant_name_str); - RawConfiguration yaml3; - yaml3[participant_name_str] = participant_config; - - DDSRouterConfiguration config3(yaml3); - auto result3 = config3.participants_configurations(); - ASSERT_EQ(1, result3.size()); - EXPECT_EQ(participant_name, result3.front().id()); - EXPECT_EQ(ParticipantConfiguration(ParticipantId(participant_name_str), participant_config), result3.front()); - } - - { - // Many Participant Configurations - uint16_t participants_num = 10; - RawConfiguration yaml4; - for (int i = 0; i < participants_num; i++) - { - yaml4[random_participant_name(i)] = random_participant_configuration(i); - } - DDSRouterConfiguration config4(yaml4); - auto result4 = config4.participants_configurations(); - ASSERT_EQ(result4.size(), participants_num); - - // For every participant in participants_configurations, check that the id is inside the actual ids stored - // TODO: check the configurations are actually the same, implement yaml compare - for (int i = 0; i < participants_num; i++) - { - ParticipantId expected_id(random_participant_name(i)); - bool in_configurations = false; - for (auto part_config: result4) - { - // They may not be sorted, so it must be checked that this is the actual participant config - // it is being tested - if (part_config.id() == expected_id) - { - in_configurations = true; - break; - } - } - ASSERT_TRUE(in_configurations); - } - } -} - -/** - * Test get real topics from allowlist - * - * CASES: - * Empty configuration - * Empty allowlist - * Allowlist with only non Real topics - * Allowlist with only Real topics - * Allowlist with random topics - */ -TEST(ConfigurationTest, real_topics) -{ - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.real_topics().empty()); - - // Empty allowlist - RawConfiguration yaml2; - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic2", "type2"); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.real_topics().empty()); - - // Allowlist with only non Real topics - RawConfiguration yaml3; - add_topics_to_list_to_yaml(yaml3, ALLOWLIST_TAG, random_filter_topic_names()); - DDSRouterConfiguration config3(yaml3); - EXPECT_TRUE(config3.real_topics().empty()); - - // Allowlist with only Real topics - RawConfiguration yaml4; - add_topics_to_list_to_yaml(yaml4, ALLOWLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config4(yaml4); - auto result4 = config4.real_topics(); - EXPECT_FALSE(result4.empty()); - for (auto random_topic : random_real_topic_names()) - { - DistributedTopic topic(random_topic.first, random_topic.second); - EXPECT_TRUE(topic_in_real_list(result4, topic)); - } - - // Allowlist with random topics - RawConfiguration yaml5; - add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_topic_names()); - DDSRouterConfiguration config5(yaml5); - auto result5 = config5.real_topics(); - EXPECT_FALSE(result5.empty()); - - uint16_t real_topics = 0; - for (auto random_topic : random_topic_names()) - { - bool real_topic = DistributedTopic::is_valid_dds_topic(random_topic.first, random_topic.second); - - if (real_topic) - { - ++real_topics; - DistributedTopic topic(random_topic.first, random_topic.second); - EXPECT_TRUE(topic_in_real_list(result5, topic)) << topic; - } - } - EXPECT_EQ(real_topics, result5.size()); -} - -/********************************* -* PUBLIC METHODS SPECIFIC CASES * -*********************************/ - -/** - * Test get allowlist with wildcards from yaml - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Empty configuration - * Empty allowlist - * Allowlist with some examples - * Allowlist with random topics - * Allowlist and blocklist with random topics - */ -TEST(ConfigurationTest, allowlist_wildcard) -{ - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.allowlist().empty()); - - // Empty allowlist - RawConfiguration yaml2; - add_empty_tag_to_yaml(yaml2, ALLOWLIST_TAG); - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic2", "type2"); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.allowlist().empty()); - - // Empty allowlist - RawConfiguration yaml3; - add_topic_to_list_to_yaml(yaml3, ALLOWLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml3, ALLOWLIST_TAG, "topic2*", "type2*"); - DDSRouterConfiguration config3(yaml3); - auto result3 = config3.allowlist(); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic1"), std::string("type1")))); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic2*"), std::string("type2*")))); - - // Allowlist with random topics - RawConfiguration yaml4; - add_topics_to_list_to_yaml(yaml4, ALLOWLIST_TAG, random_topic_names()); - DDSRouterConfiguration config4(yaml4); - EXPECT_EQ(config4.allowlist().size(), random_topic_names_number_valid_topics()); - - // Allowlist and blocklist with random topics - RawConfiguration yaml5; - add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_filter_topic_names()); - add_topics_to_list_to_yaml(yaml5, BLOCKLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config5(yaml5); - EXPECT_EQ(config5.allowlist().size(), random_filter_topic_names().size()); -} - -/** - * Test get blocklist with wildcards from yaml - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Empty configuration - * Empty blocklist - * Blocklist with some examples - * Blocklist with random topics - * Blocklist and allowlist with random topics - */ -TEST(ConfigurationTest, blocklist_wildcard) -{ - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.blocklist().empty()); - - // Empty blocklist - RawConfiguration yaml2; - add_empty_tag_to_yaml(yaml2, BLOCKLIST_TAG); - add_topic_to_list_to_yaml(yaml2, ALLOWLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml2, ALLOWLIST_TAG, "topic2", "type2"); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.blocklist().empty()); - - // Empty blocklist - RawConfiguration yaml3; - add_topic_to_list_to_yaml(yaml3, BLOCKLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml3, BLOCKLIST_TAG, "topic2*", "type2*"); - DDSRouterConfiguration config3(yaml3); - auto result3 = config3.blocklist(); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic1"), std::string("type1")))); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic2*"), std::string("type2*")))); - - // Blocklist with random topics - RawConfiguration yaml4; - add_topics_to_list_to_yaml(yaml4, BLOCKLIST_TAG, random_topic_names()); - DDSRouterConfiguration config4(yaml4); - EXPECT_EQ(config4.blocklist().size(), random_topic_names_number_valid_topics()); - - // Blocklist and allowlist with random topics - RawConfiguration yaml5; - add_topics_to_list_to_yaml(yaml5, BLOCKLIST_TAG, random_filter_topic_names()); - add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config5(yaml5); - EXPECT_EQ(config5.blocklist().size(), random_filter_topic_names().size()); -} - -/** - * Test get blocklist with wildcards from yaml - * - * TODO: when regex is implemented, create a common test case - */ -TEST(ConfigurationTest, allowlist_and_blocklist) -{ - RawConfiguration yaml; - add_topics_to_list_to_yaml(yaml, ALLOWLIST_TAG, random_real_topic_names()); - add_topics_to_list_to_yaml(yaml, BLOCKLIST_TAG, random_filter_topic_names()); - DDSRouterConfiguration config(yaml); - EXPECT_EQ(config.allowlist().size(), random_real_topic_names().size()); - EXPECT_EQ(config.blocklist().size(), random_filter_topic_names().size()); -} - -/****************************** -* PUBLIC METHODS ERROR CASES * -******************************/ - -/** - * Test DDSRouterConfiguration constructor to check it does not fail - * - * CASES: - * Array as base configuration - * Scalar as base configuration - * String as base configuration - */ -TEST(ConfigurationTest, constructor_fail) -{ - // Array case - RawConfiguration array_config; - array_config.push_back("rand_val_1"); - array_config.push_back("rand_val_2"); - EXPECT_THROW(DDSRouterConfiguration dc(array_config), utils::ConfigurationException); - - // Scalar case - RawConfiguration scalar_config; - scalar_config = 42; - EXPECT_THROW(DDSRouterConfiguration dc(scalar_config), utils::ConfigurationException); - - // Scalar case - RawConfiguration string_config; - string_config = "non_valid_config"; - EXPECT_THROW(DDSRouterConfiguration dc(string_config), utils::ConfigurationException); -} - -/** - * Test get participants configurations negative cases - */ -TEST(ConfigurationTest, participants_configurations_fail) -{ - // There is currently no way to induce an error when getting participant configurations - ASSERT_TRUE(true); -} - -/** - * Test get real topics from allowlist negative cases - * - * CASES: - * Map instead of array in topics - */ -TEST(ConfigurationTest, real_topics_fail) -{ - // Map instead of array in allowlist - RawConfiguration map_config; - map_config["key1"] = "value1"; - RawConfiguration yaml1; - yaml1[ALLOWLIST_TAG] = map_config; - DDSRouterConfiguration dc(yaml1); - EXPECT_THROW(dc.real_topics(), utils::ConfigurationException); -} - -/** - * Test get allowlist with wildcards from yaml negative cases - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Map instead of array in topics - */ -TEST(ConfigurationTest, allowlist_wildcard_fail) -{ - // Map instead of array in allowlist - RawConfiguration map_config; - map_config["key1"] = "value1"; - RawConfiguration yaml1; - yaml1[ALLOWLIST_TAG] = map_config; - DDSRouterConfiguration dc(yaml1); - EXPECT_THROW(dc.allowlist(), utils::ConfigurationException); -} - -/** - * Test get blocklist with wildcards from yaml negative cases - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Map instead of array in topics - */ -TEST(ConfigurationTest, blocklist_wildcard_fail) -{ - // Map instead of array in blocklist - RawConfiguration map_config; - map_config["key1"] = "value1"; - RawConfiguration yaml1; - yaml1[BLOCKLIST_TAG] = map_config; - DDSRouterConfiguration dc(yaml1); - EXPECT_THROW(dc.blocklist(), utils::ConfigurationException); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp b/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp index 6f60a9715..144de1480 100644 --- a/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp +++ b/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp @@ -22,63 +22,43 @@ #include #include -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; -namespace eprosima { -namespace ddspipe { -namespace core { namespace test { -/** - * This class is used to expose protected methods of the parent class - * so they can be tested. - */ -class ParticipantsDatabase : public eprosima::ddsrouter::core::ParticipantsDatabase +struct MockParticipant : public IParticipant { -public: - - ParticipantsDatabase() + types::ParticipantId id() const noexcept { + return types::ParticipantId("test_participant"); } - ParticipantsDatabase( - std::map> participants) - : ParticipantsDatabase() + bool is_rtps_kind() const noexcept { - participants_ = participants; + return false; } - std::shared_ptr pop( - const ParticipantId& id) noexcept + bool is_repeater() const noexcept { - return pop_(id); + return false; } - std::shared_ptr pop() noexcept + std::shared_ptr create_writer( + const ITopic& topic) { - return pop_(); + // NOTICE: be careful with this as this has a nullptr + return std::shared_ptr(); } - void add_participant( - ParticipantId id, - std::shared_ptr participant, - std::size_t expected_size) + std::shared_ptr create_reader( + const ITopic& topic) { - add_participant_(id, participant); - // Verify correct insertion - auto it = participants_.find(id); - ASSERT_EQ(it->second, participant); - ASSERT_EQ(participants_.size(), expected_size); + // NOTICE: be careful with this as this has a nullptr + return std::shared_ptr(); } - -}; +} } /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ /********************* * PROTECTED METHODS ** diff --git a/ddspipe_core/test/unittest/dynamic/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/CMakeLists.txt index 1175745b3..a0e7f756e 100644 --- a/ddspipe_core/test/unittest/dynamic/CMakeLists.txt +++ b/ddspipe_core/test/unittest/dynamic/CMakeLists.txt @@ -13,4 +13,3 @@ # limitations under the License. add_subdirectory(allowed_topic_list) -add_subdirectory(discovery_database) diff --git a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp index 7bae70698..91b7d215b 100644 --- a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp +++ b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp @@ -15,14 +15,18 @@ #include #include -#include +#include #include -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; using pair_topic_type = std::pair; +namespace test +{ + /****************** * FILTER METHODS * ******************/ @@ -33,13 +37,13 @@ using pair_topic_type = std::pair; * TODO: Add regex when implemented */ void add_topic_to_list( - std::set>& list, + std::set>& list, pair_topic_type topic_name, bool wildcard = true) { if (wildcard) { - auto new_topic = std::make_shared(); + auto new_topic = utils::Heritable::make_heritable(); new_topic->topic_name = topic_name.first; new_topic->type_name = topic_name.second; @@ -53,7 +57,7 @@ void add_topic_to_list( * TODO: Add regex when implemented */ void add_topics_to_list( - std::set>& list, + std::set>& list, std::vector topic_names, bool wildcard = true) { @@ -61,7 +65,7 @@ void add_topics_to_list( { for (pair_topic_type topic_name : topic_names) { - auto new_topic = std::make_shared(); + auto new_topic = utils::Heritable::make_heritable(); new_topic->topic_name = topic_name.first; new_topic->type_name = topic_name.second; @@ -82,8 +86,8 @@ void generic_test( const std::vector& real_topics_negative) { // Create AllowedTopicList object - std::set> allowlist; - std::set> blocklist; + std::set> allowlist; + std::set> blocklist; add_topics_to_list(allowlist, allowlist_topics); add_topics_to_list(blocklist, blocklist_topics); @@ -93,18 +97,24 @@ void generic_test( // Test positive cases for (pair_topic_type topic_name : real_topics_positive) { - DistributedTopic topic(topic_name.first, topic_name.second); + DdsTopic topic; + topic.m_topic_name = topic_name.first; + topic.type_name = topic_name.second; ASSERT_TRUE(atl.is_topic_allowed(topic)); } // Test negative cases for (pair_topic_type topic_name : real_topics_negative) { - DistributedTopic topic(topic_name.first, topic_name.second); + DdsTopic topic; + topic.m_topic_name = topic_name.first; + topic.type_name = topic_name.second; ASSERT_FALSE(atl.is_topic_allowed(topic)); } } +} // test + /** * Test \c AllowedTopicList \c is_topic_allowed method * @@ -124,7 +134,9 @@ TEST(AllowedTopicListTest, is_topic_allowed__default_constructor) for (pair_topic_type topic_name : real_topics) { - DistributedTopic topic(topic_name.first, topic_name.second); + DdsTopic topic; + topic.m_topic_name = topic_name.first; + topic.type_name = topic_name.second; ASSERT_TRUE(atl.is_topic_allowed(topic)); } @@ -149,7 +161,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__empty_list) {"rt/chatter", "std::std_msgs::string"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -183,7 +195,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__simple_blocklist) {"HelloWorldTopic", "HelloWorld"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -222,7 +234,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__complex_blocklist) {"rt/chatter/pub", "std::type"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -258,7 +270,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist) {"rt/chatter", "std::std_msgs::string"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -300,7 +312,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist) {"rt/chatter", "std_type"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -343,7 +355,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist) {"rt/pub", "std"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -392,7 +404,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist) {"rt/chatter/pub", "std"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -436,7 +448,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist_enta {"rt/pub", "std"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, @@ -486,7 +498,7 @@ TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist_ent {"chatter", "std::std_msgs::int"}, }; - generic_test( + test::generic_test( allowlist_topics, blocklist_topics, real_topics_positive, diff --git a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt index a145292df..4edef040f 100644 --- a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt +++ b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt @@ -19,8 +19,8 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/dynamic/AllowedTopicList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/IFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ) diff --git a/ddspipe_core/test/unittest/dynamic/discovery_database/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/discovery_database/CMakeLists.txt deleted file mode 100644 index ebcac32bc..000000000 --- a/ddspipe_core/test/unittest/dynamic/discovery_database/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2021 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. - -###################### -# Discovery Database # -###################### - -set(TEST_NAME DiscoveryDatabaseTest) - -set(TEST_SOURCES - DiscoveryDatabaseTest.cpp - ) -all_library_sources("${TEST_SOURCES}") # Add all requirements for use test_utils - -set(TEST_LIST - topic_exists - endpoint_exists - add_endpoint - update_endpoint - erase_endpoint - get_endpoint - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp b/ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp deleted file mode 100644 index 87d7fdee5..000000000 --- a/ddspipe_core/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp +++ /dev/null @@ -1,250 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace eprosima::ddsrouter::test; -using namespace eprosima::utils; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -/** - * This class is used to expose protected methods of the parent class - * so they can be tested. - */ -class DiscoveryDatabase : public eprosima::ddsrouter::core::DiscoveryDatabase -{ -public: - - DiscoveryDatabase() - : eprosima::ddsrouter::core::DiscoveryDatabase() - { - start(); - } - - bool add_endpoint_protected( - const Endpoint& new_endpoint) - { - return add_endpoint_(new_endpoint); - } - - bool update_endpoint_protected( - const Endpoint& new_endpoint) - { - return update_endpoint_(new_endpoint); - } - - ReturnCode erase_endpoint_protected( - const Endpoint& endpoint_to_erase) - { - return erase_endpoint_(endpoint_to_erase); - } - -}; - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/** - * Test \c DiscoveryDatabase \c topic_exists method - * - * CASES: - * Topic not present in database - * Topic present in database - */ -TEST(DiscoveryDatabaseTest, topic_exists) -{ - test::DiscoveryDatabase discovery_database; - Guid guid_1 = random_guid(1); - Guid guid_2 = random_guid(2); - DistributedTopic topic("test", "test"); - Endpoint endpoint_1(EndpointKind::reader, guid_1, topic); - Endpoint endpoint_2(EndpointKind::reader, guid_2, topic); - - ASSERT_FALSE(discovery_database.topic_exists(topic)); - discovery_database.add_endpoint_protected(endpoint_1); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - discovery_database.add_endpoint_protected(endpoint_2); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - discovery_database.erase_endpoint_protected(endpoint_1); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - discovery_database.erase_endpoint_protected(endpoint_2); - ASSERT_FALSE(discovery_database.topic_exists(topic)); -} - -/** - * Test \c DiscoveryDatabase \c endpoint_exists method - * - * CASES: - * Endpoint not present in database - * Endpoint present in database - */ -TEST(DiscoveryDatabaseTest, endpoint_exists) -{ - test::DiscoveryDatabase discovery_database; - Guid guid; - DistributedTopic topic("test", "test"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); - discovery_database.add_endpoint_protected(endpoint); - ASSERT_TRUE(discovery_database.endpoint_exists(guid)); - discovery_database.erase_endpoint_protected(endpoint); - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); -} - -/** - * Test \c DiscoveryDatabase \c add_endpoint method - * - * CASES: - * Endpoint to insert not present - * Endpoint to insert already present and active - * Endpoint to insert already present but inactive - */ -TEST(DiscoveryDatabaseTest, add_endpoint) -{ - test::DiscoveryDatabase discovery_database; - DistributedTopic topic("original", "original"); - // Create active endpoint - Guid active_guid = random_guid(1); - Endpoint active_endpoint(EndpointKind::reader, active_guid, topic); - // Create inactive endpoint - Guid inactive_guid = random_guid(2); - Endpoint inactive_endpoint(EndpointKind::reader, inactive_guid, topic); - inactive_endpoint.active(false); - - // Insert endpoints - ASSERT_TRUE(discovery_database.add_endpoint_protected(active_endpoint)); - ASSERT_EQ(discovery_database.get_endpoint(active_guid), active_endpoint); - ASSERT_TRUE(discovery_database.add_endpoint_protected(inactive_endpoint)); - ASSERT_EQ(discovery_database.get_endpoint(inactive_guid), inactive_endpoint); - - // Add new endpoint with same guid as already stored active endpoint - // Should throw \c InconsistencyException - DistributedTopic new_topic("new", "new"); - Endpoint active_new_endpoint(EndpointKind::reader, active_guid, new_topic); - ASSERT_THROW(discovery_database.add_endpoint_protected(active_new_endpoint), InconsistencyException); - - // Add new endpoint with same guid as already stored inactive endpoint - // Should update entry - Endpoint inactive_new_endpoint(EndpointKind::reader, inactive_guid, new_topic); - ASSERT_TRUE(discovery_database.add_endpoint_protected(inactive_new_endpoint)); - ASSERT_EQ(discovery_database.get_endpoint(inactive_guid), inactive_new_endpoint); -} - -/** - * Test \c DiscoveryDatabase \c update_endpoint method - * - * CASES: - * Endpoint to be updated not present in database - * Endpoint to be updated present in database - */ -TEST(DiscoveryDatabaseTest, update_endpoint) -{ - test::DiscoveryDatabase discovery_database; - Guid guid = random_guid(1); - DistributedTopic topic("original", "original"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - DistributedTopic new_topic("new", "new"); - Endpoint new_endpoint(EndpointKind::reader, guid, new_topic); - // Endpoint to be updated not yet inserted - ASSERT_THROW(discovery_database.update_endpoint_protected(new_endpoint), InconsistencyException); - - // Insert endpoint - ASSERT_TRUE(discovery_database.add_endpoint_protected(endpoint)); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - ASSERT_FALSE(discovery_database.topic_exists(new_topic)); - ASSERT_EQ(discovery_database.get_endpoint(guid), endpoint); - - // Update endpoint - ASSERT_TRUE(discovery_database.update_endpoint_protected(new_endpoint)); - ASSERT_FALSE(discovery_database.topic_exists(topic)); - ASSERT_TRUE(discovery_database.topic_exists(new_topic)); - ASSERT_EQ(discovery_database.get_endpoint(guid), new_endpoint); -} - -/** - * Test \c DiscoveryDatabase \c erase_endpoint method - * - * CASES: - * Endpoint to erase not present in database - * Endpoint to erase present in database - */ -TEST(DiscoveryDatabaseTest, erase_endpoint) -{ - test::DiscoveryDatabase discovery_database; - Guid guid = random_guid(1); - DistributedTopic topic("test", "test"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - - // Endpoint to erase not yet inserted - ASSERT_THROW(discovery_database.erase_endpoint_protected(endpoint), InconsistencyException); - - // Insert endpoint - discovery_database.add_endpoint_protected(endpoint); - ASSERT_TRUE(discovery_database.endpoint_exists(guid)); - - // Erase endpoint - ASSERT_EQ(discovery_database.erase_endpoint_protected(endpoint), ReturnCode::RETCODE_OK); - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); -} - -/** - * Test \c DiscoveryDatabase \c get_endpoint method - * - * CASES: - * Endpoint to retrieve not present in database - * Endpoint to retrieve present in database - */ -TEST(DiscoveryDatabaseTest, get_endpoint) -{ - test::DiscoveryDatabase discovery_database; - Guid guid = random_guid(1); - DistributedTopic topic("test", "test"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - - // Try to fetch a not stored endpoint - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); - ASSERT_THROW(discovery_database.get_endpoint(guid).kind(), InconsistencyException); - - // Insert and get endpoint - discovery_database.add_endpoint_protected(endpoint); - ASSERT_TRUE(discovery_database.endpoint_exists(guid)); - ASSERT_EQ(discovery_database.get_endpoint(guid), endpoint); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/efficiency/CMakeLists.txt b/ddspipe_core/test/unittest/efficiency/CMakeLists.txt index 692997a73..0928dcc51 100644 --- a/ddspipe_core/test/unittest/efficiency/CMakeLists.txt +++ b/ddspipe_core/test/unittest/efficiency/CMakeLists.txt @@ -21,7 +21,7 @@ set(TEST_NAME PayloadPoolTest) set(TEST_SOURCES PayloadPoolTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp ) set(TEST_LIST @@ -57,7 +57,7 @@ set(TEST_SOURCES MapPayloadPoolTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/MapPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp ) set(TEST_LIST @@ -92,7 +92,7 @@ set(TEST_SOURCES FastPayloadPoolTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/FastPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp ) set(TEST_LIST diff --git a/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp index 7283a2221..8b8763519 100644 --- a/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp +++ b/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp @@ -21,9 +21,9 @@ #include #include -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; const constexpr unsigned int TEST_NUMBER = 5; const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); diff --git a/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp index d57178816..539f344d9 100644 --- a/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp +++ b/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp @@ -21,9 +21,9 @@ #include #include -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; const constexpr unsigned int TEST_NUMBER = 5; const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); diff --git a/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp index 60f64b654..92ce7a1c8 100644 --- a/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp +++ b/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp @@ -23,9 +23,8 @@ #include #include -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; // Using for gmock using ::testing::_; @@ -41,7 +40,7 @@ namespace rtps { * This definition is needed due to googletest-distribution (1.11.0) requires to every class used inside ASSERT macro * to have the operator << defined in SAME namespace than the class. * In our case, Payload is defined as eprosima::fastrtps::rtps::SerializedPayload_t but redefined as - * eprosima::ddsrouter::core::types::Payload and the operator << is defined in eprosima::ddsrouter::core::types + * eprosima::ddspipe::core::types::Payload and the operator << is defined in eprosima::ddspipe::core::types * Thus, gtest could not find this definition (arising a very messy and cryptic compilation error). * This definition corrects that problem. * @@ -86,7 +85,7 @@ class MockPayloadPool : public PayloadPool MOCK_METHOD( bool, get_payload, - (uint32_t size, eprosima::ddsrouter::core::types::Payload& target_payload), + (uint32_t size, eprosima::ddspipe::core::types::Payload& target_payload), (override)); MOCK_METHOD( @@ -95,14 +94,14 @@ class MockPayloadPool : public PayloadPool ( const Payload& src_payload, eprosima::fastrtps::rtps::IPayloadPool*&data_owner, - eprosima::ddsrouter::core::types::Payload& target_payload + eprosima::ddspipe::core::types::Payload& target_payload ), (override)); MOCK_METHOD( bool, release_payload, - (eprosima::ddsrouter::core::types::Payload& target_payload), + (eprosima::ddspipe::core::types::Payload& target_payload), (override)); }; diff --git a/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt b/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt index 927ffbf5d..dfc2ce5fd 100644 --- a/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt +++ b/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt @@ -49,27 +49,22 @@ set(TEST_NAME EndpointTest) set(TEST_SOURCES EndpointTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/endpoint/Endpoint.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/testing/random_values.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/DomainId.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Endpoint.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/SpecificEndpointQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ) set(TEST_LIST - constructor - kind_getter - guid_getter - qos_getter - topic_getter - active_getter - active_setter - is_writer - is_reader + topic_qos + is_reader_writer ) set(TEST_EXTRA_LIBRARIES diff --git a/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp b/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp index 7bac737ce..d2775ac53 100644 --- a/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp +++ b/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp @@ -15,179 +15,20 @@ #include #include +#include #include -#include -#include -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; +using namespace eprosima::ddspipe::core::testing; -// Get a random TopicQoS configuration -TopicQoS random_qos( - uint16_t seed = 0) +namespace test { - TopicQoS qos; - if (seed % 2) - { - qos.reliability_qos = ReliabilityKind::BEST_EFFORT; - } - else - { - qos.reliability_qos = ReliabilityKind::RELIABLE; - } - - switch ((seed / 2) % 4) - { - case 0: - qos.durability_qos = DurabilityKind::VOLATILE; - break; - - case 1: - qos.durability_qos = DurabilityKind::TRANSIENT_LOCAL; - break; - - case 2: - qos.durability_qos = DurabilityKind::TRANSIENT; - break; - - case 3: - qos.durability_qos = DurabilityKind::PERSISTENT; - break; - - default: - break; - } - - return qos; -} - -// Get a random topic name -DistributedTopic random_topic( - uint16_t seed = 0) -{ - return DistributedTopic("TopicName_" + std::to_string(seed), "TopicType_" + std::to_string(seed), false, random_qos(seed)); -} - -// Get a random topic name -EndpointKind random_endpoint_kind( - uint16_t seed = 0) -{ - if (seed % 2) - { - return EndpointKind::reader; - } - else - { - return EndpointKind::writer; - } -} - -// Get a random guid -Guid random_valid_guid( - uint16_t seed = 0) -{ - eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; - std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d." + std::to_string(seed)) >> guid_prefix; - return Guid( - guid_prefix, - seed); -} - -/** - * Test \c Endpoint constructor - */ -TEST(EndpointTest, constructor) -{ - EndpointKind kind; - Guid guid; - DistributedTopic topic = random_topic(); - // TODO: add data qos - - Endpoint endpoint(kind, guid, topic); +constexpr const unsigned int TEST_ITERATIONS = 100; - ASSERT_EQ(endpoint.kind(), kind); - ASSERT_EQ(endpoint.guid(), guid); - ASSERT_EQ(endpoint.topic_qos(), topic.topic_qos.get_reference()); - ASSERT_EQ(endpoint.topic(), topic); -} - -/** - * Test \c Endpoint \c kind getter method - * - * CASES: - * Writer - * Reader - */ -TEST(EndpointTest, kind_getter) -{ - Guid guid; - DistributedTopic topic = random_topic(); +} // test - // Writer - { - Endpoint endpoint(EndpointKind::writer, guid, topic); - ASSERT_EQ(endpoint.kind(), EndpointKind::writer); - } - - // Reader - { - Endpoint endpoint(EndpointKind::reader, guid, topic); - ASSERT_EQ(endpoint.kind(), EndpointKind::reader); - } -} - -/** - * Test \c Endpoint \c guid getter method - * - * CASES: - * Default guid - * Random guids - */ -TEST(EndpointTest, guid_getter) -{ - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Default guid - { - Guid guid; - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(endpoint.guid(), guid); - } - - // Random guids - { - for (uint16_t i = 0; i < 10; i++) - { - Guid guid = random_valid_guid(i); - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(endpoint.guid(), random_valid_guid(i)) << i; - } - } -} - -/** - * Test \c Endpoint \c qos getter method - * - * CASES: - * Random TopicQoS - */ -TEST(EndpointTest, qos_getter) -{ - Guid guid = random_valid_guid(); - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Random guids - { - for (uint16_t i = 0; i < 8; i++) - { - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(topic.topic_qos, endpoint.topic_qos()) << i; - } - } -} /** * Test \c Endpoint \c topic getter method @@ -195,92 +36,12 @@ TEST(EndpointTest, qos_getter) * CASES: * Random Topics */ -TEST(EndpointTest, topic_getter) +TEST(EndpointTest, topic_qos_getter) { - Guid guid = random_valid_guid(); - EndpointKind kind = random_endpoint_kind(); - - // Random guids + for (unsigned int i = 0; i < test::TEST_ITERATIONS; i++) { - for (uint16_t i = 0; i < 10u; i++) - { - DistributedTopic topic = random_topic(i); - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(endpoint.topic(), random_topic(i)) << i; - } - } -} - -/** - * Test \c Endpoint \c active getter method - * - * CASES: - * Default value - * Change to invalid - * Change to invalid and to valid - */ -TEST(EndpointTest, active_getter) -{ - Guid guid = random_valid_guid(); - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Default value - { - Endpoint endpoint(kind, guid, topic); - ASSERT_TRUE(endpoint.active()); - } - - // Change to invalid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - ASSERT_FALSE(endpoint.active()); - } - - // Change to invalid and to valid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - endpoint.active(true); - ASSERT_TRUE(endpoint.active()); - } -} - -/** - * Test \c Endpoint \c active setter method - * - * Same test as active_setter - * CASES: - * Default value - * Change to invalid - * Change to invalid and to valid - */ -TEST(EndpointTest, active_setter) -{ - Guid guid = random_valid_guid(); - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Default value - { - Endpoint endpoint(kind, guid, topic); - ASSERT_TRUE(endpoint.active()); - } - - // Change to invalid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - ASSERT_FALSE(endpoint.active()); - } - - // Change to invalid and to valid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - endpoint.active(true); - ASSERT_TRUE(endpoint.active()); + Endpoint endpoint = random_endpoint(i); + ASSERT_EQ(endpoint.topic.topic_qos, endpoint.topic_qos()); } } @@ -291,45 +52,28 @@ TEST(EndpointTest, active_setter) * Writer * Reader */ -TEST(EndpointTest, is_writer) +TEST(EndpointTest, is_reader_writer) { - Guid guid; - DistributedTopic topic = random_topic(); - - // Writer - { - Endpoint endpoint(EndpointKind::writer, guid, topic); - ASSERT_TRUE(endpoint.is_writer()); - } - - // Reader + // Default { - Endpoint endpoint(EndpointKind::reader, guid, topic); + Endpoint endpoint; ASSERT_FALSE(endpoint.is_writer()); + ASSERT_FALSE(endpoint.is_reader()); } -} - -/** - * Test \c Endpoint \c is_reader getter method - * - * CASES: - * Writer - * Reader - */ -TEST(EndpointTest, is_reader) -{ - Guid guid; - DistributedTopic topic = random_topic(); // Writer { - Endpoint endpoint(EndpointKind::writer, guid, topic); + Endpoint endpoint; + endpoint.kind = EndpointKind::writer; + ASSERT_TRUE(endpoint.is_writer()); ASSERT_FALSE(endpoint.is_reader()); } // Reader { - Endpoint endpoint(EndpointKind::reader, guid, topic); + Endpoint endpoint; + endpoint.kind = EndpointKind::reader; + ASSERT_FALSE(endpoint.is_writer()); ASSERT_TRUE(endpoint.is_reader()); } } diff --git a/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp b/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp index 0c5884add..09b91d5f8 100644 --- a/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp +++ b/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp @@ -20,8 +20,8 @@ #include -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; /** * Test \c Guid \c is_valid method diff --git a/ddspipe_core/test/unittest/types/topic/CMakeLists.txt b/ddspipe_core/test/unittest/types/topic/CMakeLists.txt index 1eeb42b1f..863b02ece 100644 --- a/ddspipe_core/test/unittest/types/topic/CMakeLists.txt +++ b/ddspipe_core/test/unittest/types/topic/CMakeLists.txt @@ -12,41 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -################### -# Topic # -################### - -set(TEST_NAME TopicTest) - -set(TEST_SOURCES - TopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ) - -set(TEST_LIST - is_valid - ) - -set(TEST_EXTRA_LIBRARIES - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - ############# -# DistributedTopic # +# DdsTopic # ############# set(TEST_NAME DdsTopicTest) set(TEST_SOURCES DdsTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp ) @@ -73,13 +47,13 @@ add_unittest_executable( # WildcardDdsFilterTopic # ################# -set(TEST_NAME WildcardTopicTest) +set(TEST_NAME WildcardDdsFilterTopic) set(TEST_SOURCES WildcardDdsFilterTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/IFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp ) diff --git a/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp b/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp index 4a6f610ce..01ae798e3 100644 --- a/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp +++ b/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp @@ -15,15 +15,14 @@ #include #include -#include +#include -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; using pair_topic_type = std::pair; /** - * Test DistributedTopic is_valid_dds_topic method for positive cases + * Test DdsTopic is_valid_dds_topic method for positive cases */ TEST(DdsTopicTest, is_valid_dds_topic) { @@ -37,14 +36,16 @@ TEST(DdsTopicTest, is_valid_dds_topic) {"HelloWorldTopic", "HelloWorld"}, }; + eprosima::utils::Formatter __f; + for (pair_topic_type topic : topics) { - ASSERT_TRUE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); + ASSERT_TRUE(DdsTopic::is_valid_dds_topic(topic.first, topic.second, __f)); } } /** - * Test DistributedTopic is_valid_dds_topic method for negative cases + * Test DdsTopic is_valid_dds_topic method for negative cases */ TEST(DdsTopicTest, is_valid_dds_topic_negative) { @@ -75,9 +76,12 @@ TEST(DdsTopicTest, is_valid_dds_topic_negative) // TODO add regex cases }; + eprosima::utils::Formatter __f; + for (pair_topic_type topic : topics) { - ASSERT_FALSE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); + ASSERT_FALSE(DdsTopic::is_valid_dds_topic(topic.first, topic.second, __f)) + << topic.first << " " << topic.second; } } diff --git a/ddspipe_core/test/unittest/types/topic/TopicTest.cpp b/ddspipe_core/test/unittest/types/topic/TopicTest.cpp deleted file mode 100644 index 4d33842c9..000000000 --- a/ddspipe_core/test/unittest/types/topic/TopicTest.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include - -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core::types; - -/* - * Return a list of non repeated random topic names - */ -std::vector random_topic_names() -{ - return - { - {"topic1"}, - {"topic2"}, - {"topic3"}, - - {"*"}, - {"*rt"}, - {"rt*"}, - {"rt"}, - {"rt*"}, - - {"."}, - }; -} - -/** - * Test Topic constructor and std getter methods - */ -TEST(TopicTest, is_valid) -{ - eprosima::utils::Formatter __f; - - for (const std::string& topic_name : random_topic_names()) - { - Topic topic(topic_name); - ASSERT_TRUE(topic.is_valid(__f)); - } - - ASSERT_FALSE(Topic().is_valid(__f)); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp b/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp index 9d4c3d9dd..f914552b9 100644 --- a/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp +++ b/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp @@ -17,28 +17,15 @@ #include -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; using pair_topic_type = std::pair; -// TODO: extend contains tests for regex topics - -/** - * Test WildcardDdsFilterTopic construct only with topic name - */ -TEST(WildcardTopicTest, topic_name_constructor) -{ - WildcardDdsFilterTopic topic1("topic1"); - WildcardDdsFilterTopic topic2; - - ASSERT_EQ(topic1, topic2); -} - /** * Test WildcardDdsFilterTopic contains method for positive cases */ -TEST(WildcardTopicTest, contains_wildcard) +TEST(WildcardDdsFilterTopic, contains_wildcard) { std::vector< // Test cases std::pair< @@ -84,7 +71,7 @@ TEST(WildcardTopicTest, contains_wildcard) /** * Test WildcardDdsFilterTopic matches method for positive cases */ -TEST(WildcardTopicTest, matches) +TEST(WildcardDdsFilterTopic, matches) { std::vector< // Test cases std::pair< @@ -115,10 +102,12 @@ TEST(WildcardTopicTest, matches) wt.topic_name = test_case.first.first; wt.type_name = test_case.first.second; - // For every topic to test, create a DistributedTopic and test + // For every topic to test, create a DdsTopic and test for (auto real_topic_names : test_case.second) { - DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); + DdsTopic real_topic; + real_topic.m_topic_name = real_topic_names.first; + real_topic.type_name = real_topic_names.second; ASSERT_TRUE(wt.matches(real_topic)) << "wildcard: " << wt << " ; real: " << real_topic; } @@ -128,7 +117,7 @@ TEST(WildcardTopicTest, matches) /** * Test WildcardDdsFilterTopic contains method for negative cases */ -TEST(WildcardTopicTest, non_contains_wildcard) +TEST(WildcardDdsFilterTopic, non_contains_wildcard) { std::vector< // Test cases std::pair< @@ -159,7 +148,7 @@ TEST(WildcardTopicTest, non_contains_wildcard) wt.topic_name = test_case.first.first; wt.type_name = test_case.first.second; - // For every topic to test, create a DistributedTopic and test + // For every topic to test, create a DdsTopic and test for (auto real_topic_names : test_case.second) { WildcardDdsFilterTopic contained_topic; @@ -174,7 +163,7 @@ TEST(WildcardTopicTest, non_contains_wildcard) /** * Test WildcardDdsFilterTopic matches method for negative cases */ -TEST(WildcardTopicTest, non_matches) +TEST(WildcardDdsFilterTopic, non_matches) { std::vector< // Test cases std::pair< @@ -205,10 +194,12 @@ TEST(WildcardTopicTest, non_matches) wt.topic_name = test_case.first.first; wt.type_name = test_case.first.second; - // For every topic to test, create a DistributedTopic and test + // For every topic to test, create a DdsTopic and test for (auto real_topic_names : test_case.second) { - DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); + DdsTopic real_topic; + real_topic.m_topic_name = real_topic_names.first; + real_topic.type_name = real_topic_names.second; ASSERT_FALSE(wt.matches(real_topic)); } diff --git a/ddspipe_participants/test/TestUtils/test_utils.cpp b/ddspipe_participants/test/TestUtils/test_utils.cpp deleted file mode 100644 index 5ca42dbc1..000000000 --- a/ddspipe_participants/test/TestUtils/test_utils.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright 2021 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 test_utils.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace test { - -using namespace eprosima::ddsrouter::core::types; - -Guid random_guid( - uint16_t seed /* = 1 */) -{ - Guid guid; - guid.entityId.value[3] = static_cast(seed); - guid.guidPrefix.value[0] = 0x01; - guid.guidPrefix.value[1] = 0x0f; - return guid; -} - -TopicInput::TopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set) - : name(name) - , type(type) - , keyed(keyed) - , key_set(key_set) -{ -} - -DdsTopicInput::DdsTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool reliable, - bool reliable_set) - : TopicInput(name, type, keyed, key_set) - , reliable(reliable) - , reliable_set(reliable_set) -{ -} - -WildcardTopicInput::WildcardTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool type_set) - : TopicInput(name, type, keyed, key_set) - , type_set(type_set) -{ -} - -std::set> topic_set( - std::vector topics) -{ - std::set> result; - for (DdsTopicInput input : topics) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = input.name; - new_topic->type_name = input.type; - - if (input.key_set) - { - new_topic->keyed = input.keyed; - } - - - if (input.reliable_set) - { - TopicQoS qos; - if (input.reliable) - { - qos.reliability_qos = ReliabilityKind::RELIABLE; - } - else - { - qos.reliability_qos = ReliabilityKind::BEST_EFFORT; - } - new_topic->topic_qos = qos; - new_topic->topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_fuzzy); - } - - result.insert(new_topic); - } - return result; -} - -std::set> topic_set( - std::vector topics) -{ - std::set> result; - for (WildcardTopicInput input : topics) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = input.name; - new_topic->type_name = input.type; - - if (input.key_set) - { - new_topic->keyed = input.type_set; - } - - result.insert(new_topic); - - } - return result; -} - -DomainId random_domain( - uint16_t seed /* = 0 */) -{ - return DomainId(static_cast(seed)); -} - -GuidPrefix random_guid_prefix( - uint16_t seed /* = 0 */, - bool ros /* = false */) -{ - if (ros) - { - return GuidPrefix(true, seed); - } - else - { - return GuidPrefix(static_cast(seed)); - } -} - -Address random_address( - uint16_t seed /* = 0 */) -{ - return Address("127.0.0.1", seed, seed, TransportProtocol::udp); -} - -std::set random_connection_addresses( - uint16_t seed /* = 0 */, - uint16_t size /* = 1 */, - bool ros /* = false */) -{ - std::set result; - - for (int i = 0; i < size; ++i) - { - result.insert( - DiscoveryServerConnectionAddress( - random_guid_prefix((seed * size + i) * i), - std::set
({ - random_address((seed * size + i) * i), - random_address((seed * size + i) * i + 1)}))); - } - return result; -} - -std::shared_ptr random_participant_configuration( - ParticipantKind kind, - uint16_t seed /* = 0 */) -{ - ParticipantId id("Participant" + std::to_string(seed)); - - switch (kind) - { - case ParticipantKind::simple_rtps: - return std::make_shared( - id, - kind, - false, - random_domain(seed)); - - case ParticipantKind::local_discovery_server: - case ParticipantKind::wan_discovery_server: - - { - // TODO get random values - DiscoveryServerConnectionAddress connection_address = DiscoveryServerConnectionAddress( - GuidPrefix(), - std::set
({Address()}) - ); - - return std::make_shared( - id, - kind, - false, - random_domain(seed), - random_guid_prefix(seed), - std::set
(), - std::set({connection_address}), - TlsConfiguration()); - } - - case ParticipantKind::wan_initial_peers: - - { - return std::make_shared( - id, - kind, - false, - random_domain(seed), - std::set
(), - std::set
({Address()}), - TlsConfiguration()); - } - - case ParticipantKind::echo: - { - return std::make_shared( - id, - kind, - false); - } - - // Add cases where Participants need specific arguments - default: - return std::make_shared(id, false); - } -} - -ParticipantId random_participant_id( - uint16_t seed /* = 0 */) -{ - std::vector names = { - "participant", - "PART_1", - "echo", - "Barro_p", - }; - - return ParticipantId(names[seed % names.size()] + std::to_string(seed)); -} - -ParticipantKind random_participant_kind( - bool valid /* = true */, - uint16_t seed /* = 0 */) -{ - std::vector kinds(std::begin(ALL_VALID_PARTICIPANT_KINDS), std::end(ALL_VALID_PARTICIPANT_KINDS)); - if (valid) - { - return kinds[seed % kinds.size()]; - } - else - { - kinds.push_back(ParticipantKind::invalid); - return kinds[seed % kinds.size()]; - } -} - -} /* namespace test */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/test/TestUtils/test_utils.hpp b/ddspipe_participants/test/TestUtils/test_utils.hpp deleted file mode 100644 index edf261c27..000000000 --- a/ddspipe_participants/test/TestUtils/test_utils.hpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace test { - -using namespace eprosima::ddsrouter::core::types; - -// TODO: most of the methods from this test_utils that generate random types are not very "random". -// They must be refactored to generate real random values. - -constexpr const int TEST_NUMBER_ITERATIONS = 5; - -/** - * @brief Create a \c Guid with some of its bits determined by the input - * - * @param [in] seed : differentiating value for guid creation - * @return generated Guid - * @todo Make truly random using \c seed as such - * - */ -Guid random_guid( - uint16_t seed = 1); - -struct TopicInput -{ - TopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set); - - std::string name; - std::string type; - bool keyed; - bool key_set; -}; - -struct DdsTopicInput : public TopicInput -{ - DdsTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool reliable, - bool reliable_set); - - bool reliable; - bool reliable_set; -}; - -struct WildcardTopicInput : public TopicInput -{ - WildcardTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool type_set); - - bool type_set; -}; - -std::set> topic_set( - std::vector topics); - -std::set> topic_set( - std::vector topics); - -DomainId random_domain( - uint16_t seed = 0); - -GuidPrefix random_guid_prefix( - uint16_t seed = 0, - bool ros = false); - -Address random_address( - uint16_t seed = 0); - -std::set random_connection_addresses( - uint16_t seed = 0, - uint16_t size = 1, - bool ros = false); - -std::shared_ptr random_participant_configuration( - ParticipantKind kind, - uint16_t seed = 0); - -ParticipantId random_participant_id( - uint16_t seed = 0); - -ParticipantKind random_participant_kind( - bool valid = true, - uint16_t seed = 0); - -} /* namespace test */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/test/blackbox/CMakeLists.txt b/ddspipe_participants/test/blackbox/CMakeLists.txt index 992066726..447c81e4e 100644 --- a/ddspipe_participants/test/blackbox/CMakeLists.txt +++ b/ddspipe_participants/test/blackbox/CMakeLists.txt @@ -12,6 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. - add_subdirectory(ddsrouter_core) add_subdirectory(implementations) diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp index cc2948143..bb297b9c0 100644 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -451,8 +451,8 @@ void test_WAN_communication_all( } /* namespace ddspipe */ } /* namespace eprosima */ -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; /** * Test communication in HelloWorld topic between two DDS participants created in different domains, diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index c176c5065..896372e23 100644 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -202,8 +202,8 @@ void test_local_communication( } /* namespace ddspipe */ } /* namespace eprosima */ -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; /** * Test communication in HelloWorld topic between two DDS participants created in different domains, diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp index 9a563bf3e..ef8532859 100644 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp @@ -179,8 +179,8 @@ void test_local_communication_key_dispose( } /* namespace ddspipe */ } /* namespace eprosima */ -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; /** * Test that dispose values from the publisher are correctly received by the subscriber from the router. diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp index 08df465cb..a59976214 100644 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp @@ -26,9 +26,9 @@ #include -using namespace eprosima::ddsrouter::test; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::test; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; std::vector random_payload( uint16_t seed = 1) diff --git a/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp b/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp index 6b8effbc6..ce44891d0 100644 --- a/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp +++ b/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp @@ -47,9 +47,9 @@ constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; } /* namespace ddspipe */ } /* namespace eprosima */ -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::core; +using namespace eprosima::ddspipe::core::types; /** * Test that creates a DDSRouter with a Pair of Participants of same kind. diff --git a/ddspipe_participants/test/unittest/CMakeLists.txt b/ddspipe_participants/test/unittest/CMakeLists.txt deleted file mode 100644 index a2f25d2b5..000000000 --- a/ddspipe_participants/test/unittest/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2021 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. - -# TODO(annapurna) redo this tests using new configuration -# add_subdirectory(configuration) -add_subdirectory(core) -add_subdirectory(dynamic) -add_subdirectory(efficiency) -add_subdirectory(types) diff --git a/ddspipe_participants/test/unittest/_configuration/CMakeLists.txt b/ddspipe_participants/test/unittest/_configuration/CMakeLists.txt deleted file mode 100644 index fb3995783..000000000 --- a/ddspipe_participants/test/unittest/_configuration/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2021 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. - -################################ -# DDSRouter Configuration Test # -################################ - -set(TEST_NAME ValidConfigurationTest) - -set(TEST_SOURCES - ValidConfigurationTest.cpp - ) -all_library_sources("${TEST_SOURCES}") - -set(TEST_LIST - ) - -set(TEST_EXTRA_LIBRARIES - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_participants/test/unittest/_configuration/TODO.md b/ddspipe_participants/test/unittest/_configuration/TODO.md deleted file mode 100644 index 1b0c59243..000000000 --- a/ddspipe_participants/test/unittest/_configuration/TODO.md +++ /dev/null @@ -1,5 +0,0 @@ - -# CONFIGURATION TESTS - -These tests are developed using an old API. -They should be redo in the current API when possible. diff --git a/ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp b/ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp deleted file mode 100644 index daafed6c3..000000000 --- a/ddspipe_participants/test/unittest/_configuration/_ConfigurationTest.cpp +++ /dev/null @@ -1,668 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/*************** -* CONSTRUCTOR * -***************/ - -/* - * Add a topic to a list in a yaml - * If name or type is not given, that tag will not be added - */ -void add_topic_to_list_to_yaml( - RawConfiguration& yaml, - const char* list_tag, - std::string topic_name = "", - std::string topic_type = "") -{ - RawConfiguration topic; - - if (topic_name != "") - { - topic[TOPIC_NAME_TAG] = topic_name; - } - - if (topic_type != "") - { - topic[TOPIC_TYPE_NAME_TAG] = topic_type; - } - - yaml[list_tag].push_back(topic); -} - -/* - * Add a list of topics to a list in a yaml - * If name or type is not given, that tag will not be added - */ -void add_topics_to_list_to_yaml( - RawConfiguration& yaml, - const char* list_tag, - std::set> names) -{ - for (std::pair name : names) - { - add_topic_to_list_to_yaml(yaml, list_tag, name.first, name.second); - } -} - -/* - * Add a tag with empty value - */ -void add_empty_tag_to_yaml( - RawConfiguration& yaml, - std::string tag) -{ - yaml[tag] = RawConfiguration(); -} - -/* - * Check if a topic is inside a list returned by allowlist or blocklist DDSRouter methods - */ -bool topic_in_list( - std::list> list, - WildcardDdsFilterTopic compared_topic) -{ - for (std::shared_ptr topic : list) - { - // Check class and internal variables - if (typeid(*topic) == typeid(compared_topic) && - compared_topic == *topic) - { - return true; - } - } - return false; -} - -/* - * Check if a topic is inside a list returned by real_topics DDSRouter methods - */ -bool topic_in_real_list( - std::set list, - DistributedTopic compared_topic) -{ - for (DistributedTopic topic : list) - { - // Check class and internal variables - if (typeid(topic) == typeid(compared_topic) && - compared_topic == topic) - { - return true; - } - } - return false; -} - -/* - * Random Real topic names to test different configurations - */ -std::set> random_real_topic_names() -{ - return - { - {"TopicName1", "TopicType1"}, - {"TopicName2", "TopicType2"}, - {"TopicName3", "TopicType3"}, - - {"rt/chatter", "std::str::main::other_namespace"}, - - {"real/rare_topic.name", "real/rare_topic.type"}, - }; -} - -/* - * Random Non Valid topics - */ -std::set> random_non_valid_topic_names() -{ - return - { - {"", ""}, - {"", "*"}, - }; -} - -/* - * Random Non Real topic names to test different configurations - */ -std::set> random_filter_topic_names() -{ - return - { - {"rt/chatter", "*"}, - {"*", "std::str"}, - - {"rt/chatter", "std::str*"}, - {"rt/chatter/*", "std::str"}, - {"rt/chatter/*", "std::str*"}, - - {"rt/chatter", "*::std::str"}, - {"*/rt/chatter", "std::str"}, - {"*/rt/chatter", "*::std::str"}, - - {"rt/chatter", "*::std::str*"}, - {"*/rt/chatter/*", "std::str"}, - {"*/rt/chatter/*", "*::std::str*"}, - - {"rt/chatter", ""}, - {"*/rt/chatter/*", ""}, - }; -} - -/* - * Unioin of real and non real topic names - */ -std::set> random_topic_names() -{ - std::set> all_topics; - - std::set> real_topics = random_real_topic_names(); - std::set> abs_topics = random_filter_topic_names(); - std::set_union( - real_topics.begin(), real_topics.end(), - abs_topics.begin(), abs_topics.end(), - std::inserter(all_topics, all_topics.begin())); - - std::set> non_valid_topics = random_non_valid_topic_names(); - all_topics.insert(non_valid_topics.begin(), non_valid_topics.end()); - - return all_topics; -} - -/* - * Number of valid topics in random_topic_names() - */ -size_t random_topic_names_number_valid_topics() -{ - return random_real_topic_names().size() + random_filter_topic_names().size(); -} - -/* - * Random participant id - * - * TODO: create really random names - */ -std::string random_participant_name( - uint16_t seed) -{ - return std::string("PartName_") + std::to_string(seed); -} - -/* - * Random participant kind - * - * WARNING: the max_types_available must be updated with each new type added - */ -ParticipantKind random_participant_kind( - uint16_t seed = 0) -{ - // Avoid Invalid type - return ALL_VALID_PARTICIPANT_KINDS[seed % ALL_VALID_PARTICIPANT_KINDS.size()]; -} - -/* - * Random participant configuration - * - * TODO: create really random configurations - */ -RawConfiguration random_participant_configuration( - uint16_t seed) -{ - RawConfiguration config; - - for (int i = (seed); i > 0; i--) - { - std::string tag("tag" + std::to_string(i)); - - if (i % 4 == 0) - { - // Each 4 tags add an array - config[tag].push_back("value1"); - config[tag].push_back("value2"); - } - else if (i % 2 == 0) - { - // Each 4 tags add a map - RawConfiguration sub_map; - sub_map["x"] = "y"; - sub_map["a"] = "b"; - config[tag] = sub_map; - } - else - { - // The rest are direct values - config[tag] = "Random value"; - } - } - - config[PARTICIPANT_KIND_TAG] = random_participant_kind().to_string(); - - return config; -} - -/** - * Test Configuration constructor to check it does not fail - * - * CASES: - * Empty configuration - * Random configuration - */ -TEST(ConfigurationTest, constructor) -{ - // Empty case - RawConfiguration empty_yaml; - DDSRouterConfiguration config_empty(empty_yaml); - - // Random case - RawConfiguration random_config; - random_config["RAND_TAG_1"] = "rand_val_1"; - random_config["RAND_TAG_2"] = "rand_val_2"; - random_config["RAND_TAG_3"].push_back(314); - DDSRouterConfiguration config_random(random_config); -} - -/**************************** -* PUBLIC METHODS STD CASES * -****************************/ - -/** - * Test get participants configurations - * - * CASES: - * Empty configuration - * Other tags that are not participant valid ids - * One Participant Configuration - * Many Participant Configurations - * - * TODO: Change yaml tags for their proper external tags (constexpr) - */ -TEST(ConfigurationTest, participants_configurations) -{ - { - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.participants_configurations().empty()); - } - - { - // Other tags that are not participant valid ids - RawConfiguration yaml2; - add_topics_to_list_to_yaml(yaml2, ALLOWLIST_TAG, random_filter_topic_names()); - add_topics_to_list_to_yaml(yaml2, BLOCKLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.participants_configurations().empty()); - } - - { - // One Participant Configuration - RawConfiguration listening_addresses; - RawConfiguration address1; - RawConfiguration address2; - address1["ip"] = "127.0.0.1"; - address1["port"] = "31415"; - listening_addresses.push_back(address1); - address2["ip"] = "8.8.8.8"; - address2["port"] = "6666"; - listening_addresses.push_back(address2); - - RawConfiguration participant_config; - participant_config[PARTICIPANT_KIND_TAG] = random_participant_kind().to_string(); - participant_config["listening-addresses"] = listening_addresses; - - std::string participant_name_str = "wanParticipant"; - ParticipantId participant_name(participant_name_str); - RawConfiguration yaml3; - yaml3[participant_name_str] = participant_config; - - DDSRouterConfiguration config3(yaml3); - auto result3 = config3.participants_configurations(); - ASSERT_EQ(1, result3.size()); - EXPECT_EQ(participant_name, result3.front().id()); - EXPECT_EQ(ParticipantConfiguration(ParticipantId(participant_name_str), participant_config), result3.front()); - } - - { - // Many Participant Configurations - uint16_t participants_num = 10; - RawConfiguration yaml4; - for (int i = 0; i < participants_num; i++) - { - yaml4[random_participant_name(i)] = random_participant_configuration(i); - } - DDSRouterConfiguration config4(yaml4); - auto result4 = config4.participants_configurations(); - ASSERT_EQ(result4.size(), participants_num); - - // For every participant in participants_configurations, check that the id is inside the actual ids stored - // TODO: check the configurations are actually the same, implement yaml compare - for (int i = 0; i < participants_num; i++) - { - ParticipantId expected_id(random_participant_name(i)); - bool in_configurations = false; - for (auto part_config: result4) - { - // They may not be sorted, so it must be checked that this is the actual participant config - // it is being tested - if (part_config.id() == expected_id) - { - in_configurations = true; - break; - } - } - ASSERT_TRUE(in_configurations); - } - } -} - -/** - * Test get real topics from allowlist - * - * CASES: - * Empty configuration - * Empty allowlist - * Allowlist with only non Real topics - * Allowlist with only Real topics - * Allowlist with random topics - */ -TEST(ConfigurationTest, real_topics) -{ - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.real_topics().empty()); - - // Empty allowlist - RawConfiguration yaml2; - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic2", "type2"); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.real_topics().empty()); - - // Allowlist with only non Real topics - RawConfiguration yaml3; - add_topics_to_list_to_yaml(yaml3, ALLOWLIST_TAG, random_filter_topic_names()); - DDSRouterConfiguration config3(yaml3); - EXPECT_TRUE(config3.real_topics().empty()); - - // Allowlist with only Real topics - RawConfiguration yaml4; - add_topics_to_list_to_yaml(yaml4, ALLOWLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config4(yaml4); - auto result4 = config4.real_topics(); - EXPECT_FALSE(result4.empty()); - for (auto random_topic : random_real_topic_names()) - { - DistributedTopic topic(random_topic.first, random_topic.second); - EXPECT_TRUE(topic_in_real_list(result4, topic)); - } - - // Allowlist with random topics - RawConfiguration yaml5; - add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_topic_names()); - DDSRouterConfiguration config5(yaml5); - auto result5 = config5.real_topics(); - EXPECT_FALSE(result5.empty()); - - uint16_t real_topics = 0; - for (auto random_topic : random_topic_names()) - { - bool real_topic = DistributedTopic::is_valid_dds_topic(random_topic.first, random_topic.second); - - if (real_topic) - { - ++real_topics; - DistributedTopic topic(random_topic.first, random_topic.second); - EXPECT_TRUE(topic_in_real_list(result5, topic)) << topic; - } - } - EXPECT_EQ(real_topics, result5.size()); -} - -/********************************* -* PUBLIC METHODS SPECIFIC CASES * -*********************************/ - -/** - * Test get allowlist with wildcards from yaml - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Empty configuration - * Empty allowlist - * Allowlist with some examples - * Allowlist with random topics - * Allowlist and blocklist with random topics - */ -TEST(ConfigurationTest, allowlist_wildcard) -{ - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.allowlist().empty()); - - // Empty allowlist - RawConfiguration yaml2; - add_empty_tag_to_yaml(yaml2, ALLOWLIST_TAG); - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml2, BLOCKLIST_TAG, "topic2", "type2"); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.allowlist().empty()); - - // Empty allowlist - RawConfiguration yaml3; - add_topic_to_list_to_yaml(yaml3, ALLOWLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml3, ALLOWLIST_TAG, "topic2*", "type2*"); - DDSRouterConfiguration config3(yaml3); - auto result3 = config3.allowlist(); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic1"), std::string("type1")))); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic2*"), std::string("type2*")))); - - // Allowlist with random topics - RawConfiguration yaml4; - add_topics_to_list_to_yaml(yaml4, ALLOWLIST_TAG, random_topic_names()); - DDSRouterConfiguration config4(yaml4); - EXPECT_EQ(config4.allowlist().size(), random_topic_names_number_valid_topics()); - - // Allowlist and blocklist with random topics - RawConfiguration yaml5; - add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_filter_topic_names()); - add_topics_to_list_to_yaml(yaml5, BLOCKLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config5(yaml5); - EXPECT_EQ(config5.allowlist().size(), random_filter_topic_names().size()); -} - -/** - * Test get blocklist with wildcards from yaml - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Empty configuration - * Empty blocklist - * Blocklist with some examples - * Blocklist with random topics - * Blocklist and allowlist with random topics - */ -TEST(ConfigurationTest, blocklist_wildcard) -{ - // Empty configuration - RawConfiguration yaml1; - DDSRouterConfiguration config1(yaml1); - EXPECT_TRUE(config1.blocklist().empty()); - - // Empty blocklist - RawConfiguration yaml2; - add_empty_tag_to_yaml(yaml2, BLOCKLIST_TAG); - add_topic_to_list_to_yaml(yaml2, ALLOWLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml2, ALLOWLIST_TAG, "topic2", "type2"); - DDSRouterConfiguration config2(yaml2); - EXPECT_TRUE(config2.blocklist().empty()); - - // Empty blocklist - RawConfiguration yaml3; - add_topic_to_list_to_yaml(yaml3, BLOCKLIST_TAG, "topic1", "type1"); - add_topic_to_list_to_yaml(yaml3, BLOCKLIST_TAG, "topic2*", "type2*"); - DDSRouterConfiguration config3(yaml3); - auto result3 = config3.blocklist(); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic1"), std::string("type1")))); - EXPECT_TRUE(topic_in_list(result3, WildcardDdsFilterTopic(std::string("topic2*"), std::string("type2*")))); - - // Blocklist with random topics - RawConfiguration yaml4; - add_topics_to_list_to_yaml(yaml4, BLOCKLIST_TAG, random_topic_names()); - DDSRouterConfiguration config4(yaml4); - EXPECT_EQ(config4.blocklist().size(), random_topic_names_number_valid_topics()); - - // Blocklist and allowlist with random topics - RawConfiguration yaml5; - add_topics_to_list_to_yaml(yaml5, BLOCKLIST_TAG, random_filter_topic_names()); - add_topics_to_list_to_yaml(yaml5, ALLOWLIST_TAG, random_real_topic_names()); - DDSRouterConfiguration config5(yaml5); - EXPECT_EQ(config5.blocklist().size(), random_filter_topic_names().size()); -} - -/** - * Test get blocklist with wildcards from yaml - * - * TODO: when regex is implemented, create a common test case - */ -TEST(ConfigurationTest, allowlist_and_blocklist) -{ - RawConfiguration yaml; - add_topics_to_list_to_yaml(yaml, ALLOWLIST_TAG, random_real_topic_names()); - add_topics_to_list_to_yaml(yaml, BLOCKLIST_TAG, random_filter_topic_names()); - DDSRouterConfiguration config(yaml); - EXPECT_EQ(config.allowlist().size(), random_real_topic_names().size()); - EXPECT_EQ(config.blocklist().size(), random_filter_topic_names().size()); -} - -/****************************** -* PUBLIC METHODS ERROR CASES * -******************************/ - -/** - * Test DDSRouterConfiguration constructor to check it does not fail - * - * CASES: - * Array as base configuration - * Scalar as base configuration - * String as base configuration - */ -TEST(ConfigurationTest, constructor_fail) -{ - // Array case - RawConfiguration array_config; - array_config.push_back("rand_val_1"); - array_config.push_back("rand_val_2"); - EXPECT_THROW(DDSRouterConfiguration dc(array_config), utils::ConfigurationException); - - // Scalar case - RawConfiguration scalar_config; - scalar_config = 42; - EXPECT_THROW(DDSRouterConfiguration dc(scalar_config), utils::ConfigurationException); - - // Scalar case - RawConfiguration string_config; - string_config = "non_valid_config"; - EXPECT_THROW(DDSRouterConfiguration dc(string_config), utils::ConfigurationException); -} - -/** - * Test get participants configurations negative cases - */ -TEST(ConfigurationTest, participants_configurations_fail) -{ - // There is currently no way to induce an error when getting participant configurations - ASSERT_TRUE(true); -} - -/** - * Test get real topics from allowlist negative cases - * - * CASES: - * Map instead of array in topics - */ -TEST(ConfigurationTest, real_topics_fail) -{ - // Map instead of array in allowlist - RawConfiguration map_config; - map_config["key1"] = "value1"; - RawConfiguration yaml1; - yaml1[ALLOWLIST_TAG] = map_config; - DDSRouterConfiguration dc(yaml1); - EXPECT_THROW(dc.real_topics(), utils::ConfigurationException); -} - -/** - * Test get allowlist with wildcards from yaml negative cases - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Map instead of array in topics - */ -TEST(ConfigurationTest, allowlist_wildcard_fail) -{ - // Map instead of array in allowlist - RawConfiguration map_config; - map_config["key1"] = "value1"; - RawConfiguration yaml1; - yaml1[ALLOWLIST_TAG] = map_config; - DDSRouterConfiguration dc(yaml1); - EXPECT_THROW(dc.allowlist(), utils::ConfigurationException); -} - -/** - * Test get blocklist with wildcards from yaml negative cases - * - * TODO: when regex is implemented, create a common test case - * - * CASES: - * Map instead of array in topics - */ -TEST(ConfigurationTest, blocklist_wildcard_fail) -{ - // Map instead of array in blocklist - RawConfiguration map_config; - map_config["key1"] = "value1"; - RawConfiguration yaml1; - yaml1[BLOCKLIST_TAG] = map_config; - DDSRouterConfiguration dc(yaml1); - EXPECT_THROW(dc.blocklist(), utils::ConfigurationException); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/core/CMakeLists.txt b/ddspipe_participants/test/unittest/core/CMakeLists.txt deleted file mode 100644 index 8d9fde3f3..000000000 --- a/ddspipe_participants/test/unittest/core/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(participants_database) diff --git a/ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt b/ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt deleted file mode 100644 index bf91b8503..000000000 --- a/ddspipe_participants/test/unittest/core/participants_database/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2021 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. - -######################### -# Participants Database # -######################### - -set(TEST_NAME ParticipantsDatabaseTest) - -set(TEST_SOURCES - ParticipantsDatabaseTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantsDatabase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participants/reader/auxiliar/BlankReader.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participants/writer/auxiliar/BlankWriter.cpp - ) -all_header_sources("${TEST_SOURCES}") - -set(TEST_LIST - add_participant - empty - get_participant - get_participants_ids - get_participants_map - pop - size - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp b/ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp deleted file mode 100644 index 34ec3b6b5..000000000 --- a/ddspipe_participants/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include -#include -#include -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -/** - * This class is used to expose protected methods of the parent class - * so they can be tested. - */ -class ParticipantsDatabase : public eprosima::ddsrouter::core::ParticipantsDatabase -{ -public: - - ParticipantsDatabase() - { - } - - ParticipantsDatabase( - std::map> participants) - : ParticipantsDatabase() - { - participants_ = participants; - } - - std::shared_ptr pop( - const ParticipantId& id) noexcept - { - return pop_(id); - } - - std::shared_ptr pop() noexcept - { - return pop_(); - } - - void add_participant( - ParticipantId id, - std::shared_ptr participant, - std::size_t expected_size) - { - add_participant_(id, participant); - // Verify correct insertion - auto it = participants_.find(id); - ASSERT_EQ(it->second, participant); - ASSERT_EQ(participants_.size(), expected_size); - } - -}; - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/********************* -* PROTECTED METHODS ** -*********************/ - -/** - * Test the addition of a participant to the database - * - * CASES: - * - * Add not stored participant - * Add already stored participant - */ -TEST(ParticipantsDatabaseTest, add_participant) -{ - std::shared_ptr participants_database = std::make_shared(); - // Check database is empty - ASSERT_TRUE(participants_database->empty()); - - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - // Insert participant - participants_database->add_participant(participant->id(), participant, 1); - - // Reinsert and check it throws an error - ASSERT_THROW( - participants_database->add_participant( - participant->id(), - participant, 1), - eprosima::utils::InconsistencyException); -} - -/** - * Test the extraction of a participant from the database - * - * CASES: - * Empty database - * Pop random participant - * Pop specific participant - * Pop not stored participant - * Pop stored participant - */ -TEST(ParticipantsDatabaseTest, pop) -{ - std::shared_ptr participants_database = std::make_shared(); - ASSERT_TRUE(participants_database->empty()); - // Empty database, no participant should be popped - ASSERT_TRUE(participants_database->pop() == nullptr); - - ParticipantId id1("void_p1"); - std::shared_ptr participant1 = std::make_shared(id1); - ParticipantId id2("void_p2"); - std::shared_ptr participant2 = std::make_shared(id2); - // Pop not yet stored participant - ASSERT_TRUE(participants_database->pop(id1) == nullptr); - ASSERT_TRUE(participants_database->pop(id2) == nullptr); - - // Insert participants into database - participants_database->add_participant(participant1->id(), participant1, 1); - participants_database->add_participant(participant2->id(), participant2, 2); - - // Pop stored participants - ASSERT_EQ(participants_database->pop(id1), participant1); - ASSERT_EQ(participants_database->pop(), participant2); - // Participants should have been removed - ASSERT_TRUE(participants_database->get_participant(id1) == nullptr); - ASSERT_TRUE(participants_database->get_participant(id2) == nullptr); - ASSERT_TRUE(participants_database->empty()); -} - -/********************* -* PUBLIC METHODS ** -*********************/ - -/** - * Test \c ParticipantsDatabase \c empty method - * - * CASES: - * Empty database - * Non-empty database - */ -TEST(ParticipantsDatabaseTest, empty) -{ - std::shared_ptr participants_database = std::make_shared(); - // Empty database - ASSERT_TRUE(participants_database->empty()); - - // Non-empty database - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - participants_database->add_participant(participant->id(), participant, 1); - ASSERT_FALSE(participants_database->empty()); -} - -/** - * Test \c ParticipantsDatabase \c get_participant method - * - * CASES: - * Empty configuration - * Random configuration - */ -TEST(ParticipantsDatabaseTest, get_participant) -{ - std::shared_ptr participants_database = std::make_shared(); - - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - participants_database->add_participant(participant->id(), participant, 1); - - ASSERT_EQ(participants_database->get_participant(id), participant); -} - -/** - * Test \c ParticipantsDatabase \c get_participants_ids method - */ -TEST(ParticipantsDatabaseTest, get_participants_ids) -{ - std::shared_ptr participants_database = std::make_shared(); - - ParticipantId id1("void_p1"); - std::shared_ptr participant1 = std::make_shared(id1); - participants_database->add_participant(participant1->id(), participant1, 1); - - ParticipantId id2("void_p2"); - std::shared_ptr participant2 = std::make_shared(id2); - participants_database->add_participant(participant2->id(), participant2, 2); - - std::set ids {id2, id1}; - ASSERT_EQ(ids, participants_database->get_participants_ids()); -} - -/** - * Test \c ParticipantsDatabase \c get_participants_map getter method - */ -TEST(ParticipantsDatabaseTest, get_participants_map) -{ - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - std::map> participants = {{id, participant}}; - - std::shared_ptr participants_database = std::make_shared( - participants); - ASSERT_EQ(participants_database->get_participants_map(), participants); -} - -/** - * Test \c ParticipantsDatabase \c size getter method - */ -TEST(ParticipantsDatabaseTest, size) -{ - std::shared_ptr participants_database = std::make_shared(); - // Check database is empty - ASSERT_EQ(participants_database->size(), 0u); - - ParticipantId id_1("void_part"); - std::shared_ptr participant_1 = std::make_shared(id_1); - // Insert participant_1 - participants_database->add_participant(participant_1->id(), participant_1, 1); - ASSERT_EQ(participants_database->size(), 1u); - - ParticipantId id_2("simple_part"); - std::shared_ptr participant_2 = std::make_shared(id_2); - // Insert participant_2 - participants_database->add_participant(participant_2->id(), participant_2, 2); - ASSERT_EQ(participants_database->size(), 2u); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/dynamic/CMakeLists.txt b/ddspipe_participants/test/unittest/dynamic/CMakeLists.txt deleted file mode 100644 index 1175745b3..000000000 --- a/ddspipe_participants/test/unittest/dynamic/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(allowed_topic_list) -add_subdirectory(discovery_database) diff --git a/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp b/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp deleted file mode 100644 index 7bae70698..000000000 --- a/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp +++ /dev/null @@ -1,502 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -using pair_topic_type = std::pair; - -/****************** -* FILTER METHODS * -******************/ - -/* - * Add a topic to a list - * - * TODO: Add regex when implemented - */ -void add_topic_to_list( - std::set>& list, - pair_topic_type topic_name, - bool wildcard = true) -{ - if (wildcard) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = topic_name.first; - new_topic->type_name = topic_name.second; - - list.insert(new_topic); - } -} - -/* - * Add several topic to a list - * - * TODO: Add regex when implemented - */ -void add_topics_to_list( - std::set>& list, - std::vector topic_names, - bool wildcard = true) -{ - if (wildcard) - { - for (pair_topic_type topic_name : topic_names) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = topic_name.first; - new_topic->type_name = topic_name.second; - - list.insert(new_topic); - } - } -} - -/* - * Create an AllowedTopicList object with the allowlist and blocklist given by argument - * Check that all topics in real_topics_positive are allowed by the AllowedTopicList - * Check that all topics in real_topics_negative are not allowed by the AllowedTopicList - */ -void generic_test( - const std::vector& allowlist_topics, - const std::vector& blocklist_topics, - const std::vector& real_topics_positive, - const std::vector& real_topics_negative) -{ - // Create AllowedTopicList object - std::set> allowlist; - std::set> blocklist; - - add_topics_to_list(allowlist, allowlist_topics); - add_topics_to_list(blocklist, blocklist_topics); - - AllowedTopicList atl(allowlist, blocklist); - - // Test positive cases - for (pair_topic_type topic_name : real_topics_positive) - { - DistributedTopic topic(topic_name.first, topic_name.second); - ASSERT_TRUE(atl.is_topic_allowed(topic)); - } - - // Test negative cases - for (pair_topic_type topic_name : real_topics_negative) - { - DistributedTopic topic(topic_name.first, topic_name.second); - ASSERT_FALSE(atl.is_topic_allowed(topic)); - } -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using default constructor - */ -TEST(AllowedTopicListTest, is_topic_allowed__default_constructor) -{ - AllowedTopicList atl; - - std::vector real_topics = - { - {"topic1", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - for (pair_topic_type topic_name : real_topics) - { - DistributedTopic topic(topic_name.first, topic_name.second); - - ASSERT_TRUE(atl.is_topic_allowed(topic)); - } -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using empty lists - */ -TEST(AllowedTopicListTest, is_topic_allowed__empty_list) -{ - std::vector allowlist_topics; - std::vector blocklist_topics; - std::vector real_topics_negative; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple blocklist: only with real topics - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_blocklist) -{ - std::vector allowlist_topics; - - std::vector blocklist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_positive = - { - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex blocklist: with wildcards that superpose - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_blocklist) -{ - std::vector allowlist_topics; - - std::vector blocklist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt/chatter*", "std::*"}, - }; - - std::vector real_topics_positive = - { - {"topic2", "type2"}, - {"rt/topic_info", "std::std_msgs::string"}, - {"rt/chatter/pub", "std_type"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/chatter/pub", "std::type"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple allowlist: only with real topics - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist) -{ - std::vector blocklist_topics; - - std::vector allowlist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1_"}, - {"topic1_", "type1"}, - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex allowlist: with wildcards that superpose - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist) -{ - std::vector blocklist_topics; - - std::vector allowlist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt/chatter*", "std::*"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"OtherTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/chatter/pub", "std::string"}, - }; - - std::vector real_topics_negative = - { - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"rt/pub", "std::std_msgs::string"}, - {"rt/chatter", "std_type"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple allowlist and simple blocklist: only with real topics - * Lists do not superpose to each other - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist) -{ - std::vector allowlist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector blocklist_topics = - { - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type2"}, - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/pub", "std"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex allowlist and complex blocklist: with wildcards that superpose - * Lists do not superpose to each other - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist) -{ - std::vector allowlist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt/pub*", "std_type::*"}, - }; - - std::vector blocklist_topics = - { - {"topic2", "*"}, - {"*", "HelloWorldType"}, - {"rt/chatter*", "std*"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"OtherTopic", "HelloWorld"}, - {"rt/pub/topic", "std_type::string"}, - {"rt/pub", "std_type::string"}, - }; - - std::vector real_topics_negative = - { - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"OtherTopic", "HelloWorldType"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/chatter/pub", "std"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple allowlist and simple blocklist: only with real topics - * Blocklist has topics that block the allowlist ones - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist_entangled) -{ - std::vector allowlist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector blocklist_topics = - { - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type2"}, - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/pub", "std"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex allowlist and complex blocklist: with wildcards that superpose - * Blocklist has topics that block the allowlist ones - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist_entangled) -{ - std::vector allowlist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt*", "std*"}, - }; - - std::vector blocklist_topics = - { - {"topic1", "type*"}, - {"*HelloWorld", "HelloWorld"}, - {"rt/chatter*", "std_type::std_msgs*"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "wtype1"}, - {"topic1", "wtype2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"OtherTopic", "HelloWorld"}, - {"rt/pub", "std_type::std_msgs::string"}, - {"rt/chatter", "std::string"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"TopicHelloWorld", "HelloWorld"}, - {"OtherHelloWorld", "HelloWorld"}, - {"rt/chatter", "std_type::std_msgs::string"}, - {"rt/chatter/pub", "std_type::std_msgs::string"}, - {"chatter", "std::std_msgs::int"}, - }; - - generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt b/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt deleted file mode 100644 index a145292df..000000000 --- a/ddspipe_participants/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2021 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. - -set(TEST_NAME AllowedTopicListTest) - -set(TEST_SOURCES - AllowedTopicListTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic/AllowedTopicList.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ) -all_header_sources("${TEST_SOURCES}") - -set(TEST_LIST - is_topic_allowed__default_constructor - is_topic_allowed__empty_list - is_topic_allowed__simple_blocklist - is_topic_allowed__complex_blocklist - is_topic_allowed__simple_allowlist - is_topic_allowed__complex_allowlist - is_topic_allowed__simple_allowlist_and_blocklist - is_topic_allowed__complex_allowlist_and_blocklist - is_topic_allowed__simple_allowlist_and_blocklist_entangled - is_topic_allowed__complex_allowlist_and_blocklist_entangled - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt b/ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt deleted file mode 100644 index ebcac32bc..000000000 --- a/ddspipe_participants/test/unittest/dynamic/discovery_database/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2021 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. - -###################### -# Discovery Database # -###################### - -set(TEST_NAME DiscoveryDatabaseTest) - -set(TEST_SOURCES - DiscoveryDatabaseTest.cpp - ) -all_library_sources("${TEST_SOURCES}") # Add all requirements for use test_utils - -set(TEST_LIST - topic_exists - endpoint_exists - add_endpoint - update_endpoint - erase_endpoint - get_endpoint - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp b/ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp deleted file mode 100644 index 14fc05046..000000000 --- a/ddspipe_participants/test/unittest/dynamic/discovery_database/DiscoveryDatabaseTest.cpp +++ /dev/null @@ -1,250 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace eprosima::ddsrouter::test; -using namespace eprosima::utils; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -/** - * This class is used to expose protected methods of the parent class - * so they can be tested. - */ -class DiscoveryDatabase : public eprosima::ddsrouter::core::DiscoveryDatabase -{ -public: - - DiscoveryDatabase() - : eprosima::ddsrouter::core::DiscoveryDatabase() - { - start(); - } - - bool add_endpoint_protected( - const Endpoint& new_endpoint) - { - return add_endpoint_(new_endpoint); - } - - bool update_endpoint_protected( - const Endpoint& new_endpoint) - { - return update_endpoint_(new_endpoint); - } - - ReturnCode erase_endpoint_protected( - const Endpoint& endpoint_to_erase) - { - return erase_endpoint_(endpoint_to_erase); - } - -}; - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/** - * Test \c DiscoveryDatabase \c topic_exists method - * - * CASES: - * Topic not present in database - * Topic present in database - */ -TEST(DiscoveryDatabaseTest, topic_exists) -{ - test::DiscoveryDatabase discovery_database; - Guid guid_1 = random_guid(1); - Guid guid_2 = random_guid(2); - DistributedTopic topic("test", "test"); - Endpoint endpoint_1(EndpointKind::reader, guid_1, topic); - Endpoint endpoint_2(EndpointKind::reader, guid_2, topic); - - ASSERT_FALSE(discovery_database.topic_exists(topic)); - discovery_database.add_endpoint_protected(endpoint_1); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - discovery_database.add_endpoint_protected(endpoint_2); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - discovery_database.erase_endpoint_protected(endpoint_1); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - discovery_database.erase_endpoint_protected(endpoint_2); - ASSERT_FALSE(discovery_database.topic_exists(topic)); -} - -/** - * Test \c DiscoveryDatabase \c endpoint_exists method - * - * CASES: - * Endpoint not present in database - * Endpoint present in database - */ -TEST(DiscoveryDatabaseTest, endpoint_exists) -{ - test::DiscoveryDatabase discovery_database; - Guid guid; - DistributedTopic topic("test", "test"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); - discovery_database.add_endpoint_protected(endpoint); - ASSERT_TRUE(discovery_database.endpoint_exists(guid)); - discovery_database.erase_endpoint_protected(endpoint); - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); -} - -/** - * Test \c DiscoveryDatabase \c add_endpoint method - * - * CASES: - * Endpoint to insert not present - * Endpoint to insert already present and active - * Endpoint to insert already present but inactive - */ -TEST(DiscoveryDatabaseTest, add_endpoint) -{ - test::DiscoveryDatabase discovery_database; - DistributedTopic topic("original", "original"); - // Create active endpoint - Guid active_guid = random_guid(1); - Endpoint active_endpoint(EndpointKind::reader, active_guid, topic); - // Create inactive endpoint - Guid inactive_guid = random_guid(2); - Endpoint inactive_endpoint(EndpointKind::reader, inactive_guid, topic); - inactive_endpoint.active(false); - - // Insert endpoints - ASSERT_TRUE(discovery_database.add_endpoint_protected(active_endpoint)); - ASSERT_EQ(discovery_database.get_endpoint(active_guid), active_endpoint); - ASSERT_TRUE(discovery_database.add_endpoint_protected(inactive_endpoint)); - ASSERT_EQ(discovery_database.get_endpoint(inactive_guid), inactive_endpoint); - - // Add new endpoint with same guid as already stored active endpoint - // Should throw \c InconsistencyException - DistributedTopic new_topic("new", "new"); - Endpoint active_new_endpoint(EndpointKind::reader, active_guid, new_topic); - ASSERT_THROW(discovery_database.add_endpoint_protected(active_new_endpoint), InconsistencyException); - - // Add new endpoint with same guid as already stored inactive endpoint - // Should update entry - Endpoint inactive_new_endpoint(EndpointKind::reader, inactive_guid, new_topic); - ASSERT_TRUE(discovery_database.add_endpoint_protected(inactive_new_endpoint)); - ASSERT_EQ(discovery_database.get_endpoint(inactive_guid), inactive_new_endpoint); -} - -/** - * Test \c DiscoveryDatabase \c update_endpoint method - * - * CASES: - * Endpoint to be updated not present in database - * Endpoint to be updated present in database - */ -TEST(DiscoveryDatabaseTest, update_endpoint) -{ - test::DiscoveryDatabase discovery_database; - Guid guid = random_guid(1); - DistributedTopic topic("original", "original"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - DistributedTopic new_topic("new", "new"); - Endpoint new_endpoint(EndpointKind::reader, guid, new_topic); - // Endpoint to be updated not yet inserted - ASSERT_THROW(discovery_database.update_endpoint_protected(new_endpoint), InconsistencyException); - - // Insert endpoint - ASSERT_TRUE(discovery_database.add_endpoint_protected(endpoint)); - ASSERT_TRUE(discovery_database.topic_exists(topic)); - ASSERT_FALSE(discovery_database.topic_exists(new_topic)); - ASSERT_EQ(discovery_database.get_endpoint(guid), endpoint); - - // Update endpoint - ASSERT_TRUE(discovery_database.update_endpoint_protected(new_endpoint)); - ASSERT_FALSE(discovery_database.topic_exists(topic)); - ASSERT_TRUE(discovery_database.topic_exists(new_topic)); - ASSERT_EQ(discovery_database.get_endpoint(guid), new_endpoint); -} - -/** - * Test \c DiscoveryDatabase \c erase_endpoint method - * - * CASES: - * Endpoint to erase not present in database - * Endpoint to erase present in database - */ -TEST(DiscoveryDatabaseTest, erase_endpoint) -{ - test::DiscoveryDatabase discovery_database; - Guid guid = random_guid(1); - DistributedTopic topic("test", "test"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - - // Endpoint to erase not yet inserted - ASSERT_THROW(discovery_database.erase_endpoint_protected(endpoint), InconsistencyException); - - // Insert endpoint - discovery_database.add_endpoint_protected(endpoint); - ASSERT_TRUE(discovery_database.endpoint_exists(guid)); - - // Erase endpoint - ASSERT_EQ(discovery_database.erase_endpoint_protected(endpoint), ReturnCode::RETCODE_OK); - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); -} - -/** - * Test \c DiscoveryDatabase \c get_endpoint method - * - * CASES: - * Endpoint to retrieve not present in database - * Endpoint to retrieve present in database - */ -TEST(DiscoveryDatabaseTest, get_endpoint) -{ - test::DiscoveryDatabase discovery_database; - Guid guid = random_guid(1); - DistributedTopic topic("test", "test"); - Endpoint endpoint(EndpointKind::reader, guid, topic); - - // Try to fetch a not stored endpoint - ASSERT_FALSE(discovery_database.endpoint_exists(guid)); - ASSERT_THROW(discovery_database.get_endpoint(guid).kind(), InconsistencyException); - - // Insert and get endpoint - discovery_database.add_endpoint_protected(endpoint); - ASSERT_TRUE(discovery_database.endpoint_exists(guid)); - ASSERT_EQ(discovery_database.get_endpoint(guid), endpoint); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/efficiency/CMakeLists.txt b/ddspipe_participants/test/unittest/efficiency/CMakeLists.txt deleted file mode 100644 index 0fd30faee..000000000 --- a/ddspipe_participants/test/unittest/efficiency/CMakeLists.txt +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright 2022 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. - -############################## -# Interface PayloadPool Test # -############################## - -set(TEST_NAME PayloadPoolTest) - -set(TEST_SOURCES - PayloadPoolTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp - ) - -set(TEST_LIST - reserve - reserve_negative - release - reserve_and_release_counter - reserve_and_release_counter_negative - is_clean - get_payload_cache_change - get_payload_from_src_cache_change - get_payload_from_src_cache_change_negative - release_payload_cache_change - release_payload_cache_change_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -######################## -# Map PayloadPool Test # -######################## - -set(TEST_NAME MapPayloadPoolTest) - -set(TEST_SOURCES - MapPayloadPoolTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/MapPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp - ) - -set(TEST_LIST - get_payload - get_payload_from_src - get_payload_from_src_no_owner - get_payload_from_src_negative - release_payload - release_payload_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -######################## -# Fast PayloadPool Test # -######################## - -set(TEST_NAME FastPayloadPoolTest) - -set(TEST_SOURCES - FastPayloadPoolTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/FastPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp - ) - -set(TEST_LIST - get_payload - get_payload_from_src - get_payload_from_src_no_owner - get_payload_from_src_negative - release_payload - release_payload_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp b/ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp deleted file mode 100644 index 497878c7c..000000000 --- a/ddspipe_participants/test/unittest/efficiency/FastPayloadPoolTest.cpp +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -#include -#include - -#include -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -const constexpr unsigned int TEST_NUMBER = 5; -const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -/** - * @brief Mock over FastPayloadPool implementing public access to private variables. - * - */ -class MockFastPayloadPool : public FastPayloadPool -{ -public: - - using FastPayloadPool::FastPayloadPool; - - uint64_t pointers_stored() - { - return reserve_count_ - release_count_; - } - - void release_all( - std::vector& payloads) - { - for (auto& payload : payloads) - { - release_payload(payload); - } - } - -}; - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/* - * This tests does not check the methods calling cacheChange, this is tested in generic PayloadPool test. - */ - -/** - * Test get_payload method for new changes - * - * CASES: - * Get N different pointers - * fail reserve memory - */ -TEST(FastPayloadPoolTest, get_payload) -{ - // Get N different pointers - { - test::MockFastPayloadPool pool; - std::vector payloads(TEST_NUMBER); - - for (unsigned int i = 0; i < TEST_NUMBER; i++) - { - pool.get_payload(DEFAULT_SIZE, payloads[i]); - - ASSERT_EQ(payloads[i].max_size, DEFAULT_SIZE); - ASSERT_EQ(pool.pointers_stored(), i + 1); - } - - // END : Clean all remaining payloads - pool.release_all(payloads); - } - - // fail reserve memory - { - test::MockFastPayloadPool pool; - Payload payload; - - ASSERT_FALSE(pool.get_payload(0, payload)); - } -} - -/** - * Check to get_payload from a source that has been created in same pool increase references. - * - * STEPS: - * get payload0 - * get payload1 from src payload0 - * get payload2 from src payload1 - * release payload0 - * get payload3 from src payload1 - * get payload4 - * get payload5 from src payload4 - * release all - */ -TEST(FastPayloadPoolTest, get_payload_from_src) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - - Payload payload0; - Payload payload1; - Payload payload2; - Payload payload3; - Payload payload4; - Payload payload5; - - // get payload0 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE, payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // get payload1 from src payload0 - ASSERT_TRUE(pool_->get_payload(payload0, pool, payload1)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(payload1.max_size, payload0.max_size); - ASSERT_EQ(payload1.data, payload0.data); - - // get payload2 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload2)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(payload2.max_size, payload0.max_size); - ASSERT_EQ(payload2.data, payload0.data); - - // release payload0 - ASSERT_TRUE(pool_->release_payload(payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // get payload3 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload3)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(payload3.max_size, payload1.max_size); - ASSERT_EQ(payload3.data, payload1.data); - - // get payload4 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE * 0x100, payload4)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - - // get payload5 from src payload4 - ASSERT_TRUE(pool_->get_payload(payload4, pool, payload5)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - ASSERT_EQ(payload5.max_size, payload4.max_size); - ASSERT_EQ(payload5.data, payload4.data); - - // release all - ASSERT_TRUE(pool_->release_payload(payload1)); - ASSERT_TRUE(pool_->release_payload(payload2)); - ASSERT_TRUE(pool_->release_payload(payload3)); - ASSERT_TRUE(pool_->release_payload(payload4)); - ASSERT_TRUE(pool_->release_payload(payload5)); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check to get_payload from a source that has been created in a different pool - * - * STEPS: - * get payload aux from pool aux - * get payload from src payload aux - * release payload aux from pool aux - * release payload - */ -TEST(FastPayloadPoolTest, get_payload_from_src_no_owner) -{ - // Each pool has a IPayloadPool and a MockFastPayloadPool so it can be called to get_payload from source - // and specific methods from mock - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_aux_ = static_cast(pool_aux); - - Payload payload_src; - Payload payload_target; - - // get payload aux from pool aux - pool_aux_->get_payload(DEFAULT_SIZE, payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 1u); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // get payload from src payload aux - ASSERT_TRUE(pool_->get_payload(payload_src, pool_aux, payload_target)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload aux from pool aux - pool_aux_->release_payload(payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 0u); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload - pool_->release_payload(payload_target); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool_aux; - delete pool; -} - -/** - * Check negative cases for get_payload from source - * - * CASES: - * Source has size 0 and different owner - */ -TEST(FastPayloadPoolTest, get_payload_from_src_negative) -{ - // Source has size 0 and different owner - { - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = nullptr; // nullptr - - Payload payload_src; - Payload payload_target; - - ASSERT_FALSE( - pool_->get_payload( - payload_src, - pool_aux, - payload_target)); - - delete pool; - } -} - -/** - * Get some payloads from pool from src and release each of them separatly checking reference count - * - * STEPS: - * get first payload - * get N-1 payloads from first - * release N-2 payloads - * get N-2 more payloads from first - * release N payloads - */ -TEST(FastPayloadPoolTest, release_payload) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - std::vector payloads(TEST_NUMBER); - - // get first payload - pool_->get_payload(DEFAULT_SIZE, payloads[0]); - - // get N-1 payloads from first - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - } - - // release N-2 payloads - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - } - - // get N-2 more payloads from first - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - } - - // release N payloads - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - } - // Removing last payload because if not the reference count cannot be done - ASSERT_TRUE(pool_->release_payload(payloads[0])); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check release a payload that has been get from a different payload pool - */ -TEST(FastPayloadPoolTest, release_payload_negative) -{ - // 1 log error expected - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 1, 1); - - test::MockFastPayloadPool pool; - test::MockFastPayloadPool pool_aux; - Payload payload; - - pool_aux.get_payload(DEFAULT_SIZE, payload); - - ASSERT_THROW(pool.release_payload(payload), eprosima::utils::InconsistencyException); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp b/ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp deleted file mode 100644 index 2815c2f26..000000000 --- a/ddspipe_participants/test/unittest/efficiency/MapPayloadPoolTest.cpp +++ /dev/null @@ -1,374 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -#include -#include - -#include -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -const constexpr unsigned int TEST_NUMBER = 5; -const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -/** - * @brief Mock over MapPayloadPool implementing public access to private variables. - * - */ -class MockMapPayloadPool : public MapPayloadPool -{ -public: - - using MapPayloadPool::MapPayloadPool; - - uint64_t pointers_stored() - { - return reserved_payloads_.size(); - } - - uint64_t reference_count( - const Payload& payload) - { - return reserved_payloads_[payload.data]; - } - - void clean_all( - std::vector& payloads) - { - for (Payload& payload : payloads) - { - release_payload(payload); - } - } - -}; - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/* - * This tests does not check the methods calling cacheChange, this is tested in generic PayloadPool test. - */ - -/** - * Test get_payload method for new changes - * - * CASES: - * Get N different pointers - * fail reserve memory - */ -TEST(MapPayloadPoolTest, get_payload) -{ - // Get N different pointers - { - test::MockMapPayloadPool pool; - std::vector payloads(TEST_NUMBER); - - for (unsigned int i = 0; i < TEST_NUMBER; i++) - { - pool.get_payload(DEFAULT_SIZE, payloads[i]); - - ASSERT_EQ(payloads[i].max_size, DEFAULT_SIZE); - ASSERT_EQ(pool.pointers_stored(), i + 1); - ASSERT_EQ(pool.reference_count(payloads[i]), 1u); - } - - // END : Clean all remaining payloads - pool.clean_all(payloads); - } - - // fail reserve memory - { - test::MockMapPayloadPool pool; - Payload payload; - - ASSERT_FALSE(pool.get_payload(0, payload)); - } -} - -/** - * Check to get_payload from a source that has been created in same pool increase references. - * - * STEPS: - * get payload0 - * get payload1 from src payload0 - * get payload2 from src payload1 - * release payload0 - * get payload3 from src payload1 - * get payload4 - * get payload5 from src payload4 - * release all - */ -TEST(MapPayloadPoolTest, get_payload_from_src) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - - Payload payload0; - Payload payload1; - Payload payload2; - Payload payload3; - Payload payload4; - Payload payload5; - - // get payload0 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE, payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload0), 1u); - - // get payload1 from src payload0 - ASSERT_TRUE(pool_->get_payload(payload0, pool, payload1)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload1), 2u); - ASSERT_EQ(payload1.max_size, payload0.max_size); - ASSERT_EQ(payload1.data, payload0.data); - - // get payload2 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload2)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload2), 3u); - ASSERT_EQ(payload2.max_size, payload0.max_size); - ASSERT_EQ(payload2.data, payload0.data); - - // release payload0 - ASSERT_TRUE(pool_->release_payload(payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload2), 2u); - - // get payload3 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload3)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload3), 3u); - ASSERT_EQ(payload3.max_size, payload1.max_size); - ASSERT_EQ(payload3.data, payload1.data); - - // get payload4 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE * 0x100, payload4)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - ASSERT_EQ(pool_->reference_count(payload1), 3u); - ASSERT_EQ(pool_->reference_count(payload4), 1u); - - // get payload5 from src payload4 - ASSERT_TRUE(pool_->get_payload(payload4, pool, payload5)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - ASSERT_EQ(pool_->reference_count(payload1), 3u); - ASSERT_EQ(pool_->reference_count(payload5), 2u); - ASSERT_EQ(payload5.max_size, payload4.max_size); - ASSERT_EQ(payload5.data, payload4.data); - - // release all - ASSERT_TRUE(pool_->release_payload(payload1)); - ASSERT_TRUE(pool_->release_payload(payload2)); - ASSERT_TRUE(pool_->release_payload(payload3)); - ASSERT_TRUE(pool_->release_payload(payload4)); - ASSERT_TRUE(pool_->release_payload(payload5)); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check to get_payload from a source that has been created in a different pool - * - * STEPS: - * get payload aux from pool aux - * get payload from src payload aux - * release payload aux from pool aux - * release payload - */ -TEST(MapPayloadPoolTest, get_payload_from_src_no_owner) -{ - // Each pool has a IPayloadPool and a MockMapPayloadPool so it can be called to get_payload from source - // and specific methods from mock - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_aux_ = static_cast(pool_aux); - - Payload payload_src; - Payload payload_target; - - // get payload aux from pool aux - pool_aux_->get_payload(DEFAULT_SIZE, payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 1u); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // get payload from src payload aux - ASSERT_TRUE(pool_->get_payload(payload_src, pool_aux, payload_target)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload aux from pool aux - pool_aux_->release_payload(payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 0u); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload - pool_->release_payload(payload_target); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool_aux; - delete pool; -} - -/** - * Check negative cases for get_payload from source - * - * CASES: - * The source says the owner is the same pool, but is not - * Source has size 0 and different owner - */ -TEST(MapPayloadPoolTest, get_payload_from_src_negative) -{ - // The source says the owner is the same pool, but is not - { - // 1 log error expected - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 1, 1); - - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - test::MockMapPayloadPool pool_aux; - - Payload payload_src; - Payload payload_target; - - // Get payload for source - pool_aux.get_payload(DEFAULT_SIZE, payload_src); - - // In a different pool, try to source it as if it was from same pool - ASSERT_THROW(pool_->get_payload(payload_src, pool, payload_target), eprosima::utils::InconsistencyException); - - // END : release payload - pool_aux.release_payload(payload_src); - - delete pool; - } - - // Source has size 0 and different owner - { - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = nullptr; // nullptr - - Payload payload_src; - Payload payload_target; - - ASSERT_FALSE( - pool_->get_payload( - payload_src, - pool_aux, - payload_target)); - - delete pool; - } -} - -/** - * Get some payloads from pool from src and release each of them separatly checking reference count - * - * STEPS: - * get first payload - * get N-1 payloads from first - * release N-2 payloads - * get N-2 more payloads from first - * release N payloads - */ -TEST(MapPayloadPoolTest, release_payload) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - std::vector payloads(TEST_NUMBER); - - // get first payload - pool_->get_payload(DEFAULT_SIZE, payloads[0]); - - // get N-1 payloads from first - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - ASSERT_EQ(pool_->reference_count(payloads[0]), i + 1) << i; - } - - // release N-2 payloads - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - ASSERT_EQ(pool_->reference_count(payloads[0]), TEST_NUMBER + 1 - i) << i; - } - - // get N-2 more payloads from first - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - ASSERT_EQ(pool_->reference_count(payloads[0]), i + 1) << i; - } - - // release N payloads - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - ASSERT_EQ(pool_->reference_count(payloads[0]), TEST_NUMBER - i) << i; - } - // Removing last payload because if not the reference count cannot be done - ASSERT_TRUE(pool_->release_payload(payloads[0])); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check release a payload that has been get from a different payload pool - */ -TEST(MapPayloadPoolTest, release_payload_negative) -{ - // 1 log error expected - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 1, 1); - - test::MockMapPayloadPool pool; - test::MockMapPayloadPool pool_aux; - Payload payload; - - pool_aux.get_payload(DEFAULT_SIZE, payload); - - ASSERT_THROW(pool.release_payload(payload), eprosima::utils::InconsistencyException); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp b/ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp deleted file mode 100644 index 9ca790045..000000000 --- a/ddspipe_participants/test/unittest/efficiency/PayloadPoolTest.cpp +++ /dev/null @@ -1,477 +0,0 @@ -// Copyright 2022 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. - -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -// Using for gmock -using ::testing::_; -using ::testing::Invoke; -using ::testing::Return; - -namespace eprosima { -namespace fastrtps { -namespace rtps { - -/* - * WORKAROUND: - * This definition is needed due to googletest-distribution (1.11.0) requires to every class used inside ASSERT macro - * to have the operator << defined in SAME namespace than the class. - * In our case, Payload is defined as eprosima::fastrtps::rtps::SerializedPayload_t but redefined as - * eprosima::ddsrouter::core::types::Payload and the operator << is defined in eprosima::ddsrouter::core::types - * Thus, gtest could not find this definition (arising a very messy and cryptic compilation error). - * This definition corrects that problem. - * - * NOTE: - * In googletest-distribution release-1.10.0 this does not happen. - */ -void PrintTo( - const SerializedPayload_t, - std::ostream* os) -{ - *os << "::eprosima::fastrtps::rtps::SerializedPayload_t"; -} - -} /* namespace rtps */ -} /* namespace fastrtps */ -} /* namespace eprosima */ - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -/** - * @brief Mock over Payload Pool re-implementing the needed methods returning error and - * implementing public access to private variables. - * - */ -class MockPayloadPool : public PayloadPool -{ -public: - - // Using parent methods and variables as public - using PayloadPool::PayloadPool; - using PayloadPool::get_payload; - using PayloadPool::release_payload; - using PayloadPool::reserve_; - using PayloadPool::release_; - using PayloadPool::reserve_count_; - using PayloadPool::release_count_; - - // Mock this virtual methods not implemented in parent class - MOCK_METHOD( - bool, - get_payload, - (uint32_t size, eprosima::ddsrouter::core::types::Payload& target_payload), - (override)); - - MOCK_METHOD( - bool, - get_payload, - ( - const Payload& src_payload, - eprosima::fastrtps::rtps::IPayloadPool*&data_owner, - eprosima::ddsrouter::core::types::Payload& target_payload - ), - (override)); - - MOCK_METHOD( - bool, - release_payload, - (eprosima::ddsrouter::core::types::Payload& target_payload), - (override)); -}; - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/** - * Test reserve_ method - * - * CASES: - * small size - * large size - * 0 size - */ -TEST(PayloadPoolTest, reserve) -{ - // small size - { - test::MockPayloadPool pool; - Payload payload; - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - - ASSERT_TRUE(pool.reserve_(sizeof(PayloadUnit), payload)); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit)); - ASSERT_NE(payload.data, nullptr); - - // This would (maybe) fail with SEG FAULT if the data has not been correctly set - payload.data[0] = 16u; - } - - // large size - { - test::MockPayloadPool pool; - Payload payload; - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - - ASSERT_TRUE(pool.reserve_(sizeof(PayloadUnit) * 0x1000, payload)); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit) * 0x1000); - ASSERT_NE(payload.data, nullptr); - - // This would (maybe) fail with SEG FAULT if the data has not been correctly set - payload.data[0] = 4u; - payload.data[0x1000 - 1] = 5u; - } -} - -/** - * Test reserve_ method - * - * CASES: - * 0 size - */ -TEST(PayloadPoolTest, reserve_negative) -{ - - // 0 size - { - - test::MockPayloadPool pool; - Payload payload; - - ASSERT_EQ(payload.max_size, 0u); - - ASSERT_FALSE(pool.reserve_(0, payload)); - - ASSERT_EQ(payload.max_size, 0u); - } -} - -/** - * Test release_ method - * - * CASES: - * small size - * large size - */ -TEST(PayloadPoolTest, release) -{ - // small size - { - test::MockPayloadPool pool; - Payload payload; - pool.reserve_(sizeof(PayloadUnit), payload); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit)); - ASSERT_NE(payload.data, nullptr); - - ASSERT_TRUE(pool.release_(payload)); - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - } - - // large size - { - test::MockPayloadPool pool; - Payload payload; - pool.reserve_(sizeof(PayloadUnit) * 0x1000, payload); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit) * 0x1000); - ASSERT_NE(payload.data, nullptr); - - ASSERT_TRUE(pool.release_(payload)); - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - } -} - -/** - * Test release_ method - * - * STEPS: - * store 5 values - * release 4 values - * store 5 more values - * release 6 values - * release more values than reserved - */ -TEST(PayloadPoolTest, reserve_and_release_counter) -{ - test::MockPayloadPool pool; - std::vector payloads(11); - - // store 5 values - for (unsigned int i = 0; i < 5u; ++i) - { - ASSERT_EQ(pool.reserve_count_, i); - pool.reserve_(sizeof(PayloadUnit), payloads[i]); - } - ASSERT_EQ(pool.reserve_count_, 5u); - - // release 4 values - for (unsigned int i = 0; i < 4u; ++i) - { - ASSERT_EQ(pool.release_count_, i); - pool.release_(payloads[i]); - } - ASSERT_EQ(pool.release_count_, 4u); - - // store 5 values - for (unsigned int i = 5; i < 10u; ++i) - { - ASSERT_EQ(pool.reserve_count_, i); - pool.reserve_(sizeof(PayloadUnit), payloads[i]); - } - ASSERT_EQ(pool.reserve_count_, 10u); - - // release 6 values - for (unsigned int i = 4; i < 10u; ++i) - { - ASSERT_EQ(pool.release_count_, i); - pool.release_(payloads[i]); - } - ASSERT_EQ(pool.release_count_, 10u); -} - -/** - * Test release_ method - * - * STEPS: - * store 5 values - * release 5 values - * release more values than reserved - */ -TEST(PayloadPoolTest, reserve_and_release_counter_negative) -{ - // 1 log error expected - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 1, 1); - - test::MockPayloadPool pool; - std::vector payloads(5); - - // store 5 values - for (unsigned int i = 0; i < 5u; ++i) - { - ASSERT_EQ(pool.reserve_count_, i); - pool.reserve_(sizeof(PayloadUnit), payloads[i]); - } - - // release 5 values - for (unsigned int i = 0; i < 5u; ++i) - { - ASSERT_EQ(pool.release_count_, i); - pool.release_(payloads[i]); - } - - // release more values than reserved - ASSERT_THROW(pool.release_(payloads[4]), eprosima::utils::InconsistencyException); -} - -/** - * Test clean method - * - * STEPS: - * start clean - * reserve and not clean - * release and clean - */ -TEST(PayloadPoolTest, is_clean) -{ - test::MockPayloadPool pool; - - // start clean - ASSERT_TRUE(pool.is_clean()); - - // reserve and not clean - eprosima::fastrtps::rtps::CacheChange_t cc; - pool.reserve_(sizeof(PayloadUnit), cc.serializedPayload); - ASSERT_FALSE(pool.is_clean()); - - // release and clean - pool.release_(cc.serializedPayload); - ASSERT_TRUE(pool.is_clean()); -} - -/** - * Test get_payload cache_change fails if the child class fails - * - * CASES: - * - get_payload for payload goes ok - * - get_payload for payload fails - */ -TEST(PayloadPoolTest, get_payload_cache_change) -{ - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - EXPECT_CALL(pool, get_payload(_, _)).Times(1).WillOnce(Return(true)); - - EXPECT_TRUE(pool.get_payload(sizeof(PayloadUnit), cc)); - - // Clean cache change correctly so process dont break - cc.payload_owner(nullptr); - } - - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - EXPECT_CALL(pool, get_payload(_, _)).Times(1).WillOnce(Return(false)); - - EXPECT_FALSE(pool.get_payload(sizeof(PayloadUnit), cc)); - } -} - -/** - * Test get_payload cache_change with source fails if the child class fails - * - * CASES: - * - get_payload for payload goes ok - * - get_payload for payload fails - */ -TEST(PayloadPoolTest, get_payload_from_src_cache_change) -{ - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t target; - Payload source; - eprosima::fastrtps::rtps::IPayloadPool* aux_pool; - - EXPECT_CALL(pool, get_payload(_, _, _)).Times(1).WillOnce(Return(true)); - - EXPECT_TRUE(pool.get_payload(source, aux_pool, target)); - - // Clean cache change correctly so process dont break - target.payload_owner(nullptr); - } -} - -/** - * Test get_payload cache_change with source fails if the child class fails - * - * CASES: - * - get_payload for payload fails - */ -TEST(PayloadPoolTest, get_payload_from_src_cache_change_negative) -{ - // get_payload for payload fails - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t target; - Payload source; - eprosima::fastrtps::rtps::IPayloadPool* aux_pool; - - EXPECT_CALL(pool, get_payload(_, _, _)).Times(1).WillOnce(Return(false)); - - EXPECT_FALSE(pool.get_payload(source, aux_pool, target)); - } -} - -/** - * Test release_payload cache_change method using MockPayloadPool when inside get_payload method fails - * - * CASES: - * different ownership - * this ownership release ok - */ -TEST(PayloadPoolTest, release_payload_cache_change) -{ - // this ownership release ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - // ownership must be this pool - cc.payload_owner(&pool); - - EXPECT_CALL(pool, release_payload(_)).Times(1).WillOnce(Return(true)); - - EXPECT_TRUE(pool.release_payload(cc)); - } -} - -/** - * Test release_payload cache_change method from a different owner - * - * CASES: - * this ownership release fail - */ -TEST(PayloadPoolTest, release_payload_cache_change_negative) -{ - // different ownership - { - // 1 log error expected - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 1, 1); - - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - cc.payload_owner(nullptr); - - EXPECT_THROW(pool.release_payload(cc), eprosima::utils::InconsistencyException); - } - - // this ownership release fail - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - // ownership must be this pool - cc.payload_owner(&pool); - - EXPECT_CALL(pool, release_payload(_)).Times(1).WillOnce(Return(false)); - - EXPECT_FALSE(pool.release_payload(cc)); - - // Clean cache change correctly so process dont break - cc.payload_owner(nullptr); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/types/CMakeLists.txt b/ddspipe_participants/test/unittest/types/CMakeLists.txt deleted file mode 100644 index 6fbb0b168..000000000 --- a/ddspipe_participants/test/unittest/types/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(endpoint) -add_subdirectory(topic) diff --git a/ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt b/ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt deleted file mode 100644 index 927ffbf5d..000000000 --- a/ddspipe_participants/test/unittest/types/endpoint/CMakeLists.txt +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2021 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. - -######## -# GUID # -######## - -set(TEST_NAME GuidTest) - -set(TEST_SOURCES - GuidTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp - ) - -set(TEST_LIST - is_valid - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -############ -# Endpoint # -############ - -set(TEST_NAME EndpointTest) - -set(TEST_SOURCES - EndpointTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/endpoint/Endpoint.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/SpecificEndpointQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/data/Payload.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ) - -set(TEST_LIST - constructor - kind_getter - guid_getter - qos_getter - topic_getter - active_getter - active_setter - is_writer - is_reader - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp b/ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp deleted file mode 100644 index 70bcd0a50..000000000 --- a/ddspipe_participants/test/unittest/types/endpoint/EndpointTest.cpp +++ /dev/null @@ -1,343 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -// Get a random TopicQoS configuration -TopicQoS random_qos( - uint16_t seed = 0) -{ - TopicQoS qos; - - if (seed % 2) - { - qos.reliability_qos = ReliabilityKind::BEST_EFFORT; - } - else - { - qos.reliability_qos = ReliabilityKind::RELIABLE; - } - - switch ((seed / 2) % 4) - { - case 0: - qos.durability_qos = DurabilityKind::VOLATILE; - break; - - case 1: - qos.durability_qos = DurabilityKind::TRANSIENT_LOCAL; - break; - - case 2: - qos.durability_qos = DurabilityKind::TRANSIENT; - break; - - case 3: - qos.durability_qos = DurabilityKind::PERSISTENT; - break; - - default: - break; - } - - return qos; -} - -// Get a random topic name -DistributedTopic random_topic( - uint16_t seed = 0) -{ - return DistributedTopic("TopicName_" + std::to_string(seed), "TopicType_" + std::to_string(seed), false, random_qos(seed)); -} - -// Get a random topic name -EndpointKind random_endpoint_kind( - uint16_t seed = 0) -{ - if (seed % 2) - { - return EndpointKind::reader; - } - else - { - return EndpointKind::writer; - } -} - -// Get a random guid -Guid random_valid_guid( - uint16_t seed = 0) -{ - eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; - std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d." + std::to_string(seed)) >> guid_prefix; - return Guid( - guid_prefix, - seed); -} - -/** - * Test \c Endpoint constructor - */ -TEST(EndpointTest, constructor) -{ - EndpointKind kind; - Guid guid; - DistributedTopic topic = random_topic(); - // TODO: add data qos - - Endpoint endpoint(kind, guid, topic); - - ASSERT_EQ(endpoint.kind(), kind); - ASSERT_EQ(endpoint.guid(), guid); - ASSERT_EQ(endpoint.topic_qos(), topic.topic_qos.get_reference()); - ASSERT_EQ(endpoint.topic(), topic); -} - -/** - * Test \c Endpoint \c kind getter method - * - * CASES: - * Writer - * Reader - */ -TEST(EndpointTest, kind_getter) -{ - Guid guid; - DistributedTopic topic = random_topic(); - - // Writer - { - Endpoint endpoint(EndpointKind::writer, guid, topic); - ASSERT_EQ(endpoint.kind(), EndpointKind::writer); - } - - // Reader - { - Endpoint endpoint(EndpointKind::reader, guid, topic); - ASSERT_EQ(endpoint.kind(), EndpointKind::reader); - } -} - -/** - * Test \c Endpoint \c guid getter method - * - * CASES: - * Default guid - * Random guids - */ -TEST(EndpointTest, guid_getter) -{ - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Default guid - { - Guid guid; - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(endpoint.guid(), guid); - } - - // Random guids - { - for (uint16_t i = 0; i < 10; i++) - { - Guid guid = random_valid_guid(i); - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(endpoint.guid(), random_valid_guid(i)) << i; - } - } -} - -/** - * Test \c Endpoint \c qos getter method - * - * CASES: - * Random TopicQoS - */ -TEST(EndpointTest, qos_getter) -{ - Guid guid = random_valid_guid(); - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Random guids - { - for (uint16_t i = 0; i < 8; i++) - { - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(topic.topic_qos, endpoint.topic_qos()) << i; - } - } -} - -/** - * Test \c Endpoint \c topic getter method - * - * CASES: - * Random Topics - */ -TEST(EndpointTest, topic_getter) -{ - Guid guid = random_valid_guid(); - EndpointKind kind = random_endpoint_kind(); - - // Random guids - { - for (uint16_t i = 0; i < 10u; i++) - { - DistributedTopic topic = random_topic(i); - Endpoint endpoint(kind, guid, topic); - ASSERT_EQ(endpoint.topic(), random_topic(i)) << i; - } - } -} - -/** - * Test \c Endpoint \c active getter method - * - * CASES: - * Default value - * Change to invalid - * Change to invalid and to valid - */ -TEST(EndpointTest, active_getter) -{ - Guid guid = random_valid_guid(); - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Default value - { - Endpoint endpoint(kind, guid, topic); - ASSERT_TRUE(endpoint.active()); - } - - // Change to invalid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - ASSERT_FALSE(endpoint.active()); - } - - // Change to invalid and to valid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - endpoint.active(true); - ASSERT_TRUE(endpoint.active()); - } -} - -/** - * Test \c Endpoint \c active setter method - * - * Same test as active_setter - * CASES: - * Default value - * Change to invalid - * Change to invalid and to valid - */ -TEST(EndpointTest, active_setter) -{ - Guid guid = random_valid_guid(); - DistributedTopic topic = random_topic(); - EndpointKind kind = random_endpoint_kind(); - - // Default value - { - Endpoint endpoint(kind, guid, topic); - ASSERT_TRUE(endpoint.active()); - } - - // Change to invalid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - ASSERT_FALSE(endpoint.active()); - } - - // Change to invalid and to valid - { - Endpoint endpoint(kind, guid, topic); - endpoint.active(false); - endpoint.active(true); - ASSERT_TRUE(endpoint.active()); - } -} - -/** - * Test \c Endpoint \c is_writer getter method - * - * CASES: - * Writer - * Reader - */ -TEST(EndpointTest, is_writer) -{ - Guid guid; - DistributedTopic topic = random_topic(); - - // Writer - { - Endpoint endpoint(EndpointKind::writer, guid, topic); - ASSERT_TRUE(endpoint.is_writer()); - } - - // Reader - { - Endpoint endpoint(EndpointKind::reader, guid, topic); - ASSERT_FALSE(endpoint.is_writer()); - } -} - -/** - * Test \c Endpoint \c is_reader getter method - * - * CASES: - * Writer - * Reader - */ -TEST(EndpointTest, is_reader) -{ - Guid guid; - DistributedTopic topic = random_topic(); - - // Writer - { - Endpoint endpoint(EndpointKind::writer, guid, topic); - ASSERT_FALSE(endpoint.is_reader()); - } - - // Reader - { - Endpoint endpoint(EndpointKind::reader, guid, topic); - ASSERT_TRUE(endpoint.is_reader()); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp b/ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp deleted file mode 100644 index 0c5884add..000000000 --- a/ddspipe_participants/test/unittest/types/endpoint/GuidTest.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -/** - * Test \c Guid \c is_valid method - * - * CASES: - * Default constructor invalid - * Unknown guid invalid - * GuidPrefix invalid - * EntityId invalid - * Constrcutor with valid value - */ -TEST(GuidTest, is_valid) -{ - // Default constructor invalid - { - Guid invalid_guid; - ASSERT_FALSE(invalid_guid.is_valid()); - } - - // Unknown guid invalid - { - Guid invalid_guid_1( - eprosima::fastrtps::rtps::GuidPrefix_t::unknown(), - eprosima::fastrtps::rtps::EntityId_t::unknown()); - ASSERT_FALSE(invalid_guid_1.is_valid()); - - Guid invalid_guid_2( - eprosima::fastrtps::rtps::GUID_t::unknown().guidPrefix, - eprosima::fastrtps::rtps::GUID_t::unknown().entityId); - ASSERT_FALSE(invalid_guid_2.is_valid()); - } - - // GuidPrefix invalid - { - Guid invalid_guid( - eprosima::fastrtps::rtps::GuidPrefix_t(), // Invalid GuidPrefix - eprosima::fastrtps::rtps::EntityId_t(1)); // Valid EntityId - ASSERT_FALSE(invalid_guid.is_valid()); - } - - // EntityId invalid - { - eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; - std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d.41") >> guid_prefix; - Guid valid_guid( - guid_prefix, // Valid GuidPrefix - eprosima::fastrtps::rtps::EntityId_t()); // Invalid EntityId - ASSERT_FALSE(valid_guid.is_valid()); - } - - // Constrcutor with valid value - { - eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; - std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d.41") >> guid_prefix; - Guid valid_guid( - guid_prefix, // Valid GuidPrefix - eprosima::fastrtps::rtps::EntityId_t(1)); // Valid EntityId - ASSERT_TRUE(valid_guid.is_valid()); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/types/topic/CMakeLists.txt b/ddspipe_participants/test/unittest/types/topic/CMakeLists.txt deleted file mode 100644 index 1eeb42b1f..000000000 --- a/ddspipe_participants/test/unittest/types/topic/CMakeLists.txt +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright 2021 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. - -################### -# Topic # -################### - -set(TEST_NAME TopicTest) - -set(TEST_SOURCES - TopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ) - -set(TEST_LIST - is_valid - ) - -set(TEST_EXTRA_LIBRARIES - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -############# -# DistributedTopic # -############# - -set(TEST_NAME DdsTopicTest) - -set(TEST_SOURCES - DdsTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ) - -set(TEST_LIST - is_valid_dds_topic - is_valid_dds_topic_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -################# -# WildcardDdsFilterTopic # -################# - -set(TEST_NAME WildcardTopicTest) - -set(TEST_SOURCES - WildcardDdsFilterTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DistributedTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/DdsFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ) - -set(TEST_LIST - matches - non_matches - - # Not supported (TODO) - # non_contains_wildcard - # contains_wildcard - ) - -set(TEST_EXTRA_LIBRARIES - $<$:iphlpapi$Shlwapi> - fastcdr - fastrtps - cpp_utils - - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp b/ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp deleted file mode 100644 index 4a6f610ce..000000000 --- a/ddspipe_participants/test/unittest/types/topic/DdsTopicTest.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -using pair_topic_type = std::pair; - -/** - * Test DistributedTopic is_valid_dds_topic method for positive cases - */ -TEST(DdsTopicTest, is_valid_dds_topic) -{ - std::vector topics = { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"topic2", "type1"}, - - {"rt/chatter", "std::std_msg::string"}, - - {"HelloWorldTopic", "HelloWorld"}, - }; - - for (pair_topic_type topic : topics) - { - ASSERT_TRUE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); - } -} - -/** - * Test DistributedTopic is_valid_dds_topic method for negative cases - */ -TEST(DdsTopicTest, is_valid_dds_topic_negative) -{ - std::vector topics = { - {"topic", "type*"}, - {"topic*", "type"}, - {"topic*", "type*"}, - - {"topic", "*type"}, - {"*topic", "type"}, - {"*topic", "*type"}, - - {"topic", "*type*"}, - {"*topic*", "type"}, - {"*topic*", "*type*"}, - - {"topic", "ty*pe"}, - {"top*ic", "type"}, - {"top*ic", "ty*pe"}, - - {"*", "type"}, - {"topic", "*"}, - {"*", "*"}, - - {"topic", ""}, - {"", "type"}, - {"", ""}, - // TODO add regex cases - }; - - for (pair_topic_type topic : topics) - { - ASSERT_FALSE(DistributedTopic::is_valid_dds_topic(topic.first, topic.second)); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/types/topic/TopicTest.cpp b/ddspipe_participants/test/unittest/types/topic/TopicTest.cpp deleted file mode 100644 index 4d33842c9..000000000 --- a/ddspipe_participants/test/unittest/types/topic/TopicTest.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include - -#include - -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::core::types; - -/* - * Return a list of non repeated random topic names - */ -std::vector random_topic_names() -{ - return - { - {"topic1"}, - {"topic2"}, - {"topic3"}, - - {"*"}, - {"*rt"}, - {"rt*"}, - {"rt"}, - {"rt*"}, - - {"."}, - }; -} - -/** - * Test Topic constructor and std getter methods - */ -TEST(TopicTest, is_valid) -{ - eprosima::utils::Formatter __f; - - for (const std::string& topic_name : random_topic_names()) - { - Topic topic(topic_name); - ASSERT_TRUE(topic.is_valid(__f)); - } - - ASSERT_FALSE(Topic().is_valid(__f)); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp b/ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp deleted file mode 100644 index 9d4c3d9dd..000000000 --- a/ddspipe_participants/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - -using pair_topic_type = std::pair; - -// TODO: extend contains tests for regex topics - -/** - * Test WildcardDdsFilterTopic construct only with topic name - */ -TEST(WildcardTopicTest, topic_name_constructor) -{ - WildcardDdsFilterTopic topic1("topic1"); - WildcardDdsFilterTopic topic2; - - ASSERT_EQ(topic1, topic2); -} - -/** - * Test WildcardDdsFilterTopic contains method for positive cases - */ -TEST(WildcardTopicTest, contains_wildcard) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic", "type"}, {"topic", "type*"}, {"topic", "*type"}, {"topic", "type1*"}}}, - - {{"topic", "type*"}, - {{"topic", "type"}, {"topic", "type1"}, {"topic", "type1*"}}}, - - {{"*", "type"}, - {{"topic", "type"}, {"*topic", "type"}, {"topic*", "type"}, {"*rt/topic", "type"}}}, - - {{"*topic", "type"}, - {{"topic", "type"}, {"std_topic", "type"}, {"*rt/topic", "type"}}}, - - {{"topic*", "type*"}, - {{"topic", "type"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a FilterDdsTopic and test - for (auto real_topic_names : test_case.second) - { - WildcardDdsFilterTopic contained_topic; - contained_topic.topic_name = real_topic_names.first; - contained_topic.type_name = real_topic_names.second; - - ASSERT_TRUE(wt.contains(contained_topic)); - } - } -} - -/** - * Test WildcardDdsFilterTopic matches method for positive cases - */ -TEST(WildcardTopicTest, matches) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic", "type"}, {"topic", "type1"}, {"topic", "type2"}}}, - - {{"topic", "type*"}, - {{"topic", "type"}, {"topic", "type1"}, {"topic", "type2"}}}, - - {{"*", "type"}, - {{"topic", "type"}, {"std_topic", "type"}, {"rt/topic", "type"}}}, - - {{"*topic", "type"}, - {{"topic", "type"}, {"std_topic", "type"}, {"rt/topic", "type"}}}, - - {{"topic", "type"}, - {{"topic", "type"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a DistributedTopic and test - for (auto real_topic_names : test_case.second) - { - DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); - - ASSERT_TRUE(wt.matches(real_topic)) << "wildcard: " << wt << " ; real: " << real_topic; - } - } -} - -/** - * Test WildcardDdsFilterTopic contains method for negative cases - */ -TEST(WildcardTopicTest, non_contains_wildcard) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic1", "type"}, {"topic*", "type"}, {"*", "type"}, {"*topic", "*"}, {"*", "*"}}}, - - {{"topic", "type*"}, - {{"topic*", "type"}, {"topic", "*type"}, {"*", "*"}}}, - - {{"*", "type"}, - {{"topic", "type1"}, {"topic", "type*"}, {"topic*", "*"}, {"*", "type*"}, {"*", "*"}}}, - - {{"*topic", "type"}, - {{"topic", "type*"}, {"topic*", "type"}, {"*", "*"}}}, - - {{"topic*", "type*"}, - {{"*topic", "type"}, {"topic", "*type"}, {"*", "*"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a DistributedTopic and test - for (auto real_topic_names : test_case.second) - { - WildcardDdsFilterTopic contained_topic; - contained_topic.topic_name = real_topic_names.first; - contained_topic.type_name = real_topic_names.second; - - ASSERT_FALSE(wt.contains(contained_topic)); - } - } -} - -/** - * Test WildcardDdsFilterTopic matches method for negative cases - */ -TEST(WildcardTopicTest, non_matches) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic1", "type"}, {"topic1", "type1"}, {"std_topic", "type1"}}}, - - {{"topic", "type*"}, - {{"topic1", "type"}, {"topic", "std::type"}, {"topic", "std::type1"}}}, - - {{"*", "type"}, - {{"topic", "type1"}, {"std_topic", "type1"}, {"topic", "std::type"}}}, - - {{"*topic", "type"}, - {{"topic", "type1"}, {"std_topic1", "type"}, {"rt/topic1", "type"}}}, - - {{"topic", "type"}, - {{"topic", "type1"}, {"topic1", "type"}, {"topic1", "type1"}, {"std_topic", "type"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a DistributedTopic and test - for (auto real_topic_names : test_case.second) - { - DistributedTopic real_topic(real_topic_names.first, real_topic_names.second); - - ASSERT_FALSE(wt.matches(real_topic)); - } - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/TestUtils/test_utils.cpp b/ddspipe_yaml/test/TestUtils/test_utils.cpp index 9c5a004e4..22315fe6b 100644 --- a/ddspipe_yaml/test/TestUtils/test_utils.cpp +++ b/ddspipe_yaml/test/TestUtils/test_utils.cpp @@ -26,7 +26,7 @@ namespace eprosima { namespace ddspipe { namespace test { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; Guid random_guid( uint16_t seed /* = 1 */) diff --git a/ddspipe_yaml/test/TestUtils/test_utils.hpp b/ddspipe_yaml/test/TestUtils/test_utils.hpp index 1d1e8be7c..f423167a6 100644 --- a/ddspipe_yaml/test/TestUtils/test_utils.hpp +++ b/ddspipe_yaml/test/TestUtils/test_utils.hpp @@ -36,7 +36,7 @@ namespace eprosima { namespace ddspipe { namespace test { -using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddspipe::core::types; // TODO: most of the methods from this test_utils that generate random types are not very "random". // They must be refactored to generate real random values. diff --git a/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index 2f184fb0b..a1a72fbef 100644 --- a/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -22,8 +22,8 @@ #include "../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test load a whole DDS Router Configuration from yaml node for v1.0 of yaml. diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp index 1cc866a93..82c04e203 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read an address checking that default values are being used diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp index 966650dff..4d676e784 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read an address with domain name diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp index 97d9173b0..d5c0b50de 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read an address with IP diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp index 55d91790f..7fbf7cbf2 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read IP from yaml diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp index d219fd6f8..a55c0b072 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read Transport Protocol from yaml diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp index fe1c099b8..c9a866541 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read port from yaml diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp index fc0cc12fe..ed7e483ab 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read Transport Protocol from yaml diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp index 079d56fa2..2378c195a 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp @@ -23,8 +23,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test the behaviour when both ip and domain are given. diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp index 51c5f15fd..ff61e9750 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp @@ -22,8 +22,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; const constexpr unsigned int TEST_ADDRESSES_NUMBER = 5; diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp index c7234194b..afcf18c15 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp @@ -21,8 +21,8 @@ #include "../../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read a discovery server connection address that fails diff --git a/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index dcea4ca26..681f73775 100644 --- a/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -23,8 +23,8 @@ #include #include -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test load a whole DDS Router Configuration from yaml node. diff --git a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp index 43fd3776b..ad5384d1e 100644 --- a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp @@ -21,8 +21,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test read core::types::GuidPrefix from yaml with explicit guid diff --git a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp index 4a4883c54..b94335217 100644 --- a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp @@ -24,8 +24,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; namespace eprosima { namespace ddspipe { diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index e6e988a68..52b6125b1 100644 --- a/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -24,8 +24,8 @@ constexpr const uint32_t TEST_ITERATION_MAX = 5; -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp index ec6cb5909..7ebea3ad5 100644 --- a/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp @@ -24,8 +24,8 @@ #include "../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index 0d9932749..2ba8c8b86 100644 --- a/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -25,8 +25,8 @@ constexpr const uint32_t TEST_ITERATION_MAX = 5; -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index a71bbf9d3..a7cf1f969 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -23,8 +23,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml with connection address diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index 1efc6e334..0765cffaf 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -23,8 +23,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml specifing domain diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index 38e6db973..9588ab71e 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -23,8 +23,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml with listening address diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index d71be77a9..28361fabe 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -23,8 +23,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp index 5a433ec33..e147d478b 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp @@ -23,8 +23,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get DS Participant Configuration from yaml fail cases diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index 9a8c681c7..ecc1b82a3 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -23,8 +23,8 @@ #include "../../YamlConfigurationTestUtils.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Test get specifing TLS configuration diff --git a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp index 273dc2046..7a3bc6ed2 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp +++ b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp @@ -19,8 +19,8 @@ #include "YamlReaderTest_common.hpp" -using namespace eprosima::ddsrouter; -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe; +using namespace eprosima::ddspipe::yaml; /** * Check to get a boolean from a yaml diff --git a/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp b/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp index b7e5fbad9..3062c3dd3 100644 --- a/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp +++ b/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp @@ -19,7 +19,7 @@ #include -using namespace eprosima::ddsrouter::yaml; +using namespace eprosima::ddspipe::yaml; TEST(YamlTagsTest, yaml_tags) { From cec3bde12b0df1b4a05fad5c14af83074e89a049 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 11:30:15 +0100 Subject: [PATCH 09/38] Implement ddspipe_yaml tests Signed-off-by: jparisu --- .../types/data/RpcPayloadData.hpp | 3 + .../types/data/RtpsPayloadData.hpp | 2 + .../src/cpp/types/data/RpcPayloadData.cpp | 22 +- .../src/cpp/types/data/RtpsPayloadData.cpp | 5 + .../testing/random_values.hpp | 40 + .../participant/rtps/CommonParticipant.cpp | 16 +- .../src/cpp/reader/auxiliar/BaseReader.cpp | 12 +- .../src/cpp/reader/rtps/CommonReader.cpp | 5 + .../src/cpp/reader/rtps/SpecificQoSReader.cpp | 2 +- .../src/cpp/testing/random_values.cpp | 53 ++ .../src/cpp/writer/auxiliar/BaseWriter.cpp | 3 +- .../src/cpp/writer/rtps/MultiWriter.cpp | 4 +- ddspipe_participants/test/CMakeLists.txt | 7 +- .../ddsrouter_core/dds/CMakeLists.txt | 17 - .../ddsrouter_core/dds/WAN/CMakeLists.txt | 80 -- .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 705 ------------------ .../blackbox/ddsrouter_core/dds/WAN/README.md | 7 - .../ddsrouter_core/dds/WAN/TEST_XFAIL.list | 8 - .../ddsrouter_core/dds/WAN/TEST_XTSAN.list | 5 - .../ddsrouter_core/dds/local/CMakeLists.txt | 84 --- .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 329 -------- .../dds/local/DDSTestLocalDisposeKey.cpp | 201 ----- .../ddsrouter_core/dds/local/README.md | 6 - .../dds/types/HelloWorld/HelloWorld.cxx | 207 ----- .../dds/types/HelloWorld/HelloWorld.h | 216 ------ .../dds/types/HelloWorld/HelloWorld.idl | 5 - .../HelloWorld/HelloWorldPubSubTypes.cxx | 133 ---- .../types/HelloWorld/HelloWorldPubSubTypes.h | 64 -- .../types/HelloWorldKeyed/HelloWorldKeyed.cxx | 283 ------- .../types/HelloWorldKeyed/HelloWorldKeyed.h | 249 ------- .../types/HelloWorldKeyed/HelloWorldKeyed.idl | 6 - .../HelloWorldKeyedPubSubTypes.cxx | 170 ----- .../HelloWorldKeyedPubSubTypes.h | 98 --- .../dds/types/test_participants.hpp | 495 ------------ .../ddsrouter_core/resources/tls/ca.crt | 1 - .../resources/tls/ddsrouter.crt | 1 - .../resources/tls/ddsrouter.key | 1 - .../resources/tls/dh_params.pem | 1 - .../ddsrouter_core/trivial/CMakeLists.txt | 37 - .../ddsrouter_core/trivial/TrivialTest.cpp | 170 ----- .../blackbox/implementations/CMakeLists.txt | 41 - .../implementations/ImplementationsTest.cpp | 246 ------ ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp | 2 + .../include/ddspipe_yaml/YamlManager.hpp | 2 + .../include/ddspipe_yaml/YamlReader.hpp | 2 + .../include/ddspipe_yaml/impl/YamlReader.ipp | 6 +- .../ddspipe_yaml/yaml_configuration_tags.hpp | 2 + ddspipe_yaml/test/CMakeLists.txt | 3 - ddspipe_yaml/test/TestUtils/test_utils.cpp | 273 ------- ddspipe_yaml/test/TestUtils/test_utils.hpp | 131 ---- ddspipe_yaml/test/unittest/CMakeLists.txt | 4 - .../unittest/YamlConfigurationTestUtils.hpp | 85 ++- .../test/unittest/entities/CMakeLists.txt | 4 +- .../unittest/entities/address/CMakeLists.txt | 20 +- ...EntityAddressTest_get_address_defaults.ipp | 21 +- ...etEntityAddressTest_get_address_domain.ipp | 19 +- ...amlGetEntityAddressTest_get_address_ip.ipp | 27 +- .../YamlGetEntityAddressTest_get_ip.ipp | 13 +- ...amlGetEntityAddressTest_get_ip_version.ipp | 17 +- .../YamlGetEntityAddressTest_get_port.ipp | 15 +- ...tityAddressTest_get_transport_protocol.ipp | 21 +- ...YamlGetEntityAddressTest_ip_and_domain.ipp | 13 +- ...coveryServerAddressTest_get_ds_address.ipp | 27 +- ...verAddressTest_get_ds_address_negative.ipp | 25 +- .../unittest/entities/guid/CMakeLists.txt | 11 +- .../guid/YamlGetEntityGuidPrefixTest.cpp | 3 +- .../unittest/entities/topic/CMakeLists.txt | 11 +- .../entities/topic/YamlGetEntityTopicTest.cpp | 137 +--- .../test/unittest/yaml_reader/CMakeLists.txt | 9 +- .../yaml_reader/YamlReaderScalarTest.cpp | 50 +- .../yaml_reader/YamlReaderTest_common.hpp | 50 -- .../test/unittest/yaml_tags/CMakeLists.txt | 32 - .../test/unittest/yaml_tags/YamlTagsTest.cpp | 78 -- .../test}/CMakeLists.txt | 3 + .../test/unittest}/CMakeLists.txt | 11 +- .../unittest/YamlConfigurationTestUtils.hpp | 165 ++++ .../unittest/configuration/CMakeLists.txt | 7 +- .../YamlReaderConfigurationTest.cpp | 1 + .../test/unittest/entities}/CMakeLists.txt | 9 +- .../entities/ddsrouter/CMakeLists.txt | 7 +- .../YamlGetConfigurationDDSRouterTest.cpp | 11 +- .../test/unittest/participants/CMakeLists.txt | 28 +- ...lGetCommonParticipantConfigurationTest.cpp | 5 +- ...veryServerParticipantConfigurationTest.cpp | 0 ...itialPeersParticipantConfigurationTest.cpp | 9 +- ...lGetSimpleParticipantConfigurationTest.cpp | 7 +- ...t_get_participant_connection_addresses.ipp | 27 +- ...nfigurationTest_get_participant_domain.ipp | 7 +- ...st_get_participant_listening_addresses.ipp | 19 +- ...figurationTest_get_participant_minimum.ipp | 7 +- ...igurationTest_get_participant_negative.ipp | 7 +- ...tConfigurationTest_get_participant_tls.ipp | 9 +- 92 files changed, 645 insertions(+), 4847 deletions(-) rename ddspipe_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp => ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp (57%) create mode 100644 ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp create mode 100644 ddspipe_participants/src/cpp/testing/random_values.cpp delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/CMakeLists.txt delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp delete mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt delete mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt delete mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key delete mode 120000 ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt delete mode 100644 ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp delete mode 100644 ddspipe_participants/test/blackbox/implementations/CMakeLists.txt delete mode 100644 ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp delete mode 100644 ddspipe_yaml/test/TestUtils/test_utils.cpp delete mode 100644 ddspipe_yaml/test/TestUtils/test_utils.hpp delete mode 100644 ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp delete mode 100644 ddspipe_yaml/test/unittest/yaml_tags/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp rename {ddspipe_yaml/test/unittest/yaml_manager => ddsrouter_yaml/test}/CMakeLists.txt (91%) rename {ddspipe_participants/test/blackbox/ddsrouter_core => ddsrouter_yaml/test/unittest}/CMakeLists.txt (73%) create mode 100644 ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/configuration/CMakeLists.txt (84%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/configuration/YamlReaderConfigurationTest.cpp (99%) rename {ddspipe_participants/test/blackbox => ddsrouter_yaml/test/unittest/entities}/CMakeLists.txt (76%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/entities/ddsrouter/CMakeLists.txt (87%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp (95%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/CMakeLists.txt (82%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp (96%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp (100%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp (95%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp (96%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp (92%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp (94%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp (89%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp (94%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp (95%) rename {ddspipe_yaml => ddsrouter_yaml}/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp (96%) diff --git a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp index f01166b3b..b61b64cb5 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp @@ -40,6 +40,9 @@ namespace types { */ struct RpcPayloadData : public RtpsPayloadData { + + virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; + //! Write params associated to the received cache change utils::Fuzzy write_params{}; diff --git a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp index 10b263588..09f6ef754 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp @@ -47,6 +47,8 @@ struct RtpsPayloadData : public core::IRoutingData */ virtual ~RtpsPayloadData(); + virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; + //! Payload of the data received. The data in this payload must belong to the PayloadPool. core::types::Payload payload{}; diff --git a/ddspipe_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp b/ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp similarity index 57% rename from ddspipe_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp rename to ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp index c5d43fe66..3b2c1100a 100644 --- a/ddspipe_yaml/test/unittest/yaml_manager/YamlManagerTest.cpp +++ b/ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// 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. @@ -12,15 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include -// TODO +namespace eprosima { +namespace ddspipe { +namespace core { +namespace types { -int main( - int argc, - char** argv) +types::TopicInternalTypeDiscriminator RpcPayloadData::internal_type_discriminator() const noexcept { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return INTERNAL_TOPIC_TYPE_RPC; } + +} /* namespace types */ +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp b/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp index 236b6ea81..2d7be4523 100644 --- a/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp +++ b/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp @@ -28,6 +28,11 @@ RtpsPayloadData::~RtpsPayloadData() } } +types::TopicInternalTypeDiscriminator RtpsPayloadData::internal_type_discriminator() const noexcept +{ + return INTERNAL_TOPIC_TYPE_RTPS; +} + } /* namespace types */ } /* namespace core */ } /* namespace ddspipe */ diff --git a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp new file mode 100644 index 000000000..f5c12f1cf --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp @@ -0,0 +1,40 @@ +// Copyright 2021 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\. + +#pragma once + +#include + +#include + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace testing { + +types::Address random_address( + unsigned int seed = 0); + +types::DiscoveryServerConnectionAddress random_connection_address( + unsigned int seed = 0, + unsigned int size = 1, + bool ros = false); + +} /* namespace testing */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp index 116934f60..8ef9a22b4 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp @@ -82,7 +82,7 @@ void CommonParticipant::onParticipantDiscovery( if (info.status == fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) { logInfo(DDSROUTER_DISCOVERY, - "Found in Participant " << this->id_nts_() << " new Participant " << info.info.m_guid << "."); + "Found in Participant " << configuration_->id << " new Participant " << info.info.m_guid << "."); } else if (info.status == fastrtps::rtps::ParticipantDiscoveryInfo::CHANGED_QOS_PARTICIPANT) { @@ -193,7 +193,7 @@ void CommonParticipant::onReaderDiscovery( if (info.status == fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERED_READER) { logInfo(DDSROUTER_DISCOVERY, - "Found in Participant " << this->id_nts_() << " new Reader " << info.info.guid() << "."); + "Found in Participant " << configuration_->id << " new Reader " << info.info.guid() << "."); this->discovery_database_->add_endpoint(info_reader); } @@ -231,7 +231,7 @@ void CommonParticipant::onWriterDiscovery( if (info.status == fastrtps::rtps::WriterDiscoveryInfo::DISCOVERED_WRITER) { logInfo(DDSROUTER_DISCOVERY, - "Found in Participant " << this->id_nts_() << " new Writer " << info.info.guid() << "."); + "Found in Participant " << configuration_->id << " new Writer " << info.info.guid() << "."); this->discovery_database_->add_endpoint(info_writer); } @@ -258,6 +258,16 @@ void CommonParticipant::onWriterDiscovery( } } +bool CommonParticipant::is_repeater() const noexcept +{ + return configuration_->is_repeater; +} + +core::types::ParticipantId CommonParticipant::id() const noexcept +{ + return configuration_->id; +} + bool CommonParticipant::is_rtps_kind() const noexcept { return true; diff --git a/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp b/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp index 23361074a..86e6765a5 100644 --- a/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp +++ b/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp @@ -75,8 +75,7 @@ void BaseReader::set_on_data_available_callback( if (on_data_available_lambda_set_) { - logDevError(DDSROUTER_BASEREADER, "Changing on_data_available callback for Reader in topic " << - topic_ << " in Participant " << participant_id_); + logDevError(DDSROUTER_BASEREADER, "Changing on_data_available callback for Reader in Participant " << participant_id_); } on_data_available_lambda_ = on_data_available_lambda; @@ -89,8 +88,7 @@ void BaseReader::unset_on_data_available_callback() noexcept if (!on_data_available_lambda_set_) { - logDevError(DDSROUTER_BASEREADER, "Unsetting a non set on_data_available callback for Reader in topic " << - topic_ << " in Participant " << participant_id_); + logDevError(DDSROUTER_BASEREADER, "Unsetting a non set on_data_available callback for Reader in Participant " << participant_id_); } on_data_available_lambda_ = DEFAULT_ON_DATA_AVAILABLE_CALLBACK; @@ -108,8 +106,7 @@ utils::ReturnCode BaseReader::take( } else { - logDevError(DDSROUTER_BASEREADER, "Attempt to take data from disabled Reader in topic " << - topic_ << " in Participant " << participant_id_); + logDevError(DDSROUTER_BASEREADER, "Attempt to take data from disabled Reader in Participant " << participant_id_); return utils::ReturnCode::RETCODE_NOT_ENABLED; } } @@ -127,8 +124,7 @@ void BaseReader::on_data_available_() const noexcept } else { - logDevError(DDSROUTER_BASEREADER, "Calling not set on_data_available callback for Reader in topic " << - topic_ << " in Participant " << participant_id_); + logDevError(DDSROUTER_BASEREADER, "Calling not set on_data_available callback for Reader in Participant " << participant_id_); } } diff --git a/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp index 8724cce80..7fa32e9cb 100644 --- a/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp +++ b/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp @@ -144,6 +144,11 @@ uint64_t CommonReader::get_unread_count() const noexcept return rtps_reader_->get_unread_count(); } +core::types::DdsTopic CommonReader::topic() const noexcept +{ + return topic_; +} + utils::ReturnCode CommonReader::take_nts_( std::unique_ptr& data) noexcept { diff --git a/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp index ac6185819..b1a8ec7e8 100644 --- a/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp +++ b/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp @@ -60,7 +60,7 @@ void SpecificQoSReader::fill_received_data_( data_to_fill.writer_qos = specific_qos_of_writer_(data_to_fill.source_guid); logDebug( DDSROUTER_SpecificQoSReader, - "Set QoS " << data_to_fill.<< " for data from " << data_to_fill.source_guid << "."); + "Set QoS " << data_to_fill.writer_qos << " for data from " << data_to_fill.source_guid << "."); } catch (const utils::InconsistencyException& e) { diff --git a/ddspipe_participants/src/cpp/testing/random_values.cpp b/ddspipe_participants/src/cpp/testing/random_values.cpp new file mode 100644 index 000000000..54d0a9353 --- /dev/null +++ b/ddspipe_participants/src/cpp/testing/random_values.cpp @@ -0,0 +1,53 @@ +// Copyright 2021 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. + +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { +namespace testing { + +using namespace eprosima::ddspipe::participants::types; + +Address random_address( + unsigned int seed /* = 0 */) +{ + return Address("127.0.0.1", seed, seed, TransportProtocol::udp); +} + +DiscoveryServerConnectionAddress random_connection_addresses( + unsigned int seed /* = 0 */, + unsigned int size /* = 1 */, + bool ros /* = false */) +{ + std::set
addresses; + for (unsigned int i = 0; i < size; ++i) + { + addresses.insert( + random_address((seed + i))); + } + + return DiscoveryServerConnectionAddress( + core::testing::random_guid_prefix(seed, ros), + addresses + ); +} + +} /* namespace testing */ +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp index 25fb83409..2101204a9 100644 --- a/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp @@ -69,8 +69,7 @@ utils::ReturnCode BaseWriter::write( } else { - logDevError(DDSROUTER_BASEWRITER, "Attempt to write data from disabled Writer in topic " << - topic_ << " in Participant " << participant_id_); + logDevError(DDSROUTER_BASEWRITER, "Attempt to write data from disabled Writer in topic in Participant " << participant_id_); return utils::ReturnCode::RETCODE_NOT_ENABLED; } } diff --git a/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp index f91bf6da9..9c0393a81 100644 --- a/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp @@ -145,8 +145,8 @@ utils::ReturnCode MultiWriter::write_( logDebug( DDSROUTER_MULTIWRITER, - "Writing in Partitions Writer " << *this << " a data with qos " << data->properties << " from " << - data->properties.source_guid); + "Writing in Partitions Writer " << *this << " a data with qos " << rtps_data.writer_qos << " from " << + rtps_data.source_guid); // Take Writer auto this_qos_writer = get_writer_or_create_(rtps_data.writer_qos); diff --git a/ddspipe_participants/test/CMakeLists.txt b/ddspipe_participants/test/CMakeLists.txt index 7ff304e5d..9edde539e 100644 --- a/ddspipe_participants/test/CMakeLists.txt +++ b/ddspipe_participants/test/CMakeLists.txt @@ -12,9 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Include utils for this specific test -include_directories("TestUtils") - -# Add subdirectory with tests -add_subdirectory(unittest) -add_subdirectory(blackbox) +# add_subdirectory(blackbox) diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/CMakeLists.txt deleted file mode 100644 index fe8f40a72..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(local) -add_subdirectory(repeater) -add_subdirectory(WAN) diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt deleted file mode 100644 index 3c70390c2..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2021 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. - -################ -# DDS Test WAN # -################ - -set(TEST_NAME - DDSTestWAN) - -set(TEST_SOURCES - DDSTestWAN.cpp - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) - -set(TEST_LIST - end_to_end_discovery_server_WAN_communication_UDPv4 - end_to_end_initial_peers_WAN_communication_UDPv4 - - end_to_end_discovery_server_WAN_communication_UDPv6 - end_to_end_initial_peers_WAN_communication_UDPv6 - - end_to_end_discovery_server_WAN_communication_TCPv4 - end_to_end_initial_peers_WAN_communication_TCPv4 - - end_to_end_discovery_server_WAN_communication_TCPv6 - end_to_end_initial_peers_WAN_communication_TCPv6 - - end_to_end_discovery_server_WAN_communication_TLSv4 - end_to_end_initial_peers_WAN_communication_TLSv4 - - end_to_end_discovery_server_WAN_communication_TLSv6 - end_to_end_initial_peers_WAN_communication_TLSv6 - - end_to_end_discovery_server_WAN_communication_high_throughput - end_to_end_initial_peers_WAN_communication_high_throughput - ) - - -set(TEST_NEEDED_SOURCES - # TLS security files - ../../resources/tls/ca.crt - ../../resources/tls/ddsrouter.crt - ../../resources/tls/ddsrouter.key - ../../resources/tls/dh_params.pem - ) - -set(TEST_EXTRA_HEADERS - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - "${TEST_EXTRA_HEADERS}") - -# Set flaky tests as xfail -add_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XFAIL.list) - -# Set as TSAN errors due to Fast DDS -# TODO: use a cmake_utils macro -file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/TEST_XTSAN.list TEST_LIST) -foreach(XTSAN_TEST ${TEST_LIST}) - set_property(TEST ${XTSAN_TEST} PROPERTY LABELS xtsan) -endforeach() diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp deleted file mode 100644 index bb297b9c0..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ /dev/null @@ -1,705 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -enum class WanParticipantKind -{ - discovery_server, - initial_peers -}; - -enum class WanKind -{ - server, - client, - server_and_client -}; - -bool is_client( - WanKind wan_kind) -{ - return wan_kind == WanKind::client || wan_kind == WanKind::server_and_client; -} - -bool is_server( - WanKind wan_kind) -{ - return wan_kind == WanKind::server || wan_kind == WanKind::server_and_client; -} - -constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; -constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; -constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes - -types::TlsConfiguration tls_configuration( - WanKind wan_kind) -{ - // TODO: test that using server with only Server required files works - // It fails when connecting to other server - if (is_server(wan_kind)) - { - types::TlsConfiguration tls; - tls.certificate_authority_file = "../../resources/tls/ca.crt"; - tls.private_key_file = "../../resources/tls/ddsrouter.key"; - tls.certificate_chain_file = "../../resources/tls/ddsrouter.crt"; - tls.dh_params_file = "../../resources/tls/dh_params.pem"; - return tls; - } - else - { - types::TlsConfiguration tls; - tls.certificate_authority_file = "../../resources/tls/ca.crt"; - return tls; - } -} - -std::shared_ptr discovery_server_participant_configuration( - bool this_server_id_is_1, - WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool tls = false) -{ - std::set listening_addresses; - std::set connection_addresses; - - if (is_client(wan_kind)) - { - connection_addresses.insert( - types::DiscoveryServerConnectionAddress( - types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), - { - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 0u : 1u), - 11666 + (this_server_id_is_1 ? 0u : 1u), - ip_version, - transport_protocol) - } - ) - ); - } - - if (is_server(wan_kind)) - { - listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 1u : 0u), - 11666 + (this_server_id_is_1 ? 1u : 0u), - ip_version, - transport_protocol) - ); - } - - if (tls) - { - return std::make_shared( - types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_discovery_server, - false, - types::DomainId(0u), - types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), - listening_addresses, - connection_addresses, - tls_configuration(wan_kind)); - - } - else - { - return std::make_shared( - types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_discovery_server, - false, - types::DomainId(0u), - types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), - listening_addresses, - connection_addresses, - types::TlsConfiguration()); - } -} - -std::shared_ptr initial_peers_participant_configuration( - bool this_server_id_is_1, - WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool tls = false) -{ - std::set listening_addresses; - std::set connection_addresses; - types::DomainId domain(60u); - - if (is_client(wan_kind)) - { - connection_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 0u : 1u), - 11666 + (this_server_id_is_1 ? 0u : 1u), - ip_version, - transport_protocol) - ); - } - - if (is_server(wan_kind)) - { - listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 1u : 0u), - 11666 + (this_server_id_is_1 ? 1u : 0u), - ip_version, - transport_protocol) - ); - } - - if (tls) - { - return std::make_shared( - types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_initial_peers, - false, - domain, - listening_addresses, - connection_addresses, - tls_configuration(wan_kind)); - - } - else - { - return std::make_shared( - types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_initial_peers, - false, - domain, - listening_addresses, - connection_addresses, - types::TlsConfiguration()); - } -} - -std::shared_ptr wan_participant_configuration( - WanParticipantKind wan_participant_kind, - bool this_server_id_is_1, - WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool tls = false) -{ - if (wan_participant_kind == WanParticipantKind::discovery_server) - { - return discovery_server_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, - tls); - } - else // WanParticipantKind::initial_peers - { - return initial_peers_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, - tls); - } -} - -/** - * @brief Create a simple configuration for a DDS Router - * - * Create a configuration with 1 topic - * Create 1 simple participants with domains \c domain - * Create 1 custom participant by the configuration in \c participant_configuration - * - * @return DdsRouterConfiguration - */ -DdsRouterConfiguration router_configuration( - std::shared_ptr participant_configuration, - types::DomainIdType domain) -{ - // One topic - auto new_topic = std::make_shared(); - new_topic->topic_name = TOPIC_NAME; - new_topic->type_name = std::string("HelloWorld"); - - std::set> allowlist({new_topic}); - - std::set> blocklist; // empty - - std::set> builtin_topics; // empty - - // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 - std::set> participants_configurations( - { - // custom - participant_configuration, - - // simple - std::make_shared( - types::ParticipantId("simple_participant_" + std::to_string(domain)), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(domain) - ), - } - ); - - return DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - SpecsConfiguration()); -} - -/** - * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. - * This is accomplished by connecting two WAN Participants belonging to different DDS Router instances. These router - * instances communicate with the DDS Participants through Simple Participants deployed at those domains. - */ -void test_WAN_communication( - DdsRouterConfiguration ddsrouter_server_configuration, - DdsRouterConfiguration ddsrouter_client_configuration, - uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, - uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, - uint32_t msg_size = DEFAULT_MESSAGE_SIZE) -{ - // Check there are no warnings/errors - // TODO: Uncomment when having no listening addresses is no longer considered an error by the middleware - // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved - // test::LogChecker test_log_handler(Log::Kind::Error); - - uint32_t samples_sent = 0; - std::atomic samples_received(0); - - // Create a message with size specified by repeating the same string - HelloWorld msg; - std::string msg_str; - - // Add this string as many times as the msg size requires - for (uint32_t i = 0; i < msg_size; i++) - { - msg_str += "Testing DdsRouter Blackbox Local Communication ..."; - } - msg.message(msg_str); - - // Create DDS Publisher in domain 0 - TestPublisher publisher; - ASSERT_TRUE(publisher.init(0)); - - // Create DDS Subscriber in domain 1 - TestSubscriber subscriber; - ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - - // Create DdsRouter entity whose WAN Participant is configured as server - DdsRouter server_router(ddsrouter_server_configuration); - server_router.start(); - - // Create DdsRouter entity whose WAN Participant is configured as client - DdsRouter client_router(ddsrouter_client_configuration); - client_router.start(); - - // Start publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - publisher.publish(msg); - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - client_router.stop(); - server_router.stop(); -} - -/** - * Test communication between WAN participants by running \c test_WAN_communication for different configurations. - * Different combinations of server/client configurations are tested. - * - * CASES: - * server <-> client - * server <-> server-client - * server-client <-> server-client (only when basic_only is deactivate) - */ -void test_WAN_communication_all( - WanParticipantKind wan_participant_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, - bool basic_only = false, - bool tls = false) -{ - // Test architecture server <-> client - test::test_WAN_communication( - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - true, // is server 1 - WanKind::server, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 0 // domain - ), - - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - false, // is server 1 - WanKind::client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 1 // domain - ) - ); - - // Test architecture server <-> server-client - test::test_WAN_communication( - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - true, // is server 1 - WanKind::server, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 0 // domain - ), - - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - false, // is server 1 - WanKind::server_and_client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 1 // domain - ) - ); - - // This test is disabled for TCPv6 and TLSv6, as an underlying middleware issue resulting in no matching for this - // scenario exists. - // TODO: Test this as well for TCPv6 and TLSv6 cases when issue is fixed - if (!basic_only) - { - // Test architecture server-client <-> server-client - test::test_WAN_communication( - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - true, // is server 1 - WanKind::server_and_client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 0 // domain - ), - - test::router_configuration( - test::wan_participant_configuration( - wan_participant_kind, - false, // is server 1 - WanKind::server_and_client, - transport_protocol, // transport protocol - ip_version, // ip version - tls // tls - ), - 1 // domain - ) - ); - } -} - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through UDPv4. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::udp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through UDPv4. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::udp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through UDPv6. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::udp, - types::IpVersion::v6); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through UDPv6. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::udp, - types::IpVersion::v6); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TCPv4. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TCPv4. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v4); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TCPv6. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TCPv6. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TLSv4. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v4, - false, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TLSv4. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv4) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v4, - false, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through TLSv6. - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true, - true); -} - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through TLSv6. - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv6) -{ - test::test_WAN_communication_all( - test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v6, - true, - true); -} - -/** - * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected - * through UDPv4. - * - * PARAMETERS: - * - Frequency: 1ms - * - Sample size: 50K - * -> Throughput: 50MBps - */ -TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_high_throughput) -{ - test::test_WAN_communication( - test::router_configuration( - test::discovery_server_participant_configuration( - true, // is server 1 - test::WanKind::server, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 0 // domain - ), - - test::router_configuration( - test::discovery_server_participant_configuration( - false, // is server 1 - test::WanKind::client, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 1 // domain - ), - - 500, - 1, - 1000); // 50K message size -} - -/** - * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, - * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected - * through UDPv4. - * - * PARAMETERS: - * - Frequency: 1ms - * - Sample size: 50K - * -> Throughput: 50MBps - */ -TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_high_throughput) -{ - test::test_WAN_communication( - test::router_configuration( - test::initial_peers_participant_configuration( - true, // is server 1 - test::WanKind::server, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 0 // domain - ), - - test::router_configuration( - test::initial_peers_participant_configuration( - false, // is server 1 - test::WanKind::client, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version - ), - 1 // domain - ), - - 500, - 1, - 1000); // 50K message size -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md deleted file mode 100644 index 943086ca9..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# DDS Test WAN - -Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. -This is accomplished by connecting two (`DiscoveryServer` / `InitialPeers`) WAN Participants belonging to different DDS Router instances. -These router instances communicate with the DDS Participants through Simple Participants deployed at those domains. -Note that, although data transmission is accomplished by connecting two WAN Participants, the resulting communication -is still local (i.e. WAN communication is not tested here). diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list deleted file mode 100644 index 7aded2b7b..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list +++ /dev/null @@ -1,8 +0,0 @@ -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv6 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv6 diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list deleted file mode 100644 index 78996681f..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list +++ /dev/null @@ -1,5 +0,0 @@ -DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt deleted file mode 100644 index f98f1006c..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2021 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. - -################## -# DDS Test local # -################## - -set(TEST_NAME - DDSTestLocal) - -set(TEST_SOURCES - DDSTestLocal.cpp - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) - -set(TEST_LIST - end_to_end_local_communication - end_to_end_local_communication_keyed - end_to_end_local_communication_disable_dynamic_discovery - end_to_end_local_communication_disable_dynamic_discovery_keyed - end_to_end_local_communication_high_frequency - end_to_end_local_communication_high_size - end_to_end_local_communication_high_throughput - end_to_end_local_communication_transient_local - end_to_end_local_communication_transient_local_disable_dynamic_discovery) - -set(TEST_NEEDED_SOURCES - ) - -set(TEST_EXTRA_HEADERS - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - "${TEST_EXTRA_HEADERS}") - -############################## -# DDS Test local Dispose Key # -############################## - -set(TEST_NAME - DDSTestLocalDisposeKey) - -set(TEST_SOURCES - DDSTestLocalDisposeKey.cpp - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) - -set(TEST_LIST - end_to_end_local_communication_key_dispose) - -set(TEST_NEEDED_SOURCES - ) - -set(TEST_EXTRA_HEADERS - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, - ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - "${TEST_EXTRA_HEADERS}") diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp deleted file mode 100644 index 896372e23..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; -constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; -constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes - -/** - * @brief Create a simple configuration for a DDS Router - * - * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME - * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. - * Create 2 simple participants with domains 0 and 1 - * - * @return DdsRouterConfiguration - */ -DdsRouterConfiguration dds_test_simple_configuration( - bool disable_dynamic_discovery = false, - bool transient_local_readers = false) -{ - // Always filter the test topics by topic name - std::set> allowlist; // empty - allowlist.insert(std::make_shared(TOPIC_NAME)); - - std::set> blocklist; // empty - - std::set> builtin_topics; // empty - - if (disable_dynamic_discovery) - { - types::TopicQoS qos; - if (transient_local_readers) - { - qos.reliability_qos = types::ReliabilityKind::RELIABLE; - qos.durability_qos = types::DurabilityKind::TRANSIENT_LOCAL; - } - else - { - qos.reliability_qos = types::ReliabilityKind::BEST_EFFORT; - qos.durability_qos = types::DurabilityKind::VOLATILE; - } - - builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); - builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); - } - - // Two simple participants - std::set> participants_configurations( - { - std::make_shared( - types::ParticipantId("participant_0"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(0u) - ), - std::make_shared( - types::ParticipantId("participant_1"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(1u) - ) - } - ); - - return DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - SpecsConfiguration()); -} - -/** - * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. - * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. - * - * The transient_local option changes the test behavior to verify that the communication is transient_local and all old data is sent - * to Late Joiners. - */ -template -void test_local_communication( - DdsRouterConfiguration ddsrouter_configuration, - uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, - uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, - uint32_t msg_size = DEFAULT_MESSAGE_SIZE, - bool transient_local = false) -{ - - // Check there are no warnings/errors - // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved - // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - uint32_t samples_sent = 0; - std::atomic samples_received(0); - - // Create a message with size specified by repeating the same string - MsgStruct msg; - std::string msg_str; - - // Add this string as many times as the msg size requires - for (uint32_t i = 0; i < msg_size; i++) - { - msg_str += "Testing DdsRouter Blackbox Local Communication ..."; - } - msg.message(msg_str); - - // Create DDS Publisher in domain 0 - TestPublisher publisher(msg.isKeyDefined()); - ASSERT_TRUE(publisher.init(0)); - - // Create DDS Subscriber in domain 1 - TestSubscriber subscriber(msg.isKeyDefined(), transient_local); - ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - - // Create DdsRouter entity - // The DDS Router does not start here in order to test a transient_local communication - DdsRouter router(ddsrouter_configuration); - - if (transient_local) - { - // To check that the communication is transient_local and all previous published samples are sent to late joiner, - // the publisher publish all data at once. - for (samples_sent = 0; samples_sent < samples_to_receive; samples_sent++) - { - msg.index(samples_sent); - ASSERT_TRUE(publisher.publish(msg)); - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - // Once the publisher has already publish all its samples, the DDS Router starts. - router.start(); - - // The subscriber should receive all samples sent by the publisher when the communication was not - // already established. - while (samples_received.load() < samples_to_receive) - { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - } - else - { - // Start DDS Router - router.start(); - - // Start publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - publisher.publish(msg); - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - } - - router.stop(); -} - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -/** - * Test communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - */ -TEST(DDSTestLocal, end_to_end_local_communication) -{ - test::test_local_communication( - test::dds_test_simple_configuration()); -} - -/** - * Test communication in HelloWorldKeyed topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - */ -TEST(DDSTestLocal, end_to_end_local_communication_keyed) -{ - test::test_local_communication( - test::dds_test_simple_configuration()); -} - -/** - * Test communication both in HelloWorld and HelloWorldKeyed topics between two DDS participants created in - * different domains, by using a router with two Simple Participants at each domain. - * In this test allowlist and blocklist are left empty, while only builtin topics are provided. - */ -TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery) -{ - test::test_local_communication( - test::dds_test_simple_configuration(true)); -} - -TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery_keyed) -{ - test::test_local_communication( - test::dds_test_simple_configuration(true)); -} - -/** - * Test high frequency communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - * - * PARAMETERS: - * - Frequency: max - */ -TEST(DDSTestLocal, end_to_end_local_communication_high_frequency) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - 1000, // wait for 1000 samples received - 0); // send it without waiting from one sample to the other -} - -/** - * Test high message size communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - * - * PARAMETERS: - * - Sample size: 500K - */ -TEST(DDSTestLocal, end_to_end_local_communication_high_size) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - test::DEFAULT_SAMPLES_TO_RECEIVE, - test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, - 10000); // 500K message size -} - -/** - * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - * - * PARAMETERS: - * - Frequency: 1ms - * - Sample size: 50K - * -> Throughput: 50MBps - */ -TEST(DDSTestLocal, end_to_end_local_communication_high_throughput) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - 500, - 1, - 1000); // 50K message size -} - -/** - * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. - */ -TEST(DDSTestLocal, end_to_end_local_communication_transient_local) -{ - test::test_local_communication( - test::dds_test_simple_configuration(), - test::DEFAULT_SAMPLES_TO_RECEIVE, - test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, - test::DEFAULT_MESSAGE_SIZE, - true); -} - -/** - * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain and using builtin-topics - */ -TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynamic_discovery) -{ - test::test_local_communication( - test::dds_test_simple_configuration(true, true), - test::DEFAULT_SAMPLES_TO_RECEIVE, - test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, - test::DEFAULT_MESSAGE_SIZE, - true); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp deleted file mode 100644 index ef8532859..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; -constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; -constexpr const uint32_t DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION = 500; -constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes - -/** - * @brief Create a simple configuration for a DDS Router - * - * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME - * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. - * Create 2 simple participants with domains 0 and 1 - * - * @return DdsRouterConfiguration - */ -DdsRouterConfiguration dds_test_simple_configuration() -{ - // Always filter the test topics by topic name - std::set> allowlist; // only this topic - allowlist.insert(std::make_shared(TOPIC_NAME)); - - std::set> blocklist; // empty - - std::set> builtin_topics; // empty - - // Two simple participants - std::set> participants_configurations( - { - std::make_shared( - types::ParticipantId("participant_0"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(0u) - ), - std::make_shared( - types::ParticipantId("participant_1"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(1u) - ) - } - ); - - // TODO: this could be removed to use default number of threads - auto specs = SpecsConfiguration(); - specs.number_of_threads = 2; - - return DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - specs); -} - -/** - * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. - * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. - * - * The reliable option changes the test behavior to verify that the communication is reliable and all old data is sent - * to Late Joiners. - */ -void test_local_communication_key_dispose( - DdsRouterConfiguration ddsrouter_configuration, - uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, - uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, - uint32_t msg_size = DEFAULT_MESSAGE_SIZE) -{ - // Check there are no warnings/errors - // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved - // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - uint32_t samples_sent = 0; - std::atomic samples_received(0); - - // Create a message with size specified by repeating the same string - HelloWorldKeyed msg; - std::string msg_str; - - // Add this string as many times as the msg size requires - for (uint32_t i = 0; i < msg_size; i++) - { - msg_str += "Testing DdsRouter Blackbox Local Communication ..."; - } - msg.message(msg_str); - msg.id(666); - - // Create DDS Publisher in domain 0 - TestPublisher publisher(msg.isKeyDefined()); - ASSERT_TRUE(publisher.init(0)); - - // Create DDS Subscriber in domain 1 - TestSubscriber subscriber(msg.isKeyDefined()); - ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); - - // Create DdsRouter entity - // The DDS Router does not start here in order to test a reliable communication - DdsRouter router(ddsrouter_configuration); - - // Start DDS Router - router.start(); - - // Start publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - ASSERT_TRUE(publisher.publish(msg)) << samples_sent; - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - // All samples received, now dispose key from publisher and check that subscriber has receive it - ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); - std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); - samples_received.store(0); - - // Keep publishing - while (samples_received.load() < samples_to_receive) - { - msg.index(++samples_sent); - ASSERT_TRUE(publisher.publish(msg)) << samples_sent; - - // If time is 0 do not wait - if (time_between_samples > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); - } - } - - // All samples received, now dispose key from publisher and check that subscriber has receive it - ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); - std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); - - ASSERT_EQ(2u, subscriber.n_disposed()); - - router.stop(); -} - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -/** - * Test that dispose values from the publisher are correctly received by the subscriber from the router. - */ -TEST(DDSTestLocalDisposeKey, end_to_end_local_communication_key_dispose) -{ - test::test_local_communication_key_dispose( - test::dds_test_simple_configuration()); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md deleted file mode 100644 index a94c61e34..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/local/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# DDS Test Local - -Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. -This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. -First, router initialization is tested, and then communication between the DDS Participants is tested both for topics -*HelloWorld* and *HelloWorldKeyed*. diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx deleted file mode 100644 index b850b4501..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2016 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 HelloWorld.cpp - * This source file contains the definition of the described types in the IDL file. - * - * This file was generated by the tool gen. - */ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { char dummy; } -#endif - -#include "HelloWorld.h" -#include - -#include -using namespace eprosima::fastcdr::exception; - -#include - -HelloWorld::HelloWorld() -{ - // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@1622f1b - m_index = 0; - // m_message com.eprosima.idl.parser.typecode.StringTypeCode@70e8f8e - m_message =""; - -} - -HelloWorld::~HelloWorld() -{ - - -} - -HelloWorld::HelloWorld(const HelloWorld &x) -{ - m_index = x.m_index; - m_message = x.m_message; -} - -HelloWorld::HelloWorld(HelloWorld &&x) -{ - m_index = x.m_index; - m_message = std::move(x.m_message); -} - -HelloWorld& HelloWorld::operator=(const HelloWorld &x) -{ - - m_index = x.m_index; - m_message = x.m_message; - - return *this; -} - -HelloWorld& HelloWorld::operator=(HelloWorld &&x) -{ - - m_index = x.m_index; - m_message = std::move(x.m_message); - - return *this; -} - -size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment) -{ - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; - - - return current_alignment - initial_alignment; -} - -size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; - - - return current_alignment - initial_alignment; -} - -void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const -{ - - scdr << m_index; - scdr << m_message; -} - -void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr) -{ - - dcdr >> m_index; - dcdr >> m_message; -} - -/*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ -void HelloWorld::index(uint32_t _index) -{ -m_index = _index; -} - -/*! - * @brief This function returns the value of member index - * @return Value of member index - */ -uint32_t HelloWorld::index() const -{ - return m_index; -} - -/*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ -uint32_t& HelloWorld::index() -{ - return m_index; -} - -/*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ -void HelloWorld::message(const std::string &_message) -{ -m_message = _message; -} - -/*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ -void HelloWorld::message(std::string &&_message) -{ -m_message = std::move(_message); -} - -/*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ -const std::string& HelloWorld::message() const -{ - return m_message; -} - -/*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ -std::string& HelloWorld::message() -{ - return m_message; -} - -size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment) -{ - size_t current_align = current_alignment; - - - - - - return current_align; -} - -bool HelloWorld::isKeyDefined() -{ - return false; -} - -void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const -{ - (void) scdr; - - -} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h deleted file mode 100644 index c445fff76..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright 2016 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 HelloWorld.h - * This header file contains the declaration of the described types in the IDL file. - * - * This file was generated by the tool gen. - */#pragma once - -// TODO Poner en el contexto. - -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // if defined(EPROSIMA_USER_DLL_EXPORT) -#else -#define eProsima_user_DllExport -#endif // if defined(_WIN32) - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined(HelloWorld_SOURCE) -#define HelloWorld_DllAPI __declspec( dllexport ) -#else -#define HelloWorld_DllAPI __declspec( dllimport ) -#endif // HelloWorld_SOURCE -#else -#define HelloWorld_DllAPI -#endif // if defined(EPROSIMA_USER_DLL_EXPORT) -#else -#define HelloWorld_DllAPI -#endif // _WIN32 - -namespace eprosima { -namespace fastcdr { -class Cdr; -} // namespace fastcdr -} // namespace eprosima - - -/*! - * @brief This class represents the structure HelloWorld defined by the user in the IDL file. - * @ingroup HELLOWORLD - */ -class HelloWorld -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport HelloWorld(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~HelloWorld(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld( - const HelloWorld& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld( - HelloWorld&& x); - - /*! - * @brief Copy assignment. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld& operator =( - const HelloWorld& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld& operator =( - HelloWorld&& x); - - /*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ - eProsima_user_DllExport void index( - uint32_t _index); - - /*! - * @brief This function returns the value of member index - * @return Value of member index - */ - eProsima_user_DllExport uint32_t index() const; - - /*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ - eProsima_user_DllExport uint32_t& index(); - - /*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ - eProsima_user_DllExport void message( - const std::string& _message); - - /*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ - eProsima_user_DllExport void message( - std::string&& _message); - - /*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ - eProsima_user_DllExport const std::string& message() const; - - /*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ - eProsima_user_DllExport std::string& message(); - - /*! - * @brief This function returns the maximum serialized size of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function returns the serialized size of a data depending on the buffer alignment. - * @param data Data which is calculated its serialized size. - * @param current_alignment Buffer alignment. - * @return Serialized size. - */ - eProsima_user_DllExport static size_t getCdrSerializedSize( - const HelloWorld& data, - size_t current_alignment = 0); - - - /*! - * @brief This function serializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serialize( - eprosima::fastcdr::Cdr& cdr) const; - - /*! - * @brief This function deserializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void deserialize( - eprosima::fastcdr::Cdr& cdr); - - - - /*! - * @brief This function returns the maximum serialized size of the Key of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function tells you if the Key has been defined for this type - */ - eProsima_user_DllExport static bool isKeyDefined(); - - /*! - * @brief This function serializes the key members of an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serializeKey( - eprosima::fastcdr::Cdr& cdr) const; - -private: - - uint32_t m_index; - std::string m_message; -}; - -#endif // _HELLOWORLD_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl deleted file mode 100644 index 0fd2c355a..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl +++ /dev/null @@ -1,5 +0,0 @@ -struct HelloWorld -{ - unsigned long index; - string message; -}; diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx deleted file mode 100644 index a2a27e7bc..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2016 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 HelloWorldPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ - - -#include -#include - -#include "HelloWorldPubSubTypes.h" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; - -HelloWorldPubSubType::HelloWorldPubSubType() -{ - setName("HelloWorld"); - m_typeSize = static_cast(HelloWorld::getMaxCdrSerializedSize()) + 4 /*encapsulation*/; - m_isGetKeyDefined = HelloWorld::isKeyDefined(); - size_t keyLength = HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -HelloWorldPubSubType::~HelloWorldPubSubType() -{ - if(m_keyBuffer!=nullptr) - free(m_keyBuffer); -} - -bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) -{ - HelloWorld *p_type = static_cast(data); - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - // Serialize encapsulation - ser.serialize_encapsulation(); - - try - { - p_type->serialize(ser); // Serialize the object: - } - catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - payload->length = static_cast(ser.getSerializedDataLength()); //Get the serialized length - return true; -} - -bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) -{ - HelloWorld* p_type = static_cast(data); //Convert DATA to pointer of your type - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data. - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - try - { - p_type->deserialize(deser); //Deserialize the object: - } - catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloWorldPubSubType::getSerializedSizeProvider(void* data) -{ - return [data]() -> uint32_t - { - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + 4 /*encapsulation*/; - }; -} - -void* HelloWorldPubSubType::createData() -{ - return reinterpret_cast(new HelloWorld()); -} - -void HelloWorldPubSubType::deleteData(void* data) -{ - delete(reinterpret_cast(data)); -} - -bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5) -{ - if(!m_isGetKeyDefined) - return false; - HelloWorld* p_type = static_cast(data); - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer),HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data. - p_type->serializeKey(ser); - if(force_md5 || HelloWorld::getKeyMaxCdrSerializedSize()>16) { - m_md5.init(); - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); - m_md5.finalize(); - for(uint8_t i = 0;i<16;++i) { - handle->value[i] = m_md5.digest[i]; - } - } - else { - for(uint8_t i = 0;i<16;++i) { - handle->value[i] = m_keyBuffer[i]; - } - } - return true; -} - diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h deleted file mode 100644 index 44f12a5b5..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 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 HelloWorldPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ -#pragma once - -#include -#include - -#include "HelloWorld.h" - -#if !defined(GEN_API_VER) || (GEN_API_VER != 1) -#error Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // if !defined(GEN_API_VER) || (GEN_API_VER != 1) - -/*! - * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. - * @ingroup HELLOWORLD - */ -class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorld type; - - eProsima_user_DllExport HelloWorldPubSubType(); - - eProsima_user_DllExport virtual ~HelloWorldPubSubType(); - eProsima_user_DllExport virtual bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; - eProsima_user_DllExport virtual bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - eProsima_user_DllExport virtual std::function getSerializedSizeProvider( - void* data) override; - eProsima_user_DllExport virtual bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - eProsima_user_DllExport virtual void* createData() override; - eProsima_user_DllExport virtual void deleteData( - void* data) override; - MD5 m_md5; - unsigned char* m_keyBuffer; -}; - -#endif // _HELLOWORLD_PUBSUBTYPES_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx deleted file mode 100644 index 43e4eb3b9..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyed.cpp - * This source file contains the definition of the described types in the IDL file. - * - * This file was generated by the tool gen. - */ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { -char dummy; -} // namespace -#endif // _WIN32 - -#include "HelloWorldKeyed.h" -#include - -#include -using namespace eprosima::fastcdr::exception; - -#include - -HelloWorldKeyed::HelloWorldKeyed() -{ - // m_id com.eprosima.idl.parser.typecode.PrimitiveTypeCode@77a57272 - m_id = 0; - // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@7181ae3f - m_index = 0; - // m_message com.eprosima.idl.parser.typecode.StringTypeCode@46238e3f - m_message =""; - -} - -HelloWorldKeyed::~HelloWorldKeyed() -{ - - - -} - -HelloWorldKeyed::HelloWorldKeyed( - const HelloWorldKeyed& x) -{ - m_id = x.m_id; - m_index = x.m_index; - m_message = x.m_message; -} - -HelloWorldKeyed::HelloWorldKeyed( - HelloWorldKeyed&& x) -{ - m_id = x.m_id; - m_index = x.m_index; - m_message = std::move(x.m_message); -} - -HelloWorldKeyed& HelloWorldKeyed::operator =( - const HelloWorldKeyed& x) -{ - - m_id = x.m_id; - m_index = x.m_index; - m_message = x.m_message; - - return *this; -} - -HelloWorldKeyed& HelloWorldKeyed::operator =( - HelloWorldKeyed&& x) -{ - - m_id = x.m_id; - m_index = x.m_index; - m_message = std::move(x.m_message); - - return *this; -} - -bool HelloWorldKeyed::operator ==( - const HelloWorldKeyed& x) const -{ - - return (m_id == x.m_id && m_index == x.m_index && m_message == x.m_message); -} - -bool HelloWorldKeyed::operator !=( - const HelloWorldKeyed& x) const -{ - return !(*this == x); -} - -size_t HelloWorldKeyed::getMaxCdrSerializedSize( - size_t current_alignment) -{ - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; - - - return current_alignment - initial_alignment; -} - -size_t HelloWorldKeyed::getCdrSerializedSize( - const HelloWorldKeyed& data, - size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); - - - current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; - - - return current_alignment - initial_alignment; -} - -void HelloWorldKeyed::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - - scdr << m_id; - scdr << m_index; - scdr << m_message; - -} - -void HelloWorldKeyed::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - - dcdr >> m_id; - dcdr >> m_index; - dcdr >> m_message; -} - -/*! - * @brief This function sets a value in member id - * @param _id New value for member id - */ -void HelloWorldKeyed::id( - int32_t _id) -{ - m_id = _id; -} - -/*! - * @brief This function returns the value of member id - * @return Value of member id - */ -int32_t HelloWorldKeyed::id() const -{ - return m_id; -} - -/*! - * @brief This function returns a reference to member id - * @return Reference to member id - */ -int32_t& HelloWorldKeyed::id() -{ - return m_id; -} - -/*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ -void HelloWorldKeyed::index( - uint32_t _index) -{ - m_index = _index; -} - -/*! - * @brief This function returns the value of member index - * @return Value of member index - */ -uint32_t HelloWorldKeyed::index() const -{ - return m_index; -} - -/*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ -uint32_t& HelloWorldKeyed::index() -{ - return m_index; -} - -/*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ -void HelloWorldKeyed::message( - const std::string& _message) -{ - m_message = _message; -} - -/*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ -void HelloWorldKeyed::message( - std::string&& _message) -{ - m_message = std::move(_message); -} - -/*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ -const std::string& HelloWorldKeyed::message() const -{ - return m_message; -} - -/*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ -std::string& HelloWorldKeyed::message() -{ - return m_message; -} - -size_t HelloWorldKeyed::getKeyMaxCdrSerializedSize( - size_t current_alignment) -{ - size_t current_align = current_alignment; - - - current_align += 4 + eprosima::fastcdr::Cdr::alignment(current_align, 4); - - - - - - return current_align; -} - -bool HelloWorldKeyed::isKeyDefined() -{ - return true; -} - -void HelloWorldKeyed::serializeKey( - eprosima::fastcdr::Cdr& scdr) const -{ - (void) scdr; - scdr << m_id; - -} diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h deleted file mode 100644 index 8b1d2787e..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyed.h - * This header file contains the declaration of the described types in the IDL file. - * - * This file was generated by the tool gen. - */#pragma once - - -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined(HelloWorldKeyed_SOURCE) -#define HelloWorldKeyed_DllAPI __declspec( dllexport ) -#else -#define HelloWorldKeyed_DllAPI __declspec( dllimport ) -#endif // HelloWorldKeyed_SOURCE -#else -#define HelloWorldKeyed_DllAPI -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define HelloWorldKeyed_DllAPI -#endif // _WIN32 - -namespace eprosima { -namespace fastcdr { -class Cdr; -} // namespace fastcdr -} // namespace eprosima - - -/*! - * @brief This class represents the structure HelloWorldKeyed defined by the user in the IDL file. - * @ingroup HELLOWORLDKEYED - */ -class HelloWorldKeyed -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport HelloWorldKeyed(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~HelloWorldKeyed(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed( - const HelloWorldKeyed& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed( - HelloWorldKeyed&& x); - - /*! - * @brief Copy assignment. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed& operator =( - const HelloWorldKeyed& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object HelloWorldKeyed that will be copied. - */ - eProsima_user_DllExport HelloWorldKeyed& operator =( - HelloWorldKeyed&& x); - - /*! - * @brief Comparison operator. - * @param x HelloWorldKeyed object to compare. - */ - eProsima_user_DllExport bool operator ==( - const HelloWorldKeyed& x) const; - - /*! - * @brief Comparison operator. - * @param x HelloWorldKeyed object to compare. - */ - eProsima_user_DllExport bool operator !=( - const HelloWorldKeyed& x) const; - - /*! - * @brief This function sets a value in member id - * @param _id New value for member id - */ - eProsima_user_DllExport void id( - int32_t _id); - - /*! - * @brief This function returns the value of member id - * @return Value of member id - */ - eProsima_user_DllExport int32_t id() const; - - /*! - * @brief This function returns a reference to member id - * @return Reference to member id - */ - eProsima_user_DllExport int32_t& id(); - - /*! - * @brief This function sets a value in member index - * @param _index New value for member index - */ - eProsima_user_DllExport void index( - uint32_t _index); - - /*! - * @brief This function returns the value of member index - * @return Value of member index - */ - eProsima_user_DllExport uint32_t index() const; - - /*! - * @brief This function returns a reference to member index - * @return Reference to member index - */ - eProsima_user_DllExport uint32_t& index(); - - /*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ - eProsima_user_DllExport void message( - const std::string& _message); - - /*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ - eProsima_user_DllExport void message( - std::string&& _message); - - /*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ - eProsima_user_DllExport const std::string& message() const; - - /*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ - eProsima_user_DllExport std::string& message(); - - /*! - * @brief This function returns the maximum serialized size of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function returns the serialized size of a data depending on the buffer alignment. - * @param data Data which is calculated its serialized size. - * @param current_alignment Buffer alignment. - * @return Serialized size. - */ - eProsima_user_DllExport static size_t getCdrSerializedSize( - const HelloWorldKeyed& data, - size_t current_alignment = 0); - - - /*! - * @brief This function serializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serialize( - eprosima::fastcdr::Cdr& cdr) const; - - /*! - * @brief This function deserializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void deserialize( - eprosima::fastcdr::Cdr& cdr); - - - - /*! - * @brief This function returns the maximum serialized size of the Key of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( - size_t current_alignment = 0); - - /*! - * @brief This function tells you if the Key has been defined for this type - */ - eProsima_user_DllExport static bool isKeyDefined(); - - /*! - * @brief This function serializes the key members of an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serializeKey( - eprosima::fastcdr::Cdr& cdr) const; - -private: - - int32_t m_id; - uint32_t m_index; - std::string m_message; -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl deleted file mode 100644 index 6cebe626d..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl +++ /dev/null @@ -1,6 +0,0 @@ -struct HelloWorldKeyed -{ - @Key long id; - unsigned long index; - string message; -}; diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx deleted file mode 100644 index 61eb7c992..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyedPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ - - -#include -#include - -#include "HelloWorldKeyedPubSubTypes.h" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; - -HelloWorldKeyedPubSubType::HelloWorldKeyedPubSubType() -{ - setName("HelloWorldKeyed"); - auto type_size = HelloWorldKeyed::getMaxCdrSerializedSize(); - type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ - m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ - m_isGetKeyDefined = HelloWorldKeyed::isKeyDefined(); - size_t keyLength = HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16 ? - HelloWorldKeyed::getKeyMaxCdrSerializedSize() : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -HelloWorldKeyedPubSubType::~HelloWorldKeyedPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool HelloWorldKeyedPubSubType::serialize( - void* data, - SerializedPayload_t* payload) -{ - HelloWorldKeyed* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - // Serialize encapsulation - ser.serialize_encapsulation(); - - try - { - // Serialize the object. - p_type->serialize(ser); - } - catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - // Get the serialized length - payload->length = static_cast(ser.getSerializedDataLength()); - return true; -} - -bool HelloWorldKeyedPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - //Convert DATA to pointer of your type - HelloWorldKeyed* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - try - { - // Deserialize the object. - p_type->deserialize(deser); - } - catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloWorldKeyedPubSubType::getSerializedSizeProvider( - void* data) -{ - return [data]() -> uint32_t - { - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; - }; -} - -void* HelloWorldKeyedPubSubType::createData() -{ - return reinterpret_cast(new HelloWorldKeyed()); -} - -void HelloWorldKeyedPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool HelloWorldKeyedPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - HelloWorldKeyed* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - HelloWorldKeyed::getKeyMaxCdrSerializedSize()); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); - p_type->serializeKey(ser); - if (force_md5 || HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16) - { - m_md5.init(); - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); - m_md5.finalize(); - for (uint8_t i = 0; i < 16; ++i) - { - handle->value[i] = m_md5.digest[i]; - } - } - else - { - for (uint8_t i = 0; i < 16; ++i) - { - handle->value[i] = m_keyBuffer[i]; - } - } - return true; -} - diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h deleted file mode 100644 index d4a3a204f..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2016 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 HelloWorldKeyedPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastcdrgen. - */ -#pragma once - -#include -#include - -#include "HelloWorldKeyed.h" - -#if !defined(GEN_API_VER) || (GEN_API_VER != 1) -#error \ - Generated HelloWorldKeyed is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - -/*! - * @brief This class represents the TopicDataType of the type HelloWorldKeyed defined by the user in the IDL file. - * @ingroup HELLOWORLDKEYED - */ -class HelloWorldKeyedPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorldKeyed type; - - eProsima_user_DllExport HelloWorldKeyedPubSubType(); - - eProsima_user_DllExport virtual ~HelloWorldKeyedPubSubType(); - - eProsima_user_DllExport virtual bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; - - eProsima_user_DllExport virtual bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport virtual std::function getSerializedSizeProvider( - void* data) override; - - eProsima_user_DllExport virtual bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport virtual void* createData() override; - - eProsima_user_DllExport virtual void deleteData( - void* data) override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - (void)memory; - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp deleted file mode 100644 index 7bcde346e..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp +++ /dev/null @@ -1,495 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorld/HelloWorldPubSubTypes.h" -#include "HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h" - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace test { - -constexpr const char* TOPIC_NAME = "DDS-Router-Test"; - -/** - * Class used to group into a single working unit a Publisher with a DataWriter and a TypeSupport member corresponding - * to the HelloWorld datatype - */ -template -class TestPublisher -{ -public: - - TestPublisher( - bool keyed = false) - : participant_(nullptr) - , publisher_(nullptr) - , topic_(nullptr) - , writer_(nullptr) - , keyed_(keyed) - { - } - - ~TestPublisher() - { - if (participant_ != nullptr) - { - if (publisher_ != nullptr) - { - if (writer_ != nullptr) - { - publisher_->delete_datawriter(writer_); - } - participant_->delete_publisher(publisher_); - } - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); - } - } - - //! Initialize the publisher - bool init( - uint32_t domain) - { - // CREATE THE PARTICIPANT - eprosima::fastdds::dds::DomainParticipantQos pqos; - - pqos.name("Participant_pub"); - participant_ = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); - - if (participant_ == nullptr) - { - return false; - } - - // REGISTER THE TYPE - eprosima::fastdds::dds::TypeSupport type; - if (keyed_) - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); - } - else - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); - } - type.register_type(participant_); - - // CREATE THE PUBLISHER - publisher_ = participant_->create_publisher(eprosima::fastdds::dds::PUBLISHER_QOS_DEFAULT, nullptr); - - if (publisher_ == nullptr) - { - return false; - } - - // CREATE THE TOPIC - std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; - topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - // CREATE THE WRITER - // Set memory management policy so it uses realloc - eprosima::fastdds::dds::DataWriterQos wqos = eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT; - wqos.endpoint().history_memory_policy = - eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - wqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; - writer_ = publisher_->create_datawriter(topic_, wqos, &listener_); - - if (writer_ == nullptr) - { - return false; - } - - return true; - } - - //! Publish a sample - bool publish( - MsgStruct msg) - { - hello_.index(msg.index()); - hello_.message(msg.message()); - return writer_->write(&hello_); - } - - //! Dispose instance - eprosima::fastrtps::types::ReturnCode_t dispose_key( - MsgStruct msg); - - void wait_discovery( - uint32_t n_subscribers = 1) - { - listener_.wait_discovery(n_subscribers); - } - -private: - - MsgStruct hello_; - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Publisher* publisher_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataWriter* writer_; - - bool keyed_; - - class PubListener : public eprosima::fastdds::dds::DataWriterListener - { - public: - - PubListener() - : discovered(0) - { - } - - void wait_discovery( - uint32_t n_subscribers = 1) - { - if (discovered < n_subscribers) - { - std::unique_lock lock(wait_discovery_cv_mtx); - wait_discovery_cv.wait(lock, [this, n_subscribers] - { - return discovered >= n_subscribers; - }); - } - } - - void on_publication_matched( - eprosima::fastdds::dds::DataWriter*, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) - { - if (info.current_count_change == 1) - { - discovered = info.current_count; - wait_discovery_cv.notify_all(); - } - else if (info.current_count_change == -1) - { - discovered = info.current_count; - } - } - - private: - - //! Number of DataReaders discovered - std::atomic discovered; - - //! Protects wait_discovery condition variable - std::mutex wait_discovery_cv_mtx; - - //! Waits to discovery enough DataReaders - std::condition_variable wait_discovery_cv; - } - listener_; -}; - -template <> -bool TestPublisher::publish( - HelloWorldKeyed msg) -{ - hello_.index(msg.index()); - hello_.message(msg.message()); - hello_.id(msg.id()); - return writer_->write(&hello_); -} - -template <> -eprosima::fastrtps::types::ReturnCode_t TestPublisher::dispose_key( - HelloWorldKeyed msg) -{ - hello_.id(msg.id()); - return writer_->dispose(&hello_, eprosima::fastdds::dds::HANDLE_NIL); -} - -/** - * Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member - * corresponding to the HelloWorld datatype - */ -template -class TestSubscriber -{ -public: - - TestSubscriber( - bool keyed = false, - bool reliable = false) - : participant_(nullptr) - , subscriber_(nullptr) - , topic_(nullptr) - , reader_(nullptr) - , keyed_(keyed) - , reliable_ (reliable) - { - } - - ~TestSubscriber() - { - if (participant_ != nullptr) - { - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - if (subscriber_ != nullptr) - { - if (reader_ != nullptr) - { - subscriber_->delete_datareader(reader_); - } - participant_->delete_subscriber(subscriber_); - } - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); - } - } - - //! Initialize the subscriber - bool init( - uint32_t domain, - MsgStruct* msg_should_receive, - std::atomic* samples_received) - { - // INITIALIZE THE LISTENER - listener_.init(msg_should_receive, samples_received); - - // CREATE THE PARTICIPANT - eprosima::fastdds::dds::DomainParticipantQos pqos; - pqos.name("Participant_sub"); - participant_ = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); - - if (participant_ == nullptr) - { - return false; - } - - // REGISTER THE TYPE - eprosima::fastdds::dds::TypeSupport type; - if (keyed_) - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); - } - else - { - type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); - } - type.register_type(participant_); - - // CREATE THE SUBSCRIBER - subscriber_ = participant_->create_subscriber(eprosima::fastdds::dds::SUBSCRIBER_QOS_DEFAULT, nullptr); - - if (subscriber_ == nullptr) - { - return false; - } - - // CREATE THE TOPIC - std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; - topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - // CREATE THE READER - // Set memory management policy so it uses realloc - eprosima::fastdds::dds::DataReaderQos rqos = eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT; - rqos.endpoint().history_memory_policy = - eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - rqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; - if (reliable_) - { - rqos.durability().kind = eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; - rqos.reliability().kind = eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; - } - - reader_ = subscriber_->create_datareader(topic_, rqos, &listener_); - - if (reader_ == nullptr) - { - return false; - } - - return true; - } - - void wait_discovery( - uint32_t n_publishers = 1) - { - listener_.wait_discovery(n_publishers); - } - - uint32_t n_disposed() const - { - return listener_.n_key_disposed; - } - -private: - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Subscriber* subscriber_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataReader* reader_; - - bool keyed_; - - bool reliable_; - - /** - * Class handling dataflow events - */ - class SubListener : public eprosima::fastdds::dds::DataReaderListener - { - public: - - SubListener() - : discovered(0) - { - } - - //! Initialize the listener - void init( - MsgStruct* msg_should_receive_arg, - std::atomic* samples_received_arg) - { - msg_should_receive = msg_should_receive_arg; - samples_received = samples_received_arg; - n_key_disposed = 0; - } - - void wait_discovery( - uint32_t n_publishers = 1) - { - if (discovered < n_publishers) - { - std::unique_lock lock(wait_discovery_cv_mtx); - wait_discovery_cv.wait(lock, [this, n_publishers] - { - return discovered >= n_publishers; - }); - } - } - - //! Callback executed when a new sample is received - void on_data_available( - eprosima::fastdds::dds::DataReader* reader) override - { - eprosima::fastdds::dds::SampleInfo info; - while (reader->take_next_sample(&msg_received, &info) == ReturnCode_t::RETCODE_OK) - { - if (info.instance_state == eprosima::fastdds::dds::ALIVE_INSTANCE_STATE) - { - if (msg_received.message() == msg_should_receive->message()) - { - (*samples_received)++; - } - } - else if (info.instance_state == eprosima::fastdds::dds::NOT_ALIVE_DISPOSED_INSTANCE_STATE) - { - n_key_disposed++; - } - } - } - - void on_subscription_matched( - eprosima::fastdds::dds::DataReader*, - const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) - { - if (info.current_count_change == 1) - { - discovered = info.current_count; - wait_discovery_cv.notify_all(); - } - else if (info.current_count_change == -1) - { - discovered = info.current_count; - } - } - - //! Placeholder where received data is stored - MsgStruct msg_received; - - std::atomic n_key_disposed; - - //! Reference to the sample sent by the publisher - MsgStruct* msg_should_receive; - - //! Reference to received messages counter - std::atomic* samples_received; - - //! Number of DataWriters discovered - std::atomic discovered; - - //! Protects wait_discovery condition variable - std::mutex wait_discovery_cv_mtx; - - //! Waits to discovery enough DataWriters - std::condition_variable wait_discovery_cv; - } - listener_; -}; - -} /* namespace test */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt deleted file mode 120000 index 470d47e16..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ca.crt +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/ca.crt \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt deleted file mode 120000 index 19c9a0d73..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/ddsrouter.crt \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key deleted file mode 120000 index 9f58dfbe3..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/ddsrouter.key \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem b/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem deleted file mode 120000 index 65a440083..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem +++ /dev/null @@ -1 +0,0 @@ -../../../../../../resources/configurations/security/tls/dh_params.pem \ No newline at end of file diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt deleted file mode 100644 index 939063479..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2021 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. - -################ -# Trivial Test # -################ - -set(TEST_NAME - TrivialTest) - -set(TEST_SOURCES - TrivialTest.cpp) - -set(TEST_LIST - trivial_void_initialization - trivial_dummy_initialization - trivial_communication) - -set(TEST_NEEDED_SOURCES - ) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}") diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp deleted file mode 100644 index a59976214..000000000 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include - -using namespace eprosima::ddspipe::test; -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -std::vector random_payload( - uint16_t seed = 1) -{ - std::vector payload; - - for (int i = 0; i < seed; i++) - { - payload.push_back(i); - } - - return payload; -} - -DdsRouterConfiguration void_configuration() -{ - DdsRouterConfiguration configuration; - configuration.participants_configurations = - { - std::make_shared( - ParticipantId("ParticipantVoid1"), - ParticipantKind::blank, - false - ), - std::make_shared( - ParticipantId("ParticipantVoid2"), - ParticipantKind::blank, - false - ) - }; - - return configuration; -} - -/** - * @brief Create a \c DdsRouterConfiguration with 2 dummy participants and one builtin topic - * - * @return DdsRouterConfiguration - */ -DdsRouterConfiguration simple_configuration( - const std::string& participant_1_name = "Participant1", - const std::string& participant_2_name = "Participant2", - const std::string& topic_name = "topic_dummy", - const std::string& topic_type = "type_dummy") -{ - DdsRouterConfiguration configuration; - - configuration.builtin_topics = - { - std::set>({std::make_shared(topic_name, topic_type)}), - }; - - configuration.participants_configurations = - { - std::make_shared( - ParticipantId(participant_1_name), - ParticipantKind::dummy, - false - ), - std::make_shared( - ParticipantId(participant_2_name), - ParticipantKind::dummy, - false - ) - }; - - return configuration; -} - -/** - * Test Whole DdsRouter initialization by initializing two EmptyParticipants - */ -TEST(TrivialTest, trivial_void_initialization) -{ - // Create DdsRouter entity - DdsRouter router(void_configuration()); - router.start(); - router.stop(); - - // Let test finish without failing -} - -/** - * Test Whole DdsRouter initialization by initializing two DummyParticipants and a DistributedTopic - */ -TEST(TrivialTest, trivial_dummy_initialization) -{ - // Create DdsRouter entity - DdsRouter router(simple_configuration()); - router.start(); - router.stop(); - - // Let test finish without failing -} - -/** - * Test Whole DdsRouter interfaces by using two DummyParticipants and send one message from one to the other - * - * TODO - */ -TEST(TrivialTest, trivial_communication) -{ - DdsRouter router(simple_configuration()); - router.start(); - - DummyParticipant* participant_1 = DummyParticipant::get_participant(ParticipantId("Participant1")); - DummyParticipant* participant_2 = DummyParticipant::get_participant(ParticipantId("Participant2")); - ASSERT_NE(participant_1, nullptr); - ASSERT_NE(participant_2, nullptr); - - DistributedTopic topic("topic_dummy", "type_dummy"); - Guid guid = random_guid(); - std::vector payload = random_payload(3); - - DummyDataReceived data; - data.source_guid = guid; - data.payload = payload; - - participant_1->simulate_data_reception(topic, data); - - // Sleep until first data arrives to the writer - participant_2->wait_until_n_data_sent(topic, 1); - - std::vector data_received = participant_2->get_data_that_should_have_been_sent(topic); - - ASSERT_EQ(data_received.size(), 1u); - ASSERT_EQ(data_received[0].source_guid, guid); - ASSERT_EQ(data_received[0].payload, payload); - - router.stop(); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/test/blackbox/implementations/CMakeLists.txt b/ddspipe_participants/test/blackbox/implementations/CMakeLists.txt deleted file mode 100644 index fc76ab846..000000000 --- a/ddspipe_participants/test/blackbox/implementations/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2021 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. - -######################## -# Implementations Test # -######################## - -set(TEST_NAME - ImplementationsTest) - -set(TEST_SOURCES - ImplementationsTest.cpp - ) - -set(TEST_LIST - pair_implementation - pair_implementation_with_topic - all_implementations - duplicated_ids - ) - -set(TEST_NEEDED_SOURCES - ) - -add_blackbox_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_NEEDED_SOURCES}" - ) diff --git a/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp b/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp deleted file mode 100644 index ce44891d0..000000000 --- a/ddspipe_participants/test/blackbox/implementations/ImplementationsTest.cpp +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace test { - -constexpr const unsigned int DEFAULT_THREAD_POOL_SIZE = 2; -constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; - -} /* namespace test */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -/** - * Test that creates a DDSRouter with a Pair of Participants of same kind. - * It creates a DDSRouter with two Participants of same kind, starts it, then stops it and finally destroys it. - * - * This test will fail if it crashes. - */ -TEST(ImplementationsTest, pair_implementation) -{ - // TODO: Change to warning when fastdds warning: - // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: - // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> - // Function eprosima::fastdds::rtps::UDPChannelResource::Receive - // test::LogChecker test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - // For each Participant Kind - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::set> participant_configurations; - participant_configurations.insert(test::random_participant_configuration(kind, 1)); - participant_configurations.insert(test::random_participant_configuration(kind, 2)); - - SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - std::set>(), - participant_configurations, - specs); - - // Create DDSRouter entity - DDSRouter router(configuration); - // Start DDSRouter - router.start(); - - // Stop DDS Router - router.stop(); - - // Let DDSRouter object destroy for the next iteration - } -} - -/** - * Test that creates a DDSRouter with a Pair of Participants of same kind. - * It creates a DDSRouter with two Participants of same kind, starts it with an active topic, - * then stops it and finally destroys it. - * - * This test will fail if it crashes. - */ -TEST(ImplementationsTest, pair_implementation_with_topic) -{ - // TODO: Change to warning when fastdds warning: - // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: - // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> - // Function eprosima::fastdds::rtps::UDPChannelResource::Receive - // test::LogChecker test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - // For each Participant kind - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::set> builtin_topics = test::topic_set( - {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); - - std::set> participant_configurations; - participant_configurations.insert(test::random_participant_configuration(kind, 1)); - participant_configurations.insert(test::random_participant_configuration(kind, 2)); - - SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - builtin_topics, - participant_configurations, - specs); - - // Create DDSRouter entity - DDSRouter router(configuration); - - // Start DDSRouter - router.start(); - - // Stop DDS Router - router.stop(); - - // Let DDSRouter object destroy for the next iteration - } -} - -/** - * Test that creates a DDSRouter with several Participants, one of each kind - * It creates a DDSRouter with a Participant of each kind, - * starts it with an active topic, then stops it and finally destroys it. - * - * This test will fail if it crashes. - */ -TEST(ImplementationsTest, all_implementations) -{ - // TODO: Change to warning when fastdds warning: - // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: - // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> - // Function eprosima::fastdds::rtps::UDPChannelResource::Receive - // test::LogChecker test_log_handler(utils::Log::Kind::Error); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); - - { - // Set topic to active - std::set> builtin_topics = test::topic_set( - {test::DdsTopicInput("rt/chatter", "std_msgs::msg::dds_::String_", false, false, false, false)}); - - std::set> participant_configurations; - - uint16_t participant_number = 0; - - // For each Participant Kind set it in configuration - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - // Add participant - participant_configurations.insert(test::random_participant_configuration(kind, participant_number++)); - } - - SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - std::set>(), - participant_configurations, - specs); - - // Create DDSRouter entity - DDSRouter router(configuration); - - // Start DDSRouter - router.start(); - - // Stop DDS Router - router.stop(); - - // Let DDSRouter object destroy for the next iteration - } -} - -/** - * Test that creates a DDSRouter with 3 simple configurations, 2 of them with same id, fails - * - * There is no easy way to test this case as the yaml will be ill-formed with two keys. - * Thus, it must be implemented from a yaml in string format. - */ -TEST(ImplementationsTest, duplicated_ids) -{ - // For each Participant Kind - for (ParticipantKind kind : ALL_VALID_PARTICIPANT_KINDS) - { - std::set> participant_configurations; - participant_configurations.insert(test::random_participant_configuration(kind, 0)); - participant_configurations.insert(test::random_participant_configuration(kind, 0)); - - SpecsConfiguration specs; - specs.max_history_depth = test::DEFAULT_MAX_HISTORY_DEPTH; - specs.number_of_threads = test::DEFAULT_THREAD_POOL_SIZE; - - // Generate configuration - DDSRouterConfiguration configuration( - std::set>(), - std::set>(), - std::set>(), - participant_configurations, - specs); - - // Create DDSRouter entity - ASSERT_THROW(DDSRouter router(configuration), eprosima::utils::ConfigurationException) << kind; - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp b/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp index 08ae3204b..7775fa4d7 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#pragma once + #include namespace eprosima { diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp index b32d9d82a..a74f0a205 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#pragma once + #include #include diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp index 2226ee73d..eb48b6618 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#pragma once + #include #include diff --git a/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp b/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp index 4cf1013d1..53e3ad7d6 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp +++ b/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp @@ -12,11 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file YamlReader.ipp - * - */ - +#pragma once #include #include diff --git a/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp index 87360fdb8..1b986653d 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#pragma once + #include #include diff --git a/ddspipe_yaml/test/CMakeLists.txt b/ddspipe_yaml/test/CMakeLists.txt index 19c7ffc5e..1c95f651f 100644 --- a/ddspipe_yaml/test/CMakeLists.txt +++ b/ddspipe_yaml/test/CMakeLists.txt @@ -12,8 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Include utils for this specific test -include_directories("TestUtils") - # Add subdirectory with tests add_subdirectory(unittest) diff --git a/ddspipe_yaml/test/TestUtils/test_utils.cpp b/ddspipe_yaml/test/TestUtils/test_utils.cpp deleted file mode 100644 index 22315fe6b..000000000 --- a/ddspipe_yaml/test/TestUtils/test_utils.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright 2021 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 test_utils.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace test { - -using namespace eprosima::ddspipe::core::types; - -Guid random_guid( - uint16_t seed /* = 1 */) -{ - Guid guid; - guid.entityId.value[3] = static_cast(seed); - guid.guidPrefix.value[0] = 0x01; - guid.guidPrefix.value[1] = 0x0f; - return guid; -} - -TopicInput::TopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set) - : name(name) - , type(type) - , keyed(keyed) - , key_set(key_set) -{ -} - -DdsTopicInput::DdsTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool reliable, - bool reliable_set) - : TopicInput(name, type, keyed, key_set) - , reliable(reliable) - , reliable_set(reliable_set) -{ -} - -WildcardTopicInput::WildcardTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool type_set) - : TopicInput(name, type, keyed, key_set) - , type_set(type_set) -{ -} - -std::set> topic_set( - std::vector topics) -{ - std::set> result; - for (DdsTopicInput input : topics) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = input.name; - new_topic->type_name = input.type; - - if (input.key_set) - { - new_topic->keyed = input.keyed; - } - - - if (input.reliable_set) - { - TopicQoS qos; - if (input.reliable) - { - qos.reliability_qos = ReliabilityKind::RELIABLE; - } - else - { - qos.reliability_qos = ReliabilityKind::BEST_EFFORT; - } - new_topic->topic_qos = qos; - new_topic->topic_qos.set_level(utils::FuzzyLevelValues::fuzzy_level_fuzzy); - } - - result.insert(new_topic); - } - return result; -} - -std::set> topic_set( - std::vector topics) -{ - std::set> result; - for (WildcardTopicInput input : topics) - { - auto new_topic = std::make_shared(); - new_topic->topic_name = input.name; - new_topic->type_name = input.type; - - if (input.key_set) - { - new_topic->keyed = input.type_set; - } - - result.insert(new_topic); - - } - return result; -} - -DomainId random_domain( - uint16_t seed /* = 0 */) -{ - return DomainId(static_cast(seed)); -} - -GuidPrefix random_guid_prefix( - uint16_t seed /* = 0 */, - bool ros /* = false */) -{ - if (ros) - { - return GuidPrefix(true, seed); - } - else - { - return GuidPrefix(static_cast(seed)); - } -} - -Address random_address( - uint16_t seed /* = 0 */) -{ - return Address("127.0.0.1", seed, seed, TransportProtocol::udp); -} - -std::set random_connection_addresses( - uint16_t seed /* = 0 */, - uint16_t size /* = 1 */, - bool ros /* = false */) -{ - std::set result; - - for (int i = 0; i < size; ++i) - { - result.insert( - DiscoveryServerConnectionAddress( - random_guid_prefix((seed * size + i) * i), - std::set
({ - random_address((seed * size + i) * i), - random_address((seed * size + i) * i + 1)}))); - } - return result; -} - -std::shared_ptr random_participant_configuration( - ParticipantKind kind, - uint16_t seed /* = 0 */) -{ - ParticipantId id("Participant" + std::to_string(seed)); - - switch (kind) - { - case ParticipantKind::simple_rtps: - return std::make_shared( - id, - kind, - false, - random_domain(seed)); - - case ParticipantKind::local_discovery_server: - case ParticipantKind::wan_discovery_server: - - { - // TODO get random values - DiscoveryServerConnectionAddress connection_address = DiscoveryServerConnectionAddress( - GuidPrefix(), - std::set
({Address()}) - ); - - return std::make_shared( - id, - kind, - false, - random_domain(seed), - random_guid_prefix(seed), - std::set
(), - std::set({connection_address}), - security::TlsConfiguration()); - } - - case ParticipantKind::wan_initial_peers: - - { - return std::make_shared( - id, - kind, - false, - random_domain(seed), - std::set
(), - std::set
({Address()}), - security::TlsConfiguration()); - } - - case ParticipantKind::echo: - { - return std::make_shared( - id, - kind, - false); - } - - // Add cases where Participants need specific arguments - default: - return std::make_shared(id, kind, false); - } -} - -ParticipantId random_participant_id( - uint16_t seed /* = 0 */) -{ - std::vector names = { - "participant", - "PART_1", - "echo", - "Barro_p", - }; - - return ParticipantId(names[seed % names.size()] + std::to_string(seed)); -} - -ParticipantKind random_participant_kind( - bool valid /* = true */, - uint16_t seed /* = 0 */) -{ - std::vector kinds(std::begin(ALL_VALID_PARTICIPANT_KINDS), std::end(ALL_VALID_PARTICIPANT_KINDS)); - if (valid) - { - return kinds[seed % kinds.size()]; - } - else - { - kinds.push_back(ParticipantKind::invalid); - return kinds[seed % kinds.size()]; - } -} - -} /* namespace test */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/test/TestUtils/test_utils.hpp b/ddspipe_yaml/test/TestUtils/test_utils.hpp deleted file mode 100644 index f423167a6..000000000 --- a/ddspipe_yaml/test/TestUtils/test_utils.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2021 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 test_utils.hpp - */ - -#ifndef _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ -#define _DDSROUTER_TEST_TESTUTILS_TEST_UTILS_HPP_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace test { - -using namespace eprosima::ddspipe::core::types; - -// TODO: most of the methods from this test_utils that generate random types are not very "random". -// They must be refactored to generate real random values. - -constexpr const int TEST_NUMBER_ITERATIONS = 5; - -/** - * @brief Create a \c Guid with some of its bits determined by the input - * - * @param [in] seed : differentiating value for guid creation - * @return generated Guid - * @todo Make truly random using \c seed as such - * - */ -Guid random_guid( - uint16_t seed = 1); - -struct TopicInput -{ - TopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set); - - std::string name; - std::string type; - bool keyed; - bool key_set; -}; - -struct DdsTopicInput : public TopicInput -{ - DdsTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool reliable, - bool reliable_set); - - bool reliable; - bool reliable_set; -}; - -struct WildcardTopicInput : public TopicInput -{ - WildcardTopicInput( - std::string name, - std::string type, - bool keyed, - bool key_set, - bool type_set); - - bool type_set; -}; - -std::set> topic_set( - std::vector topics); - -std::set> topic_set( - std::vector topics); - -DomainId random_domain( - uint16_t seed = 0); - -GuidPrefix random_guid_prefix( - uint16_t seed = 0, - bool ros = false); - -Address random_address( - uint16_t seed = 0); - -std::set random_connection_addresses( - uint16_t seed = 0, - uint16_t size = 1, - bool ros = false); - -std::shared_ptr random_participant_configuration( - ParticipantKind kind, - uint16_t seed = 0); - -ParticipantId random_participant_id( - uint16_t seed = 0); - -ParticipantKind random_participant_kind( - bool valid = true, - uint16_t seed = 0); - -} /* namespace test */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/test/unittest/CMakeLists.txt b/ddspipe_yaml/test/unittest/CMakeLists.txt index 60bd924fc..871251792 100644 --- a/ddspipe_yaml/test/unittest/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/CMakeLists.txt @@ -16,9 +16,5 @@ # Yaml Tests # ############## -add_subdirectory(configuration) add_subdirectory(entities) -add_subdirectory(participants) -add_subdirectory(yaml_tags) -add_subdirectory(yaml_manager) add_subdirectory(yaml_reader) diff --git a/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp b/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp index 9816ec95e..b7d2b7fa3 100644 --- a/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp +++ b/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp @@ -12,20 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * @file YamlConfigurationTestUtils.hpp - */ - -#ifndef _DDSROUTER_TEST_UNITTEST_YAML_YAMLCONFIGURATIONTESTUTILS_HPP_ -#define _DDSROUTER_TEST_UNITTEST_YAML_YAMLCONFIGURATIONTESTUTILS_HPP_ +#pragma once #include -#include -#include -#include +#include +#include +#include +#include + +#include +#include +#include -#include #include #include @@ -90,26 +89,26 @@ void discovery_server_guid_prefix_to_yaml( void address_to_yaml( Yaml& yml, - const core::types::Address& address) + const participants::types::Address& address) { test::add_field_to_yaml( yml, - test::YamlField(address.ip()), + test::YamlField(address.ip()), ADDRESS_IP_TAG); test::add_field_to_yaml( yml, - test::YamlField(address.port()), + test::YamlField(address.port()), ADDRESS_PORT_TAG); - if (address.transport_protocol() == core::types::TransportProtocol::udp) + if (address.transport_protocol() == participants::types::TransportProtocol::udp) { test::add_field_to_yaml( yml, test::YamlField(ADDRESS_TRANSPORT_UDP_TAG), ADDRESS_TRANSPORT_TAG); } - else if (address.transport_protocol() == core::types::TransportProtocol::tcp) + else if (address.transport_protocol() == participants::types::TransportProtocol::tcp) { test::add_field_to_yaml( yml, @@ -117,14 +116,14 @@ void address_to_yaml( ADDRESS_TRANSPORT_TAG); } - if (address.ip_version() == core::types::IpVersion::v4) + if (address.ip_version() == participants::types::IpVersion::v4) { test::add_field_to_yaml( yml, test::YamlField(ADDRESS_IP_VERSION_V4_TAG), ADDRESS_IP_VERSION_TAG); } - else if (address.ip_version() == core::types::IpVersion::v6) + else if (address.ip_version() == participants::types::IpVersion::v6) { test::add_field_to_yaml( yml, @@ -139,28 +138,17 @@ void participantid_to_yaml( { test::add_field_to_yaml( yml, - test::YamlField(id.id_name()), + test::YamlField(id), PARTICIPANT_NAME_TAG); } -void participantkind_to_yaml( - Yaml& yml, - const core::types::ParticipantKind& kind) -{ - test::add_field_to_yaml( - yml, - test::YamlField(core::types::PARTICIPANT_KIND_ALIASES[static_cast( - kind)][0]), - PARTICIPANT_KIND_TAG); -} - void domain_to_yaml( Yaml& yml, const core::types::DomainId& domain) { test::add_field_to_yaml( yml, - test::YamlField(domain.domain_id()), + test::YamlField(domain.domain_id), DOMAIN_ID_TAG); } @@ -174,6 +162,43 @@ void repeater_to_yaml( IS_REPEATER_TAG); } +// // Create a yaml QoS object only with reliability +// void qos_to_yaml( +// Yaml& yml, +// const TopicQoS& qos) +// { +// // TODO: extend this for all qos +// test::add_field_to_yaml(yml, test::YamlField(qos.is_reliable()), QOS_RELIABLE_TAG); +// } + +// // Create a yaml Topic object with name, type and key tags +// void filter_topic_to_yaml( +// Yaml& yml, +// const WildcardDdsFilterTopic& topic) +// { +// if (topic.topic_name.is_set()) +// { +// test::add_field_to_yaml(yml, test::YamlField(topic.topic_name), TOPIC_NAME_TAG); +// } + +// if (topic.type_name.is_set()) +// { +// test::add_field_to_yaml(yml, test::YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); +// } +// } + +// // Create a yaml DdsTopic object with name, type, key and reliable tags +// void real_topic_to_yaml( +// Yaml& yml, +// const DdsTopic& topic, +// const test::YamlField& type, +// const test::YamlField& qos) +// { +// test::add_field_to_yaml(yml, test::YamlField(topic.m_topic_name), TOPIC_NAME_TAG); +// test::add_field_to_yaml(yml, test::YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); +// test::add_field_to_yaml(yml, test::YamlField(topic.topic_qos), TOPIC_QOS_TAG); +// } + } /* namespace test */ } /* namespace yaml */ } /* namespace ddspipe */ diff --git a/ddspipe_yaml/test/unittest/entities/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/CMakeLists.txt index 5a29e3f9b..2ec0d67eb 100644 --- a/ddspipe_yaml/test/unittest/entities/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/CMakeLists.txt @@ -17,6 +17,6 @@ ######################### add_subdirectory(address) -add_subdirectory(ddsrouter) add_subdirectory(guid) -add_subdirectory(topic) +# TODO uncommment when ready +# add_subdirectory(topic) diff --git a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt index c635c670d..143b72bb1 100644 --- a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt @@ -19,9 +19,9 @@ set(TEST_NAME YamlGetEntityAddressTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp YamlGetEntityAddressTest.cpp ) @@ -41,8 +41,8 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils - - ddsrouter_core + ddspipe_core + ddspipe_participants ) add_unittest_executable( @@ -58,9 +58,9 @@ add_unittest_executable( set(TEST_NAME YamlGetEntityDiscoveryServerAddressTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp YamlGetEntityDiscoveryServerAddressTest.cpp ) @@ -74,8 +74,8 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils - - ddsrouter_core + ddspipe_core + ddspipe_participants ) add_unittest_executable( diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp index 82c04e203..750c86ac1 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -40,8 +41,8 @@ TEST(YamlGetEntityAddressTest, get_address_defaults) Yaml yml; yml["address"] = yml_address; - // Get core::types::Address from Yaml - ASSERT_THROW(YamlReader::get(yml, "address", + // Get participants::types::Address from Yaml + ASSERT_THROW(YamlReader::get(yml, "address", LATEST), eprosima::utils::ConfigurationException); } @@ -52,20 +53,20 @@ TEST(YamlGetEntityAddressTest, get_address_defaults) // Add IP with ip-version ipv6 test::add_field_to_yaml( yml_address, - test::YamlField("::1"), + test::YamlField("::1"), ADDRESS_IP_TAG); Yaml yml; yml["address"] = yml_address; - // Get core::types::Address from Yaml - core::types::Address result = YamlReader::get(yml, "address", LATEST); + // Get participants::types::Address from Yaml + participants::types::Address result = YamlReader::get(yml, "address", LATEST); // Check result ASSERT_EQ("::1", result.ip()); - ASSERT_EQ(core::types::Address::default_port(), result.port()); - ASSERT_EQ(core::types::Address::default_port(), result.external_port()); - ASSERT_EQ(core::types::Address::default_transport_protocol(), result.transport_protocol()); - ASSERT_EQ(core::types::IpVersion::v6, result.ip_version()); + ASSERT_EQ(participants::types::Address::default_port(), result.port()); + ASSERT_EQ(participants::types::Address::default_port(), result.external_port()); + ASSERT_EQ(participants::types::Address::default_transport_protocol(), result.transport_protocol()); + ASSERT_EQ(participants::types::IpVersion::v6, result.ip_version()); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp index 4d676e784..6c07c0508 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -42,7 +43,7 @@ TEST(YamlGetEntityAddressTest, get_address_domain) // Add IP test::add_field_to_yaml( yml_address, - test::YamlField("localhost"), + test::YamlField("localhost"), ADDRESS_DNS_TAG); // Add IP version @@ -54,11 +55,11 @@ TEST(YamlGetEntityAddressTest, get_address_domain) Yaml yml; yml["address"] = yml_address; - // Get core::types::Address from Yaml - core::types::Address result = YamlReader::get(yml, "address", LATEST); + // Get participants::types::Address from Yaml + participants::types::Address result = YamlReader::get(yml, "address", LATEST); // Check result - ASSERT_EQ(core::types::IpVersion::v4, result.ip_version()); + ASSERT_EQ(participants::types::IpVersion::v4, result.ip_version()); ASSERT_EQ("127.0.0.1", result.ip()); } @@ -69,17 +70,17 @@ TEST(YamlGetEntityAddressTest, get_address_domain) // Add IP test::add_field_to_yaml( yml_address, - test::YamlField("localhost"), + test::YamlField("localhost"), ADDRESS_DNS_TAG); Yaml yml; yml["address"] = yml_address; - // Get core::types::Address from Yaml - core::types::Address result = YamlReader::get(yml, "address", LATEST); + // Get participants::types::Address from Yaml + participants::types::Address result = YamlReader::get(yml, "address", LATEST); // Check result - ASSERT_EQ(core::types::IpVersion::v4, result.ip_version()); + ASSERT_EQ(participants::types::IpVersion::v4, result.ip_version()); ASSERT_EQ("127.0.0.1", result.ip()); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp index d5c0b50de..52e9163a2 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -35,20 +36,20 @@ TEST(YamlGetEntityAddressTest, get_address_ip) { // ipv4 { - std::vector ips = { + std::vector ips = { "1.1.1.1", "127.0.0.1", "8.8.8.8", }; - for (core::types::IpType ip : ips) + for (participants::types::IpType ip : ips) { Yaml yml_address; // Add IP test::add_field_to_yaml( yml_address, - test::YamlField(ip), + test::YamlField(ip), ADDRESS_IP_TAG); // Add IP version @@ -60,31 +61,31 @@ TEST(YamlGetEntityAddressTest, get_address_ip) Yaml yml; yml["address"] = yml_address; - // Get core::types::Address from Yaml - core::types::Address result = YamlReader::get(yml, "address", LATEST); + // Get participants::types::Address from Yaml + participants::types::Address result = YamlReader::get(yml, "address", LATEST); // Check result - ASSERT_EQ(core::types::IpVersion::v4, result.ip_version()); + ASSERT_EQ(participants::types::IpVersion::v4, result.ip_version()); ASSERT_EQ(ip, result.ip()); } } // ipv6 { - std::vector ips = { + std::vector ips = { "::1", "12:34::89", "2001:0DB8:0000:0000:0000:0000:1428:57ab", }; - for (core::types::IpType ip : ips) + for (participants::types::IpType ip : ips) { Yaml yml_address; // Add IP test::add_field_to_yaml( yml_address, - test::YamlField(ip), + test::YamlField(ip), ADDRESS_IP_TAG); // Add IP version @@ -96,11 +97,11 @@ TEST(YamlGetEntityAddressTest, get_address_ip) Yaml yml; yml["address"] = yml_address; - // Get core::types::Address from Yaml - core::types::Address result = YamlReader::get(yml, "address", LATEST); + // Get participants::types::Address from Yaml + participants::types::Address result = YamlReader::get(yml, "address", LATEST); // Check result - ASSERT_EQ(core::types::IpVersion::v6, result.ip_version()); + ASSERT_EQ(participants::types::IpVersion::v6, result.ip_version()); ASSERT_EQ(ip, result.ip()); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp index 7fbf7cbf2..5f52c710e 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -37,21 +38,21 @@ TEST(YamlGetEntityAddressTest, get_ip) { // string values { - std::vector ips = { + std::vector ips = { "1.1.1.1", "::1", "127.0.0.1", }; - for (core::types::IpType ip : ips) + for (participants::types::IpType ip : ips) { Yaml yml; test::add_field_to_yaml( yml, - test::YamlField(ip), + test::YamlField(ip), ADDRESS_IP_TAG); - ASSERT_EQ(ip, YamlReader::get(yml, ADDRESS_IP_TAG, LATEST)); + ASSERT_EQ(ip, YamlReader::get(yml, ADDRESS_IP_TAG, LATEST)); } } @@ -59,7 +60,7 @@ TEST(YamlGetEntityAddressTest, get_ip) { Yaml yml; - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), + ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp index a55c0b072..34e857de5 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -46,9 +47,9 @@ TEST(YamlGetEntityAddressTest, get_ip_version) test::YamlField(ADDRESS_IP_VERSION_V4_TAG), ADDRESS_IP_VERSION_TAG); - core::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); + participants::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); - ASSERT_EQ(iv, core::types::IpVersion::v4); + ASSERT_EQ(iv, participants::types::IpVersion::v4); } // v6 @@ -59,16 +60,16 @@ TEST(YamlGetEntityAddressTest, get_ip_version) test::YamlField(ADDRESS_IP_VERSION_V6_TAG), ADDRESS_IP_VERSION_TAG); - core::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); + participants::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); - ASSERT_EQ(iv, core::types::IpVersion::v6); + ASSERT_EQ(iv, participants::types::IpVersion::v6); } // Empty { Yaml yml; - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), + ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), eprosima::utils::ConfigurationException); } @@ -80,7 +81,7 @@ TEST(YamlGetEntityAddressTest, get_ip_version) test::YamlField("v7"), ADDRESS_IP_VERSION_TAG); - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), + ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), eprosima::utils::ConfigurationException); } @@ -92,7 +93,7 @@ TEST(YamlGetEntityAddressTest, get_ip_version) test::YamlField(17), ADDRESS_IP_VERSION_TAG); - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), + ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp index c9a866541..4726b0586 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -38,16 +39,16 @@ TEST(YamlGetEntityAddressTest, get_port) { // numeric values { - std::vector ports = {1, 11, 111, 11666, 11777, 65535}; - for (core::types::PortType port : ports) + std::vector ports = {1, 11, 111, 11666, 11777, 65535}; + for (participants::types::PortType port : ports) { Yaml yml; test::add_field_to_yaml( yml, - test::YamlField(port), + test::YamlField(port), ADDRESS_PORT_TAG); - ASSERT_EQ(port, YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST)); + ASSERT_EQ(port, YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST)); } } @@ -56,7 +57,7 @@ TEST(YamlGetEntityAddressTest, get_port) Yaml yml; ASSERT_THROW( - YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST), + YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST), eprosima::utils::ConfigurationException); } @@ -69,7 +70,7 @@ TEST(YamlGetEntityAddressTest, get_port) ADDRESS_PORT_TAG); ASSERT_THROW( - YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST), + YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp index ed7e483ab..9a2114ae9 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -45,10 +46,10 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) test::YamlField(ADDRESS_TRANSPORT_UDP_TAG), ADDRESS_TRANSPORT_TAG); - core::types::TransportProtocol tp = - YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); + participants::types::TransportProtocol tp = + YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); - ASSERT_EQ(tp, core::types::TransportProtocol::udp); + ASSERT_EQ(tp, participants::types::TransportProtocol::udp); } // TCP @@ -59,10 +60,10 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) test::YamlField(ADDRESS_TRANSPORT_TCP_TAG), ADDRESS_TRANSPORT_TAG); - core::types::TransportProtocol tp = - YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); + participants::types::TransportProtocol tp = + YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); - ASSERT_EQ(tp, core::types::TransportProtocol::tcp); + ASSERT_EQ(tp, participants::types::TransportProtocol::tcp); } // Empty @@ -70,7 +71,7 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) Yaml yml; ASSERT_THROW( - YamlReader::get( + YamlReader::get( yml, ADDRESS_TRANSPORT_TAG, LATEST), @@ -86,7 +87,7 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) ADDRESS_TRANSPORT_TAG); ASSERT_THROW( - YamlReader::get( + YamlReader::get( yml, ADDRESS_TRANSPORT_TAG, LATEST), @@ -102,7 +103,7 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) ADDRESS_TRANSPORT_TAG); ASSERT_THROW( - YamlReader::get( + YamlReader::get( yml, ADDRESS_TRANSPORT_TAG, LATEST), diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp index 2378c195a..e733453d5 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include @@ -23,6 +23,7 @@ #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -34,7 +35,7 @@ using namespace eprosima::ddspipe::yaml; TEST(YamlGetEntityAddressTest, ip_and_domain) { // Check a warning is shown - // eprosima::ddsrouter::test::TestLogHandler log_handler(utils::Log::Kind::Warning, 1); + // eprosima::ddspipe::core::testing::TestLogHandler log_handler(utils::Log::Kind::Warning, 1); INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Warning, 1, 0); // Set address @@ -43,20 +44,20 @@ TEST(YamlGetEntityAddressTest, ip_and_domain) // Add domain yaml::test::add_field_to_yaml( yml_address, - yaml::test::YamlField("localhost"), + yaml::test::YamlField("localhost"), ADDRESS_DNS_TAG); // Add ip - core::types::IpType ip_value = "1.1.1.1"; + participants::types::IpType ip_value = "1.1.1.1"; yaml::test::add_field_to_yaml( yml_address, - yaml::test::YamlField(ip_value), + yaml::test::YamlField(ip_value), ADDRESS_IP_TAG); Yaml yml; yml[ADDRESS_TRANSPORT_TAG] = yml_address; - core::types::Address address = YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); + participants::types::Address address = YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); ASSERT_EQ(address.ip(), ip_value); } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp index ff61e9750..f1e4e841e 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp @@ -14,14 +14,15 @@ #include #include -#include +#include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -41,14 +42,14 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) Yaml yml_ds_address; // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; // Get random address and add it to yaml - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; yaml::test::address_to_yaml(yml_address, address); @@ -62,8 +63,8 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) yml["ds-address"] = yml_ds_address; // Create object DiscoveryServerAddress from yaml - core::types::DiscoveryServerConnectionAddress result = - YamlReader::get(yml, "ds-address", LATEST); + participants::types::DiscoveryServerConnectionAddress result = + YamlReader::get(yml, "ds-address", LATEST); // Check result ASSERT_EQ(guid_prefix, result.discovery_server_guid_prefix()); @@ -76,7 +77,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) Yaml yml_ds_address; // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); @@ -84,12 +85,12 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) // Get random address and add it to yaml Yaml yml_addresses; - std::vector addresses; + std::vector addresses; for (unsigned int i = 0; i < TEST_ADDRESSES_NUMBER; i++) { // Create new address and add it to already created addresses and to yaml Yaml yml_address; - core::types::Address address = eprosima::ddsrouter::test::random_address(i); + participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(i); yaml::test::address_to_yaml(yml_address, address); @@ -103,18 +104,18 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) yml["ds-address"] = yml_ds_address; // Create object DiscoveryServerAddress from yaml - core::types::DiscoveryServerConnectionAddress result = - YamlReader::get(yml, "ds-address", LATEST); + participants::types::DiscoveryServerConnectionAddress result = + YamlReader::get(yml, "ds-address", LATEST); // Check result ASSERT_EQ(guid_prefix, result.discovery_server_guid_prefix()); ASSERT_EQ(result.addresses().size(), TEST_ADDRESSES_NUMBER); // Check every address introduced in yaml is in result - for (core::types::Address address : addresses) + for (participants::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses = result.addresses(); + std::set addresses = result.addresses(); ASSERT_NE(addresses.find(address), addresses.end()); } } diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp index afcf18c15..445d5da7a 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -43,7 +44,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) yml["connection-address"] = yml_empty; ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), + YamlReader::get(yml, "connection-address", LATEST), eprosima::utils::ConfigurationException); } @@ -52,7 +53,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml_ds_address; // Get random address and add it to yaml - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; yaml::test::address_to_yaml(yml_address, address); @@ -62,7 +63,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml; yml["connection-address"] = yml_ds_address; ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), + YamlReader::get(yml, "connection-address", LATEST), eprosima::utils::ConfigurationException); } @@ -71,7 +72,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml_ds_address; // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; @@ -79,7 +80,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml; yml["connection-address"] = yml_ds_address; ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), + YamlReader::get(yml, "connection-address", LATEST), eprosima::utils::ConfigurationException); } @@ -88,7 +89,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml_ds_address; // Get random address and add it to yaml - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; yaml::test::address_to_yaml(yml_address, address); @@ -96,7 +97,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; // Guid Prefix error format (inside a sequence) - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); Yaml yml_guid_aux; @@ -106,7 +107,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml; yml["connection-address"] = yml_ds_address; ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), + YamlReader::get(yml, "connection-address", LATEST), eprosima::utils::ConfigurationException); } @@ -115,7 +116,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml_ds_address; // Address error (in map instead of sequence) - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; yaml::test::address_to_yaml(yml_address, address); @@ -123,7 +124,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; @@ -131,7 +132,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) Yaml yml; yml["connection-address"] = yml_ds_address; ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), + YamlReader::get(yml, "connection-address", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt index f655aa386..e67669ec3 100644 --- a/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt @@ -20,10 +20,11 @@ set(TEST_NAME YamlGetEntityGuidPrefixTest) set(TEST_SOURCES YamlGetEntityGuidPrefixTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ) set(TEST_LIST @@ -37,8 +38,8 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils - - ddsrouter_core + ddspipe_core + ddspipe_participants ) add_unittest_executable( diff --git a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp index ad5384d1e..c38d65757 100644 --- a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt index 38a7aa652..711c89498 100644 --- a/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt @@ -20,10 +20,11 @@ set(TEST_NAME YamlGetEntityTopicTest) set(TEST_SOURCES YamlGetEntityTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ) set(TEST_LIST @@ -37,8 +38,8 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils - - ddsrouter_core + ddspipe_core + ddspipe_participants ) add_unittest_executable( diff --git a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp index b94335217..e2b472f72 100644 --- a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp @@ -15,15 +15,16 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -46,12 +47,10 @@ void topic_to_yaml( Yaml& yml, const test::YamlField& name, const test::YamlField& type, - const test::YamlField& keyed, const test::YamlField& qos) { test::add_field_to_yaml(yml, name, TOPIC_NAME_TAG); test::add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); - test::add_field_to_yaml(yml, keyed, TOPIC_KIND_TAG); test::add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); } @@ -60,12 +59,10 @@ void real_topic_to_yaml( Yaml& yml, const test::YamlField& name, const test::YamlField& type, - const test::YamlField& keyed, const test::YamlField& qos) { test::add_field_to_yaml(yml, name, TOPIC_NAME_TAG); test::add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); - test::add_field_to_yaml(yml, keyed, TOPIC_KIND_TAG); test::add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); } @@ -74,17 +71,15 @@ void compare_topic( core::types::DdsTopic topic, std::string name, std::string type, - bool keyed, bool has_reliability_set = false, bool reliable = false) { - ASSERT_EQ(topic.topic_name, name); + ASSERT_EQ(topic.m_topic_name, name); ASSERT_EQ(topic.type_name, type); - ASSERT_EQ(topic.keyed, keyed); if (has_reliability_set) { - eprosima::ddsrouter::core::types::ReliabilityKind expected_reliability_qos; + eprosima::ddspipe::core::types::ReliabilityKind expected_reliability_qos; if (reliable) { expected_reliability_qos = core::types::ReliabilityKind::RELIABLE; @@ -94,7 +89,7 @@ void compare_topic( expected_reliability_qos = core::types::ReliabilityKind::BEST_EFFORT; } - ASSERT_EQ(topic.topic_qos.get_reference().reliability_qos, expected_reliability_qos); + ASSERT_EQ(topic.topic_qos.reliability_qos, expected_reliability_qos); } } @@ -103,22 +98,14 @@ void compare_wildcard_topic( core::types::WildcardDdsFilterTopic topic, std::string name, bool type_set, - std::string type, - bool key_set, - bool keyed) + std::string type) { ASSERT_EQ(topic.topic_name, name); if (type_set) { ASSERT_TRUE(topic.type_name.is_set()); - ASSERT_EQ(topic.type_name.get_reference(), type); - } - - if (key_set) - { - ASSERT_TRUE(topic.keyed.is_set()); - ASSERT_EQ(topic.keyed.get_reference(), keyed); + ASSERT_EQ(topic.type_name, type); } } @@ -132,8 +119,6 @@ void compare_wildcard_topic( * * POSITIVE CASES: * - Topic Std - * - Topic with key - * - Topic with no key * * NEGATIVE CASES: * - Empty @@ -160,42 +145,6 @@ TEST(YamlGetEntityTopicTest, get_real_topic) core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_topic(topic, name, type, false); // By default no keyed - } - - // Topic with key - { - Yaml yml_topic; - test::topic_to_yaml( - yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(true), - test::YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - - test::compare_topic(topic, name, type, true); - } - - // Topic with no key - { - Yaml yml_topic; - test::real_topic_to_yaml( - yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(false), - test::YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_topic(topic, name, type, false); } @@ -219,7 +168,7 @@ TEST(YamlGetEntityTopicTest, get_real_topic) core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_topic(topic, name, type, false, true, true); // By default no keyed + test::compare_topic(topic, name, type, true, true); } // Empty @@ -273,9 +222,6 @@ TEST(YamlGetEntityTopicTest, get_real_topic) * POSITIVE CASES: * - Topic Std * - Topic without type - * - Topic with key - * - Topic with no key - * - Topic with key without type */ TEST(YamlGetEntityTopicTest, get_wildcard_topic) { @@ -298,7 +244,7 @@ TEST(YamlGetEntityTopicTest, get_wildcard_topic) core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_wildcard_topic(topic, name, true, type, false, false); // By default no keyed + test::compare_wildcard_topic(topic, name, true, type, false); } // Topic without type @@ -317,64 +263,7 @@ TEST(YamlGetEntityTopicTest, get_wildcard_topic) core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_wildcard_topic(topic, name, false, "*", false, false); // By default no keyed - } - - // Topic with key - { - Yaml yml_topic; - test::topic_to_yaml( - yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(true), - test::YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", - LATEST); - - test::compare_wildcard_topic(topic, name, true, type, true, true); - } - - // Topic with no key - { - Yaml yml_topic; - test::topic_to_yaml( - yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(false), - test::YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", - LATEST); - - test::compare_wildcard_topic(topic, name, true, type, true, false); - } - - // Topic with key without type - { - Yaml yml_topic; - test::topic_to_yaml( - yml_topic, - test::YamlField(name), - test::YamlField(), - test::YamlField(true), - test::YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", - LATEST); - - test::compare_wildcard_topic(topic, name, false, "*", true, true); + test::compare_wildcard_topic(topic, name, false, "*", false); } } diff --git a/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt index fdf74d9f3..f6f6d65e2 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt @@ -19,8 +19,9 @@ set(TEST_NAME YamlReaderScalarTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp YamlReaderScalarTest.cpp ) @@ -37,8 +38,8 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils - - ddsrouter_core + ddspipe_core + ddspipe_participants ) add_unittest_executable( diff --git a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp index 7a3bc6ed2..cffd53377 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp +++ b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp @@ -17,9 +17,9 @@ #include -#include "YamlReaderTest_common.hpp" +#include -using namespace eprosima::ddspipe; +using namespace eprosima; using namespace eprosima::ddspipe::yaml; /** @@ -35,19 +35,19 @@ TEST(YamlReaderScalarTest, get_scalar_bool) // true { Yaml yml(true); - ASSERT_TRUE(test::MockYamlReader::get_scalar(yml)); + ASSERT_TRUE(YamlReader::get_scalar(yml)); } // false { Yaml yml(false); - ASSERT_FALSE(test::MockYamlReader::get_scalar(yml)); + ASSERT_FALSE(YamlReader::get_scalar(yml)); } // fail with int { Yaml yml(0); - ASSERT_THROW(test::MockYamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); + ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); } } @@ -69,8 +69,8 @@ TEST(YamlReaderScalarTest, get_scalar_int) { for (int i = 1; i < 0x1000; i *= 2) { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(i)), i) << i; - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(-i)), -i) << -i; + ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; + ASSERT_EQ(YamlReader::get_scalar(Yaml(-i)), -i) << -i; } } @@ -78,7 +78,7 @@ TEST(YamlReaderScalarTest, get_scalar_int) { for (unsigned int i = 1; i < 0x1000; i *= 2) { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(i)), i) << i; + ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; } } @@ -86,7 +86,7 @@ TEST(YamlReaderScalarTest, get_scalar_int) { for (uint16_t i = 1; i < 0x1000; i *= 2) { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(i)), i) << i; + ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; } } @@ -94,14 +94,14 @@ TEST(YamlReaderScalarTest, get_scalar_int) { for (int64_t i = 1; i < 0x1000; i *= 2) { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(i)), i) << i; - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(-i)), -i) << -i; + ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; + ASSERT_EQ(YamlReader::get_scalar(Yaml(-i)), -i) << -i; } } // fail with bool { - ASSERT_THROW(test::MockYamlReader::get_scalar(Yaml(false)), eprosima::utils::ConfigurationException); + ASSERT_THROW(YamlReader::get_scalar(Yaml(false)), eprosima::utils::ConfigurationException); } } @@ -120,12 +120,12 @@ TEST(YamlReaderScalarTest, get_scalar_string) { // empty string { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml("")), ""); + ASSERT_EQ(YamlReader::get_scalar(Yaml("")), ""); } // short string { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml("short_text")), "short_text"); + ASSERT_EQ(YamlReader::get_scalar(Yaml("short_text")), "short_text"); } // long string @@ -137,22 +137,22 @@ TEST(YamlReaderScalarTest, get_scalar_string) "each part, and newlines must be literal as " "usual."; - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(st)), st); + ASSERT_EQ(YamlReader::get_scalar(Yaml(st)), st); } // numeric string { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml("1234567890")), "1234567890"); + ASSERT_EQ(YamlReader::get_scalar(Yaml("1234567890")), "1234567890"); } // numeric { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(111)), "111"); + ASSERT_EQ(YamlReader::get_scalar(Yaml(111)), "111"); } // bool { - ASSERT_EQ(test::MockYamlReader::get_scalar(Yaml(false)), "false"); + ASSERT_EQ(YamlReader::get_scalar(Yaml(false)), "false"); } } @@ -173,28 +173,28 @@ TEST(YamlReaderScalarTest, get_scalar_from_tag) { Yaml yml; yml[tag] = true; - ASSERT_TRUE(test::MockYamlReader::get_scalar(yml, tag)); + ASSERT_TRUE(YamlReader::get_scalar(yml, tag)); } // int { Yaml yml; yml[tag] = 12345; - ASSERT_EQ(test::MockYamlReader::get_scalar(yml, tag), 12345); + ASSERT_EQ(YamlReader::get_scalar(yml, tag), 12345); } // string { Yaml yml; yml[tag] = "this is a text"; - ASSERT_EQ(test::MockYamlReader::get_scalar(yml, tag), "this is a text"); + ASSERT_EQ(YamlReader::get_scalar(yml, tag), "this is a text"); } // no tag { Yaml yml; yml["other_tag"] = 3; - ASSERT_THROW(test::MockYamlReader::get_scalar(yml, tag), eprosima::utils::ConfigurationException); + ASSERT_THROW(YamlReader::get_scalar(yml, tag), eprosima::utils::ConfigurationException); } } @@ -212,7 +212,7 @@ TEST(YamlReaderScalarTest, get_scalar_negative_cases) { Yaml yml; ASSERT_TRUE(yml.IsNull()); - ASSERT_THROW(test::MockYamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); + ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); } // sequence @@ -221,7 +221,7 @@ TEST(YamlReaderScalarTest, get_scalar_negative_cases) yml.push_back(3); yml.push_back(4); ASSERT_TRUE(yml.IsSequence()); - ASSERT_THROW(test::MockYamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); + ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); } // map @@ -230,7 +230,7 @@ TEST(YamlReaderScalarTest, get_scalar_negative_cases) yml["1"] = 3; yml["2"] = 4; ASSERT_TRUE(yml.IsMap()); - ASSERT_THROW(test::MockYamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); + ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); } } diff --git a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp deleted file mode 100644 index 7312e96d6..000000000 --- a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderTest_common.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { -namespace test { - -/** - * @brief YamlReader Mock class - * - * This class allows to use the protected methos from YamlReader - */ -class MockYamlReader : public YamlReader -{ -public: - - // Make protected methods from parent public - - using YamlReader::get_value_in_tag; - - using YamlReader::get; - - using YamlReader::get_scalar; - - using YamlReader::get_list; - - using YamlReader::get_enumeration; -}; - -} /* namespace test */ -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/test/unittest/yaml_tags/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_tags/CMakeLists.txt deleted file mode 100644 index 5b71ed017..000000000 --- a/ddspipe_yaml/test/unittest/yaml_tags/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2021 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. - -set(TEST_NAME YamlTagsTest) - -set(TEST_SOURCES - YamlTagsTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp) - -set(TEST_LIST - yaml_tags) - -set(TEST_EXTRA_LIBRARIES - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp b/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp deleted file mode 100644 index 3062c3dd3..000000000 --- a/ddspipe_yaml/test/unittest/yaml_tags/YamlTagsTest.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include - -using namespace eprosima::ddspipe::yaml; - -TEST(YamlTagsTest, yaml_tags) -{ - std::set retrieved_tags = ddsrouter_tags(); - - std::set current_tags = - { - ALLOWLIST_TAG, - BLOCKLIST_TAG, - TOPIC_NAME_TAG, - TOPIC_TYPE_NAME_TAG, - TOPIC_KIND_TAG, - PARTICIPANT_KIND_TAG, - PARTICIPANT_NAME_TAG, - COLLECTION_PARTICIPANTS_TAG, - DOMAIN_ID_TAG, - DISCOVERY_SERVER_GUID_PREFIX_TAG, - LISTENING_ADDRESSES_TAG, - CONNECTION_ADDRESSES_TAG, - COLLECTION_ADDRESSES_TAG, - TLS_TAG, - TLS_CA_TAG, - TLS_PASSWORD_TAG, - TLS_PRIVATE_KEY_TAG, - TLS_CERT_TAG, - TLS_DHPARAMS_TAG, - TLS_SNI_HOST_TAG, - ADDRESS_IP_TAG, - ADDRESS_DNS_TAG, - ADDRESS_PORT_TAG, - ADDRESS_IP_VERSION_TAG, - ADDRESS_IP_VERSION_V4_TAG, - ADDRESS_IP_VERSION_V6_TAG, - ADDRESS_TRANSPORT_TAG, - ADDRESS_TRANSPORT_UDP_TAG, - ADDRESS_TRANSPORT_TCP_TAG, - DISCOVERY_SERVER_GUID_TAG, - DISCOVERY_SERVER_ID_TAG, - DISCOVERY_SERVER_ID_ROS_TAG, - VERSION_TAG, - VERSION_TAG_V_1_0, - VERSION_TAG_V_2_0, - VERSION_TAG_V_3_0, - PARTICIPANT_KIND_TAG_V1, - }; - - ASSERT_EQ(retrieved_tags, current_tags); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/unittest/yaml_manager/CMakeLists.txt b/ddsrouter_yaml/test/CMakeLists.txt similarity index 91% rename from ddspipe_yaml/test/unittest/yaml_manager/CMakeLists.txt rename to ddsrouter_yaml/test/CMakeLists.txt index 221e8826c..1c95f651f 100644 --- a/ddspipe_yaml/test/unittest/yaml_manager/CMakeLists.txt +++ b/ddsrouter_yaml/test/CMakeLists.txt @@ -11,3 +11,6 @@ # 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. + +# Add subdirectory with tests +add_subdirectory(unittest) diff --git a/ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt b/ddsrouter_yaml/test/unittest/CMakeLists.txt similarity index 73% rename from ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt rename to ddsrouter_yaml/test/unittest/CMakeLists.txt index 4757aaf44..9be0f5513 100644 --- a/ddspipe_participants/test/blackbox/ddsrouter_core/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# Copyright 2022 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. @@ -12,5 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_subdirectory(trivial) -add_subdirectory(dds) +############## +# Yaml Tests # +############## + +add_subdirectory(configuration) +add_subdirectory(entities) +add_subdirectory(participants) diff --git a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp b/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp new file mode 100644 index 000000000..c52cda98a --- /dev/null +++ b/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp @@ -0,0 +1,165 @@ +// Copyright 2022 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. + +#pragma once + +#include + +#include +#include +#include + +#include + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { +namespace test { + +template +struct YamlField +{ + YamlField() + : present(false) + { + } + + YamlField( + T arg_value) + : value(arg_value) + , present(true) + { + } + + T value; + bool present; +}; + +template +void add_field_to_yaml( + Yaml& yml, + const YamlField& field, + const std::string& tag) +{ + if (field.present) + { + yml[tag] = field.value; + } +} + +void guid_prefix_to_yaml( + Yaml& yml, + const core::types::GuidPrefix& guid_prefix) +{ + std::stringstream ss; + ss << guid_prefix; + + test::add_field_to_yaml( + yml, + test::YamlField(ss.str()), + DISCOVERY_SERVER_GUID_TAG); +} + +void discovery_server_guid_prefix_to_yaml( + Yaml& yml, + const core::types::GuidPrefix& guid_prefix) +{ + Yaml yml_guid; + guid_prefix_to_yaml(yml_guid, guid_prefix); + + yml[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; +} + +void address_to_yaml( + Yaml& yml, + const participants::types::Address& address) +{ + test::add_field_to_yaml( + yml, + test::YamlField(address.ip()), + ADDRESS_IP_TAG); + + test::add_field_to_yaml( + yml, + test::YamlField(address.port()), + ADDRESS_PORT_TAG); + + if (address.transport_protocol() == participants::types::TransportProtocol::udp) + { + test::add_field_to_yaml( + yml, + test::YamlField(ADDRESS_TRANSPORT_UDP_TAG), + ADDRESS_TRANSPORT_TAG); + } + else if (address.transport_protocol() == participants::types::TransportProtocol::tcp) + { + test::add_field_to_yaml( + yml, + test::YamlField(ADDRESS_TRANSPORT_TCP_TAG), + ADDRESS_TRANSPORT_TAG); + } + + if (address.ip_version() == participants::types::IpVersion::v4) + { + test::add_field_to_yaml( + yml, + test::YamlField(ADDRESS_IP_VERSION_V4_TAG), + ADDRESS_IP_VERSION_TAG); + } + else if (address.ip_version() == participants::types::IpVersion::v6) + { + test::add_field_to_yaml( + yml, + test::YamlField(ADDRESS_IP_VERSION_V6_TAG), + ADDRESS_IP_VERSION_TAG); + } +} + +void participantid_to_yaml( + Yaml& yml, + const core::types::ParticipantId& id) +{ + test::add_field_to_yaml( + yml, + test::YamlField(id), + PARTICIPANT_NAME_TAG); +} + +void domain_to_yaml( + Yaml& yml, + const core::types::DomainId& domain) +{ + test::add_field_to_yaml( + yml, + test::YamlField(domain.domain_id()), + DOMAIN_ID_TAG); +} + +void repeater_to_yaml( + Yaml& yml, + const bool& repeater) +{ + test::add_field_to_yaml( + yml, + test::YamlField(repeater), + IS_REPEATER_TAG); +} + +} /* namespace test */ +} /* namespace yaml */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_yaml/test/unittest/configuration/CMakeLists.txt b/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt similarity index 84% rename from ddspipe_yaml/test/unittest/configuration/CMakeLists.txt rename to ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt index 69a687362..010658954 100644 --- a/ddspipe_yaml/test/unittest/configuration/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt @@ -20,11 +20,10 @@ set(TEST_NAME YamlReaderConfigurationTest) set(TEST_SOURCES YamlReaderConfigurationTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ) set(TEST_LIST diff --git a/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp similarity index 99% rename from ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp rename to ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index a1a72fbef..13f3301df 100644 --- a/ddspipe_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -22,6 +22,7 @@ #include "../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_participants/test/blackbox/CMakeLists.txt b/ddsrouter_yaml/test/unittest/entities/CMakeLists.txt similarity index 76% rename from ddspipe_participants/test/blackbox/CMakeLists.txt rename to ddsrouter_yaml/test/unittest/entities/CMakeLists.txt index 447c81e4e..849a06283 100644 --- a/ddspipe_participants/test/blackbox/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/entities/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# Copyright 2022 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. @@ -12,5 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_subdirectory(ddsrouter_core) -add_subdirectory(implementations) +######################### +# Yaml GetEntities Test # +######################### + +add_subdirectory(ddsrouter) diff --git a/ddspipe_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt b/ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt similarity index 87% rename from ddspipe_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt rename to ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt index 3faca14ba..3f9ce6afe 100644 --- a/ddspipe_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt @@ -20,9 +20,10 @@ set(TEST_NAME YamlGetConfigurationDDSRouterTest) set(TEST_SOURCES YamlGetConfigurationDDSRouterTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ) set(TEST_LIST diff --git a/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp similarity index 95% rename from ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp rename to ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index 681f73775..72b3db2b4 100644 --- a/ddspipe_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -17,12 +17,13 @@ #include #include -#include -#include +#include +#include #include #include +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -295,12 +296,12 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se ASSERT_EQ( ds_participant->connection_addresses.size(), 1u); - core::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses.begin(); + participants::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses.begin(); ASSERT_EQ( address, - (core::types::DiscoveryServerConnectionAddress( + (participants::types::DiscoveryServerConnectionAddress( core::types::GuidPrefix("01.0f.00.00.00.00.00.00.00.00.00.00"), - {core::types::Address("127.0.0.1", 3333, 3333, core::types::Address::default_transport_protocol())} + {participants::types::Address("127.0.0.1", 3333, 3333, participants::types::Address::default_transport_protocol())} )) ); } diff --git a/ddspipe_yaml/test/unittest/participants/CMakeLists.txt b/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt similarity index 82% rename from ddspipe_yaml/test/unittest/participants/CMakeLists.txt rename to ddsrouter_yaml/test/unittest/participants/CMakeLists.txt index 3718b06ba..c763f9d73 100644 --- a/ddspipe_yaml/test/unittest/participants/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt @@ -19,9 +19,10 @@ set(TEST_NAME YamlGetCommonParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + YamlGetCommonParticipantConfigurationTest.cpp ) @@ -51,9 +52,10 @@ add_unittest_executable( set(TEST_NAME YamlGetSimpleParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + YamlGetSimpleParticipantConfigurationTest.cpp ) @@ -84,9 +86,10 @@ add_unittest_executable( set(TEST_NAME YamlGetDiscoveryServerParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + YamlGetDiscoveryServerParticipantConfigurationTest.cpp ) @@ -125,9 +128,10 @@ add_unittest_executable( set(TEST_NAME YamlGetInitialPeersParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/yaml_configuration_tags.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader.cpp - ${PROJECT_SOURCE_DIR}/test/TestUtils/test_utils.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + YamlGetInitialPeersParticipantConfigurationTest.cpp ) diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp similarity index 96% rename from ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp rename to ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index 52b6125b1..34b382aea 100644 --- a/ddspipe_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -14,16 +14,17 @@ #include #include -#include +#include -#include +#include #include #include "../YamlConfigurationTestUtils.hpp" constexpr const uint32_t TEST_ITERATION_MAX = 5; +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp similarity index 100% rename from ddspipe_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp rename to ddsrouter_yaml/test/unittest/participants/YamlGetDiscoveryServerParticipantConfigurationTest.cpp diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp similarity index 95% rename from ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp rename to ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp index 7ebea3ad5..50d77373f 100644 --- a/ddspipe_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp @@ -14,16 +14,17 @@ #include #include -#include +#include -#include +#include -#include -#include +#include +#include #include #include "../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp similarity index 96% rename from ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp rename to ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index 2ba8c8b86..cf0727ae0 100644 --- a/ddspipe_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -14,17 +14,18 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "../YamlConfigurationTestUtils.hpp" constexpr const uint32_t TEST_ITERATION_MAX = 5; +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp similarity index 92% rename from ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp rename to ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index a7cf1f969..87ef92f50 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -14,15 +14,16 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -61,7 +62,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; @@ -101,11 +102,11 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add addresses - std::vector addresses; + std::vector addresses; for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) { // Create new address - core::types::Address address = eprosima::ddsrouter::test::random_address(i); + participants::types::Address address = eprosima::ddsrouter::test::random_address(i); addresses.push_back(address); // Add it to yaml @@ -134,10 +135,10 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect ASSERT_EQ(addresses.size(), result.connection_addresses.begin()->addresses().size()); ASSERT_EQ(connection_guid, result.connection_addresses.begin()->discovery_server_guid_prefix()); // Check every address is inside connection addresses of the configuration - for (core::types::Address address : addresses) + for (participants::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses_result = + std::set addresses_result = result.connection_addresses.begin()->addresses(); ASSERT_NE( addresses_result.find(address), @@ -165,7 +166,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_addresses; // Add address - core::types::Address address = eprosima::ddsrouter::test::random_address(i); + participants::types::Address address = eprosima::ddsrouter::test::random_address(i); // Add it to yaml Yaml yml_address; @@ -193,7 +194,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect // Check result ASSERT_EQ(connection_guids.size(), result.connection_addresses.size()); // Check that every connection has a correct number of addresses and a guid given - for (core::types::DiscoveryServerConnectionAddress connection : result.connection_addresses) + for (participants::types::DiscoveryServerConnectionAddress connection : result.connection_addresses) { ASSERT_NE( std::find(connection_guids.begin(), connection_guids.end(), connection.discovery_server_guid_prefix()) @@ -217,7 +218,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; @@ -254,7 +255,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; @@ -288,7 +289,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); // Add address wrongly yml_addresses["address1"] = yml_address; diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp similarity index 94% rename from ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp rename to ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index 0765cffaf..65fa78664 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -14,15 +14,16 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp similarity index 89% rename from ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp rename to ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index 9588ab71e..e1d9537ef 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -14,15 +14,16 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -56,7 +57,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); yml_listening_addresses.push_back(yml_address); @@ -85,11 +86,11 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add addresses - std::vector addresses; + std::vector addresses; for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) { // Create new address - core::types::Address address = eprosima::ddsrouter::test::random_address(i); + participants::types::Address address = eprosima::ddsrouter::test::random_address(i); addresses.push_back(address); // Add it to yaml @@ -109,10 +110,10 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni // Check result ASSERT_EQ(addresses.size(), result.listening_addresses.size()) << yml; // Check every address is inside listening addresses of the configuration - for (core::types::Address address : addresses) + for (participants::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses_result = result.listening_addresses; + std::set addresses_result = result.listening_addresses; ASSERT_NE( addresses_result.find(address), addresses_result.end()); @@ -132,7 +133,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni // Add address badly Yaml yml_listening_addresses; Yaml yml_address; - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); yml_listening_addresses["address1"] = yml_address; yml_participant[LISTENING_ADDRESSES_TAG] = yml_listening_addresses; diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp similarity index 94% rename from ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp rename to ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index 28361fabe..2efeb004d 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -14,15 +14,16 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp similarity index 95% rename from ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp rename to ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp index e147d478b..4d9eb8303 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp @@ -14,15 +14,16 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; diff --git a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp similarity index 96% rename from ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp rename to ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index ecc1b82a3..223cc7589 100644 --- a/ddspipe_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -14,15 +14,16 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include #include "../../YamlConfigurationTestUtils.hpp" +using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; @@ -136,7 +137,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_inact // Add addresses (so that participant configuration is valid) Yaml yml_listening_addresses; Yaml yml_address; - core::types::Address address = eprosima::ddsrouter::test::random_address(); + participants::types::Address address = eprosima::ddsrouter::test::random_address(); yaml::test::address_to_yaml(yml_address, address); yml_listening_addresses.push_back(yml_address); From 98c589c524519dd0e772ddc37d36f88cf3078d56 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 12:36:16 +0100 Subject: [PATCH 10/38] Implement tests (some)for ddsrouter_core Signed-off-by: jparisu --- .../testing/random_values.hpp | 4 - .../include/ddsrouter_core/core/DdsRouter.hpp | 1 + .../ddsrouter_core/testing/random_values.hpp | 36 + .../src/cpp/testing/random_values.cpp | 98 +++ ddsrouter_core/test/CMakeLists.txt | 15 + ddsrouter_core/test/blackbox/CMakeLists.txt | 17 + .../blackbox/ddsrouter_core/CMakeLists.txt | 15 + .../ddsrouter_core/dds/CMakeLists.txt | 17 + .../ddsrouter_core/dds/WAN/CMakeLists.txt | 80 ++ .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 705 ++++++++++++++++++ .../blackbox/ddsrouter_core/dds/WAN/README.md | 7 + .../ddsrouter_core/dds/WAN/TEST_XFAIL.list | 8 + .../ddsrouter_core/dds/WAN/TEST_XTSAN.list | 5 + .../ddsrouter_core/dds/local/CMakeLists.txt | 84 +++ .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 329 ++++++++ .../dds/local/DDSTestLocalDisposeKey.cpp | 201 +++++ .../ddsrouter_core/dds/local/README.md | 6 + .../dds/repeater/DDSTestRepeater.cpp | 35 +- .../dds/types/HelloWorld/HelloWorld.cxx | 207 +++++ .../dds/types/HelloWorld/HelloWorld.h | 219 ++++++ .../dds/types/HelloWorld/HelloWorld.idl | 5 + .../HelloWorld/HelloWorldPubSubTypes.cxx | 133 ++++ .../types/HelloWorld/HelloWorldPubSubTypes.h | 67 ++ .../types/HelloWorldKeyed/HelloWorldKeyed.cxx | 283 +++++++ .../types/HelloWorldKeyed/HelloWorldKeyed.h | 252 +++++++ .../types/HelloWorldKeyed/HelloWorldKeyed.idl | 6 + .../HelloWorldKeyedPubSubTypes.cxx | 170 +++++ .../HelloWorldKeyedPubSubTypes.h | 101 +++ .../dds/types/test_participants.hpp | 497 ++++++++++++ .../ddsrouter_core/resources/tls/ca.crt | 1 + .../resources/tls/ddsrouter.crt | 1 + .../resources/tls/ddsrouter.key | 1 + .../resources/tls/dh_params.pem | 1 + .../blackbox/implementations/CMakeLists.txt | 41 + .../implementations/ImplementationsTest.cpp | 218 ++++++ 35 files changed, 3861 insertions(+), 5 deletions(-) create mode 100644 ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp create mode 100644 ddsrouter_core/src/cpp/testing/random_values.cpp create mode 100644 ddsrouter_core/test/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/README.md create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/README.md create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h create mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp create mode 120000 ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt create mode 120000 ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt create mode 120000 ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key create mode 120000 ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem create mode 100644 ddsrouter_core/test/blackbox/implementations/CMakeLists.txt create mode 100644 ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp diff --git a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp index f5c12f1cf..daeec7eec 100644 --- a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp +++ b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp @@ -14,10 +14,6 @@ #pragma once -#include - -#include - #include #include diff --git a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp index a3847bff8..520bbf723 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp b/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp new file mode 100644 index 000000000..02d4d23fd --- /dev/null +++ b/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp @@ -0,0 +1,36 @@ +// Copyright 2021 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\. + +#pragma once + +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace testing { + +std::shared_ptr random_participant_configuration( + types::ParticipantKind kind, + unsigned int seed = 0); + +types::ParticipantKind random_participant_kind( + unsigned int seed = 0); + +} /* namespace testing */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/testing/random_values.cpp b/ddsrouter_core/src/cpp/testing/random_values.cpp new file mode 100644 index 000000000..335a77cb9 --- /dev/null +++ b/ddsrouter_core/src/cpp/testing/random_values.cpp @@ -0,0 +1,98 @@ +// Copyright 2021 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. + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace testing { + +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::core::types; +using namespace eprosima::ddspipe::participants; +using namespace eprosima::ddspipe::participants::testing; +using namespace eprosima::ddspipe::participants::types; +using namespace eprosima::ddsrouter::core::types; + +std::shared_ptr random_participant_configuration( + ParticipantKind kind, + unsigned int seed /* = 0 */) +{ + ParticipantId id = random_participant_id(seed); + + switch (kind) + { + case ParticipantKind::simple: + { + auto c = std::make_shared(); + c->id = id; + c->domain = random_domain(seed); + return c; + } + + case ParticipantKind::discovery_server: + { + auto c = std::make_shared(); + c->id = id; + c->domain = random_domain(seed); + c->discovery_server_guid_prefix = random_guid_prefix(seed); + c->connection_addresses = {random_connection_address(seed)}; + return c; + } + + case ParticipantKind::initial_peers: + + { + auto c = std::make_shared(); + c->id = id; + c->domain = random_domain(seed); + c->listening_addresses = {random_address(seed)}; + return c; + } + + case ParticipantKind::echo: + { + auto c = std::make_shared(); + c->id = id; + return c; + } + + default: + throw eprosima::utils::InconsistencyException("No valid kind"); + } +} + +ParticipantKind random_participant_kind( + unsigned int seed /* = 0 */) +{ + return VALUES_ParticipantKind[seed % N_VALUES_ParticipantKind]; +} + +} /* namespace testing */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/test/CMakeLists.txt b/ddsrouter_core/test/CMakeLists.txt new file mode 100644 index 000000000..4e105ab74 --- /dev/null +++ b/ddsrouter_core/test/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2022 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. + +add_subdirectory(blackbox) diff --git a/ddsrouter_core/test/blackbox/CMakeLists.txt b/ddsrouter_core/test/blackbox/CMakeLists.txt new file mode 100644 index 000000000..060cd8f0d --- /dev/null +++ b/ddsrouter_core/test/blackbox/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2021 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. + +# TODO uncomment when ready +# add_subdirectory(ddsrouter_core) +add_subdirectory(implementations) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/CMakeLists.txt new file mode 100644 index 000000000..b406aaeab --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2021 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. + +add_subdirectory(dds) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt new file mode 100644 index 000000000..e9705347f --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2021 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. + +add_subdirectory(local) +# add_subdirectory(repeater) +# add_subdirectory(WAN) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt new file mode 100644 index 000000000..3c70390c2 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt @@ -0,0 +1,80 @@ +# Copyright 2021 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. + +################ +# DDS Test WAN # +################ + +set(TEST_NAME + DDSTestWAN) + +set(TEST_SOURCES + DDSTestWAN.cpp + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) + +set(TEST_LIST + end_to_end_discovery_server_WAN_communication_UDPv4 + end_to_end_initial_peers_WAN_communication_UDPv4 + + end_to_end_discovery_server_WAN_communication_UDPv6 + end_to_end_initial_peers_WAN_communication_UDPv6 + + end_to_end_discovery_server_WAN_communication_TCPv4 + end_to_end_initial_peers_WAN_communication_TCPv4 + + end_to_end_discovery_server_WAN_communication_TCPv6 + end_to_end_initial_peers_WAN_communication_TCPv6 + + end_to_end_discovery_server_WAN_communication_TLSv4 + end_to_end_initial_peers_WAN_communication_TLSv4 + + end_to_end_discovery_server_WAN_communication_TLSv6 + end_to_end_initial_peers_WAN_communication_TLSv6 + + end_to_end_discovery_server_WAN_communication_high_throughput + end_to_end_initial_peers_WAN_communication_high_throughput + ) + + +set(TEST_NEEDED_SOURCES + # TLS security files + ../../resources/tls/ca.crt + ../../resources/tls/ddsrouter.crt + ../../resources/tls/ddsrouter.key + ../../resources/tls/dh_params.pem + ) + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") + +# Set flaky tests as xfail +add_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XFAIL.list) + +# Set as TSAN errors due to Fast DDS +# TODO: use a cmake_utils macro +file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/TEST_XTSAN.list TEST_LIST) +foreach(XTSAN_TEST ${TEST_LIST}) + set_property(TEST ${XTSAN_TEST} PROPERTY LABELS xtsan) +endforeach() diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp new file mode 100644 index 000000000..2ae469c87 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -0,0 +1,705 @@ +// Copyright 2021 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. + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace test { + +enum class WanParticipantKind +{ + discovery_server, + initial_peers +}; + +enum class WanKind +{ + server, + client, + server_and_client +}; + +bool is_client( + WanKind wan_kind) +{ + return wan_kind == WanKind::client || wan_kind == WanKind::server_and_client; +} + +bool is_server( + WanKind wan_kind) +{ + return wan_kind == WanKind::server || wan_kind == WanKind::server_and_client; +} + +constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; +constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; +constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes + +types::security::TlsConfiguration tls_configuration( + WanKind wan_kind) +{ + // TODO: test that using server with only Server required files works + // It fails when connecting to other server + if (is_server(wan_kind)) + { + types::security::TlsConfiguration tls; + tls.certificate_authority_file = "../../resources/tls/ca.crt"; + tls.private_key_file = "../../resources/tls/ddsrouter.key"; + tls.certificate_chain_file = "../../resources/tls/ddsrouter.crt"; + tls.dh_params_file = "../../resources/tls/dh_params.pem"; + return tls; + } + else + { + types::security::TlsConfiguration tls; + tls.certificate_authority_file = "../../resources/tls/ca.crt"; + return tls; + } +} + +std::shared_ptr discovery_server_participant_configuration( + bool this_server_id_is_1, + WanKind wan_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool tls = false) +{ + std::set listening_addresses; + std::set connection_addresses; + + if (is_client(wan_kind)) + { + connection_addresses.insert( + types::DiscoveryServerConnectionAddress( + types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), + { + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 0u : 1u), + 11666 + (this_server_id_is_1 ? 0u : 1u), + ip_version, + transport_protocol) + } + ) + ); + } + + if (is_server(wan_kind)) + { + listening_addresses.insert( + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 1u : 0u), + 11666 + (this_server_id_is_1 ? 1u : 0u), + ip_version, + transport_protocol) + ); + } + + if (tls) + { + return std::make_shared( + types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_discovery_server, + false, + types::DomainId(0u), + types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), + listening_addresses, + connection_addresses, + tls_configuration(wan_kind)); + + } + else + { + return std::make_shared( + types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_discovery_server, + false, + types::DomainId(0u), + types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), + listening_addresses, + connection_addresses, + types::security::TlsConfiguration()); + } +} + +std::shared_ptr initial_peers_participant_configuration( + bool this_server_id_is_1, + WanKind wan_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool tls = false) +{ + std::set listening_addresses; + std::set connection_addresses; + types::DomainId domain(60u); + + if (is_client(wan_kind)) + { + connection_addresses.insert( + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 0u : 1u), + 11666 + (this_server_id_is_1 ? 0u : 1u), + ip_version, + transport_protocol) + ); + } + + if (is_server(wan_kind)) + { + listening_addresses.insert( + types::Address( + (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 1u : 0u), + 11666 + (this_server_id_is_1 ? 1u : 0u), + ip_version, + transport_protocol) + ); + } + + if (tls) + { + return std::make_shared( + types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_initial_peers, + false, + domain, + listening_addresses, + connection_addresses, + tls_configuration(wan_kind)); + + } + else + { + return std::make_shared( + types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan_initial_peers, + false, + domain, + listening_addresses, + connection_addresses, + types::security::TlsConfiguration()); + } +} + +std::shared_ptr wan_participant_configuration( + WanParticipantKind wan_participant_kind, + bool this_server_id_is_1, + WanKind wan_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool tls = false) +{ + if (wan_participant_kind == WanParticipantKind::discovery_server) + { + return discovery_server_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, + tls); + } + else // WanParticipantKind::initial_peers + { + return initial_peers_participant_configuration(this_server_id_is_1, wan_kind, transport_protocol, ip_version, + tls); + } +} + +/** + * @brief Create a simple configuration for a DDS Router + * + * Create a configuration with 1 topic + * Create 1 simple participants with domains \c domain + * Create 1 custom participant by the configuration in \c participant_configuration + * + * @return configuration::DdsRouterConfiguration + */ +configuration::DdsRouterConfiguration router_configuration( + std::shared_ptr participant_configuration, + types::DomainIdType domain) +{ + // One topic + auto new_topic = std::make_shared(); + new_topic->topic_name = TOPIC_NAME; + new_topic->type_name = std::string("HelloWorld"); + + std::set> allowlist({new_topic}); + + std::set> blocklist; // empty + + std::set> builtin_topics; // empty + + // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 + std::set> participants_configurations( + { + // custom + participant_configuration, + + // simple + std::make_shared( + types::ParticipantId("simple_participant_" + std::to_string(domain)), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(domain) + ), + } + ); + + return configuration::DdsRouterConfiguration( + allowlist, + blocklist, + builtin_topics, + participants_configurations, + configuration::SpecsConfiguration()); +} + +/** + * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. + * This is accomplished by connecting two WAN Participants belonging to different DDS Router instances. These router + * instances communicate with the DDS Participants through Simple Participants deployed at those domains. + */ +void test_WAN_communication( + configuration::DdsRouterConfiguration ddsrouter_server_configuration, + configuration::DdsRouterConfiguration ddsrouter_client_configuration, + uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, + uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, + uint32_t msg_size = DEFAULT_MESSAGE_SIZE) +{ + // Check there are no warnings/errors + // TODO: Uncomment when having no listening addresses is no longer considered an error by the middleware + // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved + // test::LogChecker test_log_handler(Log::Kind::Error); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + // Create a message with size specified by repeating the same string + HelloWorld msg; + std::string msg_str; + + // Add this string as many times as the msg size requires + for (uint32_t i = 0; i < msg_size; i++) + { + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + } + msg.message(msg_str); + + // Create DDS Publisher in domain 0 + TestPublisher publisher; + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber; + ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); + + // Create DdsRouter entity whose WAN Participant is configured as server + DdsRouter server_router(ddsrouter_server_configuration); + server_router.start(); + + // Create DdsRouter entity whose WAN Participant is configured as client + DdsRouter client_router(ddsrouter_client_configuration); + client_router.start(); + + // Start publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + publisher.publish(msg); + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + client_router.stop(); + server_router.stop(); +} + +/** + * Test communication between WAN participants by running \c test_WAN_communication for different configurations. + * Different combinations of server/client configurations are tested. + * + * CASES: + * server <-> client + * server <-> server-client + * server-client <-> server-client (only when basic_only is deactivate) + */ +void test_WAN_communication_all( + WanParticipantKind wan_participant_kind, + types::TransportProtocol transport_protocol, + types::IpVersion ip_version, + bool basic_only = false, + bool tls = false) +{ + // Test architecture server <-> client + test::test_WAN_communication( + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + true, // is server 1 + WanKind::server, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 0 // domain + ), + + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + false, // is server 1 + WanKind::client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 1 // domain + ) + ); + + // Test architecture server <-> server-client + test::test_WAN_communication( + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + true, // is server 1 + WanKind::server, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 0 // domain + ), + + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + false, // is server 1 + WanKind::server_and_client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 1 // domain + ) + ); + + // This test is disabled for TCPv6 and TLSv6, as an underlying middleware issue resulting in no matching for this + // scenario exists. + // TODO: Test this as well for TCPv6 and TLSv6 cases when issue is fixed + if (!basic_only) + { + // Test architecture server-client <-> server-client + test::test_WAN_communication( + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + true, // is server 1 + WanKind::server_and_client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 0 // domain + ), + + test::router_configuration( + test::wan_participant_configuration( + wan_participant_kind, + false, // is server 1 + WanKind::server_and_client, + transport_protocol, // transport protocol + ip_version, // ip version + tls // tls + ), + 1 // domain + ) + ); + } +} + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through UDPv4. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::udp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through UDPv4. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::udp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through UDPv6. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::udp, + types::IpVersion::v6); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through UDPv6. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::udp, + types::IpVersion::v6); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TCPv4. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TCPv4. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v4); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TCPv6. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TCPv6. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TLSv4. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v4, + false, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TLSv4. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv4) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v4, + false, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through TLSv6. + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::discovery_server, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true, + true); +} + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through TLSv6. + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv6) +{ + test::test_WAN_communication_all( + test::WanParticipantKind::initial_peers, + types::TransportProtocol::tcp, + types::IpVersion::v6, + true, + true); +} + +/** + * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Discovery Server Participants connected + * through UDPv4. + * + * PARAMETERS: + * - Frequency: 1ms + * - Sample size: 50K + * -> Throughput: 50MBps + */ +TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_high_throughput) +{ + test::test_WAN_communication( + test::router_configuration( + test::discovery_server_participant_configuration( + true, // is server 1 + test::WanKind::server, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 0 // domain + ), + + test::router_configuration( + test::discovery_server_participant_configuration( + false, // is server 1 + test::WanKind::client, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 1 // domain + ), + + 500, + 1, + 1000); // 50K message size +} + +/** + * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, + * by using two routers with two Simple Participants at each domain, and two Initial Peers Participants connected + * through UDPv4. + * + * PARAMETERS: + * - Frequency: 1ms + * - Sample size: 50K + * -> Throughput: 50MBps + */ +TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_high_throughput) +{ + test::test_WAN_communication( + test::router_configuration( + test::initial_peers_participant_configuration( + true, // is server 1 + test::WanKind::server, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 0 // domain + ), + + test::router_configuration( + test::initial_peers_participant_configuration( + false, // is server 1 + test::WanKind::client, + types::TransportProtocol::udp, // transport protocol + types::IpVersion::v4 // ip version + ), + 1 // domain + ), + + 500, + 1, + 1000); // 50K message size +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/README.md b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/README.md new file mode 100644 index 000000000..943086ca9 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/README.md @@ -0,0 +1,7 @@ +# DDS Test WAN + +Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. +This is accomplished by connecting two (`DiscoveryServer` / `InitialPeers`) WAN Participants belonging to different DDS Router instances. +These router instances communicate with the DDS Participants through Simple Participants deployed at those domains. +Note that, although data transmission is accomplished by connecting two WAN Participants, the resulting communication +is still local (i.e. WAN communication is not tested here). diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list new file mode 100644 index 000000000..7aded2b7b --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list @@ -0,0 +1,8 @@ +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv6 diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list new file mode 100644 index 000000000..78996681f --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list @@ -0,0 +1,5 @@ +DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt new file mode 100644 index 000000000..f98f1006c --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt @@ -0,0 +1,84 @@ +# Copyright 2021 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. + +################## +# DDS Test local # +################## + +set(TEST_NAME + DDSTestLocal) + +set(TEST_SOURCES + DDSTestLocal.cpp + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) + +set(TEST_LIST + end_to_end_local_communication + end_to_end_local_communication_keyed + end_to_end_local_communication_disable_dynamic_discovery + end_to_end_local_communication_disable_dynamic_discovery_keyed + end_to_end_local_communication_high_frequency + end_to_end_local_communication_high_size + end_to_end_local_communication_high_throughput + end_to_end_local_communication_transient_local + end_to_end_local_communication_transient_local_disable_dynamic_discovery) + +set(TEST_NEEDED_SOURCES + ) + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") + +############################## +# DDS Test local Dispose Key # +############################## + +set(TEST_NAME + DDSTestLocalDisposeKey) + +set(TEST_SOURCES + DDSTestLocalDisposeKey.cpp + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx) + +set(TEST_LIST + end_to_end_local_communication_key_dispose) + +set(TEST_NEEDED_SOURCES + ) + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed, + ${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp new file mode 100644 index 000000000..1c00337ad --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -0,0 +1,329 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace test { + +constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; +constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; +constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes + +/** + * @brief Create a simple configuration for a DDS Router + * + * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME + * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. + * Create 2 simple participants with domains 0 and 1 + * + * @return configuration::DdsRouterConfiguration + */ +configuration::DdsRouterConfiguration dds_test_simple_configuration( + bool disable_dynamic_discovery = false, + bool transient_local_readers = false) +{ + // Always filter the test topics by topic name + std::set> allowlist; // empty + allowlist.insert(std::make_shared(TOPIC_NAME)); + + std::set> blocklist; // empty + + std::set> builtin_topics; // empty + + if (disable_dynamic_discovery) + { + types::TopicQoS qos; + if (transient_local_readers) + { + qos.reliability_qos = types::ReliabilityKind::RELIABLE; + qos.durability_qos = types::DurabilityKind::TRANSIENT_LOCAL; + } + else + { + qos.reliability_qos = types::ReliabilityKind::BEST_EFFORT; + qos.durability_qos = types::DurabilityKind::VOLATILE; + } + + builtin_topics.insert( + std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); + builtin_topics.insert( + std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); + } + + // Two simple participants + std::set> participants_configurations( + { + std::make_shared( + types::ParticipantId("participant_0"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(0u) + ), + std::make_shared( + types::ParticipantId("participant_1"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(1u) + ) + } + ); + + return configuration::DdsRouterConfiguration( + allowlist, + blocklist, + builtin_topics, + participants_configurations, + configuration::SpecsConfiguration()); +} + +/** + * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. + * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. + * + * The transient_local option changes the test behavior to verify that the communication is transient_local and all old data is sent + * to Late Joiners. + */ +template +void test_local_communication( + configuration::DdsRouterConfiguration ddsrouter_configuration, + uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, + uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, + uint32_t msg_size = DEFAULT_MESSAGE_SIZE, + bool transient_local = false) +{ + + // Check there are no warnings/errors + // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved + // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + // Create a message with size specified by repeating the same string + MsgStruct msg; + std::string msg_str; + + // Add this string as many times as the msg size requires + for (uint32_t i = 0; i < msg_size; i++) + { + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + } + msg.message(msg_str); + + // Create DDS Publisher in domain 0 + TestPublisher publisher(msg.isKeyDefined()); + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(msg.isKeyDefined(), transient_local); + ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); + + // Create DdsRouter entity + // The DDS Router does not start here in order to test a transient_local communication + DdsRouter router(ddsrouter_configuration); + + if (transient_local) + { + // To check that the communication is transient_local and all previous published samples are sent to late joiner, + // the publisher publish all data at once. + for (samples_sent = 0; samples_sent < samples_to_receive; samples_sent++) + { + msg.index(samples_sent); + ASSERT_TRUE(publisher.publish(msg)); + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + // Once the publisher has already publish all its samples, the DDS Router starts. + router.start(); + + // The subscriber should receive all samples sent by the publisher when the communication was not + // already established. + while (samples_received.load() < samples_to_receive) + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + } + else + { + // Start DDS Router + router.start(); + + // Start publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + publisher.publish(msg); + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + } + + router.stop(); +} + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + */ +TEST(DDSTestLocal, end_to_end_local_communication) +{ + test::test_local_communication( + test::dds_test_simple_configuration()); +} + +/** + * Test communication in HelloWorldKeyed topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + */ +TEST(DDSTestLocal, end_to_end_local_communication_keyed) +{ + test::test_local_communication( + test::dds_test_simple_configuration()); +} + +/** + * Test communication both in HelloWorld and HelloWorldKeyed topics between two DDS participants created in + * different domains, by using a router with two Simple Participants at each domain. + * In this test allowlist and blocklist are left empty, while only builtin topics are provided. + */ +TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery) +{ + test::test_local_communication( + test::dds_test_simple_configuration(true)); +} + +TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery_keyed) +{ + test::test_local_communication( + test::dds_test_simple_configuration(true)); +} + +/** + * Test high frequency communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + * + * PARAMETERS: + * - Frequency: max + */ +TEST(DDSTestLocal, end_to_end_local_communication_high_frequency) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + 1000, // wait for 1000 samples received + 0); // send it without waiting from one sample to the other +} + +/** + * Test high message size communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + * + * PARAMETERS: + * - Sample size: 500K + */ +TEST(DDSTestLocal, end_to_end_local_communication_high_size) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + test::DEFAULT_SAMPLES_TO_RECEIVE, + test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, + 10000); // 500K message size +} + +/** + * Test high throughput communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + * + * PARAMETERS: + * - Frequency: 1ms + * - Sample size: 50K + * -> Throughput: 50MBps + */ +TEST(DDSTestLocal, end_to_end_local_communication_high_throughput) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + 500, + 1, + 1000); // 50K message size +} + +/** + * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain. + */ +TEST(DDSTestLocal, end_to_end_local_communication_transient_local) +{ + test::test_local_communication( + test::dds_test_simple_configuration(), + test::DEFAULT_SAMPLES_TO_RECEIVE, + test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, + test::DEFAULT_MESSAGE_SIZE, + true); +} + +/** + * Test transient_local communication in HelloWorld topic between two DDS participants created in different domains, + * by using a router with two Simple Participants at each domain and using builtin-topics + */ +TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynamic_discovery) +{ + test::test_local_communication( + test::dds_test_simple_configuration(true, true), + test::DEFAULT_SAMPLES_TO_RECEIVE, + test::DEFAULT_MILLISECONDS_PUBLISH_LOOP, + test::DEFAULT_MESSAGE_SIZE, + true); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp new file mode 100644 index 000000000..a2797b693 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp @@ -0,0 +1,201 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace test { + +constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; +constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; +constexpr const uint32_t DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION = 500; +constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes + +/** + * @brief Create a simple configuration for a DDS Router + * + * Create a configuration with 1 topic in its allowlist, forwarding data for all topics with name TOPIC_NAME + * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. + * Create 2 simple participants with domains 0 and 1 + * + * @return configuration::DdsRouterConfiguration + */ +configuration::DdsRouterConfiguration dds_test_simple_configuration() +{ + // Always filter the test topics by topic name + std::set> allowlist; // only this topic + allowlist.insert(std::make_shared(TOPIC_NAME)); + + std::set> blocklist; // empty + + std::set> builtin_topics; // empty + + // Two simple participants + std::set> participants_configurations( + { + std::make_shared( + types::ParticipantId("participant_0"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(0u) + ), + std::make_shared( + types::ParticipantId("participant_1"), + types::ParticipantKind(types::ParticipantKind::simple_rtps), + false, + types::DomainId(1u) + ) + } + ); + + // TODO: this could be removed to use default number of threads + auto specs = configuration::SpecsConfiguration(); + specs.number_of_threads = 2; + + return configuration::DdsRouterConfiguration( + allowlist, + blocklist, + builtin_topics, + participants_configurations, + specs); +} + +/** + * Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. + * This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. + * + * The reliable option changes the test behavior to verify that the communication is reliable and all old data is sent + * to Late Joiners. + */ +void test_local_communication_key_dispose( + configuration::DdsRouterConfiguration ddsrouter_configuration, + uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, + uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, + uint32_t msg_size = DEFAULT_MESSAGE_SIZE) +{ + // Check there are no warnings/errors + // TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved + // eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + // Create a message with size specified by repeating the same string + HelloWorldKeyed msg; + std::string msg_str; + + // Add this string as many times as the msg size requires + for (uint32_t i = 0; i < msg_size; i++) + { + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + } + msg.message(msg_str); + msg.id(666); + + // Create DDS Publisher in domain 0 + TestPublisher publisher(msg.isKeyDefined()); + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(msg.isKeyDefined()); + ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); + + // Create DdsRouter entity + // The DDS Router does not start here in order to test a reliable communication + DdsRouter router(ddsrouter_configuration); + + // Start DDS Router + router.start(); + + // Start publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + ASSERT_TRUE(publisher.publish(msg)) << samples_sent; + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + // All samples received, now dispose key from publisher and check that subscriber has receive it + ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); + std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); + samples_received.store(0); + + // Keep publishing + while (samples_received.load() < samples_to_receive) + { + msg.index(++samples_sent); + ASSERT_TRUE(publisher.publish(msg)) << samples_sent; + + // If time is 0 do not wait + if (time_between_samples > 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples)); + } + } + + // All samples received, now dispose key from publisher and check that subscriber has receive it + ASSERT_TRUE(publisher.dispose_key(msg) == ReturnCode_t::RETCODE_OK); + std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION)); + + ASSERT_EQ(2u, subscriber.n_disposed()); + + router.stop(); +} + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; + +/** + * Test that dispose values from the publisher are correctly received by the subscriber from the router. + */ +TEST(DDSTestLocalDisposeKey, end_to_end_local_communication_key_dispose) +{ + test::test_local_communication_key_dispose( + test::dds_test_simple_configuration()); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/README.md b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/README.md new file mode 100644 index 000000000..a94c61e34 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/README.md @@ -0,0 +1,6 @@ +# DDS Test Local + +Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains. +This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain. +First, router initialization is tested, and then communication between the DDS Participants is tested both for topics +*HelloWorld* and *HelloWorldKeyed*. diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp index 16a7d25df..25a8c9ab7 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -104,9 +104,15 @@ std::shared_ptr participant_configurati * Create 1 simple participants with domains \c domain * Create 1 custom participant by the configuration in \c participant_configuration * +<<<<<<< HEAD * @return configuration::DDSRouterConfiguration */ configuration::DDSRouterConfiguration router_configuration( +======= + * @return configuration::DdsRouterConfiguration + */ +configuration::DdsRouterConfiguration router_configuration( +>>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) std::shared_ptr participant_configuration, types::DomainIdType domain, bool has_simple = true) @@ -137,7 +143,11 @@ configuration::DDSRouterConfiguration router_configuration( )); } +<<<<<<< HEAD return configuration::DDSRouterConfiguration( +======= + return configuration::DdsRouterConfiguration( +>>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) allowlist, blocklist, builtin_topics, @@ -151,9 +161,15 @@ configuration::DDSRouterConfiguration router_configuration( * instances communicate with the DDS Participants through Simple Participants deployed at those domains. */ void test_WAN_communication( +<<<<<<< HEAD configuration::DDSRouterConfiguration ddsrouter_client_configuration_1, configuration::DDSRouterConfiguration ddsrouter_client_configuration_2, configuration::DDSRouterConfiguration ddsrouter_repeater_configuration, +======= + configuration::DdsRouterConfiguration ddsrouter_client_configuration_1, + configuration::DdsRouterConfiguration ddsrouter_client_configuration_2, + configuration::DdsRouterConfiguration ddsrouter_repeater_configuration, +>>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE) @@ -173,7 +189,11 @@ void test_WAN_communication( // Add this string as many times as the msg size requires for (uint32_t i = 0; i < msg_size; i++) { +<<<<<<< HEAD msg_str += "Testing DDSRouter Blackbox Local Communication ..."; +======= + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; +>>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) } msg.message(msg_str); @@ -185,6 +205,7 @@ void test_WAN_communication( TestSubscriber subscriber; ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); +<<<<<<< HEAD // Create DDSRouter entity whose WAN Participant is configured as server DDSRouter client_router_1(ddsrouter_client_configuration_1); client_router_1.start(); @@ -195,6 +216,18 @@ void test_WAN_communication( // Create DDSRouter entity whose WAN Participant is configured as repeater DDSRouter repeater(ddsrouter_repeater_configuration); +======= + // Create DdsRouter entity whose WAN Participant is configured as server + DdsRouter client_router_1(ddsrouter_client_configuration_1); + client_router_1.start(); + + // Create DdsRouter entity whose WAN Participant is configured as client + DdsRouter client_router_2(ddsrouter_client_configuration_2); + client_router_2.start(); + + // Create DdsRouter entity whose WAN Participant is configured as repeater + DdsRouter repeater(ddsrouter_repeater_configuration); +>>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) repeater.start(); // Start publishing diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx new file mode 100644 index 000000000..b850b4501 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx @@ -0,0 +1,207 @@ +// Copyright 2016 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 HelloWorld.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { char dummy; } +#endif + +#include "HelloWorld.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +HelloWorld::HelloWorld() +{ + // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@1622f1b + m_index = 0; + // m_message com.eprosima.idl.parser.typecode.StringTypeCode@70e8f8e + m_message =""; + +} + +HelloWorld::~HelloWorld() +{ + + +} + +HelloWorld::HelloWorld(const HelloWorld &x) +{ + m_index = x.m_index; + m_message = x.m_message; +} + +HelloWorld::HelloWorld(HelloWorld &&x) +{ + m_index = x.m_index; + m_message = std::move(x.m_message); +} + +HelloWorld& HelloWorld::operator=(const HelloWorld &x) +{ + + m_index = x.m_index; + m_message = x.m_message; + + return *this; +} + +HelloWorld& HelloWorld::operator=(HelloWorld &&x) +{ + + m_index = x.m_index; + m_message = std::move(x.m_message); + + return *this; +} + +size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; + + + return current_alignment - initial_alignment; +} + +size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; + + + return current_alignment - initial_alignment; +} + +void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const +{ + + scdr << m_index; + scdr << m_message; +} + +void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr) +{ + + dcdr >> m_index; + dcdr >> m_message; +} + +/*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ +void HelloWorld::index(uint32_t _index) +{ +m_index = _index; +} + +/*! + * @brief This function returns the value of member index + * @return Value of member index + */ +uint32_t HelloWorld::index() const +{ + return m_index; +} + +/*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ +uint32_t& HelloWorld::index() +{ + return m_index; +} + +/*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ +void HelloWorld::message(const std::string &_message) +{ +m_message = _message; +} + +/*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ +void HelloWorld::message(std::string &&_message) +{ +m_message = std::move(_message); +} + +/*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ +const std::string& HelloWorld::message() const +{ + return m_message; +} + +/*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ +std::string& HelloWorld::message() +{ + return m_message; +} + +size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment) +{ + size_t current_align = current_alignment; + + + + + + return current_align; +} + +bool HelloWorld::isKeyDefined() +{ + return false; +} + +void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const +{ + (void) scdr; + + +} diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h new file mode 100644 index 000000000..fa8952126 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.h @@ -0,0 +1,219 @@ +// Copyright 2016 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 HelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _HELLOWORLD_H_ +#define _HELLOWORLD_H_ + +// TODO Poner en el contexto. + +#include +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // if defined(EPROSIMA_USER_DLL_EXPORT) +#else +#define eProsima_user_DllExport +#endif // if defined(_WIN32) + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(HelloWorld_SOURCE) +#define HelloWorld_DllAPI __declspec( dllexport ) +#else +#define HelloWorld_DllAPI __declspec( dllimport ) +#endif // HelloWorld_SOURCE +#else +#define HelloWorld_DllAPI +#endif // if defined(EPROSIMA_USER_DLL_EXPORT) +#else +#define HelloWorld_DllAPI +#endif // _WIN32 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +class HelloWorld +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport HelloWorld(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~HelloWorld(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld( + const HelloWorld& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld( + HelloWorld&& x); + + /*! + * @brief Copy assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator =( + const HelloWorld& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator =( + HelloWorld&& x); + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ + eProsima_user_DllExport void message( + const std::string& _message); + + /*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ + eProsima_user_DllExport void message( + std::string&& _message); + + /*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ + eProsima_user_DllExport const std::string& message() const; + + /*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ + eProsima_user_DllExport std::string& message(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const HelloWorld& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + uint32_t m_index; + std::string m_message; +}; + +#endif // _HELLOWORLD_H_ diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl new file mode 100644 index 000000000..0fd2c355a --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx new file mode 100644 index 000000000..a2a27e7bc --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx @@ -0,0 +1,133 @@ +// Copyright 2016 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 HelloWorldPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#include +#include + +#include "HelloWorldPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + +HelloWorldPubSubType::HelloWorldPubSubType() +{ + setName("HelloWorld"); + m_typeSize = static_cast(HelloWorld::getMaxCdrSerializedSize()) + 4 /*encapsulation*/; + m_isGetKeyDefined = HelloWorld::isKeyDefined(); + size_t keyLength = HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +HelloWorldPubSubType::~HelloWorldPubSubType() +{ + if(m_keyBuffer!=nullptr) + free(m_keyBuffer); +} + +bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) +{ + HelloWorld *p_type = static_cast(data); + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + // Serialize encapsulation + ser.serialize_encapsulation(); + + try + { + p_type->serialize(ser); // Serialize the object: + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + payload->length = static_cast(ser.getSerializedDataLength()); //Get the serialized length + return true; +} + +bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) +{ + HelloWorld* p_type = static_cast(data); //Convert DATA to pointer of your type + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data. + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + p_type->deserialize(deser); //Deserialize the object: + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + return true; +} + +std::function HelloWorldPubSubType::getSerializedSizeProvider(void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + 4 /*encapsulation*/; + }; +} + +void* HelloWorldPubSubType::createData() +{ + return reinterpret_cast(new HelloWorld()); +} + +void HelloWorldPubSubType::deleteData(void* data) +{ + delete(reinterpret_cast(data)); +} + +bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5) +{ + if(!m_isGetKeyDefined) + return false; + HelloWorld* p_type = static_cast(data); + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer),HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data. + p_type->serializeKey(ser); + if(force_md5 || HelloWorld::getKeyMaxCdrSerializedSize()>16) { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + m_md5.finalize(); + for(uint8_t i = 0;i<16;++i) { + handle->value[i] = m_md5.digest[i]; + } + } + else { + for(uint8_t i = 0;i<16;++i) { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h new file mode 100644 index 000000000..3fd9b2c65 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.h @@ -0,0 +1,67 @@ +// Copyright 2016 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 HelloWorldPubSubTypes.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#ifndef _HELLOWORLD_PUBSUBTYPES_H_ +#define _HELLOWORLD_PUBSUBTYPES_H_ + +#include +#include + +#include "HelloWorld.h" + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#error Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // if !defined(GEN_API_VER) || (GEN_API_VER != 1) + +/*! + * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef HelloWorld type; + + eProsima_user_DllExport HelloWorldPubSubType(); + + eProsima_user_DllExport virtual ~HelloWorldPubSubType(); + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + eProsima_user_DllExport virtual void* createData() override; + eProsima_user_DllExport virtual void deleteData( + void* data) override; + MD5 m_md5; + unsigned char* m_keyBuffer; +}; + +#endif // _HELLOWORLD_PUBSUBTYPES_H_ diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx new file mode 100644 index 000000000..43e4eb3b9 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx @@ -0,0 +1,283 @@ +// Copyright 2016 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 HelloWorldKeyed.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { +char dummy; +} // namespace +#endif // _WIN32 + +#include "HelloWorldKeyed.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +HelloWorldKeyed::HelloWorldKeyed() +{ + // m_id com.eprosima.idl.parser.typecode.PrimitiveTypeCode@77a57272 + m_id = 0; + // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@7181ae3f + m_index = 0; + // m_message com.eprosima.idl.parser.typecode.StringTypeCode@46238e3f + m_message =""; + +} + +HelloWorldKeyed::~HelloWorldKeyed() +{ + + + +} + +HelloWorldKeyed::HelloWorldKeyed( + const HelloWorldKeyed& x) +{ + m_id = x.m_id; + m_index = x.m_index; + m_message = x.m_message; +} + +HelloWorldKeyed::HelloWorldKeyed( + HelloWorldKeyed&& x) +{ + m_id = x.m_id; + m_index = x.m_index; + m_message = std::move(x.m_message); +} + +HelloWorldKeyed& HelloWorldKeyed::operator =( + const HelloWorldKeyed& x) +{ + + m_id = x.m_id; + m_index = x.m_index; + m_message = x.m_message; + + return *this; +} + +HelloWorldKeyed& HelloWorldKeyed::operator =( + HelloWorldKeyed&& x) +{ + + m_id = x.m_id; + m_index = x.m_index; + m_message = std::move(x.m_message); + + return *this; +} + +bool HelloWorldKeyed::operator ==( + const HelloWorldKeyed& x) const +{ + + return (m_id == x.m_id && m_index == x.m_index && m_message == x.m_message); +} + +bool HelloWorldKeyed::operator !=( + const HelloWorldKeyed& x) const +{ + return !(*this == x); +} + +size_t HelloWorldKeyed::getMaxCdrSerializedSize( + size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; + + + return current_alignment - initial_alignment; +} + +size_t HelloWorldKeyed::getCdrSerializedSize( + const HelloWorldKeyed& data, + size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1; + + + return current_alignment - initial_alignment; +} + +void HelloWorldKeyed::serialize( + eprosima::fastcdr::Cdr& scdr) const +{ + + scdr << m_id; + scdr << m_index; + scdr << m_message; + +} + +void HelloWorldKeyed::deserialize( + eprosima::fastcdr::Cdr& dcdr) +{ + + dcdr >> m_id; + dcdr >> m_index; + dcdr >> m_message; +} + +/*! + * @brief This function sets a value in member id + * @param _id New value for member id + */ +void HelloWorldKeyed::id( + int32_t _id) +{ + m_id = _id; +} + +/*! + * @brief This function returns the value of member id + * @return Value of member id + */ +int32_t HelloWorldKeyed::id() const +{ + return m_id; +} + +/*! + * @brief This function returns a reference to member id + * @return Reference to member id + */ +int32_t& HelloWorldKeyed::id() +{ + return m_id; +} + +/*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ +void HelloWorldKeyed::index( + uint32_t _index) +{ + m_index = _index; +} + +/*! + * @brief This function returns the value of member index + * @return Value of member index + */ +uint32_t HelloWorldKeyed::index() const +{ + return m_index; +} + +/*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ +uint32_t& HelloWorldKeyed::index() +{ + return m_index; +} + +/*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ +void HelloWorldKeyed::message( + const std::string& _message) +{ + m_message = _message; +} + +/*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ +void HelloWorldKeyed::message( + std::string&& _message) +{ + m_message = std::move(_message); +} + +/*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ +const std::string& HelloWorldKeyed::message() const +{ + return m_message; +} + +/*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ +std::string& HelloWorldKeyed::message() +{ + return m_message; +} + +size_t HelloWorldKeyed::getKeyMaxCdrSerializedSize( + size_t current_alignment) +{ + size_t current_align = current_alignment; + + + current_align += 4 + eprosima::fastcdr::Cdr::alignment(current_align, 4); + + + + + + return current_align; +} + +bool HelloWorldKeyed::isKeyDefined() +{ + return true; +} + +void HelloWorldKeyed::serializeKey( + eprosima::fastcdr::Cdr& scdr) const +{ + (void) scdr; + scdr << m_id; + +} diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h new file mode 100644 index 000000000..e1f8eb462 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.h @@ -0,0 +1,252 @@ +// Copyright 2016 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 HelloWorldKeyed.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ +#define _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ + + +#include +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(HelloWorldKeyed_SOURCE) +#define HelloWorldKeyed_DllAPI __declspec( dllexport ) +#else +#define HelloWorldKeyed_DllAPI __declspec( dllimport ) +#endif // HelloWorldKeyed_SOURCE +#else +#define HelloWorldKeyed_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define HelloWorldKeyed_DllAPI +#endif // _WIN32 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the structure HelloWorldKeyed defined by the user in the IDL file. + * @ingroup HELLOWORLDKEYED + */ +class HelloWorldKeyed +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport HelloWorldKeyed(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~HelloWorldKeyed(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed( + const HelloWorldKeyed& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed( + HelloWorldKeyed&& x); + + /*! + * @brief Copy assignment. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed& operator =( + const HelloWorldKeyed& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object HelloWorldKeyed that will be copied. + */ + eProsima_user_DllExport HelloWorldKeyed& operator =( + HelloWorldKeyed&& x); + + /*! + * @brief Comparison operator. + * @param x HelloWorldKeyed object to compare. + */ + eProsima_user_DllExport bool operator ==( + const HelloWorldKeyed& x) const; + + /*! + * @brief Comparison operator. + * @param x HelloWorldKeyed object to compare. + */ + eProsima_user_DllExport bool operator !=( + const HelloWorldKeyed& x) const; + + /*! + * @brief This function sets a value in member id + * @param _id New value for member id + */ + eProsima_user_DllExport void id( + int32_t _id); + + /*! + * @brief This function returns the value of member id + * @return Value of member id + */ + eProsima_user_DllExport int32_t id() const; + + /*! + * @brief This function returns a reference to member id + * @return Reference to member id + */ + eProsima_user_DllExport int32_t& id(); + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ + eProsima_user_DllExport void message( + const std::string& _message); + + /*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ + eProsima_user_DllExport void message( + std::string&& _message); + + /*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ + eProsima_user_DllExport const std::string& message() const; + + /*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ + eProsima_user_DllExport std::string& message(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const HelloWorldKeyed& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + int32_t m_id; + uint32_t m_index; + std::string m_message; +}; + +#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_H_ \ No newline at end of file diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl new file mode 100644 index 000000000..6cebe626d --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.idl @@ -0,0 +1,6 @@ +struct HelloWorldKeyed +{ + @Key long id; + unsigned long index; + string message; +}; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx new file mode 100644 index 000000000..61eb7c992 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx @@ -0,0 +1,170 @@ +// Copyright 2016 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 HelloWorldKeyedPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#include +#include + +#include "HelloWorldKeyedPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + +HelloWorldKeyedPubSubType::HelloWorldKeyedPubSubType() +{ + setName("HelloWorldKeyed"); + auto type_size = HelloWorldKeyed::getMaxCdrSerializedSize(); + type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ + m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ + m_isGetKeyDefined = HelloWorldKeyed::isKeyDefined(); + size_t keyLength = HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16 ? + HelloWorldKeyed::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +HelloWorldKeyedPubSubType::~HelloWorldKeyedPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool HelloWorldKeyedPubSubType::serialize( + void* data, + SerializedPayload_t* payload) +{ + HelloWorldKeyed* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + // Serialize encapsulation + ser.serialize_encapsulation(); + + try + { + // Serialize the object. + p_type->serialize(ser); + } + catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + // Get the serialized length + payload->length = static_cast(ser.getSerializedDataLength()); + return true; +} + +bool HelloWorldKeyedPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + //Convert DATA to pointer of your type + HelloWorldKeyed* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + // Deserialize the object. + p_type->deserialize(deser); + } + catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + return true; +} + +std::function HelloWorldKeyedPubSubType::getSerializedSizeProvider( + void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; + }; +} + +void* HelloWorldKeyedPubSubType::createData() +{ + return reinterpret_cast(new HelloWorldKeyed()); +} + +void HelloWorldKeyedPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool HelloWorldKeyedPubSubType::getKey( + void* data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + HelloWorldKeyed* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + HelloWorldKeyed::getKeyMaxCdrSerializedSize()); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); + p_type->serializeKey(ser); + if (force_md5 || HelloWorldKeyed::getKeyMaxCdrSerializedSize() > 16) + { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h new file mode 100644 index 000000000..fe9248a00 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h @@ -0,0 +1,101 @@ +// Copyright 2016 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 HelloWorldKeyedPubSubTypes.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#ifndef _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ +#define _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ + +#include +#include + +#include "HelloWorldKeyed.h" + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#error \ + Generated HelloWorldKeyed is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + +/*! + * @brief This class represents the TopicDataType of the type HelloWorldKeyed defined by the user in the IDL file. + * @ingroup HELLOWORLDKEYED + */ +class HelloWorldKeyedPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef HelloWorldKeyed type; + + eProsima_user_DllExport HelloWorldKeyedPubSubType(); + + eProsima_user_DllExport virtual ~HelloWorldKeyedPubSubType(); + + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport virtual void* createData() override; + + eProsima_user_DllExport virtual void deleteData( + void* data) override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + (void)memory; + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + MD5 m_md5; + unsigned char* m_keyBuffer; +}; + +#endif // _FAST_DDS_GENERATED_HELLOWORLDKEYED_PUBSUBTYPES_H_ \ No newline at end of file diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp new file mode 100644 index 000000000..03c0d7cb5 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp @@ -0,0 +1,497 @@ +// Copyright 2021 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. + +#pragma once + +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "HelloWorld/HelloWorldPubSubTypes.h" +#include "HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h" + +namespace eprosima { +namespace ddsrouter { +namespace core { +namespace test { + +constexpr const char* TOPIC_NAME = "DDS-Router-Test"; + +/** + * Class used to group into a single working unit a Publisher with a DataWriter and a TypeSupport member corresponding + * to the HelloWorld datatype + */ +template +class TestPublisher +{ +public: + + TestPublisher( + bool keyed = false) + : participant_(nullptr) + , publisher_(nullptr) + , topic_(nullptr) + , writer_(nullptr) + , keyed_(keyed) + { + } + + ~TestPublisher() + { + if (participant_ != nullptr) + { + if (publisher_ != nullptr) + { + if (writer_ != nullptr) + { + publisher_->delete_datawriter(writer_); + } + participant_->delete_publisher(publisher_); + } + if (topic_ != nullptr) + { + participant_->delete_topic(topic_); + } + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); + } + } + + //! Initialize the publisher + bool init( + uint32_t domain) + { + // CREATE THE PARTICIPANT + eprosima::fastdds::dds::DomainParticipantQos pqos; + + pqos.name("Participant_pub"); + participant_ = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); + + if (participant_ == nullptr) + { + return false; + } + + // REGISTER THE TYPE + eprosima::fastdds::dds::TypeSupport type; + if (keyed_) + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); + } + else + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); + } + type.register_type(participant_); + + // CREATE THE PUBLISHER + publisher_ = participant_->create_publisher(eprosima::fastdds::dds::PUBLISHER_QOS_DEFAULT, nullptr); + + if (publisher_ == nullptr) + { + return false; + } + + // CREATE THE TOPIC + std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; + topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); + + if (topic_ == nullptr) + { + return false; + } + + // CREATE THE WRITER + // Set memory management policy so it uses realloc + eprosima::fastdds::dds::DataWriterQos wqos = eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT; + wqos.endpoint().history_memory_policy = + eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + wqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; + writer_ = publisher_->create_datawriter(topic_, wqos, &listener_); + + if (writer_ == nullptr) + { + return false; + } + + return true; + } + + //! Publish a sample + bool publish( + MsgStruct msg) + { + hello_.index(msg.index()); + hello_.message(msg.message()); + return writer_->write(&hello_); + } + + //! Dispose instance + eprosima::fastrtps::types::ReturnCode_t dispose_key( + MsgStruct msg); + + void wait_discovery( + uint32_t n_subscribers = 1) + { + listener_.wait_discovery(n_subscribers); + } + +private: + + MsgStruct hello_; + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Publisher* publisher_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::DataWriter* writer_; + + bool keyed_; + + class PubListener : public eprosima::fastdds::dds::DataWriterListener + { + public: + + PubListener() + : discovered(0) + { + } + + void wait_discovery( + uint32_t n_subscribers = 1) + { + if (discovered < n_subscribers) + { + std::unique_lock lock(wait_discovery_cv_mtx); + wait_discovery_cv.wait(lock, [this, n_subscribers] + { + return discovered >= n_subscribers; + }); + } + } + + void on_publication_matched( + eprosima::fastdds::dds::DataWriter*, + const eprosima::fastdds::dds::PublicationMatchedStatus& info) + { + if (info.current_count_change == 1) + { + discovered = info.current_count; + wait_discovery_cv.notify_all(); + } + else if (info.current_count_change == -1) + { + discovered = info.current_count; + } + } + + private: + + //! Number of DataReaders discovered + std::atomic discovered; + + //! Protects wait_discovery condition variable + std::mutex wait_discovery_cv_mtx; + + //! Waits to discovery enough DataReaders + std::condition_variable wait_discovery_cv; + } + listener_; +}; + +template <> +bool TestPublisher::publish( + HelloWorldKeyed msg) +{ + hello_.index(msg.index()); + hello_.message(msg.message()); + hello_.id(msg.id()); + return writer_->write(&hello_); +} + +template <> +eprosima::fastrtps::types::ReturnCode_t TestPublisher::dispose_key( + HelloWorldKeyed msg) +{ + hello_.id(msg.id()); + return writer_->dispose(&hello_, eprosima::fastdds::dds::HANDLE_NIL); +} + +/** + * Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member + * corresponding to the HelloWorld datatype + */ +template +class TestSubscriber +{ +public: + + TestSubscriber( + bool keyed = false, + bool reliable = false) + : participant_(nullptr) + , subscriber_(nullptr) + , topic_(nullptr) + , reader_(nullptr) + , keyed_(keyed) + , reliable_ (reliable) + { + } + + ~TestSubscriber() + { + if (participant_ != nullptr) + { + if (topic_ != nullptr) + { + participant_->delete_topic(topic_); + } + if (subscriber_ != nullptr) + { + if (reader_ != nullptr) + { + subscriber_->delete_datareader(reader_); + } + participant_->delete_subscriber(subscriber_); + } + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->delete_participant(participant_); + } + } + + //! Initialize the subscriber + bool init( + uint32_t domain, + MsgStruct* msg_should_receive, + std::atomic* samples_received) + { + // INITIALIZE THE LISTENER + listener_.init(msg_should_receive, samples_received); + + // CREATE THE PARTICIPANT + eprosima::fastdds::dds::DomainParticipantQos pqos; + pqos.name("Participant_sub"); + participant_ = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(domain, pqos); + + if (participant_ == nullptr) + { + return false; + } + + // REGISTER THE TYPE + eprosima::fastdds::dds::TypeSupport type; + if (keyed_) + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType()); + } + else + { + type = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); + } + type.register_type(participant_); + + // CREATE THE SUBSCRIBER + subscriber_ = participant_->create_subscriber(eprosima::fastdds::dds::SUBSCRIBER_QOS_DEFAULT, nullptr); + + if (subscriber_ == nullptr) + { + return false; + } + + // CREATE THE TOPIC + std::string type_name = keyed_ ? "HelloWorldKeyed" : "HelloWorld"; + topic_ = participant_->create_topic(TOPIC_NAME, type_name, eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); + + if (topic_ == nullptr) + { + return false; + } + + // CREATE THE READER + // Set memory management policy so it uses realloc + eprosima::fastdds::dds::DataReaderQos rqos = eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT; + rqos.endpoint().history_memory_policy = + eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + rqos.history().kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; + if (reliable_) + { + rqos.durability().kind = eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; + rqos.reliability().kind = eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; + } + + reader_ = subscriber_->create_datareader(topic_, rqos, &listener_); + + if (reader_ == nullptr) + { + return false; + } + + return true; + } + + void wait_discovery( + uint32_t n_publishers = 1) + { + listener_.wait_discovery(n_publishers); + } + + uint32_t n_disposed() const + { + return listener_.n_key_disposed; + } + +private: + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Subscriber* subscriber_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::DataReader* reader_; + + bool keyed_; + + bool reliable_; + + /** + * Class handling dataflow events + */ + class SubListener : public eprosima::fastdds::dds::DataReaderListener + { + public: + + SubListener() + : discovered(0) + { + } + + //! Initialize the listener + void init( + MsgStruct* msg_should_receive_arg, + std::atomic* samples_received_arg) + { + msg_should_receive = msg_should_receive_arg; + samples_received = samples_received_arg; + n_key_disposed = 0; + } + + void wait_discovery( + uint32_t n_publishers = 1) + { + if (discovered < n_publishers) + { + std::unique_lock lock(wait_discovery_cv_mtx); + wait_discovery_cv.wait(lock, [this, n_publishers] + { + return discovered >= n_publishers; + }); + } + } + + //! Callback executed when a new sample is received + void on_data_available( + eprosima::fastdds::dds::DataReader* reader) override + { + eprosima::fastdds::dds::SampleInfo info; + while (reader->take_next_sample(&msg_received, &info) == ReturnCode_t::RETCODE_OK) + { + if (info.instance_state == eprosima::fastdds::dds::ALIVE_INSTANCE_STATE) + { + if (msg_received.message() == msg_should_receive->message()) + { + (*samples_received)++; + } + } + else if (info.instance_state == eprosima::fastdds::dds::NOT_ALIVE_DISPOSED_INSTANCE_STATE) + { + n_key_disposed++; + } + } + } + + void on_subscription_matched( + eprosima::fastdds::dds::DataReader*, + const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) + { + if (info.current_count_change == 1) + { + discovered = info.current_count; + wait_discovery_cv.notify_all(); + } + else if (info.current_count_change == -1) + { + discovered = info.current_count; + } + } + + //! Placeholder where received data is stored + MsgStruct msg_received; + + std::atomic n_key_disposed; + + //! Reference to the sample sent by the publisher + MsgStruct* msg_should_receive; + + //! Reference to received messages counter + std::atomic* samples_received; + + //! Number of DataWriters discovered + std::atomic discovered; + + //! Protects wait_discovery condition variable + std::mutex wait_discovery_cv_mtx; + + //! Waits to discovery enough DataWriters + std::condition_variable wait_discovery_cv; + } + listener_; +}; + +} /* namespace test */ +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* _TEST_BLACKBOX_DDSROUTERCORE_DDS_TYPES_TEST_PARTICIPANTS_HPP_ */ diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt new file mode 120000 index 000000000..470d47e16 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ca.crt @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/ca.crt \ No newline at end of file diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt new file mode 120000 index 000000000..19c9a0d73 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.crt @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/ddsrouter.crt \ No newline at end of file diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key new file mode 120000 index 000000000..9f58dfbe3 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/ddsrouter.key @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/ddsrouter.key \ No newline at end of file diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem new file mode 120000 index 000000000..65a440083 --- /dev/null +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/resources/tls/dh_params.pem @@ -0,0 +1 @@ +../../../../../../resources/configurations/security/tls/dh_params.pem \ No newline at end of file diff --git a/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt b/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt new file mode 100644 index 000000000..6b283e469 --- /dev/null +++ b/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright 2021 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. + +######################## +# Implementations Test # +######################## + +set(TEST_NAME + ImplementationsTest) + +set(TEST_SOURCES + ImplementationsTest.cpp + ) + +set(TEST_LIST + pair_implementation + pair_implementation_with_topic + all_implementations + duplicated_ids_negative + ) + +set(TEST_NEEDED_SOURCES + ) + +add_blackbox_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_NEEDED_SOURCES}" + ) diff --git a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp new file mode 100644 index 000000000..04f823547 --- /dev/null +++ b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp @@ -0,0 +1,218 @@ +// Copyright 2021 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. + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace test { + +constexpr const unsigned int DEFAULT_THREAD_POOL_SIZE = 2; +constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; + +} /* namespace test */ + +using namespace eprosima::ddsrouter::core; +using namespace eprosima::ddsrouter::core::types; +using namespace eprosima::ddsrouter::core::testing; + +/** + * Test that creates a DdsRouter with a Pair of Participants of same kind. + * It creates a DdsRouter with two Participants of same kind, starts it, then stops it and finally destroys it. + * + * This test will fail if it crashes. + */ +TEST(ImplementationsTest, pair_implementation) +{ + // TODO: Change to warning when fastdds warning: + // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: + // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> + // Function eprosima::fastdds::rtps::UDPChannelResource::Receive + // test::LogChecker test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + // For each Participant Kind + for (ParticipantKind kind : VALUES_ParticipantKind) + { + // Generate configuration + DdsRouterConfiguration configuration; + configuration.participants_configurations.insert( + { + kind, + random_participant_configuration(kind, 0) + } + ); + configuration.participants_configurations.insert( + { + kind, + random_participant_configuration(kind, 1) + } + ); + + // Create DdsRouter entity + DdsRouter router(configuration); + + // Start DdsRouter + router.start(); + + // Stop DDS Router + router.stop(); + + // Let DdsRouter object destroy for the next iteration + } +} + +/** + * Test that creates a DdsRouter with a Pair of Participants of same kind. + * It creates a DdsRouter with two Participants of same kind, starts it with an active topic, + * then stops it and finally destroys it. + * + * This test will fail if it crashes. + */ +TEST(ImplementationsTest, pair_implementation_with_topic) +{ + // TODO: Change to warning when fastdds warning: + // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: + // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> + // Function eprosima::fastdds::rtps::UDPChannelResource::Receive + // test::LogChecker test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + // For each Participant kind + for (ParticipantKind kind : VALUES_ParticipantKind) + { + // Generate configuration + DdsRouterConfiguration configuration; + configuration.participants_configurations.insert( + { + kind, + random_participant_configuration(kind, 0) + } + ); + configuration.participants_configurations.insert( + { + kind, + random_participant_configuration(kind, 1) + } + ); + + // Add topic + std::shared_ptr topic = std::make_shared(); + topic->m_topic_name = "rt/chatter"; + topic->type_name = "std_msgs::msg::dds_::String_"; + configuration.builtin_topics.insert(topic); + + // Create DdsRouter entity + DdsRouter router(configuration); + + // Start DdsRouter + router.start(); + + // Stop DDS Router + router.stop(); + + // Let DdsRouter object destroy for the next iteration + } +} + +/** + * Test that creates a DdsRouter with several Participants, one of each kind + * It creates a DdsRouter with a Participant of each kind, + * starts it with an active topic, then stops it and finally destroys it. + * + * This test will fail if it crashes. + */ +TEST(ImplementationsTest, all_implementations) +{ + // TODO: Change to warning when fastdds warning: + // [RTPS_MSG_OUT Warning] Error receiving data: receive_from: A blocking operation was interrupted by a call to WSACancelBlockingCall.: + // A blocking operation was interrupted by a call to WSACancelBlockingCall. - 0000016CEBD18C10 (0000016CEBD17A40) -> + // Function eprosima::fastdds::rtps::UDPChannelResource::Receive + // test::LogChecker test_log_handler(utils::Log::Kind::Error); + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + { + DdsRouterConfiguration configuration; + + // For each Participant Kind set it in configuration + uint16_t participant_number = 0; + for (ParticipantKind kind : VALUES_ParticipantKind) + { + // Add participant + configuration.participants_configurations.insert( + { + kind, + random_participant_configuration(kind, participant_number++) + } + ); + } + + // Create DdsRouter entity + DdsRouter router(configuration); + + // Start DdsRouter + router.start(); + + // Stop DDS Router + router.stop(); + + // Let DdsRouter object destroy for the next iteration + } +} + +/** + * Test that creates a DdsRouter with 3 simple configurations, 2 of them with same id, fails + * + * There is no easy way to test this case as the yaml will be ill-formed with two keys. + * Thus, it must be implemented from a yaml in string format. + */ +TEST(ImplementationsTest, duplicated_ids_negative) +{ + DdsRouterConfiguration configuration; + configuration.participants_configurations.insert( + { + ParticipantKind::simple, + random_participant_configuration(ParticipantKind::simple, 0) + } + ); + configuration.participants_configurations.insert( + { + ParticipantKind::simple, + random_participant_configuration(ParticipantKind::simple, 0) + } + ); + + // Create DdsRouter entity + ASSERT_THROW(DdsRouter router(configuration), eprosima::utils::ConfigurationException); +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From b08c3d0c248eb7c7a974f93313ad8eb34891bff0 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 14:14:40 +0100 Subject: [PATCH 11/38] first refactor of ddsrouter yaml tests Signed-off-by: jparisu --- .../ddspipe_yaml/testing/generate_yaml.hpp} | 65 +++---- ...EntityAddressTest_get_address_defaults.ipp | 8 +- ...etEntityAddressTest_get_address_domain.ipp | 16 +- ...amlGetEntityAddressTest_get_address_ip.ipp | 20 ++- .../YamlGetEntityAddressTest_get_ip.ipp | 8 +- ...amlGetEntityAddressTest_get_ip_version.ipp | 20 ++- .../YamlGetEntityAddressTest_get_port.ipp | 12 +- ...tityAddressTest_get_transport_protocol.ipp | 20 ++- ...YamlGetEntityAddressTest_ip_and_domain.ipp | 14 +- ...coveryServerAddressTest_get_ds_address.ipp | 21 ++- ...verAddressTest_get_ds_address_negative.ipp | 16 +- .../guid/YamlGetEntityGuidPrefixTest.cpp | 56 +++--- .../entities/topic/YamlGetEntityTopicTest.cpp | 112 ++++++------ .../DdsRouterReloadConfiguration.hpp | 4 +- ddsrouter_yaml/README.md | 2 +- .../YamlReaderConfiguration.hpp | 4 +- ..._dummy.cpp => YamlReaderConfiguration.cpp} | 0 ddsrouter_yaml/test/unittest/CMakeLists.txt | 6 +- .../unittest/YamlConfigurationTestUtils.hpp | 165 ------------------ .../unittest/configuration/CMakeLists.txt | 47 ++++- .../YamlGetConfigurationDdsRouterTest.cpp} | 118 ++++++------- .../YamlReaderConfigurationTest.cpp | 52 +++--- .../test/unittest/entities/CMakeLists.txt | 19 -- .../entities/ddsrouter/CMakeLists.txt | 51 ------ .../test/unittest/participants/CMakeLists.txt | 33 ++-- ...lGetCommonParticipantConfigurationTest.cpp | 19 +- ...itialPeersParticipantConfigurationTest.cpp | 26 +-- ...lGetSimpleParticipantConfigurationTest.cpp | 18 +- ...t_get_participant_connection_addresses.ipp | 30 ++-- ...nfigurationTest_get_participant_domain.ipp | 10 +- ...st_get_participant_listening_addresses.ipp | 18 +- ...figurationTest_get_participant_minimum.ipp | 8 +- ...igurationTest_get_participant_negative.ipp | 18 +- ...tConfigurationTest_get_participant_tls.ipp | 4 +- 34 files changed, 431 insertions(+), 609 deletions(-) rename ddspipe_yaml/{test/unittest/YamlConfigurationTestUtils.hpp => include/ddspipe_yaml/testing/generate_yaml.hpp} (69%) rename ddsrouter_yaml/src/cpp/{_dummy.cpp => YamlReaderConfiguration.cpp} (100%) delete mode 100644 ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp rename ddsrouter_yaml/test/unittest/{entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp => configuration/YamlGetConfigurationDdsRouterTest.cpp} (62%) delete mode 100644 ddsrouter_yaml/test/unittest/entities/CMakeLists.txt delete mode 100644 ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt diff --git a/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp b/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp similarity index 69% rename from ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp rename to ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp index b7d2b7fa3..16314ce9b 100644 --- a/ddspipe_yaml/test/unittest/YamlConfigurationTestUtils.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp @@ -31,7 +31,7 @@ namespace eprosima { namespace ddspipe { namespace yaml { -namespace test { +namespace testing { template struct YamlField @@ -42,9 +42,10 @@ struct YamlField } YamlField( - T arg_value) + const T& arg_value, + bool arg_present = true) : value(arg_value) - , present(true) + , present(arg_present) { } @@ -71,9 +72,9 @@ void guid_prefix_to_yaml( std::stringstream ss; ss << guid_prefix; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ss.str()), + YamlField(ss.str()), DISCOVERY_SERVER_GUID_TAG); } @@ -91,43 +92,43 @@ void address_to_yaml( Yaml& yml, const participants::types::Address& address) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(address.ip()), + YamlField(address.ip()), ADDRESS_IP_TAG); - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(address.port()), + YamlField(address.port()), ADDRESS_PORT_TAG); if (address.transport_protocol() == participants::types::TransportProtocol::udp) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_TRANSPORT_UDP_TAG), + YamlField(ADDRESS_TRANSPORT_UDP_TAG), ADDRESS_TRANSPORT_TAG); } else if (address.transport_protocol() == participants::types::TransportProtocol::tcp) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_TRANSPORT_TCP_TAG), + YamlField(ADDRESS_TRANSPORT_TCP_TAG), ADDRESS_TRANSPORT_TAG); } if (address.ip_version() == participants::types::IpVersion::v4) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_IP_VERSION_V4_TAG), + YamlField(ADDRESS_IP_VERSION_V4_TAG), ADDRESS_IP_VERSION_TAG); } else if (address.ip_version() == participants::types::IpVersion::v6) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_IP_VERSION_V6_TAG), + YamlField(ADDRESS_IP_VERSION_V6_TAG), ADDRESS_IP_VERSION_TAG); } } @@ -136,9 +137,9 @@ void participantid_to_yaml( Yaml& yml, const core::types::ParticipantId& id) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(id), + YamlField(id), PARTICIPANT_NAME_TAG); } @@ -146,9 +147,9 @@ void domain_to_yaml( Yaml& yml, const core::types::DomainId& domain) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(domain.domain_id), + YamlField(domain.domain_id), DOMAIN_ID_TAG); } @@ -156,9 +157,9 @@ void repeater_to_yaml( Yaml& yml, const bool& repeater) { - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(repeater), + YamlField(repeater), IS_REPEATER_TAG); } @@ -168,7 +169,7 @@ void repeater_to_yaml( // const TopicQoS& qos) // { // // TODO: extend this for all qos -// test::add_field_to_yaml(yml, test::YamlField(qos.is_reliable()), QOS_RELIABLE_TAG); +// add_field_to_yaml(yml, YamlField(qos.is_reliable()), QOS_RELIABLE_TAG); // } // // Create a yaml Topic object with name, type and key tags @@ -178,12 +179,12 @@ void repeater_to_yaml( // { // if (topic.topic_name.is_set()) // { -// test::add_field_to_yaml(yml, test::YamlField(topic.topic_name), TOPIC_NAME_TAG); +// add_field_to_yaml(yml, YamlField(topic.topic_name), TOPIC_NAME_TAG); // } // if (topic.type_name.is_set()) // { -// test::add_field_to_yaml(yml, test::YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); +// add_field_to_yaml(yml, YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); // } // } @@ -191,15 +192,15 @@ void repeater_to_yaml( // void real_topic_to_yaml( // Yaml& yml, // const DdsTopic& topic, -// const test::YamlField& type, -// const test::YamlField& qos) +// const YamlField& type, +// const YamlField& qos) // { -// test::add_field_to_yaml(yml, test::YamlField(topic.m_topic_name), TOPIC_NAME_TAG); -// test::add_field_to_yaml(yml, test::YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); -// test::add_field_to_yaml(yml, test::YamlField(topic.topic_qos), TOPIC_QOS_TAG); +// add_field_to_yaml(yml, YamlField(topic.m_topic_name), TOPIC_NAME_TAG); +// add_field_to_yaml(yml, YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); +// add_field_to_yaml(yml, YamlField(topic.topic_qos), TOPIC_QOS_TAG); // } -} /* namespace test */ +} /* namespace testing */ } /* namespace yaml */ } /* namespace ddspipe */ } /* namespace eprosima */ diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp index 750c86ac1..83f36cadd 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read an address checking that default values are being used @@ -51,9 +53,9 @@ TEST(YamlGetEntityAddressTest, get_address_defaults) Yaml yml_address; // Add IP with ip-version ipv6 - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField("::1"), + YamlField("::1"), ADDRESS_IP_TAG); Yaml yml; diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp index 6c07c0508..1fef1a1d0 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read an address with domain name @@ -41,15 +43,15 @@ TEST(YamlGetEntityAddressTest, get_address_domain) Yaml yml_address; // Add IP - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField("localhost"), + YamlField("localhost"), ADDRESS_DNS_TAG); // Add IP version - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField(ADDRESS_IP_VERSION_V4_TAG), + YamlField(ADDRESS_IP_VERSION_V4_TAG), ADDRESS_IP_VERSION_TAG); Yaml yml; @@ -68,9 +70,9 @@ TEST(YamlGetEntityAddressTest, get_address_domain) Yaml yml_address; // Add IP - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField("localhost"), + YamlField("localhost"), ADDRESS_DNS_TAG); Yaml yml; diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp index 52e9163a2..29163c5f3 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read an address with IP @@ -47,15 +49,15 @@ TEST(YamlGetEntityAddressTest, get_address_ip) Yaml yml_address; // Add IP - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField(ip), + YamlField(ip), ADDRESS_IP_TAG); // Add IP version - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField(ADDRESS_IP_VERSION_V4_TAG), + YamlField(ADDRESS_IP_VERSION_V4_TAG), ADDRESS_IP_VERSION_TAG); Yaml yml; @@ -83,15 +85,15 @@ TEST(YamlGetEntityAddressTest, get_address_ip) Yaml yml_address; // Add IP - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField(ip), + YamlField(ip), ADDRESS_IP_TAG); // Add IP version - test::add_field_to_yaml( + add_field_to_yaml( yml_address, - test::YamlField(ADDRESS_IP_VERSION_V6_TAG), + YamlField(ADDRESS_IP_VERSION_V6_TAG), ADDRESS_IP_VERSION_TAG); Yaml yml; diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp index 5f52c710e..a92a90f51 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read IP from yaml @@ -47,9 +49,9 @@ TEST(YamlGetEntityAddressTest, get_ip) for (participants::types::IpType ip : ips) { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ip), + YamlField(ip), ADDRESS_IP_TAG); ASSERT_EQ(ip, YamlReader::get(yml, ADDRESS_IP_TAG, LATEST)); diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp index 34e857de5..7adc34c71 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read Transport Protocol from yaml @@ -42,9 +44,9 @@ TEST(YamlGetEntityAddressTest, get_ip_version) // v4 { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_IP_VERSION_V4_TAG), + YamlField(ADDRESS_IP_VERSION_V4_TAG), ADDRESS_IP_VERSION_TAG); participants::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); @@ -55,9 +57,9 @@ TEST(YamlGetEntityAddressTest, get_ip_version) // v6 { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_IP_VERSION_V6_TAG), + YamlField(ADDRESS_IP_VERSION_V6_TAG), ADDRESS_IP_VERSION_TAG); participants::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); @@ -76,9 +78,9 @@ TEST(YamlGetEntityAddressTest, get_ip_version) // Incorrect value name { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField("v7"), + YamlField("v7"), ADDRESS_IP_VERSION_TAG); ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), @@ -88,9 +90,9 @@ TEST(YamlGetEntityAddressTest, get_ip_version) // Incorrect format { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(17), + YamlField(17), ADDRESS_IP_VERSION_TAG); ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp index 4726b0586..96c7d09c5 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read port from yaml @@ -43,9 +45,9 @@ TEST(YamlGetEntityAddressTest, get_port) for (participants::types::PortType port : ports) { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(port), + YamlField(port), ADDRESS_PORT_TAG); ASSERT_EQ(port, YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST)); @@ -64,9 +66,9 @@ TEST(YamlGetEntityAddressTest, get_port) // Incorrect format (string) { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField("P11000"), + YamlField("P11000"), ADDRESS_PORT_TAG); ASSERT_THROW( diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp index 9a2114ae9..e80c385cc 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read Transport Protocol from yaml @@ -41,9 +43,9 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) // UDP { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_TRANSPORT_UDP_TAG), + YamlField(ADDRESS_TRANSPORT_UDP_TAG), ADDRESS_TRANSPORT_TAG); participants::types::TransportProtocol tp = @@ -55,9 +57,9 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) // TCP { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(ADDRESS_TRANSPORT_TCP_TAG), + YamlField(ADDRESS_TRANSPORT_TCP_TAG), ADDRESS_TRANSPORT_TAG); participants::types::TransportProtocol tp = @@ -81,9 +83,9 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) // Incorrect tag { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField("utcp"), + YamlField("utcp"), ADDRESS_TRANSPORT_TAG); ASSERT_THROW( @@ -97,9 +99,9 @@ TEST(YamlGetEntityAddressTest, get_transport_protocol) // Incorrect format { Yaml yml; - test::add_field_to_yaml( + add_field_to_yaml( yml, - test::YamlField(17), + YamlField(17), ADDRESS_TRANSPORT_TAG); ASSERT_THROW( diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp index e733453d5..f98ecbd45 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp @@ -21,11 +21,13 @@ #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test the behaviour when both ip and domain are given. @@ -35,23 +37,23 @@ using namespace eprosima::ddspipe::yaml; TEST(YamlGetEntityAddressTest, ip_and_domain) { // Check a warning is shown - // eprosima::ddspipe::core::testing::TestLogHandler log_handler(utils::Log::Kind::Warning, 1); + // eprosima::ddspipe::core::TestLogHandler log_handler(utils::Log::Kind::Warning, 1); INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Warning, 1, 0); // Set address Yaml yml_address; // Add domain - yaml::test::add_field_to_yaml( + ddspipe::yaml::testing::add_field_to_yaml( yml_address, - yaml::test::YamlField("localhost"), + ddspipe::yaml::testing::YamlField("localhost"), ADDRESS_DNS_TAG); // Add ip participants::types::IpType ip_value = "1.1.1.1"; - yaml::test::add_field_to_yaml( + ddspipe::yaml::testing::add_field_to_yaml( yml_address, - yaml::test::YamlField(ip_value), + ddspipe::yaml::testing::YamlField(ip_value), ADDRESS_IP_TAG); Yaml yml; diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp index f1e4e841e..033cabcf5 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp @@ -20,11 +20,14 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::participants::testing; +using namespace eprosima::ddspipe::yaml::testing; const constexpr unsigned int TEST_ADDRESSES_NUMBER = 5; @@ -42,17 +45,17 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) Yaml yml_ds_address; // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = random_guid_prefix(); Yaml yml_guid; - yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); + guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; // Get random address and add it to yaml - participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); + participants::types::Address address = random_address(); Yaml yml_addresses; Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); @@ -77,9 +80,9 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) Yaml yml_ds_address; // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); + core::types::GuidPrefix guid_prefix = random_guid_prefix(); Yaml yml_guid; - yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); + guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; @@ -90,9 +93,9 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) { // Create new address and add it to already created addresses and to yaml Yaml yml_address; - participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(i); + participants::types::Address address = random_address(i); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); addresses.push_back(address); yml_addresses.push_back(yml_address); diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp index 445d5da7a..4069f3580 100644 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp +++ b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp @@ -19,11 +19,13 @@ #include #include -#include "../../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read a discovery server connection address that fails @@ -56,7 +58,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; @@ -74,7 +76,7 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) // Get random guid prefix and add it to yaml core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; - yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); + guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; Yaml yml; @@ -92,14 +94,14 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; // Guid Prefix error format (inside a sequence) core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; - yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); + guid_prefix_to_yaml(yml_guid, guid_prefix); Yaml yml_guid_aux; yml_guid_aux.push_back(yml_guid); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid_aux; @@ -119,14 +121,14 @@ TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); Yaml yml_addresses; Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses["address1"] = yml_address; yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; // Get random guid prefix and add it to yaml core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); Yaml yml_guid; - yaml::test::guid_prefix_to_yaml(yml_guid, guid_prefix); + guid_prefix_to_yaml(yml_guid, guid_prefix); yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; Yaml yml; diff --git a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp index c38d65757..e71c0366e 100644 --- a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp @@ -19,11 +19,13 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; /** * Test read core::types::GuidPrefix from yaml with explicit guid @@ -44,9 +46,9 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_explicitly) std::string st = "01.0f.00.00.00.00.00.00.00.00.ff.ff"; Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(st), + YamlField(st), DISCOVERY_SERVER_GUID_TAG); Yaml yml; @@ -62,15 +64,15 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_explicitly) std::string st = "01.0f.00.00.00.00.00.00.00.00.ff.ff"; Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(st), + YamlField(st), DISCOVERY_SERVER_GUID_TAG); // This field must be skipped - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(0), + YamlField(0), DISCOVERY_SERVER_ID_TAG); Yaml yml; @@ -96,9 +98,9 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_explicitly) // incorrect format (not string) // { // Yaml yml_gp; - // test::add_field_to_yaml( + // add_field_to_yaml( // yml_gp, - // test::YamlField(false), + // YamlField(false), // DISCOVERY_SERVER_GUID_TAG); // Yaml yml; @@ -115,9 +117,9 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_explicitly) // std::string st = "ffff"; // Yaml yml_gp; - // test::add_field_to_yaml( + // add_field_to_yaml( // yml_gp, - // test::YamlField(st), + // YamlField(st), // DISCOVERY_SERVER_GUID_TAG); // Yaml yml; @@ -148,9 +150,9 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id) for (uint32_t id : ids) { Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(id), + YamlField(id), DISCOVERY_SERVER_ID_TAG); Yaml yml; @@ -166,9 +168,9 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id) { Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField("01.0f.00.00.00.00.00.00.00.00.ff.ff"), + YamlField("01.0f.00.00.00.00.00.00.00.00.ff.ff"), DISCOVERY_SERVER_ID_TAG); Yaml yml; @@ -199,14 +201,14 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id_ros) { Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(id), + YamlField(id), DISCOVERY_SERVER_ID_TAG); - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(true), + YamlField(true), DISCOVERY_SERVER_ID_ROS_TAG); Yaml yml; @@ -226,14 +228,14 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id_ros) { Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(id), + YamlField(id), DISCOVERY_SERVER_ID_TAG); - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(false), + YamlField(false), DISCOVERY_SERVER_ID_ROS_TAG); Yaml yml; @@ -249,14 +251,14 @@ TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id_ros) { Yaml yml_gp; - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField(0), + YamlField(0), DISCOVERY_SERVER_ID_TAG); - test::add_field_to_yaml( + add_field_to_yaml( yml_gp, - test::YamlField("01.0f.00.00.00.00.00.00.00.00.ff.ff"), + YamlField("01.0f.00.00.00.00.00.00.00.00.ff.ff"), DISCOVERY_SERVER_ID_ROS_TAG); Yaml yml; diff --git a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp index e2b472f72..405f19cb7 100644 --- a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp +++ b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp @@ -22,11 +22,13 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; using namespace eprosima::ddspipe::yaml; +using namespace eprosima::ddspipe::core::testing; +using namespace eprosima::ddspipe::yaml::testing; namespace eprosima { namespace ddspipe { @@ -36,34 +38,34 @@ namespace test { // Create a yaml QoS object only with reliability void qos_to_yaml( Yaml& yml, - const test::YamlField& reliable) + const YamlField& reliable) { // TODO: extend this for all qos - test::add_field_to_yaml(yml, reliable, QOS_RELIABLE_TAG); + add_field_to_yaml(yml, reliable, QOS_RELIABLE_TAG); } // Create a yaml Topic object with name, type and key tags void topic_to_yaml( Yaml& yml, - const test::YamlField& name, - const test::YamlField& type, - const test::YamlField& qos) + const YamlField& name, + const YamlField& type, + const YamlField& qos) { - test::add_field_to_yaml(yml, name, TOPIC_NAME_TAG); - test::add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); - test::add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); + add_field_to_yaml(yml, name, TOPIC_NAME_TAG); + add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); + add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); } // Create a yaml DdsTopic object with name, type, key and reliable tags void real_topic_to_yaml( Yaml& yml, - const test::YamlField& name, - const test::YamlField& type, - const test::YamlField& qos) + const YamlField& name, + const YamlField& type, + const YamlField& qos) { - test::add_field_to_yaml(yml, name, TOPIC_NAME_TAG); - test::add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); - test::add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); + add_field_to_yaml(yml, name, TOPIC_NAME_TAG); + add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); + add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); } // Check the values of a real topic are the expected ones @@ -133,19 +135,19 @@ TEST(YamlGetEntityTopicTest, get_real_topic) // Topic Std { Yaml yml_topic; - test::topic_to_yaml( + topic_to_yaml( yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(), - test::YamlField()); + YamlField(name), + YamlField(type), + YamlField(), + YamlField()); Yaml yml; yml["topic"] = yml_topic; core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_topic(topic, name, type, false); + compare_topic(topic, name, type, false); } // Checks that a topic yaml object has been parsed correctly with the topic reliable tag set to true. @@ -153,22 +155,22 @@ TEST(YamlGetEntityTopicTest, get_real_topic) // that no data is lost in the information relay. { Yaml yml_qos; - test::qos_to_yaml(yml_qos, test::YamlField(true)); + qos_to_yaml(yml_qos, YamlField(true)); Yaml yml_topic; - test::real_topic_to_yaml( + real_topic_to_yaml( yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(false), - test::YamlField(yml_qos)); + YamlField(name), + YamlField(type), + YamlField(false), + YamlField(yml_qos)); Yaml yml; yml["topic"] = yml_topic; core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_topic(topic, name, type, true, true); + compare_topic(topic, name, type, true, true); } // Empty @@ -184,12 +186,12 @@ TEST(YamlGetEntityTopicTest, get_real_topic) // Topic without name { Yaml yml_topic; - test::topic_to_yaml( + topic_to_yaml( yml_topic, - test::YamlField(), - test::YamlField(type), - test::YamlField(), - test::YamlField()); + YamlField(), + YamlField(type), + YamlField(), + YamlField()); Yaml yml; yml["topic"] = yml_topic; @@ -201,12 +203,12 @@ TEST(YamlGetEntityTopicTest, get_real_topic) // Topic without type { Yaml yml_topic; - test::topic_to_yaml( + topic_to_yaml( yml_topic, - test::YamlField(name), - test::YamlField(), - test::YamlField(), - test::YamlField()); + YamlField(name), + YamlField(), + YamlField(), + YamlField()); Yaml yml; yml["topic"] = yml_topic; @@ -231,12 +233,12 @@ TEST(YamlGetEntityTopicTest, get_wildcard_topic) // Topic Std { Yaml yml_topic; - test::topic_to_yaml( + topic_to_yaml( yml_topic, - test::YamlField(name), - test::YamlField(type), - test::YamlField(), - test::YamlField()); + YamlField(name), + YamlField(type), + YamlField(), + YamlField()); Yaml yml; yml["topic"] = yml_topic; @@ -244,18 +246,18 @@ TEST(YamlGetEntityTopicTest, get_wildcard_topic) core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_wildcard_topic(topic, name, true, type, false); + compare_wildcard_topic(topic, name, true, type, false); } // Topic without type { Yaml yml_topic; - test::topic_to_yaml( + topic_to_yaml( yml_topic, - test::YamlField(name), - test::YamlField(), - test::YamlField(), - test::YamlField()); + YamlField(name), + YamlField(), + YamlField(), + YamlField()); Yaml yml; yml["topic"] = yml_topic; @@ -263,7 +265,7 @@ TEST(YamlGetEntityTopicTest, get_wildcard_topic) core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", LATEST); - test::compare_wildcard_topic(topic, name, false, "*", false); + compare_wildcard_topic(topic, name, false, "*", false); } } @@ -292,12 +294,12 @@ TEST(YamlGetEntityTopicTest, get_wildcard_topic_negative) // Topic without type { Yaml yml_topic; - test::topic_to_yaml( + topic_to_yaml( yml_topic, - test::YamlField(), - test::YamlField(type), - test::YamlField(), - test::YamlField()); + YamlField(), + YamlField(type), + YamlField(), + YamlField()); Yaml yml; yml["topic"] = yml_topic; diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp index 39541fa14..5fb110f66 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp @@ -52,9 +52,9 @@ struct DdsRouterReloadConfiguration : public ddspipe::core::IConfiguration // VARIABLES ///////////////////////// - std::set> allowlist {}; + std::set> allowlist {}; - std::set> blocklist {}; + std::set> blocklist {}; }; diff --git a/ddsrouter_yaml/README.md b/ddsrouter_yaml/README.md index 08494fa46..888108996 100644 --- a/ddsrouter_yaml/README.md +++ b/ddsrouter_yaml/README.md @@ -24,7 +24,7 @@ Include module is the public API used to configure a DDS Router and to interact ```cpp // START AND STOP DDS ROUTER FROM CONFIGURATION -core::configuration::DdsRouterConfiguration router_configuration; +core::DdsRouterConfiguration router_configuration; // ... populate router_configuration diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp index 025296090..ded0302d1 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReaderConfiguration.hpp @@ -34,10 +34,10 @@ class DDSROUTER_YAML_DllAPI YamlReaderConfiguration { public: - static core::DdsRouterConfiguration load_ddsrouter_configuration( + static ddsrouter::core::DdsRouterConfiguration load_ddsrouter_configuration( const Yaml& yml); - static core::DdsRouterConfiguration load_ddsrouter_configuration_from_file( + static ddsrouter::core::DdsRouterConfiguration load_ddsrouter_configuration_from_file( const std::string& file_path); protected: diff --git a/ddsrouter_yaml/src/cpp/_dummy.cpp b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp similarity index 100% rename from ddsrouter_yaml/src/cpp/_dummy.cpp rename to ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp diff --git a/ddsrouter_yaml/test/unittest/CMakeLists.txt b/ddsrouter_yaml/test/unittest/CMakeLists.txt index 9be0f5513..8341c4bad 100644 --- a/ddsrouter_yaml/test/unittest/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/CMakeLists.txt @@ -16,6 +16,6 @@ # Yaml Tests # ############## -add_subdirectory(configuration) -add_subdirectory(entities) -add_subdirectory(participants) +# TODO uncomment when ready +# add_subdirectory(configuration) +# add_subdirectory(participants) diff --git a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp b/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp deleted file mode 100644 index c52cda98a..000000000 --- a/ddsrouter_yaml/test/unittest/YamlConfigurationTestUtils.hpp +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include -#include -#include - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { -namespace test { - -template -struct YamlField -{ - YamlField() - : present(false) - { - } - - YamlField( - T arg_value) - : value(arg_value) - , present(true) - { - } - - T value; - bool present; -}; - -template -void add_field_to_yaml( - Yaml& yml, - const YamlField& field, - const std::string& tag) -{ - if (field.present) - { - yml[tag] = field.value; - } -} - -void guid_prefix_to_yaml( - Yaml& yml, - const core::types::GuidPrefix& guid_prefix) -{ - std::stringstream ss; - ss << guid_prefix; - - test::add_field_to_yaml( - yml, - test::YamlField(ss.str()), - DISCOVERY_SERVER_GUID_TAG); -} - -void discovery_server_guid_prefix_to_yaml( - Yaml& yml, - const core::types::GuidPrefix& guid_prefix) -{ - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - - yml[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; -} - -void address_to_yaml( - Yaml& yml, - const participants::types::Address& address) -{ - test::add_field_to_yaml( - yml, - test::YamlField(address.ip()), - ADDRESS_IP_TAG); - - test::add_field_to_yaml( - yml, - test::YamlField(address.port()), - ADDRESS_PORT_TAG); - - if (address.transport_protocol() == participants::types::TransportProtocol::udp) - { - test::add_field_to_yaml( - yml, - test::YamlField(ADDRESS_TRANSPORT_UDP_TAG), - ADDRESS_TRANSPORT_TAG); - } - else if (address.transport_protocol() == participants::types::TransportProtocol::tcp) - { - test::add_field_to_yaml( - yml, - test::YamlField(ADDRESS_TRANSPORT_TCP_TAG), - ADDRESS_TRANSPORT_TAG); - } - - if (address.ip_version() == participants::types::IpVersion::v4) - { - test::add_field_to_yaml( - yml, - test::YamlField(ADDRESS_IP_VERSION_V4_TAG), - ADDRESS_IP_VERSION_TAG); - } - else if (address.ip_version() == participants::types::IpVersion::v6) - { - test::add_field_to_yaml( - yml, - test::YamlField(ADDRESS_IP_VERSION_V6_TAG), - ADDRESS_IP_VERSION_TAG); - } -} - -void participantid_to_yaml( - Yaml& yml, - const core::types::ParticipantId& id) -{ - test::add_field_to_yaml( - yml, - test::YamlField(id), - PARTICIPANT_NAME_TAG); -} - -void domain_to_yaml( - Yaml& yml, - const core::types::DomainId& domain) -{ - test::add_field_to_yaml( - yml, - test::YamlField(domain.domain_id()), - DOMAIN_ID_TAG); -} - -void repeater_to_yaml( - Yaml& yml, - const bool& repeater) -{ - test::add_field_to_yaml( - yml, - test::YamlField(repeater), - IS_REPEATER_TAG); -} - -} /* namespace test */ -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt b/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt index 010658954..092033df7 100644 --- a/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt @@ -13,17 +13,14 @@ # limitations under the License. ##################################### -# Yaml DDSRouter Configuration Test # +# Yaml DdsRouter Configuration Test # ##################################### set(TEST_NAME YamlReaderConfigurationTest) set(TEST_SOURCES YamlReaderConfigurationTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp ) set(TEST_LIST @@ -40,6 +37,46 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils + ddspipe_core + ddspipe_participants + ddspipe_yaml + ddsrouter_core + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}") + +##################################### +# Yaml DdsRouter Configuration Test # +##################################### + +set(TEST_NAME YamlGetConfigurationDdsRouterTest) + +set(TEST_SOURCES + YamlGetConfigurationDdsRouterTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ) + +set(TEST_LIST + get_ddsrouter_configuration_trivial + get_ddsrouter_configuration_ros_case + + get_ddsrouter_configuration_trivial_v1 + get_ddsrouter_configuration_builtin_v1 + get_ddsrouter_configuration_discovery_server_v1 + ) + +set(TEST_EXTRA_LIBRARIES + yaml-cpp + fastcdr + fastrtps + cpp_utils + ddspipe_core + ddspipe_participants + ddspipe_yaml ddsrouter_core ) diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp similarity index 62% rename from ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp rename to ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp index 72b3db2b4..6747075bb 100644 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp @@ -17,21 +17,19 @@ #include #include -#include -#include +#include +#include #include #include using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test load a whole DDS Router Configuration from yaml node. * Only set two echo participants. */ -TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial) +TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_trivial) { const char* yml_str = R"( @@ -46,27 +44,27 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial) Yaml yml = YAML::Load(yml_str); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReader::get(yml, LATEST); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::LATEST); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, std::set>()); // Check Participant configurations - std::set> + std::set> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 2u); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind, core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::echo); } } @@ -74,7 +72,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial) * Test load a whole DDS Router Configuration from yaml node. * Add 3 different Participants of kind Simple and one builtin topic. */ -TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) +TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_ros_case) { const char* yml_str = R"( @@ -97,35 +95,35 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) Yaml yml = YAML::Load(yml_str); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReader::get(yml, V_2_0); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_2_0); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topic lists are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics; + std::set> builtin_result = configuration_result.builtin_topics; ASSERT_EQ(builtin_result.size(), 1u); - std::shared_ptr topic_result = (*builtin_result.begin()); + std::shared_ptr topic_result = (*builtin_result.begin()); ASSERT_EQ(topic_result->topic_name, "rt/chatter"); ASSERT_EQ(topic_result->type_name, "std_msgs::msg::dds_::String_"); ASSERT_EQ(topic_result->keyed, false); ASSERT_EQ(topic_result->topic_qos.get_reference().is_reliable(), false); // Check Participant configurations - std::set> + std::set> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 3u); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind, core::types::ParticipantKind::simple_rtps); + ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::simple_rtps); } } @@ -133,7 +131,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) * Test load a whole DDS Router Configuration from yaml node. * Only set two echo participants. */ -TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial_v1) +TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_trivial_v1) { const char* yml_str = R"( @@ -147,27 +145,27 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial_v1) Yaml yml = YAML::Load(yml_str); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReader::get(yml, V_1_0); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_1_0); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, std::set>()); // Check Participant configurations - std::set> + std::set> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 2u); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind, core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::echo); } } @@ -175,7 +173,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial_v1) * Test load a whole DDS Router Configuration from yaml node. * Only set two echo participants. */ -TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) +TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_builtin_v1) { const char* yml_str = R"( @@ -194,37 +192,37 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) Yaml yml = YAML::Load(yml_str); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReader::get(yml, V_1_0); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_1_0); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check block Topics are empty - ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); // Check allowlist has 2 topics - std::set> allowlist_result = configuration_result.allowlist; + std::set> allowlist_result = configuration_result.allowlist; ASSERT_EQ(allowlist_result.size(), 2u); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics; + std::set> builtin_result = configuration_result.builtin_topics; ASSERT_EQ(builtin_result.size(), 1u); - std::shared_ptr topic_result = (*builtin_result.begin()); + std::shared_ptr topic_result = (*builtin_result.begin()); ASSERT_EQ(topic_result->topic_name, "topic1"); ASSERT_EQ(topic_result->type_name, "type1"); ASSERT_EQ(topic_result->keyed, false); // Check Participant configurations - std::set> + std::set> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 2u); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind, core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::echo); } } @@ -232,7 +230,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) * Test load a whole DDS Router Configuration from yaml node. * Only set two echo participants. */ -TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_server_v1) +TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_discovery_server_v1) { const char* yml_str = R"( @@ -253,55 +251,55 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se Yaml yml = YAML::Load(yml_str); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReader::get(yml, V_1_0); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_1_0); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, std::set>()); // Check Participant configurations - std::set> + std::set> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 2u); - for (std::shared_ptr participant : participant_configurations) + for (std::shared_ptr participant : participant_configurations) { // If it is not the discovery server participant, continue - if (!(participant->kind == core::types::ParticipantKind::local_discovery_server)) + if (!(participant->id() == "participant1")) { continue; } else { // Check the DS partipant is correct - std::shared_ptr ds_participant = - std::dynamic_pointer_cast(participant); + std::shared_ptr ds_participant = + std::dynamic_pointer_cast(participant); // Check Name - ASSERT_EQ(ds_participant->id, core::types::ParticipantId("participant2")); + ASSERT_EQ(ds_participant->id, ddspipe::core::types::ParticipantId("participant2")); // Check GuidPrefix ASSERT_EQ( ds_participant->discovery_server_guid_prefix, - core::types::GuidPrefix(true, 3u)); + ddspipe::core::types::GuidPrefix(true, 3u)); // Check Connection addresses ASSERT_EQ( ds_participant->connection_addresses.size(), 1u); - participants::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses.begin(); + ddspipe::participants::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses.begin(); ASSERT_EQ( address, - (participants::types::DiscoveryServerConnectionAddress( - core::types::GuidPrefix("01.0f.00.00.00.00.00.00.00.00.00.00"), - {participants::types::Address("127.0.0.1", 3333, 3333, participants::types::Address::default_transport_protocol())} + (ddspipe::participants::types::DiscoveryServerConnectionAddress( + ddspipe::core::types::GuidPrefix("01.0f.00.00.00.00.00.00.00.00.00.00"), + {ddspipe::participants::types::Address("127.0.0.1", 3333, 3333, ddspipe::participants::types::Address::default_transport_protocol())} )) ); } diff --git a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index 13f3301df..341259448 100644 --- a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -17,14 +17,12 @@ #include #include -#include +#include #include -#include "../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test load a whole DDS Router Configuration from yaml node for v1.0 of yaml. @@ -51,11 +49,11 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v1) Yaml yml = YAML::Load(yml_configuration); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)) << error_msg; } } @@ -105,11 +103,11 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v2) Yaml yml = YAML::Load(yml_configuration); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)) << error_msg; } } @@ -137,11 +135,11 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_no_version) Yaml yml = YAML::Load(yml_configuration); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)) << error_msg; } @@ -159,11 +157,11 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_no_version) Yaml yml = YAML::Load(yml_configuration); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is not valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_FALSE(configuration_result.is_valid(error_msg)) << error_msg; } } @@ -195,8 +193,8 @@ TEST(YamlReaderConfigurationTest, version_negative_cases) // Load configuration ASSERT_THROW( - YamlReaderConfiguration::load_ddsrouter_configuration(yml), - eprosima::utils::ConfigurationException); + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml), + utils::ConfigurationException); } // not correct version: specify v1.0 and is v2.0 @@ -215,11 +213,11 @@ TEST(YamlReaderConfigurationTest, version_negative_cases) Yaml yml = YAML::Load(yml_configuration); // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is not valid - eprosima::utils::Formatter error_msg; + utils::Formatter error_msg; ASSERT_FALSE(configuration_result.is_valid(error_msg)) << error_msg; } @@ -239,8 +237,8 @@ TEST(YamlReaderConfigurationTest, version_negative_cases) // Load configuration ASSERT_THROW( - YamlReaderConfiguration::load_ddsrouter_configuration(yml), - eprosima::utils::ConfigurationException); + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml), + utils::ConfigurationException); } } @@ -273,8 +271,8 @@ TEST(YamlReaderConfigurationTest, number_of_threads) yml[SPECS_TAG] = yml_specs; // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check threads are correct ASSERT_EQ(test_case, configuration_result.advanced_options.number_of_threads); @@ -310,8 +308,8 @@ TEST(YamlReaderConfigurationTest, max_history_depth) yml[SPECS_TAG] = yml_specs; // Load configuration - core::configuration::DDSRouterConfiguration configuration_result = - YamlReaderConfiguration::load_ddsrouter_configuration(yml); + ddsrouter::core::DdsRouterConfiguration configuration_result = + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check max history depth is correct ASSERT_EQ(test_case, configuration_result.advanced_options.max_history_depth); diff --git a/ddsrouter_yaml/test/unittest/entities/CMakeLists.txt b/ddsrouter_yaml/test/unittest/entities/CMakeLists.txt deleted file mode 100644 index 849a06283..000000000 --- a/ddsrouter_yaml/test/unittest/entities/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2022 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. - -######################### -# Yaml GetEntities Test # -######################### - -add_subdirectory(ddsrouter) diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt b/ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt deleted file mode 100644 index 3f9ce6afe..000000000 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2022 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. - -##################################### -# Yaml DDSRouter Configuration Test # -##################################### - -set(TEST_NAME YamlGetConfigurationDDSRouterTest) - -set(TEST_SOURCES - YamlGetConfigurationDDSRouterTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - - ) - -set(TEST_LIST - get_ddsrouter_configuration_trivial - get_ddsrouter_configuration_ros_case - - get_ddsrouter_configuration_trivial_v1 - get_ddsrouter_configuration_builtin_v1 - get_ddsrouter_configuration_discovery_server_v1 - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastrtps - cpp_utils - - ddsrouter_core - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt b/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt index c763f9d73..aca566399 100644 --- a/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt @@ -19,10 +19,7 @@ set(TEST_NAME YamlGetCommonParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp YamlGetCommonParticipantConfigurationTest.cpp ) @@ -36,6 +33,9 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils + ddspipe_core + ddspipe_participants + ddspipe_yaml ddsrouter_core ) @@ -52,10 +52,7 @@ add_unittest_executable( set(TEST_NAME YamlGetSimpleParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp YamlGetSimpleParticipantConfigurationTest.cpp ) @@ -69,7 +66,9 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils - + ddspipe_core + ddspipe_participants + ddspipe_yaml ddsrouter_core ) @@ -86,10 +85,7 @@ add_unittest_executable( set(TEST_NAME YamlGetDiscoveryServerParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp YamlGetDiscoveryServerParticipantConfigurationTest.cpp ) @@ -112,6 +108,9 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils + ddspipe_core + ddspipe_participants + ddspipe_yaml ddsrouter_core ) @@ -128,10 +127,7 @@ add_unittest_executable( set(TEST_NAME YamlGetInitialPeersParticipantConfigurationTest) set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp YamlGetInitialPeersParticipantConfigurationTest.cpp ) @@ -145,6 +141,9 @@ set(TEST_EXTRA_LIBRARIES fastcdr fastrtps cpp_utils + ddspipe_core + ddspipe_participants + ddspipe_yaml ddsrouter_core ) diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index 34b382aea..070bd634e 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -16,11 +16,10 @@ #include #include - #include #include -#include "../YamlConfigurationTestUtils.hpp" +#include constexpr const uint32_t TEST_ITERATION_MAX = 5; @@ -51,8 +50,8 @@ TEST(YamlGetCommonParticipantConfigurationTest, get_participant) yml["participant"] = yml_participant; // Read Yaml - core::configuration::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST); + core::ParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result ASSERT_EQ(id, result.id); @@ -80,8 +79,8 @@ TEST(YamlGetCommonParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::configuration::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::ParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -97,8 +96,8 @@ TEST(YamlGetCommonParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::configuration::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::ParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -114,8 +113,8 @@ TEST(YamlGetCommonParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::configuration::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::ParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp index 50d77373f..f85266139 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp @@ -16,13 +16,13 @@ #include #include -#include +#include #include #include #include -#include "../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -52,8 +52,8 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_minimum) yml["participant"] = yml_participant; // Read Yaml - core::configuration::InitialPeersParticipantConfiguration result = - YamlReader::get( + core::InitialPeersParticipantConfiguration result = + YamlReader::get( yml, "participant", LATEST); @@ -67,7 +67,7 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_minimum) ASSERT_EQ(result.listening_addresses.size(), 0u); ASSERT_FALSE(result.tls_configuration.is_active()); ASSERT_EQ( - core::configuration::InitialPeersParticipantConfiguration().domain, + core::InitialPeersParticipantConfiguration().domain, result.domain); } } @@ -101,8 +101,8 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::InitialPeersParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -124,8 +124,8 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::InitialPeersParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -147,8 +147,8 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::InitialPeersParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -171,8 +171,8 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) // Get configuration object from yaml and expect fail ASSERT_THROW( - core::configuration::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::InitialPeersParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index cf0727ae0..70a85c46b 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -21,7 +21,7 @@ #include #include -#include "../YamlConfigurationTestUtils.hpp" +#include constexpr const uint32_t TEST_ITERATION_MAX = 5; @@ -56,8 +56,8 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant) yml["participant"] = yml_participant; // Read Yaml - core::configuration::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::SimpleParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -92,8 +92,8 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::configuration::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::SimpleParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -108,8 +108,8 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::configuration::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::SimpleParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -123,8 +123,8 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::configuration::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::SimpleParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index 87ef92f50..5f5521e17 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -21,7 +21,7 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -77,8 +77,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -126,8 +126,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -187,8 +187,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -235,8 +235,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect // Get configuration object from yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -269,8 +269,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect // Get configuration object from yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -308,8 +308,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect // Get configuration object from yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -343,8 +343,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect // Get configuration object from yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index 65fa78664..7e7608327 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -21,7 +21,7 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -59,8 +59,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -84,8 +84,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) // Get configuration object from yaml and expect fail ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index e1d9537ef..e36145655 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -21,7 +21,7 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -65,8 +65,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -103,8 +103,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni yml["participant"] = yml_participant; // Get configuration object from yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST); // Check result @@ -142,8 +142,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni // Get configuration object from yaml and expect fail ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -167,8 +167,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni // Get configuration object from yaml and expect fail ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index 2efeb004d..9fed08aa2 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -21,7 +21,7 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -55,8 +55,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_minimum yml["participant"] = yml_participant; // Read Yaml - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get( + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get( yml, "participant", LATEST); @@ -71,7 +71,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_minimum ASSERT_EQ(result.listening_addresses.size(), 0u); ASSERT_FALSE(result.tls_configuration.is_active()); ASSERT_EQ( - core::configuration::DiscoveryServerParticipantConfiguration().domain, + core::DiscoveryServerParticipantConfiguration().domain, result.domain); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp index 4d9eb8303..984b9a746 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp @@ -21,7 +21,7 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -51,8 +51,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ // Read Yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -67,8 +67,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ // Read Yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -82,8 +82,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ // Read Yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } @@ -97,8 +97,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ // Read Yaml ASSERT_THROW( - core::configuration::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + core::DiscoveryServerParticipantConfiguration result = + YamlReader::get(yml, "participant", LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index 223cc7589..d86fa6300 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -21,7 +21,7 @@ #include #include -#include "../../YamlConfigurationTestUtils.hpp" +#include using namespace eprosima; using namespace eprosima::ddspipe; @@ -149,7 +149,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_inact // No TLS tag insertion // Get configuration object from yaml - auto ds_participant_cfg = YamlReader::get(yml, + auto ds_participant_cfg = YamlReader::get(yml, "participant", LATEST); From bfbed90f797b6c4b4a7f6f0ada55a80f41dd42af Mon Sep 17 00:00:00 2001 From: RaulSanchez Date: Tue, 14 Feb 2023 12:55:46 +0100 Subject: [PATCH 12/38] Add ddsrouter_core implementation Signed-off-by: RaulSanchez --- .../ddspipe_core/dynamic/AllowedTopicList.hpp | 2 +- .../src/cpp/dynamic/AllowedTopicList.cpp | 4 + .../configuration/DdsRouterConfiguration.hpp | 2 +- .../DdsRouterReloadConfiguration.hpp | 1 + .../include/ddsrouter_core/core/DdsRouter.hpp | 18 +++ .../ddsrouter_core/types/ParticipantKind.hpp | 4 +- ddsrouter_core/src/cpp/_dummy.cpp | 8 - .../configuration/DdsRouterConfiguration.cpp | 137 ++++++++++++++++ .../DdsRouterReloadConfiguration.cpp | 44 ++++++ .../cpp/configuration/SpecsConfiguration.cpp | 48 ++++++ ddsrouter_core/src/cpp/core/DdsRouter.cpp | 127 +++++++++++++++ .../src/cpp/core/ParticipantFactory.cpp | 148 ++++++++++++++++++ 12 files changed, 531 insertions(+), 12 deletions(-) delete mode 100644 ddsrouter_core/src/cpp/_dummy.cpp create mode 100644 ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp create mode 100644 ddsrouter_core/src/cpp/configuration/DdsRouterReloadConfiguration.cpp create mode 100644 ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp create mode 100644 ddsrouter_core/src/cpp/core/DdsRouter.cpp create mode 100644 ddsrouter_core/src/cpp/core/ParticipantFactory.cpp diff --git a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp index cdeda252b..ccf35d103 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp @@ -44,7 +44,7 @@ class AllowedTopicList public: //! Default constructor with empty lists - AllowedTopicList() = default; + AllowedTopicList(); //! Constructor by initialization lists AllowedTopicList( diff --git a/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp b/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp index 43b7c3477..62ef8a3d7 100644 --- a/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp +++ b/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp @@ -27,6 +27,10 @@ namespace eprosima { namespace ddspipe { namespace core { +AllowedTopicList::AllowedTopicList() +{ +} + // TODO: Add logs AllowedTopicList::AllowedTopicList( const std::set>& allowlist, diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp index 65544931d..ab7d7f921 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp @@ -80,7 +80,7 @@ struct DdsRouterConfiguration : public DdsRouterReloadConfiguration //! Auxiliar method to validate that class type of the participants are compatible with their kinds. static bool check_correct_configuration_object_( - const std::shared_ptr configuration); + const std::pair> configuration); }; diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp index 5fb110f66..86cfeb073 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterReloadConfiguration.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp index 520bbf723..fa762e2b3 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -102,8 +103,25 @@ class DdsRouter protected: + /** + * @brief Load allowed topics from configuration + * + * @throw \c ConfigurationException in case the yaml inside allowlist is not well-formed + */ + void init_allowed_topics_(); + + /** + * @brief Create participants and add them to the participants database + * + * @throw \c ConfigurationException in case a Participant is not well configured (e.g. No kind) + * @throw \c InitializationException in case \c IParticipants creation fails. + */ + void init_participants_(); + DdsRouterConfiguration configuration_; + std::unique_ptr ddspipe_; + std::shared_ptr allowed_topics_; std::shared_ptr discovery_database_; diff --git a/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp b/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp index 4ab5ab09a..620ab1321 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp @@ -31,8 +31,8 @@ ENUMERATION_BUILDER( ); eProsima_ENUMERATION_BUILDER( - ParticipantKindBuilder , - ParticipantKind , + ParticipantKindBuilder, + ParticipantKind, { { ParticipantKind::simple COMMA { "local" COMMA "simple" } } COMMA { ParticipantKind::initial_peers COMMA {"wan" COMMA "router" COMMA "initial-peers"} } COMMA diff --git a/ddsrouter_core/src/cpp/_dummy.cpp b/ddsrouter_core/src/cpp/_dummy.cpp deleted file mode 100644 index d353d8800..000000000 --- a/ddsrouter_core/src/cpp/_dummy.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include diff --git a/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp new file mode 100644 index 000000000..3f1634be3 --- /dev/null +++ b/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp @@ -0,0 +1,137 @@ +// 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 DdsRouterConfiguration.cpp + * + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { + +void DdsRouterConfiguration::reload( + const DdsRouterReloadConfiguration& new_configuration) +{ + this->allowlist = new_configuration.allowlist; + this->blocklist = new_configuration.blocklist; +} + +bool DdsRouterConfiguration::is_valid( + utils::Formatter& error_msg) const noexcept +{ + // Check Allow list topics + if (!DdsRouterReloadConfiguration::is_valid(error_msg)) + { + return false; + } + + // Check there are at least two participants + if (participants_configurations.size() < 1) + { + error_msg << "There must be at least 1 participant."; + return false; + } + + // Check Participant Configurations AND + // check Participant Configuration IDs are not repeated + std::set ids; + for (std::pair> + configuration : participants_configurations) + { + // Check configuration is not null + if (!configuration.second) + { + logDevError(DDSROUTER_CONFIGURATION, "Invalid ptr in participant configurations."); + error_msg << "nullptr ParticipantConfiguration in participant configurations. "; + return false; + } + + // Check configuration is valid + if (!configuration.second->is_valid(error_msg)) + { + error_msg << "Error in Participant " << configuration.second->id << ". "; + return false; + } + + // Check that the configuration is of type required + if (!check_correct_configuration_object_(configuration)) + { + error_msg << "Participant " << configuration.second->id << " is not of correct Configuration class. "; + return false; + } + + // Store every id in a set to see if there are repetitions + ids.insert(configuration.second->id); + } + + // If the number of ids are not equal the number of configurations, is because they are repeated + if (ids.size() != participants_configurations.size()) + { + error_msg << "Participant ids are not unique. "; + return false; + } + + return true; +} + +template +bool check_correct_configuration_object_by_type_( + const std::shared_ptr configuration) +{ + return nullptr != std::dynamic_pointer_cast(configuration); +} + +bool DdsRouterConfiguration::check_correct_configuration_object_( + const std::pair> configuration) +{ + switch (configuration.first) + { + case types::ParticipantKind::simple: + return check_correct_configuration_object_by_type_( + configuration.second); + + case types::ParticipantKind::discovery_server: + return check_correct_configuration_object_by_type_( + configuration.second); + + case types::ParticipantKind::initial_peers: + return check_correct_configuration_object_by_type_( + configuration.second); + + case types::ParticipantKind::echo: + return check_correct_configuration_object_by_type_( + configuration.second); + + default: + return check_correct_configuration_object_by_type_( + configuration.second); + } +} + +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/DdsRouterReloadConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DdsRouterReloadConfiguration.cpp new file mode 100644 index 000000000..a25f44e99 --- /dev/null +++ b/ddsrouter_core/src/cpp/configuration/DdsRouterReloadConfiguration.cpp @@ -0,0 +1,44 @@ +// 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 DdsRouterReloadConfiguration.cpp + * + */ + +#include + +#include +#include +#include + +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { + +bool DdsRouterReloadConfiguration::is_valid( + utils::Formatter& error_msg) const noexcept +{ + // utils::Heritable objects cannot initialize its internal pointer to nullptr. + // Therfore, the previous comparison that checked that the topic (shared_ptr) is not nullptr does not apply anymore. + return true; +} + +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp new file mode 100644 index 000000000..22f93e7c2 --- /dev/null +++ b/ddsrouter_core/src/cpp/configuration/SpecsConfiguration.cpp @@ -0,0 +1,48 @@ +// 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 SpecsConfiguration.cpp + * + */ + +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { + +bool SpecsConfiguration::is_valid( + utils::Formatter& error_msg) const noexcept +{ + if (number_of_threads < 1) + { + error_msg << "Number of Threads must be at least 1."; + return false; + } + + if (max_history_depth == 0) + { + logWarning(DDSROUTER_SPECS, "Using non limited histories could lead to memory exhaustion in long executions."); + } + + return true; +} + +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp new file mode 100644 index 000000000..85dec2d8d --- /dev/null +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -0,0 +1,127 @@ +// 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 DdsRouter.cpp + * + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { + +DdsRouter::DdsRouter( + const DdsRouterConfiguration& configuration) + : discovery_database_(new ddspipe::core::DiscoveryDatabase()) + , payload_pool_(new ddspipe::core::FastPayloadPool()) + , participants_database_(new ddspipe::core::ParticipantsDatabase()) + , configuration_(configuration) + , thread_pool_(std::make_shared(configuration_.advanced_options.number_of_threads)) +{ + logDebug(DDSROUTER, "Creating DDS Router."); + + // Check that the configuration is correct + utils::Formatter error_msg; + if (!configuration_.is_valid(error_msg)) + { + throw utils::ConfigurationException( + utils::Formatter() << + "Configuration for DDS Router is invalid: " << error_msg); + } + + // Set default value for history + ddspipe::core::types::TopicQoS::default_history_depth.store( + configuration_.advanced_options.max_history_depth); + + // Init topic allowed + init_allowed_topics_(); + // Load Participants + init_participants_(); + + ddspipe_ = std::unique_ptr(new ddspipe::core::DdsPipe( + allowed_topics_, + discovery_database_, + payload_pool_, + participants_database_, + thread_pool_)); + + logDebug(DDSROUTER, "DDS Router created."); +} + +void DdsRouter::init_allowed_topics_() +{ + allowed_topics_ = std::make_shared( + configuration_.allowlist, + configuration_.blocklist); + + logInfo(DDSROUTER, "DDS Router configured with allowed topics: " << allowed_topics_); +} + +void DdsRouter::init_participants_() +{ + for (std::pair> participant_config : + configuration_.participants_configurations) + { + std::shared_ptr new_participant; + + // Create participant + // This should not be in try catch case as if it fails the whole init must fail + new_participant = + participant_factory_.create_participant( + participant_config.first, + participant_config.second, + payload_pool_, + discovery_database_); + + // create_participant should throw an exception in fail, never return nullptr + if (!new_participant) + { + // Failed to create participant + throw utils::InitializationException(utils::Formatter() + << "Failed to create creating Participant " << participant_config.second->id); + } + + logInfo(DDSROUTER, "Participant created with id: " << new_participant->id() + << " and kind " << participant_config.first << "."); + + // Add this participant to the database. If it is repeated it will cause an exception + try + { + participants_database_->add_participant( + new_participant->id(), + new_participant); + } + catch (const utils::InconsistencyException& ) + { + throw utils::ConfigurationException(utils::Formatter() + << "Participant ids must be unique. The id " << new_participant->id() << " is duplicated."); + } + } +} + +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp new file mode 100644 index 000000000..070fae89b --- /dev/null +++ b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp @@ -0,0 +1,148 @@ +// 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 ParticipantFactory.cpp + * + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace core { + +std::shared_ptr ParticipantFactory::create_participant( + const types::ParticipantKind& kind, + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) +{ + // Create a new Participant depending on the ParticipantKind specified by the configuration + switch (kind) + { + case ParticipantKind::echo: + // Echo Participant + { + std::shared_ptr conf_ = + std::dynamic_pointer_cast( + participant_configuration); + if (!conf_) + { + throw utils::ConfigurationException( + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << + " is not for Participant Kind: " << participant_configuration->kind); + } + + return std::make_shared ( + conf_, + discovery_database); + } + + case ParticipantKind::simple: + // Simple RTPS Participant + { + std::shared_ptr conf_ = + std::dynamic_pointer_cast( + participant_configuration); + if (!conf_) + { + throw utils::ConfigurationException( + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << + " is not for Participant Kind: " << participant_configuration->kind); + } + + auto participant = std::make_shared ( + conf_, + payload_pool, + discovery_database); + + // Initialize Participant (this is needed as Participant is not RAII because of Listener) + participant->init(); + + return participant; + } + + case ParticipantKind::discovery_server: + // Discovery Server RTPS Participant + { + std::shared_ptr conf_ = + std::dynamic_pointer_cast( + participant_configuration); + // TMP: Until Transparency TopicQoS module is available + if (!conf_) + { + throw utils::ConfigurationException( + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << + participant_configuration->kind); + } + + auto participant = std::make_shared ( + conf_, + payload_pool, + discovery_database); + + // Initialize Participant (this is needed as Participant is not RAII because of Listener) + participant->init(); + + return participant; + } + + case ParticipantKind::initial_peers: + // Initial Peers RTPS Participant + { + std::shared_ptr conf_ = + std::dynamic_pointer_cast( + participant_configuration); + // TMP: Until Transparency TopicQoS module is available + if (!conf_) + { + throw utils::ConfigurationException( + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << + participant_configuration->kind); + } + + auto participant = std::make_shared ( + conf_, + payload_pool, + discovery_database); + + // Initialize Participant (this is needed as Participant is not RAII because of Listener) + participant->init(); + + return participant; + } + + default: + // This should not happen as every kind must be in the switch + utils::tsnh( + utils::Formatter() << "Value of ParticipantKind out of enumeration."); + return nullptr; // Unreachable code + } +} + +} /* namespace core */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ From e29b355af539e918e28cb7cc2e14eb16377d26e6 Mon Sep 17 00:00:00 2001 From: RaulSanchez Date: Tue, 14 Feb 2023 15:20:07 +0100 Subject: [PATCH 13/38] Add ddsrouter_yaml source code Signed-off-by: RaulSanchez --- .../include/ddsrouter_core/core/DdsRouter.hpp | 1 + ddsrouter_core/src/cpp/core/DdsRouter.cpp | 40 ++++++++ .../src/cpp/core/ParticipantFactory.cpp | 55 ++++++----- ddsrouter_yaml/CMakeLists.txt | 6 +- .../src/cpp/YamlReaderConfiguration.cpp | 98 +++++++++++++++++-- 5 files changed, 166 insertions(+), 34 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp index fa762e2b3..481556808 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp index 85dec2d8d..40f537abf 100644 --- a/ddsrouter_core/src/cpp/core/DdsRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -27,6 +27,7 @@ #include #include +#include #include namespace eprosima { @@ -122,6 +123,45 @@ void DdsRouter::init_participants_() } } +utils::ReturnCode DdsRouter::reload_configuration( + const DdsRouterReloadConfiguration& new_configuration) +{ + // Check that the configuration is correct + utils::Formatter error_msg; + if (!new_configuration.is_valid(error_msg)) + { + throw utils::ConfigurationException( + utils::Formatter() << + "Configuration for Reload DDS Router is invalid: " << error_msg); + } + + return ddspipe_->reload_allowed_topics(std::make_shared( + configuration_.allowlist, + configuration_.blocklist)); +} + +utils::ReturnCode DdsRouter::start() noexcept +{ + utils::ReturnCode ret = ddspipe_->start(); + if (ret == utils::ReturnCode::RETCODE_OK) + { + logInfo(DDSROUTER, "Starting DDS Router."); + } + + return ret; +} + +utils::ReturnCode DdsRouter::stop() noexcept +{ + utils::ReturnCode ret = ddspipe_->stop(); + if (ret == utils::ReturnCode::RETCODE_OK) + { + logInfo(DDSROUTER, "Stopping DDS Router."); + } + + return ret; +} + } /* namespace core */ } /* namespace ddsrouter */ } /* namespace eprosima */ diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp index 070fae89b..cbe9979b7 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp +++ b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp @@ -18,63 +18,70 @@ */ #include +#include #include +#include #include #include +#include +#include +#include #include +#include #include #include #include #include #include +#include namespace eprosima { namespace ddsrouter { namespace core { -std::shared_ptr ParticipantFactory::create_participant( +std::shared_ptr ParticipantFactory::create_participant( const types::ParticipantKind& kind, - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database) + const std::shared_ptr& participant_configuration, + const std::shared_ptr& payload_pool, + const std::shared_ptr& discovery_database) { // Create a new Participant depending on the ParticipantKind specified by the configuration switch (kind) { - case ParticipantKind::echo: + case types::ParticipantKind::echo: // Echo Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << participant_configuration->kind); + " is not for Participant Kind: " << kind); } - return std::make_shared ( + return std::make_shared ( conf_, discovery_database); } - case ParticipantKind::simple: + case types::ParticipantKind::simple: // Simple RTPS Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << participant_configuration->kind); + " is not for Participant Kind: " << kind); } - auto participant = std::make_shared ( + auto participant = std::make_shared ( conf_, payload_pool, discovery_database); @@ -85,21 +92,21 @@ std::shared_ptr ParticipantFactory::create_participant( return participant; } - case ParticipantKind::discovery_server: + case types::ParticipantKind::discovery_server: // Discovery Server RTPS Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); // TMP: Until Transparency TopicQoS module is available if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << - participant_configuration->kind); + kind); } - auto participant = std::make_shared ( + auto participant = std::make_shared ( conf_, payload_pool, discovery_database); @@ -110,21 +117,21 @@ std::shared_ptr ParticipantFactory::create_participant( return participant; } - case ParticipantKind::initial_peers: + case types::ParticipantKind::initial_peers: // Initial Peers RTPS Participant { - std::shared_ptr conf_ = - std::dynamic_pointer_cast( + std::shared_ptr conf_ = + std::dynamic_pointer_cast( participant_configuration); // TMP: Until Transparency TopicQoS module is available if (!conf_) { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << - participant_configuration->kind); + kind); } - auto participant = std::make_shared ( + auto participant = std::make_shared ( conf_, payload_pool, discovery_database); diff --git a/ddsrouter_yaml/CMakeLists.txt b/ddsrouter_yaml/CMakeLists.txt index 0965da882..82b5e3690 100644 --- a/ddsrouter_yaml/CMakeLists.txt +++ b/ddsrouter_yaml/CMakeLists.txt @@ -70,9 +70,9 @@ compile_library( # Test ############################################################################### # Compile tests if CMake options requires it -compile_test_library( - "${PROJECT_SOURCE_DIR}/test" # Test directory -) +# compile_test_library( +# "${PROJECT_SOURCE_DIR}/test" # Test directory +# ) ############################################################################### # Packaging diff --git a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp index d353d8800..dd0de849d 100644 --- a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp @@ -1,8 +1,92 @@ +// Copyright 2022 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. -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace yaml { + +core::DdsRouterConfiguration +YamlReaderConfiguration::load_ddsrouter_configuration( + const Yaml& yml) +{ + try + { + ddspipe::yaml::YamlReaderVersion version; + // Get version if present + if (ddspipe::yaml::YamlReader::is_tag_present(yml, ddspipe::yaml::VERSION_TAG)) + { + version = ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::VERSION_TAG, ddspipe::yaml::LATEST); + } + else + { + // Get default version + version = default_yaml_version(); + logWarning(DDSROUTER_YAML, + "No version of yaml configuration given. Using version " << version << " by default. " << + "Add " << ddspipe::yaml::VERSION_TAG << " tag to your configuration in order to not break compatibility " << + "in future releases."); + } + logInfo(DDSROUTER_YAML, "Loading DDSRouter configuration with version: " << version << "."); + + // Load DDS Router Configuration + core::DdsRouterConfiguration router_configuration = + ddspipe::yaml::YamlReader::get(yml, version); + + return router_configuration; + } + catch (const std::exception& e) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "Error loading DDS Router configuration from yaml:\n " << e.what()); + } +} + +core::DdsRouterConfiguration +YamlReaderConfiguration::load_ddsrouter_configuration_from_file( + const std::string& file_path) +{ + Yaml yml; + + // Load file + try + { + yml = ddspipe::yaml::YamlManager::load_file(file_path); + } + catch (const std::exception& e) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "Error loading DDSRouter configuration from file: <" << file_path << + "> :\n " << e.what()); + } + + return YamlReaderConfiguration::load_ddsrouter_configuration(yml); +} + +ddspipe::yaml::YamlReaderVersion YamlReaderConfiguration::default_yaml_version() +{ + return ddspipe::yaml::V_3_0; +} + +} +} +} From 5e2cc398afbec9f8b3b8fe378c5efb259617bbf0 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 15:52:30 +0100 Subject: [PATCH 14/38] All code compiling Signed-off-by: jparisu --- .../src/cpp/testing/random_values.cpp | 2 +- .../include/ddsrouter_core/core/DdsRouter.hpp | 2 +- .../src/cpp/YamlReader_configuration.cpp | 186 ++++++++++++++++++ 3 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp diff --git a/ddspipe_participants/src/cpp/testing/random_values.cpp b/ddspipe_participants/src/cpp/testing/random_values.cpp index 54d0a9353..2154b0cce 100644 --- a/ddspipe_participants/src/cpp/testing/random_values.cpp +++ b/ddspipe_participants/src/cpp/testing/random_values.cpp @@ -29,7 +29,7 @@ Address random_address( return Address("127.0.0.1", seed, seed, TransportProtocol::udp); } -DiscoveryServerConnectionAddress random_connection_addresses( +DiscoveryServerConnectionAddress random_connection_address( unsigned int seed /* = 0 */, unsigned int size /* = 1 */, bool ros /* = false */) diff --git a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp index 481556808..883027c93 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp @@ -63,7 +63,7 @@ class DdsRouter * Destroy all Bridges * Destroy all Participants */ - DDSROUTER_CORE_DllAPI virtual ~DdsRouter(); + DDSROUTER_CORE_DllAPI virtual ~DdsRouter() = default; // EVENTS /** diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp new file mode 100644 index 000000000..19023b1b3 --- /dev/null +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -0,0 +1,186 @@ +// Copyright 2022 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. + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { + +template <> +void YamlReader::fill( + ddsrouter::core::SpecsConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + ///// + // Get optional number of threads + if (YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG)) + { + object.number_of_threads = YamlReader::get(yml, NUMBER_THREADS_TAG, version); + } + + ///// + // Get optional maximum history depth + if (YamlReader::is_tag_present(yml, MAX_HISTORY_DEPTH_TAG)) + { + object.max_history_depth = YamlReader::get(yml, MAX_HISTORY_DEPTH_TAG, version); + } +} + +template <> +ddsrouter::core::types::ParticipantKind YamlReader::get( + const Yaml& yml, + const YamlReaderVersion /* version */) +{ + // Domain id required + return get_enumeration_from_builder(yml, *ddsrouter::core::types::ParticipantKindBuilder::get_instance()); +} + +template <> +std::shared_ptr +YamlReader::get>( + const Yaml& yml, + const YamlReaderVersion version) +{ + // Kind required + ddsrouter::core::types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); + + logInfo(DDSROUTER_YAML_CONFIGURATION, "Loading Participant of kind " << kind << "."); + + switch (kind) + { + case ddsrouter::core::types::ParticipantKind::echo: + return std::make_shared( + YamlReader::get(yml, version)); + + case ddsrouter::core::types::ParticipantKind::simple: + return std::make_shared( + YamlReader::get(yml, version)); + + case ddsrouter::core::types::ParticipantKind::discovery_server: + return std::make_shared( + YamlReader::get(yml, version)); + + case ddsrouter::core::types::ParticipantKind::initial_peers: + return std::make_shared( + YamlReader::get(yml, version)); + + default: + // Non recheable code + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "Unkown or non valid Participant kind: " << kind << "."); + } +} + +template <> +void YamlReader::fill( + ddsrouter::core::DdsRouterConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + ///// + // Get optional allowlist + if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) + { + auto allowlist_set = YamlReader::get_set(yml, ALLOWLIST_TAG, version); + for (auto const& wild_topic : allowlist_set) + { + auto new_topic = utils::Heritable::make_heritable(wild_topic); + object.allowlist.insert(new_topic); + } + } + + ///// + // Get optional blocklist + if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) + { + auto blocklist_set = YamlReader::get_set(yml, ALLOWLIST_TAG, version); + for (auto const& wild_topic : blocklist_set) + { + auto new_topic = utils::Heritable::make_heritable(wild_topic); + object.blocklist.insert(new_topic); + } + } + + ///// + // Get optional builtin topics + if (YamlReader::is_tag_present(yml, BUILTIN_TAG)) + { + object.builtin_topics = utils::convert_set_to_shared( + YamlReader::get_set(yml, BUILTIN_TAG, version)); + } + + ///// + // Get participants configurations. Required field, if get_value_in_tag fail propagate exception. + auto participants_configurations_yml = YamlReader::get_value_in_tag(yml, COLLECTION_PARTICIPANTS_TAG); + + // TODO do it in a single instruction + // Check it is a list + if (!participants_configurations_yml.IsSequence()) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << + "Participant configurations must be specified in an array under tag: " << + COLLECTION_PARTICIPANTS_TAG); + } + + for (auto conf : participants_configurations_yml) + { + ddsrouter::core::types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); + object.participants_configurations.insert( + { + kind, + YamlReader::get>(conf, version) + } + ); + } + + ///// + // Get optional specs configuration + if (YamlReader::is_tag_present(yml, SPECS_TAG)) + { + YamlReader::fill( + object.advanced_options, + YamlReader::get_value_in_tag(yml, SPECS_TAG), + version); + } +} + +template <> +ddsrouter::core::DdsRouterConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + ddsrouter::core::DdsRouterConfiguration object; + fill(object, yml, version); + return object; +} + +} +} +} From 068afb5c687bcb170a4a2f4df2da1d8f84a23ca7 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 16:02:05 +0100 Subject: [PATCH 15/38] Tool tests passing Signed-off-by: jparisu --- .../src/cpp/YamlReader_configuration.cpp | 3 +- .../test/application/CMakeLists.txt | 6 +-- .../complex_configuration_v1.yaml | 33 -------------- .../complex_configuration_v2.yaml | 45 ------------------- .../default_version_configuration.yaml | 8 ---- .../configurations/ds_configuration.yaml | 2 +- .../configurations/v1_configuration.yaml | 17 ------- .../configurations/void_configuration.yaml | 12 ----- .../configurations/wan_configuration.yaml | 15 +++++++ 9 files changed, 19 insertions(+), 122 deletions(-) delete mode 100644 tools/ddsrouter_tool/test/application/configurations/complex_configuration_v1.yaml delete mode 100644 tools/ddsrouter_tool/test/application/configurations/complex_configuration_v2.yaml delete mode 100644 tools/ddsrouter_tool/test/application/configurations/default_version_configuration.yaml delete mode 100644 tools/ddsrouter_tool/test/application/configurations/v1_configuration.yaml delete mode 100644 tools/ddsrouter_tool/test/application/configurations/void_configuration.yaml create mode 100644 tools/ddsrouter_tool/test/application/configurations/wan_configuration.yaml diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index 19023b1b3..f6241cd68 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -151,7 +151,8 @@ void YamlReader::fill( for (auto conf : participants_configurations_yml) { - ddsrouter::core::types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); + ddsrouter::core::types::ParticipantKind kind = + YamlReader::get(conf, PARTICIPANT_KIND_TAG, version); object.participants_configurations.insert( { kind, diff --git a/tools/ddsrouter_tool/test/application/CMakeLists.txt b/tools/ddsrouter_tool/test/application/CMakeLists.txt index d0fd41d95..cfc411d9a 100644 --- a/tools/ddsrouter_tool/test/application/CMakeLists.txt +++ b/tools/ddsrouter_tool/test/application/CMakeLists.txt @@ -20,14 +20,10 @@ find_package(PythonInterp 3 REQUIRED) # Name of files to test set(TEST_CONFIGURATIONS - void_configuration simple_configuration ds_configuration - default_version_configuration - v1_configuration - complex_configuration_v1 - complex_configuration_v2 complex_configuration_v3 + wan_configuration ) # Whether one or other signal in test diff --git a/tools/ddsrouter_tool/test/application/configurations/complex_configuration_v1.yaml b/tools/ddsrouter_tool/test/application/configurations/complex_configuration_v1.yaml deleted file mode 100644 index 4a4a4a213..000000000 --- a/tools/ddsrouter_tool/test/application/configurations/complex_configuration_v1.yaml +++ /dev/null @@ -1,33 +0,0 @@ - -# 1 Echo Participant -# 2 Simple Participants in domains 0 and 1 -# 1 Local Discovery Server Participant with listening address -# 1 WAN Participant with connection address -# 2 topics, one with key and one without - - -version: v1.0 - -participant1: - type: "echo" - -participant2: - type: "discovery-server" - id: 3 - ros-discovery-server: true - connection-addresses: - - guid: "01.0f.00.00.00.00.00.00.00.00.00.00" - addresses: - - ip: 127.0.0.1 - port: 3333 - -simple_participant: - type: simple - domain: 1 - -wan: - type: wan - id: 2 - listening-addresses: - - ip: 127.0.0.1 - port: 3334 diff --git a/tools/ddsrouter_tool/test/application/configurations/complex_configuration_v2.yaml b/tools/ddsrouter_tool/test/application/configurations/complex_configuration_v2.yaml deleted file mode 100644 index c7bed9283..000000000 --- a/tools/ddsrouter_tool/test/application/configurations/complex_configuration_v2.yaml +++ /dev/null @@ -1,45 +0,0 @@ - -# 1 Echo Participant -# 2 Simple Participants in domains 0 and 1 -# 1 Local Discovery Server Participant with listening address -# 1 WAN Participant with connection address -# 2 topics, one with key and one without - -version: v2.0 - -builtin-topics: - - name: "rt/chatter" - type: "std_msgs::msg::dds_::String_" - - name: "rt/chatter/key" - type: "std_msgs::msg::dds_::String_" - keyed: true - -participants: - - - name: simple_0 - kind: simple - domain: 0 - - - name: simple_1 - kind: simple - domain: 1 - - - name: local-ds - kind: local-discovery-server - discovery-server-guid: - id: 0 - listening-addresses: - - ip: "127.0.0.1" - port: 11666 - - - name: wan - kind: wan - discovery-server-guid: - id: 1 - connection-addresses: - - discovery-server-guid: - id: 2 - addresses: - - ip: "127.0.0.1" - port: 11667 - transport: tcp diff --git a/tools/ddsrouter_tool/test/application/configurations/default_version_configuration.yaml b/tools/ddsrouter_tool/test/application/configurations/default_version_configuration.yaml deleted file mode 100644 index b32cb0c6d..000000000 --- a/tools/ddsrouter_tool/test/application/configurations/default_version_configuration.yaml +++ /dev/null @@ -1,8 +0,0 @@ - -# 2 Empty Participants - -participant1: - type: void - -participant2: - type: void diff --git a/tools/ddsrouter_tool/test/application/configurations/ds_configuration.yaml b/tools/ddsrouter_tool/test/application/configurations/ds_configuration.yaml index b2ee4e919..b88779c87 100644 --- a/tools/ddsrouter_tool/test/application/configurations/ds_configuration.yaml +++ b/tools/ddsrouter_tool/test/application/configurations/ds_configuration.yaml @@ -23,7 +23,7 @@ participants: port: 11666 - name: wan - kind: wan + kind: wan-ds discovery-server-guid: id: 1 connection-addresses: diff --git a/tools/ddsrouter_tool/test/application/configurations/v1_configuration.yaml b/tools/ddsrouter_tool/test/application/configurations/v1_configuration.yaml deleted file mode 100644 index b4810a163..000000000 --- a/tools/ddsrouter_tool/test/application/configurations/v1_configuration.yaml +++ /dev/null @@ -1,17 +0,0 @@ - -# 2 Empty Participants - -version: v1.0 - -participant1: - type: "echo" - -participant2: - type: "discovery-server" - id: 3 - ros-discovery-server: true - connection-addresses: - - guid: "01.0f.00.00.00.00.00.00.00.00.00.00" - addresses: - - ip: 127.0.0.1 - port: 3333 diff --git a/tools/ddsrouter_tool/test/application/configurations/void_configuration.yaml b/tools/ddsrouter_tool/test/application/configurations/void_configuration.yaml deleted file mode 100644 index c72b2e81e..000000000 --- a/tools/ddsrouter_tool/test/application/configurations/void_configuration.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -# 2 Empty Participants - -version: v2.0 - -participants: - - - name: void0 - kind: void - - - name: void1 - kind: void diff --git a/tools/ddsrouter_tool/test/application/configurations/wan_configuration.yaml b/tools/ddsrouter_tool/test/application/configurations/wan_configuration.yaml new file mode 100644 index 000000000..22d1b8cd1 --- /dev/null +++ b/tools/ddsrouter_tool/test/application/configurations/wan_configuration.yaml @@ -0,0 +1,15 @@ + +version: v3.0 + +participants: + + - name: local + kind: local + domain: 0 + + - name: wan + kind: wan + connection-addresses: + - ip: "127.0.0.1" + port: 11667 + transport: tcp From 381d419f58dd87776403c978a5194daced7a5cc5 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 14 Feb 2023 17:14:03 +0100 Subject: [PATCH 16/38] Some fixes Signed-off-by: jparisu --- .../communication/rpc/RPCBridge.hpp | 4 +-- .../include/ddspipe_core/core/DdsPipe.hpp | 18 ++++++---- .../testing/entities/blank_entities.hpp | 2 +- .../testing/entities/mock_entities.hpp | 2 +- .../types/data/RpcPayloadData.hpp | 2 +- .../types/data/RtpsPayloadData.hpp | 6 +++- .../topic/TopicInternalTypeDiscriminator.hpp | 4 +-- .../src/cpp/communication/dds/DdsBridge.cpp | 6 ++-- .../src/cpp/communication/dds/Track.cpp | 12 +++---- .../src/cpp/communication/rpc/RPCBridge.cpp | 21 +++++++----- ddspipe_core/src/cpp/core/DdsPipe.cpp | 34 +++++++++---------- .../src/cpp/dynamic/DiscoveryDatabase.cpp | 4 --- .../src/cpp/types/topic/rpc/RpcTopic.cpp | 7 +++- .../participant/auxiliar/EchoParticipant.cpp | 4 +++ .../participant/rtps/CommonParticipant.cpp | 10 ++++++ .../src/cpp/reader/rpc/SimpleReader.cpp | 3 +- .../cpp/writer/auxiliar/RtpsEchoWriter.cpp | 3 +- .../src/cpp/writer/rpc/SimpleWriter.cpp | 5 +++ .../src/cpp/writer/rtps/CommonWriter.cpp | 10 +----- .../src/cpp/writer/rtps/MultiWriter.cpp | 2 +- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 4 ++- ddsrouter_core/src/cpp/core/DdsRouter.cpp | 6 +--- 22 files changed, 97 insertions(+), 72 deletions(-) diff --git a/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp index e7d11ea4e..84313375d 100644 --- a/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp @@ -57,7 +57,7 @@ class RPCBridge : public Bridge * @note Always created disabled, manual enable required. First enable creates all endpoints. */ RPCBridge( - const std::shared_ptr& topic, + const types::RpcTopic& topic, const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool); @@ -185,7 +185,7 @@ class RPCBridge : public Bridge */ std::shared_timed_mutex on_transmission_mutex_; - std::shared_ptr rpc_topic_; + types::RpcTopic rpc_topic_; // Allow operator << to use private variables friend std::ostream& operator <<( diff --git a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp index 5754b5bab..7313b1bbf 100644 --- a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp +++ b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp @@ -181,7 +181,7 @@ class DdsPipe * @param [in] server_guid_prefix : GUID Prefix of discovered server */ void discovered_service_( - const std::shared_ptr& topic, + const types::RpcTopic& topic, const types::ParticipantId& server_participant_id, const types::GuidPrefix& server_guid_prefix) noexcept; @@ -195,7 +195,7 @@ class DdsPipe * @param [in] server_guid_prefix : GUID Prefix of discovered server */ void removed_service_( - const std::shared_ptr& topic, + const types::RpcTopic& topic, const types::ParticipantId& server_participant_id, const types::GuidPrefix& server_guid_prefix) noexcept; @@ -236,7 +236,7 @@ class DdsPipe * @param [in] topic : new topic */ void create_new_service_( - const std::shared_ptr& topic) noexcept; + const types::RpcTopic& topic) noexcept; /** * @brief Enable a specific topic @@ -309,7 +309,7 @@ class DdsPipe std::map, std::unique_ptr> bridges_; //! Map of RPC bridges indexed by their topic - std::map, std::unique_ptr> rpc_bridges_; + std::map> rpc_bridges_; /** * @brief List of topics discovered @@ -325,7 +325,7 @@ class DdsPipe * Every RPC topic discovered would is added to this map. * If the value is true, it means this service is allowed. */ - std::map, bool> current_services_; + std::map current_services_; ///// // AUXILIAR VARIABLES @@ -333,8 +333,12 @@ class DdsPipe //! Whether the DDSRouterImpl is currently communicating data or not std::atomic enabled_; - //! Internal mutex for concurrent calls - std::mutex mutex_; + /** + * @brief Internal mutex for concurrent calls + * + * @todo this should not require to be recursive. + */ + std::recursive_mutex mutex_; }; } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp b/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp index 7636cc7f7..0de0c74fe 100644 --- a/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp +++ b/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp @@ -96,7 +96,7 @@ struct BlankRoutingData : public IRoutingData types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; }; -constexpr types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "test_type::blank::v0"; +const types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "test_type::blank::v0"; } /* namespace testing */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp b/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp index 1e5f39808..368ccad2a 100644 --- a/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp +++ b/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp @@ -82,7 +82,7 @@ struct MockRoutingData : public BlankRoutingData types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; }; -constexpr types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "testing_type::mock::v0"; +const types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "testing_type::mock::v0"; } /* namespace testing */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp index b61b64cb5..7d3418710 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp @@ -56,7 +56,7 @@ struct RpcPayloadData : public RtpsPayloadData /** * @brief Id to identify the internal topic type id that uses \c RpcPayloadData . */ -constexpr TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; +const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; } /* namespace types */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp index 09f6ef754..5c2d8c223 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp @@ -40,6 +40,8 @@ namespace types { struct RtpsPayloadData : public core::IRoutingData { + RtpsPayloadData() = default; + /** * @brief Destroy the Rtps Payload Data object * @@ -47,6 +49,8 @@ struct RtpsPayloadData : public core::IRoutingData */ virtual ~RtpsPayloadData(); + RtpsPayloadData(const RtpsPayloadData& ) = delete; + virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; //! Payload of the data received. The data in this payload must belong to the PayloadPool. @@ -81,7 +85,7 @@ struct RtpsPayloadData : public core::IRoutingData /** * @brief Id to identify the internal topic type id that uses \c RtpsPayloadData . */ -constexpr core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; +const core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; } /* namespace types */ } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp index 6ecc37b66..2a0bba71d 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp @@ -27,9 +27,9 @@ namespace types { * * @warning as this is a const char* it is strongly suggested to only use constexpr or static values. */ -using TopicInternalTypeDiscriminator = const char*; +using TopicInternalTypeDiscriminator = std::string; -constexpr TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_NONE = ""; +const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_NONE = ""; } /* namespace types */ } /* namespace core */ diff --git a/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp index 8ef902b37..70eec3a5f 100644 --- a/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp +++ b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp @@ -94,7 +94,7 @@ void DdsBridge::enable() noexcept if (!enabled_) { - logInfo(DDSROUTER_DDSBRIDGE, "Enabling DdsBridge for topic " << topic_ << "."); + logInfo(DDSROUTER_DDSBRIDGE, "Enabling DdsBridge for topic " << topic_->topic_name() << "."); // ATTENTION: reference needed or it would copy Track for (auto& track_it : tracks_) @@ -112,7 +112,7 @@ void DdsBridge::disable() noexcept if (enabled_) { - logInfo(DDSROUTER_DDSBRIDGE, "Disabling DdsBridge for topic " << topic_ << "."); + logInfo(DDSROUTER_DDSBRIDGE, "Disabling DdsBridge for topic " << topic_->topic_name() << "."); // ATTENTION: reference needed or it would copy Track for (auto& track_it : tracks_) @@ -128,7 +128,7 @@ std::ostream& operator <<( std::ostream& os, const DdsBridge& bridge) { - os << "DdsBridge{" << bridge.topic_ << "}"; + os << "DdsBridge{" << bridge.topic_->topic_name() << "}"; return os; } diff --git a/ddspipe_core/src/cpp/communication/dds/Track.cpp b/ddspipe_core/src/cpp/communication/dds/Track.cpp index 50280e5e1..d482e0835 100644 --- a/ddspipe_core/src/cpp/communication/dds/Track.cpp +++ b/ddspipe_core/src/cpp/communication/dds/Track.cpp @@ -86,7 +86,7 @@ void Track::enable() noexcept if (!enabled_) { - logInfo(DDSROUTER_TRACK, "Enabling Track " << reader_participant_id_ << " for topic " << topic_ << "."); + logInfo(DDSROUTER_TRACK, "Enabling Track " << reader_participant_id_ << " for topic " << topic_->topic_name() << "."); enabled_ = true; // Enable writers before reader, to avoid starting a transmission (not protected with \c track_mutex_) which may @@ -110,7 +110,7 @@ void Track::disable() noexcept if (enabled_) { - logInfo(DDSROUTER_TRACK, "Disabling Track " << reader_participant_id_ << " for topic " << topic_ << "."); + logInfo(DDSROUTER_TRACK, "Disabling Track " << reader_participant_id_ << " for topic " << topic_->topic_name() << "."); // Do disable before stop in the mutex so the Track is forced to stop in next iteration enabled_ = false; @@ -197,13 +197,13 @@ void Track::transmit_() noexcept else if (!ret) { // Error reading data - logWarning(DDSROUTER_TRACK, "Error taking data in Track " << topic_ << ". Error code " << ret + logWarning(DDSROUTER_TRACK, "Error taking data in Track " << topic_->topic_name() << ". Error code " << ret << ". Skipping data and continue."); continue; } logDebug(DDSROUTER_TRACK, - "Track " << reader_participant_id_ << " for topic " << topic_ << + "Track " << reader_participant_id_ << " for topic " << topic_->topic_name() << " transmitting data from remote endpoint."); // Send data through writers @@ -217,7 +217,7 @@ void Track::transmit_() noexcept if (!ret) { - logWarning(DDSROUTER_TRACK, "Error writting data in Track " << topic_ << ". Error code " + logWarning(DDSROUTER_TRACK, "Error writting data in Track " << topic_->topic_name() << ". Error code " << ret << ". Skipping data for this writer and continue."); continue; @@ -232,7 +232,7 @@ std::ostream& operator <<( std::ostream& os, const Track& track) { - os << "Track{" << track.topic_ << ";" << track.reader_participant_id_ << "}"; + os << "Track{" << track.topic_->topic_name() << ";" << track.reader_participant_id_ << "}"; return os; } diff --git a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp index df69124e4..a0cb07714 100644 --- a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -34,7 +34,7 @@ namespace core { using namespace eprosima::ddspipe::core::types; RPCBridge::RPCBridge( - const std::shared_ptr& topic, + const RpcTopic& topic, const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool) @@ -77,9 +77,9 @@ void RPCBridge::init_nts_() // TODO: This should not be done // Wait for the new entities created to match before sending data from one side to the other + init_ = true; utils::sleep_for(500); - init_ = true; } void RPCBridge::create_proxy_server_nts_( @@ -87,8 +87,8 @@ void RPCBridge::create_proxy_server_nts_( { std::shared_ptr participant = participants_->get_participant(participant_id); - reply_writers_[participant_id] = participant->create_writer(rpc_topic_->reply_topic()); - request_readers_[participant_id] = participant->create_reader(rpc_topic_->request_topic()); + reply_writers_[participant_id] = participant->create_writer(rpc_topic_.reply_topic()); + request_readers_[participant_id] = participant->create_reader(rpc_topic_.request_topic()); create_slot_(request_readers_[participant_id]); } @@ -99,13 +99,13 @@ void RPCBridge::create_proxy_client_nts_( std::shared_ptr participant = participants_->get_participant(participant_id); // Safe casting as we are only getting RTPS participants - request_writers_[participant_id] = participant->create_writer(rpc_topic_->request_topic()); - reply_readers_[participant_id] = participant->create_reader(rpc_topic_->reply_topic()); + request_writers_[participant_id] = participant->create_writer(rpc_topic_.request_topic()); + reply_readers_[participant_id] = participant->create_reader(rpc_topic_.reply_topic()); create_slot_(reply_readers_[participant_id]); // Create service registry associated to this proxy client - service_registries_[participant_id] = std::make_shared(*rpc_topic_, participant_id); + service_registries_[participant_id] = std::make_shared(rpc_topic_, participant_id); } void RPCBridge::enable() noexcept @@ -204,6 +204,9 @@ void RPCBridge::discovered_service( { service_registries_[server_participant_id]->enable(); } + else + { + } } void RPCBridge::removed_service( @@ -297,6 +300,7 @@ void RPCBridge::transmit_( RpcPayloadData& pcr_data = dynamic_cast(*data); + // Will never return \c RETCODE_NO_DATA, otherwise would have finished before if (!ret) { @@ -345,6 +349,7 @@ void RPCBridge::transmit_( pcr_data.write_params.get_reference().related_sample_identity().writer_guid( reply_readers_[service_registry.first]->guid()); + ret = request_writers_[service_registry.first]->write(*data); if (!ret) @@ -452,7 +457,7 @@ std::ostream& operator <<( std::ostream& os, const RPCBridge& bridge) { - os << "RPCBridge{" << bridge.rpc_topic_ << "}"; + os << "RPCBridge{" << bridge.rpc_topic_.service_name() << "}"; return os; } diff --git a/ddspipe_core/src/cpp/core/DdsPipe.cpp b/ddspipe_core/src/cpp/core/DdsPipe.cpp index a460ced42..132b621c9 100644 --- a/ddspipe_core/src/cpp/core/DdsPipe.cpp +++ b/ddspipe_core/src/cpp/core/DdsPipe.cpp @@ -92,7 +92,7 @@ DdsPipe::~DdsPipe() utils::ReturnCode DdsPipe::reload_allowed_topics( const std::shared_ptr& allowed_topics) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (enabled_.load()) { @@ -134,7 +134,7 @@ utils::ReturnCode DdsPipe::reload_allowed_topics( // Check every service discovered and activate/deactivate it if needed. for (auto& service_it : current_services_) { - if (allowed_topics_->is_service_allowed(*service_it.first)) + if (allowed_topics_->is_service_allowed(service_it.first)) { service_it.second = true; rpc_bridges_[service_it.first]->enable(); @@ -187,7 +187,7 @@ utils::ReturnCode DdsPipe::stop() noexcept utils::ReturnCode DdsPipe::start_() noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!enabled_.load()) { @@ -221,7 +221,7 @@ utils::ReturnCode DdsPipe::start_() noexcept utils::ReturnCode DdsPipe::stop_() noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (enabled_.load()) { @@ -253,7 +253,7 @@ void DdsPipe::init_bridges_(const std::set& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Discovered topic: " << topic << "."); @@ -276,11 +276,11 @@ void DdsPipe::discovered_topic_( } void DdsPipe::discovered_service_( - const std::shared_ptr& topic, + const types::RpcTopic& topic, const ParticipantId& server_participant_id, const GuidPrefix& server_guid_prefix) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Discovered service: " << topic << "."); @@ -291,7 +291,7 @@ void DdsPipe::discovered_service_( // Create RPCBridge even if topic not allowed, as we need to store server in database create_new_service_(topic); - if (allowed_topics_->is_service_allowed(*topic)) + if (allowed_topics_->is_service_allowed(topic)) { current_services_[topic] = true; } @@ -309,11 +309,11 @@ void DdsPipe::discovered_service_( } void DdsPipe::removed_service_( - const std::shared_ptr& topic, + const types::RpcTopic& topic, const ParticipantId& server_participant_id, const GuidPrefix& server_guid_prefix) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Removed service: " << topic << "."); @@ -341,7 +341,7 @@ void DdsPipe::discovered_endpoint_( else if (endpoint.is_server_endpoint()) { // Service server discovered - discovered_service_(std::make_shared(endpoint.topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); + discovered_service_(types::RpcTopic(endpoint.topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); } } } @@ -357,7 +357,7 @@ void DdsPipe::removed_endpoint_( if (endpoint.is_server_endpoint()) { // Service server removed/dropped - removed_service_(std::make_shared(topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); + removed_service_(types::RpcTopic(topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); } } } @@ -366,7 +366,7 @@ void DdsPipe::create_new_bridge_( const std::shared_ptr& topic, bool enabled /*= false*/) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Creating Bridge for topic: " << topic << "."); @@ -388,9 +388,9 @@ void DdsPipe::create_new_bridge_( } void DdsPipe::create_new_service_( - const std::shared_ptr& topic) noexcept + const types::RpcTopic& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Creating Service: " << topic << "."); @@ -401,7 +401,7 @@ void DdsPipe::create_new_service_( void DdsPipe::activate_topic_( const std::shared_ptr& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Activating topic: " << topic << "."); @@ -426,7 +426,7 @@ void DdsPipe::activate_topic_( void DdsPipe::deactivate_topic_( const std::shared_ptr& topic) noexcept { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); logInfo(DDSROUTER, "Deactivating topic: " << topic << "."); diff --git a/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp index 69e5b6f60..7a42babd6 100644 --- a/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp +++ b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp @@ -91,10 +91,6 @@ bool DiscoveryDatabase::topic_exists( { return true; } - else - { - logError(DEBUG, "Topics not equal " << topic << " != " << entity.second.topic); - } } return false; } diff --git a/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp b/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp index ab5c3b404..f003e361a 100644 --- a/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp +++ b/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp @@ -19,9 +19,11 @@ #include -#include #include +#include +#include + namespace eprosima { namespace ddspipe { namespace core { @@ -80,6 +82,9 @@ RpcTopic::RpcTopic( utils::Formatter() << "Attempting to create RpcTopic from invalid topic."); } + reply_topic_.m_internal_type_discriminator = INTERNAL_TOPIC_TYPE_RPC; + request_topic_.m_internal_type_discriminator = INTERNAL_TOPIC_TYPE_RPC; + // Set both topic qos as the one found request_topic_.topic_qos = topic.topic_qos; reply_topic_.topic_qos = topic.topic_qos; diff --git a/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp b/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp index f27283cd8..c6606b81c 100644 --- a/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp @@ -68,6 +68,10 @@ std::shared_ptr EchoParticipant::create_writer( configuration_->verbose); } } + else + { + logInfo(DDSROUTER_ECHO_DISCOVERY, "Ignoring topic " << topic.topic_name() << " as it is not RTPS."); + } return std::make_shared(); } diff --git a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp index 8ef9a22b4..8d34812c5 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp @@ -146,6 +146,9 @@ core::types::Endpoint CommonParticipant::create_common_endpoint_from_info_( endpoint.specific_qos.partitions = info.info.m_qos.m_partition; } + // Set participant that discovered + endpoint.discoverer_participant_id = configuration_->id; + // NOTE: ownership is only for Writer return endpoint; } @@ -306,12 +309,15 @@ std::shared_ptr CommonParticipant::create_writer( const core::types::DdsTopic* dds_topic_ptr = dynamic_cast(&topic); if (!dds_topic_ptr) { + logDebug(DDSROUTER_RTPS_PARTICIPANT, "Not creating Writer for topic " << topic.topic_name()); return std::make_shared(); } const core::types::DdsTopic& dds_topic = *dds_topic_ptr; if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RPC) { + logDebug(DDSROUTER_RTPS_PARTICIPANT, + "Creating RPC Writer for topic " << topic.topic_name()); auto writer = std::make_shared( this->id(), dds_topic, @@ -361,12 +367,16 @@ std::shared_ptr CommonParticipant::create_reader( const core::types::DdsTopic* dds_topic_ptr = dynamic_cast(&topic); if (!dds_topic_ptr) { + logDebug(DDSROUTER_RTPS_PARTICIPANT, "Not creating Reader for topic " << topic.topic_name()); return std::make_shared(); } const core::types::DdsTopic& dds_topic = *dds_topic_ptr; if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RPC) { + logDebug(DDSROUTER_RTPS_PARTICIPANT, + "Creating RPC Reader for topic " << topic.topic_name()); + auto reader = std::make_shared( this->id(), dds_topic, diff --git a/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp b/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp index 1f09cafac..c528aa73b 100644 --- a/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp +++ b/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp @@ -39,6 +39,7 @@ SimpleReader::SimpleReader( reckon_topic_attributes_(topic), reckon_reader_qos_(topic)) { + logInfo(DDSROUTER_RPC_READER, "Creating RPC Reader for topic " << topic_); } //! Override Parent method to create an RPC data type. @@ -58,7 +59,7 @@ void SimpleReader::fill_received_data_( // Get internal RpcPayload core::types::RpcPayloadData& rpc_data = dynamic_cast(data_to_fill); // Set write params and origin sequence number - rpc_data.write_params = received_change.write_params; + rpc_data.write_params.set_value(received_change.write_params); rpc_data.origin_sequence_number = received_change.sequenceNumber; } diff --git a/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp index e8611bafb..681deda39 100644 --- a/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp @@ -39,7 +39,8 @@ RtpsEchoWriter::RtpsEchoWriter( utils::ReturnCode RtpsEchoWriter::write( core::IRoutingData& data) noexcept { - auto rtps_data = dynamic_cast(data); + auto& rtps_data = dynamic_cast(data); + // TODO: Add Participant receiver Id when added to DataReceived if (!verbose_) { diff --git a/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp b/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp index 61687229c..331054ae8 100644 --- a/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp @@ -47,6 +47,7 @@ SimpleWriter::SimpleWriter( reckon_writer_qos_(topic), reckon_cache_change_pool_configuration_(topic)) { + logInfo(DDSROUTER_RPC_WRITER, "Creating RPC Writer for topic " << topic_); } utils::ReturnCode SimpleWriter::fill_to_send_data_( @@ -72,6 +73,10 @@ void SimpleWriter::fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& sent_params, core::types::RtpsPayloadData& data_to_fill) const noexcept { + CommonWriter::fill_sent_data_( + sent_params, + data_to_fill); + core::types::RpcPayloadData& rpc_data = dynamic_cast(data_to_fill); rpc_data.sent_sequence_number = sent_params.sample_identity().sequence_number(); } diff --git a/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp index 947bc0260..49f36e0e7 100644 --- a/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp @@ -121,7 +121,7 @@ bool CommonWriter::come_from_this_participant_( utils::ReturnCode CommonWriter::write_( core::IRoutingData& data) noexcept { - auto rtps_data = dynamic_cast(data); + auto& rtps_data = dynamic_cast(data); // Take new Change from history fastrtps::rtps::CacheChange_t* new_change; @@ -217,14 +217,6 @@ utils::ReturnCode CommonWriter::fill_to_send_data_( // Set source time stamp to be the original one to_send_params.source_timestamp(data.source_timestamp); - // RPC support - // If writer params has been set specifically, use them in change - // TODO move to rpc - // if (data.write_params.is_set()) - // { - // to_send_params.related_sample_identity(data->properties.write_params.get_reference().related_sample_identity()); - // } - return utils::ReturnCode::RETCODE_OK; } diff --git a/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp index 9c0393a81..370d967af 100644 --- a/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp +++ b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp @@ -141,7 +141,7 @@ QoSSpecificWriter* MultiWriter::create_writer_nts_( utils::ReturnCode MultiWriter::write_( core::IRoutingData& data) noexcept { - auto rtps_data = dynamic_cast(data); + auto& rtps_data = dynamic_cast(data); logDebug( DDSROUTER_MULTIWRITER, diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index 9322a0124..2a8aefa1a 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -102,7 +102,9 @@ DomainId YamlReader::get( const YamlReaderVersion /* version */) { // Domain id required - return DomainId(get_scalar(yml)); + DomainId domain; + domain.domain_id = get_scalar(yml); + return domain; } template <> diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp index 40f537abf..42f5ab8ec 100644 --- a/ddsrouter_core/src/cpp/core/DdsRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -86,11 +86,7 @@ void DdsRouter::init_participants_() for (std::pair> participant_config : configuration_.participants_configurations) { - std::shared_ptr new_participant; - - // Create participant - // This should not be in try catch case as if it fails the whole init must fail - new_participant = + std::shared_ptr new_participant = participant_factory_.create_participant( participant_config.first, participant_config.second, From 00f24f156ccd06a3e301d193b55df5b8b1878dbe Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 15 Feb 2023 11:32:24 +0100 Subject: [PATCH 17/38] remove noexcept from default ctors Signed-off-by: jparisu --- ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp | 2 +- ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp index 6c81b35d3..95408a270 100644 --- a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp @@ -33,7 +33,7 @@ using DomainIdType = eprosima::fastdds::dds::DomainId_t; struct DomainId : public IConfiguration { - DDSPIPE_CORE_DllAPI DomainId () noexcept = default; + DDSPIPE_CORE_DllAPI DomainId () = default; DDSPIPE_CORE_DllAPI DomainId (bool discovery_server) noexcept; diff --git a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp index f7b62e93f..8a4e44c14 100644 --- a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp @@ -47,7 +47,7 @@ struct Endpoint { //! Default Endpoint that returns an invalid one - DDSPIPE_CORE_DllAPI Endpoint() noexcept = default; + DDSPIPE_CORE_DllAPI Endpoint() = default; /******************** * SPECIFIC GETTERS * From 741c652f80ce4acf49b95e4952e3a86e5b81433d Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 15 Feb 2023 11:53:30 +0100 Subject: [PATCH 18/38] Update github action Signed-off-by: jparisu --- .github/workflows/test.yml | 95 +++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eef5a8d2d..a4a80853d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -119,6 +119,27 @@ jobs: name: ${{ matrix.windows-version }}_${{ matrix.cmake-config }}_fastdds_install run_id: ${{ env.fastdds_job_id }} + - name: Install ddspipe_core + uses: ./DDS-Router/.github/actions/install-router-subpackage-windows + with: + cmake_build_type: ${{ matrix.cmake-config }} + subpackage: ddspipe_core + subpackage_dir: ddspipe_core + + - name: Install ddspipe_participants + uses: ./DDS-Router/.github/actions/install-router-subpackage-windows + with: + cmake_build_type: ${{ matrix.cmake-config }} + subpackage: ddspipe_participants + subpackage_dir: tools/ddspipe_participants + + - name: Install ddspipe_yaml + uses: ./DDS-Router/.github/actions/install-router-subpackage-windows + with: + cmake_build_type: ${{ matrix.cmake-config }} + subpackage: ddspipe_yaml + subpackage_dir: ddspipe_yaml + - name: Install ddsrouter_core uses: ./DDS-Router/.github/actions/install-router-subpackage-windows with: @@ -140,6 +161,27 @@ jobs: subpackage: ddsrouter_tool subpackage_dir: tools/ddsrouter_tool + - name: Run tests ddspipe_core + uses: ./DDS-Router/.github/actions/run-test-windows + with: + package_name: ddspipe_core + cmake_build_type: ${{ matrix.cmake-config }} + if: always() + + - name: Run tests ddspipe_participants + uses: ./DDS-Router/.github/actions/run-test-windows + with: + package_name: ddspipe_participants + cmake_build_type: ${{ matrix.cmake-config }} + if: always() + + - name: Run tests ddspipe_yaml + uses: ./DDS-Router/.github/actions/run-test-windows + with: + package_name: ddspipe_yaml + cmake_build_type: ${{ matrix.cmake-config }} + if: always() + - name: Run tests ddsrouter_core uses: ./DDS-Router/.github/actions/run-test-windows with: @@ -373,6 +415,18 @@ jobs: --event-handlers=console_direct+ \ --cmake-args -DBUILD_TESTS=ON + - name: Run tests ddspipe + run: | + source install/setup.bash && \ + colcon test \ + --packages-select-regex ddspipe \ + --event-handlers=console_direct+ \ + --return-code-on-test-failure \ + --ctest-args \ + --label-exclude xfail \ + --timeout 60 + if: always() + - name: Run tests ddsrouter_core run: | source install/setup.bash && \ @@ -476,6 +530,18 @@ jobs: --metas src/DDS-Router/.github/workflows/test_colcon.meta \ --mixin coverage-gcc asan-gcc + - name: Run tests ddspipe + run: | + source install/setup.bash && \ + colcon test \ + --packages-select-regex ddspipe \ + --event-handlers=console_direct+ \ + --return-code-on-test-failure \ + --ctest-args \ + --label-regex xfail \ + --timeout 60 + if: always() + - name: Run tests ddsrouter_core run: | source install/setup.bash && \ @@ -560,12 +626,27 @@ jobs: --event-handlers=console_direct+ \ --metas src/DDS-Router/.github/workflows/asan_colcon.meta + - name: Run tests ddspipe_core + uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + with: + package_name: ddspipe_core + + - name: Run tests ddspipe_participants + uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + with: + package_name: ddspipe_participants + + - name: Run tests ddspipe_yaml + uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + with: + package_name: ddspipe_yaml + - name: Run tests ddsrouter_core uses: ./src/DDS-Router/.github/actions/run-test-ubuntu with: package_name: ddsrouter_core - - name: Run tests ddsrouter_yaml + - name: Run tests ddsrouter_yamlx uses: ./src/DDS-Router/.github/actions/run-test-ubuntu with: package_name: ddsrouter_yaml @@ -630,6 +711,18 @@ jobs: --event-handlers=console_direct+ \ --metas src/DDS-Router/.github/workflows/tsan_colcon.meta + - name: Run tests ddspipe + run: | + source install/setup.bash && \ + colcon test \ + --packages-select-regex ddspipe \ + --event-handlers=console_direct+ \ + --return-code-on-test-failure \ + --ctest-args \ + --label-exclude "xfail|xtsan" \ + --timeout 60 + if: always() + - name: Run tests ddsrouter_core run: | source install/setup.bash && \ From 2308d1a533cd6dbfc436aa020128b54bc5dc70cf Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 15 Feb 2023 12:33:45 +0100 Subject: [PATCH 19/38] Fixes Signed-off-by: jparisu --- .github/workflows/test.yml | 2 +- .../ddspipe_core/communication/Bridge.hpp | 5 +---- .../ddspipe_core/communication/dds/DdsBridge.hpp | 4 +++- .../ddspipe_core/communication/dds/Track.hpp | 5 +++-- .../include/ddspipe_core/core/DdsPipe.hpp | 16 ++++++++-------- ddspipe_core/src/cpp/communication/Bridge.cpp | 4 +--- .../src/cpp/communication/dds/DdsBridge.cpp | 5 +++-- ddspipe_core/src/cpp/communication/dds/Track.cpp | 2 +- .../src/cpp/communication/rpc/RPCBridge.cpp | 5 ++--- ddspipe_core/src/cpp/core/DdsPipe.cpp | 14 +++++++------- .../include/ddsrouter_core/core/DdsRouter.hpp | 8 ++++---- .../cpp/configuration/DdsRouterConfiguration.cpp | 2 +- ddsrouter_core/src/cpp/core/DdsRouter.cpp | 12 +++++++----- ddsrouter_core/src/cpp/testing/random_values.cpp | 4 ++-- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4a80853d..d181a2e84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,7 +131,7 @@ jobs: with: cmake_build_type: ${{ matrix.cmake-config }} subpackage: ddspipe_participants - subpackage_dir: tools/ddspipe_participants + subpackage_dir: ddspipe_participants - name: Install ddspipe_yaml uses: ./DDS-Router/.github/actions/install-router-subpackage-windows diff --git a/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp index 830070475..a53706cd6 100644 --- a/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp @@ -15,6 +15,7 @@ #pragma once #include +#include #include #include @@ -46,7 +47,6 @@ class Bridge * */ Bridge( - const std::shared_ptr& topic, const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool); @@ -71,9 +71,6 @@ class Bridge protected: - //! Topic that refers to this Bridge - const std::shared_ptr topic_; - //! Collection of Participants to manage communication const std::shared_ptr participants_; diff --git a/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp index 8367879b2..79deada00 100644 --- a/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp @@ -51,7 +51,7 @@ class DdsBridge : public Bridge * @throw InitializationException in case \c IWriters or \c IReaders creation fails. */ DdsBridge( - const std::shared_ptr& topic, + const utils::Heritable& topic, const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool); @@ -76,6 +76,8 @@ class DdsBridge : public Bridge protected: + utils::Heritable topic_; + /** * Inside \c Tracks * They are indexed by the Id of the participant that is source diff --git a/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp index 212bf0e14..5b67e9172 100644 --- a/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp +++ b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -47,7 +48,7 @@ class Track * @param writers: Map of Writers that will send the data received by \c source indexed by Participant id */ Track( - const std::shared_ptr& topic, + const utils::Heritable& topic, const types::ParticipantId& reader_participant_id, const std::shared_ptr& reader, std::map>&& writers, @@ -141,7 +142,7 @@ class Track void transmit_() noexcept; //! Topic that refers to this Bridge - const std::shared_ptr topic_; + const utils::Heritable topic_; /** * @brief Id of the Participant of the Reader diff --git a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp index 7313b1bbf..60e3fdb61 100644 --- a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp +++ b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp @@ -63,7 +63,7 @@ class DdsPipe const std::shared_ptr& payload_pool, const std::shared_ptr& participants_database, const std::shared_ptr& thread_pool, - const std::set>& builtin_topics = {}); + const std::set>& builtin_topics = {}); /** * @brief Destroy the DdsPipe object @@ -150,7 +150,7 @@ class DdsPipe /** * @brief Create a disabled bridge for every real topic */ - void init_bridges_(const std::set>& builtin_topics); + void init_bridges_(const std::set>& builtin_topics); ///// // INTERNAL AUXILIAR METHODS @@ -166,7 +166,7 @@ class DdsPipe * @param [in] topic : topic discovered */ void discovered_topic_( - const std::shared_ptr& topic) noexcept; + const utils::Heritable& topic) noexcept; /** * @brief Method called every time a new endpoint (corresponding to a server) has been discovered/updated @@ -225,7 +225,7 @@ class DdsPipe * @param [in] topic : new topic */ void create_new_bridge_( - const std::shared_ptr& topic, + const utils::Heritable& topic, bool enabled = false) noexcept; /** @@ -246,7 +246,7 @@ class DdsPipe * @param [in] topic : Topic to be enabled */ void activate_topic_( - const std::shared_ptr& topic) noexcept; + const utils::Heritable& topic) noexcept; /** * @brief Disable a specific topic. @@ -256,7 +256,7 @@ class DdsPipe * @param [in] topic : Topic to be disabled */ void deactivate_topic_( - const std::shared_ptr& topic) noexcept; + const utils::Heritable& topic) noexcept; /** * @brief Activate all Topics that are allowed by the allowed topics list @@ -306,7 +306,7 @@ class DdsPipe ///////////////////////// //! Map of bridges indexed by their topic - std::map, std::unique_ptr> bridges_; + std::map, std::unique_ptr> bridges_; //! Map of RPC bridges indexed by their topic std::map> rpc_bridges_; @@ -317,7 +317,7 @@ class DdsPipe * Every topic discovered would be added to this map. * If the value is true, it means this topic is currently activated. */ - std::map, bool> current_topics_; + std::map, bool> current_topics_; /** * @brief List of RPC topics discovered diff --git a/ddspipe_core/src/cpp/communication/Bridge.cpp b/ddspipe_core/src/cpp/communication/Bridge.cpp index 4e69527a7..09ec0744c 100644 --- a/ddspipe_core/src/cpp/communication/Bridge.cpp +++ b/ddspipe_core/src/cpp/communication/Bridge.cpp @@ -22,12 +22,10 @@ namespace ddspipe { namespace core { Bridge::Bridge( - const std::shared_ptr& topic, const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool) - : topic_(topic) - , participants_(participants_database) + : participants_(participants_database) , payload_pool_(payload_pool) , thread_pool_(thread_pool) , enabled_(false) diff --git a/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp index 70eec3a5f..61978e2c6 100644 --- a/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp +++ b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp @@ -24,11 +24,12 @@ namespace core { using namespace eprosima::ddspipe::core::types; DdsBridge::DdsBridge( - const std::shared_ptr& topic, + const utils::Heritable& topic, const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool) - : Bridge(topic, participants_database, payload_pool, thread_pool) + : Bridge(participants_database, payload_pool, thread_pool) + , topic_(topic) { logDebug(DDSROUTER_DDSBRIDGE, "Creating DdsBridge " << *this << "."); diff --git a/ddspipe_core/src/cpp/communication/dds/Track.cpp b/ddspipe_core/src/cpp/communication/dds/Track.cpp index d482e0835..2ceb14334 100644 --- a/ddspipe_core/src/cpp/communication/dds/Track.cpp +++ b/ddspipe_core/src/cpp/communication/dds/Track.cpp @@ -33,7 +33,7 @@ using namespace eprosima::ddspipe::core::types; const unsigned int Track::MAX_MESSAGES_TRANSMIT_LOOP_ = 100; Track::Track( - const std::shared_ptr& topic, + const utils::Heritable& topic, const types::ParticipantId& reader_participant_id, const std::shared_ptr& reader, std::map>&& writers, diff --git a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp index a0cb07714..3d9dc7db5 100644 --- a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp +++ b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp @@ -38,7 +38,7 @@ RPCBridge::RPCBridge( const std::shared_ptr& participants_database, const std::shared_ptr& payload_pool, const std::shared_ptr& thread_pool) - : Bridge(std::shared_ptr(), participants_database, payload_pool, thread_pool) + : Bridge(participants_database, payload_pool, thread_pool) , init_(false) , rpc_topic_(topic) { @@ -78,8 +78,7 @@ void RPCBridge::init_nts_() // TODO: This should not be done // Wait for the new entities created to match before sending data from one side to the other init_ = true; - utils::sleep_for(500); - + // utils::sleep_for(500); } void RPCBridge::create_proxy_server_nts_( diff --git a/ddspipe_core/src/cpp/core/DdsPipe.cpp b/ddspipe_core/src/cpp/core/DdsPipe.cpp index 132b621c9..93c2aa14f 100644 --- a/ddspipe_core/src/cpp/core/DdsPipe.cpp +++ b/ddspipe_core/src/cpp/core/DdsPipe.cpp @@ -36,7 +36,7 @@ DdsPipe::DdsPipe( const std::shared_ptr& payload_pool, const std::shared_ptr& participants_database, const std::shared_ptr& thread_pool, - const std::set>& builtin_topics /* = {} */) + const std::set>& builtin_topics /* = {} */) : allowed_topics_(allowed_topics) , discovery_database_(discovery_database) , payload_pool_(payload_pool) @@ -242,7 +242,7 @@ utils::ReturnCode DdsPipe::stop_() noexcept } } -void DdsPipe::init_bridges_(const std::set>& builtin_topics) +void DdsPipe::init_bridges_(const std::set>& builtin_topics) { for (const auto& topic : builtin_topics) { @@ -251,7 +251,7 @@ void DdsPipe::init_bridges_(const std::set& topic) noexcept + const utils::Heritable& topic) noexcept { std::lock_guard lock(mutex_); @@ -336,7 +336,7 @@ void DdsPipe::discovered_endpoint_( { if (!RpcTopic::is_service_topic(endpoint.topic)) { - discovered_topic_(std::make_shared(endpoint.topic)); + discovered_topic_(utils::Heritable::make_heritable(endpoint.topic)); } else if (endpoint.is_server_endpoint()) { @@ -363,7 +363,7 @@ void DdsPipe::removed_endpoint_( } void DdsPipe::create_new_bridge_( - const std::shared_ptr& topic, + const utils::Heritable& topic, bool enabled /*= false*/) noexcept { std::lock_guard lock(mutex_); @@ -399,7 +399,7 @@ void DdsPipe::create_new_service_( } void DdsPipe::activate_topic_( - const std::shared_ptr& topic) noexcept + const utils::Heritable& topic) noexcept { std::lock_guard lock(mutex_); @@ -424,7 +424,7 @@ void DdsPipe::activate_topic_( } void DdsPipe::deactivate_topic_( - const std::shared_ptr& topic) noexcept + const utils::Heritable& topic) noexcept { std::lock_guard lock(mutex_); diff --git a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp index 883027c93..ea1c756e8 100644 --- a/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp +++ b/ddsrouter_core/include/ddsrouter_core/core/DdsRouter.hpp @@ -121,10 +121,6 @@ class DdsRouter DdsRouterConfiguration configuration_; - std::unique_ptr ddspipe_; - - std::shared_ptr allowed_topics_; - std::shared_ptr discovery_database_; std::shared_ptr payload_pool_; @@ -133,6 +129,10 @@ class DdsRouter std::shared_ptr thread_pool_; + std::shared_ptr allowed_topics_; + + std::unique_ptr ddspipe_; + ParticipantFactory participant_factory_; }; diff --git a/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp index 3f1634be3..b4fe63c50 100644 --- a/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp @@ -79,7 +79,7 @@ bool DdsRouterConfiguration::is_valid( // Check that the configuration is of type required if (!check_correct_configuration_object_(configuration)) { - error_msg << "Participant " << configuration.second->id << " is not of correct Configuration class. "; + error_msg << "Participant " << configuration.second->id << " is not of correct Configuration class " << configuration.first << "."; return false; } diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp index 42f5ab8ec..0e19b7804 100644 --- a/ddsrouter_core/src/cpp/core/DdsRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -36,10 +36,10 @@ namespace core { DdsRouter::DdsRouter( const DdsRouterConfiguration& configuration) - : discovery_database_(new ddspipe::core::DiscoveryDatabase()) + : configuration_(configuration) + , discovery_database_(new ddspipe::core::DiscoveryDatabase()) , payload_pool_(new ddspipe::core::FastPayloadPool()) , participants_database_(new ddspipe::core::ParticipantsDatabase()) - , configuration_(configuration) , thread_pool_(std::make_shared(configuration_.advanced_options.number_of_threads)) { logDebug(DDSROUTER, "Creating DDS Router."); @@ -131,9 +131,11 @@ utils::ReturnCode DdsRouter::reload_configuration( "Configuration for Reload DDS Router is invalid: " << error_msg); } - return ddspipe_->reload_allowed_topics(std::make_shared( - configuration_.allowlist, - configuration_.blocklist)); + allowed_topics_ = std::make_shared( + new_configuration.allowlist, + new_configuration.blocklist); + + return ddspipe_->reload_allowed_topics(allowed_topics_); } utils::ReturnCode DdsRouter::start() noexcept diff --git a/ddsrouter_core/src/cpp/testing/random_values.cpp b/ddsrouter_core/src/cpp/testing/random_values.cpp index 335a77cb9..5f80416c2 100644 --- a/ddsrouter_core/src/cpp/testing/random_values.cpp +++ b/ddsrouter_core/src/cpp/testing/random_values.cpp @@ -67,7 +67,7 @@ std::shared_ptr random_participant_configuration( case ParticipantKind::initial_peers: { - auto c = std::make_shared(); + auto c = std::make_shared(); c->id = id; c->domain = random_domain(seed); c->listening_addresses = {random_address(seed)}; @@ -76,7 +76,7 @@ std::shared_ptr random_participant_configuration( case ParticipantKind::echo: { - auto c = std::make_shared(); + auto c = std::make_shared(); c->id = id; return c; } From b9e5e4a6b9e6b0ffa8ef5f703e08a5c564d8e345 Mon Sep 17 00:00:00 2001 From: jparisu Date: Thu, 16 Feb 2023 08:41:19 +0100 Subject: [PATCH 20/38] add windows dlls Signed-off-by: jparisu --- .../configuration/IConfiguration.hpp | 4 +- .../ddspipe_core/dynamic/AllowedTopicList.hpp | 16 +++---- .../dynamic/DiscoveryDatabase.hpp | 42 +++++++++---------- .../dynamic/ParticipantsDatabase.hpp | 18 ++++---- .../efficiency/payload/PayloadPool.hpp | 26 ++++++------ .../ddspipe_core/interface/IParticipant.hpp | 2 +- .../ddspipe_core/interface/IReader.hpp | 2 +- .../ddspipe_core/interface/IRoutingData.hpp | 2 +- .../include/ddspipe_core/interface/ITopic.hpp | 2 +- .../ddspipe_core/interface/IWriter.hpp | 2 +- .../ddspipe_core/testing/random_values.hpp | 16 +++---- .../types/data/RpcPayloadData.hpp | 2 +- .../types/data/RtpsPayloadData.hpp | 8 ++-- .../ddspipe_core/types/topic/Topic.hpp | 12 +++--- .../ddspipe_core/types/topic/dds/DdsTopic.hpp | 4 +- .../types/topic/dds/DistributedTopic.hpp | 2 +- .../ddspipe_core/types/topic/rpc/RpcTopic.hpp | 18 ++++---- .../participant/auxiliar/BlankParticipant.hpp | 14 ++++--- .../participant/auxiliar/EchoParticipant.hpp | 6 +-- .../participant/rtps/CommonParticipant.hpp | 21 +++++----- .../rtps/DiscoveryServerParticipant.hpp | 2 +- .../rtps/InitialPeersParticipant.hpp | 2 +- .../participant/rtps/SimpleParticipant.hpp | 2 +- .../reader/auxiliar/BaseReader.hpp | 22 +++++----- .../reader/auxiliar/BlankReader.hpp | 4 +- .../reader/rpc/SimpleReader.hpp | 7 ++-- .../reader/rtps/CommonReader.hpp | 17 ++++---- .../reader/rtps/SimpleReader.hpp | 3 +- .../reader/rtps/SpecificQoSReader.hpp | 3 +- .../testing/random_values.hpp | 5 ++- .../writer/auxiliar/BaseWriter.hpp | 8 ++-- .../writer/auxiliar/BlankWriter.hpp | 4 +- .../writer/auxiliar/RtpsEchoWriter.hpp | 3 +- .../writer/rpc/SimpleWriter.hpp | 7 ++-- .../writer/rtps/CommonWriter.hpp | 7 ++-- .../writer/rtps/MultiWriter.hpp | 5 ++- .../writer/rtps/QoSSpecificWriter.hpp | 3 +- .../writer/rtps/SimpleWriter.hpp | 3 +- .../writer/rtps/filter/RepeaterDataFilter.hpp | 3 +- .../writer/rtps/filter/SelfDataFilter.hpp | 4 +- 40 files changed, 179 insertions(+), 154 deletions(-) diff --git a/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp b/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp index a0821a7fb..2b37f90ea 100644 --- a/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp +++ b/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp @@ -27,9 +27,9 @@ namespace core { * Thus, they are not forced to be correct in construction. * This is an Interface class that forces every configuration to have an \c is_valid method. */ -struct IConfiguration +DDSPIPE_CORE_DllAPI struct IConfiguration { - DDSPIPE_CORE_DllAPI virtual bool is_valid( + virtual bool is_valid( utils::Formatter& error_msg) const noexcept = 0; }; diff --git a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp index ccf35d103..7ec744596 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp @@ -44,22 +44,22 @@ class AllowedTopicList public: //! Default constructor with empty lists - AllowedTopicList(); + DDSPIPE_CORE_DllAPI AllowedTopicList(); //! Constructor by initialization lists - AllowedTopicList( + DDSPIPE_CORE_DllAPI AllowedTopicList( const std::set>& allowlist, const std::set>& blocklist) noexcept; //! Copy constructor. It copies internal lists. - AllowedTopicList& operator =( + DDSPIPE_CORE_DllAPI AllowedTopicList& operator =( const AllowedTopicList& other); //! Destructor - virtual ~AllowedTopicList(); + DDSPIPE_CORE_DllAPI virtual ~AllowedTopicList(); //! Clear all topics in lists - void clear() noexcept; + DDSPIPE_CORE_DllAPI void clear() noexcept; /** * Whether topic \c topic is allowed by the lists that constitute this object @@ -73,7 +73,7 @@ class AllowedTopicList * * @return True if the topic is allowed, false otherwise */ - bool is_topic_allowed( + DDSPIPE_CORE_DllAPI bool is_topic_allowed( const ITopic& topic) const noexcept; /** @@ -87,7 +87,7 @@ class AllowedTopicList * * @return True if the topic is allowed, false otherwise */ - bool is_service_allowed( + DDSPIPE_CORE_DllAPI bool is_service_allowed( const types::RpcTopic& topic) const noexcept; /** @@ -102,7 +102,7 @@ class AllowedTopicList * * @return True if they are constituted by same topics, false otherwise */ - bool operator ==( + DDSPIPE_CORE_DllAPI bool operator ==( const AllowedTopicList& other) const noexcept; protected: diff --git a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp index e202c141d..4ba90b92a 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp @@ -35,7 +35,7 @@ namespace ddspipe { namespace core { //! Operations to perform on a DiscoveryDatabase -enum class DatabaseOperation +DDSPIPE_CORE_DllAPI enum class DatabaseOperation { add, update, @@ -55,14 +55,14 @@ class DiscoveryDatabase * Create a thread in charge of processing DB transactions stored in a queue. * Call \c start() function to enable the DiscoveryDatabase. */ - DiscoveryDatabase() noexcept; + DDSPIPE_CORE_DllAPI DiscoveryDatabase() noexcept; /** * @brief Destroy the DiscoveryDatabase object * * Signal and wait for the queue processing thread to stop. */ - ~DiscoveryDatabase(); + DDSPIPE_CORE_DllAPI ~DiscoveryDatabase(); /** * @brief Initialize the queue processing thread routine @@ -74,14 +74,14 @@ class DiscoveryDatabase * The builtin topics may have special topic configurations not detected in discovery * that would mean that the topic does not have the correct configuration. */ - void start() noexcept; + DDSPIPE_CORE_DllAPI void start() noexcept; /** * @brief Stop the queue processing thread routine * * Join the thread in charge of processing the dynamic discovery of endpoints. */ - void stop() noexcept; + DDSPIPE_CORE_DllAPI void stop() noexcept; /** * @brief Whether a topic exists in any Endpoint in the database @@ -89,11 +89,11 @@ class DiscoveryDatabase * @param [in] topic: topic to check if it exists * @return true if any endpoint has this topic, false otherwise */ - bool topic_exists( + DDSPIPE_CORE_DllAPI bool topic_exists( const types::DdsTopic& topic) const noexcept; //! Whether this guid is in the database - bool endpoint_exists( + DDSPIPE_CORE_DllAPI bool endpoint_exists( const types::Guid& guid) const noexcept; /** @@ -104,7 +104,7 @@ class DiscoveryDatabase * * @param [in] new_endpoint: new endpoint to store */ - void add_endpoint( + DDSPIPE_CORE_DllAPI void add_endpoint( const types::Endpoint& new_endpoint); /** @@ -115,7 +115,7 @@ class DiscoveryDatabase * * @param [in] endpoint_to_update: endpoint to update */ - void update_endpoint( + DDSPIPE_CORE_DllAPI void update_endpoint( const types::Endpoint& endpoint_to_update); /** @@ -126,7 +126,7 @@ class DiscoveryDatabase * * @param [in] endpoint_to_erase endpoint that will be erased */ - void erase_endpoint( + DDSPIPE_CORE_DllAPI void erase_endpoint( const types::Endpoint& endpoint_to_erase); /** @@ -136,7 +136,7 @@ class DiscoveryDatabase * @return Endpoint referring to this guid * @throw \c InconsistencyException in case there is no entry associated to this guid */ - types::Endpoint get_endpoint( + DDSPIPE_CORE_DllAPI types::Endpoint get_endpoint( const types::Guid& endpoint_guid) const; /** @@ -144,7 +144,7 @@ class DiscoveryDatabase * * @param [in] endpoint_discovered_callback: callback to add */ - void add_endpoint_discovered_callback( + DDSPIPE_CORE_DllAPI void add_endpoint_discovered_callback( std::function endpoint_discovered_callback) noexcept; /** @@ -152,7 +152,7 @@ class DiscoveryDatabase * * @param [in] endpoint_updated_callback: callback to add */ - void add_endpoint_updated_callback( + DDSPIPE_CORE_DllAPI void add_endpoint_updated_callback( std::function endpoint_updated_callback) noexcept; /** @@ -160,14 +160,14 @@ class DiscoveryDatabase * * @param [in] endpoint_erased_callback: callback to add */ - void add_endpoint_erased_callback( + DDSPIPE_CORE_DllAPI void add_endpoint_erased_callback( std::function endpoint_erased_callback) noexcept; /** * @brief Remove all callbacks from all types (endpoint discovered, updated and erased) * */ - void clear_all_callbacks() noexcept; + DDSPIPE_CORE_DllAPI void clear_all_callbacks() noexcept; protected: @@ -178,7 +178,7 @@ class DiscoveryDatabase * @return true if the endpoint has been added * @throw \c InconsistencyException in case an endpoint with the same guid already exists and is active */ - bool add_endpoint_( + DDSPIPE_CORE_DllAPI bool add_endpoint_( const types::Endpoint& new_endpoint); /** @@ -188,7 +188,7 @@ class DiscoveryDatabase * @return true if the endpoint has been updated * @throw \c InconsistencyException in case there is no entry associated to this endpoint */ - bool update_endpoint_( + DDSPIPE_CORE_DllAPI bool update_endpoint_( const types::Endpoint& endpoint_to_update); /** @@ -198,22 +198,22 @@ class DiscoveryDatabase * @return \c RETCODE_OK if correctly erased * @throw \c InconsistencyException in case there is no entry associated to this endpoint */ - utils::ReturnCode erase_endpoint_( + DDSPIPE_CORE_DllAPI utils::ReturnCode erase_endpoint_( const types::Endpoint& endpoint_to_erase); //! Routine performed by dedicated thread performing database operations - void queue_processing_thread_routine_() noexcept; + DDSPIPE_CORE_DllAPI void queue_processing_thread_routine_() noexcept; /** * @brief Add new operation to the queue \c entities_to_process_ * * @param [in] item: operation to add */ - void push_item_to_queue_( + DDSPIPE_CORE_DllAPI void push_item_to_queue_( std::tuple item) noexcept; //! Process queue storing database operations - void process_queue_() noexcept; + DDSPIPE_CORE_DllAPI void process_queue_() noexcept; //! Database of endpoints indexed by guid std::map entities_; diff --git a/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp index 23e59e5d2..406697813 100644 --- a/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp +++ b/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp @@ -34,14 +34,14 @@ class ParticipantsDatabase { public: - ParticipantsDatabase() = default; + DDSPIPE_CORE_DllAPI ParticipantsDatabase() = default; /** * Destructor * * @warning it should not be called if it is not empty */ - virtual ~ParticipantsDatabase(); + DDSPIPE_CORE_DllAPI virtual ~ParticipantsDatabase(); /** * @brief Get the participant pointer @@ -49,7 +49,7 @@ class ParticipantsDatabase * @param id: id of the participant * @return pointer to the participant */ - std::shared_ptr get_participant( + DDSPIPE_CORE_DllAPI std::shared_ptr get_participant( const types::ParticipantId& id) const noexcept; /** @@ -57,27 +57,27 @@ class ParticipantsDatabase * * @return set of ids */ - std::set get_participants_ids() const noexcept; + DDSPIPE_CORE_DllAPI std::set get_participants_ids() const noexcept; /** * @brief Get all the ids of the RPTS participants stored * * @return set of ids */ - std::set get_rtps_participants_ids() const noexcept; + DDSPIPE_CORE_DllAPI std::set get_rtps_participants_ids() const noexcept; /** * @brief Get all the participants stored * * @return map of pointers to participants indexed by ids */ - const std::map>& get_participants_map() const noexcept; + DDSPIPE_CORE_DllAPI const std::map>& get_participants_map() const noexcept; //! Whether the database is empty - bool empty() const noexcept; + DDSPIPE_CORE_DllAPI bool empty() const noexcept; //! Number of Participants in the Database - size_t size() const noexcept; + DDSPIPE_CORE_DllAPI size_t size() const noexcept; /** * @brief Add a new participant @@ -87,7 +87,7 @@ class ParticipantsDatabase * * @throw \c IncosistentException if participant already exist (duplicated ids) */ - void add_participant( + DDSPIPE_CORE_DllAPI void add_participant( const types::ParticipantId& id, const std::shared_ptr& participant); diff --git a/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp index 3c1207fe6..f0d73f941 100644 --- a/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp +++ b/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp @@ -43,10 +43,10 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool public: //! Construct an empty PayloadPool - PayloadPool(); + DDSPIPE_CORE_DllAPI PayloadPool(); //! Delete PayloadPool and erase every Payload still without release - virtual ~PayloadPool(); + DDSPIPE_CORE_DllAPI virtual ~PayloadPool(); ///// // FAST DDS PART @@ -70,7 +70,7 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @pre Fields @c cache_change must not have the serialized payload initialized. */ - bool get_payload( + DDSPIPE_CORE_DllAPI virtual bool get_payload( uint32_t size, eprosima::fastrtps::rtps::CacheChange_t& cache_change) override; // TODO add noexcept once is implemented @@ -98,7 +98,7 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @pre Fields @c cache_change must not have the serialized payload initialized. */ - bool get_payload( + DDSPIPE_CORE_DllAPI virtual bool get_payload( eprosima::fastrtps::rtps::SerializedPayload_t& data, IPayloadPool*& data_owner, eprosima::fastrtps::rtps::CacheChange_t& cache_change) override; // TODO add noexcept once is implemented @@ -118,7 +118,7 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @throw IncosistencyException if cache change owner is other than this */ - bool release_payload( + DDSPIPE_CORE_DllAPI virtual bool release_payload( eprosima::fastrtps::rtps::CacheChange_t& cache_change) override; // TODO add noexcept once is implemented ///// @@ -141,7 +141,7 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @pre Fields @c payload must not have been initialized. */ - virtual bool get_payload( + DDSPIPE_CORE_DllAPI virtual bool get_payload( uint32_t size, types::Payload& payload) = 0; @@ -165,7 +165,7 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @pre Fields @c target_payload must not have been initialized. */ - virtual bool get_payload( + DDSPIPE_CORE_DllAPI virtual bool get_payload( const types::Payload& src_payload, IPayloadPool*& data_owner, types::Payload& target_payload) = 0; @@ -186,11 +186,11 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @pre @c payload must have been initialized from this pool. */ - virtual bool release_payload( + DDSPIPE_CORE_DllAPI virtual bool release_payload( types::Payload& payload) = 0; //! Wether every payload get has been released. - virtual bool is_clean() const noexcept; + DDSPIPE_CORE_DllAPI virtual bool is_clean() const noexcept; protected: @@ -205,7 +205,7 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * @return true if everything ok * @return false if something went wrong */ - virtual bool reserve_( + DDSPIPE_CORE_DllAPI virtual bool reserve_( uint32_t size, types::Payload& payload); @@ -221,14 +221,14 @@ class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool * * @throw \c IncosistencyException if more releases than reserves has been done */ - virtual bool release_( + DDSPIPE_CORE_DllAPI virtual bool release_( types::Payload& payload); //! Increase \c reserve_count_ - void add_reserved_payload_(); + DDSPIPE_CORE_DllAPI void add_reserved_payload_(); //! Increase \c release_count_ . Show a warning if there are more releases than reserves. - void add_release_payload_(); + DDSPIPE_CORE_DllAPI void add_release_payload_(); //! Count the number of reserved data from this pool std::atomic reserve_count_; diff --git a/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp index 095d2d13b..6436df05a 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp @@ -33,7 +33,7 @@ namespace core { * * @note In order to implement new Participants, create a subclass of this Interface and implement every method. */ -class IParticipant +DDSPIPE_CORE_DllAPI class IParticipant { public: diff --git a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp index eb96afa2c..fd3fa33ec 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp @@ -40,7 +40,7 @@ namespace core { * * Readers will start being disabled. */ -class IReader +DDSPIPE_CORE_DllAPI class IReader { public: diff --git a/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp index ed6b72e9a..63cc8ed47 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp @@ -25,7 +25,7 @@ namespace core { /** * @brief TODO */ -class IRoutingData +DDSPIPE_CORE_DllAPI class IRoutingData { public: diff --git a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp index ce823fa05..e8149f5fb 100644 --- a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp @@ -29,7 +29,7 @@ namespace core { /** * Generic data struct that represents an ITopic of data flow in the Router. */ -class ITopic +DDSPIPE_CORE_DllAPI class ITopic { public: diff --git a/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp b/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp index 38ea88b64..39bc3b144 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp @@ -32,7 +32,7 @@ namespace core { * * Writers will start being disabled. */ -class IWriter +DDSPIPE_CORE_DllAPI class IWriter { public: diff --git a/ddspipe_core/include/ddspipe_core/testing/random_values.hpp b/ddspipe_core/include/ddspipe_core/testing/random_values.hpp index a1a47554b..05b7854f1 100644 --- a/ddspipe_core/include/ddspipe_core/testing/random_values.hpp +++ b/ddspipe_core/include/ddspipe_core/testing/random_values.hpp @@ -28,29 +28,29 @@ namespace ddspipe { namespace core { namespace testing { -types::Guid random_guid( +DDSPIPE_CORE_DllAPI types::Guid random_guid( unsigned int seed = 0); -types::DomainId random_domain( +DDSPIPE_CORE_DllAPI types::DomainId random_domain( unsigned int seed = 0); -types::GuidPrefix random_guid_prefix( +DDSPIPE_CORE_DllAPI types::GuidPrefix random_guid_prefix( unsigned int seed = 0, bool ros = false); -types::ParticipantId random_participant_id( +DDSPIPE_CORE_DllAPI types::ParticipantId random_participant_id( unsigned int seed = 0); -types::DdsTopic random_dds_topic( +DDSPIPE_CORE_DllAPI types::DdsTopic random_dds_topic( unsigned int seed = 0); -types::EndpointKind random_endpoint_kind( +DDSPIPE_CORE_DllAPI types::EndpointKind random_endpoint_kind( unsigned int seed = 0); -types::Endpoint random_endpoint( +DDSPIPE_CORE_DllAPI types::Endpoint random_endpoint( unsigned int seed = 0); -types::TopicQoS random_topic_qos( +DDSPIPE_CORE_DllAPI types::TopicQoS random_topic_qos( unsigned int seed = 0); } /* namespace testing */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp index 7d3418710..8b7a6c257 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp @@ -41,7 +41,7 @@ namespace types { struct RpcPayloadData : public RtpsPayloadData { - virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; + DDSPIPE_CORE_DllAPI virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; //! Write params associated to the received cache change utils::Fuzzy write_params{}; diff --git a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp index 5c2d8c223..e0c8d33af 100644 --- a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp +++ b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp @@ -40,18 +40,18 @@ namespace types { struct RtpsPayloadData : public core::IRoutingData { - RtpsPayloadData() = default; + DDSPIPE_CORE_DllAPI RtpsPayloadData() = default; /** * @brief Destroy the Rtps Payload Data object * * Free the memory for the payload in the corresponding payload pool (if defined). */ - virtual ~RtpsPayloadData(); + DDSPIPE_CORE_DllAPI virtual ~RtpsPayloadData(); - RtpsPayloadData(const RtpsPayloadData& ) = delete; + DDSPIPE_CORE_DllAPI RtpsPayloadData(const RtpsPayloadData& ) = delete; - virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; + DDSPIPE_CORE_DllAPI virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; //! Payload of the data received. The data in this payload must belong to the PayloadPool. core::types::Payload payload{}; diff --git a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp index e8ddf5904..29367c15c 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp @@ -51,20 +51,20 @@ struct Topic : public ITopic , public IConfiguration * * This is specialized so if the comparison object is a std Topic it is compared as it. */ - virtual bool operator==(const ITopic& other) const noexcept override; + DDSPIPE_CORE_DllAPI virtual bool operator==(const ITopic& other) const noexcept override; - virtual bool operator<(const ITopic& other) const noexcept override; + DDSPIPE_CORE_DllAPI virtual bool operator<(const ITopic& other) const noexcept override; ///////////////////////// // METHODS ///////////////////////// //! ITopic name - virtual std::string topic_name() const noexcept override; + DDSPIPE_CORE_DllAPI virtual std::string topic_name() const noexcept override; - virtual TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; + DDSPIPE_CORE_DllAPI virtual TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; - virtual bool is_valid( + DDSPIPE_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; ///////////////////////// @@ -72,7 +72,7 @@ struct Topic : public ITopic , public IConfiguration ///////////////////////// //! ITopic unique name in processs - virtual std::string topic_unique_name() const noexcept override; + DDSPIPE_CORE_DllAPI virtual std::string topic_unique_name() const noexcept override; ///////////////////////// // VARIABLES diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp index f8bdce918..78c7d9927 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp @@ -45,10 +45,10 @@ struct DdsTopic : public DistributedTopic // METHODS ///////////////////////// - virtual bool is_valid( + DDSPIPE_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; - virtual std::string topic_unique_name() const noexcept override; + DDSPIPE_CORE_DllAPI virtual std::string topic_unique_name() const noexcept override; ///////////////////////// // STATIC METHODS diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp index de75cb5b3..ae0914888 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp @@ -33,7 +33,7 @@ namespace types { * * @note this not represents a real DDS network topic, but an "abstract" distributed one. */ -struct DistributedTopic : public Topic +struct DDSPIPE_CORE_DllAPI DistributedTopic : public Topic { // Extend nothing }; diff --git a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp index fd07bb0b3..1876d2bd0 100644 --- a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp +++ b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp @@ -31,36 +31,36 @@ class RpcTopic public: //! Constructor by service name, request topic and reply topic - RpcTopic( + DDSPIPE_CORE_DllAPI RpcTopic( const std::string& service_name, const DdsTopic& topic_request, const DdsTopic& topic_reply) noexcept; //! Constructor by request/reply topic only (infers service name and the other request/reply topic) - RpcTopic( + DDSPIPE_CORE_DllAPI RpcTopic( const DdsTopic& topic) noexcept; - RpcTopic(const RpcTopic& other) noexcept; + DDSPIPE_CORE_DllAPI RpcTopic(const RpcTopic& other) noexcept; //! Service name getter - const std::string& service_name() const; + DDSPIPE_CORE_DllAPI const std::string& service_name() const; //! Request topic getter - const DdsTopic& request_topic() const; + DDSPIPE_CORE_DllAPI const DdsTopic& request_topic() const; //! Reply topic getter - const DdsTopic& reply_topic() const; + DDSPIPE_CORE_DllAPI const DdsTopic& reply_topic() const; //! Whether a topic is a request topic - static bool is_request_topic( + DDSPIPE_CORE_DllAPI static bool is_request_topic( const DdsTopic& topic); //! Whether a topic is a reply topic - static bool is_reply_topic( + DDSPIPE_CORE_DllAPI static bool is_reply_topic( const DdsTopic& topic); //! Whether a topic is a service topic (request or reply topic) - static bool is_service_topic( + DDSPIPE_CORE_DllAPI static bool is_service_topic( const DdsTopic& topic); /** diff --git a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp index be68f413d..84fa9cbba 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp @@ -16,6 +16,8 @@ #include +#include + namespace eprosima { namespace ddspipe { namespace participants { @@ -32,24 +34,24 @@ class BlankParticipant : public core::IParticipant public: //! Constructor with Id of this participant - BlankParticipant( + DDSPIPE_PARTICIPANTS_DllAPI BlankParticipant( const core::types::ParticipantId& id_); //! Override id() IParticipant method - core::types::ParticipantId id() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI core::types::ParticipantId id() const noexcept override; //! Override is_repeater() IParticipant method - bool is_repeater() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI bool is_repeater() const noexcept override; //! Override is_rtps_kind() IParticipant method - bool is_rtps_kind() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI bool is_rtps_kind() const noexcept override; //! Override create_writer() IParticipant method - std::shared_ptr create_writer( + DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( const core::ITopic& topic) override; //! Override create_reader() IParticipant method - std::shared_ptr create_reader( + DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_reader( const core::ITopic& topic) override; protected: diff --git a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp index 5474171c5..c4b183aef 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp @@ -31,16 +31,16 @@ class EchoParticipant : public BlankParticipant public: //! Using parent class constructors - EchoParticipant( + DDSPIPE_PARTICIPANTS_DllAPI EchoParticipant( const std::shared_ptr& participant_configuration, const std::shared_ptr& discovery_database); //! Print discovery information from endpoint discovered - void echo_discovery( + DDSPIPE_PARTICIPANTS_DllAPI void echo_discovery( core::types::Endpoint endpoint_discovered) const noexcept; //! Override create_writer() IParticipant method - std::shared_ptr create_writer( + DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( const core::ITopic& topic) override; protected: diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp index b9c0bd104..ca182542f 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp @@ -27,6 +27,7 @@ #include #include +#include #include namespace eprosima { @@ -55,7 +56,7 @@ class CommonParticipant // Protected ctor to make class abstract (only built by their childs). //! Remove internal RTPS Participant - virtual ~CommonParticipant(); + DDSPIPE_PARTICIPANTS_DllAPI virtual ~CommonParticipant(); /** * @brief Create the internal RTPS Participant using the attributes given. @@ -69,27 +70,27 @@ class CommonParticipant * @warning this method is not thread safe. * @pre this method can only be called once. */ - void init(); + DDSPIPE_PARTICIPANTS_DllAPI void init(); ///////////////////////// // I PARTICIPANT METHODS ///////////////////////// //! Implement parent method \c is_repeater . - bool is_repeater() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI bool is_repeater() const noexcept override; //! Implement parent method \c id . - core::types::ParticipantId id() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI core::types::ParticipantId id() const noexcept override; //! Implement parent method \c is_rtps_kind . - virtual bool is_rtps_kind() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_rtps_kind() const noexcept override; /** * @brief Create a writer object * * Depending on the Topic QoS creates a Basic or Specific Writer. */ - std::shared_ptr create_writer( + DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( const core::ITopic& topic) override; /** @@ -97,7 +98,7 @@ class CommonParticipant * * Depending on the Topic QoS creates a Basic or Specific Reader. */ - std::shared_ptr create_reader( + DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_reader( const core::ITopic& topic) override; ///////////////////////// @@ -109,7 +110,7 @@ class CommonParticipant * * This method only is for debugging purposes. */ - virtual void onParticipantDiscovery( + DDSPIPE_PARTICIPANTS_DllAPI virtual void onParticipantDiscovery( fastrtps::rtps::RTPSParticipant* participant, fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; @@ -118,7 +119,7 @@ class CommonParticipant * * This method adds to database the endpoint discovered or modified. */ - virtual void onReaderDiscovery( + DDSPIPE_PARTICIPANTS_DllAPI virtual void onReaderDiscovery( fastrtps::rtps::RTPSParticipant* participant, fastrtps::rtps::ReaderDiscoveryInfo&& info) override; @@ -127,7 +128,7 @@ class CommonParticipant * * This method adds to database the endpoint discovered or modified. */ - virtual void onWriterDiscovery( + DDSPIPE_PARTICIPANTS_DllAPI virtual void onWriterDiscovery( fastrtps::rtps::RTPSParticipant* participant, fastrtps::rtps::WriterDiscoveryInfo&& info) override; diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp index cfb204771..87d2fd83a 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp @@ -33,7 +33,7 @@ class DiscoveryServerParticipant { public: - DiscoveryServerParticipant( + DDSPIPE_PARTICIPANTS_DllAPI DiscoveryServerParticipant( const std::shared_ptr& participant_configuration, const std::shared_ptr& payload_pool, const std::shared_ptr& discovery_database); diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp index c09e3e305..c195a5fc5 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp @@ -34,7 +34,7 @@ class InitialPeersParticipant { public: - InitialPeersParticipant( + DDSPIPE_PARTICIPANTS_DllAPI InitialPeersParticipant( const std::shared_ptr& participant_configuration, const std::shared_ptr& payload_pool, const std::shared_ptr& discovery_database); diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp index de3ffb3d1..05bee417d 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp @@ -41,7 +41,7 @@ class SimpleParticipant : public CommonParticipant * @throw \c InitializationException in case any internal error has ocurred while creating RTPSParticipant * @throw \c IConfigurationException in case configuration was incorrectly set */ - SimpleParticipant( + DDSPIPE_PARTICIPANTS_DllAPI SimpleParticipant( const std::shared_ptr& participant_configuration, const std::shared_ptr& payload_pool, const std::shared_ptr& discovery_database); diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp index 17ec4d7c7..8142cb45e 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp @@ -22,6 +22,8 @@ #include #include +#include + namespace eprosima { namespace ddspipe { namespace participants { @@ -60,7 +62,7 @@ class BaseReader : public core::IReader * * Thread safe with mutex \c mutex_ . */ - void enable() noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI void enable() noexcept override; /** * @brief Set this Reader as disabled @@ -72,7 +74,7 @@ class BaseReader : public core::IReader * * Thread safe with mutex \c mutex_ . */ - void disable() noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI void disable() noexcept override; /** * @brief Set the on_data_available callback @@ -83,7 +85,7 @@ class BaseReader : public core::IReader * * @param [in] on_data_available_lambda new callback to notify data received */ - void set_on_data_available_callback( + DDSPIPE_PARTICIPANTS_DllAPI void set_on_data_available_callback( std::function on_data_available_lambda) noexcept override; /** @@ -95,7 +97,7 @@ class BaseReader : public core::IReader * * @param [in] on_data_available_lambda new callback to notify data received */ - void unset_on_data_available_callback() noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI void unset_on_data_available_callback() noexcept override; /** * @brief Override take() IReader method @@ -105,7 +107,7 @@ class BaseReader : public core::IReader * * Thread safe with mutex \c mutex_ . */ - utils::ReturnCode take( + DDSPIPE_PARTICIPANTS_DllAPI utils::ReturnCode take( std::unique_ptr& data) noexcept override; ///////////////////////// @@ -113,7 +115,7 @@ class BaseReader : public core::IReader ///////////////////////// //! Getter of \c participant_id_ attribute - core::types::ParticipantId participant_id() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI core::types::ParticipantId participant_id() const noexcept override; ///////////////////////// // RPC REQUIRED METHODS @@ -121,15 +123,15 @@ class BaseReader : public core::IReader // TODO remove these methods once the double reference is solved //! Get GUID of internal RTPS reader - core::types::Guid guid() const override = 0; + DDSPIPE_PARTICIPANTS_DllAPI core::types::Guid guid() const override = 0; //! Get internal RTPS reader mutex - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override = 0; + DDSPIPE_PARTICIPANTS_DllAPI fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override = 0; //! Get number of unread cache changes in internal RTPS reader - uint64_t get_unread_count() const override = 0; + DDSPIPE_PARTICIPANTS_DllAPI uint64_t get_unread_count() const override = 0; - core::types::DdsTopic topic() const override = 0; + DDSPIPE_PARTICIPANTS_DllAPI core::types::DdsTopic topic() const override = 0; ///////////////////////// protected: diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp index 5e94f5a0e..f3a66ebcf 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp @@ -16,6 +16,8 @@ #include +#include + namespace eprosima { namespace ddspipe { namespace participants { @@ -25,7 +27,7 @@ namespace participants { * It does not receive anything. * It does not have messages to take. */ -class BlankReader : public core::IReader +DDSPIPE_PARTICIPANTS_DllAPI class BlankReader : public core::IReader { public: diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp index 06365ebfd..16a3bd98f 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp @@ -16,6 +16,7 @@ #include +#include #include namespace eprosima { @@ -42,18 +43,18 @@ class SimpleReader : public rtps::CommonReader * * @throw \c InitializationException in case any creation has failed */ - SimpleReader( + DDSPIPE_PARTICIPANTS_DllAPI SimpleReader( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, fastrtps::rtps::RTPSParticipant* rtps_participant); //! Override Parent method to create an RPC data type. - virtual core::types::RtpsPayloadData* create_data_( + DDSPIPE_PARTICIPANTS_DllAPI virtual core::types::RtpsPayloadData* create_data_( const fastrtps::rtps::CacheChange_t& received_change) const noexcept override; //! Override Parent method to fill fields exclusive from RPC. - virtual void fill_received_data_( + DDSPIPE_PARTICIPANTS_DllAPI virtual void fill_received_data_( const fastrtps::rtps::CacheChange_t& received_change, core::types::RtpsPayloadData& data_to_fill) const noexcept override; }; diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp index 2d7460321..32f8b9ac6 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp @@ -31,6 +31,7 @@ #include #include +#include #include namespace eprosima { @@ -60,7 +61,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * * Delete the RTPS CommonReader and CommonReader History in case they are set. */ - virtual ~CommonReader(); + DDSPIPE_PARTICIPANTS_DllAPI virtual ~CommonReader(); /** * @brief Create the internal RTPS Reader. @@ -74,7 +75,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * @warning this method is not thread safe. * @pre this method can only be called once. */ - void init(); + DDSPIPE_PARTICIPANTS_DllAPI void init(); ///////////////////////// // RTPS LISTENER METHODS @@ -89,7 +90,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * * @param [in] change new change received */ - void onNewCacheChangeAdded( + DDSPIPE_PARTICIPANTS_DllAPI void onNewCacheChangeAdded( fastrtps::rtps::RTPSReader*, const fastrtps::rtps::CacheChange_t* const change) noexcept override; @@ -101,7 +102,7 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener * * @param [in] info information about the matched Writer */ - void onReaderMatched( + DDSPIPE_PARTICIPANTS_DllAPI void onReaderMatched( fastrtps::rtps::RTPSReader*, fastrtps::rtps::MatchingInfo& info) noexcept override; @@ -111,15 +112,15 @@ class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener // TODO remove these methods once the double reference is solved //! Get GUID of internal RTPS reader - core::types::Guid guid() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI core::types::Guid guid() const noexcept override; //! Get internal RTPS reader mutex - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept override; //! Get number of unread cache changes in internal RTPS reader - uint64_t get_unread_count() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI uint64_t get_unread_count() const noexcept override; - core::types::DdsTopic topic() const noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI core::types::DdsTopic topic() const noexcept override; protected: diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp index 36b452df7..edd93e2e0 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp @@ -14,6 +14,7 @@ #pragma once +#include #include namespace eprosima { @@ -40,7 +41,7 @@ class SimpleReader : public CommonReader * * @throw \c InitializationException in case any creation has failed */ - SimpleReader( + DDSPIPE_PARTICIPANTS_DllAPI SimpleReader( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp index aa4ce45cc..99f7dab2d 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp @@ -16,6 +16,7 @@ #include +#include #include namespace eprosima { @@ -45,7 +46,7 @@ class SpecificQoSReader : public CommonReader * * @throw \c InitializationException in case any creation has failed */ - SpecificQoSReader( + DDSPIPE_PARTICIPANTS_DllAPI SpecificQoSReader( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, diff --git a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp index daeec7eec..bee590c0a 100644 --- a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp +++ b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp @@ -14,6 +14,7 @@ #pragma once +#include #include #include @@ -22,10 +23,10 @@ namespace ddspipe { namespace participants { namespace testing { -types::Address random_address( +DDSPIPE_PARTICIPANTS_DllAPI types::Address random_address( unsigned int seed = 0); -types::DiscoveryServerConnectionAddress random_connection_address( +DDSPIPE_PARTICIPANTS_DllAPI types::DiscoveryServerConnectionAddress random_connection_address( unsigned int seed = 0, unsigned int size = 1, bool ros = false); diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp index db7307a33..7912aab2f 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp @@ -23,6 +23,8 @@ #include #include +#include + namespace eprosima { namespace ddspipe { namespace participants { @@ -57,7 +59,7 @@ class BaseWriter : public core::IWriter * * Thread safe with mutex \c mutex_ . */ - void enable() noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI void enable() noexcept override; /** * @brief Set this Writer as disabled @@ -69,7 +71,7 @@ class BaseWriter : public core::IWriter * * Thread safe with mutex \c mutex_ . */ - void disable() noexcept override; + DDSPIPE_PARTICIPANTS_DllAPI void disable() noexcept override; /** * @brief Override write() IWriter method @@ -79,7 +81,7 @@ class BaseWriter : public core::IWriter * * Thread safe with mutex \c mutex_ . */ - virtual utils::ReturnCode write( + DDSPIPE_PARTICIPANTS_DllAPI virtual utils::ReturnCode write( core::IRoutingData& data) noexcept override; protected: diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp index a51e00ed7..093240db9 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp @@ -16,6 +16,8 @@ #include +#include + namespace eprosima { namespace ddspipe { namespace participants { @@ -24,7 +26,7 @@ namespace participants { * Writer that has an empty implementation. * It does not send anything. */ -class BlankWriter : public core::IWriter +DDSPIPE_PARTICIPANTS_DllAPI class BlankWriter : public core::IWriter { public: diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp index 3885cee8f..082926bbb 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp @@ -19,6 +19,7 @@ #include #include +#include #include namespace eprosima { @@ -33,7 +34,7 @@ class RtpsEchoWriter : public BlankWriter public: //! Using parent class constructors - RtpsEchoWriter( + DDSPIPE_PARTICIPANTS_DllAPI RtpsEchoWriter( const core::types::DdsTopic& topic, bool verbose); diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp index 938bfcc2c..7a873d303 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp @@ -24,6 +24,7 @@ #include +#include #include #include @@ -54,7 +55,7 @@ class SimpleWriter : public rtps::CommonWriter * * @throw \c InitializationException in case any creation has failed */ - SimpleWriter( + DDSPIPE_PARTICIPANTS_DllAPI SimpleWriter( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, @@ -62,13 +63,13 @@ class SimpleWriter : public rtps::CommonWriter const bool repeater = false); //! Override Parent method to fill fields only required for RPC. - virtual utils::ReturnCode fill_to_send_data_( + DDSPIPE_PARTICIPANTS_DllAPI virtual utils::ReturnCode fill_to_send_data_( fastrtps::rtps::CacheChange_t* to_send_change_to_fill, eprosima::fastrtps::rtps::WriteParams& to_send_params, const core::types::RtpsPayloadData& data) const noexcept; //! Override Parent method to fill fields after message is sent only required for RPC. - virtual void fill_sent_data_( + DDSPIPE_PARTICIPANTS_DllAPI virtual void fill_sent_data_( const eprosima::fastrtps::rtps::WriteParams& sent_params, core::types::RtpsPayloadData& data_to_fill) const noexcept; }; diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp index 53c95b4eb..8f836a67e 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -77,7 +78,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * * Delete the RTPS Writer and Writer History in case they are set. */ - virtual ~CommonWriter(); + DDSPIPE_PARTICIPANTS_DllAPI virtual ~CommonWriter(); /** * @brief Create the internal RTPS Writer. @@ -91,7 +92,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * @warning this method is not thread safe. * @pre this method can only be called once. */ - void init(); + DDSPIPE_PARTICIPANTS_DllAPI void init(); ///////////////////////// // RTPS LISTENER METHODS @@ -105,7 +106,7 @@ class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener * * @param [in] info information about the matched Reader */ - void onWriterMatched( + DDSPIPE_PARTICIPANTS_DllAPI void onWriterMatched( fastrtps::rtps::RTPSWriter*, fastrtps::rtps::MatchingInfo& info) noexcept override; diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp index e01b6cbde..f2e0912e1 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -49,7 +50,7 @@ class MultiWriter : public BaseWriter * * @throw \c InitializationException in case any creation has failed */ - MultiWriter( + DDSPIPE_PARTICIPANTS_DllAPI MultiWriter( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, @@ -64,7 +65,7 @@ class MultiWriter : public BaseWriter * * @todo Remove every change and release it in PayloadPool */ - virtual ~MultiWriter(); + DDSPIPE_PARTICIPANTS_DllAPI virtual ~MultiWriter(); protected: diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp index 915597f89..77e69fa41 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp @@ -14,6 +14,7 @@ #pragma once +#include #include namespace eprosima { @@ -42,7 +43,7 @@ class QoSSpecificWriter : public CommonWriter * * @throw \c InitializationException in case any creation has failed */ - QoSSpecificWriter( + DDSPIPE_PARTICIPANTS_DllAPI QoSSpecificWriter( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp index bde22b6c1..065753321 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp @@ -24,6 +24,7 @@ #include +#include #include #include @@ -54,7 +55,7 @@ class SimpleWriter : public CommonWriter * * @throw \c InitializationException in case any creation has failed */ - SimpleWriter( + DDSPIPE_PARTICIPANTS_DllAPI SimpleWriter( const core::types::ParticipantId& participant_id, const core::types::DdsTopic& topic, const std::shared_ptr& payload_pool, diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp index 4e7d66d07..fd415f539 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp @@ -14,6 +14,7 @@ #pragma once +#include #include namespace eprosima { @@ -29,7 +30,7 @@ namespace rtps { * * This uses the RouterCacheChange extra information. */ -class RepeaterDataFilter : public SelfDataFilter +DDSPIPE_PARTICIPANTS_DllAPI class RepeaterDataFilter : public SelfDataFilter { public: diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp index f4cf2248f..7d9f017fa 100644 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp +++ b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp @@ -16,6 +16,8 @@ #include +#include + ///// // Forward declarations namespace eprosima { @@ -37,7 +39,7 @@ namespace rtps { /** * This filter allows to not send messages from this Writer to the Readers in the same Participant. */ -class SelfDataFilter : public fastdds::rtps::IReaderDataFilter +DDSPIPE_PARTICIPANTS_DllAPI class SelfDataFilter : public fastdds::rtps::IReaderDataFilter { public: From d355b211f14299038675287afb1c38fb1fc56da5 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 17 Feb 2023 09:40:54 +0100 Subject: [PATCH 21/38] remove ddspipe Signed-off-by: jparisu --- ddspipe_core/CMakeLists.txt | 78 --- ddspipe_core/README.md | 55 -- .../ddspipe_core/communication/Bridge.hpp | 89 --- .../communication/dds/DdsBridge.hpp | 108 ---- .../ddspipe_core/communication/dds/Track.hpp | 226 -------- .../communication/rpc/RPCBridge.hpp | 208 ------- .../communication/rpc/ServiceRegistry.hpp | 114 ---- .../configuration/IConfiguration.hpp | 38 -- .../include/ddspipe_core/core/DdsPipe.hpp | 346 ----------- .../ddspipe_core/dynamic/AllowedTopicList.hpp | 141 ----- .../dynamic/DiscoveryDatabase.hpp | 257 --------- .../dynamic/ParticipantsDatabase.hpp | 105 ---- .../efficiency/payload/CopyPayloadPool.hpp | 53 -- .../efficiency/payload/FastPayloadPool.hpp | 143 ----- .../efficiency/payload/MapPayloadPool.hpp | 112 ---- .../efficiency/payload/PayloadPool.hpp | 241 -------- .../ddspipe_core/interface/IParticipant.hpp | 93 --- .../ddspipe_core/interface/IReader.hpp | 129 ----- .../ddspipe_core/interface/IRoutingData.hpp | 47 -- .../include/ddspipe_core/interface/ITopic.hpp | 62 -- .../ddspipe_core/interface/IWriter.hpp | 85 --- .../testing/entities/blank_entities.hpp | 104 ---- .../testing/entities/mock_entities.hpp | 90 --- .../ddspipe_core/testing/random_values.hpp | 59 -- .../types/data/RpcPayloadData.hpp | 64 --- .../types/data/RtpsPayloadData.hpp | 93 --- .../ddspipe_core/types/dds/DomainId.hpp | 70 --- .../ddspipe_core/types/dds/Endpoint.hpp | 101 ---- .../include/ddspipe_core/types/dds/Guid.hpp | 64 --- .../ddspipe_core/types/dds/GuidPrefix.hpp | 115 ---- .../ddspipe_core/types/dds/Payload.hpp | 68 --- .../types/dds/SpecificEndpointQoS.hpp | 95 --- .../ddspipe_core/types/dds/TopicQoS.hpp | 158 ----- .../types/participant/ParticipantId.hpp | 36 -- .../ddspipe_core/types/topic/Topic.hpp | 107 ---- .../topic/TopicInternalTypeDiscriminator.hpp | 37 -- .../ddspipe_core/types/topic/dds/DdsTopic.hpp | 89 --- .../types/topic/dds/DistributedTopic.hpp | 44 -- .../types/topic/filter/IFilterTopic.hpp | 101 ---- .../topic/filter/WildcardDdsFilterTopic.hpp | 95 --- .../ddspipe_core/types/topic/rpc/RpcTopic.hpp | 105 ---- ddspipe_core/package.xml | 31 - ddspipe_core/project_settings.cmake | 34 -- ddspipe_core/src/cpp/communication/Bridge.cpp | 37 -- .../src/cpp/communication/dds/DdsBridge.cpp | 138 ----- .../src/cpp/communication/dds/Track.cpp | 241 -------- .../src/cpp/communication/rpc/RPCBridge.cpp | 465 --------------- .../cpp/communication/rpc/ServiceRegistry.cpp | 128 ----- ddspipe_core/src/cpp/core/DdsPipe.cpp | 470 --------------- .../src/cpp/dynamic/AllowedTopicList.cpp | 185 ------ .../src/cpp/dynamic/DiscoveryDatabase.cpp | 347 ----------- .../src/cpp/dynamic/ParticipantsDatabase.cpp | 111 ---- .../efficiency/payload/CopyPayloadPool.cpp | 66 --- .../efficiency/payload/FastPayloadPool.cpp | 155 ----- .../cpp/efficiency/payload/MapPayloadPool.cpp | 144 ----- .../cpp/efficiency/payload/PayloadPool.cpp | 173 ------ .../cpp/testing/entities/blank_entities.cpp | 25 - .../src/cpp/testing/random_values.cpp | 144 ----- .../src/cpp/types/data/RpcPayloadData.cpp | 30 - .../src/cpp/types/data/RtpsPayloadData.cpp | 39 -- ddspipe_core/src/cpp/types/dds/DomainId.cpp | 60 -- ddspipe_core/src/cpp/types/dds/Endpoint.cpp | 70 --- ddspipe_core/src/cpp/types/dds/Guid.cpp | 58 -- ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp | 87 --- ddspipe_core/src/cpp/types/dds/Payload.cpp | 57 -- .../src/cpp/types/dds/SpecificEndpointQoS.cpp | 111 ---- ddspipe_core/src/cpp/types/dds/TopicQoS.cpp | 159 ----- ddspipe_core/src/cpp/types/topic/Topic.cpp | 99 ---- .../src/cpp/types/topic/dds/DdsTopic.cpp | 111 ---- .../cpp/types/topic/filter/IFilterTopic.cpp | 46 -- .../topic/filter/WildcardDdsFilterTopic.cpp | 93 --- .../src/cpp/types/topic/rpc/RpcTopic.cpp | 169 ------ ddspipe_core/test/CMakeLists.txt | 17 - ddspipe_core/test/unittest/CMakeLists.txt | 19 - .../test/unittest/core/CMakeLists.txt | 15 - .../core/participants_database/CMakeLists.txt | 52 -- .../ParticipantsDatabaseTest.cpp | 235 -------- .../test/unittest/dynamic/CMakeLists.txt | 15 - .../AllowedTopicListTest.cpp | 514 ----------------- .../dynamic/allowed_topic_list/CMakeLists.txt | 53 -- .../test/unittest/efficiency/CMakeLists.txt | 118 ---- .../efficiency/FastPayloadPoolTest.cpp | 324 ----------- .../efficiency/MapPayloadPoolTest.cpp | 366 ------------ .../unittest/efficiency/PayloadPoolTest.cpp | 412 ------------- .../test/unittest/types/CMakeLists.txt | 16 - .../unittest/types/endpoint/CMakeLists.txt | 81 --- .../unittest/types/endpoint/EndpointTest.cpp | 87 --- .../test/unittest/types/endpoint/GuidTest.cpp | 92 --- .../test/unittest/types/topic/CMakeLists.txt | 83 --- .../unittest/types/topic/DdsTopicTest.cpp | 94 --- .../topic/WildcardDdsFilterTopicTest.cpp | 215 ------- ddspipe_participants/CMakeLists.txt | 78 --- ddspipe_participants/README.md | 53 -- ...iscoveryServerParticipantConfiguration.hpp | 64 --- .../EchoParticipantConfiguration.hpp | 45 -- .../InitialPeersParticipantConfiguration.hpp | 62 -- .../ParticipantConfiguration.hpp | 52 -- .../SimpleParticipantConfiguration.hpp | 53 -- .../cache_change/CacheChangePool.hpp | 64 --- .../participant/auxiliar/BlankParticipant.hpp | 65 --- .../participant/auxiliar/EchoParticipant.hpp | 59 -- .../participant/rtps/CommonParticipant.hpp | 206 ------- .../rtps/DiscoveryServerParticipant.hpp | 51 -- .../rtps/InitialPeersParticipant.hpp | 52 -- .../participant/rtps/SimpleParticipant.hpp | 53 -- .../reader/auxiliar/BaseReader.hpp | 236 -------- .../reader/auxiliar/BlankReader.hpp | 73 --- .../reader/rpc/SimpleReader.hpp | 65 --- .../reader/rtps/CommonReader.hpp | 273 --------- .../reader/rtps/SimpleReader.hpp | 54 -- .../reader/rtps/SpecificQoSReader.hpp | 80 --- .../testing/random_values.hpp | 37 -- .../types/address/Address.hpp | 258 --------- .../DiscoveryServerConnectionAddress.hpp | 89 --- .../types/dds/RouterCacheChange.hpp | 54 -- .../types/security/tls/TlsConfiguration.hpp | 119 ---- .../writer/auxiliar/BaseWriter.hpp | 164 ------ .../writer/auxiliar/BlankWriter.hpp | 46 -- .../writer/auxiliar/RtpsEchoWriter.hpp | 61 -- .../writer/rpc/SimpleWriter.hpp | 80 --- .../writer/rtps/CommonWriter.hpp | 266 --------- .../writer/rtps/MultiWriter.hpp | 110 ---- .../writer/rtps/QoSSpecificWriter.hpp | 68 --- .../writer/rtps/SimpleWriter.hpp | 70 --- .../writer/rtps/filter/RepeaterDataFilter.hpp | 52 -- .../writer/rtps/filter/SelfDataFilter.hpp | 61 -- ddspipe_participants/package.xml | 32 -- ddspipe_participants/project_settings.cmake | 35 -- ...iscoveryServerParticipantConfiguration.cpp | 99 ---- .../InitialPeersParticipantConfiguration.cpp | 91 --- .../ParticipantConfiguration.cpp | 39 -- .../SimpleParticipantConfiguration.cpp | 42 -- .../cache_change/CacheChangePool.cpp | 48 -- .../participant/auxiliar/BlankParticipant.cpp | 59 -- .../participant/auxiliar/EchoParticipant.cpp | 81 --- .../participant/rtps/CommonParticipant.cpp | 437 -------------- .../rtps/DiscoveryServerParticipant.cpp | 362 ------------ .../rtps/InitialPeersParticipant.cpp | 337 ----------- .../participant/rtps/SimpleParticipant.cpp | 43 -- .../src/cpp/reader/auxiliar/BaseReader.cpp | 151 ----- .../src/cpp/reader/auxiliar/BlankReader.cpp | 73 --- .../src/cpp/reader/rpc/SimpleReader.cpp | 69 --- .../src/cpp/reader/rtps/CommonReader.cpp | 446 -------------- .../src/cpp/reader/rtps/SimpleReader.cpp | 44 -- .../src/cpp/reader/rtps/SpecificQoSReader.cpp | 78 --- .../src/cpp/testing/random_values.cpp | 53 -- .../src/cpp/types/address/Address.cpp | 438 -------------- .../DiscoveryServerConnectionAddress.cpp | 96 ---- .../types/security/tls/TlsConfiguration.cpp | 204 ------- .../src/cpp/writer/auxiliar/BaseWriter.cpp | 97 ---- .../src/cpp/writer/auxiliar/BlankWriter.cpp | 38 -- .../cpp/writer/auxiliar/RtpsEchoWriter.cpp | 70 --- .../src/cpp/writer/rpc/SimpleWriter.cpp | 87 --- .../src/cpp/writer/rtps/CommonWriter.cpp | 410 ------------- .../src/cpp/writer/rtps/MultiWriter.cpp | 165 ------ .../src/cpp/writer/rtps/QoSSpecificWriter.cpp | 71 --- .../src/cpp/writer/rtps/SimpleWriter.cpp | 53 -- .../writer/rtps/filter/RepeaterDataFilter.cpp | 58 -- .../cpp/writer/rtps/filter/SelfDataFilter.cpp | 39 -- ddspipe_participants/test/CMakeLists.txt | 15 - ddspipe_yaml/CMakeLists.txt | 78 --- ddspipe_yaml/README.md | 42 -- ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp | 30 - .../include/ddspipe_yaml/YamlManager.hpp | 37 -- .../include/ddspipe_yaml/YamlReader.hpp | 252 -------- .../include/ddspipe_yaml/impl/YamlReader.ipp | 241 -------- .../ddspipe_yaml/testing/generate_yaml.hpp | 206 ------- .../ddspipe_yaml/yaml_configuration_tags.hpp | 107 ---- ddspipe_yaml/package.xml | 34 -- ddspipe_yaml/project_settings.cmake | 35 -- ddspipe_yaml/src/cpp/YamlManager.cpp | 46 -- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 122 ---- .../src/cpp/YamlReader_participants.cpp | 258 --------- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 544 ------------------ ddspipe_yaml/test/CMakeLists.txt | 16 - ddspipe_yaml/test/unittest/CMakeLists.txt | 20 - .../test/unittest/entities/CMakeLists.txt | 22 - .../unittest/entities/address/CMakeLists.txt | 85 --- .../address/YamlGetEntityAddressTest.cpp | 36 -- ...amlGetEntityDiscoveryServerAddressTest.cpp | 30 - ...EntityAddressTest_get_address_defaults.ipp | 74 --- ...etEntityAddressTest_get_address_domain.ipp | 88 --- ...amlGetEntityAddressTest_get_address_ip.ipp | 110 ---- .../YamlGetEntityAddressTest_get_ip.ipp | 68 --- ...amlGetEntityAddressTest_get_ip_version.ipp | 101 ---- .../YamlGetEntityAddressTest_get_port.ipp | 78 --- ...tityAddressTest_get_transport_protocol.ipp | 114 ---- ...YamlGetEntityAddressTest_ip_and_domain.ipp | 65 --- ...coveryServerAddressTest_get_ds_address.ipp | 125 ---- ...verAddressTest_get_ds_address_negative.ipp | 140 ----- .../unittest/entities/guid/CMakeLists.txt | 49 -- .../guid/YamlGetEntityGuidPrefixTest.cpp | 278 --------- .../unittest/entities/topic/CMakeLists.txt | 49 -- .../entities/topic/YamlGetEntityTopicTest.cpp | 318 ---------- .../test/unittest/yaml_reader/CMakeLists.txt | 49 -- .../yaml_reader/YamlReaderScalarTest.cpp | 243 -------- ddsrouter_core/src/cpp/core/DdsRouter.cpp | 4 +- 197 files changed, 2 insertions(+), 23241 deletions(-) delete mode 100644 ddspipe_core/CMakeLists.txt delete mode 100644 ddspipe_core/README.md delete mode 100644 ddspipe_core/include/ddspipe_core/communication/Bridge.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/interface/IReader.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/interface/ITopic.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/interface/IWriter.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/testing/random_values.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp delete mode 100644 ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp delete mode 100644 ddspipe_core/package.xml delete mode 100644 ddspipe_core/project_settings.cmake delete mode 100644 ddspipe_core/src/cpp/communication/Bridge.cpp delete mode 100644 ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp delete mode 100644 ddspipe_core/src/cpp/communication/dds/Track.cpp delete mode 100644 ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp delete mode 100644 ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp delete mode 100644 ddspipe_core/src/cpp/core/DdsPipe.cpp delete mode 100644 ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp delete mode 100644 ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp delete mode 100644 ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp delete mode 100644 ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp delete mode 100644 ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp delete mode 100644 ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp delete mode 100644 ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp delete mode 100644 ddspipe_core/src/cpp/testing/entities/blank_entities.cpp delete mode 100644 ddspipe_core/src/cpp/testing/random_values.cpp delete mode 100644 ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp delete mode 100644 ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/DomainId.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/Endpoint.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/Guid.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/Payload.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/SpecificEndpointQoS.cpp delete mode 100644 ddspipe_core/src/cpp/types/dds/TopicQoS.cpp delete mode 100644 ddspipe_core/src/cpp/types/topic/Topic.cpp delete mode 100644 ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp delete mode 100644 ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp delete mode 100644 ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp delete mode 100644 ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp delete mode 100644 ddspipe_core/test/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/core/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/core/participants_database/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp delete mode 100644 ddspipe_core/test/unittest/dynamic/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp delete mode 100644 ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/efficiency/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp delete mode 100644 ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp delete mode 100644 ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp delete mode 100644 ddspipe_core/test/unittest/types/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp delete mode 100644 ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp delete mode 100644 ddspipe_core/test/unittest/types/topic/CMakeLists.txt delete mode 100644 ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp delete mode 100644 ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp delete mode 100644 ddspipe_participants/CMakeLists.txt delete mode 100644 ddspipe_participants/README.md delete mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/types/dds/RouterCacheChange.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp delete mode 100644 ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp delete mode 100644 ddspipe_participants/package.xml delete mode 100644 ddspipe_participants/project_settings.cmake delete mode 100644 ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp delete mode 100644 ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp delete mode 100644 ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp delete mode 100644 ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp delete mode 100644 ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp delete mode 100644 ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp delete mode 100644 ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp delete mode 100644 ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp delete mode 100644 ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp delete mode 100644 ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp delete mode 100644 ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp delete mode 100644 ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp delete mode 100644 ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp delete mode 100644 ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp delete mode 100644 ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp delete mode 100644 ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp delete mode 100644 ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp delete mode 100644 ddspipe_participants/src/cpp/testing/random_values.cpp delete mode 100644 ddspipe_participants/src/cpp/types/address/Address.cpp delete mode 100644 ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp delete mode 100644 ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rtps/filter/RepeaterDataFilter.cpp delete mode 100644 ddspipe_participants/src/cpp/writer/rtps/filter/SelfDataFilter.cpp delete mode 100644 ddspipe_participants/test/CMakeLists.txt delete mode 100644 ddspipe_yaml/CMakeLists.txt delete mode 100644 ddspipe_yaml/README.md delete mode 100644 ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp delete mode 100644 ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp delete mode 100644 ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp delete mode 100644 ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp delete mode 100644 ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp delete mode 100644 ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp delete mode 100644 ddspipe_yaml/package.xml delete mode 100644 ddspipe_yaml/project_settings.cmake delete mode 100644 ddspipe_yaml/src/cpp/YamlManager.cpp delete mode 100644 ddspipe_yaml/src/cpp/YamlReader_generic.cpp delete mode 100644 ddspipe_yaml/src/cpp/YamlReader_participants.cpp delete mode 100644 ddspipe_yaml/src/cpp/YamlReader_types.cpp delete mode 100644 ddspipe_yaml/test/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/entities/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp delete mode 100644 ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp delete mode 100644 ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt delete mode 100644 ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp diff --git a/ddspipe_core/CMakeLists.txt b/ddspipe_core/CMakeLists.txt deleted file mode 100644 index 644d5c7d4..000000000 --- a/ddspipe_core/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2022 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. - -############################################################################### -# CMake build rules for DDS Router Submodule -############################################################################### -cmake_minimum_required(VERSION 3.5) - -############################################################################### -# Find package cmake_utils -############################################################################### -# Package cmake_utils is required to get every cmake macro needed -find_package(cmake_utils REQUIRED) - -############################################################################### -# Project -############################################################################### -# Configure project by info set in project_settings.cmake -# - Load project_settings variables -# - Read version -# - Set installation paths -configure_project() - -# Call explictly project -project( - ${MODULE_NAME} - VERSION - ${MODULE_VERSION} - DESCRIPTION - ${MODULE_DESCRIPTION} - LANGUAGES - CXX -) - -############################################################################### -# C++ Project -############################################################################### -# Configure CPP project for dependencies and required flags: -# - Set CMake Build Type -# - Set C++ version -# - Set shared libraries by default -# - Find external packages and thirdparties -# - Activate Code coverage if flag CODE_COVERAGE -# - Activate Address sanitizer build if flag ASAN_BUILD -# - Activate Thread sanitizer build if flag TSAN_BUILD -# - Configure log depending on LOG_INFO flag and CMake type -configure_project_cpp() - -# Compile C++ library -compile_library( - "${PROJECT_SOURCE_DIR}/src/cpp" # Source directory - "${PROJECT_SOURCE_DIR}/include" # Include directory -) - -############################################################################### -# Test -############################################################################### -# Compile tests if CMake options requires it -compile_test_library( - "${PROJECT_SOURCE_DIR}/test" # Test directory -) - -############################################################################### -# Packaging -############################################################################### -# Install package -eprosima_packaging() diff --git a/ddspipe_core/README.md b/ddspipe_core/README.md deleted file mode 100644 index 90d290c4b..000000000 --- a/ddspipe_core/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# eProsima DDS Router Core Library - -> TODO - -This library contain main functionality of the DDS Router. -Include module is the public API used to configure a DDS Router and to interact with a running one: - -* **Types**: data types used to configure a router. - * Address - * DDS info (Guid, Qos, Topic, etc.) - -* **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: - * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. - * *DDSRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. - * *DDSRouterReloadConfiguration*: configuration to change topics in a running DDS Router. - -* **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. - It allows to execute a DDS Router, and to interact with it while running. - ---- - -## Example of usage - -```cpp -// START AND STOP DDS ROUTER FROM CONFIGURATION - -core::configuration::DDSRouterConfiguration router_configuration; - -// ... populate router_configuration - -core::DDSRouter router(router_configuration); -router.start(); - -// ... wait for event - -router.stop(); -``` - ---- - -## Dependencies - -* `fastrtps` -* `cpp_utils` - ---- - -## How to use it in your project - -Just import library `ddsrouter_core` into your CMake project. - -```cmake -find_package(ddsrouter_core) -target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_core) -``` diff --git a/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp b/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp deleted file mode 100644 index a53706cd6..000000000 --- a/ddspipe_core/include/ddspipe_core/communication/Bridge.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Bridge object manages the communication of a DDS Topic (or \c RpcTopic ). - * It could be seen as a channel of communication as a DDS Topic, with several Participants that - * could publish or subscribe in this specific Topic. - * - * It is implemented by \c DdsBridge and \c RPCBridge , which handle \c DistributedTopic and \c RpcTopic , respectively. - */ -class Bridge -{ -public: - - /** - * Bridge constructor by required values - * - * @param participant_database: Collection of Participants to manage communication - * @param payload_pool: Payload Pool that handles the reservation/release of payloads throughout the DDS Router - * @param thread_pool: Shared pool of threads in charge of data transmission. - * - * @note Always created disabled. Enable in children constructors if needed. - * - */ - Bridge( - const std::shared_ptr& participants_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool); - - /** - * Copy method not allowed - * - * Bridge creates in constructor all the inside Tracks needed, and thus it should not be copied - */ - void operator =( - const Bridge&) = delete; - - /** - * Enable bridge - */ - virtual void enable() noexcept = 0; - - /** - * Disable bridge - */ - virtual void disable() noexcept = 0; - -protected: - - //! Collection of Participants to manage communication - const std::shared_ptr participants_; - - //! Common shared payload pool - const std::shared_ptr payload_pool_; - - //! Common shared thread pool - const std::shared_ptr thread_pool_; - - //! Whether the Bridge is currently enabled - std::atomic enabled_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp deleted file mode 100644 index 79deada00..000000000 --- a/ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Bridge object manages the communication of a \c DistributedTopic. - * It could be seen as a channel of communication as a DDS Topic, whit several Participants that - * could publish or subscribe in this specific Topic. - * - * It contains N \c Tracks that will manage each direction of the communication, - * being N the number of Participants of this communication channel. - */ -class DdsBridge : public Bridge -{ -public: - - /** - * Bridge constructor by required values - * - * In Bridge construction, the inside \c Tracks are created. - * In Bridge construction, a Writer and a Reader are created for each Participant. - * - * @param topic: Topic of which this Bridge manages communication - * @param participant_database: Collection of Participants to manage communication - * @param payload_pool: Payload Pool that handles the reservation/release of payloads throughout the DDS Router - * @param thread_pool: Shared pool of threads in charge of data transmission. - * @param enable: Whether the Bridge should be initialized as enabled - * - * @throw InitializationException in case \c IWriters or \c IReaders creation fails. - */ - DdsBridge( - const utils::Heritable& topic, - const std::shared_ptr& participants_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool); - - ~DdsBridge(); - - /** - * Enable bridge in case it is not enabled - * Does nothing if it is already enabled - * - * Thread safe - */ - void enable() noexcept override; - - /** - * Disable bridge in case it is not enabled - * Does nothing if it is disabled - * - * Thread safe - */ - void disable() noexcept override; - -protected: - - utils::Heritable topic_; - - /** - * Inside \c Tracks - * They are indexed by the Id of the participant that is source - */ - std::map> tracks_; - - //! Mutex to prevent simultaneous calls to enable and/or disable - std::mutex mutex_; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const DdsBridge&); -}; - -/** - * @brief \c DdsBridge to stream serialization - * - * This method is merely a to_string of a Bridge definition. - * It serialize the topic - */ -std::ostream& operator <<( - std::ostream& os, - const DdsBridge& bridge); - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp b/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp deleted file mode 100644 index 5b67e9172..000000000 --- a/ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Track object manages the communication between one \c IReader as entry point of data and N - * \c IWriter that will send forward the data received. - */ -class Track -{ -public: - - /** - * Track constructor by required values. - * - * Track construction creates a new thread that manages the transmission between the reader and the writers. - * - * @param topic: Topic that this Track manages communication - * @param reader: Reader that will receive the remote data - * @param writers: Map of Writers that will send the data received by \c source indexed by Participant id - */ - Track( - const utils::Heritable& topic, - const types::ParticipantId& reader_participant_id, - const std::shared_ptr& reader, - std::map>&& writers, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool) noexcept; - - /** - * @brief Destructor - * - * It unsets the callback from Reader. - * It should stop and wait for the transmission thread. - * It must not destroy any entity as it does not create them. - */ - virtual ~Track(); - - /** - * Copy method not allowed - * - * Track creates in constructor all the inside Endpoints needed, and thus it should not be copied - */ - void operator =( - const Track&) = delete; - - /** - * Enable Track in case it is not enabled - * Does nothing if it is already enabled - * - * Thread safe - */ - void enable() noexcept; - - /** - * Disable Track in case it is enabled. This will cause that data will not be transmitted from - * source to targets. - * Does nothing if it is disabled - * - * This method does not manage if the data is still arriving to the reader. - * - * Thread safe - */ - void disable() noexcept; - -protected: - - /* - * WORKAROUND: - * A problem has been found in the use of Track within FastDDS Readers: - * the on_data_available callback is called with the Reader mutex taken, so it may occur a deadlock while - * reading a data and receiving it at the same time from different threads if on_data_available and read - * methods share a mutex. - * - * In order to avoid this deadlock, there is a DataAvailableStatus enumeration setting the status - * of the data taking into account the Listener(listen) update and the Track(read) update. - * This enumeration works as numbers and not as enumeration (could be seen as a collection of constexpr) - * - * The main point is to not have to tak any mutex in on_data_available neither in read. - */ - //! Status of the data available in the Track's Reader - enum DataAvailableStatus - { - no_more_data = 0, //! Track has announced that Reader has no more data - transmitting_data = 1, //! Track is taking data from the Reader, so it could or could not be data - new_data_arrived = 2 /* >2 */, //! Listener has announced that new data has arrived - }; - - /** - * Callback that will be called by the reader in case there is available data to be forwarded. - * - * This method is registered in the Reader so it could call it when there is new data. - * - * This method will add the variable \c data_available_status_ in \c new_data_arrived . - * It will emit a task to execute transmit in a different thread if there was no previous thread before. - */ - void data_available_() noexcept; - - /** - * Whether this Track is enabled and should not exit. - * - * This method does not lock a mutex as it only acces atomic values to read them. - */ - bool should_transmit_() noexcept; - - /** - * Take data from the Reader \c source and send this data through every writer in \c targets . - * - * When no more data is available, set \c data_available_status_ as \c no_more_data . - * - * It could exit without having finished transmitting all the data if track should terminate or track becomes - * disabled. - */ - void transmit_() noexcept; - - //! Topic that refers to this Bridge - const utils::Heritable topic_; - - /** - * @brief Id of the Participant of the Reader - * - * This id and topic identifies unequivocally a Track - */ - types::ParticipantId reader_participant_id_; - - //! Reader that will read data - std::shared_ptr reader_; - - //! Writers that will send data forward - std::map> writers_; - - //! Common shared payload pool - std::shared_ptr payload_pool_; - - //! Whether the Track is currently enabled - std::atomic enabled_; - - /** - * Mutex to prevent simultaneous calls to \c enable and/or \c disable . - * It manages access to variable \c enabled_ . - */ - std::mutex track_mutex_; - - ///// - // Transmit thread part - - /** - * Whether the Track must terminate - * - * This variable is only set in destruction. It forces \c transmit_thread_ to stop even if it is - * transmitting data. - * - * As it is only set in destruction, it is not protected by any mutex - */ - std::atomic exit_; - - /** - * Current status of the data available - * - * There are 3 states: - * \c 0 no_more_data : Track has received a NO_DATA from Reader and no data has been set from on_data_available - * \c 1 transmitting_data : Track is currently taking data, so there may or may not be data available - * \c >1 new_data_arrived : Reader Listener has notified that there are new data - * - * This variable does not need to be protected as it is atomic. - */ - std::atomic data_available_status_; - - /** - * Mutex to guard while the Track is sending a message so it could not be disabled. - */ - std::mutex on_transmission_mutex_; - - utils::TaskId transmit_task_id_; - - std::shared_ptr thread_pool_; - - static const unsigned int MAX_MESSAGES_TRANSMIT_LOOP_; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const Track&); -}; - -/** - * @brief \c Track to stream serialization - * - * This method is merely a to_string of a Track definition. - * It serialize the topic and Participant source Id - */ -std::ostream& operator <<( - std::ostream& os, - const Track& track); - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp b/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp deleted file mode 100644 index 84313375d..000000000 --- a/ddspipe_core/include/ddspipe_core/communication/rpc/RPCBridge.hpp +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Bridge object manages the communication of a \c RpcTopic. - * - * Contains a proxy server and client in each participant. - * - * Keeps track of the (actual) servers available at each participant, so the whole bridge can be disabled if no server - * is available for processing a request (services use RELIABLE & VOLATILE qos by default, so if a request is sent - * and no server is there to receive it, it will remain unanswered even if a new server appears later). - * - */ -class RPCBridge : public Bridge -{ -public: - - /** - * RPCBridge constructor by required values - * - * In RPCBridge construction, no endpoints are created. - * - * @param topic: Topic (service) of which this RPCBridge manages communication - * @param participant_database: Collection of Participants to manage communication - * @param payload_pool: Payload Pool that handles the reservation/release of payloads throughout the DDS Router - * @param thread_pool: Shared pool of threads in charge of data transmission. - * - * @note Always created disabled, manual enable required. First enable creates all endpoints. - */ - RPCBridge( - const types::RpcTopic& topic, - const std::shared_ptr& participants_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool); - - /** - * @brief Destructor - * - * Before deleting, it calls \c disable. - * It deletes all the endpoints created in this bridge. - */ - virtual ~RPCBridge(); - - /** - * Enable bridge in case it is not enabled and there are (actual) servers available - * Does nothing if it is already enabled - * - * Thread safe - */ - void enable() noexcept override; - - /** - * Disable bridge in case it is not enabled - * Does nothing if it is disabled - * - * Thread safe - */ - void disable() noexcept override; - - //! New server discovered -> add to database and enable registry in discoverer participant (in case it was disabled) - void discovered_service( - const types::ParticipantId& server_participant_id, - const types::GuidPrefix& server_guid_prefix) noexcept; - - //! Server removed -> delete from database (if present) and disable bridge if it was the last server available - void removed_service( - const types::ParticipantId& server_participant_id, - const types::GuidPrefix& server_guid_prefix) noexcept; - -protected: - - /** - * Creates all proxy clients and servers associated to this bridge. - * - * Called only once in execution (controlled by \c init_ flag). - * - * @throw InitializationException in case \c IWriters or \c IReaders creation fails. - */ - void init_nts_(); // throws exception, caught in enable - - /** - * Create a RTPS Reader in request topic and a RTPS Writer in reply topic. - * - * @param participant_id: Participant where proxy server is to be created - * - * @throw InitializationException in case \c IWriters or \c IReaders creation fails. - */ - void create_proxy_server_nts_( - types::ParticipantId participant_id); - - /** - * Create a RTPS Reader in reply topic and a RTPS Writer in request topic. - * Create a \c ServiceRegistry associated to this proxy client. - * - * @param participant_id: Participant where proxy client is to be created - * - * @throw InitializationException in case \c IWriters or \c IReaders creation fails. - */ - void create_proxy_client_nts_( - types::ParticipantId participant_id); - - //! Create slot in the thread pool for this reader - void create_slot_( - std::shared_ptr reader) noexcept; - - //! Callback to execute when a new cache change is added to this reader - void data_available_( - const types::Guid& reader_guid) noexcept; - - /** - * REQUEST: Take data from request \c reader and send this data through all proxy clients which are in contact - * with actual servers (service registry enabled). - * - * REPLY: Take data from reply \c reader and send it through the proxy server which originally received the request - * (information present in service registry). - * - * Finish execution when no more data is available, or bridge has been disabled (due to servers unavailability or - * topic being blocked). - */ - void transmit_( - std::shared_ptr reader) noexcept; - - //! Whether there are any servers in the database - bool servers_available_() const noexcept; - - //! Flag set to true when proxy clients and servers are created, so it can only be done once - bool init_; - - //! Proxy servers endpoints - std::map> request_readers_; - std::map> reply_writers_; - - //! Proxy clients endpoints - std::map> reply_readers_; - std::map> request_writers_; - - //! Map readers' GUIDs to their associated thread pool tasks, and also keep a task emission flag. - std::map> tasks_map_; - - /** - * Registry of requests received, with all the information needed to send the future reply back to the requester. - * - * There is one per participant, handling the communication of each of them with the servers they are directly - * in contact with. - */ - std::map> service_registries_; - - //! Database keeping track of the (actual) servers available at each participant. - std::map> current_servers_; - - //! Mutex to prevent simultaneous calls to enable and/or disable - std::mutex mutex_; - - /** - * Mutex to guard while the RPCBridge is sending a message so it could not be disabled. - */ - std::shared_timed_mutex on_transmission_mutex_; - - types::RpcTopic rpc_topic_; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const RPCBridge&); -}; - -/** - * @brief \c RPCBridge to stream serialization - * - * This method is merely a to_string of a RPCBridge definition. - * It serialize the RPCtopic - */ -std::ostream& operator <<( - std::ostream& os, - const RPCBridge& bridge); - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp b/ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp deleted file mode 100644 index d69bd417e..000000000 --- a/ddspipe_core/include/ddspipe_core/communication/rpc/ServiceRegistry.hpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using SampleIdentity = eprosima::fastrtps::rtps::SampleIdentity; - -using SequenceNumber = eprosima::fastrtps::rtps::SequenceNumber_t; - -/** - * Class used to store the information associated to a service request, so its reply can be forwarded through the - * appropiate proxy server with the proper write parameters. - * - * This information is stored in a map, whose insertions and deletions are protected with a mutex. - * Insertions are performed every time a request is sent, and deletions after a reply has been received and forwarded. - * - * There exists a service registry per router participant. - * - */ -class ServiceRegistry -{ -public: - - /** - * ServiceRegistry constructor by required values - * - * @param topic: Topic (service) of which this ServiceRegistry manages communication - * @param participant_id: Id of participant for which this registry is created - * - * @note Always created disabled. It is first enabled when a server is discovered. - */ - ServiceRegistry( - const types::RpcTopic& topic, - const types::ParticipantId& participant_id); - - //! Enable registry - void enable() noexcept; - - //! Disable registry - void disable() noexcept; - - //! Whether the registry is enabled - bool enabled() const noexcept; - - SampleIdentity related_sample_identity_nts() const noexcept; - - //! Add entry to the registry (if key not existing) - void add( - SequenceNumber idx, - std::pair new_entry) noexcept; - - //! Fetch entry from the registry. Returns dummy item if not present. - std::pair get( - SequenceNumber idx) const noexcept; - - //! Remove entry from the registry (if present) - void erase( - SequenceNumber idx) noexcept; - - //! RpcTopic getter - types::RpcTopic topic() const noexcept; - - //! Get \c mutex_ - std::recursive_mutex& get_mutex() noexcept; - -protected: - - //! RpcTopic (service) that this ServiceRegistry manages communication - types::RpcTopic topic_; - - //! Id of participant for which this registry is created - types::ParticipantId participant_id_; - - //! Whether the registry is activated - std::atomic enabled_; - - //! Database with an entry per received request, and the information required for forwarding replies - std::map> registry_; - - //! Default maximum number of entries stored by \c registry_ map - static const unsigned int DEFAULT_MAX_ENTRIES_; - - //! Mutex to protect concurrent access to \c registry_ - mutable std::recursive_mutex mutex_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp b/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp deleted file mode 100644 index 2b37f90ea..000000000 --- a/ddspipe_core/include/ddspipe_core/configuration/IConfiguration.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Configurations in DDS Pipe are data structures with public access to its internal methods. - * Thus, they are not forced to be correct in construction. - * This is an Interface class that forces every configuration to have an \c is_valid method. - */ -DDSPIPE_CORE_DllAPI struct IConfiguration -{ - virtual bool is_valid( - utils::Formatter& error_msg) const noexcept = 0; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp b/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp deleted file mode 100644 index 60e3fdb61..000000000 --- a/ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp +++ /dev/null @@ -1,346 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * TODO - */ -class DdsPipe -{ -public: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - /** - * @brief Construct a new DdsPipe object - * - * Initialize a whole DdsPipe: - * - Create its associated AllowedTopicList - * - Create Participants and add them to \c ParticipantsDatabase - * - Create the Bridges for (allowed) builtin topics - * - * @param [in] configuration : Configuration for the new DDS Router - * - * @throw \c ConfigurationException in case the yaml inside allowlist is not well-formed - * @throw \c InitializationException in case \c IParticipants , \c IWriters or \c IReaders creation fails. - * - * @todo change SlotThreadPool for a IThreadPool when exist. - */ - DDSPIPE_CORE_DllAPI DdsPipe( - const std::shared_ptr& allowed_topics, - const std::shared_ptr& discovery_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& participants_database, - const std::shared_ptr& thread_pool, - const std::set>& builtin_topics = {}); - - /** - * @brief Destroy the DdsPipe object - * - * Stop the DdsPipe - * Destroy all Bridges - * Destroy all Participants - */ - DDSPIPE_CORE_DllAPI ~DdsPipe(); - - ///////////////////////// - // INTERACTION METHODS - ///////////////////////// - - /** - * @brief Reload the allowed topic configuration - * - * @param [in] configuration : new configuration - * - * @return \c RETCODE_OK if configuration has been updated correctly - * @return \c RETCODE_NO_DATA if new configuration has not changed - * @return \c RETCODE_ERROR if any other error has occurred - * - * @throw \c ConfigurationException in case the new yaml is not well-formed - */ - DDSPIPE_CORE_DllAPI utils::ReturnCode reload_allowed_topics( - const std::shared_ptr& allowed_topics); - - ///////////////////////// - // ENABLING METHODS - ///////////////////////// - - /** - * @brief Start communication in DDS Router - * - * Enable every topic Bridge. - * - * @note this method returns a ReturnCode for future possible errors - * - * @return \c RETCODE_OK always - */ - DDSPIPE_CORE_DllAPI utils::ReturnCode start() noexcept; - - /** - * @brief Stop communication in DDS Router - * - * Disable every topic Bridge. - * - * @note this method returns a ReturnCode for future possible errors - * - * @return \c RETCODE_OK always - */ - DDSPIPE_CORE_DllAPI utils::ReturnCode stop() noexcept; - -protected: - - /** - * @brief Internal Start method - * - * Enable every topic Bridge. - * - * @note this method returns a ReturnCode for future possible errors - * - * @return \c RETCODE_OK if ok - * @return \c RETCODE_PRECONDITION_NOT_MET if Router was not disabled - */ - utils::ReturnCode start_() noexcept; - - /** - * @brief Internal Stop method - * - * Disable every topic Bridge. - * - * @note this method returns a ReturnCode for future possible errors - * - * @return \c RETCODE_OK if ok - * @return \c RETCODE_PRECONDITION_NOT_MET if Router was not enabled - */ - utils::ReturnCode stop_() noexcept; - - ///// - // INTERNAL INITIALIZATION METHODS - - /** - * @brief Create a disabled bridge for every real topic - */ - void init_bridges_(const std::set>& builtin_topics); - - ///// - // INTERNAL AUXILIAR METHODS - - /** - * @brief Method called every time a new endpoint has been discovered/updated - * - * This method is called with the topic of a new/updated \c Endpoint discovered. - * If the DDSRouterImpl is enabled, the new Bridge is created and enabled. - * - * @note This is the only method that adds topics to \c current_topics_ - * - * @param [in] topic : topic discovered - */ - void discovered_topic_( - const utils::Heritable& topic) noexcept; - - /** - * @brief Method called every time a new endpoint (corresponding to a server) has been discovered/updated - * - * This method is called with the topic of a new/updated \c Endpoint discovered. - * If the DDSRouterImpl is enabled and no bridge exists, the new RPCBridge is created (and enabled if allowed). - * - * @note This is the only method that adds topics to \c current_services_ - * - * @param [in] topic : topic discovered - * @param [in] server_participant_id : id of participant discovering server - * @param [in] server_guid_prefix : GUID Prefix of discovered server - */ - void discovered_service_( - const types::RpcTopic& topic, - const types::ParticipantId& server_participant_id, - const types::GuidPrefix& server_guid_prefix) noexcept; - - /** - * @brief Method called every time a new endpoint (corresponding to a server) has been removed/dropped - * - * This method is called with the topic of a removed/dropped \c Endpoint. - * - * @param [in] topic : topic discovered - * @param [in] server_participant_id : id of participant discovering server - * @param [in] server_guid_prefix : GUID Prefix of discovered server - */ - void removed_service_( - const types::RpcTopic& topic, - const types::ParticipantId& server_participant_id, - const types::GuidPrefix& server_guid_prefix) noexcept; - - /** - * @brief Method called every time a new endpoint has been discovered/updated - * - * This method calls \c discovered_topic_ with the topic of \c endpoint as parameter. - * - * @param [in] endpoint : endpoint discovered - */ - void discovered_endpoint_( - const types::Endpoint& endpoint) noexcept; - - /** - * @brief Method called every time a new endpoint has been removed/dropped - * - * @param [in] endpoint : endpoint removed/dropped - */ - void removed_endpoint_( - const types::Endpoint& endpoint) noexcept; - - /** - * @brief Create a new \c DdsBridge object - * - * It is created enabled if the DDSRouterImpl is enabled. - * - * @param [in] topic : new topic - */ - void create_new_bridge_( - const utils::Heritable& topic, - bool enabled = false) noexcept; - - /** - * @brief Create a new \c RPCBridge object - * - * It is always created disabled. - * - * @param [in] topic : new topic - */ - void create_new_service_( - const types::RpcTopic& topic) noexcept; - - /** - * @brief Enable a specific topic - * - * If the topic did not exist before, the Bridge is created. - * - * @param [in] topic : Topic to be enabled - */ - void activate_topic_( - const utils::Heritable& topic) noexcept; - - /** - * @brief Disable a specific topic. - * - * If the Bridge of the topic does not exist, do nothing. - * - * @param [in] topic : Topic to be disabled - */ - void deactivate_topic_( - const utils::Heritable& topic) noexcept; - - /** - * @brief Activate all Topics that are allowed by the allowed topics list - */ - void activate_all_topics_() noexcept; - - /** - * @brief Disable all Bridges - */ - void deactivate_all_topics_() noexcept; - - ///////////////////////// - // SHARED DATA STORAGE - ///////////////////////// - - //! List of allowed and blocked topics - std::shared_ptr allowed_topics_; - - /** - * @brief Common discovery database - * - * This object is shared by every Participant. - * Every time an endpoint is discovered by any Participant, it should be - * added to the database. - */ - std::shared_ptr discovery_database_; - - /** - * @brief Common payload pool where every payload will be stored - * - * This payload will be shared by every endpoint. - * Every reader will store its data in the pool, the track will pass this - * data to the writers, that will release it after used. - */ - std::shared_ptr payload_pool_; - - /** - * @brief Object that stores every Participant running in the DDSRouterImpl - */ - std::shared_ptr participants_database_; - - //! Thread Pool for tracks - std::shared_ptr thread_pool_; - - ///////////////////////// - // INTERNAL DATA STORAGE - ///////////////////////// - - //! Map of bridges indexed by their topic - std::map, std::unique_ptr> bridges_; - - //! Map of RPC bridges indexed by their topic - std::map> rpc_bridges_; - - /** - * @brief List of topics discovered - * - * Every topic discovered would be added to this map. - * If the value is true, it means this topic is currently activated. - */ - std::map, bool> current_topics_; - - /** - * @brief List of RPC topics discovered - * - * Every RPC topic discovered would is added to this map. - * If the value is true, it means this service is allowed. - */ - std::map current_services_; - - ///// - // AUXILIAR VARIABLES - - //! Whether the DDSRouterImpl is currently communicating data or not - std::atomic enabled_; - - /** - * @brief Internal mutex for concurrent calls - * - * @todo this should not require to be recursive. - */ - std::recursive_mutex mutex_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp b/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp deleted file mode 100644 index 7ec744596..000000000 --- a/ddspipe_core/include/ddspipe_core/dynamic/AllowedTopicList.hpp +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * This object manages the filtering of the topics. - * It is constituted by a list of allowed topics and a list of blocked topics, and filters each topic - * by topic name and topic type to see if it is allowed by the lists. - * - * In case of an empty allowlist, every topic is allowed except those in blocklist. - * In case of both lists empty, every topic is allowed. - */ -class AllowedTopicList -{ -public: - - //! Default constructor with empty lists - DDSPIPE_CORE_DllAPI AllowedTopicList(); - - //! Constructor by initialization lists - DDSPIPE_CORE_DllAPI AllowedTopicList( - const std::set>& allowlist, - const std::set>& blocklist) noexcept; - - //! Copy constructor. It copies internal lists. - DDSPIPE_CORE_DllAPI AllowedTopicList& operator =( - const AllowedTopicList& other); - - //! Destructor - DDSPIPE_CORE_DllAPI virtual ~AllowedTopicList(); - - //! Clear all topics in lists - DDSPIPE_CORE_DllAPI void clear() noexcept; - - /** - * Whether topic \c topic is allowed by the lists that constitute this object - * - * For a topic to be allowed it must: - * 1a. Allowlist be empty - * 1b. Be contained in the allowlist - * 2. Do not be contained in the blocklist - * - * @param topic: topic to check if it is allowed - * - * @return True if the topic is allowed, false otherwise - */ - DDSPIPE_CORE_DllAPI bool is_topic_allowed( - const ITopic& topic) const noexcept; - - /** - * Whether RpcTopic \c topic is allowed by the lists that constitute this object - * - * For a RpcTopic to be allowed it must: - * 1. Request topic allowed - * 2. Reply topic allowed - * - * @param topic: topic to check if it is allowed - * - * @return True if the topic is allowed, false otherwise - */ - DDSPIPE_CORE_DllAPI bool is_service_allowed( - const types::RpcTopic& topic) const noexcept; - - /** - * Equal operator. - * - * Two lists are the same if they have the same topics stored. - * - * @todo: Two lists are the same when they filter the same topics. Thus, method \c contains in - * \c IFilterTopic must be implemented completely. - * - * @param other: other \c AllowedTopicList object to compare with \c this - * - * @return True if they are constituted by same topics, false otherwise - */ - DDSPIPE_CORE_DllAPI bool operator ==( - const AllowedTopicList& other) const noexcept; - -protected: - - /** - * @brief Get a list of filtered topics and return a list that filters repeated topics eliminating redundancy - * - * @param [in] list: list of topics with redundancy - * @return Set of topics without redundancy - */ - static std::set> get_topic_list_without_repetition_( - const std::set>& list) noexcept; - - //! List of topics that are not allowed - std::set> blocklist_; - - //! List of topics that are allowed - std::set> allowlist_; - - //! Mutex to restrict access to the class - mutable std::recursive_mutex mutex_; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const AllowedTopicList&); -}; - -//! \c AllowedTopicList to stream serializator -std::ostream& operator <<( - std::ostream& os, - const AllowedTopicList& atl); - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp deleted file mode 100644 index 4ba90b92a..000000000 --- a/ddspipe_core/include/ddspipe_core/dynamic/DiscoveryDatabase.hpp +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -//! Operations to perform on a DiscoveryDatabase -DDSPIPE_CORE_DllAPI enum class DatabaseOperation -{ - add, - update, - erase -}; - -/** - * Class that stores a collection of discovered remote (not belonging to this DDSRouter) Endpoints. - */ -class DiscoveryDatabase -{ -public: - - /** - * @brief Construct a new DiscoveryDatabase object - * - * Create a thread in charge of processing DB transactions stored in a queue. - * Call \c start() function to enable the DiscoveryDatabase. - */ - DDSPIPE_CORE_DllAPI DiscoveryDatabase() noexcept; - - /** - * @brief Destroy the DiscoveryDatabase object - * - * Signal and wait for the queue processing thread to stop. - */ - DDSPIPE_CORE_DllAPI ~DiscoveryDatabase(); - - /** - * @brief Initialize the queue processing thread routine - * - * Create a thread in charge of processing the dynamic discovery of endpoints. - * The creation of the discovery database processing thread is done after the creation of the DiscoveryDatabase due - * to a data race condition that may involve first creating the topics through the discovered endpoints or creating - * them from the builtin topics configuration. - * The builtin topics may have special topic configurations not detected in discovery - * that would mean that the topic does not have the correct configuration. - */ - DDSPIPE_CORE_DllAPI void start() noexcept; - - /** - * @brief Stop the queue processing thread routine - * - * Join the thread in charge of processing the dynamic discovery of endpoints. - */ - DDSPIPE_CORE_DllAPI void stop() noexcept; - - /** - * @brief Whether a topic exists in any Endpoint in the database - * - * @param [in] topic: topic to check if it exists - * @return true if any endpoint has this topic, false otherwise - */ - DDSPIPE_CORE_DllAPI bool topic_exists( - const types::DdsTopic& topic) const noexcept; - - //! Whether this guid is in the database - DDSPIPE_CORE_DllAPI bool endpoint_exists( - const types::Guid& guid) const noexcept; - - /** - * @brief Insert endpoint to the database - * - * This method stores an insert operation in an internal queue, being this operation then performed by a - * dedicated thread. - * - * @param [in] new_endpoint: new endpoint to store - */ - DDSPIPE_CORE_DllAPI void add_endpoint( - const types::Endpoint& new_endpoint); - - /** - * @brief Add update operation to the database - * - * This method stores an update operation in an internal queue, being this operation then performed by a - * dedicated thread. - * - * @param [in] endpoint_to_update: endpoint to update - */ - DDSPIPE_CORE_DllAPI void update_endpoint( - const types::Endpoint& endpoint_to_update); - - /** - * @brief Add erase operation to the database - * - * This method stores an erase operation in an internal queue, being this operation then performed by a - * dedicated thread. - * - * @param [in] endpoint_to_erase endpoint that will be erased - */ - DDSPIPE_CORE_DllAPI void erase_endpoint( - const types::Endpoint& endpoint_to_erase); - - /** - * @brief Get the endpoint object with this guid - * - * @param [in] guid: guid to query - * @return Endpoint referring to this guid - * @throw \c InconsistencyException in case there is no entry associated to this guid - */ - DDSPIPE_CORE_DllAPI types::Endpoint get_endpoint( - const types::Guid& endpoint_guid) const; - - /** - * @brief Add callback to be called when discovering an Endpoint - * - * @param [in] endpoint_discovered_callback: callback to add - */ - DDSPIPE_CORE_DllAPI void add_endpoint_discovered_callback( - std::function endpoint_discovered_callback) noexcept; - - /** - * @brief Add callback to be called when an Endpoint has been updated - * - * @param [in] endpoint_updated_callback: callback to add - */ - DDSPIPE_CORE_DllAPI void add_endpoint_updated_callback( - std::function endpoint_updated_callback) noexcept; - - /** - * @brief Add callback to be called when an Endpoint has been erased - * - * @param [in] endpoint_erased_callback: callback to add - */ - DDSPIPE_CORE_DllAPI void add_endpoint_erased_callback( - std::function endpoint_erased_callback) noexcept; - - /** - * @brief Remove all callbacks from all types (endpoint discovered, updated and erased) - * - */ - DDSPIPE_CORE_DllAPI void clear_all_callbacks() noexcept; - -protected: - - /** - * @brief Add a new endpoint to the database. - * - * @param [in] new_endpoint: new endpoint to store - * @return true if the endpoint has been added - * @throw \c InconsistencyException in case an endpoint with the same guid already exists and is active - */ - DDSPIPE_CORE_DllAPI bool add_endpoint_( - const types::Endpoint& new_endpoint); - - /** - * @brief Update an entry of the database by replacing the stored endpoint by a new one. - * - * @param [in] endpoint_to_update: endpoint to update - * @return true if the endpoint has been updated - * @throw \c InconsistencyException in case there is no entry associated to this endpoint - */ - DDSPIPE_CORE_DllAPI bool update_endpoint_( - const types::Endpoint& endpoint_to_update); - - /** - * @brief Erase an endpoint inside the database - * - * @param [in] endpoint_to_erase endpoint that will be erased - * @return \c RETCODE_OK if correctly erased - * @throw \c InconsistencyException in case there is no entry associated to this endpoint - */ - DDSPIPE_CORE_DllAPI utils::ReturnCode erase_endpoint_( - const types::Endpoint& endpoint_to_erase); - - //! Routine performed by dedicated thread performing database operations - DDSPIPE_CORE_DllAPI void queue_processing_thread_routine_() noexcept; - - /** - * @brief Add new operation to the queue \c entities_to_process_ - * - * @param [in] item: operation to add - */ - DDSPIPE_CORE_DllAPI void push_item_to_queue_( - std::tuple item) noexcept; - - //! Process queue storing database operations - DDSPIPE_CORE_DllAPI void process_queue_() noexcept; - - //! Database of endpoints indexed by guid - std::map entities_; - - //! Mutex to guard queries to the database - mutable std::shared_timed_mutex mutex_; - - //! Vector of callbacks to be called when an Endpoint is added - std::vector> added_endpoint_callbacks_; - - //! Vector of callbacks to be called when an Endpoint is updated - std::vector> updated_endpoint_callbacks_; - - //! Vector of callbacks to be called when an Endpoint is erased - std::vector> erased_endpoint_callbacks_; - - //! Mutex to guard callbacks vectors - mutable std::mutex callbacks_mutex_; - - //! Queue storing database operations to be performed in a dedicated thread - fastrtps::DBQueue> entities_to_process_; - - //! Handle of thread dedicated to performing database operations - std::thread queue_processing_thread_; - - //! Flag used to signal \c queue_processing_thread_ it must stop - std::atomic exit_; - - //! Condition variable to wait in \c queue_processing_thread_ until a new database operation is available - std::condition_variable entities_to_process_cv_; - - //! Guards access to \c entities_to_process_cv_ - std::mutex entities_to_process_cv_mutex_; - - //! Flag to indicate whether the DiscoveryDatabase was initialized - std::atomic enabled_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp b/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp deleted file mode 100644 index 406697813..000000000 --- a/ddspipe_core/include/ddspipe_core/dynamic/ParticipantsDatabase.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief Database to store collectively all the Participants of the Router - * - * This class will be shared between all Bridges so they have access to the Participants. - */ -class ParticipantsDatabase -{ -public: - - DDSPIPE_CORE_DllAPI ParticipantsDatabase() = default; - - /** - * Destructor - * - * @warning it should not be called if it is not empty - */ - DDSPIPE_CORE_DllAPI virtual ~ParticipantsDatabase(); - - /** - * @brief Get the participant pointer - * - * @param id: id of the participant - * @return pointer to the participant - */ - DDSPIPE_CORE_DllAPI std::shared_ptr get_participant( - const types::ParticipantId& id) const noexcept; - - /** - * @brief Get all the ids of the participants stored - * - * @return set of ids - */ - DDSPIPE_CORE_DllAPI std::set get_participants_ids() const noexcept; - - /** - * @brief Get all the ids of the RPTS participants stored - * - * @return set of ids - */ - DDSPIPE_CORE_DllAPI std::set get_rtps_participants_ids() const noexcept; - - /** - * @brief Get all the participants stored - * - * @return map of pointers to participants indexed by ids - */ - DDSPIPE_CORE_DllAPI const std::map>& get_participants_map() const noexcept; - - //! Whether the database is empty - DDSPIPE_CORE_DllAPI bool empty() const noexcept; - - //! Number of Participants in the Database - DDSPIPE_CORE_DllAPI size_t size() const noexcept; - - /** - * @brief Add a new participant - * - * @param [in] id: Id of the new Participant - * @param [in] participant: Pointer to the new Participant - * - * @throw \c IncosistentException if participant already exist (duplicated ids) - */ - DDSPIPE_CORE_DllAPI void add_participant( - const types::ParticipantId& id, - const std::shared_ptr& participant); - -protected: - - //! Database variable to store participants pointers indexed by their ids - std::map> participants_; - - //! Mutex to guard access to database - mutable std::shared_timed_mutex mutex_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp deleted file mode 100644 index 0dd16a707..000000000 --- a/ddspipe_core/include/ddspipe_core/efficiency/payload/CopyPayloadPool.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief Dummy PayloadPool class to use while efficient one not implemented. - * - * This class does not handle references, but copies the payload data in each method required. - * This class does not manage whether the data has been created from this pool before releasing it. - */ -class CopyPayloadPool : public PayloadPool -{ -public: - - using PayloadPool::PayloadPool; - - //! Reserve a new memory space - bool get_payload( - uint32_t size, - types::Payload& payload) override; - - //! Reserve a new memory space and copy the data from \c src_payload to \c target_payload - bool get_payload( - const types::Payload& src_payload, - IPayloadPool*& data_owner, - types::Payload& target_payload) override; - - //! Release data in \c payload - bool release_payload( - types::Payload& payload) override; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp deleted file mode 100644 index be4190067..000000000 --- a/ddspipe_core/include/ddspipe_core/efficiency/payload/FastPayloadPool.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief This is the data type that is stored within the data allocated with the payload. - * - * It uses an atomic value so can be checked and modified in a single atomic operation. - */ -typedef std::atomic MetaInfoType; - -/** - * This class implements the interface of PayloadPool and fulfilled with it the interface of IPayloadPool from - * eProsima Fast DDS. - * - * This class is used to manage the allocation and release of the payloads used within the Router. - * The main target is not to copy or alloc data that is already in memory, but to reuse it safely. - * - * This implementation uses an idea get from TopicPayloadPool from fastrtps. - * This is, to alloc more space than required whenever a new payload is needed, and in this extra space (at the - * beginning of the data) stores the number of references this data has. - * As long as this number does not reach 0, the data is not deleted. - * - * This is a thread safe lock free (except for one atomic check) implementation. - * - * @warning this class requires for all the payloads to be released the same times they are retrieved. - * In case this does not occur, this object does not guarantee that the data will be correctly released. - * - * @warning Payloads used within this class must be allocated from this object (in case of \c get_payload it is enough - * to use the correct \c data_owner as not this one. ) otherwise it will head to undefined behavior. - */ -class FastPayloadPool : public PayloadPool -{ -public: - - //! Use parent constructor - using PayloadPool::PayloadPool; - - /** - * Reserve a new space for the payload with the size given - * - * @param size size of the new chunk of data - * @param payload object to store the new data - * - * @return true if everything OK - * @return false if something went wrong - */ - bool get_payload( - uint32_t size, - types::Payload& payload) override; - - /** - * Reserve in \c target_payload the payload in \c src_payload . - * - * In case the src has been reserved from this object, the reference counter is increased and no data is copied. - * Otherwise, this pool alloc new memory and copy the data - * - * @param [in,out] src_payload Payload to move to target - * @param [in,out] data_owner Payload pool owning incoming data \c src_payload - * @param [in,out] target_payload Payload to assign the payload to - * - * @return true if everything OK - * @return false if something went wrong - * - * @throw utils::InconsistencyException if \c data_owner is \c this but the data in \c src_payload is not from this pool. - */ - bool get_payload( - const types::Payload& src_payload, - IPayloadPool*& data_owner, - types::Payload& target_payload) override; - - /** - * Release a payload that has been reserved from this pool. - * - * It decreases the reference counter of the data and if it reaches 0, the data is deleted. - * - * @param payload payload to release - * - * @return true if everything OK - * @return false if something went wrong - * - * @throw utils::InconsistencyException if the data in \c payload is not from this pool. - */ - bool release_payload( - types::Payload& payload) override; - -protected: - - /** - * @brief Reimplement parent \c reserve_ method - * - * In this implementation, the data is allocated along with space for a \c MetaInfoType object - * that will count the times the payload is referenced - * - * @param size size of memory chunk to reserve - * @param payload object where introduce the new data pointer - * - * @return true if everything ok - * @return false if something went wrong - */ - virtual bool reserve_( - uint32_t size, - types::Payload& payload) override; - - /** - * @brief Reimplement parent \c release_ method - * - * Data must be released taking into account that the data is allocated with space for a \c MetaInfoType object. - * - * @param payload object to free the data from - * - * @return true if everything ok - * @return false if something went wrong - */ - virtual bool release_( - types::Payload& payload) override; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp deleted file mode 100644 index ee2a38016..000000000 --- a/ddspipe_core/include/ddspipe_core/efficiency/payload/MapPayloadPool.hpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief PayloadPool class to efficiently reuse data pointers get from this pool. - * - * It implements zero copy data transmission for payloads get from this pool. - * It does not handle limit of pools or sizes. - * It reserves new memory each time is required, and free memory when no one is refereing it anymore. - * - * This class stores every data that has been reserved and holds a counter to how many references has. - * Each get increases the counter. Each release decreases the counter. - * When the counter reaches 0, the data is freed. - * The data is indexed by the value of the pointer of the data reserved. - */ -class MapPayloadPool : public PayloadPool -{ -public: - - //! Use parent constructor - using PayloadPool::PayloadPool; - - //! Destroy pool and release every data that has not been released yet. - ~MapPayloadPool(); - - /** - * @brief Reserve new memory of size \c size for this payload. - * - * Add a new entrance in \c reserved_payloads_ with the new data created and set the counter to 1. - * - * @param size size of the new chunk of data - * @param payload object to store the new data - * - * @return true if everything OK - * @return false if something went wrong - */ - bool get_payload( - uint32_t size, - types::Payload& payload) override; - - /** - * @brief Set \c target_payload data to \c src_payload . - * - * In case \c data_owner is \c this , \c target_payload points to the same data as \c src_payload , saving - * a reserve and a copy, and increase the reference counter. - * Otherwise, new data is reserved and the data is copied to \c target_payload . - * - * @param [in,out] src_payload Payload to move to target - * @param [in,out] data_owner Payload pool owning incoming data \c src_payload - * @param [in,out] target_payload Payload to assign the payload to - * - * @return true if everything OK - * @return false if something went wrong - * - * @throw utils::InconsistencyException if \c data_owner is \c this but the data in \c src_payload is not from this pool. - */ - bool get_payload( - const types::Payload& src_payload, - IPayloadPool*& data_owner, - types::Payload& target_payload) override; - - /** - * @brief Decrease reference counter for data in \c payload . - * - * Decreases the data inside \c payload in 1. - * If this was the last payload that was referencing the data, this is released. - * - * @param payload payload to release - * - * @return true if everything OK - * @return false if something went wrong - * - * @throw utils::InconsistencyException if the data in \c payload is not from this pool. - */ - bool release_payload( - types::Payload& payload) override; - -protected: - - //! Store every data reserved and the number of payloads that currently reference it. - std::map reserved_payloads_; - - //! Guards access to \c reserved_payloads_ - std::mutex reserved_payloads_mutex_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp b/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp deleted file mode 100644 index f0d73f941..000000000 --- a/ddspipe_core/include/ddspipe_core/efficiency/payload/PayloadPool.hpp +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Pool to store and release payloads. - * - * A Payload is an object with a blind pointer to a string of bytes and extra info (size, length, etc.). - * Ideally, any payload data will be copied just once, and move the reference from one element to another. - * When a payload data has not more references to it, it will be erased. - * - * This Pool will be called to store a new message that a Reader receives (ideally it will be called just one - * per message received). - * Then, this payload will be moved to the Track. As the payload is already in the pool, there will be no copy. - * Finally, the payload will be moved to every Writer that has to send the data (ideally without copy). - */ -class PayloadPool : public eprosima::fastrtps::rtps::IPayloadPool -{ -public: - - //! Construct an empty PayloadPool - DDSPIPE_CORE_DllAPI PayloadPool(); - - //! Delete PayloadPool and erase every Payload still without release - DDSPIPE_CORE_DllAPI virtual ~PayloadPool(); - - ///// - // FAST DDS PART - - /** - * @brief Reserve in \c cache_change a new payload of max size \c size . - * - * It sets values to the serialized payload inside \c cache_change . - * This method calls \c get_payload for the serialized payload. - * The \c cache_change owner is set to \c this . - * - * @warning length value in \c payload is not modified. - * - * @note This method may reserve new memory. - * - * @param [in] size : Size in bytes of the payload that will be reserved - * @param [out] cache_change : the cache change which SerializedPayload will be set - * - * @return true if everything ok - * @return false if something went wrong - * - * @pre Fields @c cache_change must not have the serialized payload initialized. - */ - DDSPIPE_CORE_DllAPI virtual bool get_payload( - uint32_t size, - eprosima::fastrtps::rtps::CacheChange_t& cache_change) override; // TODO add noexcept once is implemented - - /** - * @brief Store in \c cache_change the \c data payload. - * - * This method set \c cache_change serialized payload to the same data in \c data . - * This method should reuse \c data and not copy it in case the owner of \c data is \c this . - * It sets values to the serialized payload inside \c cache_change . - * - * This method calls \c get_payload for the serialized payload. - * The \c cache_change owner is set to \c this . - * - * @note This method may reserve new memory in case the owner is not \c this . - * - * @param [in,out] data Serialized payload received - * @param [in,out] data_owner Payload pool owning incoming data \c data - * @param [in,out] cache_change Cache change to assign the payload to - * - * @warning @c data_owner can only be changed from @c nullptr to @c this. If a value different from - * @c nullptr is received it should be left unchanged. - * - * @return true if everything ok - * @return false if something went wrong - * - * @pre Fields @c cache_change must not have the serialized payload initialized. - */ - DDSPIPE_CORE_DllAPI virtual bool get_payload( - eprosima::fastrtps::rtps::SerializedPayload_t& data, - IPayloadPool*& data_owner, - eprosima::fastrtps::rtps::CacheChange_t& cache_change) override; // TODO add noexcept once is implemented - - /** - * @brief Release the data from the serialized payload inside \c cache_change . - * - * @note This method must only release the actual memory of a data in case nobody is referencing it anymore. - * - * This method calls \c release_payload for the serialized payload. - * The \c cache_change owner is set to \c nullptr . - * - * @param [in,out] cache_change Cache change to release the payload from - * - * @return true if everything ok - * @return false if something went wrong - * - * @throw IncosistencyException if cache change owner is other than this - */ - DDSPIPE_CORE_DllAPI virtual bool release_payload( - eprosima::fastrtps::rtps::CacheChange_t& cache_change) override; // TODO add noexcept once is implemented - - ///// - // DDSROUTER PART - - /** - * @brief Reserve a new data in \c payload of size \c size. - * - * It sets value \c max_size and \c data of \c payload . - * - * @note This method may reserve new memory. - * - * @warning length value in \c payload is not modified. - * - * @param [in] size : Size in bytes of the payload that will be reserved - * @param [out] payload : the SerializedPayload that will be set - * - * @return true if everything ok - * @return false if something went wrong - * - * @pre Fields @c payload must not have been initialized. - */ - DDSPIPE_CORE_DllAPI virtual bool get_payload( - uint32_t size, - types::Payload& payload) = 0; - - /** - * @brief Store in \c target_payload the data from \c src_payload . - * - * This method set \c target_payload fields \c max_size , \c lenght and \c data . - * This method "should" reuse data in \c src_payload and not copy it in case \c data_owner is \c this . - * - * @note This method may reserve new memory in case the owner is not \c this . - * - * @param [in] src_payload Payload to move to target - * @param [in,out] data_owner Payload pool owning incoming data \c src_payload - * @param [out] target_payload Payload to assign the payload to - * - * @warning @c data_owner can only be changed from @c nullptr to @c this. If a value different from - * @c nullptr is received it must be left unchanged. - * - * @return true if everything ok - * @return false if something went wrong - * - * @pre Fields @c target_payload must not have been initialized. - */ - DDSPIPE_CORE_DllAPI virtual bool get_payload( - const types::Payload& src_payload, - IPayloadPool*& data_owner, - types::Payload& target_payload) = 0; - - /** - * @brief Release the data from the \c payload . - * - * @note This method must only release the actual memory of a data in case nobody is referencing it anymore. - * - * @note This method should use method \c reserve_ to reserve new memory. - * - * Reset the \c payload info. - * - * @param [in,out] payload Payload to release data from - * - * @return true if everything ok - * @return false if something went wrong - * - * @pre @c payload must have been initialized from this pool. - */ - DDSPIPE_CORE_DllAPI virtual bool release_payload( - types::Payload& payload) = 0; - - //! Wether every payload get has been released. - DDSPIPE_CORE_DllAPI virtual bool is_clean() const noexcept; - -protected: - - /** - * @brief Reserve a new space of memory for new data. - * - * It increases \c reserve_count_ . - * - * @param size size of memory chunk to reserve - * @param payload object where introduce the new data pointer - * - * @return true if everything ok - * @return false if something went wrong - */ - DDSPIPE_CORE_DllAPI virtual bool reserve_( - uint32_t size, - types::Payload& payload); - - /** - * @brief Free a memory space. - * - * It increases \c release_count_ . - * - * @param payload object to free the data from - * - * @return true if everything ok - * @return false if something went wrong - * - * @throw \c IncosistencyException if more releases than reserves has been done - */ - DDSPIPE_CORE_DllAPI virtual bool release_( - types::Payload& payload); - - //! Increase \c reserve_count_ - DDSPIPE_CORE_DllAPI void add_reserved_payload_(); - - //! Increase \c release_count_ . Show a warning if there are more releases than reserves. - DDSPIPE_CORE_DllAPI void add_release_payload_(); - - //! Count the number of reserved data from this pool - std::atomic reserve_count_; - //! Count the number of released data from this pool - std::atomic release_count_; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp deleted file mode 100644 index 6436df05a..000000000 --- a/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Interface that represents a generic Participant as part of a DDSRouter. - * - * This class manages the discovery of new remote entities (that do not belong to the router). - * It also works as a factory for Writers and Readers. - * - * Every Participant is associated to a \c ParticipantId that uniquely identifies it. - * - * @note In order to implement new Participants, create a subclass of this Interface and implement every method. - */ -DDSPIPE_CORE_DllAPI class IParticipant -{ -public: - - /** - * @brief Virtual dtor to allow inheritance. - */ - virtual ~IParticipant() = default; - - /** - * @brief Return the unique identifier of this Participant. - * - * @return This Participant id - */ - virtual types::ParticipantId id() const noexcept = 0; - - //! Whether this participant is RTPS - virtual bool is_rtps_kind() const noexcept = 0; - - /** - * @brief Whether this Participant requires to connect ist own readers with its own writers. - */ - virtual bool is_repeater() const noexcept = 0; - - /** - * @brief Return a new Writer - * - * Each writer is associated with a \c Bridge with the topic \c topic . - * This writer will forward messages in this topic. - * - * @param [in] topic : Topic that this Writer will work with. - * - * @return Writer in this Participant referring this topic - * - * @throw \c InitializationException in case the writer creation fails. - */ - virtual std::shared_ptr create_writer( - const ITopic& topic) = 0; - - /** - * @brief Return a new Reader - * - * Each reader is associated with a \c Bridge with the topic \c topic . - * This reader will receive messages in this topic. - * - * @param [in] topic : Topic that this Reader will work with. - * - * @return Reader in this Participant referring this topic - * - * @throw \c InitializationException in case the reader creation fails. - */ - virtual std::shared_ptr create_reader( - const ITopic& topic) = 0; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp deleted file mode 100644 index fd3fa33ec..000000000 --- a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include - -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Interface that represents a generic Reader as part of a DDSRouter. - * - * This class manages the reception of new remote data in a specific topic. - * It also calls the \c Track on_data_available callback whenever new data is received. - * - * @note In order to implement new Readers, create a subclass of this Interface and implement every method. - * @note Also it is needed to add the creation of the Reader in the Participant required. - * - * Readers will start being disabled. - */ -DDSPIPE_CORE_DllAPI class IReader -{ -public: - - /** - * @brief Virtual dtor to allow inheritance. - */ - virtual ~IReader() = default; - - /** - * @brief Enable Reader - * - * A Reader enabled will call on_data_available callback whenever new data is received. - * - * By default the Reader is disabled. Call this method to activate it. - */ - virtual void enable() noexcept = 0; - - /** - * @brief Disable Reader - * - * A disabled Reader does not call on_data_available callback whenever new data is received. - * @note Disabling a Reader does not mean that messages should not arrive, that depends on the implementation. - * - * @warning: This method should stop calling the callback \c on_data_available_lambda if more data arrives while - * disabled. - */ - virtual void disable() noexcept = 0; - - /** - * @brief Set the callback that should be called whenever a new message arrives - * - * Each Reader is associated with one \c Track . This Track has a callback that should be called whenever the - * Reader receives new data. This function sets this callback for the Reader. - * - * @param [in] on_data_available_lambda : \c Track callback - */ - virtual void set_on_data_available_callback( - std::function on_data_available_lambda) noexcept = 0; - - /** - * @brief Unset the callback that should be called whenever a new message arrives. - * - * After this method, the Reader should not notify any message that arrives. - */ - virtual void unset_on_data_available_callback() noexcept = 0; - - /** - * @brief Take oldest received message from the Reader - * - * This method will take the oldest sample received by the Reader and will set it to the argument \c data - * in a way that the payload in \c data must be inside the DDS Router PayloadPool. - * In \c data, the Guid of the Endpoint that originally sent this data must be specified. - * - * @param [out] data : object where the payload received should be copied (referenced) - * - * @return \c RETCODE_OK if the data has been taken correctly - * @return \c RETCODE_NO_DATA if there is no more data to take - * @return \c RETCODE_ERROR if there has been any error while taking a sample - * @return \c RETCODE_NOT_ENABLED if the reader is not enabled (this should not happen) - */ - virtual utils::ReturnCode take( - std::unique_ptr& data) noexcept = 0; - - ///////////////////////// - // RPC REQUIRED METHODS - ///////////////////////// - // TODO remove these methods once the double reference is solved - - //! Get GUID of internal RTPS reader - virtual core::types::Guid guid() const = 0; - - //! Get internal RTPS reader mutex - virtual fastrtps::RecursiveTimedMutex& get_rtps_mutex() const = 0; - - //! Get number of unread cache changes in internal RTPS reader - virtual uint64_t get_unread_count() const = 0; - - virtual types::DdsTopic topic() const = 0; - - virtual types::ParticipantId participant_id() const = 0; - ///////////////////////// -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp b/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp deleted file mode 100644 index 63cc8ed47..000000000 --- a/ddspipe_core/include/ddspipe_core/interface/IRoutingData.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2021 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. - - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief TODO - */ -DDSPIPE_CORE_DllAPI class IRoutingData -{ - -public: - - /** - * @brief Virtual dtor to allow inheritance. - */ - virtual ~IRoutingData() = default; - - /** - * This refers to an internal used identifier that declares which kind of data type is going to be - * transmitted in this Itopic inside the core. - */ - virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept = 0; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp b/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp deleted file mode 100644 index e8149f5fb..000000000 --- a/ddspipe_core/include/ddspipe_core/interface/ITopic.hpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Generic data struct that represents an ITopic of data flow in the Router. - */ -DDSPIPE_CORE_DllAPI class ITopic -{ -public: - - /** - * @brief Virtual dtor to allow inheritance. - */ - virtual ~ITopic() = default; - - virtual bool operator < ( - const ITopic& other) const noexcept = 0; - - virtual bool operator == ( - const ITopic& other) const noexcept = 0; - - //! ITopic name - virtual std::string topic_name() const noexcept = 0; - - //! ITopic unique name in processs - virtual std::string topic_unique_name() const noexcept = 0; - - /** - * This refers to an internal used identifier that declares which kind of data type is going to be - * transmitted in this Itopic inside the core. - */ - virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept = 0; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp b/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp deleted file mode 100644 index 39bc3b144..000000000 --- a/ddspipe_core/include/ddspipe_core/interface/IWriter.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * Interface that represents a generic Writer as part of a DDSRouter. - * - * This class manages the sending of data to remote endpoints in a specific topic. - * - * @note In order to implement new Writers, create a subclass of this Interface and implement every method. - * @note Also it is needed to add the creation of the Writer in the Participant required. - * - * Writers will start being disabled. - */ -DDSPIPE_CORE_DllAPI class IWriter -{ -public: - - /** - * @brief Virtual dtor to allow inheritance. - */ - virtual ~IWriter() = default; - - /** - * @brief Enable Writer - * - * A Writer enabled can send messages. - * - * By default the Writer is disabled. Call this method to activate it. - */ - virtual void enable() noexcept = 0; - - /** - * @brief Disable Writer - * - * A Writer disabled does not send data. - * @note Method \c write should never be called from a disabled writer - */ - virtual void disable() noexcept = 0; - - /** - * @brief Asynchronously write a message for remote endpoints - * - * This method will take the data received by another Participant's Reader and should send it forward. - * In the variable \c data there is the \c Guid of the Endpoint that originally sent the data. - * In \c data there is also the payload of the data. This payload should be copied/moved from the DDSRouter's - * PayloadPool to the Writer's PayloadPool (in case it is the same Pool, the data will not be copied). - * The writer should write asynchronously. It should take the data and exit the function, - * and internally send the data. - * - * Once the data has been sent, the Writer should release the payload. - * - * @param [in] data : object containing the payload to be sent - * - * @return \c RETCODE_OK if the data has been written correctly - * @return \c RETCODE_ERROR if there has been any error while writing the sample - * @return \c RETCODE_NOT_ENABLED if the writer is not enabled (this should not happen) - */ - virtual utils::ReturnCode write( - IRoutingData& data) noexcept = 0; -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp b/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp deleted file mode 100644 index 0de0c74fe..000000000 --- a/ddspipe_core/include/ddspipe_core/testing/entities/blank_entities.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// 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. - -#pragma once - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace testing { - -struct BlankParticipant : public IParticipant -{ - types::ParticipantId id() const noexcept override; - - bool is_rtps_kind() const noexcept override; - - bool is_repeater() const noexcept override; - - std::shared_ptr create_writer( - const ITopic& topic) override; - - std::shared_ptr create_reader( - const ITopic& topic) override; -}; - -struct BlankReader : public IReader -{ - void enable() noexcept override; - - void disable() noexcept override; - - void set_on_data_available_callback( - std::function on_data_available_lambda) noexcept override; - - void unset_on_data_available_callback() noexcept override; - - utils::ReturnCode take( - std::unique_ptr& data) noexcept override; - - core::types::Guid guid() const override; - - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override; - - uint64_t get_unread_count() const override; - - types::DdsTopic topic() const override; - - types::ParticipantId participant_id() const override; -}; - -struct BlankWriter : public IWriter -{ - void enable() noexcept override; - - void disable() noexcept override; - - utils::ReturnCode write( - IRoutingData& data) noexcept override; -}; - -struct BlankTopic : public ITopic -{ - - bool operator < ( - const ITopic& other) const noexcept override; - - bool operator == ( - const ITopic& other) const noexcept override; - - std::string topic_name() const noexcept override; - - std::string topic_unique_name() const noexcept override; - - types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; -}; - -struct BlankRoutingData : public IRoutingData -{ - types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; -}; - -const types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "test_type::blank::v0"; - -} /* namespace testing */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp b/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp deleted file mode 100644 index 368ccad2a..000000000 --- a/ddspipe_core/include/ddspipe_core/testing/entities/mock_entities.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// 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. - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace testing { - -struct MockParticipant : public BlankParticipant -{ - types::ParticipantId id() const noexcept override; - - std::shared_ptr create_writer( - const ITopic& topic) override; - - std::shared_ptr create_reader( - const ITopic& topic) override; -}; - -struct MockReader : public BlankReader -{ - void enable() noexcept override; - - void disable() noexcept override; - - void set_on_data_available_callback( - std::function on_data_available_lambda) noexcept override; - - void unset_on_data_available_callback() noexcept override; - - utils::ReturnCode take( - std::unique_ptr& data) noexcept override; - - core::types::Guid guid() const override; - - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override; - - uint64_t get_unread_count() const override; - - types::DdsTopic topic() const override; - - types::ParticipantId participant_id() const override; -}; - -struct MockReader : public BlankWriter -{ - void enable() noexcept override; - - void disable() noexcept override; - - utils::ReturnCode write( - IRoutingData& data) noexcept override; -}; - -struct MockTopic : public BlankTopic -{ - types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; -}; - -struct MockRoutingData : public BlankRoutingData -{ - types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; -}; - -const types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_TEST = "testing_type::mock::v0"; - -} /* namespace testing */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/testing/random_values.hpp b/ddspipe_core/include/ddspipe_core/testing/random_values.hpp deleted file mode 100644 index 05b7854f1..000000000 --- a/ddspipe_core/include/ddspipe_core/testing/random_values.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace testing { - -DDSPIPE_CORE_DllAPI types::Guid random_guid( - unsigned int seed = 0); - -DDSPIPE_CORE_DllAPI types::DomainId random_domain( - unsigned int seed = 0); - -DDSPIPE_CORE_DllAPI types::GuidPrefix random_guid_prefix( - unsigned int seed = 0, - bool ros = false); - -DDSPIPE_CORE_DllAPI types::ParticipantId random_participant_id( - unsigned int seed = 0); - -DDSPIPE_CORE_DllAPI types::DdsTopic random_dds_topic( - unsigned int seed = 0); - -DDSPIPE_CORE_DllAPI types::EndpointKind random_endpoint_kind( - unsigned int seed = 0); - -DDSPIPE_CORE_DllAPI types::Endpoint random_endpoint( - unsigned int seed = 0); - -DDSPIPE_CORE_DllAPI types::TopicQoS random_topic_qos( - unsigned int seed = 0); - -} /* namespace testing */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp deleted file mode 100644 index 8b7a6c257..000000000 --- a/ddspipe_core/include/ddspipe_core/types/data/RpcPayloadData.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2021 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. - - -#pragma once - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * @brief Structure of the Data received from a Reader containing the data itself and its properties. - * - * Properties are related information regarding the data and QoS of the source. - */ -struct RpcPayloadData : public RtpsPayloadData -{ - - DDSPIPE_CORE_DllAPI virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; - - //! Write params associated to the received cache change - utils::Fuzzy write_params{}; - - //! Sequence number of the received cache change - eprosima::fastrtps::rtps::SequenceNumber_t origin_sequence_number{}; - - //! Sequence Number with which the internal writer (ddsrouter writer) has sent this message - eprosima::fastrtps::rtps::SequenceNumber_t sent_sequence_number; -}; - -/** - * @brief Id to identify the internal topic type id that uses \c RpcPayloadData . - */ -const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RPC = "type::rpc::v0"; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp b/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp deleted file mode 100644 index e0c8d33af..000000000 --- a/ddspipe_core/include/ddspipe_core/types/data/RtpsPayloadData.hpp +++ /dev/null @@ -1,93 +0,0 @@ -// 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. - - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * @brief Structure of the Data received from a Reader containing the data itself and its properties. - * - * Properties are related information regarding the data and QoS of the source. - */ -struct RtpsPayloadData : public core::IRoutingData -{ - - DDSPIPE_CORE_DllAPI RtpsPayloadData() = default; - - /** - * @brief Destroy the Rtps Payload Data object - * - * Free the memory for the payload in the corresponding payload pool (if defined). - */ - DDSPIPE_CORE_DllAPI virtual ~RtpsPayloadData(); - - DDSPIPE_CORE_DllAPI RtpsPayloadData(const RtpsPayloadData& ) = delete; - - DDSPIPE_CORE_DllAPI virtual types::TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; - - //! Payload of the data received. The data in this payload must belong to the PayloadPool. - core::types::Payload payload{}; - - /** - * @brief PayloadPool owner of the payload. - * - * If nullptr, the owner has not been set. - */ - core::PayloadPool* payload_owner{nullptr}; - - //! Specific Writer QoS of the Data - core::types::SpecificEndpointQoS writer_qos{}; - - //! Instance of the message (default no instance) - core::types::InstanceHandle instanceHandle{}; - - //! Kind of the change - core::types::ChangeKind kind{}; - - //! Source time stamp of the message - core::types::DataTime source_timestamp{}; - - //! Guid of the source entity that has transmit the data - core::types::Guid source_guid{}; - - //! Id of the participant from which the Reader has received the data. - core::types::ParticipantId participant_receiver{}; -}; - -/** - * @brief Id to identify the internal topic type id that uses \c RtpsPayloadData . - */ -const core::types::TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_RTPS = "payload::rtps::v0"; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp b/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp deleted file mode 100644 index 95408a270..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/DomainId.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -// Use FastDDS Domain Id type -using DomainIdType = eprosima::fastdds::dds::DomainId_t; - -/** - * @brief RTPS Domain ID. - */ -struct DomainId : public IConfiguration -{ - - DDSPIPE_CORE_DllAPI DomainId () = default; - - DDSPIPE_CORE_DllAPI DomainId (bool discovery_server) noexcept; - - DDSPIPE_CORE_DllAPI operator DomainIdType() const noexcept; - - DDSPIPE_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - //! Value of Fast DDS Domain ID - DomainIdType domain_id = DEFAULT_DOMAIN_ID; - - ///////////////////////// - // STATIC CONST VALUES - ///////////////////////// - - //! Default value for Simple Discovery - static constexpr const DomainIdType DEFAULT_DOMAIN_ID = 0; - - //! Default value for Discovery Server - static constexpr const DomainIdType DEFAULT_DISCOVERY_SERVER_DOMAIN_ID = 66; - - //! Maximum Domain Id valid - static constexpr const DomainIdType MAX_DOMAIN_ID = 232; -}; - -//! \c DomainId serializator -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& output, - const DomainId& domain); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp deleted file mode 100644 index 8a4e44c14..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/Endpoint.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -using EndpointKindType = unsigned int; - -//! Possible kinds of the endpoint -ENUMERATION_BUILDER( - EndpointKind, - invalid, - writer, - reader - ); - -/** - * Data collection to describe an Endpoint - * - * This class works as a data storage struct with the information of a discovered Endpoint - */ -struct Endpoint -{ - - //! Default Endpoint that returns an invalid one - DDSPIPE_CORE_DllAPI Endpoint() = default; - - /******************** - * SPECIFIC GETTERS * - ********************/ - - //! Qos of the topic - DDSPIPE_CORE_DllAPI TopicQoS topic_qos() const noexcept; - - //! Whether the endpoint is a writer - DDSPIPE_CORE_DllAPI bool is_writer() const noexcept; - - //! Whether the endpoint is a reader - DDSPIPE_CORE_DllAPI bool is_reader() const noexcept; - - //! Whether the endpoint belongs to a RPC server (i.e. is request reader or reply writer) - DDSPIPE_CORE_DllAPI bool is_server_endpoint() const noexcept; - - //! Equality operator (does not take \c active and \c discoverer_participant_id into consideration) - DDSPIPE_CORE_DllAPI bool operator ==( - const Endpoint& other) const noexcept; - - //! Kind of the endpoint - EndpointKind kind {EndpointKind::invalid}; - - //! Unique id of the endpoint - Guid guid {}; - - //! Topic that this endpoint belongs to - DdsTopic topic {}; - - //! Specific QoS of the entity - SpecificEndpointQoS specific_qos {}; - - //! Whether the endpoint is currently active - bool active {true}; - - //! Id of participant who discovered this endpoint - ParticipantId discoverer_participant_id {}; -}; - -/** - * @brief \c Endpoint to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const Endpoint& endpoint); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp deleted file mode 100644 index 61a7a9b66..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/Guid.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -//! Unique Id of every Endpoint -class DDSPIPE_CORE_DllAPI Guid : public fastrtps::rtps::GUID_t -{ -public: - - //! Using parent constructors - using fastrtps::rtps::GUID_t::GUID_t; - - //! Default constructor - Guid() = default; - - //! Copy constructor - Guid( - const fastrtps::rtps::GUID_t& x); - - //! Move constructor - Guid( - fastrtps::rtps::GUID_t&& x); - - //! Equal operator (inherited from GUID_t) - Guid& operator = ( - const fastrtps::rtps::GUID_t& other) noexcept; - - /** - * Whether the guid is a valid one - * - * To be valid, the GuidPrefix and the EntityId must not be invalid / unknown - */ - bool is_valid() const noexcept; - - //! Return GuidPrefix from this Guid - GuidPrefix guid_prefix() const noexcept; -}; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp b/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp deleted file mode 100644 index ef6190e6a..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/GuidPrefix.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * @brief GuidPrefix specific class for DDSRouter - * - * This class extends the \c GuidPrefix_t class in FastDDS, which is a RTPS Participant Unique Id. - * This class does not belong to class \c Guid due to a design flaw in OOP (parallel hierarchy is the future). - */ -class DDSPIPE_CORE_DllAPI GuidPrefix : public fastrtps::rtps::GuidPrefix_t -{ -public: - - //! Using parent constructors - using fastrtps::rtps::GuidPrefix_t::GuidPrefix_t; - - //! Constructor from Parent class - GuidPrefix ( - const GuidPrefix_t& guid_prefix) noexcept; - - /** - * @brief Construct a new Guid Prefix object from a string - * - * Format required: "xx.x...xx" with 12 values. - * Non set zeros is allowed. - * Lower case and Capital case are allowed for hexadecimal alphabetic numbers. - * - * @param guid_prefix string with the Guid Prefix - */ - GuidPrefix ( - const std::string& str_prefix); - - /** - * @brief Construct a new Guid Prefix object from a const char array - * - * Uses the constructor from string. - * @note This is used because creating a Guid Prefix from a const char * uses the constructor with the uint32_t id. - */ - GuidPrefix ( - const char* str_prefix); - - /** - * @brief Construct a new Guid Prefix object by seed - * - * Use \c id as seed to create an arbitrary \c GuidPrefix. - * It could be used as default Guid the ROS2 Discovery Server Guid [44.53.00.5f.45.50.52.4f.53.49.4d.41] - * or the DDSRouter Discovery Server Guid [01.0f.00.00.00.00.00.00.00.00.ca.fe]. - * - * The value in 3rd position ([2]) is the one set by seed. - * - * @todo use the seed of \c id to modify the whole guid and not only one of the 12 values. - * - * @param ros : whether to use the Discovery Server ROS2 specific guid [Default: false] - * @param id : number to seed for the final Guid Prefix [Default: 0] - */ - GuidPrefix ( - bool ros = false, - uint32_t id = 0) noexcept; - - /** - * @brief Uses Router default Guid without using ROS Discovery Server - * - * @param id : number to seed for the final Guid Prefix [Default: 0] - */ - GuidPrefix ( - uint32_t id) noexcept; - - GuidPrefix& operator = ( - const fastrtps::rtps::GuidPrefix_t& other) noexcept; - - /** - * Whether the guid prefix is a valid one - * - * To be valid, the GuidPrefix must not be invalid / unknown - */ - bool is_valid() const noexcept; - - //! Default DDSRouter Discovery Server Guid Prefix - static constexpr const char* SERVER_DEFAULT_GUID_PREFIX_STR = "01.0f.00.00.00.00.00.00.00.00.ca.fe"; - - /** - * @brief Default ROS2 Discovery Server Guid Prefix - * - * @note This coulde reuse fastdds \c DEFAULT_ROS2_SERVER_GUIDPREFIX if it was constexpr. - */ - static constexpr const char* ROS_DISCOVERY_SERVER_GUID_PREFIX_STR = "44.53.00.5f.45.50.52.4f.53.49.4d.41"; -}; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp b/ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp deleted file mode 100644 index c5cebf6b1..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/Payload.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// 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. - - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -//! Durability kind enumeration -using PartitionQosPolicy = eprosima::fastdds::dds::PartitionQosPolicy; - -//! Partition configuration -using OwnershipStrengthQosPolicy = eprosima::fastdds::dds::OwnershipStrengthQosPolicy; - -//! Instance Handler type -using InstanceHandle = eprosima::fastrtps::rtps::InstanceHandle_t; - -//! Instance Handler type -using ChangeKind = eprosima::fastrtps::rtps::ChangeKind_t; - -//! Fast DDS Time -using DataTime = eprosima::fastrtps::rtps::Time_t; - -//! Kind of every unit that creates a Payload -using PayloadUnit = eprosima::fastrtps::rtps::octet; - -//! Payload references the raw data received. -using Payload = eprosima::fastrtps::rtps::SerializedPayload_t; - -//! \c octet to stream serializator -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const PayloadUnit& octet); - -//! \c SerializedPayload_t to stream serializator -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const Payload& payload); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp b/ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp deleted file mode 100644 index d5da28dbe..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/SpecificEndpointQoS.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -//! Partitions -using PartitionQosPolicy = eprosima::fastdds::dds::PartitionQosPolicy; - -//! Ownership Strength -using OwnershipStrengthQosPolicy = eprosima::fastdds::dds::OwnershipStrengthQosPolicy; - -/** - * Collection of QoS of an Endpoint - * - * @todo Divide this in Common, Reader and Writer QoS - */ -struct DDSPIPE_CORE_DllAPI SpecificEndpointQoS -{ - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default SpecificEndpointQoS with reader less restrictive parameters - SpecificEndpointQoS() = default; - - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Minor comparison operator - bool operator < ( - const SpecificEndpointQoS& other) const noexcept; - - //! Equality operator - bool operator == ( - const SpecificEndpointQoS& other) const noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Partitions of the data - PartitionQosPolicy partitions{}; - - //! Ownership strength of the data - OwnershipStrengthQosPolicy ownership_strength{}; -}; - -/** - * @brief \c PartitionQosPolicy to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const PartitionQosPolicy& qos); - -/** - * @brief \c OwnershipStrengthQosPolicy to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const OwnershipStrengthQosPolicy& qos); - -/** - * @brief \c SpecificEndpointQoS to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const SpecificEndpointQoS& qos); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp b/ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp deleted file mode 100644 index 719cf6f9d..000000000 --- a/ddspipe_core/include/ddspipe_core/types/dds/TopicQoS.hpp +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -//! Durability kind enumeration -using DurabilityKind = eprosima::fastrtps::rtps::DurabilityKind_t; - -//! Reliability kind enumeration -using ReliabilityKind = eprosima::fastrtps::rtps::ReliabilityKind_t; - -//! History kind enumeration -using HistoryDepthType = unsigned int; - -//! Ownership configuration -using OwnershipQosPolicyKind = eprosima::fastdds::dds::OwnershipQosPolicyKind; - -/** - * Collection of QoS related with a Topic. - * - * The QoS associated with Topic are: - * - Reliability - * - Durability - * - Ownership - * - Partitions - * - History Depth (history kind is always KEEP_LAST) - * - * @warning partitions are considered as a QoS, thus a Topic can only have partitions, or not have any, but cannot - * support empty partition and partitions. - * - * @todo add keys to Topic QoS - */ -struct DDSPIPE_CORE_DllAPI TopicQoS -{ - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default TopicQoS with reader less restrictive parameters - TopicQoS(); - - ///////////////////////// - // OPERATORS - ///////////////////////// - - //! Equality operator - bool operator ==( - const TopicQoS& other) const noexcept; - - ///////////////////////// - // AUXILIARY METHODS - ///////////////////////// - - //! Whether the Topic is RELIABLE, not BEST_EFFORT - bool is_reliable() const noexcept; - - //! Whether the Topic is TRANSIENT_LOCAL, not VOLATILE - bool is_transient_local() const noexcept; - - //! Whether the Topic has EXCLUSIVE_OWNERSHIP, not SHARED_OWNERSHIP - bool has_ownership() const noexcept; - - //! Whether the Topic has partitions, not empty partition - bool has_partitions() const noexcept; - - ///////////////////////// - // GLOBAL VARIABLES - ///////////////////////// - - /** - * @brief Global value to store the default history depth in this execution. - * - * This value can change along the execution. - * Every new TopicQoS object will use this value as \c history_depth default. - */ - static std::atomic default_history_depth; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Durability kind (Default = VOLATILE) - DurabilityKind durability_qos = DurabilityKind::VOLATILE; - - //! Reliability kind (Default = BEST_EFFORT) - ReliabilityKind reliability_qos = ReliabilityKind::BEST_EFFORT; - - //! Ownership kind of the topic - OwnershipQosPolicyKind ownership_qos = OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS; - - //! Whether the topics uses partitions - bool use_partitions = false; - - /** - * @brief History Qos - * - * @note Default value would be taken from \c default_history_depth in object creation. - * @note It only stores the depth because in router it will always be keep last, as RTPS has not resource limits. - */ - HistoryDepthType history_depth = 5000; - - //! Whether the topic has key or not - bool keyed = false; -}; - -/** - * @brief \c DurabilityKind to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const DurabilityKind& kind); - -/** - * @brief \c ReliabilityKind to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const ReliabilityKind& kind); - -/** - * @brief \c OwnershipQosPolicyKind to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const OwnershipQosPolicyKind& qos); - -/** - * @brief \c TopicQoS to stream serialization - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const TopicQoS& qos); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp b/ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp deleted file mode 100644 index f21231b3f..000000000 --- a/ddspipe_core/include/ddspipe_core/types/participant/ParticipantId.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * @brief Unique Id for each DDSRouter Participant - * - * This class represents the ID that uniquely identifies a Participant inside the DDSRouter. - */ -using ParticipantId = std::string; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp deleted file mode 100644 index 29367c15c..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/Topic.hpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include - -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * Generic data struct that represents a Topic of data flow in the Router. - */ -struct Topic : public ITopic , public IConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default constructor - DDSPIPE_CORE_DllAPI Topic() = default; - - ///////////////////////// - // OPERATORS - ///////////////////////// - - /** - * @brief Specialize parent compare operator - * - * This is specialized so if the comparison object is a std Topic it is compared as it. - */ - DDSPIPE_CORE_DllAPI virtual bool operator==(const ITopic& other) const noexcept override; - - DDSPIPE_CORE_DllAPI virtual bool operator<(const ITopic& other) const noexcept override; - - ///////////////////////// - // METHODS - ///////////////////////// - - //! ITopic name - DDSPIPE_CORE_DllAPI virtual std::string topic_name() const noexcept override; - - DDSPIPE_CORE_DllAPI virtual TopicInternalTypeDiscriminator internal_type_discriminator() const noexcept override; - - DDSPIPE_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - ///////////////////////// - // METHODS TO OVERRIDE - ///////////////////////// - - //! ITopic unique name in processs - DDSPIPE_CORE_DllAPI virtual std::string topic_unique_name() const noexcept override; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - /** - * @brief Topic name - * - * @note it is called with m_ because the name \c topic_name was already in used by parent. - */ - std::string m_topic_name{}; - - /** - * This refers to an internal used identifier that declares which kind of data type is going to be - * transmitted in this topic inside the core. - * - * @note it is called with m_ because the name \c topic_name was already in used by parent. - */ - TopicInternalTypeDiscriminator m_internal_type_discriminator{INTERNAL_TOPIC_TYPE_NONE}; -}; - -/** - * Serialization method for \c Topic object. - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const Topic& t); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp b/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp deleted file mode 100644 index 2a0bba71d..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/TopicInternalTypeDiscriminator.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - - -#pragma once - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * @brief Reference the type that is used internally in the DDS Pipe to hold the data transmitted. - * - * @warning as this is a const char* it is strongly suggested to only use constexpr or static values. - */ -using TopicInternalTypeDiscriminator = std::string; - -const TopicInternalTypeDiscriminator INTERNAL_TOPIC_TYPE_NONE = ""; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp deleted file mode 100644 index 78c7d9927..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DdsTopic.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * Data struct that represents a DDS Topic of data flow in the Router. - */ -struct DdsTopic : public DistributedTopic -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default constructor - DDSPIPE_CORE_DllAPI DdsTopic(); - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSPIPE_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - DDSPIPE_CORE_DllAPI virtual std::string topic_unique_name() const noexcept override; - - ///////////////////////// - // STATIC METHODS - ///////////////////////// - - //! Whether a name and type can refer to a correct DDS Topic. - DDSPIPE_CORE_DllAPI static bool is_valid_dds_topic( - const std::string& topic_name, - const std::string& type_name, - utils::Formatter& error_msg) noexcept; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Topic Type name - std::string type_name{}; - - /** - * @brief Topic QoS - * - * @todo this makes few sense here as the qos does not depend on the QoS itself but in the discovery of it. - * This Topic class is a proxy, not an actual Topic Entity of DDS, so it should not have QoS. - */ - types::TopicQoS topic_qos{}; -}; - -/** - * Serialization method for \c DdsTopic object. - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const DdsTopic& t); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp deleted file mode 100644 index ae0914888..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/dds/DistributedTopic.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * Data struct that represents a Distributed Topic of data flow in the Router. - * - * @note this not represents a real DDS network topic, but an "abstract" distributed one. - */ -struct DDSPIPE_CORE_DllAPI DistributedTopic : public Topic -{ - // Extend nothing -}; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp deleted file mode 100644 index fac307f6b..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/filter/IFilterTopic.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * Generic data struct that represent a filter for a DDS Topic. - */ -struct DDSPIPE_CORE_DllAPI IFilterTopic -{ - - virtual ~IFilterTopic() = default; - - ///////////////////////// - // OPERATORS - ///////////////////////// - - virtual bool operator < ( - const IFilterTopic& other) const noexcept; - - virtual bool operator == ( - const IFilterTopic& other) const noexcept; - - ///////////////////////// - // FILTER METHODS - ///////////////////////// - - /** - * Whether this topic filters the same of the topic by argument. - * - * This method is used to prevent duplications in filter topic lists. - * If the topic \c other filters a subset of the topics filtered by \c this, it returns true. - * - * Example: {<*>:<*>} contains every IFilterTopic. - * Example: {<>:<>} is contained by every IFilterTopic. - * - * @param other: Other topic to check if it is contained - * - * @return: True if \c other topic filters a subset of \c this - */ - virtual bool contains( - const IFilterTopic& other) const = 0; - - /** - * Whether a Real Topic matches the filter of this topic. - * - * Virtual method. This method should be implemented in subclasses. - * - * @param topic: Real topic to check if it is filtered - * - * @return: True if \c topic matches with \c this filter - */ - virtual bool matches( - const ITopic& topic) const = 0; - - /** - * @brief Serialize the method in a \c ostream object. - * - * This method is the same as \c operator<< . - * It is implemented to allow virtual \c operator<< . - * - * @param [out] os return value of this serialized. - * @return std::ostream& this serialized inside \c os . - */ - virtual std::ostream& serialize( - std::ostream& os) const = 0; -}; - -/** - * Serialization method for \c IFilterTopic object. - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const IFilterTopic& t); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp deleted file mode 100644 index a60f1d746..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * Data struct that uses wildcards (*, ?) to filter a DDS Router. - */ -struct WildcardDdsFilterTopic : public IFilterTopic -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - //! Default ctor that does match with every topic. - DDSPIPE_CORE_DllAPI WildcardDdsFilterTopic() = default; - - ///////////////////////// - // FILTER METHODS - ///////////////////////// - - //! Implement \c contains parent method. - DDSPIPE_CORE_DllAPI virtual bool contains( - const IFilterTopic& other) const override; - - //! Implement \c matches parent method. - DDSPIPE_CORE_DllAPI virtual bool matches( - const ITopic& topic) const override; - - ///////////////////////// - // SERIALIZATION METHODS - ///////////////////////// - - //! Override parent \c serialize method. - DDSPIPE_CORE_DllAPI virtual std::ostream& serialize( - std::ostream& os) const override; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Topic name filter - utils::Fuzzy topic_name; - - //! Type name filter. If not set matches with all. - utils::Fuzzy type_name; - -protected: - - ///////////////////////// - // INTERNAL METHODS - ///////////////////////// - - //! Specialization for type of topic. Only specialized for DdsTopic. - DDSPIPE_CORE_DllAPI bool matches_( - const DdsTopic& real_topic) const; -}; - -/** - * Serialization method for \c WildcardDdsFilterTopic object. - */ -DDSPIPE_CORE_DllAPI std::ostream& operator <<( - std::ostream& os, - const WildcardDdsFilterTopic& t); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp b/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp deleted file mode 100644 index 1876d2bd0..000000000 --- a/ddspipe_core/include/ddspipe_core/types/topic/rpc/RpcTopic.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * Class that represents a RPC service in a DDS network. - * It is composed of a pair of DDS topics; one for request and other for reply. - * These two DDS topics are formed by mangling a \c service_name with different prefix and suffixes. - */ -class RpcTopic -{ -public: - - //! Constructor by service name, request topic and reply topic - DDSPIPE_CORE_DllAPI RpcTopic( - const std::string& service_name, - const DdsTopic& topic_request, - const DdsTopic& topic_reply) noexcept; - - //! Constructor by request/reply topic only (infers service name and the other request/reply topic) - DDSPIPE_CORE_DllAPI RpcTopic( - const DdsTopic& topic) noexcept; - - DDSPIPE_CORE_DllAPI RpcTopic(const RpcTopic& other) noexcept; - - //! Service name getter - DDSPIPE_CORE_DllAPI const std::string& service_name() const; - - //! Request topic getter - DDSPIPE_CORE_DllAPI const DdsTopic& request_topic() const; - - //! Reply topic getter - DDSPIPE_CORE_DllAPI const DdsTopic& reply_topic() const; - - //! Whether a topic is a request topic - DDSPIPE_CORE_DllAPI static bool is_request_topic( - const DdsTopic& topic); - - //! Whether a topic is a reply topic - DDSPIPE_CORE_DllAPI static bool is_reply_topic( - const DdsTopic& topic); - - //! Whether a topic is a service topic (request or reply topic) - DDSPIPE_CORE_DllAPI static bool is_service_topic( - const DdsTopic& topic); - - /** - * Minor operator - * - * It compares both service names lexicographically - */ - bool operator <( - const RpcTopic& other) const; - -protected: - - //! Name of the service - std::string service_name_; - - //! Topic used for transmitting requests - DdsTopic request_topic_; - - //! Topic used for transmitting replies - DdsTopic reply_topic_; - - static const std::string REQUEST_PREFIX_STR; - static const std::string REPLY_PREFIX_STR; - static const std::string REQUEST_STR; - static const std::string REPLY_STR; - static const std::string RESPONSE_STR; -}; - -/** - * Serialization method - * - * It prints the service name inside "{}" - * Example: RpcTopic{ServiceName} - */ -std::ostream& operator <<( - std::ostream& os, - const RpcTopic& a); - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/package.xml b/ddspipe_core/package.xml deleted file mode 100644 index f24165755..000000000 --- a/ddspipe_core/package.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - ddspipe_core - 1.1.0 - - *eprosima DDS Pipe* C++ library to communicate different interfaces. - - Raul Sánchez-Mateos - Javier París - Juan López - Apache 2.0 - - https://www.eprosima.com/ - https://github.com/eProsima/DDS-Router/issues - https://github.com/eProsima/DDS-Router - - cmake - - fastrtps - cpp_utils - cmake_utils - - doxygen - - googletest-distribution - - - cmake - - diff --git a/ddspipe_core/project_settings.cmake b/ddspipe_core/project_settings.cmake deleted file mode 100644 index a876dad87..000000000 --- a/ddspipe_core/project_settings.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2022 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. - -############################################################################### -# Set settings for project ddspipe_core -############################################################################### - -set(MODULE_NAME - ddspipe_core) - -set(MODULE_SUMMARY - "C++ library to build and run a DDS Router.") - -set(MODULE_FIND_PACKAGES - fastcdr - fastrtps - cpp_utils) - -set(fastrtps_MINIMUM_VERSION "2.8") - -set(MODULE_DEPENDENCIES - $<$:iphlpapi$Shlwapi> - ${MODULE_FIND_PACKAGES}) diff --git a/ddspipe_core/src/cpp/communication/Bridge.cpp b/ddspipe_core/src/cpp/communication/Bridge.cpp deleted file mode 100644 index 09ec0744c..000000000 --- a/ddspipe_core/src/cpp/communication/Bridge.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -Bridge::Bridge( - const std::shared_ptr& participants_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool) - : participants_(participants_database) - , payload_pool_(payload_pool) - , thread_pool_(thread_pool) - , enabled_(false) -{ -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp b/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp deleted file mode 100644 index 61978e2c6..000000000 --- a/ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -DdsBridge::DdsBridge( - const utils::Heritable& topic, - const std::shared_ptr& participants_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool) - : Bridge(participants_database, payload_pool, thread_pool) - , topic_(topic) -{ - logDebug(DDSROUTER_DDSBRIDGE, "Creating DdsBridge " << *this << "."); - - std::set ids = participants_->get_participants_ids(); - - std::map> writers; - std::map> readers; - - // Generate readers and writers for each participant - for (const auto& id: ids) - { - std::shared_ptr participant = participants_database->get_participant(id); - - writers[id] = participant->create_writer(*topic); - readers[id] = participant->create_reader(*topic); - } - - // Generate tracks - for (ParticipantId id: ids) - { - // List of all Participants - std::map> writers_except_one = - writers; // Create a copy of the map - - if (!participants_->get_participant(id)->is_repeater()) - { - // Remove this Track source participant because it is not repeater - writers_except_one.erase(id); - - logDebug( - DDSROUTER_DDSBRIDGE, - "Not adding own Writer to Track in " << *this << " in Participant " << id << "."); - } - - // This insert is required as there is no copy method for Track - // Tracks are always created disabled and then enabled with Bridge enable() method - tracks_[id] = - std::make_unique( - topic, - id, - readers[id], - std::move(writers_except_one), - payload_pool, - thread_pool); - } - - logDebug(DDSROUTER_DDSBRIDGE, "DdsBridge " << *this << " created."); -} - -DdsBridge::~DdsBridge() -{ - logDebug(DDSROUTER_DDSBRIDGE, "Destroying DdsBridge " << *this << "."); - - // Disable every Track before destruction - disable(); - - logDebug(DDSROUTER_DDSBRIDGE, "DdsBridge " << *this << " destroyed."); -} - -void DdsBridge::enable() noexcept -{ - std::lock_guard lock(mutex_); - - if (!enabled_) - { - logInfo(DDSROUTER_DDSBRIDGE, "Enabling DdsBridge for topic " << topic_->topic_name() << "."); - - // ATTENTION: reference needed or it would copy Track - for (auto& track_it : tracks_) - { - track_it.second->enable(); - } - - enabled_ = true; - } -} - -void DdsBridge::disable() noexcept -{ - std::lock_guard lock(mutex_); - - if (enabled_) - { - logInfo(DDSROUTER_DDSBRIDGE, "Disabling DdsBridge for topic " << topic_->topic_name() << "."); - - // ATTENTION: reference needed or it would copy Track - for (auto& track_it : tracks_) - { - track_it.second->disable(); - } - - enabled_ = false; - } -} - -std::ostream& operator <<( - std::ostream& os, - const DdsBridge& bridge) -{ - os << "DdsBridge{" << bridge.topic_->topic_name() << "}"; - return os; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/communication/dds/Track.cpp b/ddspipe_core/src/cpp/communication/dds/Track.cpp deleted file mode 100644 index 2ceb14334..000000000 --- a/ddspipe_core/src/cpp/communication/dds/Track.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2021 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 Track.cpp - * - */ - -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -const unsigned int Track::MAX_MESSAGES_TRANSMIT_LOOP_ = 100; - -Track::Track( - const utils::Heritable& topic, - const types::ParticipantId& reader_participant_id, - const std::shared_ptr& reader, - std::map>&& writers, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool) noexcept - : topic_(topic) - , reader_participant_id_(reader_participant_id) - , reader_(reader) - , writers_(std::move(writers)) - , payload_pool_(payload_pool) - , enabled_(false) - , exit_(false) - , data_available_status_(DataAvailableStatus::no_more_data) - , transmit_task_id_(utils::new_unique_task_id()) - , thread_pool_(thread_pool) -{ - logDebug(DDSROUTER_TRACK, "Creating Track " << *this << "."); - - // Set this track to on_data_available lambda call - reader_->set_on_data_available_callback(std::bind(&Track::data_available_, this)); - - // Set slot in thread pool - thread_pool_->slot( - transmit_task_id_, - std::bind(&Track::transmit_, this)); - - logDebug(DDSROUTER_TRACK, "Track " << *this << " created."); -} - -Track::~Track() -{ - logDebug(DDSROUTER_TRACK, "Destroying Track " << *this << "."); - - // Disable reader and writers - disable(); - - // Unset callback on the Reader (this is needed as Reader will live longer than Track) - reader_->unset_on_data_available_callback(); - - // It does need to guard the mutex to avoid notifying Track thread while it is checking variable condition - // Set exit status and call transmit thread to awake and terminate. Then wait for it. - exit_.store(true); - - logDebug(DDSROUTER_TRACK, "Track " << *this << " destroyed."); -} - -void Track::enable() noexcept -{ - std::lock_guard lock(track_mutex_); - - if (!enabled_) - { - logInfo(DDSROUTER_TRACK, "Enabling Track " << reader_participant_id_ << " for topic " << topic_->topic_name() << "."); - enabled_ = true; - - // Enable writers before reader, to avoid starting a transmission (not protected with \c track_mutex_) which may - // attempt to write with a yet disabled writer - - // Enabling writers - for (auto& writer_it : writers_) - { - writer_it.second->enable(); - } - - // Enabling reader - reader_->enable(); - - } -} - -void Track::disable() noexcept -{ - std::lock_guard lock(track_mutex_); - - if (enabled_) - { - logInfo(DDSROUTER_TRACK, "Disabling Track " << reader_participant_id_ << " for topic " << topic_->topic_name() << "."); - - // Do disable before stop in the mutex so the Track is forced to stop in next iteration - enabled_ = false; - { - // Stop if there is a transmission in course till the data is sent - std::unique_lock lock(on_transmission_mutex_); - } - - // Disabling Reader - reader_->disable(); - - // Disabling Writers - for (auto& writer_it : writers_) - { - writer_it.second->disable(); - } - } -} - -bool Track::should_transmit_() noexcept -{ - return !exit_ && enabled_; -} - -void Track::data_available_() noexcept -{ - // Only hear callback if it is enabled - if (enabled_) - { - logDebug(DDSROUTER_TRACK, "Track " << *this << " has data ready to be sent."); - - // Get previous status and set current one to >=2 (it it was already >=2 it will keep being >2) - unsigned int previous_status = data_available_status_.fetch_add(DataAvailableStatus::new_data_arrived); - - if (previous_status == DataAvailableStatus::no_more_data) - { - // no_more_data was set as current status, so no thread was running - // (and will not start as 2 is set as new current status) - thread_pool_->emit(transmit_task_id_); - logDebug(DDSROUTER_TRACK, "Track " << *this << " send callback to queue."); - } - } -} - -void Track::transmit_() noexcept -{ - // Loop that ends if it should stop transmitting (should_transmit_nts_). - // Called inside the loop so it is protected by a mutex that is freed in every iteration. - - // Lock Mutex on_transmition while a data is being transmitted - // This prevents the Track to be disabled (and disable writers and readers) while sending a data - // enabled_ will be set to false before taking the mutex, so the track will finish after current iteration - std::unique_lock lock(on_transmission_mutex_); - - // TODO: Count the times it loops to break it at some point if needed - while (should_transmit_()) - { - // It starts transmitting, so it sets the data available status as transmitting - // This will erase every previous value added in on_data_available and set 1 - data_available_status_.store(DataAvailableStatus::transmitting_data); - - // Get data received (send empty data to be created(allocated) in reader) - std::unique_ptr data; - utils::ReturnCode ret = reader_->take(data); - - if (ret == utils::ReturnCode::RETCODE_NO_DATA) - { - // There is no more data, so reduce in 1 the status - unsigned int previous_status = data_available_status_.fetch_sub(DataAvailableStatus::transmitting_data); - if (previous_status == DataAvailableStatus::transmitting_data) - { - // Previous Status = 1 (transmitting => no on_data_available callback has been called) - // Current Status = 0 (new callbacks will emit the task) - // => close this thread and keeps status as 0 so new data available emit task - break; - } - else - { - // New data has arrived while setting no_more_data, so it should continue - // While setting status to 1 again, the value is still >=1 so no other thread will start - continue; - } - } - else if (!ret) - { - // Error reading data - logWarning(DDSROUTER_TRACK, "Error taking data in Track " << topic_->topic_name() << ". Error code " << ret - << ". Skipping data and continue."); - continue; - } - - logDebug(DDSROUTER_TRACK, - "Track " << reader_participant_id_ << " for topic " << topic_->topic_name() << - " transmitting data from remote endpoint."); - - // Send data through writers - for (auto& writer_it : writers_) - { - logDebug( - DDSROUTER_TRACK, - "Forwarding data to writer " << writer_it.first << "."); - - ret = writer_it.second->write(*data); - - if (!ret) - { - logWarning(DDSROUTER_TRACK, "Error writting data in Track " << topic_->topic_name() << ". Error code " - << ret << - ". Skipping data for this writer and continue."); - continue; - } - } - - // Let the data to be removed by itself - } -} - -std::ostream& operator <<( - std::ostream& os, - const Track& track) -{ - os << "Track{" << track.topic_->topic_name() << ";" << track.reader_participant_id_ << "}"; - return os; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp b/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp deleted file mode 100644 index 3d9dc7db5..000000000 --- a/ddspipe_core/src/cpp/communication/rpc/RPCBridge.cpp +++ /dev/null @@ -1,465 +0,0 @@ -// Copyright 2022 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 RPCBridge.cpp - * - */ - -#include - - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -RPCBridge::RPCBridge( - const RpcTopic& topic, - const std::shared_ptr& participants_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& thread_pool) - : Bridge(participants_database, payload_pool, thread_pool) - , init_(false) - , rpc_topic_(topic) -{ - logDebug(DDSROUTER_RPCBRIDGE, "Creating RPCBridge " << *this << "."); - - logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << " created."); -} - -RPCBridge::~RPCBridge() -{ - logDebug(DDSROUTER_RPCBRIDGE, "Destroying RPCBridge " << *this << "."); - - // Disable all entities before destruction - disable(); - - logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << " destroyed."); -} - -void RPCBridge::init_nts_() -{ - logInfo(DDSROUTER_RPCBRIDGE, "Creating endpoints in RPCBridge for service " << rpc_topic_ << "."); - - // TODO: remove and use every participant - std::set ids = participants_->get_rtps_participants_ids(); - - // Create a proxy client and server in each RTPS participant - for (ParticipantId id: ids) - { - create_proxy_client_nts_(id); - create_proxy_server_nts_(id); - if (current_servers_[id].size()) - { - service_registries_[id]->enable(); - } - } - - // TODO: This should not be done - // Wait for the new entities created to match before sending data from one side to the other - init_ = true; - // utils::sleep_for(500); -} - -void RPCBridge::create_proxy_server_nts_( - ParticipantId participant_id) -{ - std::shared_ptr participant = participants_->get_participant(participant_id); - - reply_writers_[participant_id] = participant->create_writer(rpc_topic_.reply_topic()); - request_readers_[participant_id] = participant->create_reader(rpc_topic_.request_topic()); - - create_slot_(request_readers_[participant_id]); -} - -void RPCBridge::create_proxy_client_nts_( - ParticipantId participant_id) -{ - std::shared_ptr participant = participants_->get_participant(participant_id); - - // Safe casting as we are only getting RTPS participants - request_writers_[participant_id] = participant->create_writer(rpc_topic_.request_topic()); - reply_readers_[participant_id] = participant->create_reader(rpc_topic_.reply_topic()); - - create_slot_(reply_readers_[participant_id]); - - // Create service registry associated to this proxy client - service_registries_[participant_id] = std::make_shared(rpc_topic_, participant_id); -} - -void RPCBridge::enable() noexcept -{ - std::lock_guard lock(mutex_); - - if (!enabled_ && servers_available_()) - { - logInfo(DDSROUTER_RPCBRIDGE, "Enabling RPCBridge for service " << rpc_topic_ << "."); - - if (!init_) - { - try - { - init_nts_(); - } - catch (const utils::InitializationException& e) - { - logError(DDSROUTER_RPCBRIDGE, - "Error while creating endpoints in RPCBridge for service " << rpc_topic_ << - ". Error code:" << e.what() << "."); - return; - } - } - - enabled_ = true; - - // Enable writers before readers, to avoid starting a transmission (not protected with \c mutex_) which may - // attempt to write with a yet disabled writer - - for (auto& writer_it : request_writers_) - { - writer_it.second->enable(); - } - - for (auto& writer_it : reply_writers_) - { - writer_it.second->enable(); - } - - for (auto& reader_it : reply_readers_) - { - reader_it.second->enable(); - } - - for (auto& reader_it : request_readers_) - { - reader_it.second->enable(); - } - } -} - -void RPCBridge::disable() noexcept -{ - std::lock_guard lock(mutex_); - - if (enabled_) - { - logInfo(DDSROUTER_RPCBRIDGE, "Disabling RPCBridge for service " << rpc_topic_ << "."); - - enabled_ = false; - - { - // Wait for a transmission to finish before disabling endpoints - std::unique_lock lock(on_transmission_mutex_); - } - - for (auto& reader_it : request_readers_) - { - reader_it.second->disable(); - } - - for (auto& reader_it : reply_readers_) - { - reader_it.second->disable(); - } - - for (auto& writer_it : reply_writers_) - { - writer_it.second->disable(); - } - - for (auto& writer_it : request_writers_) - { - writer_it.second->disable(); - } - } -} - -void RPCBridge::discovered_service( - const types::ParticipantId& server_participant_id, - const types::GuidPrefix& server_guid_prefix) noexcept -{ - current_servers_[server_participant_id].emplace(server_guid_prefix); - if (init_) - { - service_registries_[server_participant_id]->enable(); - } - else - { - } -} - -void RPCBridge::removed_service( - const types::ParticipantId& server_participant_id, - const types::GuidPrefix& server_guid_prefix) noexcept -{ - current_servers_[server_participant_id].erase(server_guid_prefix); - if (!current_servers_[server_participant_id].size() && !servers_available_()) - { - disable(); - } -} - -bool RPCBridge::servers_available_() const noexcept -{ - for (auto it = current_servers_.begin(); it != current_servers_.end(); it++) - { - if (it->second.size()) - { - return true; - } - } - return false; -} - -void RPCBridge::data_available_( - const Guid& reader_guid) noexcept -{ - // Only hear callback if it is enabled - if (enabled_) - { - logDebug( - DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << - " has data ready to be sent in reader " << reader_guid << " ."); - - // Protected by internal RTPS Reader mutex, as called within \c onNewCacheChangeAdded callback - // This method is also called from Reader's \c enable_ , so Reader's mutex must also be taken there beforehand - std::pair& task = tasks_map_[reader_guid]; - if (!task.first) - { - task.first = true; - thread_pool_->emit(task.second); - logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << - " - " << reader_guid << " send callback to queue."); - } - else - { - logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << - " - " << reader_guid << " callback NOT sent (task already queued)."); - } - } -} - -void RPCBridge::transmit_( - std::shared_ptr reader) noexcept -{ - // Avoid being disabled while transmitting - std::shared_lock lock(on_transmission_mutex_); - - logDebug(DDSROUTER_RPCBRIDGE, "RPCBridge " << *this << - " transmitting for reader " << reader->guid() << " ."); - - while (true) - { - { - std::lock_guard lock(reader->get_rtps_mutex()); - - if (!enabled_ || !(reader->get_unread_count() > 0)) - { - if (!enabled_) - { - logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge service " << *this << " finishing transmitting: bridge disabled."); - } - else - { - logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge service " << *this << " finishing transmitting: no more data available."); - } - - // Finish transmission - tasks_map_[reader->guid()].first = false; - - return; - } - } - - // Get data received - std::unique_ptr data; - utils::ReturnCode ret = reader->take(data); - - RpcPayloadData& pcr_data = dynamic_cast(*data); - - - // Will never return \c RETCODE_NO_DATA, otherwise would have finished before - if (!ret) - { - // Error reading data - logWarning(DDSROUTER_RPCBRIDGE, - "Error taking data at service Reader in topic " << reader->topic() - << ". Error code " << ret - << ". Skipping data and continue."); - continue; - } - - if (RpcTopic::is_request_topic(reader->topic())) - { - logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << rpc_topic_ << - " transmitting request from remote endpoint " << pcr_data.source_guid << "."); - - SampleIdentity reply_related_sample_identity = - pcr_data.write_params.get_reference().sample_identity(); - reply_related_sample_identity.sequence_number(pcr_data.origin_sequence_number); - - if (reply_related_sample_identity == SampleIdentity::unknown()) - { - logWarning(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << rpc_topic_ << - " received ill-formed request from remote endpoint " << pcr_data.source_guid << - ". Ignoring..."); - } - else - { - for (auto& service_registry : service_registries_) - { - // Do not send request through same participant who received it (unless repeater), or if there are no servers to process it - if ((pcr_data.participant_receiver == service_registry.first && - !participants_->get_participant(service_registry.first)->is_repeater()) || - !service_registry.second->enabled()) - { - continue; - } - - // Perform write + add entry to registry atomically -> avoid reply processed before entry added to registry - std::lock_guard lock(service_registry.second->get_mutex()); - - // Attach the information the server needs in order to reply to the appropiate proxy client. - pcr_data.write_params.set_level(); - pcr_data.write_params.get_reference().related_sample_identity().writer_guid( - reply_readers_[service_registry.first]->guid()); - - - ret = request_writers_[service_registry.first]->write(*data); - - if (!ret) - { - logWarning(DDSROUTER_RPCBRIDGE, "Error writting request in RPCBridge for service " - << rpc_topic_ << ". Error code " << ret << ". Skipping data for this writer and continue."); - continue; - } - - eprosima::fastrtps::rtps::SequenceNumber_t sequence_number = - pcr_data.sent_sequence_number; - // Add entry to registry associated to the transmission of this request through this proxy client. - service_registry.second->add( - sequence_number, - {pcr_data.participant_receiver, reply_related_sample_identity}); - - } - } - } - else if (RpcTopic::is_reply_topic(reader->topic())) - { - logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << rpc_topic_ << - " transmitting reply from remote endpoint " << pcr_data.source_guid << "."); - - // A Server could be answering a different client in this same DDS Router or a remote client - // Thus, it must be filtered so only replies to this client are processed. - if (pcr_data.write_params.get_reference().sample_identity().writer_guid() != reader->guid()) - { - logDebug(DDSROUTER_RPCBRIDGE, - "RPCBridge for service " << *this << " from reader " << reader->guid() << - " received response meant for other client: " << - pcr_data.write_params.get_reference().sample_identity().writer_guid()); - } - else - { - std::pair registry_entry; - { - // Wait for request transmission to be finished (entry added to registry) - std::lock_guard lock( - service_registries_[reader->participant_id()]->get_mutex()); - - // Fetch information required for transmission; which proxy server should send it and with what parameters - registry_entry = service_registries_[reader->participant_id()]->get( - pcr_data.write_params.get_reference().sample_identity().sequence_number()); - } - - // Not valid means: - // Case 1: (SimpleParticipant) Request already replied by another server connected to the same participant as this one. - // Case 2: (WAN Participant repeater) Request already replied by another PROXY server connected to the same participant as this one. - // TODO: recheck ParticipantId non valid - if (!registry_entry.first.empty()) - { - pcr_data.write_params.set_level(); - pcr_data.write_params.get_reference().related_sample_identity(registry_entry.second); - - ret = reply_writers_[registry_entry.first]->write(*data); - - if (!ret) - { - logWarning(DDSROUTER_RPCBRIDGE, "Error writting reply in RPCBridge for service " - << rpc_topic_ << ". Error code " << ret << "."); - } - else - { - service_registries_[reader->participant_id()]->erase( - pcr_data.write_params.get_reference().sample_identity().sequence_number()); - } - } - } - } - else - { - utils::tsnh( - utils::Formatter() << "Data to be transmitted in RPCBridge is not in RpcTopic."); - } - - payload_pool_->release_payload(pcr_data.payload); - }/* */ -} - -void RPCBridge::create_slot_( - std::shared_ptr reader) noexcept -{ - Guid reader_guid = reader->guid(); - - reader->set_on_data_available_callback( - [=]() - { - data_available_(reader_guid); - }); - - // Set slot in thread pool for this reader - utils::TaskId task_id = utils::new_unique_task_id(); - thread_pool_->slot( - task_id, - [=]() - { - transmit_(reader); - }); - tasks_map_[reader_guid] = {false, task_id}; -} - -std::ostream& operator <<( - std::ostream& os, - const RPCBridge& bridge) -{ - os << "RPCBridge{" << bridge.rpc_topic_.service_name() << "}"; - return os; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp b/ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp deleted file mode 100644 index 4091cd64b..000000000 --- a/ddspipe_core/src/cpp/communication/rpc/ServiceRegistry.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2022 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 ServiceRegistry.cpp - * - */ - -#include -#include - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -const unsigned int ServiceRegistry::DEFAULT_MAX_ENTRIES_ = 5000; - -ServiceRegistry::ServiceRegistry( - const RpcTopic& topic, - const ParticipantId& participant_id) - : topic_(topic) - , participant_id_(participant_id) - , enabled_(false) -{ - logDebug(DDSROUTER_SERVICEREGISTRY, - "ServiceRegistry created for service " << topic << - " in participant " << participant_id << "."); -} - -void ServiceRegistry::enable() noexcept -{ - enabled_ = true; -} - -void ServiceRegistry::disable() noexcept -{ - enabled_ = false; -} - -bool ServiceRegistry::enabled() const noexcept -{ - return enabled_; -} - -void ServiceRegistry::add( - SequenceNumber idx, - std::pair new_entry) noexcept -{ - std::lock_guard lock(mutex_); - - if (registry_.count(idx)) - { - // Should never occur as each sequence number associated to a write operation is unique - logWarning(DDSROUTER_SERVICEREGISTRY, - "ServiceRegistry for service " << topic_ << " in participant " << participant_id_ << - " attempting to add entry with already present SequenceNumber."); - return; - } - - registry_[idx] = new_entry; - - // Remove oldest entry if registry full - // TMP: Use configuration specs value when available - if (registry_.size() == DEFAULT_MAX_ENTRIES_) - { - registry_.erase(registry_.begin()); - } -} - -std::pair ServiceRegistry::get( - SequenceNumber idx) const noexcept -{ - std::lock_guard lock(mutex_); - - std::pair ret; - if (registry_.count(idx)) - { - ret = registry_.at(idx); - } - else - { - ret = {ParticipantId(), SampleIdentity()}; - } - - return ret; -} - -void ServiceRegistry::erase( - SequenceNumber idx) noexcept -{ - std::lock_guard lock(mutex_); - - if (registry_.count(idx)) - { - registry_.erase(idx); - } -} - -RpcTopic ServiceRegistry::topic() const noexcept -{ - return topic_; -} - -std::recursive_mutex& ServiceRegistry::get_mutex() noexcept -{ - return mutex_; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/core/DdsPipe.cpp b/ddspipe_core/src/cpp/core/DdsPipe.cpp deleted file mode 100644 index 93c2aa14f..000000000 --- a/ddspipe_core/src/cpp/core/DdsPipe.cpp +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -// TODO: Use initial topics to start execution and start bridges - -DdsPipe::DdsPipe( - const std::shared_ptr& allowed_topics, - const std::shared_ptr& discovery_database, - const std::shared_ptr& payload_pool, - const std::shared_ptr& participants_database, - const std::shared_ptr& thread_pool, - const std::set>& builtin_topics /* = {} */) - : allowed_topics_(allowed_topics) - , discovery_database_(discovery_database) - , payload_pool_(payload_pool) - , participants_database_(participants_database) - , thread_pool_(thread_pool) - , enabled_(false) -{ - logDebug(DDSROUTER, "Creating DDS Pipe."); - - // TODO set default history qos somewhere else - - // Add callback to be called by the discovery database when an Endpoint is discovered - discovery_database_->add_endpoint_discovered_callback(std::bind(&DdsPipe::discovered_endpoint_, this, - std::placeholders::_1)); - - // Add callback to be called by the discovery database when an Endpoint is removed/dropped - discovery_database_->add_endpoint_erased_callback(std::bind(&DdsPipe::removed_endpoint_, this, - std::placeholders::_1)); - - // Create Bridges for builtin topics - init_bridges_(builtin_topics); - - // Init discovery database - // The entities should not be added to the Discovery Database until the builtin topics have been created. - // This is due to the fact that the Participants endpoints start discovering topics with different configuration - // than the one specified in the yaml configuration file. - discovery_database_->start(); - - logDebug(DDSROUTER, "DDS Pipe created."); -} - -DdsPipe::~DdsPipe() -{ - logDebug(DDSROUTER, "Destroying DDS Pipe."); - - // Stop Discovery Database - discovery_database_->stop(); - - // Stop all communications - stop_(); - - // Destroy Bridges, so Writers and Readers are destroyed before the Databases - bridges_.clear(); - - // Destroy RPCBridges, so Writers and Readers are destroyed before the Databases - rpc_bridges_.clear(); - - // There is no need to destroy shared ptrs as they will delete itslefs with 0 references - - logDebug(DDSROUTER, "DDS Pipe destroyed."); -} - -utils::ReturnCode DdsPipe::reload_allowed_topics( - const std::shared_ptr& allowed_topics) -{ - std::lock_guard lock(mutex_); - - if (enabled_.load()) - { - logDebug(DDSROUTER, "Reloading DDS Pipe configuration..."); - - // Check if it should change or is the same configuration - if (*allowed_topics == *allowed_topics_) - { - logDebug(DDSROUTER, "Same configuration, do nothing in reload."); - return utils::ReturnCode::RETCODE_NO_DATA; - } - - // Set new Allowed list - allowed_topics_ = allowed_topics; - - logDebug(DDSROUTER, "New DDS Pipe allowed topics configuration: " << allowed_topics_); - - // It must change the configuration. Check every topic discovered and activate/deactivate it if needed. - for (auto& topic_it : current_topics_) - { - // If topic is active and it is blocked, deactivate it - if (topic_it.second) - { - if (!allowed_topics_->is_topic_allowed(*topic_it.first)) - { - deactivate_topic_(topic_it.first); - } - } - else - { - // If topic is not active and it is allowed, activate it - if (allowed_topics_->is_topic_allowed(*topic_it.first)) - { - activate_topic_(topic_it.first); - } - } - } - - // Check every service discovered and activate/deactivate it if needed. - for (auto& service_it : current_services_) - { - if (allowed_topics_->is_service_allowed(service_it.first)) - { - service_it.second = true; - rpc_bridges_[service_it.first]->enable(); - } - else - { - service_it.second = false; - rpc_bridges_[service_it.first]->disable(); - } - } - - return utils::ReturnCode::RETCODE_OK; - } - else - { - allowed_topics_ = allowed_topics; - return utils::ReturnCode::RETCODE_NOT_ENABLED; - } -} - -utils::ReturnCode DdsPipe::start() noexcept -{ - utils::ReturnCode ret = start_(); - if (ret == utils::ReturnCode::RETCODE_OK) - { - logInfo(DDSROUTER, "Starting DDS Pipe."); - } - else if (ret == utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET) - { - logInfo(DDSROUTER, "Trying to start an enabled DDS Pipe."); - } - - return ret; -} - -utils::ReturnCode DdsPipe::stop() noexcept -{ - utils::ReturnCode ret = stop_(); - if (ret == utils::ReturnCode::RETCODE_OK) - { - logInfo(DDSROUTER, "Stopping DDS Pipe."); - } - else if (ret == utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET) - { - logInfo(DDSROUTER, "Trying to stop a not enabled DDS Pipe."); - } - - return ret; -} - -utils::ReturnCode DdsPipe::start_() noexcept -{ - std::lock_guard lock(mutex_); - - if (!enabled_.load()) - { - enabled_.store(true); - - logInfo(DDSROUTER, "Starting DDS Pipe."); - - // Enable thread pool - thread_pool_->enable(); - - activate_all_topics_(); - - // Enable services discovered while router disabled - for (auto it : current_services_) - { - // Enable only allowed services - if (it.second) - { - rpc_bridges_[it.first]->enable(); - } - } - - return utils::ReturnCode::RETCODE_OK; - } - else - { - logInfo(DDSROUTER, "Trying to start an already enabled DDS Pipe."); - return utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET; - } -} - -utils::ReturnCode DdsPipe::stop_() noexcept -{ - std::lock_guard lock(mutex_); - - if (enabled_.load()) - { - enabled_.store(false); - - logInfo(DDSROUTER, "Stopping DDS Pipe."); - - // Disable thread pool so tasks running finish and new tasks are not taken by threads - thread_pool_->disable(); - - deactivate_all_topics_(); - return utils::ReturnCode::RETCODE_OK; - } - else - { - logInfo(DDSROUTER, "Trying to stop a disabled DDS Pipe."); - return utils::ReturnCode::RETCODE_PRECONDITION_NOT_MET; - } -} - -void DdsPipe::init_bridges_(const std::set>& builtin_topics) -{ - for (const auto& topic : builtin_topics) - { - discovered_topic_(topic); - } -} - -void DdsPipe::discovered_topic_( - const utils::Heritable& topic) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Discovered topic: " << topic << "."); - - // Check if topic already exists - auto find_it = current_topics_.find(topic); - if (find_it != current_topics_.end()) - { - // If it already exists, do nothing - return; - } - - // Add topic to current_topics as non activated - current_topics_.emplace(topic, false); - - // If Pipe is enabled and topic allowed, activate it - if (enabled_.load() && allowed_topics_->is_topic_allowed(*topic)) - { - activate_topic_(topic); - } -} - -void DdsPipe::discovered_service_( - const types::RpcTopic& topic, - const ParticipantId& server_participant_id, - const GuidPrefix& server_guid_prefix) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Discovered service: " << topic << "."); - - auto it_bridge = rpc_bridges_.find(topic); - - if (it_bridge == rpc_bridges_.end()) - { - // Create RPCBridge even if topic not allowed, as we need to store server in database - create_new_service_(topic); - - if (allowed_topics_->is_service_allowed(topic)) - { - current_services_[topic] = true; - } - else - { - current_services_[topic] = false; - } - } - - rpc_bridges_[topic]->discovered_service(server_participant_id, server_guid_prefix); - if (enabled_.load() && current_services_[topic]) - { - rpc_bridges_[topic]->enable(); - } -} - -void DdsPipe::removed_service_( - const types::RpcTopic& topic, - const ParticipantId& server_participant_id, - const GuidPrefix& server_guid_prefix) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Removed service: " << topic << "."); - - auto it_bridge = rpc_bridges_.find(topic); - - if (it_bridge != rpc_bridges_.end()) - { - rpc_bridges_[topic]->removed_service(server_participant_id, server_guid_prefix); - } -} - -void DdsPipe::discovered_endpoint_( - const Endpoint& endpoint) noexcept -{ - logDebug(DDSROUTER, "Endpoint discovered in DDS Pipe core: " << endpoint << "."); - - // Set as discovered only if the endpoint is a Reader - // If non Readers in topics, it is considered as non discovered - if (endpoint.is_reader()) - { - if (!RpcTopic::is_service_topic(endpoint.topic)) - { - discovered_topic_(utils::Heritable::make_heritable(endpoint.topic)); - } - else if (endpoint.is_server_endpoint()) - { - // Service server discovered - discovered_service_(types::RpcTopic(endpoint.topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); - } - } -} - -void DdsPipe::removed_endpoint_( - const Endpoint& endpoint) noexcept -{ - logDebug(DDSROUTER, "Endpoint removed/dropped: " << endpoint << "."); - - const DdsTopic& topic = endpoint.topic; - if (RpcTopic::is_service_topic(topic)) - { - if (endpoint.is_server_endpoint()) - { - // Service server removed/dropped - removed_service_(types::RpcTopic(topic), endpoint.discoverer_participant_id, endpoint.guid.guid_prefix()); - } - } -} - -void DdsPipe::create_new_bridge_( - const utils::Heritable& topic, - bool enabled /*= false*/) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Creating Bridge for topic: " << topic << "."); - - try - { - auto new_bridge = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_); - if (enabled_) - { - new_bridge->enable(); - } - bridges_[topic] = std::move(new_bridge); - } - catch (const utils::InitializationException& e) - { - logError(DDSROUTER, - "Error creating Bridge for topic " << topic << - ". Error code:" << e.what() << "."); - } -} - -void DdsPipe::create_new_service_( - const types::RpcTopic& topic) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Creating Service: " << topic << "."); - - // Endpoints not created until enabled for the first time, so no exception can be thrown - rpc_bridges_[topic] = std::make_unique(topic, participants_database_, payload_pool_, thread_pool_); -} - -void DdsPipe::activate_topic_( - const utils::Heritable& topic) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Activating topic: " << topic << "."); - - // Modify current_topics_ and set this topic as active - current_topics_[topic] = true; - - // Enable bridge. In case it is already enabled nothing should happen - auto it_bridge = bridges_.find(topic); - - if (it_bridge == bridges_.end()) - { - // The Bridge did not exist - create_new_bridge_(topic, true); - } - else - { - // The Bridge already exists - it_bridge->second->enable(); - } -} - -void DdsPipe::deactivate_topic_( - const utils::Heritable& topic) noexcept -{ - std::lock_guard lock(mutex_); - - logInfo(DDSROUTER, "Deactivating topic: " << topic << "."); - - // Modify current_topics_ and set this topic as non active - current_topics_[topic] = false; - - // Disable bridge. In case it is already disabled nothing should happen - auto it_bridge = bridges_.find(topic); - - if (it_bridge != bridges_.end()) - { - // The Bridge already exists - it_bridge->second->disable(); - } - // If the Bridge does not exist, is not need to create it -} - -void DdsPipe::activate_all_topics_() noexcept -{ - for (auto it : current_topics_) - { - // Activate all topics allowed - if (allowed_topics_->is_topic_allowed(*it.first)) - { - activate_topic_(it.first); - } - } -} - -void DdsPipe::deactivate_all_topics_() noexcept -{ - for (auto it : current_topics_) - { - // Deactivate all topics - deactivate_topic_(it.first); - } -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp b/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp deleted file mode 100644 index 62ef8a3d7..000000000 --- a/ddspipe_core/src/cpp/dynamic/AllowedTopicList.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright 2021 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 AllowedTopicList.cpp - * - */ - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -AllowedTopicList::AllowedTopicList() -{ -} - -// TODO: Add logs -AllowedTopicList::AllowedTopicList( - const std::set>& allowlist, - const std::set>& blocklist) noexcept -{ - allowlist_ = AllowedTopicList::get_topic_list_without_repetition_(allowlist); - blocklist_ = AllowedTopicList::get_topic_list_without_repetition_(blocklist); - - logDebug(DDSROUTER_ALLOWEDTOPICLIST, "New Allowed topic list created:"); - logDebug(DDSROUTER_ALLOWEDTOPICLIST, "New Allowed topic list created: " << *this << "."); -} - -AllowedTopicList& AllowedTopicList::operator =( - const AllowedTopicList& other) -{ - this->allowlist_ = other.allowlist_; - this->blocklist_ = other.blocklist_; - - return *this; -} - -AllowedTopicList::~AllowedTopicList() -{ - // Eliminate all topics - clear(); -} - -void AllowedTopicList::clear() noexcept -{ - std::lock_guard lock(mutex_); - - blocklist_.clear(); - allowlist_.clear(); -} - -bool AllowedTopicList::is_topic_allowed( - const ITopic& topic) const noexcept -{ - std::lock_guard lock(mutex_); - - // It is accepted by default if allowlist is empty, if not it should pass the allowlist filter - bool accepted = allowlist_.empty(); - - // Check if allowlist filter it (this will do anything if empty and accepted will be true) - for (const auto& filter : allowlist_) - { - if (filter->matches(topic)) - { - accepted = true; - break; - } - } - - // Check if it has not passed the allowlist so blocklist is skipped - if (!accepted) - { - return false; - } - - // Allowlist passed, check blocklist - for (const auto& filter : blocklist_) - { - if (filter->matches(topic)) - { - return false; - } - } - - // Blocklist passed, the topic is allowed - return true; -} - -bool AllowedTopicList::is_service_allowed( - const types::RpcTopic& topic) const noexcept -{ - // Lock mutex to perform the verification atomically - std::lock_guard lock(mutex_); - - return is_topic_allowed(topic.request_topic()) && is_topic_allowed(topic.reply_topic()); -} - -bool AllowedTopicList::operator ==( - const AllowedTopicList& other) const noexcept -{ - return allowlist_ == other.allowlist_ && blocklist_ == other.blocklist_; -} - -std::set> AllowedTopicList::get_topic_list_without_repetition_( - const std::set>& list) noexcept -{ - std::set> non_repeated_list; - - // Store each topic without repetition - for (utils::Heritable new_topic : list) - { - bool add_it = true; - std::set> repeated; - - // Check if it is contained or contains any topic already in the list - for (utils::Heritable topic_stored : non_repeated_list) - { - if (topic_stored->contains(*new_topic)) - { - // It is repeated, so it must not be added - add_it = false; - break; - } - else if (new_topic->contains(*topic_stored)) - { - // There is a repeated topic stored, pop it and add this one instead - repeated.insert(topic_stored); - } - } - - // Remove topics repeated - for (utils::Heritable topic_repeated : repeated) - { - non_repeated_list.erase(topic_repeated); - } - - // Add new topic if it is not repeated - if (add_it) - { - non_repeated_list.insert(new_topic); - } - } - - return non_repeated_list; -} - -std::ostream& operator <<( - std::ostream& os, - const AllowedTopicList& atl) -{ - os << "AllowedTopicList{"; - - // Allowed topics - os << "allowed"; - utils::container_to_stream, true>(os, atl.allowlist_); - - // Blocked topics - os << "blocked"; - utils::container_to_stream, true>(os, atl.blocklist_); - - os << "}"; - - return os; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp b/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp deleted file mode 100644 index 7a42babd6..000000000 --- a/ddspipe_core/src/cpp/dynamic/DiscoveryDatabase.cpp +++ /dev/null @@ -1,347 +0,0 @@ -// Copyright 2021 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 DiscoveryDatabase.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -DiscoveryDatabase::DiscoveryDatabase() noexcept - : exit_(false) - , enabled_(false) -{ - logDebug(DDSROUTER_DISCOVERY_DATABASE, "Creating queue processing thread."); -} - -DiscoveryDatabase::~DiscoveryDatabase() -{ - logDebug(DDSROUTER_DISCOVERY_DATABASE, "Destroying Discovery Database."); - - stop(); -} - -void DiscoveryDatabase::start() noexcept -{ - if (!enabled_.load()) - { - queue_processing_thread_ = std::thread(&DiscoveryDatabase::queue_processing_thread_routine_, this); - enabled_.store(true); - logDebug(DDSROUTER_DISCOVERY_DATABASE, "Creating queue processing thread routine."); - } - else - { - logDebug(DDSROUTER_DISCOVERY_DATABASE, "Processing thread routine already started."); - } -} - -void DiscoveryDatabase::stop() noexcept -{ - if (enabled_.load()) - { - clear_all_callbacks(); - - { - std::lock_guard lock(entities_to_process_cv_mutex_); - exit_.store(true); - } - entities_to_process_cv_.notify_one(); - - logDebug(DDSROUTER_DISCOVERY_DATABASE, "Waiting for queue processing thread to finish."); - enabled_.store(false); - queue_processing_thread_.join(); - } - else - { - logDebug(DDSROUTER_DISCOVERY_DATABASE, "Processing thread routine already stopped."); - } -} - -bool DiscoveryDatabase::topic_exists( - const DdsTopic& topic) const noexcept -{ - std::shared_lock lock(mutex_); - - // Loop over every Endpoint checking if topic matches - // It is not required to be reference - for (const auto& entity : entities_) - { - if (entity.second.topic == topic) - { - return true; - } - } - return false; -} - -bool DiscoveryDatabase::endpoint_exists( - const Guid& guid) const noexcept -{ - std::shared_lock lock(mutex_); - return entities_.find(guid) != entities_.end(); -} - -bool DiscoveryDatabase::add_endpoint_( - const Endpoint& new_endpoint) -{ - { - std::unique_lock lock(mutex_); - - auto it = entities_.find(new_endpoint.guid); - if (it != entities_.end()) - { - // Already exists - if (it->second.active) - { - throw utils::InconsistencyException( - utils::Formatter() << - "Error adding Endpoint to database. Endpoint already exists." << new_endpoint); - } - else - { - // If exists but inactive, modify entry - it->second = new_endpoint; - - logInfo(DDSROUTER_DISCOVERY_DATABASE, - "Modifying an already discovered (inactive) Endpoint " << new_endpoint << "."); - - return true; - } - } - else - { - logInfo(DDSROUTER_DISCOVERY_DATABASE, "Inserting a new discovered Endpoint " << new_endpoint << "."); - - // Add it to the dictionary - entities_.insert(std::pair(new_endpoint.guid, new_endpoint)); - } - } - - std::lock_guard lock(callbacks_mutex_); - for (auto added_endpoint_callback : added_endpoint_callbacks_) - { - added_endpoint_callback(new_endpoint); - } - - return true; -} - -bool DiscoveryDatabase::update_endpoint_( - const Endpoint& endpoint_to_update) -{ - { - std::unique_lock lock(mutex_); - - auto it = entities_.find(endpoint_to_update.guid); - if (it == entities_.end()) - { - // Entry not found - throw utils::InconsistencyException( - utils::Formatter() << - "Error updating Endpoint in database. Endpoint entry not found." << endpoint_to_update); - } - else - { - logInfo(DDSROUTER_DISCOVERY_DATABASE, - "Modifying an already discovered Endpoint " << endpoint_to_update << "."); - - // Modify entry - it->second = endpoint_to_update; - // It is assumed a topic cannot change, otherwise further actions may be taken - } - } - - std::lock_guard lock(callbacks_mutex_); - for (auto updated_endpoint_callback : updated_endpoint_callbacks_) - { - updated_endpoint_callback(endpoint_to_update); - } - - return true; -} - -utils::ReturnCode DiscoveryDatabase::erase_endpoint_( - const Endpoint& endpoint_to_erase) -{ - { - std::unique_lock lock(mutex_); - - logInfo(DDSROUTER_DISCOVERY_DATABASE, "Erasing Endpoint " << endpoint_to_erase << "."); - - auto erased = entities_.erase(endpoint_to_erase.guid); - - if (erased == 0) - { - throw utils::InconsistencyException( - utils::Formatter() << - "Error erasing Endpoint " << endpoint_to_erase << - " from database. Endpoint entry not found."); - } - } - - std::lock_guard lock(callbacks_mutex_); - for (auto erased_endpoint_callback : erased_endpoint_callbacks_) - { - erased_endpoint_callback(endpoint_to_erase); - } - - return utils::ReturnCode::RETCODE_OK; -} - -void DiscoveryDatabase::add_endpoint( - const Endpoint& new_endpoint) -{ - push_item_to_queue_(std::make_tuple(DatabaseOperation::add, new_endpoint)); -} - -void DiscoveryDatabase::update_endpoint( - const Endpoint& endpoint_to_update) -{ - push_item_to_queue_(std::make_tuple(DatabaseOperation::update, endpoint_to_update)); -} - -void DiscoveryDatabase::erase_endpoint( - const Endpoint& endpoint_to_erase) -{ - push_item_to_queue_(std::make_tuple(DatabaseOperation::erase, endpoint_to_erase)); -} - -Endpoint DiscoveryDatabase::get_endpoint( - const Guid& endpoint_guid) const -{ - std::shared_lock lock(mutex_); - - auto it = entities_.find(endpoint_guid); - if (it == entities_.end()) - { - throw utils::InconsistencyException( - utils::Formatter() << - "Error retrieving Endpoint with GUID " << endpoint_guid << - " from database. Endpoint entry not found."); - } - - return it->second; -} - -void DiscoveryDatabase::add_endpoint_discovered_callback( - std::function endpoint_discovered_callback) noexcept -{ - std::lock_guard lock(callbacks_mutex_); - - added_endpoint_callbacks_.push_back(endpoint_discovered_callback); -} - -void DiscoveryDatabase::add_endpoint_updated_callback( - std::function endpoint_updated_callback) noexcept -{ - std::lock_guard lock(callbacks_mutex_); - - updated_endpoint_callbacks_.push_back(endpoint_updated_callback); -} - -void DiscoveryDatabase::add_endpoint_erased_callback( - std::function endpoint_erased_callback) noexcept -{ - std::lock_guard lock(callbacks_mutex_); - - erased_endpoint_callbacks_.push_back(endpoint_erased_callback); -} - -void DiscoveryDatabase::clear_all_callbacks() noexcept -{ - std::lock_guard lock(callbacks_mutex_); - - added_endpoint_callbacks_.clear(); - updated_endpoint_callbacks_.clear(); - erased_endpoint_callbacks_.clear(); -} - -void DiscoveryDatabase::queue_processing_thread_routine_() noexcept -{ - while (true) - { - { - std::unique_lock lock(entities_to_process_cv_mutex_); - entities_to_process_cv_.wait( - lock, - [&] - { - return !entities_to_process_.BothEmpty() || exit_.load(); - }); - - if (exit_.load()) - { - break; - } - } - // Release the mutex as DBQueue already has internal mutexes - process_queue_(); - } -} - -void DiscoveryDatabase::push_item_to_queue_( - std::tuple item) noexcept -{ - { - std::lock_guard lock(entities_to_process_cv_mutex_); - entities_to_process_.Push(item); - } - entities_to_process_cv_.notify_one(); -} - -void DiscoveryDatabase::process_queue_() noexcept -{ - entities_to_process_.Swap(); - while (!entities_to_process_.Empty()) - { - std::tuple queue_item = entities_to_process_.Front(); - DatabaseOperation db_operation = std::get<0>(queue_item); - Endpoint entity = std::get<1>(queue_item); - try - { - if (db_operation == DatabaseOperation::add) - { - add_endpoint_(entity); - } - else if (db_operation == DatabaseOperation::update) - { - update_endpoint_(entity); - } - else if (db_operation == DatabaseOperation::erase) - { - erase_endpoint_(entity); - } - } - catch (const utils::InconsistencyException& e) - { - logDevError(DDSROUTER_DISCOVERY_DATABASE, - "Error processing database operations queue:" << e.what() << "."); - } - entities_to_process_.Pop(); - } -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp b/ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp deleted file mode 100644 index ef8936abe..000000000 --- a/ddspipe_core/src/cpp/dynamic/ParticipantsDatabase.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2021 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 ParticipantsDatabase.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -ParticipantsDatabase::~ParticipantsDatabase() -{ - // Let the map destroy itself -} - -std::shared_ptr ParticipantsDatabase::get_participant( - const types::ParticipantId& id) const noexcept -{ - std::shared_lock lock(mutex_); - auto it = participants_.find(id); - - if (it == participants_.end()) - { - return nullptr; - } - - return it->second; -} - -std::set ParticipantsDatabase::get_participants_ids() const noexcept -{ - std::shared_lock lock(mutex_); - std::set result; - for (auto it : participants_) - { - result.insert(it.first); - } - return result; -} - -std::set ParticipantsDatabase::get_rtps_participants_ids() const noexcept -{ - std::shared_lock lock(mutex_); - std::set result; - for (auto it : participants_) - { - if (it.second->is_rtps_kind()) - { - result.insert(it.first); - } - } - return result; -} - -const std::map>& ParticipantsDatabase::get_participants_map() const noexcept -{ - std::shared_lock lock(mutex_); - return participants_; -} - -bool ParticipantsDatabase::empty() const noexcept -{ - return participants_.empty(); -} - -size_t ParticipantsDatabase::size() const noexcept -{ - return participants_.size(); -} - -void ParticipantsDatabase::add_participant( - const types::ParticipantId& id, - const std::shared_ptr& participant) -{ - std::unique_lock lock(mutex_); - - auto it = participants_.find(id); - if (it != participants_.end()) - { - throw utils::InconsistencyException( - utils::Formatter() << "Participant with Id " << id << " already in database."); - } - else - { - logInfo(DDSROUTER_PARTICIPANT_DATABASE, "Inserting a new Participant " << id); - } - - participants_[id] = participant; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp deleted file mode 100644 index a0a55e10b..000000000 --- a/ddspipe_core/src/cpp/efficiency/payload/CopyPayloadPool.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2021 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 CopyPayloadPool.cpp - * - */ - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -bool CopyPayloadPool::get_payload( - uint32_t size, - Payload& payload) -{ - reserve_(size, payload); - payload.max_size = size; - - return true; -} - -bool CopyPayloadPool::get_payload( - const Payload& src_payload, - IPayloadPool*& data_owner, - Payload& target_payload) -{ - // As this class copies always the data, it does not matter the owner of this data - static_cast(data_owner); - - if (!get_payload(src_payload.max_size, target_payload)) - { - return false; - } - std::memcpy(target_payload.data, src_payload.data, src_payload.length); - target_payload.length = src_payload.length; - target_payload.max_size = src_payload.max_size; - - return true; -} - -bool CopyPayloadPool::release_payload( - Payload& payload) -{ - return release_(payload); -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp deleted file mode 100644 index 085347769..000000000 --- a/ddspipe_core/src/cpp/efficiency/payload/FastPayloadPool.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2021 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 FastPayloadPool.cpp - * - */ - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -bool FastPayloadPool::get_payload( - uint32_t size, - Payload& payload) -{ - // Reserve new payload - if (!reserve_(size, payload)) - { - return false; - } - - return true; -} - -bool FastPayloadPool::get_payload( - const Payload& src_payload, - IPayloadPool*& data_owner, - Payload& target_payload) -{ - // If we are not the owner, create a new payload. Else, reference the existing one - if (data_owner != this) - { - // Store space for payload - if (!get_payload(src_payload.max_size, target_payload)) - { - return false; - } - - // Copy info - std::memcpy(target_payload.data, src_payload.data, src_payload.length); - target_payload.length = src_payload.length; - } - else - { - // IMPORTANT: If payload has been reserved from this object, it must have the +4 bytes before data - // We get this value and add a +1 to set that is referencing from one more payload - MetaInfoType* reference_place = reinterpret_cast(src_payload.data); - reference_place--; - - // Add reference - (*reference_place)++; - - // Set Payload to refer same payload - target_payload.data = src_payload.data; - target_payload.length = src_payload.length; - target_payload.max_size = src_payload.max_size; - } - return true; -} - -bool FastPayloadPool::release_payload( - Payload& payload) -{ - // IMPORTANT: If payload has been reserved from this object, it must have the +4 bytes before data - // We get this value and add a -1 to set that is referencing from one less payload - MetaInfoType* reference_place = reinterpret_cast(payload.data); - reference_place--; - - // Remove reference - (*reference_place)--; - - // In case it was the last reference, release payload - if ((*reference_place) == 0) - { - // Release payload - // NOTE: There is no need to check as release cannot return false - release_(payload); - } - - payload.length = 0; - payload.max_size = 0; - payload.data = nullptr; - payload.pos = 0; - - return true; -} - -bool FastPayloadPool::reserve_( - uint32_t size, - types::Payload& payload) -{ - if (size == 0) - { - logDevError(DDSROUTER_PAYLOADPOOL, - "Trying to reserve a data block of 0 bytes."); - return false; - } - - // Allocate memory + 4 bytes for reference - void* memory_allocated = std::malloc(size + sizeof(MetaInfoType)); - - // Use reference space to set that this is referenced for the first time - MetaInfoType* reference_place = reinterpret_cast(memory_allocated); - (*reference_place) = 1; - - payload.data = reinterpret_cast(reference_place + 1); - payload.max_size = size; - - add_reserved_payload_(); - - return true; -} - -bool FastPayloadPool::release_( - types::Payload& payload) -{ - // Free memory from the initial allocation, 4 bytes before - MetaInfoType* reference_place = reinterpret_cast(payload.data); - reference_place--; - free(reference_place); - - // Remove payload internal values - payload.length = 0; - payload.max_size = 0; - payload.data = nullptr; - payload.pos = 0; - - add_release_payload_(); - - return true; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp deleted file mode 100644 index 452afff11..000000000 --- a/ddspipe_core/src/cpp/efficiency/payload/MapPayloadPool.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2021 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 MapPayloadPool.cpp - * - */ - -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -MapPayloadPool::~MapPayloadPool() -{ - if (reserved_payloads_.size() > 0) - { - logDevError( - DDSROUTER_PAYLOADPOOL, - "Removing MapPayloadPool with still " << reserved_payloads_.size() << " payloads referenced."); - - // Data could not be erased because they will be erased once the Payload is destroyed - } -} - -bool MapPayloadPool::get_payload( - uint32_t size, - Payload& payload) -{ - // Reserve new payload - if (!reserve_(size, payload)) - { - return false; - } - payload.max_size = size; - - // Store this payload in map - { - std::lock_guard lock(reserved_payloads_mutex_); - reserved_payloads_[payload.data] = 1; - } - - return true; -} - -bool MapPayloadPool::get_payload( - const Payload& src_payload, - IPayloadPool*& data_owner, - Payload& target_payload) -{ - // If we are not the owner, create a new payload. Else, reference the existing one - if (data_owner != this) - { - // Store space for payload - if (!get_payload(src_payload.max_size, target_payload)) - { - return false; - } - - // Copy info - std::memcpy(target_payload.data, src_payload.data, src_payload.length); - target_payload.length = src_payload.length; - } - else - { - std::lock_guard lock(reserved_payloads_mutex_); - - // src_payload must be inside reserved payloads - auto payload_it = reserved_payloads_.find(src_payload.data); - if (payload_it == reserved_payloads_.end()) - { - logError(DDSROUTER_PAYLOADPOOL, "Payload ownership is this pool, but it is not reserved from here."); - throw utils::InconsistencyException("Payload ownership is this pool, but it is not reserved from here."); - } - - // Add reference - payload_it->second++; - - // Set Payload to refer same payload - target_payload.data = src_payload.data; - target_payload.length = src_payload.length; - target_payload.max_size = src_payload.max_size; - } - return true; -} - -bool MapPayloadPool::release_payload( - Payload& payload) -{ - std::lock_guard lock(reserved_payloads_mutex_); - - // Check that this payload is in this pool - auto payload_it = reserved_payloads_.find(payload.data); - if (payload_it == reserved_payloads_.end()) - { - logError(DDSROUTER_PAYLOADPOOL, "Trying to release a payload from this pool that is not present."); - throw utils::InconsistencyException("Trying to release a payload from this pool that is not present."); - } - - // Dereference element - payload_it->second--; - - // In case it was the last reference, release payload - if (payload_it->second == 0) - { - if (!release_(payload)) - { - return false; - } - - // Remove it from map - reserved_payloads_.erase(payload_it); - } - - // Restore payload info - payload.length = 0; - payload.pos = 0; - payload.max_size = 0; - payload.data = nullptr; - - return true; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp b/ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp deleted file mode 100644 index c426605d5..000000000 --- a/ddspipe_core/src/cpp/efficiency/payload/PayloadPool.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2021 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 PayloadPool.cpp - * - */ - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -using namespace eprosima::ddspipe::core::types; - -PayloadPool::PayloadPool() - : reserve_count_(0) - , release_count_(0) -{ -} - -PayloadPool::~PayloadPool() -{ - if (reserve_count_ < release_count_) - { - logDevError(DDSROUTER_PAYLOADPOOL, "Removing non Consistent PayloadPool."); - } - else if (reserve_count_ != release_count_) - { - logDevError(DDSROUTER_PAYLOADPOOL, - "From " << reserve_count_ << " payloads reserved only " << release_count_ << " has been released."); - } - else - { - logInfo(DDSROUTER_PAYLOADPOOL, - "Removing PayloadPool correctly after reserve: " << reserve_count_ << " payloads."); - } -} - -///// -// FAST DDS PART - -bool PayloadPool::get_payload( - uint32_t size, - eprosima::fastrtps::rtps::CacheChange_t& cache_change) -{ - if (get_payload(size, cache_change.serializedPayload)) - { - cache_change.payload_owner(this); - return true; - } - else - { - logDevError(DDSROUTER_PAYLOADPOOL, "Error occurred while creating payload.") - return false; - } -} - -bool PayloadPool::get_payload( - fastrtps::rtps::SerializedPayload_t& data, - IPayloadPool*& data_owner, - eprosima::fastrtps::rtps::CacheChange_t& cache_change) -{ - if (get_payload(data, data_owner, cache_change.serializedPayload)) - { - cache_change.payload_owner(this); - return true; - } - else - { - logDevError(DDSROUTER_PAYLOADPOOL, "Error occurred while referencing payload.") - return false; - } -} - -bool PayloadPool::release_payload( - fastrtps::rtps::CacheChange_t& cache_change) -{ - if (cache_change.payload_owner() == this) - { - if (release_payload(cache_change.serializedPayload)) - { - cache_change.payload_owner(nullptr); - return true; - } - else - { - logDevError(DDSROUTER_PAYLOADPOOL, "Error occurred while releasing payload.") - return false; - } - } - else - { - logError(DDSROUTER_PAYLOADPOOL, "Trying to remove a cache change in an incorrect pool.") - throw utils::InconsistencyException("Trying to remove a cache change in an incorrect pool."); - } -} - -bool PayloadPool::is_clean() const noexcept -{ - return reserve_count_ == release_count_; -} - -///// -// INTERNAL PART - -void PayloadPool::add_reserved_payload_() -{ - ++reserve_count_; -} - -void PayloadPool::add_release_payload_() -{ - ++release_count_; - if (release_count_ > reserve_count_) - { - logError(DDSROUTER_PAYLOADPOOL, - "Inconsistent PayloadPool, releasing more payloads than reserved."); - throw utils::InconsistencyException("Inconsistent PayloadPool, releasing more payloads than reserved."); - } -} - -bool PayloadPool::reserve_( - uint32_t size, - Payload& payload) -{ - if (size == 0) - { - logDevError(DDSROUTER_PAYLOADPOOL, - "Trying to reserve a data block of 0 bytes."); - return false; - } - - payload.reserve(size); - - add_reserved_payload_(); - - return true; -} - -bool PayloadPool::release_( - Payload& payload) -{ - payload.empty(); - - if (payload.data != nullptr) - { - return false; - } - - add_release_payload_(); - - return true; -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/testing/entities/blank_entities.cpp b/ddspipe_core/src/cpp/testing/entities/blank_entities.cpp deleted file mode 100644 index 626569a5d..000000000 --- a/ddspipe_core/src/cpp/testing/entities/blank_entities.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace testing { - -} /* namespace testing */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/testing/random_values.cpp b/ddspipe_core/src/cpp/testing/random_values.cpp deleted file mode 100644 index 13d8d35e2..000000000 --- a/ddspipe_core/src/cpp/testing/random_values.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2021 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace testing { - -using namespace eprosima::ddspipe::core::types; - -Guid random_guid( - unsigned int seed /* = 1 */) -{ - Guid guid; - guid.entityId.value[3] = static_cast(seed); - guid.guidPrefix.value[0] = 0x01; - guid.guidPrefix.value[1] = 0x0f; - return guid; -} - -DomainId random_domain( - unsigned int seed /* = 0 */) -{ - return DomainId(static_cast(seed)); -} - -GuidPrefix random_guid_prefix( - unsigned int seed /* = 0 */, - bool ros /* = false */) -{ - if (ros) - { - return GuidPrefix(true, seed); - } - else - { - return GuidPrefix(static_cast(seed)); - } -} - -ParticipantId random_participant_id( - unsigned int seed /* = 0 */) -{ - std::vector names = { - "participant", - "PART_1", - "echo", - "Barro_p", - }; - - return ParticipantId(names[seed % names.size()] + std::to_string(seed)); -} - -DdsTopic random_dds_topic( - unsigned int seed /* = 0 */) -{ - DdsTopic topic; - topic.m_topic_name = "TopicName_" + std::to_string(seed); - topic.type_name = "TopicType_" + std::to_string(seed); - topic.topic_qos = random_topic_qos(seed); - return topic; -} - -EndpointKind random_endpoint_kind( - unsigned int seed /* = 0 */) -{ - if (seed % 2) - { - return EndpointKind::reader; - } - else - { - return EndpointKind::writer; - } -} - -Endpoint random_endpoint( - unsigned int seed /* = 0 */) -{ - Endpoint endpoint; - endpoint.active = (seed % 2); - endpoint.guid = random_guid(seed); - endpoint.discoverer_participant_id = random_participant_id(seed); - endpoint.kind = random_endpoint_kind(seed); - endpoint.topic = random_dds_topic(seed); - return endpoint; -} - -TopicQoS random_topic_qos( - unsigned int seed /* = 0 */) -{ - TopicQoS qos; - - if (seed % 2) - { - qos.reliability_qos = ReliabilityKind::BEST_EFFORT; - } - else - { - qos.reliability_qos = ReliabilityKind::RELIABLE; - } - - switch ((seed / 2) % 4) - { - case 0: - qos.durability_qos = DurabilityKind::VOLATILE; - break; - - case 1: - qos.durability_qos = DurabilityKind::TRANSIENT_LOCAL; - break; - - case 2: - qos.durability_qos = DurabilityKind::TRANSIENT; - break; - - case 3: - qos.durability_qos = DurabilityKind::PERSISTENT; - break; - - default: - break; - } - - return qos; -} - -} /* namespace testing */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp b/ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp deleted file mode 100644 index 3b2c1100a..000000000 --- a/ddspipe_core/src/cpp/types/data/RpcPayloadData.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -types::TopicInternalTypeDiscriminator RpcPayloadData::internal_type_discriminator() const noexcept -{ - return INTERNAL_TOPIC_TYPE_RPC; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp b/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp deleted file mode 100644 index 2d7be4523..000000000 --- a/ddspipe_core/src/cpp/types/data/RtpsPayloadData.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -RtpsPayloadData::~RtpsPayloadData() -{ - // If payload owner exists and payload has size, release it correctly in pool - if (payload_owner && payload.length > 0) - { - payload_owner->release_payload(payload); - } -} - -types::TopicInternalTypeDiscriminator RtpsPayloadData::internal_type_discriminator() const noexcept -{ - return INTERNAL_TOPIC_TYPE_RTPS; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/DomainId.cpp b/ddspipe_core/src/cpp/types/dds/DomainId.cpp deleted file mode 100644 index cce8d7728..000000000 --- a/ddspipe_core/src/cpp/types/dds/DomainId.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2021 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -DomainId::DomainId ( - bool discovery_server) noexcept - : domain_id(DEFAULT_DOMAIN_ID) -{ - // Discovery Server case has a different default value - if (discovery_server) - { - domain_id = DEFAULT_DISCOVERY_SERVER_DOMAIN_ID; - } -} - -DomainId::operator DomainIdType() const noexcept -{ - return this->domain_id; -} - -bool DomainId::is_valid( - utils::Formatter& error_msg) const noexcept -{ - if (domain_id > MAX_DOMAIN_ID) - { - error_msg << "Domain could not be higher than " << MAX_DOMAIN_ID << ". "; - return false; - } - return true; -} - -std::ostream& operator <<( - std::ostream& output, - const DomainId& domain) -{ - output << "DomainId{" << domain.domain_id << "}"; - return output; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/Endpoint.cpp b/ddspipe_core/src/cpp/types/dds/Endpoint.cpp deleted file mode 100644 index 747b33aec..000000000 --- a/ddspipe_core/src/cpp/types/dds/Endpoint.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -TopicQoS Endpoint::topic_qos() const noexcept -{ - return topic.topic_qos; -} - -bool Endpoint::is_writer() const noexcept -{ - return kind == EndpointKind::writer; -} - -bool Endpoint::is_reader() const noexcept -{ - return kind == EndpointKind::reader; -} - -bool Endpoint::is_server_endpoint() const noexcept -{ - return (is_reader() && RpcTopic::is_request_topic(topic)) || (is_writer() && RpcTopic::is_reply_topic(topic)); -} - -bool Endpoint::operator ==( - const Endpoint& other) const noexcept -{ - return guid == other.guid; -} - -std::ostream& operator <<( - std::ostream& os, - const Endpoint& endpoint) -{ - std::string active_str = endpoint.active ? "Active" : "Inactive"; - - os << - "Endpoint{" << endpoint.guid << - ";" << endpoint.kind << - ";" << endpoint.topic << - ";" << endpoint.specific_qos << - ";" << active_str << - ";" << endpoint.discoverer_participant_id << - "}"; - - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/Guid.cpp b/ddspipe_core/src/cpp/types/dds/Guid.cpp deleted file mode 100644 index 8d5113a99..000000000 --- a/ddspipe_core/src/cpp/types/dds/Guid.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2021 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -Guid::Guid( - const fastrtps::rtps::GUID_t& x) -{ - guidPrefix = x.guidPrefix; - entityId = x.entityId; -} - -Guid::Guid( - fastrtps::rtps::GUID_t&& x) -{ - guidPrefix = std::move(x.guidPrefix); - entityId = std::move(x.entityId); -} - -Guid& Guid::operator = ( - const fastrtps::rtps::GUID_t& other) noexcept -{ - this->guidPrefix = other.guidPrefix; - this->entityId = other.entityId; - return *this; -} - -bool Guid::is_valid() const noexcept -{ - return guid_prefix().is_valid() && - entityId != eprosima::fastrtps::rtps::EntityId_t::unknown(); -} - -GuidPrefix Guid::guid_prefix() const noexcept -{ - return GuidPrefix(guidPrefix); -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp b/ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp deleted file mode 100644 index 3e329652a..000000000 --- a/ddspipe_core/src/cpp/types/dds/GuidPrefix.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2021 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -GuidPrefix::GuidPrefix ( - const GuidPrefix_t& guid_prefix) noexcept - : GuidPrefix_t(guid_prefix) -{ -} - -GuidPrefix::GuidPrefix ( - const std::string& str_prefix) -{ - std::stringstream ss(str_prefix); - ss >> *this; - - // TODO launch exception -} - -GuidPrefix::GuidPrefix ( - const char* str_prefix) - : GuidPrefix(std::string(str_prefix)) -{ -} - -GuidPrefix::GuidPrefix ( - bool ros /*= false*/, - uint32_t id /*= 0*/) noexcept -{ - if (ros) - { - std::stringstream ss(ROS_DISCOVERY_SERVER_GUID_PREFIX_STR); - ss >> *this; - } - else - { - std::stringstream ss(SERVER_DEFAULT_GUID_PREFIX_STR); - ss >> *this; - } - - // Modify depending on the seed - // TODO : make available to modify for the whole guid prefix, so it is not truncated to 255 - value[2] = static_cast(id); -} - -GuidPrefix::GuidPrefix ( - uint32_t id) noexcept - : GuidPrefix(false, id) -{ -} - -GuidPrefix& GuidPrefix::operator = ( - const fastrtps::rtps::GuidPrefix_t& other) noexcept -{ - for (unsigned int i = 0; i < this->size; ++i) - { - this->value[i] = other.value[i]; - } - return *this; -} - -bool GuidPrefix::is_valid() const noexcept -{ - return *this != eprosima::fastrtps::rtps::GuidPrefix_t::unknown(); -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/Payload.cpp b/ddspipe_core/src/cpp/types/dds/Payload.cpp deleted file mode 100644 index 8633ea169..000000000 --- a/ddspipe_core/src/cpp/types/dds/Payload.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2021 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. - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -std::ostream& operator <<( - std::ostream& os, - const eprosima::fastrtps::rtps::octet& octet) -{ - os << std::hex << std::setfill('0') << std::setw(2) << static_cast(octet) << std::dec; - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const Payload& payload) -{ - os << "Payload{"; - - for (uint32_t i = 0; (payload.length != 0) && (i < (payload.length - 1)); ++i) - { - os << payload.data[i] << " "; - } - - // Avoid printing extra space after last byte - if (payload.length > 0) - { - os << payload.data[payload.length - 1]; - } - - os << "}"; - - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/SpecificEndpointQoS.cpp b/ddspipe_core/src/cpp/types/dds/SpecificEndpointQoS.cpp deleted file mode 100644 index ffc46afdf..000000000 --- a/ddspipe_core/src/cpp/types/dds/SpecificEndpointQoS.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2022 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 SpecificEndpointQoS.cpp - * - */ - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -bool SpecificEndpointQoS::operator < ( - const SpecificEndpointQoS& other) const noexcept -{ - // Ownership - if (this->ownership_strength.value < other.ownership_strength.value) - { - return true; - } - else if (this->ownership_strength.value > other.ownership_strength.value) - { - return false; - } - - // NOTE: PartitionQosPolicy operator< out of class implementation, this should be in Fast DDS file. - if (this->partitions.size() < other.partitions.size()) - { - return true; - } - else if (this->partitions.size() > other.partitions.size()) - { - return false; - } - - auto const this_names = this->partitions.getNames(); - auto const other_names = other.partitions.getNames(); - - for (unsigned int i = 0; i < this_names.size(); ++i) - { - if (this_names[i] < other_names[i]) - { - return true; - } - else if (this_names[i] > other_names[i]) - { - return false; - } - } - - return false; -} - -bool SpecificEndpointQoS::operator == ( - const SpecificEndpointQoS& other) const noexcept -{ - return this->partitions == other.partitions && this->ownership_strength == other.ownership_strength; -} - -std::ostream& operator <<( - std::ostream& os, - const PartitionQosPolicy& qos) -{ - os << "Partitions{"; - for (auto const& p : qos) - { - os << p.name() << ";"; - } - os << "}"; - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const OwnershipStrengthQosPolicy& qos) -{ - os << "OwnershipStrength{" << qos.value << "}"; - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const SpecificEndpointQoS& qos) -{ - os << - "SpecificEndpointQoS{" << qos.partitions << - ";" << qos.ownership_strength << - "}"; - - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/dds/TopicQoS.cpp b/ddspipe_core/src/cpp/types/dds/TopicQoS.cpp deleted file mode 100644 index 57b4a29fd..000000000 --- a/ddspipe_core/src/cpp/types/dds/TopicQoS.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2022 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 TopicQoS.cpp - * - */ - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -std::atomic TopicQoS::default_history_depth{1000}; - -TopicQoS::TopicQoS() -{ - // Set history by default - history_depth = default_history_depth; -} - -bool TopicQoS::operator ==( - const TopicQoS& other) const noexcept -{ - return - this->reliability_qos == other.reliability_qos && - this->durability_qos == other.durability_qos && - this->history_depth == other.history_depth && - this->ownership_qos == other.ownership_qos && - this->use_partitions == other.use_partitions; -} - -bool TopicQoS::is_reliable() const noexcept -{ - return reliability_qos == ReliabilityKind::RELIABLE; -} - -bool TopicQoS::is_transient_local() const noexcept -{ - return durability_qos == DurabilityKind::TRANSIENT_LOCAL; -} - -bool TopicQoS::has_ownership() const noexcept -{ - return ownership_qos == OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS; -} - -bool TopicQoS::has_partitions() const noexcept -{ - return use_partitions; -} - -std::ostream& operator <<( - std::ostream& os, - const DurabilityKind& kind) -{ - switch (kind) - { - case DurabilityKind::VOLATILE: - os << "VOLATILE"; - break; - - case DurabilityKind::TRANSIENT_LOCAL: - os << "TRANSIENT_LOCAL"; - break; - - case DurabilityKind::TRANSIENT: - os << "TRANSIENT"; - break; - - case DurabilityKind::PERSISTENT: - os << "PERSISTENT"; - break; - - default: - utils::tsnh(utils::Formatter() << "Invalid Durability Kind."); - break; - } - - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const ReliabilityKind& kind) -{ - switch (kind) - { - case ReliabilityKind::RELIABLE: - os << "RELIABLE"; - break; - - case ReliabilityKind::BEST_EFFORT: - os << "BEST_EFFORT"; - break; - - default: - utils::tsnh(utils::Formatter() << "Invalid Reliability Kind."); - break; - } - - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const OwnershipQosPolicyKind& kind) -{ - switch (kind) - { - case OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS: - os << "SHARED"; - break; - - case OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS: - os << "EXCLUSIVE"; - break; - - default: - utils::tsnh(utils::Formatter() << "Invalid Ownership Kind."); - break; - } - - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const TopicQoS& qos) -{ - os << - "TopicQoS{" << qos.durability_qos << - ";" << qos.reliability_qos << - ";" << qos.ownership_qos << - (qos.has_partitions() ? ";partitions" : "") << - ";depth(" << qos.history_depth << ")" << - "}"; - - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/topic/Topic.cpp b/ddspipe_core/src/cpp/types/topic/Topic.cpp deleted file mode 100644 index 8537afa3e..000000000 --- a/ddspipe_core/src/cpp/types/topic/Topic.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2021 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 Topic.cpp - * - */ - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -///////////////////////// -// OPERATORS -///////////////////////// - -bool Topic::operator==(const ITopic& other) const noexcept -{ - return - topic_unique_name() == other.topic_unique_name(); -} - -bool Topic::operator<(const ITopic& other) const noexcept -{ - return topic_unique_name() < other.topic_unique_name(); -} - -///////////////////////// -// METHODS -///////////////////////// - -std::string Topic::topic_name() const noexcept -{ - return m_topic_name; -} - -TopicInternalTypeDiscriminator Topic::internal_type_discriminator() const noexcept -{ - return m_internal_type_discriminator; -} - -bool Topic::is_valid( - utils::Formatter& error_msg) const noexcept -{ - if (m_topic_name.empty()) - { - error_msg << "Topic name could not be empty. "; - return false; - } - - if (m_internal_type_discriminator == INTERNAL_TOPIC_TYPE_NONE) - { - error_msg << "Internal type discriminator could not be None. "; - return false; - } - - return true; -} - -///////////////////////// -// METHODS TO OVERRIDE -///////////////////////// - -//! ITopic unique name in processs -std::string Topic::topic_unique_name() const noexcept -{ - return m_topic_name + m_internal_type_discriminator; -} - -///////////////////////// -// SERIALIZE -///////////////////////// - -std::ostream& operator <<( - std::ostream& os, - const Topic& t) -{ - os << "Topic{" << t.m_topic_name << ";(" << t.m_internal_type_discriminator << ")}"; - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp b/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp deleted file mode 100644 index aa8bbc084..000000000 --- a/ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2022 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 DdsTopic.cpp - * - */ - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -DdsTopic::DdsTopic() -{ - m_internal_type_discriminator = INTERNAL_TOPIC_TYPE_RTPS; -} - -std::ostream& operator <<( - std::ostream& os, - const DdsTopic& t) -{ - os << "DdsTopic{" << t.topic_name() << ";" << t.type_name << t.topic_qos << "}"; - return os; -} - -///////////////////////// -// METHODS -///////////////////////// - -bool DdsTopic::is_valid( - utils::Formatter& error_msg) const noexcept -{ - if (!Topic::is_valid(error_msg)) - { - return false; - } - - return is_valid_dds_topic(m_topic_name, type_name, error_msg); -} - -std::string DdsTopic::topic_unique_name() const noexcept -{ - return Topic::topic_unique_name() + type_name; -} - -///////////////////////// -// STATIC METHODS -///////////////////////// - -bool DdsTopic::is_valid_dds_topic( - const std::string& topic_name, - const std::string& type_name, - utils::Formatter& error_msg) noexcept -{ - if (topic_name.empty()) - { - error_msg << "Topic name could not be empty. "; - return false; - } - - if (type_name.empty()) - { - error_msg << "Topic type name could not be empty. "; - return false; - } - - // TODO: extend with regex - // It checks if topic name or type contain an invalid substring - std::vector invalid_substrings = { - "*", // Wildcard char - }; - - for (std::string invalid_substring : invalid_substrings) - { - if (topic_name.find(invalid_substring) != std::string::npos) - { - error_msg << "Topic name could not contain " << invalid_substring << " . "; - return false; - } - else if (type_name.find(invalid_substring) != std::string::npos) - { - error_msg << "Topic type name could not contain " << invalid_substring << " . "; - return false; - } - } - - return true; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp b/ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp deleted file mode 100644 index e833b721c..000000000 --- a/ddspipe_core/src/cpp/types/topic/filter/IFilterTopic.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -bool IFilterTopic::operator < ( - const IFilterTopic& other) const noexcept -{ - return utils::generic_to_string(other) < utils::generic_to_string(*this); -} - -bool IFilterTopic::operator == ( - const IFilterTopic& other) const noexcept -{ - return utils::generic_to_string(other) == utils::generic_to_string(*this); -} - -std::ostream& operator <<( - std::ostream& os, - const IFilterTopic& t) -{ - t.serialize(os); - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp b/ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp deleted file mode 100644 index e80d2c669..000000000 --- a/ddspipe_core/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -bool WildcardDdsFilterTopic::contains( - const IFilterTopic& other) const -{ - if (!IS_SAME_TYPE_AS_THIS(other)) - { - return false; - } - // TODO: implement - static_cast (other); - return false; -} - -bool WildcardDdsFilterTopic::matches( - const ITopic& other) const -{ - if (utils::can_cast(other)) - { - return matches_(static_cast(other)); - } - return false; -} - -///////////////////////// -// SERIALIZATION METHODS -///////////////////////// - -std::ostream& WildcardDdsFilterTopic::serialize( - std::ostream& os) const -{ - os << *this; - return os; -} - -std::ostream& operator <<( - std::ostream& os, - const WildcardDdsFilterTopic& t) -{ - os << "WildcardDdsFilterTopic{" << t.topic_name << ";" << t.type_name << "}"; - return os; -} - -bool WildcardDdsFilterTopic::matches_( - const DdsTopic& real_topic) const -{ - // Compare topic_name - if (this->topic_name.is_set()) - { - if (!utils::match_pattern(this->topic_name.get_reference(), real_topic.topic_name())) - { - return false; - } - } - - // Compare type_name - if (this->type_name.is_set()) - { - if (!utils::match_pattern(this->type_name.get_reference(), real_topic.type_name)) - { - return false; - } - } - - return true; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp b/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp deleted file mode 100644 index f003e361a..000000000 --- a/ddspipe_core/src/cpp/types/topic/rpc/RpcTopic.cpp +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright 2022 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 RpcTopic.cpp - * - */ - -#include - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -const std::string RpcTopic::REQUEST_PREFIX_STR = "rq/"; -const std::string RpcTopic::REPLY_PREFIX_STR = "rr/"; -const std::string RpcTopic::REQUEST_STR = "Request"; -const std::string RpcTopic::REPLY_STR = "Reply"; -const std::string RpcTopic::RESPONSE_STR = "Response"; - -RpcTopic::RpcTopic( - const std::string& service_name, - const DdsTopic& request_topic, - const DdsTopic& reply_topic) noexcept - : service_name_(service_name) - , request_topic_(request_topic) - , reply_topic_(reply_topic) -{ -} - -RpcTopic::RpcTopic( - const DdsTopic& topic) noexcept -{ - if (is_request_topic(topic)) - { - request_topic_ = topic; - - reply_topic_ = topic; - reply_topic_.m_topic_name = - std::regex_replace(reply_topic_.m_topic_name, std::regex(REQUEST_PREFIX_STR), REPLY_PREFIX_STR); - reply_topic_.m_topic_name = - std::regex_replace(reply_topic_.m_topic_name, std::regex(REQUEST_STR), REPLY_STR); - reply_topic_.type_name = - std::regex_replace(reply_topic_.type_name, std::regex(REQUEST_STR), RESPONSE_STR); - - service_name_ = std::regex_replace(topic.m_topic_name, std::regex(REQUEST_PREFIX_STR + "|" + REQUEST_STR), ""); - } - else if (is_reply_topic(topic)) - { - reply_topic_ = topic; - - request_topic_ = topic; - request_topic_.m_topic_name = - std::regex_replace(request_topic_.m_topic_name, std::regex(REPLY_PREFIX_STR), REQUEST_PREFIX_STR); - request_topic_.m_topic_name = - std::regex_replace(request_topic_.m_topic_name, std::regex(REPLY_STR), REQUEST_STR); - request_topic_.type_name = - std::regex_replace(request_topic_.type_name, std::regex(RESPONSE_STR), REQUEST_STR); - - service_name_ = std::regex_replace(topic.m_topic_name, std::regex(REPLY_PREFIX_STR + "|" + REPLY_STR), ""); - } - else - { - utils::tsnh( - utils::Formatter() << "Attempting to create RpcTopic from invalid topic."); - } - - reply_topic_.m_internal_type_discriminator = INTERNAL_TOPIC_TYPE_RPC; - request_topic_.m_internal_type_discriminator = INTERNAL_TOPIC_TYPE_RPC; - - // Set both topic qos as the one found - request_topic_.topic_qos = topic.topic_qos; - reply_topic_.topic_qos = topic.topic_qos; -} - -RpcTopic::RpcTopic(const RpcTopic& other) noexcept - : service_name_(other.service_name_) - , request_topic_(other.request_topic_) - , reply_topic_(other.reply_topic_) -{ - -} - -const std::string& RpcTopic::service_name() const -{ - return service_name_; -} - -const DdsTopic& RpcTopic::request_topic() const -{ - return request_topic_; -} - -const DdsTopic& RpcTopic::reply_topic() const -{ - return reply_topic_; -} - -bool RpcTopic::is_request_topic( - const DdsTopic& topic) -{ - std::string m_topic_name = topic.m_topic_name; - std::string type_name = topic.type_name; - - return (m_topic_name.find(REQUEST_PREFIX_STR) == 0) && - (m_topic_name.rfind(REQUEST_STR) + REQUEST_STR.length() == m_topic_name.length()) && - (type_name.rfind(REQUEST_STR) + REQUEST_STR.length() + 1 == type_name.length()); -} - -bool RpcTopic::is_reply_topic( - const DdsTopic& topic) -{ - std::string m_topic_name = topic.m_topic_name; - std::string type_name = topic.type_name; - - return (m_topic_name.find(REPLY_PREFIX_STR) == 0) && - (m_topic_name.rfind(REPLY_STR) + REPLY_STR.length() == m_topic_name.length()) && - (type_name.rfind(RESPONSE_STR) + RESPONSE_STR.length() + 1 == type_name.length()); -} - -bool RpcTopic::is_service_topic( - const DdsTopic& topic) -{ - return is_request_topic(topic) || is_reply_topic(topic); -} - -bool RpcTopic::operator <( - const RpcTopic& other) const -{ - int name_comparison = service_name_.compare(other.service_name()); - if (name_comparison < 0) - { - return true; - } - else - { - return false; - } -} - -std::ostream& operator <<( - std::ostream& os, - const RpcTopic& a) -{ - os << "RpcTopic{" << a.service_name() << "}"; - return os; -} - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_core/test/CMakeLists.txt b/ddspipe_core/test/CMakeLists.txt deleted file mode 100644 index eefcda457..000000000 --- a/ddspipe_core/test/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2022 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. - -# Add subdirectory with tests -add_subdirectory(unittest) -# add_subdirectory(blackbox) diff --git a/ddspipe_core/test/unittest/CMakeLists.txt b/ddspipe_core/test/unittest/CMakeLists.txt deleted file mode 100644 index 45c3e49c1..000000000 --- a/ddspipe_core/test/unittest/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2021 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. - -# TODO do these tests -# add_subdirectory(core) -add_subdirectory(dynamic) -add_subdirectory(efficiency) -add_subdirectory(types) diff --git a/ddspipe_core/test/unittest/core/CMakeLists.txt b/ddspipe_core/test/unittest/core/CMakeLists.txt deleted file mode 100644 index 8d9fde3f3..000000000 --- a/ddspipe_core/test/unittest/core/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(participants_database) diff --git a/ddspipe_core/test/unittest/core/participants_database/CMakeLists.txt b/ddspipe_core/test/unittest/core/participants_database/CMakeLists.txt deleted file mode 100644 index bf91b8503..000000000 --- a/ddspipe_core/test/unittest/core/participants_database/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2021 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. - -######################### -# Participants Database # -######################### - -set(TEST_NAME ParticipantsDatabaseTest) - -set(TEST_SOURCES - ParticipantsDatabaseTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participants/participant/auxiliar/BlankParticipant.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantsDatabase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participants/reader/auxiliar/BlankReader.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/participants/writer/auxiliar/BlankWriter.cpp - ) -all_header_sources("${TEST_SOURCES}") - -set(TEST_LIST - add_participant - empty - get_participant - get_participants_ids - get_participants_map - pop - size - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp b/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp deleted file mode 100644 index 144de1480..000000000 --- a/ddspipe_core/test/unittest/core/participants_database/ParticipantsDatabaseTest.cpp +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include -#include -#include -#include - -using namespace eprosima::ddspipe::core; - -namespace test { - -struct MockParticipant : public IParticipant -{ - types::ParticipantId id() const noexcept - { - return types::ParticipantId("test_participant"); - } - - bool is_rtps_kind() const noexcept - { - return false; - } - - bool is_repeater() const noexcept - { - return false; - } - - std::shared_ptr create_writer( - const ITopic& topic) - { - // NOTICE: be careful with this as this has a nullptr - return std::shared_ptr(); - } - - std::shared_ptr create_reader( - const ITopic& topic) - { - // NOTICE: be careful with this as this has a nullptr - return std::shared_ptr(); - } -} - -} /* namespace test */ - -/********************* -* PROTECTED METHODS ** -*********************/ - -/** - * Test the addition of a participant to the database - * - * CASES: - * - * Add not stored participant - * Add already stored participant - */ -TEST(ParticipantsDatabaseTest, add_participant) -{ - std::shared_ptr participants_database = std::make_shared(); - // Check database is empty - ASSERT_TRUE(participants_database->empty()); - - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - // Insert participant - participants_database->add_participant(participant->id(), participant, 1); - - // Reinsert and check it throws an error - ASSERT_THROW( - participants_database->add_participant( - participant->id(), - participant, 1), - eprosima::utils::InconsistencyException); -} - -/** - * Test the extraction of a participant from the database - * - * CASES: - * Empty database - * Pop random participant - * Pop specific participant - * Pop not stored participant - * Pop stored participant - */ -TEST(ParticipantsDatabaseTest, pop) -{ - std::shared_ptr participants_database = std::make_shared(); - ASSERT_TRUE(participants_database->empty()); - // Empty database, no participant should be popped - ASSERT_TRUE(participants_database->pop() == nullptr); - - ParticipantId id1("void_p1"); - std::shared_ptr participant1 = std::make_shared(id1); - ParticipantId id2("void_p2"); - std::shared_ptr participant2 = std::make_shared(id2); - // Pop not yet stored participant - ASSERT_TRUE(participants_database->pop(id1) == nullptr); - ASSERT_TRUE(participants_database->pop(id2) == nullptr); - - // Insert participants into database - participants_database->add_participant(participant1->id(), participant1, 1); - participants_database->add_participant(participant2->id(), participant2, 2); - - // Pop stored participants - ASSERT_EQ(participants_database->pop(id1), participant1); - ASSERT_EQ(participants_database->pop(), participant2); - // Participants should have been removed - ASSERT_TRUE(participants_database->get_participant(id1) == nullptr); - ASSERT_TRUE(participants_database->get_participant(id2) == nullptr); - ASSERT_TRUE(participants_database->empty()); -} - -/********************* -* PUBLIC METHODS ** -*********************/ - -/** - * Test \c ParticipantsDatabase \c empty method - * - * CASES: - * Empty database - * Non-empty database - */ -TEST(ParticipantsDatabaseTest, empty) -{ - std::shared_ptr participants_database = std::make_shared(); - // Empty database - ASSERT_TRUE(participants_database->empty()); - - // Non-empty database - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - participants_database->add_participant(participant->id(), participant, 1); - ASSERT_FALSE(participants_database->empty()); -} - -/** - * Test \c ParticipantsDatabase \c get_participant method - * - * CASES: - * Empty configuration - * Random configuration - */ -TEST(ParticipantsDatabaseTest, get_participant) -{ - std::shared_ptr participants_database = std::make_shared(); - - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - participants_database->add_participant(participant->id(), participant, 1); - - ASSERT_EQ(participants_database->get_participant(id), participant); -} - -/** - * Test \c ParticipantsDatabase \c get_participants_ids method - */ -TEST(ParticipantsDatabaseTest, get_participants_ids) -{ - std::shared_ptr participants_database = std::make_shared(); - - ParticipantId id1("void_p1"); - std::shared_ptr participant1 = std::make_shared(id1); - participants_database->add_participant(participant1->id(), participant1, 1); - - ParticipantId id2("void_p2"); - std::shared_ptr participant2 = std::make_shared(id2); - participants_database->add_participant(participant2->id(), participant2, 2); - - std::set ids {id2, id1}; - ASSERT_EQ(ids, participants_database->get_participants_ids()); -} - -/** - * Test \c ParticipantsDatabase \c get_participants_map getter method - */ -TEST(ParticipantsDatabaseTest, get_participants_map) -{ - ParticipantId id("void_part"); - std::shared_ptr participant = std::make_shared(id); - std::map> participants = {{id, participant}}; - - std::shared_ptr participants_database = std::make_shared( - participants); - ASSERT_EQ(participants_database->get_participants_map(), participants); -} - -/** - * Test \c ParticipantsDatabase \c size getter method - */ -TEST(ParticipantsDatabaseTest, size) -{ - std::shared_ptr participants_database = std::make_shared(); - // Check database is empty - ASSERT_EQ(participants_database->size(), 0u); - - ParticipantId id_1("void_part"); - std::shared_ptr participant_1 = std::make_shared(id_1); - // Insert participant_1 - participants_database->add_participant(participant_1->id(), participant_1, 1); - ASSERT_EQ(participants_database->size(), 1u); - - ParticipantId id_2("simple_part"); - std::shared_ptr participant_2 = std::make_shared(id_2); - // Insert participant_2 - participants_database->add_participant(participant_2->id(), participant_2, 2); - ASSERT_EQ(participants_database->size(), 2u); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/dynamic/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/CMakeLists.txt deleted file mode 100644 index a0e7f756e..000000000 --- a/ddspipe_core/test/unittest/dynamic/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(allowed_topic_list) diff --git a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp deleted file mode 100644 index 91b7d215b..000000000 --- a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/AllowedTopicListTest.cpp +++ /dev/null @@ -1,514 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -using namespace eprosima; -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -using pair_topic_type = std::pair; - -namespace test -{ - -/****************** -* FILTER METHODS * -******************/ - -/* - * Add a topic to a list - * - * TODO: Add regex when implemented - */ -void add_topic_to_list( - std::set>& list, - pair_topic_type topic_name, - bool wildcard = true) -{ - if (wildcard) - { - auto new_topic = utils::Heritable::make_heritable(); - new_topic->topic_name = topic_name.first; - new_topic->type_name = topic_name.second; - - list.insert(new_topic); - } -} - -/* - * Add several topic to a list - * - * TODO: Add regex when implemented - */ -void add_topics_to_list( - std::set>& list, - std::vector topic_names, - bool wildcard = true) -{ - if (wildcard) - { - for (pair_topic_type topic_name : topic_names) - { - auto new_topic = utils::Heritable::make_heritable(); - new_topic->topic_name = topic_name.first; - new_topic->type_name = topic_name.second; - - list.insert(new_topic); - } - } -} - -/* - * Create an AllowedTopicList object with the allowlist and blocklist given by argument - * Check that all topics in real_topics_positive are allowed by the AllowedTopicList - * Check that all topics in real_topics_negative are not allowed by the AllowedTopicList - */ -void generic_test( - const std::vector& allowlist_topics, - const std::vector& blocklist_topics, - const std::vector& real_topics_positive, - const std::vector& real_topics_negative) -{ - // Create AllowedTopicList object - std::set> allowlist; - std::set> blocklist; - - add_topics_to_list(allowlist, allowlist_topics); - add_topics_to_list(blocklist, blocklist_topics); - - AllowedTopicList atl(allowlist, blocklist); - - // Test positive cases - for (pair_topic_type topic_name : real_topics_positive) - { - DdsTopic topic; - topic.m_topic_name = topic_name.first; - topic.type_name = topic_name.second; - ASSERT_TRUE(atl.is_topic_allowed(topic)); - } - - // Test negative cases - for (pair_topic_type topic_name : real_topics_negative) - { - DdsTopic topic; - topic.m_topic_name = topic_name.first; - topic.type_name = topic_name.second; - ASSERT_FALSE(atl.is_topic_allowed(topic)); - } -} - -} // test - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using default constructor - */ -TEST(AllowedTopicListTest, is_topic_allowed__default_constructor) -{ - AllowedTopicList atl; - - std::vector real_topics = - { - {"topic1", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - for (pair_topic_type topic_name : real_topics) - { - DdsTopic topic; - topic.m_topic_name = topic_name.first; - topic.type_name = topic_name.second; - - ASSERT_TRUE(atl.is_topic_allowed(topic)); - } -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using empty lists - */ -TEST(AllowedTopicListTest, is_topic_allowed__empty_list) -{ - std::vector allowlist_topics; - std::vector blocklist_topics; - std::vector real_topics_negative; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple blocklist: only with real topics - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_blocklist) -{ - std::vector allowlist_topics; - - std::vector blocklist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_positive = - { - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex blocklist: with wildcards that superpose - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_blocklist) -{ - std::vector allowlist_topics; - - std::vector blocklist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt/chatter*", "std::*"}, - }; - - std::vector real_topics_positive = - { - {"topic2", "type2"}, - {"rt/topic_info", "std::std_msgs::string"}, - {"rt/chatter/pub", "std_type"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/chatter/pub", "std::type"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple allowlist: only with real topics - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist) -{ - std::vector blocklist_topics; - - std::vector allowlist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1_"}, - {"topic1_", "type1"}, - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex allowlist: with wildcards that superpose - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist) -{ - std::vector blocklist_topics; - - std::vector allowlist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt/chatter*", "std::*"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"OtherTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/chatter/pub", "std::string"}, - }; - - std::vector real_topics_negative = - { - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"rt/pub", "std::std_msgs::string"}, - {"rt/chatter", "std_type"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple allowlist and simple blocklist: only with real topics - * Lists do not superpose to each other - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist) -{ - std::vector allowlist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector blocklist_topics = - { - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type2"}, - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/pub", "std"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex allowlist and complex blocklist: with wildcards that superpose - * Lists do not superpose to each other - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist) -{ - std::vector allowlist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt/pub*", "std_type::*"}, - }; - - std::vector blocklist_topics = - { - {"topic2", "*"}, - {"*", "HelloWorldType"}, - {"rt/chatter*", "std*"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"OtherTopic", "HelloWorld"}, - {"rt/pub/topic", "std_type::string"}, - {"rt/pub", "std_type::string"}, - }; - - std::vector real_topics_negative = - { - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"OtherTopic", "HelloWorldType"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/chatter/pub", "std"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using simple allowlist and simple blocklist: only with real topics - * Blocklist has topics that block the allowlist ones - */ -TEST(AllowedTopicListTest, is_topic_allowed__simple_allowlist_and_blocklist_entangled) -{ - std::vector allowlist_topics = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector blocklist_topics = - { - {"topic2", "type2"}, - {"rt/chatter", "std::std_msgs::string"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "type1"}, - {"HelloWorldTopic", "HelloWorld"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type2"}, - {"topic2", "type1"}, - {"topic2", "type2"}, - {"HelloWorldTopic", "HelloWorldType"}, - {"rt/chatter", "std::std_msgs::string"}, - {"rt/pub", "std"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -/** - * Test \c AllowedTopicList \c is_topic_allowed method - * - * Case using complex allowlist and complex blocklist: with wildcards that superpose - * Blocklist has topics that block the allowlist ones - */ -TEST(AllowedTopicListTest, is_topic_allowed__complex_allowlist_and_blocklist_entangled) -{ - std::vector allowlist_topics = - { - {"topic1", "*"}, - {"*", "HelloWorld"}, - {"rt*", "std*"}, - }; - - std::vector blocklist_topics = - { - {"topic1", "type*"}, - {"*HelloWorld", "HelloWorld"}, - {"rt/chatter*", "std_type::std_msgs*"}, - }; - - std::vector real_topics_positive = - { - {"topic1", "wtype1"}, - {"topic1", "wtype2"}, - {"HelloWorldTopic", "HelloWorld"}, - {"OtherTopic", "HelloWorld"}, - {"rt/pub", "std_type::std_msgs::string"}, - {"rt/chatter", "std::string"}, - }; - - std::vector real_topics_negative = - { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"TopicHelloWorld", "HelloWorld"}, - {"OtherHelloWorld", "HelloWorld"}, - {"rt/chatter", "std_type::std_msgs::string"}, - {"rt/chatter/pub", "std_type::std_msgs::string"}, - {"chatter", "std::std_msgs::int"}, - }; - - test::generic_test( - allowlist_topics, - blocklist_topics, - real_topics_positive, - real_topics_negative); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt b/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt deleted file mode 100644 index 4edef040f..000000000 --- a/ddspipe_core/test/unittest/dynamic/allowed_topic_list/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2021 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. - -set(TEST_NAME AllowedTopicListTest) - -set(TEST_SOURCES - AllowedTopicListTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic/AllowedTopicList.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/IFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ) -all_header_sources("${TEST_SOURCES}") - -set(TEST_LIST - is_topic_allowed__default_constructor - is_topic_allowed__empty_list - is_topic_allowed__simple_blocklist - is_topic_allowed__complex_blocklist - is_topic_allowed__simple_allowlist - is_topic_allowed__complex_allowlist - is_topic_allowed__simple_allowlist_and_blocklist - is_topic_allowed__complex_allowlist_and_blocklist - is_topic_allowed__simple_allowlist_and_blocklist_entangled - is_topic_allowed__complex_allowlist_and_blocklist_entangled - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_core/test/unittest/efficiency/CMakeLists.txt b/ddspipe_core/test/unittest/efficiency/CMakeLists.txt deleted file mode 100644 index 0928dcc51..000000000 --- a/ddspipe_core/test/unittest/efficiency/CMakeLists.txt +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright 2022 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. - -############################## -# Interface PayloadPool Test # -############################## - -set(TEST_NAME PayloadPoolTest) - -set(TEST_SOURCES - PayloadPoolTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp - ) - -set(TEST_LIST - reserve - release - reserve_and_release_counter - is_clean - get_payload_cache_change - get_payload_from_src_cache_change - release_payload_cache_change - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -######################## -# Map PayloadPool Test # -######################## - -set(TEST_NAME MapPayloadPoolTest) - -set(TEST_SOURCES - MapPayloadPoolTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/MapPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp - ) - -set(TEST_LIST - get_payload - get_payload_from_src - get_payload_from_src_no_owner - get_payload_from_src_negative - release_payload - release_payload_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -######################## -# Fast PayloadPool Test # -######################## - -set(TEST_NAME FastPayloadPoolTest) - -set(TEST_SOURCES - FastPayloadPoolTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/PayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/efficiency/payload/FastPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp - ) - -set(TEST_LIST - get_payload - get_payload_from_src - get_payload_from_src_no_owner - get_payload_from_src_negative - release_payload - release_payload_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp deleted file mode 100644 index 8b8763519..000000000 --- a/ddspipe_core/test/unittest/efficiency/FastPayloadPoolTest.cpp +++ /dev/null @@ -1,324 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -#include -#include -#include - -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -const constexpr unsigned int TEST_NUMBER = 5; -const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -/** - * @brief Mock over FastPayloadPool implementing public access to private variables. - * - */ -class MockFastPayloadPool : public FastPayloadPool -{ -public: - - using FastPayloadPool::FastPayloadPool; - - uint64_t pointers_stored() - { - return reserve_count_ - release_count_; - } - - void release_all( - std::vector& payloads) - { - for (auto& payload : payloads) - { - release_payload(payload); - } - } - -}; - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/* - * This tests does not check the methods calling cacheChange, this is tested in generic PayloadPool test. - */ - -/** - * Test get_payload method for new changes - * - * CASES: - * Get N different pointers - * fail reserve memory - */ -TEST(FastPayloadPoolTest, get_payload) -{ - // Get N different pointers - { - test::MockFastPayloadPool pool; - std::vector payloads(TEST_NUMBER); - - for (unsigned int i = 0; i < TEST_NUMBER; i++) - { - pool.get_payload(DEFAULT_SIZE, payloads[i]); - - ASSERT_EQ(payloads[i].max_size, DEFAULT_SIZE); - ASSERT_EQ(pool.pointers_stored(), i + 1); - } - - // END : Clean all remaining payloads - pool.release_all(payloads); - } - - // fail reserve memory - { - test::MockFastPayloadPool pool; - Payload payload; - - ASSERT_FALSE(pool.get_payload(0, payload)); - } -} - -/** - * Check to get_payload from a source that has been created in same pool increase references. - * - * STEPS: - * get payload0 - * get payload1 from src payload0 - * get payload2 from src payload1 - * release payload0 - * get payload3 from src payload1 - * get payload4 - * get payload5 from src payload4 - * release all - */ -TEST(FastPayloadPoolTest, get_payload_from_src) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - - Payload payload0; - Payload payload1; - Payload payload2; - Payload payload3; - Payload payload4; - Payload payload5; - - // get payload0 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE, payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // get payload1 from src payload0 - ASSERT_TRUE(pool_->get_payload(payload0, pool, payload1)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(payload1.max_size, payload0.max_size); - ASSERT_EQ(payload1.data, payload0.data); - - // get payload2 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload2)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(payload2.max_size, payload0.max_size); - ASSERT_EQ(payload2.data, payload0.data); - - // release payload0 - ASSERT_TRUE(pool_->release_payload(payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // get payload3 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload3)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(payload3.max_size, payload1.max_size); - ASSERT_EQ(payload3.data, payload1.data); - - // get payload4 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE * 0x100, payload4)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - - // get payload5 from src payload4 - ASSERT_TRUE(pool_->get_payload(payload4, pool, payload5)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - ASSERT_EQ(payload5.max_size, payload4.max_size); - ASSERT_EQ(payload5.data, payload4.data); - - // release all - ASSERT_TRUE(pool_->release_payload(payload1)); - ASSERT_TRUE(pool_->release_payload(payload2)); - ASSERT_TRUE(pool_->release_payload(payload3)); - ASSERT_TRUE(pool_->release_payload(payload4)); - ASSERT_TRUE(pool_->release_payload(payload5)); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check to get_payload from a source that has been created in a different pool - * - * STEPS: - * get payload aux from pool aux - * get payload from src payload aux - * release payload aux from pool aux - * release payload - */ -TEST(FastPayloadPoolTest, get_payload_from_src_no_owner) -{ - // Each pool has a IPayloadPool and a MockFastPayloadPool so it can be called to get_payload from source - // and specific methods from mock - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_aux_ = static_cast(pool_aux); - - Payload payload_src; - Payload payload_target; - - // get payload aux from pool aux - pool_aux_->get_payload(DEFAULT_SIZE, payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 1u); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // get payload from src payload aux - ASSERT_TRUE(pool_->get_payload(payload_src, pool_aux, payload_target)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload aux from pool aux - pool_aux_->release_payload(payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 0u); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload - pool_->release_payload(payload_target); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool_aux; - delete pool; -} - -/** - * Check negative cases for get_payload from source - * - * CASES: - * Source has size 0 and different owner - */ -TEST(FastPayloadPoolTest, get_payload_from_src_negative) -{ - // Source has size 0 and different owner - { - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = nullptr; // nullptr - - Payload payload_src; - Payload payload_target; - - ASSERT_FALSE( - pool_->get_payload( - payload_src, - pool_aux, - payload_target)); - - delete pool; - } -} - -/** - * Get some payloads from pool from src and release each of them separatly checking reference count - * - * STEPS: - * get first payload - * get N-1 payloads from first - * release N-2 payloads - * get N-2 more payloads from first - * release N payloads - */ -TEST(FastPayloadPoolTest, release_payload) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockFastPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockFastPayloadPool* pool_ = static_cast(pool); - std::vector payloads(TEST_NUMBER); - - // get first payload - pool_->get_payload(DEFAULT_SIZE, payloads[0]); - - // get N-1 payloads from first - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - } - - // release N-2 payloads - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - } - - // get N-2 more payloads from first - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - } - - // release N payloads - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - } - // Removing last payload because if not the reference count cannot be done - ASSERT_TRUE(pool_->release_payload(payloads[0])); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check release a payload that has been get from a different payload pool - */ -TEST(FastPayloadPoolTest, release_payload_negative) -{ - test::MockFastPayloadPool pool; - test::MockFastPayloadPool pool_aux; - Payload payload; - - pool_aux.get_payload(DEFAULT_SIZE, payload); - - ASSERT_THROW(pool.release_payload(payload), eprosima::utils::InconsistencyException); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp deleted file mode 100644 index 539f344d9..000000000 --- a/ddspipe_core/test/unittest/efficiency/MapPayloadPoolTest.cpp +++ /dev/null @@ -1,366 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -#include -#include -#include - -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -const constexpr unsigned int TEST_NUMBER = 5; -const constexpr size_t DEFAULT_SIZE = sizeof(PayloadUnit); - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -/** - * @brief Mock over MapPayloadPool implementing public access to private variables. - * - */ -class MockMapPayloadPool : public MapPayloadPool -{ -public: - - using MapPayloadPool::MapPayloadPool; - - uint64_t pointers_stored() - { - return reserved_payloads_.size(); - } - - uint64_t reference_count( - const Payload& payload) - { - return reserved_payloads_[payload.data]; - } - - void clean_all( - std::vector& payloads) - { - for (Payload& payload : payloads) - { - release_payload(payload); - } - } - -}; - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/* - * This tests does not check the methods calling cacheChange, this is tested in generic PayloadPool test. - */ - -/** - * Test get_payload method for new changes - * - * CASES: - * Get N different pointers - * fail reserve memory - */ -TEST(MapPayloadPoolTest, get_payload) -{ - // Get N different pointers - { - test::MockMapPayloadPool pool; - std::vector payloads(TEST_NUMBER); - - for (unsigned int i = 0; i < TEST_NUMBER; i++) - { - pool.get_payload(DEFAULT_SIZE, payloads[i]); - - ASSERT_EQ(payloads[i].max_size, DEFAULT_SIZE); - ASSERT_EQ(pool.pointers_stored(), i + 1); - ASSERT_EQ(pool.reference_count(payloads[i]), 1u); - } - - // END : Clean all remaining payloads - pool.clean_all(payloads); - } - - // fail reserve memory - { - test::MockMapPayloadPool pool; - Payload payload; - - ASSERT_FALSE(pool.get_payload(0, payload)); - } -} - -/** - * Check to get_payload from a source that has been created in same pool increase references. - * - * STEPS: - * get payload0 - * get payload1 from src payload0 - * get payload2 from src payload1 - * release payload0 - * get payload3 from src payload1 - * get payload4 - * get payload5 from src payload4 - * release all - */ -TEST(MapPayloadPoolTest, get_payload_from_src) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - - Payload payload0; - Payload payload1; - Payload payload2; - Payload payload3; - Payload payload4; - Payload payload5; - - // get payload0 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE, payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload0), 1u); - - // get payload1 from src payload0 - ASSERT_TRUE(pool_->get_payload(payload0, pool, payload1)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload1), 2u); - ASSERT_EQ(payload1.max_size, payload0.max_size); - ASSERT_EQ(payload1.data, payload0.data); - - // get payload2 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload2)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload2), 3u); - ASSERT_EQ(payload2.max_size, payload0.max_size); - ASSERT_EQ(payload2.data, payload0.data); - - // release payload0 - ASSERT_TRUE(pool_->release_payload(payload0)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload2), 2u); - - // get payload3 from src payload1 - ASSERT_TRUE(pool_->get_payload(payload1, pool, payload3)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - ASSERT_EQ(pool_->reference_count(payload3), 3u); - ASSERT_EQ(payload3.max_size, payload1.max_size); - ASSERT_EQ(payload3.data, payload1.data); - - // get payload4 - ASSERT_TRUE(pool_->get_payload(DEFAULT_SIZE * 0x100, payload4)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - ASSERT_EQ(pool_->reference_count(payload1), 3u); - ASSERT_EQ(pool_->reference_count(payload4), 1u); - - // get payload5 from src payload4 - ASSERT_TRUE(pool_->get_payload(payload4, pool, payload5)); - ASSERT_EQ(pool_->pointers_stored(), 2u); - ASSERT_EQ(pool_->reference_count(payload1), 3u); - ASSERT_EQ(pool_->reference_count(payload5), 2u); - ASSERT_EQ(payload5.max_size, payload4.max_size); - ASSERT_EQ(payload5.data, payload4.data); - - // release all - ASSERT_TRUE(pool_->release_payload(payload1)); - ASSERT_TRUE(pool_->release_payload(payload2)); - ASSERT_TRUE(pool_->release_payload(payload3)); - ASSERT_TRUE(pool_->release_payload(payload4)); - ASSERT_TRUE(pool_->release_payload(payload5)); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check to get_payload from a source that has been created in a different pool - * - * STEPS: - * get payload aux from pool aux - * get payload from src payload aux - * release payload aux from pool aux - * release payload - */ -TEST(MapPayloadPoolTest, get_payload_from_src_no_owner) -{ - // Each pool has a IPayloadPool and a MockMapPayloadPool so it can be called to get_payload from source - // and specific methods from mock - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_aux_ = static_cast(pool_aux); - - Payload payload_src; - Payload payload_target; - - // get payload aux from pool aux - pool_aux_->get_payload(DEFAULT_SIZE, payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 1u); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // get payload from src payload aux - ASSERT_TRUE(pool_->get_payload(payload_src, pool_aux, payload_target)); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload aux from pool aux - pool_aux_->release_payload(payload_src); - ASSERT_EQ(pool_aux_->pointers_stored(), 0u); - ASSERT_EQ(pool_->pointers_stored(), 1u); - - // release payload - pool_->release_payload(payload_target); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool_aux; - delete pool; -} - -/** - * Check negative cases for get_payload from source - * - * CASES: - * The source says the owner is the same pool, but is not - * Source has size 0 and different owner - */ -TEST(MapPayloadPoolTest, get_payload_from_src_negative) -{ - // The source says the owner is the same pool, but is not - { - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - test::MockMapPayloadPool pool_aux; - - Payload payload_src; - Payload payload_target; - - // Get payload for source - pool_aux.get_payload(DEFAULT_SIZE, payload_src); - - // In a different pool, try to source it as if it was from same pool - ASSERT_THROW(pool_->get_payload(payload_src, pool, payload_target), eprosima::utils::InconsistencyException); - - // END : release payload - pool_aux.release_payload(payload_src); - - delete pool; - } - - // Source has size 0 and different owner - { - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - eprosima::fastrtps::rtps::IPayloadPool* pool_aux = nullptr; // nullptr - - Payload payload_src; - Payload payload_target; - - ASSERT_FALSE( - pool_->get_payload( - payload_src, - pool_aux, - payload_target)); - - delete pool; - } -} - -/** - * Get some payloads from pool from src and release each of them separatly checking reference count - * - * STEPS: - * get first payload - * get N-1 payloads from first - * release N-2 payloads - * get N-2 more payloads from first - * release N payloads - */ -TEST(MapPayloadPoolTest, release_payload) -{ - eprosima::fastrtps::rtps::IPayloadPool* pool = new test::MockMapPayloadPool(); // Requires to be ptr to pass it to get_payload - test::MockMapPayloadPool* pool_ = static_cast(pool); - std::vector payloads(TEST_NUMBER); - - // get first payload - pool_->get_payload(DEFAULT_SIZE, payloads[0]); - - // get N-1 payloads from first - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - ASSERT_EQ(pool_->reference_count(payloads[0]), i + 1) << i; - } - - // release N-2 payloads - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - ASSERT_EQ(pool_->reference_count(payloads[0]), TEST_NUMBER + 1 - i) << i; - } - - // get N-2 more payloads from first - for (unsigned int i = 2; i < TEST_NUMBER; i++) - { - pool_->get_payload(payloads[0], pool, payloads[i]); - ASSERT_EQ(pool_->reference_count(payloads[0]), i + 1) << i; - } - - // release N payloads - for (unsigned int i = 1; i < TEST_NUMBER; i++) - { - ASSERT_TRUE(pool_->release_payload(payloads[i])); - ASSERT_EQ(pool_->reference_count(payloads[0]), TEST_NUMBER - i) << i; - } - // Removing last payload because if not the reference count cannot be done - ASSERT_TRUE(pool_->release_payload(payloads[0])); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - // Check payload pool is empty - ASSERT_TRUE(pool_->is_clean()); - ASSERT_EQ(pool_->pointers_stored(), 0u); - - delete pool; -} - -/** - * Check release a payload that has been get from a different payload pool - */ -TEST(MapPayloadPoolTest, release_payload_negative) -{ - test::MockMapPayloadPool pool; - test::MockMapPayloadPool pool_aux; - Payload payload; - - pool_aux.get_payload(DEFAULT_SIZE, payload); - - ASSERT_THROW(pool.release_payload(payload), eprosima::utils::InconsistencyException); -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp b/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp deleted file mode 100644 index 92ce7a1c8..000000000 --- a/ddspipe_core/test/unittest/efficiency/PayloadPoolTest.cpp +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright 2022 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. - -#include -#include -#include - -#include -#include - -#include -#include -#include - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -// Using for gmock -using ::testing::_; -using ::testing::Invoke; -using ::testing::Return; - -namespace eprosima { -namespace fastrtps { -namespace rtps { - -/* - * WORKAROUND: - * This definition is needed due to googletest-distribution (1.11.0) requires to every class used inside ASSERT macro - * to have the operator << defined in SAME namespace than the class. - * In our case, Payload is defined as eprosima::fastrtps::rtps::SerializedPayload_t but redefined as - * eprosima::ddspipe::core::types::Payload and the operator << is defined in eprosima::ddspipe::core::types - * Thus, gtest could not find this definition (arising a very messy and cryptic compilation error). - * This definition corrects that problem. - * - * NOTE: - * In googletest-distribution release-1.10.0 this does not happen. - */ -void PrintTo( - const SerializedPayload_t, - std::ostream* os) -{ - *os << "::eprosima::fastrtps::rtps::SerializedPayload_t"; -} - -} /* namespace rtps */ -} /* namespace fastrtps */ -} /* namespace eprosima */ - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace test { - -/** - * @brief Mock over Payload Pool re-implementing the needed methods returning error and - * implementing public access to private variables. - * - */ -class MockPayloadPool : public PayloadPool -{ -public: - - // Using parent methods and variables as public - using PayloadPool::PayloadPool; - using PayloadPool::get_payload; - using PayloadPool::release_payload; - using PayloadPool::reserve_; - using PayloadPool::release_; - using PayloadPool::reserve_count_; - using PayloadPool::release_count_; - - // Mock this virtual methods not implemented in parent class - MOCK_METHOD( - bool, - get_payload, - (uint32_t size, eprosima::ddspipe::core::types::Payload& target_payload), - (override)); - - MOCK_METHOD( - bool, - get_payload, - ( - const Payload& src_payload, - eprosima::fastrtps::rtps::IPayloadPool*&data_owner, - eprosima::ddspipe::core::types::Payload& target_payload - ), - (override)); - - MOCK_METHOD( - bool, - release_payload, - (eprosima::ddspipe::core::types::Payload& target_payload), - (override)); -}; - -} /* namespace test */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/** - * Test reserve_ method - * - * CASES: - * small size - * large size - * 0 size - */ -TEST(PayloadPoolTest, reserve) -{ - // small size - { - test::MockPayloadPool pool; - Payload payload; - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - - ASSERT_TRUE(pool.reserve_(sizeof(PayloadUnit), payload)); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit)); - ASSERT_NE(payload.data, nullptr); - - // This would (maybe) fail with SEG FAULT if the data has not been correctly set - payload.data[0] = 16u; - } - - // large size - { - test::MockPayloadPool pool; - Payload payload; - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - - ASSERT_TRUE(pool.reserve_(sizeof(PayloadUnit) * 0x1000, payload)); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit) * 0x1000); - ASSERT_NE(payload.data, nullptr); - - // This would (maybe) fail with SEG FAULT if the data has not been correctly set - payload.data[0] = 4u; - payload.data[0x1000 - 1] = 5u; - } - - // 0 size - { - test::MockPayloadPool pool; - Payload payload; - - ASSERT_EQ(payload.max_size, 0u); - - ASSERT_FALSE(pool.reserve_(0, payload)); - - ASSERT_EQ(payload.max_size, 0u); - } -} - -/** - * Test release_ method - * - * CASES: - * small size - * large size - */ -TEST(PayloadPoolTest, release) -{ - // small size - { - test::MockPayloadPool pool; - Payload payload; - pool.reserve_(sizeof(PayloadUnit), payload); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit)); - ASSERT_NE(payload.data, nullptr); - - ASSERT_TRUE(pool.release_(payload)); - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - } - - // large size - { - test::MockPayloadPool pool; - Payload payload; - pool.reserve_(sizeof(PayloadUnit) * 0x1000, payload); - - ASSERT_EQ(payload.max_size, sizeof(PayloadUnit) * 0x1000); - ASSERT_NE(payload.data, nullptr); - - ASSERT_TRUE(pool.release_(payload)); - - ASSERT_EQ(payload.max_size, 0u); - ASSERT_EQ(payload.data, nullptr); - } -} - -/** - * Test release_ method - * - * STEPS: - * store 5 values - * release 4 values - * store 5 more values - * release 6 values - * release more values than reserved - */ -TEST(PayloadPoolTest, reserve_and_release_counter) -{ - test::MockPayloadPool pool; - std::vector payloads(11); - - // store 5 values - for (unsigned int i = 0; i < 5u; ++i) - { - ASSERT_EQ(pool.reserve_count_, i); - pool.reserve_(sizeof(PayloadUnit), payloads[i]); - } - ASSERT_EQ(pool.reserve_count_, 5u); - - // release 4 values - for (unsigned int i = 0; i < 4u; ++i) - { - ASSERT_EQ(pool.release_count_, i); - pool.release_(payloads[i]); - } - ASSERT_EQ(pool.release_count_, 4u); - - // store 5 values - for (unsigned int i = 5; i < 10u; ++i) - { - ASSERT_EQ(pool.reserve_count_, i); - pool.reserve_(sizeof(PayloadUnit), payloads[i]); - } - ASSERT_EQ(pool.reserve_count_, 10u); - - // release 6 values - for (unsigned int i = 4; i < 10u; ++i) - { - ASSERT_EQ(pool.release_count_, i); - pool.release_(payloads[i]); - } - ASSERT_EQ(pool.release_count_, 10u); - - // release more values than reserved - ASSERT_THROW(pool.release_(payloads[10]), eprosima::utils::InconsistencyException); -} - -/** - * Test clean method - * - * STEPS: - * start clean - * reserve and not clean - * release and clean - */ -TEST(PayloadPoolTest, is_clean) -{ - test::MockPayloadPool pool; - - // start clean - ASSERT_TRUE(pool.is_clean()); - - // reserve and not clean - eprosima::fastrtps::rtps::CacheChange_t cc; - pool.reserve_(sizeof(PayloadUnit), cc.serializedPayload); - ASSERT_FALSE(pool.is_clean()); - - // release and clean - pool.release_(cc.serializedPayload); - ASSERT_TRUE(pool.is_clean()); -} - -/** - * Test get_payload cache_change fails if the child class fails - * - * CASES: - * - get_payload for payload goes ok - * - get_payload for payload fails - */ -TEST(PayloadPoolTest, get_payload_cache_change) -{ - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - EXPECT_CALL(pool, get_payload(_, _)).Times(1).WillOnce(Return(true)); - - EXPECT_TRUE(pool.get_payload(sizeof(PayloadUnit), cc)); - - // Clean cache change correctly so process dont break - cc.payload_owner(nullptr); - } - - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - EXPECT_CALL(pool, get_payload(_, _)).Times(1).WillOnce(Return(false)); - - EXPECT_FALSE(pool.get_payload(sizeof(PayloadUnit), cc)); - } -} - -/** - * Test get_payload cache_change with source fails if the child class fails - * - * CASES: - * - get_payload for payload goes ok - * - get_payload for payload fails - */ -TEST(PayloadPoolTest, get_payload_from_src_cache_change) -{ - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t target; - Payload source; - eprosima::fastrtps::rtps::IPayloadPool* aux_pool; - - EXPECT_CALL(pool, get_payload(_, _, _)).Times(1).WillOnce(Return(true)); - - EXPECT_TRUE(pool.get_payload(source, aux_pool, target)); - - // Clean cache change correctly so process dont break - target.payload_owner(nullptr); - } - - // get_payload for payload goes ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t target; - Payload source; - eprosima::fastrtps::rtps::IPayloadPool* aux_pool; - - EXPECT_CALL(pool, get_payload(_, _, _)).Times(1).WillOnce(Return(false)); - - EXPECT_FALSE(pool.get_payload(source, aux_pool, target)); - } -} - -/** - * Test release_payload cache_change method using MockPayloadPool when inside get_payload method fails - * - * CASES: - * different ownership - * this ownership release ok - * this ownership release fail - */ -TEST(PayloadPoolTest, release_payload_cache_change) -{ - // different ownership - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - cc.payload_owner(nullptr); - - EXPECT_THROW(pool.release_payload(cc), eprosima::utils::InconsistencyException); - } - - // this ownership release ok - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - // ownership must be this pool - cc.payload_owner(&pool); - - EXPECT_CALL(pool, release_payload(_)).Times(1).WillOnce(Return(true)); - - EXPECT_TRUE(pool.release_payload(cc)); - } - - // this ownership release fail - { - test::MockPayloadPool pool; - eprosima::fastrtps::rtps::CacheChange_t cc; - - // ownership must be this pool - cc.payload_owner(&pool); - - EXPECT_CALL(pool, release_payload(_)).Times(1).WillOnce(Return(false)); - - EXPECT_FALSE(pool.release_payload(cc)); - - // Clean cache change correctly so process dont break - cc.payload_owner(nullptr); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/types/CMakeLists.txt b/ddspipe_core/test/unittest/types/CMakeLists.txt deleted file mode 100644 index 6fbb0b168..000000000 --- a/ddspipe_core/test/unittest/types/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -add_subdirectory(endpoint) -add_subdirectory(topic) diff --git a/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt b/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt deleted file mode 100644 index dfc2ce5fd..000000000 --- a/ddspipe_core/test/unittest/types/endpoint/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2021 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. - -######## -# GUID # -######## - -set(TEST_NAME GuidTest) - -set(TEST_SOURCES - GuidTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp - ) - -set(TEST_LIST - is_valid - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -############ -# Endpoint # -############ - -set(TEST_NAME EndpointTest) - -set(TEST_SOURCES - EndpointTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/testing/random_values.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/DomainId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Endpoint.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Guid.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/GuidPrefix.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/Payload.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/SpecificEndpointQoS.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/rpc/RpcTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ) - -set(TEST_LIST - topic_qos - is_reader_writer - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp b/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp deleted file mode 100644 index d2775ac53..000000000 --- a/ddspipe_core/test/unittest/types/endpoint/EndpointTest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; -using namespace eprosima::ddspipe::core::testing; - -namespace test -{ - -constexpr const unsigned int TEST_ITERATIONS = 100; - -} // test - - -/** - * Test \c Endpoint \c topic getter method - * - * CASES: - * Random Topics - */ -TEST(EndpointTest, topic_qos_getter) -{ - for (unsigned int i = 0; i < test::TEST_ITERATIONS; i++) - { - Endpoint endpoint = random_endpoint(i); - ASSERT_EQ(endpoint.topic.topic_qos, endpoint.topic_qos()); - } -} - -/** - * Test \c Endpoint \c is_writer getter method - * - * CASES: - * Writer - * Reader - */ -TEST(EndpointTest, is_reader_writer) -{ - // Default - { - Endpoint endpoint; - ASSERT_FALSE(endpoint.is_writer()); - ASSERT_FALSE(endpoint.is_reader()); - } - - // Writer - { - Endpoint endpoint; - endpoint.kind = EndpointKind::writer; - ASSERT_TRUE(endpoint.is_writer()); - ASSERT_FALSE(endpoint.is_reader()); - } - - // Reader - { - Endpoint endpoint; - endpoint.kind = EndpointKind::reader; - ASSERT_FALSE(endpoint.is_writer()); - ASSERT_TRUE(endpoint.is_reader()); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp b/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp deleted file mode 100644 index 09b91d5f8..000000000 --- a/ddspipe_core/test/unittest/types/endpoint/GuidTest.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -/** - * Test \c Guid \c is_valid method - * - * CASES: - * Default constructor invalid - * Unknown guid invalid - * GuidPrefix invalid - * EntityId invalid - * Constrcutor with valid value - */ -TEST(GuidTest, is_valid) -{ - // Default constructor invalid - { - Guid invalid_guid; - ASSERT_FALSE(invalid_guid.is_valid()); - } - - // Unknown guid invalid - { - Guid invalid_guid_1( - eprosima::fastrtps::rtps::GuidPrefix_t::unknown(), - eprosima::fastrtps::rtps::EntityId_t::unknown()); - ASSERT_FALSE(invalid_guid_1.is_valid()); - - Guid invalid_guid_2( - eprosima::fastrtps::rtps::GUID_t::unknown().guidPrefix, - eprosima::fastrtps::rtps::GUID_t::unknown().entityId); - ASSERT_FALSE(invalid_guid_2.is_valid()); - } - - // GuidPrefix invalid - { - Guid invalid_guid( - eprosima::fastrtps::rtps::GuidPrefix_t(), // Invalid GuidPrefix - eprosima::fastrtps::rtps::EntityId_t(1)); // Valid EntityId - ASSERT_FALSE(invalid_guid.is_valid()); - } - - // EntityId invalid - { - eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; - std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d.41") >> guid_prefix; - Guid valid_guid( - guid_prefix, // Valid GuidPrefix - eprosima::fastrtps::rtps::EntityId_t()); // Invalid EntityId - ASSERT_FALSE(valid_guid.is_valid()); - } - - // Constrcutor with valid value - { - eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix; - std::istringstream("44.53.00.5f.45.50.52.4f.53.49.4d.41") >> guid_prefix; - Guid valid_guid( - guid_prefix, // Valid GuidPrefix - eprosima::fastrtps::rtps::EntityId_t(1)); // Valid EntityId - ASSERT_TRUE(valid_guid.is_valid()); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/types/topic/CMakeLists.txt b/ddspipe_core/test/unittest/types/topic/CMakeLists.txt deleted file mode 100644 index 863b02ece..000000000 --- a/ddspipe_core/test/unittest/types/topic/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2021 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. - -############# -# DdsTopic # -############# - -set(TEST_NAME DdsTopicTest) - -set(TEST_SOURCES - DdsTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ) - -set(TEST_LIST - is_valid_dds_topic - is_valid_dds_topic_negative - ) - -set(TEST_EXTRA_LIBRARIES - fastcdr - fastrtps - cpp_utils - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) - -################# -# WildcardDdsFilterTopic # -################# - -set(TEST_NAME WildcardDdsFilterTopic) - -set(TEST_SOURCES - WildcardDdsFilterTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/dds/DdsTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/Topic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/IFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/topic/filter/WildcardDdsFilterTopic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/types/dds/TopicQoS.cpp - ) - -set(TEST_LIST - matches - non_matches - - # Not supported (TODO) - # non_contains_wildcard - # contains_wildcard - ) - -set(TEST_EXTRA_LIBRARIES - $<$:iphlpapi$Shlwapi> - fastcdr - fastrtps - cpp_utils - - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}" - ) diff --git a/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp b/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp deleted file mode 100644 index 01ae798e3..000000000 --- a/ddspipe_core/test/unittest/types/topic/DdsTopicTest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include - -using namespace eprosima::ddspipe::core::types; - -using pair_topic_type = std::pair; - -/** - * Test DdsTopic is_valid_dds_topic method for positive cases - */ -TEST(DdsTopicTest, is_valid_dds_topic) -{ - std::vector topics = { - {"topic1", "type1"}, - {"topic1", "type2"}, - {"topic2", "type1"}, - - {"rt/chatter", "std::std_msg::string"}, - - {"HelloWorldTopic", "HelloWorld"}, - }; - - eprosima::utils::Formatter __f; - - for (pair_topic_type topic : topics) - { - ASSERT_TRUE(DdsTopic::is_valid_dds_topic(topic.first, topic.second, __f)); - } -} - -/** - * Test DdsTopic is_valid_dds_topic method for negative cases - */ -TEST(DdsTopicTest, is_valid_dds_topic_negative) -{ - std::vector topics = { - {"topic", "type*"}, - {"topic*", "type"}, - {"topic*", "type*"}, - - {"topic", "*type"}, - {"*topic", "type"}, - {"*topic", "*type"}, - - {"topic", "*type*"}, - {"*topic*", "type"}, - {"*topic*", "*type*"}, - - {"topic", "ty*pe"}, - {"top*ic", "type"}, - {"top*ic", "ty*pe"}, - - {"*", "type"}, - {"topic", "*"}, - {"*", "*"}, - - {"topic", ""}, - {"", "type"}, - {"", ""}, - // TODO add regex cases - }; - - eprosima::utils::Formatter __f; - - for (pair_topic_type topic : topics) - { - ASSERT_FALSE(DdsTopic::is_valid_dds_topic(topic.first, topic.second, __f)) - << topic.first << " " << topic.second; - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp b/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp deleted file mode 100644 index f914552b9..000000000 --- a/ddspipe_core/test/unittest/types/topic/WildcardDdsFilterTopicTest.cpp +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -using namespace eprosima::ddspipe::core; -using namespace eprosima::ddspipe::core::types; - -using pair_topic_type = std::pair; - -/** - * Test WildcardDdsFilterTopic contains method for positive cases - */ -TEST(WildcardDdsFilterTopic, contains_wildcard) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic", "type"}, {"topic", "type*"}, {"topic", "*type"}, {"topic", "type1*"}}}, - - {{"topic", "type*"}, - {{"topic", "type"}, {"topic", "type1"}, {"topic", "type1*"}}}, - - {{"*", "type"}, - {{"topic", "type"}, {"*topic", "type"}, {"topic*", "type"}, {"*rt/topic", "type"}}}, - - {{"*topic", "type"}, - {{"topic", "type"}, {"std_topic", "type"}, {"*rt/topic", "type"}}}, - - {{"topic*", "type*"}, - {{"topic", "type"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a FilterDdsTopic and test - for (auto real_topic_names : test_case.second) - { - WildcardDdsFilterTopic contained_topic; - contained_topic.topic_name = real_topic_names.first; - contained_topic.type_name = real_topic_names.second; - - ASSERT_TRUE(wt.contains(contained_topic)); - } - } -} - -/** - * Test WildcardDdsFilterTopic matches method for positive cases - */ -TEST(WildcardDdsFilterTopic, matches) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic", "type"}, {"topic", "type1"}, {"topic", "type2"}}}, - - {{"topic", "type*"}, - {{"topic", "type"}, {"topic", "type1"}, {"topic", "type2"}}}, - - {{"*", "type"}, - {{"topic", "type"}, {"std_topic", "type"}, {"rt/topic", "type"}}}, - - {{"*topic", "type"}, - {{"topic", "type"}, {"std_topic", "type"}, {"rt/topic", "type"}}}, - - {{"topic", "type"}, - {{"topic", "type"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a DdsTopic and test - for (auto real_topic_names : test_case.second) - { - DdsTopic real_topic; - real_topic.m_topic_name = real_topic_names.first; - real_topic.type_name = real_topic_names.second; - - ASSERT_TRUE(wt.matches(real_topic)) << "wildcard: " << wt << " ; real: " << real_topic; - } - } -} - -/** - * Test WildcardDdsFilterTopic contains method for negative cases - */ -TEST(WildcardDdsFilterTopic, non_contains_wildcard) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic1", "type"}, {"topic*", "type"}, {"*", "type"}, {"*topic", "*"}, {"*", "*"}}}, - - {{"topic", "type*"}, - {{"topic*", "type"}, {"topic", "*type"}, {"*", "*"}}}, - - {{"*", "type"}, - {{"topic", "type1"}, {"topic", "type*"}, {"topic*", "*"}, {"*", "type*"}, {"*", "*"}}}, - - {{"*topic", "type"}, - {{"topic", "type*"}, {"topic*", "type"}, {"*", "*"}}}, - - {{"topic*", "type*"}, - {{"*topic", "type"}, {"topic", "*type"}, {"*", "*"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a DdsTopic and test - for (auto real_topic_names : test_case.second) - { - WildcardDdsFilterTopic contained_topic; - contained_topic.topic_name = real_topic_names.first; - contained_topic.type_name = real_topic_names.second; - - ASSERT_FALSE(wt.contains(contained_topic)); - } - } -} - -/** - * Test WildcardDdsFilterTopic matches method for negative cases - */ -TEST(WildcardDdsFilterTopic, non_matches) -{ - std::vector< // Test cases - std::pair< - pair_topic_type, // Wildcard Topic - std::vector // List of accepted DdsTopics - >> test_cases = { - - {{"topic", "*"}, - {{"topic1", "type"}, {"topic1", "type1"}, {"std_topic", "type1"}}}, - - {{"topic", "type*"}, - {{"topic1", "type"}, {"topic", "std::type"}, {"topic", "std::type1"}}}, - - {{"*", "type"}, - {{"topic", "type1"}, {"std_topic", "type1"}, {"topic", "std::type"}}}, - - {{"*topic", "type"}, - {{"topic", "type1"}, {"std_topic1", "type"}, {"rt/topic1", "type"}}}, - - {{"topic", "type"}, - {{"topic", "type1"}, {"topic1", "type"}, {"topic1", "type1"}, {"std_topic", "type"}}}, - }; - - for (auto test_case : test_cases) - { - // Create Wildcard topic - WildcardDdsFilterTopic wt; - wt.topic_name = test_case.first.first; - wt.type_name = test_case.first.second; - - // For every topic to test, create a DdsTopic and test - for (auto real_topic_names : test_case.second) - { - DdsTopic real_topic; - real_topic.m_topic_name = real_topic_names.first; - real_topic.type_name = real_topic_names.second; - - ASSERT_FALSE(wt.matches(real_topic)); - } - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_participants/CMakeLists.txt b/ddspipe_participants/CMakeLists.txt deleted file mode 100644 index 644d5c7d4..000000000 --- a/ddspipe_participants/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2022 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. - -############################################################################### -# CMake build rules for DDS Router Submodule -############################################################################### -cmake_minimum_required(VERSION 3.5) - -############################################################################### -# Find package cmake_utils -############################################################################### -# Package cmake_utils is required to get every cmake macro needed -find_package(cmake_utils REQUIRED) - -############################################################################### -# Project -############################################################################### -# Configure project by info set in project_settings.cmake -# - Load project_settings variables -# - Read version -# - Set installation paths -configure_project() - -# Call explictly project -project( - ${MODULE_NAME} - VERSION - ${MODULE_VERSION} - DESCRIPTION - ${MODULE_DESCRIPTION} - LANGUAGES - CXX -) - -############################################################################### -# C++ Project -############################################################################### -# Configure CPP project for dependencies and required flags: -# - Set CMake Build Type -# - Set C++ version -# - Set shared libraries by default -# - Find external packages and thirdparties -# - Activate Code coverage if flag CODE_COVERAGE -# - Activate Address sanitizer build if flag ASAN_BUILD -# - Activate Thread sanitizer build if flag TSAN_BUILD -# - Configure log depending on LOG_INFO flag and CMake type -configure_project_cpp() - -# Compile C++ library -compile_library( - "${PROJECT_SOURCE_DIR}/src/cpp" # Source directory - "${PROJECT_SOURCE_DIR}/include" # Include directory -) - -############################################################################### -# Test -############################################################################### -# Compile tests if CMake options requires it -compile_test_library( - "${PROJECT_SOURCE_DIR}/test" # Test directory -) - -############################################################################### -# Packaging -############################################################################### -# Install package -eprosima_packaging() diff --git a/ddspipe_participants/README.md b/ddspipe_participants/README.md deleted file mode 100644 index 5599ab6cf..000000000 --- a/ddspipe_participants/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# eProsima DDS Router Core Library - -This library contain main functionality of the DDS Router. -Include module is the public API used to configure a DDS Router and to interact with a running one: - -* **Types**: data types used to configure a router. - * Address - * DDS info (Guid, Qos, Topic, etc.) - -* **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: - * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. - * *DDSRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. - * *DDSRouterReloadConfiguration*: configuration to change topics in a running DDS Router. - -* **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. - It allows to execute a DDS Router, and to interact with it while running. - ---- - -## Example of usage - -```cpp -// START AND STOP DDS ROUTER FROM CONFIGURATION - -core::DDSRouterConfiguration router_configuration; - -// ... populate router_configuration - -core::DDSRouter router(router_configuration); -router.start(); - -// ... wait for event - -router.stop(); -``` - ---- - -## Dependencies - -* `fastrtps` -* `cpp_utils` - ---- - -## How to use it in your project - -Just import library `ddsrouter_core` into your CMake project. - -```cmake -find_package(ddsrouter_core) -target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_core) -``` diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp deleted file mode 100644 index 50bdc37b8..000000000 --- a/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * This class joins Discovery Server Participant Configuration features and gives methods to interact with it. - */ -struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI DiscoveryServerParticipantConfiguration() = default; - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - core::types::GuidPrefix discovery_server_guid_prefix {}; - - std::set listening_addresses {}; - - std::set connection_addresses {}; - - types::TlsConfiguration tls_configuration {}; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp deleted file mode 100644 index 0d4884924..000000000 --- a/ddspipe_participants/include/ddspipe_participants/configuration/EchoParticipantConfiguration.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -struct EchoParticipantConfiguration : public ParticipantConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - DDSPIPE_PARTICIPANTS_DllAPI EchoParticipantConfiguration() = default; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - //! Whether this Participant should echo the data received - bool echo_data = false; - //! Whether this Participant should echo the discovery information - bool echo_discovery = true; - //! Whether this Participant should echo verbose information - bool verbose = false; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp deleted file mode 100644 index 8ed01d21a..000000000 --- a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * This data struct joins Initial Peers Participant Configuration features - */ -struct InitialPeersParticipantConfiguration : public SimpleParticipantConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI InitialPeersParticipantConfiguration() = default; - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - std::set listening_addresses {}; - - std::set connection_addresses {}; - - types::TlsConfiguration tls_configuration {}; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp deleted file mode 100644 index 1469db09e..000000000 --- a/ddspipe_participants/include/ddspipe_participants/configuration/ParticipantConfiguration.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -struct ParticipantConfiguration : public core::IConfiguration -{ - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI ParticipantConfiguration() = default; - - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - //! Participant Id associated with this configuration - core::types::ParticipantId id {}; - - //! Whether this Participant should connect its readers with its writers. - bool is_repeater {false}; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp deleted file mode 100644 index 31a00e2b0..000000000 --- a/ddspipe_participants/include/ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * This data struct represents a configuration for a SimpleParticipant - */ -struct SimpleParticipantConfiguration : public ParticipantConfiguration -{ -public: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - DDSPIPE_PARTICIPANTS_DllAPI SimpleParticipantConfiguration() = default; - - ///////////////////////// - // METHODS - ///////////////////////// - - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - ///////////////////////// - // VARIABLES - ///////////////////////// - - core::types::DomainId domain {0u}; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp b/ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp deleted file mode 100644 index 88b62477e..000000000 --- a/ddspipe_participants/include/ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -/** - * @brief This class implements a pool of CacheChange objects specialized as RouterCacheChanges. - * - * It reuses the UnboundedPool implementation, what allow to create an unbounded reusable pool. - * - * TODO: implement this class as an IPool (or having an internal pool), without being force to be unbounded. - */ -class CacheChangePool : public fastrtps::rtps::IChangePool, public utils::UnboundedPool -{ -public: - - /** - * @brief Construct a new Cache Change Pool object from a Pool Configuration - * - * @param configuration pool configuration - * - * @warning max size will not be used as it is Unbounded - */ - CacheChangePool( - utils::PoolConfiguration configuration); - - //! Call UnboundedPool::reserve - virtual bool reserve_cache( - fastrtps::rtps::CacheChange_t*& cache_change) override; - - //! Call UnboundedPool::release - virtual bool release_cache( - fastrtps::rtps::CacheChange_t* cache_change) override; - -protected: - - //! Override the UnboundedPool::create_element method to create a RouterCacheChange object. - virtual fastrtps::rtps::CacheChange_t* new_element_() override; - -}; - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp deleted file mode 100644 index 84fa9cbba..000000000 --- a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/BlankParticipant.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Participant that has an empty implementation. - * It does not discover anything. - * - * Writer: BlankWriter - * Reader: BlankReader - */ -class BlankParticipant : public core::IParticipant -{ -public: - - //! Constructor with Id of this participant - DDSPIPE_PARTICIPANTS_DllAPI BlankParticipant( - const core::types::ParticipantId& id_); - - //! Override id() IParticipant method - DDSPIPE_PARTICIPANTS_DllAPI core::types::ParticipantId id() const noexcept override; - - //! Override is_repeater() IParticipant method - DDSPIPE_PARTICIPANTS_DllAPI bool is_repeater() const noexcept override; - - //! Override is_rtps_kind() IParticipant method - DDSPIPE_PARTICIPANTS_DllAPI bool is_rtps_kind() const noexcept override; - - //! Override create_writer() IParticipant method - DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( - const core::ITopic& topic) override; - - //! Override create_reader() IParticipant method - DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_reader( - const core::ITopic& topic) override; - -protected: - - //! Participant Id - core::types::ParticipantId id_; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp deleted file mode 100644 index c4b183aef..000000000 --- a/ddspipe_participants/include/ddspipe_participants/participant/auxiliar/EchoParticipant.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Concrete Participant that prints in stdout each message that arrives. - */ -class EchoParticipant : public BlankParticipant -{ -public: - - //! Using parent class constructors - DDSPIPE_PARTICIPANTS_DllAPI EchoParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& discovery_database); - - //! Print discovery information from endpoint discovered - DDSPIPE_PARTICIPANTS_DllAPI void echo_discovery( - core::types::Endpoint endpoint_discovered) const noexcept; - - //! Override create_writer() IParticipant method - DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( - const core::ITopic& topic) override; - -protected: - - // Deleters do not need to be implemented - - //! Reference to alias access of this object configuration without casting every time - const std::shared_ptr configuration_; - - //! DDS Router shared Discovery Database - const std::shared_ptr discovery_database_; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp deleted file mode 100644 index ca182542f..000000000 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Abstract generic class for a RTPS Participant wrapper. - * - * Concrete classes that inherit from this would only need to specialize specific methods related with the - * qos and attributes. - * - * @warning This object is not RAII and must be initialized before used. - */ -class CommonParticipant - : public core::IParticipant - , public fastrtps::rtps::RTPSParticipantListener -{ -public: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - // Protected ctor to make class abstract (only built by their childs). - - //! Remove internal RTPS Participant - DDSPIPE_PARTICIPANTS_DllAPI virtual ~CommonParticipant(); - - /** - * @brief Create the internal RTPS Participant using the attributes given. - * - * @attention this method should be called right after constructor to create enable internal entities. - * This is required as this object is a Listener that could be called before finishing construction. - * Other alternatives have been studied but none have really fit for this case. - * - * @throw InitializationException if RTPS Participant creation fails - * - * @warning this method is not thread safe. - * @pre this method can only be called once. - */ - DDSPIPE_PARTICIPANTS_DllAPI void init(); - - ///////////////////////// - // I PARTICIPANT METHODS - ///////////////////////// - - //! Implement parent method \c is_repeater . - DDSPIPE_PARTICIPANTS_DllAPI bool is_repeater() const noexcept override; - - //! Implement parent method \c id . - DDSPIPE_PARTICIPANTS_DllAPI core::types::ParticipantId id() const noexcept override; - - //! Implement parent method \c is_rtps_kind . - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_rtps_kind() const noexcept override; - - /** - * @brief Create a writer object - * - * Depending on the Topic QoS creates a Basic or Specific Writer. - */ - DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( - const core::ITopic& topic) override; - - /** - * @brief Create a reader object - * - * Depending on the Topic QoS creates a Basic or Specific Reader. - */ - DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_reader( - const core::ITopic& topic) override; - - ///////////////////////// - // RTPS LISTENER METHODS - ///////////////////////// - - /** - * @brief Override method from \c RTPSParticipantListener . - * - * This method only is for debugging purposes. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual void onParticipantDiscovery( - fastrtps::rtps::RTPSParticipant* participant, - fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; - - /** - * @brief Override method from \c RTPSParticipantListener . - * - * This method adds to database the endpoint discovered or modified. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual void onReaderDiscovery( - fastrtps::rtps::RTPSParticipant* participant, - fastrtps::rtps::ReaderDiscoveryInfo&& info) override; - - /** - * @brief Override method from \c RTPSParticipantListener . - * - * This method adds to database the endpoint discovered or modified. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual void onWriterDiscovery( - fastrtps::rtps::RTPSParticipant* participant, - fastrtps::rtps::WriterDiscoveryInfo&& info) override; - -protected: - - /** - * @brief Construct a CommonParticipant - * - * @note This is meant to be called from child classes. - */ - CommonParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database, - const core::types::DomainId& domain_id, - const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); - - /** - * @brief Auxiliary method to create the internal RTPS participant. - */ - void create_participant_( - const core::types::DomainId& domain, - const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes); - - /** - * @brief Create a endpoint from info object - * - * Specialized for \c WriterDiscoveryInfo and \c ReaderDiscoveryInfo . - */ - template - core::types::Endpoint create_endpoint_from_info_( - DiscoveryInfoKind& info); - - //! Create a endpoint from common info from method \c create_endpoint_from_info_ . - template - core::types::Endpoint create_common_endpoint_from_info_( - DiscoveryInfoKind& info); - - ///// - // RTPS specific methods - - /** - * @brief Static method that gives the std attributes for a Participant. - * - * @note This method must be specialized from inherit classes. - */ - static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const ParticipantConfiguration* participant_configuration); - - ///// - // VARIABLES - - //! Participant configuration - const std::shared_ptr configuration_; - - //! DDS Router shared Payload Pool - const std::shared_ptr payload_pool_; - - //! DDS Router shared Discovery Database - const std::shared_ptr discovery_database_; - - //! Internal RTPS Participant - eprosima::fastrtps::rtps::RTPSParticipant* rtps_participant_; - - //! Domain Id to create the internal RTPS Participant. - core::types::DomainId domain_id_; - - //! Participant attributes to create the internal RTPS Participant. - fastrtps::rtps::RTPSParticipantAttributes participant_attributes_; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp deleted file mode 100644 index 87d2fd83a..000000000 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * TODO - */ -class DiscoveryServerParticipant - : public CommonParticipant -{ -public: - - DDSPIPE_PARTICIPANTS_DllAPI DiscoveryServerParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database); - -protected: - - static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const DiscoveryServerParticipantConfiguration* participant_configuration); - -}; - -} /* namespace rpts */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp deleted file mode 100644 index c195a5fc5..000000000 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * TODO - */ -class InitialPeersParticipant - : public CommonParticipant -{ -public: - - DDSPIPE_PARTICIPANTS_DllAPI InitialPeersParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database); - -protected: - - static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const InitialPeersParticipantConfiguration* configuration); - -}; - -} /* namespace rpts */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp deleted file mode 100644 index 05bee417d..000000000 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Participant with Simple Discovery Protocol. - * - * Standard RTPS Participant with Simple Discovery and default attributes. - */ -class SimpleParticipant : public CommonParticipant -{ -public: - - /** - * @brief Construct a new Dummy Participant object - * - * It uses the \c BaseParticipant constructor. - * Apart from BaseParticipant, it creates a new RTPSParticipant with default Attributes and domain given - * by configuration. - * - * @throw \c InitializationException in case any internal error has ocurred while creating RTPSParticipant - * @throw \c IConfigurationException in case configuration was incorrectly set - */ - DDSPIPE_PARTICIPANTS_DllAPI SimpleParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database); -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp deleted file mode 100644 index 8142cb45e..000000000 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BaseReader.hpp +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Abstract Reader that implements generic methods for every Reader. - * - * In order to inherit from this class, create the protected method take_ . - * Implement methods enabled_ and disabled_ in order to give specific functionality to these methods. - * - * @todo make topic somehow to can hold it. - */ -class BaseReader : public core::IReader -{ -public: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - // TODO Implement a way that if messages arrive when not enabled, when enable again call on_data_available - - // Protected ctor to make class abstract (only built by their childs). - - ///////////////////////// - // I READER METHODS - ///////////////////////// - - /** - * @brief Set this Reader as enabled - * - * It changes the \c enabled_ variable. - * Call protected method \c enable_() for a specific enable functionality. - * - * Override enable() IReader method - * - * Thread safe with mutex \c mutex_ . - */ - DDSPIPE_PARTICIPANTS_DllAPI void enable() noexcept override; - - /** - * @brief Set this Reader as disabled - * - * It changes the \c enabled_ variable. - * Call protected method \c disable_() for a specific disable functionality. - * - * Override disable() IReader method - * - * Thread safe with mutex \c mutex_ . - */ - DDSPIPE_PARTICIPANTS_DllAPI void disable() noexcept override; - - /** - * @brief Set the on_data_available callback - * - * Override set_on_data_available_callback() IReader method - * - * Thread safe with mutex \c mutex_ . - * - * @param [in] on_data_available_lambda new callback to notify data received - */ - DDSPIPE_PARTICIPANTS_DllAPI void set_on_data_available_callback( - std::function on_data_available_lambda) noexcept override; - - /** - * @brief Unset the on_data_available callback - * - * Override unset_on_data_available_callback() IReader method - * - * Thread safe with mutex \c mutex_ . - * - * @param [in] on_data_available_lambda new callback to notify data received - */ - DDSPIPE_PARTICIPANTS_DllAPI void unset_on_data_available_callback() noexcept override; - - /** - * @brief Override take() IReader method - * - * This method calls the protected method \c take_ to make the actual take function. - * It only manages the enable/disable status. - * - * Thread safe with mutex \c mutex_ . - */ - DDSPIPE_PARTICIPANTS_DllAPI utils::ReturnCode take( - std::unique_ptr& data) noexcept override; - - ///////////////////////// - // AUXILIARY METHODS - ///////////////////////// - - //! Getter of \c participant_id_ attribute - DDSPIPE_PARTICIPANTS_DllAPI core::types::ParticipantId participant_id() const noexcept override; - - ///////////////////////// - // RPC REQUIRED METHODS - ///////////////////////// - // TODO remove these methods once the double reference is solved - - //! Get GUID of internal RTPS reader - DDSPIPE_PARTICIPANTS_DllAPI core::types::Guid guid() const override = 0; - - //! Get internal RTPS reader mutex - DDSPIPE_PARTICIPANTS_DllAPI fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override = 0; - - //! Get number of unread cache changes in internal RTPS reader - DDSPIPE_PARTICIPANTS_DllAPI uint64_t get_unread_count() const override = 0; - - DDSPIPE_PARTICIPANTS_DllAPI core::types::DdsTopic topic() const override = 0; - ///////////////////////// - -protected: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - /** - * @brief Construct a new Base Reader object - * - * @param participant_id parent participant id - * @param topic topic that this Reader will refer to - * @param payload_pool DDS Router shared PayloadPool - */ - BaseReader( - const core::types::ParticipantId& participant_id, - const std::shared_ptr& payload_pool); - - ///////////////////////// - // PROTECTED METHODS - ///////////////////////// - - /** - * @brief Call from inherit objects whenever there are available data to read - * - * It calls the \c on_data_available_lambda_ - * - * Thread safe with mutex \c mutex_ . - */ - void on_data_available_() const noexcept; - - ///////////////////////// - // METHODS TO IMPLEMENT BY SUBCLASSES - ///////////////////////// - - /** - * @brief Do nothing - * - * Implement this method class for a specific enable functionality. - */ - virtual void enable_nts_() noexcept; - - /** - * @brief Do nothing - * - * Implement this method class for a specific disable functionality. - */ - virtual void disable_nts_() noexcept; - - /** - * @brief Take method to implement by each Reader implementation - * - * Implement this method in every inherited Reader class with take functionality. - */ - virtual utils::ReturnCode take_nts_( - std::unique_ptr& data) noexcept = 0; - - ///////////////////////// - // INTERNAL VARIABLES - ///////////////////////// - - //! Participant parent ID - const core::types::ParticipantId participant_id_; - - //! DDS Router shared Payload Pool - const std::shared_ptr payload_pool_; - - //! Lambda to call the callback whenever a new data arrives - std::function on_data_available_lambda_; - - //! True if lambda callback is set - bool on_data_available_lambda_set_; - - //! Whether the Reader is currently enabled - std::atomic enabled_; - - //! Mutex that guards every access to the Reader - mutable std::recursive_mutex mutex_; - - //! Default callback. It shows a warning that callback is not set - static const std::function DEFAULT_ON_DATA_AVAILABLE_CALLBACK; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const BaseReader&); -}; - -/** - * @brief \c BaseReader to stream serialization - * - * This method is merely a to_string of a BaseReader definition. - * It serialize the ParticipantId and topic - */ -std::ostream& operator <<( - std::ostream& os, - const BaseReader& reader); - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp deleted file mode 100644 index f3a66ebcf..000000000 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/BlankReader.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Reader that has an empty implementation. - * It does not receive anything. - * It does not have messages to take. - */ -DDSPIPE_PARTICIPANTS_DllAPI class BlankReader : public core::IReader -{ -public: - - //! Override enable() IReader method - void enable() noexcept override; - - //! Override disable() IReader method - void disable() noexcept override; - - //! Override set_on_data_available_callback() IReader method - void set_on_data_available_callback( - std::function on_data_available_lambda) noexcept override; - - //! Override unset_on_data_available_callback() IReader method - void unset_on_data_available_callback() noexcept override; - - //! Override take() IReader method - utils::ReturnCode take( - std::unique_ptr& data) noexcept override; - - ///////////////////////// - // RPC REQUIRED METHODS - ///////////////////////// - // TODO remove these methods once the double reference is solved - - //! Get GUID of internal RTPS reader - core::types::Guid guid() const override; - - //! Get internal RTPS reader mutex - fastrtps::RecursiveTimedMutex& get_rtps_mutex() const override; - - //! Get number of unread cache changes in internal RTPS reader - uint64_t get_unread_count() const override; - - core::types::DdsTopic topic() const override; - - core::types::ParticipantId participant_id() const override; - ///////////////////////// -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp deleted file mode 100644 index 16a3bd98f..000000000 --- a/ddspipe_participants/include/ddspipe_participants/reader/rpc/SimpleReader.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rpc { - -/** - * Base RTPS Reader concrete class that implements abstract CommonReader one. - */ -class SimpleReader : public rtps::CommonReader -{ -public: - - /** - * @brief Construct a new SimpleReader object - * - * Get the Attributes and TopicQoS and create the SimpleReader History and the RTPS SimpleReader. - * - * @param participant_id Router Id of the Participant that has created this SimpleReader. - * @param topic Topic that this SimpleReader subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI SimpleReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant); - - //! Override Parent method to create an RPC data type. - DDSPIPE_PARTICIPANTS_DllAPI virtual core::types::RtpsPayloadData* create_data_( - const fastrtps::rtps::CacheChange_t& received_change) const noexcept override; - - //! Override Parent method to fill fields exclusive from RPC. - DDSPIPE_PARTICIPANTS_DllAPI virtual void fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change, - core::types::RtpsPayloadData& data_to_fill) const noexcept override; -}; - -} /* namespace rpc */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp deleted file mode 100644 index 32f8b9ac6..000000000 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/CommonReader.hpp +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Abstract generic class for a RTPS Reader wrapper. - * - * It implements the ReaderListener for itself with \c onNewCacheChangeAdded and \c onReaderMatched callbacks. - * - * @warning This object is not RAII and must be initialized before used. - */ -class CommonReader : public BaseReader, public fastrtps::rtps::ReaderListener -{ -public: - - ///////////////////////// - // CONSTRUCTOR - ///////////////////////// - - // Protected ctor to make class abstract (only built by their childs). - - /** - * @brief Destroy the CommonReader object - * - * Delete the RTPS CommonReader and CommonReader History in case they are set. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual ~CommonReader(); - - /** - * @brief Create the internal RTPS Reader. - * - * @attention this method should be called right after constructor to create enable internal entities. - * This is required as this object is a Listener that could be called before finishing construction. - * Other alternatives have been studied but none have really fit for this case. - * - * @throw InitializationException if RTPS Reader creation fails - * - * @warning this method is not thread safe. - * @pre this method can only be called once. - */ - DDSPIPE_PARTICIPANTS_DllAPI void init(); - - ///////////////////////// - // RTPS LISTENER METHODS - ///////////////////////// - - /** - * @brief CommonReader Listener callback when a new data is added to History - * - * This method is call every time a new CacheChange is received by this CommonReader. - * Filter this same Participant messages. - * Call the on_data_available_ callback (method \c on_data_available_ from \c BaseReader ). - * - * @param [in] change new change received - */ - DDSPIPE_PARTICIPANTS_DllAPI void onNewCacheChangeAdded( - fastrtps::rtps::RTPSReader*, - const fastrtps::rtps::CacheChange_t* const change) noexcept override; - - /** - * @brief CommonReader Listener callback when a new Writer is matched or unmatched - * - * This method is call every time a new Writer is matched or unmatched from this CommonReader. - * It only creates a log for matching and unmatching (in case it is not a writer from this same Participant) - * - * @param [in] info information about the matched Writer - */ - DDSPIPE_PARTICIPANTS_DllAPI void onReaderMatched( - fastrtps::rtps::RTPSReader*, - fastrtps::rtps::MatchingInfo& info) noexcept override; - - ///////////////////////// - // RPC REQUIRED METHODS - ///////////////////////// - // TODO remove these methods once the double reference is solved - - //! Get GUID of internal RTPS reader - DDSPIPE_PARTICIPANTS_DllAPI core::types::Guid guid() const noexcept override; - - //! Get internal RTPS reader mutex - DDSPIPE_PARTICIPANTS_DllAPI fastrtps::RecursiveTimedMutex& get_rtps_mutex() const noexcept override; - - //! Get number of unread cache changes in internal RTPS reader - DDSPIPE_PARTICIPANTS_DllAPI uint64_t get_unread_count() const noexcept override; - - DDSPIPE_PARTICIPANTS_DllAPI core::types::DdsTopic topic() const noexcept override; - -protected: - - /** - * @brief Construct a new CommonReader object - * - * It receives all the attributes and QoS needed to create the internal entities. - * - * @note Only protected so only concrete classes are instantiated. - * - * @throw \c InitializationException in case any creation has failed - */ - CommonReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::ReaderAttributes& reader_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::ReaderQos& reader_qos); - - // Specific enable/disable do not need to be implemented - - /** - * @brief Auxiliary method to create the internal RTPS Reader and History. - */ - virtual void internal_entities_creation_( - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::ReaderAttributes& reader_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::ReaderQos& reader_qos); - - /** - * @brief Return an allocated object - * - * @attention this method allocates memory. - */ - virtual core::types::RtpsPayloadData* create_data_( - const fastrtps::rtps::CacheChange_t& received_change) const noexcept; - - /** - * @brief Auxiliary method used in \c take to fill the received data. - */ - virtual void fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change, - core::types::RtpsPayloadData& data_to_fill) const noexcept; - - // Specific enable/disable do not need to be implemented - - /** - * @brief Enable specific method for RTPS reader - * - * Check if there is data available to read - */ - void enable_() noexcept; - - /** - * @brief Take specific method - * - * Check if there are messages to take. - * Take next Untaken Change. - * Set \c data with the message taken (data payload must be stored from PayloadPool). - * Remove this change from CommonReader History and release. - * - * @note guard by mutex \c rtps_mutex_ - * - * @param data : oldest data to take - * @return \c RETCODE_OK if data has been correctly taken - * @return \c RETCODE_NO_DATA if there is no data to send - * @return \c RETCODE_ERROR if there has been an error reading the data or the data read is corrupted - */ - virtual utils::ReturnCode take_nts_( - std::unique_ptr& data) noexcept override; - - ///// - // RTPS specific methods - - /** - * @brief Default History Attributes to create CommonReader History - * - * @return Default HistoryAttributes - */ - static fastrtps::rtps::HistoryAttributes reckon_history_attributes_( - const core::types::DdsTopic& topic) noexcept; - - /** - * @brief Reader Attributes to create RTPS Reader - */ - static fastrtps::rtps::ReaderAttributes reckon_reader_attributes_( - const core::types::DdsTopic& topic) noexcept; - - //! Topic Attributes to create RTPS Reader - static fastrtps::TopicAttributes reckon_topic_attributes_( - const core::types::DdsTopic& topic) noexcept; - - //! Reader QoS to create RTPS Reader - static fastrtps::ReaderQos reckon_reader_qos_( - const core::types::DdsTopic& topic) noexcept; - - ///// - // CommonReader specific methods - - //! Whether a change received is from this Participant (to avoid auto-feedback) - bool come_from_this_participant_( - const fastrtps::rtps::CacheChange_t* change) const noexcept; - - //! Whether a guid references this Participant (to avoid auto-feedback) - bool come_from_this_participant_( - const fastrtps::rtps::GUID_t guid) const noexcept; - - utils::ReturnCode is_data_correct_( - const fastrtps::rtps::CacheChange_t* received_change) const noexcept; - - ///// - // EXTERNAL VARIABLES - - //! RTPS Participant - fastrtps::rtps::RTPSParticipant* rtps_participant_; - - ///// - // INTERNAL VARIABLES - - //! - core::types::DdsTopic topic_; - - //! RTPS Reader pointer - fastrtps::rtps::RTPSReader* rtps_reader_; - - //! RTPS Reader History associated to \c rtps_reader_ - fastrtps::rtps::ReaderHistory* rtps_history_; - - //! History attributes to create the History for the internal RTPS Reader. - fastrtps::rtps::HistoryAttributes history_attributes_; - - //! Reader attributes to create the internal RTPS Reader. - fastrtps::rtps::ReaderAttributes reader_attributes_; - - //! Topic attributes to create the internal RTPS Reader. - fastrtps::TopicAttributes topic_attributes_; - - //! Reader QoS to create the internal RTPS Reader. - fastrtps::ReaderQos reader_qos_; - -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp deleted file mode 100644 index edd93e2e0..000000000 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SimpleReader.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Base RTPS Reader concrete class that implements abstract CommonReader one. - */ -class SimpleReader : public CommonReader -{ -public: - - /** - * @brief Construct a new SimpleReader object - * - * Get the Attributes and TopicQoS and create the SimpleReader History and the RTPS SimpleReader. - * - * @param participant_id Router Id of the Participant that has created this SimpleReader. - * @param topic Topic that this SimpleReader subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI SimpleReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant); -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp deleted file mode 100644 index 99f7dab2d..000000000 --- a/ddspipe_participants/include/ddspipe_participants/reader/rtps/SpecificQoSReader.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * RTPS Reader with specific QoS implements abstract CommonReader. - * - * This class fills the data receive information with the QoS of the Writer that has sent the data. - * In order to access this QoS it has a reference to the DiscoveryDatabase. - */ -class SpecificQoSReader : public CommonReader -{ -public: - - /** - * @brief Construct a new SpecificQoSReader object - * - * Get the Attributes and TopicQoS and create the SpecificQoSReader History and the RTPS SpecificQoSReader. - * - * @param participant_id Router Id of the Participant that has created this SpecificQoSReader. - * @param topic Topic that this SpecificQoSReader subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI SpecificQoSReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const std::shared_ptr& discovery_database); - -protected: - - /** - * @brief Get the QoS from a Writer from the \c DiscoveryDatabase . - */ - core::types::SpecificEndpointQoS specific_qos_of_writer_( - const core::types::Guid& guid) const; - - /** - * Specializes \c CommonReader method and set the QoS of the data received. - */ - virtual void fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change, - core::types::RtpsPayloadData& data_to_fill) const noexcept override; - - - //! Reference to the \c DiscoveryDatabase . - std::shared_ptr discovery_database_; - -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp deleted file mode 100644 index bee590c0a..000000000 --- a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2021 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\. - -#pragma once - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace testing { - -DDSPIPE_PARTICIPANTS_DllAPI types::Address random_address( - unsigned int seed = 0); - -DDSPIPE_PARTICIPANTS_DllAPI types::DiscoveryServerConnectionAddress random_connection_address( - unsigned int seed = 0, - unsigned int size = 1, - bool ros = false); - -} /* namespace testing */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp b/ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp deleted file mode 100644 index 4a99ab611..000000000 --- a/ddspipe_participants/include/ddspipe_participants/types/address/Address.hpp +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2021 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, -// See the License for the specific language governing permissions and -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// limitations under the License. - -#pragma once - -#include - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -// Data type for Locator kind (this is because FastDDS does not have an enum but defines (dishonor on your cow)) -using LocatorType = uint32_t; -// Data Type for IP -using IpType = std::string; -// Data Type for Domain name (DNS) -using DomainType = std::string; -// Data Type for Port -using PortType = uint16_t; - -//! Different versions allowed for IP -enum class IpVersion : int -{ - v4 = 4, - v6 = 6, -}; - -//! Different Transport Protocols allowed -enum class TransportProtocol -{ - udp, - tcp -}; - -/** - * @brief Address that works as a collection of data defining a network address. - * - * An address will remain in an IP and a Port, that will uniquely define a network address for connection - * or listening. - * There are extra fields in the class such as IP version and Transport Protocol that are settable by the constructor. - */ -class Address -{ -public: - - /** - * @brief Construct a new Address object with all the parameters - * - * @param ip address ip - * @param port address port - * @param external_port external address port - * @param ip_version ip version (4 or 6) - * @param transport_protocol transport protocol (UDP or TCP) - */ - DDSPIPE_PARTICIPANTS_DllAPI Address( - const IpType& ip, - const PortType& port, - const PortType& external_port, - const IpVersion& ip_version, - const TransportProtocol& transport_protocol) noexcept; - - /** - * @brief Construct a new Address object using a DNS call to get IP from \c domain - * - * @param port address port - * @param external_port external address port - * @param ip_version ip version (4 or 6) - * @param domain address domain name to call DNS - * @param transport_protocol transport protocol (UDP or TCP) - */ - DDSPIPE_PARTICIPANTS_DllAPI Address( - const PortType& port, - const PortType& external_port, - const IpVersion& ip_version, - const DomainType& domain, - const TransportProtocol& transport_protocol) noexcept; - - /** - * @brief Construct Address and get IP version from IP format - * - * If the IP is a string with format IPv4, version will be set to IpVersion::v4. - * If the IP is a string with format IPv6, version will be set to IpVersion::v6. - * If the IP has an incorrect format, version will be set to IpVersion::v4 and address will be invalid. - */ - DDSPIPE_PARTICIPANTS_DllAPI Address( - const IpType& ip, - const PortType& port, - const PortType& external_port, - const TransportProtocol& transport_protocol) noexcept; - - /** - * @brief Construct a new Address object using a DNS call to get IP from \c domain without specifying the IP version - * - * @param port address port - * @param external_port external address port - * @param domain address domain name to call DNS - * @param transport_protocol transport protocol (UDP or TCP) - */ - DDSPIPE_PARTICIPANTS_DllAPI Address( - const PortType& port, - const PortType& external_port, - const DomainType& domain, - const TransportProtocol& transport_protocol) noexcept; - - //! Construct a default IP by default values (set in this class) - DDSPIPE_PARTICIPANTS_DllAPI Address(); - - //! Address internal Port getter - DDSPIPE_PARTICIPANTS_DllAPI PortType port() const noexcept; - //! Address external Port getter - DDSPIPE_PARTICIPANTS_DllAPI PortType external_port() const noexcept; - //! Address IP getter - DDSPIPE_PARTICIPANTS_DllAPI IpType ip() const noexcept; - //! Address IP version getter - DDSPIPE_PARTICIPANTS_DllAPI IpVersion ip_version() const noexcept; - //! Address transport protocol version getter - DDSPIPE_PARTICIPANTS_DllAPI TransportProtocol transport_protocol() const noexcept; - - //! Whether transport is UDP - DDSPIPE_PARTICIPANTS_DllAPI bool is_udp() const noexcept; - //! Whether transport is TCP - DDSPIPE_PARTICIPANTS_DllAPI bool is_tcp() const noexcept; - - //! Whether ip version is IpVersion::v4 - DDSPIPE_PARTICIPANTS_DllAPI bool is_ipv4() const noexcept; - //! Whether ip version is IpVersion::v6 - DDSPIPE_PARTICIPANTS_DllAPI bool is_ipv6() const noexcept; - - //! Get FastDDS Locator kind - DDSPIPE_PARTICIPANTS_DllAPI LocatorType get_locator_kind() const noexcept; - - /** - * @brief Whether the address is correct - * - * Checks if IP is in correct format regarding the IP version. - * Checks if Port is correct. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid() const noexcept; - - //! Minor operator - DDSPIPE_PARTICIPANTS_DllAPI bool operator <( - const Address& other) const noexcept; - - //! Equal operator - DDSPIPE_PARTICIPANTS_DllAPI bool operator ==( - const Address& other) const noexcept; - - //! Whether string \c ip has correct IpVersion::v4 format. - DDSPIPE_PARTICIPANTS_DllAPI static bool is_ipv4_correct( - const IpType& ip) noexcept; - - //! Whether string \c ip has correct IpVersion::v6 format. - DDSPIPE_PARTICIPANTS_DllAPI static bool is_ipv6_correct( - const IpType& ip) noexcept; - - //! Default port for address when is not set: 11600 - DDSPIPE_PARTICIPANTS_DllAPI static PortType default_port() noexcept; - //! Default ip for address when is not set: 127.0.0.1 - DDSPIPE_PARTICIPANTS_DllAPI static IpType default_ip( - IpVersion ip_version = default_ip_version()) noexcept; - //! Default ip version for address when is not set: IpVersion::v4 - DDSPIPE_PARTICIPANTS_DllAPI static IpVersion default_ip_version() noexcept; - //! Default transport protocol for address when is not set: UDP - DDSPIPE_PARTICIPANTS_DllAPI static TransportProtocol default_transport_protocol() noexcept; - - /** - * @brief Return the IP corresponding to the \c domain name given with IP version specified in \c ip_version - * - * Make a DNS call to get the IP related with \c domain - * - * @param domain domain name of the ip to look for - * @param ip_version version of the ip to find - * - * @return IpType IP related with \c domain name - * - * @throw DNSException in case an IP for this domain could not be retrieved - */ - DDSPIPE_PARTICIPANTS_DllAPI static IpType resolve_dns( - DomainType domain, - IpVersion ip_version); - - /** - * @brief Return the IP corresponding to the \c domain name given - * - * Make a DNS call to get the IP related with \c domain . - * Get the IP found in default IP Version (IpVersion::v4) if present. If not, find IpVersion::v6. - * - * @param domain domain name of the ip to look for - * - * @return IpType IP related with \c domain name. - * @return IpVersion version of the IP found. - * - * @throw DNSException in case an IP for this domain could not be retrieved - */ - DDSPIPE_PARTICIPANTS_DllAPI static std::pair resolve_dns( - DomainType domain); - -protected: - - //! Internal IP object - IpType ip_; - //! Domain Name with which this Address has been created (in case it is created with ip, it is not used) - DomainType domain_; - //! Whether this Address has been initialized with domain or not - bool has_domain_; - //! Whether the domain has been valid on DNS call - bool has_valid_domain_; - //! Internal (physical) Port object - PortType port_; - //! External (public) Port object - PortType external_port_; - //! Internal Ip version object - IpVersion ip_version_; - //! Internal Transport Protocol object - TransportProtocol transport_protocol_; - - //! Default Port - static const PortType DEFAULT_PORT_; // 11666 - //! Default IpVersion::v4 - static const IpType DEFAULT_IP_v4_; // 127.0.0.1 - //! Default IpVersion::v6 - static const IpType DEFAULT_IP_v6_; // ::1 - //! Default IP version - static const IpVersion DEFAULT_IP_VERSION_; // IpVersion::v4 - //! Default Transport protocol - static const TransportProtocol DEFAULT_TRANSPORT_PROTOCOL_; // UDP - - // Allow operator << to use domain info - DDSPIPE_PARTICIPANTS_DllAPI friend std::ostream& operator <<( - std::ostream& output, - const Address& address); -}; - -//! \c Address to stream serializator -DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( - std::ostream& output, - const Address& address); - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp b/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp deleted file mode 100644 index d9250d6ff..000000000 --- a/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2021 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, -// See the License for the specific language governing permissions and -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// limitations under the License. - -#pragma once - -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -/** - * @brief Collection of Addresses to connect with a remote Disovery Server. - * - * An address will remain in an IP and a Port, IP version and Transport Protocol. - * This class has several address associated with one \c GuidPrefix in order to connect with - * a remote Discovery Server. - */ -class DiscoveryServerConnectionAddress -{ -public: - - /** - * @brief Construct a new \c DiscoveryServerConnectionAddress object with all the parameters - * - * @param discovery_server_guid_ : Guid Prefix of the remote Discovery Server - * @param addresses_ collection of addresses - */ - DDSPIPE_PARTICIPANTS_DllAPI DiscoveryServerConnectionAddress( - core::types::GuidPrefix discovery_server_guid, - std::set
addresses); - - //! Discovery Server \c GuidPrefix Port getter - DDSPIPE_PARTICIPANTS_DllAPI core::types::GuidPrefix discovery_server_guid_prefix() const noexcept; - - //! Addresses getter - DDSPIPE_PARTICIPANTS_DllAPI std::set
addresses() const noexcept; - - /** - * @brief Whether the address is correct - * - * Checks if GuidPrefix is correct. - * Checks if it has at least one correct address. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid() const noexcept; - - //! Minor operator - DDSPIPE_PARTICIPANTS_DllAPI bool operator <( - const DiscoveryServerConnectionAddress& other) const noexcept; - - //! Equal operator - DDSPIPE_PARTICIPANTS_DllAPI bool operator ==( - const DiscoveryServerConnectionAddress& other) const noexcept; - -protected: - - //! Internal Discovery Server Guid Prefix object - core::types::GuidPrefix discovery_server_guid_prefix_; - - //! Internal Addresses object - std::set
addresses_; -}; - -//! \c DiscoveryServerConnectionAddress to stream serializator -DDSPIPE_PARTICIPANTS_DllAPI std::ostream& operator <<( - std::ostream& output, - const DiscoveryServerConnectionAddress& address); - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/dds/RouterCacheChange.hpp b/ddspipe_participants/include/ddspipe_participants/types/dds/RouterCacheChange.hpp deleted file mode 100644 index e42cc0eb9..000000000 --- a/ddspipe_participants/include/ddspipe_participants/types/dds/RouterCacheChange.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace core { -namespace types { - -/** - * @brief Specialization of CacheChange for DDS Router. - * - * It adds the following attributes: - * - last_writer_guid_prefix: store last jump of message Participant GuidPrefix - * - * This Change is required to be used for features: - * - Repeater participant: avoid redirecting the message to the source participant. - */ -struct RouterCacheChange : public fastrtps::rtps::CacheChange_t -{ -public: - - //! Using parent constructors - using fastrtps::rtps::CacheChange_t::CacheChange_t; - - /** - * @brief GuidPrefix of the Participant that has sent this message through the router. - * - * @note it is not the same as origin writer, as there could be more routers in the path. - */ - fastrtps::rtps::GuidPrefix_t last_writer_guid_prefix; -}; - -} /* namespace types */ -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp deleted file mode 100644 index adc6b9859..000000000 --- a/ddspipe_participants/include/ddspipe_participants/types/security/tls/TlsConfiguration.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2022 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\. - -#pragma once - -#include -#include - -#include - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -/** - * @brief Enumeration of kinds of TLS configurations. - */ -ENUMERATION_BUILDER( - TlsKind, - inactive, - client, - server, - both - ); - -/** - * Configuration holding TLS parameters. - */ -struct TlsConfiguration : public core::IConfiguration -{ - - /** - * @brief Constructs an undefined or inactive (valid nonetheless) TLSConfiguration - */ - DDSPIPE_PARTICIPANTS_DllAPI TlsConfiguration() = default; - - /** - * @brief Returns whether configuration is active - */ - DDSPIPE_PARTICIPANTS_DllAPI bool is_active() const noexcept; - - /** - * @brief Check configuration kind compatibility - * - * @tparam Kind TlsConfiguration kind - * - * @return Whether configuration is compatible with parameter \c TlsKind - * - * @note this function is implemented in hpp to avoid a new file for only this method. - */ - template - bool compatible() const noexcept - { - return this->kind != TlsKind::inactive && - (Kind == this->kind || (this->kind == TlsKind::both && Kind != TlsKind::inactive)); - } - - template - DDSPIPE_PARTICIPANTS_DllAPI bool is_valid_kind( - utils::Formatter& error_msg) const noexcept; - - //! Activate TLS configuration in a TCP transport descriptor - DDSPIPE_PARTICIPANTS_DllAPI void enable_tls( - std::shared_ptr descriptor, - bool client = false) const; - - //! Activate TLS client configuration in a TCP transport descriptor - DDSPIPE_PARTICIPANTS_DllAPI void enable_tls_client( - std::shared_ptr descriptor, - bool only_client) const; - - //! Activate TLS server configuration in a TCP transport descriptor - DDSPIPE_PARTICIPANTS_DllAPI void enable_tls_server( - std::shared_ptr descriptor) const; - - DDSPIPE_PARTICIPANTS_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - - //////// - // MEMBERS - - //! Configuration Kind - TlsKind kind = TlsKind::inactive; - bool verify_peer = true; - - //////// - // CLIENT-ONLY VARIABLES - std::string certificate_authority_file = ""; - std::string sni_server_name = ""; - - //////// - // SERVER-ONLY VARIABLES - std::string private_key_file_password = ""; - std::string private_key_file = ""; - std::string certificate_chain_file = ""; - std::string dh_params_file = ""; -}; - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp deleted file mode 100644 index 7912aab2f..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BaseWriter.hpp +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Abstract Writer that implements generic methods for every Writer. - * - * In order to inherit from this class, create the protected method write_ . - * Implement methods enabled_ and disabled_ in order to give specific functionality to these methods. - */ -class BaseWriter : public core::IWriter -{ -public: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - // Protected ctor to make class abstract (only built by their childs). - - ///////////////////////// - // I WRITER METHODS - ///////////////////////// - - /** - * @brief Set this Writer as enabled - * - * It changes the \c enabled_ variable. - * Call protected method \c enable_() for a specific enable functionality. - * - * Override enable() IWriter method - * - * Thread safe with mutex \c mutex_ . - */ - DDSPIPE_PARTICIPANTS_DllAPI void enable() noexcept override; - - /** - * @brief Set this Writer as disabled - * - * It changes the \c enabled_ variable. - * Call protected method \c disable_() for a specific disable functionality. - * - * Override disable() IWriter method - * - * Thread safe with mutex \c mutex_ . - */ - DDSPIPE_PARTICIPANTS_DllAPI void disable() noexcept override; - - /** - * @brief Override write() IWriter method - * - * This method calls the protected method \c writer_ to make the actual write function. - * It only manages the enable/disable status. - * - * Thread safe with mutex \c mutex_ . - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual utils::ReturnCode write( - core::IRoutingData& data) noexcept override; - -protected: - - ///////////////////////// - // CONSTRUCTORS - ///////////////////////// - - /** - * @brief Construct a new Base Writer object - * - * @param participant_id id of participant - * @param topic topic that this Writer will refer to - * @param payload_pool DDS Router shared PayloadPool - */ - BaseWriter( - const core::types::ParticipantId& participant_id, - const std::shared_ptr& payload_pool); - - ///////////////////////// - // METHODS TO IMPLEMENT BY SUBCLASSES - ///////////////////////// - - /** - * @brief Do nothing - * - * Implement this method for a specific enable functionality. - */ - virtual void enable_() noexcept; - - /** - * @brief Do nothing - * - * Implement this method for a specific disable functionality. - */ - virtual void disable_() noexcept; - - /** - * @brief Write method to implement by each Writer implementation - * - * Implement this method in every inherited Writer class with write functionality. - */ - virtual utils::ReturnCode write_( - core::IRoutingData& data) noexcept = 0; - - ///////////////////////// - // INTERNAL VARIABLES - ///////////////////////// - - //! Participant parent ID - const core::types::ParticipantId participant_id_; - - //! DDS Router shared Payload Pool - std::shared_ptr payload_pool_; - - //! Whether the Writer is currently enabled - std::atomic enabled_; - - //! Mutex that guards every access to the Writer - mutable std::recursive_mutex mutex_; - - // Allow operator << to use private variables - friend std::ostream& operator <<( - std::ostream&, - const BaseWriter&); -}; - -/** - * @brief \c BaseWriter to stream serialization - * - * This method is merely a to_string of a BaseWriter definition. - * It serialize the ParticipantId and topic - */ -std::ostream& operator <<( - std::ostream& os, - const BaseWriter& writer); - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp deleted file mode 100644 index 093240db9..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/BlankWriter.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Writer that has an empty implementation. - * It does not send anything. - */ -DDSPIPE_PARTICIPANTS_DllAPI class BlankWriter : public core::IWriter -{ -public: - - //! Override enable() IWriter method - void enable() noexcept override; - - //! Override disable() IWriter method - void disable() noexcept override; - - //! Override write() IWriter method - utils::ReturnCode write( - core::IRoutingData& data) noexcept override; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp deleted file mode 100644 index 082926bbb..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/RtpsEchoWriter.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -/** - * Writer Implementation that prints in stdout every message that is required to write. - */ -class RtpsEchoWriter : public BlankWriter -{ -public: - - //! Using parent class constructors - DDSPIPE_PARTICIPANTS_DllAPI RtpsEchoWriter( - const core::types::DdsTopic& topic, - bool verbose); - -protected: - - /** - * @brief Print data in a human friendly way. - * - * @param data : data to print - * @return RETCODE_OK always - */ - virtual utils::ReturnCode write( - core::IRoutingData& data) noexcept override; - - //! Topic that this Writer refers to - core::types::DdsTopic topic_; - - // Specific enable/disable do not need to be implemented - bool verbose_; -}; - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp deleted file mode 100644 index 7a873d303..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rpc/SimpleWriter.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rpc { - -/** - * Base RTPS Writer concrete class that implements abstract CommonWriter one. - */ -class SimpleWriter : public rtps::CommonWriter -{ -public: - - /** - * @brief Construct a new SimpleWriter object - * - * Get the Attributes and TopicQoS and create the SimpleWriter History and the RTPS SimpleWriter. - * - * @note use protected constructor so this class is not called but from subclasses - * (Basically make abstract class without a pure virtual function). - * - * @param participant_id Router Id of the Participant that has created this SimpleWriter. - * @param topic Topic that this SimpleWriter subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI SimpleWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater = false); - - //! Override Parent method to fill fields only required for RPC. - DDSPIPE_PARTICIPANTS_DllAPI virtual utils::ReturnCode fill_to_send_data_( - fastrtps::rtps::CacheChange_t* to_send_change_to_fill, - eprosima::fastrtps::rtps::WriteParams& to_send_params, - const core::types::RtpsPayloadData& data) const noexcept; - - //! Override Parent method to fill fields after message is sent only required for RPC. - DDSPIPE_PARTICIPANTS_DllAPI virtual void fill_sent_data_( - const eprosima::fastrtps::rtps::WriteParams& sent_params, - core::types::RtpsPayloadData& data_to_fill) const noexcept; -}; - -} /* namespace rpc */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp deleted file mode 100644 index 8f836a67e..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/CommonWriter.hpp +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -///// -// Forward declarations -namespace eprosima { -namespace ddspipe { -namespace participants { - -struct CacheChangePoolConfiguration; - -} /* namespace participants */ -} /* namespace ddspipe */ - -namespace fastdds { -namespace rtps { - -struct IReaderDataFilter; - -} /* namespace rtps */ -} /* namespace fastdds */ -} /* namespace eprosima */ - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Abstract generic class for a RTPS Writer wrapper. - * - * It implements the WriterListener for itself with \c onWriterMatched callbacks. - * - * @warning This object is not RAII and must be initialized before used. - */ -class CommonWriter : public BaseWriter, public fastrtps::rtps::WriterListener -{ -public: - - ///////////////////////// - // CONSTRUCTOR - ///////////////////////// - - // Protected ctor to make class abstract (only built by their childs). - - /** - * @brief Destroy the Writer object - * - * Delete the RTPS Writer and Writer History in case they are set. - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual ~CommonWriter(); - - /** - * @brief Create the internal RTPS Writer. - * - * @attention this method should be called right after constructor to create enable internal entities. - * This is required as this object is a Listener that could be called before finishing construction. - * Other alternatives have been studied but none have really fit for this case. - * - * @throw InitializationException if RTPS Writer creation fails - * - * @warning this method is not thread safe. - * @pre this method can only be called once. - */ - DDSPIPE_PARTICIPANTS_DllAPI void init(); - - ///////////////////////// - // RTPS LISTENER METHODS - ///////////////////////// - - /** - * @brief CommonWriter Listener callback when a new Reader is matched or unmatched - * - * This method is call every time a new Reader is matched or unmatched from this CommonWriter. - * It only creates a log for matching and unmatching (in case it is not a reader from this same Participant) - * - * @param [in] info information about the matched Reader - */ - DDSPIPE_PARTICIPANTS_DllAPI void onWriterMatched( - fastrtps::rtps::RTPSWriter*, - fastrtps::rtps::MatchingInfo& info) noexcept override; - -protected: - - /** - * @brief Construct a new Writer object - * - * It receives all the attributes and QoS needed to create the internal entities. - * - * @note Only protected so only concrete classes are instantiated. - * - * @throw \c InitializationException in case any creation has failed - */ - CommonWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater, - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::WriterAttributes& writer_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::WriterQos& writer_qos, - const utils::PoolConfiguration& pool_configuration); - - // Specific enable/disable do not need to be implemented - - /** - * @brief Write specific method - * - * Store new data as message to send (synchronously) (it could use PayloadPool to not copy payload). - * Take next Untaken Change. - * Set \c data with the message taken (data payload must be stored from PayloadPool). - * Remove this change from Reader History and release. - * - * It does not require mutex, it will be guarded by RTPS CommonWriter mutex in internal methods. - * - * @param data : oldest data to take - * @return \c RETCODE_OK if data has been correctly taken - * @return \c RETCODE_NO_DATA if \c data is empty - * @return \c RETCODE_ERROR if error occurred - */ - virtual utils::ReturnCode write_( - core::IRoutingData& data) noexcept override; - - /** - * @brief Auxiliary method used in \c write to fill the cache change to send. - * - * @param [out] to_send_change_to_fill cache change to be filled and sent. - * @param [out] to_send_params write params to be filled and sent. - * @param [in] data data received that must be sent. - */ - virtual utils::ReturnCode fill_to_send_data_( - fastrtps::rtps::CacheChange_t* to_send_change_to_fill, - eprosima::fastrtps::rtps::WriteParams& to_send_params, - const core::types::RtpsPayloadData& data) const noexcept; - - /** - * @brief Auxiliary method used after \c write to fill data value. - * - * @param [in] to_send_params write params of the cache change sent. - * @param [out] data data to be fulfilled with params. - */ - virtual void fill_sent_data_( - const eprosima::fastrtps::rtps::WriteParams& sent_params, - core::types::RtpsPayloadData& data_to_fill) const noexcept; - - ///// - // RTPS specific methods - - /** - * @brief Create \c this->rtps_writer_ internal object - * - * @note this method exists because it may be created from child classes, thus the methods may not be yet available - * to get atts and qos. - * - * @param rtps_participant - */ - void internal_entities_creation_( - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::WriterAttributes& writer_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::WriterQos& writer_qos, - const utils::PoolConfiguration& pool_configuration); - - /** - * @brief History Attributes to create RTPS Writer History - */ - static fastrtps::rtps::HistoryAttributes reckon_history_attributes_( - const core::types::DdsTopic& topic) noexcept; - - /** - * @brief Writer Attributes to create RTPS Writer - */ - static fastrtps::rtps::WriterAttributes reckon_writer_attributes_( - const core::types::DdsTopic& topic) noexcept; - - //! Topic Attributes to create RTPS Writer - static fastrtps::TopicAttributes reckon_topic_attributes_( - const core::types::DdsTopic& topic) noexcept; - - //! QoS for RTPS Writer - static fastrtps::WriterQos reckon_writer_qos_( - const core::types::DdsTopic& topic) noexcept; - - //! Cache Change Pool Configuration - static utils::PoolConfiguration reckon_cache_change_pool_configuration_( - const core::types::DdsTopic& topic) noexcept; - - //! Whether a guid references this Participant - bool come_from_this_participant_( - const fastrtps::rtps::GUID_t guid) const noexcept; - - ///// - // EXTERNAL VARIABLES - - //! RTPS Participant - fastrtps::rtps::RTPSParticipant* rtps_participant_; - - //! Wether it is repeater or not (used for data filters and/or qos) - bool repeater_; - - ///// - // INTERNAL VARIABLES - - core::types::DdsTopic topic_; - - //! RTPS CommonWriter pointer - fastrtps::rtps::RTPSWriter* rtps_writer_; - - //! RTPS CommonWriter History associated to \c rtps_reader_ - fastrtps::rtps::WriterHistory* rtps_history_; - - //! Data Filter used to filter cache changes at the RTPSWriter level. - std::unique_ptr data_filter_; - - //! History attributes to create the History for the internal RTPS Writer. - fastrtps::rtps::HistoryAttributes history_attributes_; - - //! Writer attributes to create the internal RTPS Writer. - fastrtps::rtps::WriterAttributes writer_attributes_; - - //! Topic attributes to create the internal RTPS Writer. - fastrtps::TopicAttributes topic_attributes_; - - //! Writer QoS to create the internal RTPS Writer. - fastrtps::WriterQos writer_qos_; - - //! Pool Configuration to create the internal History. - utils::PoolConfiguration pool_configuration_; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp deleted file mode 100644 index f2e0912e1..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/MultiWriter.hpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include - -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Writer collection implementation that contains multiple QoSSpecificWriter. - * - * @todo this class could have access to the Discovery DataBase and create writers in discovery and not when - * data is received. - */ -class MultiWriter : public BaseWriter -{ -public: - - /** - * @brief Construct a new MultiWriter object - * - * Get the Attributes and TopicQoS and create the MultiWriter History and the RTPS MultiWriter. - * - * @param participant_id Router Id of the Participant that has created this MultiWriter. - * @param topic Topic that this MultiWriter subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI MultiWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater = false); - - /** - * @brief Destroy the MultiWriter object - * - * Remove MultiWriter RTPS - * Remove History - * - * @todo Remove every change and release it in PayloadPool - */ - DDSPIPE_PARTICIPANTS_DllAPI virtual ~MultiWriter(); - -protected: - - //! Override specific enable to call enable in internal writers. - virtual void enable_() noexcept override; - //! Override specific disable to call disable in internal writers. - virtual void disable_() noexcept override; - - /** - * TODO - */ - virtual utils::ReturnCode write_( - core::IRoutingData& data) noexcept override; - - bool exist_partition_( - const core::types::SpecificEndpointQoS& data_qos); - QoSSpecificWriter* get_writer_or_create_( - const core::types::SpecificEndpointQoS& data_qos); - QoSSpecificWriter* create_writer_nts_( - const core::types::SpecificEndpointQoS& data_qos); - - ///////////////////////// - // INTERNAL VARIABLES - ///////////////////////// - - using WritersMapType = utils::SharedAtomicable>; - //! Map of writer indexed by Specific QoS of each. - WritersMapType writers_map_; - - core::types::DdsTopic topic_; - - //! Reference to RTPS Participant. - fastrtps::rtps::RTPSParticipant* rtps_participant_; - - //! Whether this Writer is a repeater. - bool repeater_; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp deleted file mode 100644 index 77e69fa41..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/QoSSpecificWriter.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * RTPS Writer with specific QoS implements abstract CommonWriter. - * - * This class implements a RTPS Writer with specific QoS policies. - */ -class QoSSpecificWriter : public CommonWriter -{ -public: - - /** - * @brief Construct a new QoSSpecificWriter object - * - * Get the Attributes and TopicQoS and create the QoSSpecificWriter History and the RTPS QoSSpecificWriter. - * - * @param participant_id Router Id of the Participant that has created this QoSSpecificWriter. - * @param topic Topic that this QoSSpecificWriter subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI QoSSpecificWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const core::types::SpecificEndpointQoS& specific_qos, - const bool repeater = false); - -protected: - - //! Specific writer QoS to override (more or less) the CommonWriter qos - static fastrtps::WriterQos reckon_writer_qos_( - const core::types::SpecificEndpointQoS& specific_qos, - const core::types::DdsTopic& topic) noexcept; - - //! Specific QoS of the Endpoint - core::types::SpecificEndpointQoS specific_qos_; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp deleted file mode 100644 index 065753321..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/SimpleWriter.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 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. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * Base RTPS Writer concrete class that implements abstract CommonWriter one. - */ -class SimpleWriter : public CommonWriter -{ -public: - - /** - * @brief Construct a new SimpleWriter object - * - * Get the Attributes and TopicQoS and create the SimpleWriter History and the RTPS SimpleWriter. - * - * @note use protected constructor so this class is not called but from subclasses - * (Basically make abstract class without a pure virtual function). - * - * @param participant_id Router Id of the Participant that has created this SimpleWriter. - * @param topic Topic that this SimpleWriter subscribes to. - * @param payload_pool Shared Payload Pool to received data and take it. - * @param rtps_participant RTPS Participant pointer (this is not stored). - * - * @throw \c InitializationException in case any creation has failed - */ - DDSPIPE_PARTICIPANTS_DllAPI SimpleWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater = false); - -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp deleted file mode 100644 index fd415f539..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/RepeaterDataFilter.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * This filter allows to not send messages from this Writer to the Readers belonging to the source Participant. - * It is used in "repeater" participants in order to propagate information to external participants - * (participants not belonging to the same DDS-Router instance), - * leaving out the participant from which this information was received. - * - * This uses the RouterCacheChange extra information. - */ -DDSPIPE_PARTICIPANTS_DllAPI class RepeaterDataFilter : public SelfDataFilter -{ -public: - - /** - * @brief Whether incoming change is relevant for this reader. - * - * @return true if the reader does not belong to Participant that previously sent this message. - * @return false otherwise. - */ - bool is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid - ) const override; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp deleted file mode 100644 index 7d9f017fa..000000000 --- a/ddspipe_participants/include/ddspipe_participants/writer/rtps/filter/SelfDataFilter.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include - -///// -// Forward declarations -namespace eprosima { -namespace fastrtps { -namespace rtps { - -struct CacheChange_t; -struct GUID_t; - -} /* namespace rtps */ -} /* namespace fastrtps */ -} /* namespace eprosima */ - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -/** - * This filter allows to not send messages from this Writer to the Readers in the same Participant. - */ -DDSPIPE_PARTICIPANTS_DllAPI class SelfDataFilter : public fastdds::rtps::IReaderDataFilter -{ -public: - - /** - * @brief Whether incoming change is relevant for this reader. - * - * @return true if the reader does not belong to same Participant. - * @return false otherwise. - */ - bool is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid - ) const override; -}; - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/package.xml b/ddspipe_participants/package.xml deleted file mode 100644 index 97945cbef..000000000 --- a/ddspipe_participants/package.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - ddspipe_participants - 1.1.0 - - *eprosima DDS Pipe* C++ Std Participant implementations. - - Raul Sánchez-Mateos - Javier París - Juan López - Apache 2.0 - - https://www.eprosima.com/ - https://github.com/eProsima/DDS-Router/issues - https://github.com/eProsima/DDS-Router - - cmake - - fastrtps - cpp_utils - cmake_utils - ddspipe_core - - doxygen - - googletest-distribution - - - cmake - - diff --git a/ddspipe_participants/project_settings.cmake b/ddspipe_participants/project_settings.cmake deleted file mode 100644 index 8278021ac..000000000 --- a/ddspipe_participants/project_settings.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2022 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. - -############################################################################### -# Set settings for project ddspipe_participants -############################################################################### - -set(MODULE_NAME - ddspipe_participants) - -set(MODULE_SUMMARY - "C++ library to build and run a DDS Router.") - -set(MODULE_FIND_PACKAGES - fastcdr - fastrtps - cpp_utils - ddspipe_core) - -set(fastrtps_MINIMUM_VERSION "2.8") - -set(MODULE_DEPENDENCIES - $<$:iphlpapi$Shlwapi> - ${MODULE_FIND_PACKAGES}) diff --git a/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp deleted file mode 100644 index 0af034b34..000000000 --- a/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -bool DiscoveryServerParticipantConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - // Check parent class validity - if (!SimpleParticipantConfiguration::is_valid(error_msg)) - { - return false; - } - - // Check DS Guid Prefix - if (!discovery_server_guid_prefix.is_valid()) - { - error_msg << "Non valid Participant Guid Prefix " << discovery_server_guid_prefix << ". "; - return false; - } - - // Check listening addresses - for (types::Address address : listening_addresses) - { - if (!address.is_valid()) - { - error_msg << "Incorrect address " << address << " in listening addresses. "; - return false; - } - } - - // Check connection addresses - for (types::DiscoveryServerConnectionAddress address : connection_addresses) - { - if (!address.is_valid()) - { - error_msg << "Incorrect address " << address << " in connection addresses. "; - return false; - } - } - - // Check exist at least one address - if (listening_addresses.empty() && connection_addresses.empty()) - { - error_msg << "No listening or connection address specified. "; - return false; - } - - // If active, check it is valid - if (tls_configuration.is_active()) - { - // If has listening addresses, it should be able to provide TLS server configuration - if (!listening_addresses.empty()) - { - if (!tls_configuration.compatible()) - { - error_msg << "TLS requires to support Server Configuration if listening addresses set. "; - return false; - } - } - - // If has connection addresses, it should be able to provide TLS client configuration - if (!connection_addresses.empty()) - { - if (!tls_configuration.compatible()) - { - error_msg << "TLS requires to support Client Configuration if connection addresses set. "; - return false; - } - } - } - - return true; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp deleted file mode 100644 index cdff3f3e6..000000000 --- a/ddspipe_participants/src/cpp/configuration/InitialPeersParticipantConfiguration.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -bool InitialPeersParticipantConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - // Check parent class validity - if (!SimpleParticipantConfiguration::is_valid(error_msg)) - { - return false; - } - - // Check listening addresses - for (types::Address address : listening_addresses) - { - if (!address.is_valid()) - { - error_msg << "Incorrect address " << address << " in listening addresses. "; - return false; - } - } - - // Check connection addresses - for (types::Address address : connection_addresses) - { - if (!address.is_valid()) - { - error_msg << "Incorrect address " << address << " in connection addresses. "; - return false; - } - } - - // Check exist at least one address - if (listening_addresses.empty() && connection_addresses.empty()) - { - error_msg << "No listening or connection address specified. "; - return false; - } - - // If active, check it is valid - if (tls_configuration.is_active()) - { - // If has listening addresses, it should be able to provide TLS server configuration - if (!listening_addresses.empty()) - { - if (!tls_configuration.compatible()) - { - error_msg << "TLS requires to support Server Configuration if listening addresses set. "; - return false; - } - } - - // If has connection addresses, it should be able to provide TLS client configuration - if (!connection_addresses.empty()) - { - if (!tls_configuration.compatible()) - { - error_msg << "TLS requires to support Client Configuration if connection addresses set. "; - return false; - } - } - } - - return true; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp deleted file mode 100644 index 23a14d20b..000000000 --- a/ddspipe_participants/src/cpp/configuration/ParticipantConfiguration.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2021 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. - - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -bool ParticipantConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - if (id.empty()) - { - error_msg << "Non valid Participant Id " << id << ". "; - return false; - } - - return true; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp deleted file mode 100644 index 8c5f34e89..000000000 --- a/ddspipe_participants/src/cpp/configuration/SimpleParticipantConfiguration.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021 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. - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -bool SimpleParticipantConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - if (!ParticipantConfiguration::is_valid(error_msg)) - { - return false; - } - - if (!domain.is_valid(error_msg)) - { - error_msg << "Incorrect domain " << domain << ". "; - return false; - } - - return true; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp b/ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp deleted file mode 100644 index 4c8d50a71..000000000 --- a/ddspipe_participants/src/cpp/efficiency/cache_change/CacheChangePool.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace core { - -CacheChangePool::CacheChangePool( - utils::PoolConfiguration configuration) - : utils::UnboundedPool(configuration) -{ - initialize_vector_(); -} - -bool CacheChangePool::reserve_cache( - fastrtps::rtps::CacheChange_t*& cache_change) -{ - return loan(cache_change); -} - -bool CacheChangePool::release_cache( - fastrtps::rtps::CacheChange_t* cache_change) -{ - return return_loan(cache_change); -} - -fastrtps::rtps::CacheChange_t* CacheChangePool::new_element_() -{ - return new types::RouterCacheChange(); -} - -} /* namespace core */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp b/ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp deleted file mode 100644 index 4d6539f73..000000000 --- a/ddspipe_participants/src/cpp/participant/auxiliar/BlankParticipant.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2021 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. - - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -BlankParticipant::BlankParticipant( - const core::types::ParticipantId& id) - : id_(id) -{ -} - -core::types::ParticipantId BlankParticipant::id() const noexcept -{ - return id_; -} - -bool BlankParticipant::is_repeater() const noexcept -{ - return false; -} - -bool BlankParticipant::is_rtps_kind() const noexcept -{ - return false; -} - -std::shared_ptr BlankParticipant::create_writer( - const core::ITopic& topic) -{ - return std::make_shared(); -} - -std::shared_ptr BlankParticipant::create_reader( - const core::ITopic& topic) -{ - return std::make_shared(); -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp b/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp deleted file mode 100644 index c6606b81c..000000000 --- a/ddspipe_participants/src/cpp/participant/auxiliar/EchoParticipant.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2021 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. - -#include - -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -EchoParticipant::EchoParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& discovery_database) - : BlankParticipant(participant_configuration->id) - , configuration_(participant_configuration) -{ - logDebug(DDSROUTER_TRACK, "Creating Echo Participant : " << configuration_->id << " ."); - - if (configuration_->echo_discovery) - { - // Register in Discovery DB a callback to be notified each time an endpoint is discovered - discovery_database->add_endpoint_discovered_callback( - [this](const core::types::Endpoint& endpoint_discovered) - { - this->echo_discovery(endpoint_discovered); - }); - } -} - -void EchoParticipant::echo_discovery( - core::types::Endpoint endpoint_discovered) const noexcept -{ - // TODO write this in a way that is efficient and easy to read and allow verbose option - logUser( - DDSROUTER_ECHO_DISCOVERY, - "New endpoint discovered: " << endpoint_discovered << "."); -} - -std::shared_ptr EchoParticipant::create_writer( - const core::ITopic& topic) -{ - // Check if topic is of type RTPS - if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RTPS) - { - if (configuration_->echo_data) - { - const core::types::DdsTopic& dds_topic = dynamic_cast(topic); - return std::make_shared( - dds_topic, - configuration_->verbose); - } - } - else - { - logInfo(DDSROUTER_ECHO_DISCOVERY, "Ignoring topic " << topic.topic_name() << " as it is not RTPS."); - } - - return std::make_shared(); -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp deleted file mode 100644 index 8d34812c5..000000000 --- a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp +++ /dev/null @@ -1,437 +0,0 @@ -// Copyright 2021 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. - - -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -CommonParticipant::CommonParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database, - const core::types::DomainId& domain_id, - const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes) - : configuration_(participant_configuration) - , payload_pool_(payload_pool) - , discovery_database_(discovery_database) - , domain_id_(domain_id) - , participant_attributes_(participant_attributes) -{ - // Do nothing -} - -CommonParticipant::~CommonParticipant() -{ - if (rtps_participant_) - { - fastrtps::rtps::RTPSDomain::removeRTPSParticipant(rtps_participant_); - } -} - -void CommonParticipant::init() -{ - create_participant_( - domain_id_, - participant_attributes_); -} - -void CommonParticipant::onParticipantDiscovery( - fastrtps::rtps::RTPSParticipant* participant, - fastrtps::rtps::ParticipantDiscoveryInfo&& info) -{ - if (info.info.m_guid.guidPrefix != participant->getGuid().guidPrefix) - { - if (info.status == fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) - { - logInfo(DDSROUTER_DISCOVERY, - "Found in Participant " << configuration_->id << " new Participant " << info.info.m_guid << "."); - } - else if (info.status == fastrtps::rtps::ParticipantDiscoveryInfo::CHANGED_QOS_PARTICIPANT) - { - logInfo(DDSROUTER_DISCOVERY, "Participant " << info.info.m_guid << " changed QoS."); - } - else if (info.status == fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) - { - logInfo(DDSROUTER_DISCOVERY, "Participant " << info.info.m_guid << " removed."); - } - else - { - logInfo(DDSROUTER_DISCOVERY, "Participant " << info.info.m_guid << " dropped."); - } - } -} - -template -core::types::Endpoint CommonParticipant::create_common_endpoint_from_info_( - DiscoveryInfoKind& info) -{ - // Endpoint struct to fill - core::types::Endpoint endpoint; - - // Parse GUID - endpoint.guid = info.info.guid(); - - // Parse TopicQoS - // Durability - endpoint.topic.topic_qos.durability_qos = info.info.m_qos.m_durability.durabilityKind(); - // Reliability - if (info.info.m_qos.m_reliability.kind == fastdds::dds::BEST_EFFORT_RELIABILITY_QOS) - { - endpoint.topic.topic_qos.reliability_qos = fastrtps::rtps::BEST_EFFORT; - } - else if (info.info.m_qos.m_reliability.kind == fastdds::dds::RELIABLE_RELIABILITY_QOS) - { - endpoint.topic.topic_qos.reliability_qos = fastrtps::rtps::RELIABLE; - } - else - { - utils::tsnh( - utils::Formatter() << - "Invalid ReliabilityQoS value found while parsing DiscoveryInfo for Endpoint creation."); - } - // Set Topic with Partitions - endpoint.topic.topic_qos.use_partitions = !info.info.m_qos.m_partition.empty(); - // Set Topic with ownership - endpoint.topic.topic_qos.ownership_qos = info.info.m_qos.m_ownership.kind; - // Set Topic key - endpoint.topic.topic_qos.keyed = info.info.topicKind() == eprosima::fastrtps::rtps::TopicKind_t::WITH_KEY; - - // Parse Topic - core::types::DdsTopic info_topic; - endpoint.topic.m_topic_name = std::string(info.info.topicName()); - endpoint.topic.type_name = std::string(info.info.typeName()); - endpoint.topic.m_internal_type_discriminator = core::types::INTERNAL_TOPIC_TYPE_RTPS; - - // Parse specific QoS of the entity - if (endpoint.topic.topic_qos.has_partitions()) - { - endpoint.specific_qos.partitions = info.info.m_qos.m_partition; - } - - // Set participant that discovered - endpoint.discoverer_participant_id = configuration_->id; - - // NOTE: ownership is only for Writer - return endpoint; -} - -template<> -core::types::Endpoint CommonParticipant::create_endpoint_from_info_( - fastrtps::rtps::WriterDiscoveryInfo& info) -{ - // Create Endpoint from common info - core::types::Endpoint endpoint = create_common_endpoint_from_info_(info); - - if (endpoint.topic.topic_qos.has_ownership()) - { - // Only for writers - endpoint.specific_qos.ownership_strength = info.info.m_qos.m_ownershipStrength; - } - - // Set type - endpoint.kind = core::types::EndpointKind::writer; - - return endpoint; -} - -template<> -core::types::Endpoint CommonParticipant::create_endpoint_from_info_( - fastrtps::rtps::ReaderDiscoveryInfo& info) -{ - // Create Endpoint from common info - core::types::Endpoint endpoint = create_common_endpoint_from_info_(info); - - // Set type - endpoint.kind = core::types::EndpointKind::reader; - - return endpoint; -} - -void CommonParticipant::onReaderDiscovery( - fastrtps::rtps::RTPSParticipant* participant, - fastrtps::rtps::ReaderDiscoveryInfo&& info) -{ - if (info.info.guid().guidPrefix != participant->getGuid().guidPrefix) - { - core::types::Endpoint info_reader = create_endpoint_from_info_(info); - - if (info.status == fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERED_READER) - { - logInfo(DDSROUTER_DISCOVERY, - "Found in Participant " << configuration_->id << " new Reader " << info.info.guid() << "."); - - this->discovery_database_->add_endpoint(info_reader); - } - else if (info.status == fastrtps::rtps::ReaderDiscoveryInfo::CHANGED_QOS_READER) - { - logInfo(DDSROUTER_DISCOVERY, "Reader " << info.info.guid() << " changed TopicQoS."); - - this->discovery_database_->update_endpoint(info_reader); - } - else if (info.status == fastrtps::rtps::ReaderDiscoveryInfo::REMOVED_READER) - { - logInfo(DDSROUTER_DISCOVERY, "Reader " << info.info.guid() << " removed."); - - info_reader.active = false; - this->discovery_database_->update_endpoint(info_reader); - } - else - { - logInfo(DDSROUTER_DISCOVERY, "Reader " << info.info.guid() << " dropped."); - - info_reader.active = false; - this->discovery_database_->update_endpoint(info_reader); - } - } -} - -void CommonParticipant::onWriterDiscovery( - fastrtps::rtps::RTPSParticipant* participant, - fastrtps::rtps::WriterDiscoveryInfo&& info) -{ - if (info.info.guid().guidPrefix != participant->getGuid().guidPrefix) - { - core::types::Endpoint info_writer = create_endpoint_from_info_(info); - - if (info.status == fastrtps::rtps::WriterDiscoveryInfo::DISCOVERED_WRITER) - { - logInfo(DDSROUTER_DISCOVERY, - "Found in Participant " << configuration_->id << " new Writer " << info.info.guid() << "."); - - this->discovery_database_->add_endpoint(info_writer); - } - else if (info.status == fastrtps::rtps::WriterDiscoveryInfo::CHANGED_QOS_WRITER) - { - logInfo(DDSROUTER_DISCOVERY, "Writer " << info.info.guid() << " changed TopicQoS."); - - this->discovery_database_->update_endpoint(info_writer); - } - else if (info.status == fastrtps::rtps::WriterDiscoveryInfo::REMOVED_WRITER) - { - logInfo(DDSROUTER_DISCOVERY, "Writer " << info.info.guid() << " removed."); - - info_writer.active = false; - this->discovery_database_->update_endpoint(info_writer); - } - else - { - logInfo(DDSROUTER_DISCOVERY, "Writer " << info.info.guid() << " dropped."); - - info_writer.active = false; - this->discovery_database_->update_endpoint(info_writer); - } - } -} - -bool CommonParticipant::is_repeater() const noexcept -{ - return configuration_->is_repeater; -} - -core::types::ParticipantId CommonParticipant::id() const noexcept -{ - return configuration_->id; -} - -bool CommonParticipant::is_rtps_kind() const noexcept -{ - return true; -} - -void CommonParticipant::create_participant_( - const core::types::DomainId& domain, - const fastrtps::rtps::RTPSParticipantAttributes& participant_attributes) -{ - logInfo(DDSROUTER_RTPS_PARTICIPANT, - "Creating Participant in domain " << domain); - - // Listener must be set in creation as no callbacks should be missed - // It is safe to do so here as object is already created and callbacks do not require anything set in this method - rtps_participant_ = fastrtps::rtps::RTPSDomain::createParticipant( - domain, - participant_attributes, - this); - - if (!rtps_participant_) - { - throw utils::InitializationException( - utils::Formatter() << "Error creating RTPS Participant " << this->id()); - } - - logInfo(DDSROUTER_RTPS_PARTICIPANT, - "New Participant created with id " << this->id() << - " in domain " << domain << " with guid " << rtps_participant_->getGuid() << - (this->is_repeater() ? " (repeater)" : " (non repeater)")); -} - -std::shared_ptr CommonParticipant::create_writer( - const core::ITopic& topic) -{ - // Can only create DDS Topics - const core::types::DdsTopic* dds_topic_ptr = dynamic_cast(&topic); - if (!dds_topic_ptr) - { - logDebug(DDSROUTER_RTPS_PARTICIPANT, "Not creating Writer for topic " << topic.topic_name()); - return std::make_shared(); - } - const core::types::DdsTopic& dds_topic = *dds_topic_ptr; - - if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RPC) - { - logDebug(DDSROUTER_RTPS_PARTICIPANT, - "Creating RPC Writer for topic " << topic.topic_name()); - auto writer = std::make_shared( - this->id(), - dds_topic, - this->payload_pool_, - rtps_participant_, - this->configuration_->is_repeater); - writer->init(); - - return writer; - } - else if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RTPS) - { - if (dds_topic.topic_qos.has_partitions() || dds_topic.topic_qos.has_ownership()) - { - // Notice that MultiWriter does not require an init call - return std::make_shared( - this->id(), - dds_topic, - this->payload_pool_, - rtps_participant_, - this->configuration_->is_repeater); - } - else - { - auto writer = std::make_shared( - this->id(), - dds_topic, - this->payload_pool_, - rtps_participant_, - this->configuration_->is_repeater); - writer->init(); - - return writer; - } - } - else - { - logDevError(DDSROUTER_RTPS_PARTICIPANT, "Incorrect dds Topic in Writer creation."); - return std::make_shared(); - } -} - -std::shared_ptr CommonParticipant::create_reader( - const core::ITopic& topic) -{ - // Can only create DDS Topics - const core::types::DdsTopic* dds_topic_ptr = dynamic_cast(&topic); - if (!dds_topic_ptr) - { - logDebug(DDSROUTER_RTPS_PARTICIPANT, "Not creating Reader for topic " << topic.topic_name()); - return std::make_shared(); - } - const core::types::DdsTopic& dds_topic = *dds_topic_ptr; - - if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RPC) - { - logDebug(DDSROUTER_RTPS_PARTICIPANT, - "Creating RPC Reader for topic " << topic.topic_name()); - - auto reader = std::make_shared( - this->id(), - dds_topic, - this->payload_pool_, - rtps_participant_); - reader->init(); - - return reader; - } - else if (topic.internal_type_discriminator() == core::types::INTERNAL_TOPIC_TYPE_RTPS) - { - if (dds_topic.topic_qos.has_partitions() || dds_topic.topic_qos.has_ownership()) - { - auto reader = std::make_shared( - this->id(), - dds_topic, - this->payload_pool_, - rtps_participant_, - discovery_database_); - reader->init(); - - return reader; - } - else - { - auto reader = std::make_shared( - this->id(), - dds_topic, - this->payload_pool_, - rtps_participant_); - reader->init(); - - return reader; - } - } - else - { - logDevError(DDSROUTER_RTPS_PARTICIPANT, "Incorrect dds Topic in Reader creation."); - return std::make_shared(); - } -} - -fastrtps::rtps::RTPSParticipantAttributes -CommonParticipant::reckon_participant_attributes_( - const ParticipantConfiguration* participant_configuration) -{ - fastrtps::rtps::RTPSParticipantAttributes params; - - // Add Participant name - params.setName(participant_configuration->id.c_str()); - - return params; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp deleted file mode 100644 index 102907ca3..000000000 --- a/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp +++ /dev/null @@ -1,362 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -DiscoveryServerParticipant::DiscoveryServerParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database) - : CommonParticipant( - participant_configuration, - payload_pool, - discovery_database, - participant_configuration->domain, - reckon_participant_attributes_(participant_configuration.get())) -{ -} - -fastrtps::rtps::RTPSParticipantAttributes -DiscoveryServerParticipant::reckon_participant_attributes_( - const DiscoveryServerParticipantConfiguration* configuration) -{ - // Use default as base attributes - fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); - - // Auxiliary variable to save characters and improve readability - const core::types::GuidPrefix& discovery_server_guid_prefix = configuration->discovery_server_guid_prefix; - const auto& tls_config = configuration->tls_configuration; - - // Needed values to check at the end if descriptor must be set - bool has_listening_addresses = false; - bool has_connection_addresses = false; - bool has_listening_tcp_ipv4 = false; - bool has_listening_tcp_ipv6 = false; - bool has_connection_tcp_ipv4 = false; - bool has_connection_tcp_ipv6 = false; - bool has_udp_ipv4 = false; - bool has_udp_ipv6 = false; - - params.useBuiltinTransports = false; - - ///// - // Set listening addresses - for (types::Address address : configuration->listening_addresses) - { - if (!address.is_valid()) - { - // Invalid address, continue with next one - logWarning(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Discard listening address: " << address << - " in Participant " << configuration->id << " initialization."); - continue; - } - - has_listening_addresses = true; - - // TCP Listening WAN address - if (address.is_tcp()) - { - if (address.is_ipv4()) - { - has_listening_tcp_ipv4 = true; - - std::shared_ptr descriptor; - - // We check if several descriptors share a WAN address. - // If so, we add a new port to the previously created descriptor. - bool same_wan_addr = false; - - auto it = params.userTransports.begin(); - while (it != params.userTransports.end()) - { - std::shared_ptr tmp_descriptor = - std::dynamic_pointer_cast(*it); - - if ((tmp_descriptor != nullptr) && (address.ip() == tmp_descriptor->get_WAN_address())) - { - // Save in the new descriptor the previously added descriptor with the same WAN address - descriptor = tmp_descriptor; - // Set that a descriptor with same WAN address was found - same_wan_addr = true; - // Remove the previously added descriptor as this will be replaced by the same one updated with - // more locators. - params.userTransports.erase(it); - break; - } - } - - // Add the new locator to the descriptor if another with the same wan address was found - if (same_wan_addr) - { - descriptor->add_listener_port(address.port()); - } - else - { - descriptor = std::make_shared(); - descriptor->add_listener_port(address.port()); - descriptor->set_WAN_address(address.ip()); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor); - } - - } - - params.userTransports.push_back(descriptor); - } - else - { - has_listening_tcp_ipv6 = true; - - std::shared_ptr descriptor = - std::make_shared(); - - descriptor->add_listener_port(address.port()); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor); - } - - params.userTransports.push_back(descriptor); - } - } - else - { - has_udp_ipv4 = address.is_ipv4(); - has_udp_ipv6 = !address.is_ipv4(); - } - - // For any, UDP or TCP - // Create Locator - eprosima::fastrtps::rtps::Locator_t locator; - locator.kind = address.get_locator_kind(); - - // IP - if (address.is_ipv4()) - { - eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, address.ip()); - eprosima::fastrtps::rtps::IPLocator::setWan(locator, address.ip()); - } - else - { - eprosima::fastrtps::rtps::IPLocator::setIPv6(locator, address.ip()); - } - - // Port - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, address.port()); - - if (address.is_tcp()) - { - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, address.external_port()); - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(locator, address.external_port()); - } - - // Add listening address to builtin - params.builtin.metatrafficUnicastLocatorList.push_back(locator); - params.defaultUnicastLocatorList.push_back(locator); - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Add listening address " << address << " to Participant " << configuration->id << "."); - } - - ///// - // Set connection addresses - for (types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses) - { - if (!connection_address.is_valid()) - { - // Invalid connection address, continue with next one - logWarning(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Discard connection address with remote server: " << - connection_address.discovery_server_guid_prefix() << - " in Participant " << configuration->id << " initialization."); - continue; - } - - // Set Server GUID - core::types::GuidPrefix server_prefix = connection_address.discovery_server_guid_prefix(); - - for (types::Address address : connection_address.addresses()) - { - if (!address.is_valid()) - { - // Invalid ip address, continue with next one - logWarning(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Discard connection address with remote server: " << - connection_address.discovery_server_guid_prefix() << - " due to invalid ip address " << address.ip() << " in Participant " << configuration->id << - " initialization."); - continue; - } - - has_connection_addresses = true; - - eprosima::fastrtps::rtps::RemoteServerAttributes server_attr; - server_attr.guidPrefix = server_prefix; - - eprosima::fastrtps::rtps::Locator_t locator; - - // KIND - locator.kind = address.get_locator_kind(); - - // In case it is TCP mark has_connection_tcp as true - if (address.is_tcp()) - { - has_connection_tcp_ipv4 = address.is_ipv4(); - has_connection_tcp_ipv6 = !address.is_ipv4(); - } - else - { - has_udp_ipv4 = address.is_ipv4(); - has_udp_ipv6 = !address.is_ipv4(); - } - - // IP - if (address.is_ipv4()) - { - eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, address.ip()); - } - else - { - eprosima::fastrtps::rtps::IPLocator::setIPv6(locator, address.ip()); - } - - // PORT - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, address.port()); - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(locator, address.port()); - // Warning: Logical port is not needed unless domain could change - - // Add as remote server and add it to builtin - server_attr.metatrafficUnicastLocatorList.push_back(locator); - params.builtin.discovery_config.m_DiscoveryServers.push_back(server_attr); - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Add connection address " << address << " for server " << server_prefix << - " to Participant " << configuration->id << "."); - } - } - - ///// - // Set this participant as a SERVER if has listening locators - if (has_listening_addresses) - { - params.builtin.discovery_config.discoveryProtocol = - fastrtps::rtps::DiscoveryProtocol::SERVER; - } - else - { - params.builtin.discovery_config.discoveryProtocol = - fastrtps::rtps::DiscoveryProtocol::SUPER_CLIENT; - - if (!has_connection_addresses) - { - logWarning(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Creating Participant " << configuration->id << " without listening or connection addresses. " << - "It will not communicate with any other Participant."); - } - } - - ///// - // Set Server Guid - params.prefix = discovery_server_guid_prefix; - - ///// - // Create specific descriptors if needed - - // If has TCP connections but not TCP listening addresses, it must specify the TCP transport - if (has_connection_tcp_ipv4 && !has_listening_tcp_ipv4) - { - std::shared_ptr descriptor = - std::make_shared(); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor, true); - } - - params.userTransports.push_back(descriptor); - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Adding TCPv4 Transport to Participant " << configuration->id << "."); - } - if (has_connection_tcp_ipv6 && !has_listening_tcp_ipv6) - { - std::shared_ptr descriptor = - std::make_shared(); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor, true); - } - - params.userTransports.push_back(descriptor); - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Adding TCPv6 Transport to Participant " << configuration->id << "."); - } - - // If has UDP, create descriptor because it has not been created yet - if (has_udp_ipv4) - { - std::shared_ptr descriptor = - std::make_shared(); - params.userTransports.push_back(descriptor); - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Adding UDPv4 Transport to Participant " << configuration->id << "."); - } - if (has_udp_ipv6) - { - std::shared_ptr descriptor_v6 = - std::make_shared(); - params.userTransports.push_back(descriptor_v6); - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Adding UDPv6 Transport to Participant " << configuration->id << "."); - } - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "Configured Participant " << configuration->id << " with server guid: " << - discovery_server_guid_prefix); - - return params; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp deleted file mode 100644 index 5a45d7e48..000000000 --- a/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright 2022 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. - -#include -#include -#include -#include - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -InitialPeersParticipant::InitialPeersParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database) - : CommonParticipant( - participant_configuration, - payload_pool, - discovery_database, - participant_configuration->domain, - reckon_participant_attributes_(participant_configuration.get())) -{ -} - -fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_participant_attributes_( - const InitialPeersParticipantConfiguration* configuration) -{ - // Use default as base attributes - fastrtps::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); - - // Auxiliary variable to save characters and improve readability - const auto& tls_config = configuration->tls_configuration; - - // Needed values to check at the end if descriptor must be set - bool has_listening_addresses = false; - bool has_listening_tcp_ipv4 = false; - bool has_listening_tcp_ipv6 = false; - bool has_connection_tcp_ipv4 = false; - bool has_connection_tcp_ipv6 = false; - bool has_connection_udp_ipv4 = false; - bool has_connection_udp_ipv6 = false; - bool has_udp_ipv4 = false; - bool has_udp_ipv6 = false; - - params.useBuiltinTransports = false; - - ///// - // Set listening addresses - for (const types::Address& address : configuration->listening_addresses) - { - if (!address.is_valid()) - { - // Invalid address, continue with next one - logWarning(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Discard listening address: " << address << - " in Participant " << configuration->id << " initialization."); - continue; - } - - has_listening_addresses = true; - - // TCP Listening WAN address - if (address.is_tcp()) - { - if (address.is_ipv4()) - { - has_listening_tcp_ipv4 = true; - - std::shared_ptr descriptor; - - // We check if several descriptors share a WAN address. - // If so, we add a new port to the previously created descriptor. - bool same_wan_addr = false; - - auto it = params.userTransports.begin(); - while (it != params.userTransports.end()) - { - std::shared_ptr tmp_descriptor = - std::dynamic_pointer_cast(*it); - - if ((tmp_descriptor != nullptr) && (address.ip() == tmp_descriptor->get_WAN_address())) - { - // Save in the new descriptor the previously added descriptor with the same WAN address - descriptor = tmp_descriptor; - // Set that a descriptor with same WAN address was found - same_wan_addr = true; - // Remove the previously added descriptor as this will be replaced by the same one updated with - // more locators. - params.userTransports.erase(it); - break; - } - } - - // Add the new locator to the descriptor if another with the same wan address was found - if (same_wan_addr) - { - descriptor->add_listener_port(address.port()); - } - else - { - descriptor = std::make_shared(); - descriptor->add_listener_port(address.port()); - descriptor->set_WAN_address(address.ip()); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor); - } - - } - - params.userTransports.push_back(descriptor); - } - else - { - has_listening_tcp_ipv6 = true; - - std::shared_ptr descriptor = - std::make_shared(); - - descriptor->add_listener_port(address.port()); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor); - } - - params.userTransports.push_back(descriptor); - } - } - else - { - has_udp_ipv4 = address.is_ipv4(); - has_udp_ipv6 = !address.is_ipv4(); - } - - // For any, UDP or TCP - // Create Locator - eprosima::fastrtps::rtps::Locator_t locator; - locator.kind = address.get_locator_kind(); - - // IP - if (address.is_ipv4()) - { - eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, address.ip()); - eprosima::fastrtps::rtps::IPLocator::setWan(locator, address.ip()); - } - else - { - eprosima::fastrtps::rtps::IPLocator::setIPv6(locator, address.ip()); - } - - // Set Logical port for every locator - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, address.port()); - - // In TCP case, set Physical port - if (address.is_tcp()) - { - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, address.external_port()); - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(locator, address.external_port()); - } - - // Add listening address to builtin - params.builtin.metatrafficUnicastLocatorList.push_back(locator); - params.defaultUnicastLocatorList.push_back(locator); - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Add listening address " << address << " to Participant " << configuration->id << "."); - } - - ///// - // Set connection addresses - for (const types::Address& connection_address : configuration->connection_addresses) - { - if (!connection_address.is_valid()) - { - // Invalid connection address, continue with next one - logWarning(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Discard connection address: " << connection_address << - " in Participant " << configuration->id << " initialization."); - continue; - } - - // Create Locator for connection initial peers - eprosima::fastrtps::rtps::Locator_t locator; - - // KIND - locator.kind = connection_address.get_locator_kind(); - - // In case it is TCP mark has_connection_tcp as true - if (connection_address.is_tcp()) - { - has_connection_tcp_ipv4 = connection_address.is_ipv4(); - has_connection_tcp_ipv6 = !connection_address.is_ipv4(); - } - else - { - has_connection_udp_ipv4 = connection_address.is_ipv4(); - has_connection_udp_ipv6 = !connection_address.is_ipv4(); - has_udp_ipv4 = connection_address.is_ipv4(); - has_udp_ipv6 = !connection_address.is_ipv4(); - } - - // IP - if (connection_address.is_ipv4()) - { - eprosima::fastrtps::rtps::IPLocator::setIPv4(locator, connection_address.ip()); - } - else - { - eprosima::fastrtps::rtps::IPLocator::setIPv6(locator, connection_address.ip()); - } - - // Set Logical port for every locator - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(locator, connection_address.port()); - - // In TCP case, set Physical port - if (connection_address.is_tcp()) - { - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(locator, connection_address.port()); - } - - // Add it to builtin - params.builtin.initialPeersList.push_back(locator); - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Add connection address " << connection_address << - " to Participant " << configuration->id << "."); - } - - ///// - // Create specific descriptors if needed - - // If has TCP connections but not TCP listening addresses, it must specify the TCP transport - if (has_connection_tcp_ipv4 && !has_listening_tcp_ipv4) - { - std::shared_ptr descriptor = - std::make_shared(); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor, true); - } - - params.userTransports.push_back(descriptor); - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Adding TCPv4 Transport to Participant " << configuration->id << "."); - } - - if (has_connection_tcp_ipv6 && !has_listening_tcp_ipv6) - { - std::shared_ptr descriptor = - std::make_shared(); - - // Enable TLS - if (tls_config.is_active()) - { - tls_config.enable_tls(descriptor, true); - } - - params.userTransports.push_back(descriptor); - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Adding TCPv6 Transport to Participant " << configuration->id << "."); - } - - // If has UDP, create descriptor because it has not been created yet - if (has_udp_ipv4) - { - std::shared_ptr descriptor = - std::make_shared(); - params.userTransports.push_back(descriptor); - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Adding UDPv4 Transport to Participant " << configuration->id << "."); - } - - if (has_udp_ipv6) - { - std::shared_ptr descriptor_v6 = - std::make_shared(); - params.userTransports.push_back(descriptor_v6); - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Adding UDPv6 Transport to Participant " << configuration->id << "."); - } - - // To avoid creating a multicast transport in UDP when non listening addresses - // Fast requires an empty locator that will be set by default afterwards - if (!has_listening_addresses) - { - if (has_connection_udp_ipv4) - { - eprosima::fastrtps::rtps::Locator_t locator; - locator.kind = LOCATOR_KIND_UDPv4; - params.builtin.metatrafficUnicastLocatorList.push_back(locator); - } - - if (has_connection_udp_ipv6) - { - eprosima::fastrtps::rtps::Locator_t locator; - locator.kind = LOCATOR_KIND_UDPv6; - params.builtin.metatrafficUnicastLocatorList.push_back(locator); - } - } - - logDebug(DDSROUTER_INITIALPEERS_PARTICIPANT, - "Configured Participant " << configuration->id); - - return params; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp deleted file mode 100644 index e8745d7ee..000000000 --- a/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -SimpleParticipant::SimpleParticipant( - const std::shared_ptr& participant_configuration, - const std::shared_ptr& payload_pool, - const std::shared_ptr& discovery_database) - : CommonParticipant( - participant_configuration, - payload_pool, - discovery_database, - participant_configuration->domain, - CommonParticipant::reckon_participant_attributes_(participant_configuration.get())) -{ -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp b/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp deleted file mode 100644 index 86e6765a5..000000000 --- a/ddspipe_participants/src/cpp/reader/auxiliar/BaseReader.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -const std::function BaseReader::DEFAULT_ON_DATA_AVAILABLE_CALLBACK = - []() - { - logDevError(DDSROUTER_READER, "Calling unset callback"); - }; - -BaseReader::BaseReader( - const core::types::ParticipantId& participant_id, - const std::shared_ptr& payload_pool) - : participant_id_(participant_id) - , payload_pool_(payload_pool) - , on_data_available_lambda_(DEFAULT_ON_DATA_AVAILABLE_CALLBACK) - , on_data_available_lambda_set_(false) - , enabled_(false) -{ - logDebug(DDSROUTER_BASEREADER, "Creating Reader " << *this << "."); -} - -void BaseReader::enable() noexcept -{ - std::lock_guard lock(mutex_); - - // If it is enabled, do nothing - if (!enabled_.load()) - { - enabled_.store(true); - - // Call specific enable - enable_nts_(); - } -} - -void BaseReader::disable() noexcept -{ - std::lock_guard lock(mutex_); - - // If it is not enabled, do nothing - if (enabled_.load()) - { - enabled_.store(false); - - // Call specific disable - disable_nts_(); - } -} - -void BaseReader::set_on_data_available_callback( - std::function on_data_available_lambda) noexcept -{ - std::lock_guard lock(mutex_); - - if (on_data_available_lambda_set_) - { - logDevError(DDSROUTER_BASEREADER, "Changing on_data_available callback for Reader in Participant " << participant_id_); - } - - on_data_available_lambda_ = on_data_available_lambda; - on_data_available_lambda_set_ = true; -} - -void BaseReader::unset_on_data_available_callback() noexcept -{ - std::lock_guard lock(mutex_); - - if (!on_data_available_lambda_set_) - { - logDevError(DDSROUTER_BASEREADER, "Unsetting a non set on_data_available callback for Reader in Participant " << participant_id_); - } - - on_data_available_lambda_ = DEFAULT_ON_DATA_AVAILABLE_CALLBACK; - on_data_available_lambda_set_ = false; -} - -utils::ReturnCode BaseReader::take( - std::unique_ptr& data) noexcept -{ - std::lock_guard lock(mutex_); - - if (enabled_.load()) - { - return take_nts_(data); - } - else - { - logDevError(DDSROUTER_BASEREADER, "Attempt to take data from disabled Reader in Participant " << participant_id_); - return utils::ReturnCode::RETCODE_NOT_ENABLED; - } -} - -core::types::ParticipantId BaseReader::participant_id() const noexcept -{ - return participant_id_; -} - -void BaseReader::on_data_available_() const noexcept -{ - if (on_data_available_lambda_set_) - { - on_data_available_lambda_(); - } - else - { - logDevError(DDSROUTER_BASEREADER, "Calling not set on_data_available callback for Reader in Participant " << participant_id_); - } -} - -void BaseReader::enable_nts_() noexcept -{ - // It does nothing. Override this method so it has functionality. -} - -void BaseReader::disable_nts_() noexcept -{ - // It does nothing. Override this method so it has functionality. -} - -std::ostream& operator <<( - std::ostream& os, - const BaseReader& reader) -{ - os << "Reader{" << reader.participant_id_ << "}"; - return os; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp b/ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp deleted file mode 100644 index 1f824b10d..000000000 --- a/ddspipe_participants/src/cpp/reader/auxiliar/BlankReader.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021 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. - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -void BlankReader::enable() noexcept -{ -} - -void BlankReader::disable() noexcept -{ -} - -void BlankReader::set_on_data_available_callback( - std::function) noexcept -{ -} - -void BlankReader::unset_on_data_available_callback() noexcept -{ -} - -utils::ReturnCode BlankReader::take( - std::unique_ptr& /* data */) noexcept -{ - return utils::ReturnCode::RETCODE_NO_DATA; -} - -core::types::Guid BlankReader::guid() const -{ - throw utils::UnsupportedException("guid method not allowed for non RTPS readers."); -} - -fastrtps::RecursiveTimedMutex& BlankReader::get_rtps_mutex() const -{ - throw utils::UnsupportedException("get_rtps_mutex method not allowed for non RTPS readers."); -} - -uint64_t BlankReader::get_unread_count() const -{ - throw utils::UnsupportedException("get_unread_count method not allowed for non RTPS readers."); -} - -core::types::DdsTopic BlankReader::topic() const -{ - throw utils::UnsupportedException("topic method not allowed for non RTPS readers."); -} - -core::types::ParticipantId BlankReader::participant_id() const -{ - throw utils::UnsupportedException("participant_id method not allowed for non RTPS readers."); -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp b/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp deleted file mode 100644 index c528aa73b..000000000 --- a/ddspipe_participants/src/cpp/reader/rpc/SimpleReader.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rpc { - -SimpleReader::SimpleReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant) - : CommonReader( - participant_id, topic, payload_pool, rtps_participant, - reckon_history_attributes_(topic), - reckon_reader_attributes_(topic), - reckon_topic_attributes_(topic), - reckon_reader_qos_(topic)) -{ - logInfo(DDSROUTER_RPC_READER, "Creating RPC Reader for topic " << topic_); -} - -//! Override Parent method to create an RPC data type. -core::types::RtpsPayloadData* SimpleReader::create_data_( - const fastrtps::rtps::CacheChange_t& received_change) const noexcept -{ - return new core::types::RpcPayloadData(); -} - -//! Override Parent method to fill fields exclusive from RPC. -void SimpleReader::fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change, - core::types::RtpsPayloadData& data_to_fill) const noexcept -{ - CommonReader::fill_received_data_(received_change, data_to_fill); - - // Get internal RpcPayload - core::types::RpcPayloadData& rpc_data = dynamic_cast(data_to_fill); - // Set write params and origin sequence number - rpc_data.write_params.set_value(received_change.write_params); - rpc_data.origin_sequence_number = received_change.sequenceNumber; -} - -} /* namespace rpc */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp deleted file mode 100644 index 7fa32e9cb..000000000 --- a/ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -using namespace eprosima::ddspipe::core::types; -using eprosima::ddspipe::core::types::operator<<; - -CommonReader::CommonReader( - const ParticipantId& participant_id, - const DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::ReaderAttributes& reader_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::ReaderQos& reader_qos) - : BaseReader(participant_id, payload_pool) - , topic_(topic) - , rtps_participant_(rtps_participant) - , history_attributes_(history_attributes) - , reader_attributes_(reader_attributes) - , topic_attributes_(topic_attributes) - , reader_qos_(reader_qos) -{ - // Do nothing -} - -CommonReader::~CommonReader() -{ - // This variables should be set, otherwise the creation should have fail - // Anyway, the if case is used for safety reasons - - // Delete reader - if (rtps_reader_) - { - // Unset listener before destruction (not necessary in principle, but just in case) - rtps_reader_->setListener(nullptr); - fastrtps::rtps::RTPSDomain::removeRTPSReader(rtps_reader_); - } - - // Delete History - if (rtps_history_) - { - delete rtps_history_; - } - - logInfo(DDSROUTER_RTPS_READER, "Deleting CommonReader created in Participant " << - participant_id_ << " for topic " << topic_); -} - -void CommonReader::init() -{ - internal_entities_creation_( - history_attributes_, - reader_attributes_, - topic_attributes_, - reader_qos_); -} - -void CommonReader::internal_entities_creation_( - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::ReaderAttributes& reader_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::ReaderQos& reader_qos) -{ - // Copy reader attributes because fast needs it non const (do not ask why) - fastrtps::rtps::ReaderAttributes non_const_reader_attributes = reader_attributes; - - // Create History - rtps_history_ = new fastrtps::rtps::ReaderHistory(history_attributes); - - // Create CommonReader - // Listener must be set in creation as no callbacks should be missed - // It is safe to do so here as object is already created and callbacks do not require anything set in this method - rtps_reader_ = fastrtps::rtps::RTPSDomain::createRTPSReader( - rtps_participant_, - non_const_reader_attributes, - payload_pool_, - rtps_history_, - this); - - if (!rtps_reader_) - { - throw utils::InitializationException( - utils::Formatter() << "Error creating Simple RTPSReader for Participant " << - participant_id_ << " in topic " << topic_ << "."); - } - - // Set listener after entity creation to avoid SEGFAULT (produced when callback using rtps_reader_ is - // invoked before the variable is fully set) - rtps_reader_->setListener(this); - - // Register reader with topic - if (!rtps_participant_->registerReader(rtps_reader_, topic_attributes, reader_qos)) - { - // In case it fails, remove reader and throw exception - fastrtps::rtps::RTPSDomain::removeRTPSReader(rtps_reader_); - throw utils::InitializationException(utils::Formatter() << "Error registering topic " << topic_ << - " for Simple RTPSReader in Participant " << participant_id_); - } - - logInfo(DDSROUTER_RTPS_READER, "New CommonReader created in Participant " << participant_id_ << " for topic " << - topic_ << " with guid " << rtps_reader_->getGuid()); -} - -core::types::Guid CommonReader::guid() const noexcept -{ - return rtps_reader_->getGuid(); -} - -fastrtps::RecursiveTimedMutex& CommonReader::get_rtps_mutex() const noexcept -{ - return rtps_reader_->getMutex(); -} - -uint64_t CommonReader::get_unread_count() const noexcept -{ - return rtps_reader_->get_unread_count(); -} - -core::types::DdsTopic CommonReader::topic() const noexcept -{ - return topic_; -} - -utils::ReturnCode CommonReader::take_nts_( - std::unique_ptr& data) noexcept -{ - // Check if there is data available - if (!(rtps_reader_->get_unread_count() > 0)) - { - return utils::ReturnCode::RETCODE_NO_DATA; - } - - fastrtps::rtps::CacheChange_t* received_change = nullptr; - fastrtps::rtps::WriterProxy* wp = nullptr; - - // Read first change of the history - if (!rtps_reader_->nextUntakenCache(&received_change, &wp)) - { - // Error reading. - return utils::ReturnCode::RETCODE_ERROR; - } - - // If data received is not correct, discard it and remove it from history - auto ret = is_data_correct_(received_change); - if (!ret) - { - // Remove the change in the History and release it in the reader - rtps_reader_->getHistory()->remove_change(received_change); - return ret; - } - - // Store the new data that has arrived in the Track data - auto data_ptr = create_data_(*received_change); - fill_received_data_(*received_change, *data_ptr); - data.reset(data_ptr); - - // Remove the change in the History and release it in the reader - rtps_reader_->getHistory()->remove_change(received_change); - - return utils::ReturnCode::RETCODE_OK; -} - -RtpsPayloadData* CommonReader::create_data_( - const fastrtps::rtps::CacheChange_t& received_change) const noexcept -{ - return new RtpsPayloadData(); -} - -void CommonReader::fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change, - RtpsPayloadData& data_to_fill) const noexcept -{ - // Store the new data that has arrived in the Track data - // Get the writer guid - data_to_fill.source_guid = received_change.writerGUID; - // Get source timestamp - data_to_fill.source_timestamp = received_change.sourceTimestamp; - // Get Participant receiver - data_to_fill.participant_receiver = participant_id_; - - // Store it in DDSRouter PayloadPool if size is bigger than 0 - // NOTE: in case of keyed topics an empty payload is possible - if (received_change.serializedPayload.length > 0) - { - eprosima::fastrtps::rtps::IPayloadPool* payload_owner = const_cast(received_change.payload_owner()); - payload_pool_->get_payload( - received_change.serializedPayload, - payload_owner, - data_to_fill.payload); - - data_to_fill.payload_owner = payload_pool_.get(); - } - - // Set Instance Handle to data_to_fill - if (topic_.topic_qos.keyed) - { - data_to_fill.instanceHandle = received_change.instanceHandle; - } - - // Set change kind - data_to_fill.kind = received_change.kind; - - // Note: do not fill writer specific properties in this data_to_fill from this kind of Readers. - // Implement specific class for filling it. - - logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Data transmiting to track from Reader " << *this << " with payload " << - data_to_fill.payload << " from remote writer " << data_to_fill.source_guid); - -} - -void CommonReader::enable_() noexcept -{ - // If the topic is reliable, the reader will keep the samples received when it was disabled. - // However, if the topic is best_effort, the reader will discard the samples received when it was disabled. - if (topic_.topic_qos.is_reliable()) - { - std::lock_guard lock(get_rtps_mutex()); - on_data_available_(); - } -} - -bool CommonReader::come_from_this_participant_( - const fastrtps::rtps::CacheChange_t* change) const noexcept -{ - return come_from_this_participant_(change->writerGUID); -} - -bool CommonReader::come_from_this_participant_( - const fastrtps::rtps::GUID_t guid) const noexcept -{ - return guid.guidPrefix == rtps_reader_->getGuid().guidPrefix; -} - -fastrtps::rtps::HistoryAttributes CommonReader::reckon_history_attributes_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::rtps::HistoryAttributes att; - att.memoryPolicy = - eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - - att.maximumReservedCaches = topic.topic_qos.history_depth; - - return att; -} - -fastrtps::rtps::ReaderAttributes CommonReader::reckon_reader_attributes_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::rtps::ReaderAttributes att; - - // Set Durability - att.endpoint.durabilityKind = topic.topic_qos.durability_qos; - - // Set Reliability - att.endpoint.reliabilityKind = topic.topic_qos.reliability_qos; - - // Set if topic has key - if (topic.topic_qos.keyed) - { - att.endpoint.topicKind = eprosima::fastrtps::rtps::WITH_KEY; - } - else - { - att.endpoint.topicKind = eprosima::fastrtps::rtps::NO_KEY; - } - - // Ownership and Partitions are not part of RTPS, thus they are set in properties - - return att; -} - -fastrtps::TopicAttributes CommonReader::reckon_topic_attributes_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::TopicAttributes att; - - // Set if topic has key - if (topic.topic_qos.keyed) - { - att.topicKind = eprosima::fastrtps::rtps::WITH_KEY; - } - else - { - att.topicKind = eprosima::fastrtps::rtps::NO_KEY; - } - - // Set Topic attributes - att.topicName = topic.m_topic_name; - att.topicDataType = topic.type_name; - - // Set Topic history attributes - att.historyQos.kind = eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS; - att.historyQos.depth = topic.topic_qos.history_depth; - - return att; -} - -fastrtps::ReaderQos CommonReader::reckon_reader_qos_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::ReaderQos properties; - - // Set Durability - properties.m_durability.kind = - (topic.topic_qos.is_transient_local() - ? eprosima::fastdds::dds::DurabilityQosPolicyKind_t::TRANSIENT_LOCAL_DURABILITY_QOS - : eprosima::fastdds::dds::DurabilityQosPolicyKind_t::VOLATILE_DURABILITY_QOS); - - // Set Reliability - properties.m_reliability.kind = - (topic.topic_qos.is_reliable() - ? eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS - : eprosima::fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS); - - // If topic with partitions, set this CommonReader in * - if (topic.topic_qos.use_partitions) - { - properties.m_partition.push_back("*"); - } - - // If topic is with ownership - properties.m_ownership.kind = topic.topic_qos.ownership_qos; - - return properties; -} - -void CommonReader::onNewCacheChangeAdded( - fastrtps::rtps::RTPSReader* reader, - const fastrtps::rtps::CacheChange_t* const change) noexcept -{ - if (!come_from_this_participant_(change)) - { - // Do not remove previous received changes so they can be read when the reader is enabled - if (enabled_) - { - // Call Track callback (by calling BaseReader callback method) - // TODO (paris) Uncomment - // logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, - // "Data arrived to Reader " << *this << " with payload " << change->serializedPayload << " from " << - // change->writerGUID); - on_data_available_(); - } - else - { - // Remove received change if the CommonReader is disbled and the topic is not reliable - // NOTE: this should be is_reliable and not is_transient_local for RPC sake - if (!topic_.topic_qos.is_reliable()) - { - reader->getHistory()->remove_change((fastrtps::rtps::CacheChange_t*)change); - logDebug(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Change removed from history"); - } - } - } - else - { - logWarning( - DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Ignoring data from this same Participant in reader " << *this << "."); - - // If it is a message from this Participant, do not send it forward and remove it - // TODO: do this more elegant - reader->getHistory()->remove_change((fastrtps::rtps::CacheChange_t*)change); - } -} - -void CommonReader::onReaderMatched( - fastrtps::rtps::RTPSReader*, - fastrtps::rtps::MatchingInfo& info) noexcept -{ - if (!come_from_this_participant_(info.remoteEndpointGuid)) - { - if (info.status == fastrtps::rtps::MatchingStatus::MATCHED_MATCHING) - { - logInfo(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Reader " << *this << " matched with a new Writer with guid " << info.remoteEndpointGuid); - } - else - { - logInfo(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Reader " << *this << " unmatched with Writer " << info.remoteEndpointGuid); - } - } -} - -utils::ReturnCode CommonReader::is_data_correct_( - const fastrtps::rtps::CacheChange_t* received_change) const noexcept -{ - // Check that the guid is consistent - if (received_change->writerGUID == fastrtps::rtps::GUID_t::unknown()) - { - logWarning(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Error taking data without correct writer GUID."); - - return utils::ReturnCode::RETCODE_ERROR; - } - - // Check that the data is consistent - if (!(received_change->serializedPayload.max_size > 0)) - { - // Data with 0 bytes is only correct if keyed topic and if data is being disposed - if (!(topic_.topic_qos.keyed && received_change->kind != eprosima::fastrtps::rtps::ChangeKind_t::ALIVE)) - { - logWarning(DDSROUTER_RTPS_COMMONREADER_LISTENER, - "Error taking data with length " << received_change->serializedPayload.length << "."); - - return utils::ReturnCode::RETCODE_ERROR; - } - } - - return utils::ReturnCode::RETCODE_OK; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp deleted file mode 100644 index 5f80bdaad..000000000 --- a/ddspipe_participants/src/cpp/reader/rtps/SimpleReader.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -SimpleReader::SimpleReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant) - : CommonReader( - participant_id, topic, payload_pool, rtps_participant, - reckon_history_attributes_(topic), - reckon_reader_attributes_(topic), - reckon_topic_attributes_(topic), - reckon_reader_qos_(topic)) -{ -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp b/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp deleted file mode 100644 index b1a8ec7e8..000000000 --- a/ddspipe_participants/src/cpp/reader/rtps/SpecificQoSReader.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2021 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. - - -#include -#include - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -SpecificQoSReader::SpecificQoSReader( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const std::shared_ptr& discovery_database) - : CommonReader( - participant_id, topic, payload_pool, rtps_participant, - reckon_history_attributes_(topic), - reckon_reader_attributes_(topic), - reckon_topic_attributes_(topic), - reckon_reader_qos_(topic)) - , discovery_database_(discovery_database) -{ -} - -core::types::SpecificEndpointQoS SpecificQoSReader::specific_qos_of_writer_( - const core::types::Guid& guid) const -{ - return discovery_database_->get_endpoint(guid).specific_qos; -} - -void SpecificQoSReader::fill_received_data_( - const fastrtps::rtps::CacheChange_t& received_change, - core::types::RtpsPayloadData& data_to_fill) const noexcept -{ - CommonReader::fill_received_data_(received_change, data_to_fill); - - // Find qos of writer - try - { - data_to_fill.writer_qos = specific_qos_of_writer_(data_to_fill.source_guid); - logDebug( - DDSROUTER_SpecificQoSReader, - "Set QoS " << data_to_fill.writer_qos << " for data from " << data_to_fill.source_guid << "."); - } - catch (const utils::InconsistencyException& e) - { - // Get a message from a writer not in database, this is an error. - // Remove data and make as it has not been received. - logError( - DDSROUTER_SpecificQoSReader, - "Received a message from Writer " << data_to_fill.source_guid << " that is not stored in DB."); - } -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/testing/random_values.cpp b/ddspipe_participants/src/cpp/testing/random_values.cpp deleted file mode 100644 index 2154b0cce..000000000 --- a/ddspipe_participants/src/cpp/testing/random_values.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 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. - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace testing { - -using namespace eprosima::ddspipe::participants::types; - -Address random_address( - unsigned int seed /* = 0 */) -{ - return Address("127.0.0.1", seed, seed, TransportProtocol::udp); -} - -DiscoveryServerConnectionAddress random_connection_address( - unsigned int seed /* = 0 */, - unsigned int size /* = 1 */, - bool ros /* = false */) -{ - std::set
addresses; - for (unsigned int i = 0; i < size; ++i) - { - addresses.insert( - random_address((seed + i))); - } - - return DiscoveryServerConnectionAddress( - core::testing::random_guid_prefix(seed, ros), - addresses - ); -} - -} /* namespace testing */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/types/address/Address.cpp b/ddspipe_participants/src/cpp/types/address/Address.cpp deleted file mode 100644 index 780be65c0..000000000 --- a/ddspipe_participants/src/cpp/types/address/Address.cpp +++ /dev/null @@ -1,438 +0,0 @@ -// Copyright 2021 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. - -#include - -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -const PortType Address::DEFAULT_PORT_ = 11666; -const IpType Address::DEFAULT_IP_v4_ = "127.0.0.1"; -const IpType Address::DEFAULT_IP_v6_ = "::1"; -const IpVersion Address::DEFAULT_IP_VERSION_ = IpVersion::v4; -const TransportProtocol Address::DEFAULT_TRANSPORT_PROTOCOL_ = TransportProtocol::udp; - -Address::Address() - : Address(DEFAULT_IP_v4_, DEFAULT_PORT_, DEFAULT_PORT_, DEFAULT_IP_VERSION_, DEFAULT_TRANSPORT_PROTOCOL_) -{ -} - -Address::Address( - const IpType& ip, - const PortType& port, - const PortType& external_port, - const IpVersion& ip_version, - const TransportProtocol& transport_protocol) noexcept - : ip_(ip) - , domain_() - , has_domain_(false) - , has_valid_domain_(false) - , port_(port) - , external_port_(external_port) - , ip_version_(ip_version) - , transport_protocol_(transport_protocol) -{ -} - -Address::Address( - const PortType& port, - const PortType& external_port, - const IpVersion& ip_version, - const DomainType& domain, - const TransportProtocol& transport_protocol) noexcept - : ip_() - , domain_(domain) - , has_domain_(true) - , has_valid_domain_(false) - , port_(port) - , external_port_(external_port) - , ip_version_(ip_version) - , transport_protocol_(transport_protocol) -{ - try - { - ip_ = Address::resolve_dns(domain_, ip_version_); - has_valid_domain_ = true; - } - catch (const utils::DNSException& ) - { - logWarning( - DDSROUTER_ADDRESS, "Address created without IP because given domain " << domain << " was not found."); - } -} - -Address::Address( - const IpType& ip, - const PortType& port, - const PortType& external_port, - const TransportProtocol& transport_protocol) noexcept - : Address(ip, port, external_port, IpVersion::v4, transport_protocol) -{ - if (is_ipv6_correct(ip_)) - { - ip_version_ = IpVersion::v6; - } -} - -Address::Address( - const PortType& port, - const PortType& external_port, - const DomainType& domain, - const TransportProtocol& transport_protocol) noexcept - : ip_() - , domain_(domain) - , has_domain_(true) - , has_valid_domain_(false) - , port_(port) - , external_port_(external_port) - , transport_protocol_(transport_protocol) -{ - try - { - auto dns_respone = Address::resolve_dns(domain_); - ip_ = dns_respone.first; - ip_version_ = dns_respone.second; - has_valid_domain_ = true; - } - catch (const utils::DNSException& ) - { - logWarning( - DDSROUTER_ADDRESS, "Address created without IP because given domain " << domain << " was not found."); - } -} - -PortType Address::port() const noexcept -{ - return port_; -} - -PortType Address::external_port() const noexcept -{ - return external_port_; -} - -IpType Address::ip() const noexcept -{ - return ip_; -} - -IpVersion Address::ip_version() const noexcept -{ - return ip_version_; -} - -TransportProtocol Address::transport_protocol() const noexcept -{ - return transport_protocol_; -} - -bool Address::is_udp() const noexcept -{ - return transport_protocol_ == TransportProtocol::udp; -} - -bool Address::is_tcp() const noexcept -{ - return transport_protocol_ == TransportProtocol::tcp; -} - -bool Address::is_ipv4() const noexcept -{ - return ip_version_ == IpVersion::v4; -} - -bool Address::is_ipv6() const noexcept -{ - return ip_version_ == IpVersion::v6; -} - -LocatorType Address::get_locator_kind() const noexcept -{ - if (ip_version_ == IpVersion::v4) - { - if (transport_protocol_ == TransportProtocol::udp) - { - return LOCATOR_KIND_UDPv4; - } - else if (transport_protocol_ == TransportProtocol::tcp) - { - return LOCATOR_KIND_TCPv4; - } - } - else if (ip_version_ == IpVersion::v6) - { - if (transport_protocol_ == TransportProtocol::udp) - { - return LOCATOR_KIND_UDPv6; - } - else if (transport_protocol_ == TransportProtocol::tcp) - { - return LOCATOR_KIND_TCPv6; - } - } - - return LOCATOR_KIND_INVALID; -} - -bool Address::is_valid() const noexcept -{ - if (has_domain_ && !has_valid_domain_) - { - return false; - } - - // Check that if UDP, external port must be not set (must be equal to internal port) - if (is_udp()) - { - if (port_ != external_port_) - { - return false; - } - } - - // Check correct ip - switch (ip_version_) - { - case IpVersion::v4: - return is_ipv4_correct(ip_); - - case IpVersion::v6: - return is_ipv6_correct(ip_); - - default: - utils::tsnh( - utils::Formatter() << "Ip version value out of IpVersion."); - return false; // Unreachable code - } -} - -bool Address::operator <( - const Address& other) const noexcept -{ - // Compare IPs - int ip_comparison = this->ip_.compare(other.ip_); - if (ip_comparison < 0) - { - return true; - } - else if (ip_comparison > 0) - { - return false; - } - else - { - // Compare Ports - if (this->port_ < other.port_) - { - return true; - } - else if (this->port_ > other.port_) - { - return false; - } - else - { - // Compare Protocol - if (this->transport_protocol_ < other.transport_protocol_) - { - return true; - } - else if (this->transport_protocol_ > other.transport_protocol_) - { - return false; - } - else - { - // Compare Ip Version - return this->ip_version_ < other.ip_version_; - } - } - } -} - -bool Address::operator ==( - const Address& other) const noexcept -{ - return this->ip() == other.ip() && - this->port() == other.port() && - this->transport_protocol() == other.transport_protocol() && - this->is_valid() == other.is_valid(); -} - -bool Address::is_ipv4_correct( - const IpType& ip) noexcept -{ - return eprosima::fastrtps::rtps::IPLocator::isIPv4(ip); -} - -bool Address::is_ipv6_correct( - const IpType& ip) noexcept -{ - return eprosima::fastrtps::rtps::IPLocator::isIPv6(ip); -} - -PortType Address::default_port() noexcept -{ - return DEFAULT_PORT_; -} - -IpType Address::default_ip( - IpVersion ip_version /* = default_ip_version() */) noexcept -{ - if (ip_version == IpVersion::v4) - { - return DEFAULT_IP_v4_; - } - else if (ip_version == IpVersion::v6) - { - return DEFAULT_IP_v6_; - } - else - { - utils::tsnh(utils::Formatter() << "Value v" << static_cast(ip_version) << - " is not allowed for IpVersion."); - return DEFAULT_IP_v4_; - } -} - -IpVersion Address::default_ip_version() noexcept -{ - return DEFAULT_IP_VERSION_; -} - -TransportProtocol Address::default_transport_protocol() noexcept -{ - return DEFAULT_TRANSPORT_PROTOCOL_; -} - -IpType Address::resolve_dns( - DomainType domain, - IpVersion ip_version) -{ - std::pair, std::set> dns_response = - fastrtps::rtps::IPLocator::resolveNameDNS(domain); - - if (ip_version == IpVersion::v4) - { - if (dns_response.first.empty()) - { - throw utils::DNSException( - utils::Formatter() << "Could not resolve IpVersion::v4 for domain name <" << domain << ">."); - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v4: " << dns_response.first.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << dns_response.first.size() << " valid IPs."); - return dns_response.first.begin()->data(); - } - } - else - { - if (dns_response.second.empty()) - { - throw utils::DNSException( - utils::Formatter() << "Could not resolve IpVersion::v6 for domain name <" << domain << ">."); - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v6: " << dns_response.second.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << dns_response.second.size() << " valid IPs."); - return dns_response.second.begin()->data(); - } - } -} - -std::pair Address::resolve_dns( - DomainType domain) -{ - std::pair, std::set> dns_response = - fastrtps::rtps::IPLocator::resolveNameDNS(domain); - - if (dns_response.first.empty()) - { - if (dns_response.second.empty()) - { - throw utils::DNSException( - utils::Formatter() << - "Could not resolve IP for IpVersion::v4 nor IpVersion::v6 for domain name <" << domain << - ">."); - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v6: " << dns_response.second.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << dns_response.second.size() << " valid IPs."); - return {dns_response.second.begin()->data(), IpVersion::v6}; - } - } - else - { - logInfo( - DDSROUTER_ADDRESS, - "Getting first IpVersion::v4: " << dns_response.first.begin()->data() << - " for Domain name: " << domain << - " from DNS response from " << (dns_response.first.size() + dns_response.second.size()) << - " valid IPs."); - return {dns_response.first.begin()->data(), IpVersion::v4}; - } -} - -std::ostream& operator <<( - std::ostream& output, - const Address& address) -{ - output << "{"; - - if (address.has_domain_) - { - output << address.domain_ << "(" << address.ip() << ");"; - } - else - { - output << address.ip() << ";"; - } - output << address.port() << ";"; - - if (address.is_udp()) - { - output << "udp}"; - } - else - { - // TODO change for else if cause there may be more transports - output << "tcp}"; - } - - return output; -} - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp b/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp deleted file mode 100644 index d23de30cd..000000000 --- a/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2021 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. - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -DiscoveryServerConnectionAddress::DiscoveryServerConnectionAddress( - core::types::GuidPrefix discovery_server_guid, - std::set
addresses) - : discovery_server_guid_prefix_(discovery_server_guid) - , addresses_(addresses) -{ -} - -core::types::GuidPrefix DiscoveryServerConnectionAddress::discovery_server_guid_prefix() const noexcept -{ - return discovery_server_guid_prefix_; -} - -std::set
DiscoveryServerConnectionAddress::addresses() const noexcept -{ - return addresses_; -} - -bool DiscoveryServerConnectionAddress::is_valid() const noexcept -{ - if (!discovery_server_guid_prefix_.is_valid()) - { - return false; - } - - for (auto address : addresses_) - { - if (address.is_valid()) - { - return true; - } - } - - return false; -} - -bool DiscoveryServerConnectionAddress::operator <( - const DiscoveryServerConnectionAddress& other) const noexcept -{ - if (this->discovery_server_guid_prefix() == other.discovery_server_guid_prefix()) - { - // Same Guid - return this->addresses() < other.addresses(); - } - else - { - // Different guid - return this->discovery_server_guid_prefix() < other.discovery_server_guid_prefix(); - } -} - -bool DiscoveryServerConnectionAddress::operator ==( - const DiscoveryServerConnectionAddress& other) const noexcept -{ - return (this->discovery_server_guid_prefix() == other.discovery_server_guid_prefix()) && - (this->addresses() == other.addresses()); -} - -std::ostream& operator <<( - std::ostream& output, - const DiscoveryServerConnectionAddress& address) -{ - output << "{{" << address.discovery_server_guid_prefix() << "}["; - for (auto a : address.addresses()) - { - output << a << ","; - } - output << "]}"; - return output; -} - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp b/ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp deleted file mode 100644 index 8ccbae2f0..000000000 --- a/ddspipe_participants/src/cpp/types/security/tls/TlsConfiguration.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2022 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. - -#include -#include -#include -#include -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -bool TlsConfiguration::is_active() const noexcept -{ - return this->kind != TlsKind::inactive; -} - -void TlsConfiguration::enable_tls( - std::shared_ptr descriptor, - bool client /* = false */) const -{ - // Apply security ON - descriptor->apply_security = true; - - // Options - descriptor->tls_config.add_option( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::DEFAULT_WORKAROUNDS); - descriptor->tls_config.add_option( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::SINGLE_DH_USE); - descriptor->tls_config.add_option( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSOptions::NO_SSLV2); // not safe - - if (verify_peer) - { - // Perform verification of the server - descriptor->tls_config.add_verify_mode( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_PEER); - } - else - { - descriptor->tls_config.add_verify_mode( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_NONE); - } - - if (client) - { - if (!compatible()) - { - logError(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "TLS Configuration expected a Client configuration."); - throw utils::ConfigurationException("TLS Configuration expected a Client configuration."); - } - else - { - enable_tls_client(descriptor, true); - } - } - else - { - if (!compatible()) - { - logError(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "TLS Configuration expected a Server configuration."); - throw utils::ConfigurationException("TLS Configuration expected a Server configuration."); - } - else - { - // Add configuration for server - enable_tls_server(descriptor); - - // In case it could also be client, add tls config - if (compatible()) - { - enable_tls_client(descriptor, false); - } - } - } - - logDebug(DDSROUTER_DISCOVERYSERVER_PARTICIPANT, - "TLS configured."); -} - -void TlsConfiguration::enable_tls_client( - std::shared_ptr descriptor, - bool only_client) const -{ - if (only_client && verify_peer) - { - // Fail verification if the server has no certificate - descriptor->tls_config.add_verify_mode( - eprosima::fastdds::rtps::TCPTransportDescriptor::TLSConfig::TLSVerifyMode::VERIFY_FAIL_IF_NO_PEER_CERT); - } - - // CA certificate - descriptor->tls_config.verify_file = certificate_authority_file; - - // SNI server name - descriptor->tls_config.server_name = sni_server_name; -} - -void TlsConfiguration::enable_tls_server( - std::shared_ptr descriptor) const -{ - // Password - descriptor->tls_config.password = private_key_file_password; - // Private key - descriptor->tls_config.private_key_file = private_key_file; - // DDS-Router certificate - descriptor->tls_config.cert_chain_file = certificate_chain_file; - // DH - descriptor->tls_config.tmp_dh_file = dh_params_file; -} - -template <> -DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( - utils::Formatter& error_msg) const noexcept -{ - if (verify_peer) - { - if (certificate_authority_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid certificate_authority_file while server verification must be done."; - return false; - } - } - return true; -} - -template <> -DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( - utils::Formatter& error_msg) const noexcept -{ - if (private_key_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid private_key_file."; - return false; - } - - if (dh_params_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid dh_params_file."; - return false; - } - - // chain cert is not required, however is usually needed - if (certificate_chain_file.empty()) - { - // TODO check it is a correct file - error_msg << "Invalid certificate_chain_file."; - return false; - } - - return true; -} - -template <> -DDSPIPE_CORE_DllAPI bool TlsConfiguration::is_valid_kind( - utils::Formatter& error_msg) const noexcept -{ - return is_valid_kind(error_msg) && is_valid_kind(error_msg); -} - -bool TlsConfiguration::is_valid( - utils::Formatter& error_msg) const noexcept -{ - switch (kind) - { - case TlsKind::client: - return is_valid_kind(error_msg); - - case TlsKind::server: - return is_valid_kind(error_msg); - - case TlsKind::both: - return is_valid_kind(error_msg); - - default: - // None - return true; - } -} - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp deleted file mode 100644 index 2101204a9..000000000 --- a/ddspipe_participants/src/cpp/writer/auxiliar/BaseWriter.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2021 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. - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -BaseWriter::BaseWriter( - const core::types::ParticipantId& participant_id, - const std::shared_ptr& payload_pool) - : participant_id_(participant_id) - , payload_pool_(payload_pool) - , enabled_(false) -{ - logDebug(DDSROUTER_BASEWRITER, "Creating Writer " << *this << "."); -} - -void BaseWriter::enable() noexcept -{ - std::lock_guard lock(mutex_); - - // If it is enabled, do nothing - if (!enabled_.load()) - { - enabled_.store(true); - - // Call specific enable - enable_(); - } -} - -void BaseWriter::disable() noexcept -{ - std::lock_guard lock(mutex_); - - // If it is not enabled, do nothing - if (enabled_.load()) - { - enabled_.store(false); - - // Call specific disable - disable_(); - } -} - -utils::ReturnCode BaseWriter::write( - core::IRoutingData& data) noexcept -{ - std::lock_guard lock(mutex_); - - if (enabled_.load()) - { - return write_(data); - } - else - { - logDevError(DDSROUTER_BASEWRITER, "Attempt to write data from disabled Writer in topic in Participant " << participant_id_); - return utils::ReturnCode::RETCODE_NOT_ENABLED; - } -} - -void BaseWriter::enable_() noexcept -{ - // It does nothing. Override this method so it has functionality. -} - -void BaseWriter::disable_() noexcept -{ - // It does nothing. Override this method so it has functionality. -} - -std::ostream& operator <<( - std::ostream& os, - const BaseWriter& writer) -{ - os << "Writer{" << writer.participant_id_ << "}"; - return os; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp deleted file mode 100644 index e9e11a44c..000000000 --- a/ddspipe_participants/src/cpp/writer/auxiliar/BlankWriter.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2021 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. - - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -void BlankWriter::enable() noexcept -{ -} - -void BlankWriter::disable() noexcept -{ -} - -utils::ReturnCode BlankWriter::write( - core::IRoutingData& /* data */) noexcept -{ - return utils::ReturnCode::RETCODE_OK; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp deleted file mode 100644 index 681deda39..000000000 --- a/ddspipe_participants/src/cpp/writer/auxiliar/RtpsEchoWriter.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 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. - -#include - -#include - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { - -using eprosima::ddspipe::core::types::operator<<; - -RtpsEchoWriter::RtpsEchoWriter( - const core::types::DdsTopic& topic, - bool verbose) - : topic_(topic) - , verbose_(verbose) -{ - logDebug( - DDSROUTER_BASEWRITER, - "Creating Echo Writer with verbose: " << - (verbose_ ? "active" : "inactive") << "."); -} - -utils::ReturnCode RtpsEchoWriter::write( - core::IRoutingData& data) noexcept -{ - auto& rtps_data = dynamic_cast(data); - - // TODO: Add Participant receiver Id when added to DataReceived - if (!verbose_) - { - logUser( - DDSROUTER_ECHO_DATA, - "Received data in Participant: " << rtps_data.participant_receiver << - " in topic: " << topic_.topic_name() << - "."); - } - else - { - logUser( - DDSROUTER_ECHO_DATA, - "In Endpoint: " << rtps_data.source_guid << - " from Participant: " << rtps_data.participant_receiver << - " in topic: " << topic_.topic_name() << - " payload received: " << rtps_data.payload << - " with specific qos: " << rtps_data.writer_qos << - "."); - } - - return utils::ReturnCode::RETCODE_OK; -} - -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp b/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp deleted file mode 100644 index 331054ae8..000000000 --- a/ddspipe_participants/src/cpp/writer/rpc/SimpleWriter.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2021 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. - - -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rpc { - -SimpleWriter::SimpleWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater /* = false */) - : CommonWriter( - participant_id, topic, payload_pool, rtps_participant, repeater, - reckon_history_attributes_(topic), - reckon_writer_attributes_(topic), - reckon_topic_attributes_(topic), - reckon_writer_qos_(topic), - reckon_cache_change_pool_configuration_(topic)) -{ - logInfo(DDSROUTER_RPC_WRITER, "Creating RPC Writer for topic " << topic_); -} - -utils::ReturnCode SimpleWriter::fill_to_send_data_( - fastrtps::rtps::CacheChange_t* to_send_change_to_fill, - eprosima::fastrtps::rtps::WriteParams& to_send_params, - const core::types::RtpsPayloadData& data) const noexcept -{ - CommonWriter::fill_to_send_data_( - to_send_change_to_fill, - to_send_params, - data); - - const core::types::RpcPayloadData& rpc_data = dynamic_cast(data); - if (rpc_data.write_params.is_set()) - { - to_send_params.related_sample_identity(rpc_data.write_params.get_reference().related_sample_identity()); - } - - return utils::ReturnCode::RETCODE_OK; -} - -void SimpleWriter::fill_sent_data_( - const eprosima::fastrtps::rtps::WriteParams& sent_params, - core::types::RtpsPayloadData& data_to_fill) const noexcept -{ - CommonWriter::fill_sent_data_( - sent_params, - data_to_fill); - - core::types::RpcPayloadData& rpc_data = dynamic_cast(data_to_fill); - rpc_data.sent_sequence_number = sent_params.sample_identity().sequence_number(); -} - -} /* namespace rpc */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp deleted file mode 100644 index 49f36e0e7..000000000 --- a/ddspipe_participants/src/cpp/writer/rtps/CommonWriter.cpp +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright 2021 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. - - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -using namespace eprosima::ddspipe::core::types; -using eprosima::ddspipe::core::types::operator<<; - -CommonWriter::CommonWriter( - const ParticipantId& participant_id, - const DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater, - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::WriterAttributes& writer_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::WriterQos& writer_qos, - const utils::PoolConfiguration& pool_configuration) - : BaseWriter(participant_id, payload_pool) - , rtps_participant_(rtps_participant) - , repeater_(repeater) - , history_attributes_(history_attributes) - , writer_attributes_(writer_attributes) - , topic_attributes_(topic_attributes) - , writer_qos_(writer_qos) - , pool_configuration_(pool_configuration) - , topic_(topic) -{ - // Do nothing -} - -CommonWriter::~CommonWriter() -{ - // This variables should be set, otherwise the creation should have fail - // Anyway, the if case is used for safety reasons - - // Delete writer - if (rtps_writer_) - { - // Unset listener before destruction (not necessary in principle, but just in case) - rtps_writer_->set_listener(nullptr); - // Delete the CommonWriter the History is cleaned - fastrtps::rtps::RTPSDomain::removeRTPSWriter(rtps_writer_); - } - - // Delete History - if (rtps_history_) - { - delete rtps_history_; - } - - logInfo(DDSROUTER_RTPS_COMMONWRITER, "Deleting CommonWriter created in Participant " << - participant_id_ << " for topic " << topic_); -} - -void CommonWriter::init() -{ - internal_entities_creation_( - history_attributes_, - writer_attributes_, - topic_attributes_, - writer_qos_, - pool_configuration_); -} - -void CommonWriter::onWriterMatched( - fastrtps::rtps::RTPSWriter*, - fastrtps::rtps::MatchingInfo& info) noexcept -{ - if (!come_from_this_participant_(info.remoteEndpointGuid)) - { - if (info.status == fastrtps::rtps::MatchingStatus::MATCHED_MATCHING) - { - logInfo(DDSROUTER_RTPS_COMMONWRITER_LISTENER, - "Writer " << *this << " matched with a new Reader with guid " << info.remoteEndpointGuid); - } - else - { - logInfo(DDSROUTER_RTPS_COMMONWRITER_LISTENER, - "Writer " << *this << " unmatched with Reader " << info.remoteEndpointGuid); - } - } -} - -bool CommonWriter::come_from_this_participant_( - const fastrtps::rtps::GUID_t guid) const noexcept -{ - return guid.guidPrefix == rtps_writer_->getGuid().guidPrefix; -} - -// Specific enable/disable do not need to be implemented -utils::ReturnCode CommonWriter::write_( - core::IRoutingData& data) noexcept -{ - auto& rtps_data = dynamic_cast(data); - - // Take new Change from history - fastrtps::rtps::CacheChange_t* new_change; - if (topic_.topic_qos.keyed) - { - new_change = - rtps_writer_->new_change( - rtps_data.kind, - rtps_data.instanceHandle); - } - else - { - new_change = rtps_writer_->new_change(rtps_data.kind); - } - - // If still is not able to get a change, return an error code - if (!new_change) - { - return utils::ReturnCode::RETCODE_ERROR; - } - - logDebug(DDSROUTER_RTPS_COMMONWRITER, - "CommonWriter " << *this << " sending payload " << new_change->serializedPayload << " from " << - rtps_data.source_guid); - - // Get params to write (if set) - eprosima::fastrtps::rtps::WriteParams write_params; - - // Fill cache change with specific data to send - auto ret = fill_to_send_data_(new_change, write_params, rtps_data); - if (!ret) - { - logError(DDSROUTER_RTPS_COMMONWRITER, "Error setting change to send."); - return ret; - } - - // Send data by adding it to CommonWriter History - rtps_history_->add_change(new_change, write_params); - - // At this point, write params is now the output of adding change - fill_sent_data_(write_params, rtps_data); - - // Remove change could be done here in non reliable as it is synchronous because change has already been sent - // and does not require to be resent under any circumstance. - if (!topic_.topic_qos.is_reliable()) - { - rtps_history_->remove_change(new_change); - } - else if (rtps_history_->isFull()) - { - // When max history size is reached, remove oldest cache change - rtps_history_->remove_min_change(); - } - - return utils::ReturnCode::RETCODE_OK; -} - -utils::ReturnCode CommonWriter::fill_to_send_data_( - fastrtps::rtps::CacheChange_t* to_send_change_to_fill, - eprosima::fastrtps::rtps::WriteParams& to_send_params, - const RtpsPayloadData& data) const noexcept -{ - if (repeater_) - { - // Add origin to change in case the cache change is RouterCacheChange (only in repeater mode) - core::types::RouterCacheChange& change_ref = static_cast(*to_send_change_to_fill); - change_ref.last_writer_guid_prefix = data.source_guid.guidPrefix; - } - - // Set keys in case topic has keys - if (topic_.topic_qos.keyed) - { - to_send_change_to_fill->instanceHandle = data.instanceHandle; - } - - // Get the Payload without copy only if it has length - if (data.payload.length > 0) - { - eprosima::fastrtps::rtps::IPayloadPool* payload_owner = payload_pool_.get(); - if (!payload_pool_->get_payload( - const_cast(data.payload), - payload_owner, - (*to_send_change_to_fill))) - { - logDevError(DDSROUTER_RTPS_COMMONWRITER, "Error getting Payload."); - return utils::ReturnCode::RETCODE_ERROR; - } - } - - // Set Change kind - to_send_change_to_fill->kind = data.kind; - - // Set source time stamp to be the original one - to_send_params.source_timestamp(data.source_timestamp); - - return utils::ReturnCode::RETCODE_OK; -} - -void CommonWriter::fill_sent_data_( - const eprosima::fastrtps::rtps::WriteParams& params, - core::types::RtpsPayloadData& data_to_fill) const noexcept -{ - // Set data output parameters - // TODO move to RPC - // data_to_fill->sent_sequence_number = params.sample_identity().sequence_number(); -} - -void CommonWriter::internal_entities_creation_( - const fastrtps::rtps::HistoryAttributes& history_attributes, - const fastrtps::rtps::WriterAttributes& writer_attributes, - const fastrtps::TopicAttributes& topic_attributes, - const fastrtps::WriterQos& writer_qos, - const utils::PoolConfiguration& pool_configuration) -{ - // Copy writer attributes because fast needs it non const (do not ask why) - fastrtps::rtps::WriterAttributes non_const_writer_attributes = writer_attributes; - - // Create History - rtps_history_ = new fastrtps::rtps::WriterHistory(history_attributes); - - // Create CommonWriter - // Listener must be set in creation as no callbacks should be missed - // It is safe to do so here as object is already created and callbacks do not require anything set in this method - if (repeater_) - { - logDebug(DDSROUTER_RTPS_COMMONWRITER, "CommonWriter created with repeater filter"); - - rtps_writer_ = fastrtps::rtps::RTPSDomain::createRTPSWriter( - rtps_participant_, - non_const_writer_attributes, - payload_pool_, - std::make_shared(pool_configuration), - rtps_history_, - this); - } - else - { - rtps_writer_ = fastrtps::rtps::RTPSDomain::createRTPSWriter( - rtps_participant_, - non_const_writer_attributes, - payload_pool_, - rtps_history_, - this); - } - - if (!rtps_writer_) - { - throw utils::InitializationException( - utils::Formatter() << "Error creating Simple RTPSWriter for Participant " << - participant_id_ << " in topic " << topic_ << "."); - } - - // Register writer with topic - if (!rtps_participant_->registerWriter(rtps_writer_, topic_attributes, writer_qos)) - { - // In case it fails, remove writer and throw exception - fastrtps::rtps::RTPSDomain::removeRTPSWriter(rtps_writer_); - throw utils::InitializationException(utils::Formatter() << "Error registering topic " << topic_ << - " for Simple RTPSWriter in Participant " << participant_id_); - } - - if (repeater_) - { - // Use filter writer of origin - data_filter_ = std::make_unique(); - } - else - { - // Use default filter - data_filter_ = std::make_unique(); - } - - rtps_writer_->reader_data_filter(data_filter_.get()); - - logInfo( - DDSROUTER_RTPS_COMMONWRITER, - "New CommonWriter created in Participant " << participant_id_ << - " for topic " << topic_ << - " with guid " << rtps_writer_->getGuid()); -} - -fastrtps::rtps::HistoryAttributes CommonWriter::reckon_history_attributes_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::rtps::HistoryAttributes att; - - att.memoryPolicy = - eprosima::fastrtps::rtps::MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - - att.maximumReservedCaches = topic.topic_qos.history_depth; - - return att; -} - -fastrtps::rtps::WriterAttributes CommonWriter::reckon_writer_attributes_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::rtps::WriterAttributes att; - - // Set Durability - att.endpoint.durabilityKind = topic.topic_qos.durability_qos; - - // Set Reliability - att.endpoint.reliabilityKind = topic.topic_qos.reliability_qos; - - // Set if topic has key - if (topic.topic_qos.keyed) - { - att.endpoint.topicKind = eprosima::fastrtps::rtps::WITH_KEY; - } - else - { - att.endpoint.topicKind = eprosima::fastrtps::rtps::NO_KEY; - } - - // Other attributes as partitions and ownership are not used in this writer - - // Set write mode - // ATTENTION: Changing this will change the logic of removing changes added. Please be careful. - att.mode = fastrtps::rtps::RTPSWriterPublishMode::SYNCHRONOUS_WRITER; - - return att; -} - -fastrtps::TopicAttributes CommonWriter::reckon_topic_attributes_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::TopicAttributes att; - - // Set if topic has key - if (topic.topic_qos.keyed) - { - att.topicKind = eprosima::fastrtps::rtps::WITH_KEY; - } - else - { - att.topicKind = eprosima::fastrtps::rtps::NO_KEY; - } - - // Set Topic attributes - att.topicName = topic.m_topic_name; - att.topicDataType = topic.type_name; - - return att; -} - -fastrtps::WriterQos CommonWriter::reckon_writer_qos_( - const core::types::DdsTopic& topic) noexcept -{ - fastrtps::WriterQos qos; - - // Set Durability - qos.m_durability.kind = - (topic.topic_qos.is_transient_local() - ? eprosima::fastdds::dds::DurabilityQosPolicyKind_t::TRANSIENT_LOCAL_DURABILITY_QOS - : eprosima::fastdds::dds::DurabilityQosPolicyKind_t::VOLATILE_DURABILITY_QOS); - - // Set Reliability - qos.m_reliability.kind = - (topic.topic_qos.is_reliable() - ? eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS - : eprosima::fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS); - - // Set minimum deadline so it matches with everything - qos.m_deadline.period = eprosima::fastrtps::Duration_t(0); - - // Partitions and specific ownership strength are not set in common. - - return qos; -} - -utils::PoolConfiguration CommonWriter::reckon_cache_change_pool_configuration_( - const core::types::DdsTopic& topic) noexcept -{ - utils::PoolConfiguration config; - config.maximum_size = topic.topic_qos.history_depth; - config.initial_size = 20; - config.batch_size = 20; - - return config; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp deleted file mode 100644 index 370d967af..000000000 --- a/ddspipe_participants/src/cpp/writer/rtps/MultiWriter.cpp +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2021 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. - - -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -using namespace eprosima::ddspipe::core::types; - -MultiWriter::MultiWriter( - const ParticipantId& participant_id, - const DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater /* = false */) - : BaseWriter(participant_id, payload_pool) - , rtps_participant_(rtps_participant) - , repeater_(repeater) - , topic_(topic) -{ - // Do nothing -} - -MultiWriter::~MultiWriter() -{ - // Lock so no other operations is taking place - std::unique_lock lock(writers_map_); - - // Disable every inside writer and kill it - for (auto& writer : writers_map_) - { - writer.second->disable(); - delete writer.second; - } - - logInfo(DDSROUTER_RTPS_WRITER, "Deleting MultiWriter created in Participant " << - participant_id_ << " for topic " << topic_); -} - -void MultiWriter::enable_() noexcept -{ - std::shared_lock lock(writers_map_); - for (auto& writer : writers_map_) - { - writer.second->enable(); - } -} - -void MultiWriter::disable_() noexcept -{ - std::shared_lock lock(writers_map_); - for (auto& writer : writers_map_) - { - writer.second->disable(); - } -} - -bool MultiWriter::exist_partition_( - const core::types::SpecificEndpointQoS& data_qos) -{ - std::shared_lock lock(writers_map_); - return writers_map_.find(data_qos) != writers_map_.end(); -} - -QoSSpecificWriter* MultiWriter::get_writer_or_create_( - const core::types::SpecificEndpointQoS& data_qos) -{ - // NOTE: it uses unique lock because it may change the database, and there is no way - // to do so if taking share and unique must be done. - std::unique_lock lock(writers_map_); - - // Get if it exists - auto it = writers_map_.find(data_qos); - if (it != writers_map_.end()) - { - return it->second; - } - - // Create Writer - QoSSpecificWriter* new_writer = create_writer_nts_(data_qos); - // Add it to map - writers_map_[data_qos] = new_writer; - - // If this is enabled, enable writer - if (enabled_) - { - new_writer->enable(); - } - - return new_writer; -} - -QoSSpecificWriter* MultiWriter::create_writer_nts_( - const core::types::SpecificEndpointQoS& data_qos) -{ - logDebug( - DDSROUTER_MULTIWRITER, - "Creating a new Writer in " << *this << " for qos " << data_qos << "."); - - auto writer = new QoSSpecificWriter( - this->participant_id_, - this->topic_, - this->payload_pool_, - this->rtps_participant_, - data_qos, - repeater_); - writer->init(); - - return writer; -} - -// Specific enable/disable do not need to be implemented -utils::ReturnCode MultiWriter::write_( - core::IRoutingData& data) noexcept -{ - auto& rtps_data = dynamic_cast(data); - - logDebug( - DDSROUTER_MULTIWRITER, - "Writing in Partitions Writer " << *this << " a data with qos " << rtps_data.writer_qos << " from " << - rtps_data.source_guid); - - // Take Writer - auto this_qos_writer = get_writer_or_create_(rtps_data.writer_qos); - - logDebug( - DDSROUTER_MULTIWRITER, - "Writer chosen to send is " << *this_qos_writer << "."); - - // Write - return this_qos_writer->write(data); -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp deleted file mode 100644 index 7bfd9431b..000000000 --- a/ddspipe_participants/src/cpp/writer/rtps/QoSSpecificWriter.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2021 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. - - -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -using namespace eprosima::ddspipe::core::types; - -QoSSpecificWriter::QoSSpecificWriter( - const ParticipantId& participant_id, - const DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const SpecificEndpointQoS& specific_qos, - const bool repeater /* = false */) - : CommonWriter( - participant_id, topic, payload_pool, rtps_participant, repeater - , reckon_history_attributes_(topic) - , reckon_writer_attributes_(topic) - , reckon_topic_attributes_(topic) - , reckon_writer_qos_(specific_qos, topic) // this modifies the qos of the Common Writer - , reckon_cache_change_pool_configuration_(topic)) - , specific_qos_(specific_qos) -{ -} - -fastrtps::WriterQos QoSSpecificWriter::reckon_writer_qos_( - const SpecificEndpointQoS& specific_qos, - const DdsTopic& topic) noexcept -{ - // Get QoS from parent class - fastrtps::WriterQos qos = CommonWriter::reckon_writer_qos_(topic); - - // Set Partitions - if (topic.topic_qos.has_partitions()) - { - qos.m_partition = specific_qos.partitions; - } - - // Set Ownership - if (topic.topic_qos.has_ownership()) - { - // Set ownership - qos.m_ownership.kind = topic.topic_qos.ownership_qos; - - qos.m_ownershipStrength = specific_qos.ownership_strength; - } - - return qos; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp b/ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp deleted file mode 100644 index e49539536..000000000 --- a/ddspipe_participants/src/cpp/writer/rtps/SimpleWriter.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 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. - - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -SimpleWriter::SimpleWriter( - const core::types::ParticipantId& participant_id, - const core::types::DdsTopic& topic, - const std::shared_ptr& payload_pool, - fastrtps::rtps::RTPSParticipant* rtps_participant, - const bool repeater /* = false */) - : CommonWriter( - participant_id, topic, payload_pool, rtps_participant, repeater, - reckon_history_attributes_(topic), - reckon_writer_attributes_(topic), - reckon_topic_attributes_(topic), - reckon_writer_qos_(topic), - reckon_cache_change_pool_configuration_(topic)) -{ -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rtps/filter/RepeaterDataFilter.cpp b/ddspipe_participants/src/cpp/writer/rtps/filter/RepeaterDataFilter.cpp deleted file mode 100644 index d95c00ff5..000000000 --- a/ddspipe_participants/src/cpp/writer/rtps/filter/RepeaterDataFilter.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2022 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. - - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -bool RepeaterDataFilter::is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid) const -{ - if (!SelfDataFilter::is_relevant(change, reader_guid)) - { - logDebug( - REPEATER_DATA_FILTER, - "Ignoring message by SelfDataFilter is_relevant result."); - - // If origin filter does not pass this change, it is discarded - return false; - } - - // As ChangePool is our own, and we use RouterCacheChange, we can cast this without problem - const auto& change_ref = static_cast(change); - - bool is_relevant = change_ref.last_writer_guid_prefix != reader_guid.guidPrefix; - - logDebug( - REPEATER_DATA_FILTER, - "Evaluating whether Change with origin writer GUID prefix " << change_ref.last_writer_guid_prefix << - " is relevant for reader GUID " << reader_guid << "? " << (is_relevant ? "TRUE" : "FALSE")); - - return is_relevant; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/rtps/filter/SelfDataFilter.cpp b/ddspipe_participants/src/cpp/writer/rtps/filter/SelfDataFilter.cpp deleted file mode 100644 index 03876cc43..000000000 --- a/ddspipe_participants/src/cpp/writer/rtps/filter/SelfDataFilter.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2022 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. - - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace rtps { - -bool SelfDataFilter::is_relevant( - const fastrtps::rtps::CacheChange_t& change, - const fastrtps::rtps::GUID_t& reader_guid) const -{ - // It is relevant only if the reader does not belong to same participant as writer - return change.writerGUID.guidPrefix != reader_guid.guidPrefix; -} - -} /* namespace rtps */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/test/CMakeLists.txt b/ddspipe_participants/test/CMakeLists.txt deleted file mode 100644 index 9edde539e..000000000 --- a/ddspipe_participants/test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2022 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. - -# add_subdirectory(blackbox) diff --git a/ddspipe_yaml/CMakeLists.txt b/ddspipe_yaml/CMakeLists.txt deleted file mode 100644 index 644d5c7d4..000000000 --- a/ddspipe_yaml/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2022 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. - -############################################################################### -# CMake build rules for DDS Router Submodule -############################################################################### -cmake_minimum_required(VERSION 3.5) - -############################################################################### -# Find package cmake_utils -############################################################################### -# Package cmake_utils is required to get every cmake macro needed -find_package(cmake_utils REQUIRED) - -############################################################################### -# Project -############################################################################### -# Configure project by info set in project_settings.cmake -# - Load project_settings variables -# - Read version -# - Set installation paths -configure_project() - -# Call explictly project -project( - ${MODULE_NAME} - VERSION - ${MODULE_VERSION} - DESCRIPTION - ${MODULE_DESCRIPTION} - LANGUAGES - CXX -) - -############################################################################### -# C++ Project -############################################################################### -# Configure CPP project for dependencies and required flags: -# - Set CMake Build Type -# - Set C++ version -# - Set shared libraries by default -# - Find external packages and thirdparties -# - Activate Code coverage if flag CODE_COVERAGE -# - Activate Address sanitizer build if flag ASAN_BUILD -# - Activate Thread sanitizer build if flag TSAN_BUILD -# - Configure log depending on LOG_INFO flag and CMake type -configure_project_cpp() - -# Compile C++ library -compile_library( - "${PROJECT_SOURCE_DIR}/src/cpp" # Source directory - "${PROJECT_SOURCE_DIR}/include" # Include directory -) - -############################################################################### -# Test -############################################################################### -# Compile tests if CMake options requires it -compile_test_library( - "${PROJECT_SOURCE_DIR}/test" # Test directory -) - -############################################################################### -# Packaging -############################################################################### -# Install package -eprosima_packaging() diff --git a/ddspipe_yaml/README.md b/ddspipe_yaml/README.md deleted file mode 100644 index eb195bc2a..000000000 --- a/ddspipe_yaml/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# eProsima DDS Router Yaml Module - -This library implements the required functions to translate a DDS Router configuration written in *yaml* -format into C++ source code. -It is powered by `yaml-cpp` library. - -It provides methods: - -- to create every type of object from a *yaml* node, -- to read a *yaml* file, and -- to interact with a *yaml* object using `YAML::Node` class from `yaml-cpp`. - ---- - -## Example of usage - -```cpp -// LOAD DDS ROUTER CONFIGURATION FROM FILE - -core::configuration::DDSRouterConfiguration router_configuration = - yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file("configuration.yaml"); -``` - ---- - -## Dependencies - -* `yaml-cpp` -* `cpp_utils` -* `ddsrouter_core` - - ---- - -## How to use it in your project - -Just import library `ddsrouter_yaml` into your CMake project. - -```cmake -find_package(ddsrouter_yaml) -target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_yaml) -``` diff --git a/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp b/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp deleted file mode 100644 index 7775fa4d7..000000000 --- a/ddspipe_yaml/include/ddspipe_yaml/Yaml.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -namespace eprosima { - -/** - * Configuration is in dictionary format - * - * YAML spec: https://yaml.org/spec/1.2.2/ - * - * @note: It is not legal to repeat keys in a YAML - */ -using Yaml = YAML::Node; - -} /* namespace eprosima */ diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp deleted file mode 100644 index a74f0a205..000000000 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlManager.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -/** - * Class that manages generic methods related with yaml load and yaml validation. - */ -class DDSPIPE_YAML_DllAPI YamlManager -{ -public: - - static Yaml load_file( - const std::string& file_path); -}; - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp deleted file mode 100644 index eb48b6618..000000000 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -/** - * @brief Yaml Configuration Version - * - * With each version, the yaml format could change in different aspects - * - new fields - * - eliminate fields - * - change key words / tags - * - change requirement of field - * - etc. - * - * Each version is stored in a value of this enumeration, and each \c get method (without tag) is speciallized - * for each different versions. - * - * There is a version call \c LATEST that refers to the lates valid Yaml Configuration Versions. - * Most elemnts will not change from a version change to other. Thus, all of them must be implemented as - * the \c LATEST version, and then if a specific object changes with a specific version, implement that version - * (not latest) separately. - * This way, any new version uses \c LATEST as default implementation, and old versions that diverged from latest - * have their own implementation. As old versions will not change, those methods are definitive, and do not - * need further maintenance. - */ -enum YamlReaderVersion -{ - /** - * @brief First version. - * - * @version 0.1.0 - * @version 0.2.0 - */ - V_1_0, - - /** - * @brief Version 2.0 - * - * @version 0.3.0 - * - * - Adds builtin-topics tag. - * - Adds participants list. - * - Changes the parent of guid for DS to a new tag discovery-server-guid. - * - Adds domain tag in Address to remplace ip when DNS. - */ - V_2_0, - - /** - * @brief Latest version. - * - * @version 0.4.0 - * - * - Change wan to initial peers participant - * - Add Specs - */ - V_3_0, - - /** - * @brief Main version. - * - * This is the version used when the method is not specialized regarding the version, - * or the latest version when it does. - */ - LATEST, -}; - -using TagType = std::string; - -/** - * @brief Class that encapsulates methods to get values from Yaml Node. - * - * Every method is implemented - */ -class DDSPIPE_YAML_DllAPI YamlReader -{ -public: - - /** - * @brief Whether key \c tag is present in \c yml - * - * The key \c tag must be in base level of \c yml , it will no be looked for recursively. - * - * It could only look for keys in yaml map and empty yaml. It will fail in array and scalar cases. - * In this second case, return will always be false. - * - * @param yml base yaml - * @param tag key to look for in \c yml - * @return true id \c tag is a key in \c yml - * @return false otherwise - * - * @throw \c ConfigurationException if \c yml is not a map or empty yaml - */ - static bool is_tag_present( - const Yaml& yml, - const TagType& tag); - - /** - * @brief Get the yaml inside key \c tag in \c yml - * - * \c tag must be present in \c yml . It uses \c is_tag_present to check the key is present. - * Use \c is_tag_present before calling this method in order to avoid the exception. - * - * @param yml base yaml - * @param tag key refering the value returned - * @return yaml value inside key \c tag - * - * @throw \c ConfigurationException if \c tag is not present in \c yml - */ - static Yaml get_value_in_tag( - const Yaml& yml, - const TagType& tag); - - //! TODO comment - template - static T get( - const Yaml& yml, - const YamlReaderVersion version); - - //! Get element inside \c tag - template - static T get( - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version); - - /** - * @brief Fill an element given by parameter with the values inside \c yml - * - * This method simplifies the process of retrieving an object whose parent has its own \c fill method, - * as the code is reused from one another calling parent \c fill in child. - * It is also very helpful to handle default creation values. Without this, every different default value - * must have its own if-else clause, forcing to create the respective constructor. With this method, - * the default values are initialized with the default constructor, and then are overwritten by the yaml. - * [this problem arises because C++ does not allow different order of parameters in method call] - */ - template - static void fill( - T& object, - const Yaml& yml, - const YamlReaderVersion version); - - //! Fill an element given by parameter with the values inside \c tag in \c yml - template - static void fill( - T& object, - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version); - - //! TODO comment - template - static std::list get_list( - const Yaml& yml, - const YamlReaderVersion version); - - //! Get list inside \c tag - template - static std::list get_list( - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version); - - /** - * @brief Get set inside \c tag - * - * It get a list of elements T with \c get_list and then convert it to set. - * - * @tparam T type of each object of the set - * @param yml base yaml - * @param tag key to yaml containing set - * @param version configuration version - * @return set of elements - */ - template - static std::set get_set( - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version); - - //! TODO comment - template - static T get_scalar( - const Yaml& yml); - - //! Get scalar value inside \c tag - template - static T get_scalar( - const Yaml& yml, - const TagType& tag); - - //! TODO comment - template - static T get_enumeration( - const Yaml& yml, - const std::map& enum_values); - - //! Get enumeration value inside \c tag - template - static T get_enumeration( - const Yaml& yml, - const TagType& tag, - const std::map& enum_values); - - //! TODO comment - template - static T get_enumeration_from_builder( - const Yaml& yml, - const utils::EnumBuilder& enum_builder); - - //! Get enumeration value inside \c tag - template - static T get_enumeration_from_builder( - const Yaml& yml, - const TagType& tag, - const utils::EnumBuilder& enum_builder); -}; - -/** - * @brief \c YamlReaderVersion to stream serialization - */ -std::ostream& operator <<( - std::ostream& os, - const YamlReaderVersion& version); - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -// Include implementation template file -#include diff --git a/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp b/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp deleted file mode 100644 index 53e3ad7d6..000000000 --- a/ddspipe_yaml/include/ddspipe_yaml/impl/YamlReader.ipp +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -template -T YamlReader::get( - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version) -{ - // ATTENTION: This try catch can be avoided, it is only used to add verbose information - try - { - return get(get_value_in_tag(yml, tag), version); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Error getting required value of type <" << TYPE_NAME(T) << - "> in tag <" << tag << "> :\n " << e.what()); - } -} - -template -void YamlReader::fill( - T& object, - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version) -{ - // ATTENTION: This try catch can be avoided, it is only used to add verbose information - try - { - return fill(get_value_in_tag(yml, tag), object, version); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Error filling object of type <" << TYPE_NAME(T) << - "> in tag <" << tag << "> :\n " << e.what()); - } -} - -template -T YamlReader::get_scalar( - const Yaml& yml, - const TagType& tag) -{ - try - { - return get_scalar(get_value_in_tag(yml, tag)); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error reading yaml scalar under tag <" << tag << "> :\n " << e.what()); - } -} - -template -T YamlReader::get_scalar( - const Yaml& yml) -{ - if (!yml.IsScalar()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Trying to read a primitive value of type <" << TYPE_NAME(T) << "> from a non scalar yaml."); - } - - try - { - return yml.as(); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Incorrect format for primitive value, expected <" << TYPE_NAME(T) << ">:\n " << e.what()); - } -} - -template -std::list YamlReader::get_list( - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version) -{ - try - { - return get_list(get_value_in_tag(yml, tag), version); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error reading yaml list under tag <" << tag << "> :\n " << e.what()); - } -} - -template -std::list YamlReader::get_list( - const Yaml& yml, - const YamlReaderVersion version) -{ - if (!yml.IsSequence()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Incorrect format, yaml Sequence expected."); - } - - std::list result; - - try - { - for (Yaml element : yml) - { - result.push_back(get(element, version)); - } - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error reading yaml sequence of type <" << TYPE_NAME(T) << "> :\n " << - e.what()); - } - - return result; -} - -template -std::set YamlReader::get_set( - const Yaml& yml, - const TagType& tag, - const YamlReaderVersion version) -{ - std::list elements_list = get_list(yml, tag, version); - return std::set(elements_list.begin(), elements_list.end()); -} - -template -T YamlReader::get_enumeration( - const Yaml& yml, - const TagType& tag, - const std::map& enum_values) -{ - try - { - return get_enumeration(get_value_in_tag(yml, tag), enum_values); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error reading enumeration value under tag <" << tag << "> :\n " << e.what()); - } -} - -template -T YamlReader::get_enumeration( - const Yaml& yml, - const std::map& enum_values) -{ - TagType value = get_scalar(yml); - - // Find value - auto it = enum_values.find(value); - - if (it == enum_values.end()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Value <" << value << "> is not valid in enumeration <" << TYPE_NAME(T) << "."); - } - else - { - return it->second; - } -} - -template -T YamlReader::get_enumeration_from_builder( - const Yaml& yml, - const utils::EnumBuilder& enum_builder) -{ - std::string str_value = get_scalar(yml); - T enum_value; - bool found = enum_builder.string_to_enumeration(str_value, enum_value); - - if (found) - { - return enum_value; - } - else - { - throw eprosima::utils::ConfigurationException(utils::Formatter() - << "Value <" << str_value << "> cannot be parsed as enum <" << TYPE_NAME(T) << ">."); - } -} - -template -T YamlReader::get_enumeration_from_builder( - const Yaml& yml, - const TagType& tag, - const utils::EnumBuilder& enum_builder) -{ - try - { - return get_enumeration_from_builder(get_value_in_tag(yml, tag), enum_builder); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException(utils::Formatter() - << "Error reading enumeration from builder under tag <" - << tag << "> :\n " << e.what()); - } -} - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp b/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp deleted file mode 100644 index 16314ce9b..000000000 --- a/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { -namespace testing { - -template -struct YamlField -{ - YamlField() - : present(false) - { - } - - YamlField( - const T& arg_value, - bool arg_present = true) - : value(arg_value) - , present(arg_present) - { - } - - T value; - bool present; -}; - -template -void add_field_to_yaml( - Yaml& yml, - const YamlField& field, - const std::string& tag) -{ - if (field.present) - { - yml[tag] = field.value; - } -} - -void guid_prefix_to_yaml( - Yaml& yml, - const core::types::GuidPrefix& guid_prefix) -{ - std::stringstream ss; - ss << guid_prefix; - - add_field_to_yaml( - yml, - YamlField(ss.str()), - DISCOVERY_SERVER_GUID_TAG); -} - -void discovery_server_guid_prefix_to_yaml( - Yaml& yml, - const core::types::GuidPrefix& guid_prefix) -{ - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - - yml[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; -} - -void address_to_yaml( - Yaml& yml, - const participants::types::Address& address) -{ - add_field_to_yaml( - yml, - YamlField(address.ip()), - ADDRESS_IP_TAG); - - add_field_to_yaml( - yml, - YamlField(address.port()), - ADDRESS_PORT_TAG); - - if (address.transport_protocol() == participants::types::TransportProtocol::udp) - { - add_field_to_yaml( - yml, - YamlField(ADDRESS_TRANSPORT_UDP_TAG), - ADDRESS_TRANSPORT_TAG); - } - else if (address.transport_protocol() == participants::types::TransportProtocol::tcp) - { - add_field_to_yaml( - yml, - YamlField(ADDRESS_TRANSPORT_TCP_TAG), - ADDRESS_TRANSPORT_TAG); - } - - if (address.ip_version() == participants::types::IpVersion::v4) - { - add_field_to_yaml( - yml, - YamlField(ADDRESS_IP_VERSION_V4_TAG), - ADDRESS_IP_VERSION_TAG); - } - else if (address.ip_version() == participants::types::IpVersion::v6) - { - add_field_to_yaml( - yml, - YamlField(ADDRESS_IP_VERSION_V6_TAG), - ADDRESS_IP_VERSION_TAG); - } -} - -void participantid_to_yaml( - Yaml& yml, - const core::types::ParticipantId& id) -{ - add_field_to_yaml( - yml, - YamlField(id), - PARTICIPANT_NAME_TAG); -} - -void domain_to_yaml( - Yaml& yml, - const core::types::DomainId& domain) -{ - add_field_to_yaml( - yml, - YamlField(domain.domain_id), - DOMAIN_ID_TAG); -} - -void repeater_to_yaml( - Yaml& yml, - const bool& repeater) -{ - add_field_to_yaml( - yml, - YamlField(repeater), - IS_REPEATER_TAG); -} - -// // Create a yaml QoS object only with reliability -// void qos_to_yaml( -// Yaml& yml, -// const TopicQoS& qos) -// { -// // TODO: extend this for all qos -// add_field_to_yaml(yml, YamlField(qos.is_reliable()), QOS_RELIABLE_TAG); -// } - -// // Create a yaml Topic object with name, type and key tags -// void filter_topic_to_yaml( -// Yaml& yml, -// const WildcardDdsFilterTopic& topic) -// { -// if (topic.topic_name.is_set()) -// { -// add_field_to_yaml(yml, YamlField(topic.topic_name), TOPIC_NAME_TAG); -// } - -// if (topic.type_name.is_set()) -// { -// add_field_to_yaml(yml, YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); -// } -// } - -// // Create a yaml DdsTopic object with name, type, key and reliable tags -// void real_topic_to_yaml( -// Yaml& yml, -// const DdsTopic& topic, -// const YamlField& type, -// const YamlField& qos) -// { -// add_field_to_yaml(yml, YamlField(topic.m_topic_name), TOPIC_NAME_TAG); -// add_field_to_yaml(yml, YamlField(topic.type_name), TOPIC_TYPE_NAME_TAG); -// add_field_to_yaml(yml, YamlField(topic.topic_qos), TOPIC_QOS_TAG); -// } - -} /* namespace testing */ -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp deleted file mode 100644 index 1b986653d..000000000 --- a/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2022 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. - -#pragma once - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -// Yaml related tags -constexpr const char* VERSION_TAG("version"); //! Version to parse the yaml with -constexpr const char* VERSION_TAG_V_1_0("v1.0"); //! Version v1.0 -constexpr const char* VERSION_TAG_V_2_0("v2.0"); //! Version v2.0 -constexpr const char* VERSION_TAG_V_3_0("v3.0"); //! Version v3.0 - -// Topics related tags -constexpr const char* ALLOWLIST_TAG("allowlist"); //! List of allowed topics -constexpr const char* BLOCKLIST_TAG("blocklist"); //! List of blocked topics -constexpr const char* BUILTIN_TAG("builtin-topics"); //! List of builtin topics -constexpr const char* TOPIC_NAME_TAG("name"); //! Name of a topic -constexpr const char* TOPIC_TYPE_NAME_TAG("type"); //! Type name of a topic -constexpr const char* TOPIC_KIND_TAG("keyed"); //! Kind of a topic (with or without key) -constexpr const char* TOPIC_QOS_TAG("qos"); //! QoS of a topic - -// QoS related tags -constexpr const char* QOS_RELIABLE_TAG("reliability"); //! The Endpoints of that topic will be configured as RELIABLE -constexpr const char* QOS_TRANSIENT_TAG("durability"); //! The Endpoints of that topic will be configured as TRANSIENT_LOCAL -constexpr const char* QOS_HISTORY_DEPTH_TAG("depth"); //! The Endpoints of that topic will be configured as this History Depth -constexpr const char* QOS_PARTITION_TAG("partitions"); //! The Endpoints of that topic will be configured with partitions -constexpr const char* QOS_OWNERSHIP_TAG("ownership"); //! The Endpoints of that topic will be configured with partitions - -// Participant related tags -constexpr const char* PARTICIPANT_KIND_TAG("kind"); //! Participant Kind -constexpr const char* PARTICIPANT_NAME_TAG("name"); //! Participant Name -constexpr const char* COLLECTION_PARTICIPANTS_TAG("participants"); //! TODO: add comment -constexpr const char* IS_REPEATER_TAG("repeater"); //! Is participant a repeater - -// Echo related tags -constexpr const char* ECHO_DATA_TAG("data"); //! Echo Data received -constexpr const char* ECHO_DISCOVERY_TAG("discovery"); //! Echo Discovery received -constexpr const char* ECHO_VERBOSE_TAG("verbose"); //! Echo in verbose mode - -// RTPS related tags -// Simple RTPS related tags -constexpr const char* DOMAIN_ID_TAG("domain"); //! Domain Id of the participant - -// Discovery Server related tags -constexpr const char* DISCOVERY_SERVER_GUID_PREFIX_TAG("discovery-server-guid"); //! TODO: add comment -constexpr const char* LISTENING_ADDRESSES_TAG("listening-addresses"); //! TODO: add comment -constexpr const char* CONNECTION_ADDRESSES_TAG("connection-addresses"); //! TODO: add comment -constexpr const char* COLLECTION_ADDRESSES_TAG("addresses"); //! TODO: add comment - -// TLS related tags -constexpr const char* TLS_TAG("tls"); //! TLS configuration tag -constexpr const char* TLS_CA_TAG("ca"); //! Certificate Authority Certificate -constexpr const char* TLS_PASSWORD_TAG("password"); //! DDS-Router Password -constexpr const char* TLS_PRIVATE_KEY_TAG("private_key"); //! DDS-Router Certificate Private Key -constexpr const char* TLS_CERT_TAG("cert"); //! DDS-Router Certificate -constexpr const char* TLS_DHPARAMS_TAG("dh_params"); //! Diffie-Hellman (DF) parameters -constexpr const char* TLS_PEER_VERIFICATION_TAG("peer_verification"); //! Peer Verification parameter -constexpr const char* TLS_SNI_HOST_TAG("sni_host"); //! TLS configuration tag - -// Address related tags -constexpr const char* ADDRESS_IP_TAG("ip"); //! TODO: add comment -constexpr const char* ADDRESS_DNS_TAG("domain"); //! TODO: add comment -constexpr const char* ADDRESS_PORT_TAG("port"); //! TODO: add comment -constexpr const char* ADDRESS_EXTERNAL_PORT_TAG("external-port"); //! TODO: add comment - -constexpr const char* ADDRESS_IP_VERSION_TAG("ip-version"); //! TODO: add comment -constexpr const char* ADDRESS_IP_VERSION_V4_TAG("v4"); //! TODO: add comment -constexpr const char* ADDRESS_IP_VERSION_V6_TAG("v6"); //! TODO: add comment - -constexpr const char* ADDRESS_TRANSPORT_TAG("transport"); //! TODO: add comment -constexpr const char* ADDRESS_TRANSPORT_UDP_TAG("udp"); //! TODO: add comment -constexpr const char* ADDRESS_TRANSPORT_TCP_TAG("tcp"); //! TODO: add comment - -// Discovery Server Guid related tags -constexpr const char* DISCOVERY_SERVER_GUID_TAG("guid"); //! TODO: add comment -constexpr const char* DISCOVERY_SERVER_ID_TAG("id"); //! TODO: add comment -constexpr const char* DISCOVERY_SERVER_ID_ROS_TAG("ros-discovery-server"); //! TODO: add comment - -// Advanced configuration -constexpr const char* SPECS_TAG("specs"); //! Specs options for DDS Router configuration -constexpr const char* NUMBER_THREADS_TAG("threads"); //! Number of threads to configure the thread pool -constexpr const char* MAX_HISTORY_DEPTH_TAG("max-depth"); //! Maximum size (number of stored cache changes) for RTPS History instances - -// Old versions tags -constexpr const char* PARTICIPANT_KIND_TAG_V1("type"); //! Participant Kind - - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/package.xml b/ddspipe_yaml/package.xml deleted file mode 100644 index a302acf26..000000000 --- a/ddspipe_yaml/package.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - ddspipe_yaml - 1.1.0 - - *eprosima DDS Router* Yaml Module is a C++ implementation for handling events in multithreading executions as PeriodicTimers, Signals, FileWatchers, etc. - - Raul Sánchez-Mateos - Javier París - Juan López - Apache 2.0 - - https://www.eprosima.com/ - https://github.com/eProsima/DDS-Router/issues - https://github.com/eProsima/DDS-Router - - cmake - - yamlcpp - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants - cmake_utils - - doxygen - - googletest-distribution - - - cmake - - diff --git a/ddspipe_yaml/project_settings.cmake b/ddspipe_yaml/project_settings.cmake deleted file mode 100644 index 2bbb1bd0f..000000000 --- a/ddspipe_yaml/project_settings.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2022 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. - -############################################################################### -# Set settings for project ddspipe_yaml -############################################################################### - -set(MODULE_NAME - ddspipe_yaml) - -set(MODULE_SUMMARY - "C++ library to create a DDS Router configuration from a YAML.") - -set(MODULE_FIND_PACKAGES - yaml-cpp - fastcdr - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants) - -set(MODULE_DEPENDENCIES - $<$:iphlpapi$Shlwapi> - ${MODULE_FIND_PACKAGES}) diff --git a/ddspipe_yaml/src/cpp/YamlManager.cpp b/ddspipe_yaml/src/cpp/YamlManager.cpp deleted file mode 100644 index 9c310c8b2..000000000 --- a/ddspipe_yaml/src/cpp/YamlManager.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2022 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 YamlManager.cpp - * - */ - -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -Yaml YamlManager::load_file( - const std::string& file_path) -{ - try - { - return YAML::LoadFile(file_path); - } - catch (const std::exception& e) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Error occured while loading yaml from file: " - << file_path << " : " << e.what()); - } -} - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp deleted file mode 100644 index 6bd97011a..000000000 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2022 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 YamlReader.cpp - * - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -using namespace eprosima::ddspipe::core::types; -using namespace eprosima::ddspipe::participants::types; - -/************************ -* GENERIC * -************************/ - -bool YamlReader::is_tag_present( - const Yaml& yml, - const TagType& tag) -{ - if (!yml.IsMap() && !yml.IsNull()) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Trying to find a tag: <" << tag << "> in a not yaml object map."); - } - - // Explicit conversion to avoid windows format warning - // This method performace is the same as only retrieving bool - return (yml[tag]) ? true : false; -} - -Yaml YamlReader::get_value_in_tag( - const Yaml& yml, - const TagType& tag) -{ - if (is_tag_present(yml, tag)) - { - return yml[tag]; - } - else - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << "Required tag not found: <" << tag << ">."); - } -} - -/************************ -* STANDARD * -************************/ - -template <> -int YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -template <> -unsigned int YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -template <> -bool YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -template <> -std::string YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version /* version */) -{ - return get_scalar(yml); -} - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp deleted file mode 100644 index 988ab3a85..000000000 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2022 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 YamlReader.cpp - * - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -using namespace eprosima::ddspipe::core::types; -using namespace eprosima::ddspipe::participants::types; - -/************************ -* PARTICIPANTS * -************************/ - -////////////////////////////////// -// ParticipantConfiguration -template <> -void YamlReader::fill( - participants::ParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Id required - object.id = get(yml, PARTICIPANT_NAME_TAG, version); -} - -template <> -participants::ParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::ParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// EchoParticipantConfiguration -template <> -void YamlReader::fill( - participants::EchoParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // data optional - if (is_tag_present(yml, ECHO_DATA_TAG)) - { - object.echo_data = get(yml, ECHO_DATA_TAG, version); - } - - // discovery optional - if (is_tag_present(yml, ECHO_DISCOVERY_TAG)) - { - object.echo_discovery = get(yml, ECHO_DISCOVERY_TAG, version); - } - - // verbose optional - if (is_tag_present(yml, ECHO_VERBOSE_TAG)) - { - object.verbose = get(yml, ECHO_VERBOSE_TAG, version); - } -} - -template <> -participants::EchoParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::EchoParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// SimpleParticipantConfiguration -template <> -void YamlReader::fill( - participants::SimpleParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // Domain optional - if (is_tag_present(yml, DOMAIN_ID_TAG)) - { - object.domain = get(yml, DOMAIN_ID_TAG, version); - } -} - -template <> -participants::SimpleParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::SimpleParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// DiscoveryServerParticipantConfiguration -template <> -void YamlReader::fill( - participants::DiscoveryServerParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // Optional listening addresses - if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) - { - object.listening_addresses = YamlReader::get_set
(yml, LISTENING_ADDRESSES_TAG, version); - } - - // Optional connection addresses - if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) - { - object.connection_addresses = YamlReader::get_set( - yml, - CONNECTION_ADDRESSES_TAG, - version); - } - - // Optional TLS - if (YamlReader::is_tag_present(yml, TLS_TAG)) - { - YamlReader::fill( - object.tls_configuration, - YamlReader::get_value_in_tag(yml, TLS_TAG), - version); - } - - // NOTE: The only field that change regarding the version is the GuidPrefix. - switch (version) - { - case V_1_0: - object.discovery_server_guid_prefix = - YamlReader::get(yml, version); - break; - - default: - object.discovery_server_guid_prefix = - YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); - break; - } -} - -template <> -participants::DiscoveryServerParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::DiscoveryServerParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -////////////////////////////////// -// InitialPeersParticipantConfiguration -template <> -void YamlReader::fill( - participants::InitialPeersParticipantConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Parent class fill - fill(object, yml, version); - - // Optional listening addresses - if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) - { - object.listening_addresses = YamlReader::get_set
(yml, LISTENING_ADDRESSES_TAG, version); - } - - // Optional connection addresses - if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) - { - object.connection_addresses = YamlReader::get_set
( - yml, - CONNECTION_ADDRESSES_TAG, - version); - } - - // Optional TLS - if (YamlReader::is_tag_present(yml, TLS_TAG)) - { - YamlReader::fill( - object.tls_configuration, - YamlReader::get_value_in_tag(yml, TLS_TAG), - version); - } - - // Optional Repeater - if (YamlReader::is_tag_present(yml, IS_REPEATER_TAG)) - { - object.is_repeater = YamlReader::get(yml, IS_REPEATER_TAG, version); - } -} - -template <> -participants::InitialPeersParticipantConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - participants::InitialPeersParticipantConfiguration object; - fill(object, yml, version); - return object; -} - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp deleted file mode 100644 index 2a8aefa1a..000000000 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ /dev/null @@ -1,544 +0,0 @@ -// Copyright 2022 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 YamlReader.cpp - * - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace yaml { - -using namespace eprosima::ddspipe::core::types; -using namespace eprosima::ddspipe::participants::types; - -template <> -YamlReaderVersion YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - return get_enumeration( - yml, - { - {VERSION_TAG_V_1_0, YamlReaderVersion::V_1_0}, - {VERSION_TAG_V_2_0, YamlReaderVersion::V_2_0}, - {VERSION_TAG_V_3_0, YamlReaderVersion::V_3_0}, - }); -} - -template <> -TransportProtocol YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - return get_enumeration( - yml, - { - {ADDRESS_TRANSPORT_TCP_TAG, TransportProtocol::tcp}, - {ADDRESS_TRANSPORT_UDP_TAG, TransportProtocol::udp}, - }); -} - -template <> -IpVersion YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - return get_enumeration( - yml, - { - {ADDRESS_IP_VERSION_V4_TAG, IpVersion::v4}, - {ADDRESS_IP_VERSION_V6_TAG, IpVersion::v6}, - }); -} - -template <> -PortType YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // Domain id required - return PortType(get_scalar(yml)); -} - -template <> -DomainId YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // Domain id required - DomainId domain; - domain.domain_id = get_scalar(yml); - return domain; -} - -template <> -GuidPrefix YamlReader::get( - const Yaml& yml, - const YamlReaderVersion /* version */) -{ - // If guid exists, use it. Non mandatory. - if (is_tag_present(yml, DISCOVERY_SERVER_GUID_TAG)) - { - std::string guid = get_scalar(yml, DISCOVERY_SERVER_GUID_TAG); - return GuidPrefix(guid); - } - - // ROS DS is optional. - bool ros_id; - bool ros_id_set = is_tag_present(yml, DISCOVERY_SERVER_ID_ROS_TAG); - if (ros_id_set) - { - ros_id = get_scalar(yml, DISCOVERY_SERVER_ID_ROS_TAG); - } - - // Id is mandatory if guid is not present - uint32_t id = get_scalar(yml, DISCOVERY_SERVER_ID_TAG); - - // Create GuidPrefix - if (ros_id_set) - { - return GuidPrefix(ros_id, id); - } - else - { - return GuidPrefix(id); - } -} - -template <> -Address YamlReader::get
( - const Yaml& yml, - const YamlReaderVersion version) -{ - // Optional get IP version - IpVersion ip_version; - bool ip_version_set = is_tag_present(yml, ADDRESS_IP_VERSION_TAG); - if (ip_version_set) - { - // Get IP Version from enumeration - ip_version = get(yml, ADDRESS_IP_VERSION_TAG, version); - } - - // Optional get IP - IpType ip; - bool ip_set = is_tag_present(yml, ADDRESS_IP_TAG); - if (ip_set) - { - ip = get(yml, ADDRESS_IP_TAG, version); - } - - // Optional get Domain tag for DNS - std::string domain_name; - bool domain_name_set = is_tag_present(yml, ADDRESS_DNS_TAG); - if (domain_name_set) - { - domain_name = get_scalar(yml, ADDRESS_DNS_TAG); - } - - // If IP and domain_name set, warning that domain_name will not be used - // If only domain_name set, get DNS response - // If neither set, get default - if (ip_set && domain_name_set) - { - logWarning(ddspipe_YAML, - "Tag <" << ADDRESS_DNS_TAG << "> will not be used as <" << ADDRESS_IP_TAG << "> is set."); - domain_name_set = false; - } - else if (!ip_set && !domain_name_set) - { - throw eprosima::utils::ConfigurationException(utils::Formatter() << - "Address requires to specify <" << ADDRESS_IP_TAG << "> or <" << ADDRESS_DNS_TAG << ">."); - } - - // Optional get port - PortType port; - bool port_set = is_tag_present(yml, ADDRESS_PORT_TAG); - if (port_set) - { - port = get(yml, ADDRESS_PORT_TAG, version); - } - else - { - port = Address::default_port(); - } - - // WARNING: This adds logic to the parse of the entity, - // This may not be the best place to do so. In the future move this logic to the Address class. - - // Optional get external port - // If it is not set, same as internal port is used - PortType external_port; - bool external_port_set = is_tag_present(yml, ADDRESS_EXTERNAL_PORT_TAG); - if (external_port_set) - { - external_port = get(yml, ADDRESS_EXTERNAL_PORT_TAG, version); - } - else - { - external_port = port; - } - - // Optional get Transport protocol - TransportProtocol tp; - bool tp_set = is_tag_present(yml, ADDRESS_TRANSPORT_TAG); - if (tp_set) - { - tp = get(yml, ADDRESS_TRANSPORT_TAG, version); - } - else - { - tp = Address::default_transport_protocol(); - } - - // Construct Address object - if (domain_name_set) - { - if (ip_version_set) - { - return Address(port, external_port, ip_version, domain_name, tp); - } - else - { - return Address(port, external_port, domain_name, tp); - } - } - else - { - if (ip_version_set) - { - return Address(ip, port, external_port, ip_version, tp); - } - else - { - return Address(ip, port, external_port, tp); - } - } -} - -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_v1( - const Yaml& yml, - const YamlReaderVersion version) -{ - // GuidPrefix required - GuidPrefix server_guid = YamlReader::get(yml, version); - - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(server_guid, addresses); -} - -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_latest( - const Yaml& yml, - const YamlReaderVersion version) -{ - // GuidPrefix required - GuidPrefix server_guid = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); - - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(server_guid, addresses); -} - -template <> -DiscoveryServerConnectionAddress YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - switch (version) - { - case V_1_0: - return _get_discovery_server_connection_address_v1(yml, version); - - default: - return _get_discovery_server_connection_address_latest(yml, version); - } -} - -/************************ -* QoS * -************************/ - -template <> -void YamlReader::fill( - TopicQoS& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Reliability optional - if (is_tag_present(yml, QOS_RELIABLE_TAG)) - { - if (get(yml, QOS_RELIABLE_TAG, version)) - { - object.reliability_qos = eprosima::ddspipe::core::types::ReliabilityKind::RELIABLE; - } - else - { - object.reliability_qos = eprosima::ddspipe::core::types::ReliabilityKind::BEST_EFFORT; - } - } - - // Durability optional - if (is_tag_present(yml, QOS_TRANSIENT_TAG)) - { - if (get(yml, QOS_TRANSIENT_TAG, version)) - { - object.durability_qos = eprosima::ddspipe::core::types::DurabilityKind::TRANSIENT_LOCAL; - } - else - { - object.durability_qos = eprosima::ddspipe::core::types::DurabilityKind::VOLATILE; - } - } - - // History depth optional - if (is_tag_present(yml, QOS_HISTORY_DEPTH_TAG)) - { - object.history_depth = get(yml, QOS_HISTORY_DEPTH_TAG, version); - } - - // Durability optional - if (is_tag_present(yml, QOS_PARTITION_TAG)) - { - object.use_partitions = get(yml, QOS_PARTITION_TAG, version); - } - - // Optional keyed - if (is_tag_present(yml, TOPIC_KIND_TAG)) - { - object.keyed = get(yml, TOPIC_KIND_TAG, version); - } - - // Ownership optional - if (is_tag_present(yml, QOS_OWNERSHIP_TAG)) - { - if (get(yml, QOS_OWNERSHIP_TAG, version)) - { - object.ownership_qos = eprosima::ddspipe::core::types::OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS; - } - else - { - object.ownership_qos = eprosima::ddspipe::core::types::OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS; - } - } -} - -/************************ -* TOPICS * -************************/ - -template <> -void YamlReader::fill( - DdsTopic& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Name required - object.m_topic_name = get(yml, TOPIC_NAME_TAG, version); - - // Data Type required - object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); - - // Optional QoS - if (is_tag_present(yml, TOPIC_QOS_TAG)) - { - fill(object.topic_qos, get_value_in_tag(yml, TOPIC_QOS_TAG), version); - } -} - -template <> -DdsTopic YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - DdsTopic object; - fill(object, yml, version); - return object; -} - -template <> -void YamlReader::fill( - WildcardDdsFilterTopic& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Required name - object.topic_name = get(yml, TOPIC_NAME_TAG, version); - - // Optional data type - if (is_tag_present(yml, TOPIC_TYPE_NAME_TAG)) - { - object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); - } - - // TODO: decide whether we want to use QoS as filtering -} - -template <> -WildcardDdsFilterTopic YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - WildcardDdsFilterTopic object; - fill(object, yml, version); - return object; -} - -/************************ -* TLS CONFIGURATION * -************************/ - -template <> -void YamlReader::fill( - TlsConfiguration& object, - const Yaml& yml, - const YamlReaderVersion version) -{ - // Optional private key - if (is_tag_present(yml, TLS_PRIVATE_KEY_TAG)) - { - object.private_key_file = get(yml, TLS_PRIVATE_KEY_TAG, version); - } - - // Optional private key password - if (is_tag_present(yml, TLS_PASSWORD_TAG)) - { - object.private_key_file_password = get(yml, TLS_PASSWORD_TAG, version); - } - - // Optional certificate authority - if (is_tag_present(yml, TLS_CA_TAG)) - { - object.certificate_authority_file = get(yml, TLS_CA_TAG, version); - } - - // Optional certificate chain - if (is_tag_present(yml, TLS_CERT_TAG)) - { - object.certificate_chain_file = get(yml, TLS_CERT_TAG, version); - } - - // Optional SNI server name - if (is_tag_present(yml, TLS_SNI_HOST_TAG)) - { - object.sni_server_name = get(yml, TLS_SNI_HOST_TAG, version); - } - - // Optional dh params - if (is_tag_present(yml, TLS_DHPARAMS_TAG)) - { - object.dh_params_file = get(yml, TLS_DHPARAMS_TAG, version); - } - - // Optional peer verification - if (is_tag_present(yml, TLS_PEER_VERIFICATION_TAG)) - { - object.verify_peer = get(yml, TLS_PEER_VERIFICATION_TAG, version); - } - - // Check if it should be client or server - utils::Formatter dummy_formatter__; - utils::Formatter error_msg_client; - utils::Formatter error_msg_server; - if (object.is_valid_kind(dummy_formatter__)) - { - object.kind = TlsKind::both; - } - else if (object.is_valid_kind(error_msg_client)) - { - object.kind = TlsKind::client; - } - else if (object.is_valid_kind(error_msg_server)) - { - object.kind = TlsKind::server; - } - else - { - throw eprosima::utils::ConfigurationException( - STR_ENTRY << "Incorrect TLS configuration." << - " Could not be client because: " << error_msg_client << - " Neither server because: " << error_msg_server << - "." - ); - } -} - -template <> -TlsConfiguration YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - TlsConfiguration object; - fill(object, yml, version); - return object; -} - -std::ostream& operator <<( - std::ostream& os, - const YamlReaderVersion& version) -{ - switch (version) - { - case V_1_0: - os << VERSION_TAG_V_1_0; - break; - - case V_2_0: - os << VERSION_TAG_V_2_0; - break; - - case V_3_0: - case LATEST: - os << VERSION_TAG_V_3_0; - break; - - default: - utils::tsnh(STR_ENTRY << "Value of YamlReaderVersion out of enumeration."); - break; - } - - return os; -} - -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/test/CMakeLists.txt b/ddspipe_yaml/test/CMakeLists.txt deleted file mode 100644 index 1c95f651f..000000000 --- a/ddspipe_yaml/test/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2022 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. - -# Add subdirectory with tests -add_subdirectory(unittest) diff --git a/ddspipe_yaml/test/unittest/CMakeLists.txt b/ddspipe_yaml/test/unittest/CMakeLists.txt deleted file mode 100644 index 871251792..000000000 --- a/ddspipe_yaml/test/unittest/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2022 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. - -############## -# Yaml Tests # -############## - -add_subdirectory(entities) -add_subdirectory(yaml_reader) diff --git a/ddspipe_yaml/test/unittest/entities/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/CMakeLists.txt deleted file mode 100644 index 2ec0d67eb..000000000 --- a/ddspipe_yaml/test/unittest/entities/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2022 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. - -######################### -# Yaml GetEntities Test # -######################### - -add_subdirectory(address) -add_subdirectory(guid) -# TODO uncommment when ready -# add_subdirectory(topic) diff --git a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt deleted file mode 100644 index 143b72bb1..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright 2022 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. - -################################ -# Yaml GetEntities Adress Test # -################################ - -set(TEST_NAME YamlGetEntityAddressTest) - -set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - YamlGetEntityAddressTest.cpp - ) - -set(TEST_LIST - get_transport_protocol - get_ip_version - get_port - get_ip - get_address_ip - get_address_domain - get_address_defaults - ip_and_domain - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") - -################################################ -# Yaml GetEntities DiscoveryServerAddress Test # -################################################ - -set(TEST_NAME YamlGetEntityDiscoveryServerAddressTest) - -set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - YamlGetEntityDiscoveryServerAddressTest.cpp - ) - -set(TEST_LIST - get_ds_address - get_ds_address_negative - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp b/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp deleted file mode 100644 index cc570cfd7..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityAddressTest.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -// In order to not create an enormous terrible file, each unit test has been implemented in different and independent -// files in folder "test_units", and all these files are included only from here, so they are compilated and tested. - -#include "test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp" -#include "test_units/YamlGetEntityAddressTest_get_ip_version.ipp" -#include "test_units/YamlGetEntityAddressTest_get_port.ipp" -#include "test_units/YamlGetEntityAddressTest_get_ip.ipp" -#include "test_units/YamlGetEntityAddressTest_get_address_ip.ipp" -#include "test_units/YamlGetEntityAddressTest_get_address_domain.ipp" -#include "test_units/YamlGetEntityAddressTest_get_address_defaults.ipp" -#include "test_units/YamlGetEntityAddressTest_ip_and_domain.ipp" - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp b/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp deleted file mode 100644 index 0b1c3ac1c..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -// In order to not create an enormous terrible file, each unit test has been implemented in different and independent -// files in folder "test_units", and all these files are included only from here, so they are compilated and tested. - -#include "test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp" -#include "test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp" - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp deleted file mode 100644 index 83f36cadd..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_defaults.ipp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read an address checking that default values are being used - * - * POSITIVE CASES: - * - empty - * - with ip version ipv6 - */ -TEST(YamlGetEntityAddressTest, get_address_defaults) -{ - // empty - { - Yaml yml_address; - - Yaml yml; - yml["address"] = yml_address; - - // Get participants::types::Address from Yaml - ASSERT_THROW(YamlReader::get(yml, "address", - LATEST), eprosima::utils::ConfigurationException); - } - - // with ip version ipv6 - { - Yaml yml_address; - - // Add IP with ip-version ipv6 - add_field_to_yaml( - yml_address, - YamlField("::1"), - ADDRESS_IP_TAG); - - Yaml yml; - yml["address"] = yml_address; - - // Get participants::types::Address from Yaml - participants::types::Address result = YamlReader::get(yml, "address", LATEST); - - // Check result - ASSERT_EQ("::1", result.ip()); - ASSERT_EQ(participants::types::Address::default_port(), result.port()); - ASSERT_EQ(participants::types::Address::default_port(), result.external_port()); - ASSERT_EQ(participants::types::Address::default_transport_protocol(), result.transport_protocol()); - ASSERT_EQ(participants::types::IpVersion::v6, result.ip_version()); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp deleted file mode 100644 index 1fef1a1d0..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_domain.ipp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read an address with domain name - * - * The only test able to run in every host is localhost domain - * - * POSITIVE CASES: - * - localhost - * - localhost specifying version - */ -TEST(YamlGetEntityAddressTest, get_address_domain) -{ - // localhost - { - Yaml yml_address; - - // Add IP - add_field_to_yaml( - yml_address, - YamlField("localhost"), - ADDRESS_DNS_TAG); - - // Add IP version - add_field_to_yaml( - yml_address, - YamlField(ADDRESS_IP_VERSION_V4_TAG), - ADDRESS_IP_VERSION_TAG); - - Yaml yml; - yml["address"] = yml_address; - - // Get participants::types::Address from Yaml - participants::types::Address result = YamlReader::get(yml, "address", LATEST); - - // Check result - ASSERT_EQ(participants::types::IpVersion::v4, result.ip_version()); - ASSERT_EQ("127.0.0.1", result.ip()); - } - - // localhost specifying version - { - Yaml yml_address; - - // Add IP - add_field_to_yaml( - yml_address, - YamlField("localhost"), - ADDRESS_DNS_TAG); - - Yaml yml; - yml["address"] = yml_address; - - // Get participants::types::Address from Yaml - participants::types::Address result = YamlReader::get(yml, "address", LATEST); - - // Check result - ASSERT_EQ(participants::types::IpVersion::v4, result.ip_version()); - ASSERT_EQ("127.0.0.1", result.ip()); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp deleted file mode 100644 index 29163c5f3..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_address_ip.ipp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read an address with IP - * - * POSITIVE CASES: - * - ipv4 - * - ipv6 - */ -TEST(YamlGetEntityAddressTest, get_address_ip) -{ - // ipv4 - { - std::vector ips = { - "1.1.1.1", - "127.0.0.1", - "8.8.8.8", - }; - - for (participants::types::IpType ip : ips) - { - Yaml yml_address; - - // Add IP - add_field_to_yaml( - yml_address, - YamlField(ip), - ADDRESS_IP_TAG); - - // Add IP version - add_field_to_yaml( - yml_address, - YamlField(ADDRESS_IP_VERSION_V4_TAG), - ADDRESS_IP_VERSION_TAG); - - Yaml yml; - yml["address"] = yml_address; - - // Get participants::types::Address from Yaml - participants::types::Address result = YamlReader::get(yml, "address", LATEST); - - // Check result - ASSERT_EQ(participants::types::IpVersion::v4, result.ip_version()); - ASSERT_EQ(ip, result.ip()); - } - } - - // ipv6 - { - std::vector ips = { - "::1", - "12:34::89", - "2001:0DB8:0000:0000:0000:0000:1428:57ab", - }; - - for (participants::types::IpType ip : ips) - { - Yaml yml_address; - - // Add IP - add_field_to_yaml( - yml_address, - YamlField(ip), - ADDRESS_IP_TAG); - - // Add IP version - add_field_to_yaml( - yml_address, - YamlField(ADDRESS_IP_VERSION_V6_TAG), - ADDRESS_IP_VERSION_TAG); - - Yaml yml; - yml["address"] = yml_address; - - // Get participants::types::Address from Yaml - participants::types::Address result = YamlReader::get(yml, "address", LATEST); - - // Check result - ASSERT_EQ(participants::types::IpVersion::v6, result.ip_version()); - ASSERT_EQ(ip, result.ip()); - } - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp deleted file mode 100644 index a92a90f51..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip.ipp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read IP from yaml - * - * POSITIVE CASES: - * - string values - * - * NEGATIVE CASES: - * - Empty - */ -TEST(YamlGetEntityAddressTest, get_ip) -{ - // string values - { - std::vector ips = { - "1.1.1.1", - "::1", - "127.0.0.1", - }; - - for (participants::types::IpType ip : ips) - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(ip), - ADDRESS_IP_TAG); - - ASSERT_EQ(ip, YamlReader::get(yml, ADDRESS_IP_TAG, LATEST)); - } - } - - // Empty - { - Yaml yml; - - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), - eprosima::utils::ConfigurationException); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp deleted file mode 100644 index 7adc34c71..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_ip_version.ipp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read Transport Protocol from yaml - * - * POSITIVE CASES: - * - v4 - * - v6 - * - * NEGATIVE CASES: - * - Empty - * - Incorrect value name - * - Incorrect format - */ -TEST(YamlGetEntityAddressTest, get_ip_version) -{ - // v4 - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(ADDRESS_IP_VERSION_V4_TAG), - ADDRESS_IP_VERSION_TAG); - - participants::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); - - ASSERT_EQ(iv, participants::types::IpVersion::v4); - } - - // v6 - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(ADDRESS_IP_VERSION_V6_TAG), - ADDRESS_IP_VERSION_TAG); - - participants::types::IpVersion iv = YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST); - - ASSERT_EQ(iv, participants::types::IpVersion::v6); - } - - // Empty - { - Yaml yml; - - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), - eprosima::utils::ConfigurationException); - } - - // Incorrect value name - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField("v7"), - ADDRESS_IP_VERSION_TAG); - - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), - eprosima::utils::ConfigurationException); - } - - // Incorrect format - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(17), - ADDRESS_IP_VERSION_TAG); - - ASSERT_THROW(YamlReader::get(yml, ADDRESS_IP_VERSION_TAG, LATEST), - eprosima::utils::ConfigurationException); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp deleted file mode 100644 index 96c7d09c5..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_port.ipp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read port from yaml - * - * POSITIVE CASES: - * - numeric values - * - * NEGATIVE CASES: - * - Empty - * - Incorrect format (string) - */ -TEST(YamlGetEntityAddressTest, get_port) -{ - // numeric values - { - std::vector ports = {1, 11, 111, 11666, 11777, 65535}; - for (participants::types::PortType port : ports) - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(port), - ADDRESS_PORT_TAG); - - ASSERT_EQ(port, YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST)); - } - } - - // Empty - { - Yaml yml; - - ASSERT_THROW( - YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST), - eprosima::utils::ConfigurationException); - } - - // Incorrect format (string) - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField("P11000"), - ADDRESS_PORT_TAG); - - ASSERT_THROW( - YamlReader::get(yml, ADDRESS_PORT_TAG, LATEST), - eprosima::utils::ConfigurationException); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp deleted file mode 100644 index e80c385cc..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_get_transport_protocol.ipp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read Transport Protocol from yaml - * - * POSITIVE CASES: - * - UDP - * - TCP - * - * NEGATIVE CASES: - * - Empty - * - Incorrect tag - */ -TEST(YamlGetEntityAddressTest, get_transport_protocol) -{ - // UDP - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(ADDRESS_TRANSPORT_UDP_TAG), - ADDRESS_TRANSPORT_TAG); - - participants::types::TransportProtocol tp = - YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); - - ASSERT_EQ(tp, participants::types::TransportProtocol::udp); - } - - // TCP - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(ADDRESS_TRANSPORT_TCP_TAG), - ADDRESS_TRANSPORT_TAG); - - participants::types::TransportProtocol tp = - YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); - - ASSERT_EQ(tp, participants::types::TransportProtocol::tcp); - } - - // Empty - { - Yaml yml; - - ASSERT_THROW( - YamlReader::get( - yml, - ADDRESS_TRANSPORT_TAG, - LATEST), - eprosima::utils::ConfigurationException); - } - - // Incorrect tag - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField("utcp"), - ADDRESS_TRANSPORT_TAG); - - ASSERT_THROW( - YamlReader::get( - yml, - ADDRESS_TRANSPORT_TAG, - LATEST), - eprosima::utils::ConfigurationException); - } - - // Incorrect format - { - Yaml yml; - add_field_to_yaml( - yml, - YamlField(17), - ADDRESS_TRANSPORT_TAG); - - ASSERT_THROW( - YamlReader::get( - yml, - ADDRESS_TRANSPORT_TAG, - LATEST), - eprosima::utils::ConfigurationException); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp deleted file mode 100644 index f98ecbd45..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityAddressTest_ip_and_domain.ipp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test the behaviour when both ip and domain are given. - * - * The expected behaviour is for the yml to use only IP and show a warning - */ -TEST(YamlGetEntityAddressTest, ip_and_domain) -{ - // Check a warning is shown - // eprosima::ddspipe::core::TestLogHandler log_handler(utils::Log::Kind::Warning, 1); - INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Warning, 1, 0); - - // Set address - Yaml yml_address; - - // Add domain - ddspipe::yaml::testing::add_field_to_yaml( - yml_address, - ddspipe::yaml::testing::YamlField("localhost"), - ADDRESS_DNS_TAG); - - // Add ip - participants::types::IpType ip_value = "1.1.1.1"; - ddspipe::yaml::testing::add_field_to_yaml( - yml_address, - ddspipe::yaml::testing::YamlField(ip_value), - ADDRESS_IP_TAG); - - Yaml yml; - yml[ADDRESS_TRANSPORT_TAG] = yml_address; - - participants::types::Address address = YamlReader::get(yml, ADDRESS_TRANSPORT_TAG, LATEST); - - ASSERT_EQ(address.ip(), ip_value); -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp deleted file mode 100644 index 033cabcf5..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2022 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. - -#include -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::participants::testing; -using namespace eprosima::ddspipe::yaml::testing; - -const constexpr unsigned int TEST_ADDRESSES_NUMBER = 5; - -/** - * Test read a discovery server - * - * POSITIVE CASES: - * - one address - * - several addresses - */ -TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) -{ - // one address - { - Yaml yml_ds_address; - - // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; - - // Get random address and add it to yaml - participants::types::Address address = random_address(); - Yaml yml_addresses; - Yaml yml_address; - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - - yml_addresses.push_back(yml_address); - - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Generate overall yaml - Yaml yml; - yml["ds-address"] = yml_ds_address; - - // Create object DiscoveryServerAddress from yaml - participants::types::DiscoveryServerConnectionAddress result = - YamlReader::get(yml, "ds-address", LATEST); - - // Check result - ASSERT_EQ(guid_prefix, result.discovery_server_guid_prefix()); - ASSERT_EQ(result.addresses().size(), 1u); - ASSERT_EQ(address, *result.addresses().begin()); - } - - // several addresses - { - Yaml yml_ds_address; - - // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; - - // Get random address and add it to yaml - Yaml yml_addresses; - std::vector addresses; - for (unsigned int i = 0; i < TEST_ADDRESSES_NUMBER; i++) - { - // Create new address and add it to already created addresses and to yaml - Yaml yml_address; - participants::types::Address address = random_address(i); - - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - - addresses.push_back(address); - yml_addresses.push_back(yml_address); - } - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Generate overall yaml - Yaml yml; - yml["ds-address"] = yml_ds_address; - - // Create object DiscoveryServerAddress from yaml - participants::types::DiscoveryServerConnectionAddress result = - YamlReader::get(yml, "ds-address", LATEST); - - // Check result - ASSERT_EQ(guid_prefix, result.discovery_server_guid_prefix()); - ASSERT_EQ(result.addresses().size(), TEST_ADDRESSES_NUMBER); - - // Check every address introduced in yaml is in result - for (participants::types::Address address : addresses) - { - // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses = result.addresses(); - ASSERT_NE(addresses.find(address), addresses.end()); - } - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp deleted file mode 100644 index 4069f3580..000000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read a discovery server connection address that fails - * - * NEGATIVE CASES: - * - empty - * - no guid prefix - * - no addresses - * - error format in guid prefix - * - error format in addresses - */ -TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) -{ - // empty - { - Yaml yml_empty; - Yaml yml; - yml["connection-address"] = yml_empty; - - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } - - // no guid prefix - { - Yaml yml_ds_address; - - // Get random address and add it to yaml - participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); - Yaml yml_addresses; - Yaml yml_address; - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - yml_addresses.push_back(yml_address); - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - Yaml yml; - yml["connection-address"] = yml_ds_address; - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } - - // no addresses - { - Yaml yml_ds_address; - - // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; - - Yaml yml; - yml["connection-address"] = yml_ds_address; - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } - - // error format in guid prefix - { - Yaml yml_ds_address; - - // Get random address and add it to yaml - participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); - Yaml yml_addresses; - Yaml yml_address; - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - yml_addresses.push_back(yml_address); - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Guid Prefix error format (inside a sequence) - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - Yaml yml_guid_aux; - yml_guid_aux.push_back(yml_guid); - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid_aux; - - Yaml yml; - yml["connection-address"] = yml_ds_address; - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } - - // error format in addresses - { - Yaml yml_ds_address; - - // Address error (in map instead of sequence) - participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); - Yaml yml_addresses; - Yaml yml_address; - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - yml_addresses["address1"] = yml_address; - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; - - Yaml yml; - yml["connection-address"] = yml_ds_address; - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } -} diff --git a/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt deleted file mode 100644 index e67669ec3..000000000 --- a/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2022 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. - -#################################### -# Yaml GetEntities GuidPrefix Test # -#################################### - -set(TEST_NAME YamlGetEntityGuidPrefixTest) - -set(TEST_SOURCES - YamlGetEntityGuidPrefixTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp - - ) - -set(TEST_LIST - get_guidprefix_explicitly - get_guidprefix_id - get_guidprefix_id_ros - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp b/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp deleted file mode 100644 index e71c0366e..000000000 --- a/ddspipe_yaml/test/unittest/entities/guid/YamlGetEntityGuidPrefixTest.cpp +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read core::types::GuidPrefix from yaml with explicit guid - * - * POSITIVE CASES: - * - std core::types::GuidPrefix - * - str guidprefix and id - * - * NEGATIVE CASES: - * - empty - * - incorrect format (not string) - * - incorrect guid - */ -TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_explicitly) -{ - // std core::types::GuidPrefix - { - std::string st = "01.0f.00.00.00.00.00.00.00.00.ff.ff"; - - Yaml yml_gp; - add_field_to_yaml( - yml_gp, - YamlField(st), - DISCOVERY_SERVER_GUID_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - ASSERT_EQ(gp_result, core::types::GuidPrefix(st)); - } - - // str guidprefix and id - { - std::string st = "01.0f.00.00.00.00.00.00.00.00.ff.ff"; - - Yaml yml_gp; - add_field_to_yaml( - yml_gp, - YamlField(st), - DISCOVERY_SERVER_GUID_TAG); - - // This field must be skipped - add_field_to_yaml( - yml_gp, - YamlField(0), - DISCOVERY_SERVER_ID_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - ASSERT_EQ(gp_result, core::types::GuidPrefix(st)); - } - - // empty - { - Yaml yml_gp; - Yaml yml; - yml["guid_prefix"] = yml_gp; - - ASSERT_THROW( - YamlReader::get(yml, "guid_prefix", LATEST), - eprosima::utils::ConfigurationException); - } - - // TODO: this tests requires to modify fastrtps core::types::GuidPrefix >> operator so it returns a non valid guid - // incorrect format (not string) - // { - // Yaml yml_gp; - // add_field_to_yaml( - // yml_gp, - // YamlField(false), - // DISCOVERY_SERVER_GUID_TAG); - - // Yaml yml; - // yml["guid_prefix"] = yml_gp; - - // // bool to str in yamlcpp does not cause an error - // core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - // ASSERT_FALSE(gp_result.is_valid()) << gp_result; - // } - - // // incorrect guid - // { - // std::string st = "ffff"; - - // Yaml yml_gp; - // add_field_to_yaml( - // yml_gp, - // YamlField(st), - // DISCOVERY_SERVER_GUID_TAG); - - // Yaml yml; - // yml["guid_prefix"] = yml_gp; - - // // incorrect guid does not cause an error - // core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - // ASSERT_FALSE(gp_result.is_valid()); - // } -} - -/** - * Test read core::types::GuidPrefix from yaml given an id - * - * POSITIVE CASES: - * - std ids - * - * NEGATIVE CASES: - * - incorrect format (str instead of int) - */ -TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id) -{ - // std ids - { - std::vector ids = {0, 2, 12, 234}; - - for (uint32_t id : ids) - { - Yaml yml_gp; - add_field_to_yaml( - yml_gp, - YamlField(id), - DISCOVERY_SERVER_ID_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - ASSERT_EQ(gp_result, core::types::GuidPrefix(id)); - } - } - - // incorrect format (str instead of int) - { - Yaml yml_gp; - - add_field_to_yaml( - yml_gp, - YamlField("01.0f.00.00.00.00.00.00.00.00.ff.ff"), - DISCOVERY_SERVER_ID_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - ASSERT_THROW(YamlReader::get(yml, "guid_prefix", LATEST), - eprosima::utils::ConfigurationException); - } -} - -/** - * Test read core::types::GuidPrefix from yaml with id and using ros - * - * POSITIVE CASES: - * - std ids with ros - * - std ids without ros - * - * NEGATIVE CASES: - * - incorrect format (str instead of bool) - */ -TEST(YamlGetEntityGuidPrefixTest, get_guidprefix_id_ros) -{ - // std ids with ros - { - std::vector ids = {0, 2, 12, 234}; - - for (uint32_t id : ids) - { - Yaml yml_gp; - - add_field_to_yaml( - yml_gp, - YamlField(id), - DISCOVERY_SERVER_ID_TAG); - - add_field_to_yaml( - yml_gp, - YamlField(true), - DISCOVERY_SERVER_ID_ROS_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - ASSERT_EQ(gp_result, core::types::GuidPrefix(true, id)); - } - } - - // std ids without ros - { - std::vector ids = {0, 2, 12, 234}; - - for (uint32_t id : ids) - { - Yaml yml_gp; - - add_field_to_yaml( - yml_gp, - YamlField(id), - DISCOVERY_SERVER_ID_TAG); - - add_field_to_yaml( - yml_gp, - YamlField(false), - DISCOVERY_SERVER_ID_ROS_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - core::types::GuidPrefix gp_result = YamlReader::get(yml, "guid_prefix", LATEST); - - ASSERT_EQ(gp_result, core::types::GuidPrefix(false, id)); - } - } - - // incorrect format (str instead of int) - { - Yaml yml_gp; - - add_field_to_yaml( - yml_gp, - YamlField(0), - DISCOVERY_SERVER_ID_TAG); - - add_field_to_yaml( - yml_gp, - YamlField("01.0f.00.00.00.00.00.00.00.00.ff.ff"), - DISCOVERY_SERVER_ID_ROS_TAG); - - Yaml yml; - yml["guid_prefix"] = yml_gp; - - ASSERT_THROW(YamlReader::get(yml, "guid_prefix", LATEST), - eprosima::utils::ConfigurationException); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt deleted file mode 100644 index 711c89498..000000000 --- a/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2022 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. - -############################### -# Yaml GetEntities Topic Test # -############################### - -set(TEST_NAME YamlGetEntityTopicTest) - -set(TEST_SOURCES - YamlGetEntityTopicTest.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp - - ) - -set(TEST_LIST - get_real_topic - get_wildcard_topic - get_wildcard_topic_negative - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp b/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp deleted file mode 100644 index 405f19cb7..000000000 --- a/ddspipe_yaml/test/unittest/entities/topic/YamlGetEntityTopicTest.cpp +++ /dev/null @@ -1,318 +0,0 @@ -// Copyright 2021 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. - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -namespace eprosima { -namespace ddspipe { -namespace yaml { -namespace test { - -// Create a yaml QoS object only with reliability -void qos_to_yaml( - Yaml& yml, - const YamlField& reliable) -{ - // TODO: extend this for all qos - add_field_to_yaml(yml, reliable, QOS_RELIABLE_TAG); -} - -// Create a yaml Topic object with name, type and key tags -void topic_to_yaml( - Yaml& yml, - const YamlField& name, - const YamlField& type, - const YamlField& qos) -{ - add_field_to_yaml(yml, name, TOPIC_NAME_TAG); - add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); - add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); -} - -// Create a yaml DdsTopic object with name, type, key and reliable tags -void real_topic_to_yaml( - Yaml& yml, - const YamlField& name, - const YamlField& type, - const YamlField& qos) -{ - add_field_to_yaml(yml, name, TOPIC_NAME_TAG); - add_field_to_yaml(yml, type, TOPIC_TYPE_NAME_TAG); - add_field_to_yaml(yml, qos, TOPIC_QOS_TAG); -} - -// Check the values of a real topic are the expected ones -void compare_topic( - core::types::DdsTopic topic, - std::string name, - std::string type, - bool has_reliability_set = false, - bool reliable = false) -{ - ASSERT_EQ(topic.m_topic_name, name); - ASSERT_EQ(topic.type_name, type); - - if (has_reliability_set) - { - eprosima::ddspipe::core::types::ReliabilityKind expected_reliability_qos; - if (reliable) - { - expected_reliability_qos = core::types::ReliabilityKind::RELIABLE; - } - else - { - expected_reliability_qos = core::types::ReliabilityKind::BEST_EFFORT; - } - - ASSERT_EQ(topic.topic_qos.reliability_qos, expected_reliability_qos); - } -} - -// Check the values of a wildcard topic are the expected ones -void compare_wildcard_topic( - core::types::WildcardDdsFilterTopic topic, - std::string name, - bool type_set, - std::string type) -{ - ASSERT_EQ(topic.topic_name, name); - - if (type_set) - { - ASSERT_TRUE(topic.type_name.is_set()); - ASSERT_EQ(topic.type_name, type); - } -} - -} /* namespace test */ -} /* namespace yaml */ -} /* namespace ddspipe */ -} /* namespace eprosima */ - -/** - * Test read core::types::DdsTopic from yaml - * - * POSITIVE CASES: - * - Topic Std - * - * NEGATIVE CASES: - * - Empty - * - Topic without name - * - Topic without type - */ -TEST(YamlGetEntityTopicTest, get_real_topic) -{ - std::string name = "topic_name"; - std::string type = "topic_type"; - - // Topic Std - { - Yaml yml_topic; - topic_to_yaml( - yml_topic, - YamlField(name), - YamlField(type), - YamlField(), - YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - - compare_topic(topic, name, type, false); - } - - // Checks that a topic yaml object has been parsed correctly with the topic reliable tag set to true. - // A topic configured as reliable creates RELIABLE-TRANSIENT_LOCAL RTPS Readers in order to ensure - // that no data is lost in the information relay. - { - Yaml yml_qos; - qos_to_yaml(yml_qos, YamlField(true)); - - Yaml yml_topic; - real_topic_to_yaml( - yml_topic, - YamlField(name), - YamlField(type), - YamlField(false), - YamlField(yml_qos)); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::DdsTopic topic = YamlReader::get(yml, "topic", LATEST); - - compare_topic(topic, name, type, true, true); - } - - // Empty - { - Yaml yml_topic; - Yaml yml; - yml["topic"] = yml_topic; - - ASSERT_THROW(YamlReader::get(yml, "topic", - LATEST), eprosima::utils::ConfigurationException); - } - - // Topic without name - { - Yaml yml_topic; - topic_to_yaml( - yml_topic, - YamlField(), - YamlField(type), - YamlField(), - YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - ASSERT_THROW(YamlReader::get(yml, "topic", - LATEST), eprosima::utils::ConfigurationException); - } - - // Topic without type - { - Yaml yml_topic; - topic_to_yaml( - yml_topic, - YamlField(name), - YamlField(), - YamlField(), - YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - ASSERT_THROW(YamlReader::get(yml, "topic", - LATEST), eprosima::utils::ConfigurationException); - } -} - -/** - * Test read correct core::types::WildcardDdsFilterTopic from yaml - * - * POSITIVE CASES: - * - Topic Std - * - Topic without type - */ -TEST(YamlGetEntityTopicTest, get_wildcard_topic) -{ - std::string name = "topic_name"; - std::string type = "topic_type"; - - // Topic Std - { - Yaml yml_topic; - topic_to_yaml( - yml_topic, - YamlField(name), - YamlField(type), - YamlField(), - YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", - LATEST); - - compare_wildcard_topic(topic, name, true, type, false); - } - - // Topic without type - { - Yaml yml_topic; - topic_to_yaml( - yml_topic, - YamlField(name), - YamlField(), - YamlField(), - YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - core::types::WildcardDdsFilterTopic topic = YamlReader::get(yml, "topic", - LATEST); - - compare_wildcard_topic(topic, name, false, "*", false); - } -} - -/** - * Test read correct core::types::WildcardDdsFilterTopic from yaml - * - * NEGATIVE CASES: - * - empty - * - without name - */ -TEST(YamlGetEntityTopicTest, get_wildcard_topic_negative) -{ - std::string name = "topic_name"; - std::string type = "topic_type"; - - // empty - { - Yaml yml_topic; - Yaml yml; - yml["topic"] = yml_topic; - - ASSERT_THROW(YamlReader::get(yml, "topic", - LATEST), eprosima::utils::ConfigurationException); - } - - // Topic without type - { - Yaml yml_topic; - topic_to_yaml( - yml_topic, - YamlField(), - YamlField(type), - YamlField(), - YamlField()); - - Yaml yml; - yml["topic"] = yml_topic; - - ASSERT_THROW(YamlReader::get(yml, "topic", - LATEST), eprosima::utils::ConfigurationException); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt deleted file mode 100644 index f6f6d65e2..000000000 --- a/ddspipe_yaml/test/unittest/yaml_reader/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2022 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. - -############################ -# Yaml Reader Scalaer Test # -############################ - -set(TEST_NAME YamlReaderScalarTest) - -set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - YamlReaderScalarTest.cpp - ) - -set(TEST_LIST - get_scalar_bool - get_scalar_int - get_scalar_string - get_scalar_from_tag - get_scalar_negative_cases - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastrtps - cpp_utils - ddspipe_core - ddspipe_participants - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp b/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp deleted file mode 100644 index cffd53377..000000000 --- a/ddspipe_yaml/test/unittest/yaml_reader/YamlReaderScalarTest.cpp +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2022 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. - -#include -#include - -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe::yaml; - -/** - * Check to get a boolean from a yaml - * - * CASES: - * true - * false - * fail with int - */ -TEST(YamlReaderScalarTest, get_scalar_bool) -{ - // true - { - Yaml yml(true); - ASSERT_TRUE(YamlReader::get_scalar(yml)); - } - - // false - { - Yaml yml(false); - ASSERT_FALSE(YamlReader::get_scalar(yml)); - } - - // fail with int - { - Yaml yml(0); - ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); - } -} - -/** - * Check to get an int from a yaml - * - * For each case are tested arbitrary numbers (power of 2) and negative ones in signed cases - * - * CASES: - * int - * uint - * uint16 - * int64 - * fail with bool - */ -TEST(YamlReaderScalarTest, get_scalar_int) -{ - // int - { - for (int i = 1; i < 0x1000; i *= 2) - { - ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; - ASSERT_EQ(YamlReader::get_scalar(Yaml(-i)), -i) << -i; - } - } - - // uint - { - for (unsigned int i = 1; i < 0x1000; i *= 2) - { - ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; - } - } - - // uint16 - { - for (uint16_t i = 1; i < 0x1000; i *= 2) - { - ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; - } - } - - // int64 - { - for (int64_t i = 1; i < 0x1000; i *= 2) - { - ASSERT_EQ(YamlReader::get_scalar(Yaml(i)), i) << i; - ASSERT_EQ(YamlReader::get_scalar(Yaml(-i)), -i) << -i; - } - } - - // fail with bool - { - ASSERT_THROW(YamlReader::get_scalar(Yaml(false)), eprosima::utils::ConfigurationException); - } -} - -/** - * Check to get a string from a yaml - - * CASES: - * empty string - * short string - * long string - * numeric string - * numeric - * bool - */ -TEST(YamlReaderScalarTest, get_scalar_string) -{ - // empty string - { - ASSERT_EQ(YamlReader::get_scalar(Yaml("")), ""); - } - - // short string - { - ASSERT_EQ(YamlReader::get_scalar(Yaml("short_text")), "short_text"); - } - - // long string - { - std::string st = - "This text is pretty long, but will be " - "concatenated into just a single string. " - "The disadvantage is that you have to quote " - "each part, and newlines must be literal as " - "usual."; - - ASSERT_EQ(YamlReader::get_scalar(Yaml(st)), st); - } - - // numeric string - { - ASSERT_EQ(YamlReader::get_scalar(Yaml("1234567890")), "1234567890"); - } - - // numeric - { - ASSERT_EQ(YamlReader::get_scalar(Yaml(111)), "111"); - } - - // bool - { - ASSERT_EQ(YamlReader::get_scalar(Yaml(false)), "false"); - } -} - -/** - * Check to get a scalar type under a specific tag - - * CASES: - * bool - * int - * string - * no tag - */ -TEST(YamlReaderScalarTest, get_scalar_from_tag) -{ - const char* tag = "specific_tag"; - - // bool - { - Yaml yml; - yml[tag] = true; - ASSERT_TRUE(YamlReader::get_scalar(yml, tag)); - } - - // int - { - Yaml yml; - yml[tag] = 12345; - ASSERT_EQ(YamlReader::get_scalar(yml, tag), 12345); - } - - // string - { - Yaml yml; - yml[tag] = "this is a text"; - ASSERT_EQ(YamlReader::get_scalar(yml, tag), "this is a text"); - } - - // no tag - { - Yaml yml; - yml["other_tag"] = 3; - ASSERT_THROW(YamlReader::get_scalar(yml, tag), eprosima::utils::ConfigurationException); - } -} - -/** - * Check that get_scalar fails in case that yaml is not a scalar - * - * CASES: - * null - * sequence - * map - */ -TEST(YamlReaderScalarTest, get_scalar_negative_cases) -{ - // null - { - Yaml yml; - ASSERT_TRUE(yml.IsNull()); - ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); - } - - // sequence - { - Yaml yml; - yml.push_back(3); - yml.push_back(4); - ASSERT_TRUE(yml.IsSequence()); - ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); - } - - // map - { - Yaml yml; - yml["1"] = 3; - yml["2"] = 4; - ASSERT_TRUE(yml.IsMap()); - ASSERT_THROW(YamlReader::get_scalar(yml), eprosima::utils::ConfigurationException); - } -} - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp index 0e19b7804..dfbf2e739 100644 --- a/ddsrouter_core/src/cpp/core/DdsRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -140,7 +140,7 @@ utils::ReturnCode DdsRouter::reload_configuration( utils::ReturnCode DdsRouter::start() noexcept { - utils::ReturnCode ret = ddspipe_->start(); + utils::ReturnCode ret = ddspipe_->enable(); if (ret == utils::ReturnCode::RETCODE_OK) { logInfo(DDSROUTER, "Starting DDS Router."); @@ -151,7 +151,7 @@ utils::ReturnCode DdsRouter::start() noexcept utils::ReturnCode DdsRouter::stop() noexcept { - utils::ReturnCode ret = ddspipe_->stop(); + utils::ReturnCode ret = ddspipe_->disable(); if (ret == utils::ReturnCode::RETCODE_OK) { logInfo(DDSROUTER, "Stopping DDS Router."); From 90037d1270173ee95d8078ff640b50d162c138a5 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 17 Feb 2023 09:53:28 +0100 Subject: [PATCH 22/38] update github actions Signed-off-by: jparisu --- .github/workflows/test.yml | 111 +++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d181a2e84..f0b69b737 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,11 @@ name: test on: workflow_dispatch: + inputs: + ddspipe_branch: + description: 'Branch or tag of DDS Pipe repository (https://github.com/eProsima/DDS-Pipe)' + required: true + default: 'main' pull_request: push: branches: @@ -82,6 +87,13 @@ jobs: with: path: DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install OpenSSL uses: ./DDS-Router/.github/actions/install-openssl-windows @@ -124,21 +136,21 @@ jobs: with: cmake_build_type: ${{ matrix.cmake-config }} subpackage: ddspipe_core - subpackage_dir: ddspipe_core + subpackage_dir: ../DDS-Pipe/ddspipe_core - name: Install ddspipe_participants uses: ./DDS-Router/.github/actions/install-router-subpackage-windows with: cmake_build_type: ${{ matrix.cmake-config }} subpackage: ddspipe_participants - subpackage_dir: ddspipe_participants + subpackage_dir: ../DDS-Pipe/ddspipe_participants - name: Install ddspipe_yaml uses: ./DDS-Router/.github/actions/install-router-subpackage-windows with: cmake_build_type: ${{ matrix.cmake-config }} subpackage: ddspipe_yaml - subpackage_dir: ddspipe_yaml + subpackage_dir: ../DDS-Pipe/ddspipe_yaml - name: Install ddsrouter_core uses: ./DDS-Router/.github/actions/install-router-subpackage-windows @@ -217,6 +229,13 @@ jobs: with: path: src/DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -376,6 +395,13 @@ jobs: with: path: src/DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -415,18 +441,6 @@ jobs: --event-handlers=console_direct+ \ --cmake-args -DBUILD_TESTS=ON - - name: Run tests ddspipe - run: | - source install/setup.bash && \ - colcon test \ - --packages-select-regex ddspipe \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude xfail \ - --timeout 60 - if: always() - - name: Run tests ddsrouter_core run: | source install/setup.bash && \ @@ -492,6 +506,13 @@ jobs: with: path: src/DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -530,18 +551,6 @@ jobs: --metas src/DDS-Router/.github/workflows/test_colcon.meta \ --mixin coverage-gcc asan-gcc - - name: Run tests ddspipe - run: | - source install/setup.bash && \ - colcon test \ - --packages-select-regex ddspipe \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-regex xfail \ - --timeout 60 - if: always() - - name: Run tests ddsrouter_core run: | source install/setup.bash && \ @@ -587,6 +596,13 @@ jobs: with: path: src/DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -626,21 +642,6 @@ jobs: --event-handlers=console_direct+ \ --metas src/DDS-Router/.github/workflows/asan_colcon.meta - - name: Run tests ddspipe_core - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddspipe_core - - - name: Run tests ddspipe_participants - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddspipe_participants - - - name: Run tests ddspipe_yaml - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddspipe_yaml - - name: Run tests ddsrouter_core uses: ./src/DDS-Router/.github/actions/run-test-ubuntu with: @@ -674,6 +675,13 @@ jobs: with: path: src/DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -711,18 +719,6 @@ jobs: --event-handlers=console_direct+ \ --metas src/DDS-Router/.github/workflows/tsan_colcon.meta - - name: Run tests ddspipe - run: | - source install/setup.bash && \ - colcon test \ - --packages-select-regex ddspipe \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude "xfail|xtsan" \ - --timeout 60 - if: always() - - name: Run tests ddsrouter_core run: | source install/setup.bash && \ @@ -774,6 +770,13 @@ jobs: with: path: src/DDS-Router + - name: Sync eProsima/DDS-Pip repository + uses: actions/checkout@v3 + with: + repository: eProsima/DDS-Pipe + path: DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch }} + - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages From fdcf20ab00dedcb2025cf289b61e1f1a6a1c3c69 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 17 Feb 2023 11:48:57 +0100 Subject: [PATCH 23/38] fix CI minor issues Signed-off-by: jparisu --- .github/workflows/ci.repos | 5 ++++ .github/workflows/test.yml | 61 +++++++++++++------------------------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.repos b/.github/workflows/ci.repos index 435142967..b0b00b4cb 100644 --- a/.github/workflows/ci.repos +++ b/.github/workflows/ci.repos @@ -15,3 +15,8 @@ repositories: type: git url: https://github.com/eProsima/dev-utils.git version: main + version: master + ddspipe: + type: git + url: https://github.com/eProsima/DDS-Pipe.git + version: main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f0b69b737..0066dcbe0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,12 +87,12 @@ jobs: with: path: DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install OpenSSL uses: ./DDS-Router/.github/actions/install-openssl-windows @@ -131,27 +131,6 @@ jobs: name: ${{ matrix.windows-version }}_${{ matrix.cmake-config }}_fastdds_install run_id: ${{ env.fastdds_job_id }} - - name: Install ddspipe_core - uses: ./DDS-Router/.github/actions/install-router-subpackage-windows - with: - cmake_build_type: ${{ matrix.cmake-config }} - subpackage: ddspipe_core - subpackage_dir: ../DDS-Pipe/ddspipe_core - - - name: Install ddspipe_participants - uses: ./DDS-Router/.github/actions/install-router-subpackage-windows - with: - cmake_build_type: ${{ matrix.cmake-config }} - subpackage: ddspipe_participants - subpackage_dir: ../DDS-Pipe/ddspipe_participants - - - name: Install ddspipe_yaml - uses: ./DDS-Router/.github/actions/install-router-subpackage-windows - with: - cmake_build_type: ${{ matrix.cmake-config }} - subpackage: ddspipe_yaml - subpackage_dir: ../DDS-Pipe/ddspipe_yaml - - name: Install ddsrouter_core uses: ./DDS-Router/.github/actions/install-router-subpackage-windows with: @@ -229,12 +208,12 @@ jobs: with: path: src/DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + path: src/DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -395,12 +374,12 @@ jobs: with: path: src/DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + path: src/DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -506,12 +485,12 @@ jobs: with: path: src/DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + path: src/DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -596,12 +575,12 @@ jobs: with: path: src/DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + path: src/DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -675,12 +654,12 @@ jobs: with: path: src/DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + path: src/DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages @@ -770,12 +749,12 @@ jobs: with: path: src/DDS-Router - - name: Sync eProsima/DDS-Pip repository + - name: Sync eProsima/DDS-Pipe repository uses: actions/checkout@v3 with: repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch }} + path: src/DDS-Pipe + ref: ${{ github.event.inputs.ddspipe_branch || main }} - name: Install apt packages uses: ./src/DDS-Router/.github/actions/install-apt-packages From 4900d2494dcc24608377aad173f5f5d82dde3310 Mon Sep 17 00:00:00 2001 From: jparisu Date: Thu, 20 Apr 2023 16:31:57 +0200 Subject: [PATCH 24/38] Update the CI to add Pipe and use eProsima-CI Signed-off-by: jparisu --- .../actions/project_dependencies/action.yml | 54 + .github/workflows/asan_colcon.meta | 32 - .github/workflows/build_fastdds.yml | 98 -- .github/workflows/ci.repos | 22 - .github/workflows/clang_colcon.meta | 41 - .../configurations/Linux/colcon.meta | 5 + .../configurations/Windows/colcon.meta | 34 + .github/workflows/test.yml | 959 ++++-------------- .github/workflows/test_colcon.meta | 45 - .github/workflows/tsan_colcon.meta | 32 - ddsrouter.repos | 4 + ddsrouter_yaml/project_settings.cmake | 1 + 12 files changed, 287 insertions(+), 1040 deletions(-) create mode 100644 .github/actions/project_dependencies/action.yml delete mode 100644 .github/workflows/asan_colcon.meta delete mode 100644 .github/workflows/build_fastdds.yml delete mode 100644 .github/workflows/ci.repos delete mode 100644 .github/workflows/clang_colcon.meta create mode 100644 .github/workflows/configurations/Linux/colcon.meta create mode 100644 .github/workflows/configurations/Windows/colcon.meta delete mode 100644 .github/workflows/test_colcon.meta delete mode 100644 .github/workflows/tsan_colcon.meta diff --git a/.github/actions/project_dependencies/action.yml b/.github/actions/project_dependencies/action.yml new file mode 100644 index 000000000..c05827965 --- /dev/null +++ b/.github/actions/project_dependencies/action.yml @@ -0,0 +1,54 @@ +name: fastddsspy_dependencies_ubuntu +description: Common first step for all Fast DDS Spy jobs. Checkout repository, download dependencies and install required packages. + +inputs: + + os: + description: Specify runs-on machine to download specific artifact + required: true + + cmake_build_type: + description: Specify cmake_build_type option to download specific artifact + required: true + + dependencies_artifact_postfix: + description: Specify artifact postfix in case it wants to use a manual one + required: false + default: _nightly + + target_workspace: + description: Specify directory to download dependencies + required: false + default: ${{ github.workspace }}/install + + # This must be passed as an argument because actions do not access to workflow secrets: + # Unrecognized named-value: 'secrets'. https://github.com/orgs/community/discussions/27054 + # Pass argument {{ secrets.GITHUB_TOKEN }} from workflow + secret_token: + description: 'Secret token to authenticate the WebRequest so it not get a rate limit error.' + required: false + default: '' + +runs: + using: composite + steps: + + - name: Install Fast DDS dependencies + uses: jparisu/eProsima-CI/multiplatform/install_fast_dependencies@main + with: + cmake_build_type: ${{ inputs.cmake_build_type }} + + - name: Install yaml cpp dependency + uses: jparisu/eProsima-CI/multiplatform/install_yamlcpp@main + with: + cmake_build_type: ${{ inputs.cmake_build_type }} + + # In DDS Pipe artifact there are included Fast DDS and dev-utils + - name: Download dependencies artifact + uses: jparisu/eProsima-CI/multiplatform/download_dependency@main + with: + artifact_name: built_ddspipe_${{ inputs.os }}_${{ inputs.cmake_build_type }}${{ inputs.dependencies_artifact_postfix }} + workflow_source: build_ddspipe.yml + workflow_source_repository: jparisu/eProsima-CI + target_workspace: ${{ inputs.target_workspace }} + secret_token: ${{ inputs.secret_token }} diff --git a/.github/workflows/asan_colcon.meta b/.github/workflows/asan_colcon.meta deleted file mode 100644 index 115e34162..000000000 --- a/.github/workflows/asan_colcon.meta +++ /dev/null @@ -1,32 +0,0 @@ -{ - "names": - { - "ddsrouter_core": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DASAN_BUILD=ON", - ] - }, - "ddsrouter_yaml": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DASAN_BUILD=ON", - ] - }, - "ddsrouter_tool": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DASAN_BUILD=ON", - ] - } - } -} diff --git a/.github/workflows/build_fastdds.yml b/.github/workflows/build_fastdds.yml deleted file mode 100644 index d0b2ef440..000000000 --- a/.github/workflows/build_fastdds.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: build_fastdds - -on: - workflow_dispatch: - inputs: - fastdds_branch: - description: 'Branch or tag of Fast DDS repository (https://github.com/eProsima/Fast-DDS)' - required: true - default: 'master' - utils_branch: - description: 'Branch or tag of Dev Utils repository (https://github.com/eProsima/dev-utils)' - required: true - default: 'main' - schedule: - - cron: '0 0 * * *' - - -jobs: - windows-build: - runs-on: ${{ matrix.windows-version }} - strategy: - fail-fast: false - matrix: - cmake-config: - - 'Release' - - 'Debug' - windows-version: - - 'windows-2019' - - 'windows-2022' - env: - CXXFLAGS: /MP - OPENSSL64_ROOT: "C:/Program Files/OpenSSL-Win64" - - steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: DDS-Router - - - name: Install OpenSSL - uses: ./DDS-Router/.github/actions/install-openssl-windows - - - name: Install eProsima dependencies - uses: ./DDS-Router/.github/actions/install-eprosima-dependencies-windows - env: - DEFAULT_FASTDDS_BRANCH: 'master' - DEFAULT_UTILS_BRANCH: 'main' - with: - cmake_build_type: ${{ matrix.cmake-config }} - fastdds_branch: ${{ github.event.inputs.fastdds_branch || env.DEFAULT_FASTDDS_BRANCH }} - utils_branch: ${{ github.event.inputs.utils_branch || env.DEFAULT_UTILS_BRANCH }} - - - name: Upload binaries - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.windows-version }}_${{ matrix.cmake-config }}_fastdds_install - path: ${{ github.workspace }}\eprosima\install - - ubuntu-build: - runs-on: ${{ matrix.ubuntu-version }} - strategy: - fail-fast: false - matrix: - ubuntu-version: - - 'ubuntu-20.04' - - 'ubuntu-22.04' - - steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: src/DDS-Router - - - name: Avoid DDS Router build - run: | - touch ./src/DDS-Router/COLCON_IGNORE - - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Fetch repositories - run: | - vcs import src < src/DDS-Router/.github/workflows/ci.repos - cd src/fastrtps && git checkout ${{ inputs.fastdds_branch }} && cd ../.. - cd src/dev-utils && git checkout ${{ inputs.utils_branch }} && cd ../.. - - - name: Build workspace - run: | - colcon build --event-handlers=console_direct+ - - - name: Upload binaries - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.ubuntu-version }}_fastdds_install - path: install diff --git a/.github/workflows/ci.repos b/.github/workflows/ci.repos deleted file mode 100644 index b0b00b4cb..000000000 --- a/.github/workflows/ci.repos +++ /dev/null @@ -1,22 +0,0 @@ -repositories: - foonathan_memory_vendor: - type: git - url: https://github.com/eProsima/foonathan_memory_vendor.git - version: master - fastcdr: - type: git - url: https://github.com/eProsima/Fast-CDR.git - version: master - fastdds: - type: git - url: https://github.com/eProsima/Fast-DDS.git - version: master - dev-utils: - type: git - url: https://github.com/eProsima/dev-utils.git - version: main - version: master - ddspipe: - type: git - url: https://github.com/eProsima/DDS-Pipe.git - version: main diff --git a/.github/workflows/clang_colcon.meta b/.github/workflows/clang_colcon.meta deleted file mode 100644 index 180d8d1a0..000000000 --- a/.github/workflows/clang_colcon.meta +++ /dev/null @@ -1,41 +0,0 @@ -{ - "names": - { - "ddsrouter_core": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "-DCMAKE_CXX_FLAGS='-Werror -Wall'", - ] - }, - "ddsrouter_yaml": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "-DCMAKE_CXX_FLAGS='-Werror -Wall'", - ] - }, - "ddsrouter_tool": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "-DCMAKE_CXX_FLAGS='-Werror -Wall'", - ] - }, - "ddsrouter_docs": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "-DCMAKE_CXX_FLAGS='-Werror -Wall'", - ] - } - } -} diff --git a/.github/workflows/configurations/Linux/colcon.meta b/.github/workflows/configurations/Linux/colcon.meta new file mode 100644 index 000000000..c3e503a78 --- /dev/null +++ b/.github/workflows/configurations/Linux/colcon.meta @@ -0,0 +1,5 @@ +{ + "names": + { + } +} diff --git a/.github/workflows/configurations/Windows/colcon.meta b/.github/workflows/configurations/Windows/colcon.meta new file mode 100644 index 000000000..5395f327e --- /dev/null +++ b/.github/workflows/configurations/Windows/colcon.meta @@ -0,0 +1,34 @@ +{ + "names": + { + "ddsrouter_participants": + { + "cmake-args": + [ + "-DCMAKE_CXX_FLAGS='/WX /EHsc'", + "-Ax64", + "-T host=x64" + ] + }, + + "ddsrouter_yaml": + { + "cmake-args": + [ + "-DCMAKE_CXX_FLAGS='/WX /EHsc'", + "-Ax64", + "-T host=x64" + ] + }, + + "ddsrouter_tool": + { + "cmake-args": + [ + "-DCMAKE_CXX_FLAGS='/WX /EHsc'", + "-Ax64", + "-T host=x64" + ] + }, + } +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0066dcbe0..1f6f0268b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,875 +1,294 @@ -# Main CI for DDS Router repository -# This is executed with every PullRequest (new or update), any merge in main and every night +# Main CI +# This is executed: +# - every PullRequest (new or update) +# - every merge in main +# - every night (05:00) # -# These jobs that require to install fastrtps library uses the artifact generated for the nightly job -# so they do not have to compile the whole fastrtps project. This saves huge amount of time. +# These jobs that require to install eprosima libraries uses the artifact generated for eprosima-CI nightly +# so they do not have to compile the whole project. This saves huge amount of time. # # JOBS: # -# - windows-build-test -# - [ windows-2019 | windows-2022 ] +# - multiplatform-tests +# - [ ubuntu-22.04 | ubuntu-20.04 | windows-2019 | windows-2022 ] # - [ Debug | Release ] -# - compile up-to ddsrouter_tool ; run tests +# - execute tests in different versions of ubuntu with different build types # -# - ubuntu-main-test -# - ubuntu-20.04 -# - Debug -# - compile all ; run tests ; calculate coverage +# - asan +# - ubuntu-22.04 +# - execute tests with ASAN flag # -# - ubuntu-release-test -# - [ ubuntu-20.04 | ubuntu-22.04 ] -# - Release -# - compile all ; run tests +# - tsan +# - ubuntu-22.04 +# - execute tests with TSAN flag # -# - ubuntu-build-test-flaky -# - ubuntu-20.04 -# - Debug -# - compile all ; run flaky tests +# - clang +# - ubuntu-22.04 +# - execute clang-tidy check # -# - asan-test -# - [ ubuntu-20.04 ] -# - Debug -# - compile all ; run tests +# - coverage +# - ubuntu-22.04 +# - execute test with coverage flag and upload results # -# - tsan-test -# - ubuntu-20.04 -# - Debug -# - build code ; run tests +# - flaky +# - ubuntu-22.04 +# - execute flaky tests # -# - clang-tidy -# - ubuntu-20.04 -# - Release -# - compile all ; test clang-tidy +# - docs +# - ubuntu-22.04 +# - execute docs compile and tests # # - uncrustify -# - ubuntu-20.04 +# - ubuntu-22.04 # - test uncrustify # -# The main job is ubuntu-main-test which compiles all packages (including documentation), run every test and calculates coverage. -# This main job uses ubuntu 20.04 LTS (focal fossa). +# - python-linter +# - ubuntu-22.04 +# - test python linter +# +# TODO: when merge CI in eprosima-CI repository, the jparisu fork must change for eProsima in actions. +# +# TODO: Add Windows CI +# name: test on: + workflow_dispatch: - inputs: - ddspipe_branch: - description: 'Branch or tag of DDS Pipe repository (https://github.com/eProsima/DDS-Pipe)' + inputs: + + dependencies_artifact_postfix: + description: 'Postfix name to add to artifact name to download dependencies. This is use to download a specific artifact version from eProsima-CI.' required: true - default: 'main' + default: '_nightly' + pull_request: push: branches: - main schedule: - - cron: '0 1 * * *' + - cron: '0 5 * * *' + +env: + code_packages_names: 'ddsrouter_core ddsrouter_yaml ddsrouter_tool' + docs_packages_names: 'ddsrouter_docs' + default_dependencies_artifact_postfix: '_nightly' jobs: - windows-build-test: - runs-on: ${{ matrix.windows-version }} + +##################################################################### +# TEST + + multiplatform-tests: + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - cmake-config: - - 'Release' - - 'Debug' - windows-version: - - 'windows-2019' - - 'windows-2022' - env: - CXXFLAGS: /MP - OPENSSL64_ROOT: "C:/Program Files/OpenSSL-Win64" + cmake_build_type: + - Release + - Debug + os: + - ubuntu-20.04 + - ubuntu-22.04 + - windows-2019 + - windows-2022 steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: DDS-Router - - name: Sync eProsima/DDS-Pipe repository + - name: Sync repository uses: actions/checkout@v3 with: - repository: eProsima/DDS-Pipe - path: DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} - - - name: Install OpenSSL - uses: ./DDS-Router/.github/actions/install-openssl-windows - - - name: Install GTest - uses: ./DDS-Router/.github/actions/install-gtest-windows - with: - cmake_build_type: ${{ matrix.cmake-config }} - - - name: Install yaml-cpp - uses: ./DDS-Router/.github/actions/install-yamlcpp-windows - with: - cmake_build_type: ${{ matrix.cmake-config }} - - - name: Get build eProsima dependencies Job Id - shell: pwsh - run: | - $secret = ConvertTo-SecureString -String "${{ secrets.GITHUB_TOKEN }}" -AsPlainText - $RUNS_URI = '${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/build_fastdds.yml/runs' - - # Check available queries according with github policy - "::group::Rate Limits with github action token" - ((Invoke-WebRequest -Authentication OAuth -Token $secret ` - -Uri https://api.github.com/users/octocat).Headers.GetEnumerator() | - ? Key -like "X-RateLimit*") | Out-Host - "::endgroup::" - - ((Invoke-WebRequest -Authentication OAuth -Token $secret -Uri $RUNS_URI).Content | ConvertFrom-Json).workflow_runs | ? status -eq 'completed' | - select -first 1 id | % { "fastdds_job_id=" + $_.id } | Out-File $env:GITHUB_ENV -Append - - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: ${{ github.workspace }}\..\fastdds\install - name: ${{ matrix.windows-version }}_${{ matrix.cmake-config }}_fastdds_install - run_id: ${{ env.fastdds_job_id }} + path: ${{ github.workspace }}/src - - name: Install ddsrouter_core - uses: ./DDS-Router/.github/actions/install-router-subpackage-windows + - name: Download dependencies and install requirements + uses: ./src/.github/actions/project_dependencies with: - cmake_build_type: ${{ matrix.cmake-config }} - subpackage: ddsrouter_core - subpackage_dir: ddsrouter_core + os: ${{ matrix.os }} + cmake_build_type: ${{ matrix.cmake_build_type }} + dependencies_artifact_postfix: ${{ github.event.inputs.dependencies_artifact_postfix || env.default_dependencies_artifact_postfix }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Install ddsrouter_yaml - uses: ./DDS-Router/.github/actions/install-router-subpackage-windows + - name: Compile and run tests + uses: jparisu/eProsima-CI/multiplatform/colcon_build_test@main with: - cmake_build_type: ${{ matrix.cmake-config }} - subpackage: ddsrouter_yaml - subpackage_dir: ddsrouter_yaml + packages_names: ${{ env.code_packages_names }} + cmake_args: -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} + workspace_dependencies: ${{ github.workspace }}/install + ctest_args: --label-exclude "xfail" + colcon_meta_file: ${{ github.workspace }}/src/.github/workflows/configurations/${{ runner.os }}/colcon.meta - - name: Install ddsrouter_tool - uses: ./DDS-Router/.github/actions/install-router-subpackage-windows - with: - cmake_build_type: ${{ matrix.cmake-config }} - subpackage: ddsrouter_tool - subpackage_dir: tools/ddsrouter_tool - - name: Run tests ddspipe_core - uses: ./DDS-Router/.github/actions/run-test-windows - with: - package_name: ddspipe_core - cmake_build_type: ${{ matrix.cmake-config }} - if: always() +##################################################################### +# ASAN - - name: Run tests ddspipe_participants - uses: ./DDS-Router/.github/actions/run-test-windows - with: - package_name: ddspipe_participants - cmake_build_type: ${{ matrix.cmake-config }} - if: always() + asan: + runs-on: ubuntu-22.04 + steps: - - name: Run tests ddspipe_yaml - uses: ./DDS-Router/.github/actions/run-test-windows + - name: Sync repository + uses: actions/checkout@v3 with: - package_name: ddspipe_yaml - cmake_build_type: ${{ matrix.cmake-config }} - if: always() + path: ${{ github.workspace }}/src - - name: Run tests ddsrouter_core - uses: ./DDS-Router/.github/actions/run-test-windows + - name: Download dependencies and install requirements + uses: ./src/.github/actions/project_dependencies with: - package_name: ddsrouter_core - cmake_build_type: ${{ matrix.cmake-config }} - if: always() + os: ubuntu-22.04 + cmake_build_type: Release + dependencies_artifact_postfix: ${{ github.event.inputs.dependencies_artifact_postfix || env.default_dependencies_artifact_postfix }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests ddsrouter_yaml - uses: ./DDS-Router/.github/actions/run-test-windows + - name: Compile and run tests + uses: jparisu/eProsima-CI/multiplatform/asan_build_test@main with: - package_name: ddsrouter_yaml - cmake_build_type: ${{ matrix.cmake-config }} - if: always() + packages_names: ${{ env.code_packages_names }} + workspace_dependencies: ${{ github.workspace }}/install - - name: Run tests ddsrouter_tool - uses: ./DDS-Router/.github/actions/run-test-windows - with: - package_name: ddsrouter_tool - cmake_build_type: ${{ matrix.cmake-config }} - if: always() +##################################################################### +# TSAN - ubuntu-main-test: - runs-on: ubuntu-20.04 - environment: - name: codecov - env: - COVERAGE_FILE: ${{ github.workspace }}/coverage.xml - + tsan: + runs-on: ubuntu-22.04 steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: src/DDS-Router - - name: Sync eProsima/DDS-Pipe repository + - name: Sync repository uses: actions/checkout@v3 with: - repository: eProsima/DDS-Pipe - path: src/DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} - - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install GTest - uses: ./src/DDS-Router/.github/actions/install-gtest-linux + path: ${{ github.workspace }}/src - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Get build eProsima dependencies Job Id - run: | - export JOB_ID=$(curl -sL $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/build_fastdds.yml/runs | \ - jq '.workflow_runs[] | select(.status == "completed") | .id' | \ - head -n 1) - echo "fastdds_job_id=${JOB_ID}" >> $GITHUB_ENV - - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: /home/runner/work/fastdds/install - name: ubuntu-20.04_fastdds_install - run_id: ${{ env.fastdds_job_id }} - - - name: Update colcon mixin - run: | - colcon mixin add default \ - https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml - colcon mixin update default - continue-on-error: true - - - name: Build workspace - run: | - cat src/DDS-Router/.github/workflows/test_colcon.meta - source /home/runner/work/fastdds/install/setup.bash - colcon build \ - --event-handlers=console_direct+ \ - --metas src/DDS-Router/.github/workflows/test_colcon.meta \ - --mixin coverage-gcc asan-gcc - - - name: Run tests ddsrouter_core - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + - name: Download dependencies and install requirements + uses: ./src/.github/actions/project_dependencies with: - package_name: ddsrouter_core + os: ubuntu-22.04 + cmake_build_type: Release + dependencies_artifact_postfix: ${{ github.event.inputs.dependencies_artifact_postfix || env.default_dependencies_artifact_postfix }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests ddsrouter_yaml - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + - name: Compile and run tests + uses: jparisu/eProsima-CI/multiplatform/tsan_build_test@main with: - package_name: ddsrouter_yaml - if: always() + packages_names: ${{ env.code_packages_names }} + workspace_dependencies: ${{ github.workspace }}/install - - name: Run tests ddsrouter_yaml_validator - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddsrouter_yaml_validator - if: always() - - name: Run tests ddsrouter_tool - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddsrouter_tool - if: always() +##################################################################### +# CLANG - - name: Run tests ddsrouter_docs - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddsrouter_docs - if: always() - - - name: Generate coverage report - run: | - echo "Generating coverage report in ${{ env.COVERAGE_FILE }}..." - cp src/DDS-Router/codecov.yml . - mkdir coverage-report - mkdir build/ddsrouter - cp --recursive build/ddsrouter_* build/ddsrouter - gcovr \ - --root src/DDS-Router/ \ - --output ${{ env.COVERAGE_FILE }} \ - --xml-pretty \ - --exclude='.*docs/.*' \ - --exclude='.*test/.*' \ - --exclude='.*github/.*' \ - --exclude='.*common/.*' \ - --exclude='.*dev/.*' \ - --exclude='.*thirdparty/.*' \ - --exclude='.*resources/.*' \ - --exclude-unreachable-branches \ - build/ddsrouter_* - if [[ -f "${{ env.COVERAGE_FILE }}" ]]; then - echo "Coverage file saved!" - fi - - - name: Upload coverage - uses: actions/upload-artifact@v3 - with: - name: coverage-report - path: coverage-report/ + clang: + runs-on: ubuntu-22.04 + steps: - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + - name: Sync repository + uses: actions/checkout@v3 with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ${{ env.COVERAGE_FILE }} - root_dir: src/DDS-Router - fail_ci_if_error: true + path: ${{ github.workspace }}/src - - name: Upload documentation - uses: actions/upload-artifact@v3 + - name: Download dependencies and install requirements + uses: ./src/.github/actions/project_dependencies with: - name: Documentation HTML - path: install/ddsrouter_docs/docs/ddsrouter_docs/sphinx/html/ - - - name: Check documentation spelling errors - run: | - SPELLING_ERRORS_DIR=./build/ddsrouter_docs/test/spelling - SPELLING_ERRORS_FILE=${SPELLING_ERRORS_DIR}/spelling_errors.txt - echo "spelling_errors_file=${SPELLING_ERRORS_FILE}" >> $GITHUB_ENV - if [ -d "${SPELLING_ERRORS_DIR}" ]; then - find ${SPELLING_ERRORS_DIR} \ - -type f \ - -name '*.spelling' \ - -exec cat {} + > ${SPELLING_ERRORS_FILE} - else - echo "No spelling errors found." - fi - if: always() - - - name: Upload documentation spelling errors - uses: actions/upload-artifact@v3 - with: - name: spelling_errors - path: ${{ env.spelling_errors_file }} - if-no-files-found: ignore - if: always() + os: ubuntu-22.04 + cmake_build_type: Release + dependencies_artifact_postfix: ${{ github.event.inputs.dependencies_artifact_postfix || env.default_dependencies_artifact_postfix }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Upload Logs - uses: actions/upload-artifact@v3 + - name: Compile and run tests + uses: jparisu/eProsima-CI/multiplatform/clang_build_test@main with: - name: colcon-logs-ubuntu - path: log/ - if: always() + packages_names: ${{ env.code_packages_names }} + workspace_dependencies: ${{ github.workspace }}/install - ubuntu-release-test: - runs-on: ${{ matrix.ubuntu-version }} - strategy: - fail-fast: false - matrix: - ubuntu-version: - - 'ubuntu-20.04' - - 'ubuntu-22.04' +##################################################################### +# COVERAGE + coverage: + runs-on: ubuntu-22.04 + environment: + name: codecov steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: src/DDS-Router - - name: Sync eProsima/DDS-Pipe repository + - name: Sync repository uses: actions/checkout@v3 with: - repository: eProsima/DDS-Pipe - path: src/DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} + path: ${{ github.workspace }}/src - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install GTest - uses: ./src/DDS-Router/.github/actions/install-gtest-linux - - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Get build eProsima dependencies Job Id - run: | - export JOB_ID=$(curl -sL $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/build_fastdds.yml/runs | \ - jq '.workflow_runs[] | select(.status == "completed") | .id' | \ - head -n 1) - echo "fastdds_job_id=${JOB_ID}" >> $GITHUB_ENV - - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: /home/runner/work/fastdds/install - name: ${{ matrix.ubuntu-version }}_fastdds_install - run_id: ${{ env.fastdds_job_id }} - - - name: Update colcon mixin - run: | - colcon mixin add default \ - https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml - colcon mixin update default - continue-on-error: true - - # By default it is built in release mode - - name: Build workspace - run: | - source /home/runner/work/fastdds/install/setup.bash - colcon build \ - --event-handlers=console_direct+ \ - --cmake-args -DBUILD_TESTS=ON - - - name: Run tests ddsrouter_core - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_core \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude xfail \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_yaml - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_yaml \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude xfail \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_tool - run: | - source install/setup.bash && \ - colcon test \ - --packages-select-regex ddsrouter_tool \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude xfail \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_docs - run: | - source install/setup.bash && \ - colcon test \ - --packages-select-regex ddsrouter_docs \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude xfail \ - --timeout 60 - if: always() - - - name: Upload Logs - uses: actions/upload-artifact@v3 - with: - name: colcon-logs-ubuntu - path: log/ - if: always() - - - ubuntu-build-test-flaky: - runs-on: ubuntu-20.04 - - steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 + - name: Download dependencies and install requirements + uses: ./src/.github/actions/project_dependencies with: - path: src/DDS-Router + os: ubuntu-22.04 + cmake_build_type: Release + dependencies_artifact_postfix: ${{ github.event.inputs.dependencies_artifact_postfix || env.default_dependencies_artifact_postfix }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Sync eProsima/DDS-Pipe repository - uses: actions/checkout@v3 + - name: Compile and run tests + uses: jparisu/eProsima-CI/ubuntu/coverage_build_test_upload@main with: - repository: eProsima/DDS-Pipe - path: src/DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} + packages_names: ${{ env.code_packages_names }} + workspace_dependencies: ${{ github.workspace }}/install + codecov_token: ${{ secrets.CODECOV_TOKEN }} + codecov_fix_file_path: ${{ github.workspace }}/src/codecov.yml - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - name: Install GTest - uses: ./src/DDS-Router/.github/actions/install-gtest-linux - - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Get build eProsima dependencies Job Id - run: | - export JOB_ID=$(curl -sL $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/build_fastdds.yml/runs | jq -r '.workflow_runs[0].id?') - echo "fastdds_job_id=${JOB_ID}" >> $GITHUB_ENV - - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: /home/runner/work/fastdds/install - name: ubuntu-20.04_fastdds_install - run_id: ${{ env.fastdds_job_id }} - - - name: Update colcon mixin - run: | - colcon mixin add default \ - https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml - colcon mixin update default - continue-on-error: true - - - name: Build workspace - run: | - cat src/DDS-Router/.github/workflows/test_colcon.meta - source /home/runner/work/fastdds/install/setup.bash - colcon build \ - --event-handlers=console_direct+ \ - --metas src/DDS-Router/.github/workflows/test_colcon.meta \ - --mixin coverage-gcc asan-gcc - - - name: Run tests ddsrouter_core - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_core \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-regex xfail \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_yaml - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_yaml \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-regex xfail \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_tool - run: | - source install/setup.bash && \ - colcon test \ - --packages-select-regex ddsrouter_tool \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-regex xfail \ - --timeout 60 - if: always() - - asan-test: - runs-on: ubuntu-20.04 +##################################################################### +# FLAKY + flaky: + runs-on: ubuntu-22.04 steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: src/DDS-Router - - name: Sync eProsima/DDS-Pipe repository + - name: Sync repository uses: actions/checkout@v3 with: - repository: eProsima/DDS-Pipe - path: src/DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} + path: ${{ github.workspace }}/src - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install GTest - uses: ./src/DDS-Router/.github/actions/install-gtest-linux - - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Get build eProsima dependencies Job Id - run: | - export JOB_ID=$(curl -sL $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/build_fastdds.yml/runs | \ - jq '.workflow_runs[] | select(.status == "completed") | .id' | \ - head -n 1) - echo "fastdds_job_id=${JOB_ID}" >> $GITHUB_ENV - - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: /home/runner/work/fastdds/install - name: ubuntu-20.04_fastdds_install - run_id: ${{ env.fastdds_job_id }} - - - name: Update colcon mixin - run: | - colcon mixin add default \ - https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml - colcon mixin update default - continue-on-error: true - - - name: Build workspace - run: | - cat src/DDS-Router/.github/workflows/asan_colcon.meta - source /home/runner/work/fastdds/install/setup.bash - colcon build \ - --event-handlers=console_direct+ \ - --metas src/DDS-Router/.github/workflows/asan_colcon.meta - - - name: Run tests ddsrouter_core - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + - name: Download dependencies and install requirements + uses: ./src/.github/actions/project_dependencies with: - package_name: ddsrouter_core + os: ubuntu-22.04 + cmake_build_type: Release + dependencies_artifact_postfix: ${{ github.event.inputs.dependencies_artifact_postfix || env.default_dependencies_artifact_postfix }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests ddsrouter_yamlx - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu + - name: Compile and run tests + uses: jparisu/eProsima-CI/multiplatform/colcon_build_test_flaky@main with: - package_name: ddsrouter_yaml - if: always() + packages_names: ${{ env.code_packages_names }} + workspace_dependencies: ${{ github.workspace }}/install - - name: Run tests ddsrouter_tool - uses: ./src/DDS-Router/.github/actions/run-test-ubuntu - with: - package_name: ddsrouter_tool - if: always() - - name: Upload Logs - uses: actions/upload-artifact@v3 - with: - name: asan-logs - path: log/ - if: always() - - tsan-test: - runs-on: ubuntu-20.04 +##################################################################### +# DOCUMENTATION TEST + docs: + runs-on: ubuntu-22.04 steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 + - name: Build and test documentation + uses: jparisu/eProsima-CI/ubuntu/sphinx_docs@main with: - path: src/DDS-Router + docs_subpackage_name: ${{ env.docs_packages_names }} + secret_token: ${{ secrets.GITHUB_TOKEN }} - - name: Sync eProsima/DDS-Pipe repository - uses: actions/checkout@v3 - with: - repository: eProsima/DDS-Pipe - path: src/DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} - - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install GTest - uses: ./src/DDS-Router/.github/actions/install-gtest-linux - - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Get build eProsima dependencies Job Id - run: | - export JOB_ID=$(curl -sL $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/build_fastdds.yml/runs | \ - jq '.workflow_runs[] | select(.status == "completed") | .id' | \ - head -n 1) - echo "fastdds_job_id=${JOB_ID}" >> $GITHUB_ENV - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: /home/runner/work/fastdds/install - name: ubuntu-20.04_fastdds_install - run_id: ${{ env.fastdds_job_id }} - - - name: Update colcon mixin - run: | - colcon mixin add default \ - https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml - colcon mixin update default - continue-on-error: true - - - name: Build workspace - run: | - source /home/runner/work/fastdds/install/setup.bash - colcon build \ - --event-handlers=console_direct+ \ - --metas src/DDS-Router/.github/workflows/tsan_colcon.meta - - - name: Run tests ddsrouter_core - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_core \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude "xfail|xtsan" \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_yaml - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_yaml \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude "xfail|xtsan" \ - --timeout 60 - if: always() - - - name: Run tests ddsrouter_tool - run: | - source install/setup.bash && \ - colcon test \ - --packages-select ddsrouter_tool \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude "xfail|xtsan" \ - --timeout 60 - if: always() - - - name: Upload Logs - uses: actions/upload-artifact@v3 - with: - name: tsan-logs - path: log/ - if: always() - clang-tidy: - runs-on: ubuntu-20.04 - steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: src/DDS-Router +##################################################################### +# UNCRUSTIFY - - name: Sync eProsima/DDS-Pipe repository - uses: actions/checkout@v3 - with: - repository: eProsima/DDS-Pipe - path: src/DDS-Pipe - ref: ${{ github.event.inputs.ddspipe_branch || main }} - - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install GTest - uses: ./src/DDS-Router/.github/actions/install-gtest-linux + uncrustify: + runs-on: ubuntu-22.04 + steps: - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages + - name: Uncrustify + uses: jparisu/eProsima-CI/ubuntu-22.04/uncrustify@main - - name: Get build eProsima dependencies Job Id - run: | - export JOB_ID=$(curl -sL $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/build_fastdds.yml/runs | jq -r '.workflow_runs[0].id?') - echo "fastdds_job_id=${JOB_ID}" >> $GITHUB_ENV - - name: Download eProsima dependencies - uses: dawidd6/action-download-artifact@v2 - with: - workflow: build_fastdds.yml - path: /home/runner/work/fastdds/install - name: ubuntu-20.04_fastdds_install - run_id: ${{ env.fastdds_job_id }} - - - name: Build workspace - run: | - cat src/DDS-Router/.github/workflows/clang_colcon.meta - source /home/runner/work/fastdds/install/setup.bash - colcon build \ - --event-handlers=console_direct+ \ - --metas src/DDS-Router/.github/workflows/clang_colcon.meta - - - name: Run clang-tidy - run: | - mkdir build/ddsrouter - cp --recursive build/ddsrouter_* build/ddsrouter - cd build/ddsrouter - run-clang-tidy -header-filter='.*' -checks='clang-analyzer-cplusplus' -quiet 2> ${{ github.workspace }}/clang_results.yml - - - name: Upload clang results - uses: actions/upload-artifact@v3 - with: - name: clang_results - path: ${{ github.workspace }}/clang_results.yml +##################################################################### +# PYTHON LINTER - uncrustify: - runs-on: ubuntu-20.04 + python-linter: + runs-on: ubuntu-22.04 steps: - - name: Sync eProsima/DDS-Router repository - uses: actions/checkout@v3 - with: - path: src/DDS-Router - - - name: Fetch all branches and tags - run: | - cd src/DDS-Router - git fetch --prune --unshallow - - - name: Install apt packages - uses: ./src/DDS-Router/.github/actions/install-apt-packages - - - name: Install Python packages - uses: ./src/DDS-Router/.github/actions/install-python-packages - - - name: Install uncrustify - run: | - git clone https://github.com/uncrustify/uncrustify.git \ - --branch uncrustify-0.71.0 \ - --single-branch uncrustify - mkdir -p uncrustify/build - cd uncrustify/build - cmake .. - sudo cmake --build . --target install - cd ../.. - sudo rm -rf uncrustify - - # (TODO) Change to main branch when PR is merged - - name: Clone ament_lint - run: | - git clone --branch feature/fix-language-set https://github.com/jparisu/ament_lint.git src/ament_lint - - - name: Build ament_uncrustify - run: colcon build --packages-up-to ament_uncrustify - - - name: Fetch uncrustify config file - run: | - curl \ - -l https://raw.githubusercontent.com/eProsima/cpp-style/master/uncrustify.cfg \ - -o uncrustify.cfg - - - name: Get difference - run: | - cd src/DDS-Router - echo "MODIFIED_FILES=$(git diff --name-only origin/${GITHUB_BASE_REF} origin/${GITHUB_HEAD_REF} | grep -e '\.h' -e '\.hpp' -e '\.cpp' -e '\.ipp' | tr '\n' ' ')" >> $GITHUB_ENV - - - name: Check difference - run: | - cd src/DDS-Router - if [[ -z "${MODIFIED_FILES}" ]] - then - touch empty.hpp - echo "MODIFIED_FILES=empty.hpp" >> $GITHUB_ENV - fi - - - name: Check style - run: | - source install/local_setup.bash - cd src/DDS-Router - ament_uncrustify \ - -c ../../uncrustify.cfg \ - --language CPP \ - --xunit-file ../../uncrustify_results.xml \ - ${MODIFIED_FILES} - - - name: Upload uncrustify results - uses: actions/upload-artifact@v3 - with: - name: uncrustify_results - path: uncrustify_results.xml + + - name: Python Linter + uses: jparisu/eProsima-CI/ubuntu/python_linter@main diff --git a/.github/workflows/test_colcon.meta b/.github/workflows/test_colcon.meta deleted file mode 100644 index cf9a4b6ef..000000000 --- a/.github/workflows/test_colcon.meta +++ /dev/null @@ -1,45 +0,0 @@ -{ - "names": - { - "ddsrouter_core": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DCODE_COVERAGE=ON", - "-DCMAKE_CXX_FLAGS='-Werror'" - ] - }, - "ddsrouter_yaml": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DCODE_COVERAGE=ON", - "-DCMAKE_CXX_FLAGS='-Werror'" - ] - }, - "ddsrouter_tool": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DCODE_COVERAGE=ON", - "-DCMAKE_CXX_FLAGS='-Werror'" - ] - }, - "ddsrouter_docs": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DCODE_COVERAGE=OFF", - "-DCMAKE_CXX_FLAGS='-Werror'" - ] - } - } -} diff --git a/.github/workflows/tsan_colcon.meta b/.github/workflows/tsan_colcon.meta deleted file mode 100644 index 9f47bd877..000000000 --- a/.github/workflows/tsan_colcon.meta +++ /dev/null @@ -1,32 +0,0 @@ -{ - "names": - { - "ddsrouter_core": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DTSAN_BUILD=ON" - ] - }, - "ddsrouter_yaml": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DTSAN_BUILD=ON" - ] - }, - "ddsrouter_tool": - { - "cmake-args": - [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DBUILD_TESTS=ON", - "-DTSAN_BUILD=ON" - ] - } - } -} diff --git a/ddsrouter.repos b/ddsrouter.repos index 7447cca78..86d713bbd 100644 --- a/ddsrouter.repos +++ b/ddsrouter.repos @@ -15,6 +15,10 @@ repositories: type: git url: https://github.com/eProsima/dev-utils.git version: main + ddspipe: + type: git + url: https://github.com/eProsima/DDS-Pipe.git + version: main ddsrouter: type: git url: https://github.com/eProsima/DDS-Router.git diff --git a/ddsrouter_yaml/project_settings.cmake b/ddsrouter_yaml/project_settings.cmake index 1d39158e7..314f0d489 100644 --- a/ddsrouter_yaml/project_settings.cmake +++ b/ddsrouter_yaml/project_settings.cmake @@ -23,6 +23,7 @@ set(MODULE_SUMMARY "C++ library to build and run a DDS Router.") set(MODULE_FIND_PACKAGES + yaml-cpp fastcdr fastrtps cpp_utils From 24fe66d4cc1c4dfebce16a6995136b046001b45c Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 21 Apr 2023 09:18:47 +0200 Subject: [PATCH 25/38] TMP: change postfix to _manual to test windows Signed-off-by: jparisu --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f6f0268b..8a036162e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,7 +61,7 @@ on: dependencies_artifact_postfix: description: 'Postfix name to add to artifact name to download dependencies. This is use to download a specific artifact version from eProsima-CI.' required: true - default: '_nightly' + default: '_manual' pull_request: push: @@ -73,7 +73,7 @@ on: env: code_packages_names: 'ddsrouter_core ddsrouter_yaml ddsrouter_tool' docs_packages_names: 'ddsrouter_docs' - default_dependencies_artifact_postfix: '_nightly' + default_dependencies_artifact_postfix: '_manual' jobs: From 5a2cbefe3161d80c4b8b6a23d9eefd2660377b98 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 25 Apr 2023 14:18:34 +0200 Subject: [PATCH 26/38] Add labels of TSAN to tests Signed-off-by: jparisu --- ddsrouter_core/test/CMakeLists.txt | 4 ++++ .../test/blackbox/implementations/CMakeLists.txt | 2 ++ ddsrouter_core/test/labels/CMakeLists.txt | 16 ++++++++++++++++ ddsrouter_core/test/labels/XTSAN.list | 3 +++ 4 files changed, 25 insertions(+) create mode 100644 ddsrouter_core/test/labels/CMakeLists.txt create mode 100644 ddsrouter_core/test/labels/XTSAN.list diff --git a/ddsrouter_core/test/CMakeLists.txt b/ddsrouter_core/test/CMakeLists.txt index 4e105ab74..ac1eb8010 100644 --- a/ddsrouter_core/test/CMakeLists.txt +++ b/ddsrouter_core/test/CMakeLists.txt @@ -12,4 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Add subdirectory with labels for tests +add_subdirectory(labels) + +# Add subdirectory with tests add_subdirectory(blackbox) diff --git a/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt b/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt index 6b283e469..0fade3568 100644 --- a/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt @@ -39,3 +39,5 @@ add_blackbox_executable( "${TEST_LIST}" "${TEST_NEEDED_SOURCES}" ) + +# add_test_label_from_file(${CMAKE_CURRENT_SOURCE_DIR}/../../TEST_XTSAN.list "xtsan") diff --git a/ddsrouter_core/test/labels/CMakeLists.txt b/ddsrouter_core/test/labels/CMakeLists.txt new file mode 100644 index 000000000..17e16bc1f --- /dev/null +++ b/ddsrouter_core/test/labels/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2022 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. + +# Set list of tests that can fail using TSAN +set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XTSAN.list "xtsan") diff --git a/ddsrouter_core/test/labels/XTSAN.list b/ddsrouter_core/test/labels/XTSAN.list new file mode 100644 index 000000000..7e7fb9dae --- /dev/null +++ b/ddsrouter_core/test/labels/XTSAN.list @@ -0,0 +1,3 @@ +ImplementationsTest.pair_implementation +ImplementationsTest.pair_implementation_with_topic +ImplementationsTest.all_implementations From 595d2960d80750c1703baed49cf2bc89a77ad06a Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 26 Apr 2023 11:00:32 +0200 Subject: [PATCH 27/38] Update blackbox tests Signed-off-by: jparisu --- .../configuration/DdsRouterConfiguration.hpp | 2 +- ddsrouter_core/src/cpp/core/DdsRouter.cpp | 3 +- ddsrouter_core/test/blackbox/CMakeLists.txt | 2 +- .../ddsrouter_core/dds/CMakeLists.txt | 4 +- .../ddsrouter_core/dds/WAN/CMakeLists.txt | 10 - .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 281 ++++++++---------- .../ddsrouter_core/dds/WAN/TEST_XTSAN.list | 5 - .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 99 +++--- .../dds/local/DDSTestLocalDisposeKey.cpp | 74 ++--- .../dds/repeater/CMakeLists.txt | 1 - .../dds/repeater/DDSTestRepeater.cpp | 173 ++++------- .../dds/types/test_participants.hpp | 11 +- .../implementations/ImplementationsTest.cpp | 10 +- .../WAN/TEST_XFAIL.list => labels/XFAIL.list} | 0 ddsrouter_core/test/labels/XTSAN.list | 5 + 15 files changed, 286 insertions(+), 394 deletions(-) delete mode 100644 ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list rename ddsrouter_core/test/{blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list => labels/XFAIL.list} (100%) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp index ab7d7f921..a9a5d4e62 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp @@ -63,7 +63,7 @@ struct DdsRouterConfiguration : public DdsRouterReloadConfiguration ///////////////////////// //! Builtin topics to create at the beggining of the execution - std::set> builtin_topics {}; + std::set> builtin_topics {}; //! Participant configurations std::set< diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp index dfbf2e739..25b3f9134 100644 --- a/ddsrouter_core/src/cpp/core/DdsRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -67,7 +67,8 @@ DdsRouter::DdsRouter( discovery_database_, payload_pool_, participants_database_, - thread_pool_)); + thread_pool_, + configuration_.builtin_topics)); logDebug(DDSROUTER, "DDS Router created."); } diff --git a/ddsrouter_core/test/blackbox/CMakeLists.txt b/ddsrouter_core/test/blackbox/CMakeLists.txt index 060cd8f0d..5e58868df 100644 --- a/ddsrouter_core/test/blackbox/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/CMakeLists.txt @@ -13,5 +13,5 @@ # limitations under the License. # TODO uncomment when ready -# add_subdirectory(ddsrouter_core) +add_subdirectory(ddsrouter_core) add_subdirectory(implementations) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt index e9705347f..fe8f40a72 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/CMakeLists.txt @@ -13,5 +13,5 @@ # limitations under the License. add_subdirectory(local) -# add_subdirectory(repeater) -# add_subdirectory(WAN) +add_subdirectory(repeater) +add_subdirectory(WAN) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt index 3c70390c2..fedb24fbe 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt @@ -68,13 +68,3 @@ add_blackbox_executable( "${TEST_LIST}" "${TEST_NEEDED_SOURCES}" "${TEST_EXTRA_HEADERS}") - -# Set flaky tests as xfail -add_xfail_label(${CMAKE_CURRENT_SOURCE_DIR}/TEST_XFAIL.list) - -# Set as TSAN errors due to Fast DDS -# TODO: use a cmake_utils macro -file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/TEST_XTSAN.list TEST_LIST) -foreach(XTSAN_TEST ${TEST_LIST}) - set_property(TEST ${XTSAN_TEST} PROPERTY LABELS xtsan) -endforeach() diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp index 2ae469c87..92b44f880 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -19,18 +19,21 @@ #include #include -#include -#include +#include + +#include +#include +#include +#include + #include -#include -#include -#include #include -namespace eprosima { -namespace ddsrouter { -namespace core { +using namespace eprosima; +using namespace eprosima::ddspipe; +using namespace eprosima::ddsrouter::core; + namespace test { enum class WanParticipantKind @@ -62,14 +65,14 @@ constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes -types::security::TlsConfiguration tls_configuration( +participants::types::TlsConfiguration tls_configuration( WanKind wan_kind) { // TODO: test that using server with only Server required files works // It fails when connecting to other server if (is_server(wan_kind)) { - types::security::TlsConfiguration tls; + participants::types::TlsConfiguration tls; tls.certificate_authority_file = "../../resources/tls/ca.crt"; tls.private_key_file = "../../resources/tls/ddsrouter.key"; tls.certificate_chain_file = "../../resources/tls/ddsrouter.crt"; @@ -78,30 +81,32 @@ types::security::TlsConfiguration tls_configuration( } else { - types::security::TlsConfiguration tls; + participants::types::TlsConfiguration tls; tls.certificate_authority_file = "../../resources/tls/ca.crt"; return tls; } } -std::shared_ptr discovery_server_participant_configuration( +std::pair< + types::ParticipantKind, + std::shared_ptr> +discovery_server_participant_configuration( bool this_server_id_is_1, WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version, bool tls = false) { - std::set listening_addresses; - std::set connection_addresses; + participants::DiscoveryServerParticipantConfiguration conf; if (is_client(wan_kind)) { - connection_addresses.insert( - types::DiscoveryServerConnectionAddress( - types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), + conf.connection_addresses.insert( + participants::types::DiscoveryServerConnectionAddress( + core::types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), { - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), 11666 + (this_server_id_is_1 ? 0u : 1u), 11666 + (this_server_id_is_1 ? 0u : 1u), ip_version, @@ -113,9 +118,9 @@ std::shared_ptr discovery_server_partic if (is_server(wan_kind)) { - listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + conf.listening_addresses.insert( + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), 11666 + (this_server_id_is_1 ? 1u : 0u), 11666 + (this_server_id_is_1 ? 1u : 0u), ip_version, @@ -123,61 +128,50 @@ std::shared_ptr discovery_server_partic ); } - if (tls) - { - return std::make_shared( - types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_discovery_server, - false, - types::DomainId(0u), - types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), - listening_addresses, - connection_addresses, - tls_configuration(wan_kind)); + conf.id = core::types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))); - } - else + conf.discovery_server_guid_prefix = core::types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)); + + if (tls) { - return std::make_shared( - types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_discovery_server, - false, - types::DomainId(0u), - types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), - listening_addresses, - connection_addresses, - types::security::TlsConfiguration()); + conf.tls_configuration = tls_configuration(wan_kind); } + + return { + types::ParticipantKind::discovery_server, + std::make_shared(conf) + }; } -std::shared_ptr initial_peers_participant_configuration( +std::pair< + types::ParticipantKind, + std::shared_ptr> +initial_peers_participant_configuration( bool this_server_id_is_1, WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version, bool tls = false) { - std::set listening_addresses; - std::set connection_addresses; - types::DomainId domain(60u); + participants::InitialPeersParticipantConfiguration conf; if (is_client(wan_kind)) { - connection_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + conf.connection_addresses.insert( + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), 11666 + (this_server_id_is_1 ? 0u : 1u), 11666 + (this_server_id_is_1 ? 0u : 1u), ip_version, transport_protocol) - ); + ); } if (is_server(wan_kind)) { - listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + conf.listening_addresses.insert( + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), 11666 + (this_server_id_is_1 ? 1u : 0u), 11666 + (this_server_id_is_1 ? 1u : 0u), ip_version, @@ -185,37 +179,28 @@ std::shared_ptr initial_peers_participa ); } - if (tls) - { - return std::make_shared( - types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_initial_peers, - false, - domain, - listening_addresses, - connection_addresses, - tls_configuration(wan_kind)); + conf.id = core::types::ParticipantId("WanDsParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))); - } - else + if (tls) { - return std::make_shared( - types::ParticipantId("InitialPeersParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), - types::ParticipantKind::wan_initial_peers, - false, - domain, - listening_addresses, - connection_addresses, - types::security::TlsConfiguration()); + conf.tls_configuration = tls_configuration(wan_kind); } + + return { + types::ParticipantKind::initial_peers, + std::make_shared(conf) + }; } -std::shared_ptr wan_participant_configuration( +std::pair< + types::ParticipantKind, + std::shared_ptr> +wan_participant_configuration( WanParticipantKind wan_participant_kind, bool this_server_id_is_1, WanKind wan_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version, bool tls = false) { if (wan_participant_kind == WanParticipantKind::discovery_server) @@ -237,45 +222,33 @@ std::shared_ptr wan_participant_configu * Create 1 simple participants with domains \c domain * Create 1 custom participant by the configuration in \c participant_configuration * - * @return configuration::DdsRouterConfiguration + * @return DdsRouterConfiguration */ -configuration::DdsRouterConfiguration router_configuration( - std::shared_ptr participant_configuration, - types::DomainIdType domain) +DdsRouterConfiguration router_configuration( + std::pair< + types::ParticipantKind, + std::shared_ptr> + participant_configuration, + core::types::DomainIdType domain) { - // One topic - auto new_topic = std::make_shared(); - new_topic->topic_name = TOPIC_NAME; - new_topic->type_name = std::string("HelloWorld"); - - std::set> allowlist({new_topic}); + DdsRouterConfiguration conf; - std::set> blocklist; // empty - - std::set> builtin_topics; // empty + // One topic + core::types::WildcardDdsFilterTopic topic; + topic.topic_name.set_value(TOPIC_NAME); + conf.allowlist.insert( + utils::Heritable::make_heritable(topic)); // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 - std::set> participants_configurations( - { - // custom - participant_configuration, - - // simple - std::make_shared( - types::ParticipantId("simple_participant_" + std::to_string(domain)), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(domain) - ), - } - ); + conf.participants_configurations.insert(participant_configuration); + { + auto part = std::make_shared(); + part->id = core::types::ParticipantId("simple_participant_" + std::to_string(domain)); + part->domain.domain_id = domain; + conf.participants_configurations.insert({types::ParticipantKind::simple, part}); + } - return configuration::DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - configuration::SpecsConfiguration()); + return conf; } /** @@ -284,8 +257,8 @@ configuration::DdsRouterConfiguration router_configuration( * instances communicate with the DDS Participants through Simple Participants deployed at those domains. */ void test_WAN_communication( - configuration::DdsRouterConfiguration ddsrouter_server_configuration, - configuration::DdsRouterConfiguration ddsrouter_client_configuration, + DdsRouterConfiguration ddsrouter_server_configuration, + DdsRouterConfiguration ddsrouter_client_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE) @@ -353,8 +326,8 @@ void test_WAN_communication( */ void test_WAN_communication_all( WanParticipantKind wan_participant_kind, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version, + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version, bool basic_only = false, bool tls = false) { @@ -447,12 +420,6 @@ void test_WAN_communication_all( } } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; /** * Test communication in HelloWorld topic between two DDS participants created in different domains, @@ -463,8 +430,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv4) { test::test_WAN_communication_all( test::WanParticipantKind::discovery_server, - types::TransportProtocol::udp, - types::IpVersion::v4); + participants::types::TransportProtocol::udp, + participants::types::IpVersion::v4); } /** @@ -476,8 +443,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv4) { test::test_WAN_communication_all( test::WanParticipantKind::initial_peers, - types::TransportProtocol::udp, - types::IpVersion::v4); + participants::types::TransportProtocol::udp, + participants::types::IpVersion::v4); } /** @@ -489,8 +456,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_UDPv6) { test::test_WAN_communication_all( test::WanParticipantKind::discovery_server, - types::TransportProtocol::udp, - types::IpVersion::v6); + participants::types::TransportProtocol::udp, + participants::types::IpVersion::v6); } /** @@ -502,8 +469,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_UDPv6) { test::test_WAN_communication_all( test::WanParticipantKind::initial_peers, - types::TransportProtocol::udp, - types::IpVersion::v6); + participants::types::TransportProtocol::udp, + participants::types::IpVersion::v6); } /** @@ -515,8 +482,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv4) { test::test_WAN_communication_all( test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v4); + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v4); } /** @@ -528,8 +495,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv4) { test::test_WAN_communication_all( test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v4); + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v4); } /** @@ -541,8 +508,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TCPv6) { test::test_WAN_communication_all( test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v6, + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v6, true); } @@ -555,8 +522,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TCPv6) { test::test_WAN_communication_all( test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v6, + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v6, true); } @@ -569,8 +536,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv4) { test::test_WAN_communication_all( test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v4, + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v4, false, true); } @@ -584,8 +551,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv4) { test::test_WAN_communication_all( test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v4, + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v4, false, true); } @@ -599,8 +566,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_TLSv6) { test::test_WAN_communication_all( test::WanParticipantKind::discovery_server, - types::TransportProtocol::tcp, - types::IpVersion::v6, + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v6, true, true); } @@ -614,8 +581,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_TLSv6) { test::test_WAN_communication_all( test::WanParticipantKind::initial_peers, - types::TransportProtocol::tcp, - types::IpVersion::v6, + participants::types::TransportProtocol::tcp, + participants::types::IpVersion::v6, true, true); } @@ -637,8 +604,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_high_throughput) test::discovery_server_participant_configuration( true, // is server 1 test::WanKind::server, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 0 // domain ), @@ -647,8 +614,8 @@ TEST(DDSTestWAN, end_to_end_discovery_server_WAN_communication_high_throughput) test::discovery_server_participant_configuration( false, // is server 1 test::WanKind::client, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 1 // domain ), @@ -675,8 +642,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_high_throughput) test::initial_peers_participant_configuration( true, // is server 1 test::WanKind::server, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 0 // domain ), @@ -685,8 +652,8 @@ TEST(DDSTestWAN, end_to_end_initial_peers_WAN_communication_high_throughput) test::initial_peers_participant_configuration( false, // is server 1 test::WanKind::client, - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 1 // domain ), diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list deleted file mode 100644 index 78996681f..000000000 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XTSAN.list +++ /dev/null @@ -1,5 +0,0 @@ -DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 -DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 -DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index 1c00337ad..8a20c881c 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -19,16 +19,18 @@ #include #include +#include + +#include #include -#include -#include #include -namespace eprosima { -namespace ddsrouter { -namespace core { +using namespace eprosima; +using namespace eprosima::ddspipe; +using namespace eprosima::ddsrouter::core; + namespace test { constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; @@ -42,64 +44,63 @@ constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. * Create 2 simple participants with domains 0 and 1 * - * @return configuration::DdsRouterConfiguration + * @return DdsRouterConfiguration */ -configuration::DdsRouterConfiguration dds_test_simple_configuration( +DdsRouterConfiguration dds_test_simple_configuration( bool disable_dynamic_discovery = false, bool transient_local_readers = false) { - // Always filter the test topics by topic name - std::set> allowlist; // empty - allowlist.insert(std::make_shared(TOPIC_NAME)); - - std::set> blocklist; // empty + DdsRouterConfiguration conf; - std::set> builtin_topics; // empty + // Always filter the test topics by topic name + core::types::WildcardDdsFilterTopic topic; + topic.topic_name.set_value(TOPIC_NAME); + conf.allowlist.insert( + utils::Heritable::make_heritable(topic)); if (disable_dynamic_discovery) { - types::TopicQoS qos; + core::types::TopicQoS qos; if (transient_local_readers) { - qos.reliability_qos = types::ReliabilityKind::RELIABLE; - qos.durability_qos = types::DurabilityKind::TRANSIENT_LOCAL; + qos.reliability_qos = core::types::ReliabilityKind::RELIABLE; + qos.durability_qos = core::types::DurabilityKind::TRANSIENT_LOCAL; } else { - qos.reliability_qos = types::ReliabilityKind::BEST_EFFORT; - qos.durability_qos = types::DurabilityKind::VOLATILE; + qos.reliability_qos = core::types::ReliabilityKind::BEST_EFFORT; + qos.durability_qos = core::types::DurabilityKind::VOLATILE; } - builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorld", false, qos)); - builtin_topics.insert( - std::make_shared(TOPIC_NAME, "HelloWorldKeyed", true, qos)); + core::types::DdsTopic topic; + topic.m_topic_name = TOPIC_NAME; + topic.type_name = "HelloWorld"; + topic.topic_qos = qos; + + core::types::DdsTopic topic_keyed(topic); + topic_keyed.type_name = "HelloWorldKeyed"; + topic_keyed.topic_qos.keyed = true; + + conf.builtin_topics.insert(utils::Heritable::make_heritable(topic)); + conf.builtin_topics.insert(utils::Heritable::make_heritable(topic_keyed)); } // Two simple participants - std::set> participants_configurations( - { - std::make_shared( - types::ParticipantId("participant_0"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(0u) - ), - std::make_shared( - types::ParticipantId("participant_1"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(1u) - ) - } - ); - - return configuration::DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - configuration::SpecsConfiguration()); + { + auto part = std::make_shared(); + part->id = core::types::ParticipantId("participant_0"); + part->domain.domain_id = 0u; + conf.participants_configurations.insert({types::ParticipantKind::simple, part}); + } + + { + auto part = std::make_shared(); + part->id = core::types::ParticipantId("participant_1"); + part->domain.domain_id = 1u; + conf.participants_configurations.insert({types::ParticipantKind::simple, part}); + } + + return conf; } /** @@ -111,7 +112,7 @@ configuration::DdsRouterConfiguration dds_test_simple_configuration( */ template void test_local_communication( - configuration::DdsRouterConfiguration ddsrouter_configuration, + DdsRouterConfiguration ddsrouter_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE, @@ -198,12 +199,6 @@ void test_local_communication( } } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; /** * Test communication in HelloWorld topic between two DDS participants created in different domains, diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp index a2797b693..cda404c13 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp @@ -19,17 +19,18 @@ #include #include +#include + +#include #include -#include -#include -#include #include -namespace eprosima { -namespace ddsrouter { -namespace core { +using namespace eprosima; +using namespace eprosima::ddspipe; +using namespace eprosima::ddsrouter::core; + namespace test { constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; @@ -44,46 +45,34 @@ constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes * and any possible type (such as HelloWorld and HelloWorldKeyed) both with and without key. * Create 2 simple participants with domains 0 and 1 * - * @return configuration::DdsRouterConfiguration + * @return DdsRouterConfiguration */ -configuration::DdsRouterConfiguration dds_test_simple_configuration() +DdsRouterConfiguration dds_test_simple_configuration() { + DdsRouterConfiguration conf; + // Always filter the test topics by topic name - std::set> allowlist; // only this topic - allowlist.insert(std::make_shared(TOPIC_NAME)); + core::types::WildcardDdsFilterTopic topic; + topic.topic_name.set_value(TOPIC_NAME); + conf.allowlist.insert( + utils::Heritable::make_heritable(topic)); - std::set> blocklist; // empty + // Two simple participants + { + auto part = std::make_shared(); + part->id = core::types::ParticipantId("participant_0"); + part->domain.domain_id = 0u; + conf.participants_configurations.insert({types::ParticipantKind::simple, part}); + } - std::set> builtin_topics; // empty + { + auto part = std::make_shared(); + part->id = core::types::ParticipantId("participant_1"); + part->domain.domain_id = 1u; + conf.participants_configurations.insert({types::ParticipantKind::simple, part}); + } - // Two simple participants - std::set> participants_configurations( - { - std::make_shared( - types::ParticipantId("participant_0"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(0u) - ), - std::make_shared( - types::ParticipantId("participant_1"), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(1u) - ) - } - ); - - // TODO: this could be removed to use default number of threads - auto specs = configuration::SpecsConfiguration(); - specs.number_of_threads = 2; - - return configuration::DdsRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - specs); + return conf; } /** @@ -94,7 +83,7 @@ configuration::DdsRouterConfiguration dds_test_simple_configuration() * to Late Joiners. */ void test_local_communication_key_dispose( - configuration::DdsRouterConfiguration ddsrouter_configuration, + DdsRouterConfiguration ddsrouter_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE) @@ -175,9 +164,6 @@ void test_local_communication_key_dispose( } } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/CMakeLists.txt index f72cb095b..f1803e5d1 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/CMakeLists.txt @@ -30,7 +30,6 @@ set(TEST_LIST repeater_initial_peers_communication_UDPv4 ) - set(TEST_NEEDED_SOURCES ) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp index 25a8c9ab7..7243dbad0 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp @@ -19,58 +19,63 @@ #include #include -#include +#include + +#include +#include +#include +#include -#include -#include #include -#include -#include -#include #include -namespace eprosima { -namespace ddsrouter { -namespace core { +using namespace eprosima; +using namespace eprosima::ddspipe; +using namespace eprosima::ddsrouter::core; + namespace test { constexpr const uint32_t DEFAULT_SAMPLES_TO_RECEIVE = 5; constexpr const uint32_t DEFAULT_MILLISECONDS_PUBLISH_LOOP = 100; constexpr const uint32_t DEFAULT_MESSAGE_SIZE = 1; // x50 bytes -std::shared_ptr initial_peers_participant_configuration_client( +std::pair< + types::ParticipantKind, + std::shared_ptr> +initial_peers_participant_configuration_client( bool this_server_id_is_1, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version) + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version) { - auto conf = std::make_shared(); + auto conf = std::make_shared(); - conf->id = types::ParticipantId("InitialPeersParticipant_Client_" + std::to_string((this_server_id_is_1 ? 1 : 0))); - conf->kind = types::ParticipantKind::wan_initial_peers; + conf->id = core::types::ParticipantId("InitialPeersParticipant_Client_" + std::to_string((this_server_id_is_1 ? 1 : 0))); conf->connection_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), 11666, 11666, ip_version, transport_protocol) ); - return conf; + return {types::ParticipantKind::initial_peers, conf}; } -std::shared_ptr initial_peers_participant_configuration_server( - types::TransportProtocol transport_protocol, - types::IpVersion ip_version) +std::pair< + types::ParticipantKind, + std::shared_ptr> +initial_peers_participant_configuration_server( + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version) { - auto conf = std::make_shared(); + auto conf = std::make_shared(); - conf->id = types::ParticipantId("InitialPeersParticipant_Server"); - conf->kind = types::ParticipantKind::wan_initial_peers; + conf->id = core::types::ParticipantId("InitialPeersParticipant_Server"); conf->listening_addresses.insert( - types::Address( - (ip_version == types::IpVersion::v4 ? "127.0.0.1" : "::1"), + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), 11666, 11666, ip_version, @@ -78,14 +83,17 @@ std::shared_ptr initial_peers_participa ); conf->is_repeater = true; - return conf; + return {types::ParticipantKind::initial_peers, conf}; } -std::shared_ptr participant_configuration( +std::pair< + types::ParticipantKind, + std::shared_ptr> +participant_configuration( bool server, bool this_server_id_is_1, - types::TransportProtocol transport_protocol, - types::IpVersion ip_version) + participants::types::TransportProtocol transport_protocol, + participants::types::IpVersion ip_version) { if (server) { @@ -104,55 +112,35 @@ std::shared_ptr participant_configurati * Create 1 simple participants with domains \c domain * Create 1 custom participant by the configuration in \c participant_configuration * -<<<<<<< HEAD - * @return configuration::DDSRouterConfiguration + * @return DdsRouterConfiguration */ -configuration::DDSRouterConfiguration router_configuration( -======= - * @return configuration::DdsRouterConfiguration - */ -configuration::DdsRouterConfiguration router_configuration( ->>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) - std::shared_ptr participant_configuration, - types::DomainIdType domain, +DdsRouterConfiguration router_configuration( + std::pair< + types::ParticipantKind, + std::shared_ptr> + participant_configuration, + core::types::DomainIdType domain, bool has_simple = true) { - // One topic - auto new_topic = std::make_shared(); - new_topic->topic_name = TOPIC_NAME; - new_topic->type_name = std::string("HelloWorld"); - - std::set> allowlist({new_topic}); - - std::set> blocklist; // empty + DdsRouterConfiguration conf; - std::set> builtin_topics; // empty + // One topic + core::types::WildcardDdsFilterTopic topic; + topic.topic_name.set_value(TOPIC_NAME); + conf.allowlist.insert( + utils::Heritable::make_heritable(topic)); // Two participants, one custom and other simple. If server, simple will work in 0, if not in 1 - std::set> participants_configurations = - { participant_configuration }; - + conf.participants_configurations.insert(participant_configuration); if (has_simple) { - participants_configurations.insert( - std::make_shared( - types::ParticipantId("simple_participant_" + std::to_string(domain)), - types::ParticipantKind(types::ParticipantKind::simple_rtps), - false, - types::DomainId(domain) - )); + auto part = std::make_shared(); + part->id = core::types::ParticipantId("simple_participant_" + std::to_string(domain)); + part->domain.domain_id = domain; + conf.participants_configurations.insert({types::ParticipantKind::simple, part}); } -<<<<<<< HEAD - return configuration::DDSRouterConfiguration( -======= - return configuration::DdsRouterConfiguration( ->>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) - allowlist, - blocklist, - builtin_topics, - participants_configurations, - configuration::SpecsConfiguration()); + return conf; } /** @@ -161,15 +149,9 @@ configuration::DdsRouterConfiguration router_configuration( * instances communicate with the DDS Participants through Simple Participants deployed at those domains. */ void test_WAN_communication( -<<<<<<< HEAD - configuration::DDSRouterConfiguration ddsrouter_client_configuration_1, - configuration::DDSRouterConfiguration ddsrouter_client_configuration_2, - configuration::DDSRouterConfiguration ddsrouter_repeater_configuration, -======= - configuration::DdsRouterConfiguration ddsrouter_client_configuration_1, - configuration::DdsRouterConfiguration ddsrouter_client_configuration_2, - configuration::DdsRouterConfiguration ddsrouter_repeater_configuration, ->>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) + DdsRouterConfiguration ddsrouter_client_configuration_1, + DdsRouterConfiguration ddsrouter_client_configuration_2, + DdsRouterConfiguration ddsrouter_repeater_configuration, uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE, uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP, uint32_t msg_size = DEFAULT_MESSAGE_SIZE) @@ -189,11 +171,7 @@ void test_WAN_communication( // Add this string as many times as the msg size requires for (uint32_t i = 0; i < msg_size; i++) { -<<<<<<< HEAD - msg_str += "Testing DDSRouter Blackbox Local Communication ..."; -======= msg_str += "Testing DdsRouter Blackbox Local Communication ..."; ->>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) } msg.message(msg_str); @@ -205,18 +183,6 @@ void test_WAN_communication( TestSubscriber subscriber; ASSERT_TRUE(subscriber.init(1, &msg, &samples_received)); -<<<<<<< HEAD - // Create DDSRouter entity whose WAN Participant is configured as server - DDSRouter client_router_1(ddsrouter_client_configuration_1); - client_router_1.start(); - - // Create DDSRouter entity whose WAN Participant is configured as client - DDSRouter client_router_2(ddsrouter_client_configuration_2); - client_router_2.start(); - - // Create DDSRouter entity whose WAN Participant is configured as repeater - DDSRouter repeater(ddsrouter_repeater_configuration); -======= // Create DdsRouter entity whose WAN Participant is configured as server DdsRouter client_router_1(ddsrouter_client_configuration_1); client_router_1.start(); @@ -227,7 +193,6 @@ void test_WAN_communication( // Create DdsRouter entity whose WAN Participant is configured as repeater DdsRouter repeater(ddsrouter_repeater_configuration); ->>>>>>> 89b5958 (Implement tests (some)for ddsrouter_core) repeater.start(); // Start publishing @@ -249,12 +214,6 @@ void test_WAN_communication( } } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; /** * Test communication in HelloWorld topic between two DDS participants created in different domains, @@ -269,8 +228,8 @@ TEST(DDSTestRepeater, repeater_initial_peers_communication_UDPv4) test::participant_configuration( false, // server true, // is server 1 - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 0 // domain ), // Client 0 @@ -279,8 +238,8 @@ TEST(DDSTestRepeater, repeater_initial_peers_communication_UDPv4) test::participant_configuration( false, // server false, // is server 1 - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 1 // domain ), // Client 1 @@ -289,8 +248,8 @@ TEST(DDSTestRepeater, repeater_initial_peers_communication_UDPv4) test::participant_configuration( true, // server true, // is server 1 [not used] - types::TransportProtocol::udp, // transport protocol - types::IpVersion::v4 // ip version + participants::types::TransportProtocol::udp, // transport protocol + participants::types::IpVersion::v4 // ip version ), 66, // domain false // has simple diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp index 03c0d7cb5..22592369b 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp @@ -23,7 +23,8 @@ #include #include -#include +#include + #include #include @@ -49,9 +50,6 @@ #include "HelloWorld/HelloWorldPubSubTypes.h" #include "HelloWorldKeyed/HelloWorldKeyedPubSubTypes.h" -namespace eprosima { -namespace ddsrouter { -namespace core { namespace test { constexpr const char* TOPIC_NAME = "DDS-Router-Test"; @@ -490,8 +488,3 @@ class TestSubscriber }; } /* namespace test */ -} /* namespace core */ -} /* namespace ddsrouter */ -} /* namespace eprosima */ - -#endif /* _TEST_BLACKBOX_DDSROUTERCORE_DDS_TYPES_TEST_PARTICIPANTS_HPP_ */ diff --git a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp index 04f823547..a52b6b7ea 100644 --- a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp +++ b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp @@ -35,6 +35,7 @@ constexpr const unsigned int DEFAULT_MAX_HISTORY_DEPTH = 100; } /* namespace test */ +using namespace eprosima; using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; using namespace eprosima::ddsrouter::core::testing; @@ -120,10 +121,11 @@ TEST(ImplementationsTest, pair_implementation_with_topic) ); // Add topic - std::shared_ptr topic = std::make_shared(); - topic->m_topic_name = "rt/chatter"; - topic->type_name = "std_msgs::msg::dds_::String_"; - configuration.builtin_topics.insert(topic); + eprosima::ddspipe::core::types::DdsTopic topic; + topic.m_topic_name = "rt/chatter"; + topic.type_name = "std_msgs::msg::dds_::String_"; + configuration.builtin_topics.insert( + utils::Heritable::make_heritable(topic)); // Create DdsRouter entity DdsRouter router(configuration); diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list b/ddsrouter_core/test/labels/XFAIL.list similarity index 100% rename from ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/TEST_XFAIL.list rename to ddsrouter_core/test/labels/XFAIL.list diff --git a/ddsrouter_core/test/labels/XTSAN.list b/ddsrouter_core/test/labels/XTSAN.list index 7e7fb9dae..bc7736624 100644 --- a/ddsrouter_core/test/labels/XTSAN.list +++ b/ddsrouter_core/test/labels/XTSAN.list @@ -1,3 +1,8 @@ ImplementationsTest.pair_implementation ImplementationsTest.pair_implementation_with_topic ImplementationsTest.all_implementations +DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput From 2768c5288c3563d4179baf3d6fa98bfe1eb0dd99 Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 26 Apr 2023 11:03:39 +0200 Subject: [PATCH 28/38] Fix Ci update Signed-off-by: jparisu --- .github/actions/project_dependencies/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/project_dependencies/action.yml b/.github/actions/project_dependencies/action.yml index c05827965..3fc5aac79 100644 --- a/.github/actions/project_dependencies/action.yml +++ b/.github/actions/project_dependencies/action.yml @@ -34,7 +34,7 @@ runs: steps: - name: Install Fast DDS dependencies - uses: jparisu/eProsima-CI/multiplatform/install_fast_dependencies@main + uses: jparisu/eProsima-CI/multiplatform/install_fastdds_dependencies@main with: cmake_build_type: ${{ inputs.cmake_build_type }} From 2268fd6b16c74759370f00224cace90911e905df Mon Sep 17 00:00:00 2001 From: jparisu Date: Thu, 27 Apr 2023 15:24:19 +0200 Subject: [PATCH 29/38] Fix YamlReader builtin read Signed-off-by: jparisu --- ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index f6241cd68..75df69090 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -131,8 +131,7 @@ void YamlReader::fill( // Get optional builtin topics if (YamlReader::is_tag_present(yml, BUILTIN_TAG)) { - object.builtin_topics = utils::convert_set_to_shared( - YamlReader::get_set(yml, BUILTIN_TAG, version)); + object.builtin_topics = YamlReader::get_set>(yml, BUILTIN_TAG, version); } ///// From 62661135d5c9ad7c3ebcac853aba3571eddf4025 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 23 May 2023 12:56:24 +0200 Subject: [PATCH 30/38] Update CI to eProsima v0 Signed-off-by: jparisu --- .../action.yml | 73 ------------------- .../install-fastcdr-windows/action.yml | 15 ---- .../install-fastdds-windows/action.yml | 16 ---- .../action.yml | 16 ---- .../actions/install-gtest-linux/action.yml | 21 ------ .../actions/install-gtest-windows/action.yml | 20 ----- .../install-openssl-windows/action.yml | 10 --- .../action.yml | 28 ------- .../install-yamlcpp-windows/action.yml | 19 ----- .../actions/project_dependencies/action.yml | 9 ++- .github/actions/run-test-ubuntu/action.yml | 19 ----- .github/actions/run-test-windows/action.yml | 16 ---- .github/workflows/test.yml | 38 +++++----- 13 files changed, 22 insertions(+), 278 deletions(-) delete mode 100644 .github/actions/install-eprosima-dependencies-windows/action.yml delete mode 100644 .github/actions/install-fastcdr-windows/action.yml delete mode 100644 .github/actions/install-fastdds-windows/action.yml delete mode 100644 .github/actions/install-foonathan-memory-windows/action.yml delete mode 100644 .github/actions/install-gtest-linux/action.yml delete mode 100644 .github/actions/install-gtest-windows/action.yml delete mode 100644 .github/actions/install-openssl-windows/action.yml delete mode 100644 .github/actions/install-router-subpackage-windows/action.yml delete mode 100644 .github/actions/install-yamlcpp-windows/action.yml delete mode 100644 .github/actions/run-test-ubuntu/action.yml delete mode 100644 .github/actions/run-test-windows/action.yml diff --git a/.github/actions/install-eprosima-dependencies-windows/action.yml b/.github/actions/install-eprosima-dependencies-windows/action.yml deleted file mode 100644 index 9f4f4fde3..000000000 --- a/.github/actions/install-eprosima-dependencies-windows/action.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Install eProsima dependencies -description: Install and setup foonatham-memory, Fast CDR and Fast DDS for linking and building applications in Windows -inputs: - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' - fastdds_branch: - description: 'Branch or tag of Fast DDS repository (https://github.com/eProsima/Fast-DDS)' - required: true - default: 'master' - utils_branch: - description: 'Branch or tag of Dev Utils repository (https://github.com/eProsima/dev-utils)' - required: true - default: 'main' -runs: - using: composite - steps: - - name: Install foonatham memory - shell: pwsh - run: > - git clone --recurse-submodules --branch v0.6-2 https://github.com/foonathan/memory.git; - cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\eprosima\install ` - -DBUILD_SHARED_LIBS=OFF -DFOONATHAN_MEMORY_BUILD_TOOLS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON ` - -DFOONATHAN_MEMORY_BUILD_TESTS=OFF -Ax64 -T host=x64 -B build\memory memory; - cmake --build build\memory --config ${{ inputs.cmake_build_type }} --target install - - - name: Install Fast CDR - shell: pwsh - run: > - git clone https://github.com/eProsima/Fast-CDR.git; - cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\eprosima\install ` - -DCMAKE_PREFIX_PATH=${{ github.workspace }}\eprosima\install ` - -Ax64 -T host=x64 -B build\fastcdr Fast-CDR; - cmake --build build\fastcdr --config ${{ inputs.cmake_build_type }} --target install - - - name: Install Fast DDS - shell: pwsh - run: > - git clone https://github.com/eProsima/Fast-DDS.git --branch ${{ inputs.fastdds_branch }}; - cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\eprosima\install ` - -DCMAKE_PREFIX_PATH=${{ github.workspace }}\eprosima\install ` - -DTHIRDPARTY=ON -DSECURITY=ON -DCOMPILE_EXAMPLES=OFF -DEPROSIMA_BUILD_TESTS=OFF ` - -DINTERNAL_DEBUG=ON -Ax64 -T host=x64 -B build\fastdds Fast-DDS; - cmake --build build\fastdds --config ${{ inputs.cmake_build_type }} --target install - - # This is needed for windows 2019 to use /Zc:preprocessor to use c++ std preprocessor for ENUMERATION_BUILDER - # due to a windows 2019 SDK non bug - - name: Set environment variables for Windows 2019 build - shell: pwsh - run: > - echo ("W2019_CMAKE_EXTRA_ARGS=-DCMAKE_SYSTEM_VERSION=10.0.19041.0") >> $env:GITHUB_ENV - if: contains( matrix.windows-version , '2019') - - - name: Install Dev Utils - shell: pwsh - run: > - git clone https://github.com/eProsima/dev-utils.git --branch ${{ inputs.utils_branch }}; - cmake ` - -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\eprosima\install ` - -DCMAKE_PREFIX_PATH=${{ github.workspace }}\eprosima\install ` - -DCMAKE_CXX_FLAGS="/WX /EHsc" ` - -Ax64 -T host=x64 ` - -B build\cmake_utils -S dev-utils\cmake_utils; - cmake --build build\cmake_utils --config ${{ inputs.cmake_build_type }} --target install; - cmake ` - -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\eprosima\install ` - -DCMAKE_PREFIX_PATH=${{ github.workspace }}\eprosima\install ` - -DCMAKE_CXX_FLAGS="/WX /EHsc" ` - ${{ env.W2019_CMAKE_EXTRA_ARGS }} ` - -Ax64 -T host=x64 ` - -B build\cpp_utils -S dev-utils\cpp_utils; - cmake --build build\cpp_utils --config ${{ inputs.cmake_build_type }} --target install; diff --git a/.github/actions/install-fastcdr-windows/action.yml b/.github/actions/install-fastcdr-windows/action.yml deleted file mode 100644 index bef61729a..000000000 --- a/.github/actions/install-fastcdr-windows/action.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Install Fast CDR -description: Install and setup Fast CDR for linking and building application in Windows -inputs: - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' -runs: - using: composite - steps: - - run: > - git clone https://github.com/eProsima/Fast-CDR.git; - cmake -Ax64 -T host=x64 -B build\fastcdr Fast-CDR; - cmake --build build\fastcdr --config ${{ inputs.cmake_build_type }} --target install - shell: pwsh diff --git a/.github/actions/install-fastdds-windows/action.yml b/.github/actions/install-fastdds-windows/action.yml deleted file mode 100644 index b552bfef6..000000000 --- a/.github/actions/install-fastdds-windows/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Install Fast DDS -description: Install and setup Fast DDS for linking and building application in Windows -inputs: - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' -runs: - using: composite - steps: - - run: > - git clone https://github.com/eProsima/Fast-DDS.git; - cmake -DTHIRDPARTY=ON -DSECURITY=ON -DCOMPILE_EXAMPLES=OFF -DEPROSIMA_BUILD_TESTS=OFF ` - -DINTERNAL_DEBUG=ON -Ax64 -T host=x64 -B build\fastdds Fast-DDS; - cmake --build build\fastdds --config ${{ inputs.cmake_build_type }} --target install - shell: pwsh diff --git a/.github/actions/install-foonathan-memory-windows/action.yml b/.github/actions/install-foonathan-memory-windows/action.yml deleted file mode 100644 index aa3a4a3c6..000000000 --- a/.github/actions/install-foonathan-memory-windows/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Install foonathan memory -description: Install and setup foonathan memory for linking and building application in Windows -inputs: - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' -runs: - using: composite - steps: - - run: > - git clone --recurse-submodules --branch v0.6-2 https://github.com/foonathan/memory.git; - cmake -DBUILD_SHARED_LIBS=OFF -DFOONATHAN_MEMORY_BUILD_TOOLS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON ` - -DFOONATHAN_MEMORY_BUILD_TESTS=OFF -Ax64 -T host=x64 -B build\memory memory; - cmake --build build\memory --config ${{ inputs.cmake_build_type }} --target install - shell: pwsh diff --git a/.github/actions/install-gtest-linux/action.yml b/.github/actions/install-gtest-linux/action.yml deleted file mode 100644 index 3c3257df1..000000000 --- a/.github/actions/install-gtest-linux/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Install GTest -description: Install and setup GTest for linking and building test application in Linux -runs: - using: composite - steps: - - run: sudo apt install libgtest-dev libgmock-dev - shell: bash - - run: (cd /usr/src/gtest && sudo `which cmake` .) - shell: bash - - run: sudo make -j $(nproc) -C /usr/src/gtest - shell: bash - - run: sudo ln -s /usr/src/gtest/libgtest.a /usr/lib/libgtest.a - shell: bash - - run: sudo ln -s /usr/src/gtest/libgtest_main.a /usr/lib/libgtest_main.a - shell: bash - - run: (cd /usr/src/googletest/googlemock && sudo `which cmake` .) - shell: bash - - run: sudo make -j $(nproc) -C /usr/src/googletest/googlemock - shell: bash - - run: sudo ln -s /usr/src/googletest/googlemock/libgmock.a /usr/lib/libgmock.a - shell: bash diff --git a/.github/actions/install-gtest-windows/action.yml b/.github/actions/install-gtest-windows/action.yml deleted file mode 100644 index 58dd0658f..000000000 --- a/.github/actions/install-gtest-windows/action.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Install GTest -description: Install and setup GTest for linking and building test application in Windows -inputs: - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' -runs: - using: composite - steps: - - run: > - cmake --find-package -DNAME=GTest -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=EXIST | Tee-Object -Variable res; - if ( $res -notlike '*GTest found.*') - { - git clone --branch release-1.12.1 https://github.com/google/googletest.git; - cmake -DCMAKE_INSTALL_PREFIX='C:\Program Files\gtest' -Dgtest_force_shared_crt=ON -DBUILD_GMOCK=ON ` - -B build\gtest -A x64 -T host=x64 googletest; - cmake --build build\gtest --config ${{ inputs.cmake_build_type }} --target install - } - shell: pwsh diff --git a/.github/actions/install-openssl-windows/action.yml b/.github/actions/install-openssl-windows/action.yml deleted file mode 100644 index 964caecdd..000000000 --- a/.github/actions/install-openssl-windows/action.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Install OpenSSL -description: Install and setup OpenSSL for linking and building in Windows -runs: - using: composite - steps: - - run: > - choco install openssl -yr --no-progress; - @(ls -Path C:\Windows\System32\* -Include libssl-*.dll; ls -Path C:\Windows\SysWOW64\* -Include libssl-*.dll) - | rm -ErrorAction SilentlyContinue - shell: pwsh diff --git a/.github/actions/install-router-subpackage-windows/action.yml b/.github/actions/install-router-subpackage-windows/action.yml deleted file mode 100644 index 1cf514487..000000000 --- a/.github/actions/install-router-subpackage-windows/action.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Install DDS Router subpackages -description: Install and setup DDS Router subpackages for linking and building application in Windows -inputs: - cmake_extra_args: - description: 'Specifies cmake arguments different from default' - required: false - default: ' ' - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' - subpackage: - description: 'Specifies the name of the subpackage to install' - required: true - subpackage_dir: - description: 'Specifies the path of the subpackage to install' - required: true -runs: - using: composite - steps: - - run: > - cmake -DCMAKE_PREFIX_PATH='C:\Program Files\gtest;C:\Program Files\yamlcpp;C:\Program Files;${{ github.workspace }}\..\fastdds\install' ` - -DCMAKE_CXX_FLAGS="/WX /EHsc" -DBUILD_TOOL_TESTS=ON -DBUILD_LIBRARY_TESTS=ON ` - ${{ inputs.cmake_extra_args }} ` - -B build\${{ inputs.subpackage }} -A x64 -T host=x64 DDS-Router/${{ inputs.subpackage_dir }}; - cmake --build build\${{ inputs.subpackage }} --config ${{ inputs.cmake_build_type }} --target install; - - shell: pwsh diff --git a/.github/actions/install-yamlcpp-windows/action.yml b/.github/actions/install-yamlcpp-windows/action.yml deleted file mode 100644 index 0a1613dee..000000000 --- a/.github/actions/install-yamlcpp-windows/action.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Install yaml-cpp -description: Install and setup yaml-cpp for linking and building in Windows -inputs: - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' -runs: - using: composite - steps: - - run: > - cmake --find-package -DNAME=yamlcpp -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=EXIST | Tee-Object -Variable res; - if ( $res -notlike '*yamlcpp found.*') - { - git clone --branch yaml-cpp-0.7.0 https://github.com/jbeder/yaml-cpp; - cmake -DCMAKE_INSTALL_PREFIX='C:\Program Files\yamlcpp' -B build\yamlcpp yaml-cpp - cmake --build build\yamlcpp --config ${{ inputs.cmake_build_type }} --target install - } - shell: pwsh diff --git a/.github/actions/project_dependencies/action.yml b/.github/actions/project_dependencies/action.yml index 3fc5aac79..b76f840b5 100644 --- a/.github/actions/project_dependencies/action.yml +++ b/.github/actions/project_dependencies/action.yml @@ -34,21 +34,22 @@ runs: steps: - name: Install Fast DDS dependencies - uses: jparisu/eProsima-CI/multiplatform/install_fastdds_dependencies@main + uses: eProsima/eProsima-CI/multiplatform/install_fastdds_dependencies@v0 with: cmake_build_type: ${{ inputs.cmake_build_type }} - name: Install yaml cpp dependency - uses: jparisu/eProsima-CI/multiplatform/install_yamlcpp@main + uses: eProsima/eProsima-CI/multiplatform/install_yamlcpp@v0 with: cmake_build_type: ${{ inputs.cmake_build_type }} # In DDS Pipe artifact there are included Fast DDS and dev-utils - name: Download dependencies artifact - uses: jparisu/eProsima-CI/multiplatform/download_dependency@main + uses: eProsima/eProsima-CI/multiplatform/download_dependency@v0 with: artifact_name: built_ddspipe_${{ inputs.os }}_${{ inputs.cmake_build_type }}${{ inputs.dependencies_artifact_postfix }} workflow_source: build_ddspipe.yml - workflow_source_repository: jparisu/eProsima-CI + workflow_source_repository: eProsima/eProsima-CI target_workspace: ${{ inputs.target_workspace }} secret_token: ${{ inputs.secret_token }} + workflow_conclusion: completed diff --git a/.github/actions/run-test-ubuntu/action.yml b/.github/actions/run-test-ubuntu/action.yml deleted file mode 100644 index 373c84d01..000000000 --- a/.github/actions/run-test-ubuntu/action.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Run colcon test in ubuntu -description: Run colcon test in ubuntu for a specific package -inputs: - package_name: - description: 'Specifies the package to run the tests' - required: true -runs: - using: composite - steps: - - run: | - source install/setup.bash - colcon test \ - --packages-select ${{ inputs.package_name }} \ - --event-handlers=console_direct+ \ - --return-code-on-test-failure \ - --ctest-args \ - --label-exclude xfail \ - --timeout 60 - shell: bash diff --git a/.github/actions/run-test-windows/action.yml b/.github/actions/run-test-windows/action.yml deleted file mode 100644 index 7d319838b..000000000 --- a/.github/actions/run-test-windows/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Run DDS Router subpackage tests in windows -description: Run DDS Router tests in windows for a specific package -inputs: - package_name: - description: 'Specifies the package build name to run the tests' - required: true - cmake_build_type: - description: 'Specifies the build type on single-configuration generators' - required: true - default: 'Release' -runs: - using: composite - steps: - - run: > - ctest -C ${{ inputs.cmake_build_type }} --test-dir build\${{ inputs.package_name }} -V --timeout 60 --label-exclude xfail - shell: pwsh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8a036162e..7da896975 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,10 +46,6 @@ # - ubuntu-22.04 # - test python linter # -# TODO: when merge CI in eprosima-CI repository, the jparisu fork must change for eProsima in actions. -# -# TODO: Add Windows CI -# name: test @@ -61,7 +57,7 @@ on: dependencies_artifact_postfix: description: 'Postfix name to add to artifact name to download dependencies. This is use to download a specific artifact version from eProsima-CI.' required: true - default: '_manual' + default: '_nightly' pull_request: push: @@ -73,7 +69,7 @@ on: env: code_packages_names: 'ddsrouter_core ddsrouter_yaml ddsrouter_tool' docs_packages_names: 'ddsrouter_docs' - default_dependencies_artifact_postfix: '_manual' + default_dependencies_artifact_postfix: '_nightly' jobs: @@ -98,7 +94,7 @@ jobs: steps: - name: Sync repository - uses: actions/checkout@v3 + uses: eProsima/eProsima-CI/external/checkout@v0 with: path: ${{ github.workspace }}/src @@ -111,7 +107,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: jparisu/eProsima-CI/multiplatform/colcon_build_test@main + uses: eProsima/eProsima-CI/multiplatform/colcon_build_test@v0 with: packages_names: ${{ env.code_packages_names }} cmake_args: -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} @@ -128,7 +124,7 @@ jobs: steps: - name: Sync repository - uses: actions/checkout@v3 + uses: eProsima/eProsima-CI/external/checkout@v0 with: path: ${{ github.workspace }}/src @@ -141,7 +137,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: jparisu/eProsima-CI/multiplatform/asan_build_test@main + uses: eProsima/eProsima-CI/multiplatform/asan_build_test@v0 with: packages_names: ${{ env.code_packages_names }} workspace_dependencies: ${{ github.workspace }}/install @@ -155,7 +151,7 @@ jobs: steps: - name: Sync repository - uses: actions/checkout@v3 + uses: eProsima/eProsima-CI/external/checkout@v0 with: path: ${{ github.workspace }}/src @@ -168,7 +164,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: jparisu/eProsima-CI/multiplatform/tsan_build_test@main + uses: eProsima/eProsima-CI/multiplatform/tsan_build_test@v0 with: packages_names: ${{ env.code_packages_names }} workspace_dependencies: ${{ github.workspace }}/install @@ -182,7 +178,7 @@ jobs: steps: - name: Sync repository - uses: actions/checkout@v3 + uses: eProsima/eProsima-CI/external/checkout@v0 with: path: ${{ github.workspace }}/src @@ -195,7 +191,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: jparisu/eProsima-CI/multiplatform/clang_build_test@main + uses: eProsima/eProsima-CI/multiplatform/clang_build_test@v0 with: packages_names: ${{ env.code_packages_names }} workspace_dependencies: ${{ github.workspace }}/install @@ -211,7 +207,7 @@ jobs: steps: - name: Sync repository - uses: actions/checkout@v3 + uses: eProsima/eProsima-CI/external/checkout@v0 with: path: ${{ github.workspace }}/src @@ -224,7 +220,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: jparisu/eProsima-CI/ubuntu/coverage_build_test_upload@main + uses: eProsima/eProsima-CI/ubuntu/coverage_build_test_upload@v0 with: packages_names: ${{ env.code_packages_names }} workspace_dependencies: ${{ github.workspace }}/install @@ -240,7 +236,7 @@ jobs: steps: - name: Sync repository - uses: actions/checkout@v3 + uses: eProsima/eProsima-CI/external/checkout@v0 with: path: ${{ github.workspace }}/src @@ -253,7 +249,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: jparisu/eProsima-CI/multiplatform/colcon_build_test_flaky@main + uses: eProsima/eProsima-CI/v0colcon_build_test_flaky@main with: packages_names: ${{ env.code_packages_names }} workspace_dependencies: ${{ github.workspace }}/install @@ -266,7 +262,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Build and test documentation - uses: jparisu/eProsima-CI/ubuntu/sphinx_docs@main + uses: eProsima/eProsima-CI/ubuntu/sphinx_docs@v0 with: docs_subpackage_name: ${{ env.docs_packages_names }} secret_token: ${{ secrets.GITHUB_TOKEN }} @@ -280,7 +276,7 @@ jobs: steps: - name: Uncrustify - uses: jparisu/eProsima-CI/ubuntu-22.04/uncrustify@main + uses: eProsima/eProsima-CI/ubuntu-22.04/uncrustify@v0 ##################################################################### @@ -291,4 +287,4 @@ jobs: steps: - name: Python Linter - uses: jparisu/eProsima-CI/ubuntu/python_linter@main + uses: eProsima/eProsima-CI/ubuntu/python_linter@v0 From d1fe43d0b2522b8929d6b636bd7310a1b1907205 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 23 May 2023 14:32:04 +0200 Subject: [PATCH 31/38] Add TSAN flags to tests Signed-off-by: jparisu --- .github/workflows/test.yml | 2 +- ddsrouter_core/test/labels/CMakeLists.txt | 3 +++ ddsrouter_core/test/labels/XTSAN.list | 27 ++++++++++++++++--- ddsrouter_yaml/CMakeLists.txt | 6 ++--- ddsrouter_yaml/test/unittest/CMakeLists.txt | 2 +- tools/ddsrouter_tool/test/CMakeLists.txt | 3 +++ .../ddsrouter_tool/test/labels/CMakeLists.txt | 16 +++++++++++ tools/ddsrouter_tool/test/labels/XTSAN.list | 8 ++++++ 8 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 tools/ddsrouter_tool/test/labels/CMakeLists.txt create mode 100644 tools/ddsrouter_tool/test/labels/XTSAN.list diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7da896975..432a3a6f1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -249,7 +249,7 @@ jobs: secret_token: ${{ secrets.GITHUB_TOKEN }} - name: Compile and run tests - uses: eProsima/eProsima-CI/v0colcon_build_test_flaky@main + uses: eProsima/eProsima-CI/multiplatform/colcon_build_test_flaky@v0 with: packages_names: ${{ env.code_packages_names }} workspace_dependencies: ${{ github.workspace }}/install diff --git a/ddsrouter_core/test/labels/CMakeLists.txt b/ddsrouter_core/test/labels/CMakeLists.txt index 17e16bc1f..8079fffe9 100644 --- a/ddsrouter_core/test/labels/CMakeLists.txt +++ b/ddsrouter_core/test/labels/CMakeLists.txt @@ -12,5 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Set list of tests that can fail +set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XFAIL.list "xfail") + # Set list of tests that can fail using TSAN set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XTSAN.list "xtsan") diff --git a/ddsrouter_core/test/labels/XTSAN.list b/ddsrouter_core/test/labels/XTSAN.list index bc7736624..6131efbfd 100644 --- a/ddsrouter_core/test/labels/XTSAN.list +++ b/ddsrouter_core/test/labels/XTSAN.list @@ -1,8 +1,29 @@ -ImplementationsTest.pair_implementation -ImplementationsTest.pair_implementation_with_topic -ImplementationsTest.all_implementations +DDSTestLocal.end_to_end_local_communication +DDSTestLocal.end_to_end_local_communication_keyed +DDSTestLocal.end_to_end_local_communication_disable_dynamic_discovery +DDSTestLocal.end_to_end_local_communication_disable_dynamic_discovery_keyed +DDSTestLocal.end_to_end_local_communication_high_frequency +DDSTestLocal.end_to_end_local_communication_high_size +DDSTestLocal.end_to_end_local_communication_high_throughput +DDSTestLocal.end_to_end_local_communication_transient_local +DDSTestLocal.end_to_end_local_communication_transient_local_disable_dynamic_discovery +DDSTestLocalDisposeKey.end_to_end_local_communication_key_dispose +DDSTestRepeater.repeater_initial_peers_communication_UDPv4 DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv4 DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv4 DDSTestWAN.end_to_end_discovery_server_WAN_communication_UDPv6 DDSTestWAN.end_to_end_initial_peers_WAN_communication_UDPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TCPv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TCPv6 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv4 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv4 +DDSTestWAN.end_to_end_discovery_server_WAN_communication_TLSv6 +DDSTestWAN.end_to_end_initial_peers_WAN_communication_TLSv6 DDSTestWAN.end_to_end_discovery_server_WAN_communication_high_throughput +DDSTestWAN.end_to_end_initial_peers_WAN_communication_high_throughput +ImplementationsTest.pair_implementation +ImplementationsTest.pair_implementation_with_topic +ImplementationsTest.all_implementations +ImplementationsTest.duplicated_ids_negative diff --git a/ddsrouter_yaml/CMakeLists.txt b/ddsrouter_yaml/CMakeLists.txt index 82b5e3690..0965da882 100644 --- a/ddsrouter_yaml/CMakeLists.txt +++ b/ddsrouter_yaml/CMakeLists.txt @@ -70,9 +70,9 @@ compile_library( # Test ############################################################################### # Compile tests if CMake options requires it -# compile_test_library( -# "${PROJECT_SOURCE_DIR}/test" # Test directory -# ) +compile_test_library( + "${PROJECT_SOURCE_DIR}/test" # Test directory +) ############################################################################### # Packaging diff --git a/ddsrouter_yaml/test/unittest/CMakeLists.txt b/ddsrouter_yaml/test/unittest/CMakeLists.txt index 8341c4bad..28d16b1d0 100644 --- a/ddsrouter_yaml/test/unittest/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/CMakeLists.txt @@ -16,6 +16,6 @@ # Yaml Tests # ############## -# TODO uncomment when ready +# TODO uncomment when new API applied # add_subdirectory(configuration) # add_subdirectory(participants) diff --git a/tools/ddsrouter_tool/test/CMakeLists.txt b/tools/ddsrouter_tool/test/CMakeLists.txt index 009e832d1..0c91f7704 100644 --- a/tools/ddsrouter_tool/test/CMakeLists.txt +++ b/tools/ddsrouter_tool/test/CMakeLists.txt @@ -12,5 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Add subdirectory with labels for tests +add_subdirectory(labels) + # Add subdirectory with tests add_subdirectory(application) diff --git a/tools/ddsrouter_tool/test/labels/CMakeLists.txt b/tools/ddsrouter_tool/test/labels/CMakeLists.txt new file mode 100644 index 000000000..17e16bc1f --- /dev/null +++ b/tools/ddsrouter_tool/test/labels/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2022 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. + +# Set list of tests that can fail using TSAN +set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XTSAN.list "xtsan") diff --git a/tools/ddsrouter_tool/test/labels/XTSAN.list b/tools/ddsrouter_tool/test/labels/XTSAN.list new file mode 100644 index 000000000..5b24a583c --- /dev/null +++ b/tools/ddsrouter_tool/test/labels/XTSAN.list @@ -0,0 +1,8 @@ +tool.application.ddsrouter.simple_configuration.sigint +tool.application.ddsrouter.simple_configuration.sigint.sigterm +tool.application.ddsrouter.ds_configuration.sigint +tool.application.ddsrouter.ds_configuration.sigint.sigterm +tool.application.ddsrouter.complex_configuration_v3.sigint +tool.application.ddsrouter.complex_configuration_v3.sigint.sigterm +tool.application.ddsrouter.wan_configuration.sigint +tool.application.ddsrouter.wan_configuration.sigint.sigterm From c0e42cd1cf9077868209efd5c63f3bb58617d477 Mon Sep 17 00:00:00 2001 From: jparisu Date: Fri, 26 May 2023 10:34:36 +0200 Subject: [PATCH 32/38] fix uncrustify in github actions Signed-off-by: jparisu --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 432a3a6f1..e8793c79c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -# Main CI + # Main CI # This is executed: # - every PullRequest (new or update) # - every merge in main @@ -276,7 +276,7 @@ jobs: steps: - name: Uncrustify - uses: eProsima/eProsima-CI/ubuntu-22.04/uncrustify@v0 + uses: eProsima/eProsima-CI/ubuntu/uncrustify@v0 ##################################################################### From 36abaa17e139cabb9a8395af449ee6d8875c8148 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 30 May 2023 08:49:59 +0200 Subject: [PATCH 33/38] apply suggestions Signed-off-by: jparisu --- .../actions/project_dependencies/action.yml | 4 +- .../configuration/SpecsConfiguration.hpp | 2 +- .../ddsrouter_core/testing/random_values.hpp | 2 +- ddsrouter_core/package.xml | 2 + ddsrouter_core/test/blackbox/CMakeLists.txt | 1 - .../dds/local/DDSTestLocalDisposeKey.cpp | 3 -- .../blackbox/implementations/CMakeLists.txt | 2 - ddsrouter_yaml/README.md | 54 +------------------ tools/ddsrouter_tool/package.xml | 3 ++ 9 files changed, 10 insertions(+), 63 deletions(-) diff --git a/.github/actions/project_dependencies/action.yml b/.github/actions/project_dependencies/action.yml index b76f840b5..f1cffc74d 100644 --- a/.github/actions/project_dependencies/action.yml +++ b/.github/actions/project_dependencies/action.yml @@ -1,5 +1,5 @@ -name: fastddsspy_dependencies_ubuntu -description: Common first step for all Fast DDS Spy jobs. Checkout repository, download dependencies and install required packages. +name: ddsrouter_dependencies_ubuntu +description: Common first step for all jobs. Checkout repository, download dependencies and install required packages. inputs: diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index 35841647b..41dd6333f 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -10,7 +10,7 @@ // 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\. +// limitations under the License. #pragma once diff --git a/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp b/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp index 02d4d23fd..b1044790c 100644 --- a/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp +++ b/ddsrouter_core/include/ddsrouter_core/testing/random_values.hpp @@ -10,7 +10,7 @@ // 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\. +// limitations under the License. #pragma once diff --git a/ddsrouter_core/package.xml b/ddsrouter_core/package.xml index 8607d6f47..7354eacfa 100644 --- a/ddsrouter_core/package.xml +++ b/ddsrouter_core/package.xml @@ -18,6 +18,8 @@ cmake cmake_utils + cpp_utils + ddspipe_core ddspipe_participants doxygen diff --git a/ddsrouter_core/test/blackbox/CMakeLists.txt b/ddsrouter_core/test/blackbox/CMakeLists.txt index 5e58868df..447c81e4e 100644 --- a/ddsrouter_core/test/blackbox/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/CMakeLists.txt @@ -12,6 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO uncomment when ready add_subdirectory(ddsrouter_core) add_subdirectory(implementations) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp index cda404c13..3461003fd 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp @@ -165,9 +165,6 @@ void test_local_communication_key_dispose( } /* namespace test */ -using namespace eprosima::ddsrouter::core; -using namespace eprosima::ddsrouter::core::types; - /** * Test that dispose values from the publisher are correctly received by the subscriber from the router. */ diff --git a/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt b/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt index 0fade3568..6b283e469 100644 --- a/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/implementations/CMakeLists.txt @@ -39,5 +39,3 @@ add_blackbox_executable( "${TEST_LIST}" "${TEST_NEEDED_SOURCES}" ) - -# add_test_label_from_file(${CMAKE_CURRENT_SOURCE_DIR}/../../TEST_XTSAN.list "xtsan") diff --git a/ddsrouter_yaml/README.md b/ddsrouter_yaml/README.md index 888108996..53c9e0a3b 100644 --- a/ddsrouter_yaml/README.md +++ b/ddsrouter_yaml/README.md @@ -1,55 +1,3 @@ -# eProsima DDS Router Core Library +# eProsima DDS Router Yaml Library > TODO - -This library contain main functionality of the DDS Router. -Include module is the public API used to configure a DDS Router and to interact with a running one: - -* **Types**: data types used to configure a router. - * Address - * DDS info (Guid, Qos, Topic, etc.) - -* **Configuration**: configuration objects that contains the information needed for a DDS Router. Are divided in: - * *ParticipantConfiguration*: configuration for each participant inside the DDS Router. - * *DdsRouterConfiguration*: configuration to execute a DDS Router, with its Participants and allowed lists. - * *DdsRouterReloadConfiguration*: configuration to change topics in a running DDS Router. - -* **Core**: it only contains the proxy of DDS Router class, which implementation is inside private modules. - It allows to execute a DDS Router, and to interact with it while running. - ---- - -## Example of usage - -```cpp -// START AND STOP DDS ROUTER FROM CONFIGURATION - -core::DdsRouterConfiguration router_configuration; - -// ... populate router_configuration - -core::DdsRouter router(router_configuration); -router.start(); - -// ... wait for event - -router.stop(); -``` - ---- - -## Dependencies - -* `fastrtps` -* `cpp_utils` - ---- - -## How to use it in your project - -Just import library `ddsrouter_core` into your CMake project. - -```cmake -find_package(ddsrouter_core) -target_link_libraries(${LIBRARY_TARGET_NAME} ddsrouter_core) -``` diff --git a/tools/ddsrouter_tool/package.xml b/tools/ddsrouter_tool/package.xml index 0fd8d9d7c..b041bd5f1 100644 --- a/tools/ddsrouter_tool/package.xml +++ b/tools/ddsrouter_tool/package.xml @@ -17,7 +17,10 @@ cmake + cmake_utils + cpp_utils ddsrouter_yaml + ddsrouter_core doxygen From 184bcdc03504de33188ec976811f0856005cdbbf Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 30 May 2023 09:01:07 +0200 Subject: [PATCH 34/38] Add documentation Signed-off-by: jparisu --- README.md | 2 +- .../installation/sources/linux.rst | 26 +++++++++++++++++ .../installation/sources/windows.rst | 28 +++++++++++++++++++ docs/rst/notes/forthcoming_version.rst | 10 ++++++- docs/rst/notes/notes.rst | 2 +- 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ade962448..54914b595 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ vcs import src < ddsrouter.repos 2. Build the packages: ```bash -colcon build +colcon build --packages-select-regex ddsrouter ``` This repository holds several colcon packages. diff --git a/docs/rst/developer_manual/installation/sources/linux.rst b/docs/rst/developer_manual/installation/sources/linux.rst index b8ba2f32a..23c6833fb 100644 --- a/docs/rst/developer_manual/installation/sources/linux.rst +++ b/docs/rst/developer_manual/installation/sources/linux.rst @@ -317,6 +317,32 @@ Local installation cmake ~/DDS-Router/src/dev-utils/cpp_utils -DCMAKE_INSTALL_PREFIX=~/DDS-Router/install -DCMAKE_PREFIX_PATH=~/DDS-Router/install cmake --build . --target install + * `DDS Pipe `_ + + .. code-block:: bash + + # ddspipe_core + cd ~/DDS-Router + mkdir build/ddspipe_core + cd build/ddspipe_core + cmake ~/DDS-Router/src/ddspipe/ddspipe_core -DCMAKE_INSTALL_PREFIX=~/DDS-Router/install -DCMAKE_PREFIX_PATH=~/DDS-Router/install + cmake --build . --target install + + # ddspipe_participants + cd ~/DDS-Router + mkdir build/ddspipe_participants + cd build/ddspipe_participants + cmake ~/DDS-Router/src/ddspipe/ddspipe_participants -DCMAKE_INSTALL_PREFIX=~/DDS-Router/install -DCMAKE_PREFIX_PATH=~/DDS-Router/install + cmake --build . --target install + + # ddspipe_yaml + cd ~/DDS-Router + mkdir build/ddspipe_yaml + cd build/ddspipe_yaml + cmake ~/DDS-Router/src/ddspipe/ddspipe_yaml -DCMAKE_INSTALL_PREFIX=~/DDS-Router/install -DCMAKE_PREFIX_PATH=~/DDS-Router/install + cmake --build . --target install + + #. Once all dependencies are installed, install |ddsrouter|: .. code-block:: bash diff --git a/docs/rst/developer_manual/installation/sources/windows.rst b/docs/rst/developer_manual/installation/sources/windows.rst index 8c0b7f694..df7563918 100644 --- a/docs/rst/developer_manual/installation/sources/windows.rst +++ b/docs/rst/developer_manual/installation/sources/windows.rst @@ -363,6 +363,34 @@ Local installation -DCMAKE_PREFIX_PATH=\DDS-Router\install cmake --build . --config Release --target install + * `DDS Pipe `_ + + .. code-block:: bash + + # ddspipe_core + cd \DDS-Router + mkdir build\ddspipe_core + cd build\ddspipe_core + cmake \DDS-Router\src\ddspipe\ddspipe_core -DCMAKE_INSTALL_PREFIX=\DDS-Router\install ^ + -DCMAKE_PREFIX_PATH=\DDS-Router\install + cmake --build . --config Release --target install + + # ddspipe_participants + cd \DDS-Router + mkdir build\ddspipe_participants + cd build\ddspipe_participants + cmake \DDS-Router\src\ddspipe\ddspipe_participants -DCMAKE_INSTALL_PREFIX=\DDS-Router\install ^ + -DCMAKE_PREFIX_PATH=\DDS-Router\install + cmake --build . --config Release --target install + + # ddspipe_yaml + cd \DDS-Router + mkdir build\ddspipe_yaml + cd build\ddspipe_yaml + cmake \DDS-Router\src\ddspipe\ddspipe_yaml -DCMAKE_INSTALL_PREFIX=\DDS-Router\install ^ + -DCMAKE_PREFIX_PATH=\DDS-Router\install + cmake --build . --config Release --target install + #. Once all dependencies are installed, install |ddsrouter|: .. code-block:: bash diff --git a/docs/rst/notes/forthcoming_version.rst b/docs/rst/notes/forthcoming_version.rst index 676dcc54c..1657442d4 100644 --- a/docs/rst/notes/forthcoming_version.rst +++ b/docs/rst/notes/forthcoming_version.rst @@ -1,7 +1,15 @@ .. add orphan tag when new info added to this file -:orphan: +.. :orphan: ################### Forthcoming Version ################### + +This release adds new **requirements**: + +* `DDS Pipe ` project. + +This release has the **major implementation changes**: + +* Main functionality has been moved to new repository `DDS Pipe ` to reuse it in other projects. diff --git a/docs/rst/notes/notes.rst b/docs/rst/notes/notes.rst index add10fe6b..7a5671e11 100644 --- a/docs/rst/notes/notes.rst +++ b/docs/rst/notes/notes.rst @@ -4,7 +4,7 @@ .. comment the include of forthcoming when new info is added -.. .. include:: forthcoming_version.rst +.. include:: forthcoming_version.rst ############## Version v1.2.0 From 29f79f14a00e2fe415fc3bf96298105d31d0eefd Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 5 Jun 2023 15:51:09 +0200 Subject: [PATCH 35/38] apply suggestions Signed-off-by: jparisu --- docs/rst/notes/forthcoming_version.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rst/notes/forthcoming_version.rst b/docs/rst/notes/forthcoming_version.rst index 1657442d4..38ce76738 100644 --- a/docs/rst/notes/forthcoming_version.rst +++ b/docs/rst/notes/forthcoming_version.rst @@ -10,6 +10,6 @@ This release adds new **requirements**: * `DDS Pipe ` project. -This release has the **major implementation changes**: +This release has the following **major implementation changes**: * Main functionality has been moved to new repository `DDS Pipe ` to reuse it in other projects. From a42876742c47a6d7be0caf943d5090eba8a904cf Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 5 Jun 2023 15:53:53 +0200 Subject: [PATCH 36/38] uncrustify Signed-off-by: jparisu --- .../configuration/DdsRouterConfiguration.hpp | 5 +- .../ddsrouter_core/types/ParticipantKind.hpp | 16 ++--- .../configuration/DdsRouterConfiguration.cpp | 4 +- ddsrouter_core/src/cpp/core/DdsRouter.cpp | 15 ++-- .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 20 +++--- .../dds/repeater/DDSTestRepeater.cpp | 6 +- .../implementations/ImplementationsTest.cpp | 70 +++++++++---------- .../src/cpp/YamlReaderConfiguration.cpp | 9 +-- .../src/cpp/YamlReader_configuration.cpp | 29 ++++---- .../YamlGetConfigurationDdsRouterTest.cpp | 9 ++- 10 files changed, 99 insertions(+), 84 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp index a9a5d4e62..527ea0966 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DdsRouterConfiguration.hpp @@ -71,7 +71,7 @@ struct DdsRouterConfiguration : public DdsRouterReloadConfiguration types::ParticipantKind, std::shared_ptr< ddspipe::participants::ParticipantConfiguration>>> - participants_configurations {}; + participants_configurations {}; //! Advanced configurations SpecsConfiguration advanced_options {}; @@ -80,7 +80,8 @@ struct DdsRouterConfiguration : public DdsRouterReloadConfiguration //! Auxiliar method to validate that class type of the participants are compatible with their kinds. static bool check_correct_configuration_object_( - const std::pair> configuration); + const std::pair> configuration); }; diff --git a/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp b/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp index 620ab1321..d04f454ce 100644 --- a/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp +++ b/ddsrouter_core/include/ddsrouter_core/types/ParticipantKind.hpp @@ -28,18 +28,18 @@ ENUMERATION_BUILDER( initial_peers, discovery_server, echo -); + ); eProsima_ENUMERATION_BUILDER( ParticipantKindBuilder, ParticipantKind, - { - { ParticipantKind::simple COMMA { "local" COMMA "simple" } } COMMA - { ParticipantKind::initial_peers COMMA {"wan" COMMA "router" COMMA "initial-peers"} } COMMA - { ParticipantKind::discovery_server COMMA {"discovery-server" COMMA "ds" COMMA "local-ds" COMMA "local-discovery-server" COMMA "wan-ds" COMMA "wan-discovery-server"} } COMMA - { ParticipantKind::echo COMMA {"echo"} } - } -); + { + { ParticipantKind::simple COMMA { "local" COMMA "simple" } } COMMA + { ParticipantKind::initial_peers COMMA {"wan" COMMA "router" COMMA "initial-peers"} } COMMA + { ParticipantKind::discovery_server COMMA {"discovery-server" COMMA "ds" COMMA "local-ds" COMMA "local-discovery-server" COMMA "wan-ds" COMMA "wan-discovery-server"} } COMMA + { ParticipantKind::echo COMMA {"echo"} } + } + ); } /* namespace types */ } /* namespace core */ diff --git a/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp index b4fe63c50..7a3939b77 100644 --- a/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DdsRouterConfiguration.cpp @@ -79,7 +79,9 @@ bool DdsRouterConfiguration::is_valid( // Check that the configuration is of type required if (!check_correct_configuration_object_(configuration)) { - error_msg << "Participant " << configuration.second->id << " is not of correct Configuration class " << configuration.first << "."; + error_msg + << "Participant " << configuration.second->id + << " is not of correct Configuration class " << configuration.first << "."; return false; } diff --git a/ddsrouter_core/src/cpp/core/DdsRouter.cpp b/ddsrouter_core/src/cpp/core/DdsRouter.cpp index 25b3f9134..f409d1ffe 100644 --- a/ddsrouter_core/src/cpp/core/DdsRouter.cpp +++ b/ddsrouter_core/src/cpp/core/DdsRouter.cpp @@ -63,12 +63,12 @@ DdsRouter::DdsRouter( init_participants_(); ddspipe_ = std::unique_ptr(new ddspipe::core::DdsPipe( - allowed_topics_, - discovery_database_, - payload_pool_, - participants_database_, - thread_pool_, - configuration_.builtin_topics)); + allowed_topics_, + discovery_database_, + payload_pool_, + participants_database_, + thread_pool_, + configuration_.builtin_topics)); logDebug(DDSROUTER, "DDS Router created."); } @@ -84,7 +84,8 @@ void DdsRouter::init_allowed_topics_() void DdsRouter::init_participants_() { - for (std::pair> participant_config : + for (std::pair> participant_config : configuration_.participants_configurations) { std::shared_ptr new_participant = diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp index 92b44f880..00a842616 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -104,14 +104,14 @@ discovery_server_participant_configuration( conf.connection_addresses.insert( participants::types::DiscoveryServerConnectionAddress( core::types::GuidPrefix((this_server_id_is_1 ? 0u : 1u)), - { - participants::types::Address( - (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), - 11666 + (this_server_id_is_1 ? 0u : 1u), - 11666 + (this_server_id_is_1 ? 0u : 1u), - ip_version, - transport_protocol) - } + { + participants::types::Address( + (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), + 11666 + (this_server_id_is_1 ? 0u : 1u), + 11666 + (this_server_id_is_1 ? 0u : 1u), + ip_version, + transport_protocol) + } ) ); } @@ -164,7 +164,7 @@ initial_peers_participant_configuration( 11666 + (this_server_id_is_1 ? 0u : 1u), ip_version, transport_protocol) - ); + ); } if (is_server(wan_kind)) @@ -228,7 +228,7 @@ DdsRouterConfiguration router_configuration( std::pair< types::ParticipantKind, std::shared_ptr> - participant_configuration, + participant_configuration, core::types::DomainIdType domain) { DdsRouterConfiguration conf; diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp index 7243dbad0..a8e910098 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/DDSTestRepeater.cpp @@ -50,7 +50,9 @@ initial_peers_participant_configuration_client( { auto conf = std::make_shared(); - conf->id = core::types::ParticipantId("InitialPeersParticipant_Client_" + std::to_string((this_server_id_is_1 ? 1 : 0))); + conf->id = + core::types::ParticipantId("InitialPeersParticipant_Client_" + + std::to_string((this_server_id_is_1 ? 1 : 0))); conf->connection_addresses.insert( participants::types::Address( (ip_version == participants::types::IpVersion::v4 ? "127.0.0.1" : "::1"), @@ -118,7 +120,7 @@ DdsRouterConfiguration router_configuration( std::pair< types::ParticipantKind, std::shared_ptr> - participant_configuration, + participant_configuration, core::types::DomainIdType domain, bool has_simple = true) { diff --git a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp index a52b6b7ea..4bcf0cbfb 100644 --- a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp +++ b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp @@ -61,17 +61,17 @@ TEST(ImplementationsTest, pair_implementation) // Generate configuration DdsRouterConfiguration configuration; configuration.participants_configurations.insert( - { - kind, - random_participant_configuration(kind, 0) - } - ); + { + kind, + random_participant_configuration(kind, 0) + } + ); configuration.participants_configurations.insert( - { - kind, - random_participant_configuration(kind, 1) - } - ); + { + kind, + random_participant_configuration(kind, 1) + } + ); // Create DdsRouter entity DdsRouter router(configuration); @@ -108,17 +108,17 @@ TEST(ImplementationsTest, pair_implementation_with_topic) // Generate configuration DdsRouterConfiguration configuration; configuration.participants_configurations.insert( - { - kind, - random_participant_configuration(kind, 0) - } - ); + { + kind, + random_participant_configuration(kind, 0) + } + ); configuration.participants_configurations.insert( - { - kind, - random_participant_configuration(kind, 1) - } - ); + { + kind, + random_participant_configuration(kind, 1) + } + ); // Add topic eprosima::ddspipe::core::types::DdsTopic topic; @@ -165,11 +165,11 @@ TEST(ImplementationsTest, all_implementations) { // Add participant configuration.participants_configurations.insert( - { - kind, - random_participant_configuration(kind, participant_number++) - } - ); + { + kind, + random_participant_configuration(kind, participant_number++) + } + ); } // Create DdsRouter entity @@ -195,17 +195,17 @@ TEST(ImplementationsTest, duplicated_ids_negative) { DdsRouterConfiguration configuration; configuration.participants_configurations.insert( - { - ParticipantKind::simple, - random_participant_configuration(ParticipantKind::simple, 0) - } - ); + { + ParticipantKind::simple, + random_participant_configuration(ParticipantKind::simple, 0) + } + ); configuration.participants_configurations.insert( - { - ParticipantKind::simple, - random_participant_configuration(ParticipantKind::simple, 0) - } - ); + { + ParticipantKind::simple, + random_participant_configuration(ParticipantKind::simple, 0) + } + ); // Create DdsRouter entity ASSERT_THROW(DdsRouter router(configuration), eprosima::utils::ConfigurationException); diff --git a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp index dd0de849d..979fd1634 100644 --- a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp @@ -35,7 +35,8 @@ YamlReaderConfiguration::load_ddsrouter_configuration( // Get version if present if (ddspipe::yaml::YamlReader::is_tag_present(yml, ddspipe::yaml::VERSION_TAG)) { - version = ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::VERSION_TAG, ddspipe::yaml::LATEST); + version = ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::VERSION_TAG, + ddspipe::yaml::LATEST); } else { @@ -87,6 +88,6 @@ ddspipe::yaml::YamlReaderVersion YamlReaderConfiguration::default_yaml_version() return ddspipe::yaml::V_3_0; } -} -} -} +} // namespace yaml +} // namespace ddsrouter +} // namespace eprosima diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index 75df69090..0de32a929 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -58,7 +58,8 @@ ddsrouter::core::types::ParticipantKind YamlReader::get( const YamlReaderVersion /* version */) { // Domain id required - return get_enumeration_from_builder(yml, *ddsrouter::core::types::ParticipantKindBuilder::get_instance()); + return get_enumeration_from_builder(yml, + *ddsrouter::core::types::ParticipantKindBuilder::get_instance()); } template <> @@ -68,7 +69,9 @@ YamlReader::get>( const YamlReaderVersion version) { // Kind required - ddsrouter::core::types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); + ddsrouter::core::types::ParticipantKind kind = YamlReader::get(yml, + PARTICIPANT_KIND_TAG, + version); logInfo(DDSROUTER_YAML_CONFIGURATION, "Loading Participant of kind " << kind << "."); @@ -131,7 +134,9 @@ void YamlReader::fill( // Get optional builtin topics if (YamlReader::is_tag_present(yml, BUILTIN_TAG)) { - object.builtin_topics = YamlReader::get_set>(yml, BUILTIN_TAG, version); + object.builtin_topics = YamlReader::get_set>(yml, + BUILTIN_TAG, + version); } ///// @@ -151,13 +156,13 @@ void YamlReader::fill( for (auto conf : participants_configurations_yml) { ddsrouter::core::types::ParticipantKind kind = - YamlReader::get(conf, PARTICIPANT_KIND_TAG, version); + YamlReader::get(conf, PARTICIPANT_KIND_TAG, version); object.participants_configurations.insert( - { - kind, - YamlReader::get>(conf, version) - } - ); + { + kind, + YamlReader::get>(conf, version) + } + ); } ///// @@ -181,6 +186,6 @@ ddsrouter::core::DdsRouterConfiguration YamlReader::get ds_participant = - std::dynamic_pointer_cast(participant); + std::dynamic_pointer_cast( + participant); // Check Name ASSERT_EQ(ds_participant->id, ddspipe::core::types::ParticipantId("participant2")); @@ -294,12 +295,14 @@ TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_discovery_se ASSERT_EQ( ds_participant->connection_addresses.size(), 1u); - ddspipe::participants::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses.begin(); + ddspipe::participants::types::DiscoveryServerConnectionAddress address = + *ds_participant->connection_addresses.begin(); ASSERT_EQ( address, (ddspipe::participants::types::DiscoveryServerConnectionAddress( ddspipe::core::types::GuidPrefix("01.0f.00.00.00.00.00.00.00.00.00.00"), - {ddspipe::participants::types::Address("127.0.0.1", 3333, 3333, ddspipe::participants::types::Address::default_transport_protocol())} + {ddspipe::participants::types::Address("127.0.0.1", 3333, 3333, + ddspipe::participants::types::Address::default_transport_protocol())} )) ); } From 6f5965468d96908df528ead918456970984973a6 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 6 Jun 2023 12:34:36 +0200 Subject: [PATCH 37/38] Modify documentation regarding keys in topics Signed-off-by: jparisu --- docs/rst/user_manual/configuration.rst | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/rst/user_manual/configuration.rst b/docs/rst/user_manual/configuration.rst index 5f1a0db32..15c8dcc34 100644 --- a/docs/rst/user_manual/configuration.rst +++ b/docs/rst/user_manual/configuration.rst @@ -134,8 +134,8 @@ Apart from these values, the tag ``qos`` under each topic allows to configure th * - History Depth - ``depth`` - *integer* - - *default value* - - - + - :ref:`history_depth_configuration` + - Writers and Readers History Depth * - Partitions - ``partitions`` @@ -149,6 +149,15 @@ Apart from these values, the tag ``qos`` under each topic allows to configure th - ``false`` - ``EXCLUSIVE_OWNERSHIP_QOS`` / ``SHARED_OWNERSHIP_QOS`` + * - Key + - ``keyed`` + - *bool* + - ``false`` + - Topic with / without key + +The entry ``keyed`` determines whether the corresponding topic is `keyed `_ +or not. See :term:`Topic` section for further information about the topic. + .. code-block:: yaml @@ -161,6 +170,7 @@ Apart from these values, the tag ``qos`` under each topic allows to configure th depth: 100 # Use History Depth 100 partitions: true # Topic with partitions ownership: false # Use QoS SHARED_OWNERSHIP_QOS + keyed: false # Topic without keys Topic Filtering @@ -192,7 +202,7 @@ To define these data filtering rules based on the Topics to which they belong, t These three lists of topics listed above are defined by a tag in the *YAML* configuration file, which defines a *YAML* vector (``[]``). This vector contains the list of topics for each filtering rule. -Each Topic is determined by its entries ``name``, ``type`` and ``keyed``, with only the first one being mandatory. +Each Topic is determined by its entries ``name`` and ``type``, with only the first one being mandatory. .. list-table:: :header-rows: 1 @@ -209,13 +219,6 @@ Each Topic is determined by its entries ``name``, ``type`` and ``keyed``, with o - ``string`` - ``"*"`` - * - ``keyed`` - - ``bool`` - - Both ``true`` and ``false`` - -The entry ``keyed`` determines whether the corresponding topic is `keyed `_ -or not. See :term:`Topic` section for further information about the topic. - .. note:: Tags ``allowlist``, ``blocklist`` and ``builtin-topics`` must be at yaml base level (it must not be inside any From 8d7ed6b49a29b42086ff10ce5a377afa0fe9ac3e Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Lizano Date: Tue, 6 Jun 2023 16:58:31 +0200 Subject: [PATCH 38/38] Refactor ddsrouter_yaml tests (#376) * Refactor ddsrouter_yaml tests Signed-off-by: Raul Sanchez-Mateos * Apply suggested changes Signed-off-by: Raul Sanchez-Mateos * Fix windows build Signed-off-by: Raul Sanchez-Mateos --------- Signed-off-by: Raul Sanchez-Mateos --- .../ddsrouter_yaml/testing/generate_yaml.hpp | 43 ++++ .../src/cpp/YamlReaderConfiguration.cpp | 9 +- ddsrouter_yaml/test/unittest/CMakeLists.txt | 4 +- .../test/unittest/TestUtils/test_utils.hpp | 29 +++ .../unittest/configuration/CMakeLists.txt | 8 +- .../YamlGetConfigurationDdsRouterTest.cpp | 226 ++---------------- .../YamlReaderConfigurationTest.cpp | 117 +++------ .../test/unittest/participants/CMakeLists.txt | 31 ++- ...lGetCommonParticipantConfigurationTest.cpp | 68 ++---- ...itialPeersParticipantConfigurationTest.cpp | 82 ++++--- ...lGetSimpleParticipantConfigurationTest.cpp | 60 ++--- ...t_get_participant_connection_addresses.ipp | 194 ++++++++------- ...nfigurationTest_get_participant_domain.ipp | 42 ++-- ...st_get_participant_listening_addresses.ipp | 93 +++---- ...figurationTest_get_participant_minimum.ipp | 40 ++-- ...igurationTest_get_participant_negative.ipp | 52 ++-- ...tConfigurationTest_get_participant_tls.ipp | 112 ++++----- docs/rst/user_manual/configuration.rst | 13 +- 18 files changed, 545 insertions(+), 678 deletions(-) create mode 100644 ddsrouter_yaml/include/ddsrouter_yaml/testing/generate_yaml.hpp create mode 100644 ddsrouter_yaml/test/unittest/TestUtils/test_utils.hpp diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/testing/generate_yaml.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/testing/generate_yaml.hpp new file mode 100644 index 000000000..ebb71ed95 --- /dev/null +++ b/ddsrouter_yaml/include/ddsrouter_yaml/testing/generate_yaml.hpp @@ -0,0 +1,43 @@ +// 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. + +#pragma once + +#include + +#include +#include +#include + +#include + +namespace eprosima { +namespace ddsrouter { +namespace yaml { +namespace testing { + +void participantkind_to_yaml( + Yaml& yml, + const ddsrouter::core::types::ParticipantKind& kind) +{ + ddspipe::yaml::testing::add_field_to_yaml( + yml, + ddspipe::yaml::testing::YamlField(to_string(kind)), + ddspipe::yaml::PARTICIPANT_KIND_TAG); +} + +} /* namespace testing */ +} /* namespace yaml */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp index 979fd1634..7a2a2932c 100644 --- a/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp @@ -36,7 +36,14 @@ YamlReaderConfiguration::load_ddsrouter_configuration( if (ddspipe::yaml::YamlReader::is_tag_present(yml, ddspipe::yaml::VERSION_TAG)) { version = ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::VERSION_TAG, - ddspipe::yaml::LATEST); + ddspipe::yaml::YamlReaderVersion::LATEST); + + if (version == ddspipe::yaml::YamlReaderVersion::V_1_0) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << + "Yaml configuration v1.0 not supported. Please update to latest available version."); + } } else { diff --git a/ddsrouter_yaml/test/unittest/CMakeLists.txt b/ddsrouter_yaml/test/unittest/CMakeLists.txt index 28d16b1d0..38cbace2d 100644 --- a/ddsrouter_yaml/test/unittest/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/CMakeLists.txt @@ -17,5 +17,5 @@ ############## # TODO uncomment when new API applied -# add_subdirectory(configuration) -# add_subdirectory(participants) +add_subdirectory(configuration) +add_subdirectory(participants) diff --git a/ddsrouter_yaml/test/unittest/TestUtils/test_utils.hpp b/ddsrouter_yaml/test/unittest/TestUtils/test_utils.hpp new file mode 100644 index 000000000..0c931843b --- /dev/null +++ b/ddsrouter_yaml/test/unittest/TestUtils/test_utils.hpp @@ -0,0 +1,29 @@ +// 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. + +#pragma once + +#include + +namespace eprosima { +namespace ddsrouter { +namespace yaml { +namespace testing { + +constexpr const uint32_t TEST_ITERATIONS = 10; + +} /* namespace testing */ +} /* namespace yaml */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ diff --git a/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt b/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt index 092033df7..629f0317c 100644 --- a/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt @@ -21,10 +21,11 @@ set(TEST_NAME YamlReaderConfigurationTest) set(TEST_SOURCES YamlReaderConfigurationTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_configuration.cpp ) set(TEST_LIST - get_ddsrouter_configuration_v1 + ddsrouter_configuration_v1_not_supported get_ddsrouter_configuration_v2 get_ddsrouter_configuration_no_version version_negative_cases @@ -58,15 +59,12 @@ set(TEST_NAME YamlGetConfigurationDdsRouterTest) set(TEST_SOURCES YamlGetConfigurationDdsRouterTest.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_configuration.cpp ) set(TEST_LIST get_ddsrouter_configuration_trivial get_ddsrouter_configuration_ros_case - - get_ddsrouter_configuration_trivial_v1 - get_ddsrouter_configuration_builtin_v1 - get_ddsrouter_configuration_discovery_server_v1 ) set(TEST_EXTRA_LIBRARIES diff --git a/ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp index c624a774e..47bab0cda 100644 --- a/ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlGetConfigurationDdsRouterTest.cpp @@ -13,16 +13,22 @@ // limitations under the License. #include +#include #include #include -#include +#include + #include #include #include +#include + +#include + using namespace eprosima; /** @@ -45,26 +51,28 @@ TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_trivial) // Load configuration ddsrouter::core::DdsRouterConfiguration configuration_result = - ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::LATEST); + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is valid utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, + std::set>()); // Check Participant configurations - std::set> + std::set>> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 2u); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::echo); + ASSERT_EQ(participant.first, ddsrouter::core::types::ParticipantKind::echo); } } @@ -96,216 +104,34 @@ TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_ros_case) // Load configuration ddsrouter::core::DdsRouterConfiguration configuration_result = - ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_2_0); + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check is valid utils::Formatter error_msg; ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topic lists are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics; - ASSERT_EQ(builtin_result.size(), 1u); - std::shared_ptr topic_result = (*builtin_result.begin()); - ASSERT_EQ(topic_result->topic_name, "rt/chatter"); + ASSERT_EQ(configuration_result.builtin_topics.size(), 1u); + utils::Heritable topic_result = (*configuration_result.builtin_topics.begin()); + ASSERT_EQ(topic_result->topic_name(), "rt/chatter"); ASSERT_EQ(topic_result->type_name, "std_msgs::msg::dds_::String_"); - ASSERT_EQ(topic_result->keyed, false); - ASSERT_EQ(topic_result->topic_qos.get_reference().is_reliable(), false); + ASSERT_EQ(topic_result->topic_qos.keyed, false); + ASSERT_EQ(topic_result->topic_qos.is_reliable(), false); // Check Participant configurations - std::set> + std::set>> participant_configurations = configuration_result.participants_configurations; ASSERT_EQ(participant_configurations.size(), 3u); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::simple_rtps); - } -} - -/** - * Test load a whole DDS Router Configuration from yaml node. - * Only set two echo participants. - */ -TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_trivial_v1) -{ - const char* yml_str = - R"( - version: v1.0 - participant1: - type: "echo" - participant2: - type: "echo" - )"; - - Yaml yml = YAML::Load(yml_str); - - // Load configuration - ddsrouter::core::DdsRouterConfiguration configuration_result = - ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_1_0); - - // Check is valid - utils::Formatter error_msg; - ASSERT_TRUE(configuration_result.is_valid(error_msg)); - - // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics, std::set>()); - - // Check Participant configurations - std::set> - participant_configurations = configuration_result.participants_configurations; - - ASSERT_EQ(participant_configurations.size(), 2u); - - for (auto participant : participant_configurations) - { - ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::echo); - } -} - -/** - * Test load a whole DDS Router Configuration from yaml node. - * Only set two echo participants. - */ -TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_builtin_v1) -{ - const char* yml_str = - R"( - version: v1.0 - allowlist: - - name: "topic1" - type: "type1" - - name: "topic2" - type: "*" - participant1: - type: "echo" - participant2: - type: "echo" - )"; - - Yaml yml = YAML::Load(yml_str); - - // Load configuration - ddsrouter::core::DdsRouterConfiguration configuration_result = - ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_1_0); - - // Check is valid - utils::Formatter error_msg; - ASSERT_TRUE(configuration_result.is_valid(error_msg)); - - // Check block Topics are empty - ASSERT_EQ(configuration_result.blocklist, std::set>()); - - // Check allowlist has 2 topics - std::set> allowlist_result = configuration_result.allowlist; - ASSERT_EQ(allowlist_result.size(), 2u); - - // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics; - ASSERT_EQ(builtin_result.size(), 1u); - std::shared_ptr topic_result = (*builtin_result.begin()); - ASSERT_EQ(topic_result->topic_name, "topic1"); - ASSERT_EQ(topic_result->type_name, "type1"); - ASSERT_EQ(topic_result->keyed, false); - - // Check Participant configurations - std::set> - participant_configurations = configuration_result.participants_configurations; - - ASSERT_EQ(participant_configurations.size(), 2u); - - for (auto participant : participant_configurations) - { - ASSERT_EQ(participant->kind, ddsrouter::core::types::ParticipantKind::echo); - } -} - -/** - * Test load a whole DDS Router Configuration from yaml node. - * Only set two echo participants. - */ -TEST(YamlGetConfigurationDdsRouterTest, get_ddsrouter_configuration_discovery_server_v1) -{ - const char* yml_str = - R"( - version: v1.0 - participant1: - type: "echo" - participant2: - type: "discovery-server" - id: 3 - ros-discovery-server: true - connection-addresses: - - guid: "01.0f.00.00.00.00.00.00.00.00.00.00" - addresses: - - ip: 127.0.0.1 - port: 3333 - )"; - - Yaml yml = YAML::Load(yml_str); - - // Load configuration - ddsrouter::core::DdsRouterConfiguration configuration_result = - ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::YamlReaderVersion::V_1_0); - - // Check is valid - utils::Formatter error_msg; - ASSERT_TRUE(configuration_result.is_valid(error_msg)); - - // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist, std::set>()); - ASSERT_EQ(configuration_result.blocklist, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics, std::set>()); - - // Check Participant configurations - std::set> - participant_configurations = configuration_result.participants_configurations; - - ASSERT_EQ(participant_configurations.size(), 2u); - - for (std::shared_ptr participant : participant_configurations) - { - // If it is not the discovery server participant, continue - if (!(participant->id() == "participant1")) - { - continue; - } - else - { - // Check the DS partipant is correct - std::shared_ptr ds_participant = - std::dynamic_pointer_cast( - participant); - - // Check Name - ASSERT_EQ(ds_participant->id, ddspipe::core::types::ParticipantId("participant2")); - - // Check GuidPrefix - ASSERT_EQ( - ds_participant->discovery_server_guid_prefix, - ddspipe::core::types::GuidPrefix(true, 3u)); - - // Check Connection addresses - ASSERT_EQ( - ds_participant->connection_addresses.size(), - 1u); - ddspipe::participants::types::DiscoveryServerConnectionAddress address = - *ds_participant->connection_addresses.begin(); - ASSERT_EQ( - address, - (ddspipe::participants::types::DiscoveryServerConnectionAddress( - ddspipe::core::types::GuidPrefix("01.0f.00.00.00.00.00.00.00.00.00.00"), - {ddspipe::participants::types::Address("127.0.0.1", 3333, 3333, - ddspipe::participants::types::Address::default_transport_protocol())} - )) - ); - } + ASSERT_EQ(participant.first, ddsrouter::core::types::ParticipantKind::simple); } } diff --git a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index 341259448..f32a953c4 100644 --- a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -17,11 +17,11 @@ #include #include -#include #include - #include +#include + using namespace eprosima; /** @@ -30,7 +30,7 @@ using namespace eprosima; * CASES: * - trivial configuration */ -TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v1) +TEST(YamlReaderConfigurationTest, ddsrouter_configuration_v1_not_supported) { std::vector yml_configurations = { @@ -38,9 +38,9 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v1) R"( version: v1.0 participant1: - type: "void" + type: "echo" participant2: - type: "void" + type: "echo" )", }; @@ -49,12 +49,9 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v1) Yaml yml = YAML::Load(yml_configuration); // Load configuration - ddsrouter::core::DdsRouterConfiguration configuration_result = - ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); - - // Check is valid - utils::Formatter error_msg; - ASSERT_TRUE(configuration_result.is_valid(error_msg)) << error_msg; + ASSERT_THROW( + ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml), + utils::ConfigurationException); } } @@ -74,9 +71,9 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v2) version: v2.0 participants: - name: "P1" - kind: "void" + kind: "echo" - name: "P2" - kind: "void" + kind: "echo" )", // ROS common configuration @@ -114,44 +111,22 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_v2) /** * Do not set Yaml version and get default configuration - * (currently default is v1.0) + * (currently default is v3.0) * * CASES: - * - trivial configuration of v1.0 - * - trivial configuration of v2.0 fails + * - trivial configuration of v3.0 */ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_no_version) { - // trivial configuration of v1.0 - { - const char* yml_configuration = - R"( - participant1: - type: "void" - participant2: - type: "void" - )"; - - Yaml yml = YAML::Load(yml_configuration); - - // Load configuration - ddsrouter::core::DdsRouterConfiguration configuration_result = - ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); - - // Check is valid - utils::Formatter error_msg; - ASSERT_TRUE(configuration_result.is_valid(error_msg)) << error_msg; - } - - // trivial configuration of v2.0 fails + // trivial configuration of v3.0 { const char* yml_configuration = R"( participants: - name: "P1" - kind: "void" + kind: "echo" - name: "P2" - kind: void" + kind: "echo" )"; Yaml yml = YAML::Load(yml_configuration); @@ -160,9 +135,9 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_no_version) ddsrouter::core::DdsRouterConfiguration configuration_result = ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); - // Check is not valid + // Check is valid utils::Formatter error_msg; - ASSERT_FALSE(configuration_result.is_valid(error_msg)) << error_msg; + ASSERT_TRUE(configuration_result.is_valid(error_msg)) << error_msg; } } @@ -171,8 +146,7 @@ TEST(YamlReaderConfigurationTest, get_ddsrouter_configuration_no_version) * * CASES: * - not existing version - * - not correct version: specify v1.0 and is v2.0 - * - not correct version: specify v2.0 and is v1.0 + * - get wrongly defined yaml with default version (v3.0) */ TEST(YamlReaderConfigurationTest, version_negative_cases) { @@ -184,9 +158,9 @@ TEST(YamlReaderConfigurationTest, version_negative_cases) version: v0.0 participants: - name: "P1" - kind: "void" + kind: "echo" - name: "P2" - kind: void" + kind: "echo" )"; Yaml yml = YAML::Load(yml_configuration); @@ -196,46 +170,19 @@ TEST(YamlReaderConfigurationTest, version_negative_cases) ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml), utils::ConfigurationException); } - - // not correct version: specify v1.0 and is v2.0 + // trivial configuration of default version is not correct { - // trivial configuration const char* yml_configuration = R"( - version: v1.0 - participants: - name: "P1" - kind: "void" + kind: "echo" - name: "P2" - kind: void" + kind: "echo" )"; Yaml yml = YAML::Load(yml_configuration); - // Load configuration - ddsrouter::core::DdsRouterConfiguration configuration_result = - ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml); - - // Check is not valid - utils::Formatter error_msg; - ASSERT_FALSE(configuration_result.is_valid(error_msg)) << error_msg; - } - - // not correct version: specify v2.0 and is v1.0 - { - // trivial configuration - const char* yml_configuration = - R"( - version: v2.0 - participant1: - type: "void" - participant2: - type: "void" - )"; - - Yaml yml = YAML::Load(yml_configuration); - - // Load configuration + // Load configuration and check is not valid ASSERT_THROW( ddsrouter::yaml::YamlReaderConfiguration::load_ddsrouter_configuration(yml), utils::ConfigurationException); @@ -256,9 +203,9 @@ TEST(YamlReaderConfigurationTest, number_of_threads) version: v3.0 participants: - name: "P1" - kind: "void" + kind: "echo" - name: "P2" - kind: "void" + kind: "echo" )"; Yaml yml = YAML::Load(yml_configuration); @@ -267,8 +214,8 @@ TEST(YamlReaderConfigurationTest, number_of_threads) for (unsigned int test_case : test_cases) { Yaml yml_specs; - yml_specs[NUMBER_THREADS_TAG] = test_case; - yml[SPECS_TAG] = yml_specs; + yml_specs[ddspipe::yaml::NUMBER_THREADS_TAG] = test_case; + yml[ddspipe::yaml::SPECS_TAG] = yml_specs; // Load configuration ddsrouter::core::DdsRouterConfiguration configuration_result = @@ -293,9 +240,9 @@ TEST(YamlReaderConfigurationTest, max_history_depth) version: v3.0 participants: - name: "P1" - kind: "void" + kind: "echo" - name: "P2" - kind: "void" + kind: "echo" )"; Yaml yml = YAML::Load(yml_configuration); @@ -304,8 +251,8 @@ TEST(YamlReaderConfigurationTest, max_history_depth) for (unsigned int test_case : test_cases) { Yaml yml_specs; - yml_specs[MAX_HISTORY_DEPTH_TAG] = test_case; - yml[SPECS_TAG] = yml_specs; + yml_specs[ddspipe::yaml::MAX_HISTORY_DEPTH_TAG] = test_case; + yml[ddspipe::yaml::SPECS_TAG] = yml_specs; // Load configuration ddsrouter::core::DdsRouterConfiguration configuration_result = diff --git a/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt b/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt index aca566399..773f18d0b 100644 --- a/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt +++ b/ddsrouter_yaml/test/unittest/participants/CMakeLists.txt @@ -20,6 +20,7 @@ set(TEST_NAME YamlGetCommonParticipantConfigurationTest) set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_configuration.cpp YamlGetCommonParticipantConfigurationTest.cpp ) @@ -53,6 +54,7 @@ set(TEST_NAME YamlGetSimpleParticipantConfigurationTest) set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_configuration.cpp YamlGetSimpleParticipantConfigurationTest.cpp ) @@ -72,11 +74,18 @@ set(TEST_EXTRA_LIBRARIES ddsrouter_core ) +set(TEST_NEEDED_SOURCES "") + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/unittest/TestUtils) + add_unittest_executable( "${TEST_NAME}" "${TEST_SOURCES}" "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") + "${TEST_EXTRA_LIBRARIES}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") ########################################################## # Yaml GetConfigurations DiscoveryServerParticipant Test # @@ -86,6 +95,7 @@ set(TEST_NAME YamlGetDiscoveryServerParticipantConfigurationTest) set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_configuration.cpp YamlGetDiscoveryServerParticipantConfigurationTest.cpp ) @@ -114,11 +124,18 @@ set(TEST_EXTRA_LIBRARIES ddsrouter_core ) +set(TEST_NEEDED_SOURCES "") + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/unittest/TestUtils) + add_unittest_executable( "${TEST_NAME}" "${TEST_SOURCES}" "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") + "${TEST_EXTRA_LIBRARIES}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") ########################################################## # Yaml GetConfigurations InitialPeersParticipant Test # @@ -128,6 +145,7 @@ set(TEST_NAME YamlGetInitialPeersParticipantConfigurationTest) set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReaderConfiguration.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_configuration.cpp YamlGetInitialPeersParticipantConfigurationTest.cpp ) @@ -147,8 +165,15 @@ set(TEST_EXTRA_LIBRARIES ddsrouter_core ) +set(TEST_NEEDED_SOURCES "") + +set(TEST_EXTRA_HEADERS + ${PROJECT_SOURCE_DIR}/test/unittest/TestUtils) + add_unittest_executable( "${TEST_NAME}" "${TEST_SOURCES}" "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") + "${TEST_EXTRA_LIBRARIES}" + "${TEST_NEEDED_SOURCES}" + "${TEST_EXTRA_HEADERS}") diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index 070bd634e..d258e2eb4 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -17,15 +17,17 @@ #include #include -#include +#include #include +#include + +#include + constexpr const uint32_t TEST_ITERATION_MAX = 5; using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml @@ -34,87 +36,51 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetCommonParticipantConfigurationTest, get_participant) { - for (core::types::ParticipantKind kind : core::types::ALL_VALID_PARTICIPANT_KINDS) + for (ddsrouter::core::types::ParticipantKind kind : ddsrouter::core::types::VALUES_ParticipantKind) { for (unsigned int i = 0; i < TEST_ITERATION_MAX; i++) { - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(i); + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(i); // Create a configuration with this kind and this id Yaml yml; Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); yml["participant"] = yml_participant; // Read Yaml - core::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST); + ddspipe::participants::ParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(id, result.id); - ASSERT_EQ(kind, result.kind); } } } /** - * Test get Participant Configuration from yaml fail cases - * - * NEGATIVE CASES: - * - empty - * - no id - * - no type + * Test get Participant Configuration from yaml fail cases (only id is required) */ TEST(YamlGetCommonParticipantConfigurationTest, get_participant_negative) { - // empty - { - // Create structure - Yaml yml; - Yaml yml_participant; - yml["participant"] = yml_participant; - - // Read Yaml - ASSERT_THROW( - core::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), - eprosima::utils::ConfigurationException); - } - // no id { // Create structure Yaml yml; Yaml yml_participant; - yaml::test::participantkind_to_yaml( - yml_participant, - core::types::ParticipantKind(core::types::ParticipantKind::echo)); - yml["participant"] = yml_participant; - - // Read Yaml - ASSERT_THROW( - core::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), - eprosima::utils::ConfigurationException); - } - - // no type - { - // Create structure - Yaml yml; - Yaml yml_participant; - yaml::test::participantid_to_yaml( + ddsrouter::yaml::testing::participantkind_to_yaml( yml_participant, - eprosima::ddsrouter::test::random_participant_id()); + ddsrouter::core::types::ParticipantKind::echo); yml["participant"] = yml_participant; // Read Yaml ASSERT_THROW( - core::ParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, "participant", + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp index f85266139..e756ab313 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetInitialPeersParticipantConfigurationTest.cpp @@ -14,19 +14,22 @@ #include #include + #include #include #include #include -#include +#include #include +#include + +#include + using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml @@ -36,38 +39,37 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_minimum) { - core::types::ParticipantKind kind(core::types::ParticipantKind::wan_initial_peers); - for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::initial_peers; + for (uint32_t i = 0; i < ddsrouter::yaml::testing::TEST_ITERATIONS; i++) { - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(i); - for (int j = 0; j < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; j++) + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(i); + for (uint32_t j = 0; j < ddsrouter::yaml::testing::TEST_ITERATIONS; j++) { // Create a configuration with this kind and this id Yaml yml; Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); yml["participant"] = yml_participant; // Read Yaml - core::InitialPeersParticipantConfiguration result = - YamlReader::get( + ddspipe::participants::InitialPeersParticipantConfiguration result = + ddspipe::yaml::YamlReader::get( yml, "participant", - LATEST); + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(id, result.id); - ASSERT_EQ(kind, result.kind); // Check default values ASSERT_EQ(result.connection_addresses.size(), 0u); ASSERT_EQ(result.listening_addresses.size(), 0u); ASSERT_FALSE(result.tls_configuration.is_active()); ASSERT_EQ( - core::InitialPeersParticipantConfiguration().domain, + ddspipe::participants::InitialPeersParticipantConfiguration().domain, result.domain); } } @@ -86,8 +88,8 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_minimum) */ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) { - core::types::ParticipantKind kind(core::types::ParticipantKind::wan_initial_peers); - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::initial_peers; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); // default { @@ -95,15 +97,16 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); yml["participant"] = yml_participant; // Get configuration object from yaml - core::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::InitialPeersParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_FALSE(result.is_repeater); @@ -115,18 +118,19 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); // Add repeater attribute - yaml::test::repeater_to_yaml(yml_participant, true); + ddspipe::yaml::testing::repeater_to_yaml(yml_participant, true); yml["participant"] = yml_participant; // Get configuration object from yaml - core::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::InitialPeersParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_TRUE(result.is_repeater); @@ -138,18 +142,19 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); // Add repeater attribute - yaml::test::repeater_to_yaml(yml_participant, false); + ddspipe::yaml::testing::repeater_to_yaml(yml_participant, false); yml["participant"] = yml_participant; // Get configuration object from yaml - core::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::InitialPeersParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_FALSE(result.is_repeater); @@ -161,18 +166,19 @@ TEST(YamlGetInitialPeersParticipantConfigurationTest, get_participant_repeater) Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); // Add incorrect repeater - yml_participant[IS_REPEATER_TAG] = "ERROR"; + yml_participant[ddspipe::yaml::IS_REPEATER_TAG] = "ERROR"; yml["participant"] = yml_participant; // Get configuration object from yaml and expect fail ASSERT_THROW( - core::InitialPeersParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::InitialPeersParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index 70a85c46b..7226cc3c9 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -14,20 +14,23 @@ #include #include -#include - +#include #include #include -#include +#include #include +#include + +#include + +#include + constexpr const uint32_t TEST_ITERATION_MAX = 5; using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml @@ -36,33 +39,34 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant) { - for (core::types::ParticipantKind kind : core::types::ALL_VALID_PARTICIPANT_KINDS) + for (ddsrouter::core::types::ParticipantKind kind : ddsrouter::core::types::VALUES_ParticipantKind) { for (unsigned int i = 0; i < TEST_ITERATION_MAX; i++) { - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(i); + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(i); for (unsigned int j = 0; j < TEST_ITERATION_MAX; j++) { - core::types::DomainId domain = eprosima::ddsrouter::test::random_domain(j); + ddspipe::core::types::DomainId domain = ddspipe::core::testing::random_domain(j); // Create a configuration with this kind and this id Yaml yml; Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::domain_to_yaml(yml_participant, domain); + + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::domain_to_yaml(yml_participant, domain); yml["participant"] = yml_participant; // Read Yaml - core::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::SimpleParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(id, result.id); - ASSERT_EQ(kind, result.kind); ASSERT_EQ(domain, result.domain); } } @@ -79,9 +83,9 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant) */ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) { - core::types::ParticipantKind kind(core::types::ParticipantKind::simple_rtps); - core::types::ParticipantId id(eprosima::ddsrouter::test::random_participant_id()); - core::types::DomainId domain(17u); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::simple; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); + ddspipe::core::types::DomainId domain; // empty { @@ -92,8 +96,8 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) // Read Yaml ASSERT_THROW( - core::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, "participant", + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -102,14 +106,14 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) // Create structure Yaml yml; Yaml yml_participant; - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::domain_to_yaml(yml_participant, domain); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::domain_to_yaml(yml_participant, domain); yml["participant"] = yml_participant; // Read Yaml ASSERT_THROW( - core::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, "participant", + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -117,14 +121,14 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant_negative) { Yaml yml; Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::domain_to_yaml(yml_participant, domain); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::domain_to_yaml(yml_participant, domain); yml["participant"] = yml_participant; // Read Yaml ASSERT_THROW( - core::SimpleParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, "participant", + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index 5f5521e17..4b02265b9 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -14,18 +14,23 @@ #include #include -#include - +#include #include #include -#include +#include #include +#include + +#include + +#include + +#include + using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml with connection address @@ -43,9 +48,9 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connection_addresses) { - core::types::ParticipantKind kind(core::types::ParticipantKind::local_discovery_server); - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(); - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::discovery_server; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); + ddspipe::core::types::GuidPrefix guid_prefix = ddspipe::core::testing::random_guid_prefix(); // 1 address { @@ -57,29 +62,30 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_address; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Add server guid - core::types::GuidPrefix connection_guid = eprosima::ddsrouter::test::random_guid_prefix(); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); + ddspipe::core::types::GuidPrefix connection_guid = ddspipe::core::testing::random_guid_prefix(); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); yml_connection_addresses.push_back(yml_connection_address); - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(result.connection_addresses.size(), 1u); @@ -97,48 +103,49 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_addresses; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add addresses - std::vector addresses; - for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) + std::vector addresses; + for (uint32_t i = 0; i < ddsrouter::yaml::testing::TEST_ITERATIONS; i++) { // Create new address - participants::types::Address address = eprosima::ddsrouter::test::random_address(i); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(i); addresses.push_back(address); // Add it to yaml Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); } - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Add server guid - core::types::GuidPrefix connection_guid = eprosima::ddsrouter::test::random_guid_prefix(); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); + ddspipe::core::types::GuidPrefix connection_guid = ddspipe::core::testing::random_guid_prefix(); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); yml_connection_addresses.push_back(yml_connection_address); - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(result.connection_addresses.size(), 1u); ASSERT_EQ(addresses.size(), result.connection_addresses.begin()->addresses().size()); ASSERT_EQ(connection_guid, result.connection_addresses.begin()->discovery_server_guid_prefix()); // Check every address is inside connection addresses of the configuration - for (participants::types::Address address : addresses) + for (ddspipe::participants::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses_result = + std::set addresses_result = result.connection_addresses.begin()->addresses(); ASSERT_NE( addresses_result.find(address), @@ -153,48 +160,49 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_connection_addresses; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); - std::vector connection_guids; + std::vector connection_guids; // Add connections - for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) + for (uint32_t i = 0; i < ddsrouter::yaml::testing::TEST_ITERATIONS; i++) { Yaml yml_connection_address; Yaml yml_addresses; // Add address - participants::types::Address address = eprosima::ddsrouter::test::random_address(i); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(i); // Add it to yaml Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Add server guid - core::types::GuidPrefix connection_guid = eprosima::ddsrouter::test::random_guid_prefix(i); + ddspipe::core::types::GuidPrefix connection_guid = ddspipe::core::testing::random_guid_prefix(i); connection_guids.push_back(connection_guid); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); yml_connection_addresses.push_back(yml_connection_address); } - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(connection_guids.size(), result.connection_addresses.size()); // Check that every connection has a correct number of addresses and a guid given - for (participants::types::DiscoveryServerConnectionAddress connection : result.connection_addresses) + for (ddspipe::participants::types::DiscoveryServerConnectionAddress connection : result.connection_addresses) { ASSERT_NE( std::find(connection_guids.begin(), connection_guids.end(), connection.discovery_server_guid_prefix()) @@ -213,30 +221,31 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_address; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Add server guid - core::types::GuidPrefix connection_guid = eprosima::ddsrouter::test::random_guid_prefix(); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); + ddspipe::core::types::GuidPrefix connection_guid = ddspipe::core::testing::random_guid_prefix(); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); // Add connection wrongly yml_connection_addresses["address1"] = yml_connection_address; - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -250,27 +259,28 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_address; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_addresses.push_back(yml_address); - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Do not add guid server // Add incorrect connection wrongly yml_connection_addresses.push_back(yml_connection_address); - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -284,32 +294,33 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_address; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); // Add address wrongly yml_addresses["address1"] = yml_address; - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Add server guid - core::types::GuidPrefix connection_guid = eprosima::ddsrouter::test::random_guid_prefix(); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); + ddspipe::core::types::GuidPrefix connection_guid = ddspipe::core::testing::random_guid_prefix(); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); // Add connection yml_connection_addresses.push_back(yml_connection_address); - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -323,28 +334,29 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect Yaml yml_address; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add empty address yml_addresses.push_back(yml_address); - yml_connection_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; + yml_connection_address[ddspipe::yaml::COLLECTION_ADDRESSES_TAG] = yml_addresses; // Add server guid - core::types::GuidPrefix connection_guid = eprosima::ddsrouter::test::random_guid_prefix(); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); + ddspipe::core::types::GuidPrefix connection_guid = ddspipe::core::testing::random_guid_prefix(); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_connection_address, connection_guid); // Add connection wrongly yml_connection_addresses.push_back(yml_connection_address); - yml_participant[CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; + yml_participant[ddspipe::yaml::CONNECTION_ADDRESSES_TAG] = yml_connection_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index 7e7608327..09271b51a 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -23,9 +23,11 @@ #include +#include + +#include + using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml specifing domain @@ -38,9 +40,9 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) { - core::types::ParticipantKind kind(core::types::ParticipantKind::local_discovery_server); - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(); - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::discovery_server; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); + ddspipe::core::types::GuidPrefix guid_prefix = ddspipe::core::testing::random_guid_prefix(); // specify domain { @@ -48,20 +50,21 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add domain - core::types::DomainId domain = eprosima::ddsrouter::test::random_domain(); - yaml::test::domain_to_yaml(yml_participant, domain); + ddspipe::core::types::DomainId domain = ddspipe::core::testing::random_domain(); + ddspipe::yaml::testing::domain_to_yaml(yml_participant, domain); yml["participant"] = yml_participant; // Get configuration object from yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(domain, result.domain); @@ -73,9 +76,9 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add incorrect domain yml_participant["domain"] = "DOMAIN"; @@ -84,8 +87,9 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) // Get configuration object from yaml and expect fail ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), - eprosima::utils::ConfigurationException); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), + utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index e36145655..92ca78de7 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -14,18 +14,17 @@ #include #include -#include - +#include #include #include #include #include -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; +#include + +#include /** * Test get Participant Configuration from yaml with listening address @@ -40,9 +39,9 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listening_addresses) { - core::types::ParticipantKind kind(core::types::ParticipantKind::local_discovery_server); - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(); - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::discovery_server; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); + ddspipe::core::types::GuidPrefix guid_prefix = ddspipe::core::testing::random_guid_prefix(); // 1 address { @@ -52,22 +51,23 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni Yaml yml_address; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_listening_addresses.push_back(yml_address); - yml_participant[LISTENING_ADDRESSES_TAG] = yml_listening_addresses; + yml_participant[ddspipe::yaml::LISTENING_ADDRESSES_TAG] = yml_listening_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(result.listening_addresses.size(), 1u); @@ -81,39 +81,40 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni Yaml yml_listening_addresses; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add addresses - std::vector addresses; - for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) + std::vector addresses; + for (uint32_t i = 0; i < ddsrouter::yaml::testing::TEST_ITERATIONS; i++) { // Create new address - participants::types::Address address = eprosima::ddsrouter::test::random_address(i); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(i); addresses.push_back(address); // Add it to yaml Yaml yml_address; - yaml::test::address_to_yaml(yml_address, address); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_listening_addresses.push_back(yml_address); } - yml_participant[LISTENING_ADDRESSES_TAG] = yml_listening_addresses; + yml_participant[ddspipe::yaml::LISTENING_ADDRESSES_TAG] = yml_listening_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", - LATEST); + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(addresses.size(), result.listening_addresses.size()) << yml; // Check every address is inside listening addresses of the configuration - for (participants::types::Address address : addresses) + for (ddspipe::participants::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses_result = result.listening_addresses; + std::set addresses_result = result.listening_addresses; ASSERT_NE( addresses_result.find(address), addresses_result.end()); @@ -126,24 +127,26 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add address badly Yaml yml_listening_addresses; Yaml yml_address; - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_listening_addresses["address1"] = yml_address; - yml_participant[LISTENING_ADDRESSES_TAG] = yml_listening_addresses; + yml_participant[ddspipe::yaml::LISTENING_ADDRESSES_TAG] = yml_listening_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml and expect fail ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -153,22 +156,24 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add incorrect address Yaml yml_listening_addresses; Yaml yml_address; // empty yaml = incorrect address yml_listening_addresses.push_back(yml_address); - yml_participant[LISTENING_ADDRESSES_TAG] = yml_listening_addresses; + yml_participant[ddspipe::yaml::LISTENING_ADDRESSES_TAG] = yml_listening_addresses; yml["participant"] = yml_participant; // Get configuration object from yaml and expect fail ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get(yml, + "participant", + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index 9fed08aa2..489889a00 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -14,18 +14,23 @@ #include #include -#include - +#include #include #include -#include +#include #include +#include + +#include + +#include + +#include + using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get Participant Configuration from yaml @@ -35,35 +40,34 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_minimum) { - for (core::types::ParticipantKind kind : core::types::ALL_VALID_PARTICIPANT_KINDS) + for (ddsrouter::core::types::ParticipantKind kind : ddsrouter::core::types::VALUES_ParticipantKind) { - for (int i = 0; i < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; i++) + for (uint32_t i = 0; i < ddsrouter::yaml::testing::TEST_ITERATIONS; i++) { - core::types::ParticipantId id = eprosima::ddsrouter::test::random_participant_id(i); - for (int j = 0; j < eprosima::ddsrouter::test::TEST_NUMBER_ITERATIONS; j++) + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(i); + for (uint32_t j = 0; j < ddsrouter::yaml::testing::TEST_ITERATIONS; j++) { - core::types::GuidPrefix guid = eprosima::ddsrouter::test::random_guid_prefix(j); + ddspipe::core::types::GuidPrefix guid = ddspipe::core::testing::random_guid_prefix(j); // Create a configuration with this kind and this id Yaml yml; Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid); yml["participant"] = yml_participant; // Read Yaml - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get( + ddspipe::participants::DiscoveryServerParticipantConfiguration result = + ddspipe::yaml::YamlReader::get( yml, "participant", - LATEST); + ddspipe::yaml::YamlReaderVersion::LATEST); // Check result ASSERT_EQ(id, result.id); - ASSERT_EQ(kind, result.kind); ASSERT_EQ(guid, result.discovery_server_guid_prefix); // Check default values @@ -71,7 +75,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_minimum ASSERT_EQ(result.listening_addresses.size(), 0u); ASSERT_FALSE(result.tls_configuration.is_active()); ASSERT_EQ( - core::DiscoveryServerParticipantConfiguration().domain, + ddspipe::participants::DiscoveryServerParticipantConfiguration().domain, result.domain); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp index 984b9a746..9304774d7 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_negative.ipp @@ -14,18 +14,19 @@ #include #include -#include - +#include #include #include -#include +#include #include +#include + +#include + using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; /** * Test get DS Participant Configuration from yaml fail cases @@ -38,9 +39,9 @@ using namespace eprosima::ddspipe::yaml; */ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negative) { - core::types::ParticipantKind kind(core::types::ParticipantKind::local_discovery_server); - core::types::ParticipantId id(eprosima::ddsrouter::test::random_participant_id()); - core::types::GuidPrefix ds_guid = eprosima::ddsrouter::test::random_guid_prefix(); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::discovery_server; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); + ddspipe::core::types::GuidPrefix ds_guid = ddspipe::core::testing::random_guid_prefix(); // empty { @@ -51,8 +52,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ // Read Yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -61,29 +62,14 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ // Create structure Yaml yml; Yaml yml_participant; - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, ds_guid); - yml["participant"] = yml_participant; - - // Read Yaml - ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), - eprosima::utils::ConfigurationException); - } - - // no type - { - Yaml yml; - Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, ds_guid); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, ds_guid); yml["participant"] = yml_participant; // Read Yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -91,14 +77,14 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_negativ { Yaml yml; Yaml yml_participant; - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); yml["participant"] = yml_participant; // Read Yaml ASSERT_THROW( - core::DiscoveryServerParticipantConfiguration result = - YamlReader::get(yml, "participant", LATEST), + ddspipe::yaml::YamlReader::get(yml, + "participant", ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index d86fa6300..8b610ef4e 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -23,9 +23,9 @@ #include -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; +#include + +#include /** * Test get specifing TLS configuration @@ -46,17 +46,18 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_clien Yaml yml; // Add TLS - yml[TLS_TAG] = Yaml(); - yml[TLS_TAG][TLS_CA_TAG] = "ca.pem"; - yml[TLS_TAG][TLS_SNI_HOST_TAG] = "my_server.com"; + yml[ddspipe::yaml::TLS_TAG] = Yaml(); + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_CA_TAG] = "ca.pem"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_SNI_HOST_TAG] = "my_server.com"; - core::types::security::TlsConfiguration tls_configuration = - YamlReader::get(yml, TLS_TAG, LATEST); + ddspipe::participants::types::TlsConfiguration tls_configuration = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::TLS_TAG, + ddspipe::yaml::YamlReaderVersion::LATEST); // Check tls_configuration - ASSERT_TRUE(tls_configuration.compatible()); - ASSERT_FALSE(tls_configuration.compatible()); - ASSERT_FALSE(tls_configuration.compatible()); + ASSERT_TRUE(tls_configuration.compatible()); + ASSERT_FALSE(tls_configuration.compatible()); + ASSERT_FALSE(tls_configuration.compatible()); ASSERT_TRUE(tls_configuration.is_active()); ASSERT_EQ(tls_configuration.certificate_authority_file, "ca.pem"); @@ -68,19 +69,20 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_serve Yaml yml; // Add TLS - yml[TLS_TAG] = Yaml(); - yml[TLS_TAG][TLS_PRIVATE_KEY_TAG] = "pk-file"; - yml[TLS_TAG][TLS_PASSWORD_TAG] = "pwd-file"; - yml[TLS_TAG][TLS_CERT_TAG] = "cert-chain-file"; - yml[TLS_TAG][TLS_DHPARAMS_TAG] = "dhp-file"; + yml[ddspipe::yaml::TLS_TAG] = Yaml(); + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_PRIVATE_KEY_TAG] = "pk-file"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_PASSWORD_TAG] = "pwd-file"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_CERT_TAG] = "cert-chain-file"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_DHPARAMS_TAG] = "dhp-file"; - core::types::security::TlsConfiguration tls_configuration = - YamlReader::get(yml, TLS_TAG, LATEST); + ddspipe::participants::types::TlsConfiguration tls_configuration = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::TLS_TAG, + ddspipe::yaml::YamlReaderVersion::LATEST); // Check tls_configuration - ASSERT_FALSE(tls_configuration.compatible()); - ASSERT_FALSE(tls_configuration.compatible()); - ASSERT_TRUE(tls_configuration.compatible()); + ASSERT_FALSE(tls_configuration.compatible()); + ASSERT_FALSE(tls_configuration.compatible()); + ASSERT_TRUE(tls_configuration.compatible()); ASSERT_TRUE(tls_configuration.is_active()); ASSERT_EQ(tls_configuration.private_key_file_password, "pwd-file"); @@ -95,20 +97,21 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_clien Yaml yml; // Add TLS - yml[TLS_TAG] = Yaml(); - yml[TLS_TAG][TLS_CA_TAG] = "ca.pem"; - yml[TLS_TAG][TLS_PRIVATE_KEY_TAG] = "pk-file"; - yml[TLS_TAG][TLS_PASSWORD_TAG] = "pwd-file"; - yml[TLS_TAG][TLS_CERT_TAG] = "cert-chain-file"; - yml[TLS_TAG][TLS_DHPARAMS_TAG] = "dhp-file"; + yml[ddspipe::yaml::TLS_TAG] = Yaml(); + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_CA_TAG] = "ca.pem"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_PRIVATE_KEY_TAG] = "pk-file"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_PASSWORD_TAG] = "pwd-file"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_CERT_TAG] = "cert-chain-file"; + yml[ddspipe::yaml::TLS_TAG][ddspipe::yaml::TLS_DHPARAMS_TAG] = "dhp-file"; - core::types::security::TlsConfiguration tls_configuration = - YamlReader::get(yml, TLS_TAG, LATEST); + ddspipe::participants::types::TlsConfiguration tls_configuration = + ddspipe::yaml::YamlReader::get(yml, ddspipe::yaml::TLS_TAG, + ddspipe::yaml::YamlReaderVersion::LATEST); // Check tls_configuration - ASSERT_TRUE(tls_configuration.compatible()); - ASSERT_TRUE(tls_configuration.compatible()); - ASSERT_TRUE(tls_configuration.compatible()); + ASSERT_TRUE(tls_configuration.compatible()); + ASSERT_TRUE(tls_configuration.compatible()); + ASSERT_TRUE(tls_configuration.compatible()); ASSERT_TRUE(tls_configuration.is_active()); ASSERT_EQ(tls_configuration.certificate_authority_file, "ca.pem"); @@ -122,26 +125,26 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_clien TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_inactive) { // ParticipantConfiguration with inactive TLS - core::types::ParticipantId id(eprosima::ddsrouter::test::random_participant_id()); - core::types::ParticipantKind kind(core::types::ParticipantKind::local_discovery_server); - core::types::GuidPrefix guid_prefix = eprosima::ddsrouter::test::random_guid_prefix(); + ddsrouter::core::types::ParticipantKind kind = ddsrouter::core::types::ParticipantKind::discovery_server; + ddspipe::core::types::ParticipantId id = ddspipe::core::testing::random_participant_id(); + ddspipe::core::types::GuidPrefix guid_prefix = ddspipe::core::testing::random_guid_prefix(); Yaml yml; Yaml yml_participant; // Add required fields - yaml::test::participantid_to_yaml(yml_participant, id); - yaml::test::participantkind_to_yaml(yml_participant, kind); - yaml::test::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); + ddspipe::yaml::testing::participantid_to_yaml(yml_participant, id); + ddsrouter::yaml::testing::participantkind_to_yaml(yml_participant, kind); + ddspipe::yaml::testing::discovery_server_guid_prefix_to_yaml(yml_participant, guid_prefix); // Add addresses (so that participant configuration is valid) Yaml yml_listening_addresses; Yaml yml_address; - participants::types::Address address = eprosima::ddsrouter::test::random_address(); - yaml::test::address_to_yaml(yml_address, address); + ddspipe::participants::types::Address address = ddspipe::participants::testing::random_address(); + ddspipe::yaml::testing::address_to_yaml(yml_address, address); yml_listening_addresses.push_back(yml_address); - yml_participant[LISTENING_ADDRESSES_TAG] = yml_listening_addresses; + yml_participant[ddspipe::yaml::LISTENING_ADDRESSES_TAG] = yml_listening_addresses; // Store participant yaml node @@ -149,14 +152,15 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_inact // No TLS tag insertion // Get configuration object from yaml - auto ds_participant_cfg = YamlReader::get(yml, + auto ds_participant_cfg = + ddspipe::yaml::YamlReader::get(yml, "participant", - LATEST); + ddspipe::yaml::YamlReaderVersion::LATEST); // Check tls_configuration - ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); ASSERT_FALSE(ds_participant_cfg.tls_configuration.is_active()); } @@ -166,12 +170,12 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_incor Yaml yml; // Add empty TLS - yml[TLS_TAG] = Yaml(); + yml[ddspipe::yaml::TLS_TAG] = Yaml(); ASSERT_THROW( - core::types::security::TlsConfiguration tls_configuration = YamlReader::get( - yml, TLS_TAG, - LATEST), + ddspipe::participants::types::TlsConfiguration tls_configuration = ddspipe::yaml::YamlReader::get( + yml, ddspipe::yaml::TLS_TAG, + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } @@ -183,12 +187,12 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_incor // Add empty TLS Yaml yml_array; yml_array.push_back("ca.cert"); - yml[TLS_TAG] = yml_array; + yml[ddspipe::yaml::TLS_TAG] = yml_array; // Get configuration object from yaml ASSERT_THROW( - core::types::security::TlsConfiguration tls_configuration = YamlReader::get( - yml, TLS_TAG, - LATEST), + ddspipe::participants::types::TlsConfiguration tls_configuration = ddspipe::yaml::YamlReader::get( + yml, ddspipe::yaml::TLS_TAG, + ddspipe::yaml::YamlReaderVersion::LATEST), eprosima::utils::ConfigurationException); } diff --git a/docs/rst/user_manual/configuration.rst b/docs/rst/user_manual/configuration.rst index 15c8dcc34..0cb1a1f05 100644 --- a/docs/rst/user_manual/configuration.rst +++ b/docs/rst/user_manual/configuration.rst @@ -32,15 +32,11 @@ with future releases. - String in ``version`` tag - |ddsrouter| activation release - * - version 1.0 - - ``v1.0`` - - *v0.1.0* - * - version 2.0 - ``v2.0`` - *v0.2.0* - * - version 3.0 + * - version 3.0 (default) - ``v3.0`` - *v0.3.0* @@ -49,13 +45,18 @@ This is the configuration version that is described along this page. .. note:: - The current default version when tag ``version`` is not set is *v1.0*. + The current default version when tag ``version`` is not set is *v3.0*. .. warning:: **Deprecation Warning**. In future releases tag ``version`` will be mandatory. +.. warning:: + + **Deprecation warning**. + Update to `v3.0` version as `v1.0` is no longer supported. + .. _thread_configuration: