From 55259ec03eb288105dcb01fe6e5bf4e3b91a611d Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Fri, 13 Dec 2024 11:59:11 +0100 Subject: [PATCH 1/4] Refs #22469: Regression Tests for IPv6 Signed-off-by: cferreiragonz --- test/unittest/transport/TCPv4Tests.cpp | 1 + test/unittest/transport/TCPv6Tests.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index 06ee3e8cb68..8211a6eca98 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -2035,6 +2035,7 @@ TEST_F(TCPv4Tests, client_announced_local_port_uniqueness) std::this_thread::sleep_for(std::chrono::milliseconds(100)); + EXPECT_GT(receiveTransportUnderTest.get_channel_resources().size(), 2u); std::set> channels_created; for (const auto& channel_resource : receiveTransportUnderTest.get_channel_resources()) { diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index 11e8faf1696..bac0687596b 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -368,7 +368,13 @@ TEST_F(TCPv6Tests, client_announced_local_port_uniqueness) std::this_thread::sleep_for(std::chrono::milliseconds(100)); - ASSERT_EQ(receiveTransportUnderTest.get_channel_resources().size(), 2u); + EXPECT_GT(receiveTransportUnderTest.get_channel_resources().size(), 2u); + std::set> channels_created; + for (const auto& channel_resource : receiveTransportUnderTest.get_channel_resources()) + { + channels_created.insert(channel_resource.second); + } + ASSERT_EQ(channels_created.size(), 2u); } #ifndef _WIN32 From b3183fc16c6dda43f0445cc54e389a6c1f501910 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Fri, 13 Dec 2024 11:59:42 +0100 Subject: [PATCH 2/4] Refs #22469: New method copyAddress Signed-off-by: cferreiragonz --- include/fastdds/utils/IPLocator.hpp | 9 +++++++++ src/cpp/utils/IPLocator.cpp | 21 +++++++++++++++++++++ test/unittest/utils/LocatorTests.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/include/fastdds/utils/IPLocator.hpp b/include/fastdds/utils/IPLocator.hpp index f5b8fb4a1b0..c189008fa07 100644 --- a/include/fastdds/utils/IPLocator.hpp +++ b/include/fastdds/utils/IPLocator.hpp @@ -252,6 +252,15 @@ class IPLocator const Locator_t& loc2, bool fullAddress = false); + /** Copies the whole address from one locator to another. + * @param loc1 Locator to copy from. + * @param loc2 Locator to copy to. + * @return True if the copy was successful. + */ + FASTDDS_EXPORTED_API static bool copyAddress( + const Locator_t& loc1, + Locator_t& loc2); + //! Checks if a both locators has the same IP address and physical port (as in RTCP protocol). FASTDDS_EXPORTED_API static bool compareAddressAndPhysicalPort( const Locator_t& loc1, diff --git a/src/cpp/utils/IPLocator.cpp b/src/cpp/utils/IPLocator.cpp index e5143e78573..32514d11fdc 100644 --- a/src/cpp/utils/IPLocator.cpp +++ b/src/cpp/utils/IPLocator.cpp @@ -985,6 +985,27 @@ bool IPLocator::compareAddress( } } +bool IPLocator::copyAddress( + const Locator_t& loc1, + Locator_t& loc2) +{ + if (loc1.kind != loc2.kind) + { + return false; + } + + if (loc1.kind == LOCATOR_KIND_UDPv4 || loc1.kind == LOCATOR_KIND_TCPv4) + { + memcpy(loc2.address, loc1.address, 16 * sizeof(char)); + return true; + } + else if (loc1.kind == LOCATOR_KIND_UDPv6 || loc1.kind == LOCATOR_KIND_TCPv6) + { + return copyIPv6(loc1, loc2.address); + } + return false; +} + bool IPLocator::compareAddressAndPhysicalPort( const Locator_t& loc1, const Locator_t& loc2) diff --git a/test/unittest/utils/LocatorTests.cpp b/test/unittest/utils/LocatorTests.cpp index a4e3958cf94..be3fea2e9ca 100644 --- a/test/unittest/utils/LocatorTests.cpp +++ b/test/unittest/utils/LocatorTests.cpp @@ -767,6 +767,31 @@ TEST_F(IPLocatorTests, copyIPv6) ASSERT_EQ(arr[15], 1u); } +/* + * Check to copy an address + */ +TEST_F(IPLocatorTests, copyAddress) +{ + // Copy IPv4 + Locator_t locator1(LOCATOR_KIND_UDPv4); + Locator_t locator2(LOCATOR_KIND_UDPv4); + IPLocator::setIPv4(locator1, ipv4_lo_address); + ASSERT_FALSE(IPLocator::compareAddress(locator1, locator2)); + ASSERT_TRUE(IPLocator::copyAddress(locator1, locator2)); + ASSERT_TRUE(IPLocator::compareAddress(locator1, locator2)); + + // Check cannot copy between different kinds + locator1.kind = LOCATOR_KIND_UDPv6; + ASSERT_FALSE(IPLocator::copyAddress(locator1, locator2)); + + // Copy IPv6 + locator2.kind = LOCATOR_KIND_UDPv6; + IPLocator::setIPv6(locator1, ipv6_lo_address); + ASSERT_FALSE(IPLocator::compareAddress(locator1, locator2)); + ASSERT_TRUE(IPLocator::copyAddress(locator1, locator2)); + ASSERT_TRUE(IPLocator::compareAddress(locator1, locator2)); +} + /* * Check to set ip of any kind */ From 63760f15457dbe114843d6407ce316e84b78dd09 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Fri, 13 Dec 2024 11:59:56 +0100 Subject: [PATCH 3/4] Refs #22469: Fix TCPTransportInterface Signed-off-by: cferreiragonz --- src/cpp/rtps/transport/TCPTransportInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 5a8693c2049..115ba9309da 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -319,7 +319,7 @@ ResponseCode TCPTransportInterface::bind_socket( Locator local_locator(channel->locator()); for (auto& interface_it : local_interfaces) { - IPLocator::setIPv4(local_locator, interface_it.locator); + IPLocator::copyAddress(interface_it.locator, local_locator); channel_resources_.insert(decltype(channel_resources_)::value_type{local_locator, channel}); } } @@ -1030,7 +1030,7 @@ bool TCPTransportInterface::CreateInitialConnect( Locator local_locator(physical_locator); for (auto& interface_it : local_interfaces) { - IPLocator::setIPv4(local_locator, interface_it.locator); + IPLocator::copyAddress(interface_it.locator, local_locator); channel_resources_[local_locator] = channel; } } From 62a024b151642327d1a94c9a5d4d33d002c9b98d Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Fri, 13 Dec 2024 14:03:09 +0100 Subject: [PATCH 4/4] Refs #22469: Apply Review Signed-off-by: cferreiragonz --- include/fastdds/utils/IPLocator.hpp | 3 ++- test/unittest/utils/LocatorTests.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/fastdds/utils/IPLocator.hpp b/include/fastdds/utils/IPLocator.hpp index c189008fa07..9f4807ef9f9 100644 --- a/include/fastdds/utils/IPLocator.hpp +++ b/include/fastdds/utils/IPLocator.hpp @@ -252,7 +252,8 @@ class IPLocator const Locator_t& loc2, bool fullAddress = false); - /** Copies the whole address from one locator to another. + /** + * Copies the whole address from one locator to another. * @param loc1 Locator to copy from. * @param loc2 Locator to copy to. * @return True if the copy was successful. diff --git a/test/unittest/utils/LocatorTests.cpp b/test/unittest/utils/LocatorTests.cpp index be3fea2e9ca..0eba150eefb 100644 --- a/test/unittest/utils/LocatorTests.cpp +++ b/test/unittest/utils/LocatorTests.cpp @@ -790,6 +790,12 @@ TEST_F(IPLocatorTests, copyAddress) ASSERT_FALSE(IPLocator::compareAddress(locator1, locator2)); ASSERT_TRUE(IPLocator::copyAddress(locator1, locator2)); ASSERT_TRUE(IPLocator::compareAddress(locator1, locator2)); + + // Check cannot copy between SHM locators + locator1.kind = LOCATOR_KIND_SHM; + Locator_t locator3(LOCATOR_KIND_SHM); + ASSERT_FALSE(IPLocator::copyAddress(locator1, locator3)); + ASSERT_FALSE(IPLocator::compareAddress(locator1, locator3)); } /*