Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 3 additions & 1 deletion implementation/configuration/include/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ class configuration {
virtual uint8_t get_sd_repetitions_max() const = 0;
virtual ttl_t get_sd_ttl() const = 0;
virtual int32_t get_sd_cyclic_offer_delay() const = 0;
virtual int32_t get_sd_request_response_delay() const = 0;
virtual int32_t get_sd_cyclic_request_delay() const = 0;
virtual int32_t get_sd_request_response_delay_min() const = 0;
virtual int32_t get_sd_request_response_delay_max() const = 0;
virtual uint8_t get_sd_find_initial_debounce_reps() const = 0;
virtual std::uint32_t get_sd_find_initial_debounce_time() const = 0;
virtual std::uint32_t get_sd_offer_debounce_time() const = 0;
Expand Down
12 changes: 9 additions & 3 deletions implementation/configuration/include/configuration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ class configuration_impl:
VSOMEIP_EXPORT uint8_t get_sd_repetitions_max() const;
VSOMEIP_EXPORT ttl_t get_sd_ttl() const;
VSOMEIP_EXPORT int32_t get_sd_cyclic_offer_delay() const;
VSOMEIP_EXPORT int32_t get_sd_request_response_delay() const;
VSOMEIP_EXPORT int32_t get_sd_cyclic_request_delay() const;
VSOMEIP_EXPORT int32_t get_sd_request_response_delay_min() const;
VSOMEIP_EXPORT int32_t get_sd_request_response_delay_max() const;
VSOMEIP_EXPORT uint8_t get_sd_find_initial_debounce_reps() const;
VSOMEIP_EXPORT std::uint32_t get_sd_find_initial_debounce_time() const;
VSOMEIP_EXPORT std::uint32_t get_sd_offer_debounce_time() const;
Expand Down Expand Up @@ -552,7 +554,9 @@ class configuration_impl:
uint8_t sd_repetitions_max_;
ttl_t sd_ttl_;
int32_t sd_cyclic_offer_delay_;
int32_t sd_request_response_delay_;
int32_t sd_cyclic_request_delay_;
int32_t sd_request_response_delay_min_;
int32_t sd_request_response_delay_max_;
std::uint32_t sd_offer_debounce_time_;
std::uint32_t sd_find_debounce_time_;
uint8_t sd_find_initial_debounce_reps_;
Expand Down Expand Up @@ -601,7 +605,9 @@ class configuration_impl:
ET_SERVICE_DISCOVERY_REPETITION_MAX,
ET_SERVICE_DISCOVERY_TTL,
ET_SERVICE_DISCOVERY_CYCLIC_OFFER_DELAY,
ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY,
ET_SERVICE_DISCOVERY_CYCLIC_REQUEST_DELAY,
ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY_MIN,
ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY_MAX,
ET_WATCHDOG_ENABLE,
ET_WATCHDOG_TIMEOUT,
ET_WATCHDOG_ALLOWED_MISSING_PONGS,
Expand Down
41 changes: 31 additions & 10 deletions implementation/configuration/src/configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ configuration_impl::configuration_impl(const std::string& _path) :
sd_repetitions_base_delay_ {VSOMEIP_SD_DEFAULT_REPETITIONS_BASE_DELAY},
sd_repetitions_max_ {VSOMEIP_SD_DEFAULT_REPETITIONS_MAX}, sd_ttl_ {VSOMEIP_SD_DEFAULT_TTL},
sd_cyclic_offer_delay_ {VSOMEIP_SD_DEFAULT_CYCLIC_OFFER_DELAY},
sd_request_response_delay_ {VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY},
sd_cyclic_request_delay_(VSOMEIP_SD_DEFAULT_CYCLIC_REQUEST_DELAY),
sd_request_response_delay_min_(VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY_MIN),
sd_request_response_delay_max_(VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY_MAX),
sd_offer_debounce_time_ {VSOMEIP_SD_DEFAULT_OFFER_DEBOUNCE_TIME},
sd_find_debounce_time_ {VSOMEIP_SD_DEFAULT_FIND_DEBOUNCE_TIME},
sd_find_initial_debounce_reps_(VSOMEIP_SD_INITIAL_FIND_DEBOUNCE_REPS),
Expand Down Expand Up @@ -164,7 +166,9 @@ configuration_impl::configuration_impl(const configuration_impl& _other) :
sd_repetitions_max_ = _other.sd_repetitions_max_;
sd_ttl_ = _other.sd_ttl_;
sd_cyclic_offer_delay_= _other.sd_cyclic_offer_delay_;
sd_request_response_delay_= _other.sd_request_response_delay_;
sd_cyclic_request_delay_= _other.sd_cyclic_request_delay_;
sd_request_response_delay_min_= _other.sd_request_response_delay_min_;
sd_request_response_delay_max_= _other.sd_request_response_delay_max_;
sd_find_initial_debounce_reps_ = _other.sd_find_initial_debounce_reps_;
sd_find_initial_debounce_time_ = _other.sd_find_initial_debounce_time_;
sd_offer_debounce_time_ = _other.sd_offer_debounce_time_;
Expand Down Expand Up @@ -1814,14 +1818,23 @@ void configuration_impl::load_service_discovery(
its_converter >> sd_cyclic_offer_delay_;
is_configured_[ET_SERVICE_DISCOVERY_CYCLIC_OFFER_DELAY] = true;
}
} else if (its_key == "request_response_delay") {
if (is_configured_[ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY]) {
VSOMEIP_WARNING << "Multiple definitions for service_discovery.request_response_delay."
} else if (its_key == "request_response_delay_min") {
if (is_configured_[ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY_MIN]) {
VSOMEIP_WARNING << "Multiple definitions for service_discovery.request_response_delay_min."
" Ignoring definition from " << _element.name_;
} else {
its_converter << its_value;
its_converter >> sd_request_response_delay_;
is_configured_[ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY] = true;
its_converter >> sd_request_response_delay_min_;
is_configured_[ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY_MIN] = true;
}
} else if (its_key == "request_response_delay_max") {
if (is_configured_[ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY_MAX]) {
VSOMEIP_WARNING << "Multiple definitions for service_discovery.request_response_delay_max."
" Ignoring definition from " << _element.name_;
} else {
its_converter << its_value;
its_converter >> sd_request_response_delay_max_;
is_configured_[ET_SERVICE_DISCOVERY_REQUEST_RESPONSE_DELAY_MAX] = true;
}
} else if (its_key == "find_initial_debounce_reps") {
if (is_configured_[ET_SERVICE_DISCOVERY_FIND_INITIAL_DEBOUNCE_REPS]) {
Expand Down Expand Up @@ -1959,7 +1972,7 @@ void configuration_impl::load_delays(
its_converter >> sd_cyclic_offer_delay_;
} else if (its_key == "cyclic-request") {
its_converter << std::dec << i->second.data();
its_converter >> sd_request_response_delay_;
its_converter >> sd_cyclic_request_delay_;
} else if (its_key == "ttl") {
its_converter << std::dec << i->second.data();
its_converter >> sd_ttl_;
Expand Down Expand Up @@ -3829,8 +3842,16 @@ int32_t configuration_impl::get_sd_cyclic_offer_delay() const {
return sd_cyclic_offer_delay_;
}

int32_t configuration_impl::get_sd_request_response_delay() const {
return sd_request_response_delay_;
int32_t configuration_impl::get_sd_cyclic_request_delay() const {
return sd_cyclic_request_delay_;
}

int32_t configuration_impl::get_sd_request_response_delay_min() const {
return sd_request_response_delay_min_;
}

int32_t configuration_impl::get_sd_request_response_delay_max() const {
return sd_request_response_delay_max_;
}

uint8_t configuration_impl::get_sd_find_initial_debounce_reps() const {
Expand Down
88 changes: 88 additions & 0 deletions implementation/service_discovery/include/async_sender.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (C) 2024-2025 Valeo India Private Limited
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//
// /file async_sender.hpp
//
// /brief This file implements declares a class which
// implements a queue, and functions for timeout
// for the messages. On timeout, the client of
// this class will receive a callback.
//


#pragma once

#include <memory>
#include <thread>
#include <condition_variable>
#include <queue>
#include <mutex>
#include <atomic>
#include <vector>

#include "message_impl.hpp"

namespace async
{
namespace sender
{
using time_point = std::chrono::steady_clock::time_point;

struct async_packet_data
{
std::vector<std::shared_ptr<vsomeip_v3::sd::message_impl>> messages_;
boost::asio::ip::address address_;
time_point timeout_;
};

class async_packet_send_callback
{
public:
virtual ~async_packet_send_callback() = default;
virtual void on_async_send_pkt(std::shared_ptr<async_packet_data>) = 0;
};

class time_point_comparator
{
public:
bool operator()(std::shared_ptr<async_packet_data> a, std::shared_ptr<async_packet_data> b)
{
return a->timeout_ > b->timeout_;
}
};

using priority_queue = std::priority_queue<
std::shared_ptr<async_packet_data>,
std::vector<std::shared_ptr<async_packet_data>>,
time_point_comparator>;

class async_sender
{
public:
async_sender() = default;
~async_sender();
void add_queue(std::shared_ptr<async_packet_data> _pkt);
void set_packet_sender_callback(std::shared_ptr<async_packet_send_callback> callback);
void start();
void stop();
inline bool check_if_running() { return is_running_.load(); };

private:
void worker();
void handle_packet(std::shared_ptr<async_packet_data> _pkt);
void iterate_over_queue();

private:
std::atomic<bool> is_running_;
std::thread thread_;
std::condition_variable cv_;
std::mutex mtx_;
priority_queue queue_;
std::shared_ptr<async_packet_send_callback> callback_;
uint64_t minWait_;
};
}
}
4 changes: 3 additions & 1 deletion implementation/service_discovery/include/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
#define VSOMEIP_SD_DEFAULT_REPETITIONS_MAX 3
#define VSOMEIP_SD_DEFAULT_TTL DEFAULT_TTL
#define VSOMEIP_SD_DEFAULT_CYCLIC_OFFER_DELAY 1000
#define VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY 2000
#define VSOMEIP_SD_DEFAULT_CYCLIC_REQUEST_DELAY 2000
#define VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY_MIN 10
#define VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY_MAX 30
#define VSOMEIP_SD_DEFAULT_OFFER_DEBOUNCE_TIME 500
#define VSOMEIP_SD_DEFAULT_FIND_DEBOUNCE_TIME 500
#define VSOMEIP_SD_INITIAL_FIND_DEBOUNCE_TIME 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define VSOMEIP_V3_SD_SERVICE_DISCOVERY_HPP_

#include <boost/asio/ip/address.hpp>
#include <chrono>

#include <vsomeip/primitive_types.hpp>
#include <vsomeip/enumeration_types.hpp>
Expand Down Expand Up @@ -76,6 +77,7 @@ class service_discovery {
virtual void register_reboot_notification_handler(
const reboot_notification_handler_t &_handler) = 0;
virtual std::recursive_mutex& get_subscribed_mutex() = 0;
virtual std::chrono::milliseconds get_request_response_delay_random() const = 0;
};

} // namespace sd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ipv6_option_impl.hpp"
#include "deserializer.hpp"
#include "message_impl.hpp"
#include "async_sender.hpp"

namespace vsomeip_v3 {

Expand All @@ -35,6 +36,11 @@ class serializer;

namespace sd {

using time_point_clock = std::chrono::steady_clock;
using time_point = time_point_clock::time_point;
using service_instance_timepoint = std::map<service_t, std::map<instance_t,time_point>>;
using service_instance_entry_type = std::map<service_t, std::map<instance_t,std::map<entry_type_e,std::atomic<bool>>>>;

class entry_impl;
class eventgroupentry_impl;
class option_impl;
Expand All @@ -56,8 +62,10 @@ struct entry_data_t {
std::shared_ptr<entry_impl> other_;
};

class service_discovery_impl: public service_discovery,
public std::enable_shared_from_this<service_discovery_impl> {
class service_discovery_impl :
public service_discovery,
public async::sender::async_packet_send_callback,
public std::enable_shared_from_this<service_discovery_impl> {
public:
service_discovery_impl(service_discovery_host *_host,
const std::shared_ptr<configuration>& _configuration);
Expand Down Expand Up @@ -111,6 +119,10 @@ class service_discovery_impl: public service_discovery,
void register_sd_acceptance_handler(const sd_acceptance_handler_t &_handler);
void register_reboot_notification_handler(
const reboot_notification_handler_t &_handler);

void on_async_send_pkt(std::shared_ptr<async::sender::async_packet_data>) override;

std::chrono::milliseconds get_request_response_delay_random() const;
private:
std::pair<session_t, bool> get_session(const boost::asio::ip::address &_address);
void increment_session(const boost::asio::ip::address &_address);
Expand Down Expand Up @@ -176,7 +188,8 @@ class service_discovery_impl: public service_discovery,
instance_t _instance,
major_version_t _major,
minor_version_t _minor,
bool _unicast_flag);
bool _unicast_flag,
bool _received_via_multicast);
void process_eventgroupentry(
std::shared_ptr<eventgroupentry_impl> &_entry,
const std::vector<std::shared_ptr<option_impl> > &_options,
Expand Down Expand Up @@ -272,10 +285,11 @@ class service_discovery_impl: public service_discovery,

void send_uni_or_multicast_offerservice(
const std::shared_ptr<const serviceinfo> &_info,
bool _unicast_flag);
bool _unicast_flag,
bool _received_via_multicast);
bool last_offer_shorter_half_offer_delay_ago();
void send_unicast_offer_service(
const std::shared_ptr<const serviceinfo> &_info);
const std::shared_ptr<const serviceinfo> &_info, bool _received_via_multicast);
void send_multicast_offer_service(
const std::shared_ptr<const serviceinfo>& _info);

Expand Down Expand Up @@ -372,6 +386,15 @@ class service_discovery_impl: public service_discovery,
reliability_type_e get_eventgroup_reliability(
service_t _service, instance_t _instance, eventgroup_t _eventgroup,
const std::shared_ptr<subscription>& _subscription);

void prepare_async_send(time_point _ts,
std::vector<std::shared_ptr<message_impl>> &_messages,
const boost::asio::ip::address &_address);
time_point get_time_point_for_subs_offer(bool _is_subscribe, service_t _service, instance_t _instance);
void set_async_msg_pending(std::vector<std::shared_ptr<message_impl>>& _msgs);
void reset_async_msg_pending(std::vector<std::shared_ptr<message_impl>>& _msgs);
bool check_if_async_msg_pending(service_t _s, instance_t _i, entry_type_e _e);

void deserialize_data(const byte_t* _data, const length_t& _size,
std::shared_ptr<message_impl>& _message);

Expand Down Expand Up @@ -515,6 +538,12 @@ class service_discovery_impl: public service_discovery,

std::mutex offer_mutex_;
std::mutex check_ttl_mutex_;
service_instance_timepoint last_offer_ts_;
service_instance_timepoint last_find_ts_;
async::sender::async_sender async_sender_;
service_instance_entry_type service_instance_entry_type_;
int32_t request_response_delay_min_;
int32_t request_response_delay_max_;
};

} // namespace sd
Expand Down
Loading