Skip to content

Commit

Permalink
More Predictable Port Usage in RTPS
Browse files Browse the repository at this point in the history
- Added `SedpPortMode=probe` to make it make it possible to predict what
  ports the unicast SEDP sockets use.
- Added `SpdpPortMode` which deprecates `SpdpRequestRandomPort`.
- Added `SpdpMulticastAddress`, `Ipv4SpdpMulticastAddress`,
  `SedpMulticastAddress`, and `Ipv4SedpMulticastAddress` to set the
  multicast addresses and ports separately on SPDP and SEDP.
- Calculated ports are now checked if they would overflow.
- Remove need for sentinel in `EnumList` arrays for `ConfigStore`.
  • Loading branch information
iguessthislldo committed May 21, 2024
1 parent 755adff commit b4a030c
Show file tree
Hide file tree
Showing 16 changed files with 1,061 additions and 300 deletions.
20 changes: 10 additions & 10 deletions dds/DCPS/ConfigStoreImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ class OpenDDS_Dcps_Export ConfigStoreImpl : public ConfigStore {
StringList get(const char* key,
const StringList& value) const;

template<typename T>
template<typename T, size_t count>
T get(const char* key,
T value,
const EnumList<T> decoder[])
const EnumList<T> (&decoder)[count])
{
bool found = false;
String value_as_string;
for (size_t idx = 0; decoder[idx].name; ++idx) {
for (size_t idx = 0; idx < count; ++idx) {
if (decoder[idx].value == value) {
value_as_string = decoder[idx].name;
found = true;
Expand All @@ -188,7 +188,7 @@ class OpenDDS_Dcps_Export ConfigStoreImpl : public ConfigStore {
}

const String actual = get(key, value_as_string);
for (size_t idx = 0; decoder[idx].name; ++idx) {
for (size_t idx = 0; idx < count; ++idx) {
if (decoder[idx].name == actual) {
return decoder[idx].value;
}
Expand All @@ -204,14 +204,14 @@ class OpenDDS_Dcps_Export ConfigStoreImpl : public ConfigStore {
return value;
}

template<typename T>
template<typename T, size_t count>
void set(const char* key,
T value,
const EnumList<T> decoder[])
const EnumList<T> (&decoder)[count])
{
bool found = false;
String value_as_string;
for (size_t idx = 0; decoder[idx].name; ++idx) {
for (size_t idx = 0; idx < count; ++idx) {
if (decoder[idx].value == value) {
value_as_string = decoder[idx].name;
found = true;
Expand All @@ -232,15 +232,15 @@ class OpenDDS_Dcps_Export ConfigStoreImpl : public ConfigStore {
set(key, value_as_string);
}

template<typename T>
template<typename T, size_t count>
void set(const char* key,
const String& value,
const EnumList<T> decoder[])
const EnumList<T> (&decoder)[count])
{
bool found = false;
// Sanity check.
String value_as_string;
for (size_t idx = 0; decoder[idx].name; ++idx) {
for (size_t idx = 0; idx < count; ++idx) {
if (value == decoder[idx].name) {
set(key, value);
found = true;
Expand Down
1 change: 0 additions & 1 deletion dds/DCPS/NetworkAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "NetworkAddress.h"

#include "Hash.h"
#include "LogAddr.h"

#include <cstring>

Expand Down
39 changes: 39 additions & 0 deletions dds/DCPS/RTPS/MessageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "MessageTypes.h"

#include <dds/DCPS/Time_Helper.h>
#include <dds/DCPS/debug.h>

#include <dds/OpenddsDcpsExtTypeSupportImpl.h>

OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
Expand All @@ -16,6 +18,8 @@ namespace OpenDDS {
namespace RTPS {

using DCPS::Encoding;
using DCPS::LogLevel;
using DCPS::log_level;

const DCPS::Encoding& get_locators_encoding()
{
Expand Down Expand Up @@ -134,6 +138,41 @@ bool bitmapNonEmpty(const SequenceNumberSet& snSet)
return (bool)(snSet.bitmap[last_index] & mask);
}

bool get_rtps_port(DDS::UInt16& port_result, const char* what,
DDS::UInt16 port_base, DDS::UInt16 offset,
DDS::UInt16 domain, DDS::UInt16 domain_gain,
DDS::UInt16 part, DDS::UInt16 part_gain)
{
const DDS::UInt32 port = static_cast<DDS::UInt32>(port_base) +
domain * domain_gain + part * part_gain + offset;
ACE_DEBUG((LM_DEBUG, "HERE %C %u + %u * %u + %u * %u + %u = %u\n", what, port_base, domain, domain_gain, part, part_gain, offset, port));
if (port > 65535) {
if (log_level >= LogLevel::Error) {
ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: rtps_port: %C port %u is too high\n", what, port));
}
return false;
}
port_result = static_cast<DDS::UInt16>(port);
return true;
}

namespace {
const DCPS::EnumList<PortMode> port_modes[] = {
{PortMode_System, "system"},
{PortMode_Probe, "probe"}
};
};

PortMode get_port_mode(const String& key, PortMode default_value)
{
return TheServiceParticipant->config_store()->get(key.c_str(), default_value, port_modes);
}

void set_port_mode(const String& key, PortMode value)
{
TheServiceParticipant->config_store()->set(key.c_str(), value, port_modes);
}

}
}

Expand Down
32 changes: 32 additions & 0 deletions dds/DCPS/RTPS/MessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,38 @@ handle_to_octets(DDS::Security::NativeCryptoHandle handle)
}
#endif

// Default values for spec-defined parameters for determining what ports RTPS
// uses.
const DDS::UInt16 default_port_base = 7400; // (PB)
const DDS::UInt16 default_domain_gain = 250; // (DG)
const DDS::UInt16 default_part_gain = 2; // (PG)
const DDS::UInt16 default_spdp_multicast_offset = 0; // (D0)
const DDS::UInt16 default_spdp_unicast_offset = 10; // (D1)
const DDS::UInt16 default_user_multicast_offset = 1; // (D2)
const DDS::UInt16 default_user_unicast_offset = 11; // (D3)

// Default values for OpenDDS-specific parameters for determining what ports
// RTPS uses.
const DDS::UInt16 default_sedp_multicast_offset = 2; // (DX)
const DDS::UInt16 default_sedp_unicast_offset = 12; // (DY)

OpenDDS_Rtps_Export
bool get_rtps_port(DDS::UInt16& port_result, const char* what,
DDS::UInt16 port_base, DDS::UInt16 offset,
DDS::UInt16 domain, DDS::UInt16 domain_gain,
DDS::UInt16 part = 0, DDS::UInt16 part_gain = 0);

enum PortMode {
PortMode_System,
PortMode_Probe
};

OpenDDS_Rtps_Export
PortMode get_port_mode(const String& key, PortMode default_value);

OpenDDS_Rtps_Export
void set_port_mode(const String& key, PortMode value);

} // namespace RTPS
} // namespace OpenDDS

Expand Down
Loading

0 comments on commit b4a030c

Please sign in to comment.