How do I get a data reader to receive data over multicast?

Prior to RTI Data Distribution Service version 4.4, receiving data over multicast could only be configured on the reader side. The reader Qos specifies to the writer that it wants to receive data using a multicast address. 

Starting with RTI Data Distribution Service 4.4, in addition to the description below, the Multi Channel Qos allows one to specify the multicast address  on the publisher side. Please refer to the Core Libraries and Utilities User Manual (section "MULTI_CHANNEL QoSPolicy") for more details.

Method One: Individual Reader via dataReaderQos.multicast (applies to all 4.x versions)

A- Specifying the reader multicast address programmatically 

Example C++ code snippet:

DDS_DataReaderQos reader_qos;
 
/* Customize data reader QoS to create multicast data reader */
retcode = subscriber->get_default_datareader_qos(reader_qos);
if (retcode != DDS_RETCODE_OK) {
    printf("get_reader_qos error %d\n", retcode);
    subscriber_shutdown(participant, subscriber, topic, reader);
    return -1;
}
 
if (!reader_qos.multicast.value.maximum(1)) {
    printf("DDS_Address::maximum error\n");
    subscriber_shutdown(participant, subscriber, topic, reader);
    return -1;
}
 
if (!reader_qos.multicast.value.length(1)) {
    printf("DDS_Address::length error\n");
    subscriber_shutdown(participant, subscriber, topic, reader);
    return -1;
}
 
reader_qos.multicast.value[0].receive_address =
 DDS_String_dup("239.255.1.2");
 
reader = subscriber->create_datareader(
    topic, reader_qos, reader_listener,
    DDS_STATUS_MASK_ALL);
if (reader == NULL) {
    printf("create_datareader error\n");
    subscriber_shutdown(participant, subscriber, topic, reader);
    delete reader_listener;
    return -1;
}

B- Specifying the reader multicast address via XML (applies to version 4.3 and higher)

This method uses an XML QoS profile to configure the reader QoS:

<dds>
   <qos_library name="MulticastTTLLibrary">
       <qos_profile name="DefaultProfile">
           <datareader_qos>
               <multicast> 
                   <value>
                       <element>
                           <receive_address>239.255.1.2</receive_address>
                       </element>
                   </value>
               </multicast>
           </datareader_qos> 
       </qos_profile>
   </qos_library>
</dds>

To load the QoS profile, use one of the following methods:

  • 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 Data Distribution Service 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.
    • If USER_QOS_PROFILES.xml is in the working directory, it will be automatically loaded. 

Method Two: Automatic Transport Multicast Mapping (applies to all 5.0+ versions)

This alternative method is described in the RTI_CoreLibrariesAndUtilities_UsersManual.pdf section TRANSPORT_MULTICAST_MAPPING QosPolicy (DDS Extension)

In order to enable this capability all data readers <datareader_qos> must be set up as follows:

<multicast>
     <kind>AUTOMATIC_TRANSPORT_MULTICAST_QOS</kind>
         <value>
             <element>
                <receive_port>0</receive_port>
                <receive_address></receive_address>
              </element>
         </value>
</multicast>

Example 1- Explicitly maps all topics named Port* to multicast address 239.255.2.1 and all topics named Stbd* to multicast address 239.255.1.2

<participant_qos>
   <multicast_mapping>
        <value>
            <element>
               <addresses>239.255.2.1</addresses>
               <topic_expression>Port*</topic_expression>
            </element>
            <element>
               <addresses>239.255.1.2</addresses>
               <topic_expression>Stbd*</topic_expression>
            </element>
         </value>
    </multicast_mapping>
</participant_qos>

Example 2- Defines a multicast address range from 239.255.0.1 to 239.255.2.2. A Topic named Port will be mapped using MD5 sum of the data reader's topic name to address 239.255.0.126. A Topic named Stbd will be mapped likewise to 239.255.1.126.

<participant_qos>
   <multicast_mapping>
        <value>
            <element>
               <addresses>[239.255.0.1,239.255.2.2]</addresses>
               <topic_expression>Port*,Stbd*</topic_expression>
            </element>
         </value>
    </multicast_mapping>
</participant_qos>
Note: See the Core Libraries and Utilities User’s Manual for more details on XML file loading.