diff --git a/dds/DCPS/RTPS/MessageUtils.cpp b/dds/DCPS/RTPS/MessageUtils.cpp index 13a805c3504..95cbda5d061 100644 --- a/dds/DCPS/RTPS/MessageUtils.cpp +++ b/dds/DCPS/RTPS/MessageUtils.cpp @@ -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; +} + } } diff --git a/dds/DCPS/RTPS/MessageUtils.h b/dds/DCPS/RTPS/MessageUtils.h index d52b550c659..c3e79ab4aff 100644 --- a/dds/DCPS/RTPS/MessageUtils.h +++ b/dds/DCPS/RTPS/MessageUtils.h @@ -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 diff --git a/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp b/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp index 1daf01715a8..48234ab0f40 100644 --- a/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp +++ b/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp @@ -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 @@ -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) { @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 { @@ -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) @@ -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(), diff --git a/dds/DCPS/RTPS/RtpsDiscoveryConfig.h b/dds/DCPS/RTPS/RtpsDiscoveryConfig.h index b4b248e2228..6708d0cf334 100644 --- a/dds/DCPS/RTPS/RtpsDiscoveryConfig.h +++ b/dds/DCPS/RTPS/RtpsDiscoveryConfig.h @@ -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); @@ -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); @@ -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 @@ -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); @@ -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 diff --git a/dds/DCPS/RTPS/Sedp.cpp b/dds/DCPS/RTPS/Sedp.cpp index 49f66f6d44e..1f64bcbac4c 100644 --- a/dds/DCPS/RTPS/Sedp.cpp +++ b/dds/DCPS/RTPS/Sedp.cpp @@ -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(transport_inst_); // Be careful to not call any function that causes the transport be // to created before the configuration is complete. @@ -439,15 +438,18 @@ 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); @@ -455,15 +457,8 @@ Sedp::init(const GUID_t& guid, 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, @@ -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, @@ -520,6 +516,12 @@ Sedp::init(const GUID_t& guid, const_cast(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. diff --git a/dds/DCPS/RTPS/Spdp.cpp b/dds/DCPS/RTPS/Spdp.cpp index 35ba9d0d7b2..b0af3fdb0d1 100644 --- a/dds/DCPS/RTPS/Spdp.cpp +++ b/dds/DCPS/RTPS/Spdp.cpp @@ -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, diff --git a/dds/DCPS/transport/rtps_udp/RtpsUdpDataLink.cpp b/dds/DCPS/transport/rtps_udp/RtpsUdpDataLink.cpp index e7ed59c9817..ce35897bd5f 100644 --- a/dds/DCPS/transport/rtps_udp/RtpsUdpDataLink.cpp +++ b/dds/DCPS/transport/rtps_udp/RtpsUdpDataLink.cpp @@ -443,7 +443,7 @@ void RtpsUdpDataLink::on_data_available(RcHandlemulticast_group_address(tport->domain()), multicast_socket_ #ifdef ACE_HAS_IPV6 - , cfg->ipv6_multicast_group_address(), + , cfg->ipv6_multicast_group_address(tport->domain()), ipv6_multicast_socket_ #endif ); diff --git a/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp b/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp index a965d753c64..c5f71fb30ba 100644 --- a/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp +++ b/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp @@ -304,14 +304,16 @@ DDS::UInt16 RtpsUdpInst::d3() const RTPS::default_user_unicast_offset); } -bool RtpsUdpInst::multicast_port(DDS::UInt16& port, DDS::UInt16 domain) const +bool RtpsUdpInst::set_multicast_port(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const { - return RTPS::get_rtps_port(port, "RTPS/UDP multicast", pb(), d2(), domain, dg()); + return RTPS::set_rtps_multicast_port(addr, "RTPS/UDP multicast", pb(), d2(), domain, dg()); } -bool RtpsUdpInst::unicast_port(DDS::UInt16& port, DDS::UInt16 domain, DDS::UInt16 part) const +bool RtpsUdpInst::set_unicast_port(DCPS::NetworkAddress& addr, bool& fixed_port, + DDS::DomainId_t domain, DDS::UInt16 part_id) const { - return RTPS::get_rtps_port(port, "RTPS/UDP unicast", pb(), d3(), domain, dg(), part, pg()); + return RTPS::set_rtps_unicast_port(addr, fixed_port, "RTPS/UDP unicast", port_mode(), + pb(), d3(), domain, dg(), part_id, pg()); } void @@ -336,13 +338,10 @@ bool RtpsUdpInst::multicast_address(DCPS::NetworkAddress& na, DDS::DomainId_t do NetworkAddress(0, "239.255.0.2"), ConfigStoreImpl::Format_Optional_Port, ConfigStoreImpl::Kind_IPV4); - DDS::UInt16 default_port = 0; - if (!multicast_port(default_port, domain)) { + if (!set_multicast_port(na, domain)) { return false; } - if (na.get_port_number() == 0) { - na.set_port_number(default_port); - } + const DDS::UInt16 default_port = na.get_port_number(); const NetworkAddress na_original = na; if (is_template()) { @@ -448,15 +447,7 @@ bool RtpsUdpInst::unicast_address(DCPS::NetworkAddress& addr, bool& fixed_port, DDS::DomainId_t domain, DDS::UInt16 part_id) const { addr = local_address(); - fixed_port = addr.get_port_number() > 0; - if (!fixed_port && port_mode() == RTPS::PortMode_Probe) { - DDS::UInt16 port; - if (!unicast_port(port, domain, part_id)) { - return false; - } - addr.set_port_number(port); - } - return true; + return set_unicast_port(addr, fixed_port, domain, part_id); } void @@ -496,19 +487,11 @@ RtpsUdpInst::ipv6_multicast_group_address(DDS::DomainId_t domain) const bool RtpsUdpInst::ipv6_multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const { - NetworkAddress addr = TheServiceParticipant->config_store()->get( + addr = TheServiceParticipant->config_store()->get( config_key("IPV6_MULTICAST_GROUP_ADDRESS").c_str(), NetworkAddress(0, "FF03::2"), ConfigStoreImpl::Format_Optional_Port, ConfigStoreImpl::Kind_IPV6); - - if (na.get_port_number() == 0) { - DDS::UInt16 default_port = 0; - if (!multicast_port(default_port, domain)) { - return false; - } - na.set_port_number(default_port); - } - return + return set_multicast_port(addr, domain); } void RtpsUdpInst::ipv6_init_participant_port_id(DDS::UInt16 part_id) @@ -545,15 +528,7 @@ bool RtpsUdpInst::ipv6_unicast_address(DCPS::NetworkAddress& addr, bool& fixed_p DDS::DomainId_t domain, DDS::UInt16 part_id) const { addr = ipv6_local_address(); - fixed_port = addr.get_port_number() > 0; - if (!fixed_port && port_mode() == RTPS::PortMode_Probe) { - DDS::UInt16 port; - if (!unicast_port(port, domain, part_id)) { - return false; - } - addr.set_port_number(port); - } - return true; + return set_unicast_port(addr, fixed_port, domain, part_id); } void @@ -696,7 +671,7 @@ RtpsUdpInst::populate_locator(TransportLocator& info, address_to_locator(locators[idx++], multicast_group_addr.to_addr()); } #ifdef ACE_HAS_IPV6 - const NetworkAddress ipv6_multicast_group_addr = ipv6_multicast_group_address(); + const NetworkAddress ipv6_multicast_group_addr = ipv6_multicast_group_address(domain); if ((flags & CONNINFO_MULTICAST) && use_multicast() && ipv6_multicast_group_addr != NetworkAddress::default_IPV6) { grow(locators); address_to_locator(locators[idx++], ipv6_multicast_group_addr.to_addr()); diff --git a/dds/DCPS/transport/rtps_udp/RtpsUdpInst.h b/dds/DCPS/transport/rtps_udp/RtpsUdpInst.h index 5c39013a8a9..01a5094f976 100644 --- a/dds/DCPS/transport/rtps_udp/RtpsUdpInst.h +++ b/dds/DCPS/transport/rtps_udp/RtpsUdpInst.h @@ -114,8 +114,9 @@ class OpenDDS_Rtps_Udp_Export RtpsUdpInst : public TransportInst { void d3(DDS::UInt16 unicast_offset); DDS::UInt16 d3() const; - bool multicast_port(DDS::UInt16& port, DDS::UInt16 domain) const; - bool unicast_port(DDS::UInt16& port, DDS::UInt16 domain, DDS::UInt16 part) const; + bool set_multicast_port(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const; + bool set_unicast_port(DCPS::NetworkAddress& addr, bool& fixed_port, + DDS::DomainId_t domain, DDS::UInt16 part_id) const; bool multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const; void multicast_group_address(const NetworkAddress& addr); @@ -135,7 +136,7 @@ class OpenDDS_Rtps_Udp_Export RtpsUdpInst : public TransportInst { #ifdef ACE_HAS_IPV6 bool ipv6_multicast_address(DCPS::NetworkAddress& addr, DDS::DomainId_t domain) const; void ipv6_multicast_group_address(const NetworkAddress& addr); - NetworkAddress ipv6_multicast_group_address() const; + NetworkAddress ipv6_multicast_group_address(DDS::DomainId_t domain) const; void ipv6_init_participant_port_id(DDS::UInt16 part_id); DDS::UInt16 ipv6_init_participant_port_id() const; diff --git a/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.cpp b/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.cpp index 097fb6a4665..6c77cb1134e 100644 --- a/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.cpp +++ b/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.cpp @@ -513,40 +513,69 @@ RtpsUdpTransport::append_transport_statistics(TransportStatisticsSequence& seq) } bool RtpsUdpTransport::open_socket( - const RtpsUdpInst_rch& config, ACE_SOCK_Dgram& sock, int protocol, DDS::UInt16 part_port_id, - NetworkAddress& actual, bool& fail) + const RtpsUdpInst_rch& config, ACE_SOCK_Dgram& sock, int protocol, ACE_INET_Addr& actual) { - fail = true; const bool ipv4 = protocol == PF_INET; + const DDS::UInt16 init_part_port_id = +#ifdef ACE_HAS_IPV6 + ipv4 ? config->init_participant_port_id() : config->ipv6_init_participant_port_id(); +#else + config->init_participant_port_id(); +#endif NetworkAddress address; bool fixed_port; - if (ipv4) { - if (!config->unicast_address(address, fixed_port, domain_, part_port_id)) { + DDS::UInt16 part_port_id = init_part_port_id; + while (true) { +#ifdef ACE_HAS_IPV6 + if (ipv4) { +#endif + if (!config->unicast_address(address, fixed_port, domain_, part_port_id)) { + return false; + } +#ifdef ACE_HAS_IPV6 + } else if (!config->ipv6_unicast_address(address, fixed_port, domain_, part_port_id)) { return false; } -#ifdef ACE_HAS_IPV6 - } else if (!config->ipv6_unicast_address(address, fixed_port, domain_, part_port_id)) { - return false; #endif - } - if (sock.open(address.to_addr(), protocol) != 0) { + if (sock.open(address.to_addr(), protocol) == 0) { + break; + } + if (fixed_port) { if (log_level >= LogLevel::Error) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: RtpsUdpTransport::open_socket: " "failed to open unicast %C socket for %C: %m\n", ipv4 ? "IPv4" : "IPv6", LogAddr(address).c_str())); } + return false; + } else { if (DCPS::DCPS_debug_level > 3) { ACE_DEBUG((LM_DEBUG, "(%P|%t) RtpsUdpTransport::open_socket: " "failed to open unicast %C socket for %C: %m, trying next participant ID...\n", ipv4 ? "IPv4" : "IPv6", LogAddr(address).c_str())); } - fail = false; + + ++part_port_id; + + if (part_port_id == init_part_port_id) { + if (log_level >= LogLevel::Error) { + ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: RtpsUdpTransport::open_socket: " + "could not find a free %C unicast port\n", + ipv4 ? "IPv4" : "IPv6")); + } + return false; + } } - return false; + } + + if (DCPS::DCPS_debug_level > 3) { + ACE_DEBUG((LM_DEBUG, + "(%P|%t) RtpsUdpTransport::open_socket: " + "opened %C unicast socket %d for %C\n", + ipv4 ? "IPv4" : "IPv6", sock.get_handle(), LogAddr(address).c_str())); } #ifdef ACE_WIN32 @@ -561,8 +590,7 @@ bool RtpsUdpTransport::open_socket( } #endif - ACE_INET_Addr ace_actual; - if (sock.get_local_addr(ace_actual) != 0) { + if (sock.get_local_addr(actual) != 0) { if (log_level >= LogLevel::Error) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: RtpsUdpTransport::open_socket: " "failed to get actual address from %C socket for %C: %m\n", @@ -570,7 +598,6 @@ bool RtpsUdpTransport::open_socket( } return false; } - actual = ace_actual; if (!set_recvpktinfo(sock, ipv4)) { if (log_level >= LogLevel::Error) { @@ -581,7 +608,6 @@ bool RtpsUdpTransport::open_socket( return false; } - fail = false; return true; } @@ -598,40 +624,15 @@ RtpsUdpTransport::configure_i(const RtpsUdpInst_rch& config) // detect and report errors during DataReader/Writer setup instead // of during association. - bool error = false; - const DDS::UInt16 init_part_port_id4 = config->init_participant_port_id(); - DDS::UInt16 part_port_id4 = init_part_port_id4; - NetworkAddress actual4; - while (!open_socket(config, unicast_socket_, PF_INET, part_port_id4, actual4, error) && !error) { - ++part_port_id4; - if (part_port_id4 == init_part_port_id4) { - if (log_level >= LogLevel::Error) { - ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: RtpsUdpTransport::configure_i: " - "could not find a free IPv4 unicast port\n")); - } - return false; - } - } - if (error) { + ACE_INET_Addr actual4; + if (!open_socket(config, unicast_socket_, PF_INET, actual4)) { return false; } config->actual_local_address_ = actual4; #ifdef ACE_HAS_IPV6 - const DDS::UInt16 init_part_port_id6 = config->ipv6_init_participant_port_id(); - DDS::UInt16 part_port_id6 = init_part_port_id6; - NetworkAddress actual6; - while (!open_socket(config, ipv6_unicast_socket_, PF_INET6, part_port_id, actual6, error) && !error) { - ++part_port_id6; - if (part_port_id6 == init_part_port_id6) { - if (log_level >= LogLevel::Error) { - ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: RtpsUdpTransport::configure_i: " - "could not find a free IPv6 unicast port\n")); - } - return false; - } - } - if (error) { + ACE_INET_Addr actual6; + if (!open_socket(config, ipv6_unicast_socket_, PF_INET6, actual6)) { return false; } NetworkAddress temp(actual6); diff --git a/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.h b/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.h index 197ea73e53d..4e8e49ceb06 100644 --- a/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.h +++ b/dds/DCPS/transport/rtps_udp/RtpsUdpTransport.h @@ -289,8 +289,7 @@ class OpenDDS_Rtps_Udp_Export RtpsUdpTransport : public TransportImpl, public Co bool association_failed); bool open_socket( - const RtpsUdpInst_rch& config, ACE_SOCK_Dgram& sock, int protocol, DDS::UInt16 part_port_id, - NetworkAddress& actual, bool& fail); + const RtpsUdpInst_rch& config, ACE_SOCK_Dgram& sock, int protocol, ACE_INET_Addr& actual); bool configure_i(const RtpsUdpInst_rch& config); diff --git a/docs/devguide/run_time_configuration.rst b/docs/devguide/run_time_configuration.rst index 22c5d92e908..d56c4ad6139 100644 --- a/docs/devguide/run_time_configuration.rst +++ b/docs/devguide/run_time_configuration.rst @@ -108,6 +108,14 @@ In this case, the ``MY_DISCOVERY`` instance of ``RTPS_DISCOVERY`` will have a `` :sec:`transport` + * - :ref:`config-templates` + + - :sec:`DomainRange` + + :sec:`transport_template` + + :sec:`Customization` + * - Other - :sec:`ice` @@ -227,8 +235,8 @@ For example: publisher -DCPSConfigFile pub.ini -For each of the section types with the exception of :sec:`common` and ``[ice]``, the syntax of a section header takes the form of ``[/]``. -For example, a ``[repository]`` section type would always be used in a configuration file like so: ``[repository/repo_1]`` where ``repository`` is the section type and ``repo_1`` is an instance name of a repository configuration. +For each of the section types with the exception of :sec:`common` and :sec:`ice`, the syntax of a section header takes the form of ``[/]``. +For example, a :sec:`repository` section type would always be used in a configuration file like so: ``[repository/repo_1]`` where ``repository`` is the section type and ``repo_1`` is an instance name of a repository configuration. Using instances to configure discovery and transports is explained further in :ref:`config-disc` and :ref:`config-transport` respectively. @@ -675,13 +683,13 @@ When DDS applications are written, participants are assigned to a domain and nee OpenDDS offers a centralized discovery mechanism, a peer-to-peer discovery mechanism, and a static discovery mechanism. The centralized mechanism uses a separate service running a ``DCPSInfoRepo`` process. -The RTPS peer-to-peer mechanism uses the DDSI-RTPS discovery protocol standard to achieve non-centralized discovery. +The RTPS peer-to-peer mechanism uses the RTPS discovery protocol standard to achieve non-centralized discovery. The static discovery mechanism uses the configuration file to determine which writers and readers should be associated and uses the underlying transport to determine which writers and readers exist. A number of configuration options exist to meet the deployment needs of DDS applications. Except for static discovery, each mechanism uses default values if no configuration is supplied either via the command line or configuration file. The following sections show how to configure the advanced discovery capabilities. -For example, some deployments may need to use multiple ``DCPSInfoRepo`` services or DDSI-RTPS discovery to satisfy interoperability requirements. +For example, some deployments may need to use multiple ``DCPSInfoRepo`` services or RTPS discovery to satisfy interoperability requirements. .. _config-domain: .. _run_time_configuration--domain-configuration: @@ -795,7 +803,9 @@ For more explanation of a similar configuration for RTPS discovery see :ref:`run Key value of the mapped repository - .. deprecated:: Provided for backward compatibility. + .. deprecated:: 3.1.0 + + Provided for backward compatibility. .. prop:: DiscoveryConfig= :default: :prop:`[common]DCPSDefaultDiscovery` @@ -1003,7 +1013,9 @@ Here are the valid properties for a ``[repository]`` section: Unique key value for the repository - .. deprecated:: Provided for backward compatibility. + .. deprecated:: 3.1.0 + + Provided for backward compatibility. .. _rtps-disc-config: .. _run_time_configuration--configuring-for-ddsi-rtps-discovery: @@ -1115,72 +1127,75 @@ Those properties, along with options specific to OpenDDS's RTPS discovery implem Extends the lease of discovered participants by the set amount of seconds. Useful on spotty connections to reduce load on the :ref:`RtpsRelay `. - .. prop:: PB= + .. prop:: PB= :default: ``7400`` - This number sets the starting point for deriving port numbers used for Simple Endpoint Discovery Protocol (SEDP). - This property is used in conjunction with :prop:`DG`, :prop:`PG`, :prop:`D0` (or :prop:`DX`), and :prop:`D1` to construct the necessary Endpoints for RTPS discovery communication. - See :omgspec:`rtps:9.6.1.1` for how these Endpoints are constructed. + The port base parameter for the :ref:`computed RTPS ports `. .. prop:: DG= :default: ``250`` - An integer value representing the Domain Gain. - This is a multiplier that assists in formulating Multicast or Unicast ports for RTPS. + The domain gain coefficient parameter for the :ref:`computed RTPS ports `. .. prop:: PG= :default: ``2`` - An integer that assists in configuring SPDP Unicast ports and serves as an offset multiplier. - Participants are assigned addresses using the formula: - - .. math:: - - \mathit{PB} + DG \times \mathit{domainId} + \mathit{d}1 + \mathit{PG} \times \mathit{participantId} - - See :omgspec:`rtps:9.6.1.1` for how these Endpoints are constructed. + The participant gain coefficient parameter for the :ref:`computed RTPS ports `. .. prop:: D0= :default: The value of the ``OPENDDS_RTPS_DEFAULT_D0`` environment variable if set, else ``0`` - An integer value that assists in providing an offset for calculating an assignable port in SPDP Multicast configurations. - The formula used is: - - .. math:: - - \mathit{PB} + \mathit{DG} \times \mathit{domainId} + \mathit{d0} - - See :omgspec:`rtps:9.6.1.1` for how these Endpoints are constructed. + The offset parameter for the :ref:`computed SPDP multicast port `. .. prop:: D1= :default: ``10`` - An integer value that assists in providing an offset for calculating an assignable port in SPDP Unicast configurations. - The formula used is: + The offset parameter for the :ref:`computed SPDP unicast port `. + + .. prop:: DX= + :default: ``2`` - .. math:: + The offset parameter for the :ref:`computed SEDP multicast port `. - \mathit{PB} + \mathit{DG} \times \mathit{domainId} + \mathit{d1} + \mathit{PG} \times \mathit{participantId} + .. prop:: DY= + :default: ``12`` - See :omgspec:`rtps:9.6.1.1` for how these Endpoints are constructed. + The offset parameter for the :ref:`computed SEDP unicast port `. - .. prop:: DX= - :default: ``2`` + .. prop:: SpdpPortMode=system|probe + :default: :val:`system` - An integer value that assists in providing an offset for calculating a port in SEDP Multicast configurations. - This is only valid when :prop:`SedpMulticast=1 `. - The formula used is: + When :prop:`SpdpLocalAddress` and :prop:`Ipv6SpdpLocalAddress` don't explicitly set the ports, they are assigned according to one of these methods: - .. math:: + .. val:: system - \mathit{PB} + \mathit{DG} \times \mathit{domainId} + \mathit{dx} + The operating system assigns one when the socket is opened. - This is an OpenDDS extension and not part of the OMG DDSI-RTPS specification. + .. val:: probe + + :ref:`Computed SPDP unicast port ` .. prop:: SpdpRequestRandomPort= :default: ``0`` - Use a random port for SPDP. + ``0`` is the same as :val:`SpdpPortMode=probe` and ``1`` is the same as :val:`SpdpPortMode=system`. + + .. deprecated:: 3.29.0 + + Use :prop:`SpdpPortMode` instead. + + .. prop:: SedpPortMode=system|probe + :default: :val:`system` + + When :prop:`SedpLocalAddress` and :prop:`Ipv6SedpLocalAddress` don't explicitly set the ports, they are assigned according to one of these methods: + + .. val:: system + + The operating system assigns one when the socket is opened. + + .. val:: probe + + :ref:`Computed SEDP unicast port ` .. prop:: SedpMaxMessageSize= :default: ``65466`` (maximum worst-case UDP payload size) @@ -1196,18 +1211,52 @@ Those properties, along with options specific to OpenDDS's RTPS discovery implem When set to ``1``, Multicast is used. When set to ``0``, Unicast is used. - .. prop:: SedpLocalAddress=:[] + .. prop:: SedpMulticastAddress=[:] + :default: :prop:`InteropMulticastOverride` + + The multicast group to use for SEDP multicast traffic. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-sedp-multicast`. + + .. prop:: Ipv6SedpMulticastAddress=[:] + :default: :prop:`Ipv6DefaultMulticastGroup` + + IPv6 variant of :prop:`SedpMulticastAddress`. + + .. prop:: SedpLocalAddress=:[] :default: :prop:`[common]DCPSDefaultAddress` Configure the transport instance created and used by SEDP to bind to the specified local address and port. In order to leave the port unspecified, it can be omitted from the setting but the trailing ``:`` must be present. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-sedp-unicast`. - .. prop:: SpdpLocalAddress=[:] + .. prop:: Ipv6SedpLocalAddress=:[] + :default: :prop:`[common]DCPSDefaultAddress` + + IPv6 variant of :prop:`SedpLocalAddress`. + + .. prop:: SpdpMulticastAddress=[:] + :default: :prop:`InteropMulticastOverride` + + The multicast group to use for SPDP multicast traffic. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-spdp-multicast`. + + .. prop:: Ipv6SpdpMulticastAddress=[:] + :default: :prop:`Ipv6DefaultMulticastGroup` + + IPv6 variant of :prop:`Ipv6SpdpMulticastAddress`. + + .. prop:: SpdpLocalAddress=[:] :default: :prop:`[common]DCPSDefaultAddress` Address of a local interface, which will be used by SPDP to bind to that specific interface. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-spdp-unicast`. + + .. prop:: Ipv6SpdpLocalAddress=[:] + :default: :prop:`[common]DCPSDefaultAddress` - .. prop:: SedpAdvertisedLocalAddress=:[] + IPv6 variant of :prop:`SpdpLocalAddress`. + + .. prop:: SedpAdvertisedLocalAddress=:[] Sets the address advertised by SEDP. Typically used when the participant is behind a firewall or NAT. @@ -1251,10 +1300,17 @@ Those properties, along with options specific to OpenDDS's RTPS discovery implem This setting should be disabled for participants that cannot use multicast to send SPDP announcements, e.g., an RtpsRelay. .. prop:: InteropMulticastOverride= + :default: ``239.255.0.1`` + + A network address specifying the multicast group to be used for SPDP and SEDP. + The default is defined by the RTPS specification. + This property can be used, for example, to specify use of a routed group address to provide a larger discovery scope. + It can be modified by :prop:`[Customization]InteropMulticastOverride`. - A network address specifying the multicast group to be used for SPDP discovery. - This overrides the interoperability group of the specification, ``239.255.0.1`` - It can be used, for example, to specify use of a routed group address to provide a larger discovery scope. + .. prop:: Ipv6DefaultMulticastGroup= + :default: ``ff03::1`` + + IPv6-variant of :prop:`InteropMulticastOverride`. .. prop:: TTL=n :default: ``1`` (all data is restricted to the local network) @@ -1413,16 +1469,82 @@ Those properties, along with options specific to OpenDDS's RTPS discovery implem If ```` is 0 (the default), the submessage is not added. Otherwise this submessage's contents is the 4-byte unsigned integer ````. +.. _config-ports-used-by-rtps-disc: + +Ports Used by RTPS Discovery +---------------------------- + +See :omgspec:`rtps:9.6.1 Default Locators` for the related RTPS spec definitions. + +.. _config-ports-used-by-spdp: + +Simple Participant Discovery Protocol (SPDP) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. _config-ports-used-by-spdp-multicast: + +SPDP Multicast +"""""""""""""" + +The SPDP multicast port will be one of the following: + +- Port from :prop:`SpdpMulticastAddress <[rtps_discovery]SpdpMulticastAddress>` if set +- :prop:`PB <[rtps_discovery]PB>` + :prop:`DG <[rtps_discovery]DG>` × *domainId* + :prop:`D0 <[rtps_discovery]D0>` + +.. _config-ports-used-by-spdp-unicast: + +SPDP Unicast +"""""""""""" + +The SPDP unicast port will be one of the following: + +- Port from :prop:`SpdpLocalAddress <[rtps_discovery]SpdpLocalAddress>` if set +- A system-provided port if :val:`SpdpPortMode=system <[rtps_discovery]SpdpPortMode=system>` +- :prop:`PB <[rtps_discovery]PB>` + :prop:`DG <[rtps_discovery]DG>` × *domainId* + :prop:`D1 <[rtps_discovery]D1>` + :prop:`PG <[rtps_discovery]PG>` × *participantId* if :val:`SpdpPortMode=probe <[rtps_discovery]SpdpPortMode=probe>` is set (default) + + - If the port can not be opened, then the *participantId* is incremented until a port can be opened. + - If no valid UDP port can be opened, then an error will be logged. + +.. _config-ports-used-by-sedp: + +Simple Endpoint Discovery Protocol (SEDP) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. note:: + + :prop:`DX <[rtps_discovery]DX>` and :prop:`DY <[rtps_discovery]DY>` are OpenDDS-specific. + +.. _config-ports-used-by-sedp-multicast: + +SEDP Multicast +"""""""""""""" + +If :prop:`SedpMulticast=1 <[rtps_discovery]SedpMulticast>`, the SEDP multicast port will be one of the following: + +- Port from :prop:`SedpMulticastAddress <[rtps_discovery]SedpMulticastAddress>` if set (the same as SPDP) +- :prop:`PB <[rtps_discovery]PB>` + :prop:`DG <[rtps_discovery]DG>` × *domainId* + :prop:`DX <[rtps_discovery]DX>` + +.. _config-ports-used-by-sedp-unicast: + +SEDP Unicast +"""""""""""" + +The SEDP unicast port will be one of the following: + +- Port from :prop:`SedpLocalAddress <[rtps_discovery]SedpLocalAddress>` if set +- :prop:`PB <[rtps_discovery]PB>` + :prop:`DG <[rtps_discovery]DG>` × *domainId* + :prop:`DY <[rtps_discovery]DY>` + :prop:`PG <[rtps_discovery]PG>` × *participantId* if :val:`SedpPortMode=probe <[rtps_discovery]SedpPortMode=probe>` is set +- A system-provided port if :val:`SedpPortMode=system <[rtps_discovery]SedpPortMode=system>` (default) + .. _run_time_configuration--additional-ddsi-rtps-discovery-features: -Additional DDSI-RTPS Discovery Features ---------------------------------------- +Additional RTPS Discovery Features +---------------------------------- .. Sect<7.3.3.1> -The DDSI_RTPS discovery implementation creates and manages a transport instance -- specifically an object of class ``RtpsUdpInst``. -In order for applications to access this object and enable advanced features (:ref:`Additional RTPS_UDP Features `), the ``RtpsDiscovery`` class provides the method ``sedp_transport_inst(domainId, participant)``. +The RTPS discovery implementation creates and manages a transport instance -- specifically an object of class ``RtpsUdpInst``. +In order for applications to access this object and :ref:`enable advanced features `, the ``RtpsDiscovery`` class provides the method ``sedp_transport_inst(domainId, participant)``. .. _static-disc-config: .. _run_time_configuration--configuring-for-static-discovery: @@ -2595,16 +2717,17 @@ Some implementation notes related to using the ``rtps_udp`` transport protocol a When set to ``0`` (false) the transport uses Unicast, otherwise a value of ``1`` (true) will use Multicast. .. prop:: multicast_group_address=: - :default: ``239.255.0.2:7401`` + :default: ``239.255.0.2:0`` When :prop:`use_multicast` is enabled, this is the multicast network address that should be used. - If ```` is not specified for the network address, port 7401 will be used. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-rtps-udp-multicast`. + It can be modified by :prop:`[Customization]multicast_group_address`. .. prop:: ipv6_multicast_group_address= - :default: ``[FF03::2]:7401`` + :default: ``[FF03::2]:0`` When the transport is set to multicast, this is the multicast network address that should be used. - If ```` is not specified for the network address, port 7401 will be used. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-rtps-udp-multicast`. .. prop:: multicast_interface= :default: :prop:`[common]DCPSDefaultAddress` @@ -2612,17 +2735,57 @@ Some implementation notes related to using the ``rtps_udp`` transport protocol a Specifies the network interface to be used by this transport instance. This uses a platform-specific format that identifies the network interface. - .. prop:: local_address=:[] + .. prop:: local_address=:[] :default: :prop:`[common]DCPSDefaultAddress` Bind the socket to the given address and port. - Port can be omitted but the trailing ``:`` is required. + ```` can be omitted but the trailing ``:`` is required. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-rtps-udp-unicast`. - .. prop:: ipv6_local_address=:[] + .. prop:: ipv6_local_address=:[] :default: :prop:`[common]DCPSDefaultAddress` Bind the socket to the given address and port. - Port can be omitted but the trailing ``:`` is required. + ```` can be omitted but the trailing ``:`` is required. + If ```` is ``0`` or not specified, it is calculated as described in :ref:`config-ports-used-by-rtps-udp-unicast`. + + .. prop:: PortMode=system|probe + :default: :val:`system` + + When :prop:`local_address` and :prop:`ipv6_local_address` don't explicitly set the ports, they are assigned according to one of these methods: + + .. val:: system + + The operating system assigns one when the socket is opened. + + .. val:: probe + + :ref:`Computed unicast port ` + + .. prop:: PB= + :default: ``7400`` + + The port base parameter for the :ref:`computed RTPS ports `. + + .. prop:: DG= + :default: ``250`` + + The domain gain coefficient parameter for the :ref:`computed RTPS ports `. + + .. prop:: PG= + :default: ``2`` + + The participant gain coefficient parameter for the :ref:`computed RTPS ports `. + + .. prop:: D2= + :default: ``1`` + + The offset parameter for the :ref:`computed multicast port `. + + .. prop:: D3= + :default: ``11`` + + The offset parameter for the :ref:`computed unicast port `. .. prop:: advertised_address=:[] @@ -2710,6 +2873,34 @@ Some implementation notes related to using the ``rtps_udp`` transport protocol a Enable or disable :ref:`ICE ` for this transport instance. +.. _config-ports-used-by-rtps-udp: + +Ports used by RTPS/UDP +^^^^^^^^^^^^^^^^^^^^^^ + +See :omgspec:`rtps:9.6.1 Default Locators` for the related RTPS spec definitions. + +.. _config-ports-used-by-rtps-udp-multicast: + +Multicast +""""""""" + +If :prop:`use_multicast=1 <[transport@rtps_udp]use_multicast>` the RTPS/UDP multicast port will be one of the following: + +- Port from :prop:`multicast_group_address <[transport@rtps_udp]multicast_group_address>` and :prop:`ipv6_multicast_group_address <[transport@rtps_udp]ipv6_multicast_group_address>` if set +- :prop:`PB <[transport@rtps_udp]PB>` + :prop:`DG <[transport@rtps_udp]DG>` × *domainId* + :prop:`D2 <[transport@rtps_udp]D2>` + +.. _config-ports-used-by-rtps-udp-unicast: + +Unicast +""""""" + +The RTPS/UDP unicast port will be one of the following: + +- Port from :prop:`local_address <[transport@rtps_udp]local_address>` and :prop:`ipv6_local_address <[transport@rtps_udp]ipv6_local_address>` if set +- :prop:`PB <[transport@rtps_udp]PB>` + :prop:`DG <[transport@rtps_udp]DG>` × *domainId* + :prop:`D3 <[transport@rtps_udp]D3>` + :prop:`PG <[transport@rtps_udp]PG>` × *participantId* if :val:`PortMode=prob <[transport@rtps_udp]PortMode=probe>` +- A system-provided port if :val:`PortMode=system <[transport@rtps_udp]PortMode=system>` (default) + .. _run_time_configuration--additional-rtps-udp-features: Additional RTPS UDP Features diff --git a/docs/news.d/rtps-ports.rst b/docs/news.d/rtps-ports.rst new file mode 100644 index 00000000000..136c28a0404 --- /dev/null +++ b/docs/news.d/rtps-ports.rst @@ -0,0 +1,22 @@ +.. news-prs: 4655 + +.. news-start-section: Additions +- Added config properties to give more control over what UDP ports RTPS uses: + + - For RTPS Discovery: + + - :cfg:val:`[rtps_discovery]SedpPortMode=probe` will use ports similar to how the RTPS specification defines them. + This uses the existing port parameter properties for SPDP and a new one, :cfg:prop:`[rtps_discovery]DY`. + - Added :cfg:prop:`[rtps_discovery]SpdpPortMode` as an alias to the now deprecated :cfg:prop:`[rtps_discovery]SpdpRequestRandomPort`. + - Added :cfg:prop:`[rtps_discovery]SpdpMulticastAddress`, :cfg:prop:`[rtps_discovery]Ipv6SpdpMulticastAddress`, :cfg:prop:`[rtps_discovery]SedpMulticastAddress`, and :cfg:prop:`[rtps_discovery]Ipv6SedpMulticastAddress` to set the multicast addresses and ports separately on SPDP and SEDP. + - See :ref:`here ` for the full overview of port usage. + + - For RTPS/UDP Transport: + + - Added :cfg:val:`[transport@rtps_udp]PortMode=probe` will use port exactly as the RTPS specification defines them. + This uses new port parameter properties: :cfg:prop:`[transport@rtps_udp]PB`, :cfg:prop:`[transport@rtps_udp]DG`, :cfg:prop:`[transport@rtps_udp]PG`, :cfg:prop:`[transport@rtps_udp]D2`, and :cfg:prop:`[transport@rtps_udp]D3`. + - See :ref:`here ` for the full overview of port usage. + + - All ports calculated using port parameter properties now warn if they overflow the 16 bit integer. + - :cfg:val:`[rtps_discovery]SedpPortMode=probe` and :cfg:val:`[transport@rtps_udp]PortMode=probe` might make :ref:`config template customizations ` unnecessary. +.. news-end-section diff --git a/tests/unit-tests/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp b/tests/unit-tests/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp index 3c58317c493..6ba9cd1f540 100644 --- a/tests/unit-tests/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp +++ b/tests/unit-tests/dds/DCPS/RTPS/RtpsDiscoveryConfig.cpp @@ -26,82 +26,21 @@ namespace { store->unset_section(rtps.config_prefix()); } }; -} - -TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, sedp_unicast_address) -{ - { - AddressTest t; - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_System); - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); - } - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7662, "0.0.0.0")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7668, "0.0.0.0")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - t.rtps.pb(7500); - t.rtps.dg(260); - t.rtps.pg(3); - t.rtps.dy(8); - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "0.0.0.0")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - t.rtps.pb(9999); - t.rtps.dg(9999); - t.rtps.pg(9999); - t.rtps.dy(9999); - LogRestore lr; - log_level.set(LogLevel::None); - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 9999, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(29664, "0.0.0.0")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_local_address(NetworkAddress(1234, "1.2.3.4")); - ASSERT_TRUE(t.rtps.sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "1.2.3.4")); - EXPECT_FALSE(t.fixed); - } + const NetworkAddress fake_ipv4_addr(1234, "1.2.3.4"); +#ifdef ACE_HAS_IPV6 + const NetworkAddress fake_ipv6_addr(1234, "::1:2:3:4"); +#endif } TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_unicast_address) { + const char* const default_addr = "0.0.0.0"; + { AddressTest t; ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, "0.0.0.0")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, default_addr)); EXPECT_FALSE(t.fixed); } @@ -109,7 +48,7 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_unicast_address) AddressTest t; t.rtps.spdp_port_mode(PortMode_Probe); ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, "0.0.0.0")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, default_addr)); EXPECT_FALSE(t.fixed); } @@ -118,15 +57,15 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_unicast_address) AddressTest t; t.rtps.spdp_port_mode(PortMode_System); ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(0, default_addr)); + EXPECT_TRUE(t.fixed); } { AddressTest t; t.rtps.spdp_port_mode(PortMode_Probe); ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7666, "0.0.0.0")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7666, default_addr)); EXPECT_FALSE(t.fixed); } @@ -138,7 +77,7 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_unicast_address) t.rtps.pg(3); t.rtps.d1(8); ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "0.0.0.0")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, default_addr)); EXPECT_FALSE(t.fixed); } @@ -152,32 +91,34 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_unicast_address) LogRestore lr; log_level.set(LogLevel::None); ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 9999, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(29664, "0.0.0.0")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(29664, default_addr)); EXPECT_FALSE(t.fixed); } { AddressTest t; - t.rtps.spdp_local_address(NetworkAddress(1234, "1.2.3.4")); + t.rtps.spdp_local_address(fake_ipv4_addr); ASSERT_TRUE(t.rtps.spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "1.2.3.4")); + EXPECT_ADDR_EQ(t.addr, fake_ipv4_addr); EXPECT_TRUE(t.fixed); } } TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_multicast_address) { + const char* const default_addr = "239.255.0.1"; + { AddressTest t; ASSERT_TRUE(t.rtps.spdp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7650, "239.255.0.1")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7650, default_addr)); EXPECT_FALSE(t.fixed); } { AddressTest t; ASSERT_TRUE(t.rtps.spdp_multicast_address(t.addr, 2)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7900, "239.255.0.1")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7900, default_addr)); EXPECT_FALSE(t.fixed); } @@ -187,7 +128,7 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_multicast_address) t.rtps.dg(260); t.rtps.d0(17); ASSERT_TRUE(t.rtps.spdp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "239.255.0.1")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, default_addr)); EXPECT_FALSE(t.fixed); } @@ -199,142 +140,29 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, spdp_multicast_address) LogRestore lr; log_level.set(LogLevel::None); ASSERT_TRUE(t.rtps.spdp_multicast_address(t.addr, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(57599, "239.255.0.1")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(57599, default_addr)); EXPECT_FALSE(t.fixed); } { AddressTest t; - t.rtps.spdp_multicast_address(NetworkAddress(1234, "1.2.3.4")); + t.rtps.spdp_multicast_address(fake_ipv4_addr); ASSERT_TRUE(t.rtps.spdp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "1.2.3.4")); + EXPECT_ADDR_EQ(t.addr, fake_ipv4_addr); EXPECT_FALSE(t.fixed); } } -TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, sedp_multicast_address) -{ - { - AddressTest t; - ASSERT_TRUE(t.rtps.sedp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7652, "239.255.0.1")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - ASSERT_TRUE(t.rtps.sedp_multicast_address(t.addr, 2)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7902, "239.255.0.1")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.pb(7500); - t.rtps.dg(260); - t.rtps.dx(17); - ASSERT_TRUE(t.rtps.sedp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "239.255.0.1")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.pb(9999); - t.rtps.dg(9999); - t.rtps.dx(9999); - LogRestore lr; - log_level.set(LogLevel::None); - ASSERT_TRUE(t.rtps.sedp_multicast_address(t.addr, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(57599, "239.255.0.1")); - - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_multicast_address(NetworkAddress(1234, "1.2.3.4")); - ASSERT_TRUE(t.rtps.sedp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "1.2.3.4")); - EXPECT_FALSE(t.fixed); - } -} #ifdef ACE_HAS_IPV6 -TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_sedp_unicast_address) -{ - { - AddressTest t; - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_System); - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7662, "[::]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7668, "[::]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - t.rtps.pb(7500); - t.rtps.dg(260); - t.rtps.pg(3); - t.rtps.dy(8); - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "[::]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_port_mode(PortMode_Probe); - t.rtps.pb(9999); - t.rtps.dg(9999); - t.rtps.pg(9999); - t.rtps.dy(9999); - LogRestore lr; - log_level.set(LogLevel::None); - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 9999, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(29664, "[::]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.sedp_local_address(NetworkAddress(1234, "[1:2:3:4]")); - ASSERT_TRUE(t.rtps.ipv6_sedp_unicast_address(t.addr, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "[1:2:3:4]")); - EXPECT_FALSE(t.fixed); - } -} - TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_unicast_address) { + const char* const default_addr = "::"; + { AddressTest t; ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, "[::]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, default_addr)); EXPECT_FALSE(t.fixed); } @@ -342,7 +170,7 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_unicast_address) AddressTest t; t.rtps.spdp_port_mode(PortMode_Probe); ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, "[::]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7660, default_addr)); EXPECT_FALSE(t.fixed); } @@ -352,14 +180,14 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_unicast_address) t.rtps.spdp_port_mode(PortMode_System); ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 1, 0)); EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); + EXPECT_TRUE(t.fixed); } { AddressTest t; t.rtps.spdp_port_mode(PortMode_Probe); ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7666, "[::]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7666, default_addr)); EXPECT_FALSE(t.fixed); } @@ -371,7 +199,7 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_unicast_address) t.rtps.pg(3); t.rtps.d1(8); ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 1, 3)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "[::]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, default_addr)); EXPECT_FALSE(t.fixed); } @@ -385,32 +213,34 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_unicast_address) LogRestore lr; log_level.set(LogLevel::None); ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 9999, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(29664, "[::]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(29664, default_addr)); EXPECT_FALSE(t.fixed); } { AddressTest t; - t.rtps.spdp_local_address(NetworkAddress(1234, "[1:2:3:4]")); + t.rtps.ipv6_spdp_local_address(fake_ipv6_addr); ASSERT_TRUE(t.rtps.ipv6_spdp_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "[1:2:3:4]")); + EXPECT_ADDR_EQ(t.addr, fake_ipv6_addr); EXPECT_TRUE(t.fixed); } } TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_multicast_address) { + const char* const default_addr = "ff03::1"; + { AddressTest t; ASSERT_TRUE(t.rtps.ipv6_spdp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7650, "[FF03::1]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7650, default_addr)); EXPECT_FALSE(t.fixed); } { AddressTest t; ASSERT_TRUE(t.rtps.ipv6_spdp_multicast_address(t.addr, 2)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7900, "[FF03::1]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7900, default_addr)); EXPECT_FALSE(t.fixed); } @@ -420,7 +250,7 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_multicast_address) t.rtps.dg(260); t.rtps.d0(17); ASSERT_TRUE(t.rtps.ipv6_spdp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "[FF03::1]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, default_addr)); EXPECT_FALSE(t.fixed); } @@ -432,62 +262,15 @@ TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_spdp_multicast_address) LogRestore lr; log_level.set(LogLevel::None); ASSERT_TRUE(t.rtps.ipv6_spdp_multicast_address(t.addr, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(57599, "[FF03::1]")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(57599, default_addr)); EXPECT_FALSE(t.fixed); } { AddressTest t; - t.rtps.ipv6_spdp_multicast_address(NetworkAddress(1234, "[1:2:3:4]")); + t.rtps.ipv6_spdp_multicast_address(fake_ipv6_addr); ASSERT_TRUE(t.rtps.ipv6_spdp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "[1:2:3:4]")); - EXPECT_FALSE(t.fixed); - } -} - -TEST(dds_DCPS_RTPS_RtpsDiscoveryConfig, ipv6_sedp_multicast_address) -{ - { - AddressTest t; - ASSERT_TRUE(t.rtps.ipv6_sedp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7652, "[FF03::1]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - ASSERT_TRUE(t.rtps.ipv6_sedp_multicast_address(t.addr, 2)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7902, "[FF03::1]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.pb(7500); - t.rtps.dg(260); - t.rtps.dx(17); - ASSERT_TRUE(t.rtps.ipv6_sedp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(7777, "[FF03::1]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.pb(9999); - t.rtps.dg(9999); - t.rtps.dx(9999); - LogRestore lr; - log_level.set(LogLevel::None); - ASSERT_TRUE(t.rtps.ipv6_sedp_multicast_address(t.addr, 9999)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(57599, "[FF03::1]")); - EXPECT_FALSE(t.fixed); - } - - { - AddressTest t; - t.rtps.ipv6_sedp_multicast_address(NetworkAddress(1234, "[1:2:3:4]")); - ASSERT_TRUE(t.rtps.ipv6_sedp_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "[1:2:3:4]")); + EXPECT_ADDR_EQ(t.addr, fake_ipv6_addr); EXPECT_FALSE(t.fixed); } } diff --git a/tests/unit-tests/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp b/tests/unit-tests/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp index f7e22f36aae..6b48dca7c34 100644 --- a/tests/unit-tests/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp +++ b/tests/unit-tests/dds/DCPS/transport/rtps_udp/RtpsUdpInst.cpp @@ -12,7 +12,7 @@ namespace { RtpsUdpType() : store(make_rch(TheServiceParticipant->config_topic())) - , rtps_udp(make_rch("RTPS_UDP_INST_UNIT_TEST", false)) + , rtps_udp(make_rch("RTPS_UDP_INST_UNIT_TEST", true)) { store->unset_section(rtps_udp->config_prefix()); } @@ -33,6 +33,11 @@ namespace { { } }; + + const NetworkAddress fake_ipv4_addr(1234, "1.2.3.4"); +#ifdef ACE_HAS_IPV6 + const NetworkAddress fake_ipv6_addr(1234, "::1:2:3:4"); +#endif } TEST(dds_DCPS_RTPS_RtpsUdpInst, multicast_address) @@ -77,9 +82,31 @@ TEST(dds_DCPS_RTPS_RtpsUdpInst, multicast_address) { AddressTest t; - t.rtps_udp->multicast_group_address(NetworkAddress(1234, "1.2.3.4")); + t.rtps_udp->multicast_group_address(fake_ipv4_addr); + ASSERT_TRUE(t.rtps_udp->multicast_address(t.addr, 1)); + EXPECT_ADDR_EQ(t.addr, fake_ipv4_addr); + EXPECT_FALSE(t.fixed); + } + + // add_domain_id_to_port template with fixed port + { + AddressTest t; + t.store->set_string(t.rtps_udp->config_key("CUSTOMIZATION").c_str(), "CUST"); + t.store->set_string("CUSTOMIZATION_CUST_MULTICAST_GROUP_ADDRESS", "add_domain_id_to_port"); + t.rtps_udp->multicast_group_address(fake_ipv4_addr); + ASSERT_TRUE(t.rtps_udp->multicast_address(t.addr, 1)); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(1235, "1.2.3.4")); + EXPECT_FALSE(t.fixed); + } + + // add_domain_id_to_port template with spec port + { + AddressTest t; + t.store->set_string(t.rtps_udp->config_key("CUSTOMIZATION").c_str(), "CUST"); + t.store->set_string("CUSTOMIZATION_CUST_MULTICAST_GROUP_ADDRESS", "add_domain_id_to_port"); + t.rtps_udp->multicast_group_address(NetworkAddress(0, "1.2.3.4")); ASSERT_TRUE(t.rtps_udp->multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "1.2.3.4")); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(7652, "1.2.3.4")); EXPECT_FALSE(t.fixed); } } @@ -91,16 +118,16 @@ TEST(dds_DCPS_RTPS_RtpsUdpInst, unicast_address) { AddressTest t; ASSERT_TRUE(t.rtps_udp->unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(0, default_addr)); + EXPECT_TRUE(t.fixed); } { AddressTest t; t.rtps_udp->port_mode(PortMode_System); ASSERT_TRUE(t.rtps_udp->unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(0, default_addr)); + EXPECT_TRUE(t.fixed); } { @@ -147,9 +174,9 @@ TEST(dds_DCPS_RTPS_RtpsUdpInst, unicast_address) { AddressTest t; - t.rtps_udp->local_address(NetworkAddress(1234, "1.2.3.4")); + t.rtps_udp->local_address(fake_ipv4_addr); ASSERT_TRUE(t.rtps_udp->unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "1.2.3.4")); + EXPECT_ADDR_EQ(t.addr, fake_ipv4_addr); EXPECT_TRUE(t.fixed); } } @@ -157,7 +184,7 @@ TEST(dds_DCPS_RTPS_RtpsUdpInst, unicast_address) #ifdef ACE_HAS_IPV6 TEST(dds_DCPS_RTPS_RtpsUdpInst, ipv6_multicast_address) { - const char* const default_addr = "239.255.0.2"; + const char* const default_addr = "ff03::2"; { AddressTest t; @@ -197,30 +224,30 @@ TEST(dds_DCPS_RTPS_RtpsUdpInst, ipv6_multicast_address) { AddressTest t; - t.rtps_udp->multicast_group_address(NetworkAddress(1234, "[1:2:3:4]")); + t.rtps_udp->ipv6_multicast_group_address(fake_ipv6_addr); ASSERT_TRUE(t.rtps_udp->ipv6_multicast_address(t.addr, 1)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "[1:2:3:4]")); + EXPECT_ADDR_EQ(t.addr, fake_ipv6_addr); EXPECT_FALSE(t.fixed); } } TEST(dds_DCPS_RTPS_RtpsUdpInst, ipv6_unicast_address) { - const char* const default_addr = "[::]"; + const char* const default_addr = "::"; { AddressTest t; ASSERT_TRUE(t.rtps_udp->ipv6_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(0, default_addr)); + EXPECT_TRUE(t.fixed); } { AddressTest t; t.rtps_udp->port_mode(PortMode_System); ASSERT_TRUE(t.rtps_udp->ipv6_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress()); - EXPECT_FALSE(t.fixed); + EXPECT_ADDR_EQ(t.addr, NetworkAddress(0, default_addr)); + EXPECT_TRUE(t.fixed); } { @@ -267,9 +294,9 @@ TEST(dds_DCPS_RTPS_RtpsUdpInst, ipv6_unicast_address) { AddressTest t; - t.rtps_udp->local_address(NetworkAddress(1234, "[1:2:3:4]")); + t.rtps_udp->ipv6_local_address(fake_ipv6_addr); ASSERT_TRUE(t.rtps_udp->ipv6_unicast_address(t.addr, t.fixed, 1, 0)); - EXPECT_ADDR_EQ(t.addr, NetworkAddress(1234, "[1:2:3:4]")); + EXPECT_ADDR_EQ(t.addr, fake_ipv6_addr); EXPECT_TRUE(t.fixed); } }