6.2. UDP Transport

UDP is a connectionless transport, where the receiving DomainParticipant must open a UDP port listening for incoming messages, and the sending DomainParticipant sends messages to this port.

Warning

This documentation assumes the reader has basic knowledge of UDP/IP concepts, since terms like Time To Live (TTL), socket buffers, and port numbering are not explained in detail. However, it is possible to configure a basic UDP transport on Fast DDS without this knowledge.

6.2.1. UDPTransportDescriptor

eProsima Fast DDS implements UDP transport for both UDPv4 and UDPv6. Each of these transports is independent from the other, and has its own TransportDescriptor. However, all their TransportDescriptor data members are common.

The following table describes the common data members for both UDPv4 and UDPv6.

Member

Data type

Default

Description

sendBufferSize

uint32_t

0

Size of the sending buffer of the socket (octets).

receiveBufferSize

uint32_t

0

Size of the receiving buffer of the socket (octets).

interfaceWhiteList

vector<string>

empty

List of allowed interfaces. See Interface Whitelist

TTL

uint8_t

1

Time to live, in number of hops.

m_output_udp_socket

uint16_t

0

Port number for the outgoing messages.

non_blocking_send

bool

false

Do not block on send operations (*).

Note

When non_blocking_send is set to true, send operations will return immediately if the buffer is full, but no error will be returned to the upper layer. This means that the application will behave as if the datagram is sent and lost. This value is specially useful on high-frequency best-effort writers.

When set to false, send operations will block until the network buffer has space for the datagram. This may hinder performance on high-frequency writers.

6.2.1.1. UDPv4TransportDescriptor

UDPv4TransportDescriptor has no additional data members from the common ones described in UDPTransportDescriptor.

Note

The kind value for a UDPv4TransportDescriptor is given by the value eprosima::fastrtps::rtps::LOCATOR_KIND_UDPv4

6.2.1.2. UDPv6TransportDescriptor

UDPv6TransportDescriptor has no additional data members from the common ones described in UDPTransportDescriptor.

Note

The kind value for a UDPv6TransportDescriptor is given by the value eprosima::fastrtps::rtps::LOCATOR_KIND_UDPv6

6.2.2. Enabling UDP Transport

Fast DDS enables a UDPv4 transport by default. Nevertheless, the application can enable other UDP transports if needed. To enable a new UDP transport in a DomainParticipant, first create an instance of UDPv4TransportDescriptor (for UDPv4) or UDPv6TransportDescriptor (for UDPv6), and add it to the user transport list of the DomainParticipant.

The examples below show this procedure in both C++ code and XML file.

C++

DomainParticipantQos qos;

// Create a descriptor for the new transport.
auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
udp_transport->sendBufferSize = 9216;
udp_transport->receiveBufferSize = 9216;
udp_transport->non_blocking_send = true;

// Link the Transport Layer to the Participant.
qos.transport().user_transports.push_back(udp_transport);

// Avoid using the default transport
qos.transport().use_builtin_transports = false;

XML

<?xml version="1.0" encoding="UTF-8" ?>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
    <transport_descriptors>
        <transport_descriptor>
            <transport_id>udp_transport</transport_id>
            <type>UDPv4</type>
            <sendBufferSize>9216</sendBufferSize>
            <receiveBufferSize>9216</receiveBufferSize>
            <non_blocking_send>true</non_blocking_send>
        </transport_descriptor>
    </transport_descriptors>

    <participant profile_name="UDPParticipant">
        <rtps>
            <userTransports>
                <transport_id>udp_transport</transport_id>
            </userTransports>
            <useBuiltinTransports>false</useBuiltinTransports>
        </rtps>
    </participant>
</profiles>