Fast DDS  Version 3.0.1
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
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
26namespace eprosima {
27namespace fastdds {
28namespace rtps {
29
35{
36public:
37
39 : portBase(7400)
40 , domainIDGain(250)
42 , offsetd0(0)
43 , offsetd1(10)
44 , offsetd2(1)
45 , offsetd3(11)
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 }
64
71 inline uint32_t getMulticastPort(
72 uint32_t domainId) const
73 {
74 uint32_t port = portBase + domainIDGain * domainId + offsetd0;
75
76 if (port > 65535)
77 {
78 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
79 << "or portBase is too high.");
80 std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
81 << "or portBase is too high." << std::endl;
82 std::cout.flush();
83 exit(EXIT_FAILURE);
84 }
85
86 return port;
87 }
88
96 inline uint32_t getUnicastPort(
97 uint32_t domainId,
98 uint32_t RTPSParticipantID) const
99 {
100 uint32_t port = portBase + domainIDGain * domainId + offsetd1 + participantIDGain * RTPSParticipantID;
101
102 if (port > 65535)
103 {
104 EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232, there are "
105 << "too much participants created or portBase is too high.");
106 std::cout << "Calculated port number is too high. Probably the domainId is over 232, there are "
107 << "too much participants created or portBase is too high." << std::endl;
108 std::cout.flush();
109 exit(EXIT_FAILURE);
110 }
111
112 return port;
113 }
114
115public:
116
118 uint16_t portBase;
120 uint16_t domainIDGain;
124 uint16_t offsetd0;
126 uint16_t offsetd1;
128 uint16_t offsetd2;
130 uint16_t offsetd3;
131};
132
133} // namespace rtps
134} // namespace rtps
135} // namespace eprosima
136
137#endif // FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
Class PortParameters, to define the port parameters and gains related with the RTPS protocol.
Definition PortParameters.hpp:35
uint16_t participantIDGain
ParticipantID gain, default value 2.
Definition PortParameters.hpp:122
uint16_t offsetd0
Offset d0, default value 0.
Definition PortParameters.hpp:124
uint16_t domainIDGain
DomainID gain, default value 250.
Definition PortParameters.hpp:120
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:96
uint16_t offsetd3
Offset d3, default value 11.
Definition PortParameters.hpp:130
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:71
uint16_t offsetd2
Offset d2, default value 1.
Definition PortParameters.hpp:128
PortParameters()
Definition PortParameters.hpp:38
uint16_t portBase
PortBase, default value 7400.
Definition PortParameters.hpp:118
bool operator==(const PortParameters &b) const
Definition PortParameters.hpp:53
uint16_t offsetd1
Offset d1, default value 10.
Definition PortParameters.hpp:126
eProsima namespace.