Skip to content

Commit

Permalink
Refs #21096: Implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL committed Jun 3, 2024
1 parent faad69b commit bc5c906
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 89 deletions.
2 changes: 2 additions & 0 deletions include/fastdds/dds/core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace dds {

typedef uint32_t DomainId_t;

const DomainId_t c_DomainId_t_Unknown = 0xFFFFFFFF;

const int32_t LENGTH_UNLIMITED = -1;

} // namespace dds
Expand Down
37 changes: 37 additions & 0 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,43 @@ class ParameterGuid_t : public Parameter_t

#define PARAMETER_GUID_LENGTH 16

/**
* @ingroup PARAMETER_MODULE
*/
class ParameterDomainId_t : public Parameter_t
{
public:

//!Domain ID. <br> By default, 0.
uint32_t domain_id;

/**
* @brief Constructor without parameters
*/
ParameterDomainId_t()
: domain_id(0)
{
}

/**
* Constructor using a parameter PID and the parameter length
*
* @param pid Pid of the parameter
* @param in_length Its associated length
*/
ParameterDomainId_t(
ParameterId_t pid,
uint16_t in_length)
: Parameter_t(pid, in_length)
, domain_id(0)
{
domain_id = 0;
}

};

#define PARAMETER_DOMAINID_LENGTH 4

/**
* @ingroup PARAMETER_MODULE
*/
Expand Down
3 changes: 3 additions & 0 deletions include/fastdds/rtps/builtin/data/ParticipantProxyData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <chrono>

#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/dds/core/Types.hpp>
#include <fastdds/rtps/attributes/ReaderAttributes.h>
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
#include <fastdds/rtps/attributes/WriterAttributes.h>
Expand Down Expand Up @@ -77,6 +78,8 @@ class ParticipantProxyData
GUID_t m_guid;
//!Vendor ID
fastdds::rtps::VendorId_t m_VendorId;
//!Domain ID
fastdds::dds::DomainId_t m_domain_id;
//!Expects Inline QOS.
bool m_expectsInlineQos;
//!Available builtin endpoints
Expand Down
1 change: 1 addition & 0 deletions include/fastrtps/qos/ParameterTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ using ParameterPort_t = fastdds::dds::ParameterPort_t;
using ParameterGuid_t = fastdds::dds::ParameterGuid_t;
using ParameterProtocolVersion_t = fastdds::dds::ParameterProtocolVersion_t;
using ParameterVendorId_t = fastdds::dds::ParameterVendorId_t;
using ParameterDomainId_t = fastdds::dds::ParameterDomainId_t;
using ParameterIP4Address_t = fastdds::dds::ParameterIP4Address_t;
using ParameterBool_t = fastdds::dds::ParameterBool_t;
using ParameterStatusInfo_t = fastdds::dds::ParameterStatusInfo_t;
Expand Down
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ set(${PROJECT_NAME}_source_files
rtps/builtin/discovery/participant/DirectMessageSender.cpp
rtps/builtin/discovery/participant/PDP.cpp
rtps/builtin/discovery/participant/PDPClient.cpp
rtps/builtin/discovery/participant/PDPClientListener.cpp
rtps/builtin/discovery/participant/PDPListener.cpp
rtps/builtin/discovery/participant/PDPServer.cpp
rtps/builtin/discovery/participant/PDPServerListener.cpp
Expand Down
25 changes: 25 additions & 0 deletions src/cpp/fastdds/core/policy/ParameterSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,31 @@ inline bool ParameterSerializer<ParameterVendorId_t>::read_content_from_cdr_mess
return valid;
}

template<>
inline bool ParameterSerializer<ParameterDomainId_t>::add_content_to_cdr_message(
const ParameterDomainId_t& parameter,
fastrtps::rtps::CDRMessage_t* cdr_message)
{
bool valid = fastrtps::rtps::CDRMessage::addUInt32(cdr_message, parameter.domain_id);
return valid;
}

template<>
inline bool ParameterSerializer<ParameterDomainId_t>::read_content_from_cdr_message(
ParameterDomainId_t& parameter,
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_VENDOR_LENGTH)
{
return false;
}
parameter.length = parameter_length;
bool valid = fastrtps::rtps::CDRMessage::readUInt32(cdr_message, &parameter.domain_id);
cdr_message->pos += 2; //padding
return valid;
}

template<>
inline bool ParameterSerializer<ParameterIP4Address_t>::add_content_to_cdr_message(
const ParameterIP4Address_t& parameter,
Expand Down
27 changes: 27 additions & 0 deletions src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ParticipantProxyData::ParticipantProxyData(
const RTPSParticipantAllocationAttributes& allocation)
: m_protocolVersion(c_ProtocolVersion)
, m_VendorId(c_VendorId_Unknown)
, m_domain_id(fastdds::dds::c_DomainId_t_Unknown)
, m_expectsInlineQos(false)
, m_availableBuiltinEndpoints(0)
, m_networkConfiguration(0)
Expand All @@ -78,6 +79,7 @@ ParticipantProxyData::ParticipantProxyData(
: m_protocolVersion(pdata.m_protocolVersion)
, m_guid(pdata.m_guid)
, m_VendorId(pdata.m_VendorId)
, m_domain_id(pdata.m_domain_id)
, m_expectsInlineQos(pdata.m_expectsInlineQos)
, m_availableBuiltinEndpoints(pdata.m_availableBuiltinEndpoints)
, m_networkConfiguration(pdata.m_networkConfiguration)
Expand Down Expand Up @@ -151,6 +153,9 @@ uint32_t ParticipantProxyData::get_serialized_size(
// PID_VENDORID
ret_val += 4 + 4;

// PID_DOMAIN_ID
ret_val += 4 + 4;

if (m_expectsInlineQos)
{
// PID_EXPECTS_INLINE_QOS
Expand Down Expand Up @@ -252,6 +257,14 @@ bool ParticipantProxyData::writeToCDRMessage(
return false;
}
}
{
ParameterDomainId_t p(fastdds::dds::PID_DOMAIN_ID, 4);
p.domain_id = this->m_domain_id;
if (!fastdds::dds::ParameterSerializer<ParameterDomainId_t>::add_to_cdr_message(p, msg))
{
return false;
}
}
if (this->m_expectsInlineQos)
{
ParameterBool_t p(fastdds::dds::PID_EXPECTS_INLINE_QOS, PARAMETER_BOOL_LENGTH, m_expectsInlineQos);
Expand Down Expand Up @@ -443,6 +456,18 @@ bool ParticipantProxyData::readFromCDRMessage(
is_shm_transport_available &= (m_VendorId == c_VendorId_eProsima);
break;
}
case fastdds::dds::PID_DOMAIN_ID:
{
ParameterDomainId_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterDomainId_t>::read_from_cdr_message(p, msg,
plength))
{
return false;
}

m_domain_id = p.domain_id;
break;
}
case fastdds::dds::PID_EXPECTS_INLINE_QOS:
{
ParameterBool_t p(pid, plength);
Expand Down Expand Up @@ -740,6 +765,7 @@ void ParticipantProxyData::clear()
m_guid = GUID_t();
//set_VendorId_Unknown(m_VendorId);
m_VendorId = c_VendorId_Unknown;
m_domain_id = fastdds::dds::c_DomainId_t_Unknown;
m_expectsInlineQos = false;
m_availableBuiltinEndpoints = 0;
m_networkConfiguration = 0;
Expand Down Expand Up @@ -771,6 +797,7 @@ void ParticipantProxyData::copy(
m_guid = pdata.m_guid;
m_VendorId[0] = pdata.m_VendorId[0];
m_VendorId[1] = pdata.m_VendorId[1];
m_domain_id = pdata.m_domain_id;
m_availableBuiltinEndpoints = pdata.m_availableBuiltinEndpoints;
m_networkConfiguration = pdata.m_networkConfiguration;
metatraffic_locators = pdata.metatraffic_locators;
Expand Down
1 change: 1 addition & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void PDP::initializeParticipantProxyData(
RTPSParticipantAttributes& attributes = mp_RTPSParticipant->getAttributes();
bool announce_locators = !mp_RTPSParticipant->is_intraprocess_only();

participant_data->m_domain_id = mp_RTPSParticipant->get_domain_id();
participant_data->m_leaseDuration = attributes.builtin.discovery_config.leaseDuration;
//set_VendorId_eProsima(participant_data->m_VendorId);
participant_data->m_VendorId = c_VendorId_eProsima;
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <rtps/builtin/discovery/participant/PDPClient.h>
#include <rtps/builtin/discovery/participant/PDPClientListener.hpp>

#include <algorithm>
#include <forward_list>
Expand Down Expand Up @@ -356,7 +357,7 @@ bool PDPClient::create_ds_pdp_reliable_endpoints(
}
#endif // HAVE_SECURITY

endpoints.reader.listener_.reset(new PDPListener(this));
endpoints.reader.listener_.reset(new PDPClientListener(this));

RTPSReader* reader = nullptr;
#if HAVE_SECURITY
Expand Down
64 changes: 64 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPClientListener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file PDPClientListener.cpp
*
*/

#include <rtps/builtin/discovery/participant/PDPClientListener.hpp>

#include <mutex>

#include <fastdds/core/policy/ParameterList.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/rtps/history/ReaderHistory.h>
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.h>
#include <fastdds/rtps/participant/RTPSParticipantListener.h>
#include <fastdds/rtps/reader/RTPSReader.h>

#include <rtps/builtin/discovery/endpoint/EDP.h>
#include <rtps/builtin/discovery/participant/PDP.h>
#include <rtps/builtin/discovery/participant/PDPEndpoints.hpp>
#include <rtps/network/utils/external_locators.hpp>
#include <rtps/participant/RTPSParticipantImpl.h>
#include <rtps/resources/TimedEvent.h>

using ParameterList = eprosima::fastdds::dds::ParameterList;

namespace eprosima {
namespace fastrtps {
namespace rtps {

PDPClientListener::PDPClientListener(
PDP* parent_pdp)
: PDPListener(parent_pdp)
{
}

bool PDPClientListener::check_discovery_conditions(
ParticipantProxyData& /* participant_data */,
void* /* extra data*/)
{
/* Do not check PID_VENDOR_ID */
// In Discovery Server we don't impose
// domain ids to be the same
/* Do not check PID_DOMAIN_ID */
/* Do not check PARTICIPANT_TYPE */
return true;
}

} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */
62 changes: 62 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPClientListener.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file PDPClientListener.h
*
*/

#ifndef _FASTDDS_RTPS_PDPCLIENTLISTENER_H_
#define _FASTDDS_RTPS_PDPCLIENTLISTENER_H_
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <rtps/builtin/discovery/participant/PDPListener.h>

namespace eprosima {
namespace fastrtps {
namespace rtps {

/**
* Class PDPClientListener used by a PDP discovery client.
* This class is implemented in order to use the same structure than with any other RTPSReader.
* @ingroup DISCOVERY_MODULE
*/
class PDPClientListener : public PDPListener
{

public:

/**
* @param parent Pointer to object creating this object
*/
PDPClientListener(
PDP* parent);

virtual ~PDPClientListener() override = default;

protected:

bool check_discovery_conditions(
ParticipantProxyData& pdata,
void* extra_data) override;

};


} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */

#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* _FASTDDS_RTPS_PDPCLIENTLISTENER_H_ */
31 changes: 31 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ void PDPListener::onNewCacheChangeAdded(
return;
}

void* empty_extra_data = nullptr;
static_cast<void>(empty_extra_data);
if (!check_discovery_conditions(temp_participant_data_, empty_extra_data))
{
return;
}

// Filter locators
const auto& pattr = parent_pdp_->getRTPSParticipant()->getAttributes();
fastdds::rtps::network::external_locators::filter_remote_locators(temp_participant_data_,
Expand Down Expand Up @@ -274,6 +281,30 @@ void PDPListener::process_alive_data(
reader->getMutex().lock();
}

bool PDPListener::check_discovery_conditions(
ParticipantProxyData& participant_data,
void* /*extra_data*/)
{
bool ret = true;
uint32_t remote_participant_domain_id = participant_data.m_domain_id;

// In PDPSimple, do not match if the participant is from a different domain.
// If the domain id is unknown, it is assumed to be the same domain
if (remote_participant_domain_id != parent_pdp_->getRTPSParticipant()->get_domain_id() &&
remote_participant_domain_id != fastdds::dds::c_DomainId_t_Unknown)
{
EPROSIMA_LOG_INFO(RTPS_PDP_DISCOVERY, "Received participant with different domain id ("
<< remote_participant_domain_id << ") than ours ("
<< parent_pdp_->getRTPSParticipant()->get_domain_id() << ")");
std::cout << "Received participant with different domain id ("
<< remote_participant_domain_id << ") than ours ("
<< parent_pdp_->getRTPSParticipant()->get_domain_id() << ")" << std::endl;
ret = false;
}

return ret;
}

bool PDPListener::get_key(
CacheChange_t* change)
{
Expand Down
Loading

0 comments on commit bc5c906

Please sign in to comment.