Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
 * @file RTPSParticipantAttributes.h
17
 */
18
19
#ifndef _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_
20
#define _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_
21
22
#include <fastdds/rtps/attributes/ExternalLocators.hpp>
23
#include <fastdds/rtps/attributes/PropertyPolicy.h>
24
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
25
#include <fastdds/rtps/attributes/ServerAttributes.h>
26
#include <fastdds/rtps/common/Locator.h>
27
#include <fastdds/rtps/common/PortParameters.h>
28
#include <fastdds/rtps/common/Time_t.h>
29
#include <fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp>
30
#include <fastdds/rtps/flowcontrol/ThroughputControllerDescriptor.h>
31
#include <fastdds/rtps/resources/ResourceManagement.h>
32
#include <fastdds/rtps/transport/TransportInterface.h>
33
#include <fastrtps/utils/fixed_size_string.hpp>
34
35
#include <memory>
36
#include <sstream>
37
38
namespace eprosima {
39
40
namespace fastdds {
41
42
namespace rtps {
43
44
/**
45
 * Struct to define participant types to set participant type parameter property
46
 *@ingroup DISCOVERY_MODULE
47
 */
48
struct ParticipantType
49
{
50
    static constexpr const char* SIMPLE = "SIMPLE";
51
    static constexpr const char* SERVER = "SERVER";
52
    static constexpr const char* CLIENT = "CLIENT";
53
    static constexpr const char* SUPER_CLIENT = "SUPER_CLIENT";
54
    static constexpr const char* BACKUP = "BACKUP";
55
    static constexpr const char* NONE = "NONE";
56
    static constexpr const char* EXTERNAL = "EXTERNAL";
57
    static constexpr const char* UNKNOWN = "UNKNOWN";
58
};
59
60
} /* namespace rtps */
61
} /* namespace fastdds */
62
63
namespace fastrtps {
64
namespace rtps {
65
66
67
//!PDP subclass choice
68
typedef enum DiscoveryProtocol
69
{
70
    NONE,
71
    /*!<
72
        NO discovery whatsoever would be used.
73
        Publisher and Subscriber defined with the same topic name would NOT be linked.
74
        All matching must be done manually through the addReaderLocator, addReaderProxy, addWriterProxy methods.
75
     */
76
    SIMPLE,
77
    /*!<
78
        Discovery works according to 'The Real-time Publish-Subscribe Protocol(RTPS) DDS
79
        Interoperability Wire Protocol Specification'
80
     */
81
    EXTERNAL,
82
    /*!<
83
        A user defined PDP subclass object must be provided in the attributes that deals with the discovery.
84
        Framework is not responsible of this object lifetime.
85
     */
86
    CLIENT, /*!< The participant will behave as a client concerning discovery operation.
87
                 Server locators should be specified as attributes. */
88
    SERVER, /*!< The participant will behave as a server concerning discovery operation.
89
                 Discovery operation is volatile (discovery handshake must take place if shutdown). */
90
    BACKUP,  /*!< The participant will behave as a server concerning discovery operation.
91
                 Discovery operation persist on a file (discovery handshake wouldn't repeat if shutdown). */
92
    SUPER_CLIENT  /*!< The participant will behave as a client concerning all internal behaviour.
93
                     Remote servers will treat it as a server and will share every discovery information. */
94
95
} DiscoveryProtocol_t;
96
97
inline std::ostream& operator <<(
98
        std::ostream& output,
99
        const DiscoveryProtocol& discovery_protocol)
100
0
{
101
0
    switch (discovery_protocol)
102
0
    {
103
0
        case DiscoveryProtocol::NONE:
104
0
            output << fastdds::rtps::ParticipantType::NONE;
105
0
            break;
106
0
        case DiscoveryProtocol::SIMPLE:
107
0
            output << fastdds::rtps::ParticipantType::SIMPLE;
108
0
            break;
109
0
        case DiscoveryProtocol::EXTERNAL:
110
0
            output << fastdds::rtps::ParticipantType::EXTERNAL;
111
0
            break;
112
0
        case DiscoveryProtocol::CLIENT:
113
0
            output << fastdds::rtps::ParticipantType::CLIENT;
114
0
            break;
115
0
        case DiscoveryProtocol::SUPER_CLIENT:
116
0
            output << fastdds::rtps::ParticipantType::SUPER_CLIENT;
117
0
            break;
118
0
        case DiscoveryProtocol::SERVER:
119
0
            output << fastdds::rtps::ParticipantType::SERVER;
120
0
            break;
121
0
        case DiscoveryProtocol::BACKUP:
122
0
            output << fastdds::rtps::ParticipantType::BACKUP;
123
0
            break;
124
0
        default:
125
0
            output << fastdds::rtps::ParticipantType::UNKNOWN;
126
0
    }
127
0
    return output;
128
0
}
129
130
//!Filtering flags when discovering participants
131
typedef enum ParticipantFilteringFlags : uint32_t
132
{
133
    NO_FILTER = 0,
134
    FILTER_DIFFERENT_HOST = 0x1,
135
    FILTER_DIFFERENT_PROCESS = 0x2,
136
    FILTER_SAME_PROCESS = 0x4
137
} ParticipantFilteringFlags_t;
138
139
#define BUILTIN_DATA_MAX_SIZE 512
140
141
//! PDP factory for EXTERNAL type
142
class PDP;
143
class BuiltinProtocols;
144
145
typedef struct _PDPFactory
146
{
147
    // Pointer to the PDP creator
148
    PDP* (*CreatePDPInstance)(BuiltinProtocols*);
149
    // Pointer to the PDP destructor
150
    void (* ReleasePDPInstance)(
151
            PDP*);
152
153
    bool operator ==(
154
            const struct _PDPFactory& e) const
155
0
    {
156
0
        return (CreatePDPInstance == e.CreatePDPInstance)
157
0
               && (ReleasePDPInstance == e.ReleasePDPInstance);
158
0
    }
159
160
} PDPFactory;
161
162
/**
163
 * Class SimpleEDPAttributes, to define the attributes of the Simple Endpoint Discovery Protocol.
164
 * @ingroup RTPS_ATTRIBUTES_MODULE
165
 */
166
class SimpleEDPAttributes
167
{
168
public:
169
170
    //!Default value true.
171
    bool use_PublicationWriterANDSubscriptionReader;
172
173
    //!Default value true.
174
    bool use_PublicationReaderANDSubscriptionWriter;
175
176
#if HAVE_SECURITY
177
    bool enable_builtin_secure_publications_writer_and_subscriptions_reader;
178
179
    bool enable_builtin_secure_subscriptions_writer_and_publications_reader;
180
#endif // if HAVE_SECURITY
181
182
    SimpleEDPAttributes()
183
        : use_PublicationWriterANDSubscriptionReader(true)
184
        , use_PublicationReaderANDSubscriptionWriter(true)
185
#if HAVE_SECURITY
186
        , enable_builtin_secure_publications_writer_and_subscriptions_reader(true)
187
        , enable_builtin_secure_subscriptions_writer_and_publications_reader(true)
188
#endif // if HAVE_SECURITY
189
19.6k
    {
190
19.6k
    }
191
192
    bool operator ==(
193
            const SimpleEDPAttributes& b) const
194
0
    {
195
0
        return (this->use_PublicationWriterANDSubscriptionReader == b.use_PublicationWriterANDSubscriptionReader) &&
196
0
#if HAVE_SECURITY
197
0
               (this->enable_builtin_secure_publications_writer_and_subscriptions_reader ==
198
0
               b.enable_builtin_secure_publications_writer_and_subscriptions_reader) &&
199
0
               (this->enable_builtin_secure_subscriptions_writer_and_publications_reader ==
200
0
               b.enable_builtin_secure_subscriptions_writer_and_publications_reader) &&
201
0
#endif // if HAVE_SECURITY
202
0
               (this->use_PublicationReaderANDSubscriptionWriter == b.use_PublicationReaderANDSubscriptionWriter);
203
0
    }
204
205
};
206
207
/**
208
 * Struct InitialAnnouncementConfig defines the behavior of the RTPSParticipant initial announcements.
209
 * @ingroup RTPS_ATTRIBUTES_MODULE
210
 */
211
struct InitialAnnouncementConfig
212
{
213
    /// Number of initial announcements with specific period (default 5)
214
    uint32_t count = 5u;
215
216
    /// Specific period for initial announcements (default 100ms)
217
    Duration_t period = { 0, 100000000u };
218
219
    bool operator ==(
220
            const InitialAnnouncementConfig& b) const
221
0
    {
222
0
        return (count == b.count) && (period == b.period);
223
0
    }
224
225
};
226
227
/**
228
 * Class DiscoverySettings, to define the attributes of the several discovery protocols available
229
 * @ingroup RTPS_ATTRIBUTES_MODULE
230
 */
231
232
class DiscoverySettings
233
{
234
public:
235
236
    //! Chosen discovery protocol
237
    DiscoveryProtocol_t discoveryProtocol = DiscoveryProtocol_t::SIMPLE;
238
239
    /**
240
     * If set to true, SimpleEDP would be used.
241
     */
242
    bool use_SIMPLE_EndpointDiscoveryProtocol = true;
243
244
    /**
245
     * If set to true, StaticEDP based on an XML file would be implemented.
246
     * The XML filename must be provided.
247
     */
248
    bool use_STATIC_EndpointDiscoveryProtocol = false;
249
250
    /**
251
     * Lease Duration of the RTPSParticipant,
252
     * indicating how much time remote RTPSParticipants should consider this RTPSParticipant alive.
253
     */
254
    Duration_t leaseDuration = { 20, 0 };
255
256
    /**
257
     * The period for the RTPSParticipant to send its Discovery Message to all other discovered RTPSParticipants
258
     * as well as to all Multicast ports.
259
     */
260
    Duration_t leaseDuration_announcementperiod = { 3, 0 };
261
262
    //!Initial announcements configuration
263
    InitialAnnouncementConfig initial_announcements;
264
265
    //!Attributes of the SimpleEDP protocol
266
    SimpleEDPAttributes m_simpleEDP;
267
268
    //! function that returns a PDP object (only if EXTERNAL selected)
269
    PDPFactory m_PDPfactory{};
270
    /**
271
     * The period for the RTPSParticipant to:
272
     *  send its Discovery Message to its servers
273
     *  check for EDP endpoints matching
274
     */
275
    Duration_t discoveryServer_client_syncperiod = { 0, 450 * 1000000}; // 450 milliseconds
276
277
    //! Discovery Server settings, only needed if use_CLIENT_DiscoveryProtocol=true
278
    eprosima::fastdds::rtps::RemoteServerList_t m_DiscoveryServers;
279
280
    //! Filtering participants out depending on location
281
    ParticipantFilteringFlags_t ignoreParticipantFlags = ParticipantFilteringFlags::NO_FILTER;
282
283
19.6k
    DiscoverySettings() = default;
284
285
    bool operator ==(
286
            const DiscoverySettings& b) const
287
0
    {
288
0
        return (this->discoveryProtocol == b.discoveryProtocol) &&
289
0
               (this->use_SIMPLE_EndpointDiscoveryProtocol == b.use_SIMPLE_EndpointDiscoveryProtocol) &&
290
0
               (this->use_STATIC_EndpointDiscoveryProtocol == b.use_STATIC_EndpointDiscoveryProtocol) &&
291
0
               (this->discoveryServer_client_syncperiod == b.discoveryServer_client_syncperiod) &&
292
0
               (this->m_PDPfactory == b.m_PDPfactory) &&
293
0
               (this->leaseDuration == b.leaseDuration) &&
294
0
               (this->leaseDuration_announcementperiod == b.leaseDuration_announcementperiod) &&
295
0
               (this->initial_announcements == b.initial_announcements) &&
296
0
               (this->m_simpleEDP == b.m_simpleEDP) &&
297
0
               (this->static_edp_xml_config_ == b.static_edp_xml_config_) &&
298
0
               (this->m_DiscoveryServers == b.m_DiscoveryServers) &&
299
0
               (this->ignoreParticipantFlags == b.ignoreParticipantFlags);
300
0
    }
301
302
    /**
303
     * Get the static endpoint XML filename
304
     * @return Static endpoint XML filename
305
     */
306
    FASTRTPS_DEPRECATED("Use static_edp_xml_config()")
307
    const char* getStaticEndpointXMLFilename() const
308
0
    {
309
0
        return static_edp_xml_config();
310
0
    }
311
312
    /**
313
     * Set the static endpoint XML filename
314
     * @param str Static endpoint XML filename
315
     * @deprecated
316
     */
317
    FASTRTPS_DEPRECATED("Use static_edp_xml_config()")
318
    void setStaticEndpointXMLFilename(
319
            const char* str)
320
0
    {
321
0
        static_edp_xml_config_ = "file://" + std::string(str);
322
0
    }
323
324
    /**
325
     * Set the static endpoint XML configuration.
326
     * @param str URI specifying the static endpoint XML configuration.
327
     * The string could contain a filename (file://) or the XML content directly (data://).
328
     */
329
    void static_edp_xml_config(
330
            const char* str)
331
0
    {
332
0
        static_edp_xml_config_ = str;
333
0
    }
334
335
    /**
336
     * Get the static endpoint XML configuration.
337
     * @return URI specifying the static endpoint XML configuration.
338
     * The string could contain a filename (file://) or the XML content directly (data://).
339
     */
340
    const char* static_edp_xml_config() const
341
0
    {
342
0
        return static_edp_xml_config_.c_str();
343
0
    }
344
345
private:
346
347
    //! URI specifying the static EDP XML configuration, only necessary if use_STATIC_EndpointDiscoveryProtocol=true
348
    //! This string could contain a filename or the XML content directly.
349
    std::string static_edp_xml_config_ = "";
350
};
351
352
/**
353
 * TypeLookupService settings.
354
 */
355
class TypeLookupSettings
356
{
357
public:
358
359
    //!Indicates to use the TypeLookup Service client endpoints
360
    bool use_client = false;
361
362
    //!Indicates to use the TypeLookup Service server endpoints
363
    bool use_server = false;
364
365
};
366
367
/**
368
 * Class BuiltinAttributes, to define the behavior of the RTPSParticipant builtin protocols.
369
 * @ingroup RTPS_ATTRIBUTES_MODULE
370
 */
371
class BuiltinAttributes
372
{
373
public:
374
375
    //! Discovery protocol related attributes
376
    DiscoverySettings discovery_config;
377
378
    //! Indicates to use the WriterLiveliness protocol.
379
    bool use_WriterLivelinessProtocol = true;
380
381
    //! TypeLookup Service settings
382
    TypeLookupSettings typelookup_config;
383
384
    //! Metatraffic Unicast Locator List
385
    LocatorList_t metatrafficUnicastLocatorList;
386
387
    //! Metatraffic Multicast Locator List.
388
    LocatorList_t metatrafficMulticastLocatorList;
389
390
    //! The collection of external locators to use for communication on metatraffic topics.
391
    fastdds::rtps::ExternalLocators metatraffic_external_unicast_locators;
392
393
    //! Initial peers.
394
    LocatorList_t initialPeersList;
395
396
    //! Memory policy for builtin readers
397
    MemoryManagementPolicy_t readerHistoryMemoryPolicy =
398
            MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
399
400
    //! Maximum payload size for builtin readers
401
    uint32_t readerPayloadSize = BUILTIN_DATA_MAX_SIZE;
402
403
    //! Memory policy for builtin writers
404
    MemoryManagementPolicy_t writerHistoryMemoryPolicy =
405
            MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
406
407
    //! Maximum payload size for builtin writers
408
    uint32_t writerPayloadSize = BUILTIN_DATA_MAX_SIZE;
409
410
    //! Mutation tries if the port is being used.
411
    uint32_t mutation_tries = 100u;
412
413
    //! Set to true to avoid multicast traffic on builtin endpoints
414
    bool avoid_builtin_multicast = true;
415
416
19.6k
    BuiltinAttributes() = default;
417
418
19.1k
    virtual ~BuiltinAttributes() = default;
419
420
    bool operator ==(
421
            const BuiltinAttributes& b) const
422
0
    {
423
0
        return (this->discovery_config == b.discovery_config) &&
424
0
               (this->use_WriterLivelinessProtocol == b.use_WriterLivelinessProtocol) &&
425
0
               (typelookup_config.use_client == b.typelookup_config.use_client) &&
426
0
               (typelookup_config.use_server == b.typelookup_config.use_server) &&
427
0
               (this->metatrafficUnicastLocatorList == b.metatrafficUnicastLocatorList) &&
428
0
               (this->metatrafficMulticastLocatorList == b.metatrafficMulticastLocatorList) &&
429
0
               (this->metatraffic_external_unicast_locators == b.metatraffic_external_unicast_locators) &&
430
0
               (this->initialPeersList == b.initialPeersList) &&
431
0
               (this->readerHistoryMemoryPolicy == b.readerHistoryMemoryPolicy) &&
432
0
               (this->readerPayloadSize == b.readerPayloadSize) &&
433
0
               (this->writerHistoryMemoryPolicy == b.writerHistoryMemoryPolicy) &&
434
0
               (this->writerPayloadSize == b.writerPayloadSize) &&
435
0
               (this->mutation_tries == b.mutation_tries) &&
436
0
               (this->avoid_builtin_multicast == b.avoid_builtin_multicast);
437
0
    }
438
439
};
440
441
/**
442
 * Class RTPSParticipantAttributes used to define different aspects of a RTPSParticipant.
443
 *@ingroup RTPS_ATTRIBUTES_MODULE
444
 */
445
class RTPSParticipantAttributes
446
{
447
    using FlowControllerDescriptorList = std::vector<std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>>;
448
449
public:
450
451
    RTPSParticipantAttributes()
452
19.6k
    {
453
19.6k
        setName("RTPSParticipant");
454
19.6k
        sendSocketBufferSize = 0;
455
19.6k
        listenSocketBufferSize = 0;
456
19.6k
        participantID = -1;
457
19.6k
        useBuiltinTransports = true;
458
19.6k
    }
459
460
    virtual ~RTPSParticipantAttributes()
461
19.1k
    {
462
19.1k
    }
463
464
    bool operator ==(
465
            const RTPSParticipantAttributes& b) const
466
0
    {
467
0
        return (this->name == b.name) &&
468
0
               (this->defaultUnicastLocatorList == b.defaultUnicastLocatorList) &&
469
0
               (this->defaultMulticastLocatorList == b.defaultMulticastLocatorList) &&
470
0
               (this->default_external_unicast_locators == b.default_external_unicast_locators) &&
471
0
               (this->ignore_non_matching_locators == b.ignore_non_matching_locators) &&
472
0
               (this->sendSocketBufferSize == b.sendSocketBufferSize) &&
473
0
               (this->listenSocketBufferSize == b.listenSocketBufferSize) &&
474
0
               (this->builtin == b.builtin) &&
475
0
               (this->port == b.port) &&
476
0
               (this->userData == b.userData) &&
477
0
               (this->participantID == b.participantID) &&
478
0
               (this->throughputController == b.throughputController) &&
479
0
               (this->useBuiltinTransports == b.useBuiltinTransports) &&
480
0
               (this->properties == b.properties) &&
481
0
               (this->prefix == b.prefix) &&
482
0
               (this->flow_controllers == b.flow_controllers);
483
0
    }
484
485
    /**
486
     * Default list of Unicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the case
487
     * that it was defined with NO UnicastLocators. At least ONE locator should be included in this list.
488
     */
489
    LocatorList_t defaultUnicastLocatorList;
490
491
    /**
492
     * Default list of Multicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the
493
     * case that it was defined with NO MulticastLocators. This is usually left empty.
494
     */
495
    LocatorList_t defaultMulticastLocatorList;
496
497
    /**
498
     * The collection of external locators to use for communication on user created topics.
499
     */
500
    fastdds::rtps::ExternalLocators default_external_unicast_locators;
501
502
    /**
503
     * Whether locators that don't match with the announced locators should be kept.
504
     */
505
    bool ignore_non_matching_locators = false;
506
507
    /*!
508
     * @brief Send socket buffer size for the send resource. Zero value indicates to use default system buffer size.
509
     * Default value: 0.
510
     */
511
    uint32_t sendSocketBufferSize;
512
513
    /*! Listen socket buffer for all listen resources. Zero value indicates to use default system buffer size.
514
     * Default value: 0.
515
     */
516
    uint32_t listenSocketBufferSize;
517
518
    //! Optionally allows user to define the GuidPrefix_t
519
    GuidPrefix_t prefix;
520
521
    RTPS_DllAPI inline bool ReadguidPrefix(
522
            const char* pfx)
523
0
    {
524
0
        return bool(std::istringstream(pfx) >> prefix);
525
0
    }
526
527
    //! Builtin parameters.
528
    BuiltinAttributes builtin;
529
530
    //! Port Parameters
531
    PortParameters port;
532
533
    //! User Data of the participant
534
    std::vector<octet> userData;
535
536
    //! Participant ID
537
    int32_t participantID;
538
539
    //! Throughput controller parameters. Leave default for uncontrolled flow.
540
    ThroughputControllerDescriptor throughputController;
541
542
    //! User defined transports to use alongside or in place of builtins.
543
    std::vector<std::shared_ptr<fastdds::rtps::TransportDescriptorInterface>> userTransports;
544
545
    //! Set as false to disable the default UDPv4 implementation.
546
    bool useBuiltinTransports;
547
548
    //! Holds allocation limits affecting collections managed by a participant.
549
    RTPSParticipantAllocationAttributes allocation;
550
551
    //! Property policies
552
    PropertyPolicy properties;
553
554
    //! Set the name of the participant.
555
    inline void setName(
556
            const char* nam)
557
21.1k
    {
558
21.1k
        name = nam;
559
21.1k
    }
560
561
    //! Get the name of the participant.
562
    inline const char* getName() const
563
0
    {
564
0
        return name.c_str();
565
0
    }
566
567
    //! Flow controllers.
568
    FlowControllerDescriptorList flow_controllers;
569
570
private:
571
572
    //! Name of the participant.
573
    string_255 name;
574
};
575
576
} /* namespace rtps */
577
} /* namespace fastrtps */
578
} /* namespace eprosima */
579
580
#endif /* _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ */