From c3330f96963c3e998deae8204310890ca3b07971 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 15:40:26 +0200 Subject: [PATCH 01/26] Refs #20972. Method socket_buffer_size in DDS_PIM helpers sets also sending buffer. Signed-off-by: Miguel Company --- test/blackbox/api/dds-pim/PubSubReader.hpp | 1 + test/blackbox/api/dds-pim/PubSubWriter.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/test/blackbox/api/dds-pim/PubSubReader.hpp b/test/blackbox/api/dds-pim/PubSubReader.hpp index 00df6c72cd0..b69cce7f7a9 100644 --- a/test/blackbox/api/dds-pim/PubSubReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubReader.hpp @@ -1313,6 +1313,7 @@ class PubSubReader uint32_t sockerBufferSize) { participant_qos_.transport().listen_socket_buffer_size = sockerBufferSize; + participant_qos_.transport().send_socket_buffer_size = sockerBufferSize; return *this; } diff --git a/test/blackbox/api/dds-pim/PubSubWriter.hpp b/test/blackbox/api/dds-pim/PubSubWriter.hpp index 9a9ad818fae..543190f3f6c 100644 --- a/test/blackbox/api/dds-pim/PubSubWriter.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriter.hpp @@ -1493,6 +1493,7 @@ class PubSubWriter uint32_t sockerBufferSize) { participant_qos_.transport().listen_socket_buffer_size = sockerBufferSize; + participant_qos_.transport().send_socket_buffer_size = sockerBufferSize; return *this; } From 98b43860c15b831422ac9445f79b6fbe1474dd09 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 15:42:08 +0200 Subject: [PATCH 02/26] Refs #20972. Improvements in on_sample_lost blackbox tests. Signed-off-by: Miguel Company --- .../common/DDSBlackboxTestsListeners.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/blackbox/common/DDSBlackboxTestsListeners.cpp b/test/blackbox/common/DDSBlackboxTestsListeners.cpp index 185e0965c0f..9fcba4cba3a 100644 --- a/test/blackbox/common/DDSBlackboxTestsListeners.cpp +++ b/test/blackbox/common/DDSBlackboxTestsListeners.cpp @@ -674,11 +674,22 @@ TEST_P(DDSStatus, DataAvailableConditions) subscriber_reader.wait_waitset_timeout(); } +// We want to ensure that samples are only lost due to the custom filter we have set in sample_lost_test_dw_init. +// Since we are going to send 300KB samples in the test for fragments, let's increase the buffer size to avoid any +// other possible loss. +static constexpr uint32_t SAMPLE_LOST_TEST_BUFFER_SIZE = + 300ul * 1024ul // sample size + * 13ul // number of samples + * 2ul; // 2x to avoid any possible loss + template void sample_lost_test_dw_init( PubSubWriter& writer) { auto testTransport = std::make_shared(); + testTransport->sendBufferSize = SAMPLE_LOST_TEST_BUFFER_SIZE; + testTransport->receiveBufferSize = SAMPLE_LOST_TEST_BUFFER_SIZE; + testTransport->drop_data_messages_filter_ = [](eprosima::fastrtps::rtps::CDRMessage_t& msg)-> bool { uint32_t old_pos = msg.pos; @@ -777,15 +788,8 @@ void sample_lost_test_init( PubSubWriter& writer, std::function functor) { - // We want to ensure that samples are only lost due to the custom filter we have set in sample_lost_test_dw_init. - // Since we are going to send 300KB samples in the test for fragments, let's increase the buffer size to avoid any - // other possible loss. - constexpr uint32_t BUFFER_SIZE = - 300ul * 1024ul // sample size - * 13ul // number of samples - * 2ul; // 2x to avoid any possible loss - reader.socket_buffer_size(BUFFER_SIZE); - writer.socket_buffer_size(BUFFER_SIZE); + reader.socket_buffer_size(SAMPLE_LOST_TEST_BUFFER_SIZE); + writer.socket_buffer_size(SAMPLE_LOST_TEST_BUFFER_SIZE); sample_lost_test_dw_init(writer); sample_lost_test_dr_init(reader, functor); From ead1b121b36cecf60ba72d66d6c2bc74c8ec51c3 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 11:32:26 +0200 Subject: [PATCH 03/26] Refs #20972. Move code into new private methods. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 62 +++++++++++-------- .../rtps/transport/UDPTransportInterface.h | 6 ++ 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index fa924ee0469..0fed654fbd8 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -117,42 +117,50 @@ bool UDPTransportInterface::DoInputLocatorsMatch( return IPLocator::getPhysicalPort(left) == IPLocator::getPhysicalPort(right); } -bool UDPTransportInterface::init( - const fastrtps::rtps::PropertyPolicy*, - const uint32_t& max_msg_size_no_frag) +void UDPTransportInterface::configure_send_buffer_size() { - if (configuration()->sendBufferSize == 0 || configuration()->receiveBufferSize == 0) + ip::udp::socket socket(io_service_); + socket.open(generate_protocol()); + + if (configuration()->sendBufferSize == 0) { - // Check system buffer sizes. - ip::udp::socket socket(io_service_); - socket.open(generate_protocol()); + socket_base::send_buffer_size option; + socket.get_option(option); + set_send_buffer_size(static_cast(option.value())); - if (configuration()->sendBufferSize == 0) + if (configuration()->sendBufferSize < s_minimumSocketBuffer) { - socket_base::send_buffer_size option; - socket.get_option(option); - set_send_buffer_size(static_cast(option.value())); - - if (configuration()->sendBufferSize < s_minimumSocketBuffer) - { - set_send_buffer_size(s_minimumSocketBuffer); - mSendBufferSize = s_minimumSocketBuffer; - } + set_send_buffer_size(s_minimumSocketBuffer); + mSendBufferSize = s_minimumSocketBuffer; } + } +} - if (configuration()->receiveBufferSize == 0) - { - socket_base::receive_buffer_size option; - socket.get_option(option); - set_receive_buffer_size(static_cast(option.value())); +void UDPTransportInterface::configure_receive_buffer_size() +{ + ip::udp::socket socket(io_service_); + socket.open(generate_protocol()); - if (configuration()->receiveBufferSize < s_minimumSocketBuffer) - { - set_receive_buffer_size(s_minimumSocketBuffer); - mReceiveBufferSize = s_minimumSocketBuffer; - } + if (configuration()->receiveBufferSize == 0) + { + socket_base::receive_buffer_size option; + socket.get_option(option); + set_receive_buffer_size(static_cast(option.value())); + + if (configuration()->receiveBufferSize < s_minimumSocketBuffer) + { + set_receive_buffer_size(s_minimumSocketBuffer); + mReceiveBufferSize = s_minimumSocketBuffer; } } +} + +bool UDPTransportInterface::init( + const fastrtps::rtps::PropertyPolicy*, + const uint32_t& max_msg_size_no_frag) +{ + configure_send_buffer_size(); + configure_receive_buffer_size(); uint32_t maximumMessageSize = max_msg_size_no_frag == 0 ? s_maximumMessageSize : max_msg_size_no_frag; diff --git a/src/cpp/rtps/transport/UDPTransportInterface.h b/src/cpp/rtps/transport/UDPTransportInterface.h index 0f69318e74e..3e3d57ab8af 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.h +++ b/src/cpp/rtps/transport/UDPTransportInterface.h @@ -305,6 +305,12 @@ class UDPTransportInterface : public TransportInterface bool return_loopback = false); std::atomic_bool rescan_interfaces_ = {true}; + +private: + + void configure_send_buffer_size(); + void configure_receive_buffer_size(); + }; } // namespace rtps From 0286875e3f638e96cfa7f6b0306970ea8437503d Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 12:01:18 +0200 Subject: [PATCH 04/26] Refs #20972. Refactor on configure_send_buffer_size. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 0fed654fbd8..b298e9c257c 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -119,21 +119,56 @@ bool UDPTransportInterface::DoInputLocatorsMatch( void UDPTransportInterface::configure_send_buffer_size() { + asio::error_code ec; ip::udp::socket socket(io_service_); - socket.open(generate_protocol()); + socket.open(generate_protocol(), ec); + if (!!ec) + { + EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "Error creating socket: " << ec.message()); + return; + } - if (configuration()->sendBufferSize == 0) + // If sendBufferSize is 0, try using the system default value + uint32_t send_buffer_size = configuration()->sendBufferSize; + uint32_t initial_value = send_buffer_size; + if (send_buffer_size == 0) { socket_base::send_buffer_size option; - socket.get_option(option); - set_send_buffer_size(static_cast(option.value())); + socket.get_option(option, ec); + if (!ec) + { + send_buffer_size = static_cast(option.value()); + } + } - if (configuration()->sendBufferSize < s_minimumSocketBuffer) + // Ensure the minimum value is used + if (send_buffer_size < s_minimumSocketBuffer) + { + send_buffer_size = s_minimumSocketBuffer; + set_send_buffer_size(send_buffer_size); + } + + // Try to set the highest possible value the system allows + for (; send_buffer_size >= s_minimumSocketBuffer; send_buffer_size /= 2) + { + socket_base::send_buffer_size option(static_cast(send_buffer_size)); + socket.set_option(option, ec); + if (!ec) { - set_send_buffer_size(s_minimumSocketBuffer); - mSendBufferSize = s_minimumSocketBuffer; + set_send_buffer_size(send_buffer_size); + break; } } + + // Keep final configuration value + mSendBufferSize = configuration()->sendBufferSize; + + // Inform the user if the desired value could not be set + if (initial_value != 0 && mSendBufferSize != initial_value) + { + EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport sendBufferSize could not be set to the desired value. " + << "Using " << mSendBufferSize << " instead of " << initial_value); + } } void UDPTransportInterface::configure_receive_buffer_size() From b49b916b0a96a79ebe7e7d82faf89877e4115f76 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 13:47:38 +0200 Subject: [PATCH 05/26] Refs #20972. Refactor on configure_receive_buffer_size. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index b298e9c257c..03d4eaffd0c 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -173,21 +173,56 @@ void UDPTransportInterface::configure_send_buffer_size() void UDPTransportInterface::configure_receive_buffer_size() { + asio::error_code ec; ip::udp::socket socket(io_service_); - socket.open(generate_protocol()); + socket.open(generate_protocol(), ec); + if (!!ec) + { + EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "Error creating socket: " << ec.message()); + return; + } - if (configuration()->receiveBufferSize == 0) + // If receiveBufferSize is 0, try using the system default value + uint32_t receive_buffer_size = configuration()->receiveBufferSize; + uint32_t initial_value = receive_buffer_size; + if (receive_buffer_size == 0) { socket_base::receive_buffer_size option; - socket.get_option(option); - set_receive_buffer_size(static_cast(option.value())); + socket.get_option(option, ec); + if (!ec) + { + receive_buffer_size = static_cast(option.value()); + } + } - if (configuration()->receiveBufferSize < s_minimumSocketBuffer) + // Ensure the minimum value is used + if (receive_buffer_size < s_minimumSocketBuffer) + { + receive_buffer_size = s_minimumSocketBuffer; + set_receive_buffer_size(receive_buffer_size); + } + + // Try to set the highest possible value the system allows + for (; receive_buffer_size >= s_minimumSocketBuffer; receive_buffer_size /= 2) + { + socket_base::receive_buffer_size option(static_cast(receive_buffer_size)); + socket.set_option(option, ec); + if (!ec) { - set_receive_buffer_size(s_minimumSocketBuffer); - mReceiveBufferSize = s_minimumSocketBuffer; + set_receive_buffer_size(receive_buffer_size); + break; } } + + // Keep final configuration value + mReceiveBufferSize = configuration()->receiveBufferSize; + + // Inform the user if the desired value could not be set + if (initial_value != 0 && mReceiveBufferSize != initial_value) + { + EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport receiveBufferSize could not be set to the desired value. " + << "Using " << mReceiveBufferSize << " instead of " << initial_value); + } } bool UDPTransportInterface::init( From 7648c69e511f2430d606923b03c2911e4ba674cc Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 15:19:38 +0200 Subject: [PATCH 06/26] Refs #20972. Check user configuration at the beginning of init method. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/UDPTransportInterface.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 03d4eaffd0c..4d3f0033870 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -229,30 +229,32 @@ bool UDPTransportInterface::init( const fastrtps::rtps::PropertyPolicy*, const uint32_t& max_msg_size_no_frag) { - configure_send_buffer_size(); - configure_receive_buffer_size(); - uint32_t maximumMessageSize = max_msg_size_no_frag == 0 ? s_maximumMessageSize : max_msg_size_no_frag; + uint32_t cfg_max_msg_size = configuration()->maxMessageSize; + uint32_t cfg_send_size = configuration()->sendBufferSize; + uint32_t cfg_recv_size = configuration()->receiveBufferSize; - if (configuration()->maxMessageSize > maximumMessageSize) + if (cfg_max_msg_size > maximumMessageSize) { EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "maxMessageSize cannot be greater than " << std::to_string(maximumMessageSize)); return false; } - - if (configuration()->maxMessageSize > configuration()->sendBufferSize) + if ((cfg_send_size > 0) && (cfg_max_msg_size > cfg_send_size)) { EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "maxMessageSize cannot be greater than send_buffer_size"); return false; } - if (configuration()->maxMessageSize > configuration()->receiveBufferSize) + if ((cfg_recv_size > 0) && (cfg_max_msg_size > cfg_recv_size)) { EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "maxMessageSize cannot be greater than receive_buffer_size"); return false; } + configure_send_buffer_size(); + configure_receive_buffer_size(); + return true; } From f87a2cb137bfc9bb379f9e4faea47d42e33e4743 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 15:26:31 +0200 Subject: [PATCH 07/26] Refs #20972. Use maxMessageSize as minimum possible value. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/UDPTransportInterface.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 4d3f0033870..95fd8a9f8b9 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -142,14 +142,15 @@ void UDPTransportInterface::configure_send_buffer_size() } // Ensure the minimum value is used - if (send_buffer_size < s_minimumSocketBuffer) + uint32_t minimum_socket_buffer = configuration()->maxMessageSize; + if (send_buffer_size < minimum_socket_buffer) { - send_buffer_size = s_minimumSocketBuffer; + send_buffer_size = minimum_socket_buffer; set_send_buffer_size(send_buffer_size); } // Try to set the highest possible value the system allows - for (; send_buffer_size >= s_minimumSocketBuffer; send_buffer_size /= 2) + for (; send_buffer_size >= minimum_socket_buffer; send_buffer_size /= 2) { socket_base::send_buffer_size option(static_cast(send_buffer_size)); socket.set_option(option, ec); @@ -196,14 +197,15 @@ void UDPTransportInterface::configure_receive_buffer_size() } // Ensure the minimum value is used - if (receive_buffer_size < s_minimumSocketBuffer) + uint32_t minimum_socket_buffer = configuration()->maxMessageSize; + if (receive_buffer_size < minimum_socket_buffer) { - receive_buffer_size = s_minimumSocketBuffer; + receive_buffer_size = minimum_socket_buffer; set_receive_buffer_size(receive_buffer_size); } // Try to set the highest possible value the system allows - for (; receive_buffer_size >= s_minimumSocketBuffer; receive_buffer_size /= 2) + for (; receive_buffer_size >= minimum_socket_buffer; receive_buffer_size /= 2) { socket_base::receive_buffer_size option(static_cast(receive_buffer_size)); socket.set_option(option, ec); From 7862ca5d658633e62d897ad412a9fa6f1f86ba3f Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 8 May 2024 16:13:52 +0200 Subject: [PATCH 08/26] Refs #20972. Applying changes on OpenAndBindUnicastOutputSocket. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 95fd8a9f8b9..91c357fa11c 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -117,6 +117,35 @@ bool UDPTransportInterface::DoInputLocatorsMatch( return IPLocator::getPhysicalPort(left) == IPLocator::getPhysicalPort(right); } +/** + * @brief Set the send buffer size of the socket to the highest possible value the system allows. + * + * @param socket The socket on which to set the send buffer size. + * @param initial_buffer_value The initial value to try to set. + * @param minimum_buffer_value The minimum value to set. + * + * @return The final value set. + */ +static uint32_t try_setting_send_buffer_size( + asio::ip::udp::socket& socket, + uint32_t initial_buffer_value, + uint32_t minimum_buffer_value) +{ + // Try to set the highest possible value the system allows + for (auto send_size = initial_buffer_value; send_size >= minimum_buffer_value; send_size /= 2) + { + asio::error_code ec; + socket_base::send_buffer_size option(static_cast(send_size)); + socket.set_option(option, ec); + if (!ec) + { + return send_size; + } + } + + return minimum_buffer_value; +} + void UDPTransportInterface::configure_send_buffer_size() { asio::error_code ec; @@ -146,23 +175,14 @@ void UDPTransportInterface::configure_send_buffer_size() if (send_buffer_size < minimum_socket_buffer) { send_buffer_size = minimum_socket_buffer; - set_send_buffer_size(send_buffer_size); } // Try to set the highest possible value the system allows - for (; send_buffer_size >= minimum_socket_buffer; send_buffer_size /= 2) - { - socket_base::send_buffer_size option(static_cast(send_buffer_size)); - socket.set_option(option, ec); - if (!ec) - { - set_send_buffer_size(send_buffer_size); - break; - } - } + send_buffer_size = try_setting_send_buffer_size(socket, send_buffer_size, minimum_socket_buffer); + set_send_buffer_size(send_buffer_size); // Keep final configuration value - mSendBufferSize = configuration()->sendBufferSize; + mSendBufferSize = send_buffer_size; // Inform the user if the desired value could not be set if (initial_value != 0 && mSendBufferSize != initial_value) @@ -327,7 +347,13 @@ eProsimaUDPSocket UDPTransportInterface::OpenAndBindUnicastOutputSocket( getSocketPtr(socket)->open(generate_protocol()); if (mSendBufferSize != 0) { - getSocketPtr(socket)->set_option(socket_base::send_buffer_size(static_cast(mSendBufferSize))); + uint32_t configured_value; + configured_value = try_setting_send_buffer_size(socket, mSendBufferSize, configuration()->maxMessageSize); + if (configured_value != mSendBufferSize) + { + EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport sendBufferSize could not be set to the desired value. " + << "Using " << configured_value << " instead of " << mSendBufferSize); + } } getSocketPtr(socket)->set_option(ip::multicast::hops(configuration()->TTL)); getSocketPtr(socket)->bind(endpoint); From d0e9cab341b3233a82aae6c33487849f532acea9 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 11:47:51 +0200 Subject: [PATCH 09/26] Refs #20972. Add helper header with template method. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/asio_helpers.hpp | 77 +++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/cpp/rtps/transport/asio_helpers.hpp diff --git a/src/cpp/rtps/transport/asio_helpers.hpp b/src/cpp/rtps/transport/asio_helpers.hpp new file mode 100644 index 00000000000..0b6848c6150 --- /dev/null +++ b/src/cpp/rtps/transport/asio_helpers.hpp @@ -0,0 +1,77 @@ +// Copyright 2024 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. + +#ifndef RTPS_TRANSPORT__ASIO_HELPERS_HPP_ +#define RTPS_TRANSPORT__ASIO_HELPERS_HPP_ + +#include + +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/// Helper functions for asio. +// NOTE: using a struct instead of a namespace to avoid linker errors when using inline free functions. +struct asio_helpers +{ + /** + * @brief Try to set a buffer size on a socket, trying to set the initial value and then halving it until it is + * possible to set it or the minimum value is reached. + * + * @tparam BufferOptionType Type of the buffer option to set. + * @tparam SocketType Type of socket on which to set the buffer size option. + * + * @param socket Socket on which to set the buffer size option. + * @param initial_buffer_value Initial value to try to set. + * @param minimum_buffer_value Minimum value to set. + * @param final_buffer_value Output parameter where the final value set will be stored. + * + * @return true if the buffer size was successfully set, false otherwise. + */ + template + static inline bool try_setting_buffer_size( + SocketType& socket, + const uint32_t initial_buffer_value, + const uint32_t minimum_buffer_value, + uint32_t& final_buffer_value) + { + asio::error_code ec; + + final_buffer_value = initial_buffer_value; + while (final_buffer_value >= minimum_buffer_value) + { + socket.set_option(BufferOptionType(static_cast(final_buffer_value)), ec); + if (!ec) + { + return true; + } + + final_buffer_value /= 2; + } + + final_buffer_value = minimum_buffer_value; + socket.set_option(BufferOptionType(final_buffer_value), ec); + return !ec; + } + +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // RTPS_TRANSPORT__ASIO_HELPERS_HPP_ + From 72ba395e757fb65d6fd7e315fa3d4dbd8400f204 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 12:00:49 +0200 Subject: [PATCH 10/26] Refs #20972. Configure methods return boolean. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 17 +++++++++-------- src/cpp/rtps/transport/UDPTransportInterface.h | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 91c357fa11c..e0571cb5a1a 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -146,7 +146,7 @@ static uint32_t try_setting_send_buffer_size( return minimum_buffer_value; } -void UDPTransportInterface::configure_send_buffer_size() +bool UDPTransportInterface::configure_send_buffer_size() { asio::error_code ec; ip::udp::socket socket(io_service_); @@ -154,7 +154,7 @@ void UDPTransportInterface::configure_send_buffer_size() if (!!ec) { EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "Error creating socket: " << ec.message()); - return; + return false; } // If sendBufferSize is 0, try using the system default value @@ -190,9 +190,11 @@ void UDPTransportInterface::configure_send_buffer_size() EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport sendBufferSize could not be set to the desired value. " << "Using " << mSendBufferSize << " instead of " << initial_value); } + + return true; } -void UDPTransportInterface::configure_receive_buffer_size() +bool UDPTransportInterface::configure_receive_buffer_size() { asio::error_code ec; ip::udp::socket socket(io_service_); @@ -200,7 +202,7 @@ void UDPTransportInterface::configure_receive_buffer_size() if (!!ec) { EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "Error creating socket: " << ec.message()); - return; + return false; } // If receiveBufferSize is 0, try using the system default value @@ -245,6 +247,8 @@ void UDPTransportInterface::configure_receive_buffer_size() EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport receiveBufferSize could not be set to the desired value. " << "Using " << mReceiveBufferSize << " instead of " << initial_value); } + + return true; } bool UDPTransportInterface::init( @@ -274,10 +278,7 @@ bool UDPTransportInterface::init( return false; } - configure_send_buffer_size(); - configure_receive_buffer_size(); - - return true; + return configure_send_buffer_size() && configure_receive_buffer_size(); } bool UDPTransportInterface::IsInputChannelOpen( diff --git a/src/cpp/rtps/transport/UDPTransportInterface.h b/src/cpp/rtps/transport/UDPTransportInterface.h index 3e3d57ab8af..3dbb30e6418 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.h +++ b/src/cpp/rtps/transport/UDPTransportInterface.h @@ -308,8 +308,8 @@ class UDPTransportInterface : public TransportInterface private: - void configure_send_buffer_size(); - void configure_receive_buffer_size(); + bool configure_send_buffer_size(); + bool configure_receive_buffer_size(); }; From 32e18917d74b693a7e79e72e2103594cc6500415 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 12:42:13 +0200 Subject: [PATCH 11/26] Refs #20972. Configure methods use new template method. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index e0571cb5a1a..088b05309bd 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -23,6 +23,8 @@ #include #include #include + +#include #include #include @@ -178,10 +180,16 @@ bool UDPTransportInterface::configure_send_buffer_size() } // Try to set the highest possible value the system allows - send_buffer_size = try_setting_send_buffer_size(socket, send_buffer_size, minimum_socket_buffer); - set_send_buffer_size(send_buffer_size); + if (!asio_helpers::try_setting_buffer_size( + socket, send_buffer_size, minimum_socket_buffer, send_buffer_size)) + { + EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, + "Couldn't set send buffer size to minimum value: " << minimum_socket_buffer); + return false; + } // Keep final configuration value + set_send_buffer_size(send_buffer_size); mSendBufferSize = send_buffer_size; // Inform the user if the desired value could not be set @@ -227,19 +235,17 @@ bool UDPTransportInterface::configure_receive_buffer_size() } // Try to set the highest possible value the system allows - for (; receive_buffer_size >= minimum_socket_buffer; receive_buffer_size /= 2) + if (!asio_helpers::try_setting_buffer_size( + socket, receive_buffer_size, minimum_socket_buffer, receive_buffer_size)) { - socket_base::receive_buffer_size option(static_cast(receive_buffer_size)); - socket.set_option(option, ec); - if (!ec) - { - set_receive_buffer_size(receive_buffer_size); - break; - } + EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, + "Couldn't set receive buffer size to minimum value: " << minimum_socket_buffer); + return false; } // Keep final configuration value - mReceiveBufferSize = configuration()->receiveBufferSize; + set_receive_buffer_size(receive_buffer_size); + mReceiveBufferSize = receive_buffer_size; // Inform the user if the desired value could not be set if (initial_value != 0 && mReceiveBufferSize != initial_value) From ebd62f277576f8dd9d475de0db559933992a501e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 14:57:16 +0200 Subject: [PATCH 12/26] Refs #20972. OpenAndBindUnicastOutputSocket uses new template method. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 088b05309bd..bfb47d16f86 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -119,35 +119,6 @@ bool UDPTransportInterface::DoInputLocatorsMatch( return IPLocator::getPhysicalPort(left) == IPLocator::getPhysicalPort(right); } -/** - * @brief Set the send buffer size of the socket to the highest possible value the system allows. - * - * @param socket The socket on which to set the send buffer size. - * @param initial_buffer_value The initial value to try to set. - * @param minimum_buffer_value The minimum value to set. - * - * @return The final value set. - */ -static uint32_t try_setting_send_buffer_size( - asio::ip::udp::socket& socket, - uint32_t initial_buffer_value, - uint32_t minimum_buffer_value) -{ - // Try to set the highest possible value the system allows - for (auto send_size = initial_buffer_value; send_size >= minimum_buffer_value; send_size /= 2) - { - asio::error_code ec; - socket_base::send_buffer_size option(static_cast(send_size)); - socket.set_option(option, ec); - if (!ec) - { - return send_size; - } - } - - return minimum_buffer_value; -} - bool UDPTransportInterface::configure_send_buffer_size() { asio::error_code ec; @@ -354,9 +325,14 @@ eProsimaUDPSocket UDPTransportInterface::OpenAndBindUnicastOutputSocket( getSocketPtr(socket)->open(generate_protocol()); if (mSendBufferSize != 0) { - uint32_t configured_value; - configured_value = try_setting_send_buffer_size(socket, mSendBufferSize, configuration()->maxMessageSize); - if (configured_value != mSendBufferSize) + uint32_t configured_value = 0; + if (!asio_helpers::try_setting_buffer_size( + socket, mSendBufferSize, configuration()->maxMessageSize, configured_value)) + { + EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, + "Couldn't set send buffer size to minimum value: " << configuration()->maxMessageSize); + } + else if (configured_value != mSendBufferSize) { EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport sendBufferSize could not be set to the desired value. " << "Using " << configured_value << " instead of " << mSendBufferSize); From ea9ce1f73ce26ae1af1849076f750a53aa01d82f Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 15:08:19 +0200 Subject: [PATCH 13/26] Refs #20972. Changes in OpenAndBindInputSocket. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/UDPv4Transport.cpp | 16 +++++++++++++++- src/cpp/rtps/transport/UDPv6Transport.cpp | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/cpp/rtps/transport/UDPv4Transport.cpp b/src/cpp/rtps/transport/UDPv4Transport.cpp index 5ade2ae6f43..b2ebb3c3f84 100644 --- a/src/cpp/rtps/transport/UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/UDPv4Transport.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -395,7 +396,20 @@ eProsimaUDPSocket UDPv4Transport::OpenAndBindInputSocket( getSocketPtr(socket)->open(generate_protocol()); if (mReceiveBufferSize != 0) { - getSocketPtr(socket)->set_option(socket_base::receive_buffer_size(mReceiveBufferSize)); + uint32_t configured_value = 0; + uint32_t minimum_value = configuration()->maxMessageSize; + if (!asio_helpers::try_setting_buffer_size( + socket, mReceiveBufferSize, minimum_value, configured_value)) + { + EPROSIMA_LOG_ERROR(TRANSPORT_UDPV4, + "Couldn't set receive buffer size to minimum value: " << minimum_value); + } + else if (mReceiveBufferSize != configured_value) + { + EPROSIMA_LOG_WARNING(TRANSPORT_UDPV4, + "Receive buffer size could not be set to the desired value. " + << "Using " << configured_value << " instead of " << mReceiveBufferSize); + } } if (is_multicast) diff --git a/src/cpp/rtps/transport/UDPv6Transport.cpp b/src/cpp/rtps/transport/UDPv6Transport.cpp index 935944a4f13..2af84773c66 100644 --- a/src/cpp/rtps/transport/UDPv6Transport.cpp +++ b/src/cpp/rtps/transport/UDPv6Transport.cpp @@ -25,6 +25,7 @@ #include #include +#include #include using namespace std; @@ -397,7 +398,20 @@ eProsimaUDPSocket UDPv6Transport::OpenAndBindInputSocket( getSocketPtr(socket)->open(generate_protocol()); if (mReceiveBufferSize != 0) { - getSocketPtr(socket)->set_option(socket_base::receive_buffer_size(mReceiveBufferSize)); + uint32_t configured_value = 0; + uint32_t minimum_value = configuration()->maxMessageSize; + if (!asio_helpers::asio_helpers::try_setting_buffer_size( + socket, mReceiveBufferSize, minimum_value, configured_value)) + { + EPROSIMA_LOG_ERROR(TRANSPORT_UDPV6, + "Couldn't set receive buffer size to minimum value: " << minimum_value); + } + else if (mReceiveBufferSize != configured_value) + { + EPROSIMA_LOG_WARNING(TRANSPORT_UDPV6, + "Receive buffer size could not be set to the desired value. " + << "Using " << configured_value << " instead of " << mReceiveBufferSize); + } } if (is_multicast) From 930a24305f9d82f10fdd99d16ffd2617529d2f5f Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 15:37:39 +0200 Subject: [PATCH 14/26] Refs #20972.Setting options on TCP channels. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/TCPChannelResource.cpp | 48 +++++++++++++++++++ src/cpp/rtps/transport/TCPChannelResource.h | 4 ++ .../transport/TCPChannelResourceBasic.cpp | 4 +- .../transport/TCPChannelResourceSecure.cpp | 4 +- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/cpp/rtps/transport/TCPChannelResource.cpp b/src/cpp/rtps/transport/TCPChannelResource.cpp index ea36dfa42ac..4f37eb72dfb 100644 --- a/src/cpp/rtps/transport/TCPChannelResource.cpp +++ b/src/cpp/rtps/transport/TCPChannelResource.cpp @@ -18,6 +18,8 @@ #include #include + +#include #include namespace eprosima { @@ -370,6 +372,52 @@ bool TCPChannelResource::check_socket_send_buffer( return true; } +void TCPChannelResource::set_socket_options( + asio::basic_socket& socket, + const TCPTransportDescriptor* options) +{ + uint32_t minimum_value = options->maxMessageSize; + + // Set the send buffer size + { + uint32_t desired_value = options->sendBufferSize; + uint32_t configured_value = 0; + if (!asio_helpers::try_setting_buffer_size( + socket, desired_value, minimum_value, configured_value)) + { + EPROSIMA_LOG_ERROR(TCP_TRANSPORT, + "Couldn't set send buffer size to minimum value: " << minimum_value); + } + else if (desired_value != configured_value) + { + EPROSIMA_LOG_WARNING(TCP_TRANSPORT, + "Couldn't set send buffer size to desired value. " + << "Using " << configured_value << " instead of " << desired_value); + } + } + + // Set the receive buffer size + { + uint32_t desired_value = options->receiveBufferSize; + uint32_t configured_value = 0; + if (!asio_helpers::try_setting_buffer_size( + socket, desired_value, minimum_value, configured_value)) + { + EPROSIMA_LOG_ERROR(TCP_TRANSPORT, + "Couldn't set receive buffer size to minimum value: " << minimum_value); + } + else if (desired_value != configured_value) + { + EPROSIMA_LOG_WARNING(TCP_TRANSPORT, + "Couldn't set receive buffer size to desired value. " + << "Using " << configured_value << " instead of " << desired_value); + } + } + + // Set the TCP_NODELAY option + socket.set_option(asio::ip::tcp::no_delay(options->enable_tcp_nodelay)); +} + } // namespace rtps } // namespace fastdds } // namespace eprosima diff --git a/src/cpp/rtps/transport/TCPChannelResource.h b/src/cpp/rtps/transport/TCPChannelResource.h index c0a9e97f7bb..d625ac5c949 100644 --- a/src/cpp/rtps/transport/TCPChannelResource.h +++ b/src/cpp/rtps/transport/TCPChannelResource.h @@ -234,6 +234,10 @@ class TCPChannelResource : public ChannelResource const size_t& msg_size, const asio::ip::tcp::socket::native_handle_type& socket_native_handle); + static void set_socket_options( + asio::basic_socket& socket, + const TCPTransportDescriptor* options); + TCPConnectionType tcp_connection_type_; friend class TCPTransportInterface; diff --git a/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp b/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp index 2efc8873e82..879bdb23718 100644 --- a/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp +++ b/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp @@ -200,9 +200,7 @@ asio::ip::tcp::endpoint TCPChannelResourceBasic::local_endpoint( void TCPChannelResourceBasic::set_options( const TCPTransportDescriptor* options) { - socket_->set_option(socket_base::receive_buffer_size(options->receiveBufferSize)); - socket_->set_option(socket_base::send_buffer_size(options->sendBufferSize)); - socket_->set_option(ip::tcp::no_delay(options->enable_tcp_nodelay)); + TCPChannelResource::set_socket_options(*socket_, options); } void TCPChannelResourceBasic::cancel() diff --git a/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp b/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp index 79e2391a732..0ac617a6774 100644 --- a/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp +++ b/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp @@ -280,9 +280,7 @@ asio::ip::tcp::endpoint TCPChannelResourceSecure::local_endpoint( void TCPChannelResourceSecure::set_options( const TCPTransportDescriptor* options) { - secure_socket_->lowest_layer().set_option(socket_base::receive_buffer_size(options->receiveBufferSize)); - secure_socket_->lowest_layer().set_option(socket_base::send_buffer_size(options->sendBufferSize)); - secure_socket_->lowest_layer().set_option(ip::tcp::no_delay(options->enable_tcp_nodelay)); + TCPChannelResource::set_socket_options(secure_socket_->lowest_layer(), options); } void TCPChannelResourceSecure::set_tls_verify_mode( From 07aa0c69cc8ad0cf96793725c7836061f0a57a8e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 16:09:00 +0200 Subject: [PATCH 15/26] Refs #20972. Doxygen. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/TCPChannelResource.h | 6 ++++++ src/cpp/rtps/transport/UDPTransportInterface.h | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/cpp/rtps/transport/TCPChannelResource.h b/src/cpp/rtps/transport/TCPChannelResource.h index d625ac5c949..589ae6221e7 100644 --- a/src/cpp/rtps/transport/TCPChannelResource.h +++ b/src/cpp/rtps/transport/TCPChannelResource.h @@ -234,6 +234,12 @@ class TCPChannelResource : public ChannelResource const size_t& msg_size, const asio::ip::tcp::socket::native_handle_type& socket_native_handle); + /** + * @brief Set descriptor options on a socket. + * + * @param socket Socket on which to set the options. + * @param options Descriptor with the options to set. + */ static void set_socket_options( asio::basic_socket& socket, const TCPTransportDescriptor* options); diff --git a/src/cpp/rtps/transport/UDPTransportInterface.h b/src/cpp/rtps/transport/UDPTransportInterface.h index 3dbb30e6418..ca8af5b722b 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.h +++ b/src/cpp/rtps/transport/UDPTransportInterface.h @@ -308,7 +308,16 @@ class UDPTransportInterface : public TransportInterface private: + /** + * @brief Prepare transport configuration regarding send buffer size. + * @return true if a send buffer size greater than max message size could be set, false otherwise. + */ bool configure_send_buffer_size(); + + /** + * @brief Prepare transport configuration regarding receive buffer size. + * @return true if a receive buffer size greater than max message size could be set, false otherwise. + */ bool configure_receive_buffer_size(); }; From 4f567780fc37a589949c466399add679c66849ba Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 16:27:33 +0200 Subject: [PATCH 16/26] Refs #20972. Check limits of configured sizes. Signed-off-by: Miguel Company --- .../rtps/transport/TCPTransportInterface.cpp | 32 ++++++--- .../rtps/transport/UDPTransportInterface.cpp | 66 +++++++++++-------- 2 files changed, 64 insertions(+), 34 deletions(-) diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 5ca68274cc6..cd6e9ad5bea 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -18,10 +18,11 @@ #include #include #include +#include #include -#include #include #include +#include #include #include #include @@ -485,23 +486,38 @@ bool TCPTransportInterface::init( } uint32_t maximumMessageSize = max_msg_size_no_frag == 0 ? s_maximumMessageSize : max_msg_size_no_frag; + uint32_t cfg_max_msg_size = configuration()->maxMessageSize; + uint32_t cfg_send_size = configuration()->sendBufferSize; + uint32_t cfg_recv_size = configuration()->receiveBufferSize; + uint32_t max_int_value = static_cast(std::numeric_limits::max()); + + if (cfg_max_msg_size > maximumMessageSize) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than " << maximumMessageSize); + return false; + } + + if (cfg_send_size > max_int_value) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "sendBufferSize cannot be greater than " << max_int_value); + return false; + } - if (configuration()->maxMessageSize > maximumMessageSize) + if (cfg_recv_size > max_int_value) { - EPROSIMA_LOG_ERROR(RTCP_MSG_OUT, - "maxMessageSize cannot be greater than " << std::to_string(maximumMessageSize)); + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "receiveBufferSize cannot be greater than " << max_int_value); return false; } - if (configuration()->maxMessageSize > configuration()->sendBufferSize) + if (cfg_max_msg_size > cfg_send_size) { - EPROSIMA_LOG_ERROR(RTCP_MSG_OUT, "maxMessageSize cannot be greater than send_buffer_size"); + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than sendBufferSize"); return false; } - if (configuration()->maxMessageSize > configuration()->receiveBufferSize) + if (cfg_max_msg_size > cfg_recv_size) { - EPROSIMA_LOG_ERROR(RTCP_MSG_OUT, "maxMessageSize cannot be greater than receive_buffer_size"); + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than receiveBufferSize"); return false; } diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index bfb47d16f86..142445d3d82 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -14,14 +14,15 @@ #include -#include -#include #include #include +#include +#include +#include +#include #include #include -#include #include #include @@ -126,7 +127,7 @@ bool UDPTransportInterface::configure_send_buffer_size() socket.open(generate_protocol(), ec); if (!!ec) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "Error creating socket: " << ec.message()); + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Error creating socket: " << ec.message()); return false; } @@ -154,7 +155,7 @@ bool UDPTransportInterface::configure_send_buffer_size() if (!asio_helpers::try_setting_buffer_size( socket, send_buffer_size, minimum_socket_buffer, send_buffer_size)) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Couldn't set send buffer size to minimum value: " << minimum_socket_buffer); return false; } @@ -166,7 +167,7 @@ bool UDPTransportInterface::configure_send_buffer_size() // Inform the user if the desired value could not be set if (initial_value != 0 && mSendBufferSize != initial_value) { - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport sendBufferSize could not be set to the desired value. " + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport sendBufferSize could not be set to the desired value. " << "Using " << mSendBufferSize << " instead of " << initial_value); } @@ -180,7 +181,7 @@ bool UDPTransportInterface::configure_receive_buffer_size() socket.open(generate_protocol(), ec); if (!!ec) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "Error creating socket: " << ec.message()); + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Error creating socket: " << ec.message()); return false; } @@ -209,7 +210,7 @@ bool UDPTransportInterface::configure_receive_buffer_size() if (!asio_helpers::try_setting_buffer_size( socket, receive_buffer_size, minimum_socket_buffer, receive_buffer_size)) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Couldn't set receive buffer size to minimum value: " << minimum_socket_buffer); return false; } @@ -221,7 +222,7 @@ bool UDPTransportInterface::configure_receive_buffer_size() // Inform the user if the desired value could not be set if (initial_value != 0 && mReceiveBufferSize != initial_value) { - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport receiveBufferSize could not be set to the desired value. " + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport receiveBufferSize could not be set to the desired value. " << "Using " << mReceiveBufferSize << " instead of " << initial_value); } @@ -236,22 +237,35 @@ bool UDPTransportInterface::init( uint32_t cfg_max_msg_size = configuration()->maxMessageSize; uint32_t cfg_send_size = configuration()->sendBufferSize; uint32_t cfg_recv_size = configuration()->receiveBufferSize; + uint32_t max_int_value = static_cast(std::numeric_limits::max()); if (cfg_max_msg_size > maximumMessageSize) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, - "maxMessageSize cannot be greater than " << std::to_string(maximumMessageSize)); + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "maxMessageSize cannot be greater than " << maximumMessageSize); return false; } + + if (cfg_send_size > max_int_value) + { + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "sendBufferSize cannot be greater than " << max_int_value); + return false; + } + + if (cfg_recv_size > max_int_value) + { + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "receiveBufferSize cannot be greater than " << max_int_value); + return false; + } + if ((cfg_send_size > 0) && (cfg_max_msg_size > cfg_send_size)) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "maxMessageSize cannot be greater than send_buffer_size"); + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "maxMessageSize cannot be greater than sendBufferSize"); return false; } if ((cfg_recv_size > 0) && (cfg_max_msg_size > cfg_recv_size)) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "maxMessageSize cannot be greater than receive_buffer_size"); + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "maxMessageSize cannot be greater than receiveBufferSize"); return false; } @@ -293,9 +307,8 @@ bool UDPTransportInterface::OpenAndBindInputSockets( catch (asio::system_error const& e) { (void)e; - EPROSIMA_LOG_INFO(RTPS_MSG_OUT, "UDPTransport Error binding at port: (" << IPLocator::getPhysicalPort( - locator) << ")" - << " with msg: " << e.what()); + EPROSIMA_LOG_INFO(TRANSPORT_UDP, "UDPTransport Error binding at port: (" + << IPLocator::getPhysicalPort(locator) << ")" << " with msg: " << e.what()); mInputSockets.erase(IPLocator::getPhysicalPort(locator)); return false; } @@ -329,12 +342,12 @@ eProsimaUDPSocket UDPTransportInterface::OpenAndBindUnicastOutputSocket( if (!asio_helpers::try_setting_buffer_size( socket, mSendBufferSize, configuration()->maxMessageSize, configured_value)) { - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Couldn't set send buffer size to minimum value: " << configuration()->maxMessageSize); } else if (configured_value != mSendBufferSize) { - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport sendBufferSize could not be set to the desired value. " + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport sendBufferSize could not be set to the desired value. " << "Using " << configured_value << " instead of " << mSendBufferSize); } } @@ -423,7 +436,7 @@ bool UDPTransportInterface::OpenOutputChannel( catch (asio::system_error const& e) { (void)e; - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport Error binding interface " + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport Error binding interface " << localhost_name() << " (skipping) with msg: " << e.what()); } } @@ -447,7 +460,7 @@ bool UDPTransportInterface::OpenOutputChannel( catch (asio::system_error const& e) { (void)e; - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDPTransport Error binding interface " + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport Error binding interface " << (*locIt).name << " (skipping) with msg: " << e.what()); } } @@ -480,7 +493,7 @@ bool UDPTransportInterface::OpenOutputChannel( { (void)e; /* TODO Que hacer? - EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "UDPTransport Error binding at port: (" << IPLocator::getPhysicalPort(locator) << ")" + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "UDPTransport Error binding at port: (" << IPLocator::getPhysicalPort(locator) << ")" << " with msg: " << e.what()); for (auto& socket : mOutputSockets) { @@ -644,23 +657,24 @@ bool UDPTransportInterface::send( if ((ec.value() == asio::error::would_block) || (ec.value() == asio::error::try_again)) { - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, "UDP send would have blocked. Packet is dropped."); + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDP send would have blocked. Packet is dropped."); return true; } - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, ec.message()); + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, ec.message()); return false; } } catch (const std::exception& error) { - EPROSIMA_LOG_WARNING(RTPS_MSG_OUT, error.what()); + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, error.what()); return false; } (void)bytesSent; - EPROSIMA_LOG_INFO(RTPS_MSG_OUT, "UDPTransport: " << bytesSent << " bytes TO endpoint: " << destinationEndpoint - << " FROM " << getSocketPtr(socket)->local_endpoint()); + EPROSIMA_LOG_INFO(TRANSPORT_UDP, + "UDPTransport: " << bytesSent << " bytes TO endpoint: " << destinationEndpoint << + " FROM " << getSocketPtr(socket)->local_endpoint()); success = true; } From 40f62645386d8a0c57546ed6d32c6f58fa0ebe7a Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 9 May 2024 17:29:29 +0200 Subject: [PATCH 17/26] Refs #20972. Add UDP unit tests. Signed-off-by: Miguel Company --- test/unittest/transport/UDPv4Tests.cpp | 63 ++++++++++++++++++++++++++ test/unittest/transport/UDPv6Tests.cpp | 62 +++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/test/unittest/transport/UDPv4Tests.cpp b/test/unittest/transport/UDPv4Tests.cpp index 21d5f2d037b..37bf2f0b20c 100644 --- a/test/unittest/transport/UDPv4Tests.cpp +++ b/test/unittest/transport/UDPv4Tests.cpp @@ -12,12 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include #include +#include #include #include #include @@ -79,6 +81,67 @@ class UDPv4Tests : public ::testing::Test std::unique_ptr receiverThread; }; +TEST_F(UDPv4Tests, wrong_configuration) +{ + // Too big sendBufferSize + { + UDPv4TransportDescriptor wrong_descriptor; + wrong_descriptor.sendBufferSize = std::numeric_limits::max(); + UDPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big receiveBufferSize + { + UDPv4TransportDescriptor wrong_descriptor; + wrong_descriptor.receiveBufferSize = std::numeric_limits::max(); + UDPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big maxMessageSize + { + UDPv4TransportDescriptor wrong_descriptor; + wrong_descriptor.maxMessageSize = std::numeric_limits::max(); + UDPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than receiveBufferSize + { + UDPv4TransportDescriptor wrong_descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.receiveBufferSize = 5; + UDPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than sendBufferSize + { + UDPv4TransportDescriptor wrong_descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.sendBufferSize = 5; + UDPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Buffer sizes automatically decrease + { + UDPv4TransportDescriptor wrong_descriptor; + wrong_descriptor.sendBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.receiveBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.maxMessageSize = 1470; + UDPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_TRUE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } +} + TEST_F(UDPv4Tests, locators_with_kind_1_supported) { // Given diff --git a/test/unittest/transport/UDPv6Tests.cpp b/test/unittest/transport/UDPv6Tests.cpp index 803753dfb9d..5ffed411888 100644 --- a/test/unittest/transport/UDPv6Tests.cpp +++ b/test/unittest/transport/UDPv6Tests.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -87,6 +88,67 @@ class UDPv6Tests : public ::testing::Test std::unique_ptr receiverThread; }; +TEST_F(UDPv6Tests, wrong_configuration) +{ + // Too big sendBufferSize + { + UDPv6TransportDescriptor wrong_descriptor; + wrong_descriptor.sendBufferSize = std::numeric_limits::max(); + UDPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big receiveBufferSize + { + UDPv6TransportDescriptor wrong_descriptor; + wrong_descriptor.receiveBufferSize = std::numeric_limits::max(); + UDPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big maxMessageSize + { + UDPv6TransportDescriptor wrong_descriptor; + wrong_descriptor.maxMessageSize = std::numeric_limits::max(); + UDPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than receiveBufferSize + { + UDPv6TransportDescriptor wrong_descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.receiveBufferSize = 5; + UDPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than sendBufferSize + { + UDPv6TransportDescriptor wrong_descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.sendBufferSize = 5; + UDPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Buffer sizes automatically decrease + { + UDPv6TransportDescriptor wrong_descriptor; + wrong_descriptor.sendBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.receiveBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.maxMessageSize = 1470; + UDPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_TRUE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } +} + TEST_F(UDPv6Tests, conversion_to_ip6_string) { Locator_t locator; From 36c8d207c707d3480dfd5ddbdbb2a42bb8a31fe3 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 10 May 2024 07:50:34 +0200 Subject: [PATCH 18/26] Refs #20972. Add TCP unit tests. Signed-off-by: Miguel Company --- test/unittest/transport/TCPv4Tests.cpp | 62 ++++++++++++++++++++++++++ test/unittest/transport/TCPv6Tests.cpp | 62 ++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index 64786dfcd13..cc59b4e62e9 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -89,6 +90,67 @@ class TCPv4Tests : public ::testing::Test std::unique_ptr receiverThread; }; +TEST_F(TCPv4Tests, wrong_configuration_values) +{ + // Too big sendBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.sendBufferSize = std::numeric_limits::max(); + TCPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big receiveBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.receiveBufferSize = std::numeric_limits::max(); + TCPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big maxMessageSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.maxMessageSize = std::numeric_limits::max(); + TCPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than receiveBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.receiveBufferSize = 5; + TCPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than sendBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.sendBufferSize = 5; + TCPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Buffer sizes automatically decrease + { + auto wrong_descriptor = descriptor; + wrong_descriptor.sendBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.receiveBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.maxMessageSize = 1470; + TCPv4Transport transportUnderTest(wrong_descriptor); + ASSERT_TRUE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } +} + TEST_F(TCPv4Tests, locators_with_kind_1_supported) { // Given diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index c5abb31ca88..72843235bd7 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -85,6 +86,67 @@ class TCPv6Tests : public ::testing::Test std::unique_ptr receiverThread; }; +TEST_F(TCPv6Tests, wrong_configuration_values) +{ + // Too big sendBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.sendBufferSize = std::numeric_limits::max(); + TCPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big receiveBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.receiveBufferSize = std::numeric_limits::max(); + TCPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Too big maxMessageSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.maxMessageSize = std::numeric_limits::max(); + TCPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than receiveBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.receiveBufferSize = 5; + TCPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // maxMessageSize bigger than sendBufferSize + { + auto wrong_descriptor = descriptor; + wrong_descriptor.maxMessageSize = 10; + wrong_descriptor.sendBufferSize = 5; + TCPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_FALSE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } + + // Buffer sizes automatically decrease + { + auto wrong_descriptor = descriptor; + wrong_descriptor.sendBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.receiveBufferSize = static_cast(std::numeric_limits::max()); + wrong_descriptor.maxMessageSize = 1470; + TCPv6Transport transportUnderTest(wrong_descriptor); + ASSERT_TRUE(transportUnderTest.init()); + eprosima::fastdds::dds::Log::Flush(); + } +} + TEST_F(TCPv6Tests, conversion_to_ip6_string) { Locator_t locator; From e89db9396b1eb0a7c303196f8bc316c8d3960ed1 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 10 May 2024 13:56:29 +0200 Subject: [PATCH 19/26] Refs #20972. Move checks in TCP to beginning of init. Signed-off-by: Miguel Company --- .../rtps/transport/TCPTransportInterface.cpp | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index cd6e9ad5bea..7e474ba9151 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -437,6 +437,42 @@ bool TCPTransportInterface::init( const fastrtps::rtps::PropertyPolicy*, const uint32_t& max_msg_size_no_frag) { + uint32_t maximumMessageSize = max_msg_size_no_frag == 0 ? s_maximumMessageSize : max_msg_size_no_frag; + uint32_t cfg_max_msg_size = configuration()->maxMessageSize; + uint32_t cfg_send_size = configuration()->sendBufferSize; + uint32_t cfg_recv_size = configuration()->receiveBufferSize; + uint32_t max_int_value = static_cast(std::numeric_limits::max()); + + if (cfg_max_msg_size > maximumMessageSize) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than " << maximumMessageSize); + return false; + } + + if (cfg_send_size > max_int_value) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "sendBufferSize cannot be greater than " << max_int_value); + return false; + } + + if (cfg_recv_size > max_int_value) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "receiveBufferSize cannot be greater than " << max_int_value); + return false; + } + + if ((cfg_send_size > 0) && (cfg_max_msg_size > cfg_send_size)) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than sendBufferSize"); + return false; + } + + if ((cfg_recv_size > 0) && (cfg_max_msg_size > cfg_recv_size)) + { + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than receiveBufferSize"); + return false; + } + if (!apply_tls_config()) { // TODO decide wether the Transport initialization should keep working after this error @@ -485,42 +521,6 @@ bool TCPTransportInterface::init( } } - uint32_t maximumMessageSize = max_msg_size_no_frag == 0 ? s_maximumMessageSize : max_msg_size_no_frag; - uint32_t cfg_max_msg_size = configuration()->maxMessageSize; - uint32_t cfg_send_size = configuration()->sendBufferSize; - uint32_t cfg_recv_size = configuration()->receiveBufferSize; - uint32_t max_int_value = static_cast(std::numeric_limits::max()); - - if (cfg_max_msg_size > maximumMessageSize) - { - EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than " << maximumMessageSize); - return false; - } - - if (cfg_send_size > max_int_value) - { - EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "sendBufferSize cannot be greater than " << max_int_value); - return false; - } - - if (cfg_recv_size > max_int_value) - { - EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "receiveBufferSize cannot be greater than " << max_int_value); - return false; - } - - if (cfg_max_msg_size > cfg_send_size) - { - EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than sendBufferSize"); - return false; - } - - if (cfg_max_msg_size > cfg_recv_size) - { - EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "maxMessageSize cannot be greater than receiveBufferSize"); - return false; - } - if (!rtcp_message_manager_) { rtcp_message_manager_ = std::make_shared(this); From 1769956a8236535e84cd37c16321c10ff99ad49e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 10 May 2024 14:19:17 +0200 Subject: [PATCH 20/26] Refs #20972. Refactor for common code in UDP. Signed-off-by: Miguel Company --- .../rtps/transport/UDPTransportInterface.cpp | 143 ++++-------------- .../rtps/transport/UDPTransportInterface.h | 14 -- src/cpp/rtps/transport/asio_helpers.hpp | 78 ++++++++++ 3 files changed, 111 insertions(+), 124 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 142445d3d82..e51603fb6a1 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -120,115 +120,6 @@ bool UDPTransportInterface::DoInputLocatorsMatch( return IPLocator::getPhysicalPort(left) == IPLocator::getPhysicalPort(right); } -bool UDPTransportInterface::configure_send_buffer_size() -{ - asio::error_code ec; - ip::udp::socket socket(io_service_); - socket.open(generate_protocol(), ec); - if (!!ec) - { - EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Error creating socket: " << ec.message()); - return false; - } - - // If sendBufferSize is 0, try using the system default value - uint32_t send_buffer_size = configuration()->sendBufferSize; - uint32_t initial_value = send_buffer_size; - if (send_buffer_size == 0) - { - socket_base::send_buffer_size option; - socket.get_option(option, ec); - if (!ec) - { - send_buffer_size = static_cast(option.value()); - } - } - - // Ensure the minimum value is used - uint32_t minimum_socket_buffer = configuration()->maxMessageSize; - if (send_buffer_size < minimum_socket_buffer) - { - send_buffer_size = minimum_socket_buffer; - } - - // Try to set the highest possible value the system allows - if (!asio_helpers::try_setting_buffer_size( - socket, send_buffer_size, minimum_socket_buffer, send_buffer_size)) - { - EPROSIMA_LOG_ERROR(TRANSPORT_UDP, - "Couldn't set send buffer size to minimum value: " << minimum_socket_buffer); - return false; - } - - // Keep final configuration value - set_send_buffer_size(send_buffer_size); - mSendBufferSize = send_buffer_size; - - // Inform the user if the desired value could not be set - if (initial_value != 0 && mSendBufferSize != initial_value) - { - EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport sendBufferSize could not be set to the desired value. " - << "Using " << mSendBufferSize << " instead of " << initial_value); - } - - return true; -} - -bool UDPTransportInterface::configure_receive_buffer_size() -{ - asio::error_code ec; - ip::udp::socket socket(io_service_); - socket.open(generate_protocol(), ec); - if (!!ec) - { - EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Error creating socket: " << ec.message()); - return false; - } - - // If receiveBufferSize is 0, try using the system default value - uint32_t receive_buffer_size = configuration()->receiveBufferSize; - uint32_t initial_value = receive_buffer_size; - if (receive_buffer_size == 0) - { - socket_base::receive_buffer_size option; - socket.get_option(option, ec); - if (!ec) - { - receive_buffer_size = static_cast(option.value()); - } - } - - // Ensure the minimum value is used - uint32_t minimum_socket_buffer = configuration()->maxMessageSize; - if (receive_buffer_size < minimum_socket_buffer) - { - receive_buffer_size = minimum_socket_buffer; - set_receive_buffer_size(receive_buffer_size); - } - - // Try to set the highest possible value the system allows - if (!asio_helpers::try_setting_buffer_size( - socket, receive_buffer_size, minimum_socket_buffer, receive_buffer_size)) - { - EPROSIMA_LOG_ERROR(TRANSPORT_UDP, - "Couldn't set receive buffer size to minimum value: " << minimum_socket_buffer); - return false; - } - - // Keep final configuration value - set_receive_buffer_size(receive_buffer_size); - mReceiveBufferSize = receive_buffer_size; - - // Inform the user if the desired value could not be set - if (initial_value != 0 && mReceiveBufferSize != initial_value) - { - EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport receiveBufferSize could not be set to the desired value. " - << "Using " << mReceiveBufferSize << " instead of " << initial_value); - } - - return true; -} - bool UDPTransportInterface::init( const fastrtps::rtps::PropertyPolicy*, const uint32_t& max_msg_size_no_frag) @@ -269,7 +160,39 @@ bool UDPTransportInterface::init( return false; } - return configure_send_buffer_size() && configure_receive_buffer_size(); + asio::error_code ec; + ip::udp::socket socket(io_service_); + socket.open(generate_protocol(), ec); + if (!!ec) + { + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Error creating socket: " << ec.message()); + return false; + } + + bool ret = asio_helpers::configure_buffer_sizes(socket, *configuration(), mSendBufferSize, mReceiveBufferSize); + if (ret) + { + if (cfg_send_size > 0 && mSendBufferSize != cfg_send_size) + { + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport sendBufferSize could not be set to the desired value. " + << "Using " << mSendBufferSize << " instead of " << cfg_send_size); + } + + if (cfg_recv_size > 0 && mReceiveBufferSize != cfg_recv_size) + { + EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport receiveBufferSize could not be set to the desired value. " + << "Using " << mReceiveBufferSize << " instead of " << cfg_recv_size); + } + + set_send_buffer_size(mSendBufferSize); + set_receive_buffer_size(mReceiveBufferSize); + } + else + { + EPROSIMA_LOG_ERROR(TRANSPORT_UDP, "Couldn't set buffer sizes to minimum value: " << cfg_max_msg_size); + } + + return ret; } bool UDPTransportInterface::IsInputChannelOpen( diff --git a/src/cpp/rtps/transport/UDPTransportInterface.h b/src/cpp/rtps/transport/UDPTransportInterface.h index ca8af5b722b..f70b30b0f22 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.h +++ b/src/cpp/rtps/transport/UDPTransportInterface.h @@ -306,20 +306,6 @@ class UDPTransportInterface : public TransportInterface std::atomic_bool rescan_interfaces_ = {true}; -private: - - /** - * @brief Prepare transport configuration regarding send buffer size. - * @return true if a send buffer size greater than max message size could be set, false otherwise. - */ - bool configure_send_buffer_size(); - - /** - * @brief Prepare transport configuration regarding receive buffer size. - * @return true if a receive buffer size greater than max message size could be set, false otherwise. - */ - bool configure_receive_buffer_size(); - }; } // namespace rtps diff --git a/src/cpp/rtps/transport/asio_helpers.hpp b/src/cpp/rtps/transport/asio_helpers.hpp index 0b6848c6150..f9ba81b84e0 100644 --- a/src/cpp/rtps/transport/asio_helpers.hpp +++ b/src/cpp/rtps/transport/asio_helpers.hpp @@ -67,6 +67,84 @@ struct asio_helpers return !ec; } + /** + * @brief Configure a buffer size on a socket, using the system default value if the initial value is 0. + * Ensures that the final buffer size is at least the minimum value. + * + * @tparam BufferOptionType Type of the buffer option to set. + * @tparam SocketType Type of socket on which to set the buffer size option. + * + * @param socket Socket on which to set the buffer size option. + * @param initial_buffer_value Initial value to try to set. + * @param minimum_buffer_value Minimum value to set. + * @param final_buffer_value Output parameter where the final value set will be stored. + * + * @return true if the buffer size was successfully set, false otherwise. + */ + template + static inline bool configure_buffer_size( + SocketType& socket, + const uint32_t initial_buffer_value, + const uint32_t minimum_buffer_value, + uint32_t& final_buffer_value) + { + final_buffer_value = initial_buffer_value; + + // If the initial value is 0, try using the system default value + if (initial_buffer_value == 0) + { + asio::error_code ec; + BufferOptionType option; + socket.get_option(option, ec); + if (!ec) + { + final_buffer_value = option.value(); + } + } + + // Ensure the minimum value is used + if (final_buffer_value < minimum_buffer_value) + { + final_buffer_value = minimum_buffer_value; + } + + // Try to set the highest possible value the system allows + return try_setting_buffer_size(socket, final_buffer_value, minimum_buffer_value, + final_buffer_value); + } + + /** + * @brief Configure the send and receive buffer sizes on a socket, using the system default value if the initial + * values are 0. Ensures that the final buffer sizes are at least the minimum value. + * + * @tparam SocketType Type of socket on which to set the buffer size options. + * + * @param socket Socket on which to set the buffer size options. + * @param descriptor Transport descriptor with the buffer sizes to set. + * @param final_send_buffer_size Output parameter where the final send buffer size will be stored. + * @param final_receive_buffer_size Output parameter where the final receive buffer size will be stored. + * + * @return true if the buffer sizes were successfully set, false otherwise. + */ + template + static inline bool configure_buffer_sizes( + SocketType& socket, + const SocketTransportDescriptor& descriptor, + uint32_t& final_send_buffer_size, + uint32_t& final_receive_buffer_size) + { + uint32_t minimum_socket_buffer = descriptor.maxMessageSize; + uint32_t send_buffer_size = descriptor.sendBufferSize; + uint32_t receive_buffer_size = descriptor.receiveBufferSize; + + bool send_buffer_size_set = configure_buffer_size( + socket, send_buffer_size, minimum_socket_buffer, final_send_buffer_size); + bool receive_buffer_size_set = configure_buffer_size( + socket, receive_buffer_size, minimum_socket_buffer, final_receive_buffer_size); + + return send_buffer_size_set && receive_buffer_size_set; + } + }; } // namespace rtps From f683035b15a5aa16b4d59220d8209add5808c15d Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 13 May 2024 07:48:14 +0200 Subject: [PATCH 21/26] Refs #20972. Refactor for common code in TCP. Signed-off-by: Miguel Company --- .../rtps/transport/TCPTransportInterface.cpp | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 7e474ba9151..0375ef5069f 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -497,30 +498,30 @@ bool TCPTransportInterface::init( initial_peer_local_locator_port_ = local_endpoint.port(); // Check system buffer sizes. - if (configuration()->sendBufferSize == 0) + uint32_t send_size = 0; + uint32_t recv_size = 0; + if (!asio_helpers::configure_buffer_sizes( + *initial_peer_local_locator_socket_, *configuration(), send_size, recv_size)) { - socket_base::send_buffer_size option; - initial_peer_local_locator_socket_->get_option(option); - set_send_buffer_size(option.value()); - - if (configuration()->sendBufferSize < s_minimumSocketBuffer) - { - set_send_buffer_size(s_minimumSocketBuffer); - } + EPROSIMA_LOG_ERROR(TRANSPORT_TCP, "Couldn't set buffer sizes to minimum value: " << cfg_max_msg_size); + return false; } - if (configuration()->receiveBufferSize == 0) + if (cfg_send_size > 0 && send_size != cfg_send_size) { - socket_base::receive_buffer_size option; - initial_peer_local_locator_socket_->get_option(option); - set_receive_buffer_size(option.value()); + EPROSIMA_LOG_WARNING(TRANSPORT_TCP, "UDPTransport sendBufferSize could not be set to the desired value. " + << "Using " << send_size << " instead of " << cfg_send_size); + } - if (configuration()->receiveBufferSize < s_minimumSocketBuffer) - { - set_receive_buffer_size(s_minimumSocketBuffer); - } + if (cfg_recv_size > 0 && recv_size != cfg_recv_size) + { + EPROSIMA_LOG_WARNING(TRANSPORT_TCP, "UDPTransport receiveBufferSize could not be set to the desired value. " + << "Using " << recv_size << " instead of " << cfg_recv_size); } + set_send_buffer_size(send_size); + set_receive_buffer_size(recv_size); + if (!rtcp_message_manager_) { rtcp_message_manager_ = std::make_shared(this); From fd5bb8fe9e7c2615ff8e523ee7aa51b7e9f743df Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 13 May 2024 08:39:58 +0200 Subject: [PATCH 22/26] Refs #20972. Remove unused constants in UDP tests. Signed-off-by: Miguel Company --- test/unittest/transport/UDPv4Tests.cpp | 4 ---- test/unittest/transport/UDPv6Tests.cpp | 4 ---- 2 files changed, 8 deletions(-) diff --git a/test/unittest/transport/UDPv4Tests.cpp b/test/unittest/transport/UDPv4Tests.cpp index 37bf2f0b20c..470631fba3b 100644 --- a/test/unittest/transport/UDPv4Tests.cpp +++ b/test/unittest/transport/UDPv4Tests.cpp @@ -36,10 +36,6 @@ using UDPv4Transport = eprosima::fastdds::rtps::UDPv4Transport; using UDPv4TransportDescriptor = eprosima::fastdds::rtps::UDPv4TransportDescriptor; using SendResourceList = eprosima::fastdds::rtps::SendResourceList; -#ifndef __APPLE__ -const uint32_t ReceiveBufferCapacity = 65536; -#endif // ifndef __APPLE__ - #if defined(_WIN32) #define GET_PID _getpid #else diff --git a/test/unittest/transport/UDPv6Tests.cpp b/test/unittest/transport/UDPv6Tests.cpp index 5ffed411888..942741cde5d 100644 --- a/test/unittest/transport/UDPv6Tests.cpp +++ b/test/unittest/transport/UDPv6Tests.cpp @@ -35,10 +35,6 @@ using UDPv6Transport = eprosima::fastdds::rtps::UDPv6Transport; using UDPv6TransportDescriptor = eprosima::fastdds::rtps::UDPv6TransportDescriptor; using SendResourceList = eprosima::fastdds::rtps::SendResourceList; -#ifndef __APPLE__ -const uint32_t ReceiveBufferCapacity = 65536; -#endif // ifndef __APPLE__ - #if defined(_WIN32) #define GET_PID _getpid #else From c3b2a675eb8d2f05c9e34bb96721795affb1c5f2 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 13 May 2024 16:45:08 +0200 Subject: [PATCH 23/26] Refs #20972. Remove unused constant `s_minimumSocketBuffer`. Signed-off-by: Miguel Company --- include/fastdds/rtps/transport/TransportInterface.h | 2 -- include/fastrtps/transport/TransportInterface.h | 1 - test/unittest/transport/TCPv4Tests.cpp | 4 ++-- test/unittest/transport/TCPv6Tests.cpp | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/fastdds/rtps/transport/TransportInterface.h b/include/fastdds/rtps/transport/TransportInterface.h index b016492476b..000e5e0edca 100644 --- a/include/fastdds/rtps/transport/TransportInterface.h +++ b/include/fastdds/rtps/transport/TransportInterface.h @@ -39,8 +39,6 @@ namespace rtps { constexpr uint32_t s_maximumMessageSize = 65500; //! Default maximum initial peers range constexpr uint32_t s_maximumInitialPeersRange = 4; -//! Default minimum socket buffer -constexpr uint32_t s_minimumSocketBuffer = 65536; //! Default IPv4 address static const std::string s_IPv4AddressAny = "0.0.0.0"; //! Default IPv6 address diff --git a/include/fastrtps/transport/TransportInterface.h b/include/fastrtps/transport/TransportInterface.h index 9f0a5f88760..107a0d3db8b 100644 --- a/include/fastrtps/transport/TransportInterface.h +++ b/include/fastrtps/transport/TransportInterface.h @@ -29,7 +29,6 @@ using TransportInterface = fastdds::rtps::TransportInterface; static const uint32_t s_maximumMessageSize = fastdds::rtps::s_maximumMessageSize; static const uint32_t s_maximumInitialPeersRange = fastdds::rtps::s_maximumInitialPeersRange; -static const uint32_t s_minimumSocketBuffer = fastdds::rtps::s_minimumSocketBuffer; static const std::string s_IPv4AddressAny = fastdds::rtps::s_IPv4AddressAny; static const std::string s_IPv6AddressAny = fastdds::rtps::s_IPv6AddressAny; diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index cc59b4e62e9..70f08d07388 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -1403,7 +1403,7 @@ TEST_F(TCPv4Tests, secure_non_blocking_send) eprosima::fastdds::dds::Log::SetVerbosity(eprosima::fastdds::dds::Log::Kind::Info); uint16_t port = g_default_port; - uint32_t msg_size = eprosima::fastdds::rtps::s_minimumSocketBuffer; + uint32_t msg_size = 64ul * 1024ul; // Create a TCP Server transport using TLSOptions = TCPTransportDescriptor::TLSConfig::TLSOptions; using TLSVerifyMode = TCPTransportDescriptor::TLSConfig::TLSVerifyMode; @@ -1963,7 +1963,7 @@ TEST_F(TCPv4Tests, client_announced_local_port_uniqueness) TEST_F(TCPv4Tests, non_blocking_send) { uint16_t port = g_default_port; - uint32_t msg_size = eprosima::fastdds::rtps::s_minimumSocketBuffer; + uint32_t msg_size = 64ul * 1024ul; // Create a TCP Server transport eprosima::fastdds::rtps::TCPv4TransportDescriptor senderDescriptor; senderDescriptor.add_listener_port(port); diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index 72843235bd7..11e5d6425b5 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -371,7 +371,7 @@ TEST_F(TCPv6Tests, client_announced_local_port_uniqueness) TEST_F(TCPv6Tests, non_blocking_send) { uint16_t port = g_default_port; - uint32_t msg_size = eprosima::fastdds::rtps::s_minimumSocketBuffer; + uint32_t msg_size = 64ul * 1024ul; // Create a TCP Server transport eprosima::fastdds::rtps::TCPv6TransportDescriptor senderDescriptor; senderDescriptor.add_listener_port(port); From 27a04e98107b3a6b63680ae240dc63b94e9166f9 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 13 May 2024 16:59:16 +0200 Subject: [PATCH 24/26] Refs #20972. Check final configuration on unit tests. Signed-off-by: Miguel Company --- test/unittest/transport/TCPv4Tests.cpp | 5 +++++ test/unittest/transport/TCPv6Tests.cpp | 5 +++++ test/unittest/transport/UDPv4Tests.cpp | 5 +++++ test/unittest/transport/UDPv6Tests.cpp | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index 70f08d07388..65293cbf25e 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -147,6 +147,11 @@ TEST_F(TCPv4Tests, wrong_configuration_values) wrong_descriptor.maxMessageSize = 1470; TCPv4Transport transportUnderTest(wrong_descriptor); ASSERT_TRUE(transportUnderTest.init()); + auto* final_cfg = transportUnderTest.configuration(); + EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index 11e5d6425b5..1a04363e43e 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -143,6 +143,11 @@ TEST_F(TCPv6Tests, wrong_configuration_values) wrong_descriptor.maxMessageSize = 1470; TCPv6Transport transportUnderTest(wrong_descriptor); ASSERT_TRUE(transportUnderTest.init()); + auto* final_cfg = transportUnderTest.configuration(); + EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } diff --git a/test/unittest/transport/UDPv4Tests.cpp b/test/unittest/transport/UDPv4Tests.cpp index 470631fba3b..df95b38c7af 100644 --- a/test/unittest/transport/UDPv4Tests.cpp +++ b/test/unittest/transport/UDPv4Tests.cpp @@ -134,6 +134,11 @@ TEST_F(UDPv4Tests, wrong_configuration) wrong_descriptor.maxMessageSize = 1470; UDPv4Transport transportUnderTest(wrong_descriptor); ASSERT_TRUE(transportUnderTest.init()); + auto* final_cfg = transportUnderTest.configuration(); + EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } diff --git a/test/unittest/transport/UDPv6Tests.cpp b/test/unittest/transport/UDPv6Tests.cpp index 942741cde5d..60ff08a3c36 100644 --- a/test/unittest/transport/UDPv6Tests.cpp +++ b/test/unittest/transport/UDPv6Tests.cpp @@ -141,6 +141,11 @@ TEST_F(UDPv6Tests, wrong_configuration) wrong_descriptor.maxMessageSize = 1470; UDPv6Transport transportUnderTest(wrong_descriptor); ASSERT_TRUE(transportUnderTest.init()); + auto* final_cfg = transportUnderTest.configuration(); + EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); + EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } From c0a0f6371e5ea6423265570cddbabdb01b88ddcc Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 14 May 2024 07:50:33 +0200 Subject: [PATCH 25/26] Refs #20972. Uncrustify. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/UDPTransportInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index e51603fb6a1..96f39bbeaf6 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -175,13 +175,13 @@ bool UDPTransportInterface::init( if (cfg_send_size > 0 && mSendBufferSize != cfg_send_size) { EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport sendBufferSize could not be set to the desired value. " - << "Using " << mSendBufferSize << " instead of " << cfg_send_size); + << "Using " << mSendBufferSize << " instead of " << cfg_send_size); } if (cfg_recv_size > 0 && mReceiveBufferSize != cfg_recv_size) { EPROSIMA_LOG_WARNING(TRANSPORT_UDP, "UDPTransport receiveBufferSize could not be set to the desired value. " - << "Using " << mReceiveBufferSize << " instead of " << cfg_recv_size); + << "Using " << mReceiveBufferSize << " instead of " << cfg_recv_size); } set_send_buffer_size(mSendBufferSize); From 6d94732c6174e10a7bf506f485bcc44df328ecf4 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 14 May 2024 10:56:14 +0200 Subject: [PATCH 26/26] Refs #20972. Less strict tests. Signed-off-by: Miguel Company --- test/unittest/transport/TCPv4Tests.cpp | 6 ++++-- test/unittest/transport/TCPv6Tests.cpp | 6 ++++-- test/unittest/transport/UDPv4Tests.cpp | 6 ++++-- test/unittest/transport/UDPv6Tests.cpp | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index 65293cbf25e..cc11a5b1d50 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -149,9 +149,11 @@ TEST_F(TCPv4Tests, wrong_configuration_values) ASSERT_TRUE(transportUnderTest.init()); auto* final_cfg = transportUnderTest.configuration(); EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + // The system could allow for the send buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); + // The system could allow for the receive buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index 1a04363e43e..ee7f5a7361e 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -145,9 +145,11 @@ TEST_F(TCPv6Tests, wrong_configuration_values) ASSERT_TRUE(transportUnderTest.init()); auto* final_cfg = transportUnderTest.configuration(); EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + // The system could allow for the send buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); + // The system could allow for the receive buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } diff --git a/test/unittest/transport/UDPv4Tests.cpp b/test/unittest/transport/UDPv4Tests.cpp index df95b38c7af..54bfc4561ef 100644 --- a/test/unittest/transport/UDPv4Tests.cpp +++ b/test/unittest/transport/UDPv4Tests.cpp @@ -136,9 +136,11 @@ TEST_F(UDPv4Tests, wrong_configuration) ASSERT_TRUE(transportUnderTest.init()); auto* final_cfg = transportUnderTest.configuration(); EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + // The system could allow for the send buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); + // The system could allow for the receive buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } } diff --git a/test/unittest/transport/UDPv6Tests.cpp b/test/unittest/transport/UDPv6Tests.cpp index 60ff08a3c36..44497c72abb 100644 --- a/test/unittest/transport/UDPv6Tests.cpp +++ b/test/unittest/transport/UDPv6Tests.cpp @@ -143,9 +143,11 @@ TEST_F(UDPv6Tests, wrong_configuration) ASSERT_TRUE(transportUnderTest.init()); auto* final_cfg = transportUnderTest.configuration(); EXPECT_GE(final_cfg->sendBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); + // The system could allow for the send buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->sendBufferSize, wrong_descriptor.sendBufferSize); EXPECT_GE(final_cfg->receiveBufferSize, final_cfg->maxMessageSize); - EXPECT_LT(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); + // The system could allow for the receive buffer to be MAX_INT, so we cannot check it to be strictly lower + EXPECT_LE(final_cfg->receiveBufferSize, wrong_descriptor.receiveBufferSize); eprosima::fastdds::dds::Log::Flush(); } }