Skip to content

Commit 55f67e1

Browse files
Configure ROS 2 Easy Mode via C++ and XML (#5689)
* Refs #22872: Add setter and getter for EASY_MODE Discovery Server IP Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Add XML tag Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Update versions.md Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Apply suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Avoid showing log errors when calling easy_mode() with empty ip Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Apply suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Apply suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22872: Update docstring Signed-off-by: Carlosespicur <[email protected]> --------- Signed-off-by: Carlosespicur <[email protected]>
1 parent 777a71b commit 55f67e1

19 files changed

+255
-32
lines changed

include/fastdds/dds/core/policy/QosPolicies.hpp

+49-1
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
#include <bitset>
2424
#include <vector>
2525

26+
#include <fastdds/dds/core/detail/DDSReturnCode.hpp>
2627
#include <fastdds/dds/core/policy/ParameterTypes.hpp>
2728
#include <fastdds/dds/core/Types.hpp>
2829
#include <fastdds/dds/xtypes/type_representation/detail/dds_xtypes_typeobject.hpp>
2930
#include <fastdds/rtps/attributes/ExternalLocators.hpp>
3031
#include <fastdds/rtps/attributes/PropertyPolicy.hpp>
32+
#include <fastdds/rtps/attributes/ResourceManagement.hpp>
3133
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
3234
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.hpp>
3335
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
3436
#include <fastdds/rtps/common/LocatorList.hpp>
3537
#include <fastdds/rtps/common/Time_t.hpp>
3638
#include <fastdds/rtps/common/Types.hpp>
3739
#include <fastdds/rtps/flowcontrol/FlowControllerConsts.hpp>
38-
#include <fastdds/rtps/attributes/ResourceManagement.hpp>
3940
#include <fastdds/rtps/transport/network/NetmaskFilterKind.hpp>
4041

4142
#include <fastdds/utils/collections/ResourceLimitedVector.hpp>
@@ -2664,6 +2665,7 @@ class WireProtocolConfigQos : public QosPolicy
26642665
FASTDDS_EXPORTED_API WireProtocolConfigQos()
26652666
: QosPolicy(false)
26662667
, participant_id(-1)
2668+
, easy_mode_("")
26672669
{
26682670
}
26692671

@@ -2683,6 +2685,7 @@ class WireProtocolConfigQos : public QosPolicy
26832685
(this->default_multicast_locator_list == b.default_multicast_locator_list) &&
26842686
(this->default_external_unicast_locators == b.default_external_unicast_locators) &&
26852687
(this->ignore_non_matching_locators == b.ignore_non_matching_locators) &&
2688+
(this->easy_mode_ == b.easy_mode()) &&
26862689
QosPolicy::operator ==(b);
26872690
}
26882691

@@ -2725,6 +2728,51 @@ class WireProtocolConfigQos : public QosPolicy
27252728
* Whether locators that don't match with the announced locators should be kept.
27262729
*/
27272730
bool ignore_non_matching_locators = false;
2731+
2732+
/**
2733+
* @brief Setter for ROS 2 Easy Mode IP
2734+
*
2735+
* @param ip IP address to set
2736+
* @note The IP address must be an IPv4 address. If it is not, the IP address will not be set.
2737+
*
2738+
* @return RETCODE_OK if the IP address is set, an specific error code otherwise:
2739+
* RETCODE_BAD_PARAMETER if the IP address is not an IPv4 address.
2740+
*/
2741+
ReturnCode_t easy_mode(
2742+
const std::string& ip)
2743+
{
2744+
// Check if the input is empty
2745+
if (!ip.empty())
2746+
{
2747+
// Check if the input is a valid IP
2748+
if (!rtps::IPLocator::isIPv4(ip))
2749+
{
2750+
EPROSIMA_LOG_ERROR(
2751+
WIREPROTOCOLQOS, "Invalid IP address format for ROS 2 Easy Mode. It must be an IPv4 address.");
2752+
2753+
return RETCODE_BAD_PARAMETER;
2754+
}
2755+
}
2756+
2757+
easy_mode_ = ip;
2758+
2759+
return RETCODE_OK;
2760+
}
2761+
2762+
/**
2763+
* @brief Getter for ROS 2 Easy Mode IP
2764+
*
2765+
* @return IP address if set, empty string otherwise
2766+
*/
2767+
const std::string& easy_mode() const
2768+
{
2769+
return easy_mode_;
2770+
}
2771+
2772+
private:
2773+
2774+
//! ROS 2 Easy Mode IP
2775+
std::string easy_mode_;
27282776
};
27292777

27302778
//! Qos Policy to configure the transport layer

include/fastdds/rtps/attributes/RTPSParticipantAttributes.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ class RTPSParticipantAttributes
444444
(this->port == b.port) &&
445445
(this->userData == b.userData) &&
446446
(this->participantID == b.participantID) &&
447+
(this->easy_mode_ip == b.easy_mode_ip) &&
447448
(this->useBuiltinTransports == b.useBuiltinTransports) &&
448449
(this->properties == b.properties) &&
449450
(this->prefix == b.prefix) &&
@@ -527,6 +528,9 @@ class RTPSParticipantAttributes
527528
//! Participant ID
528529
int32_t participantID = -1;
529530

531+
//! IP of the Host where master Server is located (EASY_MODE context)
532+
std::string easy_mode_ip = "";
533+
530534
//! User defined transports to use alongside or in place of builtins.
531535
std::vector<std::shared_ptr<fastdds::rtps::TransportDescriptorInterface>> userTransports;
532536

resources/xsd/fastdds_profiles.xsd

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
├ builtin [0~1],
132132
├ port [0~1],
133133
├ participantID [int32],
134+
├ easy_mode_ip [string],
134135
├ userTransports [0~1],
135136
| └ transport_id [1~*] [string],
136137
├ useBuiltinTransports [bool],
@@ -172,6 +173,7 @@
172173
<xs:element name="builtin" type="builtinAttributesType" minOccurs="0" maxOccurs="1"/>
173174
<xs:element name="port" type="portType" minOccurs="0" maxOccurs="1"/>
174175
<xs:element name="participantID" type="int32" minOccurs="0" maxOccurs="1"/>
176+
<xs:element name="easy_mode_ip" type="string" minOccurs="0" maxOccurs="1"/>
175177
<xs:element name="userTransports" minOccurs="0" maxOccurs="1">
176178
<xs:complexType>
177179
<xs:sequence>

src/cpp/fastdds/utils/QosConverters.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void set_qos_from_attributes(
148148
qos.wire_protocol().default_multicast_locator_list = attr.defaultMulticastLocatorList;
149149
qos.wire_protocol().default_external_unicast_locators = attr.default_external_unicast_locators;
150150
qos.wire_protocol().ignore_non_matching_locators = attr.ignore_non_matching_locators;
151+
qos.wire_protocol().easy_mode(attr.easy_mode_ip);
151152
qos.transport().user_transports = attr.userTransports;
152153
qos.transport().use_builtin_transports = attr.useBuiltinTransports;
153154
qos.transport().send_socket_buffer_size = attr.sendSocketBufferSize;
@@ -198,6 +199,7 @@ void set_attributes_from_qos(
198199
attr.setName(qos.name());
199200
attr.prefix = qos.wire_protocol().prefix;
200201
attr.participantID = qos.wire_protocol().participant_id;
202+
attr.easy_mode_ip = qos.wire_protocol().easy_mode();
201203
attr.builtin = qos.wire_protocol().builtin;
202204
attr.port = qos.wire_protocol().port;
203205
attr.defaultUnicastLocatorList = qos.wire_protocol().default_unicast_locator_list;

src/cpp/rtps/attributes/ServerAttributes.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ const std::string& ros_easy_mode_env()
7373
{
7474
static std::string ip_value;
7575
SystemInfo::get_env(ROS2_EASY_MODE_URI, ip_value);
76+
77+
if (!ip_value.empty())
78+
{
79+
// Check that the value is a valid IPv4 address
80+
if (!IPLocator::isIPv4(ip_value))
81+
{
82+
EPROSIMA_LOG_WARNING(
83+
SERVERATTRIBUTES,
84+
"Invalid format: Easy Mode IP must be a valid IPv4 address. "
85+
"Ignoring " << ROS2_EASY_MODE_URI << " value.");
86+
87+
ip_value = "";
88+
}
89+
}
7690
return ip_value;
7791
}
7892

src/cpp/rtps/attributes/ServerAttributes.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ const std::string& ros_discovery_server_env();
198198

199199
/**
200200
* Get the value of environment variable ROS2_EASY_MODE_URI
201-
* @return The value of environment variable ROS2_EASY_MODE_URI. Empty string if the variable is not defined.
201+
* @return The value of environment variable ROS2_EASY_MODE_URI.
202+
* Empty string if the variable is not defined or does not have a valid IPv4 format.
202203
*/
203204
const std::string& ros_easy_mode_env();
204205

src/cpp/xmlparser/XMLParser.cpp

+74-28
Original file line numberDiff line numberDiff line change
@@ -2230,27 +2230,55 @@ XMLP_ret XMLParser::fillDataNode(
22302230
DataNode<fastdds::xmlparser::ParticipantAttributes>& participant_node)
22312231
{
22322232
/*
2233-
<xs:complexType name="rtpsParticipantAttributesType">
2234-
<xs:all minOccurs="0">
2235-
<xs:element name="domainId" type="uint32Type" minOccurs="0"/>
2236-
<xs:element name="allocation" type="rtpsParticipantAllocationAttributesType" minOccurs="0"/>
2237-
<xs:element name="prefix" type="guid" minOccurs="0"/>
2238-
<xs:element name="default_external_unicast_locators" type="externalLocatorListType" minOccurs="0"/>
2239-
<xs:element name="ignore_non_matching_locators" type="boolType" minOccurs="0"/>
2240-
<xs:element name="defaultUnicastLocatorList" type="locatorListType" minOccurs="0"/>
2241-
<xs:element name="defaultMulticastLocatorList" type="locatorListType" minOccurs="0"/>
2242-
<xs:element name="sendSocketBufferSize" type="uint32Type" minOccurs="0"/>
2243-
<xs:element name="listenSocketBufferSize" type="uint32Type" minOccurs="0"/>
2244-
<xs:element name="netmask_filter" type="netmaskFilterType" minOccurs="0" maxOccurs="1"/>
2245-
<xs:element name="builtin" type="builtinAttributesType" minOccurs="0"/>
2246-
<xs:element name="port" type="portType" minOccurs="0"/>
2247-
<xs:element name="userData" type="octetVectorType" minOccurs="0"/>
2248-
<xs:element name="participantID" type="int32Type" minOccurs="0"/>
2249-
<xs:element name="flow_controller_descriptors" type="flowControllerDescriptorsType" minOccurs="0"/>
2250-
<xs:element name="userTransports" type="stringListType" minOccurs="0"/>
2251-
<xs:element name="useBuiltinTransports" type="boolType" minOccurs="0"/>
2252-
<xs:element name="propertiesPolicy" type="propertyPolicyType" minOccurs="0"/>
2253-
<xs:element name="name" type="stringType" minOccurs="0"/>
2233+
<xs:complexType name="participantProfileType">
2234+
<xs:all>
2235+
<xs:element name="domainId" type="domainIDType" minOccurs="0" maxOccurs="1"/>
2236+
<xs:element name="rtps" minOccurs="0" maxOccurs="1">
2237+
<xs:complexType>
2238+
<xs:all>
2239+
<xs:element name="name" type="string" minOccurs="0" maxOccurs="1"/>
2240+
<xs:element name="defaultUnicastLocatorList" type="locatorListType" minOccurs="0" maxOccurs="1"/>
2241+
<xs:element name="defaultMulticastLocatorList" type="locatorListType" minOccurs="0" maxOccurs="1"/>
2242+
<xs:element name="default_external_unicast_locators" type="externalLocatorListType" minOccurs="0" maxOccurs="1"/>
2243+
<xs:element name="ignore_non_matching_locators" type="boolean" minOccurs="0" maxOccurs="1"/>
2244+
<xs:element name="sendSocketBufferSize" type="uint32" minOccurs="0" maxOccurs="1"/>
2245+
<xs:element name="listenSocketBufferSize" type="uint32" minOccurs="0" maxOccurs="1"/>
2246+
<xs:element name="netmask_filter" minOccurs="0" maxOccurs="1">
2247+
<xs:simpleType>
2248+
<xs:restriction base="xs:string">
2249+
<xs:enumeration value="OFF"/>
2250+
<xs:enumeration value="AUTO"/>
2251+
<xs:enumeration value="ON"/>
2252+
</xs:restriction>
2253+
</xs:simpleType>
2254+
</xs:element>
2255+
<xs:element name="builtin" type="builtinAttributesType" minOccurs="0" maxOccurs="1"/>
2256+
<xs:element name="port" type="portType" minOccurs="0" maxOccurs="1"/>
2257+
<xs:element name="participantID" type="int32" minOccurs="0" maxOccurs="1"/>
2258+
<xs:element name="easy_mode_ip" type="string" minOccurs="0" maxOccurs="1"/>
2259+
<xs:element name="userTransports" minOccurs="0" maxOccurs="1">
2260+
<xs:complexType>
2261+
<xs:sequence>
2262+
<xs:element name="transport_id" type="string" minOccurs="1" maxOccurs="unbounded"/>
2263+
</xs:sequence>
2264+
</xs:complexType>
2265+
</xs:element>
2266+
<xs:element name="useBuiltinTransports" type="boolean" minOccurs="0" maxOccurs="1"/>
2267+
<xs:element name="builtinTransports" type="builtinTransportsType" minOccurs="0" maxOccurs="1"/>
2268+
<xs:element name="propertiesPolicy" type="propertyPolicyType" minOccurs="0" maxOccurs="1"/>
2269+
<xs:element name="allocation" type="rtpsParticipantAllocationAttributesType" minOccurs="0" maxOccurs="1"/>
2270+
<xs:element name="userData" type="octectVectorQosPolicyType" minOccurs="0" maxOccurs="1"/>
2271+
<xs:element name="prefix" type="prefixType" minOccurs="0" maxOccurs="1"/>
2272+
<xs:element name="flow_controller_descriptor_list" type="flowControllerDescriptorListType" minOccurs="0" maxOccurs="1"/>
2273+
<xs:element name="builtin_controllers_sender_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
2274+
<xs:element name="timed_events_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
2275+
<xs:element name="discovery_server_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
2276+
<xs:element name="typelookup_service_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
2277+
<xs:element name="builtin_transports_reception_threads" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
2278+
<xs:element name="security_log_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
2279+
</xs:all>
2280+
</xs:complexType>
2281+
</xs:element>
22542282
</xs:all>
22552283
</xs:complexType>
22562284
*/
@@ -2286,7 +2314,7 @@ XMLP_ret XMLParser::fillDataNode(
22862314

22872315
if (strcmp(p_element->Name(), DOMAIN_ID) == 0)
22882316
{
2289-
// domainId - uint32Type
2317+
// domainId - uint32
22902318
if (XMLP_ret::XML_OK != getXMLUint(p_element, &participant_node.get()->domainId, ident))
22912319
{
22922320
return XMLP_ret::XML_ERROR;
@@ -2343,7 +2371,7 @@ XMLP_ret XMLParser::fillDataNode(
23432371
}
23442372
else if (strcmp(name, IGN_NON_MATCHING_LOCS) == 0)
23452373
{
2346-
// ignore_non_matching_locators - boolType
2374+
// ignore_non_matching_locators - boolean
23472375
if (XMLP_ret::XML_OK !=
23482376
getXMLBool(p_aux0, &participant_node.get()->rtps.ignore_non_matching_locators, ident))
23492377
{
@@ -2380,15 +2408,15 @@ XMLP_ret XMLParser::fillDataNode(
23802408
}
23812409
else if (strcmp(name, SEND_SOCK_BUF_SIZE) == 0)
23822410
{
2383-
// sendSocketBufferSize - uint32Type
2411+
// sendSocketBufferSize - uint32
23842412
if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &participant_node.get()->rtps.sendSocketBufferSize, ident))
23852413
{
23862414
return XMLP_ret::XML_ERROR;
23872415
}
23882416
}
23892417
else if (strcmp(name, LIST_SOCK_BUF_SIZE) == 0)
23902418
{
2391-
// listenSocketBufferSize - uint32Type
2419+
// listenSocketBufferSize - uint32
23922420
if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &participant_node.get()->rtps.listenSocketBufferSize, ident))
23932421
{
23942422
return XMLP_ret::XML_ERROR;
@@ -2440,12 +2468,30 @@ XMLP_ret XMLParser::fillDataNode(
24402468
}
24412469
else if (strcmp(name, PART_ID) == 0)
24422470
{
2443-
// participantID - int32Type
2471+
// participantID - int32
24442472
if (XMLP_ret::XML_OK != getXMLInt(p_aux0, &participant_node.get()->rtps.participantID, ident))
24452473
{
24462474
return XMLP_ret::XML_ERROR;
24472475
}
24482476
}
2477+
else if (strcmp(name, EASY_MODE_IP) == 0)
2478+
{
2479+
// easy_mode_ip - string
2480+
std::string str_aux;
2481+
if (XMLP_ret::XML_OK != getXMLString(p_aux0, &str_aux, ident))
2482+
{
2483+
return XMLP_ret::XML_ERROR;
2484+
}
2485+
2486+
// Check that the string is a valid IPv4 address
2487+
if (!fastdds::rtps::IPLocator::isIPv4(str_aux))
2488+
{
2489+
EPROSIMA_LOG_ERROR(XMLPARSER, "'easy_mode_ip' is not a valid IPv4 address.");
2490+
return XMLP_ret::XML_ERROR;
2491+
}
2492+
2493+
participant_node.get()->rtps.easy_mode_ip = str_aux;
2494+
}
24492495
else if (strcmp(name, FLOW_CONTROLLER_DESCRIPTOR_LIST) == 0)
24502496
{
24512497
// flow_controller_descriptors
@@ -2465,7 +2511,7 @@ XMLP_ret XMLParser::fillDataNode(
24652511
}
24662512
else if (strcmp(name, USE_BUILTIN_TRANS) == 0)
24672513
{
2468-
// useBuiltinTransports - boolType
2514+
// useBuiltinTransports - boolean
24692515
if (XMLP_ret::XML_OK != getXMLBool(p_aux0, &participant_node.get()->rtps.useBuiltinTransports, ident))
24702516
{
24712517
return XMLP_ret::XML_ERROR;
@@ -2492,7 +2538,7 @@ XMLP_ret XMLParser::fillDataNode(
24922538
}
24932539
else if (strcmp(name, NAME) == 0)
24942540
{
2495-
// name - stringType
2541+
// name - string
24962542
std::string s;
24972543
if (XMLP_ret::XML_OK != getXMLString(p_aux0, &s, ident))
24982544
{

src/cpp/xmlparser/XMLParserCommon.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const char* LOGICAL_PORT = "logical_port";
123123
const char* PHYSICAL_PORT = "physical_port";
124124
const char* USER_DATA = "userData";
125125
const char* PART_ID = "participantID";
126+
const char* EASY_MODE_IP = "easy_mode_ip";
126127
const char* FLOW_CONTROLLER_DESCRIPTOR_LIST = "flow_controller_descriptor_list";
127128
const char* USER_TRANS = "userTransports";
128129
const char* USE_BUILTIN_TRANS = "useBuiltinTransports";

src/cpp/xmlparser/XMLParserCommon.h

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ extern const char* LOGICAL_PORT;
137137
extern const char* PHYSICAL_PORT;
138138
extern const char* USER_DATA;
139139
extern const char* PART_ID;
140+
extern const char* EASY_MODE_IP;
140141
extern const char* IP4_TO_SEND;
141142
extern const char* IP6_TO_SEND;
142143
extern const char* FLOW_CONTROLLER_DESCRIPTOR_LIST;

0 commit comments

Comments
 (0)