From 7f9022cd3f8f6ce27f1c4b982c8476206e5f437d Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 12 Jun 2024 11:42:58 +0200 Subject: [PATCH] Refs #21095: Create a test for each transport and intialize to ::1 when ipv6 is used Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 25 ++++++++++++++++--- .../discovery_server/ClientPublisherApp.cpp | 4 --- test/examples/test_discovery_server.py | 5 +++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index 3bd233147c5..e18393117ab 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -252,6 +252,8 @@ class CLIParser bool uses_ipv6 = false; bool listening_address_was_set = false; + bool connection_address_was_set = false; + for (int i = 2; i < argc; ++i) { std::string arg = argv[i]; @@ -323,6 +325,7 @@ class CLIParser { config.srv_config.is_also_client = true; } + connection_address_was_set = true; } else { @@ -687,11 +690,25 @@ class CLIParser } } - if (uses_ipv6 - && !listening_address_was_set - && config.entity == CLIParser::EntityKind::SERVER) + // change default values if IPv6 is used + // and user did not specified ones + if (uses_ipv6) { - config.srv_config.listening_address = "::1"; + if (config.entity == CLIParser::EntityKind::SERVER && + !listening_address_was_set) + { + config.srv_config.listening_address = "::1"; + } + + if (!connection_address_was_set) + { + config.pub_config.connection_address = "::1"; + config.sub_config.connection_address = "::1"; + if (config.srv_config.is_also_client) + { + config.srv_config.connection_address = "::1"; + } + } } return config; diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 1643aab8d4d..2d917fe0ece 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -115,8 +115,6 @@ ClientPublisherApp::ClientPublisherApp( case TransportKind::TCPv4: { auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub descriptor_tmp->add_listener_port(0); descriptor = descriptor_tmp; @@ -129,8 +127,6 @@ ClientPublisherApp::ClientPublisherApp( case TransportKind::TCPv6: { auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub descriptor_tmp->add_listener_port(0); descriptor = descriptor_tmp; diff --git a/test/examples/test_discovery_server.py b/test/examples/test_discovery_server.py index 2614aa1739a..278190d86fa 100644 --- a/test/examples/test_discovery_server.py +++ b/test/examples/test_discovery_server.py @@ -10,7 +10,10 @@ ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), ('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5') + ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5'), + ('--transport udpv6 --connection-ds-id 1 --samples 10', '--transport udpv6 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport udpv6 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport udpv6 --id 2 --listening-port 18000 --timeout 5'), + ('--transport tcpv4 --connection-ds-id 1 --samples 10', '--transport tcpv4 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport tcpv4 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport tcpv4 --id 2 --listening-port 18000 --timeout 5'), + ('--transport tcpv6 --connection-ds-id 1 --samples 10', '--transport tcpv6 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport tcpv6 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport tcpv6 --id 2 --listening-port 18000 --timeout 5') ] @pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases)