Skip to content

Commit ad9b4eb

Browse files
authored
Fix issues in Dynamic Network Interfaces (#5282) (#5304) (#5390)
* Fix issues in Dynamic Network Interfaces (#5282) * Refs #21690. Parse `--rescan` argument on communication applications. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Implement rescan mechanism. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Add docker infrastructure. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Add CMake infrastructure. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Ensure same domain and topic name are used. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Add `--loops` argument to publisher. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Publisher exits after publishing all samples. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Improve subscriber script. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Add test. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Make publisher wait subscriber. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Possible fix. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Clear locators before recalculating them. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Move local participant proxy update to PDP. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Improve new method's logic. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Include what you use. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Add empty method to update endpoint locators. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Add implementation for `update_endpoint_locators_if_default_nts`. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Compare against old default locators. Signed-off-by: Miguel Company <[email protected]> * Refs #21690. Update locators in attributes. Signed-off-by: Miguel Company <[email protected]> * Refs #17283. Avoid early return on `PDP::local_participant_attributes_update_nts`. Signed-off-by: Miguel Company <[email protected]> * Refs #17283. Apply suggestions. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> (cherry picked from commit 91bd7c8) * Refs #17283: Fix conflicts Signed-off-by: eProsima <[email protected]> * Refs #17283: Keep original PR functionality Signed-off-by: eProsima <[email protected]> * Refs #17283: Please uncrustify Signed-off-by: eProsima <[email protected]> * Restore discovery server list check code. Signed-off-by: Miguel Company <[email protected]> * Make backported methods static methods instead of inline code. Signed-off-by: Miguel Company <[email protected]> * Methods get_default_xxx_locators with output argument. Signed-off-by: Miguel Company <[email protected]> * Only update attributes when necessary. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: eProsima <[email protected]> Signed-off-by: Miguel Company <[email protected]> Co-authored-by: Miguel Company <[email protected]> Co-authored-by: eProsima <[email protected]> (cherry picked from commit 66ec998) Signed-off-by: Miguel Company <[email protected]> # Conflicts: # src/cpp/rtps/participant/RTPSParticipantImpl.cpp # test/communication/PublisherMain.cpp # test/communication/SubscriberMain.cpp # test/dds/communication/SubscriberMain.cpp # test/dds/communication/SubscriberModule.hpp # test/dds/communication/security/PublisherModule.cpp # test/dds/communication/security/PublisherModule.hpp # test/dds/communication/security/SubscriberModule.cpp # test/dds/communication/security/SubscriberModule.hpp Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 67ce284 commit ad9b4eb

15 files changed

+493
-93
lines changed

include/fastdds/rtps/builtin/discovery/participant/PDP.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
2323

2424
#include <atomic>
25+
#include <cstdint>
2526
#include <functional>
2627
#include <memory>
2728
#include <mutex>
29+
#include <string>
30+
#include <vector>
2831

2932
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
3033
#include <fastdds/rtps/builtin/data/ReaderProxyData.h>
@@ -61,6 +64,7 @@ class RTPSWriter;
6164
class RTPSReader;
6265
class WriterHistory;
6366
class ReaderHistory;
67+
struct RTPSParticipantAllocationAttributes;
6468
class RTPSParticipantImpl;
6569
class RTPSParticipantListener;
6670
class BuiltinProtocols;
@@ -70,6 +74,7 @@ class ReaderProxyData;
7074
class WriterProxyData;
7175
class ParticipantProxyData;
7276
class ReaderListener;
77+
class PDPEndpoints;
7378
class PDPListener;
7479
class PDPServerListener;
7580
class ITopicPayloadPool;

src/cpp/rtps/participant/RTPSParticipantImpl.cpp

+202-63
Large diffs are not rendered by default.

src/cpp/rtps/participant/RTPSParticipantImpl.h

+6
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,17 @@ class RTPSParticipantImpl
762762
*/
763763
void get_default_metatraffic_locators();
764764

765+
void get_default_metatraffic_locators(
766+
RTPSParticipantAttributes& att);
767+
765768
/**
766769
* Get default unicast locators when not provided by the user.
767770
*/
768771
void get_default_unicast_locators();
769772

773+
void get_default_unicast_locators(
774+
RTPSParticipantAttributes& att);
775+
770776
bool match_local_endpoints_ = true;
771777

772778
bool should_match_local_endpoints(

test/dds/communication/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,7 @@ if(Python3_Interpreter_FOUND)
206206
endif()
207207
endforeach()
208208
endif()
209+
210+
if(UNIX AND NOT(APPLE) AND NOT(QNXNTO) AND NOT(ANDROID))
211+
add_subdirectory(dyn_network)
212+
endif()

test/dds/communication/PubSubMain.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void publisher_run(
5252
publisher->wait_discovery(wait);
5353
}
5454

55-
publisher->run(samples, loops, interval);
55+
publisher->run(samples, 0, loops, interval);
5656
}
5757

5858
int main(
@@ -197,7 +197,7 @@ int main(
197197
DomainParticipantFactory::get_instance()->load_XML_profiles_file(xml_file);
198198
}
199199

200-
SubscriberModule subscriber(publishers, samples, fixed_type, zero_copy);
200+
SubscriberModule subscriber(publishers, samples, fixed_type, zero_copy, false);
201201
PublisherModule publisher(exit_on_lost_liveliness, fixed_type, zero_copy);
202202

203203
uint32_t result = 1;
@@ -208,7 +208,7 @@ int main(
208208

209209
if (subscriber.init(seed, magic))
210210
{
211-
result = subscriber.run(notexit, timeout) ? 0 : -1;
211+
result = subscriber.run(notexit, 0, timeout) ? 0 : -1;
212212
}
213213

214214
publisher_thread.join();

test/dds/communication/PublisherMain.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ using namespace eprosima::fastdds::dds;
2929
* --seed <int>
3030
* --wait <int>
3131
* --samples <int>
32+
* --loops <int>
33+
* --interval <int>
3234
* --magic <str>
3335
* --xmlfile <path>
34-
* --interval <int>
36+
* --rescan <int>
3537
*/
3638

3739
int main(
@@ -46,7 +48,9 @@ int main(
4648
uint32_t wait = 0;
4749
char* xml_file = nullptr;
4850
uint32_t samples = 4;
51+
uint32_t loops = 0;
4952
uint32_t interval = 250;
53+
uint32_t rescan_interval_seconds = 0;
5054
std::string magic;
5155

5256
while (arg_count < argc)
@@ -93,6 +97,16 @@ int main(
9397

9498
samples = strtol(argv[arg_count], nullptr, 10);
9599
}
100+
else if (strcmp(argv[arg_count], "--loops") == 0)
101+
{
102+
if (++arg_count >= argc)
103+
{
104+
std::cout << "--loops expects a parameter" << std::endl;
105+
return -1;
106+
}
107+
108+
loops = strtol(argv[arg_count], nullptr, 10);
109+
}
96110
else if (strcmp(argv[arg_count], "--interval") == 0)
97111
{
98112
if (++arg_count >= argc)
@@ -123,6 +137,16 @@ int main(
123137

124138
xml_file = argv[arg_count];
125139
}
140+
else if (strcmp(argv[arg_count], "--rescan") == 0)
141+
{
142+
if (++arg_count >= argc)
143+
{
144+
std::cout << "--rescan expects a parameter" << std::endl;
145+
return -1;
146+
}
147+
148+
rescan_interval_seconds = strtol(argv[arg_count], nullptr, 10);
149+
}
126150
else
127151
{
128152
std::cout << "Wrong argument " << argv[arg_count] << std::endl;
@@ -146,7 +170,7 @@ int main(
146170
publisher.wait_discovery(wait);
147171
}
148172

149-
publisher.run(samples, 0, interval);
173+
publisher.run(samples, rescan_interval_seconds, loops, interval);
150174
return 0;
151175
}
152176

test/dds/communication/PublisherModule.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,30 @@ void PublisherModule::wait_discovery(
131131

132132
void PublisherModule::run(
133133
uint32_t samples,
134+
const uint32_t rescan_interval,
134135
const uint32_t loops,
135136
uint32_t interval)
136137
{
137138
uint32_t current_loop = 0;
138139
uint16_t index = 1;
139140
void* sample = nullptr;
140141

142+
std::thread net_rescan_thread([this, rescan_interval]()
143+
{
144+
if (rescan_interval > 0)
145+
{
146+
auto interval = std::chrono::seconds(rescan_interval);
147+
while (run_)
148+
{
149+
std::this_thread::sleep_for(interval);
150+
if (run_)
151+
{
152+
participant_->set_qos(participant_->get_qos());
153+
}
154+
}
155+
}
156+
});
157+
141158
while (run_ && (loops == 0 || loops > current_loop))
142159
{
143160
if (zero_copy_)
@@ -184,6 +201,9 @@ void PublisherModule::run(
184201

185202
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
186203
}
204+
205+
run_ = false;
206+
net_rescan_thread.join();
187207
}
188208

189209
void PublisherModule::on_publication_matched(

test/dds/communication/PublisherModule.hpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#ifndef TEST_DDS_COMMUNICATION_PUBLISHERMODULE_HPP
2020
#define TEST_DDS_COMMUNICATION_PUBLISHERMODULE_HPP
2121

22+
#include <atomic>
23+
#include <chrono>
24+
#include <condition_variable>
25+
#include <mutex>
26+
2227
#include <fastdds/dds/domain/DomainParticipant.hpp>
2328
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
2429
#include <fastdds/dds/publisher/PublisherListener.hpp>
@@ -27,9 +32,6 @@
2732
#include "types/FixedSizedPubSubTypes.h"
2833
#include "types/HelloWorldPubSubTypes.h"
2934

30-
#include <mutex>
31-
#include <condition_variable>
32-
3335
namespace eprosima {
3436
namespace fastdds {
3537
namespace dds {
@@ -41,8 +43,8 @@ class PublisherModule
4143

4244
PublisherModule(
4345
bool exit_on_lost_liveliness,
44-
bool fixed_type = false,
45-
bool zero_copy = false)
46+
bool fixed_type,
47+
bool zero_copy)
4648
: exit_on_lost_liveliness_(exit_on_lost_liveliness)
4749
, fixed_type_(zero_copy || fixed_type) // If zero copy active, fixed type is required
4850
, zero_copy_(zero_copy)
@@ -80,8 +82,9 @@ class PublisherModule
8082

8183
void run(
8284
uint32_t samples,
83-
uint32_t loops = 0,
84-
uint32_t interval = 250);
85+
const uint32_t rescan_interval,
86+
uint32_t loops,
87+
uint32_t interval);
8588

8689
private:
8790

@@ -93,7 +96,7 @@ class PublisherModule
9396
bool exit_on_lost_liveliness_ = false;
9497
bool fixed_type_ = false;
9598
bool zero_copy_ = false;
96-
bool run_ = true;
99+
std::atomic_bool run_{true};
97100
DomainParticipant* participant_ = nullptr;
98101
TypeSupport type_;
99102
Publisher* publisher_ = nullptr;

test/dds/communication/SubscriberMain.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ using namespace eprosima::fastdds::dds;
2626
* --notexit
2727
* --fixed_type
2828
* --zero_copy
29+
* --succeed_on_timeout
2930
* --seed <int>
3031
* --samples <int>
3132
* --magic <str>
33+
* --timeout <int>
3234
* --xmlfile <path>
3335
* --publishers <int>
34-
* --succeed_on_timeout
35-
* --timeout <int>
36+
* --rescan <int>
3637
*/
3738

3839
int main(
@@ -48,6 +49,7 @@ int main(
4849
uint32_t samples = 4;
4950
uint32_t publishers = 1;
5051
uint32_t timeout = 86400000; // 24 h in ms
52+
uint32_t rescan_interval_seconds = 0;
5153
char* xml_file = nullptr;
5254
std::string magic;
5355

@@ -129,6 +131,16 @@ int main(
129131

130132
publishers = strtol(argv[arg_count], nullptr, 10);
131133
}
134+
else if (strcmp(argv[arg_count], "--rescan") == 0)
135+
{
136+
if (++arg_count >= argc)
137+
{
138+
std::cout << "--rescan expects a parameter" << std::endl;
139+
return -1;
140+
}
141+
142+
rescan_interval_seconds = strtol(argv[arg_count], nullptr, 10);
143+
}
132144
else
133145
{
134146
std::cout << "Wrong argument " << argv[arg_count] << std::endl;
@@ -147,7 +159,7 @@ int main(
147159

148160
if (subscriber.init(seed, magic))
149161
{
150-
return subscriber.run(notexit, timeout) ? 0 : -1;
162+
return subscriber.run(notexit, rescan_interval_seconds, timeout) ? 0 : -1;
151163
}
152164

153165
return -1;

test/dds/communication/SubscriberModule.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,35 @@ bool SubscriberModule::init(
130130

131131
bool SubscriberModule::run(
132132
bool notexit,
133+
const uint32_t rescan_interval,
133134
uint32_t timeout)
134135
{
135-
return run_for(notexit, std::chrono::milliseconds(timeout));
136+
return run_for(notexit, rescan_interval, std::chrono::milliseconds(timeout));
136137
}
137138

138139
bool SubscriberModule::run_for(
139140
bool notexit,
141+
const uint32_t rescan_interval,
140142
const std::chrono::milliseconds& timeout)
141143
{
142144
bool returned_value = false;
143145

146+
std::thread net_rescan_thread([this, rescan_interval]()
147+
{
148+
if (rescan_interval > 0)
149+
{
150+
auto interval = std::chrono::seconds(rescan_interval);
151+
while (run_)
152+
{
153+
std::this_thread::sleep_for(interval);
154+
if (run_)
155+
{
156+
participant_->set_qos(participant_->get_qos());
157+
}
158+
}
159+
}
160+
});
161+
144162
while (notexit && run_)
145163
{
146164
std::this_thread::sleep_for(std::chrono::milliseconds(250));
@@ -152,7 +170,7 @@ bool SubscriberModule::run_for(
152170
std::unique_lock<std::mutex> lock(mutex_);
153171
returned_value = cv_.wait_for(lock, timeout, [&]
154172
{
155-
if (succeeed_on_timeout_ && (std::chrono::steady_clock::now() - t0) > timeout)
173+
if (succeed_on_timeout_ && (std::chrono::steady_clock::now() - t0) > timeout)
156174
{
157175
return true;
158176
}
@@ -190,6 +208,9 @@ bool SubscriberModule::run_for(
190208
returned_value = false;
191209
}
192210

211+
run_ = false;
212+
net_rescan_thread.join();
213+
193214
return returned_value;
194215
}
195216

0 commit comments

Comments
 (0)