From f8263624e11330a9551e9b427da4d231b3239e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Wed, 18 Dec 2024 08:43:04 +0100 Subject: [PATCH] Improve PDPClients initialization (#5459) * Refs #21433: Add Test Signed-off-by: cferreiragonz * Refs #21433: Avoid using multicast metatraffic for CLIENTS & SUPER_CLIENTS Signed-off-by: cferreiragonz * Refs #21433: Typo Signed-off-by: cferreiragonz --------- Signed-off-by: cferreiragonz (cherry picked from commit 451847c6d5254077f4e8a839d5a8a582fcf5e861) --- .../discovery/participant/PDPClient.cpp | 2 +- .../rtps/participant/RTPSParticipantImpl.cpp | 10 ++++++--- .../dds/participant/ParticipantTests.cpp | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index b5ade4acbf9..4db528da099 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -192,7 +192,7 @@ ParticipantProxyData* PDPClient::createParticipantProxyData( ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, is_server, &participant_data); if (pdata != nullptr) { - // Clients only assert its server lifeliness, other clients liveliness is provided + // Clients only assert its server liveliness, other clients liveliness is provided // through server's PDP discovery data if (is_server) { diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index baa4deecb0b..12bb2f9c136 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -2728,9 +2728,13 @@ void RTPSParticipantImpl::get_default_metatraffic_locators( { uint32_t metatraffic_multicast_port = att.port.getMulticastPort(domain_id_); - m_network_Factory.getDefaultMetatrafficMulticastLocators(att.builtin.metatrafficMulticastLocatorList, - metatraffic_multicast_port); - m_network_Factory.NormalizeLocators(att.builtin.metatrafficMulticastLocatorList); + if (m_att.builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::CLIENT && + m_att.builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::SUPER_CLIENT) + { + m_network_Factory.getDefaultMetatrafficMulticastLocators(att.builtin.metatrafficMulticastLocatorList, + metatraffic_multicast_port); + m_network_Factory.NormalizeLocators(att.builtin.metatrafficMulticastLocatorList); + } m_network_Factory.getDefaultMetatrafficUnicastLocators(att.builtin.metatrafficUnicastLocatorList, metatraffic_unicast_port_); diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 1a383e557f4..23662a2e965 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -1043,6 +1043,28 @@ TEST(ParticipantTests, SimpleParticipantRemoteServerListConfiguration) EXPECT_EQ(RETCODE_OK, DomainParticipantFactory::get_instance()->delete_participant(participant)); } +/** + * Test that checks a CLIENT participant is not initialized with builtin metatrafficMulticastLocators. + */ +TEST(ParticipantTests, NoBuiltinMetatrafficMulticastForClients) +{ + DomainParticipantQos qos; + qos.wire_protocol().builtin.discovery_config.discoveryProtocol = fastdds::rtps::DiscoveryProtocol::CLIENT; + DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant( + (uint32_t)GET_PID() % 230, qos); + ASSERT_NE(nullptr, participant); + + fastdds::rtps::RTPSParticipantAttributes attributes; + get_rtps_attributes(participant, attributes); + EXPECT_EQ(attributes.builtin.discovery_config.discoveryProtocol, fastdds::rtps::DiscoveryProtocol::CLIENT); + EXPECT_EQ(attributes.builtin.metatrafficMulticastLocatorList.size(), 0); + + DomainParticipantQos result_qos = participant->get_qos(); + EXPECT_EQ(RETCODE_OK, participant->set_qos(result_qos)); + + EXPECT_EQ(RETCODE_OK, DomainParticipantFactory::get_instance()->delete_participant(participant)); +} + /** * Test that a SIMPLE participant is transformed into a CLIENT if the variable ROS_SUPER_CLIENT is false and into a SUPERCLIENT if it's true.