RTPSParticipantAllocationAttributes.hpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright 2019 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 RTPSParticipantAllocationAttributes.hpp
  16. */
  17. #ifndef _FASTDDS_RTPS_RTPSPARTICIPANTALLOCATIONATTRIBUTES_HPP_
  18. #define _FASTDDS_RTPS_RTPSPARTICIPANTALLOCATIONATTRIBUTES_HPP_
  19. #include <fastrtps/utils/collections/ResourceLimitedContainerConfig.hpp>
  20. namespace eprosima {
  21. namespace fastrtps {
  22. namespace rtps {
  23. /**
  24. * @brief Holds limits for collections of remote locators.
  25. */
  26. struct RemoteLocatorsAllocationAttributes
  27. {
  28. bool operator ==(
  29. const RemoteLocatorsAllocationAttributes& b) const
  30. {
  31. return (this->max_unicast_locators == b.max_unicast_locators) &&
  32. (this->max_multicast_locators == b.max_multicast_locators);
  33. }
  34. /** Maximum number of unicast locators per remote entity.
  35. *
  36. * This attribute controls the maximum number of unicast locators to keep for
  37. * each discovered remote entity (be it a participant, reader of writer). It is
  38. * recommended to use the highest number of local addresses found on all the systems
  39. * belonging to the same domain as this participant.
  40. */
  41. size_t max_unicast_locators = 4u;
  42. /** Maximum number of multicast locators per remote entity.
  43. *
  44. * This attribute controls the maximum number of multicast locators to keep for
  45. * each discovered remote entity (be it a participant, reader of writer). The
  46. * default value of 1 is usually enough, as it doesn't make sense to add more
  47. * than one multicast locator per entity.
  48. */
  49. size_t max_multicast_locators = 1u;
  50. };
  51. /**
  52. * @brief Holds limits for send buffers allocations.
  53. */
  54. struct SendBuffersAllocationAttributes
  55. {
  56. bool operator ==(
  57. const SendBuffersAllocationAttributes& b) const
  58. {
  59. return (this->preallocated_number == b.preallocated_number) &&
  60. (this->dynamic == b.dynamic);
  61. }
  62. /** Initial number of send buffers to allocate.
  63. *
  64. * This attribute controls the initial number of send buffers to be allocated.
  65. * The default value of 0 will perform an initial guess of the number of buffers
  66. * required, based on the number of threads from which a send operation could be
  67. * started.
  68. */
  69. size_t preallocated_number = 0u;
  70. /** Whether the number of send buffers is allowed to grow.
  71. *
  72. * This attribute controls how the buffer manager behaves when a send buffer is not
  73. * available. When true, a new buffer will be created. When false, it will wait for a
  74. * buffer to be returned. This is a tradeoff between latency and dynamic allocations.
  75. */
  76. bool dynamic = false;
  77. };
  78. /**
  79. * @brief Holds limits for variable-length data.
  80. */
  81. struct VariableLengthDataLimits
  82. {
  83. bool operator ==(
  84. const VariableLengthDataLimits& b) const
  85. {
  86. return (this->max_properties == b.max_properties) &&
  87. (this->max_user_data == b.max_user_data) &&
  88. (this->max_partitions == b.max_partitions);
  89. }
  90. //! Defines the maximum size (in octets) of properties data in the local or remote participant
  91. size_t max_properties = 0;
  92. //! Defines the maximum size (in octets) of user data in the local or remote participant
  93. size_t max_user_data = 0;
  94. //! Defines the maximum size (in octets) of partitions data
  95. size_t max_partitions = 0;
  96. };
  97. /**
  98. * @brief Holds allocation limits affecting collections managed by a participant.
  99. */
  100. struct RTPSParticipantAllocationAttributes
  101. {
  102. //! Holds limits for collections of remote locators.
  103. RemoteLocatorsAllocationAttributes locators;
  104. //! Defines the allocation behaviour for collections dependent on the total number of participants.
  105. ResourceLimitedContainerConfig participants;
  106. //! Defines the allocation behaviour for collections dependent on the total number of readers per participant.
  107. ResourceLimitedContainerConfig readers;
  108. //! Defines the allocation behaviour for collections dependent on the total number of writers per participant.
  109. ResourceLimitedContainerConfig writers;
  110. //! Defines the allocation behaviour for the send buffer manager.
  111. SendBuffersAllocationAttributes send_buffers;
  112. //! Holds limits for variable-length data
  113. VariableLengthDataLimits data_limits;
  114. //! @return the allocation config for the total of readers in the system (participants * readers)
  115. ResourceLimitedContainerConfig total_readers() const
  116. {
  117. return total_endpoints(readers);
  118. }
  119. //! @return the allocation config for the total of writers in the system (participants * writers)
  120. ResourceLimitedContainerConfig total_writers() const
  121. {
  122. return total_endpoints(writers);
  123. }
  124. bool operator ==(
  125. const RTPSParticipantAllocationAttributes& b) const
  126. {
  127. return (this->locators == b.locators) &&
  128. (this->participants == b.participants) &&
  129. (this->readers == b.readers) &&
  130. (this->writers == b.writers) &&
  131. (this->send_buffers == b.send_buffers) &&
  132. (this->data_limits == b.data_limits);
  133. }
  134. private:
  135. ResourceLimitedContainerConfig total_endpoints(
  136. const ResourceLimitedContainerConfig& endpoints) const
  137. {
  138. constexpr size_t max = std::numeric_limits<size_t>::max();
  139. size_t initial;
  140. size_t maximum;
  141. size_t increment;
  142. initial = participants.initial * endpoints.initial;
  143. maximum = (participants.maximum == max || endpoints.maximum == max)
  144. ? max : participants.maximum * endpoints.maximum;
  145. increment = std::max(participants.increment, endpoints.increment);
  146. return { initial, maximum, increment };
  147. }
  148. };
  149. const RTPSParticipantAllocationAttributes c_default_RTPSParticipantAllocationAttributes
  150. = RTPSParticipantAllocationAttributes();
  151. } /* namespace rtps */
  152. } /* namespace fastrtps */
  153. } /* namespace eprosima */
  154. #endif /* _FASTDDS_RTPS_RTPSPARTICIPANTALLOCATIONATTRIBUTES_HPP_ */