Skip to content

Commit e98b208

Browse files
RPC whole implementation (#281)
* Add RPC support (services) Signed-off-by: Juan López Fernández <[email protected]> * Apply suggestions Signed-off-by: Juan López Fernández <[email protected]> * Fix rebase errors Signed-off-by: Juan López Fernández <[email protected]> * Add repeater condition Signed-off-by: Juan López Fernández <[email protected]> * Document code and improve error handling Signed-off-by: Juan López Fernández <[email protected]> * Uncrustify Signed-off-by: Juan López Fernández <[email protected]> * Add RPC Docker Compose tests Signed-off-by: jparisu <[email protected]> * Add vulcanexus to github action Signed-off-by: jparisu <[email protected]> * Fix windows compilation Signed-off-by: jparisu <[email protected]> * Fix target messages from router Signed-off-by: jparisu <[email protected]> * Add Writer matching debug log Signed-off-by: jparisu <[email protected]> * Fix race condition in on_data_available task_map Signed-off-by: jparisu <[email protected]> * Increase timeout of ros2 services tests Signed-off-by: jparisu <[email protected]> * uncrustify Signed-off-by: jparisu <[email protected]> * Limit number of elements in registries Signed-off-by: Juan López Fernández <[email protected]> * Take reader mutex when enabling it Signed-off-by: Juan López Fernández <[email protected]> * More accurate documentation Signed-off-by: Juan López Fernández <[email protected]> * Fix compose tests Signed-off-by: Juan López Fernández <[email protected]> * Some fixes Signed-off-by: Juan López Fernández <[email protected]> * Apply suggestions Signed-off-by: Juan López Fernández <[email protected]> * Uncrustify Signed-off-by: Juan López Fernández <[email protected]> Signed-off-by: Juan López Fernández <[email protected]> Signed-off-by: jparisu <[email protected]> Co-authored-by: Juan López Fernández <[email protected]>
1 parent e1447b3 commit e98b208

File tree

106 files changed

+4263
-684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+4263
-684
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ RUN pip3 install \
4141

4242
WORKDIR /ddsrouter
4343

44-
ARG ddsrouter_branch=main
44+
4545
ARG fastdds_branch=master
46+
ARG ddsrouter_branch=main
4647

4748
RUN mkdir src && \
4849
wget https://raw.githubusercontent.com/eProsima/DDS-Router/${ddsrouter_branch}/ddsrouter.repos && \
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ARG docker_image_base
2+
FROM $docker_image_base
3+
4+
5+
6+
# Avoid interactuation with installation of some package that needs the locale.
7+
ENV TZ=Europe/Madrid
8+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
9+
10+
# Avoids using interactions during building
11+
ENV DEBIAN_FRONTEND=noninteractive
12+
13+
# Use a bash shell so it is possigle to run things like `source` (required for colcon builds)
14+
SHELL ["/bin/bash", "-c"]
15+
16+
ARG docker_image_base
17+
RUN echo "Docker Base image used: ${docker_image_base}"
18+
19+
# Install message interface required package
20+
RUN source "/opt/vulcanexus/$VULCANEXUS_DISTRO/setup.bash" && \
21+
apt-get update && \
22+
apt-get install -y \
23+
ros-humble-example-interfaces
24+
25+
# Copy and use run.bash as entrypoint
26+
COPY run.bash /root/run.bash
27+
28+
RUN chmod +x /root/run.bash
29+
30+
ENTRYPOINT ["/root/run.bash" ]

.github/docker/vulcanexus/run.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Setup environment
4+
source "/opt/vulcanexus/$VULCANEXUS_DISTRO/setup.bash"
5+
6+
exec "$@"

.github/workflows/docker_test.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,94 @@ on:
1818
schedule:
1919
- cron: '0 0 * * *'
2020

21+
env:
22+
REGISTRY: ghcr.io
23+
2124
jobs:
2225
docker_test:
26+
2327
runs-on: ubuntu-20.04
28+
2429
env:
2530
DEFAULT_FASTDDS_BRANCH: 'master'
2631
DEFAULT_DDSROUTER_BRANCH: 'main'
2732
DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE: "ddsrouter:ci"
33+
DDSROUTER_COMPOSE_TEST_ROS2_DOCKER_IMAGE: "vulcanexus:ci"
34+
2835
steps:
36+
37+
# Sync current branch
2938
- name: Sync eProsima/DDS-Router repository
3039
uses: actions/checkout@v2
3140
with:
3241
path: src/DDS-Router
3342

43+
# Echo Env Var to debug workflow
3444
- name: Echo env variables
3545
run: |
3646
echo "--- Input Variables ---"
3747
echo "github.event.inputs.fastdds_branch: ${{ github.event.inputs.fastdds_branch }}"
3848
echo "github.event.inputs.ddsrouter_branch: ${{ github.event.inputs.ddsrouter_branch }}"
39-
4049
echo "--- Github Environment Variables ---"
4150
echo "github.head_ref: ${{ github.head_ref }}"
42-
4351
echo "--- Environment Variables ---"
4452
echo "DEFAULT_FASTDDS_BRANCH: ${{ env.DEFAULT_FASTDDS_BRANCH }}"
4553
echo "DEFAULT_DDSROUTER_BRANCH: ${{ env.DEFAULT_DDSROUTER_BRANCH }}"
46-
echo "DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE: ${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }}"
4754
48-
# Install colcon and required packages
49-
- name: Install apt packages
50-
uses: ./src/DDS-Router/.github/actions/install-apt-packages
55+
# It enables the use of Vulcanexus container
56+
- name: Log in to the Container registry
57+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
58+
with:
59+
registry: ${{ env.REGISTRY }}
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.DOCKER_CONTAINER_REGISTRY_TOKEN }}
5162

52-
- name: Install Python packages
53-
uses: ./src/DDS-Router/.github/actions/install-python-packages
63+
# Build Vulcanexus Docker image
64+
- name: Build custom Vulcanexus Docker image
65+
run: |
66+
cd src/DDS-Router/.github/docker/vulcanexus
67+
docker build \
68+
--no-cache \
69+
--build-arg docker_image_base=ghcr.io/eprosima/ubuntu-vulcanexus:humble-core \
70+
-t ${{ env.DDSROUTER_COMPOSE_TEST_ROS2_DOCKER_IMAGE }} \
71+
-f Dockerfile .
5472
73+
# Build DDS Router Docker image
5574
- name: Build DDS Router Docker image
5675
run: |
57-
cd src/DDS-Router/.github/docker
76+
cd src/DDS-Router/.github/docker/ddsrouter
5877
docker build \
5978
--no-cache \
6079
--build-arg fastdds_branch=${{ github.event.inputs.fastdds_branch || env.DEFAULT_FASTDDS_BRANCH }} \
6180
--build-arg ddsrouter_branch=${{ github.event.inputs.ddsrouter_branch || github.head_ref || env.DEFAULT_DDSROUTER_BRANCH }} \
6281
-t ${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }} \
6382
-f Dockerfile .
83+
echo "DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE: ${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }}"
84+
85+
# Install colcon and required apt packages
86+
- name: Install apt packages
87+
uses: ./src/DDS-Router/.github/actions/install-apt-packages
88+
89+
# Install colcon and required python packages
90+
- name: Install Python packages
91+
uses: ./src/DDS-Router/.github/actions/install-python-packages
6492

65-
- name: Check if Docker image exists
93+
# Check Docker images exist
94+
- name: Check if Docker images exist
6695
run: |
6796
[ -n "$(docker images -q ${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }})" ] || echo "DDS Router Docker image does not exists"
97+
[ -n "$(docker images -q ${{ env.DDSROUTER_COMPOSE_TEST_ROS2_DOCKER_IMAGE }})" ] || echo "Vulcanexus image does not exists"
6898
99+
# Run ddsrouter_test compose tests
69100
- name: Run tests
70101
run: |
71102
export DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE=${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }}
103+
export DDSROUTER_COMPOSE_TEST_ROS2_DOCKER_IMAGE=${{ env.DDSROUTER_COMPOSE_TEST_ROS2_DOCKER_IMAGE }}
72104
colcon build --event-handlers console_direct+ --packages-up-to ddsrouter_test --cmake-args -DBUILD_COMPOSE_TESTS=ON
73105
colcon test \
74106
--packages-select ddsrouter_test \
75107
--event-handlers console_direct+ \
76108
--return-code-on-test-failure \
77109
--ctest-args \
78110
--label-exclude xfail \
79-
--timeout 60
111+
--timeout 60

ddsrouter_core/include/ddsrouter_core/types/dds/Data.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define _DDSROUTERCORE_TYPES_DDS_DATA_HPP_
2121

2222
#include <fastdds/rtps/common/SerializedPayload.h>
23+
#include <fastdds/rtps/common/WriteParams.h>
2324

2425
#include <ddsrouter_core/library/library_dll.h>
2526
#include <ddsrouter_core/types/dds/Guid.hpp>
@@ -47,6 +48,12 @@ struct DataReceived
4748

4849
//! Id of the participant from which the Reader has received the data.
4950
ParticipantId participant_receiver;
51+
52+
//! Sequence number of the received cache change
53+
eprosima::fastrtps::rtps::SequenceNumber_t sequenceNumber;
54+
55+
//! Write params associated to the received cache change
56+
eprosima::fastrtps::rtps::WriteParams write_params;
5057
};
5158

5259
//! \c octet to stream serializator

ddsrouter_core/include/ddsrouter_core/types/dds/Guid.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ class DDSROUTER_CORE_DllAPI Guid : public fastrtps::rtps::GUID_t
3737
//! Using parent constructors
3838
using fastrtps::rtps::GUID_t::GUID_t;
3939

40+
//! Default constructor
41+
Guid() = default;
42+
43+
//! Copy constructor
44+
Guid(
45+
const fastrtps::rtps::GUID_t& x);
46+
47+
//! Move constructor
48+
Guid(
49+
fastrtps::rtps::GUID_t&& x);
50+
4051
//! Equal operator (inherited from GUID_t)
4152
Guid& operator = (
4253
const fastrtps::rtps::GUID_t& other) noexcept;

ddsrouter_core/include/ddsrouter_core/types/endpoint/Endpoint.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include <ddsrouter_core/library/library_dll.h>
2323
#include <ddsrouter_core/types/dds/Guid.hpp>
2424
#include <ddsrouter_core/types/endpoint/QoS.hpp>
25+
#include <ddsrouter_core/types/participant/ParticipantId.hpp>
2526
#include <ddsrouter_core/types/topic/RealTopic.hpp>
27+
#include <ddsrouter_core/types/topic/RPCTopic.hpp>
2628

2729
namespace eprosima {
2830
namespace ddsrouter {
@@ -70,7 +72,8 @@ class Endpoint
7072
const EndpointKind& kind,
7173
const Guid& guid,
7274
const QoS& qos,
73-
const RealTopic& topic) noexcept;
75+
const RealTopic& topic,
76+
const ParticipantId& discoverer_participant_id = ParticipantId()) noexcept;
7477

7578
//! Endpoint kind getter
7679
DDSROUTER_CORE_DllAPI EndpointKind kind() const noexcept;
@@ -84,6 +87,9 @@ class Endpoint
8487
//! Topic getter
8588
DDSROUTER_CORE_DllAPI RealTopic topic() const noexcept;
8689

90+
//! Id of participant who discovered this endpoint
91+
DDSROUTER_CORE_DllAPI ParticipantId discoverer_participant_id() const noexcept;
92+
8793
//! Whether the endpoint referenced is currently active
8894
DDSROUTER_CORE_DllAPI bool active() const noexcept;
8995

@@ -104,6 +110,9 @@ class Endpoint
104110
//! Whether the endpoint is a reader
105111
DDSROUTER_CORE_DllAPI bool is_reader() const noexcept;
106112

113+
//! Whether the endpoint belongs to a RPC server (i.e. is request reader or reply writer)
114+
DDSROUTER_CORE_DllAPI bool is_server_endpoint() const noexcept;
115+
107116
//! Copy operator
108117
DDSROUTER_CORE_DllAPI Endpoint& operator =(
109118
const Endpoint& other) noexcept;
@@ -129,6 +138,9 @@ class Endpoint
129138
//! Whether the endpoint is currently active
130139
bool active_;
131140

141+
//! Id of participant who discovered this endpoint
142+
ParticipantId discoverer_participant_id_;
143+
132144
// Allow operator << to use private variables
133145
DDSROUTER_CORE_DllAPI friend std::ostream& operator <<(
134146
std::ostream&,

ddsrouter_core/include/ddsrouter_core/types/participant/ParticipantId.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ class ParticipantId
8282
DDSROUTER_CORE_DllAPI bool operator ==(
8383
const ParticipantId& other) const noexcept;
8484

85+
/**
86+
* @brief Not equals operator
87+
*
88+
* Check whether both objects identify different participants
89+
*
90+
* @param [in] other \c ParticipantId to compare with
91+
* @return true if this Ids are not equal. False otherwise.
92+
*/
93+
DDSROUTER_CORE_DllAPI bool operator !=(
94+
const ParticipantId& other) const noexcept;
95+
8596
/**
8697
* @brief Minor operator
8798
*
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file RPCTopic.hpp
17+
*/
18+
19+
#ifndef _DDSROUTERCORE_TYPES_TOPIC_RPCTOPIC_HPP_
20+
#define _DDSROUTERCORE_TYPES_TOPIC_RPCTOPIC_HPP_
21+
22+
#include <ddsrouter_core/types/topic/RealTopic.hpp>
23+
24+
namespace eprosima {
25+
namespace ddsrouter {
26+
namespace core {
27+
namespace types {
28+
29+
/**
30+
* Class that represents a RPC service in a DDS network.
31+
* It is composed of a pair of DDS topics; one for request and other for reply.
32+
* These two DDS topics are formed by mangling a \c service_name with different prefix and suffixes.
33+
*/
34+
class RPCTopic
35+
{
36+
public:
37+
38+
//! Constructor by service name, request topic and reply topic
39+
RPCTopic(
40+
const std::string& service_name,
41+
const RealTopic& topic_request,
42+
const RealTopic& topic_reply) noexcept;
43+
44+
//! Constructor by request/reply topic only (infers service name and the other request/reply topic)
45+
RPCTopic(
46+
const RealTopic& topic) noexcept;
47+
48+
//! Service name getter
49+
const std::string& service_name() const;
50+
51+
//! Request topic getter
52+
const RealTopic& request_topic() const;
53+
54+
//! Reply topic getter
55+
const RealTopic& reply_topic() const;
56+
57+
//! Whether a topic is a request topic
58+
static bool is_request_topic(
59+
const RealTopic& topic);
60+
61+
//! Whether a topic is a reply topic
62+
static bool is_reply_topic(
63+
const RealTopic& topic);
64+
65+
//! Whether a topic is a service topic (request or reply topic)
66+
static bool is_service_topic(
67+
const RealTopic& topic);
68+
69+
/**
70+
* Minor operator
71+
*
72+
* It compares both service names lexicographically
73+
*/
74+
bool operator <(
75+
const RPCTopic& other) const;
76+
77+
protected:
78+
79+
//! Name of the service
80+
std::string service_name_;
81+
82+
//! Topic used for transmitting requests
83+
RealTopic request_topic_;
84+
85+
//! Topic used for transmitting replies
86+
RealTopic reply_topic_;
87+
88+
static const std::string REQUEST_PREFIX_STR;
89+
static const std::string REPLY_PREFIX_STR;
90+
static const std::string REQUEST_STR;
91+
static const std::string REPLY_STR;
92+
static const std::string RESPONSE_STR;
93+
};
94+
95+
/**
96+
* Serialization method
97+
*
98+
* It prints the service name inside "{}"
99+
* Example: RPCTopic{ServiceName}
100+
*/
101+
std::ostream& operator <<(
102+
std::ostream& os,
103+
const RPCTopic& a);
104+
105+
} /* namespace types */
106+
} /* namespace core */
107+
} /* namespace ddsrouter */
108+
} /* namespace eprosima */
109+
110+
#endif /* _DDSROUTERCORE_TYPES_TOPIC_RPCTOPIC_HPP_ */

0 commit comments

Comments
 (0)