RTPSParticipantAttributes.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. * @file RTPSParticipantAttributes.h
  16. */
  17. #ifndef _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_
  18. #define _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_
  19. #include <fastdds/rtps/common/Time_t.h>
  20. #include <fastdds/rtps/common/Locator.h>
  21. #include <fastdds/rtps/common/PortParameters.h>
  22. #include <fastdds/rtps/attributes/PropertyPolicy.h>
  23. #include <fastdds/rtps/flowcontrol/ThroughputControllerDescriptor.h>
  24. #include <fastdds/rtps/transport/TransportInterface.h>
  25. #include <fastdds/rtps/resources/ResourceManagement.h>
  26. #include <fastrtps/utils/fixed_size_string.hpp>
  27. #include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
  28. #include <fastdds/rtps/attributes/ServerAttributes.h>
  29. #include <memory>
  30. #include <sstream>
  31. namespace eprosima {
  32. namespace fastrtps {
  33. namespace rtps {
  34. //!PDP subclass choice
  35. typedef enum DiscoveryProtocol
  36. {
  37. NONE,
  38. /*!<
  39. NO discovery whatsoever would be used.
  40. Publisher and Subscriber defined with the same topic name would NOT be linked.
  41. All matching must be done manually through the addReaderLocator, addReaderProxy, addWriterProxy methods.
  42. */
  43. SIMPLE,
  44. /*!<
  45. Discovery works according to 'The Real-time Publish-Subscribe Protocol(RTPS) DDS
  46. Interoperability Wire Protocol Specification'
  47. */
  48. EXTERNAL,
  49. /*!<
  50. A user defined PDP subclass object must be provided in the attributes that deals with the discovery.
  51. Framework is not responsible of this object lifetime.
  52. */
  53. CLIENT, /*!< The participant will behave as a client concerning discovery operation.
  54. Server locators should be specified as attributes. */
  55. SERVER, /*!< The participant will behave as a server concerning discovery operation.
  56. Discovery operation is volatile (discovery handshake must take place if shutdown). */
  57. BACKUP /*!< The participant will behave as a server concerning discovery operation.
  58. Discovery operation persist on a file (discovery handshake wouldn't repeat if shutdown). */
  59. } DiscoveryProtocol_t;
  60. //!Filtering flags when discovering participants
  61. typedef enum ParticipantFilteringFlags : uint32_t
  62. {
  63. NO_FILTER = 0,
  64. FILTER_DIFFERENT_HOST = 0x1,
  65. FILTER_DIFFERENT_PROCESS = 0x2,
  66. FILTER_SAME_PROCESS = 0x4
  67. } ParticipantFilteringFlags_t;
  68. #define BUILTIN_DATA_MAX_SIZE 512
  69. //! PDP factory for EXTERNAL type
  70. class PDP;
  71. class BuiltinProtocols;
  72. typedef struct _PDPFactory
  73. {
  74. // Pointer to the PDP creator
  75. PDP* (*CreatePDPInstance)(BuiltinProtocols*);
  76. // Pointer to the PDP destructor
  77. void (* ReleasePDPInstance)(
  78. PDP*);
  79. bool operator ==(
  80. const struct _PDPFactory& e) const
  81. {
  82. return (CreatePDPInstance == e.CreatePDPInstance)
  83. && (ReleasePDPInstance == e.ReleasePDPInstance);
  84. }
  85. } PDPFactory;
  86. /**
  87. * Class SimpleEDPAttributes, to define the attributes of the Simple Endpoint Discovery Protocol.
  88. * @ingroup RTPS_ATTRIBUTES_MODULE
  89. */
  90. class SimpleEDPAttributes
  91. {
  92. public:
  93. //!Default value true.
  94. bool use_PublicationWriterANDSubscriptionReader;
  95. //!Default value true.
  96. bool use_PublicationReaderANDSubscriptionWriter;
  97. #if HAVE_SECURITY
  98. bool enable_builtin_secure_publications_writer_and_subscriptions_reader;
  99. bool enable_builtin_secure_subscriptions_writer_and_publications_reader;
  100. #endif
  101. SimpleEDPAttributes()
  102. : use_PublicationWriterANDSubscriptionReader(true)
  103. , use_PublicationReaderANDSubscriptionWriter(true)
  104. #if HAVE_SECURITY
  105. , enable_builtin_secure_publications_writer_and_subscriptions_reader(true)
  106. , enable_builtin_secure_subscriptions_writer_and_publications_reader(true)
  107. #endif
  108. {
  109. }
  110. bool operator ==(
  111. const SimpleEDPAttributes& b) const
  112. {
  113. return (this->use_PublicationWriterANDSubscriptionReader == b.use_PublicationWriterANDSubscriptionReader) &&
  114. #if HAVE_SECURITY
  115. (this->enable_builtin_secure_publications_writer_and_subscriptions_reader ==
  116. b.enable_builtin_secure_publications_writer_and_subscriptions_reader) &&
  117. (this->enable_builtin_secure_subscriptions_writer_and_publications_reader ==
  118. b.enable_builtin_secure_subscriptions_writer_and_publications_reader) &&
  119. #endif
  120. (this->use_PublicationReaderANDSubscriptionWriter == b.use_PublicationReaderANDSubscriptionWriter);
  121. }
  122. };
  123. /**
  124. * Struct InitialAnnouncementConfig defines the behavior of the RTPSParticipant initial announcements.
  125. * @ingroup RTPS_ATTRIBUTES_MODULE
  126. */
  127. struct InitialAnnouncementConfig
  128. {
  129. /// Number of initial announcements with specific period (default 5)
  130. uint32_t count = 5u;
  131. /// Specific period for initial announcements (default 100ms)
  132. Duration_t period = { 0, 100000000u };
  133. bool operator ==(
  134. const InitialAnnouncementConfig& b) const
  135. {
  136. return (count == b.count) && (period == b.period);
  137. }
  138. };
  139. /**
  140. * Class DiscoverySettings, to define the attributes of the several discovery protocols available
  141. * @ingroup RTPS_ATTRIBUTES_MODULE
  142. */
  143. class DiscoverySettings
  144. {
  145. public:
  146. //! Chosen discovery protocol
  147. DiscoveryProtocol_t discoveryProtocol = DiscoveryProtocol_t::SIMPLE;
  148. /**
  149. * If set to true, SimpleEDP would be used.
  150. */
  151. bool use_SIMPLE_EndpointDiscoveryProtocol = true;
  152. /**
  153. * If set to true, StaticEDP based on an XML file would be implemented.
  154. * The XML filename must be provided.
  155. */
  156. bool use_STATIC_EndpointDiscoveryProtocol = false;
  157. /**
  158. * Lease Duration of the RTPSParticipant,
  159. * indicating how much time remote RTPSParticipants should consider this RTPSParticipant alive.
  160. */
  161. Duration_t leaseDuration = { 20, 0 };
  162. /**
  163. * The period for the RTPSParticipant to send its Discovery Message to all other discovered RTPSParticipants
  164. * as well as to all Multicast ports.
  165. */
  166. Duration_t leaseDuration_announcementperiod = { 3, 0 };
  167. //!Initial announcements configuration
  168. InitialAnnouncementConfig initial_announcements;
  169. //!Attributes of the SimpleEDP protocol
  170. SimpleEDPAttributes m_simpleEDP;
  171. //! function that returns a PDP object (only if EXTERNAL selected)
  172. PDPFactory m_PDPfactory{};
  173. /**
  174. * The period for the RTPSParticipant to:
  175. * send its Discovery Message to its servers
  176. * check for EDP endpoints matching
  177. */
  178. Duration_t discoveryServer_client_syncperiod = { 0, 450 * 1000000}; // 450 milliseconds
  179. //! Discovery Server settings, only needed if use_CLIENT_DiscoveryProtocol=true
  180. RemoteServerList_t m_DiscoveryServers;
  181. //! Filtering participants out depending on location
  182. ParticipantFilteringFlags_t ignoreParticipantFlags = ParticipantFilteringFlags::NO_FILTER;
  183. DiscoverySettings() = default;
  184. bool operator ==(
  185. const DiscoverySettings& b) const
  186. {
  187. return (this->discoveryProtocol == b.discoveryProtocol) &&
  188. (this->use_SIMPLE_EndpointDiscoveryProtocol == b.use_SIMPLE_EndpointDiscoveryProtocol) &&
  189. (this->use_STATIC_EndpointDiscoveryProtocol == b.use_STATIC_EndpointDiscoveryProtocol) &&
  190. (this->discoveryServer_client_syncperiod == b.discoveryServer_client_syncperiod) &&
  191. (this->m_PDPfactory == b.m_PDPfactory) &&
  192. (this->leaseDuration == b.leaseDuration) &&
  193. (this->leaseDuration_announcementperiod == b.leaseDuration_announcementperiod) &&
  194. (this->initial_announcements == b.initial_announcements) &&
  195. (this->m_simpleEDP == b.m_simpleEDP) &&
  196. (this->m_staticEndpointXMLFilename == b.m_staticEndpointXMLFilename) &&
  197. (this->m_DiscoveryServers == b.m_DiscoveryServers) &&
  198. (this->ignoreParticipantFlags == b.ignoreParticipantFlags);
  199. }
  200. /**
  201. * Get the static endpoint XML filename
  202. * @return Static endpoint XML filename
  203. */
  204. const char* getStaticEndpointXMLFilename() const
  205. {
  206. return m_staticEndpointXMLFilename.c_str();
  207. }
  208. /**
  209. * Set the static endpoint XML filename
  210. * @param str Static endpoint XML filename
  211. */
  212. void setStaticEndpointXMLFilename(
  213. const char* str)
  214. {
  215. m_staticEndpointXMLFilename = std::string(str);
  216. }
  217. private:
  218. //! StaticEDP XML filename, only necessary if use_STATIC_EndpointDiscoveryProtocol=true
  219. std::string m_staticEndpointXMLFilename = "";
  220. };
  221. /**
  222. * TypeLookupService settings.
  223. */
  224. class TypeLookupSettings
  225. {
  226. public:
  227. //!Indicates to use the TypeLookup Service client endpoints
  228. bool use_client = false;
  229. //!Indicates to use the TypeLookup Service server endpoints
  230. bool use_server = false;
  231. };
  232. /**
  233. * Class BuiltinAttributes, to define the behavior of the RTPSParticipant builtin protocols.
  234. * @ingroup RTPS_ATTRIBUTES_MODULE
  235. */
  236. class BuiltinAttributes
  237. {
  238. public:
  239. //! Discovery protocol related attributes
  240. DiscoverySettings discovery_config;
  241. //!Indicates to use the WriterLiveliness protocol.
  242. bool use_WriterLivelinessProtocol = true;
  243. //!TypeLookup Service settings
  244. TypeLookupSettings typelookup_config;
  245. //!Metatraffic Unicast Locator List
  246. LocatorList_t metatrafficUnicastLocatorList;
  247. //!Metatraffic Multicast Locator List.
  248. LocatorList_t metatrafficMulticastLocatorList;
  249. //! Initial peers.
  250. LocatorList_t initialPeersList;
  251. //! Memory policy for builtin readers
  252. MemoryManagementPolicy_t readerHistoryMemoryPolicy =
  253. MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
  254. //! Maximum payload size for builtin readers
  255. uint32_t readerPayloadSize = BUILTIN_DATA_MAX_SIZE;
  256. //! Memory policy for builtin writers
  257. MemoryManagementPolicy_t writerHistoryMemoryPolicy =
  258. MemoryManagementPolicy_t::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
  259. //! Maximum payload size for builtin writers
  260. uint32_t writerPayloadSize = BUILTIN_DATA_MAX_SIZE;
  261. //! Mutation tries if the port is being used.
  262. uint32_t mutation_tries = 100u;
  263. //!Set to true to avoid multicast traffic on builtin endpoints
  264. bool avoid_builtin_multicast = true;
  265. BuiltinAttributes() = default;
  266. virtual ~BuiltinAttributes() = default;
  267. bool operator ==(
  268. const BuiltinAttributes& b) const
  269. {
  270. return (this->discovery_config == b.discovery_config) &&
  271. (this->use_WriterLivelinessProtocol == b.use_WriterLivelinessProtocol) &&
  272. (typelookup_config.use_client == b.typelookup_config.use_client) &&
  273. (typelookup_config.use_server == b.typelookup_config.use_server) &&
  274. (this->metatrafficUnicastLocatorList == b.metatrafficUnicastLocatorList) &&
  275. (this->metatrafficMulticastLocatorList == b.metatrafficMulticastLocatorList) &&
  276. (this->initialPeersList == b.initialPeersList) &&
  277. (this->readerHistoryMemoryPolicy == b.readerHistoryMemoryPolicy) &&
  278. (this->readerPayloadSize == b.readerPayloadSize) &&
  279. (this->writerHistoryMemoryPolicy == b.writerHistoryMemoryPolicy) &&
  280. (this->writerPayloadSize == b.writerPayloadSize) &&
  281. (this->mutation_tries == b.mutation_tries) &&
  282. (this->avoid_builtin_multicast == b.avoid_builtin_multicast);
  283. }
  284. };
  285. /**
  286. * Class RTPSParticipantAttributes used to define different aspects of a RTPSParticipant.
  287. *@ingroup RTPS_ATTRIBUTES_MODULE
  288. */
  289. class RTPSParticipantAttributes
  290. {
  291. public:
  292. RTPSParticipantAttributes()
  293. {
  294. setName("RTPSParticipant");
  295. sendSocketBufferSize = 0;
  296. listenSocketBufferSize = 0;
  297. participantID = -1;
  298. useBuiltinTransports = true;
  299. }
  300. virtual ~RTPSParticipantAttributes()
  301. {
  302. }
  303. bool operator ==(
  304. const RTPSParticipantAttributes& b) const
  305. {
  306. return (this->name == b.name) &&
  307. (this->defaultUnicastLocatorList == b.defaultUnicastLocatorList) &&
  308. (this->defaultMulticastLocatorList == b.defaultMulticastLocatorList) &&
  309. (this->sendSocketBufferSize == b.sendSocketBufferSize) &&
  310. (this->listenSocketBufferSize == b.listenSocketBufferSize) &&
  311. (this->builtin == b.builtin) &&
  312. (this->port == b.port) &&
  313. (this->userData == b.userData) &&
  314. (this->participantID == b.participantID) &&
  315. (this->throughputController == b.throughputController) &&
  316. (this->useBuiltinTransports == b.useBuiltinTransports) &&
  317. (this->properties == b.properties &&
  318. (this->prefix == b.prefix));
  319. }
  320. /**
  321. * Default list of Unicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the case
  322. * that it was defined with NO UnicastLocators. At least ONE locator should be included in this list.
  323. */
  324. LocatorList_t defaultUnicastLocatorList;
  325. /**
  326. * Default list of Multicast Locators to be used for any Endpoint defined inside this RTPSParticipant in the
  327. * case that it was defined with NO UnicastLocators. This is usually left empty.
  328. */
  329. LocatorList_t defaultMulticastLocatorList;
  330. /*!
  331. * @brief Send socket buffer size for the send resource. Zero value indicates to use default system buffer size.
  332. * Default value: 0.
  333. */
  334. uint32_t sendSocketBufferSize;
  335. /*! Listen socket buffer for all listen resources. Zero value indicates to use default system buffer size.
  336. * Default value: 0.
  337. */
  338. uint32_t listenSocketBufferSize;
  339. //! Optionally allows user to define the GuidPrefix_t
  340. GuidPrefix_t prefix;
  341. RTPS_DllAPI inline bool ReadguidPrefix(
  342. const char* pfx)
  343. {
  344. return bool(std::istringstream(pfx) >> prefix);
  345. }
  346. //! Builtin parameters.
  347. BuiltinAttributes builtin;
  348. //!Port Parameters
  349. PortParameters port;
  350. //!User Data of the participant
  351. std::vector<octet> userData;
  352. //!Participant ID
  353. int32_t participantID;
  354. //!Throughput controller parameters. Leave default for uncontrolled flow.
  355. ThroughputControllerDescriptor throughputController;
  356. //!User defined transports to use alongside or in place of builtins.
  357. std::vector<std::shared_ptr<fastdds::rtps::TransportDescriptorInterface> > userTransports;
  358. //!Set as false to disable the default UDPv4 implementation.
  359. bool useBuiltinTransports;
  360. //!Holds allocation limits affecting collections managed by a participant.
  361. RTPSParticipantAllocationAttributes allocation;
  362. //! Property policies
  363. PropertyPolicy properties;
  364. //!Set the name of the participant.
  365. inline void setName(
  366. const char* nam)
  367. {
  368. name = nam;
  369. }
  370. //!Get the name of the participant.
  371. inline const char* getName() const
  372. {
  373. return name.c_str();
  374. }
  375. private:
  376. //!Name of the participant.
  377. string_255 name;
  378. };
  379. } /* namespace rtps */
  380. } /* namespace fastrtps */
  381. } /* namespace eprosima */
  382. #endif /* _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ */