Skip to content

Commit

Permalink
Add customizable transport: ignore participant flags, non-builtin des…
Browse files Browse the repository at this point in the history
…criptors and interface whitelist (#42)

* Add whitelist interfaces to DDS Pipe

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Add transport and ignore participant flags configuration

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Disable builtin transport with UDP-only configuration

Signed-off-by: Juan López Fernández <[email protected]>

* Apply whitelist configuration to WAN participants

Signed-off-by: Juan López Fernández <[email protected]>

* Uncrustify

Signed-off-by: Juan López Fernández <[email protected]>

* Fix typo

Signed-off-by: Juan López Fernández <[email protected]>

* Remove repeated push_back

Signed-off-by: Juan López Fernández <[email protected]>

* Make create_descriptor method public

Signed-off-by: Juan López Fernández <[email protected]>

* Apply suggestions

Signed-off-by: Juan López Fernández <[email protected]>

---------

Signed-off-by: Raul Sanchez-Mateos <[email protected]>
Signed-off-by: Juan López Fernández <[email protected]>
Co-authored-by: Raul Sanchez-Mateos <[email protected]>
  • Loading branch information
juanlofer-eprosima and rsanchez15 authored Jun 15, 2023
1 parent 1113dee commit 56367b8
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 21 deletions.
43 changes: 43 additions & 0 deletions ddspipe_core/include/ddspipe_core/types/dds/CustomTransport.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// limitations under the License.

#pragma once

namespace eprosima {
namespace ddspipe {
namespace core {
namespace types {

//! Different options for transport configuration
enum class TransportDescriptors
{
builtin,
udp_only,
shm_only
};

//! Possible values for Ignore Participant Flags
enum class IgnoreParticipantFlags
{
no_filter,
filter_different_host,
filter_different_process,
filter_same_process,
filter_different_and_same_process
};

} /* namespace types */
} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

#pragma once

#include <ddspipe_core/types/dds/CustomTransport.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_participants/configuration/ParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_participants/types/address/Address.hpp>

namespace eprosima {
namespace ddspipe {
Expand Down Expand Up @@ -48,6 +50,12 @@ struct SimpleParticipantConfiguration : public ParticipantConfiguration
/////////////////////////

core::types::DomainId domain {0u};

std::set<participants::types::IpType> whitelist {};

core::types::TransportDescriptors transport {core::types::TransportDescriptors::builtin};

core::types::IgnoreParticipantFlags ignore_participant_flags {core::types::IgnoreParticipantFlags::no_filter};
};

} /* namespace participants */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
#include <fastdds/rtps/rtps_fwd.h>
#include <fastdds/rtps/writer/WriterDiscoveryInfo.h>
#include <fastrtps/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastrtps/rtps/RTPSDomain.h>
#include <fastrtps/rtps/participant/RTPSParticipantListener.h>
#include <fastrtps/rtps/RTPSDomain.h>


#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_core/dynamic/DiscoveryDatabase.hpp>
#include <ddspipe_core/efficiency/payload/PayloadPool.hpp>
#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>

#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/configuration/ParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/types/address/Address.hpp>

namespace eprosima {
namespace ddspipe {
Expand Down Expand Up @@ -156,6 +158,16 @@ class CommonParticipant
const core::types::DdsTopic& topic,
const core::types::ParticipantId& discoverer_id);

/**
* @brief Create a transport descriptor with given whitelist.
*
* This templated method is specialized for UPDv4, UDPv6, TCPv4 and TCPv6.
*/
template<typename T>
DDSPIPE_PARTICIPANTS_DllAPI
static std::shared_ptr<T> create_descriptor(
std::set<types::IpType> whitelist = {});

protected:

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class SimpleParticipant : public CommonParticipant
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration,
const std::shared_ptr<core::PayloadPool>& payload_pool,
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database);

protected:

/**
* @brief Static method that gives the attributes for a Simple Participant.
*/
static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
const SimpleParticipantConfiguration* configuration);
};

} /* namespace rtps */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cpp_utils/Log.hpp>

#include <ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp>
#include <ddspipe_participants/types/address/Address.hpp>

namespace eprosima {
namespace ddspipe {
Expand All @@ -34,6 +35,16 @@ bool SimpleParticipantConfiguration::is_valid(
return false;
}

// Check whitelist interfaces
for (types::IpType ip : whitelist)
{
if (!types::Address::is_ipv4_correct(ip))
{
error_msg << "Incorrect IPv4 address " << ip << " in whitelist interfaces. ";
return false;
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include <fastrtps/types/DynamicType.h>
#include <fastrtps/types/DynamicTypePtr.h>
#include <fastrtps/types/TypeObjectFactory.h>

#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <ddspipe_core/types/dynamic_types/types.hpp>

#include <ddspipe_participants/reader/auxiliar/BlankReader.hpp>
Expand Down Expand Up @@ -179,13 +181,79 @@ void DynTypesParticipant::internal_notify_type_object_(

void DynTypesParticipant::initialize_internal_dds_participant_()
{

std::shared_ptr<SimpleParticipantConfiguration> configuration =
std::dynamic_pointer_cast<SimpleParticipantConfiguration>(this->configuration_);

eprosima::fastdds::dds::DomainParticipantQos pqos;
pqos.name(this->id());

// Set Type LookUp to ON
pqos.wire_protocol().builtin.typelookup_config.use_server = false;
pqos.wire_protocol().builtin.typelookup_config.use_client = true;

// Configure Participant transports
if (configuration->transport == core::types::TransportDescriptors::builtin)
{
if (!configuration->whitelist.empty())
{
pqos.transport().use_builtin_transports = false;

std::shared_ptr<eprosima::fastdds::rtps::SharedMemTransportDescriptor> shm_transport =
std::make_shared<eprosima::fastdds::rtps::SharedMemTransportDescriptor>();
pqos.transport().user_transports.push_back(shm_transport);

std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor> udp_transport =
create_descriptor<eprosima::fastdds::rtps::UDPv4TransportDescriptor>(configuration->whitelist);
pqos.transport().user_transports.push_back(udp_transport);
}
}
else if (configuration->transport == core::types::TransportDescriptors::shm_only)
{
pqos.transport().use_builtin_transports = false;

std::shared_ptr<eprosima::fastdds::rtps::SharedMemTransportDescriptor> shm_transport =
std::make_shared<eprosima::fastdds::rtps::SharedMemTransportDescriptor>();
pqos.transport().user_transports.push_back(shm_transport);
}
else if (configuration->transport == core::types::TransportDescriptors::udp_only)
{
pqos.transport().use_builtin_transports = false;

std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor> udp_transport =
create_descriptor<eprosima::fastdds::rtps::UDPv4TransportDescriptor>(configuration->whitelist);
pqos.transport().user_transports.push_back(udp_transport);
}

// Participant discovery filter configuration
switch (configuration->ignore_participant_flags)
{
case core::types::IgnoreParticipantFlags::no_filter:
pqos.wire_protocol().builtin.discovery_config.ignoreParticipantFlags =
eprosima::fastrtps::rtps::ParticipantFilteringFlags_t::NO_FILTER;
break;
case core::types::IgnoreParticipantFlags::filter_different_host:
pqos.wire_protocol().builtin.discovery_config.ignoreParticipantFlags =
eprosima::fastrtps::rtps::ParticipantFilteringFlags_t::FILTER_DIFFERENT_HOST;
break;
case core::types::IgnoreParticipantFlags::filter_different_process:
pqos.wire_protocol().builtin.discovery_config.ignoreParticipantFlags =
eprosima::fastrtps::rtps::ParticipantFilteringFlags_t::FILTER_DIFFERENT_PROCESS;
break;
case core::types::IgnoreParticipantFlags::filter_same_process:
pqos.wire_protocol().builtin.discovery_config.ignoreParticipantFlags =
eprosima::fastrtps::rtps::ParticipantFilteringFlags_t::FILTER_SAME_PROCESS;
break;
case core::types::IgnoreParticipantFlags::filter_different_and_same_process:
pqos.wire_protocol().builtin.discovery_config.ignoreParticipantFlags =
static_cast<eprosima::fastrtps::rtps::ParticipantFilteringFlags_t>(
eprosima::fastrtps::rtps::ParticipantFilteringFlags_t::FILTER_DIFFERENT_PROCESS |
eprosima::fastrtps::rtps::ParticipantFilteringFlags_t::FILTER_SAME_PROCESS);
break;
default:
break;
}

// Force DDS entities to be created disabled
// NOTE: this is very dangerous because we are modifying a global variable (and a not thread safe one) in a
// local function.
Expand All @@ -200,7 +268,7 @@ void DynTypesParticipant::initialize_internal_dds_participant_()

// CREATE THE PARTICIPANT
dds_participant_ = eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->create_participant(
std::dynamic_pointer_cast<SimpleParticipantConfiguration>(this->configuration_)->domain,
configuration->domain,
pqos);

dds_participant_->set_listener(this);
Expand Down
112 changes: 112 additions & 0 deletions ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

#include <memory>

#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/TCPv6TransportDescriptor.h>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/UDPv6TransportDescriptor.h>
#include <fastrtps/rtps/participant/RTPSParticipant.h>
#include <fastrtps/rtps/RTPSDomain.h>

Expand Down Expand Up @@ -276,6 +280,114 @@ core::types::Endpoint CommonParticipant::simulate_endpoint(
return endpoint;
}

template<>
std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor> udp_transport =
std::make_shared<eprosima::fastdds::rtps::UDPv4TransportDescriptor>();

for (const types::IpType& ip : whitelist)
{
if (types::Address::is_ipv4_correct(ip))
{
udp_transport->interfaceWhiteList.emplace_back(ip);
logInfo(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << ip << " to UDP whitelist interfaces.");
}
else
{
// Invalid address, continue with next one
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv4. Discarding UDP whitelist interface " << ip << ".");
}
}

return udp_transport;
}

template<>
std::shared_ptr<eprosima::fastdds::rtps::UDPv6TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::UDPv6TransportDescriptor> udp_transport =
std::make_shared<eprosima::fastdds::rtps::UDPv6TransportDescriptor>();

for (const types::IpType& ip : whitelist)
{
if (types::Address::is_ipv6_correct(ip))
{
udp_transport->interfaceWhiteList.emplace_back(ip);
logInfo(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << ip << " to UDP whitelist interfaces.");
}
else
{
// Invalid address, continue with next one
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv6. Discarding UDP whitelist interface " << ip << ".");
}
}

return udp_transport;
}

template<>
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> tcp_transport =
std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();

for (const types::IpType& ip : whitelist)
{
if (types::Address::is_ipv4_correct(ip))
{
tcp_transport->interfaceWhiteList.emplace_back(ip);
logInfo(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << ip << " to TCP whitelist interfaces.");
}
else
{
// Invalid address, continue with next one
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv4. Discarding TCP whitelist interface " << ip << ".");
}
}

return tcp_transport;
}

template<>
std::shared_ptr<eprosima::fastdds::rtps::TCPv6TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::TCPv6TransportDescriptor> tcp_transport =
std::make_shared<eprosima::fastdds::rtps::TCPv6TransportDescriptor>();

for (const types::IpType& ip : whitelist)
{
if (types::Address::is_ipv6_correct(ip))
{
tcp_transport->interfaceWhiteList.emplace_back(ip);
logInfo(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << ip << " to TCP whitelist interfaces.");
}
else
{
// Invalid address, continue with next one
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv6. Discarding TCP whitelist interface " << ip << ".");
}
}

return tcp_transport;
}

bool CommonParticipant::is_repeater() const noexcept
{
return configuration_->is_repeater;
Expand Down
Loading

0 comments on commit 56367b8

Please sign in to comment.