6. Tutorials¶
Note
The commands shown in these examples are for the x64Linux3gcc5.4.0
architecture. For simplicity, all the examples assume that all the
applications run on the same host machine and the environment variable
NDDSHOME
is set to point to your RTI Connext DDS installation.
Note
Some of the examples require OpenSSL libraries and you must ensure they are
present in your library path before starting the applications.
Example commands assume the existence of the environment variable
OPENSSLHOMELIB
set to the directory that contains the OpenSSL libraries.
If you use the OpenSSL libraries distributed by RTI, the libraries directory will have the following locations:
- On UNIX-based systems:
<INSTALL DIR>
/<architecture>/release/lib- On Windows systems:
<INSTALL DIR>
\<architecture>\release\bin
6.1. Example: Using a Builtin UDP Transport¶
This example illustrates the basic functionality of Cloud Discovery Service. It shows how Connext DDS applications discover each other through an instance of Cloud Discovery Service.
6.1.1. Setup¶
The first step is to have two Connext DDS applications that can talk to each
other. For that, you can use an IDL file of your choice and run rtiddsgen to
generate the example. For instance, you can create a file named
CDSHelloWorld.idl
with the following content:
struct CDSHelloWorld {
long count;
};
Generate the publisher and subscriber examples by running the following command
(you can replace C++03
with any other supported language of your choice):
$NDDHSOME/bin/rtiddsgen -language C++03 -example x64Linux3gcc5.4.0 \
-ppDisable CDSHelloWorld.idl
Modify CDSHelloWorld_publisher.cxx
to increase the count
field each time
the sample is written. For instance, you can add the following line in the
main writing loop:
sample.count(count);
To compile the generated code, run:
make -f makefile_CDSHelloWorld_x64Linux3gcc5.4.0
You should have two executables, CDSHelloWorld_publisher
and
CDSHelloWorld_subscriber.
Now you can run the examples to make sure
everything is fine. You need to run the examples from the directory that
contains the generated USER_QOS_PROFILES.xml
.
From one terminal run:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher
Writing CDSHelloWorld, count 0
Writing CDSHelloWorld, count 1
...
From a different terminal, run:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber
CDSHelloWorld subscriber sleeping for 4 sec...
[count: 3]
CDSHelloWorld subscriber sleeping for 4 sec...
[count: 4]
...
You should see that the subscriber application receives the samples generated by the publisher application. This occurs because by default, DomainParticipants enable multicast. That is, participant announcements are automatically sent to a multicast destination.
6.1.2. Disable Multicast¶
Stop the applications and disable multicast. For that, you can specify an empty list of initial peers by setting the environment as follows:
export NDDS_DISCOVERY_PEERS=
Now if you run the publisher and subscriber applications again, notice that the subscriber does not receive any samples:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber
CDSHelloWorld subscriber sleeping for 4 sec...
CDSHelloWorld subscriber sleeping for 4 sec...
CDSHelloWorld subscriber sleeping for 4 sec...
...
You can stop the applications now.
6.1.3. Cloud Discovery Service in Action¶
To make the applications communicate, we need to run Cloud Discovery Service. From a terminal, run the following command:
$NDDSHOME/bin/rticlouddiscoveryservice
This command will run Cloud Discovery Service with the builtin configuration that listens on port 7400 over the UDP transport.
Re-run the publisher and subscriber applications, but this time set the initial peers to talk to Cloud Discovery Service (see Section 3.2.1). For that, you can set the environment from the application terminal as follows:
export NDDS_DISCOVERY_PEERS=rtps@localhost:7400
Now run the applications and verify that the subscriber receives samples. You can also stop Cloud Discovery Service and see how the applications continue communicating. In addition, you can start more publishers and subscribers, then see how they all discover each other and communicate.
6.2. Example: Using a Custom Listening Port¶
This example extends Example: Using a Builtin UDP Transport to run Cloud Discovery Service on a custom listening port over UDP. For that, you can run Cloud Discovery Service as follows:
$NDDSHOME/bin/rticlouddiscoveryservice -transport <port>
where <port>
represents the port number you want to use.
This example will use 10000
.
$NDDSHOME/bin/rticlouddiscoveryservice -transport 10000
To see which exact address Cloud Discovery Service is using to listen for participant
announcements, run the service with -verbosity 4
and look for the
line:
...
[CDS DETECTOR] listening for announcements on:
udpv4://172.17.0.2:10000
...
Set the initial peers accordingly to indicate where Cloud Discovery Service is listening:
export NDDS_DISCOVERY_PEERS=rtps@udpv4://172.17.0.2:10000
6.3. Example: Using RTI TCP Transport¶
This example extends Example: Using a Builtin UDP Transport to use the RTI TCP transport for both discovery and user data. The example shows how to run Cloud Discovery Service using the preregistered instance of RTI TCP transport.
Note
To run this example, you need RTI TCP Transport, which is included with Connext DDS.
6.3.1. Setup¶
The first step of this example is to configure the publisher and subscriber
applications so they communicate over the RTI TCP transport in LAN mode.
For that, you can include the following XML code within the
<participant_qos>
tag of the file USER_QOS_PROFILES.xml
generated by rtiddsgen.
<property>
<value>
<element>
<name>dds.transport.load_plugins</name>
<value>dds.transport.tcp.tcp1</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.library</name>
<value>nddstransporttcp</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.create_function</name>
<value>NDDS_Transport_TCPv4_create</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.server_bind_port</name>
<value>$(BIND_PORT)</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.parent.classid</name>
<value>NDDS_TRANSPORT_CLASSID_TCPV4_LAN</value>
</element>
</value>
</property>
The server bind port property value is obtained from the environment variable
$(BIND_PORT)
. This is a convenience for this example so you can reuse the
same file to specify a different port for the publisher and subscriber
applications, which is required when running on the same host machine.
Now you can run the applications. You need to run from the directory that
contains the generated USER_QOS_PROFILES.xml
you just modified.
From the terminal, run the Publisher application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0
export BIND_PORT=7401
export NDDS_DISCOVERY_PEERS=tcpv4_lan://localhost:7402
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher
Then run the Subscriber application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0
export BIND_PORT=7402
export NDDS_DISCOVERY_PEERS=tcpv4_lan://localhost:7401
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber
You should see the subscriber receive samples. This is possible since in the initial peers list, you indicated how the applications can reach each other.
6.3.2. Cloud Discovery Service in Action¶
Now you will use Cloud Discovery Service to provide the discovery for the applications.
From a terminal, run the following:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0
$NDDSHOME/bin/rticlouddiscoveryservice -transport tcpv4_lan:7400
This will run Cloud Discovery Service with the builtin configuration and override the
transport selection to use RTI TCP with bind port 7400
.
Re-run the publisher and subscriber application, but this time set the initial peers to talk to Cloud Discovery Service (see Section 3.2.1). For that, you can set the environment from the application terminal as follows:
For the Publisher application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0
export BIND_PORT=7401
export NDDS_DISCOVERY_PEERS=rtps@tcpv4_lan://localhost:7400
For the Subscriber application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0
export BIND_PORT=7402
export NDDS_DISCOVERY_PEERS=rtps@tcpv4_lan://localhost:7400
Now run the applications and verify that the subscriber receives samples. You can also stop Cloud Discovery Service and see how the applications continue communicating.
6.3.3. Configuration for TCP transport in WAN Mode using a public address¶
In this example, we have seen how to configure the TCP transport on the publisher and subscriber applications and Cloud Discovery Service to operate in LAN mode. However, there can be situations where Cloud Discovery Service or the publisher and subscriber applications are located across LANs or firewalls. In such a use case, it would be typical to have Cloud Discovery Service expose a public IP address which can be used for asymmetric discovery by the publisher or subscriber application.
To apply this example in that context, you would need to make the following changes:
6.3.3.1. USER_QOS_PROFILES.xml¶
Change the classid for the TCP transport used by the publisher and subscriber applications as follows:
<property>
<value>
<element>
<name>dds.transport.tcp.tcp1.parent.classid</name>
<value>NDDS_TRANSPORT_CLASSID_TCPV4_WAN</value>
</element>
</value>
</property>
6.3.3.2. Cloud Discovery Service¶
Create a configuration file for Cloud Discovery Service and select the TCP transport for the WAN alias and set the public address. This public address will be used by the publisher and the subscriber applications in their discovery peers.
<?xml version="1.0" ?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/6.0.0/rti_cloud_discovery_service.xsd">
<cloud_discovery_service name="ExampleTCPWAN">
<annotation>
<documentation>
<![CDATA[
Example that configures the pre-registered instance of the
RTI TCP WAN transport with a public IP address.
]]>
</documentation>
</annotation>
<transport>
<element>
<alias>tcpv4_wan</alias>
<receive_port>9000</receive_port>
<property>
<element>
<name>dds.transport.cds.tcp1.public_address</name>
<value>35.6.9.10:4589</value>
</element>
</property>
</element>
</transport>
</cloud_discovery_service>
</dds>
You can download the configuration file from here:
rti_cds_example_tcp_wan.xml
You can read more about the public_address property of the RTI TCP transport in
RTI TCP Transport configuration. An important thing to note here
is the format of the specified address. It follows the [ip:port]
format, where the IP
is the public address of the router that provides access to the WAN. The port is the router
port that is used to reach the private server_bind_port
inside the LAN from the outside.
In this example, the private server_bind_port
is 9000
and the external port is 4589
.
You should change these values as per your network configuration.
To use this configuration, from the terminal, run:
$NDDSHOME/bin/rticlouddiscoveryservice \
-cfgFile <working_dir>/rti_cds_example_tcp_wan.xml -cfgName ExampleTCPWAN
6.3.3.3. NDDS_DISCOVERY_PEERS¶
Run the publisher and subscriber applications exactly the way you did in Setup, but with one modification.
export NDDS_DISCOVERY_PEERS=rtps@tcpv4_wan://35.6.9.10:4589
You will see that until Cloud Discovery Service is started, the publisher and subscriber applications won’t discover each other. Once Cloud Discovery Service starts, these applications will complete discovery and start communicating with each other.
6.4. Example: Using RTI TCP Transport with RTI TLS Support¶
This example extends Example: Using a Builtin UDP Transport to enable TLS for secure communication. The example shows how to run Cloud Discovery Service using the preregistered transport instance of the RTI TCP transport with TLS enabled.
Note
To run this example, you need the RTI TCP Transport, which is shipped with RTI Connext DDS. Additionally, you will need to install the optional packages RTI TLS support and OpenSSL.
6.4.1. Setup¶
The first step in this example is to configure the publisher and subscriber
applications to communicate over the RTI TCP transport in LAN mode with
TLS enabled. For that, you can include the following XML code within the
<participant_qos>
tag of the file USER_QOS_PROFILES.xml
generated
by rtiddsgen.
<property>
<value>
<element>
<name>dds.transport.load_plugins</name>
<value>dds.transport.tcp.tcp1</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.library</name>
<value>nddstransporttcp</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.create_function</name>
<value>NDDS_Transport_TCPv4_create</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.server_bind_port</name>
<value>$(BIND_PORT)</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.parent.classid</name>
<value>NDDS_TRANSPORT_CLASSID_TLSV4_LAN</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.tls.verify.ca_file</name>
<value>cacert.pem</value>
</element>
<element>
<name>dds.transport.tcp.tcp1.tls.identity.certificate_chain_file</name>
<value>peer1.pem</value>
</element>
</value>
</property>
The server bind port property value is obtained from the environment variable
$(BIND_PORT)
. This is a convenience for this example so you can reuse the
same file to specify different ports for the publisher and subscriber
applications, which is required when running on the same host machine.
You must also provide certificate files. You can obtain example certificates from the following links:
Now you can run the applications. You need to run from the directory that
contains the generated USER_QOS_PROFILES.xml
that you just modified and
the certificates.
Because TLS is enabled, you must ensure that the RTI TLS Support and OpenSSL libraries are present in your library path before starting the applications. See the beginning of this section for a note on how to locate the OpenSSL libraries.
From the terminal, run the Publisher application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export BIND_PORT=7401
export NDDS_DISCOVERY_PEERS=tlsv4_lan://localhost:7402
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher
Then run the Subscriber application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export BIND_PORT=7402
export NDDS_DISCOVERY_PEERS=tlsv4_lan://localhost:7401
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber
You should see the subscriber receives samples. This is possible since in the initial peers list, you indicated how the applications can reach each other.
6.4.2. Cloud Discovery Service in Action¶
Now you will use Cloud Discovery Service to provide the discovery for the applications. In this case, you need to configure the transport with an instance of the RTI TCP transport with TLS enabled.
The configuration required for this example is shown below:
<?xml version="1.0"?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/6.0.0/rti_cloud_discovery_service.xsd">
<cloud_discovery_service name="ExampleTls">
<annotation>
<documentation><![CDATA[
Example that configures the pre-registered instance of the
RTI TCP transport with TLS enabled.
]]>
</documentation>
</annotation>
<transport>
<element>
<alias>tlsv4_lan</alias>
<receive_port>7400</receive_port>
<property>
<element>
<name>dds.transport.cds.tcp1.tls.verify.ca_file</name>
<value>cacert.pem</value>
</element>
<element>
<name>dds.transport.cds.tcp1.tls.identity.certificate_chain_file</name>
<value>peer1.pem</value>
</element>
</property>
</element>
</transport>
</cloud_discovery_service>
</dds>
You can download the configuration file from here:
rti_cds_example_tls.xml
From a terminal, run:
export LD_LIBRARY_PATH=$OPENSSLHOMELIB
$NDDSHOME/bin/rticlouddiscoveryservice \
-cfgFile <working_dir>/rti_cds_example_tls.xml -cfgName ExampleTls
This command will run Cloud Discovery Service with the custom configuration for this example,
located under the directory <working_dir>.
Re-run the publisher and subscriber applications, but this time set the initial peers to talk to Cloud Discovery Service (see Section 3.2.1). For that, you can set the environment from the application terminal as follows:
For the Publisher application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export BIND_PORT=7401
export NDDS_DISCOVERY_PEERS=rtps@tlsv4_lan://localhost:7400
For the Subscriber application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export BIND_PORT=7402
export NDDS_DISCOVERY_PEERS=rtps@tlsv4_lan://localhost:7400
Now run the applications and verify that the subscriber receives samples. You can also stop Cloud Discovery Service and see how the applications continue communicating.
6.5. Example: Using RTI Secure WAN Transport¶
This example extends the example in Section 6.1 to use RTI Secure WAN Transport for communication. The example shows how to run Cloud Discovery Service with a user-registered transport instance of RTI Secure WAN Transport.
Note
To run this example, you will need RTI Secure Wan Transport and its dependencies. Because DTLS is enabled, you must ensure that OpenSSL libraries are present in your library path before starting the applications. See the beginning of this section for a note on how to locate the OpenSSL libraries.
The provided example uses the WAN transport with security disabled. The WAN transport relies on a rendezvous server based on the STUN protocol in order to locate peers and establish communication. You can run the WAN server as follows:
${NDDSHOME}/bin/rtiwanserver -address <address> -port <port>
Where <address>
and <port>
define where the WAN server listens and how the
publisher and subscriber applications can reach it. In this example, the values
for the address and port are 127.0.0.1
and 3478, respectively.
You will need the WAN server to be running for all the applications to communicate.
6.5.1. Setup¶
The first step in this example is to configure the publisher and subscriber
applications to communicate over the RTI Secure WAN Transport. For that, you
can include the following XML code within the <participant_qos>
tag of the
file USER_QOS_PROFILES.xml
generated by rtiddsgen.
<property>
<value>
<element>
<name>dds.transport.load_plugins</name>
<value>dds.transport.wan_plugin.wan</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.library</name>
<value>nddstransportwan</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.create_function</name>
<value>NDDS_Transport_WAN_create</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.server</name>
<value>127.0.0.1</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.transport_instance_id</name>
<value>$(WAN_ID)</value>
</element>
</value>
</property>
The WAN ID property value is obtained from the environment variable
$(WAN_ID)
. This is a convenience for this example so you can specify a
different ID for the publisher and subscriber without having to modify the file.
Now you can run the applications. You need to run from the directory that
contains the generated USER_QOS_PROFILES.xml
that you just modified.
For the Publisher application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export WAN_ID=2
export NDDS_DISCOVERY_PEERS=wan://::3:127.0.0.1
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher
For the Subscriber application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export WAN_ID=3
export NDDS_DISCOVERY_PEERS=wan://::2:127.0.0.1
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber
You should see the subscriber receive samples. This is possible since in the initial peers list, you indicated how the applications can reach each other.
6.5.2. Cloud Discovery Service in Action¶
Now you will use Cloud Discovery Service to provide discovery for the applications. In this case, you need to configure the transport with a user-registered instance of the RTI Secure WAN Transport.
The configuration required for this example is shown below:
<?xml version="1.0"?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/6.0.0/rti_cloud_discovery_service.xsd">
<cloud_discovery_service name="ExampleWan">
<annotation>
<documentation><![CDATA[
Example that configures an user-registered instance of the
RTI WAN transport.
]]>
</documentation>
</annotation>
<transport>
<element>
<alias>wan</alias>
<receive_port>7400</receive_port>
<property>
<element>
<name>dds.transport.load_plugins</name>
<value>dds.transport.wan_plugin.wan</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.library</name>
<value>nddstransportwan</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.create_function</name>
<value>NDDS_Transport_WAN_create</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.server</name>
<value>127.0.0.1</value>
</element>
<element>
<name>dds.transport.wan_plugin.wan.transport_instance_id</name>
<value>1</value>
</element>
</property>
</element>
</transport>
</cloud_discovery_service>
</dds>
You can download the configuration file from here:
rti_cds_example_wan.xml
From a terminal, run the following command:
$NDDSHOME/bin/rticlouddiscoveryservice \
-cfgFile <working_dir>/rti_cds_example_wan.xml -cfgName ExampleWan
This command will run Cloud Discovery Service with the custom configuration for this example,
located under the directory <working_dir>
.
Re-run the publisher and subscriber application, but this time set the initial peers to talk to Cloud Discovery Service (see Section 3.2.1). For that, you can set the environment in the application terminal as follows:
For the Publisher application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export WAN_ID=2
export NDDS_DISCOVERY_PEERS=rtps@wan://::1:127.0.0.1:7400
For the Subscriber application:
export LD_LIBRARY_PATH=$NDDSHOME/lib/x64Linux3gcc5.4.0:$OPENSSLHOMELIB
export WAN_ID=3
export NDDS_DISCOVERY_PEERS=rtps@wan://::1:127.0.0.1:7400
Now run the applications and verify that the subscriber receives samples. You can also stop Cloud Discovery Service and see how the applications continue communicating.
6.6. Example: Discovering Connext DDS Micro applications with Cloud Discovery Service¶
This example illustrates how a Connext DDS Micro publisher application discovers a subscriber application via an instance of Cloud Discovery Service. To reiterate, we are assuming that we are on a network that doesn’t support multicast.
6.6.1. Installing Connext DDS Micro¶
Before we move to how Cloud Discovery Service is configured, you first need to have Connext DDS Micro installed. This example assumes that you have Connext DDS Micro version 3.0.0 or higher installed. This includes the rtiddsgen code generator. rtiddsgen can be used to generate example applications for publishing and subscribing to data. Earlier versions of rtiddsgen shipped with Connext DDS Micro didn’t support this functionality of generating examples. Please follow the step by step instructions in the Connext DDS Micro documentation to build the source code before moving on to the next steps.
6.6.2. Setup¶
Just like Connext DDS Pro, you will need an IDL file to feed into rtiddsgen to
create an example publisher and subscriber application. You can use the same
IDL as used in Section 6.1.1, CDSHelloWorld.idl
:
struct CDSHelloWorld {
long count;
};
Generate the publisher and subscriber applications by running the following command (you can also use C++):
$RTIMEHOME/rtiddsgen/scripts/rtiddsgen -micro -language C -example \
CDSHelloWorld.idl
Modify the CDSHelloWorld_publisher.c
file to increase the count
variable
with each written sample. For instance, you could add the following line to the
main writing loop:
sample->count = i;
The next step is to compile the applications.
Note
rtiddsgen creates a README.txt file which contains instructions on how to compile for most standard platforms.
For example:
$RTIMEHOME/resource/scripts/rtime-make --config Release --build --name \
x64Linux3gcc5.4.0 --target Linux --source-dir . \
-G "Unix Makefiles" --delete
This will generate two executables, CDSHelloWorld_publisher
and
CDSHelloWorld_subscriber
, under the objs/
folder. Run the examples to
make sure everything is as expected. From the top-level directory of the project,
run the following commands in two different terminals.
Terminal 1:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher
Written sample 1
Matched a subscriber
Written sample 2
Written sample 3
Written sample 4
Written sample 5
Terminal 2:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber
Running for 24 hours, press Ctrl-C to exit
Matched a publisher
Valid sample received
Valid sample received
Valid sample received
Valid sample received
You should see that the subscriber application receives the samples generated by the publisher application. This happens because the Connext DDS Micro application you created adds the loopback address as a default peer and runs on domain ID 0.
6.6.3. Understanding the Connext DDS Micro Peer Descriptor¶
Connext DDS Micro follows a different naming convention than Connext DDS Pro when it comes to its peer descriptor string. The peer descriptor format is:
[participant_index@][interface://]address
You can read more about this in the documentation. But the important point to note here is that Connext DDS Micro doesn’t allow you to directly specify a port number in the peer descriptor. So you need to be aware of which port number is selected based on the combination of participant index and domain ID. As you will see in more detail below, it is essential for the purpose of avoiding port conflicts.
For the use case of Cloud Discovery Service working with Connext DDS Micro, we have two configuration options:
- Configure by Port - You can compute the port number that the combination of peer descriptor and domain ID will refer to, based on the RTPS well-known ports specification. This idea is useful when one of the Connext DDS Micro publishers or subscribers is running on the same machine as Cloud Discovery Service.
- Configure by Domain ID - You can configure Cloud Discovery Service to run on a particular domain ID and by default it will assume the participant index 0. This idea is useful when Cloud Discovery Service is running on a separate machine than the publisher or the subscriber application.
6.6.4. Configure by Port¶
6.6.4.1. Setup¶
This example assumes that Cloud Discovery Service runs on the same machine as either the publisher or subscriber application or both. If you want to test a Cloud Discovery Service instance running on a different machine, you can still use this example by just changing the IP address part in the peer descriptor or you can check out the simpler method of Configure by Domain ID.
6.6.4.2. Changing the default initial peer¶
We are going to change the initial peer for the publisher and the subscriber
applications so they won’t be able to discover each other. To demonstrate this
example on the same machine, we will have the publisher and subscriber applications
contact a specific participant index that doesn’t correspond to either of them.
This will allow Cloud Discovery Service to come into the picture. To do that, run the publisher and
subscriber applications as follows, using the -peer
and -domain
command-line arguments.
CDSHelloWorld_publisher:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher -peer [5]@_udp://127.0.0.1 \
-domain 0
CDSHelloWorld_subscriber:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber -peer [5]@_udp://127.0.0.1 \
-domain 0
At this point you should notice that the publisher and subscriber applications cannot discover each other.
6.6.4.3. Cloud Discovery Service in Action¶
To make the applications communicate, we need a special configuration for Cloud Discovery Service. We need a configuration where Cloud Discovery Service listens on the ports referred to by the combination of peer descriptor and domain ID for the publisher and the subscriber applications.
The configuration from file
rti_cds_example_micro.xml
required for this example is shown below:
<cloud_discovery_service name="ExampleMicroByPort">
<annotation>
<documentation>
<![CDATA[
Example that configures CDS for Micro based on port numbers
computed from the domain ID and participant index
]]>
</documentation>
</annotation>
<transport>
<element>
<alias>udpv4</alias>
<receive_port kind="PORT">7420</receive_port>
</element>
</transport>
</cloud_discovery_service>
Here 7420
is the port number corresponding to participant index 5 on domain 0
when the RTPS well-known port mapping is kept to its default setting. You can read
more about the defaults in the API documentation.
This allows Cloud Discovery Service to discover both the publisher and subscriber applications and
relay their announcements to each other.
Note
Assuming there are no other Connext DDS Micro or Connext DDS Pro applications running on the system, if we start the publisher first, it will take the participant index 0 and the subscriber will take the participant index 1 on domain 0. If you have more applications running on your system on the same domain, you will have to increase the participant index in the peer descriptor to be a higher number (than 5 which was used) to avoid port conflicts with other running DDS applications. At the same time you will have to change the port number Cloud Discovery Service binds to, based on the corresponding combination of participant index and domain ID.
From the terminal, you can run the following command to use the above configuration:
$NDDSHOME/bin/rticlouddiscoveryservice -cfgFile <working_dir>/rti_cds_example_micro.xml \
-cfgName ExampleMicroByPort
Once Cloud Discovery Service starts, you should see the publisher and subscriber applications sending data to each other. You can stop Cloud Discovery Service and still see the applications continue to communicate.
6.6.5. Configure by Domain ID¶
6.6.5.1. Setup¶
This method assumes that Cloud Discovery Service runs on a separate machine. This is because if Cloud Discovery Service runs on the same machine as your publisher or subscriber application, you may end up with port conflicts depending on which application (the publisher, subscriber or Cloud Discovery Service) is started first. Cloud Discovery Service when working in this configuration tries to bind to the port corresponding to participant index 0. To see Cloud Discovery Service in action on the same machine as your Connext DDS Micro publisher, subscriber or both, please refer to the Configure by Port section.
6.6.5.2. Changing the default initial peer¶
We are going to change the initial peer for the publisher and the subscriber
application such that they won’t be able to discover each other. To do that we
will be running the publisher and subscriber applications as follows using the
-peer
and -domain
command-line arguments.
In the example commands below, note that 10.10.10.10
is a hypothetical
address for the machine running Cloud Discovery Service. You may want to replace that with the
IP address of your machine that is running Cloud Discovery Service.
CDSHelloWorld_publisher:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_publisher -peer _udp://10.10.10.10 \
-domain 0
CDSHelloWorld_subscriber:
./objs/x64Linux3gcc5.4.0/CDSHelloWorld_subscriber -peer _udp://10.10.10.10 \
-domain 0
At this point you should notice that the publisher and subscriber applications cannot discover each other.
6.6.5.3. Cloud Discovery Service in Action¶
To make the applications communicate, we need a special configuration for Cloud Discovery Service. We need a configuration where Cloud Discovery Service listens on a port computed from the RTPS well-known port mapping for a given domain ID. Note that the participant index cannot be configured and defaults to 0.
The configuration from file
rti_cds_example_micro.xml
required for this example is shown below:
<cloud_discovery_service name="ExampleMicroByDomainID">
<annotation>
<documentation>
<![CDATA[
Example that configures CDS for Micro based on domain ID since Micro
doesn't allow a peer descriptor to have a port number
]]>
</documentation>
</annotation>
<transport>
<element>
<alias>udpv4</alias>
<receive_port kind="DOMAIN_ID_DERIVED">0</receive_port>
</element>
</transport>
</cloud_discovery_service>
From the terminal, run the following command:
$NDDSHOME/bin/rticlouddiscoveryservice -cfgFile <working_dir>/rti_cds_example_micro.xml \
-cfgName ExampleMicroByDomainID
Once Cloud Discovery Service starts you should see the publisher and subscriber applications sending data to each other. As before, you can stop Cloud Discovery Service and still see the applications continue to communicate.