Skip to content

Extend DISCOVERY_TOPIC to include physical information [14006] #2549

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

Merged
merged 19 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0d27eca
Refs 14006: Extend DiscoveryTime
EduPonz Mar 2, 2022
beb386b
Refs 14006: Populate physical properties if empty
EduPonz Mar 3, 2022
836cf10
Refs 14006: Add empty physical properties if FASTDDS_STATISTICS is ac…
EduPonz Mar 3, 2022
bfdba84
Refs 14006: Add test for default constructed physical properties
EduPonz Mar 4, 2022
16c3873
Refs 14006: Add physical properties to DATA[p]
EduPonz Mar 4, 2022
19a3759
Refs 14006: Test that physical data is present in received Participan…
EduPonz Mar 5, 2022
945756c
Refs 14006: Add negative case to test
EduPonz Mar 5, 2022
d1454a0
Refs 14006: Address MSVC warning
EduPonz Mar 6, 2022
c113d9d
Refs 14006: Add physical information to DiscoveryTime samples
EduPonz Mar 7, 2022
b8bd9d8
Refs 14006: Add end-to-end discovery time with physical data positive…
EduPonz Mar 7, 2022
cd94801
Refs 14006: Correctly notify physical data to listener
EduPonz Mar 8, 2022
9f33461
Refs 14006: Improve discovery_topic_physical_data test
EduPonz Mar 8, 2022
8d718f4
Refs 14006: Extend discovery_topic_physical_data to cover all specifi…
EduPonz Mar 8, 2022
be6af62
Refs 14006: Update versions.md
EduPonz Mar 8, 2022
84ec9a5
Refs 14006: DomainParticipant properties in XML override values of th…
EduPonz Mar 8, 2022
eaf3c4c
Refs 14006: Fix compilation when FASTDDS_STATISTICS is not defined
EduPonz Mar 8, 2022
e2929d2
Refs 14006: Add test for setting physical properties using XML
EduPonz Mar 8, 2022
d916655
Refs 14006: Apply suggestions
EduPonz Mar 9, 2022
d9b2259
Refs 14006: Apply suggestions
EduPonz Mar 9, 2022
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
21 changes: 21 additions & 0 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,27 @@ const std::string parameter_property_ds_version = "DS_VERSION";
*/
const std::string parameter_property_current_ds_version = "2.0";

/**
* Parameter property value for Host physical data
*
* @ingroup PARAMETER_MODULE
*/
const char* const parameter_policy_physical_data_host = "fastdds.physical_data.host";

/**
* Parameter property value for User physical data
*
* @ingroup PARAMETER_MODULE
*/
const char* const parameter_policy_physical_data_user = "fastdds.physical_data.user";

/**
* Parameter property value for Process physical data
*
* @ingroup PARAMETER_MODULE
*/
const char* const parameter_policy_physical_data_process = "fastdds.physical_data.process";

/**
* @ingroup PARAMETER_MODULE
*/
Expand Down
12 changes: 12 additions & 0 deletions include/fastdds/dds/domain/qos/DomainParticipantQos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef _FASTDDS_PARTICIPANTQOS_HPP_
#define _FASTDDS_PARTICIPANTQOS_HPP_

#include <string>

#include <fastrtps/fastrtps_dll.h>
#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp>
Expand Down Expand Up @@ -50,6 +52,16 @@ class DomainParticipantQos
*/
RTPS_DllAPI DomainParticipantQos()
{
#ifdef FASTDDS_STATISTICS
/*
* In the case of Statistics, the following properties are set with an empty value. This is because if these
* properties are set and empty during the enabling of the DomainParticipant, they are fill with the default
* mechanism
*/
properties_.properties().emplace_back(parameter_policy_physical_data_host, "");
properties_.properties().emplace_back(parameter_policy_physical_data_user, "");
properties_.properties().emplace_back(parameter_policy_physical_data_process, "");
#endif // ifdef FASTDDS_STATISTICS
}

/**
Expand Down
4 changes: 3 additions & 1 deletion include/fastdds/rtps/builtin/discovery/participant/PDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ class PDP
*
* @param participant_guid GUID of the participant for which to create the proxy object.
* @param with_lease_duration indicates whether lease duration event should be created.
* @param participant_proxy_data The participant proxy data from which the copy is made (if provided)
*
* @return pointer to the currently inserted entry, nullptr if allocation limits were reached.
*/
ParticipantProxyData* add_participant_proxy_data(
const GUID_t& participant_guid,
bool with_lease_duration);
bool with_lease_duration,
const ParticipantProxyData* participant_proxy_data = nullptr);

/**
* Gets the key of a participant proxy data.
Expand Down
3 changes: 3 additions & 0 deletions include/fastdds/statistics/types.idl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct DiscoveryTime
@Key detail::GUID_s local_participant_guid;
@Key detail::GUID_s remote_entity_guid;
unsigned long long time;
string host;
string user;
string process;
};

struct EntityCount
Expand Down
31 changes: 30 additions & 1 deletion src/cpp/fastdds/domain/DomainParticipantFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,26 @@ namespace eprosima {
namespace fastdds {
namespace dds {

/**
* @brief Fill DomainParticipantQos from a given attributes RTPSParticipantAttributes object
*
* For the case of the non-binary properties, instead of the RTPSParticipantAttributes overriding the
* property list in the DomainParticipantQos, a merge is performed in the following manner:
*
* - If any property from the RTPSParticipantAttributes is not in the DomainParticipantQos, then it is appended
* to the DomainParticipantQos.
* - If any property from the RTPSParticipantAttributes property is also in the DomainParticipantQos, then the
* value in the DomainParticipantQos is overridden with that of the RTPSParticipantAttributes.
*
* @param[in, out] qos The DomainParticipantQos to set
* @param[in] attr The RTPSParticipantAttributes from which the @c qos is set.
*/
static void set_qos_from_attributes(
DomainParticipantQos& qos,
const eprosima::fastrtps::rtps::RTPSParticipantAttributes& attr)
{
qos.user_data().setValue(attr.userData);
qos.allocation() = attr.allocation;
qos.properties() = attr.properties;
qos.wire_protocol().prefix = attr.prefix;
qos.wire_protocol().participant_id = attr.participantID;
qos.wire_protocol().builtin = attr.builtin;
Expand All @@ -68,6 +81,22 @@ static void set_qos_from_attributes(
qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize;
qos.name() = attr.getName();
qos.flow_controllers() = attr.flow_controllers;

// Merge attributes and qos properties
for (auto property : attr.properties.properties())
{
std::string* property_value = fastrtps::rtps::PropertyPolicyHelper::find_property(
qos.properties(), property.name());
if (nullptr == property_value)
{
qos.properties().properties().emplace_back(property);
}
else
{
*property_value = property.value();
}
}
qos.properties().binary_properties() = attr.properties.binary_properties();
}

DomainParticipantFactory::DomainParticipantFactory()
Expand Down
51 changes: 39 additions & 12 deletions src/cpp/fastdds/domain/DomainParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,48 @@
*
*/

#include <chrono>
#include <string>

#include <asio.hpp>

#include <fastdds/domain/DomainParticipantImpl.hpp>

#include <fastdds/core/policy/QosPolicyUtils.hpp>
#include <fastdds/dds/builtin/typelookup/TypeLookupManager.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include <fastdds/dds/topic/IContentFilterFactory.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>

#include <fastdds/rtps/RTPSDomain.h>
#include <fastdds/publisher/PublisherImpl.hpp>
#include <fastdds/rtps/attributes/PropertyPolicy.h>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/builtin/liveliness/WLP.h>
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.h>
#include <fastdds/rtps/participant/RTPSParticipant.h>
#include <fastdds/rtps/reader/ReaderDiscoveryInfo.h>
#include <fastdds/rtps/RTPSDomain.h>
#include <fastdds/rtps/writer/WriterDiscoveryInfo.h>

#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/attributes/SubscriberAttributes.h>

#include <fastrtps/types/DynamicTypeBuilderFactory.h>
#include <fastrtps/types/DynamicPubSubType.h>
#include <fastrtps/types/DynamicType.h>
#include <fastrtps/types/DynamicTypeBuilderFactory.h>
#include <fastrtps/types/DynamicTypeMember.h>
#include <fastrtps/types/TypeObjectFactory.h>

#include <fastrtps/xmlparser/XMLProfileManager.h>

#include <fastdds/publisher/PublisherImpl.hpp>
#include <fastdds/subscriber/SubscriberImpl.hpp>
#include <fastdds/topic/TopicImpl.hpp>
#include <fastdds/topic/ContentFilteredTopicImpl.hpp>

#include <fastdds/topic/TopicImpl.hpp>
#include <rtps/RTPSDomainImpl.hpp>

#include <chrono>
#include <utils/SystemInfo.hpp>

namespace eprosima {
namespace fastdds {
Expand Down Expand Up @@ -166,6 +167,32 @@ DomainParticipantImpl::DomainParticipantImpl(
// Pre calculate participant id and generated guid
participant_id_ = qos_.wire_protocol().participant_id;
eprosima::fastrtps::rtps::RTPSDomainImpl::create_participant_guid(participant_id_, guid_);

/* Fill physical data properties if they are found and empty */
std::string* property_value = fastrtps::rtps::PropertyPolicyHelper::find_property(
qos_.properties(), parameter_policy_physical_data_host);
if (nullptr != property_value && property_value->empty())
{
property_value->assign(asio::ip::host_name() + ":" + std::to_string(utils::default_domain_id()));
}

property_value = fastrtps::rtps::PropertyPolicyHelper::find_property(
qos_.properties(), parameter_policy_physical_data_user);
if (nullptr != property_value && property_value->empty())
{
std::string username = "unknown";
if (ReturnCode_t::RETCODE_OK == SystemInfo::get_username(username))
{
property_value->assign(username);
}
}

property_value = fastrtps::rtps::PropertyPolicyHelper::find_property(
qos_.properties(), parameter_policy_physical_data_process);
if (nullptr != property_value && property_value->empty())
{
property_value->assign(std::to_string(SystemInfo::instance().process_id()));
}
}

void DomainParticipantImpl::disable()
Expand Down
38 changes: 31 additions & 7 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ PDP::~PDP()

ParticipantProxyData* PDP::add_participant_proxy_data(
const GUID_t& participant_guid,
bool with_lease_duration)
bool with_lease_duration,
const ParticipantProxyData* participant_proxy_data)
{
ParticipantProxyData* ret_val = nullptr;

Expand Down Expand Up @@ -218,11 +219,15 @@ ParticipantProxyData* PDP::add_participant_proxy_data(
// Add returned entry to the collection
ret_val->should_check_lease_duration = with_lease_duration;
ret_val->m_guid = participant_guid;
if (nullptr != participant_proxy_data)
{
ret_val->copy(*participant_proxy_data);
ret_val->isAlive = true;
// Notify discovery of remote participant
getRTPSParticipant()->on_entity_discovery(participant_guid, ret_val->m_properties);
}
participant_proxies_.push_back(ret_val);

// notify statistics module
getRTPSParticipant()->on_entity_discovery(participant_guid);

return ret_val;
}

Expand Down Expand Up @@ -355,6 +360,22 @@ void PDP::initializeParticipantProxyData(
participant_type << mp_RTPSParticipant->getAttributes().builtin.discovery_config.discoveryProtocol;
auto ptype = participant_type.str();
participant_data->m_properties.push_back(fastdds::dds::parameter_property_participant_type, ptype);

/* Add physical properties if present */
std::vector<std::string> physical_property_names = {
fastdds::dds::parameter_policy_physical_data_host,
fastdds::dds::parameter_policy_physical_data_user,
fastdds::dds::parameter_policy_physical_data_process
};
for (auto physical_property_name : physical_property_names)
{
std::string* physical_property = PropertyPolicyHelper::find_property(
mp_RTPSParticipant->getAttributes().properties, physical_property_name);
if (nullptr != physical_property)
{
participant_data->m_properties.push_back(physical_property_name, *physical_property);
}
}
}

bool PDP::initPDP(
Expand All @@ -373,7 +394,7 @@ bool PDP::initPDP(
mp_builtin->updateMetatrafficLocators(this->mp_PDPReader->getAttributes().unicastLocatorList);

mp_mutex->lock();
ParticipantProxyData* pdata = add_participant_proxy_data(mp_RTPSParticipant->getGuid(), false);
ParticipantProxyData* pdata = add_participant_proxy_data(mp_RTPSParticipant->getGuid(), false, nullptr);
mp_mutex->unlock();

if (pdata == nullptr)
Expand Down Expand Up @@ -410,6 +431,9 @@ bool PDP::enable()
set_initial_announcement_interval();

enable_ = true;
// Notify "self-discovery"
getRTPSParticipant()->on_entity_discovery(mp_RTPSParticipant->getGuid(),
get_participant_proxy_data(mp_RTPSParticipant->getGuid().guidPrefix)->m_properties);

return mp_RTPSParticipant->enableReader(mp_PDPReader);
}
Expand Down Expand Up @@ -713,7 +737,7 @@ ReaderProxyData* PDP::addReaderProxyData(
ReaderProxyData* ret_val = nullptr;

// notify statistics module
getRTPSParticipant()->on_entity_discovery(reader_guid);
getRTPSParticipant()->on_entity_discovery(reader_guid, ParameterPropertyList_t());

std::lock_guard<std::recursive_mutex> guardPDP(*this->mp_mutex);

Expand Down Expand Up @@ -808,7 +832,7 @@ WriterProxyData* PDP::addWriterProxyData(
WriterProxyData* ret_val = nullptr;

// notify statistics module
getRTPSParticipant()->on_entity_discovery(writer_guid);
getRTPSParticipant()->on_entity_discovery(writer_guid, ParameterPropertyList_t());

std::lock_guard<std::recursive_mutex> guardPDP(*this->mp_mutex);

Expand Down
5 changes: 1 addition & 4 deletions src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ ParticipantProxyData* PDPClient::createParticipantProxyData(
}
}

ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, is_server);
ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, is_server, &participant_data);
if (pdata != nullptr)
{
pdata->copy(participant_data);
pdata->isAlive = true;

// Clients only assert its server lifeliness, other clients liveliness is provided
// through server's PDP discovery data
if (is_server)
Expand Down
4 changes: 1 addition & 3 deletions src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ ParticipantProxyData* PDPServer::createParticipantProxyData(
}
}

ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, do_lease);
ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, do_lease, &participant_data);
if (pdata != nullptr)
{
pdata->copy(participant_data);
pdata->isAlive = true;
if (do_lease)
{
pdata->lease_duration_event->update_interval(pdata->m_leaseDuration);
Expand Down
4 changes: 1 addition & 3 deletions src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ ParticipantProxyData* PDPSimple::createParticipantProxyData(
}
}

ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, true);
ParticipantProxyData* pdata = add_participant_proxy_data(participant_data.m_guid, true, &participant_data);
if (pdata != nullptr)
{
pdata->copy(participant_data);
pdata->isAlive = true;
pdata->lease_duration_event->update_interval(pdata->m_leaseDuration);
pdata->lease_duration_event->restart_timer();
}
Expand Down
Loading