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 3 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
24 changes: 24 additions & 0 deletions include/fastdds/dds/core/policy/QosPolicies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,7 @@ class WireProtocolConfigQos : public QosPolicy
FASTDDS_EXPORTED_API WireProtocolConfigQos()
: QosPolicy(false)
, participant_id(-1)
, easy_mode_("")
{
}

Expand All @@ -2683,6 +2684,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 +2727,28 @@ class WireProtocolConfigQos : public QosPolicy
* Whether locators that don't match with the announced locators should be kept.
*/
bool ignore_non_matching_locators = false;

/**
* Setter for ROS 2 Easy Mode IP
*/
void easy_mode(
std::string ip)
{
easy_mode_ = ip;
}

/**
* Getter for ROS 2 Easy Mode IP
*/
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 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
9 changes: 9 additions & 0 deletions src/cpp/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,7 @@ XMLP_ret XMLParser::fillDataNode(
<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="easy_mode_ip" type="stringType" 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"/>
Expand Down Expand Up @@ -2446,6 +2447,14 @@ XMLP_ret XMLParser::fillDataNode(
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, EASY_MODE_IP) == 0)
{
// easy_mode_ip - stringType
if (XMLP_ret::XML_OK != getXMLString(p_aux0, &participant_node.get()->rtps.easy_mode_ip, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, FLOW_CONTROLLER_DESCRIPTOR_LIST) == 0)
{
// flow_controller_descriptors
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
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,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 @@ -553,6 +554,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
5 changes: 5 additions & 0 deletions test/unittest/xmlparser/XMLParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ TEST_F(XMLParserTests, Data)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -638,6 +639,7 @@ TEST_F(XMLParserTests, DataDeprecated)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -733,6 +735,7 @@ TEST_F(XMLParserTests, DataBuffer)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -828,6 +831,7 @@ TEST_F(XMLParserTests, DataBufferDeprecated)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -1862,6 +1866,7 @@ TEST_F(XMLParserTests, fillDataNodeParticipantNegativeClauses)
"<builtin><bad_element></bad_element></builtin>",
"<port><bad_element></bad_element></port>",
"<participantID><bad_element></bad_element></participantID>",
"<easy_mode_ip><bad_element></bad_element></easy_mode_ip>",
"<flow_controller_descriptor_list><bad_element></bad_element></flow_controller_descriptor_list>",
"<userTransports><bad_element></bad_element></userTransports>",
"<useBuiltinTransports><bad_element></bad_element></useBuiltinTransports>",
Expand Down
9 changes: 7 additions & 2 deletions test/unittest/xmlparser/XMLProfileParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class XMLProfileParserTests : public XMLProfileParserBasicTests, public testing:

std::string xml_filename_ = "test_xml_profile.xml";

const std::pair<std::string, std::string> c_environment_values_[168]
const std::pair<std::string, std::string> c_environment_values_[169]
{
{"XML_PROFILES_ENV_VAR_1", "123"},
{"XML_PROFILES_ENV_VAR_2", "4"},
Expand Down Expand Up @@ -305,7 +305,8 @@ class XMLProfileParserTests : public XMLProfileParserBasicTests, public testing:
{"XML_PROFILES_ENV_VAR_165", "2048"},
{"XML_PROFILES_ENV_VAR_166", "45"},
{"XML_PROFILES_ENV_VAR_167", "test_flow_controller"},
{"XML_PROFILES_ENV_VAR_168", "251"}
{"XML_PROFILES_ENV_VAR_168", "251"},
{"XML_PROFILES_ENV_VAR_169", "127.0.0.1"}
};

};
Expand Down Expand Up @@ -568,6 +569,7 @@ TEST_P(XMLProfileParserTests, XMLParserParticipant)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -669,6 +671,7 @@ TEST_F(XMLProfileParserBasicTests, XMLParserParticipantDeprecated)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -753,6 +756,7 @@ TEST_P(XMLProfileParserTests, XMLParserDefaultParticipantProfile)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down Expand Up @@ -837,6 +841,7 @@ TEST_F(XMLProfileParserBasicTests, XMLParserDefaultParticipantProfileDeprecated)
EXPECT_EQ(port.offsetd3, 456);
EXPECT_EQ(port.offsetd4, 251);
EXPECT_EQ(rtps_atts.participantID, 9898);
EXPECT_EQ(rtps_atts.easy_mode_ip, "127.0.0.1");
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->max_bytes_per_period, 2048);
EXPECT_EQ(rtps_atts.flow_controllers.at(0)->period_ms, 45u);
EXPECT_EQ(rtps_atts.useBuiltinTransports, true);
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/test_xml_deprecated.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<offsetd4>251</offsetd4>
</port>
<participantID>9898</participantID>
<easy_mode_ip>127.0.0.1</easy_mode_ip>
<flow_controller_descriptor_list>
<flow_controller_descriptor>
<name>test_flow_controller</name>
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/test_xml_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<offsetd4>251</offsetd4>
</port>
<participantID>9898</participantID>
<easy_mode_ip>127.0.0.1</easy_mode_ip>
<useBuiltinTransports>true</useBuiltinTransports>
<netmask_filter>ON</netmask_filter>
<name>test_name</name>
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/test_xml_profile_env_var.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<offsetd4>${XML_PROFILES_ENV_VAR_168}</offsetd4>
</port>
<participantID>${XML_PROFILES_ENV_VAR_63}</participantID>
<easy_mode_ip>${XML_PROFILES_ENV_VAR_169}</easy_mode_ip>
<useBuiltinTransports>${XML_PROFILES_ENV_VAR_64}</useBuiltinTransports>
<netmask_filter>${XML_PROFILES_ENV_VAR_162}</netmask_filter>
<name>${XML_PROFILES_ENV_VAR_65}</name>
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/test_xml_rooted_deprecated.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<offsetd4>251</offsetd4>
</port>
<participantID>9898</participantID>
<easy_mode_ip>127.0.0.1</easy_mode_ip>
<flow_controller_descriptor_list>
<flow_controller_descriptor>
<name>test_flow_controller</name>
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/test_xml_rooted_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<offsetd4>251</offsetd4>
</port>
<participantID>9898</participantID>
<easy_mode_ip>127.0.0.1</easy_mode_ip>
<useBuiltinTransports>true</useBuiltinTransports>
<name>test_name</name>
<builtin_controllers_sender_thread>
Expand Down
1 change: 1 addition & 0 deletions versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Forthcoming
* New `ROS2_EASY_MODE` environment variable
* Extended CLI ``discovery`` command to handle Fast DDS daemon.
* Added P2P builtin transport.
* Added new `easy_mode_ip` XML tag and `easy_mode_` member in `WireProtocolConfigQos` for Discovery Server IP configuration.

Version v3.1.0
--------------
Expand Down