Skip to content

Commit

Permalink
Refs #18002. User unicast port calculated on participant instead of N…
Browse files Browse the repository at this point in the history
…etworkFactory.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Mar 12, 2024
1 parent ba5ebc6 commit 83286e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
11 changes: 4 additions & 7 deletions src/cpp/rtps/network/NetworkFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 10 additions & 13 deletions src/cpp/rtps/network/NetworkFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<std::unique_ptr<fastdds::rtps::TransportInterface>> mRegisteredTransports;
Expand All @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 83286e1

Please sign in to comment.