diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt index 8997869c0..cfc405722 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt @@ -37,7 +37,8 @@ set(TEST_LIST 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) + end_to_end_local_communication_transient_local_disable_dynamic_discovery, + end_to_end_local_communication_original_writer_forwarding) set(TEST_NEEDED_SOURCES ) 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 7b54503f5..63dfcf064 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -206,6 +206,68 @@ void test_local_communication( router.stop(); } +template +void test_original_writer_forwarding( + DdsRouterConfiguration ddsrouter_configuration) +{ + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + MsgStruct sent_msg; + MsgStructType type; + std::string msg_str; + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + sent_msg.message(msg_str); + // Create DDS Publisher in domain 0 + TestPublisher publisher(type.is_compute_key_provided); + + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(type.is_compute_key_provided, true); + ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received)); + + // Create DdsRouter entity + DdsRouter router(ddsrouter_configuration); + router.start(); + + // CASE 1: Send message without original_writer_param, should be set to writers guid + sent_msg.index(++samples_sent); + ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK); + // Watiting for the message to be received + while (samples_received.load() < 1) + { + } + ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); + + // CASE 2: Send message with original_writer_param set to some value, value must be kept + sent_msg.index(++samples_sent); + eprosima::fastdds::rtps::WriteParams params_with_og_writer; + eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678); + params_with_og_writer.original_writer_info().original_writer_guid(guid); + ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK); + // Waiting for the message to be received + while (samples_received.load() < 2) + { + } + ASSERT_EQ(subscriber.original_writer_guid(), guid); + + // CASE 3: Send message with original_writer_param set to unknown, should be set to other value + sent_msg.index(++samples_sent); + eprosima::fastdds::rtps::WriteParams params; + params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown()); + ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK); + // Waiting for the message to be received + while (samples_received.load() < 3) + { + } + ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); + + router.stop(); +} + } /* namespace test */ /** @@ -322,6 +384,16 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami true); } +/** + * Test original writer forwarding 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_original_writer_forwarding) +{ + test::test_original_writer_forwarding( + test::dds_test_simple_configuration()); +} + int main( int argc, char** argv) 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 7a1dba444..d172eb7c7 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 @@ -152,6 +152,16 @@ class TestPublisher return writer_->write(&hello_); } + //! Publish a sample with parameters + eprosima::fastdds::dds::ReturnCode_t publish_with_params( + MsgStruct msg, + eprosima::fastdds::rtps::WriteParams params) + { + hello_.index(msg.index()); + hello_.message(msg.message()); + return writer_->write(&hello_, params); + } + //! Dispose instance eprosima::fastdds::dds::ReturnCode_t dispose_key( MsgStruct msg); @@ -162,6 +172,11 @@ class TestPublisher listener_.wait_discovery(n_subscribers); } + eprosima::fastdds::rtps::GUID_t original_writer_guid() const + { + return writer_->guid(); + } + private: MsgStruct hello_; @@ -357,6 +372,13 @@ class TestSubscriber return listener_.n_key_disposed; } + eprosima::fastdds::rtps::GUID_t original_writer_guid() + { + std::lock_guard lock(listener_.original_writer_guid_mtx); + eprosima::fastdds::rtps::GUID_t guid = listener_.original_writer_guid; + return guid; + } + private: eprosima::fastdds::dds::DomainParticipant* participant_; @@ -424,6 +446,11 @@ class TestSubscriber { n_key_disposed++; } + + { + std::lock_guard lock(original_writer_guid_mtx); + original_writer_guid = info.original_writer_info.original_writer_guid(); + } } } @@ -445,6 +472,12 @@ class TestSubscriber //! Placeholder where received data is stored MsgStruct msg_received; + //! Placeholder where original writer GUID is stored + eprosima::fastdds::rtps::GUID_t original_writer_guid; + + //! Protects original_writer_guid + std::mutex original_writer_guid_mtx; + std::atomic n_key_disposed; //! Reference to the sample sent by the publisher