Skip to content

Commit

Permalink
[config] Transport layer struct rework (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen authored Dec 12, 2024
1 parent 32f028f commit e5b7b4e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 47 deletions.
1 change: 0 additions & 1 deletion ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ set(ecal_config_src
src/config/default_configuration.cpp
src/config/ecal_config.cpp
src/config/ecal_config_initializer.cpp
src/config/transport_layer.cpp
src/types/ecal_custom_data_types.cpp
)
if (ECAL_CORE_CONFIGURATION)
Expand Down
45 changes: 15 additions & 30 deletions ecal/core/include/ecal/config/transport_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,32 @@ namespace eCAL
{
namespace UDP
{
namespace Network
struct MulticastConfiguration
{
struct Configuration
{
Types::IpAddressV4 group { "239.0.0.1" }; //!< UDP multicast group base (Default: 239.0.0.1)
unsigned int ttl { 3U }; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination (Default: 3) */
};
}

namespace Local
{
struct Configuration
{
Types::IpAddressV4 group { "127.255.255.255" }; //!< UDP multicast group base (Default: 127.255.255.255)
unsigned int ttl { 1U }; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination (Default: 1) */
};
}
Types::IpAddressV4 group{"239.0.0.1"}; //!< UDP multicast group base
unsigned int ttl; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination */
};

struct Configuration
{
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
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)
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)*/

unsigned int send_buffer { 5242880 }; //!< UDP send buffer in bytes (Default: 5242880)
unsigned int receive_buffer { 5242880 }; //!< UDP receive buffer in bytes (Default: 5242880)
bool join_all_interfaces { false }; /*!< Linux specific setting to enable joining multicast groups on all network interfacs
unsigned int send_buffer { 5242880 }; //!< UDP send buffer in bytes (Default: 5242880)
unsigned int receive_buffer { 5242880 }; //!< UDP receive buffer in bytes (Default: 5242880)
bool join_all_interfaces { false }; /*!< Linux specific setting to enable joining multicast groups on all network interfacs
independent of their link state. Enabling this makes sure that eCAL processes
receive data if they are started before network devices are up and running. (Default: false)*/
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)

Network::Configuration network;
const Local::Configuration local;

ECAL_API Configuration& operator=(const Configuration& other);
MulticastConfiguration network { "239.0.0.1", 3U }; //!< default: "239.0.0.1", 3U
MulticastConfiguration local { "127.255.255.255", 1U}; //!< default: "127.255.255.255", 1U
};
}

Expand Down
10 changes: 5 additions & 5 deletions ecal/core/include/ecal/types/ecal_custom_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ namespace eCAL
**/
class IpAddressV4
{
public:
ECAL_API IpAddressV4(const std::string& ip_address_);
public:
ECAL_API IpAddressV4(const std::string& ip_address_);
ECAL_API IpAddressV4(const char* ip_address_);

ECAL_API std::string Get() const;

ECAL_API IpAddressV4& operator=(const std::string& ip_string_);
ECAL_API IpAddressV4& operator=(const char* ip_string_);
ECAL_API IpAddressV4& operator=(const char* ip_string_);
ECAL_API operator std::string() const;
ECAL_API bool operator==(const eCAL::Types::IpAddressV4& rhs) const;
ECAL_API friend bool operator==(eCAL::Types::IpAddressV4 lhs, const char* ip_string_);
Expand All @@ -61,7 +61,7 @@ namespace eCAL
ECAL_API friend bool operator==(const std::string& ip_string_, eCAL::Types::IpAddressV4 rhs);

private:
ECAL_API void validateIpString(const std::string& ip_address_);
ECAL_API void validateIpString(const std::string& ip_address_);

std::string m_ip_address{};
};
Expand All @@ -79,4 +79,4 @@ namespace eCAL
};

}
}
}
8 changes: 5 additions & 3 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ namespace YAML
return true;
}

Node convert<eCAL::TransportLayer::UDP::Network::Configuration>::encode(const eCAL::TransportLayer::UDP::Network::Configuration& config_)
Node convert<eCAL::TransportLayer::UDP::MulticastConfiguration>::encode(const eCAL::TransportLayer::UDP::MulticastConfiguration& config_)
{
Node node;
node["group"] = config_.group.Get();
node["ttl"] = config_.ttl;
return node;
}

bool convert<eCAL::TransportLayer::UDP::Network::Configuration>::decode(const Node& node_, eCAL::TransportLayer::UDP::Network::Configuration& config_)
bool convert<eCAL::TransportLayer::UDP::MulticastConfiguration>::decode(const Node& node_, eCAL::TransportLayer::UDP::MulticastConfiguration& config_)
{
AssignValue<std::string>(config_.group, node_, "group");
AssignValue<unsigned int>(config_.ttl, node_, "ttl");
Expand All @@ -247,6 +247,7 @@ namespace YAML
node["join_all_interfaces"] = config_.join_all_interfaces;
node["npcap_enabled"] = config_.npcap_enabled;
node["network"] = config_.network;
node["local"] = config_.local;
return node;
}

Expand All @@ -265,7 +266,8 @@ namespace YAML
AssignValue<bool>(config_.join_all_interfaces, node_, "join_all_interfaces");
AssignValue<bool>(config_.npcap_enabled, node_, "npcap_enabled");

AssignValue<eCAL::TransportLayer::UDP::Network::Configuration>(config_.network, node_, "network");
AssignValue<eCAL::TransportLayer::UDP::MulticastConfiguration>(config_.network, node_, "network");
AssignValue<eCAL::TransportLayer::UDP::MulticastConfiguration>(config_.local, node_, "local");
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/config/configuration_to_yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ namespace YAML
};

template<>
struct convert<eCAL::TransportLayer::UDP::Network::Configuration>
struct convert<eCAL::TransportLayer::UDP::MulticastConfiguration>
{
static Node encode(const eCAL::TransportLayer::UDP::Network::Configuration& config_);
static Node encode(const eCAL::TransportLayer::UDP::MulticastConfiguration& config_);

static bool decode(const Node& node_, eCAL::TransportLayer::UDP::Network::Configuration& config_);
static bool decode(const Node& node_, eCAL::TransportLayer::UDP::MulticastConfiguration& config_);
};

template<>
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/config/default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ namespace eCAL
ss << R"( # Windows specific setting to enable receiving UDP traffic with the Npcap based receiver)" << "\n";
ss << R"( npcap_enabled: )" << config_.transport_layer.udp.npcap_enabled << "\n";
ss << R"()" << "\n";
ss << R"( # In local mode multicast group and ttl are set by default and are not adjustable)" << "\n";
ss << R"( # Local mode multicast group and ttl)" << "\n";
ss << R"( local:)" << "\n";
ss << R"( # Multicast group base. All registration and logging is sent on this address)" << "\n";
ss << R"( # group: "127.0.0.1")" << "\n";
ss << R"( group: )" << quoteString(config_.transport_layer.udp.local.group) << "\n";
ss << R"( # TTL (hop limit) is used to determine the amount of routers being traversed towards the destination)" << "\n";
ss << R"( # ttl: 0)" << "\n";
ss << R"( ttl: )" << config_.transport_layer.udp.local.ttl << "\n";
ss << R"()" << "\n";
ss << R"( network:)" << "\n";
ss << R"( # Multicast group base. All registration and logging is sent on this address)" << "\n";
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/types/ecal_custom_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ namespace eCAL
IpAddressV4::IpAddressV4(const std::string& ip_address_)
{
validateIpString(ip_address_);
}
}

IpAddressV4::IpAddressV4(const char* ip_address_)
{
validateIpString(ip_address_);
}
}

void IpAddressV4::validateIpString(const std::string& ip_address_)
{
Expand Down

0 comments on commit e5b7b4e

Please sign in to comment.