From 83286e12e71e288b0574d4c36422e578be2c8960 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 6 Apr 2023 18:02:05 +0200 Subject: [PATCH] Refs #18002. User unicast port calculated on participant instead of NetworkFactory. Signed-off-by: Miguel Company --- src/cpp/rtps/network/NetworkFactory.cpp | 11 ++++----- src/cpp/rtps/network/NetworkFactory.h | 23 ++++++++----------- .../rtps/participant/RTPSParticipantImpl.cpp | 16 +++++++++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/cpp/rtps/network/NetworkFactory.cpp b/src/cpp/rtps/network/NetworkFactory.cpp index 154354b58f7..b3282cf828b 100644 --- a/src/cpp/rtps/network/NetworkFactory.cpp +++ b/src/cpp/rtps/network/NetworkFactory.cpp @@ -403,30 +403,27 @@ bool NetworkFactory::configureInitialPeerLocator( } bool NetworkFactory::getDefaultUnicastLocators( - uint32_t domain_id, LocatorList_t& locators, - const RTPSParticipantAttributes& m_att) const + uint32_t port) const { bool result = false; for (auto& transport : mRegisteredTransports) { - result |= transport->getDefaultUnicastLocators(locators, calculate_well_known_port(domain_id, m_att, false)); + result |= transport->getDefaultUnicastLocators(locators, port); } return result; } bool NetworkFactory::fill_default_locator_port( - uint32_t domain_id, Locator_t& locator, - const RTPSParticipantAttributes& m_att, - bool is_multicast) const + uint32_t port) const { bool result = false; for (auto& transport : mRegisteredTransports) { if (transport->IsLocatorSupported(locator)) { - result |= transport->fillUnicastLocator(locator, calculate_well_known_port(domain_id, m_att, is_multicast)); + result |= transport->fillUnicastLocator(locator, port); } } return result; diff --git a/src/cpp/rtps/network/NetworkFactory.h b/src/cpp/rtps/network/NetworkFactory.h index 21d21334028..6fd705763a6 100644 --- a/src/cpp/rtps/network/NetworkFactory.h +++ b/src/cpp/rtps/network/NetworkFactory.h @@ -227,18 +227,15 @@ class NetworkFactory * Add locators to the default unicast configuration. * */ bool getDefaultUnicastLocators( - uint32_t domain_id, LocatorList_t& locators, - const RTPSParticipantAttributes& m_att) const; + uint32_t port) const; /** * Fill the locator with the default unicast configuration. * */ bool fill_default_locator_port( - uint32_t domain_id, Locator_t& locator, - const RTPSParticipantAttributes& m_att, - bool is_multicast) const; + uint32_t port) const; /** * Shutdown method to close the connections of the transports. @@ -262,6 +259,14 @@ class NetworkFactory const LocatorList_t& remote_participant_locators, const LocatorList_t& participant_initial_peers) const; + /** + * Calculate well-known ports. + */ + uint16_t calculate_well_known_port( + uint32_t domain_id, + const RTPSParticipantAttributes& att, + bool is_multicast) const; + private: std::vector> mRegisteredTransports; @@ -278,14 +283,6 @@ class NetworkFactory // Mask using transport kinds to indicate whether the transports allows localhost NetworkConfigSet_t network_configuration_; - - /** - * Calculate well-known ports. - */ - uint16_t calculate_well_known_port( - uint32_t domain_id, - const RTPSParticipantAttributes& att, - bool is_multicast) const; }; } // namespace rtps diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index 1a4012ce9dc..e774e572052 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -499,17 +499,20 @@ void RTPSParticipantImpl::setup_user_traffic() else { // Locator with port 0, calculate port. + uint32_t unicast_port = metatraffic_unicast_port_ + m_att.port.offsetd3 - m_att.port.offsetd1; std::for_each(m_att.defaultUnicastLocatorList.begin(), m_att.defaultUnicastLocatorList.end(), [&](Locator_t& loc) { - m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, false); + m_network_Factory.fill_default_locator_port(loc, unicast_port); }); m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList); + // Locator with port 0, calculate port. + uint32_t multicast_port = m_network_Factory.calculate_well_known_port(domain_id_, m_att, true); std::for_each(m_att.defaultMulticastLocatorList.begin(), m_att.defaultMulticastLocatorList.end(), [&](Locator_t& loc) { - m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, true); + m_network_Factory.fill_default_locator_port(loc, multicast_port); }); } @@ -2097,13 +2100,15 @@ void RTPSParticipantImpl::normalize_endpoint_locators( EndpointAttributes& endpoint_att) { // Locators with port 0, calculate port. + uint32_t unicast_port = metatraffic_unicast_port_ + m_att.port.offsetd3 - m_att.port.offsetd1; for (Locator_t& loc : endpoint_att.unicastLocatorList) { - m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, false); + m_network_Factory.fill_default_locator_port(loc, unicast_port); } + uint32_t multicast_port = m_network_Factory.calculate_well_known_port(domain_id_, m_att, true); for (Locator_t& loc : endpoint_att.multicastLocatorList) { - m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, true); + m_network_Factory.fill_default_locator_port(loc, multicast_port); } // Normalize unicast locators @@ -2653,7 +2658,8 @@ void RTPSParticipantImpl::get_default_metatraffic_locators() void RTPSParticipantImpl::get_default_unicast_locators() { - m_network_Factory.getDefaultUnicastLocators(domain_id_, m_att.defaultUnicastLocatorList, m_att); + uint32_t unicast_port = metatraffic_unicast_port_ + m_att.port.offsetd3 - m_att.port.offsetd1; + m_network_Factory.getDefaultUnicastLocators(m_att.defaultUnicastLocatorList, unicast_port); m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList); }