Skip to content

Commit

Permalink
Feature: use PID_DOMAIN_ID during PDP (#4888)
Browse files Browse the repository at this point in the history
* Refs #21096: Extend test transport configuration

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Add BB tests

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Little fixes on existing unittests an BB tests

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Implementation

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Linter

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Prevent undefined behavior initializing variables in test_transport

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Specialize check_discovery_conditions() in PDPSecurityInitiator DS listener

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Fix cyclone dds participant discovery test. Match the domains

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Applied Edus review

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: versions.md

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21096: Add PDPClientListener.cpp to statefulreadertests

Signed-off-by: Mario Dominguez <[email protected]>

---------

Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Jun 12, 2024
1 parent 3780507 commit 150941f
Show file tree
Hide file tree
Showing 33 changed files with 835 additions and 107 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 DOMAIN_ID_UNKNOWN = 0xFFFFFFFF;

const int32_t LENGTH_UNLIMITED = -1;

} // namespace dds
Expand Down
38 changes: 38 additions & 0 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <fastcdr/cdr/fixed_size_string.hpp>

#include <fastdds/dds/core/Types.hpp>
#include <fastdds/rtps/common/InstanceHandle.h>
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/common/SampleIdentity.h>
Expand Down Expand Up @@ -525,6 +526,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, DOMAIN_ID_UNKNOWN.
uint32_t domain_id;

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

/**
* 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(DOMAIN_ID_UNKNOWN)
{
domain_id = DOMAIN_ID_UNKNOWN;
}

};

#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
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ struct test_UDPv4TransportDescriptor : public SocketTransportDescriptor
//! Test shim parameters
//! Percentage of data messages being dropped
mutable std::atomic<uint8_t> dropDataMessagesPercentage;
//! Percentage of Data[P] messages being dropped
mutable std::atomic<uint8_t> dropParticipantBuiltinDataMessagesPercentage;
//! Percentage of Data[W] messages being dropped
mutable std::atomic<uint8_t> dropPublicationBuiltinDataMessagesPercentage;
//! Percentage of Data[R] messages being dropped
mutable std::atomic<uint8_t> dropSubscriptionBuiltinDataMessagesPercentage;
//! Filtering function for dropping data messages
filter drop_data_messages_filter_;
//! Filtering function for dropping builtin data messages
filter drop_builtin_data_messages_filter_;
//! Flag to enable dropping of discovery Participant DATA(P) messages
bool dropParticipantBuiltinTopicData;
//! Flag to enable dropping of discovery Writer DATA(W) messages
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 @@ -131,6 +131,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
22 changes: 22 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,28 @@ 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)
{
return fastrtps::rtps::CDRMessage::addUInt32(cdr_message, parameter.domain_id);
}

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_DOMAINID_LENGTH)
{
return false;
}
parameter.length = parameter_length;
return fastrtps::rtps::CDRMessage::readUInt32(cdr_message, &parameter.domain_id);
}

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::DOMAIN_ID_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 + PARAMETER_DOMAINID_LENGTH;

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::DOMAIN_ID_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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ void PDPSecurityInitiatorListener::process_alive_data(

}

bool PDPSecurityInitiatorListener::check_discovery_conditions(
ParticipantProxyData& /* participant_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 */
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class PDPSecurityInitiatorListener : public PDPListener

protected:

bool check_discovery_conditions(
ParticipantProxyData& participant_data) override;

void process_alive_data(
ParticipantProxyData* old_data,
ParticipantProxyData& new_data,
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 @@ -357,7 +358,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
63 changes: 63 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPClientListener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 */)
{
/* 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 */
59 changes: 59 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPClientListener.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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_

#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) override;

};


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

#endif /* _FASTDDS_RTPS_PDPCLIENTLISTENER_H_ */
Loading

0 comments on commit 150941f

Please sign in to comment.