Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,71 @@ void test_local_communication(
router.stop();
}


template <class MsgStruct, class MsgStructType>
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<uint32_t> samples_received(0);
std::atomic<uint32_t> samples_to_receive(1);

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<MsgStruct> publisher(type.is_compute_key_provided);

ASSERT_TRUE(publisher.init(0));

// Create DDS Subscriber in domain 1
TestSubscriber<MsgStruct> 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 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() < 2)
{
}
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());

// CASE 3: 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() < 3)
{
}
ASSERT_EQ(subscriber.original_writer_guid(), guid);


router.stop();
}

} /* namespace test */

/**
Expand Down Expand Up @@ -322,6 +387,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<HelloWorld, HelloWorldPubSubType>(
test::dds_test_simple_configuration());
}

int main(
int argc,
char** argv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ 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);
Expand All @@ -162,6 +174,11 @@ class TestPublisher
listener_.wait_discovery(n_subscribers);
}

eprosima::fastdds::rtps::GUID_t original_writer_guid() const
{
return writer_->guid();
}

private:

MsgStruct hello_;
Expand Down Expand Up @@ -357,6 +374,11 @@ class TestSubscriber
return listener_.n_key_disposed;
}

eprosima::fastdds::rtps::GUID_t original_writer_guid() const
{
return listener_.original_writer_guid;
}

private:

eprosima::fastdds::dds::DomainParticipant* participant_;
Expand Down Expand Up @@ -424,6 +446,8 @@ class TestSubscriber
{
n_key_disposed++;
}

original_writer_guid = info.original_writer_info.original_writer_guid();
}
}

Expand All @@ -445,6 +469,9 @@ 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;

std::atomic<std::uint32_t> n_key_disposed;

//! Reference to the sample sent by the publisher
Expand Down
Loading