Skip to content

Commit

Permalink
[config] Improved network configuration options (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen authored Mar 5, 2025
1 parent e4a0e21 commit cf09b16
Show file tree
Hide file tree
Showing 38 changed files with 551 additions and 390 deletions.
10 changes: 10 additions & 0 deletions ecal/core/include/ecal/config/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@

namespace eCAL
{
enum class eCommunicationMode
{
local,
network
};

struct Configuration
{
TransportLayer::Configuration transport_layer;
Expand All @@ -53,6 +59,10 @@ namespace eCAL
Application::Configuration application;
Logging::Configuration logging;

eCommunicationMode communication_mode { eCommunicationMode::local }; /*!< eCAL components communication mode:
local: local host only communication (default)
cloud: communication across network boundaries */

ECAL_API Configuration();

ECAL_API void InitFromConfig();
Expand Down
55 changes: 40 additions & 15 deletions ecal/core/include/ecal/config/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,70 @@ namespace eCAL
{
namespace Registration
{
namespace Layer
namespace Local
{
enum class eTransportType
{
shm,
udp
};
namespace SHM
{
struct Configuration
{
bool enable { false }; /*!< Enable shared memory based registration (Default: false) */
std::string domain { "ecal_mon" }; //!< Domain name for shared memory based registration (Default: ecal_mon)
size_t queue_size { 1024 }; //!< Queue size of registration events (Default: 1024)
std::string domain { "ecal_mon" }; //!< Domain name for shared memory based registration (Default: ecal_mon)
size_t queue_size { 1024 }; //!< Queue size of registration events (Default: 1024)
};
}

namespace UDP
{
struct Configuration
{
unsigned int port { 14000 }; /*!< UDP broadcast port number (Default: 14000) */
};
}

struct Configuration
{
eTransportType transport_type { eTransportType::udp }; //!< Transport type for registration (Default: udp)

SHM::Configuration shm;
UDP::Configuration udp;
};
} // namespeace Local

namespace Network
{
enum class eTransportType
{
udp
};
namespace UDP
{
struct Configuration
{
bool enable { true }; /*!< Enable UDP based registration (Default: true) */
unsigned int port { 14000 }; /*!< UDP multicast port number (Default: 14000) */
};
}

struct Configuration
{
SHM::Configuration shm; /*!< Shared memory based registration configuration */
UDP::Configuration udp; /*!< UDP based registration configuration */
eTransportType transport_type { eTransportType::udp }; //!< Transport type for registration (Default: udp)
UDP::Configuration udp;
};
}
} // namespace Network

struct Configuration
{
unsigned int registration_timeout { 10000U }; //!< Timeout for topic registration in ms (internal) (Default: 10000)
unsigned int registration_refresh { 1000U }; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000)
unsigned int registration_timeout { 10000U }; //!< Timeout for topic registration in ms (internal) (Default: 10000)
unsigned int registration_refresh { 1000U }; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000)

bool network_enabled { false }; /*!< true = all eCAL components communicate over network boundaries
false = local host only communication (Default: false) */
bool loopback { true }; //!< enable to receive udp messages on the same local machine (Default: true)
std::string shm_transport_domain { "" }; /*!< Common shm transport domain that enables interprocess mechanisms across
bool loopback { true }; //!< enable to receive udp messages on the same local machine (Default: true)
std::string shm_transport_domain { "" }; /*!< Common shm transport domain that enables interprocess mechanisms across
(virtual) host borders (e.g, Docker); by default equivalent to local host name (Default: "") */
Layer::Configuration layer;
Local::Configuration local;
Network::Configuration network;
};
}
}
3 changes: 1 addition & 2 deletions ecal/core/include/ecal/config/transport_layer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* =========================== LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,6 @@ namespace eCAL
v1: default behavior
v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups (Default: v2) */
unsigned int port { 14002 }; /*!< UDP multicast port number (Default: 14002) */
Types::UDPMode mode { Types::UDPMode::LOCAL }; /*!< Valid modes: local, network (Default: local)*/
Types::IpAddressV4 mask { "255.255.255.240" }; /*!< v1: Mask maximum number of dynamic multicast group (Default: 0.0.0.1-0.0.0.255)
v2: masks are now considered like routes masking (Default: 255.0.0.0-255.255.255.255)*/

Expand Down
9 changes: 1 addition & 8 deletions ecal/core/include/ecal/types/custom_data_types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* =========================== LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,12 +71,5 @@ namespace eCAL
V1 = 1,
V2 = 2
};

enum class UDPMode
{
NETWORK,
LOCAL
};

}
}
65 changes: 36 additions & 29 deletions ecal/core/src/config/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,46 @@ namespace eCAL
{
namespace Logging
{
SProviderAttributes BuildLoggingProviderAttributes(const Logging::Configuration& log_config_, const Registration::Configuration& reg_config_, const TransportLayer::Configuration& tl_config_)
SProviderAttributes BuildLoggingProviderAttributes(const eCAL::Configuration& config_)
{
const auto& logging_config = config_.logging;
const auto& transport_layer_config = config_.transport_layer;
const auto& registration_config = config_.registration;

SProviderAttributes attributes;

attributes.host_name = Process::GetHostName();
attributes.process_id = Process::GetProcessID();
attributes.process_name = Process::GetProcessName();
attributes.unit_name = Process::GetUnitName();

attributes.udp_sink.enabled = log_config_.provider.udp.enable;
attributes.udp_sink.log_level = log_config_.provider.udp.log_level;
attributes.udp_sink.enabled = logging_config.provider.udp.enable;
attributes.udp_sink.log_level = logging_config.provider.udp.log_level;

attributes.file_sink.enabled = log_config_.provider.file.enable;
attributes.file_sink.log_level = log_config_.provider.file.log_level;
attributes.file_sink.enabled = logging_config.provider.file.enable;
attributes.file_sink.log_level = logging_config.provider.file.log_level;

attributes.file_config.path = Util::GeteCALLogDir();

attributes.console_sink.enabled = log_config_.provider.console.enable;
attributes.console_sink.log_level = log_config_.provider.console.log_level;
attributes.console_sink.enabled = logging_config.provider.console.enable;
attributes.console_sink.log_level = logging_config.provider.console.log_level;

// UDP related configuration part
attributes.udp_config.broadcast = !reg_config_.network_enabled;
attributes.udp_config.loopback = reg_config_.loopback;
attributes.udp_config.broadcast = config_.communication_mode == eCAL::eCommunicationMode::local;
attributes.udp_config.loopback = registration_config.loopback;

attributes.udp_config.sndbuf = tl_config_.udp.send_buffer;
attributes.udp_config.port = log_config_.provider.udp_config.port;
attributes.udp_config.sndbuf = transport_layer_config.udp.send_buffer;
attributes.udp_config.port = logging_config.provider.udp_config.port;

switch (tl_config_.udp.mode)
switch (config_.communication_mode)
{
case Types::UDPMode::NETWORK:
attributes.udp_config.address = tl_config_.udp.network.group;
attributes.udp_config.ttl = tl_config_.udp.network.ttl;
case eCAL::eCommunicationMode::network:
attributes.udp_config.address = transport_layer_config.udp.network.group;
attributes.udp_config.ttl = transport_layer_config.udp.network.ttl;
break;
case Types::UDPMode::LOCAL:
attributes.udp_config.address = tl_config_.udp.local.group;
attributes.udp_config.ttl = tl_config_.udp.local.ttl;
case eCAL::eCommunicationMode::local:
attributes.udp_config.address = transport_layer_config.udp.local.group;
attributes.udp_config.ttl = transport_layer_config.udp.local.ttl;
break;
default:
break;
Expand All @@ -50,28 +54,31 @@ namespace eCAL
return attributes;
}

SReceiverAttributes BuildLoggingReceiverAttributes(const Logging::Configuration& log_config_, const Registration::Configuration& reg_config_, const TransportLayer::Configuration& tl_config_)
SReceiverAttributes BuildLoggingReceiverAttributes(const eCAL::Configuration& config_)
{
const auto& logging_config = config_.logging;
const auto& transport_layer_config = config_.transport_layer;

SReceiverAttributes attributes;

attributes.network_enabled = reg_config_.network_enabled;
attributes.network_enabled = config_.communication_mode == eCAL::eCommunicationMode::network;
attributes.host_name = Process::GetHostName();

attributes.receive_enabled = log_config_.receiver.enable;
attributes.receive_enabled = logging_config.receiver.enable;

attributes.udp_receiver.broadcast = !reg_config_.network_enabled;
attributes.udp_receiver.broadcast = config_.communication_mode == eCAL::eCommunicationMode::local;
attributes.udp_receiver.loopback = true;

attributes.udp_receiver.rcvbuf = tl_config_.udp.receive_buffer;
attributes.udp_receiver.port = log_config_.receiver.udp_config.port;
attributes.udp_receiver.rcvbuf = transport_layer_config.udp.receive_buffer;
attributes.udp_receiver.port = logging_config.receiver.udp_config.port;

switch (tl_config_.udp.mode)
switch (config_.communication_mode)
{
case Types::UDPMode::NETWORK:
attributes.udp_receiver.address = tl_config_.udp.network.group;
case eCAL::eCommunicationMode::network:
attributes.udp_receiver.address = transport_layer_config.udp.network.group;
break;
case Types::UDPMode::LOCAL:
attributes.udp_receiver.address = tl_config_.udp.local.group;
case eCAL::eCommunicationMode::local:
attributes.udp_receiver.address = transport_layer_config.udp.local.group;
break;
default:
break;
Expand Down
10 changes: 4 additions & 6 deletions ecal/core/src/config/builder/logging_attribute_builder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,15 +21,13 @@

#include "logging/config/attributes/ecal_log_provider_attributes.h"
#include "logging/config/attributes/ecal_log_receiver_attributes.h"
#include "ecal/config/logging.h"
#include "ecal/config/registration.h"
#include "ecal/config/transport_layer.h"
#include "ecal/config/configuration.h"

namespace eCAL
{
namespace Logging
{
SProviderAttributes BuildLoggingProviderAttributes(const Logging::Configuration& log_config_, const Registration::Configuration& reg_config_, const TransportLayer::Configuration& tl_config_);
SReceiverAttributes BuildLoggingReceiverAttributes(const Logging::Configuration& log_config_, const Registration::Configuration& reg_config_, const TransportLayer::Configuration& tl_config_);
SProviderAttributes BuildLoggingProviderAttributes(const eCAL::Configuration& config_);
SReceiverAttributes BuildLoggingReceiverAttributes(const eCAL::Configuration& config_);
}
}
64 changes: 44 additions & 20 deletions ecal/core/src/config/builder/registration_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,62 @@

#include "registration_attribute_builder.h"
#include "ecal/process.h"
#include "ecal/config.h"

namespace eCAL
{
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Registration::Configuration& reg_config_, const eCAL::TransportLayer::UDP::Configuration& tl_udp_confi_, int process_id_)
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Configuration& config_, int process_id_)
{
const auto& reg_config = config_.registration;
const auto& tl_udp_config = config_.transport_layer.udp;

Registration::SAttributes attr;

attr.timeout = std::chrono::milliseconds(reg_config_.registration_timeout);
attr.refresh = reg_config_.registration_refresh;
attr.network_enabled = reg_config_.network_enabled;
attr.loopback = reg_config_.loopback;
attr.network_enabled = config_.communication_mode == eCAL::eCommunicationMode::network;
attr.timeout = std::chrono::milliseconds(reg_config.registration_timeout);
attr.refresh = reg_config.registration_refresh;
attr.loopback = reg_config.loopback;
attr.host_name = eCAL::Process::GetHostName();
attr.shm_transport_domain = reg_config_.shm_transport_domain;
attr.shm_transport_domain = reg_config.shm_transport_domain;

attr.process_id = process_id_;

attr.shm_enabled = reg_config_.layer.shm.enable;
attr.udp_enabled = reg_config_.layer.udp.enable;

attr.shm.domain = reg_config_.layer.shm.domain;
attr.shm.queue_size = reg_config_.layer.shm.queue_size;
attr.shm.domain = reg_config.local.shm.domain;
attr.shm.queue_size = reg_config.local.shm.queue_size;

attr.udp.port = reg_config_.layer.udp.port;
attr.udp.sendbuffer = tl_udp_confi_.send_buffer;
attr.udp.receivebuffer = tl_udp_confi_.receive_buffer;
attr.udp.mode = tl_udp_confi_.mode;

attr.udp.network.group = tl_udp_confi_.network.group;
attr.udp.network.ttl = tl_udp_confi_.network.ttl;
switch (config_.communication_mode)
{
case eCAL::eCommunicationMode::network:
attr.udp.port = reg_config.network.udp.port;
attr.udp.group = tl_udp_config.network.group;
attr.udp.ttl = tl_udp_config.network.ttl;
attr.udp.broadcast = false;
// Only udp transport type is supported for network communication right now
attr.transport_mode = Registration::eTransportMode::udp;
break;
case eCAL::eCommunicationMode::local:
attr.udp.port = reg_config.local.udp.port;
attr.udp.group = tl_udp_config.local.group;
attr.udp.ttl = tl_udp_config.local.ttl;
attr.udp.broadcast = true;
switch (reg_config.local.transport_type)
{
case Registration::Local::eTransportType::udp:
attr.transport_mode = Registration::eTransportMode::udp;
break;
case Registration::Local::eTransportType::shm:
attr.transport_mode = Registration::eTransportMode::shm;
break;
default:
break;
}
break;
default:
break;
}

attr.udp.local.group = tl_udp_confi_.local.group;
attr.udp.local.ttl = tl_udp_confi_.local.ttl;
attr.udp.sendbuffer = tl_udp_config.send_buffer;
attr.udp.receivebuffer = tl_udp_config.receive_buffer;

return attr;
}
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/config/builder/registration_attribute_builder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,5 +25,5 @@

namespace eCAL
{
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Registration::Configuration& reg_config_, const eCAL::TransportLayer::UDP::Configuration& tl_udp_confi_, int process_id_);
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Configuration& config_, int process_id_);
}
8 changes: 1 addition & 7 deletions ecal/core/src/config/configuration_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ namespace
{
void MapConfiguration(const YAML::Node& node_, eCAL::Configuration& config_)
{
YAML::AssignValue<eCAL::TransportLayer::Configuration>(config_.transport_layer, node_, "transport_layer");
YAML::AssignValue<eCAL::Publisher::Configuration>(config_.publisher, node_, "publisher");
YAML::AssignValue<eCAL::Subscriber::Configuration>(config_.subscriber, node_, "subscriber");
YAML::AssignValue<eCAL::Registration::Configuration>(config_.registration, node_, "registration");
YAML::AssignValue<eCAL::Time::Configuration>(config_.timesync, node_, "time");
YAML::AssignValue<eCAL::Application::Configuration>(config_.application, node_, "application");
YAML::AssignValue<eCAL::Logging::Configuration>(config_.logging, node_, "logging");
config_ = node_.as<eCAL::Configuration>();
}
}

Expand Down
Loading

0 comments on commit cf09b16

Please sign in to comment.