| Fast DDS Version 3.3.0 Fast DDS

Loading...
Searching...
No Matches
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
18
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#include <cstdlib>
25
26 namespace eprosima {
27 namespace fastdds {
28 namespace rtps {
29
34 class PortParameters
35{
36 public:
37
38 PortParameters()
39 : portBase(7400)
40 , domainIDGain(250)
41 , participantIDGain(2)
42 , offsetd0(0)
43 , offsetd1(10)
44 , offsetd2(1)
45 , offsetd3(11)
46 , offsetd4(2)
47 {
48 }
49
50 virtual ~PortParameters()
51 {
52 }
53
54 bool operator ==(
55 const PortParameters& b) const
56 {
57 return (this->portBase == b.portBase) &&
58 (this->domainIDGain == b.domainIDGain) &&
59 (this->participantIDGain == b.participantIDGain) &&
60 (this->offsetd0 == b.offsetd0) &&
61 (this->offsetd1 == b.offsetd1) &&
62 (this->offsetd2 == b.offsetd2) &&
63 (this->offsetd3 == b.offsetd3) &&
64 (this->offsetd4 == b.offsetd4);
65 }
66
73 inline uint32_t getMulticastPort(
74 uint32_t domainId) const
75 {
76 uint32_t port = portBase + domainIDGain * domainId + offsetd0;
77
78 if (port > 65535)
79 {
80 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
81 << "or portBase is too high.");
82 std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
83 << "or portBase is too high." << std::endl;
84 std::cout.flush();
85 exit(EXIT_FAILURE);
86 }
87
88 return port;
89 }
90
98 inline uint32_t getUnicastPort(
99 uint32_t domainId,
100 uint32_t RTPSParticipantID) const
101 {
102 uint32_t port = portBase + domainIDGain * domainId + offsetd1 + participantIDGain * RTPSParticipantID;
103
104 if (port > 65535)
105 {
106 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232, there are "
107 << "too much participants created or portBase is too high.");
108 std::cout << "Calculated port number is too high. Probably the domainId is over 232, there are "
109 << "too much participants created or portBase is too high." << std::endl;
110 std::cout.flush();
111 exit(EXIT_FAILURE);
112 }
113
114 return port;
115 }
116
123 inline uint16_t get_discovery_server_port(
124 uint32_t domainId) const
125 {
126 uint32_t port = portBase + domainIDGain * domainId + offsetd4;
127
128 if (port > 65535)
129 {
130 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
131 << "or portBase is too high.");
132 std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
133 << "or portBase is too high." << std::endl;
134 std::cout.flush();
135 exit(EXIT_FAILURE);
136 }
137
138 return static_cast<uint16_t>(port);
139 }
140
141 public:
142
144 uint16_t portBase;
146 uint16_t domainIDGain;
148 uint16_t participantIDGain;
150 uint16_t offsetd0;
152 uint16_t offsetd1;
154 uint16_t offsetd2;
156 uint16_t offsetd3;
158 uint16_t offsetd4;
159};
160
161} // namespace rtps
162} // namespace rtps
163} // namespace eprosima
164
165#endif // FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
eprosima::fastdds::rtps::PortParameters::participantIDGain
uint16_t participantIDGain
ParticipantID gain, default value 2.
Definition PortParameters.hpp:148
eprosima::fastdds::rtps::PortParameters::offsetd0
uint16_t offsetd0
Offset d0, default value 0.
Definition PortParameters.hpp:150
eprosima::fastdds::rtps::PortParameters::domainIDGain
uint16_t domainIDGain
DomainID gain, default value 250.
Definition PortParameters.hpp:146
eprosima::fastdds::rtps::PortParameters::getUnicastPort
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:98
eprosima::fastdds::rtps::PortParameters::offsetd3
uint16_t offsetd3
Offset d3, default value 11.
Definition PortParameters.hpp:156
eprosima::fastdds::rtps::PortParameters::~PortParameters
virtual ~PortParameters()
Definition PortParameters.hpp:50
eprosima::fastdds::rtps::PortParameters::getMulticastPort
uint32_t getMulticastPort(uint32_t domainId) const
Get a multicast port based on the domain ID.
Definition PortParameters.hpp:73
eprosima::fastdds::rtps::PortParameters::offsetd2
uint16_t offsetd2
Offset d2, default value 1.
Definition PortParameters.hpp:154
eprosima::fastdds::rtps::PortParameters::PortParameters
PortParameters()
Definition PortParameters.hpp:38
eprosima::fastdds::rtps::PortParameters::portBase
uint16_t portBase
PortBase, default value 7400.
Definition PortParameters.hpp:144
eprosima::fastdds::rtps::PortParameters::get_discovery_server_port
uint16_t get_discovery_server_port(uint32_t domainId) const
Get a discovery server port based on the domain ID.
Definition PortParameters.hpp:123
eprosima::fastdds::rtps::PortParameters::operator==
bool operator==(const PortParameters &b) const
Definition PortParameters.hpp:54
eprosima::fastdds::rtps::PortParameters::offsetd4
uint16_t offsetd4
Offset d4, default value 2.
Definition PortParameters.hpp:158
eprosima::fastdds::rtps::PortParameters::offsetd1
uint16_t offsetd1
Offset d1, default value 10.
Definition PortParameters.hpp:152
eprosima::fastdds::rtps
Contains the RTPS protocol implementation.
eprosima::fastdds
eprosima
eProsima namespace.