Skip to content

Commit

Permalink
Merge branch 'eProsima:master' into trail
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindraja93 authored Sep 1, 2023
2 parents 52155a7 + 40954c2 commit df51b1a
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 32 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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}")

Expand All @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions include/uxr/agent/message/InputMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion include/uxr/agent/middleware/Middleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <functional>
#include <chrono>

#define UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF (255)
#define UXR_CLIENT_DOMAIN_ID_TO_OVERRIDE_WITH_ENV (255)

namespace eprosima {
namespace uxr {

Expand Down Expand Up @@ -296,7 +299,7 @@ class Middleware
/**********************************************************************************************************************
* Members.
**********************************************************************************************************************/
protected:
protected:
bool intraprocess_enabled_;
};

Expand Down
3 changes: 3 additions & 0 deletions include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ class FastDDSMiddleware : public Middleware
std::shared_ptr<FastDDSParticipant>& participant,
const fastrtps::ReplierAttributes& attrs);

int16_t get_domain_id_from_env();

int16_t agent_domain_id_ = 0;
std::unordered_map<uint16_t, std::shared_ptr<FastDDSParticipant>> participants_;
std::unordered_map<uint16_t, std::shared_ptr<FastDDSTopic>> topics_;
std::unordered_map<uint16_t, std::shared_ptr<FastDDSPublisher>> publishers_;
Expand Down
8 changes: 6 additions & 2 deletions src/cpp/middleware/fast/FastMiddleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/cpp/middleware/fastdds/FastDDSEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -524,7 +524,7 @@ ReturnCode_t FastDDSParticipant::delete_publisher(
return ret;
}
}
}
}
}

return ptr_->delete_publisher(publisher);
Expand Down Expand Up @@ -567,7 +567,7 @@ ReturnCode_t FastDDSParticipant::delete_subscriber(
return ret;
}
}
}
}
}

return ptr_->delete_subscriber(subscriber);
Expand Down Expand Up @@ -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;
}
Expand Down
52 changes: 47 additions & 5 deletions src/cpp/middleware/fastdds/FastDDSMiddleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp>
#include <uxr/agent/utils/Conversion.hpp>
#include <uxr/agent/logger/Logger.hpp>

#include <fastrtps/xmlparser/XMLProfileManager.h>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
Expand Down Expand Up @@ -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_);
}

}

/**********************************************************************************************************************
Expand All @@ -62,7 +71,13 @@ bool FastDDSMiddleware::create_participant_by_ref(
const std::string& ref)
{
bool rv = false;
std::shared_ptr<FastDDSParticipant> 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<int16_t>(attrs.domainId);
}
std::shared_ptr<FastDDSParticipant> participant(new FastDDSParticipant(participant_domain_id));
if (participant->create_by_ref(ref))
{
auto emplace_res = participants_.emplace(participant_id, std::move(participant));
Expand Down Expand Up @@ -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<int16_t>(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<FastDDSParticipant> participant(new FastDDSParticipant((int16_t) participant_xrce.domain_id()));
std::shared_ptr<FastDDSParticipant> participant(new FastDDSParticipant(participant_domain_id));
if (participant->create_by_bin(participant_xrce))
{
auto emplace_res = participants_.emplace(participant_id, std::move(participant));
Expand Down Expand Up @@ -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<FastDDSRequester> requester = create_requester(participant, attrs);
if (nullptr == requester)
Expand Down Expand Up @@ -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<FastDDSReplier> replier = create_replier(participant, attrs);
if (nullptr == replier)
Expand Down Expand Up @@ -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<int16_t>(attrs.domainId);
}
rv = (participant_domain_id== it->second->domain_id()) && (it->second->match_from_ref(ref));
}
return rv;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<int16_t>(std::atoi(agent_domain_id_env));
}
return agent_domain_id;
}

} // namespace uxr
} // namespace eprosima
2 changes: 1 addition & 1 deletion src/cpp/replier/Replier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/requester/Requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/transport/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void Server<EndPoint>::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
Expand Down
8 changes: 7 additions & 1 deletion test/unittest/agent/AgentUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit df51b1a

Please sign in to comment.