Skip to content

Commit

Permalink
Refs #21170: Add DS servers connection test
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <[email protected]>
  • Loading branch information
cferreiragonz committed Jun 12, 2024
1 parent ae42cf7 commit 816e9a9
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions test/blackbox/common/DDSBlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,124 @@ TEST(DDSDiscovery, AddDiscoveryServerToListTCP)
server_2.wait_discovery(std::chrono::seconds::zero(), 2, true); // Knows client1 and server1
}

TEST(DDSDiscovery, ServersConnectionTCP)
{
using namespace eprosima;
using namespace eprosima::fastdds::dds;
using namespace eprosima::fastrtps::rtps;

// TCP default DS port
std::string W_UNICAST_PORT_RANDOM_NUMBER_STR = "42100";

/* Create first server */
PubSubParticipant<HelloWorldPubSubType> server_1(0u, 0u, 0u, 0u);
// Set participant as server
WireProtocolConfigQos server_1_qos;
server_1_qos.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SERVER;
// Generate random GUID prefix
srand(static_cast<unsigned>(time(nullptr)));
GuidPrefix_t server_1_prefix;
for (auto i = 0; i < 12; i++)
{
server_1_prefix.value[i] = eprosima::fastrtps::rtps::octet(rand() % 254);
}
server_1_qos.prefix = server_1_prefix;
// Generate server's listening locator
Locator_t locator_server_1;
IPLocator::setIPv4(locator_server_1, 127, 0, 0, 1);
uint16_t server_1_port = static_cast<uint16_t>(stoi(W_UNICAST_PORT_RANDOM_NUMBER_STR));
IPLocator::setPhysicalPort(locator_server_1, server_1_port);
locator_server_1.kind = LOCATOR_KIND_TCPv4;
// Leave logical port as 0 to use TCP DS default logical port
server_1_qos.builtin.metatrafficUnicastLocatorList.push_back(locator_server_1);
// Add TCP transport
auto descriptor_1 = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
descriptor_1->add_listener_port(server_1_port);
// Init server
ASSERT_TRUE(server_1.wire_protocol(server_1_qos)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_1)
.init_participant());

/* Create second server */
PubSubParticipant<HelloWorldPubSubType> server_2(0u, 0u, 0u, 0u);
// Set participant as server
WireProtocolConfigQos server_2_qos;
server_2_qos.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SERVER;
// Generate random GUID prefix
GuidPrefix_t server_2_prefix = server_1_prefix;
server_2_prefix.value[11]++;
server_2_qos.prefix = server_2_prefix;
// Generate server's listening locator
Locator_t locator_server_2;
IPLocator::setIPv4(locator_server_2, 127, 0, 0, 1);
uint16_t server_2_port = server_1_port + 1;
IPLocator::setPhysicalPort(locator_server_2, server_2_port);
locator_server_2.kind = LOCATOR_KIND_TCPv4;
// Leave logical port as 0 to use TCP DS default logical port
server_2_qos.builtin.metatrafficUnicastLocatorList.push_back(locator_server_2);
// Add TCP transport
auto descriptor_2 = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
descriptor_2->add_listener_port(server_2_port);
// Connect to first server
RemoteServerAttributes server_1_att;
server_1_att.guidPrefix = server_1_prefix;
server_1_att.metatrafficUnicastLocatorList.push_back(Locator_t(locator_server_1));
server_2_qos.builtin.discovery_config.m_DiscoveryServers.push_back(server_1_att);

// Init server
ASSERT_TRUE(server_2.wire_protocol(server_2_qos)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_2)
.init_participant());

/* Create third server */
PubSubParticipant<HelloWorldPubSubType> server_3(0u, 0u, 0u, 0u);
// Set participant as server
WireProtocolConfigQos server_3_qos;
server_3_qos.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SERVER;
// Generate random GUID prefix
GuidPrefix_t server_3_prefix = server_1_prefix;
server_3_prefix.value[11]--;
server_3_qos.prefix = server_3_prefix;
// Generate server's listening locator
Locator_t locator_server_3;
IPLocator::setIPv4(locator_server_3, 127, 0, 0, 1);
uint16_t server_3_port = server_1_port - 1;
IPLocator::setPhysicalPort(locator_server_3, server_3_port);
locator_server_3.kind = LOCATOR_KIND_TCPv4;
// Leave logical port as 0 to use TCP DS default logical port
server_3_qos.builtin.metatrafficUnicastLocatorList.push_back(locator_server_3);
// Add TCP transport
auto descriptor_3 = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
descriptor_3->add_listener_port(server_3_port);
// Connect to first server
server_3_qos.builtin.discovery_config.m_DiscoveryServers.push_back(server_1_att);

// Init server
ASSERT_TRUE(server_3.wire_protocol(server_3_qos)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_3)
.init_participant());

// Check adding servers before initialization
server_1.wait_discovery(std::chrono::seconds::zero(), 2, true); // Knows server2 and server3
server_2.wait_discovery(std::chrono::seconds::zero(), 1, true); // Knows server1
server_3.wait_discovery(std::chrono::seconds::zero(), 1, true); // Knows server1

/* Add server_2 to server_1 */
RemoteServerAttributes server_3_att;
server_3_att.guidPrefix = server_3_prefix;
server_3_att.metatrafficUnicastLocatorList.push_back(Locator_t(locator_server_3));
server_2_qos.builtin.discovery_config.m_DiscoveryServers.push_back(server_3_att);
ASSERT_TRUE(server_2.update_wire_protocol(server_2_qos));

// Check adding servers after initialization
server_1.wait_discovery(std::chrono::seconds::zero(), 2, true); // Knows server2 and server3
server_2.wait_discovery(std::chrono::seconds::zero(), 2, true); // Knows server1 and server3
server_3.wait_discovery(std::chrono::seconds::zero(), 2, true); // Knows server1 and server2
}

/**
* This test checks the addition of network interfaces at run-time.
*
Expand Down

0 comments on commit 816e9a9

Please sign in to comment.