Skip to content

Commit

Permalink
Merge pull request OpenDDS#4710 from mitza-oci/spdp-infodst
Browse files Browse the repository at this point in the history
Parse InfoDestinationSubmessages in incoming SPDP messages
  • Loading branch information
mitza-oci committed Jun 26, 2024
2 parents 91ec626 + cc9e6f9 commit e0cd8c8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
33 changes: 18 additions & 15 deletions dds/DCPS/RTPS/Spdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,8 @@ Spdp::SpdpTransport::handle_input(ACE_HANDLE h)
message.hdr = header;
}

DCPS::GuidPrefix_t destinationGuidPrefix = {0};

while (buff_.length() > 3) {
const char subm = buff_.rd_ptr()[0], flags = buff_.rd_ptr()[1];
ser.swap_bytes((flags & FLAG_E) != ACE_CDR_BYTE_ORDER);
Expand All @@ -3122,9 +3124,11 @@ Spdp::SpdpTransport::handle_input(ACE_HANDLE h)
append_submessage(message, data);
}

if (data.writerId != ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER) {
// Not our message: this could be the same multicast group used
// for SEDP and other traffic.
if (data.writerId != ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER ||
(data.readerId != ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER &&
data.readerId != ENTITYID_UNKNOWN) ||
(!DCPS::equal_guid_prefixes(destinationGuidPrefix, hdr_.guidPrefix) &&
!DCPS::equal_guid_prefixes(destinationGuidPrefix, DCPS::GUIDPREFIX_UNKNOWN))) {
break;
}

Expand Down Expand Up @@ -3164,22 +3168,21 @@ Spdp::SpdpTransport::handle_input(ACE_HANDLE h)
break;
}
case INFO_DST: {
if (DCPS::transport_debug.log_messages) {
InfoDestinationSubmessage sm;
if (!(ser >> sm)) {
if (DCPS::DCPS_debug_level > 0) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Spdp::SpdpTransport::handle_input() - ")
ACE_TEXT("failed to deserialize INFO_DST header for SPDP\n")));
}
return 0;
InfoDestinationSubmessage sm;
if (!(ser >> sm)) {
if (DCPS::DCPS_debug_level > 0) {
ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: Spdp::SpdpTransport::handle_input() - "
"failed to deserialize INFO_DST submessage for SPDP\n"));
}
submessageLength = sm.smHeader.submessageLength;
return 0;
}
assign(destinationGuidPrefix, sm.guidPrefix);
submessageLength = sm.smHeader.submessageLength;
if (DCPS::transport_debug.log_messages) {
append_submessage(message, sm);
break;
}
break;
}
// fallthrough
default:
SubmessageHeader smHeader;
if (!(ser >> smHeader)) {
Expand Down
6 changes: 6 additions & 0 deletions docs/news.d/spdp-infodst.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. news-prs: 4710
.. news-start-section: Additions
- The Info Destination submessage is now used if present in incoming SPDP messages

.. news-end-section
43 changes: 40 additions & 3 deletions tests/transport/spdp/spdp_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct TestParticipant: ACE_Event_Handler {
: sock_(sock)
, recv_mb_(64 * 1024)
{
assign(destination_prefix_, GUIDPREFIX_UNKNOWN);
const Header hdr = {
{'R', 'T', 'P', 'S'}, PROTOCOLVERSION, VENDORID_OPENDDS,
{prefix[0], prefix[1], prefix[2], prefix[3], prefix[4], prefix[5],
Expand Down Expand Up @@ -121,6 +122,11 @@ struct TestParticipant: ACE_Event_Handler {
return true;
}

void set_infodst(const GuidPrefix_t& dst)
{
assign(destination_prefix_, dst);
}

bool send_data(const OpenDDS::DCPS::EntityId_t& writer,
const SequenceNumber_t& seq, OpenDDS::RTPS::ParameterList& plist, const ACE_INET_Addr& send_to)
{
Expand All @@ -132,19 +138,36 @@ struct TestParticipant: ACE_Event_Handler {
};

const Encoding encoding(Encoding::KIND_XCDR1, OpenDDS::DCPS::ENDIAN_LITTLE);

InfoDestinationSubmessage idst = { {INFO_DST, FLAG_E, 0}, {0} };
size_t size = 0;
serialized_size(encoding, size, hdr_);
if (!equal_guid_prefixes(destination_prefix_, GUIDPREFIX_UNKNOWN)) {
serialized_size(encoding, size, idst);
}
serialized_size(encoding, size, ds);
primitive_serialized_size_ulong(encoding, size);
serialized_size(encoding, size, plist);

ACE_Message_Block mb(size);
Serializer ser(&mb, encoding);

if (!(ser << hdr_)) {
ACE_DEBUG((LM_DEBUG, "ERROR: failed to serialize message headers\n"));
return false;
}

if (!equal_guid_prefixes(destination_prefix_, GUIDPREFIX_UNKNOWN)) {
assign(idst.guidPrefix, destination_prefix_);
assign(destination_prefix_, GUIDPREFIX_UNKNOWN);
if (!(ser << idst)) {
ACE_DEBUG((LM_DEBUG, "ERROR: failed to serialize InfoDestinationSubmessage\n"));
return false;
}
}

const EncapsulationHeader encap(encoding, MUTABLE);
if (!(ser << hdr_ && ser << ds && ser << encap)) {
ACE_DEBUG((LM_DEBUG, "ERROR: failed to serialize headers\n"));
if (!(ser << ds && ser << encap)) {
ACE_DEBUG((LM_DEBUG, "ERROR: failed to serialize submessage headers\n"));
return false;
}

Expand Down Expand Up @@ -225,6 +248,7 @@ struct TestParticipant: ACE_Event_Handler {
ACE_SOCK_Dgram& sock_;
Header hdr_;
ACE_Message_Block recv_mb_;
GuidPrefix_t destination_prefix_;
};


Expand Down Expand Up @@ -426,6 +450,19 @@ bool run_test()
return false;
}

ACE_DEBUG((LM_DEBUG, "Info Destination Test\n"));
part1.set_infodst(gp); // The next send_data will insert an InfoDestination submessage before Data.
// Using the GuidPrefix 'gp' sets the destination GUID to part1's own guid, so it won't be read by 'spdp'.
if (!part1.send_data(test_part_guid.entityId, seq, plist, send_addr)) {
ACE_DEBUG((LM_DEBUG, "ERROR: Info Destination test couldn't send\n"));
return false;
}
reactor_wait();
if (spdp_friend.check_for_participant(false)) {
ACE_DEBUG((LM_DEBUG, "ERROR: Info Destination test resulted in discovery when it shouldn't\n"));
return false;
}

// Test for performing sequence reset.
ACE_DEBUG((LM_DEBUG, ACE_TEXT("Basic Reset Test\n")));
for (seq = first_seq; seq.low < 8;) {
Expand Down

0 comments on commit e0cd8c8

Please sign in to comment.