Skip to content

Commit

Permalink
Add XML configuration for FlowControllerDescriptor to 2.x (#4893)
Browse files Browse the repository at this point in the history
* Refs #21136: Replace const char* with string

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21136: Update fastRTPS_profiles.xsd

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21136: Implement flow controller descriptor list in XML related source files

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21136: Update tests

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21136: versions.md

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21136: Linter

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21136: Apply rev

Signed-off-by: Mario Dominguez <[email protected]>

---------

Signed-off-by: Mario Dominguez <[email protected]>
(cherry picked from commit e6044e0)

# Conflicts:
#	test/unittest/xmlparser/XMLProfileParserTests.cpp
#	versions.md
  • Loading branch information
Mario-DL authored and mergify[bot] committed Jun 6, 2024
1 parent c0c5a79 commit 2237970
Show file tree
Hide file tree
Showing 22 changed files with 561 additions and 7 deletions.
4 changes: 2 additions & 2 deletions include/fastdds/dds/core/policy/QosPolicies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ class PublishModeQosPolicy : public QosPolicy
*
* @since 2.4.0
*/
const char* flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT;
std::string flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT;

inline void clear() override
{
Expand All @@ -2058,7 +2058,7 @@ class PublishModeQosPolicy : public QosPolicy
const PublishModeQosPolicy& b) const
{
return (this->kind == b.kind) &&
0 == strcmp(flow_controller_name, b.flow_controller_name) &&
flow_controller_name == b.flow_controller_name.c_str() &&
QosPolicy::operator ==(b);
}

Expand Down
2 changes: 1 addition & 1 deletion include/fastdds/rtps/attributes/WriterAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class WriterAttributes
Duration_t keep_duration;

//! Flow controller name. Default: fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT.
const char* flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT;
std::string flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT;
};

} /* namespace rtps */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP
#define FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP

#include <string>

#include <fastdds/rtps/attributes/ThreadSettings.hpp>

#include "FlowControllerConsts.hpp"
Expand All @@ -33,7 +35,7 @@ namespace rtps {
struct FlowControllerDescriptor
{
//! Name of the flow controller.
const char* name = nullptr;
std::string name = FASTDDS_FLOW_CONTROLLER_DEFAULT;

//! Scheduler policy used by the flow controller.
//!
Expand Down
7 changes: 7 additions & 0 deletions include/fastrtps/xmlparser/XMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class XMLParser

public:

using FlowControllerDescriptorList = std::vector<std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>>;

/**
* Load the default XML file.
* @return XMLP_ret::XML_OK on success, XMLP_ret::XML_ERROR in other case.
Expand Down Expand Up @@ -536,6 +538,11 @@ class XMLParser
rtps::ThroughputControllerDescriptor& throughputController,
uint8_t ident);

RTPS_DllAPI static XMLP_ret getXMLFlowControllerDescriptorList(
tinyxml2::XMLElement* elem,
FlowControllerDescriptorList& flow_controller_descriptor_list,
uint8_t ident);

RTPS_DllAPI static XMLP_ret getXMLPortParameters(
tinyxml2::XMLElement* elem,
rtps::PortParameters& port,
Expand Down
12 changes: 12 additions & 0 deletions include/fastrtps/xmlparser/XMLParserCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extern const char* PART_ID;
extern const char* IP4_TO_SEND;
extern const char* IP6_TO_SEND;
extern const char* THROUGHPUT_CONT;
extern const char* FLOW_CONTROLLER_DESCRIPTOR_LIST;
extern const char* USER_TRANS;
extern const char* USE_BUILTIN_TRANS;
extern const char* BUILTIN_TRANS;
Expand Down Expand Up @@ -287,6 +288,17 @@ extern const char* ALLOCATED_SAMPLES;
extern const char* EXTRA_SAMPLES;
extern const char* BYTES_PER_SECOND;
extern const char* PERIOD_MILLISECS;
extern const char* FLOW_CONTROLLER_DESCRIPTOR;
extern const char* SCHEDULER;
extern const char* SENDER_THREAD;
extern const char* MAX_BYTES_PER_PERIOD;
extern const char* PERIOD_MS;
extern const char* FLOW_CONTROLLER_NAME;
extern const char* FIFO;
extern const char* HIGH_PRIORITY;
extern const char* ROUND_ROBIN;
extern const char* PRIORITY_WITH_RESERVATION;
extern const char* FLOW_CONTROLLER_NAME;
extern const char* PORT_BASE;
extern const char* DOMAIN_ID_GAIN;
extern const char* PARTICIPANT_ID_GAIN;
Expand Down
41 changes: 40 additions & 1 deletion resources/xsd/fastRTPS_profiles.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
├ allocation [0~1],
├ userData [0~1],
├ prefix [0~1],
├ flow_controller_descriptor_list [flowControllerDescriptorListType],
├ builtin_controllers_sender_thread [threadSettingsType],
├ timed_events_thread [threadSettingsType],
├ discovery_server_thread [threadSettingsType],
Expand Down Expand Up @@ -182,6 +183,7 @@
<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"/>
Expand Down Expand Up @@ -1616,7 +1618,8 @@
</xs:complexType>

<!--QoS Publish Mode:
└ kind [string] ("ASYNCHRONOUS", "SYNCHRONOUS") -->
├ kind [string] ("ASYNCHRONOUS", "SYNCHRONOUS")
└ flow_controller_name [string] -->
<xs:complexType name="publishModeQosPolicyType">
<xs:all>
<xs:element name="kind" minOccurs="0" maxOccurs="1">
Expand All @@ -1627,6 +1630,7 @@
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="flow_controller_name" type="string" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>

Expand Down Expand Up @@ -1757,6 +1761,41 @@
</xs:all>
</xs:complexType>

<!--Flow Controller Descriptor List Type:
└ flow_controller_descriptor [1~*]-->
<xs:complexType name="flowControllerDescriptorListType">
<xs:sequence minOccurs="1" maxOccurs="unbounded"> <!-- multiple instances of the elements -->
<xs:element name="flow_controller_descriptor" type="flowControllerDescriptorType"/>
</xs:sequence>
</xs:complexType>

<!--Flow Controller Descriptor Type:
├ name [string] req,
├ scheduler [flowControllerSchedulerPolicy],
├ max_bytes_per_period [int32],
├ period_ms [uint64],
└ sender_thread [threadSettingsType]-->
<xs:complexType name="flowControllerDescriptorType">
<xs:all>
<xs:element name="name" type="string" minOccurs="1" maxOccurs="1"/>
<xs:element name="scheduler" type="flowControllerSchedulerPolicy" minOccurs="0" maxOccurs="1"/>
<xs:element name="max_bytes_per_period" type="int32" minOccurs="0" maxOccurs="1"/>
<xs:element name="period_ms" type="uint64" minOccurs="0" maxOccurs="1"/>
<xs:element name="sender_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>

<!--Flow Controller Scheduler Policy Type [string]:
("FIFO", "ROUND_ROBIN", "HIGH_PRIORITY", "PRIORITY_WITH_RESERVATION")-->
<xs:simpleType name="flowControllerSchedulerPolicy">
<xs:restriction base="xs:string">
<xs:enumeration value="FIFO" />
<xs:enumeration value="ROUND_ROBIN" />
<xs:enumeration value="HIGH_PRIORITY" />
<xs:enumeration value="PRIORITY_WITH_RESERVATION" />
</xs:restriction>
</xs:simpleType>

<!--Thread Settings Type:
| ╠ att. port [uint32]
|
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ bool RTPSParticipantImpl::create_writer(

GUID_t guid(m_guid.guidPrefix, entId);
fastdds::rtps::FlowController* flow_controller = nullptr;
const char* flow_controller_name = param.flow_controller_name;
std::string flow_controller_name = param.flow_controller_name;

// Support of old flow controller style.
if (param.throughputController.bytesPerPeriod != UINT32_MAX && param.throughputController.periodMillisecs != 0)
Expand Down
149 changes: 149 additions & 0 deletions src/cpp/rtps/xmlparser/XMLElementParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,145 @@ XMLP_ret XMLParser::getXMLThroughputController(
return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::getXMLFlowControllerDescriptorList(
tinyxml2::XMLElement* elem,
FlowControllerDescriptorList& flow_controller_descriptor_list,
uint8_t ident)
{
/*
<xs:complexType name="flowControllerDescriptorListType">
<xs:sequence>
<xs:element name="flow_controller_descriptor" type="flowControllerDescriptorType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
*/

tinyxml2::XMLElement* p_aux0 = nullptr;
p_aux0 = elem->FirstChildElement(FLOW_CONTROLLER_DESCRIPTOR);
if (nullptr == p_aux0)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Node '" << elem->Value() << "' without content");
return XMLP_ret::XML_ERROR;
}

while (nullptr != p_aux0)
{
/*
<xs:complexType name="flowControllerDescriptorType">
<xs:all>
<xs:element name="name" type="string" minOccurs="1" maxOccurs="1"/>
<xs:element name="scheduler" type="flowControllerSchedulerPolicy" minOccurs="0" maxOccurs="1"/>
<xs:element name="max_bytes_per_period" type="int32" minOccurs="0" maxOccurs="1"/>
<xs:element name="period_ms" type="uint64" minOccurs="0" maxOccurs="1"/>
<xs:element name="sender_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
<xs:simpleType name="flowControllerSchedulerPolicy">
<xs:restriction base="xs:string">
<xs:enumeration value="FIFO" />
<xs:enumeration value="ROUND_ROBIN" />
<xs:enumeration value="HIGH_PRIORITY" />
<xs:enumeration value="PRIORITY_WITH_RESERVATION" />
</xs:restriction>
</xs:simpleType>
*/

tinyxml2::XMLElement* p_aux1;
bool name_defined = false;
std::set<std::string> tags_present;

auto flow_controller_descriptor = std::make_shared<fastdds::rtps::FlowControllerDescriptor>();

for (p_aux1 = p_aux0->FirstChildElement(); p_aux1 != NULL; p_aux1 = p_aux1->NextSiblingElement())
{
const char* name = p_aux1->Name();

if (tags_present.count(name) != 0)
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Duplicated element found in 'flowControllerDescriptorType'. Name: " << name);
return XMLP_ret::XML_ERROR;
}
else
{
tags_present.emplace(name);
}

if (strcmp(name, NAME) == 0)
{
// name - stringType
flow_controller_descriptor->name = get_element_text(p_aux1);
if (flow_controller_descriptor->name.empty())
{
EPROSIMA_LOG_ERROR(XMLPARSER, "<" << p_aux1->Value() << "> getXMLString XML_ERROR!");
return XMLP_ret::XML_ERROR;
}
name_defined = true;
}
else if (strcmp(name, SCHEDULER) == 0)
{
std::string text = get_element_text(p_aux1);
if (text.empty())
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Node '" << SCHEDULER << "' without content");
return XMLP_ret::XML_ERROR;
}

// scheduler - flowControllerSchedulerPolicy
if (!get_element_enum_value(text.c_str(), flow_controller_descriptor->scheduler,
FIFO, fastdds::rtps::FlowControllerSchedulerPolicy::FIFO,
HIGH_PRIORITY, fastdds::rtps::FlowControllerSchedulerPolicy::HIGH_PRIORITY,
ROUND_ROBIN, fastdds::rtps::FlowControllerSchedulerPolicy::ROUND_ROBIN,
PRIORITY_WITH_RESERVATION,
fastdds::rtps::FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Node '" << SCHEDULER << "' with bad content");
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, MAX_BYTES_PER_PERIOD) == 0)
{
// max_bytes_per_period - int32Type
if (XMLP_ret::XML_OK != getXMLInt(p_aux1, &flow_controller_descriptor->max_bytes_per_period, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, PERIOD_MS) == 0)
{
// period_ms - uint64Type
if (XMLP_ret::XML_OK != getXMLUint(p_aux1, &flow_controller_descriptor->period_ms, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, SENDER_THREAD) == 0)
{
// sender_thread - threadSettingsType
getXMLThreadSettings(*p_aux1, flow_controller_descriptor->sender_thread);
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Invalid element found into 'flowControllerDescriptorType'. Name: " << name);
return XMLP_ret::XML_ERROR;
}
}

if (!name_defined)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Flow Controller Descriptor requires a 'name'");
return XMLP_ret::XML_ERROR;
}

flow_controller_descriptor_list.push_back(flow_controller_descriptor);
p_aux0 = p_aux0->NextSiblingElement(FLOW_CONTROLLER_DESCRIPTOR);

}

return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::getXMLTopicAttributes(
tinyxml2::XMLElement* elem,
TopicAttributes& topic,
Expand Down Expand Up @@ -2697,6 +2836,16 @@ XMLP_ret XMLParser::getXMLPublishModeQos(
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, FLOW_CONTROLLER_NAME) == 0)
{

publishMode.flow_controller_name = get_element_text(p_aux0);
if (publishMode.flow_controller_name.empty())
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Node '" << FLOW_CONTROLLER_NAME << "' without content");
return XMLP_ret::XML_ERROR;
}
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found into 'publishModeQosPolicyType'. Name: " << name);
Expand Down
11 changes: 11 additions & 0 deletions src/cpp/rtps/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@ XMLP_ret XMLParser::fillDataNode(
<xs:element name="userData" type="octetVectorType" minOccurs="0"/>
<xs:element name="participantID" type="int32Type" minOccurs="0"/>
<xs:element name="throughputController" type="throughputControllerType" 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"/>
Expand Down Expand Up @@ -2217,6 +2218,16 @@ XMLP_ret XMLParser::fillDataNode(
}
EPROSIMA_LOG_WARNING(XML_PARSER, THROUGHPUT_CONT << " XML tag is deprecated");
}
else if (strcmp(name, FLOW_CONTROLLER_DESCRIPTOR_LIST) == 0)
{
// flow_controller_descriptors
if (XMLP_ret::XML_OK !=
getXMLFlowControllerDescriptorList(p_aux0,
participant_node.get()->rtps.flow_controllers, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, USER_TRANS) == 0)
{
// userTransports
Expand Down
11 changes: 11 additions & 0 deletions src/cpp/rtps/xmlparser/XMLParserCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const char* PHYSICAL_PORT = "physical_port";
const char* USER_DATA = "userData";
const char* PART_ID = "participantID";
const char* THROUGHPUT_CONT = "throughputController";
const char* FLOW_CONTROLLER_DESCRIPTOR_LIST = "flow_controller_descriptor_list";
const char* USER_TRANS = "userTransports";
const char* USE_BUILTIN_TRANS = "useBuiltinTransports";
const char* BUILTIN_TRANS = "builtinTransports";
Expand Down Expand Up @@ -275,6 +276,16 @@ const char* ALLOCATED_SAMPLES = "allocated_samples";
const char* EXTRA_SAMPLES = "extra_samples";
const char* BYTES_PER_SECOND = "bytesPerPeriod";
const char* PERIOD_MILLISECS = "periodMillisecs";
const char* FLOW_CONTROLLER_DESCRIPTOR = "flow_controller_descriptor";
const char* SCHEDULER = "scheduler";
const char* SENDER_THREAD = "sender_thread";
const char* MAX_BYTES_PER_PERIOD = "max_bytes_per_period";
const char* PERIOD_MS = "period_ms";
const char* FLOW_CONTROLLER_NAME = "flow_controller_name";
const char* FIFO = "FIFO";
const char* HIGH_PRIORITY = "HIGH_PRIORITY";
const char* ROUND_ROBIN = "ROUND_ROBIN";
const char* PRIORITY_WITH_RESERVATION = "PRIORITY_WITH_RESERVATION";
const char* PORT_BASE = "portBase";
const char* DOMAIN_ID_GAIN = "domainIDGain";
const char* PARTICIPANT_ID_GAIN = "participantIDGain";
Expand Down
Loading

0 comments on commit 2237970

Please sign in to comment.