Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/docker/ddsrouter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ RUN pip3 install \
colcon-mixin \
lxml \
vcstool \
GitPython \
pyyaml \
jsonschema
GitPython

WORKDIR /ddsrouter

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ log/
docs/rst/_static/css/eprosima-furo.css
docs/rst/_static/eprosima-logo-white.png
docs/rst/_templates/sidebar/
docs/resources/examples/


### Python ###
Expand Down
28 changes: 28 additions & 0 deletions ddsrouter_yaml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ compile_test_library(
"${PROJECT_SOURCE_DIR}/test" # Test directory
)

###############################################################################
# Resources
###############################################################################
Comment on lines +77 to +79

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this property for debugging purpose. I was changing ddsrouter_config_schema.json but the build files did not refresh.

Suggested change
###############################################################################
# Resources
###############################################################################
###############################################################################
# Resources
###############################################################################
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/../resources/configurations/ddsrouter_config_schema.json")

file(READ "${PROJECT_SOURCE_DIR}/../resources/configurations/ddsrouter_config_schema.json"
DDSROUTER_CONFIG_SCHEMA_CONTENT)

# Split into <=16000-char chunks to work around MSVC C2026 string literal size limit.
# Adjacent string literals are concatenated by the compiler.
string(LENGTH "${DDSROUTER_CONFIG_SCHEMA_CONTENT}" _schema_len)
set(_chunk_size 16000)
set(DDSROUTER_CONFIG_SCHEMA_CHUNKS "")
set(_offset 0)
while(_offset LESS _schema_len)
string(SUBSTRING "${DDSROUTER_CONFIG_SCHEMA_CONTENT}" ${_offset} ${_chunk_size} _chunk)
string(APPEND DDSROUTER_CONFIG_SCHEMA_CHUNKS " R\"json(${_chunk})json\"\n")
math(EXPR _offset "${_offset} + ${_chunk_size}")
endwhile()

configure_file(
"${PROJECT_SOURCE_DIR}/include/ddsrouter_yaml/DdsRouterConfigSchema.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/ddsrouter_yaml/DdsRouterConfigSchema.hpp"
@ONLY
)

target_include_directories(${MODULE_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
)

###############################################################################
# Packaging
###############################################################################
Expand Down
18 changes: 18 additions & 0 deletions ddsrouter_yaml/include/ddsrouter_yaml/DdsRouterConfigSchema.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

static const char* DDSROUTER_CONFIG_SCHEMA =
@DDSROUTER_CONFIG_SCHEMA_CHUNKS@;
3 changes: 3 additions & 0 deletions ddsrouter_yaml/project_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ set(fastdds_MINIMUM_VERSION "3.0.0")
set(MODULE_DEPENDENCIES
$<$<BOOL:${WIN32}>:iphlpapi$<SEMICOLON>Shlwapi>
${MODULE_FIND_PACKAGES})

set(MODULE_CPP_VERSION
C++17)
51 changes: 37 additions & 14 deletions ddsrouter_yaml/src/cpp/YamlReaderConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include <ddspipe_yaml/Yaml.hpp>
#include <ddspipe_yaml/YamlManager.hpp>
#include <ddspipe_yaml/YamlReader.hpp>
#include <ddspipe_yaml/YamlValidator.hpp>

#include <ddsrouter_core/configuration/DdsRouterConfiguration.hpp>

#include <ddsrouter_yaml/YamlReaderConfiguration.hpp>
#include <ddsrouter_yaml/DdsRouterConfigSchema.hpp>

namespace eprosima {
namespace ddsrouter {
Expand All @@ -30,6 +32,16 @@ YamlReaderConfiguration::load_ddsrouter_configuration(
const Yaml& yml,
const CommandlineArgsRouter* args /*= nullptr*/)
{
// Ensure the Yaml is valid
ddspipe::yaml::YamlValidator validator = ddspipe::yaml::YamlValidator(
ddspipe::yaml::YamlValidator::InputType::FROM_STRING,
DDSROUTER_CONFIG_SCHEMA);
if (!validator.validate_YAML(yml))
{
throw eprosima::utils::ConfigurationException(
utils::Formatter() << "Error, the provided yaml file is not a valid ddsrouter configuration.");
}

try
{
ddspipe::yaml::YamlReaderVersion version;
Expand All @@ -49,18 +61,27 @@ YamlReaderConfiguration::load_ddsrouter_configuration(
case ddspipe::yaml::YamlReaderVersion::V_2_0:
case ddspipe::yaml::YamlReaderVersion::V_3_0:
case ddspipe::yaml::YamlReaderVersion::V_3_1:
default:

throw eprosima::utils::ConfigurationException(
utils::Formatter() <<
"The yaml configuration version " << version <<
" is no longer supported. Please update to v5.0.");
utils::Formatter()
<< "The yaml configuration version " << version
<< " is no longer supported. Please update to "
<< ddspipe::yaml::YamlReaderVersion::LATEST << ".");
break;

case ddspipe::yaml::YamlReaderVersion::V_4_0:
EPROSIMA_LOG_WARNING(DDSROUTER_YAML,
"The yaml configuration version " << version <<
" is deprecated and will be removed in a future release. Please update to v5.0.");
"The yaml configuration version "
<< version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Suggested change
"The yaml configuration version "
<< version
"The yaml configuration version " << version

<< " is deprecated and will be removed in a future release. "
<< "Please update to " << ddspipe::yaml::YamlReaderVersion::LATEST << ".");
break;

default:
throw eprosima::utils::ConfigurationException(
utils::Formatter()
<< "The yaml configuration version " << version
<< " is unknown and not supported. Please update to "
<< ddspipe::yaml::YamlReaderVersion::LATEST << ".");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw eprosima::utils::ConfigurationException(
utils::Formatter()
<< "The yaml configuration version " << version
<< " is unknown and not supported. Please update to "
<< ddspipe::yaml::YamlReaderVersion::LATEST << ".");
// Defensive fallback. with mandatory schema validation enabled, it is not necessary.
throw eprosima::utils::ConfigurationException(utils::Formatter()
<< "The yaml configuration version " << version << " is unknown and not supported." \
"Please update to " << ddspipe::yaml::YamlReaderVersion::LATEST << ".");

break;
}
}
Expand All @@ -69,9 +90,11 @@ YamlReaderConfiguration::load_ddsrouter_configuration(
// Get default version
version = default_yaml_version();
EPROSIMA_LOG_WARNING(DDSROUTER_YAML,
"No version of yaml configuration given. Using version " << version << " by default. " <<
"Add " << ddspipe::yaml::VERSION_TAG << " tag to your configuration in order to not break compatibility " <<
"in future releases.");
"No version of yaml configuration given. Using version "
<< version << " by default. "
<< "Add " << ddspipe::yaml::VERSION_TAG
<< " tag to your configuration in order to not break compatibility "
<< "in future releases.");
}

EPROSIMA_LOG_INFO(DDSROUTER_YAML, "Loading DDSRouter configuration with version: " << version << ".");
Expand Down Expand Up @@ -111,15 +134,15 @@ YamlReaderConfiguration::load_ddsrouter_configuration_from_file(
catch (const std::exception& e)
{
throw eprosima::utils::ConfigurationException(
utils::Formatter() << "Error loading DDSRouter configuration from file: <" << file_path <<
"> :\n " << e.what());
utils::Formatter() << "Error loading DDSRouter configuration from file: <" << file_path
<< "> :\n " << e.what());
}

if (yml.IsNull())
{
throw eprosima::utils::ConfigurationException(
utils::Formatter() << "Error loading DDSRouter configuration from file: <" << file_path <<
"> :\n " << "yaml node is null.");
utils::Formatter() << "Error loading DDSRouter configuration from file: <" << file_path
<< "> :\n " << "yaml node is null.");
}

return YamlReaderConfiguration::load_ddsrouter_configuration(yml, args);
Expand Down
1 change: 1 addition & 0 deletions ddsrouter_yaml/test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
# TODO uncomment when new API applied
add_subdirectory(configuration)
add_subdirectory(participants)
add_subdirectory(ddsrouter_yaml_validator)
14 changes: 11 additions & 3 deletions ddsrouter_yaml/test/unittest/configuration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ set(TEST_SOURCES
)

set(TEST_LIST
# ddsrouter_configuration_v1_not_supported
# get_ddsrouter_configuration_v2
error_loading_yaml
configuration_version_not_supported
configuration_version_deprecated
valid_yaml_invalid_config
get_ddsrouter_configuration_no_version
version_negative_cases
number_of_threads
Expand All @@ -51,11 +53,17 @@ set(TEST_EXTRA_LIBRARIES
ddsrouter_core
)

file(GLOB_RECURSE TEST_NEEDED_SOURCES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"empty_file.yaml"
)

add_unittest_executable(
"${TEST_NAME}"
"${TEST_SOURCES}"
"${TEST_LIST}"
"${TEST_EXTRA_LIBRARIES}")
"${TEST_EXTRA_LIBRARIES}"
"${TEST_NEEDED_SOURCES}")

#####################################
# Yaml DdsRouter Configuration Test #
Expand Down
Loading
Loading