How do I change the multicast time-to-live (TTL)?
Note: Applies to RTI Connext 4.x and above
RTI Connext 4.x and above uses a default multicast time-to-live (TTL) value of 1. This means that, by default, multicast traffic will not cross subnet boundaries. The TTL value can be adjusted in the transport property.
Method One for modifying the TTL (applies to all 4.x and above versions)
The following C++ code snippet shows how to change the TTL.
// First, create a domain participant without enabling it. // To do so, modify the QoS of the participant factory. DDS_DomainParticipantFactoryQos factory_qos; retcode = DDSTheParticipantFactory->get_qos(factory_qos); if (retcode != DDS_RETCODE_OK) { // handle error! } factory_qos.entity_factory.autoenable_created_entities = DDS_BOOLEAN_FALSE; retcode = DDSTheParticipantFactory->set_qos(factory_qos); if (retcode != DDS_RETCODE_OK) {// handle error! } // Now we can create the participant as usual, but it will be disabled participant = DDSTheParticipantFactory->create_participant(domainId, DDS_PARTICIPANT_QOS_DEFAULT, NULL /* listener */, DDS_STATUS_MASK_NONE); if (participant == NULL) { // handle error! } // Finally, modify the properties of the UDPv4 transport struct NDDS_Transport_UDPv4_Property_t udp_property = NDDS_TRANSPORT_UDPV4_PROPERTY_DEFAULT; retcode = NDDSTransportSupport::get_builtin_transport_property(participant, DDS_TRANSPORTBUILTIN_UDPv4, (struct NDDS_Transport_Property_t&) udp_property); if (retcode != DDS_RETCODE_OK) { // handle error! } udp_property.multicast_ttl = 2; // or appropriate value for your case retcode = NDDSTransportSupport::set_builtin_transport_property(participant, DDS_TRANSPORTBUILTIN_UDPv4, (struct NDDS_Transport_Property_t&) udp_property); if (retcode != DDS_RETCODE_OK) { // handle error! } // After setting the appropriate transport property // we can now enable the participant if (participant->enable() != DDS_RETCODE_OK) { //handle error }
Method Two for modifying the TTL (applies to version 4.2 and higher)
DDS_DomainParticipantQos participant_qos; DDSTheParticipantFactory->get_default_participant_qos(participant_qos); DDSPropertyQosPolicyHelper::add_property(participant_qos.property, "dds.transport.UDPv4.builtin.multicast_ttl", "2", RTI_FALSE); DDSTheParticipantFactory->create_participant(....)
Note: Changing properties with the Property QosPolicy will overwrite any properties set by calling
set_builtin_transport_property()
.
Method Three for modifying TTL (applies to version 4.3 and higher)
This method uses an XML QoS profile to configure the DomainParticipant and transport properties.
<dds> <qos_library name="MulticastTTLLibrary"> <qos_profile name="DefaultProfile"> <participant_qos> <property> <value> <element> <name>dds.transport.UDPv4.builtin.multicast_ttl</name> <!-- Whatever your new value needs to be --> <value>2</value> </element> </value> </property> </participant_qos> </qos_profile> </qos_library> </dds>
If you are using RTI Data Distribution Service 4.3e, you must call
DDSTheParticipantFactory->load_profiles()
before creating the DomainParticipant with a profile.
When using RTI Connext 4.4 and higher, the XML file can be automatically loaded. If NDDS_QOS_PROFILES.xml is in the $NDDSHOME/resource/xml directory, it will be automatically loaded. Similarly, if USER_QOS_PROFILES.xml is in the working directory, it will be automatically loaded. See the Core Libraries and Utilities User’s Manual for more details on XML file loading.
When using RTI Connext 4.4 and higher, place the attached USER_QOS_PROFILES.xml file in the working directory. It specifies MulticastTTLLibrary
as the default QoS profile and will be loaded when your RTI Connext application starts.