Skip to content

Commit

Permalink
Fix IPv6, SEDP Ports, Simplify Code, and News
Browse files Browse the repository at this point in the history
  • Loading branch information
iguessthislldo committed May 28, 2024
1 parent b547e36 commit 5e07cfb
Show file tree
Hide file tree
Showing 15 changed files with 510 additions and 569 deletions.
33 changes: 33 additions & 0 deletions dds/DCPS/RTPS/MessageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,39 @@ void set_port_mode(const String& key, PortMode value)
TheServiceParticipant->config_store()->set(key.c_str(), value, port_modes);
}

bool set_rtps_multicast_port(
DCPS::NetworkAddress& addr, const char* what,
DDS::UInt16 port_base, DDS::UInt16 offset,
DDS::UInt16 domain, DDS::UInt16 domain_gain)
{
if (addr.get_port_number() == 0) {
DDS::UInt16 port;
if (!get_rtps_port(port, what, port_base, offset, domain, domain_gain)) {
return false;
}
addr.set_port_number(port);
}
return true;
}

bool set_rtps_unicast_port(
DCPS::NetworkAddress& addr, bool& fixed_port,
const char* what, PortMode port_mode,
DDS::UInt16 port_base, DDS::UInt16 offset,
DDS::UInt16 domain, DDS::UInt16 domain_gain,
DDS::UInt16 part, DDS::UInt16 part_gain)
{
fixed_port = addr.get_port_number() > 0 || port_mode != PortMode_Probe;
if (!fixed_port) {
DDS::UInt16 port = 0;
if (!get_rtps_port(port, what, port_base, offset, domain, domain_gain, part, part_gain)) {
return false;
}
addr.set_port_number(port);
}
return true;
}

}
}

Expand Down
14 changes: 14 additions & 0 deletions dds/DCPS/RTPS/MessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,20 @@ PortMode get_port_mode(const String& key, PortMode default_value);
OpenDDS_Rtps_Export
void set_port_mode(const String& key, PortMode value);

OpenDDS_Rtps_Export
bool set_rtps_multicast_port(
DCPS::NetworkAddress& addr, const char* what,
DDS::UInt16 port_base, DDS::UInt16 offset,
DDS::UInt16 domain, DDS::UInt16 domain_gain);

OpenDDS_Rtps_Export
bool set_rtps_unicast_port(
DCPS::NetworkAddress& addr, bool& fixed_port,
const char* what, PortMode port_mode,
DDS::UInt16 port_base, DDS::UInt16 offset,
DDS::UInt16 domain, DDS::UInt16 domain_gain,
DDS::UInt16 part, DDS::UInt16 part_gain);

} // namespace RTPS
} // namespace OpenDDS

Expand Down
128 changes: 14 additions & 114 deletions dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,17 @@ RtpsDiscoveryConfig::dy(DDS::UInt16 sedp_unicast_offset)
sedp_unicast_offset);
}

bool RtpsDiscoveryConfig::spdp_multicast_port(DDS::UInt16& port, DDS::UInt16 domain) const
bool RtpsDiscoveryConfig::set_spdp_multicast_port(DCPS::NetworkAddress& addr,
DDS::DomainId_t domain) const
{
return get_rtps_port(port, "SPDP multicast", pb(), d0(), domain, dg());
return set_rtps_multicast_port(addr, "SPDP multicast", pb(), d0(), domain, dg());
}

bool RtpsDiscoveryConfig::spdp_unicast_port(DDS::UInt16& port, DDS::UInt16 domain, DDS::UInt16 part) const
{
return get_rtps_port(port, "SPDP unicast", pb(), d1(), domain, dg(), part, pg());
}

bool RtpsDiscoveryConfig::sedp_multicast_port(DDS::UInt16& port, DDS::UInt16 domain) const
{
return get_rtps_port(port, "SEDP multicast", pb(), dx(), domain, dg());
}

bool RtpsDiscoveryConfig::sedp_unicast_port(DDS::UInt16& port, DDS::UInt16 domain, DDS::UInt16 part) const
bool RtpsDiscoveryConfig::set_spdp_unicast_port(DCPS::NetworkAddress& addr, bool& fixed_port,
DDS::DomainId_t domain, DDS::UInt16 part_id) const
{
return get_rtps_port(port, "SEDP unicast", pb(), dy(), domain, dg(), part, pg());
return set_rtps_unicast_port(addr, fixed_port, "SPDP unicast", spdp_port_mode(),
pb(), d1(), domain, dg(), part_id, pg());
}

unsigned char
Expand Down Expand Up @@ -385,20 +378,6 @@ RtpsDiscoveryConfig::sedp_local_address() const
DCPS::ConfigStoreImpl::Kind_IPV4);
}

bool RtpsDiscoveryConfig::sedp_unicast_address(
DCPS::NetworkAddress& addr, DDS::DomainId_t domain, DDS::UInt16 part_id) const
{
addr = sedp_local_address();
if (addr.get_port_number() == 0 && sedp_port_mode() == PortMode_Probe) {
DDS::UInt16 port = 0;
if (!sedp_unicast_port(port, domain, part_id)) {
return false;
}
addr.set_port_number(port);
}
return true;
}

void
RtpsDiscoveryConfig::sedp_local_address(const DCPS::NetworkAddress& mi)
{
Expand Down Expand Up @@ -448,15 +427,7 @@ bool RtpsDiscoveryConfig::spdp_unicast_address(DCPS::NetworkAddress& addr, bool&
DDS::DomainId_t domain, DDS::UInt16 part_id) const
{
addr = spdp_local_address();
fixed_port = addr.get_port_number() > 0;
if (!fixed_port && spdp_port_mode() == PortMode_Probe) {
DDS::UInt16 port = 0;
if (!spdp_unicast_port(port, domain, part_id)) {
return false;
}
addr.set_port_number(port);
}
return true;
return set_spdp_unicast_port(addr, fixed_port, domain, part_id);
}

OPENDDS_STRING
Expand Down Expand Up @@ -539,15 +510,7 @@ bool RtpsDiscoveryConfig::spdp_multicast_address(
default_multicast_group(domain),
DCPS::ConfigStoreImpl::Format_Optional_Port,
DCPS::ConfigStoreImpl::Kind_IPV4);

if (addr.get_port_number() == 0) {
DDS::UInt16 port;
if (!spdp_multicast_port(port, domain)) {
return false;
}
addr.set_port_number(port);
}
return true;
return set_spdp_multicast_port(addr, domain);
}

void RtpsDiscoveryConfig::spdp_multicast_address(const DCPS::NetworkAddress& addr)
Expand All @@ -558,23 +521,13 @@ void RtpsDiscoveryConfig::spdp_multicast_address(const DCPS::NetworkAddress& add
DCPS::ConfigStoreImpl::Kind_IPV4);
}

bool RtpsDiscoveryConfig::sedp_multicast_address(
DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const
DCPS::NetworkAddress RtpsDiscoveryConfig::sedp_multicast_address(DDS::DomainId_t domain) const
{
addr = TheServiceParticipant->config_store()->get(
return TheServiceParticipant->config_store()->get(
config_key("SEDP_MULTICAST_ADDRESS").c_str(),
default_multicast_group(domain),
DCPS::ConfigStoreImpl::Format_Optional_Port,
DCPS::ConfigStoreImpl::Kind_IPV4);

if (addr.get_port_number() == 0) {
DDS::UInt16 port;
if (!sedp_multicast_port(port, domain)) {
return false;
}
addr.set_port_number(port);
}
return true;
}

void RtpsDiscoveryConfig::sedp_multicast_address(const DCPS::NetworkAddress& addr)
Expand Down Expand Up @@ -608,17 +561,7 @@ bool RtpsDiscoveryConfig::ipv6_spdp_unicast_address(DCPS::NetworkAddress& addr,
DDS::DomainId_t domain, DDS::UInt16 part_id) const
{
addr = ipv6_spdp_local_address();
fixed_port = addr.get_port_number() > 0;
if (!fixed_port) {
if (spdp_port_mode() == PortMode_Probe) {
DDS::UInt16 port = 0;
if (!spdp_unicast_port(port, domain, part_id)) {
return false;
}
addr.set_port_number(port);
}
}
return true;
return set_spdp_unicast_port(addr, fixed_port, domain, part_id);
}

DCPS::NetworkAddress
Expand All @@ -639,22 +582,6 @@ RtpsDiscoveryConfig::ipv6_sedp_local_address(const DCPS::NetworkAddress& mi)
DCPS::ConfigStoreImpl::Kind_IPV6);
}

bool RtpsDiscoveryConfig::ipv6_sedp_unicast_address(
DCPS::NetworkAddress& addr, DDS::DomainId_t domain, DDS::UInt16 part_id) const
{
addr = ipv6_sedp_local_address();
if (addr.get_port_number() == 0) {
if (sedp_port_mode() == PortMode_Probe) {
DDS::UInt16 port = 0;
if (!sedp_unicast_port(port, domain, part_id)) {
return false;
}
addr.set_port_number(port);
}
}
return true;
}

DCPS::NetworkAddress
RtpsDiscoveryConfig::ipv6_sedp_advertised_local_address() const
{
Expand Down Expand Up @@ -696,18 +623,10 @@ bool RtpsDiscoveryConfig::ipv6_spdp_multicast_address(
{
addr = TheServiceParticipant->config_store()->get(
config_key("IPV6_SPDP_MULTICAST_ADDRESS").c_str(),
ipv6_default_multicast_group(domain),
ipv6_default_multicast_group(),
DCPS::ConfigStoreImpl::Format_Optional_Port,
DCPS::ConfigStoreImpl::Kind_IPV6);

if (addr.get_port_number() == 0) {
DDS::UInt16 port;
if (!spdp_multicast_port(port, domain)) {
return false;
}
addr.set_port_number(port);
}
return true;
return set_spdp_multicast_port(addr, domain);
}

void RtpsDiscoveryConfig::ipv6_spdp_multicast_address(const DCPS::NetworkAddress& addr)
Expand All @@ -718,25 +637,6 @@ void RtpsDiscoveryConfig::ipv6_spdp_multicast_address(const DCPS::NetworkAddress
DCPS::ConfigStoreImpl::Kind_IPV6);
}

bool RtpsDiscoveryConfig::ipv6_sedp_multicast_address(
DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const
{
addr = TheServiceParticipant->config_store()->get(
config_key("IPV6_SEDP_MULTICAST_ADDRESS").c_str(),
ipv6_default_multicast_group(domain),
DCPS::ConfigStoreImpl::Format_Optional_Port,
DCPS::ConfigStoreImpl::Kind_IPV6);

if (addr.get_port_number() == 0) {
DDS::UInt16 port;
if (!sedp_multicast_port(port, domain)) {
return false;
}
addr.set_port_number(port);
}
return true;
}

void RtpsDiscoveryConfig::ipv6_sedp_multicast_address(const DCPS::NetworkAddress& addr)
{
TheServiceParticipant->config_store()->set(config_key("IPV6_SEDP_MULTICAST_ADDRESS").c_str(),
Expand Down
17 changes: 5 additions & 12 deletions dds/DCPS/RTPS/RtpsDiscoveryConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ class OpenDDS_Rtps_Export RtpsDiscoveryConfig : public OpenDDS::DCPS::RcObject {
DDS::UInt16 dy() const;
void dy(DDS::UInt16 sedp_unicast_offset);

bool spdp_multicast_port(DDS::UInt16& port, DDS::UInt16 domain) const;
bool spdp_unicast_port(DDS::UInt16& port, DDS::UInt16 domain, DDS::UInt16 part) const;
bool sedp_multicast_port(DDS::UInt16& port, DDS::UInt16 domain) const;
bool sedp_unicast_port(DDS::UInt16& port, DDS::UInt16 domain, DDS::UInt16 part) const;
bool set_spdp_multicast_port(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const;
bool set_spdp_unicast_port(DCPS::NetworkAddress& addr, bool& fixed_port,
DDS::DomainId_t domain, DDS::UInt16 part_id) const;

unsigned char ttl() const;
void ttl(unsigned char time_to_live);
Expand All @@ -103,9 +102,6 @@ class OpenDDS_Rtps_Export RtpsDiscoveryConfig : public OpenDDS::DCPS::RcObject {
DCPS::NetworkAddress sedp_local_address() const;
void sedp_local_address(const DCPS::NetworkAddress& mi);

bool sedp_unicast_address(
DCPS::NetworkAddress& addr, DDS::DomainId_t domain, DDS::UInt16 part_id) const;

DCPS::NetworkAddress sedp_advertised_local_address() const;
void sedp_advertised_local_address(const DCPS::NetworkAddress& mi);

Expand All @@ -127,7 +123,7 @@ class OpenDDS_Rtps_Export RtpsDiscoveryConfig : public OpenDDS::DCPS::RcObject {
bool spdp_multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const;
void spdp_multicast_address(const DCPS::NetworkAddress& addr);

bool sedp_multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const;
DCPS::NetworkAddress sedp_multicast_address(DDS::DomainId_t domain) const;
void sedp_multicast_address(const DCPS::NetworkAddress& addr);

#ifdef ACE_HAS_IPV6
Expand All @@ -140,9 +136,6 @@ class OpenDDS_Rtps_Export RtpsDiscoveryConfig : public OpenDDS::DCPS::RcObject {
DCPS::NetworkAddress ipv6_sedp_local_address() const;
void ipv6_sedp_local_address(const DCPS::NetworkAddress& mi);

bool ipv6_sedp_unicast_address(
DCPS::NetworkAddress& addr, DDS::DomainId_t domain, DDS::UInt16 part_id) const;

DCPS::NetworkAddress ipv6_sedp_advertised_local_address() const;
void ipv6_sedp_advertised_local_address(const DCPS::NetworkAddress& mi);

Expand All @@ -152,7 +145,7 @@ class OpenDDS_Rtps_Export RtpsDiscoveryConfig : public OpenDDS::DCPS::RcObject {
bool ipv6_spdp_multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const;
void ipv6_spdp_multicast_address(const DCPS::NetworkAddress& addr);

bool ipv6_sedp_multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const;
DCPS::NetworkAddress ipv6_sedp_multicast_address(DDS::DomainId_t domain) const;
void ipv6_sedp_multicast_address(const DCPS::NetworkAddress& addr);
#endif

Expand Down
34 changes: 18 additions & 16 deletions dds/DCPS/RTPS/Sedp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ Sedp::init(const GUID_t& guid,
DCPS::TransportRegistry::DEFAULT_INST_PREFIX +
OPENDDS_STRING("_SEDPTransportInst_") + key + domainStr,
"rtps_udp");
DCPS::RtpsUdpInst_rch inst = DCPS::static_rchandle_cast<DCPS::RtpsUdpInst>(transport_inst_);

// Be careful to not call any function that causes the transport be
// to created before the configuration is complete.
Expand All @@ -439,31 +438,27 @@ Sedp::init(const GUID_t& guid,
transport_inst_->receive_preallocated_message_blocks(disco.config()->sedp_receive_preallocated_message_blocks());
transport_inst_->receive_preallocated_data_blocks(disco.config()->sedp_receive_preallocated_data_blocks());

set_port_mode(transport_inst_->config_key("PORT_MODE").c_str(), disco.config()->sedp_port_mode());
config_store_->set_int32(transport_inst_->config_key("PB").c_str(), disco.config()->pb());
config_store_->set_int32(transport_inst_->config_key("DG").c_str(), disco.config()->dg());
config_store_->set_int32(transport_inst_->config_key("PG").c_str(), disco.config()->pg());
config_store_->set_int32(transport_inst_->config_key("D2").c_str(), disco.config()->dx());
config_store_->set_int32(transport_inst_->config_key("D3").c_str(), disco.config()->dy());

const bool sedp_multicast = disco.sedp_multicast();
config_store_->set_boolean(transport_inst_->config_key("USE_MULTICAST").c_str(), sedp_multicast);
if (sedp_multicast) {
DCPS::NetworkAddress mc_addr;
if (!disco.config()->sedp_multicast_address(mc_addr, domainId)) {
return DDS::RETCODE_ERROR;
}
config_store_->set(transport_inst_->config_key("MULTICAST_GROUP_ADDRESS").c_str(),
mc_addr,
disco.config()->sedp_multicast_address(domainId),
ConfigStoreImpl::Format_Optional_Port,
ConfigStoreImpl::Kind_IPV4);

config_store_->set_uint32(transport_inst_->config_key("TTL").c_str(), disco.ttl());
config_store_->set(transport_inst_->config_key("MULTICAST_INTERFACE").c_str(), disco.multicast_interface());
}

inst->port_mode(disco.config()->sedp_port_mode());
inst->pb(disco.config()->pb());
inst->dg(disco.config()->dg());
inst->pg(disco.config()->pg());
inst->d2(disco.config()->dx());
inst->d3(disco.config()->dy());
inst->d3(disco.config()->dy());

inst->init_participant_port_id(ipv4_participant_port_id);
config_store_->set_int32(
transport_inst_->config_key("INIT_PARTICIPANT_PORT_ID").c_str(), ipv4_participant_port_id);
config_store_->set(transport_inst_->config_key("LOCAL_ADDRESS").c_str(),
disco.config()->sedp_local_address(),
ConfigStoreImpl::Format_Required_Port,
Expand All @@ -473,7 +468,8 @@ Sedp::init(const GUID_t& guid,
ConfigStoreImpl::Format_Required_Port,
ConfigStoreImpl::Kind_IPV4);
#ifdef ACE_HAS_IPV6
inst->ipv6_init_participant_port_id(ipv6_participant_port_id);
config_store_->set_int32(
transport_inst_->config_key("IPV6_INIT_PARTICIPANT_PORT_ID").c_str(), ipv6_participant_port_id);
config_store_->set(transport_inst_->config_key("IPV6_LOCAL_ADDRESS").c_str(),
disco.config()->ipv6_sedp_local_address(),
ConfigStoreImpl::Format_Required_Port,
Expand Down Expand Up @@ -520,6 +516,12 @@ Sedp::init(const GUID_t& guid,
const_cast<bool&>(use_xtypes_complete_) = disco.use_xtypes_complete();

reactor_task_ = transport_inst_->reactor_task(domainId, 0);
if (!reactor_task_) {
if (log_level >= LogLevel::Error) {
ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: Sedp::init: SEDP transport initialization failed\n"));
}
return DDS::RETCODE_ERROR;
}
// One should assume that the transport is configured after this
// point. Changes to transport_inst_ or rtps_inst after this line
// may not be reflected.
Expand Down
2 changes: 1 addition & 1 deletion dds/DCPS/RTPS/Spdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3459,7 +3459,7 @@ void Spdp::SpdpTransport::set_unicast_socket_opts(
throw std::runtime_error("failed to get address from socket");
}
port = addr.get_port_number();
const bool ipv4 = addr.get_type () == AF_INET;
const bool ipv4 = addr.get_type() == AF_INET;

if (DCPS::DCPS_debug_level > 3) {
ACE_DEBUG((LM_DEBUG,
Expand Down
Loading

0 comments on commit 5e07cfb

Please sign in to comment.