Skip to content

Commit

Permalink
PDP endpoints refactor (#3162)
Browse files Browse the repository at this point in the history
* Refs #16500. Modelling PDP <-> PDPEndpoints relationship.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Builtin endpoints constants moved to separate header.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Added BuiltinReader aggregate.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Added BuiltinWriter aggregate.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Added SimplePDPEndpoints container.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Refactor on PDPSimple.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Remove references to builtin endpoints on PDP.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Update PDPSimple to PDP refactor

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Improvements on PDP::initializeParticipantProxyData

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Added DiscoveryServerPDPEndpoints container.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Update PDPClient to PDP refactor

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Update PDPServer to PDP refactor

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Update EDPServer to PDP refactor.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Update PDPListener to PDP refactor.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Update PDPServerListener to PDP refactor.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Ensure endpoints are assigned before being used.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Fix warning.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Uncrustify

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #16500. Apply suggestion.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

Co-authored-by: Mario Domínguez López <116071334+Mario-DL@users.noreply.github.com>

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
Co-authored-by: Mario Domínguez López <116071334+Mario-DL@users.noreply.github.com>
  • Loading branch information
MiguelCompany and Mario-DL committed Jan 21, 2023
1 parent 7f6f4b6 commit 04b9463
Show file tree
Hide file tree
Showing 18 changed files with 823 additions and 291 deletions.
47 changes: 47 additions & 0 deletions include/fastdds/rtps/builtin/data/BuiltinEndpoints.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2022 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 BuiltinEndpoints.hpp
*/

#ifndef FASTDDS_RTPS_BUILTIN_DATA__BUILTINENDPOINTS_HPP
#define FASTDDS_RTPS_BUILTIN_DATA__BUILTINENDPOINTS_HPP

#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER (0x00000001 << 0)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR (0x00000001 << 1)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER (0x00000001 << 2)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR (0x00000001 << 3)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER (0x00000001 << 4)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR (0x00000001 << 5)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_ANNOUNCER (0x00000001 << 6)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_DETECTOR (0x00000001 << 7)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_ANNOUNCER (0x00000001 << 8)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_DETECTOR (0x00000001 << 9)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER (0x00000001 << 10)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER (0x00000001 << 11)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REQUEST_DATA_WRITER (0x00000001 << 12)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REQUEST_DATA_READER (0x00000001 << 13)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REPLY_DATA_WRITER (0x00000001 << 14)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REPLY_DATA_READER (0x00000001 << 15)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_ANNOUNCER (0x00000001 << 16)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_DETECTOR (0x00000001 << 17)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_ANNOUNCER (0x00000001 << 18)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_DETECTOR (0x00000001 << 19)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_SECURE_DATA_WRITER (0x00000001 << 20)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_SECURE_DATA_READER (0x00000001 << 21)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_ANNOUNCER (0x00000001 << 26)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_DETECTOR (0x00000001 << 27)

#endif // FASTDDS_RTPS_BUILTIN_DATA__BUILTINENDPOINTS_HPP
26 changes: 1 addition & 25 deletions include/fastdds/rtps/builtin/data/ParticipantProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
#include <fastdds/rtps/attributes/WriterAttributes.h>
#include <fastdds/rtps/attributes/ReaderAttributes.h>
#include <fastdds/rtps/builtin/data/BuiltinEndpoints.hpp>
#include <fastdds/rtps/common/Token.h>
#include <fastdds/rtps/common/RemoteLocators.hpp>

Expand All @@ -38,31 +39,6 @@
#define BUILTIN_PARTICIPANT_DATA_MAX_SIZE 100
#define TYPELOOKUP_DATA_MAX_SIZE 5000

#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER (0x00000001 << 0)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR (0x00000001 << 1)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER (0x00000001 << 2)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR (0x00000001 << 3)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER (0x00000001 << 4)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR (0x00000001 << 5)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_ANNOUNCER (0x00000001 << 6)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_DETECTOR (0x00000001 << 7)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_ANNOUNCER (0x00000001 << 8)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_DETECTOR (0x00000001 << 9)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER (0x00000001 << 10)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER (0x00000001 << 11)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REQUEST_DATA_WRITER (0x00000001 << 12)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REQUEST_DATA_READER (0x00000001 << 13)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REPLY_DATA_WRITER (0x00000001 << 14)
#define BUILTIN_ENDPOINT_TYPELOOKUP_SERVICE_REPLY_DATA_READER (0x00000001 << 15)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_ANNOUNCER (0x00000001 << 16)
#define DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_DETECTOR (0x00000001 << 17)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_ANNOUNCER (0x00000001 << 18)
#define DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_DETECTOR (0x00000001 << 19)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_SECURE_DATA_WRITER (0x00000001 << 20)
#define BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_SECURE_DATA_READER (0x00000001 << 21)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_ANNOUNCER (0x00000001 << 26)
#define DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_DETECTOR (0x00000001 << 27)

namespace eprosima {
namespace fastrtps {
namespace rtps {
Expand Down
40 changes: 26 additions & 14 deletions include/fastdds/rtps/builtin/discovery/participant/PDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <atomic>
#include <mutex>
#include <functional>
#include <memory>
#include <mutex>

#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/builtin/data/ReaderProxyData.h>
Expand All @@ -40,6 +41,7 @@ namespace fastdds {
namespace rtps {

class PDPServerListener;
class PDPEndpoints;

} // namespace rtps
} // namespace fastdds
Expand Down Expand Up @@ -128,7 +130,7 @@ class PDP
virtual void announceParticipantState(
bool new_change,
bool dispose = false,
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT);
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT) = 0;

//!Stop the RTPSParticipantAnnouncement (only used in tests).
virtual void stopParticipantAnnouncement();
Expand Down Expand Up @@ -384,10 +386,8 @@ class PDP
RTPSParticipantImpl* mp_RTPSParticipant;
//!Discovery attributes.
BuiltinAttributes m_discovery;
//!Pointer to the PDPWriter.
RTPSWriter* mp_PDPWriter;
//!Pointer to the PDPReader.
RTPSReader* mp_PDPReader;
//!Builtin PDP endpoints
std::unique_ptr<fastdds::rtps::PDPEndpoints> builtin_endpoints_;
//!Pointer to the EDP object.
EDP* mp_EDP;
//!Number of participant proxy data objects created
Expand All @@ -408,14 +408,6 @@ class PDP
std::atomic_bool m_hasChangedLocalPDP;
//!Listener for the SPDP messages.
ReaderListener* mp_listener;
//!WriterHistory
WriterHistory* mp_PDPWriterHistory;
//!Writer payload pool
std::shared_ptr<ITopicPayloadPool> writer_payload_pool_;
//!Reader History
ReaderHistory* mp_PDPReaderHistory;
//!Reader payload pool
std::shared_ptr<ITopicPayloadPool> reader_payload_pool_;
//! ProxyPool for temporary reader proxies
ProxyPool<ReaderProxyData> temp_reader_proxies_;
//! ProxyPool for temporary writer proxies
Expand Down Expand Up @@ -454,6 +446,26 @@ class PDP
const GUID_t& participant_guid,
InstanceHandle_t& key);

/**
* Force the sending of our local DPD to all remote RTPSParticipants and multicast Locators.
* @param writer RTPSWriter to use for sending the announcement
* @param history history where the change should be added
* @param new_change If true a new change (with new seqNum) is created and sent;If false the last change is re-sent
* @param dispose sets change kind to NOT_ALIVE_DISPOSED_UNREGISTERED
* @param wparams allows to identify the change
*/
void announceParticipantState(
RTPSWriter& writer,
WriterHistory& history,
bool new_change,
bool dispose = false,
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT);

/**
* Called after creating the builtin endpoints to update the metatraffic unicast locators of BuiltinProtocols
*/
virtual void update_builtin_locators() = 0;

private:

//!TimedEvent to periodically resend the local RTPSParticipant information.
Expand Down
28 changes: 17 additions & 11 deletions include/fastdds/rtps/builtin/discovery/participant/PDPSimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class PDPSimple : public PDP
* @param part Pointer to the RTPSParticipant.
* @return True on success
*/
bool init(RTPSParticipantImpl* part) override;
bool init(
RTPSParticipantImpl* part) override;

/**
* Creates an initializes a new participant proxy from a DATA(p) raw info
Expand All @@ -63,8 +64,8 @@ class PDPSimple : public PDP
* @return new ParticipantProxyData * or nullptr on failure
*/
ParticipantProxyData* createParticipantProxyData(
const ParticipantProxyData& p,
const GUID_t& writer_guid) override;
const ParticipantProxyData& p,
const GUID_t& writer_guid) override;

/**
* Some PDP classes require EDP matching with update PDP DATAs like EDPStatic
Expand All @@ -79,28 +80,31 @@ class PDPSimple : public PDP
* @param wparams allows to identify the change
*/
void announceParticipantState(
bool new_change,
bool dispose = false,
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT) override;
bool new_change,
bool dispose = false,
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT) override;

/**
* This method assigns remote endpoints to the builtin endpoints defined in this protocol. It also calls
* the corresponding methods in EDP and WLP.
* @param pdata Pointer to the ParticipantProxyData object.
*/
void assignRemoteEndpoints(ParticipantProxyData* pdata) override;
void assignRemoteEndpoints(
ParticipantProxyData* pdata) override;

/**
* Remove remote endpoints from the participant discovery protocol
* @param pdata Pointer to the ParticipantProxyData to remove
*/
void removeRemoteEndpoints(ParticipantProxyData * pdata) override;
void removeRemoteEndpoints(
ParticipantProxyData* pdata) override;

/**
* This method notifies EDP and WLP of the existence of a new participant.
* @param pdata
*/
void notifyAboveRemoteEndpoints(const ParticipantProxyData& pdata) override;
void notifyAboveRemoteEndpoints(
const ParticipantProxyData& pdata) override;

/**
* Activate a new Remote Endpoint that has been statically discovered.
Expand All @@ -113,10 +117,12 @@ class PDPSimple : public PDP
int16_t userDefinedId,
EndpointKind_t kind);

void update_builtin_locators() override;

private:

void initializeParticipantProxyData(ParticipantProxyData* participant_data) override;
void initializeParticipantProxyData(
ParticipantProxyData* participant_data) override;

/**
* Create the SPDP Writer and Reader
Expand All @@ -130,5 +136,5 @@ class PDPSimple : public PDP
} /* namespace fastrtps */
} /* namespace eprosima */

#endif
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif //_FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_PDPSIMPLE_H_
84 changes: 84 additions & 0 deletions src/cpp/rtps/builtin/BuiltinReader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2022 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 BuiltinReader.hpp
*/

#ifndef RTPS_BUILTIN__BUILTINREADER_HPP_
#define RTPS_BUILTIN__BUILTINREADER_HPP_

#include <memory>

#include <fastdds/rtps/history/ReaderHistory.h>

#include <rtps/history/ITopicPayloadPool.h>
#include <rtps/history/PoolConfig.h>

namespace eprosima {
namespace fastdds {
namespace rtps {

/**
* Keeps data of a builtin reader
*/
template<typename TReader>
struct BuiltinReader
{
~BuiltinReader()
{
release();
}

void release()
{
if (history_)
{
auto cfg = fastrtps::rtps::PoolConfig::from_history_attributes(history_->m_att);
history_.reset();
if (payload_pool_)
{
payload_pool_->release_history(cfg, true);
}
}
}

void remove_from_history(
const fastrtps::rtps::InstanceHandle_t& key)
{
history_->getMutex()->lock();
for (auto it = history_->changesBegin(); it != history_->changesEnd(); ++it)
{
if ((*it)->instanceHandle == key)
{
history_->remove_change(*it);
break;
}
}
history_->getMutex()->unlock();
}

//! Payload pool for the topic
std::shared_ptr<fastrtps::rtps::ITopicPayloadPool> payload_pool_;
//! History for the builtin reader
std::unique_ptr<fastrtps::rtps::ReaderHistory> history_;
//! Builtin RTPS reader
TReader* reader_ = nullptr;
};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif // RTPS_BUILTIN__BUILTINREADER_HPP_
Loading

0 comments on commit 04b9463

Please sign in to comment.