Skip to content
6 changes: 5 additions & 1 deletion include/fastdds/rtps/transport/TransportInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ class FASTDDS_EXPORTED_API TransportInterface
uint32_t domainId,
LocatorList& list) const = 0;

//! Assign port to the given unicast locator if not already defined
/**
* Assign only the port to the given unicast locator if not already defined
* Note: As the default address is usually valid for unicast, this method
* does not assign a new value
*/
virtual bool fillUnicastLocator(
Locator& locator,
uint32_t well_known_port) const = 0;
Expand Down
38 changes: 38 additions & 0 deletions src/cpp/rtps/network/NetworkFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <fastdds/utils/IPLocator.hpp>

#include <rtps/network/NetworkConfiguration.hpp>
#include <rtps/transport/MulticastTransportInterface.hpp>
#include <rtps/transport/TCPTransportInterface.h>

using namespace std;
Expand Down Expand Up @@ -488,6 +489,23 @@ bool NetworkFactory::getDefaultUnicastLocators(
return result;
}

bool NetworkFactory::getDefaultMulticastLocators(
LocatorList_t& locators,
uint32_t port) const
{
bool result = false;
for (auto& transport : mRegisteredTransports)
{
const MulticastTransportInterface* multicast_transport =
dynamic_cast<const MulticastTransportInterface*>(transport.get());
if (multicast_transport)
{
result |= multicast_transport->getDefaultMulticastLocators(locators, port);
}
}
return result;
}

bool NetworkFactory::fill_default_locator_port(
Locator_t& locator,
uint32_t port) const
Expand All @@ -503,6 +521,26 @@ bool NetworkFactory::fill_default_locator_port(
return result;
}

bool NetworkFactory::fill_default_multicast_locator(
Locator_t& locator,
uint32_t port) const
{
bool result = false;
for (auto& transport : mRegisteredTransports)
{
if (transport->IsLocatorSupported(locator))
{
const MulticastTransportInterface* multicast_transport =
dynamic_cast<const MulticastTransportInterface*>(transport.get());
if (multicast_transport)
{
result |= multicast_transport->fillMulticastLocator(locator, port);
}
}
}
return result;
}

void NetworkFactory::Shutdown()
{
for (auto& transport : mRegisteredTransports)
Expand Down
17 changes: 17 additions & 0 deletions src/cpp/rtps/network/NetworkFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,30 @@ class NetworkFactory
LocatorList_t& locators,
uint32_t port) const;

/**
* Add the default multicast locator to the given locator list.
*
* @param locators List to be filled with the default multicast locator.
* @param port Port to be used in the default multicast locator.
* */
Comment thread
emiliocuestaf marked this conversation as resolved.
bool getDefaultMulticastLocators(
LocatorList_t& locators,
uint32_t port) const;

/**
* Fill the locator with the default unicast configuration.
* */
bool fill_default_locator_port(
Locator_t& locator,
uint32_t port) const;

/**
* Fill the locator with the default multicast configuration.
* */
bool fill_default_multicast_locator(
Locator_t& locator,
uint32_t port) const;

/**
* Shutdown method to close the connections of the transports.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ void RTPSParticipantImpl::setup_user_traffic()
std::for_each(m_att.defaultUnicastLocatorList.begin(), m_att.defaultUnicastLocatorList.end(),
[&](Locator_t& loc)
{
// This methods always leaves the address unchanged
m_network_Factory.fill_default_locator_port(loc, default_unicast_port_);
});
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);
Expand All @@ -687,7 +688,8 @@ void RTPSParticipantImpl::setup_user_traffic()
std::for_each(m_att.defaultMulticastLocatorList.begin(), m_att.defaultMulticastLocatorList.end(),
[&](Locator_t& loc)
{
m_network_Factory.fill_default_locator_port(loc, multicast_port);
// This methods leaves the address unchanged if it was already set
m_network_Factory.fill_default_multicast_locator(loc, multicast_port);
});
}

Expand Down Expand Up @@ -2332,7 +2334,7 @@ void RTPSParticipantImpl::normalize_endpoint_locators(
uint32_t multicast_port = m_network_Factory.calculate_well_known_port(domain_id_, m_att, true);
for (Locator_t& loc : endpoint_att.multicastLocatorList)
{
m_network_Factory.fill_default_locator_port(loc, multicast_port);
m_network_Factory.fill_default_multicast_locator(loc, multicast_port);
}

// Normalize unicast locators
Expand Down
47 changes: 47 additions & 0 deletions src/cpp/rtps/transport/MulticastTransportInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2026 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <rtps/transport/MulticastTransportInterface.hpp>

#include <fastdds/utils/IPLocator.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

bool MulticastTransportInterface::fillMulticastLocator(
Locator& locator,
uint32_t well_known_port) const
{
LocatorList defaults;
getDefaultMulticastLocators(defaults, well_known_port);
if (!defaults.empty())
{
const Locator& default_loc = *defaults.begin();
if (locator.port == 0)
{
locator.port = default_loc.port;
}
if (!IsAddressDefined(locator))
{
IPLocator::copy_address(default_loc, locator);
}
}

return true;
}

} // namespace rtps
} // namespace fastdds
} // namespace eprosima
46 changes: 46 additions & 0 deletions src/cpp/rtps/transport/MulticastTransportInterface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima).
Comment thread
cferreiragonz marked this conversation as resolved.
//
// 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef _FASTDDS_MULTICAST_TRANSPORT_INTERFACE_HPP_
#define _FASTDDS_MULTICAST_TRANSPORT_INTERFACE_HPP_

#include <cstdint>

#include <fastdds/rtps/common/Locator.hpp>
#include <fastdds/rtps/common/LocatorList.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

class MulticastTransportInterface
{
public:

virtual ~MulticastTransportInterface() = default;

virtual bool getDefaultMulticastLocators(
LocatorList& locators,
uint32_t multicast_port) const = 0;

virtual bool fillMulticastLocator(
Locator& locator,
uint32_t well_known_port) const;
};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif // _FASTDDS_MULTICAST_TRANSPORT_INTERFACE_HPP_
4 changes: 2 additions & 2 deletions src/cpp/rtps/transport/TCPTransportInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ bool TCPTransportInterface::getDefaultMetatrafficMulticastLocators(
uint32_t ) const
{
// TCP doesn't have multicast support
return true;
return false;
}

bool TCPTransportInterface::getDefaultMetatrafficUnicastLocators(
Expand Down Expand Up @@ -1722,7 +1722,7 @@ bool TCPTransportInterface::fillMetatrafficMulticastLocator(
uint32_t) const
{
// TCP doesn't have multicast support
return true;
return false;
}

bool TCPTransportInterface::fillMetatrafficUnicastLocator(
Expand Down
8 changes: 8 additions & 0 deletions src/cpp/rtps/transport/TCPTransportInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ class TCPTransportInterface : public TransportInterface
*/
virtual std::vector<std::string> get_binding_interfaces_list() = 0;

/**
* This method should never be called because TCP interfaces do not support
* multicast locators. It always returns false
*/
bool getDefaultMetatrafficMulticastLocators(
LocatorList& locators,
uint32_t metatraffic_multicast_port) const override;
Expand All @@ -464,6 +468,10 @@ class TCPTransportInterface : public TransportInterface
LocatorList& locators,
uint32_t unicast_port) const override;

/**
* This method should never be called because TCP interfaces do not support
* multicast locators. It always returns false
*/
bool fillMetatrafficMulticastLocator(
Locator& locator,
uint32_t metatraffic_multicast_port) const override;
Expand Down
14 changes: 12 additions & 2 deletions src/cpp/rtps/transport/UDPTransportInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,19 @@ bool UDPTransportInterface::fillMetatrafficMulticastLocator(
Locator& locator,
uint32_t metatraffic_multicast_port) const
{
if (locator.port == 0)
LocatorList defaults;
getDefaultMetatrafficMulticastLocators(defaults, metatraffic_multicast_port);
if (!defaults.empty())
{
locator.port = metatraffic_multicast_port;
const Locator& default_loc = *defaults.begin();
if (locator.port == 0)
{
locator.port = default_loc.port;
}
if (!IsAddressDefined(locator))
{
IPLocator::copy_address(default_loc, locator);
}
}
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/cpp/rtps/transport/UDPTransportInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
#include <fastdds/rtps/transport/UDPTransportDescriptor.hpp>
#include <fastdds/utils/IPFinder.hpp>

#include <rtps/transport/MulticastTransportInterface.hpp>
#include <rtps/transport/UDPChannelResource.h>
#include <statistics/rtps/messages/OutputTrafficManager.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

class UDPTransportInterface : public TransportInterface
class UDPTransportInterface
: public TransportInterface
, public MulticastTransportInterface
{
friend class UDPSenderResource;
friend struct TSN_UDPSender;
Expand Down
12 changes: 12 additions & 0 deletions src/cpp/rtps/transport/UDPv4Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ bool UDPv4Transport::getDefaultMetatrafficMulticastLocators(
return true;
}

bool UDPv4Transport::getDefaultMulticastLocators(
LocatorList& locators,
uint32_t multicast_port) const
{
Locator locator;
locator.kind = LOCATOR_KIND_UDPv4;
locator.port = static_cast<uint16_t>(multicast_port);
IPLocator::setIPv4(locator, DEFAULT_MULTICAST_ADDRESS);
locators.push_back(locator);
return true;
}

bool UDPv4Transport::getDefaultMetatrafficUnicastLocators(
LocatorList& locators,
uint32_t metatraffic_unicast_port) const
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/rtps/transport/UDPv4Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class UDPv4Transport : public UDPTransportInterface
LocatorList& locators,
uint32_t metatraffic_unicast_port) const override;

bool getDefaultMulticastLocators(
LocatorList& locators,
uint32_t multicast_port) const override;

bool getDefaultUnicastLocators(
LocatorList& locators,
uint32_t unicast_port) const override;
Expand Down Expand Up @@ -169,6 +173,9 @@ class UDPv4Transport : public UDPTransportInterface
};

const char* const DEFAULT_METATRAFFIC_MULTICAST_ADDRESS = "239.255.0.1";
// Metatraffic multicast address is the same as default multicast address,
// but we keep this definition in case we want to differentiate them in the future
const char* const DEFAULT_MULTICAST_ADDRESS = DEFAULT_METATRAFFIC_MULTICAST_ADDRESS;

} // namespace rtps
} // namespace fastdds
Expand Down
16 changes: 14 additions & 2 deletions src/cpp/rtps/transport/UDPv6Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ bool UDPv6Transport::getDefaultMetatrafficMulticastLocators(
Locator locator;
locator.kind = LOCATOR_KIND_UDPv6;
locator.port = static_cast<uint16_t>(metatraffic_multicast_port);
IPLocator::setIPv6(locator, "ff1e::ffff:efff:1");
IPLocator::setIPv6(locator, DEFAULT_METATRAFFIC_MULTICAST_ADDRESS_v6);
locators.push_back(locator);
return true;
}
Expand All @@ -275,6 +275,18 @@ bool UDPv6Transport::getDefaultMetatrafficUnicastLocators(
return true;
}

bool UDPv6Transport::getDefaultMulticastLocators(
LocatorList& locators,
uint32_t multicast_port) const
{
Locator locator;
locator.kind = LOCATOR_KIND_UDPv6;
locator.port = static_cast<uint16_t>(multicast_port);
IPLocator::setIPv6(locator, DEFAULT_MULTICAST_ADDRESS_v6);
locators.push_back(locator);
return true;
}

bool UDPv6Transport::getDefaultUnicastLocators(
LocatorList& locators,
uint32_t unicast_port) const
Expand All @@ -293,7 +305,7 @@ void UDPv6Transport::AddDefaultOutputLocator(
{
// TODO What is the default IPv6 address?
Locator temp;
IPLocator::createLocator(LOCATOR_KIND_UDPv6, "ff1e::ffff:efff:1", 0, temp);
IPLocator::createLocator(LOCATOR_KIND_UDPv6, DEFAULT_MULTICAST_ADDRESS_v6, 0, temp);
defaultList.push_back(temp);
}

Expand Down
Loading
Loading