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 cfc405722..9332e0f0f 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt @@ -38,7 +38,9 @@ set(TEST_LIST 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_original_writer_forwarding) + end_to_end_local_communication_original_writer_forwarding_unset, + end_to_end_local_communication_original_writer_forwarding_populated, + end_to_end_local_communication_original_writer_forwarding_unknown) 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 63dfcf064..f61c954a0 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -206,8 +206,12 @@ void test_local_communication( router.stop(); } +/** + * This test checks that, when the original writer parameter is not set by a writer, + * the router still sets it to the original writer's GUID when forwarding the message. + */ template -void test_original_writer_forwarding( +void test_original_writer_forwarding_unset( DdsRouterConfiguration ddsrouter_configuration) { INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); @@ -233,34 +237,104 @@ void test_original_writer_forwarding( DdsRouter router(ddsrouter_configuration); router.start(); - // CASE 1: Send message without original_writer_param, should be set to writers guid + // CASE: Send message without original_writer_param, it should be set to the original writers guid + // in the router either way 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 + router.stop(); +} + +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is not equal to unknown, the router keeps that value when forwarding the message. + */ +template +void test_original_writer_forwarding_populated( + 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: Send message with original_writer_param set to some value distinct to unknown, 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) + while (samples_received.load() < 1) { } ASSERT_EQ(subscriber.original_writer_guid(), guid); - // CASE 3: Send message with original_writer_param set to unknown, should be set to other value + router.stop(); +} + +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is equal to unknown, the router populates it with the original writer's GUID when forwarding the message. + */ +template +void test_original_writer_forwarding_unknown( + 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: 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) + while (samples_received.load() < 1) { } ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); @@ -385,12 +459,32 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami } /** - * 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. + * This test checks that, when the original writer parameter is not set by a writer, + * the router still sets it to the original writer's GUID when forwarding the message. + */ +TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unset) +{ + test::test_original_writer_forwarding_unset( + test::dds_test_simple_configuration()); +} + +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is not equal to unknown, the router keeps that value when forwarding the message. + */ +TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_populated) +{ + test::test_original_writer_forwarding_populated( + test::dds_test_simple_configuration()); +} + +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is equal to unknown, the router populates it with the original writer's GUID when forwarding the message. */ -TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding) +TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unknown) { - test::test_original_writer_forwarding( + test::test_original_writer_forwarding_unknown( test::dds_test_simple_configuration()); }