Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/include/fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp
Line
Count
Source (jump to first uncovered line)
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
/**
16
 * @file RTPSParticipantAllocationAttributes.hpp
17
 */
18
19
#ifndef FASTDDS_RTPS_ATTRIBUTES__RTPSPARTICIPANTALLOCATIONATTRIBUTES_HPP
20
#define FASTDDS_RTPS_ATTRIBUTES__RTPSPARTICIPANTALLOCATIONATTRIBUTES_HPP
21
22
#include <fastdds/rtps/builtin/data/ContentFilterProperty.hpp>
23
24
#include <fastdds/utils/collections/ResourceLimitedContainerConfig.hpp>
25
26
namespace eprosima {
27
namespace fastdds {
28
namespace rtps {
29
30
/**
31
 * @brief Holds limits for collections of remote locators.
32
 */
33
struct RemoteLocatorsAllocationAttributes
34
{
35
    bool operator ==(
36
            const RemoteLocatorsAllocationAttributes& b) const
37
0
    {
38
0
        return (this->max_unicast_locators == b.max_unicast_locators) &&
39
0
               (this->max_multicast_locators == b.max_multicast_locators);
40
0
    }
41
42
    /** Maximum number of unicast locators per remote entity.
43
     *
44
     * This attribute controls the maximum number of unicast locators to keep for
45
     * each discovered remote entity (be it a participant, reader of writer). It is
46
     * recommended to use the highest number of local addresses found on all the systems
47
     * belonging to the same domain as this participant.
48
     */
49
    size_t max_unicast_locators = 4u;
50
51
    /** Maximum number of multicast locators per remote entity.
52
     *
53
     * This attribute controls the maximum number of multicast locators to keep for
54
     * each discovered remote entity (be it a participant, reader of writer). The
55
     * default value of 1 is usually enough, as it doesn't make sense to add more
56
     * than one multicast locator per entity.
57
     */
58
    size_t max_multicast_locators = 1u;
59
};
60
61
/**
62
 * @brief Holds limits for send buffers allocations.
63
 */
64
struct SendBuffersAllocationAttributes
65
{
66
    bool operator ==(
67
            const SendBuffersAllocationAttributes& b) const
68
0
    {
69
0
        return (this->preallocated_number == b.preallocated_number) &&
70
0
               (this->dynamic == b.dynamic) &&
71
0
               (this->network_buffers_config == b.network_buffers_config);
72
0
    }
73
74
    /** Initial number of send buffers to allocate.
75
     *
76
     * This attribute controls the initial number of send buffers to be allocated.
77
     * The default value of 0 will perform an initial guess of the number of buffers
78
     * required, based on the number of threads from which a send operation could be
79
     * started.
80
     */
81
    size_t preallocated_number = 0u;
82
83
    /** Whether the number of send buffers is allowed to grow.
84
     *
85
     * This attribute controls how the buffer manager behaves when a send buffer is not
86
     * available. When true, a new buffer will be created. When false, it will wait for a
87
     * buffer to be returned. This is a trade-off between latency and dynamic allocations.
88
     */
89
    bool dynamic = false;
90
91
    /** Configuration for the network buffers.
92
     *
93
     * This attribute controls the allocation behavior of the network buffers used by each
94
     * send buffer. The default value will use a value of 16 network buffers for both
95
     * the preallocated buffers and the dynamic increment allocation, with no maximum limit.
96
     */
97
    ResourceLimitedContainerConfig network_buffers_config = ResourceLimitedContainerConfig(16u,
98
                    std::numeric_limits<size_t>::max dummy_avoid_winmax (), 16u);
99
};
100
101
/**
102
 * @brief Holds limits for variable-length data.
103
 */
104
struct VariableLengthDataLimits
105
{
106
    bool operator ==(
107
            const VariableLengthDataLimits& b) const
108
0
    {
109
0
        return (this->max_properties == b.max_properties) &&
110
0
               (this->max_user_data == b.max_user_data) &&
111
0
               (this->max_partitions == b.max_partitions) &&
112
0
               (this->max_datasharing_domains == b.max_datasharing_domains);
113
0
    }
114
115
    //! Defines the maximum size (in octets) of properties data in the local or remote participant
116
    size_t max_properties = 0;
117
    //! Defines the maximum size (in octets) of user data in the local or remote participant
118
    size_t max_user_data = 0;
119
    //! Defines the maximum size (in octets) of partitions data
120
    size_t max_partitions = 0;
121
    //! Defines the maximum size (in elements) of the list of data sharing domain IDs
122
    size_t max_datasharing_domains = 0;
123
};
124
125
/**
126
 * @brief Holds allocation limits affecting collections managed by a participant.
127
 */
128
struct RTPSParticipantAllocationAttributes
129
{
130
    //! Holds limits for collections of remote locators.
131
    RemoteLocatorsAllocationAttributes locators;
132
    //! Defines the allocation behaviour for collections dependent on the total number of participants.
133
    ResourceLimitedContainerConfig participants;
134
    //! Defines the allocation behaviour for collections dependent on the total number of readers per participant.
135
    ResourceLimitedContainerConfig readers;
136
    //! Defines the allocation behaviour for collections dependent on the total number of writers per participant.
137
    ResourceLimitedContainerConfig writers;
138
    //! Defines the allocation behaviour for the send buffer manager.
139
    SendBuffersAllocationAttributes send_buffers;
140
    //! Holds limits for variable-length data
141
    VariableLengthDataLimits data_limits;
142
    //! Defines the allocation behavior of content filter discovery information
143
    fastdds::rtps::ContentFilterProperty::AllocationConfiguration content_filter;
144
145
    //! @return the allocation config for the total of readers in the system (participants * readers)
146
    ResourceLimitedContainerConfig total_readers() const
147
0
    {
148
0
        return total_endpoints(readers);
149
0
    }
150
151
    //! @return the allocation config for the total of writers in the system (participants * writers)
152
    ResourceLimitedContainerConfig total_writers() const
153
0
    {
154
0
        return total_endpoints(writers);
155
0
    }
156
157
    bool operator ==(
158
            const RTPSParticipantAllocationAttributes& b) const
159
0
    {
160
0
        return (this->locators == b.locators) &&
161
0
               (this->participants == b.participants) &&
162
0
               (this->readers == b.readers) &&
163
0
               (this->writers == b.writers) &&
164
0
               (this->send_buffers == b.send_buffers) &&
165
0
               (this->data_limits == b.data_limits);
166
0
    }
167
168
private:
169
170
    ResourceLimitedContainerConfig total_endpoints(
171
            const ResourceLimitedContainerConfig& endpoints) const
172
0
    {
173
0
        constexpr size_t max = (std::numeric_limits<size_t>::max)();
174
0
        size_t initial;
175
0
        size_t maximum;
176
0
        size_t increment;
177
178
0
        initial = participants.initial * endpoints.initial;
179
0
        maximum = (participants.maximum == max || endpoints.maximum == max)
180
0
                ? max : participants.maximum * endpoints.maximum;
181
0
        increment = (std::max)(participants.increment, endpoints.increment);
182
183
0
        return { initial, maximum, increment };
184
0
    }
185
186
};
187
188
const RTPSParticipantAllocationAttributes c_default_RTPSParticipantAllocationAttributes
189
    = RTPSParticipantAllocationAttributes();
190
191
} // namespace rtps
192
} // namespace fastdds
193
} // namespace eprosima
194
195
#endif // FASTDDS_RTPS_ATTRIBUTES__RTPSPARTICIPANTALLOCATIONATTRIBUTES_HPP