Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StatelessWriter locators filtering [18950] #3655

Merged
merged 11 commits into from
Jul 11, 2023
12 changes: 7 additions & 5 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/rtps/participant/RTPSParticipantImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/cpp/rtps/transport/test_UDPv4Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ test_UDPv4Transport::test_UDPv4Transport(
}
test_UDPv4Transport_DropLog.clear();
test_UDPv4Transport_DropLogLength = descriptor.dropLogLength;
messages_sent.clear();
}

test_UDPv4TransportDescriptor::test_UDPv4TransportDescriptor()
Expand Down
41 changes: 25 additions & 16 deletions test/blackbox/common/DDSBlackboxTestsTransportSHMUDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ class SHMUDP : public testing::TestWithParam<communication_type>

};

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<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
Expand All @@ -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());

Expand All @@ -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)
Expand Down Expand Up @@ -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<uint32_t, uint32_t>::iterator it = test_UDPv4Transport::messages_sent.begin();
it != test_UDPv4Transport::messages_sent.end(); ++it)
for (const std::pair<uint32_t, uint32_t>& 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);
}
MiguelCompany marked this conversation as resolved.
Show resolved Hide resolved

#ifdef INSTANTIATE_TEST_SUITE_P
#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w)
#else
Expand Down