/src/Fast-DDS/include/fastdds/rtps/common/PortParameters.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
15 | | /** |
16 | | * @file PortParameters.h |
17 | | */ |
18 | | |
19 | | #ifndef _FASTDDS_RTPS_PORT_PARAMETERS_H_ |
20 | | #define _FASTDDS_RTPS_PORT_PARAMETERS_H_ |
21 | | |
22 | | #include <fastdds/rtps/common/Types.h> |
23 | | #include <fastdds/dds/log/Log.hpp> |
24 | | |
25 | | namespace eprosima { |
26 | | namespace fastrtps { |
27 | | namespace rtps { |
28 | | |
29 | | /** |
30 | | * Class PortParameters, to define the port parameters and gains related with the RTPS protocol. |
31 | | * @ingroup RTPS_ATTRIBUTES_MODULE |
32 | | */ |
33 | | class PortParameters |
34 | | { |
35 | | public: |
36 | | |
37 | | PortParameters() |
38 | | : portBase(7400) |
39 | | , domainIDGain(250) |
40 | | , participantIDGain(2) |
41 | | , offsetd0(0) |
42 | | , offsetd1(10) |
43 | | , offsetd2(1) |
44 | | , offsetd3(11) |
45 | 19.6k | { |
46 | 19.6k | } |
47 | | |
48 | | virtual ~PortParameters() |
49 | 19.1k | { |
50 | 19.1k | } |
51 | | |
52 | | bool operator ==( |
53 | | const PortParameters& b) const |
54 | 0 | { |
55 | 0 | return (this->portBase == b.portBase) && |
56 | 0 | (this->domainIDGain == b.domainIDGain) && |
57 | 0 | (this->participantIDGain == b.participantIDGain) && |
58 | 0 | (this->offsetd0 == b.offsetd0) && |
59 | 0 | (this->offsetd1 == b.offsetd1) && |
60 | 0 | (this->offsetd2 == b.offsetd2) && |
61 | 0 | (this->offsetd3 == b.offsetd3); |
62 | 0 | } |
63 | | |
64 | | /** |
65 | | * Get a multicast port based on the domain ID. |
66 | | * |
67 | | * @param domainId Domain ID. |
68 | | * @return Multicast port |
69 | | */ |
70 | | inline uint32_t getMulticastPort( |
71 | | uint32_t domainId) const |
72 | 0 | { |
73 | 0 | uint32_t port = portBase + domainIDGain * domainId + offsetd0; |
74 | |
|
75 | 0 | if (port > 65535) |
76 | 0 | { |
77 | 0 | logError(RTPS, "Calculated port number is too high. Probably the domainId is over 232 " |
78 | 0 | << "or portBase is too high."); |
79 | 0 | std::cout << "Calculated port number is too high. Probably the domainId is over 232 " |
80 | 0 | << "or portBase is too high." << std::endl; |
81 | 0 | std::cout.flush(); |
82 | 0 | exit(EXIT_FAILURE); |
83 | 0 | } |
84 | | |
85 | 0 | return port; |
86 | 0 | } Unexecuted instantiation: eprosima::fastrtps::rtps::PortParameters::getMulticastPort(unsigned int) const Unexecuted instantiation: eprosima::fastrtps::rtps::PortParameters::getMulticastPort(unsigned int) const |
87 | | |
88 | | /** |
89 | | * Get a unicast port based on the domain ID and the participant ID. |
90 | | * |
91 | | * @param domainId Domain ID. |
92 | | * @param RTPSParticipantID Participant ID. |
93 | | * @return Unicast port |
94 | | */ |
95 | | inline uint32_t getUnicastPort( |
96 | | uint32_t domainId, |
97 | | uint32_t RTPSParticipantID) const |
98 | 0 | { |
99 | 0 | uint32_t port = portBase + domainIDGain * domainId + offsetd1 + participantIDGain * RTPSParticipantID; |
100 | |
|
101 | 0 | if (port > 65535) |
102 | 0 | { |
103 | 0 | logError(RTPS, "Calculated port number is too high. Probably the domainId is over 232, there are " |
104 | 0 | << "too much participants created or portBase is too high."); |
105 | 0 | std::cout << "Calculated port number is too high. Probably the domainId is over 232, there are " |
106 | 0 | << "too much participants created or portBase is too high." << std::endl; |
107 | 0 | std::cout.flush(); |
108 | 0 | exit(EXIT_FAILURE); |
109 | 0 | } |
110 | | |
111 | 0 | return port; |
112 | 0 | } |
113 | | |
114 | | public: |
115 | | |
116 | | //!PortBase, default value 7400. |
117 | | uint16_t portBase; |
118 | | //!DomainID gain, default value 250. |
119 | | uint16_t domainIDGain; |
120 | | //!ParticipantID gain, default value 2. |
121 | | uint16_t participantIDGain; |
122 | | //!Offset d0, default value 0. |
123 | | uint16_t offsetd0; |
124 | | //!Offset d1, default value 10. |
125 | | uint16_t offsetd1; |
126 | | //!Offset d2, default value 1. |
127 | | uint16_t offsetd2; |
128 | | //!Offset d3, default value 11. |
129 | | uint16_t offsetd3; |
130 | | }; |
131 | | |
132 | | } // namespace rtps |
133 | | } /* namespace rtps */ |
134 | | } /* namespace eprosima */ |
135 | | |
136 | | #endif /* _FASTDDS_RTPS_PORT_PARAMETERS_H_ */ |