diff --git a/include/fastrtps/participant/Participant.h b/include/fastrtps/participant/Participant.h index 6f9db3436c1..11dab5dbf2c 100644 --- a/include/fastrtps/participant/Participant.h +++ b/include/fastrtps/participant/Participant.h @@ -95,6 +95,11 @@ class RTPS_DllAPI Participant const rtps::GUID_t& readerGuid, rtps::ReaderProxyData& returnedInfo); + /** + * @brief Asserts liveliness of manual by participant publishers + */ + void assert_liveliness(); + private: Participant(); diff --git a/include/fastrtps/rtps/builtin/liveliness/WLP.h b/include/fastrtps/rtps/builtin/liveliness/WLP.h index 48462f961cf..d5e4bd3d5e1 100644 --- a/include/fastrtps/rtps/builtin/liveliness/WLP.h +++ b/include/fastrtps/rtps/builtin/liveliness/WLP.h @@ -126,6 +126,12 @@ class WLP LivelinessQosPolicyKind kind, Duration_t lease_duration); + /** + * @brief A method to assert liveliness of MANUAL_BY_PARTICIPANT writers + * @return True if there were any MANUAL_BY_PARTICIPANT writers + */ + bool assert_liveliness_manual_by_participant(); + /** * Get the builtin protocols * @return Builtin protocols diff --git a/src/cpp/participant/Participant.cpp b/src/cpp/participant/Participant.cpp index 7b7257e2db5..5519b1418db 100644 --- a/src/cpp/participant/Participant.cpp +++ b/src/cpp/participant/Participant.cpp @@ -70,3 +70,8 @@ bool Participant::get_remote_reader_info( { return mp_impl->get_remote_reader_info(readerGuid, returnedInfo); } + +void Participant::assert_liveliness() +{ + mp_impl->assert_liveliness(); +} diff --git a/src/cpp/participant/ParticipantImpl.cpp b/src/cpp/participant/ParticipantImpl.cpp index c3d3ebeb8ca..84989db3dae 100644 --- a/src/cpp/participant/ParticipantImpl.cpp +++ b/src/cpp/participant/ParticipantImpl.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -516,3 +517,15 @@ ResourceEvent& ParticipantImpl::get_resource_event() const { return mp_rtpsParticipant->get_resource_event(); } + +void ParticipantImpl::assert_liveliness() +{ + if (mp_rtpsParticipant->wlp() != nullptr) + { + mp_rtpsParticipant->wlp()->assert_liveliness_manual_by_participant(); + } + else + { + logError(PARTICIPANT, "Invalid WLP, cannot assert liveliness of participant"); + } +} diff --git a/src/cpp/participant/ParticipantImpl.h b/src/cpp/participant/ParticipantImpl.h index db0768ab04e..9af95198e8a 100644 --- a/src/cpp/participant/ParticipantImpl.h +++ b/src/cpp/participant/ParticipantImpl.h @@ -160,6 +160,11 @@ class ParticipantImpl rtps::ResourceEvent& get_resource_event() const; + /** + * @brief Asserts liveliness of manual by participant readers + */ + void assert_liveliness(); + private: //!Participant Attributes ParticipantAttributes m_att; diff --git a/src/cpp/rtps/builtin/liveliness/WLP.cpp b/src/cpp/rtps/builtin/liveliness/WLP.cpp index 6c2dff35039..d6b20466524 100644 --- a/src/cpp/rtps/builtin/liveliness/WLP.cpp +++ b/src/cpp/rtps/builtin/liveliness/WLP.cpp @@ -822,6 +822,15 @@ bool WLP::assert_liveliness( lease_duration); } +bool WLP::assert_liveliness_manual_by_participant() +{ + if (manual_by_participant_writers_.size() > 0) + { + return pub_liveliness_manager_->assert_liveliness(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS); + } + return false; +} + void WLP::pub_liveliness_changed( const GUID_t& writer, const LivelinessQosPolicyKind& kind, diff --git a/test/blackbox/BlackboxTestsLivelinessQos.cpp b/test/blackbox/BlackboxTestsLivelinessQos.cpp index e0c96d95d43..d592b12ac47 100644 --- a/test/blackbox/BlackboxTestsLivelinessQos.cpp +++ b/test/blackbox/BlackboxTestsLivelinessQos.cpp @@ -1552,3 +1552,45 @@ TEST(LivelinessQos, LivelinessChangedStatus_NotAlive_Unmatched) EXPECT_EQ(status.not_alive_count, 0); EXPECT_EQ(status.not_alive_count_change, -1); } + + +//! Tests the assert_liveliness on the participant +//! A participant with three publishers, two MANUAL_BY_PARTICIPANT liveliness, one MANUAL_BY_TOPIC +TEST(LivelinessQos, AssertLivelinessParticipant) +{ + unsigned int num_pub = 3; + unsigned int lease_duration_ms = 100; + unsigned int announcement_period_ms = 10; + + // Publishers + PubSubParticipant publishers(num_pub, 0u, 0u, 0u); + ASSERT_TRUE(publishers.init_participant()); + publishers.pub_topic_name(TEST_TOPIC_NAME) + .reliability(RELIABLE_RELIABILITY_QOS) + .pub_liveliness_announcement_period(announcement_period_ms * 1e-3) + .pub_liveliness_lease_duration(lease_duration_ms * 1e-3) + .pub_liveliness_kind(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS); + ASSERT_TRUE(publishers.init_publisher(0u)); + publishers.pub_topic_name(TEST_TOPIC_NAME) + .reliability(RELIABLE_RELIABILITY_QOS) + .pub_liveliness_announcement_period(announcement_period_ms * 1e-3) + .pub_liveliness_lease_duration(lease_duration_ms * 1e-3) + .pub_liveliness_kind(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS); + ASSERT_TRUE(publishers.init_publisher(1u)); + publishers.pub_topic_name(TEST_TOPIC_NAME) + .reliability(RELIABLE_RELIABILITY_QOS) + .pub_liveliness_announcement_period(announcement_period_ms * 1e-3) + .pub_liveliness_lease_duration(lease_duration_ms * 1e-3) + .pub_liveliness_kind(MANUAL_BY_TOPIC_LIVELINESS_QOS); + ASSERT_TRUE(publishers.init_publisher(1u)); + + // Assert liveliness + publishers.assert_liveliness_participant(); + + // Wait for alive publishers (only the two MANUAL_BY_PARTICIPANT publishers should be alive) to lose liveliness + std::this_thread::sleep_for(std::chrono::milliseconds(lease_duration_ms * 4)); + + // Only the two MANUAL_BY_PARTICIPANT publishers will have lost liveliness, as the + // MANUAL_BY_TOPIC was never asserted + EXPECT_EQ(publishers.pub_times_liveliness_lost(), 2u); +} diff --git a/test/blackbox/PubSubParticipant.hpp b/test/blackbox/PubSubParticipant.hpp index 4808e3c721a..d00ffb97f4b 100644 --- a/test/blackbox/PubSubParticipant.hpp +++ b/test/blackbox/PubSubParticipant.hpp @@ -110,6 +110,7 @@ class PubSubParticipant { (void)sub; (status.alive_count_change == 1) ? participant_->sub_liveliness_recovered() : participant_->sub_liveliness_lost(); + } private: @@ -225,6 +226,11 @@ class PubSubParticipant return publishers_[index]->write((void*)&msg); } + void assert_liveliness_participant() + { + participant_->assert_liveliness(); + } + void assert_liveliness(unsigned int index = 0) { publishers_[index]->assert_liveliness();