Skip to content

[21913] DomainParticipant creation fails if SHM MaxMessageSize is lower than minimum #5473

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 29 additions & 2 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ static bool get_unique_flows_parameters(
return true;
}

/**
* @brief This method checks if the maximum message size is equal or higher than the PDP package size.
* @return true if the maximum message size is equal or higher than the PDP package size, false otherwise.
*/
static bool is_max_message_size_big_enough(
const uint32_t max_message_size)
{
constexpr uint32_t info_dst_message_length = 16;
constexpr uint32_t info_ts_message_length = 12;
uint32_t statistics_message_length = 0;
#ifdef FASTDDS_STATISTICS
statistics_message_length = eprosima::fastdds::statistics::rtps::statistics_submessage_length;
#endif // FASTDDS_STATISTICS

return max_message_size >=
(RTPSMESSAGE_HEADER_SIZE + BUILTIN_DATA_MAX_SIZE + info_dst_message_length +
info_ts_message_length + statistics_message_length);
}

Locator_t& RTPSParticipantImpl::applyLocatorAdaptRule(
Locator_t& loc)
{
Expand Down Expand Up @@ -480,6 +499,14 @@ bool RTPSParticipantImpl::setup_transports()
register_transport = false;
}
}
auto max_message_size = transportDescriptor->max_message_size();
if (!is_max_message_size_big_enough(max_message_size))
{
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT,
"User transport failed to register. Maximum message size needs to be equal or higher than "
"the PDP package size.");
register_transport = false;
}

bool transport_registered = register_transport && m_network_Factory.RegisterTransport(
transportDescriptor.get(), &m_att.properties, m_att.max_msg_size_no_frag);
Expand All @@ -495,12 +522,12 @@ bool RTPSParticipantImpl::setup_transports()
if (transport_registered)
{
has_shm_transport_ |=
(dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr);
(nullptr != dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get()));
}
else
{
// SHM transport could be disabled
if ((dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr))
if ((nullptr != dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get())))
{
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT,
"Unable to Register SHM Transport. SHM Transport is not supported in"
Expand Down
1 change: 1 addition & 0 deletions test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if(NOT QNX)
endif()
add_subdirectory(rtps/history)
add_subdirectory(rtps/network)
add_subdirectory(rtps/participant)
add_subdirectory(rtps/persistence)
add_subdirectory(rtps/reader)
add_subdirectory(rtps/resources/timedevent)
Expand Down
2 changes: 0 additions & 2 deletions test/unittest/rtps/history/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ target_link_libraries(TopicPayloadPoolTests
${CMAKE_DL_LIBS})
gtest_discover_tests(TopicPayloadPoolTests)



add_executable(WriterHistoryTests ${WRITERHISTORYTESTS_SOURCE})
target_compile_definitions(WriterHistoryTests PRIVATE
BOOST_ASIO_STANDALONE
Expand Down
30 changes: 30 additions & 0 deletions test/unittest/rtps/participant/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(PARTICIPANTTESTS_SOURCE ParticipantTests.cpp)

add_executable(RTPSParticipantTests ${PARTICIPANTTESTS_SOURCE})
target_compile_definitions(RTPSParticipantTests PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_link_libraries(RTPSParticipantTests fastcdr fastdds foonathan_memory
fastcdr
fastdds
foonathan_memory
GTest::gtest
${CMAKE_DL_LIBS})
gtest_discover_tests(RTPSParticipantTests)
62 changes: 62 additions & 0 deletions test/unittest/rtps/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include <fastdds/rtps/RTPSDomain.hpp>
#include <fastdds/rtps/participant/RTPSParticipant.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

using namespace testing;

RTPSParticipant* transport_size_participant_init(
uint32_t max_message_size)
{
uint32_t domain_id = 0;
std::string max_message_size_str = std::to_string(max_message_size);

RTPSParticipantAttributes p_attr;
BuiltinTransportsOptions options;
options.maxMessageSize = max_message_size;
p_attr.setup_transports(BuiltinTransports::SHM, options);
RTPSParticipant* participant = RTPSDomain::createParticipant(
domain_id, true, p_attr);

return participant;
}

/**
* This test checks that the participant is not created when the max message size is smaller than the PDP package size
* but it is properly created when the max message size is bigger than the PDP package size.
*/
TEST(RTPSParticipantTests, participant_creation_message_size)
{
ASSERT_EQ(transport_size_participant_init(100), nullptr);
ASSERT_NE(transport_size_participant_init(1000), nullptr);
}

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

int main(
int argc,
char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading