From 81d26790321f4b697e57874e45221830689db1ca Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Fri, 30 Jun 2023 12:23:14 +0200 Subject: [PATCH 01/11] Refs #18950: Introduce regression test Signed-off-by: JesusPoderoso --- .../BasicConfigurationPublisher.cpp | 2 +- .../rtps/transport/test_UDPv4Transport.cpp | 17 ++ src/cpp/rtps/transport/test_UDPv4Transport.h | 6 + .../api/fastrtps_deprecated/PubSubReader.hpp | 14 ++ .../api/fastrtps_deprecated/PubSubWriter.hpp | 14 ++ .../PubSubWriterReader.hpp | 28 +++ .../RTPSBlackboxTestsTransportSHMUDP.cpp | 208 ++++++++++++++++++ 7 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp diff --git a/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp b/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp index 1f231adf86d..3be9cd60da1 100644 --- a/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp +++ b/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp @@ -160,7 +160,7 @@ bool HelloWorldPublisher::init( DataWriterQos wqos = DATAWRITER_QOS_DEFAULT; // Data sharing set in endpoint. If it is not default, set it to off - if (transport != DEFAULT) + if (true/*transport != DEFAULT*/) { wqos.data_sharing().off(); } diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index 08e211d7a55..5fe599abc23 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -245,6 +245,7 @@ bool test_UDPv4Transport::send( } else { + increase_message_sent(remote_locator.port); return UDPv4Transport::send(send_buffer, send_buffer_size, socket, remote_locator, only_multicast_purpose, whitelisted, timeout); } @@ -496,6 +497,22 @@ bool test_UDPv4Transport::should_be_dropped( return false; } +void test_UDPv4Transport::increase_message_sent( + uint32_t port) +{ + for (std::map::iterator it = messages_sent.begin(); it != messages_sent.end(); ++it) + { + if (it->first == port) + { + it->second++; + return; + } + } + // if code reaches here, it means it was not part of the map + messages_sent.insert({port,1}); +} + + } // namespace rtps } // namespace fastrtps } // namespace eprosima diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index 93a611675fc..1f58a662287 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -62,6 +62,9 @@ class test_UDPv4Transport : public UDPv4Transport RTPS_DllAPI static test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter; + // Record the number of packages sent to the different ports (key) + RTPS_DllAPI static std::map messages_sent; + protected: virtual void get_ips( @@ -101,6 +104,9 @@ class test_UDPv4Transport : public UDPv4Transport std::vector sequence_number_data_messages_to_drop_; test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter_; + void increase_message_sent( + uint32_t port); + bool should_drop_locator( const Locator& remote_locator); diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp index 3b5b506c18c..a7a610c8275 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp @@ -1180,6 +1180,20 @@ class PubSubReader return subscriber_->updateAttributes(subscriber_attr_); } + PubSubReader& data_sharing( + bool enable) + { + if (enable) + { + subscriber_attr_.qos.data_sharing().automatic(); + } + else + { + subscriber_attr_.qos.data_sharing().off(); + } + return *this; + } + /*** Function for discovery callback ***/ void wait_discovery_result() diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp index 5f777a20dfd..5cdb7e433da 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp @@ -1118,6 +1118,20 @@ class PubSubWriter return *this; } + PubSubWriter& data_sharing( + bool enable) + { + if (enable) + { + publisher_attr_.qos.data_sharing().automatic(); + } + else + { + publisher_attr_.qos.data_sharing().off(); + } + return *this; + } + PubSubWriter& max_initial_peers_range( uint32_t maxInitialPeerRange) { diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp index 11621ee7e76..faa89ef32ed 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp @@ -749,6 +749,34 @@ class PubSubWriterReader return *this; } + PubSubWriterReader& pub_data_sharing( + bool enable) + { + if (enable) + { + publisher_attr_.qos.data_sharing().automatic(); + } + else + { + publisher_attr_.qos.data_sharing().off(); + } + return *this; + } + + PubSubWriterReader& sub_data_sharing( + bool enable) + { + if (enable) + { + subscriber_attr_.qos.data_sharing().automatic(); + } + else + { + subscriber_attr_.qos.data_sharing().off(); + } + return *this; + } + private: void receive_one( diff --git a/test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp new file mode 100644 index 00000000000..c0eb315a6a4 --- /dev/null +++ b/test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp @@ -0,0 +1,208 @@ +// 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 "BlackboxTests.hpp" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "RTPSAsSocketReader.hpp" +#include "RTPSAsSocketWriter.hpp" +#include "RTPSWithRegistrationReader.hpp" +#include "RTPSWithRegistrationWriter.hpp" + +#include "PubSubReader.hpp" +#include "PubSubWriter.hpp" +#include + +using namespace eprosima::fastrtps; +using namespace eprosima::fastrtps::rtps; +using test_UDPv4Transport = eprosima::fastdds::rtps::test_UDPv4Transport; + +enum communication_type +{ + INTERPROCESS, + INTRAPROCESS +}; + +enum data_sharing_status +{ + ENABLED, + DISABLED +}; + +struct test_parameters +{ + communication_type type; + data_sharing_status status; +}; + +class RTPS : public testing::TestWithParam +{ +public: + + void SetUp() override + { + LibrarySettingsAttributes library_settings; + switch (GetParam().type) + { + case INTRAPROCESS: + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case INTERPROCESS: + default: + break; + } + } + + void TearDown() override + { + LibrarySettingsAttributes library_settings; + switch (GetParam().type) + { + case INTRAPROCESS: + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case INTERPROCESS: + default: + break; + } + } +}; + +TEST_P(RTPS, RTPSTransport_SHM_UDP_test) +{ + bool enable_data_sharing = false; + switch (GetParam().status) + { + case ENABLED: + enable_data_sharing = true; + break; + case DISABLED: + default: + enable_data_sharing = false; + break; + } + + static struct test_conditions{ + uint32_t pub_unicast_port = 7525; + uint32_t pub_metatraffic_unicast_port = 7526; + uint32_t sub_unicast_port = 7527; + uint32_t sub_metatraffic_unicast_port = 7528; + } conditions; + + // Set up + PubSubReader reader(TEST_TOPIC_NAME); + PubSubWriter writer(TEST_TOPIC_NAME); + + auto sub_shm_descriptor = std::make_shared(); + sub_shm_descriptor->segment_size(2 * 1024 * 1024); + std::shared_ptr sub_udp_descriptor = + std::make_shared(); + reader.disable_builtin_transport() + .add_user_transport_to_pparams(sub_shm_descriptor) + .add_user_transport_to_pparams(sub_udp_descriptor) + .data_sharing(enable_data_sharing) + .reliability(BEST_EFFORT_RELIABILITY_QOS) + .durability_kind(VOLATILE_DURABILITY_QOS) + .add_to_unicast_locator_list("localhost", conditions.sub_unicast_port) + .add_to_metatraffic_unicast_locator_list("localhost", conditions.sub_metatraffic_unicast_port) + .init(); + ASSERT_TRUE(reader.isInitialized()); + + auto pub_shm_descriptor = std::make_shared(); + pub_shm_descriptor->segment_size(2 * 1024 * 1024); + + auto pub_udp_descriptor = std::make_shared(); + writer.disable_builtin_transport() + .add_user_transport_to_pparams(pub_shm_descriptor) + .add_user_transport_to_pparams(pub_udp_descriptor) + .data_sharing(enable_data_sharing) + .reliability(BEST_EFFORT_RELIABILITY_QOS) + .durability_kind(VOLATILE_DURABILITY_QOS) + .asynchronously(SYNCHRONOUS_PUBLISH_MODE) + .add_to_unicast_locator_list("localhost", conditions.pub_unicast_port) + .add_to_metatraffic_unicast_locator_list("localhost", conditions.pub_metatraffic_unicast_port) + .init(); + ASSERT_TRUE(writer.isInitialized()); + + // Because its volatile the durability, wait for discovery + writer.wait_discovery(); + reader.wait_discovery(); + + // Send some data. + auto data = default_helloworld_data_generator(); + writer.send(data); + // In this test all data should be sent. + ASSERT_TRUE(data.empty()); + + // Check that reader receives the unmatched. + reader.block_for_all(); + + // check that no data has been received in the udp transport + uint32_t n_packages_sent = sizeof(uint32_t); + for (std::map::iterator it = test_UDPv4Transport::messages_sent.begin(); it != test_UDPv4Transport::messages_sent.end(); ++it) + { + if (it->first == conditions.pub_unicast_port) + { + n_packages_sent = it->second; + } + } + ASSERT_EQ(n_packages_sent, 0u); +} + +#ifdef INSTANTIATE_TEST_SUITE_P +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w) +#else +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_CASE_P(x, y, z, w) +#endif // ifdef INSTANTIATE_TEST_SUITE_P + +GTEST_INSTANTIATE_TEST_MACRO(RTPS, + RTPS, + testing::Values(INTERPROCESS, INTRAPROCESS, ENABLED, DISABLED), + [](const testing::TestParamInfo& info) + { + switch (info.param) + { + case INTRAPROCESS: + return "Communication intraprocess"; + break; + case INTERPROCESS: + return "Communication interprocess"; + break; + case ENABLED: + return "Data sharing automatic (enabled)"; + break; + case DISABLED: + default: + return "Data sharing disabled"; + } + + }); From c3817786ea05809258cb902e375333ec99a4e6e1 Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Mon, 3 Jul 2023 08:34:38 +0200 Subject: [PATCH 02/11] Refs #18950: Make test build Signed-off-by: JesusPoderoso --- .../rtps/transport/test_UDPv4Transport.cpp | 25 ++++- src/cpp/rtps/transport/test_UDPv4Transport.h | 4 +- test/blackbox/api/dds-pim/PubSubReader.hpp | 14 +++ test/blackbox/api/dds-pim/PubSubWriter.hpp | 14 +++ .../api/dds-pim/PubSubWriterReader.hpp | 28 ++++++ .../api/fastrtps_deprecated/PubSubReader.hpp | 14 --- .../api/fastrtps_deprecated/PubSubWriter.hpp | 14 --- .../PubSubWriterReader.hpp | 28 ------ ...pp => DDSBlackboxTestsTransportSHMUDP.cpp} | 99 ++++++++----------- 9 files changed, 120 insertions(+), 120 deletions(-) rename test/blackbox/common/{RTPSBlackboxTestsTransportSHMUDP.cpp => DDSBlackboxTestsTransportSHMUDP.cpp} (75%) diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index 5fe599abc23..d3990f922d7 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -41,6 +41,7 @@ test_UDPv4TransportDescriptor::DestinationLocatorFilter test_UDPv4Transport::loc { return false; }); +std::map test_UDPv4Transport::messages_sent{}; test_UDPv4Transport::test_UDPv4Transport( const test_UDPv4TransportDescriptor& descriptor) @@ -245,7 +246,24 @@ bool test_UDPv4Transport::send( } else { - increase_message_sent(remote_locator.port); + //increase_message_sent(remote_locator.port); + bool inserted = false; + for (std::map::iterator it = messages_sent.begin(); it != messages_sent.end(); ++it) + { + if (it->first == remote_locator.port) + { + it->second++; + inserted = true; + break; + } + } + + if (!inserted) + { + messages_sent.insert({remote_locator.port,1}); + } + + return UDPv4Transport::send(send_buffer, send_buffer_size, socket, remote_locator, only_multicast_purpose, whitelisted, timeout); } @@ -497,7 +515,7 @@ bool test_UDPv4Transport::should_be_dropped( return false; } -void test_UDPv4Transport::increase_message_sent( +/*void test_UDPv4Transport::increase_message_sent( uint32_t port) { for (std::map::iterator it = messages_sent.begin(); it != messages_sent.end(); ++it) @@ -510,8 +528,7 @@ void test_UDPv4Transport::increase_message_sent( } // if code reaches here, it means it was not part of the map messages_sent.insert({port,1}); -} - +}*/ } // namespace rtps } // namespace fastrtps diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index 1f58a662287..0e8b06d071c 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -104,8 +104,8 @@ class test_UDPv4Transport : public UDPv4Transport std::vector sequence_number_data_messages_to_drop_; test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter_; - void increase_message_sent( - uint32_t port); + /*void increase_message_sent( + uint32_t port);*/ bool should_drop_locator( const Locator& remote_locator); diff --git a/test/blackbox/api/dds-pim/PubSubReader.hpp b/test/blackbox/api/dds-pim/PubSubReader.hpp index 4b827a3cfb8..37fa570488c 100644 --- a/test/blackbox/api/dds-pim/PubSubReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubReader.hpp @@ -1010,6 +1010,20 @@ class PubSubReader return *this; } + PubSubReader& data_sharing( + bool enable) + { + if (enable) + { + datareader_qos_.data_sharing().automatic(); + } + else + { + datareader_qos_.data_sharing().off(); + } + return *this; + } + PubSubReader& unicastLocatorList( const eprosima::fastdds::rtps::LocatorList& unicast_locators) { diff --git a/test/blackbox/api/dds-pim/PubSubWriter.hpp b/test/blackbox/api/dds-pim/PubSubWriter.hpp index 5a97217f0d7..fc1f95ca984 100644 --- a/test/blackbox/api/dds-pim/PubSubWriter.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriter.hpp @@ -972,6 +972,20 @@ class PubSubWriter return *this; } + PubSubWriter& data_sharing( + bool enable) + { + if (enable) + { + datawriter_qos_.data_sharing().automatic(); + } + else + { + datawriter_qos_.data_sharing().off(); + } + return *this; + } + PubSubWriter& matched_readers_allocation( size_t initial, size_t maximum) diff --git a/test/blackbox/api/dds-pim/PubSubWriterReader.hpp b/test/blackbox/api/dds-pim/PubSubWriterReader.hpp index ab9b4a80d5e..52d96ee8f9a 100644 --- a/test/blackbox/api/dds-pim/PubSubWriterReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriterReader.hpp @@ -840,6 +840,34 @@ class PubSubWriterReader return *this; } + PubSubWriterReader& pub_data_sharing( + bool enable) + { + if (enable) + { + datawriter_qos_.data_sharing().automatic(); + } + else + { + datawriter_qos_.data_sharing().off(); + } + return *this; + } + + PubSubWriterReader& sub_data_sharing( + bool enable) + { + if (enable) + { + datareader_qos_.data_sharing().automatic(); + } + else + { + datareader_qos_.data_sharing().off(); + } + return *this; + } + void assert_liveliness() { datawriter_->assert_liveliness(); diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp index a7a610c8275..3b5b506c18c 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp @@ -1180,20 +1180,6 @@ class PubSubReader return subscriber_->updateAttributes(subscriber_attr_); } - PubSubReader& data_sharing( - bool enable) - { - if (enable) - { - subscriber_attr_.qos.data_sharing().automatic(); - } - else - { - subscriber_attr_.qos.data_sharing().off(); - } - return *this; - } - /*** Function for discovery callback ***/ void wait_discovery_result() diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp index 5cdb7e433da..5f777a20dfd 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp @@ -1118,20 +1118,6 @@ class PubSubWriter return *this; } - PubSubWriter& data_sharing( - bool enable) - { - if (enable) - { - publisher_attr_.qos.data_sharing().automatic(); - } - else - { - publisher_attr_.qos.data_sharing().off(); - } - return *this; - } - PubSubWriter& max_initial_peers_range( uint32_t maxInitialPeerRange) { diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp index faa89ef32ed..11621ee7e76 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubWriterReader.hpp @@ -749,34 +749,6 @@ class PubSubWriterReader return *this; } - PubSubWriterReader& pub_data_sharing( - bool enable) - { - if (enable) - { - publisher_attr_.qos.data_sharing().automatic(); - } - else - { - publisher_attr_.qos.data_sharing().off(); - } - return *this; - } - - PubSubWriterReader& sub_data_sharing( - bool enable) - { - if (enable) - { - subscriber_attr_.qos.data_sharing().automatic(); - } - else - { - subscriber_attr_.qos.data_sharing().off(); - } - return *this; - } - private: void receive_one( diff --git a/test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp similarity index 75% rename from test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp rename to test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index c0eb315a6a4..fbb49c3b785 100644 --- a/test/blackbox/common/RTPSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -21,23 +21,13 @@ #include -#include -#include -#include -#include -#include #include #include #include #include -#include "RTPSAsSocketReader.hpp" -#include "RTPSAsSocketWriter.hpp" -#include "RTPSWithRegistrationReader.hpp" -#include "RTPSWithRegistrationWriter.hpp" - -#include "PubSubReader.hpp" -#include "PubSubWriter.hpp" +#include "../api/dds-pim/PubSubReader.hpp" +#include "../api/dds-pim/PubSubWriter.hpp" #include using namespace eprosima::fastrtps; @@ -46,37 +36,35 @@ using test_UDPv4Transport = eprosima::fastdds::rtps::test_UDPv4Transport; enum communication_type { - INTERPROCESS, - INTRAPROCESS -}; - -enum data_sharing_status -{ - ENABLED, - DISABLED -}; - -struct test_parameters -{ - communication_type type; - data_sharing_status status; + TRANSPORT, + INTRAPROCESS, + DATASHARING }; -class RTPS : public testing::TestWithParam +class RTPS : public testing::TestWithParam { public: void SetUp() override { LibrarySettingsAttributes library_settings; - switch (GetParam().type) + switch (GetParam()) { case INTRAPROCESS: + enable_datasharing = false; library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; xmlparser::XMLProfileManager::library_settings(library_settings); break; - case INTERPROCESS: + case DATASHARING: + enable_datasharing = true; + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case TRANSPORT: default: + enable_datasharing = false; + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; + xmlparser::XMLProfileManager::library_settings(library_settings); break; } } @@ -84,35 +72,27 @@ class RTPS : public testing::TestWithParam void TearDown() override { LibrarySettingsAttributes library_settings; - switch (GetParam().type) + switch (GetParam()) { case INTRAPROCESS: - library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; xmlparser::XMLProfileManager::library_settings(library_settings); break; - case INTERPROCESS: + case DATASHARING: + enable_datasharing = false; + break; + case TRANSPORT: default: break; } } + }; -TEST_P(RTPS, RTPSTransport_SHM_UDP_test) +TEST_P(RTPS, Transport_SHM_UDP_test) { - bool enable_data_sharing = false; - switch (GetParam().status) - { - case ENABLED: - enable_data_sharing = true; - break; - case DISABLED: - default: - enable_data_sharing = false; - break; - } - static struct test_conditions{ - uint32_t pub_unicast_port = 7525; + uint32_t pub_unicast_port = 7411; uint32_t pub_metatraffic_unicast_port = 7526; uint32_t sub_unicast_port = 7527; uint32_t sub_metatraffic_unicast_port = 7528; @@ -129,14 +109,18 @@ TEST_P(RTPS, RTPSTransport_SHM_UDP_test) reader.disable_builtin_transport() .add_user_transport_to_pparams(sub_shm_descriptor) .add_user_transport_to_pparams(sub_udp_descriptor) - .data_sharing(enable_data_sharing) + .data_sharing(enable_datasharing) .reliability(BEST_EFFORT_RELIABILITY_QOS) .durability_kind(VOLATILE_DURABILITY_QOS) + .history_kind(KEEP_ALL_HISTORY_QOS) .add_to_unicast_locator_list("localhost", conditions.sub_unicast_port) .add_to_metatraffic_unicast_locator_list("localhost", conditions.sub_metatraffic_unicast_port) .init(); ASSERT_TRUE(reader.isInitialized()); + //reader.unicastLocatorList() + // get locator list and obtain port + auto pub_shm_descriptor = std::make_shared(); pub_shm_descriptor->segment_size(2 * 1024 * 1024); @@ -144,9 +128,10 @@ TEST_P(RTPS, RTPSTransport_SHM_UDP_test) writer.disable_builtin_transport() .add_user_transport_to_pparams(pub_shm_descriptor) .add_user_transport_to_pparams(pub_udp_descriptor) - .data_sharing(enable_data_sharing) + .data_sharing(enable_datasharing) .reliability(BEST_EFFORT_RELIABILITY_QOS) .durability_kind(VOLATILE_DURABILITY_QOS) + .history_kind(KEEP_ALL_HISTORY_QOS) .asynchronously(SYNCHRONOUS_PUBLISH_MODE) .add_to_unicast_locator_list("localhost", conditions.pub_unicast_port) .add_to_metatraffic_unicast_locator_list("localhost", conditions.pub_metatraffic_unicast_port) @@ -159,6 +144,7 @@ TEST_P(RTPS, RTPSTransport_SHM_UDP_test) // Send some data. auto data = default_helloworld_data_generator(); + reader.startReception(data); writer.send(data); // In this test all data should be sent. ASSERT_TRUE(data.empty()); @@ -170,6 +156,7 @@ TEST_P(RTPS, RTPSTransport_SHM_UDP_test) uint32_t n_packages_sent = sizeof(uint32_t); for (std::map::iterator it = test_UDPv4Transport::messages_sent.begin(); it != test_UDPv4Transport::messages_sent.end(); ++it) { + std::cout << "port: " << it->first << ", n_packages: " << it->second << std::endl; if (it->first == conditions.pub_unicast_port) { n_packages_sent = it->second; @@ -186,23 +173,19 @@ TEST_P(RTPS, RTPSTransport_SHM_UDP_test) GTEST_INSTANTIATE_TEST_MACRO(RTPS, RTPS, - testing::Values(INTERPROCESS, INTRAPROCESS, ENABLED, DISABLED), + testing::Values(TRANSPORT, INTRAPROCESS, DATASHARING), [](const testing::TestParamInfo& info) { switch (info.param) { case INTRAPROCESS: - return "Communication intraprocess"; + return "Intraprocess"; break; - case INTERPROCESS: - return "Communication interprocess"; + case DATASHARING: + return "Datasharing"; break; - case ENABLED: - return "Data sharing automatic (enabled)"; - break; - case DISABLED: + case TRANSPORT: default: - return "Data sharing disabled"; + return "Transport"; } - }); From e5efa0a8ec10ca921eab80beeef7ce3957229b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Wed, 5 Jul 2023 15:00:09 +0200 Subject: [PATCH 03/11] Finalize test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- .../BasicConfigurationPublisher.cpp | 2 +- .../rtps/transport/test_UDPv4Transport.cpp | 40 +++------------ src/cpp/rtps/transport/test_UDPv4Transport.h | 3 -- test/blackbox/api/dds-pim/PubSubReader.hpp | 14 ----- test/blackbox/api/dds-pim/PubSubWriter.hpp | 14 ----- .../api/dds-pim/PubSubWriterReader.hpp | 28 ---------- .../DDSBlackboxTestsTransportSHMUDP.cpp | 51 ++++++++----------- 7 files changed, 30 insertions(+), 122 deletions(-) diff --git a/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp b/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp index 3be9cd60da1..1f231adf86d 100644 --- a/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp +++ b/examples/cpp/dds/BasicConfigurationExample/BasicConfigurationPublisher.cpp @@ -160,7 +160,7 @@ bool HelloWorldPublisher::init( DataWriterQos wqos = DATAWRITER_QOS_DEFAULT; // Data sharing set in endpoint. If it is not default, set it to off - if (true/*transport != DEFAULT*/) + if (transport != DEFAULT) { wqos.data_sharing().off(); } diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index d3990f922d7..aac8ae87fa8 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -202,6 +202,12 @@ bool test_UDPv4Transport::send( while (it != *destination_locators_end) { + if (!IsLocatorSupported(*it)) + { + ++it; + continue; + } + auto now = std::chrono::steady_clock::now(); if (now < max_blocking_time_point) @@ -246,24 +252,7 @@ bool test_UDPv4Transport::send( } else { - //increase_message_sent(remote_locator.port); - bool inserted = false; - for (std::map::iterator it = messages_sent.begin(); it != messages_sent.end(); ++it) - { - if (it->first == remote_locator.port) - { - it->second++; - inserted = true; - break; - } - } - - if (!inserted) - { - messages_sent.insert({remote_locator.port,1}); - } - - + messages_sent[remote_locator.port]++; return UDPv4Transport::send(send_buffer, send_buffer_size, socket, remote_locator, only_multicast_purpose, whitelisted, timeout); } @@ -515,21 +504,6 @@ bool test_UDPv4Transport::should_be_dropped( return false; } -/*void test_UDPv4Transport::increase_message_sent( - uint32_t port) -{ - for (std::map::iterator it = messages_sent.begin(); it != messages_sent.end(); ++it) - { - if (it->first == port) - { - it->second++; - return; - } - } - // if code reaches here, it means it was not part of the map - messages_sent.insert({port,1}); -}*/ - } // namespace rtps } // namespace fastrtps } // namespace eprosima diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index 0e8b06d071c..fbb4b498080 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -104,9 +104,6 @@ class test_UDPv4Transport : public UDPv4Transport std::vector sequence_number_data_messages_to_drop_; test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter_; - /*void increase_message_sent( - uint32_t port);*/ - bool should_drop_locator( const Locator& remote_locator); diff --git a/test/blackbox/api/dds-pim/PubSubReader.hpp b/test/blackbox/api/dds-pim/PubSubReader.hpp index 37fa570488c..4b827a3cfb8 100644 --- a/test/blackbox/api/dds-pim/PubSubReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubReader.hpp @@ -1010,20 +1010,6 @@ class PubSubReader return *this; } - PubSubReader& data_sharing( - bool enable) - { - if (enable) - { - datareader_qos_.data_sharing().automatic(); - } - else - { - datareader_qos_.data_sharing().off(); - } - return *this; - } - PubSubReader& unicastLocatorList( const eprosima::fastdds::rtps::LocatorList& unicast_locators) { diff --git a/test/blackbox/api/dds-pim/PubSubWriter.hpp b/test/blackbox/api/dds-pim/PubSubWriter.hpp index fc1f95ca984..5a97217f0d7 100644 --- a/test/blackbox/api/dds-pim/PubSubWriter.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriter.hpp @@ -972,20 +972,6 @@ class PubSubWriter return *this; } - PubSubWriter& data_sharing( - bool enable) - { - if (enable) - { - datawriter_qos_.data_sharing().automatic(); - } - else - { - datawriter_qos_.data_sharing().off(); - } - return *this; - } - PubSubWriter& matched_readers_allocation( size_t initial, size_t maximum) diff --git a/test/blackbox/api/dds-pim/PubSubWriterReader.hpp b/test/blackbox/api/dds-pim/PubSubWriterReader.hpp index 52d96ee8f9a..ab9b4a80d5e 100644 --- a/test/blackbox/api/dds-pim/PubSubWriterReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriterReader.hpp @@ -840,34 +840,6 @@ class PubSubWriterReader return *this; } - PubSubWriterReader& pub_data_sharing( - bool enable) - { - if (enable) - { - datawriter_qos_.data_sharing().automatic(); - } - else - { - datawriter_qos_.data_sharing().off(); - } - return *this; - } - - PubSubWriterReader& sub_data_sharing( - bool enable) - { - if (enable) - { - datareader_qos_.data_sharing().automatic(); - } - else - { - datareader_qos_.data_sharing().off(); - } - return *this; - } - void assert_liveliness() { datawriter_->assert_liveliness(); diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index fbb49c3b785..92e454f8038 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -41,7 +41,7 @@ enum communication_type DATASHARING }; -class RTPS : public testing::TestWithParam +class SHMUDP : public testing::TestWithParam { public: @@ -51,20 +51,14 @@ class RTPS : public testing::TestWithParam switch (GetParam()) { case INTRAPROCESS: - enable_datasharing = false; library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; xmlparser::XMLProfileManager::library_settings(library_settings); break; case DATASHARING: enable_datasharing = true; - library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; - xmlparser::XMLProfileManager::library_settings(library_settings); break; case TRANSPORT: default: - enable_datasharing = false; - library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; - xmlparser::XMLProfileManager::library_settings(library_settings); break; } } @@ -89,13 +83,10 @@ class RTPS : public testing::TestWithParam }; -TEST_P(RTPS, Transport_SHM_UDP_test) +TEST_P(SHMUDP, Transport_SHM_UDP_test) { static struct test_conditions{ - uint32_t pub_unicast_port = 7411; - uint32_t pub_metatraffic_unicast_port = 7526; uint32_t sub_unicast_port = 7527; - uint32_t sub_metatraffic_unicast_port = 7528; } conditions; // Set up @@ -106,35 +97,31 @@ TEST_P(RTPS, Transport_SHM_UDP_test) sub_shm_descriptor->segment_size(2 * 1024 * 1024); std::shared_ptr sub_udp_descriptor = std::make_shared(); + reader.disable_builtin_transport() .add_user_transport_to_pparams(sub_shm_descriptor) .add_user_transport_to_pparams(sub_udp_descriptor) - .data_sharing(enable_datasharing) .reliability(BEST_EFFORT_RELIABILITY_QOS) .durability_kind(VOLATILE_DURABILITY_QOS) .history_kind(KEEP_ALL_HISTORY_QOS) - .add_to_unicast_locator_list("localhost", conditions.sub_unicast_port) - .add_to_metatraffic_unicast_locator_list("localhost", conditions.sub_metatraffic_unicast_port) + // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) + // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) + // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) + // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) .init(); ASSERT_TRUE(reader.isInitialized()); - //reader.unicastLocatorList() - // get locator list and obtain port - auto pub_shm_descriptor = std::make_shared(); pub_shm_descriptor->segment_size(2 * 1024 * 1024); - auto pub_udp_descriptor = std::make_shared(); + writer.disable_builtin_transport() .add_user_transport_to_pparams(pub_shm_descriptor) .add_user_transport_to_pparams(pub_udp_descriptor) - .data_sharing(enable_datasharing) .reliability(BEST_EFFORT_RELIABILITY_QOS) .durability_kind(VOLATILE_DURABILITY_QOS) .history_kind(KEEP_ALL_HISTORY_QOS) .asynchronously(SYNCHRONOUS_PUBLISH_MODE) - .add_to_unicast_locator_list("localhost", conditions.pub_unicast_port) - .add_to_metatraffic_unicast_locator_list("localhost", conditions.pub_metatraffic_unicast_port) .init(); ASSERT_TRUE(writer.isInitialized()); @@ -152,14 +139,20 @@ TEST_P(RTPS, Transport_SHM_UDP_test) // Check that reader receives the unmatched. reader.block_for_all(); - // check that no data has been received in the udp transport - uint32_t n_packages_sent = sizeof(uint32_t); + // check that no (user) data has been sent via UDP transport + // TODO: check no data is sent for a specific port (set with add_to_default_unicast_locator_list or + // add_to_unicast_locator_list). Currently this cannot be achieved, as adding a non-default UDP locator makes it + // necessary to also add a non-default SHM one (if SHM communication is desired, as it is the case), but this cannot + // be done until the creation of SHM locators is exposed (currently available in internal SHMLocator::create_locator). + // As a workaround, it is checked that no user data is sent at any port, knowing that metatraffic ports are always + // even and user ones odd. + // uint32_t n_packages_sent = test_UDPv4Transport::messages_sent[conditions.sub_unicast_port]; + uint32_t n_packages_sent = 0; for (std::map::iterator it = test_UDPv4Transport::messages_sent.begin(); it != test_UDPv4Transport::messages_sent.end(); ++it) { - std::cout << "port: " << it->first << ", n_packages: " << it->second << std::endl; - if (it->first == conditions.pub_unicast_port) + if (it->first % 2) { - n_packages_sent = it->second; + n_packages_sent += it->second; } } ASSERT_EQ(n_packages_sent, 0u); @@ -171,10 +164,10 @@ TEST_P(RTPS, Transport_SHM_UDP_test) #define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_CASE_P(x, y, z, w) #endif // ifdef INSTANTIATE_TEST_SUITE_P -GTEST_INSTANTIATE_TEST_MACRO(RTPS, - RTPS, +GTEST_INSTANTIATE_TEST_MACRO(SHMUDP, + SHMUDP, testing::Values(TRANSPORT, INTRAPROCESS, DATASHARING), - [](const testing::TestParamInfo& info) + [](const testing::TestParamInfo& info) { switch (info.param) { From 61dd20d8d9f58c04736cb50f18362078f650e121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Wed, 5 Jul 2023 15:00:27 +0200 Subject: [PATCH 04/11] Add fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- .../rtps/participant/RTPSParticipantImpl.cpp | 19 +++++++++++++++++++ .../rtps/participant/RTPSParticipantImpl.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index a28b190610d..05003d6a30a 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -734,6 +734,9 @@ bool RTPSParticipantImpl::create_writer( return false; } + // Use participant's external locators if writer has none + setupExternalLocators(SWriter); + #if HAVE_SECURITY if (!is_builtin) { @@ -864,6 +867,11 @@ bool RTPSParticipantImpl::create_reader( return false; } + // Use participant's external locators if reader has none + // WARNING: call before createAndAssociateReceiverswithEndpoint, as the latter intentionally clears external + // locators list when using unique_flows feature + setupExternalLocators(SReader); + #if HAVE_SECURITY if (!is_builtin) @@ -1658,6 +1666,17 @@ bool RTPSParticipantImpl::createSendResources( return true; } +void RTPSParticipantImpl::setupExternalLocators( + Endpoint* pend) +{ + auto& attributes = pend->getAttributes(); + if (attributes.external_unicast_locators.empty()) + { + // Take external locators from the participant. + attributes.external_unicast_locators = m_att.default_external_unicast_locators; + } +} + bool RTPSParticipantImpl::createReceiverResources( LocatorList_t& Locator_list, bool ApplyMutation, diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.h b/src/cpp/rtps/participant/RTPSParticipantImpl.h index 7c7e1f72949..df1a207e9aa 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.h +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.h @@ -642,6 +642,12 @@ class RTPSParticipantImpl bool createSendResources( Endpoint* pend); + /** Add participant's external locators to endpoint's when none available + @param pend - Pointer to the endpoint whose external locators are to be set + */ + void setupExternalLocators( + Endpoint* pend); + /** When we want to create a new Resource but the physical channel specified by the Locator can not be opened, we want to mutate the Locator to open a more or less equivalent channel. @param loc - Locator we want to change From fbdbd2ca8e4df0b0d3cc345e8768b55a54ba7932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Wed, 5 Jul 2023 15:39:42 +0200 Subject: [PATCH 05/11] Uncrustify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- src/cpp/rtps/transport/test_UDPv4Transport.cpp | 2 +- src/cpp/rtps/transport/test_UDPv4Transport.h | 2 +- .../common/DDSBlackboxTestsTransportSHMUDP.cpp | 17 ++++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index aac8ae87fa8..efaaf07b06f 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -41,7 +41,7 @@ test_UDPv4TransportDescriptor::DestinationLocatorFilter test_UDPv4Transport::loc { return false; }); -std::map test_UDPv4Transport::messages_sent{}; +std::map test_UDPv4Transport::messages_sent{}; test_UDPv4Transport::test_UDPv4Transport( const test_UDPv4TransportDescriptor& descriptor) diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index fbb4b498080..c9145ddbe86 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -63,7 +63,7 @@ class test_UDPv4Transport : public UDPv4Transport RTPS_DllAPI static test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter; // Record the number of packages sent to the different ports (key) - RTPS_DllAPI static std::map messages_sent; + RTPS_DllAPI static std::map messages_sent; protected: diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index 92e454f8038..c59f72f2fbb 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -85,9 +85,11 @@ class SHMUDP : public testing::TestWithParam TEST_P(SHMUDP, Transport_SHM_UDP_test) { - static struct test_conditions{ + static struct test_conditions + { uint32_t sub_unicast_port = 7527; - } conditions; + } + conditions; // Set up PubSubReader reader(TEST_TOPIC_NAME); @@ -104,10 +106,10 @@ TEST_P(SHMUDP, Transport_SHM_UDP_test) .reliability(BEST_EFFORT_RELIABILITY_QOS) .durability_kind(VOLATILE_DURABILITY_QOS) .history_kind(KEEP_ALL_HISTORY_QOS) - // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) - // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) - // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) - // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) + // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) + // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) + // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) + // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) .init(); ASSERT_TRUE(reader.isInitialized()); @@ -148,7 +150,8 @@ TEST_P(SHMUDP, Transport_SHM_UDP_test) // even and user ones odd. // uint32_t n_packages_sent = test_UDPv4Transport::messages_sent[conditions.sub_unicast_port]; uint32_t n_packages_sent = 0; - for (std::map::iterator it = test_UDPv4Transport::messages_sent.begin(); it != test_UDPv4Transport::messages_sent.end(); ++it) + for (std::map::iterator it = test_UDPv4Transport::messages_sent.begin(); + it != test_UDPv4Transport::messages_sent.end(); ++it) { if (it->first % 2) { From 9f245e56b764ae9df288b149780e203a2c4a14e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Thu, 6 Jul 2023 14:46:37 +0200 Subject: [PATCH 06/11] Apply suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- .../rtps/participant/RTPSParticipantImpl.cpp | 12 +++--- .../rtps/participant/RTPSParticipantImpl.h | 6 +-- .../rtps/transport/test_UDPv4Transport.cpp | 1 + .../DDSBlackboxTestsTransportSHMUDP.cpp | 41 +++++++++++-------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index 05003d6a30a..9634443b027 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -735,7 +735,9 @@ bool RTPSParticipantImpl::create_writer( } // Use participant's external locators if writer has none - setupExternalLocators(SWriter); + // WARNING: call before createAndAssociateReceiverswithEndpoint, as the latter intentionally clears external + // locators list when using unique_flows feature + setup_external_locators(SWriter); #if HAVE_SECURITY if (!is_builtin) @@ -870,7 +872,7 @@ bool RTPSParticipantImpl::create_reader( // Use participant's external locators if reader has none // WARNING: call before createAndAssociateReceiverswithEndpoint, as the latter intentionally clears external // locators list when using unique_flows feature - setupExternalLocators(SReader); + setup_external_locators(SReader); #if HAVE_SECURITY @@ -1666,10 +1668,10 @@ bool RTPSParticipantImpl::createSendResources( return true; } -void RTPSParticipantImpl::setupExternalLocators( - Endpoint* pend) +void RTPSParticipantImpl::setup_external_locators( + Endpoint* endpoint) { - auto& attributes = pend->getAttributes(); + auto& attributes = endpoint->getAttributes(); if (attributes.external_unicast_locators.empty()) { // Take external locators from the participant. diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.h b/src/cpp/rtps/participant/RTPSParticipantImpl.h index df1a207e9aa..4674aa58ee8 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.h +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.h @@ -643,10 +643,10 @@ class RTPSParticipantImpl Endpoint* pend); /** Add participant's external locators to endpoint's when none available - @param pend - Pointer to the endpoint whose external locators are to be set + @param endpoint - Pointer to the endpoint whose external locators are to be set */ - void setupExternalLocators( - Endpoint* pend); + void setup_external_locators( + Endpoint* endpoint); /** When we want to create a new Resource but the physical channel specified by the Locator can not be opened, we want to mutate the Locator to open a more or less equivalent channel. diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index efaaf07b06f..122f2c04452 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -73,6 +73,7 @@ test_UDPv4Transport::test_UDPv4Transport( } test_UDPv4Transport_DropLog.clear(); test_UDPv4Transport_DropLogLength = descriptor.dropLogLength; + messages_sent.clear(); } test_UDPv4TransportDescriptor::test_UDPv4TransportDescriptor() diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index c59f72f2fbb..b154858da39 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -83,13 +83,15 @@ class SHMUDP : public testing::TestWithParam }; -TEST_P(SHMUDP, Transport_SHM_UDP_test) +void run_parametrized_test( + bool reliable_writer, + bool reliable_reader) { - static struct test_conditions - { - uint32_t sub_unicast_port = 7527; - } - conditions; + // Set test parameters + ReliabilityQosPolicyKind writer_reliability = + reliable_writer ? RELIABLE_RELIABILITY_QOS : BEST_EFFORT_RELIABILITY_QOS; + ReliabilityQosPolicyKind reader_reliability = + reliable_reader ? RELIABLE_RELIABILITY_QOS : BEST_EFFORT_RELIABILITY_QOS; // Set up PubSubReader reader(TEST_TOPIC_NAME); @@ -103,13 +105,9 @@ TEST_P(SHMUDP, Transport_SHM_UDP_test) reader.disable_builtin_transport() .add_user_transport_to_pparams(sub_shm_descriptor) .add_user_transport_to_pparams(sub_udp_descriptor) - .reliability(BEST_EFFORT_RELIABILITY_QOS) + .reliability(reader_reliability) .durability_kind(VOLATILE_DURABILITY_QOS) .history_kind(KEEP_ALL_HISTORY_QOS) - // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) - // .add_to_default_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) - // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port) - // .add_to_unicast_locator_list("127.0.0.1", conditions.sub_unicast_port, true) // SHM (extend method) .init(); ASSERT_TRUE(reader.isInitialized()); @@ -120,7 +118,7 @@ TEST_P(SHMUDP, Transport_SHM_UDP_test) writer.disable_builtin_transport() .add_user_transport_to_pparams(pub_shm_descriptor) .add_user_transport_to_pparams(pub_udp_descriptor) - .reliability(BEST_EFFORT_RELIABILITY_QOS) + .reliability(writer_reliability) .durability_kind(VOLATILE_DURABILITY_QOS) .history_kind(KEEP_ALL_HISTORY_QOS) .asynchronously(SYNCHRONOUS_PUBLISH_MODE) @@ -150,17 +148,28 @@ TEST_P(SHMUDP, Transport_SHM_UDP_test) // even and user ones odd. // uint32_t n_packages_sent = test_UDPv4Transport::messages_sent[conditions.sub_unicast_port]; uint32_t n_packages_sent = 0; - for (std::map::iterator it = test_UDPv4Transport::messages_sent.begin(); - it != test_UDPv4Transport::messages_sent.end(); ++it) + for (const std::pair& item : test_UDPv4Transport::messages_sent) { - if (it->first % 2) + if (item.first % 2) { - n_packages_sent += it->second; + n_packages_sent += item.second; } } ASSERT_EQ(n_packages_sent, 0u); } +TEST_P(SHMUDP, Transport_SHM_UDP_test) +{ + // Test BEST_EFFORT writer and reader + run_parametrized_test(false, false); + + // Test RELIABLE writer and BEST_EFFORT reader + run_parametrized_test(true, false); + + // Test RELIABLE writer and reader + run_parametrized_test(true, true); +} + #ifdef INSTANTIATE_TEST_SUITE_P #define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w) #else From 1ad167e944f19429ce6164475b872a1a4e64f416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Thu, 6 Jul 2023 15:03:33 +0200 Subject: [PATCH 07/11] Separate parametrized tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index b154858da39..e8d5cd8b9a9 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -158,14 +158,20 @@ void run_parametrized_test( ASSERT_EQ(n_packages_sent, 0u); } -TEST_P(SHMUDP, Transport_SHM_UDP_test) +TEST_P(SHMUDP, Transport_BestEffort_BestEffort_test) { // Test BEST_EFFORT writer and reader run_parametrized_test(false, false); +} +TEST_P(SHMUDP, Transport_Reliable_BestEffort_test) +{ // Test RELIABLE writer and BEST_EFFORT reader run_parametrized_test(true, false); +} +TEST_P(SHMUDP, Transport_Reliable_Reliable_test) +{ // Test RELIABLE writer and reader run_parametrized_test(true, true); } From dbb0d65c2d25c553ab8993b577e9918917aaeaa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Fri, 7 Jul 2023 08:35:28 +0200 Subject: [PATCH 08/11] Issue test compilation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index e8d5cd8b9a9..4c1348e7ba6 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -148,7 +148,7 @@ void run_parametrized_test( // even and user ones odd. // uint32_t n_packages_sent = test_UDPv4Transport::messages_sent[conditions.sub_unicast_port]; uint32_t n_packages_sent = 0; - for (const std::pair& item : test_UDPv4Transport::messages_sent) + for (const auto& item : test_UDPv4Transport::messages_sent) { if (item.first % 2) { From 9f47201864da9ea7a6f585f34df98e72ab62a54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Fri, 7 Jul 2023 12:31:46 +0200 Subject: [PATCH 09/11] Make messages_sent an object attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- src/cpp/rtps/transport/test_UDPv4Transport.cpp | 6 ++++-- src/cpp/rtps/transport/test_UDPv4Transport.h | 3 ++- test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index 122f2c04452..6c89b1e5b38 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -32,6 +32,7 @@ using SubmessageHeader_t = fastrtps::rtps::SubmessageHeader_t; using SequenceNumber_t = fastrtps::rtps::SequenceNumber_t; using EntityId_t = fastrtps::rtps::EntityId_t; +std::map test_UDPv4Transport::created_transports{}; std::vector> test_UDPv4Transport::test_UDPv4Transport_DropLog; std::atomic test_UDPv4Transport::test_UDPv4Transport_DropLogLength(0); std::atomic test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork(false); @@ -41,7 +42,6 @@ test_UDPv4TransportDescriptor::DestinationLocatorFilter test_UDPv4Transport::loc { return false; }); -std::map test_UDPv4Transport::messages_sent{}; test_UDPv4Transport::test_UDPv4Transport( const test_UDPv4TransportDescriptor& descriptor) @@ -122,7 +122,9 @@ test_UDPv4TransportDescriptor::test_UDPv4TransportDescriptor() TransportInterface* test_UDPv4TransportDescriptor::create_transport() const { - return new test_UDPv4Transport(*this); + test_UDPv4Transport* transport = new test_UDPv4Transport(*this); + test_UDPv4Transport::created_transports[this] = transport; + return transport; } bool test_UDPv4TransportDescriptor::operator ==( diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index c9145ddbe86..c2deaccd5b8 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -53,6 +53,7 @@ class test_UDPv4Transport : public UDPv4Transport virtual LocatorList NormalizeLocator( const Locator& locator) override; + RTPS_DllAPI static std::map created_transports; RTPS_DllAPI static std::atomic test_UDPv4Transport_ShutdownAllNetwork; // Handle to a persistent log of dropped packets. Defaults to length 0 (no logging) to prevent wasted resources. RTPS_DllAPI static std::vector> test_UDPv4Transport_DropLog; @@ -63,7 +64,7 @@ class test_UDPv4Transport : public UDPv4Transport RTPS_DllAPI static test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter; // Record the number of packages sent to the different ports (key) - RTPS_DllAPI static std::map messages_sent; + RTPS_DllAPI std::map messages_sent; protected: diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index 4c1348e7ba6..54f8052afd1 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -148,7 +148,7 @@ void run_parametrized_test( // even and user ones odd. // uint32_t n_packages_sent = test_UDPv4Transport::messages_sent[conditions.sub_unicast_port]; uint32_t n_packages_sent = 0; - for (const auto& item : test_UDPv4Transport::messages_sent) + for (const auto& item : test_UDPv4Transport::created_transports[pub_udp_descriptor.get()]->messages_sent) { if (item.first % 2) { From 2950f42c1197880bf7cd752344362a7fad967534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Mon, 10 Jul 2023 10:13:48 +0200 Subject: [PATCH 10/11] Get rid of messages_sent and use object's locator_filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- .../rtps/transport/test_UDPv4Transport.cpp | 7 +----- src/cpp/rtps/transport/test_UDPv4Transport.h | 4 ---- .../DDSBlackboxTestsTransportSHMUDP.cpp | 22 ++++++++++--------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index 6c89b1e5b38..e680b888451 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -32,7 +32,6 @@ using SubmessageHeader_t = fastrtps::rtps::SubmessageHeader_t; using SequenceNumber_t = fastrtps::rtps::SequenceNumber_t; using EntityId_t = fastrtps::rtps::EntityId_t; -std::map test_UDPv4Transport::created_transports{}; std::vector> test_UDPv4Transport::test_UDPv4Transport_DropLog; std::atomic test_UDPv4Transport::test_UDPv4Transport_DropLogLength(0); std::atomic test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork(false); @@ -73,7 +72,6 @@ test_UDPv4Transport::test_UDPv4Transport( } test_UDPv4Transport_DropLog.clear(); test_UDPv4Transport_DropLogLength = descriptor.dropLogLength; - messages_sent.clear(); } test_UDPv4TransportDescriptor::test_UDPv4TransportDescriptor() @@ -122,9 +120,7 @@ test_UDPv4TransportDescriptor::test_UDPv4TransportDescriptor() TransportInterface* test_UDPv4TransportDescriptor::create_transport() const { - test_UDPv4Transport* transport = new test_UDPv4Transport(*this); - test_UDPv4Transport::created_transports[this] = transport; - return transport; + return new test_UDPv4Transport(*this); } bool test_UDPv4TransportDescriptor::operator ==( @@ -255,7 +251,6 @@ bool test_UDPv4Transport::send( } else { - messages_sent[remote_locator.port]++; return UDPv4Transport::send(send_buffer, send_buffer_size, socket, remote_locator, only_multicast_purpose, whitelisted, timeout); } diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index c2deaccd5b8..93a611675fc 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -53,7 +53,6 @@ class test_UDPv4Transport : public UDPv4Transport virtual LocatorList NormalizeLocator( const Locator& locator) override; - RTPS_DllAPI static std::map created_transports; RTPS_DllAPI static std::atomic test_UDPv4Transport_ShutdownAllNetwork; // Handle to a persistent log of dropped packets. Defaults to length 0 (no logging) to prevent wasted resources. RTPS_DllAPI static std::vector> test_UDPv4Transport_DropLog; @@ -63,9 +62,6 @@ class test_UDPv4Transport : public UDPv4Transport RTPS_DllAPI static test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter; - // Record the number of packages sent to the different ports (key) - RTPS_DllAPI std::map messages_sent; - protected: virtual void get_ips( diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index 54f8052afd1..ce7d53dcb9a 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -113,7 +113,18 @@ void run_parametrized_test( auto pub_shm_descriptor = std::make_shared(); pub_shm_descriptor->segment_size(2 * 1024 * 1024); + auto pub_udp_descriptor = std::make_shared(); + std::atomic messages_on_odd_port{ 0 }; // Messages corresponding to user data + pub_udp_descriptor->locator_filter_ = [&messages_on_odd_port]( + const eprosima::fastdds::rtps::Locator& destination) + { + if (destination.port % 2) + { + ++messages_on_odd_port; + } + return false; + }; writer.disable_builtin_transport() .add_user_transport_to_pparams(pub_shm_descriptor) @@ -146,16 +157,7 @@ void run_parametrized_test( // be done until the creation of SHM locators is exposed (currently available in internal SHMLocator::create_locator). // As a workaround, it is checked that no user data is sent at any port, knowing that metatraffic ports are always // even and user ones odd. - // uint32_t n_packages_sent = test_UDPv4Transport::messages_sent[conditions.sub_unicast_port]; - uint32_t n_packages_sent = 0; - for (const auto& item : test_UDPv4Transport::created_transports[pub_udp_descriptor.get()]->messages_sent) - { - if (item.first % 2) - { - n_packages_sent += item.second; - } - } - ASSERT_EQ(n_packages_sent, 0u); + ASSERT_EQ(messages_on_odd_port, 0u); } TEST_P(SHMUDP, Transport_BestEffort_BestEffort_test) From 8bc81f71ecfff788105144aff219016de4b67598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20L=C3=B3pez=20Fern=C3=A1ndez?= Date: Mon, 10 Jul 2023 10:36:11 +0200 Subject: [PATCH 11/11] Apply suggestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan López Fernández --- test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp index ce7d53dcb9a..cbe06dba4b2 100644 --- a/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp +++ b/test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp @@ -119,7 +119,7 @@ void run_parametrized_test( pub_udp_descriptor->locator_filter_ = [&messages_on_odd_port]( const eprosima::fastdds::rtps::Locator& destination) { - if (destination.port % 2) + if (0 != (destination.port % 2)) { ++messages_on_odd_port; }