Fast DDS  Version 3.6.1.0
Fast DDS
TransportInterface.hpp
1 // Copyright 2019 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 FASTDDS_RTPS_TRANSPORT__TRANSPORTINTERFACE_HPP
21 #define FASTDDS_RTPS_TRANSPORT__TRANSPORTINTERFACE_HPP
22 
23 #include <memory>
24 #include <vector>
25 
26 #include <fastdds/rtps/attributes/PropertyPolicy.hpp>
27 #include <fastdds/rtps/common/Locator.hpp>
28 #include <fastdds/rtps/common/LocatorList.hpp>
29 #include <fastdds/rtps/common/LocatorSelector.hpp>
30 #include <fastdds/rtps/common/LocatorSelectorEntry.hpp>
31 #include <fastdds/rtps/common/LocatorWithMask.hpp>
32 #include <fastdds/rtps/common/PortParameters.hpp>
33 #include <fastdds/rtps/transport/network/AllowedNetworkInterface.hpp>
34 #include <fastdds/rtps/transport/network/NetmaskFilterKind.hpp>
35 #include <fastdds/rtps/transport/SenderResource.hpp>
36 #include <fastdds/rtps/transport/TransportDescriptorInterface.hpp>
37 #include <fastdds/rtps/transport/TransportReceiverInterface.hpp>
38 
39 namespace eprosima {
40 namespace fastdds {
41 namespace rtps {
42 
44 constexpr uint32_t s_maximumMessageSize = 65500;
46 constexpr uint32_t s_maximumInitialPeersRange = 4;
48 static const std::string s_IPv4AddressAny = "0.0.0.0";
50 static const std::string s_IPv6AddressAny = "::";
51 
52 using SendResourceList = std::vector<std::unique_ptr<fastdds::rtps::SenderResource>>;
53 using NetmaskFilterInfo = std::pair<NetmaskFilterKind, std::vector<AllowedNetworkInterface>>;
54 using TransportNetmaskFilterInfo = std::pair<int32_t, NetmaskFilterInfo>;
55 
63 class FASTDDS_EXPORTED_API TransportInterface
64 {
65 public:
66 
77  virtual ~TransportInterface() = default;
78 
81  const TransportInterface& t) = delete;
82 
84  TransportInterface& operator =(
85  const TransportInterface& t) = delete;
86 
89  TransportInterface&& t) = delete;
90 
92  TransportInterface& operator =(
93  TransportInterface&& t) = delete;
94 
101  virtual bool init(
102  const fastdds::rtps::PropertyPolicy* properties = nullptr,
103  const uint32_t& max_msg_size_no_frag = 0) = 0;
104 
109  virtual bool IsInputChannelOpen(
110  const Locator&) const = 0;
111 
113  virtual bool IsLocatorSupported(
114  const Locator&) const = 0;
115 
117  virtual bool is_locator_allowed(
118  const Locator&) const = 0;
119 
127  virtual bool is_locator_reachable(
128  const Locator_t& locator) = 0;
129 
130 
133  const Locator& remote) const = 0;
134 
147  const Locator& remote_locator,
148  Locator& result_locator) const
149  {
150  (void)remote_locator;
151  (void)result_locator;
152  return false;
153  }
154 
157  virtual bool OpenOutputChannel(
158  SendResourceList& sender_resource_list,
159  const Locator&) = 0;
160 
170  virtual bool OpenOutputChannels(
171  SendResourceList& sender_resource_list,
172  const fastdds::rtps::LocatorSelectorEntry& locator_selector_entry);
173 
180  virtual void CloseOutputChannels(
181  SendResourceList& sender_resource_list,
182  const fastdds::rtps::LocatorSelectorEntry& locator_selector_entry);
183 
187  virtual bool OpenInputChannel(
188  const Locator&,
190  uint32_t) = 0;
191 
197  virtual bool CloseInputChannel(
198  const Locator&) = 0;
199 
201  virtual bool DoInputLocatorsMatch(
202  const Locator&,
203  const Locator&) const = 0;
204 
207  const Locator& locator) = 0;
208 
219  virtual void select_locators(
220  fastdds::rtps::LocatorSelector& selector) const = 0;
221 
223  virtual bool is_local_locator(
224  const Locator& locator) const = 0;
225 
228 
231  LocatorList& defaultList) = 0;
232 
235  LocatorList& locators,
236  uint32_t metatraffic_multicast_port) const = 0;
237 
240  LocatorList& locators,
241  uint32_t metatraffic_unicast_port) const = 0;
242 
245  LocatorList& locators,
246  uint32_t unicast_port) const = 0;
247 
250  Locator& locator,
251  uint32_t metatraffic_multicast_port) const = 0;
252 
255  Locator& locator,
256  uint32_t metatraffic_unicast_port) const = 0;
257 
260  Locator& locator,
261  const fastdds::rtps::PortParameters& port_params,
262  uint32_t domainId,
263  LocatorList& list) const = 0;
264 
266  virtual bool fillUnicastLocator(
267  Locator& locator,
268  uint32_t well_known_port) const = 0;
269 
273  virtual uint32_t max_recv_buffer_size() const = 0;
274 
278  virtual void shutdown()
279  {
280  }
281 
286  {
287  }
288 
290  int32_t kind() const
291  {
292  return transport_kind_;
293  }
294 
309  const Locator& remote_locator,
310  Locator& result_locator,
311  bool allowed_remote_localhost,
312  bool allowed_local_localhost) const
313  {
314  static_cast<void>(allowed_remote_localhost);
315  static_cast<void>(allowed_local_localhost);
316  return transform_remote_locator(remote_locator, result_locator);
317  }
318 
320  virtual bool is_localhost_allowed() const
321  {
322  return false;
323  }
324 
327  {
328  return {NetmaskFilterKind::AUTO, {}};
329  }
330 
331 protected:
332 
334  int32_t transport_kind)
335  : transport_kind_(transport_kind)
336  {
337  }
338 
340 };
341 
342 } // namespace rtps
343 } // namespace fastdds
344 } // namespace eprosima
345 
346 #endif // FASTDDS_RTPS_TRANSPORT__TRANSPORTINTERFACE_HPP
Class Locator_t, uniquely identifies a communication channel for a particular transport.
Definition: Locator.hpp:74
Class LocatorList, a Locator vector that doesn't allow duplicates.
Definition: LocatorList.hpp:97
A class used for the efficient selection of locators when sending data to multiple entities.
Definition: LocatorSelector.hpp:55
Class PortParameters, to define the port parameters and gains related with the RTPS protocol.
Definition: PortParameters.hpp:34
Definition: PropertyPolicy.hpp:30
Interface against which to implement a transport layer, decoupled from Fast DDS internals.
Definition: TransportInterface.hpp:64
virtual void shutdown()
Shutdown method to close the connections of the transports.
Definition: TransportInterface.hpp:278
virtual bool is_local_locator(const Locator &locator) const =0
Must report whether the given locator is from the local host.
virtual bool is_locator_allowed(const Locator &) const =0
Must report whether the given locator is allowed by this transport.
virtual void CloseOutputChannels(SendResourceList &sender_resource_list, const fastdds::rtps::LocatorSelectorEntry &locator_selector_entry)
Close the channel that maps to/from the given locator selector entry.
int32_t transport_kind_
Definition: TransportInterface.hpp:339
virtual bool init(const fastdds::rtps::PropertyPolicy *properties=nullptr, const uint32_t &max_msg_size_no_frag=0)=0
Initialize this transport.
virtual Locator RemoteToMainLocal(const Locator &remote) const =0
Returns the locator describing the main (most general) channel that can write to the provided remote ...
virtual bool DoInputLocatorsMatch(const Locator &, const Locator &) const =0
Must report whether two locators map to the same internal channel.
virtual bool getDefaultMetatrafficUnicastLocators(LocatorList &locators, uint32_t metatraffic_unicast_port) const =0
Add metatraffic unicast locator with the given port.
virtual void AddDefaultOutputLocator(LocatorList &defaultList)=0
Add default output locator to the locator list.
virtual LocatorList NormalizeLocator(const Locator &locator)=0
Performs locator normalization (assign valid IP if not defined by user)
virtual bool IsInputChannelOpen(const Locator &) const =0
Must report whether the input channel associated to this locator is open.
virtual bool getDefaultUnicastLocators(LocatorList &locators, uint32_t unicast_port) const =0
Add unicast locator with the given port.
virtual TransportDescriptorInterface * get_configuration()=0
Return the transport configuration (Transport Descriptor)
virtual bool is_localhost_allowed() const
Must report whether localhost locator is allowed.
Definition: TransportInterface.hpp:320
TransportInterface(const TransportInterface &t)=delete
Copy constructor.
virtual bool fillMetatrafficMulticastLocator(Locator &locator, uint32_t metatraffic_multicast_port) const =0
Assign port to the given metatraffic multicast locator if not already defined.
virtual NetmaskFilterInfo netmask_filter_info() const
Returns netmask filter information (transport's netmask filter kind and allowlist)
Definition: TransportInterface.hpp:326
virtual bool CloseInputChannel(const Locator &)=0
Must close the channel that maps to/from the given locator.
virtual bool OpenOutputChannel(SendResourceList &sender_resource_list, const Locator &)=0
Must open the channel that maps to/from the given locator.
virtual bool getDefaultMetatrafficMulticastLocators(LocatorList &locators, uint32_t metatraffic_multicast_port) const =0
Add metatraffic multicast locator with the given port.
TransportInterface(TransportInterface &&t)=delete
Move constructor.
virtual bool OpenOutputChannels(SendResourceList &sender_resource_list, const fastdds::rtps::LocatorSelectorEntry &locator_selector_entry)
Must open the channel that maps to/from the given locator selector entry.
int32_t kind() const
Return the transport kind.
Definition: TransportInterface.hpp:290
virtual bool fillUnicastLocator(Locator &locator, uint32_t well_known_port) const =0
Assign port to the given unicast locator if not already defined.
virtual ~TransportInterface()=default
Aside from the API defined here, an user-defined Transport must define a descriptor data type and a c...
virtual bool transform_remote_locator(const Locator &remote_locator, Locator &result_locator) const
Transforms a remote locator into a locator optimized for local communications.
Definition: TransportInterface.hpp:146
virtual bool IsLocatorSupported(const Locator &) const =0
Must report whether the given locator is supported by this transport (typically inspecting its "kind"...
virtual bool OpenInputChannel(const Locator &, TransportReceiverInterface *, uint32_t)=0
Opens an input channel to receive incoming connections.
virtual bool fillMetatrafficUnicastLocator(Locator &locator, uint32_t metatraffic_unicast_port) const =0
Assign port to the given metatraffic unicast locator if not already defined.
virtual void update_network_interfaces()
Update network interfaces.
Definition: TransportInterface.hpp:285
virtual bool transform_remote_locator(const Locator &remote_locator, Locator &result_locator, bool allowed_remote_localhost, bool allowed_local_localhost) const
Transforms a remote locator into a locator optimized for local communications.
Definition: TransportInterface.hpp:308
virtual bool is_locator_reachable(const Locator_t &locator)=0
Must report whether the given locator is reachable by this transport.
TransportInterface(int32_t transport_kind)
Definition: TransportInterface.hpp:333
virtual uint32_t max_recv_buffer_size() const =0
virtual bool configureInitialPeerLocator(Locator &locator, const fastdds::rtps::PortParameters &port_params, uint32_t domainId, LocatorList &list) const =0
Configure the initial peer locators list.
virtual void select_locators(fastdds::rtps::LocatorSelector &selector) const =0
Performs the locator selection algorithm for this transport.
Interface against which to implement a data receiver, decoupled from transport internals.
Definition: TransportReceiverInterface.hpp:34
std::pair< int32_t, NetmaskFilterInfo > TransportNetmaskFilterInfo
Definition: TransportInterface.hpp:54
constexpr uint32_t s_maximumMessageSize
Default maximum message size.
Definition: TransportInterface.hpp:44
std::pair< NetmaskFilterKind, std::vector< AllowedNetworkInterface > > NetmaskFilterInfo
Definition: TransportInterface.hpp:53
static const std::string s_IPv6AddressAny
Default IPv6 address.
Definition: TransportInterface.hpp:50
constexpr uint32_t s_maximumInitialPeersRange
Default maximum initial peers range.
Definition: TransportInterface.hpp:46
static const std::string s_IPv4AddressAny
Default IPv4 address.
Definition: TransportInterface.hpp:48
std::vector< std::unique_ptr< fastdds::rtps::SenderResource > > SendResourceList
Definition: TransportInterface.hpp:52
An entry for the LocatorSelector.
Definition: LocatorSelectorEntry.hpp:39
Virtual base class for the data type used to define transport configuration.
Definition: TransportDescriptorInterface.hpp:48