Skip to content

Commit f3b42cb

Browse files
authored
Add participant locators if new network interfaces are found (#2336)
* Refs #12754: refactor get default locators when not provided by the user Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: update interfaces RTPS layer Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: link to dds layer Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: linters Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: fix failing Participant tests Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: apply review suggestions Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: ensure PDP update Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12754: linters. Remove traces Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: override NormalizeLocator test_UDPv4Transport Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: add API to RTPS Blackbox Reader & Writer Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: add RTPS Blackbox test Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: drop unicast packets if simulating no interfaces Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: only run Transport case Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: improve test documentation Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: add DDS blackbox test Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: linters Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: apply review suggestions Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: fix Windows warning Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: improve test documentation Signed-off-by: JLBuenoLopez-eProsima <[email protected]> * Refs #12753: fix Windows warning Signed-off-by: JLBuenoLopez-eProsima <[email protected]>
1 parent cd7968e commit f3b42cb

13 files changed

+405
-123
lines changed

src/cpp/fastdds/domain/DomainParticipantImpl.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,21 @@ ReturnCode_t DomainParticipantImpl::set_qos(
345345
return ReturnCode_t::RETCODE_IMMUTABLE_POLICY;
346346
}
347347

348-
if (set_qos(qos_, qos_to_set, !enabled) && enabled)
348+
bool qos_should_be_updated = set_qos(qos_, qos_to_set, !enabled);
349+
if (enabled)
349350
{
350-
// Notify the participant that there is a QoS update
351-
fastrtps::rtps::RTPSParticipantAttributes patt;
352-
set_attributes_from_qos(patt, qos_);
353-
rtps_participant_->update_attributes(patt);
351+
if (qos_should_be_updated)
352+
{
353+
// Notify the participant that there is a QoS update
354+
fastrtps::rtps::RTPSParticipantAttributes patt;
355+
set_attributes_from_qos(patt, qos_);
356+
rtps_participant_->update_attributes(patt);
357+
}
358+
else
359+
{
360+
// Trigger update of network interfaces by calling update_attributes
361+
rtps_participant_->update_attributes(rtps_participant_->getRTPSParticipantAttributes());
362+
}
354363
}
355364

356365
return ReturnCode_t::RETCODE_OK;

src/cpp/rtps/participant/RTPSParticipantImpl.cpp

Lines changed: 131 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,7 @@ RTPSParticipantImpl::RTPSParticipantImpl(
243243
/* INSERT DEFAULT MANDATORY MULTICAST LOCATORS HERE */
244244
if (m_att.builtin.metatrafficMulticastLocatorList.empty() && m_att.builtin.metatrafficUnicastLocatorList.empty())
245245
{
246-
m_network_Factory.getDefaultMetatrafficMulticastLocators(m_att.builtin.metatrafficMulticastLocatorList,
247-
metatraffic_multicast_port);
248-
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficMulticastLocatorList);
249-
250-
m_network_Factory.getDefaultMetatrafficUnicastLocators(m_att.builtin.metatrafficUnicastLocatorList,
251-
metatraffic_unicast_port);
252-
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficUnicastLocatorList);
246+
get_default_metatraffic_locators();
253247
}
254248
else
255249
{
@@ -291,7 +285,6 @@ RTPSParticipantImpl::RTPSParticipantImpl(
291285
}
292286

293287
// Creation of user locator and receiver resources
294-
bool hasLocatorsDefined = true;
295288
//If no default locators are defined we define some.
296289
/* The reasoning here is the following.
297290
If the parameters of the RTPS Participant don't hold default listening locators for the creation
@@ -303,9 +296,9 @@ RTPSParticipantImpl::RTPSParticipantImpl(
303296
{
304297
//Default Unicast Locators in case they have not been provided
305298
/* INSERT DEFAULT UNICAST LOCATORS FOR THE PARTICIPANT */
306-
hasLocatorsDefined = false;
307-
308-
m_network_Factory.getDefaultUnicastLocators(domain_id_, m_att.defaultUnicastLocatorList, m_att);
299+
get_default_unicast_locators();
300+
logInfo(RTPS_PARTICIPANT, m_att.getName() << " Created with NO default Unicast Locator List, adding Locators:"
301+
<< m_att.defaultUnicastLocatorList);
309302
}
310303
else
311304
{
@@ -315,22 +308,13 @@ RTPSParticipantImpl::RTPSParticipantImpl(
315308
{
316309
m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, false);
317310
});
311+
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);
318312

319313
std::for_each(m_att.defaultMulticastLocatorList.begin(), m_att.defaultMulticastLocatorList.end(),
320314
[&](Locator_t& loc)
321315
{
322316
m_network_Factory.fill_default_locator_port(domain_id_, loc, m_att, true);
323317
});
324-
325-
}
326-
327-
// Normalize unicast locators.
328-
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);
329-
330-
if (!hasLocatorsDefined)
331-
{
332-
logInfo(RTPS_PARTICIPANT, m_att.getName() << " Created with NO default Unicast Locator List, adding Locators:"
333-
<< m_att.defaultUnicastLocatorList);
334318
}
335319

336320
#if HAVE_SECURITY
@@ -1176,110 +1160,140 @@ bool RTPSParticipantImpl::registerReader(
11761160
void RTPSParticipantImpl::update_attributes(
11771161
const RTPSParticipantAttributes& patt)
11781162
{
1179-
// Check if there are changes
1180-
if (patt.builtin.discovery_config.m_DiscoveryServers == m_att.builtin.discovery_config.m_DiscoveryServers
1181-
&& patt.userData == m_att.userData)
1163+
bool update_pdp = false;
1164+
// Check if new interfaces have been added
1165+
if (patt.builtin.metatrafficMulticastLocatorList.empty() && patt.builtin.metatrafficUnicastLocatorList.empty())
11821166
{
1183-
return;
1167+
LocatorList_t metatraffic_multicast_locator_list = m_att.builtin.metatrafficMulticastLocatorList;
1168+
LocatorList_t metatraffic_unicast_locator_list = m_att.builtin.metatrafficUnicastLocatorList;
1169+
1170+
get_default_metatraffic_locators();
1171+
1172+
if (!(metatraffic_multicast_locator_list == m_att.builtin.metatrafficMulticastLocatorList) ||
1173+
!(metatraffic_unicast_locator_list == m_att.builtin.metatrafficUnicastLocatorList))
1174+
{
1175+
update_pdp = true;
1176+
logInfo(RTPS_PARTICIPANT, m_att.getName() << " updated its metatraffic locators");
1177+
}
1178+
}
1179+
if (patt.defaultUnicastLocatorList.empty() && patt.defaultMulticastLocatorList.empty())
1180+
{
1181+
LocatorList_t default_unicast_locator_list = m_att.defaultUnicastLocatorList;
1182+
get_default_unicast_locators();
1183+
if (!(default_unicast_locator_list == m_att.defaultUnicastLocatorList))
1184+
{
1185+
update_pdp = true;
1186+
logInfo(RTPS_PARTICIPANT, m_att.getName() << " updated default unicast locator list, current locators: "
1187+
<< m_att.defaultUnicastLocatorList);
1188+
}
11841189
}
11851190

1186-
// Check that the remote servers list is consistent: all the already known remote servers must be included in the
1187-
// list and only new remote servers can be added.
1188-
for (auto existing_server : m_att.builtin.discovery_config.m_DiscoveryServers)
1191+
auto pdp = mp_builtinProtocols->mp_PDP;
1192+
// Check if there are changes
1193+
if (patt.builtin.discovery_config.m_DiscoveryServers != m_att.builtin.discovery_config.m_DiscoveryServers
1194+
|| patt.userData != m_att.userData)
11891195
{
1190-
bool contained = false;
1191-
bool locator_contained = false;
1192-
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
1196+
update_pdp = true;
1197+
// Check that the remote servers list is consistent: all the already known remote servers must be included in the
1198+
// list and only new remote servers can be added.
1199+
for (auto existing_server : m_att.builtin.discovery_config.m_DiscoveryServers)
11931200
{
1194-
if (existing_server.guidPrefix == incoming_server.guidPrefix)
1201+
bool contained = false;
1202+
bool locator_contained = false;
1203+
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
11951204
{
1196-
for (auto incoming_locator : incoming_server.metatrafficUnicastLocatorList)
1205+
if (existing_server.guidPrefix == incoming_server.guidPrefix)
11971206
{
1198-
for (auto existing_locator : existing_server.metatrafficUnicastLocatorList)
1207+
for (auto incoming_locator : incoming_server.metatrafficUnicastLocatorList)
11991208
{
1200-
if (incoming_locator == existing_locator)
1209+
for (auto existing_locator : existing_server.metatrafficUnicastLocatorList)
12011210
{
1202-
locator_contained = true;
1203-
break;
1211+
if (incoming_locator == existing_locator)
1212+
{
1213+
locator_contained = true;
1214+
break;
1215+
}
1216+
}
1217+
if (!locator_contained)
1218+
{
1219+
logWarning(RTPS_QOS_CHECK,
1220+
"Discovery Servers cannot add/modify their locators: " << incoming_locator <<
1221+
" has not been added")
1222+
return;
12041223
}
12051224
}
1206-
if (!locator_contained)
1207-
{
1208-
logWarning(RTPS_QOS_CHECK,
1209-
"Discovery Servers cannot add/modify their locators: " << incoming_locator <<
1210-
" has not been added")
1211-
return;
1212-
}
1225+
contained = true;
1226+
break;
12131227
}
1214-
contained = true;
1215-
break;
1228+
}
1229+
if (!contained)
1230+
{
1231+
logWarning(RTPS_QOS_CHECK,
1232+
"Discovery Servers cannot be removed from the list; they can only be added");
1233+
return;
12161234
}
12171235
}
1218-
if (!contained)
1219-
{
1220-
logWarning(RTPS_QOS_CHECK,
1221-
"Discovery Servers cannot be removed from the list; they can only be added");
1222-
return;
1223-
}
1224-
}
12251236

1226-
// Update RTPSParticipantAttributes member
1227-
m_att.userData = patt.userData;
1237+
// Update RTPSParticipantAttributes member
1238+
m_att.userData = patt.userData;
12281239

1229-
auto pdp = mp_builtinProtocols->mp_PDP;
1230-
{
1231-
std::unique_lock<std::recursive_mutex> lock(*pdp->getMutex());
1240+
{
1241+
std::unique_lock<std::recursive_mutex> lock(*pdp->getMutex());
12321242

1233-
// Update user data
1234-
auto local_participant_proxy_data = pdp->getLocalParticipantProxyData();
1235-
local_participant_proxy_data->m_userData.data_vec(m_att.userData);
1243+
// Update user data
1244+
auto local_participant_proxy_data = pdp->getLocalParticipantProxyData();
1245+
local_participant_proxy_data->m_userData.data_vec(m_att.userData);
12361246

1237-
// Update remote servers list
1238-
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
1239-
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT ||
1240-
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
1241-
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
1242-
{
1243-
// Add incoming servers iff we don't know about them already
1244-
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
1247+
// Update remote servers list
1248+
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
1249+
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT ||
1250+
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
1251+
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
12451252
{
1246-
eprosima::fastdds::rtps::RemoteServerList_t::iterator server_it;
1247-
for (server_it = m_att.builtin.discovery_config.m_DiscoveryServers.begin();
1248-
server_it != m_att.builtin.discovery_config.m_DiscoveryServers.end(); server_it++)
1253+
// Add incoming servers iff we don't know about them already
1254+
for (auto incoming_server : patt.builtin.discovery_config.m_DiscoveryServers)
12491255
{
1250-
if (server_it->guidPrefix == incoming_server.guidPrefix)
1256+
eprosima::fastdds::rtps::RemoteServerList_t::iterator server_it;
1257+
for (server_it = m_att.builtin.discovery_config.m_DiscoveryServers.begin();
1258+
server_it != m_att.builtin.discovery_config.m_DiscoveryServers.end(); server_it++)
12511259
{
1252-
break;
1260+
if (server_it->guidPrefix == incoming_server.guidPrefix)
1261+
{
1262+
break;
1263+
}
1264+
}
1265+
if (server_it == m_att.builtin.discovery_config.m_DiscoveryServers.end())
1266+
{
1267+
m_att.builtin.discovery_config.m_DiscoveryServers.push_back(incoming_server);
12531268
}
12541269
}
1255-
if (server_it == m_att.builtin.discovery_config.m_DiscoveryServers.end())
1256-
{
1257-
m_att.builtin.discovery_config.m_DiscoveryServers.push_back(incoming_server);
1258-
}
1259-
}
12601270

1261-
// Update the servers list in builtin protocols
1262-
mp_builtinProtocols->m_DiscoveryServers = m_att.builtin.discovery_config.m_DiscoveryServers;
1271+
// Update the servers list in builtin protocols
1272+
mp_builtinProtocols->m_DiscoveryServers = m_att.builtin.discovery_config.m_DiscoveryServers;
12631273

1264-
// Notify PDPServer
1265-
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
1266-
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
1267-
{
1268-
fastdds::rtps::PDPServer* pdp_server = static_cast<fastdds::rtps::PDPServer*>(pdp);
1269-
pdp_server->update_remote_servers_list();
1270-
}
1271-
// Notify PDPClient
1272-
else if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
1273-
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT)
1274-
{
1275-
fastdds::rtps::PDPClient* pdp_client = static_cast<fastdds::rtps::PDPClient*>(pdp);
1276-
pdp_client->update_remote_servers_list();
1274+
// Notify PDPServer
1275+
if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SERVER ||
1276+
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::BACKUP)
1277+
{
1278+
fastdds::rtps::PDPServer* pdp_server = static_cast<fastdds::rtps::PDPServer*>(pdp);
1279+
pdp_server->update_remote_servers_list();
1280+
}
1281+
// Notify PDPClient
1282+
else if (m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::CLIENT ||
1283+
m_att.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol::SUPER_CLIENT)
1284+
{
1285+
fastdds::rtps::PDPClient* pdp_client = static_cast<fastdds::rtps::PDPClient*>(pdp);
1286+
pdp_client->update_remote_servers_list();
1287+
}
12771288
}
12781289
}
12791290
}
12801291

1281-
// Send DATA(P)
1282-
pdp->announceParticipantState(true);
1292+
if (update_pdp)
1293+
{
1294+
// Send DATA(P)
1295+
pdp->announceParticipantState(true);
1296+
}
12831297
}
12841298

12851299
bool RTPSParticipantImpl::updateLocalWriter(
@@ -2198,6 +2212,27 @@ void RTPSParticipantImpl::environment_file_has_changed()
21982212
}
21992213
}
22002214

2215+
void RTPSParticipantImpl::get_default_metatraffic_locators()
2216+
{
2217+
uint32_t metatraffic_multicast_port = m_att.port.getMulticastPort(domain_id_);
2218+
uint32_t metatraffic_unicast_port = m_att.port.getUnicastPort(domain_id_,
2219+
static_cast<uint32_t>(m_att.participantID));
2220+
2221+
m_network_Factory.getDefaultMetatrafficMulticastLocators(m_att.builtin.metatrafficMulticastLocatorList,
2222+
metatraffic_multicast_port);
2223+
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficMulticastLocatorList);
2224+
2225+
m_network_Factory.getDefaultMetatrafficUnicastLocators(m_att.builtin.metatrafficUnicastLocatorList,
2226+
metatraffic_unicast_port);
2227+
m_network_Factory.NormalizeLocators(m_att.builtin.metatrafficUnicastLocatorList);
2228+
}
2229+
2230+
void RTPSParticipantImpl::get_default_unicast_locators()
2231+
{
2232+
m_network_Factory.getDefaultUnicastLocators(domain_id_, m_att.defaultUnicastLocatorList, m_att);
2233+
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);
2234+
}
2235+
22012236
#ifdef FASTDDS_STATISTICS
22022237

22032238
bool RTPSParticipantImpl::register_in_writer(

src/cpp/rtps/participant/RTPSParticipantImpl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,16 @@ class RTPSParticipantImpl
705705
bool enable,
706706
const Functor& callback);
707707

708+
/**
709+
* Get default metatraffic locators when not provided by the user.
710+
*/
711+
void get_default_metatraffic_locators();
712+
713+
/**
714+
* Get default unicast locators when not provided by the user.
715+
*/
716+
void get_default_unicast_locators();
717+
708718
public:
709719

710720
const RTPSParticipantAttributes& getRTPSParticipantAttributes() const

src/cpp/rtps/transport/test_UDPv4Transport.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <functional>
1919

2020
#include <asio.hpp>
21+
#include <fastrtps/utils/IPLocator.h>
2122

2223
using namespace std;
2324

@@ -153,6 +154,28 @@ void test_UDPv4Transport::get_ips(
153154
}
154155
}
155156

157+
LocatorList test_UDPv4Transport::NormalizeLocator(
158+
const Locator& locator)
159+
{
160+
if (!simulate_no_interfaces)
161+
{
162+
return UDPv4Transport::NormalizeLocator(locator);
163+
}
164+
165+
LocatorList list;
166+
if (fastrtps::rtps::IPLocator::isAny(locator))
167+
{
168+
Locator newloc(locator);
169+
fastrtps::rtps::IPLocator::setIPv4(newloc, "127.0.0.1");
170+
list.push_back(newloc);
171+
}
172+
else
173+
{
174+
list.push_back(locator);
175+
}
176+
return list;
177+
}
178+
156179
bool test_UDPv4Transport::send(
157180
const octet* send_buffer,
158181
uint32_t send_buffer_size,
@@ -199,7 +222,11 @@ bool test_UDPv4Transport::send(
199222
bool only_multicast_purpose,
200223
const std::chrono::microseconds& timeout)
201224
{
202-
if (packet_should_drop(send_buffer, send_buffer_size))
225+
if (packet_should_drop(send_buffer, send_buffer_size) ||
226+
// If there are no interfaces (simulate_no_interfaces), only multicast and localhost traffic is sent
227+
(simulate_no_interfaces &&
228+
!fastrtps::rtps::IPLocator::isMulticast(remote_locator) &&
229+
!fastrtps::rtps::IPLocator::isLocal(remote_locator)))
203230
{
204231
statistics_info_.set_statistics_message_data(remote_locator, send_buffer, send_buffer_size);
205232
log_drop(send_buffer, send_buffer_size);

0 commit comments

Comments
 (0)