diff --git a/CMakeLists.txt b/CMakeLists.txt index 3aac97cad..8ff1d8eb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ ############################################################################### # CMake build rules for Micro XRCE-DDS Agent ############################################################################### -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) ############################################################################### # Build options @@ -40,8 +40,8 @@ option(UAGENT_SECURITY_PROFILE "Build security profile." ON) option(UAGENT_BUILD_EXECUTABLE "Build Micro XRCE-DDS Agent provided executable." ON) option(UAGENT_BUILD_USAGE_EXAMPLES "Build Micro XRCE-DDS Agent built-in usage examples" OFF) -set(UAGENT_P2P_CLIENT_VERSION 2.2.0 CACHE STRING "Sets Micro XRCE-DDS client version for P2P") -set(UAGENT_P2P_CLIENT_TAG v2.2.0 CACHE STRING "Sets Micro XRCE-DDS client tag for P2P") +set(UAGENT_P2P_CLIENT_VERSION 2.4.1 CACHE STRING "Sets Micro XRCE-DDS client version for P2P") +set(UAGENT_P2P_CLIENT_TAG v2.4.1 CACHE STRING "Sets Micro XRCE-DDS client tag for P2P") option(UAGENT_BUILD_CI_TESTS "Build CI test cases.") if(UAGENT_BUILD_CI_TESTS) @@ -80,8 +80,8 @@ set(_deps "") if(UAGENT_USE_SYSTEM_FASTCDR) set(_fastcdr_version 1) else() - set(_fastcdr_version 1.0.22) - set(_fastcdr_tag v1.0.22) + set(_fastcdr_version 1.1.0) + set(_fastcdr_tag v1.1.0) endif() list(APPEND _deps "fastcdr\;${_fastcdr_version}") @@ -95,9 +95,9 @@ if(UAGENT_FAST_PROFILE) if(UAGENT_USE_SYSTEM_FASTDDS) set(_fastdds_version 2) else() - set(_fastdds_version 2.4.1) - set(_fastdds_tag v2.4.1) - set(_foonathan_memory_tag v0.7-1) # This tag should be updated every time it gets updated in foonathan_memory_vendor eProsima's package + set(_fastdds_version 2.11) + set(_fastdds_tag 2.11.x) + set(_foonathan_memory_tag v0.7-3) # This tag should be updated every time it gets updated in foonathan_memory_vendor eProsima's package endif() list(APPEND _deps "fastrtps\;${_fastdds_version}") endif() @@ -117,7 +117,7 @@ endif() ############################################################################### set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT UAGENT_SUPERBUILD) - project(microxrcedds_agent VERSION "2.2.0" LANGUAGES C CXX) + project(microxrcedds_agent VERSION "2.4.1" LANGUAGES C CXX) else() project(uagent_superbuild NONE) include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 3acb1edac..0d4c86299 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -201,7 +201,7 @@ if(UAGENT_BUILD_TESTS) GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG - 2fe3bd994b3189899d93f1d5a881e725e046fdc2 + release-1.11.0 PREFIX ${PROJECT_BINARY_DIR}/googletest INSTALL_DIR diff --git a/include/uxr/agent/message/InputMessage.hpp b/include/uxr/agent/message/InputMessage.hpp index 73b5184d7..8533fdb90 100644 --- a/include/uxr/agent/message/InputMessage.hpp +++ b/include/uxr/agent/message/InputMessage.hpp @@ -38,7 +38,10 @@ class InputMessage deserializer_(fastbuffer_) { memcpy(buf_, buf, len); - deserialize(header_); + + // A valid XRCE message must have a valid header and at least 1 submessage + valid_xrce_message_ = deserialize(header_); + valid_xrce_message_ = valid_xrce_message_ && count_submessages() > 0; } uint8_t* get_buf() const { return buf_; } @@ -70,6 +73,8 @@ class InputMessage size_t count_submessages(); + bool is_valid_xrce_message() { return valid_xrce_message_; } + dds::xrce::SubmessageId get_submessage_id(); private: @@ -85,6 +90,7 @@ class InputMessage dds::xrce::SubmessageHeader subheader_; fastcdr::FastBuffer fastbuffer_; fastcdr::Cdr deserializer_; + bool valid_xrce_message_ = false; }; inline bool InputMessage::prepare_next_submessage() @@ -114,8 +120,15 @@ inline size_t InputMessage::count_submessages() local_deserializer.jump((4 - ((local_deserializer.getCurrentPosition() - local_deserializer.getBufferPointer()) & 3)) & 3); if (fastbuffer_.getBufferSize() > local_deserializer.getSerializedDataLength()) { - local_subheader.deserialize(local_deserializer); - count++; + try + { + local_subheader.deserialize(local_deserializer); + count++; + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + rv = false; + } } else { rv = false; } diff --git a/include/uxr/agent/middleware/Middleware.hpp b/include/uxr/agent/middleware/Middleware.hpp index b6e800250..d3b89786e 100644 --- a/include/uxr/agent/middleware/Middleware.hpp +++ b/include/uxr/agent/middleware/Middleware.hpp @@ -25,6 +25,9 @@ #include #include +#define UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF (255) +#define UXR_CLIENT_DOMAIN_ID_TO_OVERRIDE_WITH_ENV (255) + namespace eprosima { namespace uxr { @@ -296,7 +299,7 @@ class Middleware /********************************************************************************************************************** * Members. **********************************************************************************************************************/ -protected: +protected: bool intraprocess_enabled_; }; diff --git a/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp b/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp index a1ae2f497..e69519378 100644 --- a/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp +++ b/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp @@ -284,6 +284,9 @@ class FastDDSMiddleware : public Middleware std::shared_ptr& participant, const fastrtps::ReplierAttributes& attrs); + int16_t get_domain_id_from_env(); + + int16_t agent_domain_id_ = 0; std::unordered_map> participants_; std::unordered_map> topics_; std::unordered_map> publishers_; diff --git a/src/cpp/middleware/fast/FastMiddleware.cpp b/src/cpp/middleware/fast/FastMiddleware.cpp index d80ac4b7b..e8c4afd0a 100644 --- a/src/cpp/middleware/fast/FastMiddleware.cpp +++ b/src/cpp/middleware/fast/FastMiddleware.cpp @@ -49,7 +49,9 @@ bool FastMiddleware::create_participant_by_ref( fastrtps::ParticipantAttributes attrs; if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) { - attrs.domainId = uint32_t(domain_id); + if(domain_id != UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF) { + attrs.domainId = domain_id; + } fastrtps::Participant* impl = fastrtps::Domain::createParticipant(attrs, &listener_); if (nullptr != impl) { @@ -773,7 +775,9 @@ bool FastMiddleware::matched_participant_from_ref( fastrtps::ParticipantAttributes attrs; if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) { - attrs.domainId = uint32_t(domain_id); + if(domain_id != UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF) { + attrs.domainId = domain_id; + } rv = it->second->match(attrs); } } diff --git a/src/cpp/middleware/fastdds/FastDDSEntities.cpp b/src/cpp/middleware/fastdds/FastDDSEntities.cpp index 0de43aff0..b953f4856 100644 --- a/src/cpp/middleware/fastdds/FastDDSEntities.cpp +++ b/src/cpp/middleware/fastdds/FastDDSEntities.cpp @@ -427,7 +427,7 @@ bool FastDDSParticipant::match_from_ref( { fastdds::dds::DomainParticipantQos qos; set_qos_from_attributes(qos, attrs.rtps); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos().name() == qos.name()); } } return rv; @@ -444,7 +444,7 @@ bool FastDDSParticipant::match_from_xml( { fastdds::dds::DomainParticipantQos qos; set_qos_from_attributes(qos, attrs.rtps); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos().name() == qos.name()); } } return rv; @@ -458,7 +458,7 @@ bool FastDDSParticipant::match_from_bin( { fastdds::dds::DomainParticipantQos qos; set_qos_from_xrce_object(qos, participant_xrce); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos().name() == qos.name()); } return rv; } @@ -524,7 +524,7 @@ ReturnCode_t FastDDSParticipant::delete_publisher( return ret; } } - } + } } return ptr_->delete_publisher(publisher); @@ -567,7 +567,7 @@ ReturnCode_t FastDDSParticipant::delete_subscriber( return ret; } } - } + } } return ptr_->delete_subscriber(subscriber); @@ -1225,8 +1225,8 @@ bool FastDDSRequester::match(const fastrtps::RequesterAttributes& attrs) const fastdds::dds::SubscriberQos qos_subscriber; set_qos_from_attributes(qos_subscriber, attrs.subscriber); - return reply_topic_->match(attrs.publisher.topic) - && request_topic_->match(attrs.subscriber.topic) + return reply_topic_->match(attrs.subscriber.topic) + && request_topic_->match(attrs.publisher.topic) && publisher_ptr_->get_qos() == qos_publisher && subscriber_ptr_->get_qos() == qos_subscriber; } diff --git a/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp b/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp index 6e958b9f6..ab6259c09 100644 --- a/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp +++ b/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -51,6 +52,14 @@ FastDDSMiddleware::FastDDSMiddleware(bool intraprocess_enabled) , repliers_() , callback_factory_(callback_factory_.getInstance()) { + agent_domain_id_ = get_domain_id_from_env(); + if (agent_domain_id_) + { + UXR_AGENT_LOG_INFO( + UXR_DECORATE_GREEN("Micro XRCE-DDS Agent DOMAIN_ID read from env"), + "domain_id: {}", agent_domain_id_); + } + } /********************************************************************************************************************** @@ -62,7 +71,13 @@ bool FastDDSMiddleware::create_participant_by_ref( const std::string& ref) { bool rv = false; - std::shared_ptr participant(new FastDDSParticipant(domain_id)); + fastrtps::ParticipantAttributes attrs; + auto participant_domain_id = domain_id; + if(domain_id == UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF && XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) + { + participant_domain_id = static_cast(attrs.domainId); + } + std::shared_ptr participant(new FastDDSParticipant(participant_domain_id)); if (participant->create_by_ref(ref)) { auto emplace_res = participants_.emplace(participant_id, std::move(participant)); @@ -102,8 +117,17 @@ bool FastDDSMiddleware::create_participant_by_bin( uint16_t participant_id, const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) { + auto participant_domain_id = static_cast(participant_xrce.domain_id()); + if(participant_domain_id == UXR_CLIENT_DOMAIN_ID_TO_OVERRIDE_WITH_ENV){ + participant_domain_id = agent_domain_id_; + UXR_AGENT_LOG_WARN( + UXR_DECORATE_YELLOW("Overriding Micro XRCE-DDS Client DOMAIN_ID"), + "domain_id: {}", participant_domain_id + ); + } + bool rv = false; - std::shared_ptr participant(new FastDDSParticipant((int16_t) participant_xrce.domain_id())); + std::shared_ptr participant(new FastDDSParticipant(participant_domain_id)); if (participant->create_by_bin(participant_xrce)) { auto emplace_res = participants_.emplace(participant_id, std::move(participant)); @@ -568,6 +592,7 @@ bool FastDDSMiddleware::create_requester_by_bin( attrs.publisher.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; attrs.subscriber.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + attrs.subscriber.qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS; std::shared_ptr requester = create_requester(participant, attrs); if (nullptr == requester) @@ -699,6 +724,7 @@ bool FastDDSMiddleware::create_replier_by_bin( attrs.publisher.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; attrs.subscriber.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + attrs.subscriber.qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS; std::shared_ptr replier = create_replier(participant, attrs); if (nullptr == replier) @@ -984,7 +1010,13 @@ bool FastDDSMiddleware::matched_participant_from_ref( auto it = participants_.find(participant_id); if (participants_.end() != it) { - rv = (domain_id == it->second->domain_id()) && (it->second->match_from_ref(ref)); + fastrtps::ParticipantAttributes attrs; + auto participant_domain_id = domain_id; + if(domain_id == UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF && XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) + { + participant_domain_id = static_cast(attrs.domainId); + } + rv = (participant_domain_id== it->second->domain_id()) && (it->second->match_from_ref(ref)); } return rv; } @@ -1171,7 +1203,7 @@ bool FastDDSMiddleware::matched_requester_from_xml( auto it = requesters_.find(requester_id); if (requesters_.end() != it) { - rv = it->second->match_from_ref(xml); + rv = it->second->match_from_xml(xml); } return rv; } @@ -1210,7 +1242,7 @@ bool FastDDSMiddleware::matched_replier_from_xml( auto it = repliers_.find(requester_id); if (repliers_.end() != it) { - rv = it->second->match_from_ref(xml); + rv = it->second->match_from_xml(xml); } return rv; } @@ -1228,5 +1260,15 @@ bool FastDDSMiddleware::matched_replier_from_bin( return rv; } +int16_t FastDDSMiddleware::get_domain_id_from_env(){ + int16_t agent_domain_id = 0; + const char * agent_domain_id_env = std::getenv( "XRCE_DOMAIN_ID_OVERRIDE" ); + if (nullptr != agent_domain_id_env) + { + agent_domain_id = static_cast(std::atoi(agent_domain_id_env)); + } + return agent_domain_id; +} + } // namespace uxr } // namespace eprosima \ No newline at end of file diff --git a/src/cpp/replier/Replier.cpp b/src/cpp/replier/Replier.cpp index 69daecc63..c6010caa4 100644 --- a/src/cpp/replier/Replier.cpp +++ b/src/cpp/replier/Replier.cpp @@ -98,7 +98,7 @@ bool Replier::matched( } case dds::xrce::REPRESENTATION_AS_XML_STRING: { - const std::string& xml = new_object_rep.replier().representation().object_reference(); + const std::string& xml = new_object_rep.replier().representation().xml_string_representation(); rv = proxy_client_->get_middleware().matched_replier_from_xml(get_raw_id(), xml); break; } diff --git a/src/cpp/requester/Requester.cpp b/src/cpp/requester/Requester.cpp index 19b59ab1a..d747f0ed1 100644 --- a/src/cpp/requester/Requester.cpp +++ b/src/cpp/requester/Requester.cpp @@ -100,7 +100,7 @@ bool Requester::matched( } case dds::xrce::REPRESENTATION_AS_XML_STRING: { - const std::string& xml = new_object_rep.requester().representation().object_reference(); + const std::string& xml = new_object_rep.requester().representation().xml_string_representation(); rv = proxy_client_->get_middleware().matched_requester_from_xml(get_raw_id(), xml); break; } diff --git a/src/cpp/transport/Server.cpp b/src/cpp/transport/Server.cpp index b07b3c50e..f9b2a3149 100644 --- a/src/cpp/transport/Server.cpp +++ b/src/cpp/transport/Server.cpp @@ -192,7 +192,7 @@ void Server::receiver_loop() TransportRc transport_rc = TransportRc::ok; if (recv_message(input_packet, RECEIVE_TIMEOUT, transport_rc)) { - if(dds::xrce::HEARTBEAT == input_packet.message->get_submessage_id() && 1U == input_packet.message->count_submessages()){ + if(input_packet.message->is_valid_xrce_message() && 1U == input_packet.message->count_submessages() && dds::xrce::HEARTBEAT == input_packet.message->get_submessage_id()){ input_scheduler_.push(std::move(input_packet), 1); } else diff --git a/test/unittest/agent/AgentUnitTests.cpp b/test/unittest/agent/AgentUnitTests.cpp index 9c93e261f..a21dc632a 100644 --- a/test/unittest/agent/AgentUnitTests.cpp +++ b/test/unittest/agent/AgentUnitTests.cpp @@ -1077,7 +1077,13 @@ TEST_P(AgentUnitTests, RegisterCallbackFunctions) // TODO (pablogs): Add tests for binary entity creation -INSTANTIATE_TEST_CASE_P(AgentUnitTestsParams, +#ifdef INSTANTIATE_TEST_SUITE_P +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z) INSTANTIATE_TEST_SUITE_P(x, y, z) +#else +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z) INSTANTIATE_TEST_CASE_P(x, y, z) +#endif // ifdef INSTANTIATE_TEST_SUITE_P + +GTEST_INSTANTIATE_TEST_MACRO(AgentUnitTestsParams, AgentUnitTests, ::testing::Values(Middleware::Kind::FASTRTPS,Middleware::Kind::FASTDDS));