Skip to content

[22872] Configure ROS 2 Easy Mode via C++ and XML #5689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion include/fastdds/dds/core/policy/QosPolicies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
#include <bitset>
#include <vector>

#include <fastdds/dds/core/detail/DDSReturnCode.hpp>
#include <fastdds/dds/core/policy/ParameterTypes.hpp>
#include <fastdds/dds/core/Types.hpp>
#include <fastdds/dds/xtypes/type_representation/detail/dds_xtypes_typeobject.hpp>
#include <fastdds/rtps/attributes/ExternalLocators.hpp>
#include <fastdds/rtps/attributes/PropertyPolicy.hpp>
#include <fastdds/rtps/attributes/ResourceManagement.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.hpp>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/common/LocatorList.hpp>
#include <fastdds/rtps/common/Time_t.hpp>
#include <fastdds/rtps/common/Types.hpp>
#include <fastdds/rtps/flowcontrol/FlowControllerConsts.hpp>
#include <fastdds/rtps/attributes/ResourceManagement.hpp>
#include <fastdds/rtps/transport/network/NetmaskFilterKind.hpp>

#include <fastdds/utils/collections/ResourceLimitedVector.hpp>
Expand Down Expand Up @@ -2664,6 +2665,7 @@ class WireProtocolConfigQos : public QosPolicy
FASTDDS_EXPORTED_API WireProtocolConfigQos()
: QosPolicy(false)
, participant_id(-1)
, easy_mode_("")
{
}

Expand All @@ -2683,6 +2685,7 @@ class WireProtocolConfigQos : public QosPolicy
(this->default_multicast_locator_list == b.default_multicast_locator_list) &&
(this->default_external_unicast_locators == b.default_external_unicast_locators) &&
(this->ignore_non_matching_locators == b.ignore_non_matching_locators) &&
(this->easy_mode_ == b.easy_mode()) &&
QosPolicy::operator ==(b);
}

Expand Down Expand Up @@ -2725,6 +2728,51 @@ class WireProtocolConfigQos : public QosPolicy
* Whether locators that don't match with the announced locators should be kept.
*/
bool ignore_non_matching_locators = false;

/**
* @brief Setter for ROS 2 Easy Mode IP
*
* @param ip IP address to set
* @note The IP address must be an IPv4 address. If it is not, the IP address will not be set.
*
* @return RETCODE_OK if the IP address is set, an specific error code otherwise:
* RETCODE_BAD_PARAMETER if the IP address is not an IPv4 address.
*/
ReturnCode_t easy_mode(
const std::string& ip)
{
// Check if the input is empty
if (!ip.empty())
{
// Check if the input is a valid IP
if (!rtps::IPLocator::isIPv4(ip))
{
EPROSIMA_LOG_ERROR(
WIREPROTOCOLQOS, "Invalid IP address format for ROS 2 Easy Mode. It must be an IPv4 address.");

return RETCODE_BAD_PARAMETER;
}
}

easy_mode_ = ip;

return RETCODE_OK;
}

/**
* @brief Getter for ROS 2 Easy Mode IP
*
* @return IP address if set, empty string otherwise
*/
const std::string& easy_mode() const
{
return easy_mode_;
}

private:

//! ROS 2 Easy Mode IP
std::string easy_mode_;
};

//! Qos Policy to configure the transport layer
Expand Down
4 changes: 4 additions & 0 deletions include/fastdds/rtps/attributes/RTPSParticipantAttributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class RTPSParticipantAttributes
(this->port == b.port) &&
(this->userData == b.userData) &&
(this->participantID == b.participantID) &&
(this->easy_mode_ip == b.easy_mode_ip) &&
(this->useBuiltinTransports == b.useBuiltinTransports) &&
(this->properties == b.properties) &&
(this->prefix == b.prefix) &&
Expand Down Expand Up @@ -527,6 +528,9 @@ class RTPSParticipantAttributes
//! Participant ID
int32_t participantID = -1;

//! IP of the Host where master Server is located (EASY_MODE context)
std::string easy_mode_ip = "";

//! User defined transports to use alongside or in place of builtins.
std::vector<std::shared_ptr<fastdds::rtps::TransportDescriptorInterface>> userTransports;

Expand Down
2 changes: 2 additions & 0 deletions resources/xsd/fastdds_profiles.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
├ builtin [0~1],
├ port [0~1],
├ participantID [int32],
├ easy_mode_ip [string],
├ userTransports [0~1],
| └ transport_id [1~*] [string],
├ useBuiltinTransports [bool],
Expand Down Expand Up @@ -172,6 +173,7 @@
<xs:element name="builtin" type="builtinAttributesType" minOccurs="0" maxOccurs="1"/>
<xs:element name="port" type="portType" minOccurs="0" maxOccurs="1"/>
<xs:element name="participantID" type="int32" minOccurs="0" maxOccurs="1"/>
<xs:element name="easy_mode_ip" type="string" minOccurs="0" maxOccurs="1"/>
<xs:element name="userTransports" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/fastdds/utils/QosConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void set_qos_from_attributes(
qos.wire_protocol().default_multicast_locator_list = attr.defaultMulticastLocatorList;
qos.wire_protocol().default_external_unicast_locators = attr.default_external_unicast_locators;
qos.wire_protocol().ignore_non_matching_locators = attr.ignore_non_matching_locators;
qos.wire_protocol().easy_mode(attr.easy_mode_ip);
qos.transport().user_transports = attr.userTransports;
qos.transport().use_builtin_transports = attr.useBuiltinTransports;
qos.transport().send_socket_buffer_size = attr.sendSocketBufferSize;
Expand Down Expand Up @@ -198,6 +199,7 @@ void set_attributes_from_qos(
attr.setName(qos.name());
attr.prefix = qos.wire_protocol().prefix;
attr.participantID = qos.wire_protocol().participant_id;
attr.easy_mode_ip = qos.wire_protocol().easy_mode();
attr.builtin = qos.wire_protocol().builtin;
attr.port = qos.wire_protocol().port;
attr.defaultUnicastLocatorList = qos.wire_protocol().default_unicast_locator_list;
Expand Down
14 changes: 14 additions & 0 deletions src/cpp/rtps/attributes/ServerAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ const std::string& ros_easy_mode_env()
{
static std::string ip_value;
SystemInfo::get_env(ROS2_EASY_MODE_URI, ip_value);

if (!ip_value.empty())
{
// Check that the value is a valid IPv4 address
if (!IPLocator::isIPv4(ip_value))
{
EPROSIMA_LOG_WARNING(
SERVERATTRIBUTES,
"Invalid format: Easy Mode IP must be a valid IPv4 address. "
"Ignoring " << ROS2_EASY_MODE_URI << " value.");

ip_value = "";
}
}
return ip_value;
}

Expand Down
3 changes: 2 additions & 1 deletion src/cpp/rtps/attributes/ServerAttributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ const std::string& ros_discovery_server_env();

/**
* Get the value of environment variable ROS2_EASY_MODE_URI
* @return The value of environment variable ROS2_EASY_MODE_URI. Empty string if the variable is not defined.
* @return The value of environment variable ROS2_EASY_MODE_URI.
* Empty string if the variable is not defined or does not have a valid IPv4 format.
*/
const std::string& ros_easy_mode_env();

Expand Down
102 changes: 74 additions & 28 deletions src/cpp/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2230,27 +2230,55 @@ XMLP_ret XMLParser::fillDataNode(
DataNode<fastdds::xmlparser::ParticipantAttributes>& participant_node)
{
/*
<xs:complexType name="rtpsParticipantAttributesType">
<xs:all minOccurs="0">
<xs:element name="domainId" type="uint32Type" minOccurs="0"/>
<xs:element name="allocation" type="rtpsParticipantAllocationAttributesType" minOccurs="0"/>
<xs:element name="prefix" type="guid" minOccurs="0"/>
<xs:element name="default_external_unicast_locators" type="externalLocatorListType" minOccurs="0"/>
<xs:element name="ignore_non_matching_locators" type="boolType" minOccurs="0"/>
<xs:element name="defaultUnicastLocatorList" type="locatorListType" minOccurs="0"/>
<xs:element name="defaultMulticastLocatorList" type="locatorListType" minOccurs="0"/>
<xs:element name="sendSocketBufferSize" type="uint32Type" minOccurs="0"/>
<xs:element name="listenSocketBufferSize" type="uint32Type" minOccurs="0"/>
<xs:element name="netmask_filter" type="netmaskFilterType" minOccurs="0" maxOccurs="1"/>
<xs:element name="builtin" type="builtinAttributesType" minOccurs="0"/>
<xs:element name="port" type="portType" minOccurs="0"/>
<xs:element name="userData" type="octetVectorType" minOccurs="0"/>
<xs:element name="participantID" type="int32Type" minOccurs="0"/>
<xs:element name="flow_controller_descriptors" type="flowControllerDescriptorsType" minOccurs="0"/>
<xs:element name="userTransports" type="stringListType" minOccurs="0"/>
<xs:element name="useBuiltinTransports" type="boolType" minOccurs="0"/>
<xs:element name="propertiesPolicy" type="propertyPolicyType" minOccurs="0"/>
<xs:element name="name" type="stringType" minOccurs="0"/>
<xs:complexType name="participantProfileType">
<xs:all>
<xs:element name="domainId" type="domainIDType" minOccurs="0" maxOccurs="1"/>
<xs:element name="rtps" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="name" type="string" minOccurs="0" maxOccurs="1"/>
<xs:element name="defaultUnicastLocatorList" type="locatorListType" minOccurs="0" maxOccurs="1"/>
<xs:element name="defaultMulticastLocatorList" type="locatorListType" minOccurs="0" maxOccurs="1"/>
<xs:element name="default_external_unicast_locators" type="externalLocatorListType" minOccurs="0" maxOccurs="1"/>
<xs:element name="ignore_non_matching_locators" type="boolean" minOccurs="0" maxOccurs="1"/>
<xs:element name="sendSocketBufferSize" type="uint32" minOccurs="0" maxOccurs="1"/>
<xs:element name="listenSocketBufferSize" type="uint32" minOccurs="0" maxOccurs="1"/>
<xs:element name="netmask_filter" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="OFF"/>
<xs:enumeration value="AUTO"/>
<xs:enumeration value="ON"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="builtin" type="builtinAttributesType" minOccurs="0" maxOccurs="1"/>
<xs:element name="port" type="portType" minOccurs="0" maxOccurs="1"/>
<xs:element name="participantID" type="int32" minOccurs="0" maxOccurs="1"/>
<xs:element name="easy_mode_ip" type="string" minOccurs="0" maxOccurs="1"/>
<xs:element name="userTransports" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="transport_id" type="string" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="useBuiltinTransports" type="boolean" minOccurs="0" maxOccurs="1"/>
<xs:element name="builtinTransports" type="builtinTransportsType" minOccurs="0" maxOccurs="1"/>
<xs:element name="propertiesPolicy" type="propertyPolicyType" minOccurs="0" maxOccurs="1"/>
<xs:element name="allocation" type="rtpsParticipantAllocationAttributesType" minOccurs="0" maxOccurs="1"/>
<xs:element name="userData" type="octectVectorQosPolicyType" minOccurs="0" maxOccurs="1"/>
<xs:element name="prefix" type="prefixType" minOccurs="0" maxOccurs="1"/>
<xs:element name="flow_controller_descriptor_list" type="flowControllerDescriptorListType" minOccurs="0" maxOccurs="1"/>
<xs:element name="builtin_controllers_sender_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
<xs:element name="timed_events_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
<xs:element name="discovery_server_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
<xs:element name="typelookup_service_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
<xs:element name="builtin_transports_reception_threads" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
<xs:element name="security_log_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
*/
Expand Down Expand Up @@ -2286,7 +2314,7 @@ XMLP_ret XMLParser::fillDataNode(

if (strcmp(p_element->Name(), DOMAIN_ID) == 0)
{
// domainId - uint32Type
// domainId - uint32
if (XMLP_ret::XML_OK != getXMLUint(p_element, &participant_node.get()->domainId, ident))
{
return XMLP_ret::XML_ERROR;
Expand Down Expand Up @@ -2343,7 +2371,7 @@ XMLP_ret XMLParser::fillDataNode(
}
else if (strcmp(name, IGN_NON_MATCHING_LOCS) == 0)
{
// ignore_non_matching_locators - boolType
// ignore_non_matching_locators - boolean
if (XMLP_ret::XML_OK !=
getXMLBool(p_aux0, &participant_node.get()->rtps.ignore_non_matching_locators, ident))
{
Expand Down Expand Up @@ -2380,15 +2408,15 @@ XMLP_ret XMLParser::fillDataNode(
}
else if (strcmp(name, SEND_SOCK_BUF_SIZE) == 0)
{
// sendSocketBufferSize - uint32Type
// sendSocketBufferSize - uint32
if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &participant_node.get()->rtps.sendSocketBufferSize, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, LIST_SOCK_BUF_SIZE) == 0)
{
// listenSocketBufferSize - uint32Type
// listenSocketBufferSize - uint32
if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &participant_node.get()->rtps.listenSocketBufferSize, ident))
{
return XMLP_ret::XML_ERROR;
Expand Down Expand Up @@ -2440,12 +2468,30 @@ XMLP_ret XMLParser::fillDataNode(
}
else if (strcmp(name, PART_ID) == 0)
{
// participantID - int32Type
// participantID - int32
if (XMLP_ret::XML_OK != getXMLInt(p_aux0, &participant_node.get()->rtps.participantID, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, EASY_MODE_IP) == 0)
{
// easy_mode_ip - string
std::string str_aux;
if (XMLP_ret::XML_OK != getXMLString(p_aux0, &str_aux, ident))
{
return XMLP_ret::XML_ERROR;
}

// Check that the string is a valid IPv4 address
if (!fastdds::rtps::IPLocator::isIPv4(str_aux))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "'easy_mode_ip' is not a valid IPv4 address.");
return XMLP_ret::XML_ERROR;
}

participant_node.get()->rtps.easy_mode_ip = str_aux;
}
else if (strcmp(name, FLOW_CONTROLLER_DESCRIPTOR_LIST) == 0)
{
// flow_controller_descriptors
Expand All @@ -2465,7 +2511,7 @@ XMLP_ret XMLParser::fillDataNode(
}
else if (strcmp(name, USE_BUILTIN_TRANS) == 0)
{
// useBuiltinTransports - boolType
// useBuiltinTransports - boolean
if (XMLP_ret::XML_OK != getXMLBool(p_aux0, &participant_node.get()->rtps.useBuiltinTransports, ident))
{
return XMLP_ret::XML_ERROR;
Expand All @@ -2492,7 +2538,7 @@ XMLP_ret XMLParser::fillDataNode(
}
else if (strcmp(name, NAME) == 0)
{
// name - stringType
// name - string
std::string s;
if (XMLP_ret::XML_OK != getXMLString(p_aux0, &s, ident))
{
Expand Down
1 change: 1 addition & 0 deletions src/cpp/xmlparser/XMLParserCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const char* LOGICAL_PORT = "logical_port";
const char* PHYSICAL_PORT = "physical_port";
const char* USER_DATA = "userData";
const char* PART_ID = "participantID";
const char* EASY_MODE_IP = "easy_mode_ip";
const char* FLOW_CONTROLLER_DESCRIPTOR_LIST = "flow_controller_descriptor_list";
const char* USER_TRANS = "userTransports";
const char* USE_BUILTIN_TRANS = "useBuiltinTransports";
Expand Down
1 change: 1 addition & 0 deletions src/cpp/xmlparser/XMLParserCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ extern const char* LOGICAL_PORT;
extern const char* PHYSICAL_PORT;
extern const char* USER_DATA;
extern const char* PART_ID;
extern const char* EASY_MODE_IP;
extern const char* IP4_TO_SEND;
extern const char* IP6_TO_SEND;
extern const char* FLOW_CONTROLLER_DESCRIPTOR_LIST;
Expand Down
Loading
Loading