Fast DDS  Version 3.6.1.0
Fast DDS
PortParameters.hpp
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
19#ifndef FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
20#define FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
21
22#include <fastdds/rtps/common/Types.hpp>
23#include <fastdds/dds/log/Log.hpp>
24
25namespace eprosima {
26namespace fastdds {
27namespace rtps {
28
34{
35public:
36
38 : portBase(7400)
39 , domainIDGain(250)
41 , offsetd0(0)
42 , offsetd1(10)
43 , offsetd2(1)
44 , offsetd3(11)
45 , offsetd4(2)
46 {
47 }
48
50 {
51 }
52
54 const PortParameters& b) const
55 {
56 return (this->portBase == b.portBase) &&
57 (this->domainIDGain == b.domainIDGain) &&
59 (this->offsetd0 == b.offsetd0) &&
60 (this->offsetd1 == b.offsetd1) &&
61 (this->offsetd2 == b.offsetd2) &&
62 (this->offsetd3 == b.offsetd3) &&
63 (this->offsetd4 == b.offsetd4);
64 }
65
72 inline uint32_t getMulticastPort(
73 uint32_t domainId) const
74 {
75 uint32_t port = portBase + domainIDGain * domainId + offsetd0;
76
77 if (port > 65535)
78 {
79 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
80 << "or portBase is too high.");
81 std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
82 << "or portBase is too high." << std::endl;
83 std::cout.flush();
84 exit(EXIT_FAILURE);
85 }
86
87 return port;
88 }
89
97 inline uint32_t getUnicastPort(
98 uint32_t domainId,
99 uint32_t RTPSParticipantID) const
100 {
101 uint32_t port = portBase + domainIDGain * domainId + offsetd1 + participantIDGain * RTPSParticipantID;
102
103 if (port > 65535)
104 {
105 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232, there are "
106 << "too much participants created or portBase is too high.");
107 std::cout << "Calculated port number is too high. Probably the domainId is over 232, there are "
108 << "too much participants created or portBase is too high." << std::endl;
109 std::cout.flush();
110 exit(EXIT_FAILURE);
111 }
112
113 return port;
114 }
115
123 uint32_t domainId) const
124 {
125 uint32_t port = portBase + domainIDGain * domainId + offsetd4;
126
127 if (port > 65535)
128 {
129 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
130 << "or portBase is too high.");
131 std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
132 << "or portBase is too high." << std::endl;
133 std::cout.flush();
134 exit(EXIT_FAILURE);
135 }
136
137 return static_cast<uint16_t>(port);
138 }
139
140public:
141
143 uint16_t portBase;
145 uint16_t domainIDGain;
149 uint16_t offsetd0;
151 uint16_t offsetd1;
153 uint16_t offsetd2;
155 uint16_t offsetd3;
157 uint16_t offsetd4;
158};
159
160} // namespace rtps
161} // namespace rtps
162} // namespace eprosima
163
164#endif // FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
Class PortParameters, to define the port parameters and gains related with the RTPS protocol.
Definition: PortParameters.hpp:34
uint16_t participantIDGain
ParticipantID gain, default value 2.
Definition: PortParameters.hpp:147
uint16_t offsetd0
Offset d0, default value 0.
Definition: PortParameters.hpp:149
uint16_t domainIDGain
DomainID gain, default value 250.
Definition: PortParameters.hpp:145
uint32_t getUnicastPort(uint32_t domainId, uint32_t RTPSParticipantID) const
Get a unicast port based on the domain ID and the participant ID.
Definition: PortParameters.hpp:97
uint16_t offsetd3
Offset d3, default value 11.
Definition: PortParameters.hpp:155
virtual ~PortParameters()
Definition: PortParameters.hpp:49
uint32_t getMulticastPort(uint32_t domainId) const
Get a multicast port based on the domain ID.
Definition: PortParameters.hpp:72
uint16_t offsetd2
Offset d2, default value 1.
Definition: PortParameters.hpp:153
PortParameters()
Definition: PortParameters.hpp:37
uint16_t portBase
PortBase, default value 7400.
Definition: PortParameters.hpp:143
uint16_t get_discovery_server_port(uint32_t domainId) const
Get a discovery server port based on the domain ID.
Definition: PortParameters.hpp:122
bool operator==(const PortParameters &b) const
Definition: PortParameters.hpp:53
uint16_t offsetd4
Offset d4, default value 2.
Definition: PortParameters.hpp:157
uint16_t offsetd1
Offset d1, default value 10.
Definition: PortParameters.hpp:151
eProsima namespace.