Skip to content

Commit 338b951

Browse files
authored
New version of EDP static discovery (#5860)
* Refs #22200. First impl EDPStatic v2_Reduced Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #22200. Fix persistence with new static discovery Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #22200. Change new static discovery version name Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #22200. Tests Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #22200. Add entry in versions.md Signed-off-by: Ricardo González Moreno <[email protected]> * Refs 23392. Fix tests Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #23392. Apply suggestion Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #23392. Improve base64 encode and decode Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #23392. Fix compilation warning Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #23392. Add doxygen documentation Signed-off-by: Ricardo González Moreno <[email protected]> --------- Signed-off-by: Ricardo González Moreno <[email protected]>
1 parent 10117c2 commit 338b951

File tree

11 files changed

+574
-84
lines changed

11 files changed

+574
-84
lines changed

src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.cpp

Lines changed: 351 additions & 44 deletions
Large diffs are not rendered by default.

src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class EDPStatic : public EDP
4343
enum class ExchangeFormat : uint32_t
4444
{
4545
v1, //! Standard exchange format for Static Discovery.
46-
v1_Reduced //! Exchange format that reduces the used network bandwidth.
46+
v1_Reduced, //! Exchange format that reduces the used network bandwidth.
47+
v2 //! Exchange format that reduces the used network bandwidth with more restrictions.
4748
};
4849

4950
/**
@@ -148,6 +149,18 @@ class EDPStatic : public EDP
148149
bool checkEntityId(
149150
WriterProxyData* wdata);
150151

152+
bool enable_reader_on_v2_property(
153+
const std::string& local_participant_name,
154+
fastdds::dds::ParameterPropertyList_t& pdp_properties,
155+
uint16_t id,
156+
bool disable);
157+
158+
bool enable_writer_on_v2_property(
159+
const std::string& local_participant_name,
160+
fastdds::dds::ParameterPropertyList_t& pdp_properties,
161+
uint16_t id,
162+
bool disable);
163+
151164
private:
152165

153166
xmlparser::XMLEndpointParser* mp_edpXML;

src/cpp/xmlparser/XMLEndpointParser.cpp

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <xmlparser/XMLEndpointParser.h>
2121

22+
#include <algorithm>
2223
#include <cstdlib>
2324
#include <string>
2425

@@ -789,21 +790,28 @@ XMLP_ret XMLEndpointParser::loadXMLWriterEndpoint(
789790
XMLP_ret XMLEndpointParser::lookforReader(
790791
const char* partname,
791792
uint16_t id,
792-
ReaderProxyData** rdataptr)
793+
ReaderProxyData** rdataptr,
794+
uint32_t& position)
793795
{
794796
for (std::vector<StaticRTPSParticipantInfo*>::iterator pit = m_RTPSParticipants.begin();
795797
pit != m_RTPSParticipants.end(); ++pit)
796798
{
797799
if ((*pit)->m_RTPSParticipantName == partname || true) //it doenst matter the name fo the RTPSParticipant, only for organizational purposes
798800
{
801+
position = 0;
799802
for (std::vector<ReaderProxyData*>::iterator rit = (*pit)->m_readers.begin();
800803
rit != (*pit)->m_readers.end(); ++rit)
801804
{
802805
if ((*rit)->user_defined_id() == id)
803806
{
804-
*rdataptr = *rit;
807+
if (nullptr != rdataptr)
808+
{
809+
*rdataptr = *rit;
810+
}
805811
return XMLP_ret::XML_OK;
806812
}
813+
814+
++position;
807815
}
808816
}
809817
}
@@ -813,27 +821,132 @@ XMLP_ret XMLEndpointParser::lookforReader(
813821
XMLP_ret XMLEndpointParser::lookforWriter(
814822
const char* partname,
815823
uint16_t id,
816-
WriterProxyData** wdataptr)
824+
WriterProxyData** wdataptr,
825+
uint32_t& position)
817826
{
818827
for (std::vector<StaticRTPSParticipantInfo*>::iterator pit = m_RTPSParticipants.begin();
819828
pit != m_RTPSParticipants.end(); ++pit)
820829
{
821830
if ((*pit)->m_RTPSParticipantName == partname || true) //it doenst matter the name fo the RTPSParticipant, only for organizational purposes
822831
{
832+
position = 0;
823833
for (std::vector<WriterProxyData*>::iterator wit = (*pit)->m_writers.begin();
824834
wit != (*pit)->m_writers.end(); ++wit)
825835
{
826836
if ((*wit)->user_defined_id() == id)
827837
{
828-
*wdataptr = *wit;
838+
if (nullptr != wdataptr)
839+
{
840+
*wdataptr = *wit;
841+
}
829842
return XMLP_ret::XML_OK;
830843
}
844+
845+
++position;
831846
}
832847
}
833848
}
834849
return XMLP_ret::XML_ERROR;
835850
}
836851

852+
XMLP_ret XMLEndpointParser::get_reader_from_position(
853+
const std::string& participant_name,
854+
size_t pos,
855+
rtps::ReaderProxyData** rdataptr)
856+
{
857+
XMLP_ret ret_value {XMLP_ret::XML_ERROR};
858+
859+
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
860+
[&participant_name](StaticRTPSParticipantInfo* participant_info)
861+
{
862+
if (participant_info->m_RTPSParticipantName ==
863+
participant_name.substr(0, participant_name.find_first_of('#')))
864+
{
865+
return true;
866+
}
867+
return false;
868+
});
869+
870+
if (m_RTPSParticipants.end() != participant_it && (*participant_it)->m_readers.size() > pos && nullptr != rdataptr)
871+
{
872+
*rdataptr = (*participant_it)->m_readers.at(pos);
873+
ret_value = XMLP_ret::XML_OK;
874+
}
875+
return ret_value;
876+
}
877+
878+
XMLP_ret XMLEndpointParser::get_writer_from_position(
879+
const std::string& participant_name,
880+
size_t pos,
881+
rtps::WriterProxyData** wdataptr)
882+
{
883+
XMLP_ret ret_value {XMLP_ret::XML_ERROR};
884+
885+
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
886+
[&participant_name](StaticRTPSParticipantInfo* participant_info)
887+
{
888+
if (participant_info->m_RTPSParticipantName ==
889+
participant_name.substr(0, participant_name.find_first_of('#')))
890+
{
891+
return true;
892+
}
893+
return false;
894+
});
895+
896+
if (m_RTPSParticipants.end() != participant_it && (*participant_it)->m_writers.size() > pos && nullptr != wdataptr)
897+
{
898+
*wdataptr = (*participant_it)->m_writers.at(pos);
899+
ret_value = XMLP_ret::XML_OK;
900+
}
901+
return ret_value;
902+
}
903+
904+
size_t XMLEndpointParser::get_number_of_readers(
905+
const std::string& participant_name)
906+
{
907+
size_t ret_value {0};
908+
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
909+
[&participant_name](StaticRTPSParticipantInfo* participant_info)
910+
{
911+
if (participant_info->m_RTPSParticipantName ==
912+
participant_name.substr(0, participant_name.find_first_of('#')))
913+
{
914+
return true;
915+
}
916+
return false;
917+
});
918+
919+
if (m_RTPSParticipants.end() != participant_it)
920+
{
921+
ret_value = (*participant_it)->m_readers.size();
922+
}
923+
924+
return ret_value;
925+
}
926+
927+
size_t XMLEndpointParser::get_number_of_writers(
928+
const std::string& participant_name)
929+
{
930+
size_t ret_value {0};
931+
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
932+
[&participant_name](StaticRTPSParticipantInfo* participant_info)
933+
{
934+
if (participant_info->m_RTPSParticipantName ==
935+
participant_name.substr(0, participant_name.find_first_of('#')))
936+
{
937+
return true;
938+
}
939+
return false;
940+
});
941+
942+
if (m_RTPSParticipants.end() != participant_it)
943+
{
944+
ret_value = (*participant_it)->m_writers.size();
945+
}
946+
947+
return ret_value;
948+
}
949+
837950
} // namespace xmlparser
838951
} // namespace fastdds
839952
} // namespace eprosima

src/cpp/xmlparser/XMLEndpointParser.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,68 @@ class XMLEndpointParser : XMLParser
126126
* @param [in] partname RTPSParticipant name
127127
* @param [in] id Id of the reader
128128
* @param [out] rdataptr Pointer to pointer to return the information.
129+
* @param [out] position Return the position of the reader in the vector of readers.
129130
* @return True if found.
130131
*/
131132
XMLP_ret lookforReader(
132133
const char* partname,
133134
uint16_t id,
134-
rtps::ReaderProxyData** rdataptr);
135+
rtps::ReaderProxyData** rdataptr,
136+
uint32_t& position);
135137
/**
136138
* Look for a writer in the previously loaded endpoints.
137139
* @param [in] partname RTPSParticipant name
138140
* @param [in] id Id of the writer
139141
* @param [out] wdataptr Pointer to pointer to return the information.
142+
* @param [out] position Return the position of the writer in the vector of writers.
140143
* @return True if found
141144
*/
142145
XMLP_ret lookforWriter(
143146
const char* partname,
144147
uint16_t id,
148+
rtps::WriterProxyData** wdataptr,
149+
uint32_t& position);
150+
151+
/**
152+
* Get a reader from the position in the vector of readers.
153+
* @param[in] participant_name Name of the participant
154+
* @param[in] pos Position in the vector of readers.
155+
* @param[out] rdataptr Pointer to pointer to return the information.
156+
* @return XMLP_ret::XML_OK if found, XMLP_ret::XML_ERROR otherwise.
157+
*/
158+
XMLP_ret get_reader_from_position(
159+
const std::string& participant_name,
160+
size_t pos,
161+
rtps::ReaderProxyData** rdataptr);
162+
163+
/**
164+
* Get a writer from the position in the vector of writers.
165+
* @param[in] participant_name Name of the participant
166+
* @param[in] pos Position in the vector of writers.
167+
* @param[out] wdataptr Pointer to pointer to return the information.
168+
* @return XMLP_ret::XML_OK if found, XMLP_ret::XML_ERROR otherwise.
169+
*/
170+
XMLP_ret get_writer_from_position(
171+
const std::string& participant_name,
172+
size_t pos,
145173
rtps::WriterProxyData** wdataptr);
146174

175+
/**
176+
* Get the number of readers for a participant.
177+
* @param[in] participant_name Name of the participant.
178+
* @return Number of readers for the participant.
179+
*/
180+
size_t get_number_of_readers(
181+
const std::string& participant_name);
182+
183+
/**
184+
* Get the number of writers for a participant.
185+
* @param[in] participant_name Name of the participant.
186+
* @return Number of writers for the participant.
187+
*/
188+
size_t get_number_of_writers(
189+
const std::string& participant_name);
190+
147191
private:
148192

149193
XMLP_ret get_disable_positive_acks_qos(

test/blackbox/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ if(W_UNICAST_PORT_RANDOM_NUMBER LESS 1025)
156156
endif()
157157
math(EXPR R_UNICAST_PORT_RANDOM_NUMBER "${W_UNICAST_PORT_RANDOM_NUMBER} + 1")
158158
math(EXPR MULTICAST_PORT_RANDOM_NUMBER "${R_UNICAST_PORT_RANDOM_NUMBER} + 1")
159-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PubSubWriter_static_disc.xml.in
160-
${CMAKE_CURRENT_BINARY_DIR}/PubSubWriter_static_disc.xml)
161-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PubSubReader_static_disc.xml.in
162-
${CMAKE_CURRENT_BINARY_DIR}/PubSubReader_static_disc.xml)
159+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/RTPSParticipant_static_disc.xml.in
160+
${CMAKE_CURRENT_BINARY_DIR}/RTPSParticipant_static_disc.xml)
163161
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PubSubWriterPersistence_static_disc.xml.in
164162
${CMAKE_CURRENT_BINARY_DIR}/PubSubWriterPersistence_static_disc.xml)
165163
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PubSubReaderPersistence_static_disc.xml.in

test/blackbox/PubSubReader_static_disc.xml.in

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/blackbox/PubSubWriter_static_disc.xml.in renamed to test/blackbox/RTPSParticipant_static_disc.xml.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,20 @@
1717
port="@MULTICAST_PORT_RANDOM_NUMBER@"/>
1818
<durabilityQos>TRANSIENT_LOCAL_DURABILITY_QOS</durabilityQos>
1919
</reader>
20+
<writer>
21+
<userId>1</userId>
22+
<entityID>2</entityID>
23+
<topicName>BlackBox_StaticDiscovery_@TOPIC_RANDOM_NUMBER@</topicName>
24+
<topicDataType>HelloWorld</topicDataType>
25+
<topicKind>NO_KEY</topicKind>
26+
<reliabilityQos>RELIABLE_RELIABILITY_QOS</reliabilityQos>
27+
<unicastLocator
28+
address="127.0.0.1"
29+
port="@W_UNICAST_PORT_RANDOM_NUMBER@"/>
30+
<multicastLocator
31+
address="127.0.0.1"
32+
port="@MULTICAST_PORT_RANDOM_NUMBER@"/>
33+
<durabilityQos>TRANSIENT_LOCAL_DURABILITY_QOS</durabilityQos>
34+
</writer>
2035
</participant>
2136
</staticdiscovery>

test/blackbox/common/BlackboxTestsDiscovery.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void static_discovery_test(
200200
writer.history_kind(eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS)
201201
.durability_kind(eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS)
202202
.property_policy(writer_property_policy);
203-
writer.static_discovery("file://PubSubWriter_static_disc.xml").reliability(
203+
writer.static_discovery("file://RTPSParticipant_static_disc.xml").reliability(
204204
eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS).
205205
unicastLocatorList(WriterUnicastLocators).multicast_locator_list(WriterMulticastLocators).
206206
setPublisherIDs(1,
@@ -236,7 +236,7 @@ void static_discovery_test(
236236
.history_kind(eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS)
237237
.durability_kind(eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS)
238238
.property_policy(reader_property_policy);
239-
reader.static_discovery("file://PubSubReader_static_disc.xml").
239+
reader.static_discovery("file://RTPSParticipant_static_disc.xml").
240240
unicastLocatorList(ReaderUnicastLocators).multicast_locator_list(ReaderMulticastLocators).
241241
setSubscriberIDs(3,
242242
4).setManualTopicName(std::string("BlackBox_StaticDiscovery_") + TOPIC_RANDOM_NUMBER).init();
@@ -280,6 +280,21 @@ TEST(Discovery, StaticDiscovery_v1_Mixed)
280280
static_discovery_test("v1", "v1_Reduced");
281281
}
282282

283+
TEST(Discovery, StaticDiscovery_v2)
284+
{
285+
static_discovery_test("v2", "v2");
286+
}
287+
288+
TEST(Discovery, StaticDiscovery_v1_v2)
289+
{
290+
static_discovery_test("v1", "v2");
291+
}
292+
293+
TEST(Discovery, StaticDiscovery_v1_Reduced_v2)
294+
{
295+
static_discovery_test("v1_Reduced", "v2");
296+
}
297+
283298
TEST(Discovery, StaticDiscovery_wrong_exchange_format)
284299
{
285300
static_discovery_test("wrong", "wrong", false);

0 commit comments

Comments
 (0)