Skip to content

Commit ca4f44f

Browse files
cferreiragonzEugenioCollado
authored andcommitted
Fix DS initialization on "any" if no interfaces are available (#5850)
* Refs #23248: Add regression test Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #23248: Use localhost if no interfaces are found Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #23248: Fix permissions of .bash Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #23248: NITs Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> --------- Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> (cherry picked from commit 4e6a68f)
1 parent 42288ed commit ca4f44f

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed

src/cpp/rtps/participant/RTPSParticipantImpl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,13 @@ bool RTPSParticipantImpl::did_mutation_took_place_on_meta(
28882888
if (locals.empty())
28892889
{
28902890
IPFinder::getIP4Address(&locals);
2891+
// If no local interfaces found, use localhost
2892+
if (locals.empty())
2893+
{
2894+
Locator_t loc_lo;
2895+
IPLocator::setIPv4(loc_lo, "127.0.0.1");
2896+
locals.push_back(loc_lo);
2897+
}
28912898
}
28922899

28932900
// add a locator for each local

test/dds/communication/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ list(APPEND TEST_DEFINITIONS
120120

121121

122122
list(APPEND XML_CONFIGURATION_FILES
123+
ds_client.xml
123124
simple_reliable_profile.xml
124125
simple_besteffort_profile.xml
125126
simple_reliable_zerocopy_profile.xml

test/dds/communication/ds_client.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<dds xmlns="http://www.eprosima.com">
3+
<profiles>
4+
<transport_descriptors>
5+
<transport_descriptor>
6+
<transport_id>udp_transport</transport_id>
7+
<type>UDPv4</type>
8+
</transport_descriptor>
9+
</transport_descriptors>
10+
11+
<participant profile_name="Client" is_default_profile="true">
12+
<rtps>
13+
<useBuiltinTransports>false</useBuiltinTransports>
14+
<userTransports>
15+
<transport_id>udp_transport</transport_id>
16+
</userTransports>
17+
<builtin>
18+
<discovery_config>
19+
<discoveryProtocol>CLIENT</discoveryProtocol>
20+
<discoveryServersList>
21+
<locator>
22+
<udpv4>
23+
<address>${SERVER_IP}</address>
24+
<port>11811</port>
25+
</udpv4>
26+
</locator>
27+
</discoveryServersList>
28+
</discovery_config>
29+
30+
<metatrafficUnicastLocatorList>
31+
<locator>
32+
<udpv4>
33+
<port>17401</port>
34+
</udpv4>
35+
</locator>
36+
</metatrafficUnicastLocatorList>
37+
</builtin>
38+
39+
<defaultUnicastLocatorList>
40+
<locator>
41+
<udpv4>
42+
<port>17400</port>
43+
</udpv4>
44+
</locator>
45+
</defaultUnicastLocatorList>
46+
</rtps>
47+
</participant>
48+
49+
<data_writer profile_name="simple_publisher_profile" is_default_profile="true">
50+
<qos>
51+
<reliability>
52+
<kind>RELIABLE</kind>
53+
</reliability>
54+
<data_sharing>
55+
<kind>OFF</kind>
56+
</data_sharing>
57+
</qos>
58+
</data_writer>
59+
<data_reader profile_name="simple_subscriber_profile" is_default_profile="true">
60+
<qos>
61+
<reliability>
62+
<kind>RELIABLE</kind>
63+
</reliability>
64+
<data_sharing>
65+
<kind>OFF</kind>
66+
</data_sharing>
67+
</qos>
68+
</data_reader>
69+
70+
</profiles>
71+
</dds>

test/dds/communication/dyn_network/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ configure_file(launch_subscriber.bash
5959
add_test(NAME dds.communication.dynamic_interfaces
6060
COMMAND ${DOCKER_EXECUTABLE} compose -f ${CMAKE_CURRENT_BINARY_DIR}/dynamic_interfaces.compose.yml up
6161
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
62+
63+
configure_file(ds_init_no_interfaces.compose.yml
64+
${CMAKE_CURRENT_BINARY_DIR}/ds_init_no_interfaces.compose.yml @ONLY)
65+
configure_file(launch_ds_no_interfaces.bash
66+
${CMAKE_CURRENT_BINARY_DIR}/launch_ds_no_interfaces.bash @ONLY)
67+
add_test(NAME dds.commmunication.ds_init_with_no_interfaces
68+
COMMAND ${DOCKER_EXECUTABLE} compose -f ${CMAKE_CURRENT_BINARY_DIR}/ds_init_no_interfaces.compose.yml up --exit-code-from server-pub-sub
69+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

test/dds/communication/dyn_network/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,17 @@ ENV DEBIAN_FRONTEND=noninteractive
2525

2626
# Install apt dependencies
2727
RUN apt-get update && apt-get install --yes net-tools && rm -rf /var/lib/apt/lists/*
28+
29+
FROM ubuntu:$ubuntu_version AS ubuntu-cli
30+
31+
# Needed for a dependency that forces to set timezone
32+
ENV TZ=Europe/Madrid
33+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
34+
35+
# Avoids using interactions during building
36+
ENV DEBIAN_FRONTEND=noninteractive
37+
38+
# Install apt dependencies
39+
RUN apt-get update && apt-get install --yes python3 python3-pip && rm -rf /var/lib/apt/lists/*
40+
41+
RUN pip3 install psutil
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
services:
16+
server-pub-sub:
17+
build: .
18+
image: ubuntu-cli:22.04
19+
volumes:
20+
- @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@
21+
- @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@
22+
- @CMAKE_INSTALL_PREFIX@:@CMAKE_INSTALL_PREFIX@
23+
@TINYXML2_LIB_DIR_COMPOSE_VOLUME@
24+
environment:
25+
# Load also fastdds libraries to run the CLI
26+
LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@:@CMAKE_INSTALL_PREFIX@/lib:$LD_LIBRARY_PATH
27+
SERVER_IP: 127.0.0.1
28+
working_dir: @PROJECT_BINARY_DIR@/test/dds/communication
29+
command: @SHELL_EXECUTABLE@ "dyn_network/launch_ds_no_interfaces.bash"
30+
network_mode: none
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
17+
set -e
18+
19+
PREFIX="@CMAKE_INSTALL_PREFIX@"
20+
EXAMPLE_DIR="@PROJECT_BINARY_DIR@/test/dds/communication"
21+
export EXAMPLE_DIR
22+
23+
echo "[INFO] Starting discovery server"
24+
"$PREFIX/bin/fastdds" discovery -l 0.0.0.0 &
25+
SERVER_PID=$!
26+
27+
28+
# Publisher
29+
echo "[INFO] Starting publisher"
30+
"$EXAMPLE_DIR/DDSCommunicationPublisher" \
31+
--xmlfile "$EXAMPLE_DIR/ds_client.xml" \
32+
--wait 1 --samples 10 --loops 1 --seed 0 --magic T &
33+
PUB_PID=$!
34+
35+
# Subscriber
36+
echo "[INFO] Starting subscriber"
37+
"$EXAMPLE_DIR/DDSCommunicationSubscriber" \
38+
--xmlfile "$EXAMPLE_DIR/ds_client.xml" \
39+
--samples 10 --seed 0 --magic T --rescan 2 &
40+
SUB_PID=$!
41+
42+
sleep 15
43+
# Discovery server process must still be running
44+
if ! kill "$SERVER_PID" 2>/dev/null; then
45+
echo "[ERROR] Discover server ended unexpectedly"
46+
exit 1
47+
else
48+
echo "[INFO] Manually killing discovery server. Server execution successful"
49+
fi
50+
51+
# PUBLISHER and SUBSCRIBER processes must end gracefully
52+
wait $PUB_PID
53+
wait $SUB_PID
54+
echo "[INFO] Test completed successfully"

0 commit comments

Comments
 (0)