Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding assert_liveliness to participant [5771] #579

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/fastrtps/participant/Participant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions include/fastrtps/rtps/builtin/liveliness/WLP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/cpp/participant/Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
13 changes: 13 additions & 0 deletions src/cpp/participant/ParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <fastrtps/transport/UDPv4Transport.h>
#include <fastrtps/transport/UDPv6Transport.h>
#include <fastrtps/transport/test_UDPv4Transport.h>
#include <fastrtps/rtps/builtin/liveliness/WLP.h>

#include <fastrtps/log/Log.h>

Expand Down Expand Up @@ -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");
}
}
5 changes: 5 additions & 0 deletions src/cpp/participant/ParticipantImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/cpp/rtps/builtin/liveliness/WLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 42 additions & 0 deletions test/blackbox/BlackboxTestsLivelinessQos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HelloWorldType> 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);
}
6 changes: 6 additions & 0 deletions test/blackbox/PubSubParticipant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class PubSubParticipant
{
(void)sub;
(status.alive_count_change == 1) ? participant_->sub_liveliness_recovered() : participant_->sub_liveliness_lost();

}

private:
Expand Down Expand Up @@ -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();
Expand Down