Skip to content

Commit 19d2357

Browse files
authored
Merge pull request #741 from iutrilladn/master
ROUTING-1322 - Improving UDP socket adapter plugin example. Adding Data-diode reference in doc.
2 parents 67ce08a + e25f691 commit 19d2357

33 files changed

+1836
-21
lines changed

examples/routing_service/udp_socket_adapter/CMakeLists.txt renamed to examples/routing_service/udp_socket_adapter_dynamic/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
2+
# (c) 2025 Copyright, Real-Time Innovations, Inc. All rights reserved.
33
#
44
# RTI grants Licensee a license to use, modify, compile, and create derivative
55
# works of the Software. Licensee has the right to distribute object form
@@ -37,6 +37,8 @@ add_library(${PROJECT_NAME}
3737
"${CMAKE_CURRENT_SOURCE_DIR}/src/SocketInputDiscoveryStreamReader.hpp"
3838
"${CMAKE_CURRENT_SOURCE_DIR}/src/SocketStreamReader.cxx"
3939
"${CMAKE_CURRENT_SOURCE_DIR}/src/SocketStreamReader.hpp"
40+
"${CMAKE_CURRENT_SOURCE_DIR}/src/SocketStreamWriter.cxx"
41+
"${CMAKE_CURRENT_SOURCE_DIR}/src/SocketStreamWriter.hpp"
4042
"${CMAKE_CURRENT_SOURCE_DIR}/src/UdpSocket.cxx"
4143
"${CMAKE_CURRENT_SOURCE_DIR}/src/UdpSocket.hpp"
4244
)
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Example Code: Routing Service C++11 Socket Adapter using Dynamic Data
2+
3+
## Example Description
4+
5+
This example shows how to implement a simple Routing Service Adapter plugin
6+
in C++11 to receive data from a UDP socket using RTI Routing Service.
7+
8+
This examples uses dynamic data API and there is no need to know the data type
9+
information beforehand.
10+
11+
The code in this directory provides the following components:
12+
13+
- `src/SocketAdapter` implements the plugin that is loaded by *RTI Routing
14+
Service*. It responsible for creating and deleting connections.
15+
- `src/SocketConnection` implements a connection. This component is
16+
responsible for the creation and deletion of `StreamReaders`.
17+
- `src/SocketInputDiscoveryStreamReader` implements the logic necessary to
18+
propagate information about the discovered input streams (in this case
19+
sockets) to the Routing Service.
20+
- `src/SocketStreamReader` implements a `StreamReader` that reads sample
21+
information from a UDP socket.
22+
- `src/SocketStreamWriter` implements a `StreamWriter` that sends sample
23+
information to a UDP socket.
24+
25+
26+
For more details, please refer to the *RTI Routing Service SDK* documentation.
27+
28+
## Building the C++ example
29+
30+
In order to build this example, you need to define the variables
31+
`CONNEXTDDS_DIR` and `CONNEXTDDS_ARCH`. You can do so by exporting them
32+
manually, by sourcing the `rtisetenv` script for your architecture, or by
33+
passing them to the `cmake` command as arguments:
34+
35+
```bash
36+
mkdir build
37+
cd build
38+
cmake -DCONNEXTDDS_DIR=<Connext DDS Directory> \ # If not exported
39+
-DCONNEXTDDS_ARCH=<Connext DDS Architecture> \ # If not exported
40+
-DBUILD_SHARED_LIBS=ON|OFF \ # ON is preferred
41+
-DCMAKE_BUILD_TYPE=Debug|Release ..
42+
cmake --build .
43+
cd ..
44+
```
45+
46+
Example command for Windows:
47+
48+
```bash
49+
cmake .. -DCONNEXTDDS_DIR="%NDDSHOME%" -DCONNEXTDDS_ARCH=x64Win64VS2015 -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -A x64 -G "Visual Studio 17 2022"
50+
cd ..
51+
```
52+
53+
**Note**: You do not need to define `CONNEXTDDS_ARCH` if you only have one
54+
architecture target installed in your system.
55+
56+
**Note**: When compiling on a Windows 64-bit machine you will need to add the
57+
`-A x64` parameter to the call to CMake.
58+
59+
**Note:** If you are using a multi-configuration generator, such as Visual
60+
Studio Solutions, you can specify the configuration mode to build as follows:
61+
62+
```bash
63+
cmake --build . --config Release|Debug
64+
```
65+
66+
Here is more information about generating
67+
[Visual Studio Solutions for Windows using CMake](https://cmake.org/cmake/help/v3.16/generator/Visual%20Studio%2016%202019.html#platform-selection).
68+
69+
**Note:** `BUILD_SHARED_LIBS` allows you to control if the generated library
70+
for this example is a static or a dynamic shared library. The following
71+
sections assume you are building a dynamic shared library. However, Routing
72+
Service also supports static linking of adapters. To use this functionality
73+
you would need to create an application that uses Routing Service as a library
74+
component and statically links to this `SocketAdapter` library.
75+
76+
### Cross-compilation
77+
78+
When you need to cross-compile the example, the above
79+
command will not work, the assigned compiler won't be the cross-compiler and
80+
errors may happen when linking against the cross-compiled Connext binaries.
81+
To fix this, you have to create a file with the architecture name and call
82+
CMake with a specific flag called ``-DCMAKE_TOOLCHAIN_FILE``.
83+
An example of the file to create with the toolchain settings (e.g. for an
84+
ARM architectures):
85+
86+
```cmake
87+
set(CMAKE_SYSTEM_NAME Linux)
88+
set(toolchain_path "<path to>/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian")
89+
set(CMAKE_C_COMPILER "${toolchain_path}/bin/arm-linux-gnueabihf-gcc")
90+
set(CMAKE_CXX_COMPILER "${toolchain_path}/bin/arm-linux-gnueabihf-g++")
91+
```
92+
93+
Then you can call CMake like this:
94+
95+
```bash
96+
cmake -DCONNEXTDDS_DIR=<connext dir> -DCMAKE_TOOLCHAIN_FILE=<toolchain file created above>
97+
-DCONNEXTDDS_ARCH=<connext architecture> ..
98+
```
99+
100+
## Running the C++ example
101+
102+
To run the example, you just need to run the following commands from the top
103+
level folder. This example has been written to allow easy experimentation with
104+
the RTI DDSPing tool shipped with *RTI Connext DDS* installer bundle. If you wish
105+
to create a real Routing Service adapter, you should modify the code and XML accordingly.
106+
107+
There are 2 configurations (`-cfgName`) in the Routing Service XML file:
108+
109+
- **SocketAdapterToDDS** - It reads data from a UDP socket using the
110+
SocketAdapter and outputs it to DDS. You can visualize the ouptut by running:
111+
112+
- **DDSToSocketAdapter** - It sends data from DDS to a UDP socket. You can
113+
publish DDS data by running command:
114+
115+
116+
To run Routing Service, you will need first to set up your environment as
117+
follows.
118+
119+
Before running the RTI Routing Service, you need to specify where the
120+
`SocketAdapterCpp` library is located as shown below:
121+
122+
Linux:
123+
124+
```bash
125+
$export RTI_LD_LIBRARY_PATH=$NDDSHOME/lib/<Connext DDS Architecture>:<Path to SocketAdapterCpp library, the build/ folder>
126+
```
127+
128+
Windows:
129+
130+
```bash
131+
set PATH=%NDDSHOME%/lib/<Connext DDS Architecture>;<Path to SocketAdapterCpp library, the build/Release folder>
132+
```
133+
134+
The SocketAdapterCpp library will be in the `./build` folder.
135+
136+
```bash
137+
# From the build/ directory
138+
$NDDSHOME/bin/rtiroutingservice -cfgFile RsSocketAdapter.xml -cfgName SocketAdapterToDDS
139+
```
140+
141+
Here is an output from a sample run:
142+
143+
```bash
144+
$export RTI_LD_LIBRARY_PATH=~/$NDDSHOME/lib/$CONNEXT_ARCH:~/udp_socket_adapter_dynamic/build/
145+
146+
$ $NDDSHOME/bin/rtiroutingservice -cfgFile RsSocketAdapter.xml -cfgName SocketAdapterToDDS
147+
RTI Routing Service 7.3.0 executing (with name SocketAdapterToSocketAdapter)
148+
```
149+
150+
Now you'll need to send data to the UDP sockets. By default, DDS Ping data is
151+
expected on `127.0.0.1:10203`. You can change both the expected type and topic name
152+
and the UDP socket configuration on `RsSocketAdapter.xml`.
153+
154+
To run a simple test, run in different terminals:
155+
156+
```bash
157+
$export RTI_LD_LIBRARY_PATH=~/$NDDSHOME/lib/$CONNEXT_ARCH:~/udp_socket_adapter_dynamic/build/
158+
159+
$ $NDDSHOME/bin/rtiroutingservice -cfgFile RsSocketAdapter.xml -cfgName DDSToSocketAdapter
160+
RTI Routing Service 7.3.0 executing (with configuration=DDSToSocketAdapter)
161+
```
162+
163+
164+
```bash
165+
$NDDSHOME/bin/rtiddsping -publisher -domainId 0
166+
```
167+
168+
## Running a data-diode example
169+
170+
You can configure a data-diode scenario by using two Routing Services instances;
171+
- One using **DDSToSocketAdapter** configuration to publish DDS data over a one direction UDP socket
172+
- The other using **SocketAdapterToDDS** configuration to convert back to DDS samples
173+
```
174+
┌───────────┐ ┌─────────────┐ ┌─────────────┐ ┌───────────┐
175+
│ Connext │ │ Routing │ ┌────────────────┐ │ Routing │ │ Connext │
176+
│ App ├─►│ Service ├───►│ UDP DATA DIODE ├──►│ Service ├─►│ App │
177+
│ │ │ DDS TO UDP │ └────────────────┘ │ UDP TO DDS │ │ │
178+
└───────────┘ └─────────────┘ └─────────────┘ └───────────┘
179+
```
180+
To run this example in a local machine:
181+
```bash
182+
$export RTI_LD_LIBRARY_PATH=~/$NDDSHOME/lib/$CONNEXT_ARCH:~/udp_socket_adapter_dynamic/build/
183+
184+
$ $NDDSHOME/bin/rtiroutingservice -cfgFile RsSocketAdapter.xml -cfgName SocketAdapterToDDS
185+
RTI Routing Service 7.3.0 executing (with configuration=SocketAdapterToDDS)
186+
```
187+
And in a different terminal:
188+
```bash
189+
$export RTI_LD_LIBRARY_PATH=~/$NDDSHOME/lib/$CONNEXT_ARCH:~/udp_socket_adapter_dynamic/build/
190+
191+
$ $NDDSHOME/bin/rtiroutingservice -cfgFile RsSocketAdapter.xml -cfgName DDSToSocketAdapter
192+
RTI Routing Service 7.3.0 executing (with configuration=DDSToSocketAdapter)
193+
```
194+
195+
Using the default configuration from RsSocketAdapter.xml, you need to publish DDS Ping data
196+
on domain id 0 and subscribe to DSS Ping data on domain id 1:
197+
198+
```bash
199+
$NDDSHOME/bin/rtiddsping -publisher -domainId 0
200+
```
201+
202+
```bash
203+
$NDDSHOME/bin/rtiddsping -subscriber -domainId 1
204+
```
205+
206+
## Requirements
207+
208+
To run this example you will need:
209+
210+
- RTI Connext Professional version 6.0.0 or higher.
211+
- CMake version 3.10 or higher.
212+
- A target platform with support for RTI Routing Service and C++11.
213+
- Python3.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0"?>
2+
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/7.3.0/rti_routing_service.xsd">
4+
5+
<plugin_library name="AdapterLib">
6+
<adapter_plugin name="SocketAdapter">
7+
<dll>SocketAdapterCpp</dll>
8+
<create_function>SocketAdapter_create_adapter_plugin</create_function>
9+
</adapter_plugin>
10+
</plugin_library>
11+
12+
<!-- Demonstrates a scenario where the SocketAdapter reads ping data from a socket
13+
and the DDSAdapter writes it to a DDS domain -->
14+
<routing_service name="SocketAdapterToDDS">
15+
<domain_route name="SocketBridge">
16+
<connection name="SocketConnection" plugin_name="AdapterLib::SocketAdapter">
17+
</connection>
18+
<participant name="DDSConnection">
19+
<domain_id>1</domain_id>
20+
<domain_participant_qos base_name="BuiltinQosLib::Generic.Common" />
21+
</participant>
22+
<session name="session">
23+
<route>
24+
<input connection="SocketConnection">
25+
<creation_mode>IMMEDIATE</creation_mode>
26+
<registered_type_name>PingType</registered_type_name>
27+
<stream_name>PingStream</stream_name>
28+
<!-- You must set these 2 properties -->
29+
<property>
30+
<value>
31+
<!-- Receive address for UDP data -->
32+
<element>
33+
<name>receive_address</name>
34+
<value>127.0.0.1</value>
35+
</element>
36+
<!-- Receive port for UDP data -->
37+
<element>
38+
<name>receive_port</name>
39+
<value>10203</value>
40+
</element>
41+
</value>
42+
</property>
43+
</input>
44+
<dds_output participant="DDSConnection">
45+
<creation_mode>ON_DOMAIN_MATCH</creation_mode>
46+
<registered_type_name>PingType</registered_type_name>
47+
<topic_name>PingTopic</topic_name>
48+
<datawriter_qos base_name="BuiltinQosLib::Generic.Common" />
49+
</dds_output>
50+
</route>
51+
</session>
52+
</domain_route>
53+
</routing_service>
54+
55+
<routing_service name="DDSToSocketAdapter">
56+
<domain_route name="SocketBridge">
57+
<connection name="SocketConnection" plugin_name="AdapterLib::SocketAdapter">
58+
<register_type name="PingType" type_ref="PingType" />
59+
</connection>
60+
<participant name="DDSConnection">
61+
<domain_id>0</domain_id>
62+
<domain_participant_qos base_name="BuiltinQosLib::Generic.Common" />
63+
<register_type name="PingType" type_ref="PingType" />
64+
</participant>
65+
<session>
66+
<route>
67+
<output connection="SocketConnection">
68+
<creation_mode>ON_ROUTE_MATCH</creation_mode>
69+
<registered_type_name>PingType</registered_type_name>
70+
<stream_name>PingStream</stream_name>
71+
<property> <!--Set
72+
the IP addresses and ports for sender and destination-->
73+
<value>
74+
<element>
75+
<name>send_address</name>
76+
<value>127.0.0.1</value>
77+
</element>
78+
<element>
79+
<name>send_port</name>
80+
<value>0</value> <!--Set
81+
to 0 for automatic use of available port-->
82+
</element>
83+
<element>
84+
<name>dest_address</name>
85+
<value>127.0.0.1</value>
86+
</element>
87+
<element>
88+
<name>dest_port</name>
89+
<value>10203</value>
90+
</element>
91+
</value>
92+
</property>
93+
</output>
94+
<dds_input participant="DDSConnection">
95+
<creation_mode>ON_DOMAIN_MATCH</creation_mode>
96+
<registered_type_name>PingType</registered_type_name>
97+
<topic_name>PingTopic</topic_name>
98+
<datareader_qos base_name="BuiltinQosLib::Generic.Common" />
99+
</dds_input>
100+
</route>
101+
</session>
102+
</domain_route>
103+
</routing_service>
104+
105+
</dds>

examples/routing_service/udp_socket_adapter/src/SocketAdapter.cxx renamed to examples/routing_service/udp_socket_adapter_dynamic/src/SocketAdapter.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
2+
* (c) 2025 Copyright, Real-Time Innovations, Inc. All rights reserved.
33
*
44
* RTI grants Licensee a license to use, modify, compile, and create derivative
55
* works of the Software. Licensee has the right to distribute object form

examples/routing_service/udp_socket_adapter/src/SocketAdapter.hpp renamed to examples/routing_service/udp_socket_adapter_dynamic/src/SocketAdapter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
2+
* (c) 2025 Copyright, Real-Time Innovations, Inc. All rights reserved.
33
*
44
* RTI grants Licensee a license to use, modify, compile, and create derivative
55
* works of the Software. Licensee has the right to distribute object form

0 commit comments

Comments
 (0)