Fast RTPS  Version 2.3.4
Fast RTPS
IPLocator.h
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 
20 #ifndef IP_LOCATOR_H_
21 #define IP_LOCATOR_H_
22 
23 #include <fastdds/rtps/common/Types.h>
24 #include <fastdds/dds/log/Log.hpp>
25 
26 #include <vector>
27 #include <string>
28 
29 namespace eprosima {
30 namespace fastrtps {
31 namespace rtps {
32 
33 class Locator_t;
34 
39 class IPLocator
40 {
41 public:
42 
50  RTPS_DllAPI static void createLocator(
51  int32_t kindin,
52  const std::string& address,
53  uint32_t portin,
54  Locator_t& locator);
55 
57  RTPS_DllAPI static bool setIPv4(
58  Locator_t& locator,
59  const unsigned char* addr);
60 
62  RTPS_DllAPI static bool setIPv4(
63  Locator_t& locator,
64  octet o1,
65  octet o2,
66  octet o3,
67  octet o4);
68 
70  RTPS_DllAPI static bool setIPv4(
71  Locator_t& locator,
72  const std::string& ipv4);
73 
75  RTPS_DllAPI static bool setIPv4(
76  Locator_t& destlocator,
77  const Locator_t& origlocator);
78 
80  RTPS_DllAPI static bool setIPv4address(
81  Locator_t& destlocator,
82  const std::string& lan,
83  const std::string& wan,
84  const std::string& ipv4);
85 
87  RTPS_DllAPI static const octet* getIPv4(
88  const Locator_t& locator);
89 
91  RTPS_DllAPI static bool hasIPv4(
92  const Locator_t& locator);
93 
95  RTPS_DllAPI static std::string toIPv4string(
96  const Locator_t& locator);
97 
99  RTPS_DllAPI static bool copyIPv4(
100  const Locator_t& locator,
101  unsigned char* dest);
102 
103  // IPv6
105  RTPS_DllAPI static bool setIPv6(
106  Locator_t& locator,
107  const unsigned char* addr);
108 
110  RTPS_DllAPI static bool setIPv6(
111  Locator_t& locator,
112  uint16_t group0,
113  uint16_t group1,
114  uint16_t group2,
115  uint16_t group3,
116  uint16_t group4,
117  uint16_t group5,
118  uint16_t group6,
119  uint16_t group7);
120 
122  RTPS_DllAPI static bool setIPv6(
123  Locator_t& locator,
124  const std::string& ipv6);
125 
127  RTPS_DllAPI static bool setIPv6(
128  Locator_t& destlocator,
129  const Locator_t& origlocator);
130 
132  RTPS_DllAPI static const octet* getIPv6(
133  const Locator_t& locator);
134 
136  RTPS_DllAPI static bool hasIPv6(
137  const Locator_t& locator);
138 
140  RTPS_DllAPI static std::string toIPv6string(
141  const Locator_t& locator);
142 
144  RTPS_DllAPI static bool copyIPv6(
145  const Locator_t& locator,
146  unsigned char* dest);
147 
149  RTPS_DllAPI static bool ip(
150  Locator_t& locator,
151  const std::string& ip);
152 
154  RTPS_DllAPI static std::string ip_to_string(
155  const Locator_t& locator);
156 
157  // TCP
159  RTPS_DllAPI static bool setLogicalPort(
160  Locator_t& locator,
161  uint16_t port);
162 
164  RTPS_DllAPI static uint16_t getLogicalPort(
165  const Locator_t& locator);
166 
168  RTPS_DllAPI static bool setPhysicalPort(
169  Locator_t& locator,
170  uint16_t port);
171 
173  RTPS_DllAPI static uint16_t getPhysicalPort(
174  const Locator_t& locator);
175 
176  // TCPv4
178  RTPS_DllAPI static bool setWan(
179  Locator_t& locator,
180  octet o1,
181  octet o2,
182  octet o3,
183  octet o4);
184 
186  RTPS_DllAPI static bool setWan(
187  Locator_t& locator,
188  const std::string& wan);
189 
191  RTPS_DllAPI static const octet* getWan(
192  const Locator_t& locator);
193 
195  RTPS_DllAPI static bool hasWan(
196  const Locator_t& locator);
197 
199  RTPS_DllAPI static std::string toWanstring(
200  const Locator_t& locator);
201 
203  RTPS_DllAPI static bool setLanID(
204  Locator_t& locator,
205  const std::string& lanId);
206 
208  RTPS_DllAPI static const octet* getLanID(
209  const Locator_t& locator);
210 
212  RTPS_DllAPI static std::string toLanIDstring(
213  const Locator_t& locator);
214 
216  RTPS_DllAPI static Locator_t toPhysicalLocator(
217  const Locator_t& locator);
218 
220  RTPS_DllAPI static bool ip_equals_wan(
221  const Locator_t& locator);
222 
223  // Common
225  RTPS_DllAPI static bool setPortRTPS(
226  Locator_t& locator,
227  uint16_t port);
228 
230  RTPS_DllAPI static uint16_t getPortRTPS(
231  Locator_t& locator);
232 
234  RTPS_DllAPI static bool isLocal(
235  const Locator_t& locator);
236 
238  RTPS_DllAPI static bool isAny(
239  const Locator_t& locator);
240 
242  RTPS_DllAPI static bool compareAddress(
243  const Locator_t& loc1,
244  const Locator_t& loc2,
245  bool fullAddress = false);
246 
248  RTPS_DllAPI static bool compareAddressAndPhysicalPort(
249  const Locator_t& loc1,
250  const Locator_t& loc2);
251 
253  RTPS_DllAPI static std::string to_string(
254  const Locator_t& locator);
255 
256  // UDP
258  RTPS_DllAPI static bool isMulticast(
259  const Locator_t& locator);
260 
261 protected:
262 
263  // Checks if the locator address is equal to 0
264  // It checks the proper locator address depending on the locator kind
265  static bool isEmpty(
266  const Locator_t& locator);
267 
268  // Checks if the locator address from index till the end is equal to 0
269  static bool isEmpty(
270  const Locator_t& locator,
271  uint16_t index);
272 
273  // Checks if a string matches an ipv6 address
274  static bool IPv6isCorrect(
275  const std::string& ipv6);
276 
277 private:
278 
279  IPLocator() = delete;
280  ~IPLocator() = delete;
281 
282 };
283 
284 } // namespace rtps
285 } // namespace fastrtps
286 } /* namespace eprosima */
287 
288 #endif /* IP_LOCATOR_H_ */
Class IPLocator, to provide helper functions to the IP based transports.
Definition: IPLocator.h:40
static RTPS_DllAPI bool setIPv6(Locator_t &destlocator, const Locator_t &origlocator)
Copies locator's IPv6.
static RTPS_DllAPI bool hasIPv6(const Locator_t &locator)
Check if the locator has IPv6.
static RTPS_DllAPI const octet * getWan(const Locator_t &locator)
Gets locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI bool copyIPv6(const Locator_t &locator, unsigned char *dest)
Copies locator's IPv6.
static RTPS_DllAPI bool setIPv6(Locator_t &locator, uint16_t group0, uint16_t group1, uint16_t group2, uint16_t group3, uint16_t group4, uint16_t group5, uint16_t group6, uint16_t group7)
Sets locator's IPv6.
static RTPS_DllAPI bool setIPv4address(Locator_t &destlocator, const std::string &lan, const std::string &wan, const std::string &ipv4)
Copies locator's IPv4.
static RTPS_DllAPI bool ip_equals_wan(const Locator_t &locator)
Checks if a locator WAN address and IP address are the same (as in RTCP protocol).
static RTPS_DllAPI const octet * getIPv4(const Locator_t &locator)
Retrieves locator's IPv4 as octet array.
static RTPS_DllAPI bool isLocal(const Locator_t &locator)
Checks if a locator has local IP address.
static RTPS_DllAPI bool setIPv6(Locator_t &locator, const std::string &ipv6)
Sets locator's IPv6.
static RTPS_DllAPI std::string toIPv6string(const Locator_t &locator)
Returns a string representation of the locator's IPv6 following RFC 5952 recommendation.
static bool IPv6isCorrect(const std::string &ipv6)
static RTPS_DllAPI uint16_t getLogicalPort(const Locator_t &locator)
Gets locator's logical port (as in RTCP protocol)
static RTPS_DllAPI bool setIPv4(Locator_t &destlocator, const Locator_t &origlocator)
Copies locator's IPv4.
static RTPS_DllAPI bool setWan(Locator_t &locator, octet o1, octet o2, octet o3, octet o4)
Sets locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI bool compareAddressAndPhysicalPort(const Locator_t &loc1, const Locator_t &loc2)
Checks if a both locators has the same IP address and physical port (as in RTCP protocol).
static bool isEmpty(const Locator_t &locator, uint16_t index)
static RTPS_DllAPI bool hasWan(const Locator_t &locator)
Checks if the locator has WAN address (as in RTCP protocol)
static RTPS_DllAPI bool setPortRTPS(Locator_t &locator, uint16_t port)
Sets locator's RTCP port. Physical for UDP and logical for TCP (as in RTCP protocol)
static RTPS_DllAPI std::string ip_to_string(const Locator_t &locator)
Returns a string representation of the locator's IP.
static RTPS_DllAPI bool setLogicalPort(Locator_t &locator, uint16_t port)
Sets locator's logical port (as in RTCP protocol)
static RTPS_DllAPI const octet * getLanID(const Locator_t &locator)
Gets locator's LAN ID (as in RTCP protocol)
static RTPS_DllAPI bool setLanID(Locator_t &locator, const std::string &lanId)
Sets locator's LAN ID (as in RTCP protocol)
static RTPS_DllAPI bool setIPv6(Locator_t &locator, const unsigned char *addr)
Sets locator's IPv6.
static RTPS_DllAPI const octet * getIPv6(const Locator_t &locator)
Retrieves locator's IPv6 as octet array.
static RTPS_DllAPI bool isMulticast(const Locator_t &locator)
Checks if the locator has a multicast IP address.
static bool isEmpty(const Locator_t &locator)
static RTPS_DllAPI bool copyIPv4(const Locator_t &locator, unsigned char *dest)
Copies locator's IPv4.
static RTPS_DllAPI bool hasIPv4(const Locator_t &locator)
Check if the locator has IPv4.
static RTPS_DllAPI bool setIPv4(Locator_t &locator, octet o1, octet o2, octet o3, octet o4)
Sets locator's IPv4.
static RTPS_DllAPI bool setPhysicalPort(Locator_t &locator, uint16_t port)
Sets locator's physical port (as in RTCP protocol)
static RTPS_DllAPI std::string toLanIDstring(const Locator_t &locator)
Retrieves a string representation of the locator's LAN ID (as in RTCP protocol)
static RTPS_DllAPI bool isAny(const Locator_t &locator)
Checks if a locator has any IP address.
static RTPS_DllAPI uint16_t getPortRTPS(Locator_t &locator)
Gets locator's RTCP port. Physical for UDP and logical for TCP (as in RTCP protocol)
static RTPS_DllAPI std::string toWanstring(const Locator_t &locator)
Retrieves a string representation of the locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI Locator_t toPhysicalLocator(const Locator_t &locator)
Returns a new locator without logical port (as in RTCP protocol).
static RTPS_DllAPI bool setIPv4(Locator_t &locator, const unsigned char *addr)
Sets locator's IPv4.
static RTPS_DllAPI bool setWan(Locator_t &locator, const std::string &wan)
Sets locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI std::string toIPv4string(const Locator_t &locator)
Returns a string representation of the locator's IPv4.
static RTPS_DllAPI bool compareAddress(const Locator_t &loc1, const Locator_t &loc2, bool fullAddress=false)
Checks if both locators has the same IP address.
static RTPS_DllAPI std::string to_string(const Locator_t &locator)
Returns a string representation of the given locator.
static RTPS_DllAPI uint16_t getPhysicalPort(const Locator_t &locator)
Gets locator's physical port (as in RTCP protocol)
static RTPS_DllAPI void createLocator(int32_t kindin, const std::string &address, uint32_t portin, Locator_t &locator)
Fills locator with the given parameters.
static RTPS_DllAPI bool setIPv4(Locator_t &locator, const std::string &ipv4)
Sets locator's IPv4.
static RTPS_DllAPI bool ip(Locator_t &locator, const std::string &ip)
Sets locator's IP.
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23