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

[19347] Fix encapsulation format in WLP (backport #3784) #3790

Merged
merged 2 commits into from
Oct 24, 2023
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
54 changes: 35 additions & 19 deletions include/fastdds/rtps/builtin/liveliness/WLPListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
#define _FASTDDS_RTPS_WLPLISTENER_H_
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <fastdds/rtps/reader/ReaderListener.h>
#include <fastdds/rtps/common/Guid.h>
#include <fastdds/rtps/common/GuidPrefix_t.hpp>
#include <fastdds/rtps/common/InstanceHandle.h>

#include <fastdds/rtps/common/Types.h>
#include <fastdds/rtps/reader/ReaderListener.h>
#include <fastrtps/qos/QosPolicies.h>

namespace eprosima {
namespace fastrtps{
namespace fastrtps {
namespace rtps {

class WLP;
Expand All @@ -39,14 +39,16 @@ struct CacheChange_t;
* Class WLPListener that receives the liveliness messages asserting the liveliness of remote endpoints.
* @ingroup LIVELINESS_MODULE
*/
class WLPListener: public ReaderListener {
class WLPListener : public ReaderListener
{
public:

/**
* @brief Constructor
* @param pwlp Pointer to the writer liveliness protocol
*/
WLPListener(WLP* pwlp);
WLPListener(
WLP* pwlp);

/**
* @brief Destructor
Expand All @@ -60,27 +62,41 @@ class WLPListener: public ReaderListener {
*/
void onNewCacheChangeAdded(
RTPSReader* reader,
const CacheChange_t* const change) override;
const CacheChange_t* const change) override;

private:

/**
* Separate the Key between the GuidPrefix_t and the liveliness Kind
* @param key InstanceHandle_t to separate.
* @param guidP GuidPrefix_t pointer to store the info.
* @param liveliness Liveliness Kind Pointer.
* @return True if correctly separated.
*/
* Separate the Key between the GuidPrefix_t and the liveliness Kind
* @param key InstanceHandle_t to separate.
* @param guidP GuidPrefix_t pointer to store the info.
* @param liveliness Liveliness Kind Pointer.
* @return True if correctly separated.
*/
bool separateKey(
InstanceHandle_t& key,
GuidPrefix_t* guidP,
LivelinessQosPolicyKind* liveliness);

/**
* Compute the key from a CacheChange_t
* @param change
*/
bool computeKey(CacheChange_t* change);
* Compute the key from a CacheChange_t
* @param change
*/
bool computeKey(
CacheChange_t* change);

/**
* @brief Check that the ParticipantMessageData kind is a valid one for WLP and extract the liveliness kind.
*
* @param[in] serialized_kind A pointer to the first octet of the kind array. The function assumes 4 elements
* in the array.
* @param[out] liveliness_kind A reference to the LivelinessQosPolicyKind.
*
* @return True if the kind corresponds with one for WLP, false otherwise.
*/
bool get_wlp_kind(
const octet* serialized_kind,
LivelinessQosPolicyKind& liveliness_kind);

//! A pointer to the writer liveliness protocol
WLP* mp_WLP;
Expand All @@ -89,6 +105,6 @@ class WLPListener: public ReaderListener {

} /* namespace rtps */
} /* namespace eprosima */
}
#endif
} // namespace eprosima
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* _FASTDDS_RTPS_WLPLISTENER_H_ */
6 changes: 5 additions & 1 deletion include/fastdds/rtps/common/CDRMessage_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ struct RTPS_DllAPI CDRMessage_t final
const SerializedPayload_t& payload)
: wraps(true)
{
msg_endian = payload.encapsulation == PL_CDR_BE ? BIGEND : LITTLEEND;
msg_endian = LITTLEEND;
if (payload.encapsulation == PL_CDR_BE || payload.encapsulation == CDR_BE)
{
msg_endian = BIGEND;
}
pos = payload.pos;
length = payload.length;
buffer = payload.data;
Expand Down
2 changes: 1 addition & 1 deletion include/fastdds/rtps/common/SerializedPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace rtps {
#define PL_CDR_LE 0x0003

#if FASTDDS_IS_BIG_ENDIAN_TARGET
#define DEFAULT_ENCAPSULATION CDR_LE
#define DEFAULT_ENCAPSULATION CDR_BE
#define PL_DEFAULT_ENCAPSULATION PL_CDR_BE
#else
#define DEFAULT_ENCAPSULATION CDR_LE
Expand Down
11 changes: 11 additions & 0 deletions include/fastdds/rtps/messages/CDRMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ inline bool addParticipantGenericMessage(

///@}

/**
* @brief Skip bytes in serialized buffer
*
* @param msg The CDR message
* @param length The number of bytes to skip
* @return true if skipped, false otherwise
*/
inline bool skip(
CDRMessage_t* msg,
uint32_t length);

} /* namespace CDRMessage */

} /* namespace rtps */
Expand Down
14 changes: 14 additions & 0 deletions include/fastdds/rtps/messages/CDRMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,20 @@ inline bool CDRMessage::readParticipantGenericMessage(
return true;
}

inline bool CDRMessage::skip(
CDRMessage_t* msg,
uint32_t length)
{
// Validate input
bool ret = (msg != nullptr) && (msg->pos + length <= msg->length);
if (ret)
{
// Advance index the number of specified bytes
msg->pos += length;
}
return ret;
}

} // namespace rtps
} // namespace fastrtps
} // namespace eprosima
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/rtps/builtin/liveliness/WLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,9 @@ bool WLP::send_liveliness_message(

if (change != nullptr)
{
change->serializedPayload.encapsulation = (uint16_t)PL_DEFAULT_ENCAPSULATION;
change->serializedPayload.encapsulation = (uint16_t)DEFAULT_ENCAPSULATION;
change->serializedPayload.data[0] = 0;
change->serializedPayload.data[1] = PL_DEFAULT_ENCAPSULATION;
change->serializedPayload.data[1] = DEFAULT_ENCAPSULATION;
change->serializedPayload.data[2] = 0;
change->serializedPayload.data[3] = 0;

Expand Down
Loading