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

Add participant locators if new network interfaces are found [12753] #2336

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
19 changes: 14 additions & 5 deletions src/cpp/fastdds/domain/DomainParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,21 @@ ReturnCode_t DomainParticipantImpl::set_qos(
return ReturnCode_t::RETCODE_IMMUTABLE_POLICY;
}

if (set_qos(qos_, qos_to_set, !enabled) && enabled)
bool qos_should_be_updated = set_qos(qos_, qos_to_set, !enabled);
if (enabled)
{
// Notify the participant that there is a QoS update
fastrtps::rtps::RTPSParticipantAttributes patt;
set_attributes_from_qos(patt, qos_);
rtps_participant_->update_attributes(patt);
if (qos_should_be_updated)
{
// Notify the participant that there is a QoS update
fastrtps::rtps::RTPSParticipantAttributes patt;
set_attributes_from_qos(patt, qos_);
rtps_participant_->update_attributes(patt);
}
else
{
// Trigger update of network interfaces by calling update_attributes
rtps_participant_->update_attributes(rtps_participant_->getRTPSParticipantAttributes());
}
}

return ReturnCode_t::RETCODE_OK;
Expand Down
227 changes: 131 additions & 96 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,7 @@ RTPSParticipantImpl::RTPSParticipantImpl(
/* INSERT DEFAULT MANDATORY MULTICAST LOCATORS HERE */
if (m_att.builtin.metatrafficMulticastLocatorList.empty() && m_att.builtin.metatrafficUnicastLocatorList.empty())
{
m_network_Factory.getDefaultMetatrafficMulticastLocators(m_att.builtin.metatrafficMulticastLocatorList,
metatraffic_multicast_port);
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficMulticastLocatorList);

m_network_Factory.getDefaultMetatrafficUnicastLocators(m_att.builtin.metatrafficUnicastLocatorList,
metatraffic_unicast_port);
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficUnicastLocatorList);
get_default_metatraffic_locators();
}
else
{
Expand Down Expand Up @@ -291,7 +285,6 @@ RTPSParticipantImpl::RTPSParticipantImpl(
}

// Creation of user locator and receiver resources
bool hasLocatorsDefined = true;
//If no default locators are defined we define some.
/* The reasoning here is the following.
If the parameters of the RTPS Participant don't hold default listening locators for the creation
Expand All @@ -303,9 +296,9 @@ RTPSParticipantImpl::RTPSParticipantImpl(
{
//Default Unicast Locators in case they have not been provided
/* INSERT DEFAULT UNICAST LOCATORS FOR THE PARTICIPANT */
hasLocatorsDefined = false;

m_network_Factory.getDefaultUnicastLocators(domain_id_, m_att.defaultUnicastLocatorList, m_att);
get_default_unicast_locators();
logInfo(RTPS_PARTICIPANT, m_att.getName() << " Created with NO default Unicast Locator List, adding Locators:"
<< m_att.defaultUnicastLocatorList);
}
else
{
Expand All @@ -315,22 +308,13 @@ RTPSParticipantImpl::RTPSParticipantImpl(
{
m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, false);
});
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);

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);
});

}

// Normalize unicast locators.
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);

if (!hasLocatorsDefined)
{
logInfo(RTPS_PARTICIPANT, m_att.getName() << " Created with NO default Unicast Locator List, adding Locators:"
<< m_att.defaultUnicastLocatorList);
}

#if HAVE_SECURITY
Expand Down Expand Up @@ -1167,110 +1151,140 @@ bool RTPSParticipantImpl::registerReader(
void RTPSParticipantImpl::update_attributes(
const RTPSParticipantAttributes& patt)
{
// Check if there are changes
if (patt.builtin.discovery_config.m_DiscoveryServers == m_att.builtin.discovery_config.m_DiscoveryServers
&& patt.userData == m_att.userData)
bool update_pdp = false;
// Check if new interfaces have been added
if (patt.builtin.metatrafficMulticastLocatorList.empty() && patt.builtin.metatrafficUnicastLocatorList.empty())
{
return;
LocatorList_t metatraffic_multicast_locator_list = m_att.builtin.metatrafficMulticastLocatorList;
LocatorList_t metatraffic_unicast_locator_list = m_att.builtin.metatrafficUnicastLocatorList;

get_default_metatraffic_locators();

if (!(metatraffic_multicast_locator_list == m_att.builtin.metatrafficMulticastLocatorList) ||
!(metatraffic_unicast_locator_list == m_att.builtin.metatrafficUnicastLocatorList))
{
update_pdp = true;
logInfo(RTPS_PARTICIPANT, m_att.getName() << " updated its metatraffic locators");
}
}
if (patt.defaultUnicastLocatorList.empty() && patt.defaultMulticastLocatorList.empty())
{
LocatorList_t default_unicast_locator_list = m_att.defaultUnicastLocatorList;
get_default_unicast_locators();
if (!(default_unicast_locator_list == m_att.defaultUnicastLocatorList))
{
update_pdp = true;
logInfo(RTPS_PARTICIPANT, m_att.getName() << " updated default unicast locator list, current locators: "
<< m_att.defaultUnicastLocatorList);
}
}

// Check that the remote servers list is consistent: all the already known remote servers must be included in the
// list and only new remote servers can be added.
for (auto existing_server : m_att.builtin.discovery_config.m_DiscoveryServers)
auto pdp = mp_builtinProtocols->mp_PDP;
// Check if there are changes
if (patt.builtin.discovery_config.m_DiscoveryServers != m_att.builtin.discovery_config.m_DiscoveryServers
|| patt.userData != m_att.userData)
{
bool contained = false;
bool locator_contained = false;
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
update_pdp = true;
// Check that the remote servers list is consistent: all the already known remote servers must be included in the
// list and only new remote servers can be added.
for (auto existing_server : m_att.builtin.discovery_config.m_DiscoveryServers)
{
if (existing_server.guidPrefix == incoming_server.guidPrefix)
bool contained = false;
bool locator_contained = false;
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
{
for (auto incoming_locator : incoming_server.metatrafficUnicastLocatorList)
if (existing_server.guidPrefix == incoming_server.guidPrefix)
{
for (auto existing_locator : existing_server.metatrafficUnicastLocatorList)
for (auto incoming_locator : incoming_server.metatrafficUnicastLocatorList)
{
if (incoming_locator == existing_locator)
for (auto existing_locator : existing_server.metatrafficUnicastLocatorList)
{
locator_contained = true;
break;
if (incoming_locator == existing_locator)
{
locator_contained = true;
break;
}
}
if (!locator_contained)
{
logWarning(RTPS_QOS_CHECK,
"Discovery Servers cannot add/modify their locators: " << incoming_locator <<
" has not been added")
return;
}
}
if (!locator_contained)
{
logWarning(RTPS_QOS_CHECK,
"Discovery Servers cannot add/modify their locators: " << incoming_locator <<
" has not been added")
return;
}
contained = true;
break;
}
contained = true;
break;
}
if (!contained)
{
logWarning(RTPS_QOS_CHECK,
"Discovery Servers cannot be removed from the list; they can only be added");
return;
}
}
if (!contained)
{
logWarning(RTPS_QOS_CHECK,
"Discovery Servers cannot be removed from the list; they can only be added");
return;
}
}

// Update RTPSParticipantAttributes member
m_att.userData = patt.userData;
// Update RTPSParticipantAttributes member
m_att.userData = patt.userData;

auto pdp = mp_builtinProtocols->mp_PDP;
{
std::unique_lock<std::recursive_mutex> lock(*pdp->getMutex());
{
std::unique_lock<std::recursive_mutex> lock(*pdp->getMutex());

// Update user data
auto local_participant_proxy_data = pdp->getLocalParticipantProxyData();
local_participant_proxy_data->m_userData.data_vec(m_att.userData);
// Update user data
auto local_participant_proxy_data = pdp->getLocalParticipantProxyData();
local_participant_proxy_data->m_userData.data_vec(m_att.userData);

// Update remote servers list
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
{
// Add incoming servers iff we don't know about them already
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
// Update remote servers list
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
{
eprosima::fastdds::rtps::RemoteServerList_t::iterator server_it;
for (server_it = m_att.builtin.discovery_config.m_DiscoveryServers.begin();
server_it != m_att.builtin.discovery_config.m_DiscoveryServers.end(); server_it++)
// Add incoming servers iff we don't know about them already
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
{
if (server_it->guidPrefix == incoming_server.guidPrefix)
eprosima::fastdds::rtps::RemoteServerList_t::iterator server_it;
for (server_it = m_att.builtin.discovery_config.m_DiscoveryServers.begin();
server_it != m_att.builtin.discovery_config.m_DiscoveryServers.end(); server_it++)
{
break;
if (server_it->guidPrefix == incoming_server.guidPrefix)
{
break;
}
}
if (server_it == m_att.builtin.discovery_config.m_DiscoveryServers.end())
{
m_att.builtin.discovery_config.m_DiscoveryServers.push_back(incoming_server);
}
}
if (server_it == m_att.builtin.discovery_config.m_DiscoveryServers.end())
{
m_att.builtin.discovery_config.m_DiscoveryServers.push_back(incoming_server);
}
}

// Update the servers list in builtin protocols
mp_builtinProtocols->m_DiscoveryServers = m_att.builtin.discovery_config.m_DiscoveryServers;
// Update the servers list in builtin protocols
mp_builtinProtocols->m_DiscoveryServers = m_att.builtin.discovery_config.m_DiscoveryServers;

// Notify PDPServer
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
{
fastdds::rtps::PDPServer* pdp_server = static_cast<fastdds::rtps::PDPServer*>(pdp);
pdp_server->update_remote_servers_list();
}
// Notify PDPClient
else if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT)
{
fastdds::rtps::PDPClient* pdp_client = static_cast<fastdds::rtps::PDPClient*>(pdp);
pdp_client->update_remote_servers_list();
// Notify PDPServer
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
{
fastdds::rtps::PDPServer* pdp_server = static_cast<fastdds::rtps::PDPServer*>(pdp);
pdp_server->update_remote_servers_list();
}
// Notify PDPClient
else if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT)
{
fastdds::rtps::PDPClient* pdp_client = static_cast<fastdds::rtps::PDPClient*>(pdp);
pdp_client->update_remote_servers_list();
}
}
}
}

// Send DATA(P)
pdp->announceParticipantState(true);
if (update_pdp)
{
// Send DATA(P)
pdp->announceParticipantState(true);
}
}

bool RTPSParticipantImpl::updateLocalWriter(
Expand Down Expand Up @@ -2189,6 +2203,27 @@ void RTPSParticipantImpl::environment_file_has_changed()
}
}

void RTPSParticipantImpl::get_default_metatraffic_locators()
{
uint32_t metatraffic_multicast_port = m_att.port.getMulticastPort(domain_id_);
uint32_t metatraffic_unicast_port = m_att.port.getUnicastPort(domain_id_,
static_cast<uint32_t>(m_att.participantID));

m_network_Factory.getDefaultMetatrafficMulticastLocators(m_att.builtin.metatrafficMulticastLocatorList,
metatraffic_multicast_port);
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficMulticastLocatorList);

m_network_Factory.getDefaultMetatrafficUnicastLocators(m_att.builtin.metatrafficUnicastLocatorList,
metatraffic_unicast_port);
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficUnicastLocatorList);
}

void RTPSParticipantImpl::get_default_unicast_locators()
{
m_network_Factory.getDefaultUnicastLocators(domain_id_, m_att.defaultUnicastLocatorList, m_att);
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);
}

#ifdef FASTDDS_STATISTICS

bool RTPSParticipantImpl::register_in_writer(
Expand Down
10 changes: 10 additions & 0 deletions src/cpp/rtps/participant/RTPSParticipantImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,16 @@ class RTPSParticipantImpl
bool enable,
const Functor& callback);

/**
* Get default metatraffic locators when not provided by the user.
*/
void get_default_metatraffic_locators();

/**
* Get default unicast locators when not provided by the user.
*/
void get_default_unicast_locators();

public:

const RTPSParticipantAttributes& getRTPSParticipantAttributes() const
Expand Down
29 changes: 28 additions & 1 deletion src/cpp/rtps/transport/test_UDPv4Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <functional>

#include <asio.hpp>
#include <fastrtps/utils/IPLocator.h>

using namespace std;

Expand Down Expand Up @@ -153,6 +154,28 @@ void test_UDPv4Transport::get_ips(
}
}

LocatorList test_UDPv4Transport::NormalizeLocator(
const Locator& locator)
{
if (!simulate_no_interfaces)
{
return UDPv4Transport::NormalizeLocator(locator);
}

LocatorList list;
if (fastrtps::rtps::IPLocator::isAny(locator))
{
Locator newloc(locator);
fastrtps::rtps::IPLocator::setIPv4(newloc, "127.0.0.1");
list.push_back(newloc);
}
else
{
list.push_back(locator);
}
return list;
}

bool test_UDPv4Transport::send(
const octet* send_buffer,
uint32_t send_buffer_size,
Expand Down Expand Up @@ -199,7 +222,11 @@ bool test_UDPv4Transport::send(
bool only_multicast_purpose,
const std::chrono::microseconds& timeout)
{
if (packet_should_drop(send_buffer, send_buffer_size))
if (packet_should_drop(send_buffer, send_buffer_size) ||
// If there are no interfaces (simulate_no_interfaces), only multicast and localhost traffic is sent
(simulate_no_interfaces &&
!fastrtps::rtps::IPLocator::isMulticast(remote_locator) &&
!fastrtps::rtps::IPLocator::isLocal(remote_locator)))
{
statistics_info_.set_statistics_message_data(remote_locator, send_buffer, send_buffer_size);
log_drop(send_buffer, send_buffer_size);
Expand Down
Loading